Skip to content
Open
19 changes: 18 additions & 1 deletion src/main/java/org/tap4j/plugin/AbstractTapProjectAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,33 @@
*/
package org.tap4j.plugin;

import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.tasks.test.TestResultProjectAction;

/**
* Base class for TAP Project action.
*
* @author Bruno P. Kinoshita - http://www.kinoshita.eti.br
* @since 1.0
*/
public class AbstractTapProjectAction implements Action {
public class AbstractTapProjectAction extends TestResultProjectAction implements Action {
protected AbstractProject<?, ?> project;


public AbstractTapProjectAction(AbstractProject<?, ?> project) {
super(project);
this.project = project;
}

public AbstractProject<?, ?> getProject() {
return this.project;
}

protected Class<TapBuildAction> getBuildActionClass() {
return TapBuildAction.class;
}

public static final String URL_NAME = "tapResults";
public static final String ICON_NAME = "/plugin/tap/icons/tap-24.png";

Expand Down
31 changes: 30 additions & 1 deletion src/main/java/org/tap4j/plugin/TapBuildAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@

import hudson.model.Action;
import hudson.model.AbstractBuild;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixRun;

import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;

import org.kohsuke.stapler.StaplerProxy;
import org.tap4j.plugin.model.TapStreamResult;

/**
* TAP Build action with TAP results.
Expand Down Expand Up @@ -89,6 +94,24 @@ public String getUrlName() {
return URL_NAME;
}

public List<TapBuildAction> getChildren()
{
if(this.build instanceof MatrixBuild)
{
List<TapBuildAction> actions = new ArrayList();

MatrixBuild b = (MatrixBuild)this.build;
for(MatrixRun run : b.getRuns())
{
actions.add(run.getAction(TapBuildAction.class));
}
return actions;
}
else
{
return null;
}
}
/**
* @return the build
*/
Expand Down Expand Up @@ -124,5 +147,11 @@ public TapBuildAction getPreviousAction() {

return previousAction;
}


public TapStreamResult getStreamResult()
{
TapTestResultAction action = build.getAction(TapTestResultAction.class);
TapStreamResult result = (TapStreamResult) action.getResult();
return result;
}
}
195 changes: 195 additions & 0 deletions src/main/java/org/tap4j/plugin/TapBuildHistoryAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/*
* The MIT License
*
* Copyright 2016 Jenkins.
*
* 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.
*/
package org.tap4j.plugin;

import hudson.matrix.MatrixConfiguration;
import hudson.matrix.MatrixProject;
import hudson.model.AbstractProject;
import hudson.model.ProminentProjectAction;
import hudson.model.Run;
import org.tap4j.model.TestResult;
import org.tap4j.util.DirectiveValues;
import org.tap4j.plugin.model.TestSetMap;
import java.util.List;
import java.util.ArrayList;

/**
*
* @author evandy
*/
public class TapBuildHistoryAction implements ProminentProjectAction {

public class HistoryResult
{
private final String status;
private final String directive;

public HistoryResult(String status, String directive)
{
this.status = status;
this.directive = directive;
}

public String getStatus() { return this.status; }
public String getDirective() { return this.directive; }
}

private final Integer maxBuildsToShow;
private final AbstractProject<?, ?> project;

public TapBuildHistoryAction(AbstractProject<?, ?> project, Integer maxBuildsToShow) {
this.project = project;
this.maxBuildsToShow = maxBuildsToShow;
}

public AbstractProject<?, ?> getProject() {
return this.project;
}

protected Class<TapBuildAction> getBuildActionClass() {
return TapBuildAction.class;
}

@Override
public String getIconFileName() {
return "/plugin/tap/icons/tap-24.png";
}

@Override
public String getDisplayName() {
return "Tap Test History";
}

@Override
public String getUrlName() {
return "tapHistory";
}

public String getTitle() {
if(getProject() instanceof MatrixConfiguration)
{
MatrixConfiguration p = (MatrixConfiguration)getProject();
return p.getParent().getDisplayName() + ": " + p.getDisplayName();
}
else
{
return getProject().getDisplayName();
}
}

public List<Run<?,?> > getBuilds()
{
List<Run<?,?> > builds = new ArrayList();

// Matrix configurations should list against the parent's build list
if(getProject() instanceof MatrixConfiguration)
{
MatrixConfiguration p = (MatrixConfiguration)getProject();
for (Run<?, ?> build = p.getParent().getLastBuild(); build != null; build = build.getPreviousBuild()) {
builds.add(build);
if(builds.size() >= this.maxBuildsToShow)
{
break;
}
}
}
else
{
for (Run<?, ?> build = getProject().getLastBuild(); build != null; build = build.getPreviousBuild()) {
builds.add(build);
if(builds.size() >= this.maxBuildsToShow)
{
break;
}
}
}
return builds;
}

public List<TapBuildHistoryAction> getChildren()
{
if(!(getProject() instanceof MatrixProject))
{
return null;
}
else
{
MatrixProject mp = (MatrixProject)getProject();
List<TapBuildHistoryAction> children = new ArrayList();
for (MatrixConfiguration configuration : mp.getActiveConfigurations())
{
AbstractProject<?, ?> p = configuration;
TapBuildHistoryAction c = p.getAction(TapBuildHistoryAction.class);
if(c != null)
{
children.add(c);
}
}
return children;
}
}
public List<TestSetMap> getTestSets()
{
Run<?,?> lastBuild = getProject().getLastBuild();

if(lastBuild == null) {
return null;
}

TapBuildAction action = lastBuild.getAction(getBuildActionClass());
return action.getResult().getTestSets();
}

public HistoryResult getBuildStatus(TestSetMap set, TestResult result, Run<?,?> b)
{
// If a sub to a matrix project, given the parent's build, so grab the
// right one.
Run<?,?> build = getProject().getBuildByNumber(b.getNumber());
TapBuildAction action = build != null ? build.getAction(getBuildActionClass()) : null;
if(action == null)
{
// No TAP results for this build
return new HistoryResult("","");
}

for(TestSetMap map : action.getResult().getTestSets())
{
if(map.getFileName().equals(set.getFileName()))
{
for(TestResult r : map.getTestSet().getTestResults())
{
if(r.getDescription().equals(result.getDescription()))
{
org.tap4j.model.Directive d = r.getDirective();
return new HistoryResult(r.getStatus().toString().toUpperCase(),
d==null?"":d.getDirectiveValue().toString().toUpperCase());
}
}
return new HistoryResult("","");
//break; // Not found; don't keep looking
}
}
return new HistoryResult("","");
}
}
Loading