Skip to content

Commit

Permalink
[FIXED JENKINS-18918] From plugins we must use target/ not target/cla…
Browse files Browse the repository at this point in the history
…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.)
(cherry picked from commit 2152cf4)
  • Loading branch information
jglick authored and olivergondza committed Aug 6, 2013
1 parent 8eb7633 commit 31c302c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -92,6 +92,9 @@ <h3><a name=v1.524>What's new in 1.524</a> <!--=DATE=--></h3>
<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>)
Expand Down
19 changes: 9 additions & 10 deletions test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java
Expand Up @@ -585,11 +585,11 @@ protected MavenInstallation configureMaven3() 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;
}
Expand All @@ -606,18 +606,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;
}
Expand Down
20 changes: 8 additions & 12 deletions test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java
Expand Up @@ -643,13 +643,10 @@ public Maven.MavenInstallation configureMaven3() throws Exception {
*/
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;
}
Expand All @@ -666,18 +663,17 @@ public Maven.MavenInstallation configureDefaultMaven(String mavenVersion, int ma

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

0 comments on commit 31c302c

Please sign in to comment.