From ccb71280accf589ad0ef3c62eb54eeaae574595f Mon Sep 17 00:00:00 2001 From: lore Date: Sun, 20 Mar 2016 10:38:03 +0200 Subject: [PATCH 01/14] Added configuration for xz components --- .../resources/META-INF/plexus/components.xml | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/resources/META-INF/plexus/components.xml b/src/main/resources/META-INF/plexus/components.xml index ee2406a2d..02ca1a1ce 100644 --- a/src/main/resources/META-INF/plexus/components.xml +++ b/src/main/resources/META-INF/plexus/components.xml @@ -11,6 +11,12 @@ org.codehaus.plexus.archiver.bzip2.BZip2Archiver per-lookup + + org.codehaus.plexus.archiver.Archiver + xz + org.codehaus.plexus.archiver.xz.XZArchiver + per-lookup + org.codehaus.plexus.archiver.Archiver dir @@ -80,6 +86,12 @@ org.codehaus.plexus.archiver.bzip2.BZip2UnArchiver per-lookup + + org.codehaus.plexus.archiver.UnArchiver + xz + org.codehaus.plexus.archiver.xz.XZUnArchiver + per-lookup + org.codehaus.plexus.archiver.UnArchiver gzip @@ -201,6 +213,13 @@ org.codehaus.plexus.archiver.tar.TarBZip2UnArchiver per-lookup + + + org.codehaus.plexus.archiver.UnArchiver + tar.xz + org.codehaus.plexus.archiver.tar.TarXZUnArchiver + per-lookup + org.codehaus.plexus.archiver.UnArchiver @@ -249,6 +268,12 @@ org.codehaus.plexus.archiver.bzip2.PlexusIoBzip2ResourceCollection per-lookup + + org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection + xz + org.codehaus.plexus.archiver.xz.PlexusIoXZResourceCollection + per-lookup + org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection gzip @@ -381,6 +406,12 @@ org.codehaus.plexus.archiver.tar.PlexusIoTarBZip2FileResourceCollection per-lookup + + org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection + tar.xz + org.codehaus.plexus.archiver.tar.PlexusIoTarXZFileResourceCollection + per-lookup + org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection From a2a45f8d1cb646f4ee4d8d0f25beaae48ea89708 Mon Sep 17 00:00:00 2001 From: lore Date: Sun, 20 Mar 2016 10:38:52 +0200 Subject: [PATCH 02/14] Added xz package to support xz archiving and un-archiving --- .../xz/PlexusIOXZResourceCollection.java | 63 +++++++++++++++ .../plexus/archiver/xz/XZArchiver.java | 72 +++++++++++++++++ .../plexus/archiver/xz/XZCompressor.java | 60 ++++++++++++++ .../plexus/archiver/xz/XZUnArchiver.java | 80 +++++++++++++++++++ 4 files changed, 275 insertions(+) create mode 100644 src/main/java/org/codehaus/plexus/archiver/xz/PlexusIOXZResourceCollection.java create mode 100644 src/main/java/org/codehaus/plexus/archiver/xz/XZArchiver.java create mode 100644 src/main/java/org/codehaus/plexus/archiver/xz/XZCompressor.java create mode 100644 src/main/java/org/codehaus/plexus/archiver/xz/XZUnArchiver.java diff --git a/src/main/java/org/codehaus/plexus/archiver/xz/PlexusIOXZResourceCollection.java b/src/main/java/org/codehaus/plexus/archiver/xz/PlexusIOXZResourceCollection.java new file mode 100644 index 000000000..656ac35ab --- /dev/null +++ b/src/main/java/org/codehaus/plexus/archiver/xz/PlexusIOXZResourceCollection.java @@ -0,0 +1,63 @@ +/* + * Copyright 2016 Codehaus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.plexus.archiver.xz; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import org.codehaus.plexus.components.io.attributes.Java7FileAttributes; +import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; +import org.codehaus.plexus.components.io.resources.PlexusIoCompressedFileResourceCollection; +import org.codehaus.plexus.util.IOUtil; + +/** + * + * @author lore + */ +public class PlexusIOXZResourceCollection extends PlexusIoCompressedFileResourceCollection +{ + + @Override + protected PlexusIoResourceAttributes getAttributes( File file ) throws IOException + { + return new Java7FileAttributes(file, new HashMap(), new HashMap()); + } + + @Override + protected String getDefaultExtension() + { + return ".xz"; + } + + @Override + protected InputStream getInputStream( File file ) throws IOException + { + FileInputStream fileIs = new FileInputStream( file ); + + try + { + final InputStream result = XZUnArchiver.getXZInputStream( fileIs ); + + return result; + } + finally + { + IOUtil.close(fileIs); + } + } +} diff --git a/src/main/java/org/codehaus/plexus/archiver/xz/XZArchiver.java b/src/main/java/org/codehaus/plexus/archiver/xz/XZArchiver.java new file mode 100644 index 000000000..1a84947ea --- /dev/null +++ b/src/main/java/org/codehaus/plexus/archiver/xz/XZArchiver.java @@ -0,0 +1,72 @@ +/* + * Copyright 2016 Codehaus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.plexus.archiver.xz; + +import java.io.IOException; +import org.codehaus.plexus.archiver.AbstractArchiver; +import org.codehaus.plexus.archiver.ArchiveEntry; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.ResourceIterator; + +/** + * + * @author philiplourandos + */ +public class XZArchiver extends AbstractArchiver { + + private final XZCompressor compressor = new XZCompressor(); + + public XZArchiver() + { + } + + @Override + protected void execute() throws ArchiverException, IOException + { + if ( !checkForced()) + { + return; + } + + ResourceIterator iter = getResources(); + ArchiveEntry entry = iter.next(); + if ( iter.hasNext() ) + { + throw new ArchiverException( "There is more than one file in input." ); + } + compressor.setSource( entry.getResource() ); + compressor.setDestFile( getDestFile() ); + compressor.compress(); + } + + @Override + public boolean isSupportingForced() + { + return true; + } + + @Override + protected void close() throws IOException + { + compressor.close(); + } + + @Override + protected String getArchiveType() + { + return "xz"; + } +} diff --git a/src/main/java/org/codehaus/plexus/archiver/xz/XZCompressor.java b/src/main/java/org/codehaus/plexus/archiver/xz/XZCompressor.java new file mode 100644 index 000000000..9797f95ef --- /dev/null +++ b/src/main/java/org/codehaus/plexus/archiver/xz/XZCompressor.java @@ -0,0 +1,60 @@ +/* + * Copyright 2016 Codehaus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.plexus.archiver.xz; + +import java.io.IOException; +import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.util.Compressor; +import org.codehaus.plexus.util.IOUtil; + +import static org.codehaus.plexus.archiver.util.Streams.bufferedOutputStream; +import static org.codehaus.plexus.archiver.util.Streams.fileOutputStream; + +/** + * + * @author philip.lourandos + */ +public class XZCompressor extends Compressor +{ + private XZCompressorOutputStream xzOut; + + public XZCompressor() + { + } + + @Override + public void compress() throws ArchiverException + { + try + { + xzOut = new XZCompressorOutputStream( bufferedOutputStream( fileOutputStream( getDestFile() ) ) ); + + compress( getSource(), xzOut); + } + catch ( IOException ioe ) + { + throw new ArchiverException( "Problem creating xz " + ioe.getMessage(), ioe); + } + } + + @Override + public void close() + { + IOUtil.close( xzOut ); + xzOut = null; + } +} diff --git a/src/main/java/org/codehaus/plexus/archiver/xz/XZUnArchiver.java b/src/main/java/org/codehaus/plexus/archiver/xz/XZUnArchiver.java new file mode 100644 index 000000000..48e229966 --- /dev/null +++ b/src/main/java/org/codehaus/plexus/archiver/xz/XZUnArchiver.java @@ -0,0 +1,80 @@ +/* + * Copyright 2016 Codehaus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.plexus.archiver.xz; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import javax.annotation.Nonnull; +import org.apache.commons.compress.compressors.xz.XZCompressorInputStream; +import org.codehaus.plexus.archiver.AbstractUnArchiver; +import org.codehaus.plexus.archiver.ArchiverException; + +import static org.codehaus.plexus.archiver.util.Streams.bufferedInputStream; +import static org.codehaus.plexus.archiver.util.Streams.bufferedOutputStream; +import static org.codehaus.plexus.archiver.util.Streams.copyFully; +import static org.codehaus.plexus.archiver.util.Streams.fileInputStream; +import static org.codehaus.plexus.archiver.util.Streams.fileOutputStream; + +/** + * + * @author philip.lourandos + */ +public class XZUnArchiver extends AbstractUnArchiver +{ + private static final String OPERATION_XZ = "xz"; + + public XZUnArchiver() + { + } + + public XZUnArchiver( File source ) + { + super( source ); + } + + @Override + protected void execute() throws ArchiverException + { + if ( getSourceFile().lastModified() > getDestFile().lastModified() ) + { + getLogger().info( "Expanding " + getSourceFile().getAbsolutePath() + " to " + + getDestFile().getAbsolutePath() ); + + copyFully( getXZInputStream( bufferedInputStream( fileInputStream( getSourceFile(), OPERATION_XZ) ) ), + bufferedOutputStream( fileOutputStream( getDestFile(), OPERATION_XZ) ), OPERATION_XZ ); + } + } + + public static @Nonnull XZCompressorInputStream getXZInputStream( InputStream in ) + throws ArchiverException + { + try + { + return new XZCompressorInputStream(in); + } + catch (IOException ioe) + { + throw new ArchiverException( "Trouble creating BZIP2 compressor, invalid file ?", ioe ); + } + } + + @Override + protected void execute(String path, File outputDirectory) throws ArchiverException { + throw new UnsupportedOperationException("Targeted execution not supported in xz format"); + + } +} From ce16809f3dc016e28a0bf13ae0740f03656409c9 Mon Sep 17 00:00:00 2001 From: lore Date: Sun, 20 Mar 2016 10:39:21 +0200 Subject: [PATCH 03/14] Add xz components for tar operations --- .../PlexusIoTarXZFileResourceCollection.java | 37 +++++++++++++++++ .../plexus/archiver/tar/TarXZUnArchiver.java | 40 +++++++++++++++++++ .../plexus/archiver/tar/XZTarFile.java | 40 +++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 src/main/java/org/codehaus/plexus/archiver/tar/PlexusIoTarXZFileResourceCollection.java create mode 100644 src/main/java/org/codehaus/plexus/archiver/tar/TarXZUnArchiver.java create mode 100644 src/main/java/org/codehaus/plexus/archiver/tar/XZTarFile.java diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/PlexusIoTarXZFileResourceCollection.java b/src/main/java/org/codehaus/plexus/archiver/tar/PlexusIoTarXZFileResourceCollection.java new file mode 100644 index 000000000..a030d9949 --- /dev/null +++ b/src/main/java/org/codehaus/plexus/archiver/tar/PlexusIoTarXZFileResourceCollection.java @@ -0,0 +1,37 @@ +/* + * Copyright 2016 Codehaus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.plexus.archiver.tar; + +import java.io.File; + +/** + * + * @author philip.lourandos + */ +public class PlexusIoTarXZFileResourceCollection extends + PlexusIoTarFileResourceCollection +{ + + public PlexusIoTarXZFileResourceCollection() + { + } + + @Override + protected TarFile newTarFile(File file) + { + return new XZTarFile( file ); + } +} diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/TarXZUnArchiver.java b/src/main/java/org/codehaus/plexus/archiver/tar/TarXZUnArchiver.java new file mode 100644 index 000000000..ecc60ccfb --- /dev/null +++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarXZUnArchiver.java @@ -0,0 +1,40 @@ +/* + * Copyright 2016 Codehaus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.plexus.archiver.tar; + +import java.io.File; + +/** + * + * @author philip.lourandos + */ +public class TarXZUnArchiver extends TarUnArchiver +{ + public TarXZUnArchiver() { + setupCompressionMethod(); + } + + public TarXZUnArchiver(File sourceFile) { + super(sourceFile); + + setupCompressionMethod(); + } + + private final void setupCompressionMethod() + { + setCompression(TarUnArchiver.UntarCompressionMethod.XZ); + } +} diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/XZTarFile.java b/src/main/java/org/codehaus/plexus/archiver/tar/XZTarFile.java new file mode 100644 index 000000000..5a700fead --- /dev/null +++ b/src/main/java/org/codehaus/plexus/archiver/tar/XZTarFile.java @@ -0,0 +1,40 @@ +/* + * Copyright 2016 Codehaus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.plexus.archiver.tar; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import org.codehaus.plexus.archiver.xz.XZUnArchiver; + +/** + * + * @author philip.lourandos + */ +public class XZTarFile extends TarFile +{ + + public XZTarFile ( File file ) + { + super(file); + } + + @Override + protected InputStream getInputStream( File file ) throws IOException + { + return XZUnArchiver.getXZInputStream( super.getInputStream( file ) ); + } +} From 3a9117b56555ba3b8d5c555c5a86ba8d34bb5923 Mon Sep 17 00:00:00 2001 From: lore Date: Sun, 20 Mar 2016 10:40:28 +0200 Subject: [PATCH 04/14] Added check for xz to return xz compressor output stream --- .../org/codehaus/plexus/archiver/tar/TarArchiver.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/TarArchiver.java b/src/main/java/org/codehaus/plexus/archiver/tar/TarArchiver.java index 47a2851cf..2425e0189 100644 --- a/src/main/java/org/codehaus/plexus/archiver/tar/TarArchiver.java +++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarArchiver.java @@ -20,6 +20,7 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; +import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; import org.codehaus.plexus.archiver.AbstractArchiver; import org.codehaus.plexus.archiver.ArchiveEntry; import org.codehaus.plexus.archiver.ArchiverException; @@ -465,7 +466,8 @@ public static enum TarCompressionMethod none, gzip, bzip2, - snappy + snappy, + xz } @@ -484,6 +486,11 @@ else if ( TarCompressionMethod.snappy.equals( tarCompressionMethod ) ) { return new SnappyOutputStream( bufferedOutputStream( ostream ) ); } + else if (TarCompressionMethod.xz.equals( tarCompressionMethod ) ) + { + return new XZCompressorOutputStream( bufferedOutputStream( ostream ) ); + } + return ostream; } From d97f829d4478c063436befe6ccfc5d30e1b93d84 Mon Sep 17 00:00:00 2001 From: lore Date: Sun, 20 Mar 2016 10:41:04 +0200 Subject: [PATCH 05/14] Added check for xz to return xz decompressor input stream --- .../org/codehaus/plexus/archiver/tar/TarUnArchiver.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/TarUnArchiver.java b/src/main/java/org/codehaus/plexus/archiver/tar/TarUnArchiver.java index 3de21e5d5..82dff777d 100644 --- a/src/main/java/org/codehaus/plexus/archiver/tar/TarUnArchiver.java +++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarUnArchiver.java @@ -20,6 +20,7 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; +import org.apache.commons.compress.compressors.xz.XZCompressorInputStream; import org.codehaus.plexus.archiver.AbstractUnArchiver; import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.util.Streams; @@ -63,6 +64,7 @@ public TarUnArchiver( File sourceFile ) *
  • gzip - Gzip compression
  • *
  • bzip2 - Bzip2 compression
  • *
  • snappy - Snappy compression
  • + *
  • xz - Xz compression
  • * * * @param method compression method @@ -149,6 +151,10 @@ else if ( compression == UntarCompressionMethod.BZIP2 ) else if ( compression == UntarCompressionMethod.SNAPPY ) { return new SnappyInputStream( istream, true ); + } + else if (compression == UntarCompressionMethod.XZ) + { + return new XZCompressorInputStream(istream); } return istream; } @@ -161,7 +167,8 @@ public static enum UntarCompressionMethod NONE( "none" ), GZIP( "gzip" ), BZIP2( "bzip2" ), - SNAPPY( "snappy" ); + SNAPPY( "snappy" ), + XZ("xz"); final String value; From 67370b80a5ef2807f78be16d4fcddf685e3cc793 Mon Sep 17 00:00:00 2001 From: lore Date: Sun, 20 Mar 2016 10:57:11 +0200 Subject: [PATCH 06/14] Testcase for tar xz --- .../archiver/tar/TarXzUnArchiverTest.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/test/java/org/codehaus/plexus/archiver/tar/TarXzUnArchiverTest.java diff --git a/src/test/java/org/codehaus/plexus/archiver/tar/TarXzUnArchiverTest.java b/src/test/java/org/codehaus/plexus/archiver/tar/TarXzUnArchiverTest.java new file mode 100644 index 000000000..c1c5963d0 --- /dev/null +++ b/src/test/java/org/codehaus/plexus/archiver/tar/TarXzUnArchiverTest.java @@ -0,0 +1,80 @@ +/* + * Copyright 2016 Codehaus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.plexus.archiver.tar; + +import java.io.File; +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertTrue; +import org.codehaus.plexus.PlexusTestCase; +import static org.codehaus.plexus.PlexusTestCase.getTestFile; +import org.codehaus.plexus.archiver.Archiver; +import org.codehaus.plexus.archiver.UnArchiver; +import org.codehaus.plexus.archiver.xz.XZArchiver; + +/** + * + * @author philip.lourandos + */ +public class TarXzUnArchiverTest extends PlexusTestCase { + + public void testExtract() + throws Exception + { + TarArchiver tarArchiver = (TarArchiver) lookup( Archiver.ROLE, "tar" ); + tarArchiver.setLongfile(TarLongFileMode.posix ); + + String fileName1 = "TarBZip2UnArchiverTest1.txt"; + String fileName2 = "TarBZip2UnArchiverTest2.txt"; + File file1InTar = getTestFile( "target/output/" + fileName1 ); + File file2InTar = getTestFile( "target/output/" + fileName2 ); + file1InTar.delete(); + file2InTar.delete(); + + assertFalse(file1InTar.exists()); + assertFalse(file2InTar.exists()); + + File testXZFile = getTestFile( "target/output/archive.tar.xz" ); + assertFalse(testXZFile.exists()); + + tarArchiver.addFile( getTestFile( "src/test/resources/manifests/manifest1.mf" ), fileName1 ); + tarArchiver.addFile( getTestFile( "src/test/resources/manifests/manifest2.mf" ), fileName2, 0664 ); + tarArchiver.setDestFile( getTestFile( "target/output/archive.tar" ) ); + tarArchiver.createArchive(); + + XZArchiver xzArchiver = (XZArchiver) lookup( Archiver.ROLE, "xz" ); + + assertTrue(testXZFile.exists()); + xzArchiver.setDestFile( testXZFile ); + xzArchiver.addFile( getTestFile( "target/output/archive.tar" ), "dontcare" ); + xzArchiver.createArchive(); + + TarXZUnArchiver tarXZUnArchiver = (TarXZUnArchiver) lookup( UnArchiver.ROLE, "tar.xz" ); + + tarXZUnArchiver.setDestDirectory( getTestFile( "target/output" ) ); + tarXZUnArchiver.setSourceFile( testXZFile ); + tarXZUnArchiver.extract(); + + assertTrue( file1InTar.exists() ); + assertTrue( file2InTar.exists() ); + + assertEquals( testXZFile, tarXZUnArchiver.getSourceFile() ); + } + + public void testLookup() throws Exception + { + assertNotNull( lookup( UnArchiver.ROLE, "tar.xz" ) ); + } +} From 2d7174d8c44e8ef9ec9101893cb66feca3902467 Mon Sep 17 00:00:00 2001 From: lore Date: Sun, 20 Mar 2016 16:46:36 +0200 Subject: [PATCH 07/14] Renamed --- .../xz/PlexusIOXZResourceCollection.java | 63 ------------------- 1 file changed, 63 deletions(-) delete mode 100644 src/main/java/org/codehaus/plexus/archiver/xz/PlexusIOXZResourceCollection.java diff --git a/src/main/java/org/codehaus/plexus/archiver/xz/PlexusIOXZResourceCollection.java b/src/main/java/org/codehaus/plexus/archiver/xz/PlexusIOXZResourceCollection.java deleted file mode 100644 index 656ac35ab..000000000 --- a/src/main/java/org/codehaus/plexus/archiver/xz/PlexusIOXZResourceCollection.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2016 Codehaus. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.codehaus.plexus.archiver.xz; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import org.codehaus.plexus.components.io.attributes.Java7FileAttributes; -import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; -import org.codehaus.plexus.components.io.resources.PlexusIoCompressedFileResourceCollection; -import org.codehaus.plexus.util.IOUtil; - -/** - * - * @author lore - */ -public class PlexusIOXZResourceCollection extends PlexusIoCompressedFileResourceCollection -{ - - @Override - protected PlexusIoResourceAttributes getAttributes( File file ) throws IOException - { - return new Java7FileAttributes(file, new HashMap(), new HashMap()); - } - - @Override - protected String getDefaultExtension() - { - return ".xz"; - } - - @Override - protected InputStream getInputStream( File file ) throws IOException - { - FileInputStream fileIs = new FileInputStream( file ); - - try - { - final InputStream result = XZUnArchiver.getXZInputStream( fileIs ); - - return result; - } - finally - { - IOUtil.close(fileIs); - } - } -} From f13591453034fb61f5dd7cd0f4a2eac5a637eb53 Mon Sep 17 00:00:00 2001 From: lore Date: Sun, 20 Mar 2016 16:48:52 +0200 Subject: [PATCH 08/14] Renamed --- .../xz/PlexusIoXZResourceCollection.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/main/java/org/codehaus/plexus/archiver/xz/PlexusIoXZResourceCollection.java diff --git a/src/main/java/org/codehaus/plexus/archiver/xz/PlexusIoXZResourceCollection.java b/src/main/java/org/codehaus/plexus/archiver/xz/PlexusIoXZResourceCollection.java new file mode 100644 index 000000000..440640cdb --- /dev/null +++ b/src/main/java/org/codehaus/plexus/archiver/xz/PlexusIoXZResourceCollection.java @@ -0,0 +1,63 @@ +/* + * Copyright 2016 Codehaus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.plexus.archiver.xz; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import org.codehaus.plexus.components.io.attributes.Java7FileAttributes; +import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; +import org.codehaus.plexus.components.io.resources.PlexusIoCompressedFileResourceCollection; +import org.codehaus.plexus.util.IOUtil; + +/** + * + * @author lore + */ +public class PlexusIoXZResourceCollection extends PlexusIoCompressedFileResourceCollection +{ + + @Override + protected PlexusIoResourceAttributes getAttributes( File file ) throws IOException + { + return new Java7FileAttributes(file, new HashMap(), new HashMap()); + } + + @Override + protected String getDefaultExtension() + { + return ".xz"; + } + + @Override + protected InputStream getInputStream( File file ) throws IOException + { + FileInputStream fileIs = new FileInputStream( file ); + + try + { + final InputStream result = XZUnArchiver.getXZInputStream( fileIs ); + + return result; + } + finally + { + IOUtil.close(fileIs); + } + } +} From 999a6dd702a63d278bbc2491e55d3265f2ac8822 Mon Sep 17 00:00:00 2001 From: lore Date: Sun, 20 Mar 2016 16:49:33 +0200 Subject: [PATCH 09/14] Testcase added --- .../plexus/archiver/xz/XzArchiverTest.java | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 src/test/java/org/codehaus/plexus/archiver/xz/XzArchiverTest.java diff --git a/src/test/java/org/codehaus/plexus/archiver/xz/XzArchiverTest.java b/src/test/java/org/codehaus/plexus/archiver/xz/XzArchiverTest.java new file mode 100644 index 000000000..ed1fa2039 --- /dev/null +++ b/src/test/java/org/codehaus/plexus/archiver/xz/XzArchiverTest.java @@ -0,0 +1,128 @@ +/* + * Copyright 2016 Codehaus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.plexus.archiver.xz; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.Arrays; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertFalse; +import static junit.framework.TestCase.assertTrue; +import static org.codehaus.plexus.PlexusTestCase.getTestFile; +import org.codehaus.plexus.archiver.Archiver; +import org.codehaus.plexus.archiver.BasePlexusArchiverTest; +import org.codehaus.plexus.archiver.xz.XZArchiver; +import org.codehaus.plexus.archiver.zip.ZipArchiver; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.IOUtil; + +/** + * + * @author philip.lourandos + */ +public class XzArchiverTest extends BasePlexusArchiverTest +{ + public void testCreateArchive() + throws Exception + { + ZipArchiver zipArchiver = (ZipArchiver) lookup( Archiver.ROLE, "zip" ); + zipArchiver.addDirectory( getTestFile( "src" ) ); + zipArchiver.setDestFile( getTestFile( "target/output/archiveForxz.zip" ) ); + zipArchiver.createArchive(); + + XZArchiver archiver = (XZArchiver) lookup( Archiver.ROLE, "xz" ); + String[] inputFiles = new String[ 1 ]; + inputFiles[ 0 ] = "archiveForxz.zip"; + + File targetOutputFile = getTestFile( "target/output/archive.xz" ); + assertFalse( targetOutputFile.exists() ); + + archiver.addDirectory( getTestFile( "target/output" ), inputFiles, null ); + archiver.setDestFile( targetOutputFile ); + archiver.createArchive(); + + assertTrue( targetOutputFile.exists() ); + } + + public void testCreateResourceCollection() throws Exception + { + final File pomFile = new File("pom.xml"); + final File xzFile = new File( "target/output/pom.xml.xz" ); + XZArchiver xzArchiver = (XZArchiver) lookup( Archiver.ROLE, "xz" ); + xzArchiver.setDestFile( xzFile ); + xzArchiver.addFile( pomFile, "pom.xml" ); + FileUtils.removePath( xzFile.getPath() ); + xzArchiver.createArchive(); + + System.out.println( "Created: " + xzFile.getAbsolutePath() ); + + final File zipFile = new File( "target/output/pomxz.zip" ); + ZipArchiver zipArchiver = (ZipArchiver) lookup( Archiver.ROLE, "zip" ); + zipArchiver.setDestFile( zipFile ); + zipArchiver.addArchivedFileSet( xzFile, "prfx/" ); + FileUtils.removePath( zipFile.getPath() ); + zipArchiver.createArchive(); + + final ZipFile juZipFile = new ZipFile( zipFile ); + final ZipEntry zipEntry = juZipFile.getEntry( "prfx/target/output/pom.xml" ); + final InputStream archivePom = juZipFile.getInputStream( zipEntry ); + final InputStream pom = new FileInputStream( pomFile ); + + assertTrue( Arrays.equals( IOUtil.toByteArray( pom ), IOUtil.toByteArray( archivePom ) ) ); + archivePom.close(); + pom.close(); + juZipFile.close(); + } + + /** + * Tests the .xz archiver is forced set to true, and after that + * tests the behavior when the forced is set to false. + * + * @throws Exception + */ + public void testBz2IsForcedBehaviour() throws Exception + { + XZArchiver xzArchiver = (XZArchiver) createArchiver( "xz" ); + + assertTrue( xzArchiver.isSupportingForced() ); + xzArchiver.createArchive(); + + final long creationTime = xzArchiver.getDestFile().lastModified(); + + waitUntilNewTimestamp( xzArchiver.getDestFile(), creationTime ); + + xzArchiver = (XZArchiver) createArchiver( "xz" ); + + xzArchiver.setForced( true ); + xzArchiver.createArchive(); + + final long firstRunTime = xzArchiver.getDestFile().lastModified(); + + assertFalse( creationTime==firstRunTime ); + + xzArchiver = (XZArchiver) createArchiver( "xz" ); + + xzArchiver.setForced( false ); + xzArchiver.createArchive(); + + final long secondRunTime = xzArchiver.getDestFile().lastModified(); + + assertEquals( firstRunTime,secondRunTime ); + } +} From 888acbb54d8b1786494d17f422001cdd117454d3 Mon Sep 17 00:00:00 2001 From: lore Date: Sun, 20 Mar 2016 16:49:59 +0200 Subject: [PATCH 10/14] Added org.tukaani dependency --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index 50851e94d..ce66bf4aa 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,12 @@ 3.0.0 provided + + org.tukaani + xz + 1.5 + runtime + From 4cec92aeedac93f164ed885147aebc4a57f7a3f3 Mon Sep 17 00:00:00 2001 From: lore Date: Sun, 20 Mar 2016 17:01:42 +0200 Subject: [PATCH 11/14] Added 'txz' extension registration --- src/main/resources/META-INF/plexus/components.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/resources/META-INF/plexus/components.xml b/src/main/resources/META-INF/plexus/components.xml index 02ca1a1ce..d19b7a89f 100644 --- a/src/main/resources/META-INF/plexus/components.xml +++ b/src/main/resources/META-INF/plexus/components.xml @@ -214,6 +214,13 @@ per-lookup
    + + org.codehaus.plexus.archiver.UnArchiver + txz + org.codehaus.plexus.archiver.tar.TarXZUnArchiver + per-lookup + + org.codehaus.plexus.archiver.UnArchiver tar.xz @@ -406,6 +413,12 @@ org.codehaus.plexus.archiver.tar.PlexusIoTarBZip2FileResourceCollection per-lookup + + org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection + txz + org.codehaus.plexus.archiver.tar.PlexusIoTarXZFileResourceCollection + per-lookup + org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection tar.xz From 920719185b734705123b27198c4967e7a0caafb9 Mon Sep 17 00:00:00 2001 From: Philip Lourandos Date: Sun, 27 Mar 2016 12:10:29 +0200 Subject: [PATCH 12/14] Corrected placement of assertion for file --- .../org/codehaus/plexus/archiver/tar/TarXzUnArchiverTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/codehaus/plexus/archiver/tar/TarXzUnArchiverTest.java b/src/test/java/org/codehaus/plexus/archiver/tar/TarXzUnArchiverTest.java index c1c5963d0..51309641f 100644 --- a/src/test/java/org/codehaus/plexus/archiver/tar/TarXzUnArchiverTest.java +++ b/src/test/java/org/codehaus/plexus/archiver/tar/TarXzUnArchiverTest.java @@ -56,10 +56,11 @@ public void testExtract() XZArchiver xzArchiver = (XZArchiver) lookup( Archiver.ROLE, "xz" ); - assertTrue(testXZFile.exists()); xzArchiver.setDestFile( testXZFile ); xzArchiver.addFile( getTestFile( "target/output/archive.tar" ), "dontcare" ); xzArchiver.createArchive(); + + assertTrue(testXZFile.exists()); TarXZUnArchiver tarXZUnArchiver = (TarXZUnArchiver) lookup( UnArchiver.ROLE, "tar.xz" ); From 5f9ef4cbe722aa9f826ac6355f0dd0d17f759b68 Mon Sep 17 00:00:00 2001 From: Philip Lourandos Date: Sun, 27 Mar 2016 12:31:40 +0200 Subject: [PATCH 13/14] # Removed import statement # Corrected method name to reflect xz test not bz2 --- .../java/org/codehaus/plexus/archiver/xz/XzArchiverTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/org/codehaus/plexus/archiver/xz/XzArchiverTest.java b/src/test/java/org/codehaus/plexus/archiver/xz/XzArchiverTest.java index ed1fa2039..3aab6ab8c 100644 --- a/src/test/java/org/codehaus/plexus/archiver/xz/XzArchiverTest.java +++ b/src/test/java/org/codehaus/plexus/archiver/xz/XzArchiverTest.java @@ -27,7 +27,6 @@ import static org.codehaus.plexus.PlexusTestCase.getTestFile; import org.codehaus.plexus.archiver.Archiver; import org.codehaus.plexus.archiver.BasePlexusArchiverTest; -import org.codehaus.plexus.archiver.xz.XZArchiver; import org.codehaus.plexus.archiver.zip.ZipArchiver; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; @@ -96,7 +95,7 @@ public void testCreateResourceCollection() throws Exception * * @throws Exception */ - public void testBz2IsForcedBehaviour() throws Exception + public void testXzIsForcedBehaviour() throws Exception { XZArchiver xzArchiver = (XZArchiver) createArchiver( "xz" ); From 394c0081e10f5860eba0b7110a0f1bc6d8e3dd32 Mon Sep 17 00:00:00 2001 From: Philip Lourandos Date: Sun, 27 Mar 2016 12:44:38 +0200 Subject: [PATCH 14/14] # Removed finally as this was causing the unit test to fail when creating zip archive --- .../xz/PlexusIoXZResourceCollection.java | 27 +++++-------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/archiver/xz/PlexusIoXZResourceCollection.java b/src/main/java/org/codehaus/plexus/archiver/xz/PlexusIoXZResourceCollection.java index 440640cdb..4b0c5599f 100644 --- a/src/main/java/org/codehaus/plexus/archiver/xz/PlexusIoXZResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/archiver/xz/PlexusIoXZResourceCollection.java @@ -23,41 +23,28 @@ import org.codehaus.plexus.components.io.attributes.Java7FileAttributes; import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; import org.codehaus.plexus.components.io.resources.PlexusIoCompressedFileResourceCollection; -import org.codehaus.plexus.util.IOUtil; /** * * @author lore */ -public class PlexusIoXZResourceCollection extends PlexusIoCompressedFileResourceCollection -{ +public class PlexusIoXZResourceCollection extends PlexusIoCompressedFileResourceCollection { @Override - protected PlexusIoResourceAttributes getAttributes( File file ) throws IOException - { + protected PlexusIoResourceAttributes getAttributes(File file) throws IOException { return new Java7FileAttributes(file, new HashMap(), new HashMap()); } @Override - protected String getDefaultExtension() - { + protected String getDefaultExtension() { return ".xz"; } @Override - protected InputStream getInputStream( File file ) throws IOException - { - FileInputStream fileIs = new FileInputStream( file ); - - try - { - final InputStream result = XZUnArchiver.getXZInputStream( fileIs ); + protected InputStream getInputStream(File file) throws IOException { + FileInputStream fileIs = new FileInputStream(file); + + return XZUnArchiver.getXZInputStream(fileIs); - return result; - } - finally - { - IOUtil.close(fileIs); - } } }