Skip to content

Commit

Permalink
Merge pull request #29 from oleg-nenashev/bug/JENKINS-48924-jep-200
Browse files Browse the repository at this point in the history
[JENKINS-48924, JENKINS-48995] - Fix plugin compatibility with Jenkins 2.102+
  • Loading branch information
kinow committed Jan 25, 2018
2 parents 97f9c84 + b56640e commit 9d4b1cc
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 110 deletions.
43 changes: 39 additions & 4 deletions src/main/java/hudson/plugins/testlink/TestLinkBuildAction.java
Expand Up @@ -25,32 +25,52 @@

import hudson.model.Action;
import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.plugins.testlink.util.TestLinkHelper;

import java.io.Serializable;

import jenkins.model.RunAction2;
import org.kohsuke.stapler.StaplerProxy;

/**
* @author Bruno P. Kinoshita - http://www.kinoshita.eti.br
* @since 1.0
*/
public class TestLinkBuildAction implements Action, Serializable, StaplerProxy {
public class TestLinkBuildAction implements RunAction2, Serializable, StaplerProxy {

private static final long serialVersionUID = -914904584770393909L;

public static final String DISPLAY_NAME = "TestLink";
public static final String ICON_FILE_NAME = "/plugin/testlink/icons/testlink-24.png";
public static final String URL_NAME = "testLinkResult";

private AbstractBuild<?, ?> build;
private transient Run<?, ?> build;
private TestLinkResult result;

public TestLinkBuildAction(TestLinkResult result) {
this.result = result;
}

/**
* @deprecated Use {@link #TestLinkBuildAction(TestLinkResult)} without build definition.
*/
@Deprecated
public TestLinkBuildAction(AbstractBuild<?, ?> build, TestLinkResult result) {
this.build = build;
this.result = result;
}

@Override
public void onLoad(Run<?, ?> r) {
this.build = r;
}

@Override
public void onAttached(Run<?, ?> r) {
this.build = r;
}

public String getDisplayName() {
return DISPLAY_NAME;
}
Expand All @@ -67,10 +87,25 @@ public Object getTarget() {
return this.result;
}

public AbstractBuild<?, ?> getBuild() {
/**
* Gets Run to which the action is attached.
* @return Run instance
* @since TODO
*/
public Run<?, ?> getRun() {
return build;
}

/**
* @deprecated Use {@link #getRun()}
*/
public AbstractBuild<?, ?> getBuild() {
if (build instanceof AbstractBuild<?, ?>) {
return (AbstractBuild<?, ?>)build;
}
throw new IllegalStateException("Calling old API against a non-AbstractBuild run type. Run: " + build);
}

/**
* @return TestLink job execution result
*/
Expand Down Expand Up @@ -107,7 +142,7 @@ public TestLinkResult getPreviousResult() {
*/
public TestLinkBuildAction getPreviousAction() {
if (this.build != null) {
AbstractBuild<?, ?> previousBuild = this.build.getPreviousBuild();
Run<?, ?> previousBuild = this.build.getPreviousBuild();
if (previousBuild != null) {
return previousBuild.getAction(TestLinkBuildAction.class);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/testlink/TestLinkBuilder.java
Expand Up @@ -275,8 +275,8 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,

listener.getLogger().println(Messages.TestLinkBuilder_ShowFoundTestResults(report.getTestsTotal()));

final TestLinkResult result = new TestLinkResult(report, build);
final TestLinkBuildAction buildAction = new TestLinkBuildAction(build, result);
final TestLinkResult result = new TestLinkResult(report);
final TestLinkBuildAction buildAction = new TestLinkBuildAction(result);
build.addAction(buildAction);

if(report.getTestsTotal() <= 0 && this.getFailIfNoResults() == Boolean.TRUE) {
Expand Down
Expand Up @@ -49,7 +49,6 @@
import org.kohsuke.stapler.StaplerRequest;

import com.tupilabs.testng.parser.Suite;
import com.tupilabs.testng.parser.TestNGParser;

/**
* @author Bruno P. Kinoshita - http://www.kinoshita.eti.br
Expand Down Expand Up @@ -158,7 +157,6 @@ public boolean isApplicable(Class<? extends AbstractProject> jobType) {
@Initializer(before = InitMilestone.PLUGINS_STARTED)
public static void addAliases() {
Items.XSTREAM2.addCompatibilityAlias("hudson.plugins.testlink.testng.Suite", Suite.class);
Items.XSTREAM2.addCompatibilityAlias("hudson.plugins.testlink.testng.TestNGParser", TestNGParser.class);
Items.XSTREAM2.addCompatibilityAlias("hudson.plugins.testlink.testng.Test",
com.tupilabs.testng.parser.Test.class);
Items.XSTREAM2.addCompatibilityAlias("hudson.plugins.testlink.testng.TestMethod",
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/hudson/plugins/testlink/TestLinkResult.java
Expand Up @@ -30,19 +30,39 @@
/**
* @author Bruno P. Kinoshita - http://www.kinoshita.eti.br
* @since 1.0
* @see TestLinkBuildAction
*/
public class TestLinkResult implements Serializable {

private static final long serialVersionUID = 3355678827881770594L;

private Report report;
private AbstractBuild<?, ?> build;
private final Report report;

// It would be possible to link actions, but there is no immediate need in the plugin API
private final transient AbstractBuild<?, ?> build;

/**
* Constructor
* @param report
*/
public TestLinkResult(Report report) {
this.report = report;
this.build = null;
}

/**
* @deprecated Use {@link #TestLinkResult(Report)}
*/
@Deprecated
public TestLinkResult(Report report, AbstractBuild<?, ?> build) {
this.report = report;
this.build = build;
}

/**
* @deprecated No longer used AND not persisted during restarts
*/
@Deprecated
public AbstractBuild<?, ?> getOwner() {
return this.build;
}
Expand Down
Expand Up @@ -26,14 +26,11 @@
import java.io.File;
import java.io.IOException;

import org.jenkinsci.remoting.Role;
import org.jenkinsci.remoting.RoleChecker;
import org.jenkinsci.remoting.RoleSensitive;
import jenkins.MasterToSlaveFileCallable;

import br.eti.kinoshita.testlinkjavaapi.constants.ExecutionStatus;
import br.eti.kinoshita.testlinkjavaapi.model.Attachment;
import br.eti.kinoshita.testlinkjavaapi.util.TestLinkAPIException;
import hudson.FilePath.FileCallable;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Result;
Expand Down Expand Up @@ -85,7 +82,7 @@ protected void handleResult(TestCaseWrapper automatedTestCase, AbstractBuild<?,
final int executionId = testlink.updateTestCase(automatedTestCase);

if(executionId > 0 && this.isAttachJUnitXML()) {
Attachment attachment = build.getWorkspace().act( new FileCallable<Attachment>() {
Attachment attachment = build.getWorkspace().act( new MasterToSlaveFileCallable<Attachment>() {

private static final long serialVersionUID = -5411683541842375558L;

Expand All @@ -105,11 +102,6 @@ public Attachment invoke(File f,

return attachment;
}

@Override
public void checkRoles(RoleChecker roleChecker) throws SecurityException {
roleChecker.check((RoleSensitive) this, Role.UNKNOWN);
}
});
testlink.uploadAttachment(executionId, attachment);
}
Expand Down
Expand Up @@ -11,9 +11,7 @@
import java.util.Map.Entry;
import java.util.Set;

import org.jenkinsci.remoting.Role;
import org.jenkinsci.remoting.RoleChecker;
import org.jenkinsci.remoting.RoleSensitive;
import jenkins.MasterToSlaveFileCallable;
import org.tap4j.consumer.TapConsumer;
import org.tap4j.consumer.TapConsumerFactory;
import org.tap4j.model.Directive;
Expand All @@ -27,8 +25,6 @@
import br.eti.kinoshita.testlinkjavaapi.constants.ExecutionStatus;
import br.eti.kinoshita.testlinkjavaapi.model.Attachment;
import br.eti.kinoshita.testlinkjavaapi.util.TestLinkAPIException;
import hudson.FilePath;
import hudson.FilePath.FileCallable;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
Expand Down Expand Up @@ -109,7 +105,7 @@ public void seek(final TestCaseWrapper[] automatedTestCases, AbstractBuild<?, ?>

try {
final Map<String, TestSet> testSets = build.getWorkspace().act(
new FilePath.FileCallable<Map<String, TestSet>>() {
new MasterToSlaveFileCallable<Map<String, TestSet>>() {
private static final long serialVersionUID = 1L;

private Map<String, TestSet> testSets;
Expand All @@ -130,10 +126,6 @@ public Map<String, TestSet> invoke(File workspace, VirtualChannel channel) throw

return testSets;
}

public void checkRoles(RoleChecker roleChecker) throws SecurityException {
roleChecker.check((RoleSensitive) this, Role.UNKNOWN);
}
});

for (String key : testSets.keySet()) {
Expand Down Expand Up @@ -191,7 +183,7 @@ protected void handleResult(TestCaseWrapper automatedTestCase, final AbstractBui

if (executionId > 0 && this.isAttachTAPStream()) {
final String remoteWs = build.getWorkspace().getRemote();
List<Attachment> attachments = build.getWorkspace().act(new FileCallable<List<Attachment>>() {
List<Attachment> attachments = build.getWorkspace().act(new MasterToSlaveFileCallable<List<Attachment>>() {

private static final long serialVersionUID = -5411683541842375558L;

Expand All @@ -217,11 +209,6 @@ public List<Attachment> invoke(File f, VirtualChannel channel) throws IOExceptio

return attachments;
}

@Override
public void checkRoles(RoleChecker roleChecker) throws SecurityException {
roleChecker.check((RoleSensitive) this, Role.UNKNOWN);
}
});
for (Attachment attachment : attachments) {
testlink.uploadAttachment(executionId, attachment);
Expand Down
Expand Up @@ -23,7 +23,6 @@
*/
package hudson.plugins.testlink.result;

import hudson.FilePath.FileCallable;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.model.AbstractBuild;
Expand All @@ -33,9 +32,7 @@
import java.io.File;
import java.io.IOException;

import org.jenkinsci.remoting.Role;
import org.jenkinsci.remoting.RoleChecker;
import org.jenkinsci.remoting.RoleSensitive;
import jenkins.MasterToSlaveFileCallable;

import br.eti.kinoshita.testlinkjavaapi.constants.ExecutionStatus;
import br.eti.kinoshita.testlinkjavaapi.model.Attachment;
Expand All @@ -44,6 +41,8 @@
import com.tupilabs.testng.parser.Suite;
import com.tupilabs.testng.parser.TestNGParser;

import javax.annotation.Nonnull;

/**
* @author Bruno P. Kinoshita - http://www.kinoshita.eti.br
* @since 3.1
Expand All @@ -58,7 +57,7 @@ public abstract class AbstractTestNGResultSeeker extends ResultSeeker {

public static final String TEXT_XML_CONTENT_TYPE = "text/xml";

protected final TestNGParser parser = new TestNGParser();
protected transient TestNGParser _parser = null;

private boolean attachTestNGXML = false;

Expand All @@ -70,6 +69,14 @@ public AbstractTestNGResultSeeker(String includePattern, String keyCustomField,
this.markSkippedTestAsBlocked = markSkippedTestAsBlocked;
}

@Nonnull
protected TestNGParser getParser() {
if (_parser == null) {
_parser = new TestNGParser();
}
return _parser;
}

public void setAttachTestNGXML(boolean attachTestNGXML) {
this.attachTestNGXML = attachTestNGXML;
}
Expand All @@ -92,7 +99,7 @@ protected void handleResult(TestCaseWrapper automatedTestCase, AbstractBuild<?,
final int executionId = testlink.updateTestCase(automatedTestCase);

if(executionId > 0 && this.isAttachTestNGXML()) {
Attachment attachment = build.getWorkspace().act( new FileCallable<Attachment>() {
Attachment attachment = build.getWorkspace().act( new MasterToSlaveFileCallable<Attachment>() {

private static final long serialVersionUID = -5411683541842375558L;

Expand All @@ -112,11 +119,6 @@ public Attachment invoke(File f,

return attachment;
}

@Override
public void checkRoles(RoleChecker roleChecker) throws SecurityException {
roleChecker.check((RoleSensitive) this, Role.UNKNOWN);
}
});
testlink.uploadAttachment(executionId, attachment);
}
Expand Down
Expand Up @@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.List;

import jenkins.MasterToSlaveFileCallable;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.remoting.Role;
import org.jenkinsci.remoting.RoleChecker;
Expand Down Expand Up @@ -92,7 +93,7 @@ public String getDisplayName() {
public void seek(TestCaseWrapper[] automatedTestCases, AbstractBuild<?, ?> build, Launcher launcher, final BuildListener listener, TestLinkSite testlink) throws ResultSeekerException {
listener.getLogger().println( Messages.Results_TestNG_LookingForTestSuites() );
try {
final List<Suite> suites = build.getWorkspace().act(new FilePath.FileCallable<List<Suite>>() {
final List<Suite> suites = build.getWorkspace().act(new MasterToSlaveFileCallable<List<Suite>>() {
private static final long serialVersionUID = 1L;

private List<Suite> suites = new ArrayList<Suite>();
Expand All @@ -103,19 +104,14 @@ public List<Suite> invoke(File workspace, VirtualChannel channel)

for(String xml : xmls) {
final File input = new File(workspace, xml);
List <Suite> suitz = parser.parse(input);
List <Suite> suitz = getParser().parse(input);
for(Suite suite : suitz){
suites.add(suite);
}
}

return suites;
}

@Override
public void checkRoles(RoleChecker roleChecker) throws SecurityException {
roleChecker.check((RoleSensitive) this, Role.UNKNOWN);
}
});
for(Suite suite : suites) {
for(Test test : suite.getTests() ) {
Expand Down

0 comments on commit 9d4b1cc

Please sign in to comment.