Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add closing resources in quarkus cli as windows is more strict #1378

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ public static Properties readPropertiesYamlFile(QuarkusCliRestService app) throw

public static Properties loadPropertiesFromFile(File file) throws IOException {
Properties properties = new Properties();
properties.load(new FileInputStream(file));
return properties;
try (FileInputStream is = new FileInputStream(file)) {
properties.load(is);
return properties;
}
}

public static File getPropertiesFile(QuarkusCliRestService app) {
Expand Down Expand Up @@ -312,13 +314,15 @@ public static Model getPom(QuarkusCliRestService app) throws XmlPullParserExcept
public static Model getPom(QuarkusCliRestService app, String subdir) throws IOException, XmlPullParserException {
File pomfile = app.getFileFromApplication(subdir, POM_FILE);
MavenXpp3Reader mavenReader = new MavenXpp3Reader();
XmlStreamReader streamReader = new XmlStreamReader(pomfile);
return mavenReader.read(streamReader);
try (XmlStreamReader streamReader = new XmlStreamReader(pomfile)) {
return mavenReader.read(streamReader);
}
}

public static void savePom(QuarkusCliRestService app, Model model) throws IOException {
OutputStream output = new FileOutputStream(app.getFileFromApplication(POM_FILE));
new MavenXpp3Writer().write(output, model);
try (OutputStream output = new FileOutputStream(app.getFileFromApplication(POM_FILE))) {
new MavenXpp3Writer().write(output, model);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collection;
Expand All @@ -22,14 +21,16 @@ public static void writePropertiesIntoYaml(File yamlFile, Properties properties)
yaml.dump(properties, new FileWriter(yamlFile));
}

public static Properties readYamlFileIntoProperties(File yamlFile) throws FileNotFoundException {
public static Properties readYamlFileIntoProperties(File yamlFile) throws IOException {
Yaml yaml = new Yaml();
Map<String, Object> obj = yaml.load(new FileInputStream(yamlFile));
try (FileInputStream is = new FileInputStream(yamlFile)) {
Map<String, Object> obj = yaml.load(is);

Properties properties = new Properties();
properties.putAll(getFlattenedMap(obj));
Properties properties = new Properties();
properties.putAll(getFlattenedMap(obj));

return properties;
return properties;
}
}

private static Map<String, Object> getFlattenedMap(Map<String, Object> source) {
Expand Down