This is an automated email from the ASF dual-hosted git repository.

olamy pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/maven-build-cache-extension.git


The following commit(s) were added to refs/heads/master by this push:
     new ac3e95b  [MBUILDCACHE-57] Configure remote url/remote server id with 
command line property (#74)
ac3e95b is described below

commit ac3e95ba3772142ad81205ab26ea4460c4348ba1
Author: Olivier Lamy <[email protected]>
AuthorDate: Wed Apr 26 14:38:24 2023 +1000

    [MBUILDCACHE-57] Configure remote url/remote server id with command line 
property (#74)
    
    * [MBUILDCACHE-57] Configure remote url/remote server id with command line 
property
    
    ---------
    
    Signed-off-by: Olivier Lamy <[email protected]>
---
 .../maven/buildcache/xml/CacheConfigImpl.java      |  6 ++-
 src/site/markdown/parameters.md                    |  2 +
 .../maven/buildcache/its/RemoteCacheDavTest.java   | 48 +++++++++++++++++++---
 3 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/maven/buildcache/xml/CacheConfigImpl.java 
b/src/main/java/org/apache/maven/buildcache/xml/CacheConfigImpl.java
index 8d09042..2e58b25 100644
--- a/src/main/java/org/apache/maven/buildcache/xml/CacheConfigImpl.java
+++ b/src/main/java/org/apache/maven/buildcache/xml/CacheConfigImpl.java
@@ -83,6 +83,8 @@ public class CacheConfigImpl implements 
org.apache.maven.buildcache.xml.CacheCon
     public static final String CACHE_ENABLED_PROPERTY_NAME = 
"maven.build.cache.enabled";
     public static final String CACHE_LOCATION_PROPERTY_NAME = 
"maven.build.cache.location";
     public static final String REMOTE_ENABLED_PROPERTY_NAME = 
"maven.build.cache.remote.enabled";
+    public static final String REMOTE_URL_PROPERTY_NAME = 
"maven.build.cache.remote.url";
+    public static final String REMOTE_SERVER_ID_PROPERTY_NAME = 
"maven.build.cache.remote.server.id";
     public static final String SAVE_TO_REMOTE_PROPERTY_NAME = 
"maven.build.cache.remote.save.enabled";
     public static final String SAVE_NON_OVERRIDEABLE_NAME = 
"maven.build.cache.remote.save.final";
     public static final String FAIL_FAST_PROPERTY_NAME = 
"maven.build.cache.failFast";
@@ -504,13 +506,13 @@ public class CacheConfigImpl implements 
org.apache.maven.buildcache.xml.CacheCon
     @Override
     public String getId() {
         checkInitializedState();
-        return getRemote().getId();
+        return getProperty(REMOTE_SERVER_ID_PROPERTY_NAME, 
getRemote().getId());
     }
 
     @Override
     public String getUrl() {
         checkInitializedState();
-        return getRemote().getUrl();
+        return getProperty(REMOTE_URL_PROPERTY_NAME, getRemote().getUrl());
     }
 
     @Override
diff --git a/src/site/markdown/parameters.md b/src/site/markdown/parameters.md
index a765eb1..d3c8f89 100644
--- a/src/site/markdown/parameters.md
+++ b/src/site/markdown/parameters.md
@@ -28,6 +28,8 @@ This documents contains various configuration parameters 
supported by cache engi
 | `-Dmaven.build.cache.remote.enabled=(true/false)`          | Checks and 
downloads artifacts from the remote cache (overrides <remote 
enabled=("true"/"false")>)                                       | To control 
remote cache access by node, if, say, some nodes lack reliable access   |
 | `-Dmaven.build.cache.remote.save.enabled=(true/false)`     | Remote cache 
save allowed or not                                                             
                                            | To designate nodes which allowed 
to push in remote shared cache                    |
 | `-Dmaven.build.cache.remote.save.final=(true/false)`       | Prohibit to 
override remote cache                                                           
                                             | To ensure that reference build 
is not overridden by interim build                  |
+| `-Dmaven.build.cache.remote.url=`                          | Url of the 
remote cache (overrides  <remote><url></url></remote>)                          
                                              | To override url of remote cache 
from command line                                  |
+| `-Dmaven.build.cache.remote.server.id=`                    | Id of the 
remote cache server (overrides  <remote id=""></remote>)                        
                                               | To override id of remote cache 
server from command line                            |
 | `-Dmaven.build.cache.failFast=(true/false)`                | Fail on the 
first module which cannot be restored from cache                                
                                             | Remote cache 
setup/tuning/troubleshooting                                          |
 | `-Dmaven.build.cache.baselineUrl=<http url>`               | Location of 
baseline build for comparison                                                   
                                             | Remote cache 
setup/tuning/troubleshooting                                          |
 | `-Dmaven.build.cache.lazyRestore=(true/false)`             | Restore 
artifacts from remote cache lazily                                              
                                                 | Performance optimization     
                                                      |
diff --git 
a/src/test/java/org/apache/maven/buildcache/its/RemoteCacheDavTest.java 
b/src/test/java/org/apache/maven/buildcache/its/RemoteCacheDavTest.java
index 595be62..059741b 100644
--- a/src/test/java/org/apache/maven/buildcache/its/RemoteCacheDavTest.java
+++ b/src/test/java/org/apache/maven/buildcache/its/RemoteCacheDavTest.java
@@ -62,6 +62,8 @@ import org.testcontainers.junit.jupiter.Container;
 import org.testcontainers.junit.jupiter.Testcontainers;
 import org.testcontainers.utility.DockerImageName;
 
+import static 
org.apache.maven.buildcache.xml.CacheConfigImpl.REMOTE_SERVER_ID_PROPERTY_NAME;
+import static 
org.apache.maven.buildcache.xml.CacheConfigImpl.REMOTE_URL_PROPERTY_NAME;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -124,20 +126,19 @@ public class RemoteCacheDavTest {
     @AfterEach
     public void cleanup() throws Exception {
 
-        org.testcontainers.containers.Container.ExecResult result =
-                dav.execInContainer("ls", "-lrt", "/var/webdav/public/");
+        org.testcontainers.containers.Container.ExecResult result = 
dav.execInContainer("ls", "-lrt", "/var/webdav");
 
         LOGGER.info("before clean in container result: {}", result);
 
-        result = dav.execInContainer("rm", "-rf", "/var/webdav/public");
+        result = dav.execInContainer("rm", "-rf", "/var/webdav");
 
         LOGGER.info("clean in container result: {}", result);
 
-        result = dav.execInContainer("ls", "-lrt", "/var/webdav/");
+        result = dav.execInContainer("ls", "-lrt", "/var/webdav");
 
         LOGGER.info("after clean in container result: {}", result);
 
-        cleanDirs(localCache, remoteCache.resolve("mbce"));
+        cleanDirs(localCache);
 
         dav.close();
     }
@@ -178,7 +179,7 @@ public class RemoteCacheDavTest {
         assertTrue(hasBuildInfoXml(localCache), () -> error(localCache, 
"local", true));
         assertFalse(hasBuildInfoXml(remoteCache), () -> error(remoteCache, 
"remote", false));
 
-        cleanDirs(localCache, remoteCache.resolve("mbce"));
+        cleanDirs(localCache);
 
         verifier.getCliOptions().clear();
         verifier.addCliOption("--settings=" + settings);
@@ -205,6 +206,40 @@ public class RemoteCacheDavTest {
 
         assertTrue(hasBuildInfoXml(localCache), () -> error(localCache, 
"local", true));
         assertTrue(hasBuildInfoXml(remoteCache), () -> error(remoteCache, 
"remote", true));
+
+        // replace url and server id with a bad one to be sure cli property is 
used
+        substitute(
+                basedir.resolve(".mvn/maven-build-cache-config.xml"),
+                "url",
+                "http://foo.com";,
+                "id",
+                "foo",
+                "location",
+                localCache.toString());
+
+        cleanDirs(localCache);
+        try {
+            // depending on uid used for execution but can be different from 
the one using docker and so different file
+            // permissions..
+            dav.execInContainer("rm", "-rf", "/var/webdav/public/*");
+        } catch (InterruptedException e) {
+            throw new IOException("cannot delete remote cache");
+        }
+
+        verifier.getCliOptions().clear();
+        verifier.addCliOption("--settings=" + settings);
+        verifier.addCliOption("-X");
+        verifier.addCliOption("-D" + HTTP_TRANSPORT_PRIORITY + "=" + 
("wagon".equals(transport) ? "0" : "10"));
+        verifier.addCliOption("-D" + WAGON_TRANSPORT_PRIORITY + "=" + 
("wagon".equals(transport) ? "10" : "0"));
+        verifier.addCliOption("-D" + MAVEN_BUILD_CACHE_REMOTE_SAVE_ENABLED + 
"=true");
+        verifier.setSystemProperty(REMOTE_URL_PROPERTY_NAME, url);
+        verifier.setSystemProperty(REMOTE_SERVER_ID_PROPERTY_NAME, REPO_ID);
+        verifier.setLogFileName("../log-4.txt");
+        verifier.executeGoals(Arrays.asList("clean", "install"));
+        verifier.verifyErrorFreeLog();
+
+        assertTrue(hasBuildInfoXml(localCache), () -> error(localCache, 
"local", true));
+        assertTrue(hasBuildInfoXml(remoteCache), () -> error(remoteCache, 
"remote", true));
     }
 
     private boolean hasBuildInfoXml(Path cache) throws IOException {
@@ -229,6 +264,7 @@ public class RemoteCacheDavTest {
         for (int i = 0; i < strings.length / 2; i++) {
             str = str.replaceAll(Pattern.quote("${" + strings[i * 2] + "}"), 
strings[i * 2 + 1]);
         }
+        Files.deleteIfExists(path);
         Files.write(path, str.getBytes(StandardCharsets.UTF_8));
     }
 

Reply via email to