Skip to content

Commit

Permalink
Update parent POM, update dependencies, solve spotbug errors, test wi…
Browse files Browse the repository at this point in the history
…th Java 21 #105 (#243)

* Test with Java 21.

* Found reliance on default encoding

[ERROR] High: Found reliance on default encoding in hudson.plugins.performance.PerformancePublisher.writeErrorThresholdReportInXML(Run, PerformanceReport): new java.io.FileWriter(File) [hudson.plugins.performance.PerformancePublisher] At PerformancePublisher.java:[line 650] DM_DEFAULT_ENCODING

* Found reliance on default encoding

[ERROR] High: Found reliance on default encoding in hudson.plugins.performance.PerformancePublisher.writeRelativeThresholdReportInXML(Run, StringBuilder, StringBuilder, StringBuilder): new java.io.FileWriter(File) [hudson.plugins.performance.PerformancePublisher] At PerformancePublisher.java:[line 884] DM_DEFAULT_ENCODING

* Found reliance on default encoding

[ERROR] High: Found reliance on default encoding in hudson.plugins.performance.PerformancePublisher.writeStandardResultsToXML(Run, Collection): new java.io.FileWriter(File) [hudson.plugins.performance.PerformancePublisher] At PerformancePublisher.java:[line 606] DM_DEFAULT_ENCODING

* Possible null pointer dereference

[ERROR] Medium: Possible null pointer dereference in hudson.plugins.performance.PerformancePublisher.evaluateInExpertMode(Run, FilePath, TaskListener) due to return value of called method [hudson.plugins.performance.PerformancePublisher, hudson.plugins.performance.PerformancePublisher] Dereferenced at PerformancePublisher.java:[line 1056]Known null at PerformancePublisher.java:[line 1056] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

* Possible null pointer dereference

[ERROR] Medium: Possible null pointer dereference in hudson.plugins.performance.PerformancePublisher.evaluateInExpertMode(Run, FilePath, TaskListener) due to return value of called method [hudson.plugins.performance.PerformancePublisher, hudson.plugins.performance.PerformancePublisher] Dereferenced at PerformancePublisher.java:[line 1055]Known null at PerformancePublisher.java:[line 1055] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

* Possible null pointer dereference

[ERROR] Medium: Possible null pointer dereference in hudson.plugins.performance.PerformancePublisher.evaluateInExpertMode(Run, FilePath, TaskListener) due to return value of called method [hudson.plugins.performance.PerformancePublisher, hudson.plugins.performance.PerformancePublisher] Dereferenced at PerformancePublisher.java:[line 1055]Known null at PerformancePublisher.java:[line 1055] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

* Possible null pointer dereference

[ERROR] Medium: Possible null pointer dereference in hudson.plugins.performance.PerformanceReportMap.parseReports(Run, TaskListener, PerformanceReportMap$PerformanceReportCollector, String) due to return value of called method [hudson.plugins.performance.PerformanceReportMap, hudson.plugins.performance.PerformanceReportMap] Method invoked at PerformanceReportMap.java:[line 515]Known null at PerformanceReportMap.java:[line 502] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

* Possible null pointer dereference

[ERROR] Medium: Possible null pointer dereference in hudson.plugins.performance.PerformanceReportMap.parseReports(Run, TaskListener, PerformanceReportMap$PerformanceReportCollector, String) due to return value of called method [hudson.plugins.performance.PerformanceReportMap, hudson.plugins.performance.PerformanceReportMap] Method invoked at PerformanceReportMap.java:[line 515]Known null at PerformanceReportMap.java:[line 502] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

* inefficient use of keySet iterator instead of entrySet iterator

[ERROR] Medium: hudson.plugins.performance.PerformanceReportMap.doSummarizerGraph(StaplerRequest, StaplerResponse) makes inefficient use of keySet iterator instead of entrySet iterator [hudson.plugins.performance.PerformanceReportMap] At PerformanceReportMap.java:[line 448] WMI_WRONG_MAP_ITERATOR

* Inconsistent synchronization

[ERROR] Medium: Inconsistent synchronization of hudson.plugins.performance.actions.PerformanceBuildAction.performanceReportMap; locked 66% of time [hudson.plugins.performance.actions.PerformanceBuildAction, hudson.plugins.performance.actions.PerformanceBuildAction, hudson.plugins.performance.actions.PerformanceBuildAction] Unsynchronized access at PerformanceBuildAction.java:[line 97]Synchronized access at PerformanceBuildAction.java:[line 79]Synchronized access at PerformanceBuildAction.java:[line 91] IS2_INCONSISTENT_SYNC

* Possible null pointer dereference

