Skip to content

Commit

Permalink
src/main/java/io/openliberty/tools/common/plugins/util/PrepareFeature…
Browse files Browse the repository at this point in the history
…Util.java
  • Loading branch information
jjiwooLim committed Sep 22, 2023
1 parent 067b90e commit 876ffb7
Showing 1 changed file with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ private void prepareFeature(String groupId, String artifactId, String version, F
jsonFile = generatedJson;
provideJsonFileDependency(generatedJson, groupId, version);
info("The features.json has been generated at the following location: " + generatedJson);
}else {
warn("The features.json could not be generated at the following location: " + generatedJson);
}
} catch (PluginExecutionException e) {
warn("Error: The features.json could not be generated.");
Expand Down Expand Up @@ -244,8 +246,6 @@ private String parseRepositoryLocation(File fileFromRepo, String groupId, String
* @throws PluginExecutionException Throws an error if unable to generate JSON
*/
public File generateJson(String targetJsonFile, Map<File, String> esaFileMap) throws PluginExecutionException {
FileInputStream instream = null;
FileOutputStream outstream = null;
try {
Path targetDir = Files.createTempDirectory("generatedJson");
URL installJarURL = null;
Expand Down Expand Up @@ -278,26 +278,19 @@ public File generateJson(String targetJsonFile, Map<File, String> esaFileMap) th
throw new PluginExecutionException("Could not load the jar " + installJarFile.getAbsolutePath(), e);
}
File targetFile = new File(targetJsonFile);
instream = new FileInputStream(json);
targetFile.getParentFile().mkdirs();
outstream = new FileOutputStream(targetFile);
byte[] buffer = new byte[1024];
int length;
while ((length = instream.read(buffer)) > 0) {
outstream.write(buffer, 0, length);
try(FileInputStream instream = new FileInputStream(json); FileOutputStream outstream = new FileOutputStream(targetFile)){
byte[] buffer = new byte[1024];
int length;
while ((length = instream.read(buffer)) > 0) {
outstream.write(buffer, 0, length);
}
}

return targetFile;
} catch (IOException e) {
debug(e);
throw new PluginExecutionException("Cannot read or create json file " + targetJsonFile, e);
} finally {
try {
instream.close();
outstream.close();
} catch (IOException e) {
}
}
}
}

private File loadInstallJarFile(File installDirectory) {
Expand Down

0 comments on commit 876ffb7

Please sign in to comment.