Skip to content
Merged
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The class could be actually made static, but it needs update of the bundled lib

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe should be volatile.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Does not matter much. In the worst case there will be two instances of a same class which actually has no dynamic context at all. The class methods should be reworked to static, I just decided not to do breaking changes in this PR


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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,16 @@
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;
import org.jenkinsci.remoting.RoleSensitive;
import org.kohsuke.stapler.DataBoundConstructor;

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

import br.eti.kinoshita.testlinkjavaapi.constants.ExecutionStatus;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
Expand All @@ -61,8 +57,6 @@
public class TestNGMethodNameDataProviderNameResultSeeker extends AbstractTestNGResultSeeker {

private static final long serialVersionUID = -3337191837294608305L;

private final TestNGParser parser = new TestNGParser();

private final String dataProviderNameKeyCustomField;

Expand Down Expand Up @@ -112,7 +106,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_LookingForTestMethodDataProvider() );
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 @@ -123,19 +117,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
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,16 @@
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;
import org.jenkinsci.remoting.RoleSensitive;
import org.kohsuke.stapler.DataBoundConstructor;

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

import br.eti.kinoshita.testlinkjavaapi.constants.ExecutionStatus;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
Expand All @@ -61,9 +57,7 @@
public class TestNGMethodNameResultSeeker extends AbstractTestNGResultSeeker {

private static final long serialVersionUID = 3885800916930897675L;

private final TestNGParser parser = new TestNGParser();


/**
* @param includePattern
* @param keyCustomField
Expand Down Expand Up @@ -95,7 +89,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_LookingForTestMethod() );
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 @@ -106,19 +100,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
Loading