[ERROR] Medium: Possible null pointer dereference in hudson.plugins.performance.actions.PerformanceProjectAction.getPerformanceReportList() due to return value of called method [hudson.plugins.performance.actions.PerformanceProjectAction, hudson.plugins.performance.actions.PerformanceProjectAction] Dereferenced at PerformanceProjectAction.java:[line 786]Known null at PerformanceProjectAction.java:[line 786] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

* Possible null pointer dereference

[ERROR] Medium: Possible null pointer dereference in hudson.plugins.performance.actions.PerformanceProjectAction.getPerformanceReportList() due to return value of called method [hudson.plugins.performance.actions.PerformanceProjectAction, hudson.plugins.performance.actions.PerformanceProjectAction] Dereferenced at PerformanceProjectAction.java:[line 786]Known null at PerformanceProjectAction.java:[line 786] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

* inefficient use of keySet iterator instead of entrySet iterator

[ERROR] Medium: hudson.plugins.performance.PerformanceReportMap.doSummarizerGraph(StaplerRequest, StaplerResponse) makes inefficient use of keySet iterator instead of entrySet iterator [hudson.plugins.performance.PerformanceReportMap] At PerformanceReportMap.java:[line 449] WMI_WRONG_MAP_ITERATOR

* Inconsistent synchronization

[ERROR] Medium: Inconsistent synchronization of hudson.plugins.performance.actions.PerformanceBuildAction.performanceReportMap; locked 66% of time [hudson.plugins.performance.actions.PerformanceBuildAction, hudson.plugins.performance.actions.PerformanceBuildAction, hudson.plugins.performance.actions.PerformanceBuildAction] Unsynchronized access at PerformanceBuildAction.java:[line 99]Synchronized access at PerformanceBuildAction.java:[line 80]Synchronized access at PerformanceBuildAction.java:[line 93] IS2_INCONSISTENT_SYNC

* Possible null pointer dereference

[ERROR] Medium: Possible null pointer dereference in hudson.plugins.performance.actions.PerformanceProjectAction.getPerformanceReportList() due to return value of called method [hudson.plugins.performance.actions.PerformanceProjectAction, hudson.plugins.performance.actions.PerformanceProjectAction] Method invoked at PerformanceProjectAction.java:[line 783]Known null at PerformanceProjectAction.java:[line 783] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

* getPerformanceReportMap() is unsynchronized, setPerformanceReportMap(WeakReference) is synchronized

[ERROR] Medium: hudson.plugins.performance.actions.PerformanceBuildAction.getPerformanceReportMap() is unsynchronized, hudson.plugins.performance.actions.PerformanceBuildAction.setPerformanceReportMap(WeakReference) is synchronized [hudson.plugins.performance.actions.PerformanceBuildAction] At PerformanceBuildAction.java:[line 74] UG_SYNC_SET_UNSYNC_GET

* Possible null pointer dereference

[ERROR] Medium: Possible null pointer dereference in hudson.plugins.performance.actions.PerformanceProjectAction.getPerformanceReportList() due to return value of called method [hudson.plugins.performance.actions.PerformanceProjectAction, hudson.plugins.performance.actions.PerformanceProjectAction] Method invoked at PerformanceProjectAction.java:[line 785]Known null at PerformanceProjectAction.java:[line 785] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

* [ERROR] Medium: hudson.plugins.performance.reports.UriReport defines compareTo(UriReport) and uses Object.equals() [hudson.plugins.performance.reports.UriReport] At UriReport.java:[lines 207-210] EQ_COMPARETO_USE_OBJECT_EQUALS

* [ERROR] High: hudson.plugins.performance.reports.UriReport$Sample defines equals and uses Object.hashCode() [hudson.plugins.performance.reports.UriReport$Sample] At UriReport.java:[lines 631-635] HE_EQUALS_USE_HASHCODE

* [ERROR] High: hudson.plugins.performance.reports.UriReport defines equals and uses Object.hashCode() [hudson.plugins.performance.reports.UriReport] At UriReport.java:[lines 214-217] HE_EQUALS_USE_HASHCODE

* [ERROR] Medium: hudson.plugins.performance.reports.PerformanceReport defines compareTo(PerformanceReport) and uses Object.equals() [hudson.plugins.performance.reports.PerformanceReport] At PerformanceReport.java:[lines 255-258] EQ_COMPARETO_USE_OBJECT_EQUALS

* Exceptional return value of java.io.File.mkdirs() ignored

[ERROR] Medium: Exceptional return value of java.io.File.mkdirs() ignored in hudson.plugins.performance.reports.ConstraintReport.writeResultsToFile() [hudson.plugins.performance.reports.ConstraintReport] At ConstraintReport.java:[line 314] RV_RETURN_VALUE_IGNORED_BAD_PRACTICE

