Skip to content

Commit

Permalink
Merge pull request #40 from andresrc/JENKINS-33343
Browse files Browse the repository at this point in the history
[JENKINS-33343] Update to parent POM 2.3
  • Loading branch information
jglick committed Mar 17, 2016
2 parents 8d85657 + e0720e7 commit aa4414f
Show file tree
Hide file tree
Showing 33 changed files with 532 additions and 202 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Expand Up @@ -3,14 +3,18 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.580.1</version>
<version>2.3</version>
</parent>
<artifactId>junit</artifactId>
<version>1.12-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>JUnit Plugin</name>
<description>Allows JUnit-format test results to be published.</description>
<url>http://wiki.jenkins-ci.org/display/JENKINS/JUnit+Plugin</url>
<properties>
<jenkins.version>1.580.1</jenkins.version>
<java.level>6</java.level>
</properties>
<licenses>
<license>
<name>MIT</name>
Expand Down Expand Up @@ -48,10 +52,6 @@
</exclusion>
</exclusions>
</dependency>
<!--
Override beta version declared by jenkins-test-harness.
TODO: Reomve once depending on 1.600 or newer: f987f9ce89952c79e045f6125c08bfd7c6b9aa99
-->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
Expand Down
43 changes: 40 additions & 3 deletions src/main/java/hudson/tasks/junit/CaseResult.java
Expand Up @@ -23,6 +23,7 @@
*/
package hudson.tasks.junit;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.util.TextFile;
import org.apache.commons.io.FileUtils;
import org.jvnet.localizer.Localizable;
Expand Down Expand Up @@ -69,8 +70,10 @@ public class CaseResult extends TestResult implements Comparable<CaseResult> {
private final String skippedMessage;
private final String errorStackTrace;
private final String errorDetails;
@SuppressFBWarnings(value = "SE_TRANSIENT_FIELD_NOT_RESTORED", justification = "Specific method to restore it")
private transient SuiteResult parent;

@SuppressFBWarnings(value = "IS2_INCONSISTENT_SYNC", justification = "Not guarded, though read in synchronized blocks")
private transient ClassResult classResult;

/**
Expand Down Expand Up @@ -162,6 +165,7 @@ static String possiblyTrimStdio(Collection<CaseResult> results, boolean keepLong
/**
* Flavor of {@link #possiblyTrimStdio(Collection, boolean, String)} that doesn't try to read the whole thing into memory.
*/
@SuppressFBWarnings(value = "DM_DEFAULT_ENCODING", justification = "Expected behavior")
static String possiblyTrimStdio(Collection<CaseResult> results, boolean keepLongStdio, File stdio) throws IOException {
long len = stdio.length();
if (keepLongStdio && len < 1024 * 1024) {
Expand Down Expand Up @@ -204,8 +208,11 @@ private static int halfMaxSize(Collection<CaseResult> results) {

/**
* Used to create a fake failure, when Hudson fails to load data from XML files.
*
* Public since 1.526.
*
* @param parent Parent result.
* @param testName Test name.
* @param errorStackTrace Error stack trace.
*/
public CaseResult(SuiteResult parent, String testName, String errorStackTrace) {
this.className = parent == null ? "unnamed" : parent.getName();
Expand Down Expand Up @@ -313,6 +320,8 @@ public float getDuration() {

/**
* Gets the class name of a test class.
*
* @return the class name of a test class.
*/
@Exported(visibility=9)
public String getClassName() {
Expand All @@ -321,14 +330,18 @@ public String getClassName() {

/**
* Gets the simple (not qualified) class name.
*
* @return the simple (not qualified) class name.
*/
public String getSimpleName() {
int idx = className.lastIndexOf('.');
return className.substring(idx+1);
}

/**
* Gets the package name of a test case
* Gets the package name of a test case.
*
* @return the package name of a test case.
*/
public String getPackageName() {
int idx = className.lastIndexOf('.');
Expand Down Expand Up @@ -392,6 +405,8 @@ public Run<?,?> getFailedSinceRun() {
/**
* Gets the number of consecutive builds (including this)
* that this test case has been failing.
*
* @return the number of consecutive failing builds.
*/
@Exported(visibility=9)
public int getAge() {
Expand Down Expand Up @@ -581,7 +596,29 @@ public void freeze(SuiteResult parent) {
}

public int compareTo(CaseResult that) {
return this.getFullName().compareTo(that.getFullName());
if (this == that) {
return 0;
}
int r = this.getFullName().compareTo(that.getFullName());
if (r != 0) {
return r;
}
// Only equals is exact reference
return System.identityHashCode(this) >= System.identityHashCode(that) ? 1 : -1;
}

// Method overridden to provide explicit declaration of the equivalence relation used
// as Comparable is also implemented
@Override
public boolean equals(Object obj) {
return (this == obj);
}

// Method overridden to provide explicit declaration of the equivalence relation used
// as Comparable is also implemented
@Override
public int hashCode() {
return System.identityHashCode(this);
}

@Exported(name="status",visibility=9) // because stapler notices suffix 's' and remove it
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/hudson/tasks/junit/ClassResult.java
Expand Up @@ -205,7 +205,29 @@ public String getClassName() {
}

public int compareTo(ClassResult that) {
return this.className.compareTo(that.className);
if (this.equals(that)) {
return 0;
}
int r = this.className.compareTo(that.className);
if (r != 0) {
return r;
}
// Only equals is exact reference
return System.identityHashCode(this) >= System.identityHashCode(that) ? 1 : -1;
}

// Method overridden to provide explicit declaration of the equivalence relation used
// as Comparable is also implemented
@Override
public boolean equals(Object obj) {
return (this == obj);
}

// Method overridden to provide explicit declaration of the equivalence relation used
// as Comparable is also implemented
@Override
public int hashCode() {
return System.identityHashCode(this);
}

public String getDisplayName() {
Expand Down Expand Up @@ -235,4 +257,6 @@ public String getRelativePathFrom(TestObject it) {
return super.getRelativePathFrom(it);
}
}

private static final long serialVersionUID = 1L;
}
27 changes: 27 additions & 0 deletions src/main/java/hudson/tasks/junit/Helper.java
@@ -0,0 +1,27 @@
package hudson.tasks.junit;

import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

import jenkins.model.Jenkins;

/**
* Simple helper so we don't have to check {@code Jenkins.getInstance() != null} everywhere.
* TODO: replace with Jenkins.getActiveInstance() when on core {@literal >=} 1.609
*/
@Restricted(NoExternalUse.class)
public final class Helper {
/** Not instantiable. */
private Helper() {
throw new AssertionError("Not instantiable");
}

public static Jenkins getActiveInstance() {
Jenkins instance = Jenkins.getInstance();
if (instance == null) {
throw new IllegalStateException("Jenkins has not been started, or was already shut down");
}
return instance;
}
}
12 changes: 10 additions & 2 deletions src/main/java/hudson/tasks/junit/History.java
Expand Up @@ -94,6 +94,8 @@ public List<TestResult> getList() {

/**
* Graph of duration of tests over time.
*
* @return a graph of duration of tests over time.
*/
public Graph getDurationGraph() {
return new GraphImpl("seconds") {
Expand Down Expand Up @@ -131,6 +133,8 @@ else if (o.getSkipCount() > 0)

/**
* Graph of # of tests over time.
*
* @return a graph of number of tests over time.
*/
public Graph getCountGraph() {
return new GraphImpl("") {
Expand Down Expand Up @@ -253,11 +257,15 @@ public String getUrl() {
return url;
}

private void generateUrl() {
private void generateUrl() {
Run<?,?> build = o.getRun();
String buildLink = build.getUrl();
String actionUrl = o.getTestResultAction().getUrlName();
this.url = Jenkins.getInstance().getRootUrl() + buildLink + actionUrl + o.getUrl();
final String rootUrl = Helper.getActiveInstance().getRootUrl();
if (rootUrl == null) {
throw new IllegalStateException("Jenkins root URL not available");
}
this.url = rootUrl + buildLink + actionUrl + o.getUrl();
}

public int compareTo(ChartLabel that) {
Expand Down
35 changes: 30 additions & 5 deletions src/main/java/hudson/tasks/junit/JUnitResultArchiver.java
Expand Up @@ -131,7 +131,11 @@ private TestResult parse(String expandedTestResults, Run<?,?> run, @Nonnull File
protected TestResult parse(String expandedTestResults, AbstractBuild build, Launcher launcher, BuildListener listener)
throws IOException, InterruptedException
{
return parse(expandedTestResults, build, build.getWorkspace(), launcher, listener);
final FilePath workspace = build.getWorkspace();
if (workspace == null) {
throw new IllegalArgumentException("The provided build has no workspace");
}
return parse(expandedTestResults, build, workspace, launcher, listener);
}

@Override
Expand Down Expand Up @@ -195,7 +199,11 @@ public void perform(Run build, FilePath workspace, Launcher launcher,

/**
* Not actually used, but left for backward compatibility
* @param ds Directory scanner.
* @param buildTime Build Time.
*
* @return a {@link TestResult}.
* @throws IOException if an error occurs.
* @deprecated since 2009-08-10.
*/
protected TestResult parseResult(DirectoryScanner ds, long buildTime)
Expand All @@ -215,7 +223,11 @@ public double getHealthScaleFactor() {
return healthScaleFactor == null ? 1.0 : healthScaleFactor;
}

/** @since 1.2-beta-1 */
/**
* @param healthScaleFactor Health scale factor.
*
* @since 1.2-beta-1
*/
@DataBoundSetter public final void setHealthScaleFactor(double healthScaleFactor) {
this.healthScaleFactor = Math.max(0.0, healthScaleFactor);
}
Expand All @@ -224,20 +236,28 @@ public double getHealthScaleFactor() {
return testDataPublishers == null ? Collections.<TestDataPublisher>emptyList() : testDataPublishers;
}

/** @since 1.2 */
/**
* @param testDataPublishers Test data publishers.
*
* @since 1.2
*/
@DataBoundSetter public final void setTestDataPublishers(@Nonnull List<? extends TestDataPublisher> testDataPublishers) {
this.testDataPublishers = new DescribableList<TestDataPublisher,Descriptor<TestDataPublisher>>(Saveable.NOOP);
this.testDataPublishers.addAll(testDataPublishers);
}

/**
* @return the keepLongStdio
* @return the keepLongStdio.
*/
public boolean isKeepLongStdio() {
return keepLongStdio;
}

/** @since 1.2-beta-1 */
/**
* @param keepLongStdio Whether to keep long stdio.
*
* @since 1.2-beta-1
*/
@DataBoundSetter public final void setKeepLongStdio(boolean keepLongStdio) {
this.keepLongStdio = keepLongStdio;
}
Expand Down Expand Up @@ -265,6 +285,11 @@ public String getDisplayName() {

/**
* Performs on-the-fly validation on the file mask wildcard.
* @param project Project.
* @param value File mask to validate.
*
* @return the validation result.
* @throws IOException if an error occurs.
*/
public FormValidation doCheckTestResults(
@AncestorInPath AbstractProject project,
Expand Down
28 changes: 27 additions & 1 deletion src/main/java/hudson/tasks/junit/PackageResult.java
Expand Up @@ -188,6 +188,8 @@ public List<CaseResult> getFailedTests() {

/**
* Returns a list of the failed cases, sorted by age.
*
* @return a list of the failed cases, sorted by age.
*/
public List<CaseResult> getFailedTestsSortedByAge() {
List<CaseResult> failedTests = getFailedTests();
Expand Down Expand Up @@ -297,10 +299,34 @@ void freeze() {
}

public int compareTo(PackageResult that) {
return this.packageName.compareTo(that.packageName);
if (this.equals(that)) {
return 0;
}
int r = this.packageName.compareTo(that.packageName);
if (r != 0) {
return r;
}
// Only equals is exact reference
return System.identityHashCode(this) >= System.identityHashCode(that) ? 1 : -1;
}

// Method overridden to provide explicit declaration of the equivalence relation used
// as Comparable is also implemented
@Override
public boolean equals(Object obj) {
return (this == obj);
}

// Method overridden to provide explicit declaration of the equivalence relation used
// as Comparable is also implemented
@Override
public int hashCode() {
return System.identityHashCode(this);
}

public String getDisplayName() {
return TestNameTransformer.getTransformedName(packageName);
}

private static final long serialVersionUID = 1L;
}

0 comments on commit aa4414f

Please sign in to comment.