Skip to content

Commit a99ee38

Browse files
committed
fix: address PR review feedback on java-cloud-bom migration
1 parent 0fbea61 commit a99ee38

5 files changed

Lines changed: 21 additions & 15 deletions

File tree

java-cloud-bom/dashboard/src/main/java/com/google/cloud/tools/opensource/cloudbomdashboard/ArtifactMavenData.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ private static LatestMetadata getLatestVersionAndLastUpdated(String metadataUrl)
116116
FileUtils.copyURLToFile(url, metadataFile);
117117

118118
MetadataXpp3Reader reader = new MetadataXpp3Reader();
119-
Metadata metadata = reader.read(new FileInputStream(metadataFile));
119+
Metadata metadata;
120+
try (FileInputStream fis = new FileInputStream(metadataFile)) {
121+
metadata = reader.read(fis);
122+
}
120123

121124
if (metadata.getVersioning() == null) {
122125
return new LatestMetadata("", "");
@@ -210,7 +213,10 @@ private static Optional<String> getSharedDependenciesVersionFromUrl(String pomUr
210213
BufferedInputStream input = new BufferedInputStream(url.openStream());
211214
FileUtils.copyInputStreamToFile(input, pomFile);
212215
MavenXpp3Reader read = new MavenXpp3Reader();
213-
Model model = read.read(new FileInputStream(pomFile));
216+
Model model;
217+
try (FileInputStream fis = new FileInputStream(pomFile)) {
218+
model = read.read(fis);
219+
}
214220
ModelBuildingRequest request = new DefaultModelBuildingRequest();
215221
request.setRawModel(model);
216222
RepositorySystem repositorySystem = RepositoryUtility.newRepositorySystem();

java-cloud-bom/dashboard/src/main/java/com/google/cloud/tools/opensource/cloudbomdashboard/DashboardMain.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ public static void main(String[] arguments)
121121
Path relativePath = dashboardArguments.getOutputFile();
122122
Files.createDirectories(relativePath.getParent());
123123
File file = new File(String.valueOf(relativePath));
124-
OutputStream outputStream = new FileOutputStream(file);
125-
if (!report(bom, outputStream)) {
126-
throw new RuntimeException("Failed to converge dependencies");
124+
try (OutputStream outputStream = new FileOutputStream(file)) {
125+
if (!report(bom, outputStream)) {
126+
throw new RuntimeException("Failed to converge dependencies");
127+
}
127128
}
128-
outputStream.close();
129129
}
130130
}
131131

java-cloud-bom/libraries-bom-table-generation/updateREADMETable.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ def run_maven_flatten_clean():
1919
root = tree.getroot()
2020

2121
# Load the metadata
22-
with open('libraries-bom-table-generation/javaModulesMetadata.yaml', 'r') as metadata_file:
22+
with open('libraries-bom-table-generation/javaModulesMetadata.yaml', 'r', encoding='utf-8') as metadata_file:
2323
metadata = yaml.safe_load(metadata_file)
2424

2525
# Manual list of runtime modules
2626
runtime_modules = ['google-http-client',
2727
'gax',
2828
'api-common',
2929
'google-cloud-core',
30-
'google-iam-policy'
30+
'google-iam-policy',
3131
'google-auth-library',
3232
]
3333

@@ -120,7 +120,7 @@ def run_maven_flatten_clean():
120120
# Append the dependency to the table
121121
table += f"| {artifact_id} | {library_type} | {library_reference_hyperlink} | {product_reference_hyperlink} |\n"
122122

123-
with open('README.md', 'r') as readme_file:
123+
with open('README.md', 'r', encoding='utf-8') as readme_file:
124124
readme = readme_file.read()
125125

126126
# Update existing table in README.md
@@ -129,6 +129,6 @@ def run_maven_flatten_clean():
129129
table_pattern = re.compile(r'(?s)<!-- TABLE_START -->.*?<!-- TABLE_END -->')
130130
updated_readme = table_pattern.sub(table_start_comment + "\n" + table + table_end_comment, readme)
131131

132-
with open('README.md', 'w') as readme_file:
132+
with open('README.md', 'w', encoding='utf-8') as readme_file:
133133
readme_file.write(updated_readme)
134134
run_maven_flatten_clean()

java-cloud-bom/release-note-generation/src/main/java/com/google/cloud/ReleaseNoteGeneration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,12 @@ static String fetchReleaseNote(String owner, String repository, String tag)
614614

615615
ProcessBuilder builder =
616616
new ProcessBuilder("gh", "release", "--repo", owner + "/" + repository, "view", tag);
617+
builder.redirectErrorStream(true);
617618
Process process = builder.start();
618-
String errorOutput = new String(process.getErrorStream().readAllBytes());
619+
String output = new String(process.getInputStream().readAllBytes(), java.nio.charset.StandardCharsets.UTF_8);
619620
boolean finished = process.waitFor(1, TimeUnit.MINUTES);
620621
Verify.verify(finished, "The process timed out");
621-
Verify.verify(0 == process.exitValue(), "The command failed: %s", errorOutput);
622-
String output = new String(process.getInputStream().readAllBytes());
622+
Verify.verify(0 == process.exitValue(), "The command failed: %s", output);
623623
return output;
624624
}
625625
}

java-cloud-bom/tests/validate-bom/src/main/java/com/google/cloud/CreateBomCanaryProject.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static void main(String[] arguments) throws Exception {
5555
.replace("DEPENDENCIES", dependenciesSection);
5656

5757
Path pomToWrite = outputProjectDirectory.resolve("pom.xml");
58-
Files.write(pomToWrite, replacedContent.getBytes());
58+
Files.write(pomToWrite, replacedContent.getBytes(java.nio.charset.StandardCharsets.UTF_8));
5959
System.out.println("Wrote " + pomToWrite);
6060
}
6161

@@ -64,7 +64,7 @@ private static String readPomTemplate() throws IOException {
6464
try (InputStream inputStream =
6565
CreateBomCanaryProject.class.getClassLoader().getResourceAsStream("template.pom.xml")) {
6666
Verify.verifyNotNull(inputStream);
67-
return new String(inputStream.readAllBytes());
67+
return new String(com.google.common.io.ByteStreams.toByteArray(inputStream), java.nio.charset.StandardCharsets.UTF_8);
6868
}
6969
}
7070

0 commit comments

Comments
 (0)