Skip to content

Commit

Permalink
Merge branch 'master' into java11-readiness
Browse files Browse the repository at this point in the history
  • Loading branch information
batmat committed Jun 28, 2019
2 parents 3df6ac7 + cbe283c commit e6202f8
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 60 deletions.
7 changes: 7 additions & 0 deletions .mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
<extension>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>git-changelist-maven-extension</artifactId>
<version>1.0-beta-7</version>
</extension>
</extensions>
2 changes: 2 additions & 0 deletions .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-Pconsume-incrementals
-Pmight-produce-incrementals
22 changes: 12 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.42</version>
<version>3.43</version>
<relativePath />
</parent>
<artifactId>junit</artifactId>
<version>1.28-SNAPSHOT</version>
<version>${revision}${changelist}</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>2.121.1</jenkins.version>
<revision>1.29</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.138.4</jenkins.version>
<java.level>8</java.level>
<no-test-jar>false</no-test-jar>
<workflow-cps.version>2.37</workflow-cps.version>
<workflow-cps.version>2.66</workflow-cps.version>
<workflow-support.version>3.2</workflow-support.version>
</properties>
<licenses>
Expand All @@ -29,7 +31,7 @@
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
<tag>HEAD</tag>
<tag>${scmTag}</tag>
</scm>
<repositories>
<repository>
Expand Down Expand Up @@ -57,12 +59,12 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.33</version>
<version>2.34</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<version>1.57</version>
<version>1.56</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down Expand Up @@ -90,7 +92,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>2.11.1</version>
<version>2.32</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -103,7 +105,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>2.6</version>
<version>2.15</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -128,7 +130,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>2.13</version>
<version>2.28</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/hudson/tasks/junit/CaseResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@ public int getPassCount() {
public int getFailedSince() {
// If we haven't calculated failedSince yet, and we should,
// do it now.
recomputeFailedSinceIfNeeded();
return failedSince;
}

private void recomputeFailedSinceIfNeeded() {
if (failedSince==0 && getFailCount()==1) {
CaseResult prev = getPreviousResult();
if(prev!=null && !prev.isPassed())
Expand All @@ -413,9 +418,8 @@ else if (getRun() != null) {
// failedSince will be 0, which isn't correct.
}
}
return failedSince;
}

public Run<?,?> getFailedSinceRun() {
return getRun().getParent().getBuildByNumber(getFailedSince());
}
Expand Down Expand Up @@ -637,13 +641,7 @@ public void setParentSuiteResult(SuiteResult parent) {
public void freeze(SuiteResult parent) {
this.parent = parent;
// some old test data doesn't have failedSince value set, so for those compute them.
if(!isPassed() && failedSince==0) {
CaseResult prev = getPreviousResult();
if(prev!=null && !prev.isPassed())
this.failedSince = prev.failedSince;
else
this.failedSince = getRun().getNumber();
}
recomputeFailedSinceIfNeeded();
}

public int compareTo(CaseResult that) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hudson/tasks/junit/JUnitParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
* Parse some JUnit xml files and generate a TestResult containing all the
* results parsed.
*/
@Extension
@Extension // see TestResultParser.all
public class JUnitParser extends TestResultParser {

private final boolean keepLongStdio;
private final boolean allowEmptyResults;

/** TODO TestResultParser.all does not seem to ever be called so why must this be an Extension? */
/** Generally unused, but present for extension compatibility. */
@Deprecated
public JUnitParser() {
this(false, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.tasks.junit.JUnitResultArchiver;
import hudson.tasks.junit.TestResult;
import hudson.tasks.junit.TestResultAction;
import hudson.tasks.junit.TestResultSummary;
import hudson.tasks.test.PipelineTestDetails;
Expand All @@ -14,6 +15,7 @@
import javax.annotation.Nonnull;
import org.jenkinsci.plugins.workflow.actions.LabelAction;
import org.jenkinsci.plugins.workflow.actions.ThreadNameAction;
import org.jenkinsci.plugins.workflow.actions.WarningAction;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.graph.StepNode;
import org.jenkinsci.plugins.workflow.steps.StepContext;
Expand Down Expand Up @@ -50,11 +52,13 @@ protected TestResultSummary run() throws Exception {
TestResultAction testResultAction = JUnitResultArchiver.parseAndAttach(step, pipelineTestDetails, run, workspace, launcher, listener);

if (testResultAction != null) {
// TODO: Once JENKINS-43995 lands, update this to set the step status instead of the entire build.
if (testResultAction.getResult().getFailCount() > 0) {
TestResult testResult = testResultAction.getResult().getResultByNode(nodeId);
int testFailures = testResult.getFailCount();
if (testFailures > 0) {
node.addOrReplaceAction(new WarningAction(Result.UNSTABLE).withMessage(testFailures + " tests failed"));
run.setResult(Result.UNSTABLE);
}
return new TestResultSummary(testResultAction.getResult().getResultByNode(nodeId));
return new TestResultSummary(testResult);
}
} catch (Exception e) {
listener.getLogger().println(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
*
* @since 1.343
* @author Kohsuke Kawaguchi
* @deprecated Unused, unusable.
*/
@Deprecated
public abstract class DefaultTestResultParserImpl extends TestResultParser implements Serializable {
/**
* This method is executed on the slave that has the report files to parse test reports and builds {@link TestResult}.
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/hudson/tasks/test/TestObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -188,7 +189,7 @@ public String getRelativePathFrom(TestObject it) {
buf.insert(0, Functions.getRelativeLinkTo(myBuildAsItem));
} else {
// We're not in a stapler request. Okay, give up.
LOGGER.info("trying to get relative path, but it is not my ancestor, and we're not in a stapler request. Trying absolute hudson url...");
LOGGER.fine("trying to get relative path, but it is not my ancestor, and we are not in a stapler request. Trying absolute hudson url...");
String hudsonRootUrl = Helper.getActiveInstance().getRootUrl();
if (hudsonRootUrl==null||hudsonRootUrl.length()==0) {
LOGGER.warning("Can't find anything like a decent hudson url. Punting, returning empty string.");
Expand All @@ -199,7 +200,7 @@ public String getRelativePathFrom(TestObject it) {
buf.insert(0, hudsonRootUrl);
}

LOGGER.info("Here's our relative path: " + buf.toString());
LOGGER.log(Level.FINE, "Here is our relative path: {0}", buf);
return buf.toString();
}

Expand Down
22 changes: 9 additions & 13 deletions src/main/java/hudson/tasks/test/TestResultParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,29 @@
import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.tasks.Publisher;

import java.io.IOException;
import javax.annotation.Nonnull;

/**
* Parses test result files and builds in-memory representation of it as {@link TestResult}.
*
* <p>
* This extension point encapsulates the knowledge of a particular test report format and its parsing process,
* thereby improving the pluggability of test result parsing; integration with a new test tool can be done
* by just writing a parser, without writing a custom {@link Publisher}, and the test reports are displayed
* with the default UI and recognized by the rest of Hudson as test reports.
*
* <p>
* Most typical implementations of this class should extend from {@link DefaultTestResultParserImpl},
* which handles a set of default error checks on user inputs.
*
* Originally this was treated as an {@link ExtensionPoint},
* but no supported code path actually uses this API directly. See {@link #all}.
* <p>
* Parsers are stateless, and the {@link #parseResult} method
* can be concurrently invoked by multiple threads for different builds.
*
* @since 1.343
* @see DefaultTestResultParserImpl
*/
public abstract class TestResultParser implements ExtensionPoint {
public abstract class TestResultParser {
/**
* Returns a human readable name of the parser, like "JUnit Parser".
*
* @return a human readable name of the parser, like "JUnit Parser".
* @deprecated Normally unused.
*/
@Deprecated
public String getDisplayName() {
return "Unknown Parser";
}
Expand All @@ -72,7 +64,9 @@ public String getDisplayName() {
* For example, "JUnit XML reports:"
*
* @return the text is used in the UI prompt for the GLOB that specifies files to be parsed by this parser.
* @deprecated Normally unused.
*/
@Deprecated
public String getTestResultLocationMessage() {
return "Paths to results files to parse:";
}
Expand All @@ -81,7 +75,9 @@ public String getTestResultLocationMessage() {
* All registered {@link TestResultParser}s.
*
* @return all registered {@link TestResultParser}s.
* @deprecated Unused. In fact only the {@code labeled-test-groups-publisher} plugin seems to actually enumerate parsers this way (though not using this method), a use case superseded by {@link PipelineTestDetails}.
*/
@Deprecated
public static ExtensionList<TestResultParser> all() {
return ExtensionList.lookup(TestResultParser.class);
}
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/hudson/tasks/junit/TestResultLinksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@
import hudson.model.FreeStyleProject;
import hudson.model.Result;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.concurrent.TimeUnit;

import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRule.WebClient;
import org.jvnet.hudson.test.TouchBuilder;
Expand Down Expand Up @@ -117,4 +121,20 @@ public void testNonDescendantRelativePath() throws Exception {
boolean pathStartsWithRootUrl = !pathIsEmptyOrNull && relativePath2.startsWith(rule.jenkins.getRootUrl());
assertTrue("relative path is empty OR begins with the app root", pathIsEmptyOrNull || pathStartsWithRootUrl );
}

@Issue("JENKINS-31660")
@Test
public void testPreviousBuildNotLoaded() throws IOException, URISyntaxException {
TestResult testResult = new TestResult();
File dataFile = TestResultTest.getDataFile("SKIPPED_MESSAGE/skippedTestResult.xml");
testResult.parse(dataFile, null);
FreeStyleBuild build = new FreeStyleBuild(project) {
@Override
public FreeStyleBuild getPreviousBuild() {
fail("When no tests fail, we don't need tp load previous builds (expensive)");
return null;
}
};
testResult.freeze(new TestResultAction(build, testResult, null));
}
}
2 changes: 1 addition & 1 deletion src/test/java/hudson/tasks/junit/TestResultTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* @author dty
*/
public class TestResultTest {
private File getDataFile(String name) throws URISyntaxException {
protected static File getDataFile(String name) throws URISyntaxException {
return new File(TestResultTest.class.getResource(name).toURI());
}

Expand Down

0 comments on commit e6202f8

Please sign in to comment.