Skip to content

Add publish pipeline step #14

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

Open
wants to merge 3 commits 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
20 changes: 15 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
plugins {
id 'org.jenkins-ci.jpi' version '0.17.0'
id 'com.github.hierynomus.license' version '0.12.1'
id 'org.jenkins-ci.jpi' version '0.32.0'
id 'com.github.hierynomus.license' version '0.12.1'
}

group = 'org.jenkins-ci.plugins'
version = '1.9-SNAPSHOT'
version = '1.10-SNAPSHOT'
description = 'Provides an easy way to execute and report Clang scan-build errors using jenkins'

license {
header = file('LICENSE.mit')
}

repositories {
mavenCentral()
}

jenkinsPlugin {
// version of Jenkins core this plugin depends on
coreVersion = '1.609.3'
coreVersion = '2.164.1'

shortName = 'clang-scanbuild'
displayName = 'Clang Scan-Build Plugin'
Expand All @@ -37,7 +41,13 @@ jenkinsPlugin {
}

dependencies {
jenkinsTest 'org.jenkins-ci.plugins:matrix-project:1.6@jar'
testCompile group: 'org.easymock', name: 'easymock', version: '4.0.2'
compile group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-step-api', version: '2.19'

// compile group: 'org.jenkins-ci.plugins', name: 'matrix-project', version: '1.14'
jenkinsPlugins group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-cps', version: '2.68'
jenkinsPlugins group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-job', version: '2.32'
jenkinsPlugins group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-step-api', version: '2.19'
}

defaultTasks 'jpi', 'test'
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon May 09 19:05:02 PDT 2016
#Mon May 27 16:43:52 CEST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
package jenkins.plugins.clangscanbuild;

import hudson.FilePath;
import hudson.model.AbstractBuild;
import hudson.model.Run;


public class ClangScanBuildUtils{
Expand All @@ -37,7 +37,7 @@ public static String getTransparentImagePath(){
return "/plugin/" + SHORTNAME + "/transparent.png";
}

public static FilePath locateClangScanBuildReportFolder( AbstractBuild<?,?> build, String folderName ){
public static FilePath locateClangScanBuildReportFolder(Run<?, ?> build, String folderName ){
if( build == null ) return null;
return new FilePath( new FilePath( build.getRootDir() ), folderName );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@
import hudson.model.AbstractBuild;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.regex.Pattern;
import java.util.logging.Logger;
import static java.util.logging.Level.WARNING;

import static java.util.logging.Level.FINEST;

import hudson.model.Run;
import jenkins.plugins.clangscanbuild.ClangScanBuildUtils;
import jenkins.plugins.clangscanbuild.history.ClangScanBuildBugSummary;

import org.kohsuke.stapler.QueryParameter;
import jenkins.tasks.SimpleBuildStep;
import org.kohsuke.stapler.StaplerProxy;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
Expand All @@ -47,7 +51,7 @@
*
* @author Josh Kennedy
*/
public class ClangScanBuildAction implements Action, StaplerProxy, ModelObject{
public class ClangScanBuildAction implements Action, SimpleBuildStep.LastBuildAction, StaplerProxy, ModelObject{
private static final Logger LOGGER = Logger.getLogger(ClangScanBuildAction.class.getName());

public static final String BUILD_ACTION_URL_NAME = "clangScanBuildBugs";
Expand All @@ -56,64 +60,25 @@ public class ClangScanBuildAction implements Action, StaplerProxy, ModelObject{
private boolean markBuildUnstable;
private int bugCount;
private String outputFolderName;

public Run<?,?> build;
private final List<ClangScanBuildProjectAction> projectActions;

private Pattern APPROVED_REPORT_REQUEST_PATTERN = Pattern.compile( "[^.\\\\/]*\\.html|StaticAnalyzer.*\\.html" );

public ClangScanBuildAction( AbstractBuild<?,?> build, int bugCount, boolean markBuildUnstable,
int bugThreshold, FilePath bugSummaryXML, String outputFolderName ){
public ClangScanBuildAction(Run<?, ?> build, int bugCount, boolean markBuildUnstable,
int bugThreshold, FilePath bugSummaryXML, String outputFolderName ){
this.bugThreshold = bugThreshold;
this.bugCount = bugCount;
this.bugSummaryXML = bugSummaryXML;
this.markBuildUnstable = markBuildUnstable;
this.build = build;
this.outputFolderName = outputFolderName;
}

public AbstractBuild<?,?> build;

public boolean buildFailedDueToExceededThreshold(){
if( !markBuildUnstable ) return false;
return getBugCount() > bugThreshold;
}

public int getBugThreshhold(){
return bugThreshold;
List<ClangScanBuildProjectAction> projectActions = new ArrayList<>();
projectActions.add(new ClangScanBuildProjectAction(build.getParent()));
this.projectActions = projectActions;
}

/**
* The only thing stored in the actual builds in the bugCount and bugThreshold. This was done in order to make the
* build XML smaller to reduce load times. The counts are need in order to render the trend charts.
*
* This method actually loads the XML file that was generated at build time and placed alongside the clang output files
* This XML contains the list of bugs and is used to render the report which links to the clang files.
*
* DON'T CALL THIS UNLESS YOU NEED THE ACTUAL BUG SUMMARY
*/
public ClangScanBuildBugSummary loadBugSummary(){
if( bugSummaryXML == null ) return null;

try{
if( bugSummaryXML.length() != 0 )
{
return (ClangScanBuildBugSummary) AbstractBuild.XSTREAM.fromXML( bugSummaryXML.read() );
}
else
{
return null;
}
}catch( java.lang.InterruptedException ie ){
LOGGER.log(FINEST, "", ie);
return null;
}catch( IOException ioe ){
LOGGER.log(FINEST, "", ioe);
return null;
}
}

public int getBugCount(){
return bugCount;
}


/**
* Indicates which icon should be displayed next to the link
*/
Expand Down Expand Up @@ -149,7 +114,59 @@ public String getUrlName() {
public Object getTarget(){
return this;
}


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

public Run<?, ?> getBuild() {
return build;
}

public int getBugCount(){
return bugCount;
}

public boolean buildFailedDueToExceededThreshold(){
if( !markBuildUnstable ) return false;
return getBugCount() > bugThreshold;
}

public int getBugThreshhold(){
return bugThreshold;
}

/**
* The only thing stored in the actual builds in the bugCount and bugThreshold. This was done in order to make the
* build XML smaller to reduce load times. The counts are need in order to render the trend charts.
*
* This method actually loads the XML file that was generated at build time and placed alongside the clang output files
* This XML contains the list of bugs and is used to render the report which links to the clang files.
*
* DON'T CALL THIS UNLESS YOU NEED THE ACTUAL BUG SUMMARY
*/
public ClangScanBuildBugSummary loadBugSummary(){
if( bugSummaryXML == null ) return null;

try{
if( bugSummaryXML.length() != 0 )
{
return (ClangScanBuildBugSummary) AbstractBuild.XSTREAM.fromXML( bugSummaryXML.read() );
}
else
{
return null;
}
}catch( java.lang.InterruptedException ie ){
LOGGER.log(FINEST, "", ie);
return null;
}catch( IOException ioe ){
LOGGER.log(FINEST, "", ioe);
return null;
}
}

/**
* This method is used to serve up report HTML files from the hidden build folder. It essentially exposes
* the reports to the web.
Expand Down Expand Up @@ -187,5 +204,4 @@ private String trimFirstSlash( String path ){
if( !path.startsWith("/") ) return path.trim();
return path.substring(1).trim();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import hudson.model.Action;
import hudson.model.AbstractProject;
import hudson.model.Job;
import hudson.util.ChartUtil;

import java.io.IOException;
Expand All @@ -47,25 +48,18 @@
public class ClangScanBuildProjectAction implements Action{

private static final String DEFAULT_IMAGE = "/images/headless.png";
public final AbstractProject<?,?> project;
private ClangScanBuildHistoryGatherer gatherer = new ClangScanBuildHistoryGathererImpl();

public ClangScanBuildProjectAction( AbstractProject<?,?> project ) {
super();

public final Job<?,?> project;

public ClangScanBuildProjectAction(Job<?,?> project ) {
this.project = project;
}

@Override
public String getIconFileName() {
return ClangScanBuildUtils.getIconsPath() + "scanbuild-32x32.png";
}

/**
* Doing this wastefully because i do not know the lifecycle of this object. Is it a singleton?
*/
public ClangBuildGraph getGraph(){
return new ClangBuildGraph( gatherer.gatherHistoryDataSet( project.getLastBuild() ) );
}

@Override
public String getDisplayName() {
Expand All @@ -77,6 +71,17 @@ public String getUrlName() {
return "clangScanBuildTrend";
}

public Job<?, ?> getProject() {
return project;
}

/**
* Doing this wastefully because i do not know the lifecycle of this object. Is it a singleton?
*/
public ClangBuildGraph getGraph(){
return new ClangBuildGraph( gatherer.gatherHistoryDataSet( project.getLastBuild() ) );
}

public void doGraph( StaplerRequest req, StaplerResponse rsp ) throws IOException {
if( ChartUtil.awtProblemCause != null ){
rsp.sendRedirect2( req.getContextPath() + DEFAULT_IMAGE );
Expand All @@ -90,9 +95,8 @@ public void doMap( StaplerRequest req, StaplerResponse rsp ) throws IOException
getGraph().doMap( req, rsp );
}

public boolean buildDataExists(){
List<GraphPoint> points = gatherer.gatherHistoryDataSet( project.getLastBuild() );
return points.size() > 0;
}

public boolean buildDataExists() {
List<GraphPoint> points = gatherer.gatherHistoryDataSet(project.getLastBuild());
return points.size() > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
*/
package jenkins.plugins.clangscanbuild.history;

import hudson.model.AbstractBuild;

import java.util.List;

import hudson.model.Run;
import jenkins.plugins.clangscanbuild.reports.GraphPoint;

public interface ClangScanBuildHistoryGatherer {

public List<GraphPoint> gatherHistoryDataSet( AbstractBuild<?,?> latestBuild );
public List<GraphPoint> gatherHistoryDataSet(Run<?, ?> latestBuild );

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.List;

import hudson.model.Run;
import jenkins.plugins.clangscanbuild.actions.ClangScanBuildAction;
import jenkins.plugins.clangscanbuild.reports.GraphPoint;

Expand All @@ -42,12 +43,12 @@ public ClangScanBuildHistoryGathererImpl( int numberOfBuildsToGather ){
this.numberOfBuildsToGather = numberOfBuildsToGather;
}

public List<GraphPoint> gatherHistoryDataSet( AbstractBuild<?,?> latestBuild ){
public List<GraphPoint> gatherHistoryDataSet(Run<?, ?> latestBuild ){
List<GraphPoint> points = new ArrayList<GraphPoint>();
if( latestBuild == null ) return points;

int gatheredBuilds = 0;
for( AbstractBuild<?,?> build = latestBuild; build != null; build = build.getPreviousBuild() ){
for( Run<?,?> build = latestBuild; build != null; build = build.getPreviousBuild() ){
if( gatheredBuilds >= numberOfBuildsToGather ) return points;

ClangScanBuildAction action = build.getAction( ClangScanBuildAction.class );
Expand Down
Loading