Skip to content
Permalink
Browse files

Merge pull request #15 from jglick/JENKINS-16526

[FIXED JENKINS-16526] [FIXED JENKINS-16107] Cache parsers after creation.
  • Loading branch information
uhafner committed Jan 31, 2013
2 parents 6a770de + 33eae66 commit d677b1f5d9f15275884b17cb705c032ac74eae47
@@ -5,14 +5,17 @@
import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.plugins.warnings.parser.AbstractWarningsParser;
import hudson.plugins.warnings.parser.DynamicDocumentParser;
import hudson.plugins.warnings.parser.DynamicParser;
import hudson.plugins.warnings.parser.Warning;
import hudson.util.FormValidation;
import hudson.util.FormValidation.Kind;

import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import javax.annotation.CheckForNull;

import org.apache.commons.lang.StringUtils;
import org.codehaus.groovy.control.CompilationFailedException;
@@ -35,6 +38,7 @@
private String linkName;
/** Trend report name. @since 4.0 */
private String trendName;
private transient @CheckForNull AbstractWarningsParser parser;

/**
* Creates a new instance of {@link GroovyParser}.
@@ -63,6 +67,7 @@ public GroovyParser(final String name, final String regexp, final String script,
this.example = example;
this.linkName = linkName;
this.trendName = trendName;
parser = createParser();
}

/**
@@ -91,7 +96,7 @@ private Object readResolve() {
if (trendName == null) {
trendName = Messages._Warnings_Trend_Name().toString(Locale.ENGLISH);
}

parser = createParser();
return this;
}

@@ -177,6 +182,22 @@ private static boolean containsNewline(final String expression) {
return StringUtils.contains(expression, "\\n");
}

private @CheckForNull AbstractWarningsParser createParser() {
if (isValid()) {
if (hasMultiLineSupport()) {
return new DynamicDocumentParser(name, regexp, script, linkName, trendName);
} else {
return new DynamicParser(name, regexp, script, linkName, trendName);
}
} else {
return null;
}
}

public @CheckForNull AbstractWarningsParser getParser() {
return parser;
}

/**
* Descriptor to validate {@link GroovyParser}.
*
@@ -224,16 +224,8 @@ public static boolean exists(final String parserName) {
static List<AbstractWarningsParser> getDynamicParsers(final Iterable<GroovyParser> parserDescriptions) {
List<AbstractWarningsParser> parsers = Lists.newArrayList();
for (GroovyParser description : parserDescriptions) {
if (description.isValid()) {
AbstractWarningsParser parser;
if (description.hasMultiLineSupport()) {
parser = new DynamicDocumentParser(description.getName(), description.getRegexp(), description.getScript(),
description.getLinkName(), description.getTrendName());
}
else {
parser = new DynamicParser(description.getName(), description.getRegexp(), description.getScript(),
description.getLinkName(), description.getTrendName());
}
AbstractWarningsParser parser = description.getParser();
if (parser != null) {
parsers.add(parser);
}
}

0 comments on commit d677b1f

Please sign in to comment.
You can’t perform that action at this time.