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

Commit

Permalink
[FIXED JENKINS-17762] Replace old parser names with new names.
Browse files Browse the repository at this point in the history
During de-serialization the old parser names should be replaced 
with the new names otherwise the UI can't show the selected parser.
  • Loading branch information
uhafner committed May 1, 2013
1 parent 6c343de commit 475666b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main/java/hudson/plugins/warnings/WarningsPublisher.java
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -197,9 +198,46 @@ protected Object readResolve() {
}
}

replaceConsoleParsersWithChangedName();
replaceFileParsersWithChangedName();

return this;
}

private void replaceConsoleParsersWithChangedName() {
List<ConsoleParser> updatedConsoleParsers = new ArrayList<ConsoleParser>(consoleParsers);
for (ConsoleParser parser : consoleParsers) {
String parserName = parser.getParserName();
if (ParserRegistry.exists(parserName)) {
String group = getGroup(parserName);
if (!group.equals(parserName)) {
updatedConsoleParsers.remove(parser);
updatedConsoleParsers.add(new ConsoleParser(group));
}
}
consoleParsers = updatedConsoleParsers;
}
}

private void replaceFileParsersWithChangedName() {
List<ParserConfiguration> updatedFileParsers = new ArrayList<ParserConfiguration>(parserConfigurations);
for (ParserConfiguration parser : parserConfigurations) {
String parserName = parser.getParserName();
if (ParserRegistry.exists(parserName)) {
String group = getGroup(parserName);
if (!group.equals(parserName)) {
updatedFileParsers.remove(parser);
updatedFileParsers.add(new ParserConfiguration(parser.getPattern(), group));
}
}
parserConfigurations = updatedFileParsers;
}
}

private String getGroup(final String parserName) {
return ParserRegistry.getParser(parserName).getGroup();
}

private void upgradeFrom318() {
consoleLogParsers = Sets.newHashSet();
parserConfigurations = Lists.newArrayList();
Expand Down
Expand Up @@ -51,6 +51,21 @@ public void testRegistry() {
assertEquals("Wrong mixed API implementations", 1, ParserRegistry.getParsers(MIXED_API).size());
}

/**
* Verifies that the registry detects old and new API extensions and maps them correctly.
*/
@Test
public void testIssue17762() {
String oldClang = "Apple LLVM Compiler (Clang)";
String newClang = "Clang (LLVM based)";

assertEquals("Wrong new API implementations", 1, ParserRegistry.getParsers(oldClang).size());
assertEquals("Wrong old API implementations", 1, ParserRegistry.getParsers(newClang).size());

assertTrue("Parser does not exist: " + oldClang, ParserRegistry.exists(oldClang));
assertTrue("Parser does not exist: " + newClang, ParserRegistry.exists(newClang));
}

/**
* Verifies that we parse two warnings if we use the key of the 3.x version.
*
Expand Down

0 comments on commit 475666b

Please sign in to comment.