Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tag include and exclude options #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
51 changes: 47 additions & 4 deletions src/main/java/hudson/plugins/robot/RobotParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package hudson.plugins.robot;

import org.apache.commons.lang.StringUtils;

import hudson.AbortException;
import hudson.FilePath;
import hudson.Util;
Expand Down Expand Up @@ -44,10 +46,12 @@

public class RobotParser {

public RobotResult parse(String outputFileLocations, String outputPath, Run<?, ?> build, FilePath workSpace, String logFileName, String reportFileName)
public RobotResult parse(String outputFileLocations, String outputPath, Run<?, ?> build,
FilePath workSpace, String logFileName, String reportFileName,
String includeTags[], String excludeTags[])
throws InterruptedException, IOException {
RobotResult result = new FilePath(workSpace, outputPath).act(
new RobotParserCallable(outputFileLocations, logFileName, reportFileName));
new RobotParserCallable(outputFileLocations, logFileName, reportFileName, includeTags, excludeTags));
return result;
}

Expand All @@ -58,11 +62,29 @@ public static final class RobotParserCallable implements
private final String outputFileLocations;
private final String logFileName;
private final String reportFileName;
private final String[] includeTags;
private final String[] excludeTags;

private String[] filterTags(String tags[]) {
List<String> out = new ArrayList<String>();
if (tags != null) {
for (String tag : tags) {
tag = StringUtils.strip(tag);
if (StringUtils.isNotEmpty(tag)) {
out.add(tag);
}
}
}
return out.toArray(new String[0]);
}

