Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tap4j.version>4.4.2</tap4j.version>
<junit.plugin.version>1.6</junit.plugin.version>
<dashboard.plugin.version>2.0</dashboard.plugin.version>
<!-- TODO: remove once FindBugs issues are fixed -->
<findbugs.failOnError>false</findbugs.failOnError>
</properties>
Expand Down Expand Up @@ -110,6 +111,12 @@
<artifactId>junit</artifactId>
<version>${junit.plugin.version}</version>
</dependency>
<!-- For dashboard view support -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>dashboard-view</artifactId>
<version>${dashboard.plugin.version}</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The protection against NPEs looks easy to be reviewed and merged. This dependency and the classes added are a bit more complicated to review, I think. Would be easier if this could be an optional dependency, but I am not sure if that wouldn't cause some runtime errors for users without he plug-in (I think in active choices I have an optional dependency, will check what steps were taken for that.

</dependency>
<!-- Test -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/tap4j/plugin/TapResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
* The MIT License
*
* Copyright (c) 2011 Bruno P. Kinoshita
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -189,6 +189,9 @@ public void tally() {

for (TestSetMap testSet : testSets) {
TestSet realTestSet = testSet.getTestSet();
if (realTestSet == null) {
continue;
}
List<TestResult> testResults = realTestSet.getTestResults();

total += testResults.size();
Expand Down Expand Up @@ -327,7 +330,7 @@ public String getName() {

/*
* (non-Javadoc)
*
*
* @see hudson.model.ModelObject#getDisplayName()
*/
public String getDisplayName() {
Expand Down
46 changes: 26 additions & 20 deletions src/main/java/org/tap4j/plugin/model/TapStreamResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
* The MIT License
*
* Copyright (c) 2012 Bruno P. Kinoshita
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -58,7 +58,7 @@ public TapStreamResult(Run<?, ?> owner, TapResult tapResult) {
this.tapResult = tapResult;
setChildrenInfo();
}

/* (non-Javadoc)
* @see hudson.model.ModelObject#getDisplayName()
*/
Expand Down Expand Up @@ -89,7 +89,7 @@ public TestObject getParent() {
public TestResult findCorrespondingResult(String id) {
return null;
}

/* (non-Javadoc)
* @see hudson.tasks.test.TabulatedResult#getChildren()
*/
Expand All @@ -105,7 +105,7 @@ public Collection<? extends TestResult> getChildren() {
public boolean hasChildren() {
return children.size() > 0;
}

/* (non-Javadoc)
* @see hudson.tasks.test.AbstractTestResultAction#getFailCount()
*/
Expand All @@ -123,7 +123,7 @@ public int getFailCount() {
public int getTotalCount() {
return tapResult.getTotal();
}

/* (non-Javadoc)
* @see hudson.tasks.test.AbstractTestResultAction#getSkipCount()
*/
Expand All @@ -145,16 +145,18 @@ public List<CaseResult> getFailedTests() {
//throw new AssertionError("Not supposed to be called");
return Collections.emptyList();
}

// FIXME: use the getFailedTests, or explain why it's not used
public List<TestResult> getFailedTests2() {
List<TestResult> failedTests = new ArrayList<TestResult>();
if(tapResult != null && tapResult.getTestSets().size() > 0) {
for(TestSetMap tsm : tapResult.getTestSets()) {
TestSet ts = tsm.getTestSet();
for(org.tap4j.model.TestResult tr : ts.getTestResults()) {
if(tr.getStatus() == StatusValues.NOT_OK) {
failedTests.add(new TapTestResultResult(owner, tsm, tr, this.tapResult.getTodoIsFailure(), tapResult.getIncludeCommentDiagnostics(), tapResult.getValidateNumberOfTests()));
if (ts != null) {
for(org.tap4j.model.TestResult tr : ts.getTestResults()) {
if(tr.getStatus() == StatusValues.NOT_OK) {
failedTests.add(new TapTestResultResult(owner, tsm, tr, this.tapResult.getTodoIsFailure(), tapResult.getIncludeCommentDiagnostics(), tapResult.getValidateNumberOfTests()));
}
}
}
}
Expand Down Expand Up @@ -189,29 +191,31 @@ private TapTestResultResult getTapTestResultResult(String name) {
return null; // we don't allow null, nay!
if (name.lastIndexOf("-") <= 0)
return null; // ops, where's the - mate?

name = name.trim();

int rightIndex = name.length();
while (name.charAt(rightIndex-1) == '/') {
rightIndex -= 1;
}
int leftIndex = name.lastIndexOf('/') +1;

String testResultName = name.substring(leftIndex, rightIndex); // but we want the test result name (testSet1.tap)
if (testResultName.indexOf('-') <= 0) // plus the number (testSet1.tap-2)
return null;
String testNumber = testResultName.substring(testResultName.lastIndexOf('-')+1);
String fileName = name.substring(0, name.lastIndexOf('-'));

for(TestSetMap tsm : tapResult.getTestSets()) {
if(tsm.getFileName().equals(fileName)) {
TestSet ts = tsm.getTestSet();
org.tap4j.model.TestResult desired = ts.getTestResult(Integer.parseInt(testNumber));
return new TapTestResultResult(owner, tsm, desired, this.tapResult.getTodoIsFailure(), tapResult.getIncludeCommentDiagnostics(), tapResult.getValidateNumberOfTests());
if (ts != null) {
org.tap4j.model.TestResult desired = ts.getTestResult(Integer.parseInt(testNumber));
return new TapTestResultResult(owner, tsm, desired, this.tapResult.getTodoIsFailure(), tapResult.getIncludeCommentDiagnostics(), tapResult.getValidateNumberOfTests());
}
}
}

return null; // ops, something went wrong
}

Expand All @@ -227,8 +231,10 @@ public void merge(TapResult other) {
private void setChildrenInfo() {
for(TestSetMap tsm : tapResult.getTestSets()) {
TestSet ts = tsm.getTestSet();
for(org.tap4j.model.TestResult tr : ts.getTestResults()) {
this.children.add(new TapTestResultResult(owner, tsm, tr, tapResult.getTodoIsFailure(), tapResult.getIncludeCommentDiagnostics(), tapResult.getValidateNumberOfTests()));
if (ts != null) {
for(org.tap4j.model.TestResult tr : ts.getTestResults()) {
this.children.add(new TapTestResultResult(owner, tsm, tr, tapResult.getTodoIsFailure(), tapResult.getIncludeCommentDiagnostics(), tapResult.getValidateNumberOfTests()));
}
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/org/tap4j/plugin/util/DiagnosticUtil.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
/*
* The MIT License
*
*
* Copyright (c) 2010 Bruno P. Kinoshita
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -29,7 +29,7 @@

/**
* Used to create YAML view.
*
*
* @author Bruno P. Kinoshita - http://www.kinoshita.eti.br
* @since 1.0
*/
Expand All @@ -55,7 +55,7 @@ public static String createDiagnosticTable(String tapFile, Map<String, Object> d
}

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void createDiagnosticTableRecursively(String tapFile, String parentKey,
public static void createDiagnosticTableRecursively(String tapFile, String parentKey,
Map<String, Object> diagnostic, StringBuilder sb, int depth) {

sb.append(INNER_TABLE_HEADER);
Expand All @@ -67,11 +67,11 @@ public static void createDiagnosticTableRecursively(String tapFile, String paren
String key = entry.getKey();
Object value = entry.getValue();
sb.append("<tr>");

for (int i = 0; i < depth; ++i) {
sb.append("<td width='5%' class='hidden'> </td>");
}
sb.append("<td style=\"width: auto;\">" + key + "</td>");
sb.append("<td style=\"width: auto;\">").append(key).append("</td>");
if(key.equals("File-Content")) {
String fileName = "attachment";
Object o = diagnostic.get("File-Name");
Expand All @@ -84,9 +84,9 @@ public static void createDiagnosticTableRecursively(String tapFile, String paren
downloadKey = parentKey;
}
}
sb.append("<td><a href='downloadAttachment?f="+tapFile+"&key="+downloadKey+"'>"+fileName+"</a></td>");
sb.append("<td><a href='downloadAttachment?f=").append(tapFile).append("&key=").append(downloadKey).append("'>").append(fileName).append("</a></td>");
} else {
sb.append("<td><pre>" + org.apache.commons.lang.StringEscapeUtils.escapeHtml(value.toString()) + "</pre></td>");
sb.append("<td><pre>").append(org.apache.commons.lang.StringEscapeUtils.escapeHtml(value != null ? value.toString() : "")).append("</pre></td>");
}
sb.append("</tr>");
}
Expand All @@ -95,7 +95,7 @@ public static void createDiagnosticTableRecursively(String tapFile, String paren
String key = entry.getKey();
Object value = entry.getValue();
sb.append("<tr>");

for (int i = 0; i < depth; ++i) {
sb.append("<td width='5%' class='hidden'> </td>");
}
Expand All @@ -105,7 +105,7 @@ public static void createDiagnosticTableRecursively(String tapFile, String paren
createDiagnosticTableRecursively(tapFile, key, (java.util.Map) value, sb,
(depth + 1));
} else {
sb.append("<td><pre>" + org.apache.commons.lang.StringEscapeUtils.escapeHtml(value.toString()) + "</pre></td>");
sb.append("<td><pre>").append(org.apache.commons.lang.StringEscapeUtils.escapeHtml(value != null ? value.toString() : "")).append("</pre></td>");
}
sb.append("</tr>");
}
Expand Down
Loading