Skip to content

Commit

Permalink
Merge pull request #2 from lbordowitz/FreeLabel
Browse files Browse the repository at this point in the history
[JENKINS-13376] Free the test group label!
  • Loading branch information
lbordowitz committed Jan 5, 2015
2 parents 1a9f51d + 186aae1 commit 0085c51
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 39 deletions.
Expand Up @@ -24,21 +24,30 @@
package hudson.plugins.labeledgroupedtests;


import hudson.Extension;
import hudson.Util;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.tasks.junit.JUnitParser;
import hudson.util.FormValidation;
import hudson.model.Describable;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

/**
* Keeps track of the association between a test result location file mask,
* the parser to invoke, and the label (aka phase) to apply to those results.
*/
public class LabeledTestGroupConfiguration {
public class LabeledTestGroupConfiguration implements Describable<LabeledTestGroupConfiguration>, Comparable<LabeledTestGroupConfiguration> {
private String parserClassName;
private String testResultFileMask;
private String label;
private static final Pattern VALID_LABEL = Pattern.compile("^[a-zA-Z0-9 ]+$");

@DataBoundConstructor
public LabeledTestGroupConfiguration(String parserClassName, String testResultFileMask, String label) {
Expand Down Expand Up @@ -86,6 +95,30 @@ public String toNameString() {
return Util.rawEncode(niceName);
}

public Descriptor<LabeledTestGroupConfiguration> getDescriptor() {
// Copied from AbstractDescribableImpl.java, which isn't available in the current version.
return Hudson.getInstance().getDescriptorOrDie(getClass());
}

@Extension
public static class DescriptorImpl extends Descriptor<LabeledTestGroupConfiguration> {

@Override
public String getDisplayName() {
return StringUtils.EMPTY;
}

public FormValidation doCheckLabel(@QueryParameter String value){
if(VALID_LABEL.matcher(value).matches()){
return FormValidation.ok();
}
else{
return FormValidation.error("Label must be a non-empty, alphanumeric string.");
}
}

}

static Map<String, String> DISPLAY_NAME_MAP = new HashMap<String, String>(5);


Expand All @@ -99,4 +132,7 @@ public String toNameString() {
DISPLAY_NAME_MAP.put("hudson.plugins.cppunitparser.CPPUnitTestResultParser", "cppunit");
}

public int compareTo(LabeledTestGroupConfiguration that) {
return this.getLabel().compareTo(that.getLabel());
}
}
Expand Up @@ -86,10 +86,6 @@ public static List<TestResultParser> getTestResultParsers() {
return testResultParsers;
}

public static List<String> getPhases() {
return Arrays.asList("unit", "smoke", "regression", "integration", "special", "misc");
}

public void debugPrint() {
for (LabeledTestGroupConfiguration config: configs) {
LOGGER.info("got config: " + config.toString());
Expand Down
@@ -0,0 +1,46 @@
<!--
The MIT License
Copyright (c) 2010 Yahoo!, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">

<j:invokeStatic className="hudson.plugins.labeledgroupedtests.LabeledTestResultGroupPublisher" method="getTestResultParsers" var="parsers" />

<f:entry title="Report File Mask" field="testResultFileMask">
<f:textbox />
</f:entry>
<f:entry name="parserClassName" title="Result Format" field="parserClassName">
<select name="parserClassName">
<j:forEach var="parser" items="${parsers}">
<f:option value="${parser.class.name}" selected="${parser.class.name==it.parserClassName}">${parser.displayName}</f:option>
</j:forEach>
</select>
</f:entry>
<f:entry title="Group Label" field="label">
<f:textbox />
</f:entry>
<f:entry title="">
<div align="right">
<f:repeatableDeleteButton value="Delete Test Result Group"/>
</div>
</f:entry>
</j:jelly>
Expand Up @@ -21,41 +21,12 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">

<j:invokeStatic className="hudson.plugins.labeledgroupedtests.LabeledTestResultGroupPublisher" method="getTestResultParsers" var="parsers" />
<j:invokeStatic className="hudson.plugins.labeledgroupedtests.LabeledTestResultGroupPublisher" method="getPhases" var="phases"/>

<f:entry>
<f:repeatable name="configs" var="curConfig" items="${instance.configs}"
add="Add Test Report Group" minimum="1">
<table width="100%">
<f:entry title="">
<f:entry title="Report File Mask">
<f:textbox name="testResultFileMask" value="${curConfig.testResultFileMask}" ></f:textbox>
<f:entry title="Result Format" name="format">
<select name="parserClassName">
<j:forEach var="parser" items="${parsers}">
<f:option value="${parser.class.name}" selected="${parser.class.name==curConfig.parserClassName}">${parser.displayName}</f:option>
</j:forEach>
</select>
</f:entry>

<f:entry title="Group Label">
<select name="label">
<j:forEach var="phase" items="${phases}">
<f:option value="${phase}" selected="${phase==curConfig.label}">${phase}</f:option>
</j:forEach>
</select>
</f:entry>

</f:entry>
</f:entry>
<f:entry title="">
<div align="right">
<f:repeatableDeleteButton value="Delete Test Result Group"/>
</div>
</f:entry>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry field="configs">
<f:repeatable field="configs" add="Add Test Report Group" >
<table style="width:100%">
<st:include page="config.jelly" class="${descriptor.clazz}" />
</table>
</f:repeatable>
</f:entry>
Expand Down

0 comments on commit 0085c51

Please sign in to comment.