Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[FIXED JENKINS-11792] Stop parsing if user canceled the build.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Nov 22, 2011
1 parent f62bcf8 commit a2cb7b4
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 19 deletions.
42 changes: 27 additions & 15 deletions src/main/java/hudson/plugins/warnings/WarningsPublisher.java
Expand Up @@ -18,6 +18,7 @@
import hudson.plugins.analysis.util.model.FileAnnotation;
import hudson.plugins.warnings.parser.FileWarningsParser;
import hudson.plugins.warnings.parser.ParserRegistry;
import hudson.plugins.warnings.parser.ParsingCanceledException;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -230,30 +231,41 @@ public Action getProjectAction(final AbstractProject<?, ?> project) {

/** {@inheritDoc} */
@Override
public BuildResult perform(final AbstractBuild<?, ?> build, final PluginLogger logger) throws InterruptedException, IOException {
if (getConsoleLogParsers().isEmpty() && getParserConfigurations().isEmpty()) {
throw new IOException("Error: No warning parsers defined.");
}
public BuildResult perform(final AbstractBuild<?, ?> build, final PluginLogger logger)
throws InterruptedException, IOException {
try {
if (getConsoleLogParsers().isEmpty() && getParserConfigurations().isEmpty()) {
throw new IOException("Error: No warning parsers defined.");
}

ParserResult project = parseFiles(build, logger);
returnIfCanceled();
ParserResult project = parseFiles(build, logger);
returnIfCanceled();

parseConsoleLog(build, logger, project);
parseConsoleLog(build, logger, project);

project = build.getWorkspace().act(new AnnotationsClassifier(project, getDefaultEncoding()));
for (FileAnnotation annotation : project.getAnnotations()) {
annotation.setPathName(build.getWorkspace().getRemote());
}
project = build.getWorkspace().act(
new AnnotationsClassifier(project, getDefaultEncoding()));
for (FileAnnotation annotation : project.getAnnotations()) {
annotation.setPathName(build.getWorkspace().getRemote());
}

WarningsResult result = new WarningsResult(build, getDefaultEncoding(), project);
build.getActions().add(new WarningsResultAction(build, this, result));
WarningsResult result = new WarningsResult(build, getDefaultEncoding(), project);
build.getActions().add(new WarningsResultAction(build, this, result));

return result;
}
catch (ParsingCanceledException exception) {
throw createInterruptedException();
}
}

return result;
private InterruptedException createInterruptedException() {
return new InterruptedException("Canceling parsing since build has been aborted.");
}

private void returnIfCanceled() throws InterruptedException {
if (Thread.interrupted()) {
throw new InterruptedException("Canceling parsing since build has been aborted.");
throw createInterruptedException();
}
}

Expand Down
@@ -0,0 +1,20 @@
package hudson.plugins.warnings.parser;

import java.io.IOException;

/**
* Indicates that parsing has been canceled due to a user initiated interrupt.
*
* @author Ulli Hafner
*/
public class ParsingCanceledException extends IOException {
private static final long serialVersionUID = 3341274949787014225L;

/**
* Creates a new instance of {@link ParsingCanceledException}.
*/
public ParsingCanceledException() {
super("Canceling parsing since build has been aborted.");
}
}

16 changes: 12 additions & 4 deletions src/main/java/hudson/plugins/warnings/parser/RegexpParser.java
Expand Up @@ -63,12 +63,17 @@ public RegexpParser(final String warningPattern, final boolean useMultiLine, fin
}

/**
* Parses the specified string content and creates annotations for each found warning.
* Parses the specified string content and creates annotations for each
* found warning.
*
* @param content the content to scan
* @param warnings the found annotations
* @param content
* the content to scan
* @param warnings
* the found annotations
* @throws ParsingCanceledException
* indicates that the user canceled the operation
*/
protected void findAnnotations(final String content, final List<FileAnnotation> warnings) {
protected void findAnnotations(final String content, final List<FileAnnotation> warnings) throws ParsingCanceledException {
Matcher matcher = pattern.matcher(content);

while (matcher.find()) {
Expand All @@ -77,6 +82,9 @@ protected void findAnnotations(final String content, final List<FileAnnotation>
detectPackageName(warning);
warnings.add(warning);
}
if (Thread.interrupted()) {
throw new ParsingCanceledException();
}
}
}

Expand Down
Expand Up @@ -31,6 +31,8 @@ public interface WarningsParser extends ExtensionPoint {
* @return the collection of annotations
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws ParsingCanceledException // NOCHECKSTYLE
* Signals that the user canceled this operation
*/
Collection<FileAnnotation> parse(final Reader reader) throws IOException;

Expand Down

0 comments on commit a2cb7b4

Please sign in to comment.