From f4233876cdab86c7d19ecf3fcd8f0c530d39117f Mon Sep 17 00:00:00 2001 From: Christoph Kutzinski Date: Fri, 25 Mar 2011 15:50:10 +0100 Subject: [PATCH] [FIXED JENKINS-5764] maven incremental builds leave modules unbuilt upon failure --- .../main/java/hudson/maven/MavenBuild.java | 34 +++++++++++- .../hudson/maven/MavenModuleSetBuild.java | 38 +++++++++++-- .../hudson/maven/UnbuiltModuleAction.java | 54 +++++++++++++++++++ 3 files changed, 120 insertions(+), 6 deletions(-) mode change 100755 => 100644 maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java create mode 100644 maven-plugin/src/main/java/hudson/maven/UnbuiltModuleAction.java diff --git a/maven-plugin/src/main/java/hudson/maven/MavenBuild.java b/maven-plugin/src/main/java/hudson/maven/MavenBuild.java index e4214f6b44..9c4729c26f 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenBuild.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenBuild.java @@ -525,8 +525,10 @@ public class MavenBuild extends AbstractMavenBuild { } 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()); @@ -539,6 +541,34 @@ public class MavenBuild extends AbstractMavenBuild { 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(); + } + } + } } } diff --git a/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java b/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java old mode 100755 new mode 100644 index 1d1886a34d..2b0eafac0e --- a/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java @@ -604,11 +604,15 @@ public class MavenModuleSetBuild extends AbstractMavenBuild(); - List changedModules = new ArrayList(); + List changedModules = new ArrayList(); + + 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. @@ -620,7 +624,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild moduleNames = new ArrayList(); + + public void addUnbuiltModule(ModuleName moduleName) { + this.moduleNames.add(moduleName); + } + + public boolean removeUnbuildModule(ModuleName moduleName) { + return this.moduleNames.remove(moduleName); + } + + public Collection getUnbuildModules() { + return this.moduleNames; + } + + /** + * {@inheritDoc} + */ + public String getIconFileName() { + return null; + } + + /** + * {@inheritDoc} + */ + public String getDisplayName() { + return "Unbuilt Modules"; + } + + /** + * {@inheritDoc} + */ + public String getUrlName() { + return null; + } + +}