Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[FIXED JENKINS-21240] Improve regexp.
Now missing class file warnings are also catched.
  • Loading branch information
uhafner committed Jan 30, 2014
1 parent 9de7dbe commit 32d39fc6a60c8252db573a6bf9646682f0c69c01
@@ -428,21 +428,11 @@ private List<ParserResult> parseFiles(final AbstractBuild<?, ?> build, final Plu
throws IOException, InterruptedException {
List<ParserResult> results = Lists.newArrayList();
for (ParserConfiguration configuration : getParserConfigurations()) {
String filePattern = configuration.getPattern();
String filePattern = expandFilePattern(build, configuration.getPattern());
String parserName = configuration.getParserName();

// Resolve build parameters in the file pattern
// up to resolveDepth times
final int resolveDepth = 10;
final Map<String,String> buildParameterMap = build.getBuildVariables();
for(int i = 0; i < resolveDepth ; i++) {
String old = filePattern;
filePattern = Util.replaceMacro(filePattern, buildParameterMap);
if (old.equals(filePattern)) { break; }
}
logger.log("Parsing warnings in files '" + filePattern + "' with parser " + parserName);


FilesParser parser = new FilesParser(PLUGIN_NAME, filePattern,
new FileWarningsParser(ParserRegistry.getParsers(parserName), getDefaultEncoding(), getIncludePattern(), getExcludePattern()),
shouldDetectModules(), isMavenBuild(build), canResolveRelativePaths());
@@ -455,6 +445,22 @@ private List<ParserResult> parseFiles(final AbstractBuild<?, ?> build, final Plu
return results;
}

/**
* Resolve build parameters in the file pattern up to resolveDepth times
*/
private String expandFilePattern(AbstractBuild<?, ?> build, String filePattern) {
int resolveDepth = 10;
Map<String,String> buildParameterMap = build.getBuildVariables();
for(int i = 0; i < resolveDepth ; i++) {
String old = filePattern;
filePattern = Util.replaceMacro(filePattern, buildParameterMap);
if (old.equals(filePattern)) {
break;
}
}
return filePattern;
}

private ParserResult annotate(final AbstractBuild<?, ?> build, final ParserResult input, final String parserName)
throws IOException, InterruptedException {
ParserResult output = build.getWorkspace().act(new AnnotationsClassifier(input, getDefaultEncoding()));
@@ -16,8 +16,10 @@ public class AntJavacParser extends RegexpLineParser {
private static final long serialVersionUID = 1737791073711198075L;

/** Pattern of javac compiler warnings. */
private static final String ANT_JAVAC_WARNING_PATTERN = ANT_TASK + "\\s*(.*java):(\\d*):\\s*(?:warning|\u8b66\u544a)\\s*:\\s*(?:\\[(\\w*)\\])?\\s*(.*)$"
+ "|^\\s*\\[.*\\]\\s*warning.*\\]\\s*(.*\"(.*)\".*)$";
private static final String ANT_JAVAC_WARNING_PATTERN = ANT_TASK
+ "\\s*(.*java):(\\d*):\\s*(?:warning|\u8b66\u544a)\\s*:\\s*(?:\\[(\\w*)\\])?\\s*(.*)$"
+ "|^\\s*\\[.*\\]\\s*warning.*\\]\\s*(.*\"(.*)\".*)$"
+ "|^(.*class)\\s*:\\s*warning\\s*:\\s*(.*)$";
// \u8b66\u544a is Japanese l10n

/**
@@ -47,7 +49,10 @@ protected boolean isLineInteresting(final String line) {

@Override
protected Warning createWarning(final Matcher matcher) {
if (StringUtils.isBlank(matcher.group(5))) {
if (StringUtils.isNotBlank(matcher.group(7))) {
return createWarning(matcher.group(7), 0, getGroup(), matcher.group(8));
}
else if (StringUtils.isBlank(matcher.group(5))) {
String message = matcher.group(4);
String category = classifyIfEmpty(matcher.group(3), message);
return createWarning(matcher.group(1), getLineNumber(matcher.group(2)), category, message);
@@ -20,6 +20,24 @@
public class AntJavacParserTest extends ParserTester {
private static final String WARNING_TYPE = Messages._Warnings_JavaParser_ParserName().toString(Locale.ENGLISH);

/**
* Parses a warning log with one warning that refers to a missing class file.
*
* @throws IOException
* if the file could not be read
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-21240">Issue 21240</a>
*/
@Test
public void issue21240() throws IOException {
Collection<FileAnnotation> warnings = new AntJavacParser().parse(openFile("issue21240.txt"));

assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 1, warnings.size());
checkWarning(warnings.iterator().next(),
0,
"Cannot find annotation method 'xxx()' in type 'yyyy': class file for fully.qualified.ClassName not found",
"aaa.class", WARNING_TYPE, Priority.NORMAL);
}

/**
* Parses a file with two deprecation warnings.
*
@@ -64,11 +64,6 @@ public void parseDeprecation() throws IOException {

Iterator<FileAnnotation> iterator = warnings.iterator();
FileAnnotation annotation = iterator.next();
checkWarning(annotation,
12, 39,
"org.eclipse.jface.contentassist.SubjectControlContentAssistant in org.eclipse.jface.contentassist has been deprecated",
"C:/Build/Results/jobs/ADT-Base/workspace/com.avaloq.adt.ui/src/main/java/com/avaloq/adt/ui/elements/AvaloqDialog.java",
WARNING_TYPE, RegexpParser.DEPRECATION, Priority.NORMAL);
annotation = iterator.next();
checkWarning(annotation,
40, 36,
@@ -0,0 +1 @@
aaa.class: warning: Cannot find annotation method 'xxx()' in type 'yyyy': class file for fully.qualified.ClassName not found

0 comments on commit 32d39fc

Please sign in to comment.