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

Commit

Permalink
[FIXED JENKINS-12280] Make all parsers be serializable in order to be
Browse files Browse the repository at this point in the history
available on the slave.
  • Loading branch information
uhafner committed Jan 26, 2012
1 parent e1f36eb commit 87c2191
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/main/java/hudson/plugins/warnings/WarningsPublisher.java
Expand Up @@ -295,8 +295,9 @@ private ParserResult parseFiles(final AbstractBuild<?, ?> build, final PluginLog
String filePattern = configuration.getPattern();
String parserName = configuration.getParserName();
logger.log("Parsing warnings in files '" + filePattern + "' with parser " + parserName);

FilesParser parser = new FilesParser(PLUGIN_NAME, filePattern,
new FileWarningsParser(parserName, getDefaultEncoding(), getIncludePattern(), getExcludePattern()),
new FileWarningsParser(ParserRegistry.getParsers(parserName), getDefaultEncoding(), getIncludePattern(), getExcludePattern()),
shouldDetectModules(), isMavenBuild(build));
ParserResult additionalProject = build.getWorkspace().act(parser);
logger.logLines(additionalProject.getLogMessages());
Expand Down
Expand Up @@ -7,9 +7,7 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Set;

import com.google.common.collect.Sets;
import java.util.List;

/**
* A {@link WarningsParser} that scans files.
Expand All @@ -25,14 +23,14 @@ public class FileWarningsParser implements AnnotationParser {
private final String excludePattern;
/** The parsers to scan the files with. */
@edu.umd.cs.findbugs.annotations.SuppressWarnings("Se")
private final Set<String> parserNames;
private final List<WarningsParser> parsers;
/** The default encoding to be used when reading and parsing files. */
private final String defaultEncoding;

/**
* Creates a new instance of {@link FileWarningsParser}.
*
* @param parserNames
* @param parsers
* the parsers to scan the files with
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
Expand All @@ -41,33 +39,17 @@ public class FileWarningsParser implements AnnotationParser {
* @param excludePattern
* ant file-set pattern of files to exclude from report
*/
public FileWarningsParser(final Set<String> parserNames, final String defaultEncoding, final String includePattern, final String excludePattern) {
this.parserNames = parserNames;
public FileWarningsParser(final List<WarningsParser> parsers, final String defaultEncoding, final String includePattern, final String excludePattern) {
this.parsers = parsers;
this.includePattern = includePattern;
this.excludePattern = excludePattern;
this.defaultEncoding = defaultEncoding;
}

/**
* Creates a new instance of {@link FileWarningsParser}.
*
* @param parserName
* the parser to scan the files with
* @param defaultEncoding
* the default encoding to be used when reading and parsing files
* @param includePattern
* ant file-set pattern of files to include in report
* @param excludePattern
* ant file-set pattern of files to exclude from report
*/
public FileWarningsParser(final String parserName, final String defaultEncoding, final String includePattern, final String excludePattern) {
this(Sets.newHashSet(parserName), defaultEncoding, includePattern, excludePattern);
}

/** {@inheritDoc} */
public Collection<FileAnnotation> parse(final File file, final String moduleName) throws InvocationTargetException {
try {
Collection<FileAnnotation> annotations = new ParserRegistry(ParserRegistry.getParsers(parserNames), defaultEncoding, includePattern, excludePattern).parse(file);
Collection<FileAnnotation> annotations = new ParserRegistry(parsers, defaultEncoding, includePattern, excludePattern).parse(file);
for (FileAnnotation annotation : annotations) {
annotation.setModuleName(moduleName);
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/hudson/plugins/warnings/parser/ParserRegistry.java
Expand Up @@ -75,6 +75,18 @@ private static Set<String> getAllParserNames() {
return parsers;
}

/**
* Returns a list of parsers that match the specified name. Note that the
* mapping of names to parsers is one to many.
*
* @param parserName
* the parser name
* @return a list of parsers, might be modified by the receiver
*/
public static List<WarningsParser> getParsers(final String parserName) {
return getParsers(Collections.singleton(parserName));
}

/**
* Returns a list of parsers that match the specified names. Note that the
* mapping of names to parsers is one to many.
Expand Down
Expand Up @@ -15,6 +15,8 @@
* @author Ulli Hafner
*/
public abstract class RegexpParser implements WarningsParser {
private static final long serialVersionUID = -82635675595933170L;

/** Used to define a false positive warnings that should be excluded after the regular expression scan. */
protected static final Warning FALSE_POSITIVE = new Warning(StringUtils.EMPTY, 0, StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY);
/** Warning classification. */
Expand Down
Expand Up @@ -5,6 +5,7 @@

import java.io.IOException;
import java.io.Reader;
import java.io.Serializable;
import java.util.Collection;

/**
Expand All @@ -20,7 +21,7 @@
*
* @author Ulli Hafner
*/
public interface WarningsParser extends ExtensionPoint {
public interface WarningsParser extends ExtensionPoint, Serializable {
/**
* Parses the specified input stream for compiler warnings and returns the
* found annotations. Note that the implementor of this method must not
Expand Down

0 comments on commit 87c2191

Please sign in to comment.