Skip to content

Commit

Permalink
try with closed resources
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea committed Sep 12, 2024
1 parent 0bc0ff0 commit cea9c45
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/main/java/io/jenkins/plugins/jfrog/JfStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,19 +329,20 @@ Version getJfrogCliVersion(Launcher.ProcStarter launcher) throws IOException, In
if (this.currentCliVersion != null) {
return this.currentCliVersion;
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ArgumentListBuilder builder = new ArgumentListBuilder();
builder.add(jfrogBinaryPath).add("-v");
int exitCode = launcher
.cmds(builder)
.pwd(launcher.pwd())
.stdout(outputStream)
.join();
if (exitCode != 0) {
throw new IOException("Failed to get JFrog CLI version: " + outputStream.toString(StandardCharsets.UTF_8));
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()){
ArgumentListBuilder builder = new ArgumentListBuilder();
builder.add(jfrogBinaryPath).add("-v");
int exitCode = launcher
.cmds(builder)
.pwd(launcher.pwd())
.stdout(outputStream)
.join();
if (exitCode != 0) {
throw new IOException("Failed to get JFrog CLI version: " + outputStream.toString(StandardCharsets.UTF_8));
}
String versionOutput = outputStream.toString(StandardCharsets.UTF_8).trim();
String version = StringUtils.substringAfterLast(versionOutput, " ");
return new Version(version);
}
String versionOutput = outputStream.toString(StandardCharsets.UTF_8).trim();
String version = StringUtils.substringAfterLast(versionOutput, " ");
return new Version(version);
}
}

0 comments on commit cea9c45

Please sign in to comment.