* [ERROR] High: hudson.plugins.performance.reports.PerformanceReport defines equals and uses Object.hashCode() [hudson.plugins.performance.reports.PerformanceReport] At PerformanceReport.java:[lines 263-266] HE_EQUALS_USE_HASHCODE

* [ERROR] High: Found reliance on default encoding in hudson.plugins.performance.reports.ConstraintReport.writeResultsToFile(): String.getBytes() [hudson.plugins.performance.reports.ConstraintReport] At ConstraintReport.java:[line 323] DM_DEFAULT_ENCODING

* [ERROR] High: Found reliance on default encoding in hudson.plugins.performance.parsers.WrkSummarizerParser.parse(File): new java.util.Scanner(File) [hudson.plugins.performance.parsers.WrkSummarizerParser] At WrkSummarizerParser.java:[line 88] DM_DEFAULT_ENCODING

* [ERROR] High: Boxing/unboxing to parse a primitive hudson.plugins.performance.parsers.TaurusParser.getTaurusFinalStats(Element) [hudson.plugins.performance.parsers.TaurusParser, hudson.plugins.performance.parsers.TaurusParser] At TaurusParser.java:[line 96]Another occurrence at TaurusParser.java:[line 100] DM_BOXED_PRIMITIVE_FOR_PARSING

* Found reliance on default encoding

[ERROR] High: Found reliance on default encoding in hudson.plugins.performance.parsers.ParserDetector.detect(String): new java.io.FileReader(File) [hudson.plugins.performance.parsers.ParserDetector] At ParserDetector.java:[line 34] DM_DEFAULT_ENCODING

* Integral division result cast to double or float

[ERROR] Medium: Integral division result cast to double or float in hudson.plugins.performance.parsers.LocustParser.parse(File) [hudson.plugins.performance.parsers.LocustParser] At LocustParser.java:[line 69] ICAST_IDIV_CAST_TO_DOUBLE

* Found reliance on default encoding

[ERROR] High: Found reliance on default encoding in hudson.plugins.performance.parsers.LocustParser.getCsvData(File): new java.io.FileReader(File) [hudson.plugins.performance.parsers.LocustParser] At LocustParser.java:[line 99] DM_DEFAULT_ENCODING

* Found reliance on default encoding

[ERROR] High: Found reliance on default encoding in hudson.plugins.performance.parsers.JmeterSummarizerParser.parse(File): new java.util.Scanner(File) [hudson.plugins.performance.parsers.JmeterSummarizerParser] At JmeterSummarizerParser.java:[line 53] DM_DEFAULT_ENCODING

* Boxing/unboxing to parse a primitive

[ERROR] High: Boxing/unboxing to parse a primitive hudson.plugins.performance.parsers.JMeterParser$1.startElement(String, String, String, Attributes) [hudson.plugins.performance.parsers.JMeterParser$1, hudson.plugins.performance.parsers.JMeterParser$1] At JMeterParser.java:[line 131]Another occurrence at JMeterParser.java:[line 139] DM_BOXED_PRIMITIVE_FOR_PARSING

* Boxing/unboxing to parse a primitive

[ERROR] High: Boxing/unboxing to parse a primitive hudson.plugins.performance.parsers.JMeterParser$1.startElement(String, String, String, Attributes) [hudson.plugins.performance.parsers.JMeterParser$1] At JMeterParser.java:[line 139] DM_BOXED_PRIMITIVE_FOR_PARSING

* Found reliance on default encoding

[ERROR] High: Found reliance on default encoding in hudson.plugins.performance.parsers.JMeterParser.isXmlFile(File): new java.io.FileReader(File) [hudson.plugins.performance.parsers.JMeterParser] At JMeterParser.java:[line 71] DM_DEFAULT_ENCODING

* Found reliance on default encoding

[ERROR] High: Found reliance on default encoding in hudson.plugins.performance.parsers.JMeterCsvParser.parse(File): new java.io.FileReader(File) [hudson.plugins.performance.parsers.JMeterCsvParser, hudson.plugins.performance.parsers.JMeterCsvParser] At JMeterCsvParser.java:[line 61]Another occurrence at JMeterCsvParser.java:[line 69] DM_DEFAULT_ENCODING

* Boxing/unboxing to parse a primitive

[ERROR] High: Boxing/unboxing to parse a primitive hudson.plugins.performance.parsers.JMeterCsvParser.getSample(CSVRecord) [hudson.plugins.performance.parsers.JMeterCsvParser] At JMeterCsvParser.java:[line 138] DM_BOXED_PRIMITIVE_FOR_PARSING

* Found reliance on default encoding

[ERROR] High: Found reliance on default encoding in hudson.plugins.performance.parsers.JMeterCsvParser.parse(File): new java.io.FileReader(File) [hudson.plugins.performance.parsers.JMeterCsvParser] At JMeterCsvParser.java:[line 58] DM_DEFAULT_ENCODING

