Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[FIXED JENKINS-11792] Stop parsing if user canceled the build.
  • Loading branch information
uhafner committed Nov 22, 2011
1 parent f62bcf8 commit a2cb7b406603f8ae30b94913ffb9d093ec650406
@@ -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;
@@ -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();
}
}

@@ -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.");
}
}

@@ -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()) {
@@ -77,6 +82,9 @@ protected void findAnnotations(final String content, final List<FileAnnotation>
detectPackageName(warning);
warnings.add(warning);
}
if (Thread.interrupted()) {
throw new ParsingCanceledException();
}
}
}

@@ -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;

0 comments on commit a2cb7b4

Please sign in to comment.