Skip to content
Permalink
Browse files
JENKINS-30369: Support specifying result file formats during result p…
…ublishing
  • Loading branch information
stolp committed Sep 9, 2015
1 parent 131239f commit d6a1126a1dea5b63f6f040666cbc2d6d967b1a9e
@@ -56,6 +56,7 @@
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.FileRequestEntity;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
@@ -78,6 +79,34 @@ public class KlarosTestResultPublisher extends Recorder implements Serializable

private static final long serialVersionUID = -3220438013049857329L;

private static final ArrayList<ResultFormat> DEFAULT_FORMATS;

static {
DEFAULT_FORMATS = new ArrayList<ResultFormat>();
DEFAULT_FORMATS.add(new ResultFormat("aunit", "AUnit"));
DEFAULT_FORMATS.add(new ResultFormat("boosttest", "Boost Test"));
DEFAULT_FORMATS.add(new ResultFormat("check", "Check"));
DEFAULT_FORMATS.add(new ResultFormat("cpptestunit", "UnitTest++"));
DEFAULT_FORMATS.add(new ResultFormat("cppunit", "CppUnit"));
DEFAULT_FORMATS.add(new ResultFormat("ctest", "ctest"));
DEFAULT_FORMATS.add(new ResultFormat("cunit", "CUnit"));
DEFAULT_FORMATS.add(new ResultFormat("fpcunit", "Free Pascal Unit"));
DEFAULT_FORMATS.add(new ResultFormat("jubula", "Jubula/GUIDancer"));
DEFAULT_FORMATS.add(new ResultFormat("junit", "JUnit"));
DEFAULT_FORMATS.add(new ResultFormat("mbunit", "MbUnit"));
DEFAULT_FORMATS.add(new ResultFormat("mstest", "MSTest"));
DEFAULT_FORMATS.add(new ResultFormat("nunit", "NUnit"));
DEFAULT_FORMATS.add(new ResultFormat("phpunit", "PHPUnit"));
DEFAULT_FORMATS.add(new ResultFormat("qftest", "QFTest"));
DEFAULT_FORMATS.add(new ResultFormat("qtestlib", "QTestLib"));
DEFAULT_FORMATS.add(new ResultFormat("ranorex", "Ranorex"));
DEFAULT_FORMATS.add(new ResultFormat("tusar", "Tusar"));
DEFAULT_FORMATS.add(new ResultFormat("unittest", "UnitTest"));
DEFAULT_FORMATS.add(new ResultFormat("testcomplete", "Test Complete"));
DEFAULT_FORMATS.add(new ResultFormat("valgrind", "Valgrind"));
DEFAULT_FORMATS.add(new ResultFormat("xunitdotnet", "xUnit.net"));
}

/** The Klaros project id. */
private String config;

@@ -91,7 +120,7 @@ public class KlarosTestResultPublisher extends Recorder implements Serializable
private String sut;

/** The type. */
private String type = "junit";
private String type;

/**
* The path test results.
@@ -116,6 +145,8 @@ public class KlarosTestResultPublisher extends Recorder implements Serializable
/** The create test suite flag. */
private boolean createTestSuite;

private ResultFormat[] types;

/**
* Instantiates a new Klaros test result publisher.
*
@@ -145,6 +176,41 @@ public KlarosTestResultPublisher(final String config, final String iteration, fi
this.url = url;
this.username = username;
this.password = password;
this.type = type;
this.types = null;
}

private ResultFormat[] loadFormats() {

final String strURL = buildServletURL(url) + "/supportedFormats";

GetMethod get = new GetMethod(strURL);
StringBuffer query = new StringBuffer();
if (StringUtils.isNotEmpty(username)) {
query.append("username=").append(username).append("&password=").append(password);
}
get.setQueryString(query.toString());

try {
HttpClient client = new HttpClient();
int result = client.executeMethod(get);
if (result == HttpServletResponse.SC_OK) {
String response = get.getResponseBodyAsString();
if (StringUtils.isNotBlank(response)) {
String[] ids = response.split("=.*\\R");
String[] names = response.split(".*=\\R");
ResultFormat[] formats = new ResultFormat[ids.length];
for (int i=0; i< ids.length; i++ ) {
formats[i] = new ResultFormat(ids[i], names[i]);
}
}
}
} catch (Exception e) {
// ignore
} finally {
get.releaseConnection();
}
return DEFAULT_FORMATS.toArray(new ResultFormat[DEFAULT_FORMATS.size()]);
}

/**
@@ -297,16 +363,49 @@ public void setSut(final String value) {
sut = StringUtils.trim(value);
}

/**
* Checks if the create test suite flag is set.
*
* @return true, if set
*/
public boolean isCreateTestSuite() {

return createTestSuite;
}

/**
* Sets the create test suite flag.
*
* @param createTestSuite the new create test suite flag
*/
public void setCreateTestSuite(boolean createTestSuite) {

this.createTestSuite = createTestSuite;
}

/**
* Gets the valid result types.
*
* @return the valid result types
*/
public ResultFormat[] getTypes() {

if (types == null) {
types = loadFormats();
}
return types;
}

/**
* Sets the valid result types.
*
* @param types the new result types
*/
public void setTypes(ResultFormat[] types) {

this.types = types;
}

