Skip to content

Commit

Permalink
Merge pull request #81 from jftsunami/JENKINS-55715
Browse files Browse the repository at this point in the history
[FIXED JENKINS-55715] Extract file name and package from taglist.
  • Loading branch information
uhafner authored Jan 22, 2019
2 parents 398c9e3 + 999e8db commit 1a47a2d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=80
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
Expand Down
23 changes: 19 additions & 4 deletions src/main/java/edu/hm/hafner/analysis/parser/TaglistParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
import edu.hm.hafner.analysis.ReaderFactory;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.util.XmlElementUtil;
import edu.umd.cs.findbugs.annotations.Nullable;

/**
* Parser for Taglist Maven Plugin output.
* Parser for Taglist Maven Plugin output. During parse, class names are converted into assumed file system names, so
* {@code package.name.class} becomes {@code package/name/class.java}.
*
* @author Jason Faust
* @see <a href=
* "https://www.mojohaus.org/taglist-maven-plugin/">https://www.mojohaus.org/taglist-maven-plugin/</a>
* @see <a href= "https://www.mojohaus.org/taglist-maven-plugin/">https://www.mojohaus.org/taglist-maven-plugin/</a>
*/
public class TaglistParser extends IssueParser {
private static final long serialVersionUID = 1L;
Expand All @@ -43,7 +44,12 @@ public Report parse(final ReaderFactory readerFactory) throws ParsingException {

NodeList files = (NodeList)xPath.evaluate("files/file", tag, XPathConstants.NODESET);
for (Element file : XmlElementUtil.nodeListToList(files)) {
issueBuilder.setFileName(xPath.evaluate("@name", file));
String clazz = xPath.evaluate("@name", file);
if (clazz != null) {
issueBuilder.setFileName(class2file(clazz));
issueBuilder.setPackageName(class2package(clazz));
issueBuilder.setAdditionalProperties(clazz);
}

NodeList comments = (NodeList)xPath.evaluate("comments/comment", file, XPathConstants.NODESET);
for (Element comment : XmlElementUtil.nodeListToList(comments)) {
Expand All @@ -62,4 +68,13 @@ public Report parse(final ReaderFactory readerFactory) throws ParsingException {
}
}

private String class2file(String clazz) {
return clazz.replace('.', '/').concat(".java");
}

private @Nullable String class2package(String clazz) {
int idx = clazz.lastIndexOf('.');
return idx > 0 ? clazz.substring(0, idx) : null;
}

}
19 changes: 19 additions & 0 deletions src/test/java/edu/hm/hafner/analysis/assertj/IssueAssert.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.hm.hafner.analysis.assertj;

import java.io.Serializable;
import java.util.Objects;
import java.util.UUID;

Expand Down Expand Up @@ -335,4 +336,22 @@ public IssueAssert hasReference(final String reference) {
}
return this;
}

/**
* Checks whether an Issue has specific additional properties.
*
* @param additionalProperties
* Serializable specifying additional properties.
*
* @return this
*/
public IssueAssert hasAdditionalProperties(final Serializable additionalProperties) {
isNotNull();

if (!Objects.equals(actual.getAdditionalProperties(), additionalProperties)) {
failWithMessage(EXPECTED_BUT_WAS_MESSAGE, "additional properties", actual, additionalProperties,
actual.getAdditionalProperties());
}
return this;
}
}
16 changes: 12 additions & 4 deletions src/test/java/edu/hm/hafner/analysis/parser/TaglistParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,39 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti
.hasLineStart(6)
.hasLineEnd(6)
.hasMessage("main")
.hasFileName("y.Z");
.hasFileName("y/Z.java")
.hasPackageName("y")
.hasAdditionalProperties("y.Z");

softly.assertThat(report.get(1))
.hasSeverity(Severity.WARNING_NORMAL)
.hasCategory("TODO")
.hasLineStart(3)
.hasLineEnd(3)
.hasMessage("todo")
.hasFileName("y.Z");
.hasFileName("y/Z.java")
.hasPackageName("y")
.hasAdditionalProperties("y.Z");

softly.assertThat(report.get(2))
.hasSeverity(Severity.WARNING_NORMAL)
.hasCategory("TODO")
.hasLineStart(8)
.hasLineEnd(8)
.hasMessage("main method")
.hasFileName("y.Z");
.hasFileName("y/Z.java")
.hasPackageName("y")
.hasAdditionalProperties("y.Z");

softly.assertThat(report.get(3))
.hasSeverity(Severity.WARNING_NORMAL)
.hasCategory("TODO")
.hasLineStart(3)
.hasLineEnd(3)
.hasMessage("todo")
.hasFileName("y.Z2");
.hasFileName("y/Z2.java")
.hasPackageName("y")
.hasAdditionalProperties("y.Z2");
}

}

0 comments on commit 1a47a2d

Please sign in to comment.