Skip to content

Commit

Permalink
Merge pull request #32 from jenkinsci/vgaidarji/make-compatible-with-…
Browse files Browse the repository at this point in the history
…pipeline

[JENKINS-35571] Make compatible with Pipeline
  • Loading branch information
vgaidarji committed Nov 2, 2017
2 parents 2995edb + a012cb6 commit 7141331
Show file tree
Hide file tree
Showing 36 changed files with 858 additions and 283 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,5 @@ work
.classpath
.project
.settings
*.iml
.idea
30 changes: 27 additions & 3 deletions pom.xml
@@ -1,15 +1,24 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.565</version>
<version>2.32</version>
<relativePath/>
</parent>

<properties>
<!-- Baseline Jenkins version you use to build the plugin. Users must have this version or newer to run. -->
<jenkins.version>1.625.3</jenkins.version>
<!-- Java Level to use. Java 7 required when using core >= 1.612 -->
<java.level>7</java.level>
</properties>

<artifactId>plot</artifactId>
<packaging>hpi</packaging>
<name>Plot plugin</name>
<version>1.12-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Plot+Plugin</url>

<developers>
Expand All @@ -21,13 +30,28 @@
<id>ericbn</id>
<name>Eric Nielsen</name>
</developer>
<developer>
<id>vgaidarji</id>
<name>Veaceslav Gaidarji</name>
<email>veaceslav.gaidarji@gmail.com</email>
</developer>
</developers>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>1.0</version>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>junit</artifactId>
<version>1.20</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>net.sf.opencsv</groupId>
Expand Down
58 changes: 37 additions & 21 deletions src/main/java/hudson/plugins/plot/CSVSeries.java
Expand Up @@ -5,12 +5,15 @@

package hudson.plugins.plot;

import hudson.Extension;
import hudson.FilePath;

import hudson.model.Descriptor;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand All @@ -21,12 +24,14 @@

import javax.servlet.ServletException;

import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.ObjectUtils;
import org.kohsuke.stapler.DataBoundConstructor;

import au.com.bytecode.opencsv.CSVReader;
import org.kohsuke.stapler.StaplerRequest;

