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

fix: remove commons io dependency #113

Merged
merged 4 commits into from Mar 16, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 0 additions & 7 deletions pom.xml
Expand Up @@ -95,12 +95,5 @@
<artifactId>commons-compress</artifactId>
<version>1.20</version>
</dependency>

<!-- pin at 2.6 for jdk 7 compatibility-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</project>
4 changes: 0 additions & 4 deletions renovate.json
Expand Up @@ -66,10 +66,6 @@
"^com.fasterxml.jackson.core"
],
"groupName": "jackson dependencies"
},
{
"packagePatterns": ["^commons-io"],
"enabled": false
}
],
"semanticCommits": true,
Expand Down
26 changes: 16 additions & 10 deletions src/main/java/com/google/cloud/DownloadComponentsMojo.java
Expand Up @@ -53,7 +53,6 @@
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.io.FileUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -242,15 +241,14 @@ private void updateCachedManifest() throws IOException {
@SuppressWarnings("unused")
boolean ignored = localCache.delete();

FileUtils.moveFile(tempFile, localCache);
Files.move(tempFile.toPath(), localCache.toPath());
}

/** Parse the locally cached manifest and extract the relevant components. */
private List<Component> parseManifest() throws IOException {
JsonParser parser = new JsonParser();
JsonElement json;
try (FileReader reader = new FileReader(getManifestCache())) {
json = parser.parse(reader);
json = JsonParser.parseReader(reader);
}

JsonArray jsonComponents = json.getAsJsonObject().get("components").getAsJsonArray();
Expand All @@ -274,10 +272,9 @@ private Map<String, String> parseLocalChecksums() throws IOException {
JsonElement json = new JsonObject();

if (getChecksumFile().exists()) {
JsonParser parser = new JsonParser();

try (FileReader reader = new FileReader(getChecksumFile())) {
json = parser.parse(reader);
json = JsonParser.parseReader(reader);
}
}

Expand Down Expand Up @@ -366,8 +363,18 @@ private void downloadComponent(Component component) throws IOException, NoSuchAl

// Move it into place
File localPath = getComponentPath(component);
FileUtils.deleteDirectory(localPath);
FileUtils.moveDirectory(tmpPath, localPath);
deleteRecursively(localPath);
Files.move(tmpPath.toPath(), localPath.toPath());
}

private static void deleteRecursively(File directory) {
File[] contents = directory.listFiles();
if (contents != null) {
for (File file : contents) {
deleteRecursively(file);
}
}
directory.delete();
}

private static String byteArrayToHex(byte[] a) {
Expand All @@ -386,9 +393,8 @@ private void writeLocalChecksums(List<Component> components) throws IOException
JsonObject results = new JsonObject();

try {
JsonParser parser = new JsonParser();
try (FileReader reader = new FileReader(getChecksumFile())) {
results = parser.parse(reader).getAsJsonObject();
results = JsonParser.parseReader(reader).getAsJsonObject();
}
} catch (FileNotFoundException e) {
// ignored
Expand Down