mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 05:22:22 +00:00
[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.)
This commit is contained in:
1 parent
68f1fa281f
commit
2152cf478e
3 files changed
+20
-22
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user