From 29df1717c941eeefd7734a39ce321216bec6eb46 Mon Sep 17 00:00:00 2001 From: abayer Date: Thu, 20 Aug 2009 15:52:23 +0000 Subject: [PATCH] [FIXED HUDSON-4205] Added support for Use Private Repository option for freestyle Maven steps, including those invoked through m2-extra-steps git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@20969 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/tasks/Maven.java | 29 +++++++++++++++++-- .../resources/hudson/tasks/Maven/config.jelly | 3 ++ .../tasks/EnvVarsInConfigTasksTest.java | 5 ++-- .../src/test/java/hudson/tasks/MavenTest.java | 3 +- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/hudson/tasks/Maven.java b/core/src/main/java/hudson/tasks/Maven.java index bfbe981143..c2ebbafafb 100644 --- a/core/src/main/java/hudson/tasks/Maven.java +++ b/core/src/main/java/hudson/tasks/Maven.java @@ -98,26 +98,49 @@ public class Maven extends Builder { */ public final String properties; + /** + * If true, the build will use its own local Maven repository + * via "-Dmaven.repo.local=...". + *

+ * This would consume additional disk space, but provides isolation with other builds on the same machine, + * such as mixing SNAPSHOTS. Maven also doesn't try to coordinate the concurrent access to Maven repositories + * from multiple Maven process, so this helps there too. + * + * Identical to logic used in maven-plugin. + * + * @since 1.322 + */ + public boolean usePrivateRepository = false; + private final static String MAVEN_1_INSTALLATION_COMMON_FILE = "bin/maven"; private final static String MAVEN_2_INSTALLATION_COMMON_FILE = "bin/mvn"; public Maven(String targets,String name) { - this(targets,name,null,null,null); + this(targets,name,null,null,null,false); } @DataBoundConstructor - public Maven(String targets,String name, String pom, String properties, String jvmOptions) { + public Maven(String targets,String name, String pom, String properties, String jvmOptions, boolean usePrivateRepository) { this.targets = targets; this.mavenName = name; this.pom = Util.fixEmptyAndTrim(pom); this.properties = Util.fixEmptyAndTrim(properties); this.jvmOptions = Util.fixEmptyAndTrim(jvmOptions); + this.usePrivateRepository = usePrivateRepository; } public String getTargets() { return targets; } + public void setUsePrivateRepository(boolean usePrivateRepository) { + this.usePrivateRepository = usePrivateRepository; + } + + public boolean usesPrivateRepository() { + return usePrivateRepository; + } + /** * Gets the Maven to invoke, * or null to invoke the default one. @@ -221,6 +244,8 @@ public class Maven extends Builder { args.add("-f",pom); args.addKeyValuePairs("-D",build.getBuildVariables()); args.addKeyValuePairsFromPropertyString("-D",properties,vr); + if(usesPrivateRepository()) + args.add("-Dmaven.repo.local="+build.getWorkspace().child(".repository")); args.addTokenized(normalizedTarget); if(mi!=null) { diff --git a/core/src/main/resources/hudson/tasks/Maven/config.jelly b/core/src/main/resources/hudson/tasks/Maven/config.jelly index 10f0f974bb..5229ab396c 100644 --- a/core/src/main/resources/hudson/tasks/Maven/config.jelly +++ b/core/src/main/resources/hudson/tasks/Maven/config.jelly @@ -46,5 +46,8 @@ THE SOFTWARE. + + + \ No newline at end of file diff --git a/test/src/test/java/hudson/tasks/EnvVarsInConfigTasksTest.java b/test/src/test/java/hudson/tasks/EnvVarsInConfigTasksTest.java index 2f06417c20..4a42d6f220 100644 --- a/test/src/test/java/hudson/tasks/EnvVarsInConfigTasksTest.java +++ b/test/src/test/java/hudson/tasks/EnvVarsInConfigTasksTest.java @@ -145,8 +145,9 @@ public class EnvVarsInConfigTasksTest extends HudsonTestCase { "/simple-projects.zip"))); project.getBuildersList().add( - new Maven("test", "varMaven", "pom.xml${" - + DUMMY_LOCATION_VARNAME + "}", "", "")); + new Maven("test", "varMaven", "pom.xml${" + + DUMMY_LOCATION_VARNAME + "}", "", "", + false)); // test the regular slave - variable not expanded project.setAssignedLabel(slaveRegular.getSelfLabel()); diff --git a/test/src/test/java/hudson/tasks/MavenTest.java b/test/src/test/java/hudson/tasks/MavenTest.java index 0a857788df..c247f219e0 100644 --- a/test/src/test/java/hudson/tasks/MavenTest.java +++ b/test/src/test/java/hudson/tasks/MavenTest.java @@ -65,7 +65,7 @@ public class MavenTest extends HudsonTestCase { hudson.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(); // reset FreeStyleProject p = createFreeStyleProject(); - p.getBuildersList().add(new Maven("a", null, "b.pom", "c=d", "-e")); + p.getBuildersList().add(new Maven("a", null, "b.pom", "c=d", "-e", true)); WebClient webClient = new WebClient(); HtmlPage page = webClient.getPage(p, "configure"); @@ -80,6 +80,7 @@ public class MavenTest extends HudsonTestCase { assertEquals("b.pom", m.pom); assertEquals("c=d", m.properties); assertEquals("-e", m.jvmOptions); + assertTrue(m.usesPrivateRepository()); } public void testWithNodeProperty() throws Exception { -- GitLab