/**
* Gets the path test results.
*
@@ -337,7 +436,7 @@ public void setPathTestResults(final String value) {
private void migratePathTestResults() {

if (StringUtils.isNotEmpty(pathTestResults)) {
resultSets = new ResultSet[]{new ResultSet(StringUtils.trim(pathTestResults)) };
resultSets = new ResultSet[]{new ResultSet(StringUtils.trim(pathTestResults), "") };
pathTestResults = null;
}
}
@@ -422,7 +521,7 @@ public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher,
listener.getLogger().println(
"The test result(s) contained in target " + resultSet.getSpec()
+ " will be exported to the " + "Klaros-Testmanagement Server at "
+ getUrl(url) + ".");
+ getUrl(url) + "using the " + resultSet.getFormat() + " format.");
listener.getLogger().print("With parameters Project[" + config + "]");
if (StringUtils.isNotBlank(iteration)) {
listener.getLogger().print(" Iteration[" + iteration + "]");
@@ -582,7 +681,8 @@ public List<Integer> invoke(final File baseDir, final VirtualChannel channel) th
query.append("&iteration=").append(expandVariables(iteration, build));
}
query.append("&env=").append(expandVariables(env, build)).append("&sut=").append(
expandVariables(sut, build)).append("&type=").append(expandVariables(type, build));
expandVariables(sut, build)).append("&type=").append(
expandVariables(resultSet.getFormat(), build));
if (createTestSuite) {
query.append("&createTestSuiteResults=true");
}
@@ -699,7 +799,7 @@ public static final class DescriptorImpl extends BuildStepDescriptor<Publisher>
private List<String> urls = new ArrayList<String>();

/**
* Instantiates a new descriptor impl.
* Instantiates a new descriptor implementation.
*/
public DescriptorImpl() {

@@ -795,8 +895,9 @@ protected FormValidation check() throws IOException, ServletException {
if (findText(open(new URL(cooked)), "Klaros")) {
result = FormValidation.ok();
} else {
result = FormValidation.error( //
"This URL does not point to a running Klaros-Testmanagement installation");
result =
FormValidation
.error("This URL does not point to a running Klaros-Testmanagement installation");
}
} catch (IOException e) {
result = handleIOException(value, e);
@@ -0,0 +1,41 @@
package hudson.plugins.klaros;

public class ResultFormat {

private final String id;
private final String name;

/**
* Instantiates a new result format.
*
* @param id the format id
* @param name the format name
* @param script the script to transform this format
*/
ResultFormat(final String id, final String name) {

this.id = id;
this.name = name;
}

/**
* Gets the id.
*
* @return the id
*/
public String getId() {

return id;
}

/**
* Gets the name.
*
* @return the name
*/
public String getName() {

return name;
}

}
@@ -1,26 +1,87 @@
/*
* Copyright 2003 - 2015 verit Informationssysteme GmbH, Europaallee 10,
* 67657 Kaiserslautern, Germany, http://www.verit.de.
*
* All rights reserved.
*
* This product or document is protected by copyright and distributed
* under licenses restricting its use, copying, distribution, and
* decompilation. No part of this product or documentation may be
* reproduced in any form by any means without prior written authorization
* of verit Informationssysteme GmbH and its licensors, if any.
*/
package hudson.plugins.klaros;

import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* The result set specification.
*/
public class ResultSet {


private static final String DEFAULT_FORMAT = "junit";

private String spec;
private String format;

public ResultSet() {

format = DEFAULT_FORMAT;
}

@DataBoundConstructor
public ResultSet(String spec) {

this.spec = StringUtils.trim(spec);

this(spec, DEFAULT_FORMAT);
}

@DataBoundConstructor
public ResultSet(String spec, String format) {

this.spec = StringUtils.strip(spec);
this.format = StringUtils.strip(format);
if (StringUtils.isBlank(format)) {
format = DEFAULT_FORMAT;
}
}

/**
* Gets the spec.
*
* @return the spec
*/
public String getSpec() {

return spec;
}


/**
* Sets the spec.
*
* @param spec the new spec
*/
public void setSpec(String spec) {

this.spec = StringUtils.trim(spec);
}
}

/**
* Gets the format.
*
* @return the format
*/
public String getFormat() {

return format;
}

/**
* Sets the format.
*
* @param format the new format
*/
public void setFormat(String format) {

this.format = format;
}
}
@@ -94,6 +94,15 @@
checkUrl="'descriptorByName/KlarosTestResultPublisher/check?value='+escape(this.value)" />
</f:entry>

<f:entry title="${%ResultFormat}" field="format"
description="${%ResultFormatDescription}">
<select name="format">
<j:forEach var="t" items="${instance.types}">
<f:option value="${t.id}" selected="${resultSet.format==t.id}">${t.name}</f:option>
</j:forEach>
</select>
</f:entry>

<f:entry title="">
<div align="right">
<f:repeatableDeleteButton />
@@ -34,3 +34,5 @@ Username=Username
Password=Password
Test Connection=Test Connection
Testing...=Testing...
ResultFormat=Result Format
ResultFormatDescription=The format of the uploaded result files
@@ -34,3 +34,5 @@ Username=Benutzername
Password=Passwort
Test Connection=Verbindung testen
Testing...=Teste...
ResultFormat=Ergebnisformat
ResultFormatDescription=Das Format der übertragenen Ergebnisdateien

0 comments on commit d6a1126

Please sign in to comment.