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.)
Originally-Committed-As: 2152cf478e26e01b90be8c818cfe3bb628b32263
  • Loading branch information
jglick committed Jul 24, 2013
1 parent f7537ac commit 4157033
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
19 changes: 9 additions & 10 deletions test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
20 changes: 8 additions & 12 deletions test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java
Expand Up @@ -622,13 +622,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 @@ -645,18 +642,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 4157033

Please sign in to comment.