Bug 553191 - Try-resource in o.e.test.performance.ui
Change-Id: Ief887bf6dbd21d4da11fc0949356d403e1834890
Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
diff --git a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/db/DB_Results.java b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/db/DB_Results.java
index fde0277..77e05b7 100644
--- a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/db/DB_Results.java
+++ b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/db/DB_Results.java
@@ -1040,14 +1040,8 @@
if (scenarioPattern != null) DEBUG_WRITER.print(" with pattern "+scenarioPattern); //$NON-NLS-1$
if (buildName != null) DEBUG_WRITER.print(" for build: "+buildName); //$NON-NLS-1$
}
- ResultSet result = null;
Map<String, List<ScenarioResults>> allScenarios = new HashMap<>();
- try {
- if (buildName == null) {
- result = this.fSQL.queryBuildAllScenarios(scenarioPattern);
- } else {
- result = this.fSQL.queryBuildScenarios(scenarioPattern, buildName);
- }
+ try (ResultSet result = buildName == null ? this.fSQL.queryBuildAllScenarios(scenarioPattern) : this.fSQL.queryBuildScenarios(scenarioPattern, buildName)) {
int previousId = -1;
List<ScenarioResults> scenarios = null;
List<String> scenariosNames = new ArrayList<>();
@@ -1071,12 +1065,6 @@
} catch (SQLException e) {
PerformanceTestPlugin.log(e);
} finally {
- if (result != null) {
- try {
- result.close();
- } catch (SQLException e1) { // ignored
- }
- }
if (DEBUG) DEBUG_WRITER.println("done in " + (System.currentTimeMillis() - start) + "ms]"); //$NON-NLS-1$ //$NON-NLS-2$
}
return allScenarios;
@@ -1090,13 +1078,11 @@
}
if (LOG) LOG_WRITER.starts(" -> configPattern: " + configPattern + " buildName (if any): " + buildName);
internalQueryAllVariations(configPattern); // need to read all variations to have all build names
- ResultSet result = null;
- try {
+ try (ResultSet result = buildName == null
+ ? this.fSQL.queryScenarioDataPoints(configPattern, scenarioResults.getId())
+ : this.fSQL.queryScenarioBuildDataPoints(configPattern, scenarioResults.getId(), buildName)) {
int count = 0;
- result = buildName == null
- ? this.fSQL.queryScenarioDataPoints(configPattern, scenarioResults.getId())
- : this.fSQL.queryScenarioBuildDataPoints(configPattern, scenarioResults.getId(), buildName);
while (result.next()) {
int dp_id = result.getInt(1);
int step = result.getInt(2);
@@ -1121,14 +1107,6 @@
if (LOG) LOG_WRITER.ends(" -> " + count + " values read"); //$NON-NLS-1$ //$NON-NLS-2$
} catch (SQLException e) {
PerformanceTestPlugin.log(e);
- } finally {
- if (result != null) {
- try {
- result.close();
- } catch (SQLException e1) {
- // ignored
- }
- }
}
}
diff --git a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/model/PerformanceResultsElement.java b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/model/PerformanceResultsElement.java
index 7576f44..16ffb99 100644
--- a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/model/PerformanceResultsElement.java
+++ b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/model/PerformanceResultsElement.java
@@ -333,10 +333,8 @@
if (this.results == null) {
return;
}
- try {
- // Create the stream
- PrintStream stream = new PrintStream(new BufferedOutputStream(new FileOutputStream(resultsFile)));
-
+ // Create the stream
+ try (PrintStream stream = new PrintStream(new BufferedOutputStream(new FileOutputStream(resultsFile)))) {
// Print main title
stream.print("<link href=\""+Utils.TOOLTIP_STYLE+"\" rel=\"stylesheet\" type=\"text/css\">\n");
stream.print("<script src=\""+Utils.TOOLTIP_SCRIPT+"\"></script>\n");
@@ -365,11 +363,9 @@
BuildsComparisonTable table = new BuildsComparisonTable(this.children[i].getName(), stream, build, reference);
table.print(getPerformanceResults());
}
- }
- finally {
- stream.print("</body>");
- stream.close();
- }
+ } finally {
+ stream.print("</body>");
+ }
} catch (FileNotFoundException e) {
System.err.println("Can't create output file"+resultsFile); //$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/performance/ui/GenerateResults.java b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/performance/ui/GenerateResults.java
index d74846d..b75ae8b 100644
--- a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/performance/ui/GenerateResults.java
+++ b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/performance/ui/GenerateResults.java
@@ -628,46 +628,42 @@
long start = System.currentTimeMillis();
if (this.printStream != null) this.printStream.print("Print scenarios variations summary...");
File outputFile = new File(this.outputDir, "cvsummary.html");
- PrintStream stream = null;
- try {
- stream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFile)));
- printSummaryPresentation(stream);
-// List scenarioNames = DB_Results.getScenarios();
-// int size = scenarioNames.size();
- String[] components = this.performanceResults.getComponents();
- int componentsLength = components.length;
- printSummaryColumnsTitle(stream/*, performanceResults*/);
- String[] configs = this.performanceResults.getConfigNames(true/*sorted*/);
- int configsLength = configs.length;
- for (int i=0; i<componentsLength; i++) {
- String componentName = components[i];
- List<AbstractResults> scenarioNames = this.performanceResults.getComponentScenarios(componentName);
- int size = scenarioNames.size();
- for (int s=0; s<size; s++) {
- String scenarioName = scenarioNames.get(s).getName();
- if (scenarioName == null) continue;
- ScenarioResults scenarioResults = this.performanceResults.getScenarioResults(scenarioName);
- if (scenarioResults != null) {
- stream.print("<tr>\n");
- for (int j=0; j<2; j++) {
- for (int c=0; c<configsLength; c++) {
- printSummaryScenarioLine(j, configs[c], scenarioResults, stream);
- }
- }
- stream.print("<td>");
- stream.print(scenarioName);
- stream.print("</td></tr>\n");
- }
- }
- }
+ try (PrintStream stream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFile)))) {
+ try {
+ printSummaryPresentation(stream);
+ // List scenarioNames = DB_Results.getScenarios();
+ // int size = scenarioNames.size();
+ String[] components = this.performanceResults.getComponents();
+ int componentsLength = components.length;
+ printSummaryColumnsTitle(stream/*, performanceResults*/);
+ String[] configs = this.performanceResults.getConfigNames(true/*sorted*/);
+ int configsLength = configs.length;
+ for (int i=0; i<componentsLength; i++) {
+ String componentName = components[i];
+ List<AbstractResults> scenarioNames = this.performanceResults.getComponentScenarios(componentName);
+ int size = scenarioNames.size();
+ for (int s=0; s<size; s++) {
+ String scenarioName = scenarioNames.get(s).getName();
+ if (scenarioName == null) continue;
+ ScenarioResults scenarioResults = this.performanceResults.getScenarioResults(scenarioName);
+ if (scenarioResults != null) {
+ stream.print("<tr>\n");
+ for (int j=0; j<2; j++) {
+ for (int c=0; c<configsLength; c++) {
+ printSummaryScenarioLine(j, configs[c], scenarioResults, stream);
+ }
+ }
+ stream.print("<td>");
+ stream.print(scenarioName);
+ stream.print("</td></tr>\n");
+ }
+ }
+ }
+ } finally {
+ stream.print("</table></body></html>\n");
+ }
} catch (Exception e) {
e.printStackTrace();
- } finally {
- if (stream != null) {
- stream.print("</table></body></html>\n");
- stream.flush();
- stream.close();
- }
}
if (this.printStream != null) this.printStream.println("done in "+(System.currentTimeMillis()-start)+"ms");
}