提交 34387b2f 编写于 作者: A abayer

Added meetsMavenReqVersion method to Maven.MavenInstallation - generalization...

Added meetsMavenReqVersion method to Maven.MavenInstallation - generalization of logic from isMaven2_1 - tests modified to check whether default MavenInstallation meets required Maven version before using bundled Maven install instead

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@23000 71c3de6d-444a-0410-be80-ed276b4c234a
上级 f2402ec6
......@@ -347,7 +347,13 @@ public class Maven extends Builder {
* Represents a Maven installation in a system.
*/
public static final class MavenInstallation extends ToolInstallation implements EnvironmentSpecific<MavenInstallation>, NodeSpecific<MavenInstallation> {
/**
* Constants for describing Maven versions for comparison.
*/
public static final int MAVEN_20 = 0;
public static final int MAVEN_21 = 1;
/**
* @deprecated since 2009-02-25.
*/
......@@ -386,6 +392,43 @@ public class Maven extends Builder {
return super.getHome();
}
/**
* Compares the version of this Maven installation to the minimum required version specified.
*
* @param launcher
* Represents the node on which we evaluate the path.
* @param mavenReqVersion
* Represents the minimum required Maven version - constants defined above.
*/
public boolean meetsMavenReqVersion(Launcher launcher, int mavenReqVersion) throws IOException, InterruptedException {
String mavenVersion = launcher.getChannel().call(new Callable<String,IOException>() {
public String call() throws IOException {
File[] jars = new File(getHomeDir(),"lib").listFiles();
if(jars!=null) { // be defensive
for (File jar : jars) {
if (jar.getName().endsWith("-uber.jar") && jar.getName().startsWith("maven-")) {
return jar.getName();
}
}
}
return "";
}
});
if (!mavenVersion.equals("")) {
if (mavenReqVersion == MAVEN_20) {
if(mavenVersion.startsWith("maven-2.") || mavenVersion.startsWith("maven-core-2"))
return true;
}
else if (mavenReqVersion == MAVEN_21) {
if(mavenVersion.startsWith("maven-2.") && !mavenVersion.startsWith("maven-2.0"))
return true;
}
}
return false;
}
/**
* Is this Maven 2.1.x or later?
*
......@@ -393,7 +436,9 @@ public class Maven extends Builder {
* Represents the node on which we evaluate the path.
*/
public boolean isMaven2_1(Launcher launcher) throws IOException, InterruptedException {
return launcher.getChannel().call(new Callable<Boolean,IOException>() {
return meetsMavenReqVersion(launcher, MAVEN_21);
}
/* return launcher.getChannel().call(new Callable<Boolean,IOException>() {
public Boolean call() throws IOException {
File[] jars = new File(getHomeDir(),"lib").listFiles();
if(jars!=null) // be defensive
......@@ -402,8 +447,8 @@ public class Maven extends Builder {
return true;
return false;
}
});
}
});
} */
/**
* Gets the executable path of this maven on the given target system.
......@@ -552,4 +597,5 @@ public class Maven extends Builder {
*/
MavenInstallation inferMavenInstallation();
}
}
......@@ -374,19 +374,21 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
* Returns the older default Maven, while still allowing specification of other bundled Mavens.
*/
protected MavenInstallation configureDefaultMaven() throws Exception {
return configureDefaultMaven("maven-2.0.7");
return configureDefaultMaven("maven-2.0.7", MavenInstallation.MAVEN_20);
}
/**
* Locates Maven2 and configure that as the only Maven in the system.
*/
protected MavenInstallation configureDefaultMaven(String mavenVersion) throws Exception {
// first if we are running inside Maven, pick that Maven.
protected 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..
String home = System.getProperty("maven.home");
if(home!=null) {
MavenInstallation mavenInstallation = new MavenInstallation("default",home, NO_PROPERTIES);
hudson.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(mavenInstallation);
return mavenInstallation;
if (mavenInstallation.meetsMavenReqVersion(createLocalLauncher(), mavenReqVersion)) {
hudson.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(mavenInstallation);
return mavenInstallation;
}
}
// otherwise extract the copy we have.
......
......@@ -10,6 +10,7 @@ import org.jvnet.hudson.test.ExtractChangeLogSet;
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.tasks.Maven.MavenInstallation;
import java.io.IOException;
import java.util.List;
......@@ -33,7 +34,7 @@ public class MavenMultiModuleTest extends HudsonTestCase {
}
public void testIncrementalMultiModMaven() throws Exception {
configureDefaultMaven("apache-maven-2.2.1");
configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21);
MavenModuleSet m = createMavenProject();
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource("maven-multimod.zip"),
......@@ -69,7 +70,7 @@ public class MavenMultiModuleTest extends HudsonTestCase {
* enabled and a new module is added.
*/
public void testNewModMultiModMaven() throws Exception {
configureDefaultMaven("apache-maven-2.2.1");
configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21);
MavenModuleSet m = createMavenProject();
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource("maven-multimod.zip"),
......@@ -85,7 +86,7 @@ public class MavenMultiModuleTest extends HudsonTestCase {
*/
@Bug(4491)
public void testMultiModMavenNonRecursiveParsing() throws Exception {
configureDefaultMaven("apache-maven-2.2.1");
configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21);
MavenModuleSet m = createMavenProject();
m.setGoals("clean install -N");
m.getReporters().add(new TestReporter());
......@@ -120,7 +121,7 @@ public class MavenMultiModuleTest extends HudsonTestCase {
*/
@Bug(4152)
public void testIncrementalMultiModWithErrorsMaven() throws Exception {
configureDefaultMaven("apache-maven-2.2.1");
configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21);
MavenModuleSet m = createMavenProject();
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource("maven-multimod-incr.zip"),
......@@ -160,7 +161,7 @@ public class MavenMultiModuleTest extends HudsonTestCase {
*/
@Bug(4378)
public void testMultiModWithTestFailuresMaven() throws Exception {
configureDefaultMaven("apache-maven-2.2.1");
configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21);
MavenModuleSet m = createMavenProject();
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimod-incr.zip")));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册