* Found reliance on default encoding

[ERROR] High: Found reliance on default encoding in hudson.plugins.performance.parsers.IagoParser.parse(File): new java.io.FileReader(File) [hudson.plugins.performance.parsers.IagoParser] At IagoParser.java:[line 71] DM_DEFAULT_ENCODING

* [ERROR] Medium: hudson.plugins.performance.parsers.AbstractParser.DATE_FORMATS should be package protected [hudson.plugins.performance.parsers.AbstractParser] At AbstractParser.java:[line 56] MS_PKGPROTECT

* Boxing/unboxing to parse a primitive

[ERROR] High: Boxing/unboxing to parse a primitive hudson.plugins.performance.parsers.AbstractParser.parseTimestamp(String) [hudson.plugins.performance.parsers.AbstractParser] At AbstractParser.java:[line 212] DM_BOXED_PRIMITIVE_FOR_PARSING

* [ERROR] Medium: hudson.plugins.performance.data.HttpSample defines compareTo(HttpSample) and uses Object.equals() [hudson.plugins.performance.data.HttpSample] At HttpSample.java:[line 127] EQ_COMPARETO_USE_OBJECT_EQUALS

* Possible null pointer dereference

[ERROR] Medium: Possible null pointer dereference in hudson.plugins.performance.constraints.RelativeConstraint.evaluatePreviousBuilds(List) due to return value of called method [hudson.plugins.performance.constraints.RelativeConstraint, hudson.plugins.performance.constraints.RelativeConstraint] Dereferenced at RelativeConstraint.java:[line 475]Known null at RelativeConstraint.java:[line 475] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

* [ERROR] High: hudson.plugins.performance.data.HttpSample defines equals and uses Object.hashCode() [hudson.plugins.performance.data.HttpSample] At HttpSample.java:[lines 132-135] HE_EQUALS_USE_HASHCODE

* Possible null pointer dereference

[ERROR] Medium: Possible null pointer dereference in hudson.plugins.performance.constraints.RelativeConstraint.evaluatePreviousBuilds(List) due to return value of called method [hudson.plugins.performance.constraints.RelativeConstraint, hudson.plugins.performance.constraints.RelativeConstraint] Dereferenced at RelativeConstraint.java:[line 473]Known null at RelativeConstraint.java:[line 473] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

* [ERROR] High: hudson.plugins.performance.constraints.RelativeConstraint defines clone() but doesn't implement Cloneable [hudson.plugins.performance.constraints.RelativeConstraint] At RelativeConstraint.java:[line 267] CN_IMPLEMENTS_CLONE_BUT_NOT_CLONEABLE

* [ERROR] Medium: hudson.plugins.performance.constraints.AbstractConstraint$Operator.setSelected(boolean) unconditionally sets the field isSelected [hudson.plugins.performance.constraints.AbstractConstraint$Operator] At AbstractConstraint.java:[line 287] ME_ENUM_FIELD_SETTER

* Not a clonable object.

* [ERROR] Medium: hudson.plugins.performance.constraints.AbstractConstraint$Metric.setSelected(boolean) unconditionally sets the field isSelected [hudson.plugins.performance.constraints.AbstractConstraint$Metric] At AbstractConstraint.java:[line 237] ME_ENUM_FIELD_SETTER

* [ERROR] Medium: hudson.plugins.performance.build.PerformanceTestBuild.extractDefaultReportToWorkingDirectory(FilePath) may fail to clean up java.io.InputStream [hudson.plugins.performance.build.PerformanceTestBuild, hudson.plugins.performance.build.PerformanceTestBuild] Obligation to clean up resource created at PerformanceTestBuild.java:[line 431] is not dischargedPath continues at PerformanceTestBuild.java:[line 432] OBL_UNSATISFIED_OBLIGATION

* Possible null pointer dereference

[ERROR] Medium: Possible null pointer dereference in hudson.plugins.performance.build.PerformanceTestBuild.perform(Run, FilePath, Launcher, TaskListener) due to return value of called method [hudson.plugins.performance.build.PerformanceTestBuild, hudson.plugins.performance.build.PerformanceTestBuild] Dereferenced at PerformanceTestBuild.java:[line 149]Known null at PerformanceTestBuild.java:[line 149] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

* [ERROR] Medium: hudson.plugins.performance.build.PerformanceTestBuild.CREATE_LOCAL_PYTHON_COMMAND_WITH_SYSTEM_PACKAGES_OPTION should be package protected [hudson.plugins.performance.build.PerformanceTestBuild] At PerformanceTestBuild.java:[line 53] MS_PKGPROTECT

