From b79dcb7627b5eeb8e5846dd46a1c4bb0c49f822f Mon Sep 17 00:00:00 2001 From: Francois Marot Date: Wed, 13 Jul 2016 16:58:15 +0200 Subject: [PATCH] Trying to close issue #20 (Oracle packaging not handled correctly) --- nativedependencies-maven-plugin/pom.xml | 2 +- .../nativedependencies/ArtifactHandler.java | 25 +++++++++++++------ .../nativedependencies/CopyNativesMojo.java | 2 +- .../nativedependencies/IArtifactHandler.java | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/nativedependencies-maven-plugin/pom.xml b/nativedependencies-maven-plugin/pom.xml index d4c25fa..f3acfb9 100644 --- a/nativedependencies-maven-plugin/pom.xml +++ b/nativedependencies-maven-plugin/pom.xml @@ -28,7 +28,7 @@ 2.7 2.0.0 - 1.10 + 1.12 1.5 2.6.0 diff --git a/nativedependencies-maven-plugin/src/main/java/com/teamtter/mavennatives/nativedependencies/ArtifactHandler.java b/nativedependencies-maven-plugin/src/main/java/com/teamtter/mavennatives/nativedependencies/ArtifactHandler.java index 503f2cc..3873dc0 100644 --- a/nativedependencies-maven-plugin/src/main/java/com/teamtter/mavennatives/nativedependencies/ArtifactHandler.java +++ b/nativedependencies-maven-plugin/src/main/java/com/teamtter/mavennatives/nativedependencies/ArtifactHandler.java @@ -10,7 +10,6 @@ import java.util.List; import org.apache.commons.compress.archivers.ArchiveEntry; -import org.apache.commons.compress.archivers.ArchiveException; import org.apache.commons.compress.archivers.ArchiveInputStream; import org.apache.commons.compress.archivers.ArchiveStreamFactory; import org.apache.commons.compress.compressors.CompressorException; @@ -34,8 +33,12 @@ public class ArtifactHandler implements IArtifactHandler { /** Wraps any Exception encountered into an ArtifactUnpackingException which is a RUNTIME Exception */ @Override - public void moveOrUnpackTo(File unpackingDir, Artifact artifact) { + public void moveOrUnpackArtifactTo(File unpackingDir, Artifact artifact) { File artifactFile = artifact.getFile(); + moveOrUnpackFileTo(unpackingDir, artifactFile); + } + + public static void moveOrUnpackFileTo(File unpackingDir, File artifactFile) { String fileName = artifactFile.getName(); String extension = FilenameUtils.getExtension(fileName); @@ -44,7 +47,7 @@ public void moveOrUnpackTo(File unpackingDir, Artifact artifact) { log.info("Artifact {} will be uncompressed as tar-gz-like to {}", artifactFile, unpackingDir); String basename = FilenameUtils.getBaseName(artifactFile.getName()); File uncompressedTarFile = new File(unpackingDir, basename); - uncompressAFile(artifactFile, uncompressedTarFile); + uncompressAFile(artifactFile, unpackingDir); uncompressAnArchive(uncompressedTarFile, unpackingDir); uncompressedTarFile.delete(); } else if (zipLikeExtensions.contains(extension)) { @@ -60,13 +63,18 @@ public void moveOrUnpackTo(File unpackingDir, Artifact artifact) { throw new ArtifactUnpackingException(e); } } + + - public static void uncompressAnArchive(File fileIn, File dirOut) { + private static void uncompressAnArchive(File fileIn, File dirOut) { try { FileInputStream fin = new FileInputStream(fileIn); BufferedInputStream bis = new BufferedInputStream(fin); - + + // CompressorStreamFactory csf = new CompressorStreamFactory(); + // try (ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(csf.createCompressorInputStream(bis)))) { try (ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(bis)) { + ArchiveEntry entry = null; while ((entry = ais.getNextEntry()) != null) { @@ -81,13 +89,13 @@ public static void uncompressAnArchive(File fileIn, File dirOut) { } } } - } catch (IOException | ArchiveException e) { + } catch (Exception e) { log.error("Unable to fully uncompress {} to {}", fileIn, dirOut); throw new ArtifactUnpackingException(e); } } - public static void uncompressAFile(File fileIn, File dirOut) { + private static void uncompressAFile(File fileIn, File dirOut) { dirOut.mkdirs(); try { FileInputStream fin = new FileInputStream(fileIn); @@ -105,4 +113,7 @@ public static void uncompressAFile(File fileIn, File dirOut) { } } + public static void main(String[] args) { + moveOrUnpackFileTo(new File("/tmp"), new File("/home/francois/Downloads/jdk-8u91-linux-x64.tar.gz")); + } } diff --git a/nativedependencies-maven-plugin/src/main/java/com/teamtter/mavennatives/nativedependencies/CopyNativesMojo.java b/nativedependencies-maven-plugin/src/main/java/com/teamtter/mavennatives/nativedependencies/CopyNativesMojo.java index 772ae57..2df7ac2 100644 --- a/nativedependencies-maven-plugin/src/main/java/com/teamtter/mavennatives/nativedependencies/CopyNativesMojo.java +++ b/nativedependencies-maven-plugin/src/main/java/com/teamtter/mavennatives/nativedependencies/CopyNativesMojo.java @@ -191,7 +191,7 @@ private void writeAlreadyUnpackedArtifactsInfo(UnpackedArtifactsInfo unpackedArt private void handleDependancyCopyingOrUnpacking(Artifact artifact, String classifier, UnpackedArtifactsInfo unpackedArtifactsInfo) { log.info("Will unpack: " + artifactToString(artifact)); File unpackingDir = computeUnpackingDir(classifier); - artifactHandler.moveOrUnpackTo(unpackingDir, artifact); + artifactHandler.moveOrUnpackArtifactTo(unpackingDir, artifact); unpackedArtifactsInfo.flagAsUnpacked(artifact.getFile()); } diff --git a/nativedependencies-maven-plugin/src/main/java/com/teamtter/mavennatives/nativedependencies/IArtifactHandler.java b/nativedependencies-maven-plugin/src/main/java/com/teamtter/mavennatives/nativedependencies/IArtifactHandler.java index c73e5a3..a975823 100644 --- a/nativedependencies-maven-plugin/src/main/java/com/teamtter/mavennatives/nativedependencies/IArtifactHandler.java +++ b/nativedependencies-maven-plugin/src/main/java/com/teamtter/mavennatives/nativedependencies/IArtifactHandler.java @@ -6,6 +6,6 @@ public interface IArtifactHandler { - public void moveOrUnpackTo(File unpackingDir, Artifact artifact) throws ArtifactUnpackingException; + public void moveOrUnpackArtifactTo(File unpackingDir, Artifact artifact) throws ArtifactUnpackingException; }