Skip to content

Commit

Permalink
JENKINS-36571: fix/upgrade language level issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mheinzerling committed Oct 12, 2016
1 parent 9b95ced commit 7d7a9ce
Show file tree
Hide file tree
Showing 20 changed files with 152 additions and 178 deletions.
19 changes: 8 additions & 11 deletions src/main/java/hudson/plugins/jacoco/ExecutionFileLoader.java
Expand Up @@ -39,7 +39,7 @@ public class ExecutionFileLoader implements Serializable {
private ArrayList<FilePath> execFiles;

public ExecutionFileLoader() {
execFiles=new ArrayList<FilePath>();
execFiles= new ArrayList<>();
}

public void addExecFile(FilePath execFile) {
Expand Down Expand Up @@ -84,14 +84,11 @@ private void loadExecutionData() throws IOException {
for (FilePath filePath : execFiles) {
File executionDataFile = new File(filePath.getRemote());
try {
final FileInputStream fis = new FileInputStream(executionDataFile);
try {
final ExecutionDataReader reader = new ExecutionDataReader(fis);
reader.setSessionInfoVisitor(sessionInfoStore);
reader.setExecutionDataVisitor(executionDataStore);
reader.read();
} finally {
fis.close();
try (FileInputStream fis = new FileInputStream(executionDataFile)) {
final ExecutionDataReader reader = new ExecutionDataReader(fis);
reader.setSessionInfoVisitor(sessionInfoStore);
reader.setExecutionDataVisitor(executionDataStore);
reader.read();
}
} catch (final IOException e) {
System.out.println("While reading execution data-file: " + executionDataFile);
Expand Down Expand Up @@ -138,11 +135,11 @@ public IBundleCoverage loadBundleCoverage() throws IOException {
return this.bundleCoverage;
}

public void setIncludes(String[] includes) {
public void setIncludes(String... includes) {
this.includes = includes;
}

public void setExcludes(String[] excludes) {
public void setExcludes(String... excludes) {
this.excludes = excludes;
}
}
8 changes: 4 additions & 4 deletions src/main/java/hudson/plugins/jacoco/JacocoBuildAction.java
Expand Up @@ -118,7 +118,7 @@ public HealthReport getBuildHealth() {
thresholds.ensureValid();
int score = 100;
float percent;
ArrayList<Localizable> reports = new ArrayList<Localizable>(5);
ArrayList<Localizable> reports = new ArrayList<>(5);
if (clazz != null && thresholds.getMaxClass() > 0) {
percent = clazz.getPercentageFloat();
if (percent < thresholds.getMaxClass()) {
Expand Down Expand Up @@ -224,7 +224,7 @@ public synchronized CoverageReport getResult() {

try {
CoverageReport r = new CoverageReport(this, reportFolder.parse(inclusions, exclusions));
report = new WeakReference<CoverageReport>(r);
report = new WeakReference<>(r);
r.setThresholds(thresholds);
return r;
} catch (IOException e) {
Expand All @@ -244,7 +244,7 @@ public JacocoBuildAction getPreviousResult() {
*/
public Map<Coverage,Boolean> getCoverageRatios(){
CoverageReport result = getResult();
Map<Coverage,Boolean> ratios = new LinkedHashMap<Coverage,Boolean>();
Map<Coverage,Boolean> ratios = new LinkedHashMap<>();
if( result != null ) {
Coverage instructionCoverage = result.getInstructionCoverage();
Coverage classCoverage = result.getClassCoverage();
Expand Down Expand Up @@ -313,7 +313,7 @@ public static JacocoBuildAction load(Run<?,?> owner, JacocoHealthReportThreshold
* @return
* @throws IOException
*/
private static Map<Type, Coverage> loadRatios(JacocoReportDir layout, Map<Type, Coverage> ratios, String[] includes, String[] excludes) throws IOException {
private static Map<Type, Coverage> loadRatios(JacocoReportDir layout, Map<Type, Coverage> ratios, String[] includes, String... excludes) throws IOException {

if (ratios == null) {
ratios = new LinkedHashMap<CoverageElement.Type, Coverage>();
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/hudson/plugins/jacoco/JacocoPublisher.java
Expand Up @@ -400,18 +400,16 @@ protected static FilePath[] resolveDirPaths(FilePath workspace, TaskListener lis
FilePath[] directoryPaths = null;
try {
directoryPaths = workspace.act(new ResolveDirPaths(input));
} catch(InterruptedException ie) {
} catch(InterruptedException | IOException ie) {
ie.printStackTrace();
} catch(IOException io) {
io.printStackTrace();
}
return directoryPaths;
return directoryPaths;
}


@Override
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull Launcher launcher, @Nonnull TaskListener taskListener) throws InterruptedException, IOException {
Map<String, String> envs = run instanceof AbstractBuild ? ((AbstractBuild) run).getBuildVariables() : Collections.<String, String>emptyMap();
Map<String, String> envs = run instanceof AbstractBuild ? ((AbstractBuild<?,?>) run).getBuildVariables() : Collections.<String, String>emptyMap();

healthReports = createJacocoHealthReportThresholds();

Expand Down Expand Up @@ -440,7 +438,7 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull
JacocoReportDir dir = new JacocoReportDir(run.getRootDir());

if (run instanceof AbstractBuild) {
execPattern = resolveFilePaths((AbstractBuild) run, taskListener, execPattern);
execPattern = resolveFilePaths((AbstractBuild<?,?>) run, taskListener, execPattern);
}

List<FilePath> matchedExecFiles = Arrays.asList(filePath.list(resolveFilePaths(run, taskListener, execPattern, env)));
Expand Down Expand Up @@ -542,6 +540,7 @@ public String getDisplayName() {
}

@Override
@SuppressWarnings("rawtypes")
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
return true;
}
Expand Down Expand Up @@ -592,7 +591,7 @@ public ResolveDirPaths(String input) {

public FilePath[] invoke(File f, VirtualChannel channel) throws IOException {
FilePath base = new FilePath(f);
ArrayList<FilePath> localDirectoryPaths= new ArrayList<FilePath>();
ArrayList<FilePath> localDirectoryPaths= new ArrayList<>();
String[] includes = input.split(DIR_SEP);
DirectoryScanner ds = new DirectoryScanner();

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/jacoco/JacocoReportDir.java
Expand Up @@ -60,7 +60,7 @@ public File getExecFilesDir() {
* Lists up existing jacoco.exec files.
*/
public List<File> getExecFiles() {
List<File> r = new ArrayList<File>();
List<File> r = new ArrayList<>();
int i = 0;
File root = getExecFilesDir();
File checkPath;
Expand Down Expand Up @@ -89,7 +89,7 @@ public void addExecFiles(Iterable<FilePath> execFiles) throws IOException, Inter
/**
* Parses the saved "jacoco.exec" files into an {@link ExecutionFileLoader}.
*/
public ExecutionFileLoader parse(String[] includes, String[] excludes) throws IOException {
public ExecutionFileLoader parse(String[] includes, String... excludes) throws IOException {
ExecutionFileLoader efl = new ExecutionFileLoader();
for (File exec : getExecFiles()) {
efl.addExecFile(new FilePath(exec));
Expand Down
Expand Up @@ -216,8 +216,8 @@ public String toString()
}

private float baseStroke = 4f;
private Stack<Axis> axes = new Stack<Axis>();
private Stack<Plot> plots = new Stack<Plot>();
private Stack<Axis> axes = new Stack<>();
private Stack<Plot> plots = new Stack<>();

public CoverageGraphLayout baseStroke(float baseStroke)
{
Expand Down Expand Up @@ -308,7 +308,7 @@ public List<Plot> getPlots()
public void apply(JFreeChart chart)
{
final CategoryPlot plot = chart.getCategoryPlot();
Map<Axis, Integer> axisIds = new HashMap<Axis, Integer>();
Map<Axis, Integer> axisIds = new HashMap<>();
int axisId = 0;
for (Axis axis : axes)
{
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/hudson/plugins/jacoco/model/CoverageObject.java
Expand Up @@ -392,14 +392,14 @@ GraphImpl createGraph(final Calendar t, final int width, final int height, final
@Override
protected Map<Axis, DataSetBuilder<String, NumberOnlyBuildLabel>> createDataSetBuilder(CoverageObject<SELF> obj)
{
Map<Axis, DataSetBuilder<String, NumberOnlyBuildLabel>> builders = new LinkedHashMap<Axis, DataSetBuilder<String, NumberOnlyBuildLabel>>();
Map<Axis, DataSetBuilder<String, NumberOnlyBuildLabel>> builders = new LinkedHashMap<>();
for (Axis axis : layout.getAxes())
{
builders.put(axis, new DataSetBuilder<String, NumberOnlyBuildLabel>());
if (axis.isCrop()) bounds.put(axis, new Bounds());
}

Map<Plot, Number> last = new HashMap<Plot, Number>();
Map<Plot, Number> last = new HashMap<>();
for (CoverageObject<SELF> a = obj; a != null; a = a.getPreviousResult())
{
NumberOnlyBuildLabel label = new NumberOnlyBuildLabel(a.getBuild());
Expand Down Expand Up @@ -463,13 +463,13 @@ public JFreeChart getGraph( )

@Override
protected JFreeChart createGraph() {
Map<Axis, CategoryDataset> dataSets = new LinkedHashMap<Axis, CategoryDataset>();
Map<Axis, CategoryDataset> dataSets = new LinkedHashMap<>();
Map<Axis, DataSetBuilder<String, NumberOnlyBuildLabel>> dataSetBuilders = createDataSetBuilder(obj);
for (Entry<Axis, DataSetBuilder<String, NumberOnlyBuildLabel>> e : dataSetBuilders.entrySet())
{
dataSets.put(e.getKey(), e.getValue().build());
}
List<Axis> axes = new ArrayList<Axis>(dataSets.keySet());
List<Axis> axes = new ArrayList<>(dataSets.keySet());

final JFreeChart chart = ChartFactory.createLineChart(
null, // chart title
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/hudson/plugins/jacoco/portlet/JacocoLoadData.java
Expand Up @@ -36,6 +36,7 @@
import hudson.plugins.jacoco.portlet.utils.Utils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -65,9 +66,9 @@ private JacocoLoadData() {
* number of days
* @return Map The sorted summaries
*/
public static Map<LocalDate, JacocoCoverageResultSummary> loadChartDataWithinRange(List<Job> jobs, int daysNumber) {
public static Map<LocalDate, JacocoCoverageResultSummary> loadChartDataWithinRange(List<Job<?,?>> jobs, int daysNumber) {

Map<LocalDate, JacocoCoverageResultSummary> summaries = new HashMap<LocalDate, JacocoCoverageResultSummary>();
Map<LocalDate, JacocoCoverageResultSummary> summaries = new HashMap<>();

// Get the last build (last date) of the all jobs
LocalDate lastDate = Utils.getLastDate(jobs);
Expand Down Expand Up @@ -109,7 +110,7 @@ public static Map<LocalDate, JacocoCoverageResultSummary> loadChartDataWithinRan
}

// Sorting by date, ascending order
Map<LocalDate, JacocoCoverageResultSummary> sortedSummaries = new TreeMap<LocalDate, JacocoCoverageResultSummary>(summaries);
Map<LocalDate, JacocoCoverageResultSummary> sortedSummaries = new TreeMap<>(summaries);

return sortedSummaries;

Expand Down Expand Up @@ -241,41 +242,41 @@ public static JacocoCoverageResultSummary getResultSummary(final Collection<Job<
if (null != jacocoAction.getClassCoverage()) {
classCoverage = jacocoAction.getClassCoverage().getPercentageFloat();
BigDecimal bigClassCoverage = new BigDecimal(classCoverage);
bigClassCoverage = bigClassCoverage.setScale(1, BigDecimal.ROUND_HALF_EVEN);
bigClassCoverage = bigClassCoverage.setScale(1, RoundingMode.HALF_EVEN);
classCoverage = bigClassCoverage.floatValue();
}
if (null != jacocoAction.getLineCoverage()) {
lineCoverage = jacocoAction.getLineCoverage().getPercentageFloat();
BigDecimal bigLineCoverage = new BigDecimal(lineCoverage);
bigLineCoverage = bigLineCoverage.setScale(1, BigDecimal.ROUND_HALF_EVEN);
bigLineCoverage = bigLineCoverage.setScale(1, RoundingMode.HALF_EVEN);
lineCoverage = bigLineCoverage.floatValue();
}

if (null != jacocoAction.getMethodCoverage()) {
methodCoverage = jacocoAction.getMethodCoverage().getPercentageFloat();
BigDecimal bigMethodCoverage = new BigDecimal(methodCoverage);
bigMethodCoverage = bigMethodCoverage.setScale(1, BigDecimal.ROUND_HALF_EVEN);
bigMethodCoverage = bigMethodCoverage.setScale(1, RoundingMode.HALF_EVEN);
methodCoverage = bigMethodCoverage.floatValue();
}

if (null != jacocoAction.getBranchCoverage()) {
branchCoverage = jacocoAction.getBranchCoverage().getPercentageFloat();
BigDecimal bigBranchCoverage = new BigDecimal(branchCoverage);
bigBranchCoverage = bigBranchCoverage.setScale(1, BigDecimal.ROUND_HALF_EVEN);
bigBranchCoverage = bigBranchCoverage.setScale(1, RoundingMode.HALF_EVEN);
branchCoverage = bigBranchCoverage.floatValue();
}

if (null != jacocoAction.getInstructionCoverage()) {
instructionCoverage = jacocoAction.getInstructionCoverage().getPercentageFloat();
BigDecimal bigInstructionCoverage = new BigDecimal(instructionCoverage);
bigInstructionCoverage = bigInstructionCoverage.setScale(1, BigDecimal.ROUND_HALF_EVEN);
bigInstructionCoverage = bigInstructionCoverage.setScale(1, RoundingMode.HALF_EVEN);
instructionCoverage = bigInstructionCoverage.floatValue();
}

if (null != jacocoAction.getComplexityScore()) {
complexityScore = jacocoAction.getComplexityScore().getPercentageFloat();
BigDecimal bigComplexityCoverage = new BigDecimal(complexityScore);
bigComplexityCoverage = bigComplexityCoverage.setScale(1, BigDecimal.ROUND_HALF_EVEN);
bigComplexityCoverage = bigComplexityCoverage.setScale(1, RoundingMode.HALF_EVEN);
complexityScore = bigComplexityCoverage.floatValue();
}
}
Expand Down
Expand Up @@ -30,6 +30,7 @@
package hudson.plugins.jacoco.portlet.bean;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -76,7 +77,7 @@ public class JacocoCoverageResultSummary {
*/
private float complexityScore;

private List<JacocoCoverageResultSummary> coverageResults = new ArrayList<JacocoCoverageResultSummary>();
private List<JacocoCoverageResultSummary> coverageResults = new ArrayList<>();

/**
* Default Constructor.
Expand Down Expand Up @@ -149,7 +150,7 @@ public float getTotalClassCoverage() {
}

float totalClass = this.getClassCoverage() / this.getCoverageResults().size();
totalClass = Utils.roundFLoat(1, BigDecimal.ROUND_HALF_EVEN, totalClass);
totalClass = Utils.roundFloat(1, RoundingMode.HALF_EVEN, totalClass);
return totalClass;
}

Expand All @@ -164,7 +165,7 @@ public float getTotalBranchCoverage() {
}

float totalBranch = this.getBranchCoverage() / this.getCoverageResults().size();
totalBranch = Utils.roundFLoat(1, BigDecimal.ROUND_HALF_EVEN, totalBranch);
totalBranch = Utils.roundFloat(1, RoundingMode.HALF_EVEN, totalBranch);
return totalBranch;
}

Expand All @@ -179,7 +180,7 @@ public float getTotalInstructionCoverage() {
}

float totalInstr = this.getInstructionCoverage() / this.getCoverageResults().size();
totalInstr = Utils.roundFLoat(1, BigDecimal.ROUND_HALF_EVEN, totalInstr);
totalInstr = Utils.roundFloat(1, RoundingMode.HALF_EVEN, totalInstr);
return totalInstr;
}

Expand All @@ -194,7 +195,7 @@ public float getTotalComplexityScore() {
}

float totalComplex = this.getComplexityScore() / this.getCoverageResults().size();
totalComplex = Utils.roundFLoat(1, BigDecimal.ROUND_HALF_EVEN, totalComplex);
totalComplex = Utils.roundFloat(1, RoundingMode.HALF_EVEN, totalComplex);
return totalComplex;
}

Expand All @@ -209,7 +210,7 @@ public float getTotalLineCoverage() {
}

float totalLine = this.getLineCoverage() / this.getCoverageResults().size();
totalLine = Utils.roundFLoat(1, BigDecimal.ROUND_HALF_EVEN, totalLine);
totalLine = Utils.roundFloat(1, RoundingMode.HALF_EVEN, totalLine);
return totalLine;
}

Expand All @@ -224,7 +225,7 @@ public float getTotalMethodCoverage() {
}

float totalMethod = this.getMethodCoverage() / this.getCoverageResults().size();
totalMethod = Utils.roundFLoat(1, BigDecimal.ROUND_HALF_EVEN, totalMethod);
totalMethod = Utils.roundFloat(1, RoundingMode.HALF_EVEN, totalMethod);
return totalMethod;
}

Expand Down
Expand Up @@ -37,6 +37,8 @@

import java.awt.BasicStroke;
import java.awt.Color;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -116,7 +118,8 @@ public Graph getSummaryGraph() {
Map<LocalDate, JacocoCoverageResultSummary> summaries;

// Retrieve Dashboard View jobs
List<Job> jobs = getDashboard().getJobs();
@SuppressWarnings({"unchecked", "rawtypes"})
List<Job<?,?>> jobs = (List) getDashboard().getJobs();

// Fill a HashMap with the data will be showed in the chart
summaries = JacocoLoadData.loadChartDataWithinRange(jobs, daysNumber);
Expand Down Expand Up @@ -203,7 +206,7 @@ protected JFreeChart createGraph() {
*/
private static CategoryDataset buildDataSet(Map<LocalDate, JacocoCoverageResultSummary> summaries) {

DataSetBuilder<String, LocalDate> dataSetBuilder = new DataSetBuilder<String, LocalDate>();
DataSetBuilder<String, LocalDate> dataSetBuilder = new DataSetBuilder<>();

for (Map.Entry<LocalDate, JacocoCoverageResultSummary> entry : summaries.entrySet()) {
float classCoverage = 0;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/hudson/plugins/jacoco/portlet/utils/Utils.java
Expand Up @@ -33,6 +33,7 @@
import hudson.model.Run;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

import org.joda.time.LocalDate;
Expand Down Expand Up @@ -93,7 +94,7 @@ public static int validateChartAttributes(String attribute, int defaultValue) {
* @return LocalDate the last date of all jobs that belogs to
* Dashboard View.
*/
public static LocalDate getLastDate(List<Job> jobs) {
public static LocalDate getLastDate(List<Job<?,?>> jobs) {
LocalDate lastDate = null;
for (Job<?,?> job : jobs) {
Run<?,?> lastRun = job.getLastCompletedBuild();
Expand Down Expand Up @@ -121,7 +122,7 @@ public static LocalDate getLastDate(List<Job> jobs) {
* the value to be rounded
* @return the rounded value
*/
public static float roundFLoat(int scale, int roundingMode, float value) {
public static float roundFloat(int scale, RoundingMode roundingMode, float value) {
BigDecimal bigDecimal = new BigDecimal(value);
bigDecimal = bigDecimal.setScale(scale, roundingMode);
return bigDecimal.floatValue();
Expand Down

0 comments on commit 7d7a9ce

Please sign in to comment.