From 55d48d60c7544fa500c696f32f45aeecbd1080f2 Mon Sep 17 00:00:00 2001 From: Souvik Karfa Date: Thu, 1 Aug 2024 09:40:22 +0530 Subject: [PATCH 1/2] closed IO streams in finally block --- pom.xml | 2 +- pom.xml.versionsBackup | 144 ++++++++++++++++++ .../ast/TraceableASTGenerateReportAction.java | 31 +++- 3 files changed, 169 insertions(+), 8 deletions(-) create mode 100644 pom.xml.versionsBackup diff --git a/pom.xml b/pom.xml index 08a7e77..92146d1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.jenkins-ci.plugins plugin - 4.83 + 4.86 io.jenkins.plugins diff --git a/pom.xml.versionsBackup b/pom.xml.versionsBackup new file mode 100644 index 0000000..08a7e77 --- /dev/null +++ b/pom.xml.versionsBackup @@ -0,0 +1,144 @@ + + + 4.0.0 + + org.jenkins-ci.plugins + plugin + 4.83 + + + io.jenkins.plugins + traceable + ${revision}${changelist} + hpi + traceable-plugin + https://github.com/jenkinsci/${project.artifactId}-plugin + 2024 + + + + MIT License + https://opensource.org/licenses/MIT + + + + + dhruv-singhal-github + Dhruv Singhal + + + + + scm:git:https://github.com/${gitHubRepo} + scm:git:https://github.com/${gitHubRepo} + ${scmTag} + https://github.com/${gitHubRepo} + + + 1.0 + -SNAPSHOT + + + 2.440.3 + jenkinsci/${project.artifactId}-plugin + v@{project.version} + + + + + + + io.jenkins.tools.bom + bom-2.332.x + 1763.v092b_8980a_f5e + pom + import + + + + + + com.aspose + aspose-html + 24.5 + + + org.jenkins-ci.plugins + structs + + + org.projectlombok + lombok + 1.18.32 + provided + + + org.jenkins-ci.plugins.workflow + workflow-basic-steps + test + + + org.jenkins-ci.plugins.workflow + workflow-cps + test + + + org.jenkins-ci.plugins.workflow + workflow-durable-task-step + test + + + org.jenkins-ci.plugins.workflow + workflow-job + test + + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + AsposeJavaAPI + Aspose Java API + https://repository.aspose.com/repo/ + + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + + + com.diffplug.spotless + spotless-maven-plugin + 2.43.0 + + + format + + check + apply + + process-sources + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + param,return,throws,link + false + true + + + + + diff --git a/src/main/java/io/jenkins/plugins/traceable/ast/TraceableASTGenerateReportAction.java b/src/main/java/io/jenkins/plugins/traceable/ast/TraceableASTGenerateReportAction.java index f22b550..e32e866 100644 --- a/src/main/java/io/jenkins/plugins/traceable/ast/TraceableASTGenerateReportAction.java +++ b/src/main/java/io/jenkins/plugins/traceable/ast/TraceableASTGenerateReportAction.java @@ -77,7 +77,7 @@ private void runScript(String scriptPath, String[] args) { .append(tempFile.getAbsolutePath()) .toString(); for (int i = 0; i < args.length; i++) { - if (args[i] != null && !args[i].equals("")) execScript += " " + args[i]; + if (args[i] != null && !args[i].isEmpty()) execScript += " " + args[i]; else execScript += " ''"; } ProcessBuilder processBuilder = new ProcessBuilder(execScript); @@ -172,26 +172,43 @@ private String createHtmlReport(String markdown) { return ""; } - private String readFile(Path filePath) { + private String readFile(Path filePath) throws IOException { + InputStream is = null; + InputStreamReader isr = null; + BufferedReader br = null; + try { - InputStream is = java.nio.file.Files.newInputStream(filePath); - InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8); - BufferedReader br = new BufferedReader(isr); + is = java.nio.file.Files.newInputStream(filePath); + isr = new InputStreamReader(is, StandardCharsets.UTF_8); + br = new BufferedReader(isr); return br.lines().collect(Collectors.joining("\n")); } catch (IOException e) { e.printStackTrace(); + } finally { + if (is != null) { + is.close(); + } + if (isr != null) { + isr.close(); + } + if (br != null) { + br.close(); + } } return ""; } - private void writeToFile(File file, String data) { + private void writeToFile(File file, String data) throws IOException { FileWriter fw = null; try { fw = new FileWriter(file, true); fw.append(data); - fw.close(); } catch (IOException e) { e.printStackTrace(); + } finally { + if (fw != null) { + fw.close(); + } } } } From 7f6136f8b0107ce5ffaa2c5b0e6cdec47f6a2ce6 Mon Sep 17 00:00:00 2001 From: Souvik Karfa Date: Thu, 1 Aug 2024 15:21:35 +0530 Subject: [PATCH 2/2] removed backup pom --- pom.xml.versionsBackup | 144 ----------------------------------------- 1 file changed, 144 deletions(-) delete mode 100644 pom.xml.versionsBackup diff --git a/pom.xml.versionsBackup b/pom.xml.versionsBackup deleted file mode 100644 index 08a7e77..0000000 --- a/pom.xml.versionsBackup +++ /dev/null @@ -1,144 +0,0 @@ - - - 4.0.0 - - org.jenkins-ci.plugins - plugin - 4.83 - - - io.jenkins.plugins - traceable - ${revision}${changelist} - hpi - traceable-plugin - https://github.com/jenkinsci/${project.artifactId}-plugin - 2024 - - - - MIT License - https://opensource.org/licenses/MIT - - - - - dhruv-singhal-github - Dhruv Singhal - - - - - scm:git:https://github.com/${gitHubRepo} - scm:git:https://github.com/${gitHubRepo} - ${scmTag} - https://github.com/${gitHubRepo} - - - 1.0 - -SNAPSHOT - - - 2.440.3 - jenkinsci/${project.artifactId}-plugin - v@{project.version} - - - - - - - io.jenkins.tools.bom - bom-2.332.x - 1763.v092b_8980a_f5e - pom - import - - - - - - com.aspose - aspose-html - 24.5 - - - org.jenkins-ci.plugins - structs - - - org.projectlombok - lombok - 1.18.32 - provided - - - org.jenkins-ci.plugins.workflow - workflow-basic-steps - test - - - org.jenkins-ci.plugins.workflow - workflow-cps - test - - - org.jenkins-ci.plugins.workflow - workflow-durable-task-step - test - - - org.jenkins-ci.plugins.workflow - workflow-job - test - - - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - AsposeJavaAPI - Aspose Java API - https://repository.aspose.com/repo/ - - - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - - - - com.diffplug.spotless - spotless-maven-plugin - 2.43.0 - - - format - - check - apply - - process-sources - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - param,return,throws,link - false - true - - - - -