/**
* Represents a plot data series configuration from an CSV file.
Expand Down Expand Up @@ -72,16 +77,6 @@ public enum InclusionFlag {

private boolean displayTableFlag;

/**
*
* @param file
* @param label
* @param req
* Stapler request
* @param radioButtonId
* ID used to find the parameters specific to this instance.
* @throws ServletException
*/
@DataBoundConstructor
public CSVSeries(String file, String url, String inclusionFlag,
String exclusionValues, boolean displayTableFlag) {
Expand Down Expand Up @@ -128,9 +123,9 @@ public List<PlotPoint> loadSeries(FilePath workspaceRootDir,
InputStreamReader inputReader = null;

try {
List<PlotPoint> ret = new ArrayList<PlotPoint>();
List<PlotPoint> ret = new ArrayList<>();

FilePath[] seriesFiles = null;
FilePath[] seriesFiles;
try {
seriesFiles = workspaceRootDir.list(getFile());
} catch (Exception e) {
Expand Down Expand Up @@ -163,7 +158,7 @@ public List<PlotPoint> loadSeries(FilePath workspaceRootDir,
+ getFile());

// load existing plot file
inputReader = new InputStreamReader(in);
inputReader = new InputStreamReader(in, Charset.defaultCharset().name());
reader = new CSVReader(inputReader);
String[] nextLine;

Expand Down Expand Up @@ -239,15 +234,14 @@ public List<PlotPoint> loadSeries(FilePath workspaceRootDir,
/**
* This function checks the exclusion/inclusion filters from the properties
* file and returns true if a point should be excluded.
*
*
* @return true if the point should be excluded based on label or column
*/
private boolean excludePoint(String label, int index) {
if (inclusionFlag == null || inclusionFlag == InclusionFlag.OFF)
return false;

boolean retVal = false;

boolean retVal;
switch (inclusionFlag) {
case INCLUDE_BY_STRING:
// if the set contains it, don't exclude it.
Expand All @@ -268,6 +262,8 @@ private boolean excludePoint(String label, int index) {
// if the set doesn't contain it, don't exclude it.
retVal = colExclusionSet.contains(Integer.valueOf(index));
break;
default:
retVal = false;
}

if (LOGGER.isLoggable(Level.FINEST))
Expand All @@ -293,13 +289,15 @@ private void loadExclusionSet() {
switch (inclusionFlag) {
case INCLUDE_BY_STRING:
case EXCLUDE_BY_STRING:
strExclusionSet = new HashSet<String>();
strExclusionSet = new HashSet<>();
break;

case INCLUDE_BY_COLUMN:
case EXCLUDE_BY_COLUMN:
colExclusionSet = new HashSet<Integer>();
colExclusionSet = new HashSet<>();
break;
default:
LOGGER.log(Level.SEVERE, "Failed to initialize columns exclusions set.");
}

for (String str : PAT_COMMA.split(exclusionValues)) {
Expand All @@ -321,11 +319,29 @@ private void loadExclusionSet() {
LOGGER.finest(inclusionFlag + " CSV Column: " + str);
colExclusionSet.add(Integer.valueOf(str));
} catch (NumberFormatException nfe) {
LOGGER.log(Level.SEVERE, "Exception converting to integer",
nfe);
LOGGER.log(Level.SEVERE, "Exception converting to integer", nfe);
}
break;
break;
default:
LOGGER.log(Level.SEVERE, "Failed to identify columns exclusions.");
}
}
}

@Override
public Descriptor<Series> getDescriptor() {
return new DescriptorImpl();
}

@Extension
public static class DescriptorImpl extends Descriptor<Series> {
public String getDisplayName() {
return Messages.Plot_CsvSeries();
}

@Override
public Series newInstance(StaplerRequest req, JSONObject formData) throws FormException {
return SeriesFactory.createSeries(formData, req);
}
}
}
8 changes: 4 additions & 4 deletions src/main/java/hudson/plugins/plot/MatrixPlotAction.java
Expand Up @@ -32,22 +32,22 @@ public MatrixPlotAction(MatrixConfiguration project,
return project;
}

// called from PlotAction/index.jelly
// called from MatrixPlotAction/index.jelly
public boolean hasPlots() throws IOException {
return CollectionUtils.isNotEmpty(publisher.getPlots(project));
}

// called from PlotAction/index.jelly
// called from MatrixPlotAction/index.jelly
public List<String> getOriginalGroups() {
return publisher.getOriginalGroups(project);
}

// called from PlotAction/index.jelly
// called from MatrixPlotAction/index.jelly
public String getUrlGroup(String originalGroup) {
return publisher.originalGroupToUrlEncodedGroup(originalGroup);
}

// called from href created in PlotAction/index.jelly
// called from href created in MatrixPlotAction/index.jelly
public PlotReport getDynamic(String group, StaplerRequest req,
StaplerResponse rsp) throws IOException {
return new PlotReport(project, publisher.urlGroupToOriginalGroup(
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/hudson/plugins/plot/MatrixPlotPublisher.java
Expand Up @@ -35,7 +35,7 @@
*/
public class MatrixPlotPublisher extends AbstractPlotPublisher {

transient private Map<MatrixConfiguration, List<Plot>> plotsOfConfigurations = new HashMap<MatrixConfiguration, List<Plot>>();
transient private Map<MatrixConfiguration, List<Plot>> plotsOfConfigurations = new HashMap<>();

transient private Map<String, List<Plot>> groupMap = new HashMap<String, List<Plot>>();

Expand Down Expand Up @@ -66,7 +66,7 @@ public String urlGroupToOriginalGroup(String urlGroup, MatrixConfiguration c) {
* Returns all group names as the original user specified strings.
*/
public List<String> getOriginalGroups(MatrixConfiguration configuration) {
List<String> originalGroups = new ArrayList<String>();
List<String> originalGroups = new ArrayList<>();
for (String urlGroup : groupMap.keySet()) {
originalGroups
.add(urlGroupToOriginalGroup(urlGroup, configuration));
Expand All @@ -83,8 +83,8 @@ public List<String> getOriginalGroups(MatrixConfiguration configuration) {
*/
public void setPlots(List<Plot> plots) {
this.plots = plots;
groupMap = new HashMap<String, List<Plot>>();
plotsOfConfigurations = new HashMap<MatrixConfiguration, List<Plot>>();
groupMap = new HashMap<>();
plotsOfConfigurations = new HashMap<>();
}

/**
Expand All @@ -99,7 +99,7 @@ public void addPlot(Plot plot) {
List<Plot> list = groupMap.get(urlGroup);
list.add(plot);
} else {
List<Plot> list = new ArrayList<Plot>();
List<Plot> list = new ArrayList<>();
list.add(plot);
groupMap.put(urlGroup, list);
}
Expand Down Expand Up @@ -132,7 +132,7 @@ public List<Plot> getPlots() {
*/
public List<Plot> getPlots(String urlGroup,
MatrixConfiguration configuration) {
List<Plot> groupPlots = new ArrayList<Plot>();
List<Plot> groupPlots = new ArrayList<>();
List<Plot> p = groupMap.get(urlGroup);
if (p != null) {
for (Plot plot : p) {
Expand Down

0 comments on commit 7141331

Please sign in to comment.