* [ERROR] Medium: hudson.plugins.performance.build.PerformanceTestBuild.CREATE_LOCAL_PYTHON_COMMAND should be package protected [hudson.plugins.performance.build.PerformanceTestBuild] At PerformanceTestBuild.java:[line 55] MS_PKGPROTECT

* Possible null pointer dereference

[ERROR] Medium: Possible null pointer dereference in hudson.plugins.performance.build.PerformanceTestBuild.perform(Run, FilePath, Launcher, TaskListener) due to return value of called method [hudson.plugins.performance.build.PerformanceTestBuild, hudson.plugins.performance.build.PerformanceTestBuild] Method invoked at PerformanceTestBuild.java:[line 146]Known null at PerformanceTestBuild.java:[line 146] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

* [ERROR] Medium: hudson.plugins.performance.build.PerformanceTestBuild.CHECK_VIRTUALENV_COMMAND should be package protected [hudson.plugins.performance.build.PerformanceTestBuild] At PerformanceTestBuild.java:[line 48] MS_PKGPROTECT

* Dead store to files

[ERROR] Medium: Dead store to files in hudson.plugins.performance.actions.PerformanceProjectAction.getPerformanceReportList() [hudson.plugins.performance.actions.PerformanceProjectAction] At PerformanceProjectAction.java:[line 783] DLS_DEAD_LOCAL_STORE

* Possible null pointer dereference

[ERROR] Medium: Possible null pointer dereference in hudson.plugins.performance.actions.PerformanceProjectAction.getPerformanceReportList() due to return value of called method [hudson.plugins.performance.actions.PerformanceProjectAction, hudson.plugins.performance.actions.PerformanceProjectAction] Method invoked at PerformanceProjectAction.java:[line 786]Known null at PerformanceProjectAction.java:[line 786] NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

* Found reliance on default encoding

[ERROR] High: Found reliance on default encoding in hudson.plugins.performance.build.PerformanceTestBuild.runCmd(String[], FilePath, OutputStream, Launcher, EnvVars): String.getBytes() [hudson.plugins.performance.build.PerformanceTestBuild, hudson.plugins.performance.build.PerformanceTestBuild] At PerformanceTestBuild.java:[line 419]Another occurrence at PerformanceTestBuild.java:[line 421] DM_DEFAULT_ENCODING

* Found reliance on default encoding

[ERROR] High: Found reliance on default encoding in hudson.plugins.performance.build.PerformanceTestBuild.runCmd(String[], FilePath, OutputStream, Launcher, EnvVars): String.getBytes() [hudson.plugins.performance.build.PerformanceTestBuild] At PerformanceTestBuild.java:[line 420] DM_DEFAULT_ENCODING

* [ERROR] Medium: hudson.plugins.performance.constraints.AbstractConstraint$Escalation.setSelected(boolean) unconditionally sets the field isSelected [hudson.plugins.performance.constraints.AbstractConstraint$Escalation] At AbstractConstraint.java:[line 259] ME_ENUM_FIELD_SETTER
  • Loading branch information
gounthar authored Oct 17, 2023
1 parent f29bd34 commit abdb63a
Show file tree
Hide file tree
Showing 21 changed files with 213 additions and 146 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ node('linux-amd64') {
sh 'pip install -r requirements.txt'

def args = ['clean', 'install', '-Dset.changelist']
infra.runMaven(args, 11)
infra.runMaven(args, 21)
}
}

