Skip to content
Permalink
Browse files

Merge pull request #8 from mrebasti/jenkins-13926

[FIXED JENKINS-13926] Don't save per-job MAVEN_OPTS if they're the same as the global ones
  • Loading branch information
kutzi committed Nov 5, 2013
2 parents e1e7d22 + 09fb4a5 commit 05b809ee431140e9a5a797c8f454fb16ffcb1b76
Showing with 47 additions and 5 deletions.
  1. +16 −5 src/main/java/hudson/maven/MavenModuleSet.java
  2. +31 −0 src/test/java/hudson/maven/MavenOptsTest.java
@@ -1041,24 +1041,35 @@ public boolean isNonRecursive() {
*/
public String getMavenOpts() {
if ((mavenOpts!=null) && (mavenOpts.trim().length()>0)) {
return mavenOpts.replaceAll("[\t\r\n]+"," ");
return getFormattedMavenOpts(mavenOpts);
}
else {
String globalOpts = getDescriptor().getGlobalMavenOpts();
if (globalOpts!=null) {
return globalOpts.replaceAll("[\t\r\n]+"," ");
return getFormattedMavenOpts(globalOpts);
}
else {
return globalOpts;
}
}
}

private String getFormattedMavenOpts(String mavenOpts) {
return mavenOpts == null? null: mavenOpts.replaceAll("[\t\r\n]+"," ");
}

/**
* Set mavenOpts.
* Set mavenOpts. If the new mavenOpts are equals to the global mavenOpts,
* job mavenOpts are set to null.
*/
public void setMavenOpts(String mavenOpts) {
this.mavenOpts = mavenOpts;
String globalMavenOpts = getFormattedMavenOpts(getDescriptor().getGlobalMavenOpts());

if (mavenOpts != null && !getFormattedMavenOpts(mavenOpts).equals(globalMavenOpts)) {
this.mavenOpts = mavenOpts;
} else {
this.mavenOpts = null;
}
}

/**
@@ -1144,7 +1155,7 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
if(rootPOM!=null && rootPOM.equals("pom.xml")) rootPOM=null; // normalization

goals = Util.fixEmpty(req.getParameter("goals").trim());
mavenOpts = Util.fixEmpty(req.getParameter("mavenOpts").trim());
setMavenOpts(Util.fixEmpty(req.getParameter("mavenOpts").trim()));
settings = SettingsProvider.parseSettingsProvider(req);
globalSettings = GlobalSettingsProvider.parseSettingsProvider(req);

@@ -122,6 +122,37 @@ public void testEnvironmentVariableExpansion() throws Exception {

assertLogContains("[hudson.mavenOpt.test=foo]", m.getLastBuild());
}

@Bug(13926)
public void testMustnt_store_global_maven_opts_in_job_maven_opts() throws Exception {
final String firstGlobalMavenOpts = "first maven opts";
final String secondGlobalMavenOpts = "second maven opts";
final String jobMavenOpts = "job maven opts";

configureDefaultMaven();
MavenModuleSet m = createMavenProject();

assertNull(m.getMavenOpts());

d.setGlobalMavenOpts(firstGlobalMavenOpts);
assertEquals(firstGlobalMavenOpts, m.getMavenOpts());

m.setMavenOpts(firstGlobalMavenOpts);
assertEquals(firstGlobalMavenOpts, m.getMavenOpts());

d.setGlobalMavenOpts(secondGlobalMavenOpts);
assertEquals(secondGlobalMavenOpts, m.getMavenOpts());

m.setMavenOpts(jobMavenOpts);
assertEquals(jobMavenOpts, m.getMavenOpts());

d.setGlobalMavenOpts(firstGlobalMavenOpts);
m.setMavenOpts(firstGlobalMavenOpts);
assertEquals(firstGlobalMavenOpts, m.getMavenOpts());

d.setGlobalMavenOpts(secondGlobalMavenOpts);
assertEquals(secondGlobalMavenOpts, m.getMavenOpts());
}

}

0 comments on commit 05b809e

Please sign in to comment.
You can’t perform that action at this time.