提交 c8094046 编写于 作者: A abayer

[FIXED HUDSON-2932] Maven projects now properly fall back through...

[FIXED HUDSON-2932] Maven projects now properly fall back through project-defined MAVEN_OPTS to globally-defined MAVEN_OPTS to executor environment variable MAVEN_OPTS - also added globally-defined MAVEN_OPTS and related changes

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@24652 71c3de6d-444a-0410-be80-ed276b4c234a
上级 9b19525e
......@@ -23,6 +23,7 @@
*/
package hudson.model;
import hudson.ExtensionList;
import org.kohsuke.stapler.StaplerRequest;
/**
......@@ -87,4 +88,12 @@ public abstract class TopLevelItemDescriptor extends Descriptor<TopLevelItem> {
* Creates a new {@link Job}.
*/
public abstract TopLevelItem newInstance(String name);
/**
* Returns all the registered {@link TopLevelItem} descriptors.
*/
public static ExtensionList<TopLevelItemDescriptor> all() {
return Hudson.getInstance().getExtensionList(TopLevelItemDescriptor.class);
}
}
......@@ -159,6 +159,7 @@ THE SOFTWARE.
<local:globalConfig className="hudson.tasks.Publisher" />
<local:globalConfig className="hudson.model.JobPropertyDescriptor" />
<local:globalConfig className="hudson.model.PageDecorator" />
<local:globalConfig className="hudson.model.TopLevelItemDescriptor" />
<j:if test="${!empty(h.getCloudDescriptors())}">
<f:section title="${%Cloud}">
......
......@@ -615,9 +615,23 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
/**
* Possibly null, whitespace-separated (including TAB, NL, etc) VM options
* to be used to launch Maven process.
*
* If mavenOpts is null or empty, we'll return the globally-defined MAVEN_OPTS.
*/
public String getMavenOpts() {
return mavenOpts;
if ((mavenOpts!=null) && (mavenOpts.trim().length()>0)) {
return mavenOpts;
}
else {
return DESCRIPTOR.getGlobalMavenOpts();
}
}
/**
* Set mavenOpts.
*/
public void setMavenOpts(String mavenOpts) {
this.mavenOpts = mavenOpts;
}
/**
......@@ -753,6 +767,20 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();
public static final class DescriptorImpl extends AbstractProjectDescriptor {
/**
* Globally-defined MAVEN_OPTS.
*/
private String globalMavenOpts;
public String getGlobalMavenOpts() {
return globalMavenOpts;
}
public void setGlobalMavenOpts(String globalMavenOpts) {
this.globalMavenOpts = globalMavenOpts;
save();
}
public String getDisplayName() {
return Messages.MavenModuleSet_DiplayName();
}
......@@ -765,6 +793,14 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
return Hudson.getInstance().getDescriptorByType(Maven.DescriptorImpl.class);
}
@Override
public boolean configure( StaplerRequest req, JSONObject o ) {
globalMavenOpts = Util.fixEmptyAndTrim(o.getString("globalMavenOpts"));
save();
return true;
}
@Override
public boolean isApplicable(Descriptor descriptor) {
return !NOT_APPLICABLE_TYPES.contains(descriptor.clazz);
......
......@@ -263,7 +263,7 @@ final class MavenProcessFactory implements ProcessCache.Factory {
args.add("-agentlib:yjpagent=tracing");
args.addTokenized(getMavenOpts());
args.add("-cp");
args.add(
(isMaster? Which.jarFile(Main.class).getAbsolutePath():slaveRoot.child("maven-agent.jar").getRemote())+
......@@ -300,7 +300,27 @@ final class MavenProcessFactory implements ProcessCache.Factory {
}
public String getMavenOpts() {
return envVars.expand(mms.getMavenOpts());
String mavenOpts = mms.getMavenOpts();
if ((mavenOpts==null) || (mavenOpts.trim().length()==0)) {
Node n = getCurrentNode();
if (n!=null) {
try {
String localMavenOpts = n.toComputer().getEnvironment().get("MAVEN_OPTS");
if ((localMavenOpts!=null) && (localMavenOpts.trim().length()>0)) {
mavenOpts = localMavenOpts;
}
} catch (IOException e) {
} catch (InterruptedException e) {
// Don't do anything - this just means the slave isn't running, so we
// don't want to use its MAVEN_OPTS anyway.
}
}
}
return envVars.expand(mavenOpts);
}
public MavenInstallation getMavenInstallation(TaskListener log) throws IOException, InterruptedException {
......
......@@ -112,6 +112,10 @@ public final class ProcessCache {
this.systemProperties = channel.call(new GetSystemProperties());
}
public String getMavenOpts() {
return mavenOpts;
}
boolean matches(String mavenOpts,MavenInstallation installation, JDK jdk) {
return Util.fixNull(this.mavenOpts).equals(Util.fixNull(mavenOpts))
&& this.installation==installation
......
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<!--
Config page
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:section title="Maven Project Configuration">
<f:entry title="Global MAVEN_OPTS" help="/plugin/maven-plugin/maven-opts.html">
<f:expandableTextbox name="globalMavenOpts" value="${it.globalMavenOpts}" />
</f:entry>
</f:section>
</j:jelly>
\ No newline at end of file
package hudson.maven;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
import hudson.EnvVars;
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.util.NullStream;
import java.io.IOException;
import java.io.PrintWriter;
/**
* @author Andrew Bayer
*/
public class MavenOptsTest extends HudsonTestCase {
public void testEnvMavenOptsNoneInProject() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-opts-echo.zip")));
m.setGoals("validate");
m.setAssignedLabel(createSlave(null, new EnvVars("MAVEN_OPTS", "-Dhudson.mavenOpt.test=foo")).getSelfLabel());
assertBuildStatusSuccess(m.scheduleBuild2(0).get());
assertLogContains("[hudson.mavenOpt.test=foo]", m.getLastBuild());
}
public void testEnvMavenOptsOverriddenByProject() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-opts-echo.zip")));
m.setGoals("validate");
m.setMavenOpts("-Dhudson.mavenOpt.test=bar");
m.setAssignedLabel(createSlave(null, new EnvVars("MAVEN_OPTS", "-Dhudson.mavenOpt.test=foo")).getSelfLabel());
assertBuildStatusSuccess(m.scheduleBuild2(0).get());
assertLogContains("[hudson.mavenOpt.test=bar]", m.getLastBuild());
}
public void testEnvAndGlobalMavenOptsOverriddenByProject() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-opts-echo.zip")));
m.setGoals("validate");
m.DESCRIPTOR.setGlobalMavenOpts("-Dhudson.mavenOpt.test=bar");
m.setAssignedLabel(createSlave(null, new EnvVars("MAVEN_OPTS", "-Dhudson.mavenOpt.test=foo")).getSelfLabel());
m.setMavenOpts("-Dhudson.mavenOpt.test=baz");
assertBuildStatusSuccess(m.scheduleBuild2(0).get());
assertLogContains("[hudson.mavenOpt.test=baz]", m.getLastBuild());
}
public void testGlobalMavenOpts() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-opts-echo.zip")));
m.setGoals("validate");
m.DESCRIPTOR.setGlobalMavenOpts("-Dhudson.mavenOpt.test=bar");
assertBuildStatusSuccess(m.scheduleBuild2(0).get());
assertLogContains("[hudson.mavenOpt.test=bar]", m.getLastBuild());
}
public void testGlobalMavenOptsOverridenByProject() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-opts-echo.zip")));
m.setGoals("validate");
m.DESCRIPTOR.setGlobalMavenOpts("-Dhudson.mavenOpt.test=bar");
m.setMavenOpts("-Dhudson.mavenOpt.test=foo");
assertBuildStatusSuccess(m.scheduleBuild2(0).get());
assertLogContains("[hudson.mavenOpt.test=foo]", m.getLastBuild());
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册