Expand Down
44 changes: 28 additions & 16 deletions src/main/java/hudson/plugins/performance/PerformancePublisher.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package hudson.plugins.performance;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -455,8 +452,14 @@ private Collection<PerformanceReport> locatePerformanceReports(Run<?, ?> run, Fi

List<FilePath> files = locatePerformanceReports(workspace, glob);
if (files.isEmpty()) {
if (run.getResult().isWorseThan(Result.UNSTABLE)) {
return Collections.emptyList();
Result result = run.getResult();
if (result != null) {
if (result.isWorseThan(Result.UNSTABLE)) {
return Collections.emptyList();
}
} else {
// Handle the situation when result is null
logger.println("Result is null");
}

if (failBuildIfNoResultFile) {
Expand Down Expand Up @@ -606,7 +609,7 @@ private Result checkAverageResponseTime(PerformanceReport performanceReport, Has
private void writeStandardResultsToXML(Run<?, ?> run, Collection<PerformanceReport> parsedReports) throws IOException {
File xmlDirectory = createArchiveDirectoryIfMissing(run);
File xmlfile = new File(xmlDirectory, "standardResults.xml");
try (FileWriter fw = new FileWriter(xmlfile);
try (OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream(xmlfile), StandardCharsets.UTF_8);
BufferedWriter bw = new BufferedWriter(fw)){

String xml = new StringBuilder("<?xml version=\"1.0\"?>\n")
Expand Down Expand Up @@ -646,9 +649,8 @@ private void writeErrorThresholdReportInXML(Run<?, ?> run, PerformanceReport per
String[] arr = glob.split("/");

File xmlfile = new File(xmlDirectory, "/dashBoard_" + arr[arr.length - 1].split("\\.")[0] + ".xml");

try (FileWriter fw = new FileWriter(xmlfile);
BufferedWriter bw = new BufferedWriter(fw)) {
try (OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream(xmlfile), StandardCharsets.UTF_8);
BufferedWriter bw = new BufferedWriter(fw)) {
String xml = "<?xml version=\"1.0\"?>\n";
xml += "<results>\n";
xml += "<absoluteDefinition>\n";
Expand Down Expand Up @@ -884,9 +886,8 @@ private void writeRelativeThresholdReportInXML(Run<?, ?> run, StringBuilder aver
File xmlDirectory = createArchiveDirectoryIfMissing(run);

File xmlfile = new File(xmlDirectory, "dashBoard_results.xml");

try (FileWriter fw = new FileWriter(xmlfile);
BufferedWriter bw = new BufferedWriter(fw)) {
try (OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream(xmlfile), StandardCharsets.UTF_8);
BufferedWriter bw = new BufferedWriter(fw)) {

String buildNo = "\t<buildNum>" + (compareBuildPrevious ? "previous" : nthBuildNumber) + "</buildNum>\n";

Expand Down Expand Up @@ -1057,9 +1058,20 @@ public void evaluateInExpertMode(Run<?, ?> run, FilePath workspace, TaskListener
if (junitOutput != null && !junitOutput.isEmpty()) {
listener.getLogger().println("Performance: Generating JUnit output: "+junitOutput);
FilePath output = new FilePath(workspace, junitOutput);
output.getParent().mkdirs();
FilePath parent = output.getParent();
if (parent != null) {
parent.mkdirs();
} else {
// Handle the situation when parent is null
listener.getLogger().println("Failed to create parent dirs because the path is null.");
}
try {
output.write(cr.getJunitReport(), null);
String junitReport = cr.getJunitReport();
if (junitReport != null) {
output.write(junitReport, null);
} else {
listener.getLogger().println("Failed to write JUnit file because junitreport is null.");
}
}
catch (IOException ex) {
listener.getLogger().println("Failed to write JUnit file: "+ex.getMessage());
Expand Down
37 changes: 22 additions & 15 deletions src/main/java/hudson/plugins/performance/PerformanceReportMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ public void doRespondingTimeGraph(StaplerRequest request,
DataSetBuilder<String, NumberOnlyBuildLabel> dataSetBuilder = new DataSetBuilder<String, NumberOnlyBuildLabel>();
ReportValueSelector valueSelector = ReportValueSelector.get(getBuild().getParent());
String keyLabel = getKeyLabel(valueSelector.getGraphType());
for (Run<?, ?> currentBuild : buildReports.keySet()) {
NumberOnlyBuildLabel label = new NumberOnlyBuildLabel(currentBuild);
PerformanceReport report = buildReports.get(currentBuild).get(parameter);
for (Map.Entry<Run<?, ?>, Map<String, PerformanceReport>> entry : buildReports.entrySet()) {
NumberOnlyBuildLabel label = new NumberOnlyBuildLabel(entry.getKey());
PerformanceReport report = entry.getValue().get(parameter);
dataSetBuilder.add(valueSelector.getValue(report),
keyLabel, label);
}
Expand Down Expand Up @@ -443,16 +443,15 @@ public void doSummarizerGraph(StaplerRequest request, StaplerResponse response)
Map<Run<?, ?>, Map<String, PerformanceReport>> buildReports = getBuildReports(parameter, previousBuild);
DataSetBuilder<NumberOnlyBuildLabel, String> dataSetBuilderSummarizer = new DataSetBuilder<NumberOnlyBuildLabel, String>();
ReportValueSelector valueSelector = ReportValueSelector.get(getBuild().getParent());
for (Run<?, ?> currentBuild : buildReports.keySet()) {
NumberOnlyBuildLabel label = new NumberOnlyBuildLabel(currentBuild);
PerformanceReport report = buildReports.get(currentBuild).get(parameter);
for (Map.Entry<Run<?, ?>, Map<String, PerformanceReport>> entry : buildReports.entrySet()) {
NumberOnlyBuildLabel label = new NumberOnlyBuildLabel(entry.getKey());
PerformanceReport report = entry.getValue().get(parameter);

// Now we should have the data necessary to generate the graphs!
for (String key : report.getUriReportMap().keySet()) {
long methodValue = valueSelector.getValue(report.getUriReportMap().get(key));
dataSetBuilderSummarizer.add(methodValue, label, key);
for (Map.Entry<String, UriReport> secondEntry : report.getUriReportMap().entrySet()) {
long methodValue = valueSelector.getValue(secondEntry.getValue());
dataSetBuilderSummarizer.add(methodValue, label, secondEntry.getKey());
}

}

new Graph(-1, 400, 200) {
Expand Down Expand Up @@ -511,11 +510,15 @@ public boolean accept(File dir, String name) {
return false;
}
});
try {
collector.addAll(p.parse(build, Arrays.asList(listFiles), listener));
} catch (IOException ex) {
listener.getLogger().println("Unable to process directory '" + dir + "'.");
ex.printStackTrace(listener.getLogger());
if (listener != null && listener.getLogger() != null) {
try {
collector.addAll(p.parse(build, Arrays.asList(listFiles), listener));
} catch (IOException ex) {
listener.getLogger().println("Unable to process directory '" + dir + "'.");
ex.printStackTrace(listener.getLogger());
}
} else {
// Handle the situation when listener or its logger is null
}
}
}
Expand Down Expand Up @@ -585,6 +588,10 @@ public Object createTrendReportGraphs(final StaplerRequest request) {
String filename = getTrendReportFilename(request);
PerformanceReport report = performanceReportMap.get(filename);
Run<?, ?> build = getBuild();
if (build == null) {
// Handle the situation when build is null
return null;
}

TrendReportGraphs trendReport = new TrendReportGraphs(build.getParent(),
build, request, filename, report);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,19 @@ public PrintStream getHudsonConsoleWriter() {
return hudsonConsoleWriter;
}

public PerformanceReportMap getPerformanceReportMap() {
public synchronized PerformanceReportMap getPerformanceReportMap() {
return getPerformanceReportMap(true);
}

public synchronized PerformanceReportMap getPerformanceReportMap(boolean isInitNextLevel) {
PerformanceReportMap reportMap = null;
WeakReference<PerformanceReportMap> wr = this.performanceReportMap;
if (wr != null) {
reportMap = wr.get();
if (reportMap != null) {
return reportMap;
synchronized(this) {
WeakReference<PerformanceReportMap> wr = this.performanceReportMap;
if (wr != null) {
reportMap = wr.get();
if (reportMap != null) {
return reportMap;
}
}
}
try {
Expand All @@ -92,8 +94,9 @@ public synchronized PerformanceReportMap getPerformanceReportMap(boolean isInitN
return reportMap;
}


public void setPerformanceReportMap(WeakReference<PerformanceReportMap> performanceReportMap) {
this.performanceReportMap = performanceReportMap;
public synchronized void setPerformanceReportMap(WeakReference<PerformanceReportMap> performanceReportMap) {
synchronized(this) {
this.performanceReportMap = performanceReportMap;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@
import org.kohsuke.stapler.StaplerResponse;

import edu.umd.cs.findbugs.annotations.NonNull;

import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -243,7 +241,7 @@ public static JFreeChart createThroughputChart(final CategoryDataset dataset) {
}

public static JFreeChart doCreateSummarizerChart(CategoryDataset dataset,
String yAxis, String chartTitle) {
String yAxis, String chartTitle) {

final JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart
// title
Expand Down Expand Up @@ -549,7 +547,7 @@ public void doRespondingTimeGraph(StaplerRequest request, StaplerResponse respon
protected JFreeChart createGraph() {
return createRespondingTimeChart(dataSetBuilderAverage.build(), limit);
}
}.doPng(request, response);
}.doPng(request, response);
}

public void doThroughputGraph(final StaplerRequest request, final StaplerResponse response) throws IOException {
Expand Down Expand Up @@ -782,20 +780,31 @@ public List<String> getPerformanceReportList() {
if (!file.isDirectory()) {
return performanceReportList;
}
File[] files = file.listFiles();

if (files != null) {
for (File entry : files) {
if (entry.isDirectory()) {
File[] entryFiles = entry.listFiles();
if (entryFiles != null) {
for (File e : Objects.requireNonNull(entryFiles)) {
if (!e.getName().endsWith(".serialized") && !e.getName().endsWith(".serialized-v2")) {
this.performanceReportList.add(e.getName());
}
}
}

for (File entry : file.listFiles()) {
if (entry.isDirectory()) {
for (File e : entry.listFiles()) {
if (!e.getName().endsWith(".serialized") && !e.getName().endsWith(".serialized-v2")) {
this.performanceReportList.add(e.getName());
} else {
if (!entry.getName().endsWith(".serialized") && !entry.getName().endsWith(".serialized-v2")) {
this.performanceReportList.add(entry.getName());
}
}
} else {
if (!entry.getName().endsWith(".serialized") && !entry.getName().endsWith(".serialized-v2")) {
this.performanceReportList.add(entry.getName());
}

}

} else {
// Handle the situation when files is null
return performanceReportList;
}

Collections.sort(performanceReportList);
Expand All @@ -820,7 +829,7 @@ public boolean isTrendVisibleOnProjectDashboard() {
* @return the dynamic result of the analysis (detail page).
*/
public Object getDynamic(final String link, final StaplerRequest request,
final StaplerResponse response) {
final StaplerResponse response) {
if (CONFIGURE_LINK.equals(link)) {
return createUserConfiguration(request);
} else if (TRENDREPORT_LINK.equals(link)) {
Expand Down Expand Up @@ -873,7 +882,7 @@ private String getTestSuiteReportFilename(final StaplerRequest request) {
}

private DataSetBuilder<String, NumberOnlyBuildLabel> getTrendReportData(final StaplerRequest request,
String performanceReportNameFile) {
String performanceReportNameFile) {

DataSetBuilder<String, NumberOnlyBuildLabel> dataSet = new DataSetBuilder<>();
List<? extends Run<?, ?>> builds = getJob().getBuilds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,14 @@
import org.kohsuke.stapler.DataBoundSetter;

import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;

import java.io.*;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.InvalidPathException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.logging.Logger;

/**
Expand All @@ -50,12 +45,12 @@ public class PerformanceTestBuild extends Builder implements SimpleBuildStep {
protected final static String VIRTUALENV_PATH_UNIX = "/taurus-venv/bin/";
protected final static String VIRTUALENV_PATH_WINDOWS = "\\taurus-venv\\Scripts\\";

protected final static String[] CHECK_BZT_COMMAND = new String[]{PERFORMANCE_TEST_COMMAND, HELP_OPTION};
protected final static String[] CHECK_VIRTUALENV_COMMAND = new String[]{VIRTUALENV_COMMAND, HELP_OPTION};
final static String[] CHECK_BZT_COMMAND = new String[]{PERFORMANCE_TEST_COMMAND, HELP_OPTION};
final static String[] CHECK_VIRTUALENV_COMMAND = new String[]{VIRTUALENV_COMMAND, HELP_OPTION};

protected final static String[] CREATE_LOCAL_PYTHON_COMMAND_WITH_SYSTEM_PACKAGES_OPTION =
final static String[] CREATE_LOCAL_PYTHON_COMMAND_WITH_SYSTEM_PACKAGES_OPTION =
new String[]{VIRTUALENV_COMMAND, "--clear", "--system-site-packages", "taurus-venv"};
protected final static String[] CREATE_LOCAL_PYTHON_COMMAND = new String[]{VIRTUALENV_COMMAND, "--clear", "taurus-venv"};
final static String[] CREATE_LOCAL_PYTHON_COMMAND = new String[]{VIRTUALENV_COMMAND, "--clear", "taurus-venv"};

protected final static String DEFAULT_CONFIG_FILE = "jenkins-report.yml";

Expand Down Expand Up @@ -149,8 +144,8 @@ public void perform(@NonNull Run<?, ?> run, @NonNull FilePath workspace, @NonNul
getBztJobResult(testExitCode) :
getJobResult(testExitCode)
);

if (generatePerformanceTrend && run.getResult().isBetterThan(Result.FAILURE)) {
Result result = run.getResult();
if (generatePerformanceTrend && result != null && Result.FAILURE.isWorseThan(result)) {
generatePerformanceTrend(bztWorkingDirectory.getRemote(), run, workspace, launcher, listener);
}

Expand Down Expand Up @@ -422,17 +417,20 @@ public int runCmd(String[] commands, FilePath workspace, OutputStream logger, La
try {
return launcher.launch().cmds(commands).envs(envVars).stdout(logger).stderr(logger).pwd(workspace).start().join();
} catch (IOException ex) {
logger.write(ex.getMessage().getBytes());
logger.write(ex.getMessage().getBytes(StandardCharsets.UTF_8));
if (printDebugOutput) {
logger.write(Functions.printThrowable(ex).getBytes());
logger.write(Functions.printThrowable(ex).getBytes(StandardCharsets.UTF_8));
}
return 1;
}
}

protected String extractDefaultReportToWorkingDirectory(FilePath workingDirectory) throws IOException, InterruptedException {
FilePath defaultConfig = workingDirectory.child(DEFAULT_CONFIG_FILE);
defaultConfig.copyFrom(getClass().getResourceAsStream(DEFAULT_CONFIG_FILE));
try (InputStream is = getClass().getResourceAsStream(DEFAULT_CONFIG_FILE)) {
assert is != null;
defaultConfig.copyFrom(is);
}
return defaultConfig.getRemote();
}

Expand Down
Loading

0 comments on commit abdb63a

Please sign in to comment.