Skip to content
Permalink
Browse files

[FIXED JENKINS-18918] From plugins we must use target/ not target/cla…

…sses/ 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.)
  • Loading branch information...
jglick committed Jul 24, 2013
1 parent 68f1fa2 commit 2152cf478e26e01b90be8c818cfe3bb628b32263
@@ -70,6 +70,9 @@
<li class='major bug'>
Since 1.517, Maven projects using Maven 2 could not build projects using extensions depending on Apache Commons Codec.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-18178">issue 18178</a>)
<li class=bug>
Test harness was packing copies of Maven into plugin archives under some conditions.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-18918">issue 18918</a>)
<li class=bug>
Provided maven settings.xml in maven builder is lost.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-15976">issue 15976</a>)
@@ -560,11 +560,11 @@ protected MavenInstallation configureMaven31() throws Exception {
*/
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 @@ protected MavenInstallation configureDefaultMaven(String mavenVersion, int maven

// 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;
}
@@ -622,13 +622,10 @@ public UserRealm configureUserRealm() {
*/
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 UserRealm configureUserRealm() {

// 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;
}

0 comments on commit 2152cf4

Please sign in to comment.
You can’t perform that action at this time.