Skip to content
Merged
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
21 changes: 8 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.9</version>
<version>3.43</version>
</parent>

<artifactId>cppcheck</artifactId>
<packaging>hpi</packaging>
<name>Jenkins Cppcheck Plug-in</name>
<version>1.25-SNAPSHOT</version>
<version>1.26-SNAPSHOT</version>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Cppcheck+Plugin</url>

<licenses>
Expand Down Expand Up @@ -48,15 +48,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<jaxb.api.version>2.2.1</jaxb.api.version>
<jaxb.impl.version>2.2.1.1</jaxb.impl.version>
<jaxb.version>2.3.0</jaxb.version>
<jaxb2.maven.plugin.version>2.1</jaxb2.maven.plugin.version>
<java2html.version>5.0</java2html.version>
<junit.version>4.12</junit.version>
<mockito.version>1.8.5</mockito.version>
<dashboard.view.version>2.0</dashboard.view.version>
<jenkins.version>2.60.3</jenkins.version>
<java.level>7</java.level>
<java.level>8</java.level>
</properties>

<repositories>
Expand All @@ -80,16 +79,12 @@
<artifactId>structs</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb.api.version}</version>
</dependency>


<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>${jaxb.impl.version}</version>
<groupId>io.jenkins.plugins</groupId>
<artifactId>jaxb</artifactId>
<version>${jaxb.version}</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@

import hudson.model.*;
import org.kohsuke.stapler.StaplerProxy;
import jenkins.model.RunAction2;

