Skip to content

Commit

Permalink
fix: remove commons io dependency (#113)
Browse files Browse the repository at this point in the history
* remove commons-io dependency

* remove guava

* remove commons-io dependency

* format
  • Loading branch information
elharo committed Mar 16, 2021
1 parent 3c91622 commit 4cf5185
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
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>
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

0 comments on commit 4cf5185

Please sign in to comment.