public RobotParserCallable(String outputFileLocations, String logFileName, String reportFileName) {
public RobotParserCallable(String outputFileLocations, String logFileName, String reportFileName,
String includeTags[], String excludeTags[]) {
this.outputFileLocations = outputFileLocations;
this.logFileName = logFileName;
this.reportFileName = reportFileName;
this.includeTags = filterTags(includeTags);
this.excludeTags = filterTags(excludeTags);
}

public RobotResult invoke(File ws, VirtualChannel channel)
Expand Down Expand Up @@ -151,7 +173,28 @@ private RobotSuiteResult processSuite(XMLStreamReader reader, RobotTestObject pa
} else if("suite".equals(tagName)){
suite.addChild(processSuite(reader, suite, baseDirectory));
} else if("test".equals(tagName)){
suite.addCaseResult(processTest(reader, suite));
RobotCaseResult test = processTest(reader, suite);
List<String> tags = test.getTags();
// If no include tags are given, default is to include
boolean include = includeTags.length == 0;

for (String tag : includeTags) {
if (tags.contains(tag)) {
include = true;
break;
}
}

for (String tag : excludeTags) {
if (tags.contains(tag)) {
include = false;
break;
}
}

if (include) {
suite.addCaseResult(test);
}
} else if("kw".equals(tagName) && "teardown".equals(reader.getAttributeValue(null, "type"))) {
ignoreUntilStarts(reader, "status");
if ("FAIL".equals(reader.getAttributeValue(null, "status"))) {
Expand Down
36 changes: 34 additions & 2 deletions src/main/java/hudson/plugins/robot/RobotPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class RobotPublisher extends Recorder implements Serializable,
final private double unstableThreshold;
private String[] otherFiles;
final private boolean enableCache;
private String[] includeTags;
private String[] excludeTags;

//Default to true
private boolean onlyCritical = true;
Expand Down Expand Up @@ -91,12 +93,17 @@ public class RobotPublisher extends Recorder implements Serializable,
* Other files to be saved
* @param enableCache
* True if caching is used
* @param includeTags
* Include only tests with these tags
* @param excludeTags
* Exclude tests with these tags
*/
@DataBoundConstructor
public RobotPublisher(String outputPath, String outputFileName,
boolean disableArchiveOutput, String reportFileName, String logFileName,
double passThreshold, double unstableThreshold,
boolean onlyCritical, String otherFiles, boolean enableCache) {
boolean onlyCritical, String otherFiles, boolean enableCache,
String includeTags, String excludeTags) {
this.outputPath = outputPath;
this.outputFileName = outputFileName;
this.disableArchiveOutput = disableArchiveOutput;
Expand All @@ -114,6 +121,14 @@ public RobotPublisher(String outputPath, String outputFileName,
}
this.otherFiles = filemasks;
}

if (includeTags != null) {
this.includeTags = includeTags.split("[, ]+");
}

if (excludeTags != null) {
this.excludeTags = excludeTags.split("[, ]+");
}
}

/**
Expand Down Expand Up @@ -204,6 +219,22 @@ public String getOtherFiles() {
return StringUtils.join(otherFiles, ",");
}

/**
* Gets the comma separated list of tags to include
* @return List of tags as string
*/
public String getIncludeTags() {
return StringUtils.join(includeTags, ",");
}

/**
* Gets the comma separated list of tags to exclude
* @return List of tags as string
*/
public String getExcludeTags() {
return StringUtils.join(excludeTags, ",");
}

/**
* {@inheritDoc}
*/
Expand All @@ -218,7 +249,7 @@ public Collection<Action> getProjectActions(AbstractProject<?, ?> project) {
protected RobotResult parse(String expandedTestResults, String outputPath, Run<?,?> build, FilePath workspace,
Launcher launcher, TaskListener listener) throws IOException,
InterruptedException {
return new RobotParser().parse(expandedTestResults, outputPath, build, workspace, getLogFileName(), getReportFileName());
return new RobotParser().parse(expandedTestResults, outputPath, build, workspace, getLogFileName(), getReportFileName(), includeTags, excludeTags);
}

/**
Expand All @@ -229,6 +260,7 @@ public void perform(Run<?, ?> build, FilePath workspace, Launcher launcher, Task
if (build.getResult() != Result.ABORTED) {
PrintStream logger = listener.getLogger();
logger.println(Messages.robot_publisher_started());
logger.println(String.format("Using '%s', '%s'", StringUtils.join(includeTags, ","), StringUtils.join(excludeTags, ",")));
logger.println(Messages.robot_publisher_parsing());
RobotResult result;

Expand Down
28 changes: 27 additions & 1 deletion src/main/java/hudson/plugins/robot/RobotStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class RobotStep extends Step {
private @CheckForNull String[] otherFiles;
private boolean enableCache = true;
private boolean onlyCritical = true;
private @CheckForNull String[] includeTags;
private @CheckForNull String[] excludeTags;



Expand Down Expand Up @@ -89,7 +91,15 @@ public boolean getEnableCache() {
public boolean getOnlyCritical() {
return this.onlyCritical;
}


public String getIncludeTags() {
return StringUtils.join(includeTags, ",");
}

public String getExcludeTags() {
return StringUtils.join(excludeTags, ",");
}

@DataBoundSetter
public void setReportFileName(String reportFileName) {
this.reportFileName = Util.fixEmpty(reportFileName);
Expand Down Expand Up @@ -142,6 +152,22 @@ public void setOtherFiles(String otherFiles) {
}
}

@DataBoundSetter
public void setIncludeTags(String includeTags) {
includeTags = Util.fixEmpty(includeTags);
if (includeTags != null) {
this.includeTags = includeTags.split("[, ]+");
}
}

@DataBoundSetter
public void setExcludeTags(String excludeTags) {
excludeTags = Util.fixEmpty(excludeTags);
if (excludeTags != null) {
this.excludeTags = excludeTags.split("[, ]+");
}
}

@Override
public StepExecution start(StepContext context) throws Exception {
return new RobotStepExecution(this, context);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/hudson/plugins/robot/RobotStepExecution.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public class RobotStepExecution extends SynchronousNonBlockingStepExecution<Void
@Override protected Void run() throws Exception {
FilePath workspace = getContext().get(FilePath.class);
workspace.mkdirs();
RobotPublisher rp = new RobotPublisher(step.getOutputPath(), step.getOutputFileName(), step.getDisableArchiveOutput(), step.getReportFileName(), step.getLogFileName(), step.getPassThreshold(), step.getUnstableThreshold(), step.getOnlyCritical(), step.getOtherFiles(), step.getEnableCache());
RobotPublisher rp = new RobotPublisher(step.getOutputPath(), step.getOutputFileName(),
step.getDisableArchiveOutput(), step.getReportFileName(),
step.getLogFileName(), step.getPassThreshold(), step.getUnstableThreshold(),
step.getOnlyCritical(), step.getOtherFiles(), step.getEnableCache(),
step.getIncludeTags(), step.getExcludeTags());
rp.perform(getContext().get(Run.class), workspace, getContext().get(Launcher.class), getContext().get(TaskListener.class));
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ limitations under the License.
<f:entry title="${%advanced.loghtml}" description="${%advanced.loghtml.description}" field="logFileName">
<f:textbox />
</f:entry>
<f:entry title="${%advanced.includeTags}" description="${%advanced.includeTags.description}" field="includeTags">
<f:textbox />
</f:entry>
<f:entry title="${%advanced.excludeTags}" description="${%advanced.excludeTags.description}" field="excludeTags">
<f:textbox />
</f:entry>
<f:entry title="${%advanced.otherfiles}" description="${%advanced.otherfiles.description}" field="otherFiles">
<f:textbox />
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ advanced.otherfiles=Other files to copy
advanced.otherfiles.description=Comma separated list of robot related artifacts to be saved
advanced.enableCache=Enable cache
advanced.enableCache.description=Enable cache for test results

advanced.includeTags=Include Tags
advanced.includeTags.description=Comma separated list of tags to include
advanced.excludeTags=Exclude Tags
advanced.excludeTags.description=Comma separated list of tags to exclude
thresholds.label=Thresholds for build result
thresholds.onlycritical=Use thresholds for critical tests only
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
<p>Tests that match these tags are completely excluded.</p>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>
<p>Only include tests with these tags.</p>
<p>If empty all tests are included.</p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ limitations under the License.
<f:entry title="${%advanced.loghtml}" description="${%advanced.loghtml.description}" field="logFileName">
<f:textbox />
</f:entry>
<f:entry title="${%advanced.includeTags}" description="${%advanced.includeTags.description}" field="includeTags">
<f:textbox />
</f:entry>
<f:entry title="${%advanced.excludeTags}" description="${%advanced.excludeTags.description}" field="excludeTags">
<f:textbox />
</f:entry>
<f:entry title="${%advanced.otherfiles}" description="${%advanced.otherfiles.description}" field="otherFiles">
<f:textbox />
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ advanced.otherfiles=Other files to copy
advanced.otherfiles.description=Comma separated list of robot related artifacts to be saved
advanced.enableCache=Enable cache
advanced.enableCache.description=Enable cache for test results

advanced.includeTags=Include Tags
advanced.includeTags.description=Comma separated list of tags to include
advanced.excludeTags=Exclude Tags
advanced.excludeTags.description=Comma separated list of tags to exclude
thresholds.label=Thresholds for build result
thresholds.onlycritical=Use thresholds for critical tests only
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
<p>Tests that match these tags are completely excluded.</p>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>
<p>Only include tests with these tags.</p>
<p>If empty all tests are included.</p>
</div>
10 changes: 7 additions & 3 deletions src/test/java/hudson/plugins/robot/RobotPublisherSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ public class RobotPublisherSystemTest {
public void testRoundTripConfig() throws Exception {
FreeStyleProject p = j.jenkins.createProject(FreeStyleProject.class, "testRoundTripConfig");
RobotPublisher before = new RobotPublisher("a", "b", false, "c", "d", 11, 27, true, "dir1/*.jpg, dir2/*.png",
false);
false, "include,include2", "exclude,exclude2");
p.getPublishersList().add(before);
j.configRoundtrip(p);
RobotPublisher after = p.getPublishersList().get(RobotPublisher.class);
assertThat(
"outputPath,outputFileName,reportFileName,logFileName,passThreshold,unstableThreshold,onlyCritical,otherFiles",
"outputPath,outputFileName,reportFileName,logFileName,passThreshold,unstableThreshold,onlyCritical,otherFiles,includeTags,excludeTags",
before, samePropertyValuesAs(after));
}

@Test
public void testConfigView() throws Exception {
FreeStyleProject p = j.jenkins.createProject(FreeStyleProject.class, "testConfigView");
RobotPublisher before = new RobotPublisher("a", "b", false, "c", "d", 11, 27, true, "dir1/*.jpg, dir2/*.png",
false);
false, "include,include2", "exclude,exclude2");
p.getPublishersList().add(before);
HtmlPage page = j.createWebClient().getPage(p, "configure");
WebAssert.assertTextPresent(page, "Publish Robot Framework");
Expand All @@ -82,6 +82,10 @@ public void testConfigView() throws Exception {
WebAssert.assertInputContainsValue(page, "_.reportFileName", "c");
WebAssert.assertInputPresent(page, "_.logFileName");
WebAssert.assertInputContainsValue(page, "_.logFileName", "d");
WebAssert.assertInputPresent(page, "_.includeTags");
WebAssert.assertInputContainsValue(page, "_.includeTags", "include,include2");
WebAssert.assertInputPresent(page, "_.excludeTags");
WebAssert.assertInputContainsValue(page, "_.excludeTags", "exclude,exclude2");
WebAssert.assertInputPresent(page, "_.unstableThreshold");
WebAssert.assertInputContainsValue(page, "_.unstableThreshold", "27.0");
WebAssert.assertInputPresent(page, "_.passThreshold");
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/hudson/plugins/robot/RobotPublisherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected void setUp() throws Exception {
}

private RobotPublisher getRobotPublisher(double passThreshold, double unstableThreshold) {
return new RobotPublisher("", "", false, "", "", passThreshold, unstableThreshold, onlyCritical, "", false);
return new RobotPublisher("", "", false, "", "", passThreshold, unstableThreshold, onlyCritical, "", false, null, null);
}

public void testBlankConfigShouldReturnDefaults() {
Expand Down Expand Up @@ -102,7 +102,7 @@ public void testShouldBeSuccessWithOnlyCritical(){
}

public void testShouldUnstableLowFailures() throws Exception{
RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("low_failure_output.xml", null, null);
RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("low_failure_output.xml", null, null, null, null);
RobotResult result = remoteOperation.invoke(new File(RobotPublisherTest.class.getResource("low_failure_output.xml").toURI()).getParentFile(), null);
result.tally(null);

Expand All @@ -118,7 +118,7 @@ public void testShouldUnstableLowFailures() throws Exception{
}

public void testShouldHandleDurationWithoutTimes() throws Exception {
RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("rebot_output.xml", null, null);
RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("rebot_output.xml", null, null, null, null);
RobotResult result = remoteOperation.invoke(new File(RobotPublisherTest.class.getResource("rebot_output.xml").toURI()).getParentFile(), null);
result.tally(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class RobotGraphHelperTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();

RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("output.xml", null, null);
RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("output.xml", null, null, null, null);
RobotResult result = remoteOperation.invoke(new File(new RobotGraphHelperTest().getClass().getResource("output.xml").toURI()).getParentFile(), null);
result.tally(null);

Expand Down
Loading