Skip to content

Commit

Permalink
Merge pull request #39 from mixalturek/master
Browse files Browse the repository at this point in the history
[JENKINS-22303] Should have option to not care about build failure status
  • Loading branch information
mixalturek committed Mar 30, 2014
2 parents 4f30bbf + 38eedb0 commit 2d99566
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/main/java/hudson/plugins/sloccount/SloccountPublisher.java
Expand Up @@ -46,13 +46,17 @@ public class SloccountPublisher extends Recorder implements Serializable {
*/
private final int numBuildsInGraph;

@DataBoundConstructor
/** Try to process the report files even if the build state is marked as failed. */
private final boolean ignoreBuildFailure;

@DataBoundConstructor
public SloccountPublisher(String pattern, String encoding,
int numBuildsInGraph){
int numBuildsInGraph, boolean ignoreBuildFailure){
super();
this.pattern = pattern;
this.encoding = encoding;
this.numBuildsInGraph = numBuildsInGraph;
this.ignoreBuildFailure = ignoreBuildFailure;
}

@Override
Expand All @@ -69,8 +73,13 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
PrintStream logger = listener.getLogger();

if (!canContinue(build.getResult())) {
logger.println("[SLOCCount] Skipping results publication since the build is not successful");
return true;
if(ignoreBuildFailure) {
logger.println("[SLOCCount] Trying to process the report files even if the build is not successful");
// Continue as usual
} else {
logger.println("[SLOCCount] Skipping results publication since the build is not successful");
return true;
}
}

SloccountParser parser = new SloccountParser(this.getRealEncoding(), this.getRealPattern(), logger);
Expand All @@ -89,6 +98,7 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
if (report.getSourceFiles().size() == 0) {
logger.format("[SLOCCount] No file is matching the input pattern: %s%n",
getRealPattern());
return false;
}

SloccountResult result = new SloccountResult(report.getStatistics(),
Expand All @@ -106,6 +116,7 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
return false;
}

logger.format("[SLOCCount] Report successfully processed and all data stored%n");
return true;
}

Expand Down Expand Up @@ -180,4 +191,8 @@ public String getEncoding() {
public int getNumBuildsInGraph() {
return numBuildsInGraph;
}

public boolean isIgnoreBuildFailure() {
return ignoreBuildFailure;
}
}
Expand Up @@ -12,5 +12,10 @@
<f:entry title="${%Builds in graph}" description="${%description.numBuildsInGraph}">
<f:textbox name="numBuildsInGraph" value="${instance.numBuildsInGraph}"/>
</f:entry>

<f:entry>
<f:checkbox name="ignoreBuildFailure" checked="${instance.ignoreBuildFailure}"/>
<label for="ignoreBuildFailure">${%Try to process the report files even if the build is not successful}</label>
</f:entry>
</f:advanced>
</j:jelly>

0 comments on commit 2d99566

Please sign in to comment.