Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-5764] maven incremental builds leave modules unbuilt
upon failure
Originally-Committed-As: f4233876cdab86c7d19ecf3fcd8f0c530d39117f
  • Loading branch information
kutzi committed Mar 25, 2011
1 parent e231553 commit 3faaa85
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 6 deletions.
34 changes: 32 additions & 2 deletions src/main/java/hudson/maven/MavenBuild.java
Expand Up @@ -525,8 +525,10 @@ protected void close() {
}

if(hasntStartedYet()) {
// Mark the build as aborted. This method is used when the aggregated build
// failed before it didn't even get to this module.
// Mark the build as not_built. This method is used when the aggregated build
// failed before it didn't even get to this module
// OR if the aggregated build is an incremental one and this
// module needn't be build.
run(new Runner() {
public Result run(BuildListener listener) {
listener.getLogger().println(Messages.MavenBuild_FailedEarlier());
Expand All @@ -539,6 +541,34 @@ public void post(BuildListener listener) {
public void cleanUp(BuildListener listener) {
}
});


// record modules which have not been build though they should have - i.e. because they
// have SCM changes.
// see JENKINS-5764
if (getParentBuild().getParent().isIncrementalBuild() && getParentBuild().getResult() == Result.FAILURE) {
UnbuiltModuleAction action = getParentBuild().getAction(UnbuiltModuleAction.class);
if (action == null) {
action = new UnbuiltModuleAction();
getParentBuild().getActions().add(action);
}
action.addUnbuiltModule(getParent().getModuleName());
}
} else {
// mark that this module has been built now, if it has previously been remembered as unbuilt
// JENKINS-5764
MavenModuleSetBuild previousParentBuild = getParentBuild().getPreviousBuild();
if (previousParentBuild != null) {
UnbuiltModuleAction unbuiltModuleAction = previousParentBuild.getAction(UnbuiltModuleAction.class);
if (unbuiltModuleAction != null) {
unbuiltModuleAction.removeUnbuildModule(getParent().getModuleName());
try {
previousParentBuild.save();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}

Expand Down
38 changes: 34 additions & 4 deletions src/main/java/hudson/maven/MavenModuleSetBuild.java 100755 → 100644
Expand Up @@ -604,11 +604,15 @@ protected Result doRun(final BuildListener listener) throws Exception {
parsePoms(listener, logger, envVars, mvn, mavenVersion); // #5428 : do pre-build *before* parsing pom
SplittableBuildListener slistener = new SplittableBuildListener(listener);
proxies = new HashMap<ModuleName, ProxyImpl2>();
List<String> changedModules = new ArrayList<String>();
List<ModuleName> changedModules = new ArrayList<ModuleName>();

if (project.isIncrementalBuild() && !getChangeSet().isEmptySet()) {
changedModules.addAll(getUnbuildModulesSinceLastSuccessfulBuild());
}

for (MavenModule m : project.sortedActiveModules) {
MavenBuild mb = m.newBuild();
// HUDSON-8418
// JENKINS-8418
mb.setBuiltOnStr( getBuiltOnStr() );
// Check if incrementalBuild is selected and that there are changes -
// we act as if incrementalBuild is not set if there are no changes.
Expand All @@ -620,7 +624,7 @@ protected Result doRun(final BuildListener listener) throws Exception {
if ((mb.getPreviousBuiltBuild() == null) ||
(!getChangeSetFor(m).isEmpty())
|| (mb.getPreviousBuiltBuild().getResult().isWorseThan(Result.SUCCESS))) {
changedModules.add(m.getModuleName().toString());
changedModules.add(m.getModuleName());
}
}

Expand Down Expand Up @@ -758,14 +762,40 @@ protected Result doRun(final BuildListener listener) throws Exception {
return Result.FAILURE;
} catch (RuntimeException e) {
// bug in the code.
e.printStackTrace(listener.error("Processing failed due to a bug in the code. Please report this to jenkins-users@googlegroups.com"));
e.printStackTrace(listener.error("Processing failed due to a bug in the code. Please report this to jenkinsci-users@googlegroups.com"));
logger.println("project="+project);
logger.println("project.getModules()="+project.getModules());
logger.println("project.getRootModule()="+project.getRootModule());
throw e;
}
}

/**
* Returns the modules which have not been build since the last successful aggregator build
* though they should be because they had SCM changes.
* This can happen when the aggregator build fails before it reaches the module.
*
* See JENKINS-5764
*/
private Collection<ModuleName> getUnbuildModulesSinceLastSuccessfulBuild() {
Collection<ModuleName> unbuiltModules = new ArrayList<ModuleName>();
MavenModuleSetBuild previousSuccessfulBuild = getPreviousSuccessfulBuild();
if (previousSuccessfulBuild != null) {
MavenModuleSetBuild previousBuild = previousSuccessfulBuild;
do {
UnbuiltModuleAction unbuiltModuleAction = previousBuild.getAction(UnbuiltModuleAction.class);
if (unbuiltModuleAction != null) {
for (ModuleName name : unbuiltModuleAction.getUnbuildModules()) {
unbuiltModules.add(name);
}
}

previousBuild = previousBuild.getNextBuild();
} while (previousBuild != null && previousBuild != MavenModuleSetBuild.this);
}
return unbuiltModules;
}

private void parsePoms(BuildListener listener, PrintStream logger, EnvVars envVars, MavenInstallation mvn, String mavenVersion) throws IOException, InterruptedException {
logger.println("Parsing POMs");

Expand Down
54 changes: 54 additions & 0 deletions src/main/java/hudson/maven/UnbuiltModuleAction.java
@@ -0,0 +1,54 @@
package hudson.maven;

import hudson.model.Action;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
* Action which remembers all module which have not been built since the last successful build
* though they should have been, because they have SCM changes since then.
*
* See JENKINS-5764
*
* @author kutzi
*/
public class UnbuiltModuleAction implements Action {

private List<ModuleName> moduleNames = new ArrayList<ModuleName>();

public void addUnbuiltModule(ModuleName moduleName) {
this.moduleNames.add(moduleName);
}

public boolean removeUnbuildModule(ModuleName moduleName) {
return this.moduleNames.remove(moduleName);
}

public Collection<ModuleName> getUnbuildModules() {
return this.moduleNames;
}

/**
* {@inheritDoc}
*/
public String getIconFileName() {
return null;
}

/**
* {@inheritDoc}
*/
public String getDisplayName() {
return "Unbuilt Modules";
}

/**
* {@inheritDoc}
*/
public String getUrlName() {
return null;
}

}

0 comments on commit 3faaa85

Please sign in to comment.