From 2152cf478e26e01b90be8c818cfe3bb628b32263 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 24 Jul 2013 18:16:18 -0400 Subject: [PATCH] [FIXED JENKINS-18918] From plugins we must use target/ not target/classes/ to unpack Maven. Also cleaning up variable names to be less misleading. Note that new File("target") is really a bad idea since we cannot predict the CWD in effect when Maven is run. (From the standard bin/mvn launcher, it seems that it will always be *some* Maven project at least. This may not be true for Maven run embedded from various tools.) But leaving that as is for now, since it is not clear how else we would find the project location. (new File(env.description().getTestClass().getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile() might work but it is pretty hacky.) --- changelog.html | 3 +++ .../org/jvnet/hudson/test/HudsonTestCase.java | 19 +++++++++--------- .../org/jvnet/hudson/test/JenkinsRule.java | 20 ++++++++----------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/changelog.html b/changelog.html index 0bce7d179b..d103743bd1 100644 --- a/changelog.html +++ b/changelog.html @@ -70,6 +70,9 @@ Upcoming changes
  • Since 1.517, Maven projects using Maven 2 could not build projects using extensions depending on Apache Commons Codec. (issue 18178) +
  • + Test harness was packing copies of Maven into plugin archives under some conditions. + (issue 18918)
  • Provided maven settings.xml in maven builder is lost. (issue 15976) diff --git a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java index fab8aaffb1..86f6995a0b 100644 --- a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java +++ b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java @@ -560,11 +560,11 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { */ protected MavenInstallation configureDefaultMaven(String mavenVersion, int mavenReqVersion) throws Exception { // Does it exists in the buildDirectory - i.e. already extracted from previous test? - // see maven-junit-plugin systemProperties: buildDirectory -> ${project.build.directory} (so no reason to be null ;-) ) - String buildDirectory = System.getProperty( "buildDirectory", "./target/classes/" ); - File mavenAlreadyInstalled = new File(buildDirectory, mavenVersion); - if (mavenAlreadyInstalled.exists()) { - MavenInstallation mavenInstallation = new MavenInstallation("default",mavenAlreadyInstalled.getAbsolutePath(), NO_PROPERTIES); + // defined in jenkins-test-harness POM, but not plugins; TODO should not use relative paths as we do not know what CWD is + File buildDirectory = new File(System.getProperty("buildDirectory", "target")); + File mvnHome = new File(buildDirectory, mavenVersion); + if (mvnHome.exists()) { + MavenInstallation mavenInstallation = new MavenInstallation("default", mvnHome.getAbsolutePath(), NO_PROPERTIES); jenkins.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(mavenInstallation); return mavenInstallation; } @@ -581,18 +581,17 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { // otherwise extract the copy we have. // this happens when a test is invoked from an IDE, for example. - LOGGER.warning("Extracting a copy of Maven bundled in the test harness. " + + LOGGER.warning("Extracting a copy of Maven bundled in the test harness into " + mvnHome + ". " + "To avoid a performance hit, set the system property 'maven.home' to point to a Maven2 installation."); FilePath mvn = jenkins.getRootPath().createTempFile("maven", "zip"); mvn.copyFrom(HudsonTestCase.class.getClassLoader().getResource(mavenVersion + "-bin.zip")); - File mvnHome = new File(buildDirectory); - mvn.unzip(new FilePath(mvnHome)); + mvn.unzip(new FilePath(buildDirectory)); // TODO: switch to tar that preserves file permissions more easily if(!Functions.isWindows()) - GNUCLibrary.LIBC.chmod(new File(mvnHome,mavenVersion+"/bin/mvn").getPath(),0755); + GNUCLibrary.LIBC.chmod(new File(mvnHome, "bin/mvn").getPath(),0755); MavenInstallation mavenInstallation = new MavenInstallation("default", - new File(mvnHome,mavenVersion).getAbsolutePath(), NO_PROPERTIES); + mvnHome.getAbsolutePath(), NO_PROPERTIES); jenkins.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(mavenInstallation); return mavenInstallation; } diff --git a/test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java b/test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java index 0ef9ac3ed6..3ec3495d32 100644 --- a/test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java +++ b/test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java @@ -622,13 +622,10 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction { */ public Maven.MavenInstallation configureDefaultMaven(String mavenVersion, int mavenReqVersion) throws Exception { // first if we are running inside Maven, pick that Maven, if it meets the criteria we require.. - // does it exists in the buildDirectory see maven-junit-plugin systemProperties - // buildDirectory -> ${project.build.directory} (so no reason to be null ;-) ) - String buildDirectory = System.getProperty( "buildDirectory", "./target/classes/" ); - File mavenAlreadyInstalled = new File(buildDirectory, mavenVersion); - if (mavenAlreadyInstalled.exists()) { - Maven.MavenInstallation - mavenInstallation = new Maven.MavenInstallation("default",mavenAlreadyInstalled.getAbsolutePath(), NO_PROPERTIES); + File buildDirectory = new File(System.getProperty("buildDirectory", "target")); // TODO relative path + File mvnHome = new File(buildDirectory, mavenVersion); + if (mvnHome.exists()) { + Maven.MavenInstallation mavenInstallation = new Maven.MavenInstallation("default", mvnHome.getAbsolutePath(), NO_PROPERTIES); jenkins.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(mavenInstallation); return mavenInstallation; } @@ -645,18 +642,17 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction { // otherwise extract the copy we have. // this happens when a test is invoked from an IDE, for example. - LOGGER.warning("Extracting a copy of Maven bundled in the test harness. " + + LOGGER.warning("Extracting a copy of Maven bundled in the test harness into " + mvnHome + ". " + "To avoid a performance hit, set the system property 'maven.home' to point to a Maven2 installation."); FilePath mvn = jenkins.getRootPath().createTempFile("maven", "zip"); mvn.copyFrom(HudsonTestCase.class.getClassLoader().getResource(mavenVersion + "-bin.zip")); - File mvnHome = new File(buildDirectory);//createTmpDir(); - mvn.unzip(new FilePath(mvnHome)); + mvn.unzip(new FilePath(buildDirectory)); // TODO: switch to tar that preserves file permissions more easily if(!Functions.isWindows()) - GNUCLibrary.LIBC.chmod(new File(mvnHome,mavenVersion+"/bin/mvn").getPath(),0755); + GNUCLibrary.LIBC.chmod(new File(mvnHome, "bin/mvn").getPath(),0755); Maven.MavenInstallation mavenInstallation = new Maven.MavenInstallation("default", - new File(mvnHome,mavenVersion).getAbsolutePath(), NO_PROPERTIES); + mvnHome.getAbsolutePath(), NO_PROPERTIES); jenkins.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(mavenInstallation); return mavenInstallation; }