public abstract class AbstractCppcheckBuildAction extends Actionable implements Action, HealthReportingAction, StaplerProxy {
protected Run<?, ?> owner;
public abstract class AbstractCppcheckBuildAction extends Actionable implements RunAction2, HealthReportingAction, StaplerProxy {
protected transient Run<?, ?> owner;

protected AbstractCppcheckBuildAction(Run<?, ?> owner) {
this.owner = owner;
Expand All @@ -49,4 +50,16 @@ public <T extends AbstractCppcheckBuildAction> T getPreviousResult() {
public Run<?, ?> getOwner() {
return owner;
}

public void setOwner(Run<?,?> owner) {
this.owner = owner;
}

public void onAttached(Run<?,?> r) {
setOwner(r);
}

public void onLoad(Run<?,?> r) {
setOwner(r);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import com.thalesgroup.hudson.plugins.cppcheck.util.AbstractCppcheckBuildAction;
Expand All @@ -17,32 +18,33 @@
import org.jenkinsci.plugins.cppcheck.config.CppcheckConfigSeverityEvaluation;
import org.jenkinsci.plugins.cppcheck.util.CppcheckBuildHealthEvaluator;

import javax.annotation.Nonnull;

/**
* @author Gregory Boissinot
*/
public class CppcheckBuildAction extends AbstractCppcheckBuildAction implements SimpleBuildStep.LastBuildAction {

public static final String URL_NAME = "cppcheckResult";

private CppcheckResult result;
private final CppcheckResult result;
private final CppcheckConfig config;

private List<CppcheckProjectAction> projectActions;
/**
* The health report percentage.
*
* @since 1.15
*/
private int healthReportPercentage;

public CppcheckBuildAction(Run<?, ?> owner, CppcheckResult result, CppcheckConfig config,
public CppcheckBuildAction(@Nonnull Run<?, ?> owner, @Nonnull CppcheckResult result, @Nonnull CppcheckConfig config,
int healthReportPercentage) {
super(owner);

this.result = result;
this.config = config;
this.healthReportPercentage = healthReportPercentage;

List<CppcheckProjectAction> projectActions = new ArrayList<>();
projectActions.add(new CppcheckProjectAction(owner, config.getConfigGraph()));
this.projectActions = projectActions;

}

public String getIconFileName() {
Expand All @@ -65,6 +67,10 @@ public CppcheckResult getResult() {
return this.result;
}

public CppcheckConfig getConfig() {
return this.config;
}

Run<?, ?> getBuild() {
return this.owner;
}
Expand Down Expand Up @@ -121,6 +127,18 @@ private Object readResolve() {

@Override
public Collection<? extends Action> getProjectActions() {
return this.projectActions;

if (this.owner == null) {
return Collections.emptySet();
} else {
return Collections.singleton(new CppcheckProjectAction(owner.getParent()));
}
}

@Override
public synchronized void setOwner(Run<?,?> owner) {
super.setOwner(owner);

this.result.setOwner(owner);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.util.Calendar;
import javax.annotation.Nonnull;
import hudson.model.AbstractProject;
import hudson.model.Job;
import hudson.model.Run;
Expand All @@ -21,77 +22,38 @@
* @author Gregory Boissinot
*/
public class CppcheckProjectAction extends AbstractCppcheckProjectAction {
/** Cppcheck graph configuration. */
private final CppcheckConfigGraph configGraph;

public String getSearchUrl() {
return getUrlName();
}
public CppcheckProjectAction(final Run<?, ?> run,
CppcheckConfigGraph configGraph) {
super(run);
this.configGraph = configGraph;
}

private boolean isRunCompleted(Run<?, ?> run) {
if (run == null) {
return false;
}

if (run.isBuilding()) {
return false;
}

if (run.getResult() == Result.SUCCESS || run.getResult() == Result.UNSTABLE) {
return true;
}

return false;
public CppcheckProjectAction(@Nonnull final Job<?, ?> job) {
super(job);
}


@Override
public Run<?, ?> getLastFinishedBuild() {
// get the very last build - no matter of its result or buildstate and search towards previous builds until the first successful or unstable result was found.
Run<?, ?> prevCompletedRun = run.getPreviousBuild();

Run<?, ?> lastRun = prevCompletedRun;
if (lastRun != null)
{
while(lastRun != null && lastRun.getNextBuild() != null) {
lastRun = lastRun.getNextBuild();
}
}
else
{
return prevCompletedRun;
}

while(lastRun != null) {
if (isRunCompleted(lastRun)) {
return lastRun;

}
lastRun = lastRun.getPreviousBuild();
}

return null;
}
Run<?, ?> lastBuild = getJob().getLastBuild();
while (lastBuild != null
&& (lastBuild.isBuilding() || lastBuild.getAction(CppcheckBuildAction.class) == null))
{
lastBuild = lastBuild.getPreviousBuild();
}

public final Run<?, ?> getProject() {
CppcheckBuildAction lastAction = getLastFinishedBuildAction();
return (lastAction != null) ? lastAction.getOwner() : null;
}

public Run<?,?> getRun() {
return super.run;
return lastBuild;
}
/**
* Get build action of the last finished build.
*
* @return the build action or null
*/
public CppcheckBuildAction getLastFinishedBuildAction() {
Run<?, ?> lastBuild = getLastFinishedBuild();
return (lastBuild != null) ? lastBuild.getAction(CppcheckBuildAction.class) : null;

@Override
public Run<?, ?> getLastResultBuild() {
for (Run<?, ?> b = getJob().getLastBuild(); b != null; b = b.getPreviousBuiltBuild())
{
CppcheckBuildAction r = b.getAction(CppcheckBuildAction.class);

if (r != null)
return b;
}
return null;
}

public final boolean isDisplayGraph() {
Expand All @@ -101,36 +63,24 @@ public final boolean isDisplayGraph() {
return false;
}

//Affect previous
b = b.getPreviousBuild();
if (b != null) {

for (; b != null; b = b.getPreviousBuild()) {
if (b.getResult().isWorseOrEqualTo(Result.FAILURE)) {
continue;
}
CppcheckBuildAction action = b.getAction(CppcheckBuildAction.class);
if (action == null || action.getResult() == null) {
continue;
}
CppcheckResult result = action.getResult();
if (result == null)
continue;

return true;
}
}
return false;
}
// Affect previous
for (b = b.getPreviousBuild(); b != null; b = b.getPreviousBuild())
{
if (b.getResult() == null || b.getResult().isWorseOrEqualTo(Result.FAILURE))
continue;

public Integer getLastResultBuild() {
Run<?, ?> b = getLastFinishedBuild();
if (b != null) {
return b.getNumber();
}
return null;
}
CppcheckBuildAction action = b.getAction(CppcheckBuildAction.class);
if (action == null ||
action.getResult() == null ||
action.getConfig() == null ||
action.getConfig().getConfigGraph() == null)
continue;

return true;
}

return false;
}

public String getDisplayName() {
return Messages.cppcheck_CppcheckResults();
Expand All @@ -153,25 +103,37 @@ public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException
return;
}

Graph g = new CppcheckGraph(lastBuild, getDataSetBuilder().build(),
Messages.cppcheck_NumberOfErrors(),
configGraph.getXSize(),
configGraph.getYSize());
Run<?, ?> lastBuildWithResult = getLastResultBuild();
CppcheckBuildAction lastAction = lastBuildWithResult.getAction(CppcheckBuildAction.class);
CppcheckConfigGraph configGraph = (lastAction != null) ?
((lastAction.getConfig() != null) ?
lastAction.getConfig().getConfigGraph() : null) : null;

if (configGraph == null) {
rsp.sendRedirect2(req.getContextPath() + "/images/headless.png");
return;
}

Graph g = new CppcheckGraph(lastBuild, getDataSetBuilder(configGraph).build(), Messages.cppcheck_NumberOfErrors(),
configGraph.getXSize(), configGraph.getYSize());
g.doPng(req, rsp);
}

private DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel> getDataSetBuilder() {
private DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel> getDataSetBuilder(CppcheckConfigGraph configGraph) {
DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel> dsb
= new DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel>();

if (configGraph == null)
return dsb;

Run<?,?> lastBuild = getLastFinishedBuild();
CppcheckBuildAction lastAction = lastBuild.getAction(CppcheckBuildAction.class);

int numBuilds = 0;

// numBuildsInGraph <= 1 means unlimited
for (CppcheckBuildAction a = lastAction;
a != null && (configGraph.getNumBuildsInGraph() <= 1 || numBuilds < configGraph.getNumBuildsInGraph());
(a != null) && (configGraph.getNumBuildsInGraph() <= 1 || numBuilds < configGraph.getNumBuildsInGraph());
a = a.getPreviousResult(), ++numBuilds) {

ChartUtil.NumberOnlyBuildLabel label = new ChartUtil.NumberOnlyBuildLabel(a.getOwner());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ public CppcheckStatistics getStatistics() {
return statistics;
}

public Run<?, ?> getOwner() {
public synchronized Run<?, ?> getOwner() {
return owner;
}

public synchronized void setOwner(Run<?,?> owner) {
this.owner = owner;
}

public CppcheckSourceContainer getCppcheckSourceContainer() {
return lazyLoadSourceContainer();
}
Expand Down
Loading