-
Notifications
You must be signed in to change notification settings - Fork 49
Added xz compression support #27
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
Merged
ChristianSchulte
merged 14 commits into
codehaus-plexus:master
from
philiplourandos:master
May 6, 2016
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ccb7128
Added configuration for xz components
a2a45f8
Added xz package to support xz archiving and un-archiving
ce16809
Add xz components for tar operations
3a9117b
Added check for xz to return xz compressor output stream
d97f829
Added check for xz to return xz decompressor input stream
67370b8
Testcase for tar xz
2d7174d
Renamed
f135914
Renamed
999a6dd
Testcase added
888acbb
Added org.tukaani dependency
4cec92a
Added 'txz' extension registration
9207191
Corrected placement of assertion for file
philiplourandos 5f9ef4c
# Removed import statement
philiplourandos 394c008
# Removed finally as this was causing the unit test to fail when crea…
philiplourandos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/org/codehaus/plexus/archiver/tar/PlexusIoTarXZFileResourceCollection.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/org/codehaus/plexus/archiver/tar/TarXZUnArchiver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/org/codehaus/plexus/archiver/tar/XZTarFile.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ) ); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/org/codehaus/plexus/archiver/xz/PlexusIoXZResourceCollection.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* | ||
* @author lore | ||
*/ | ||
public class PlexusIoXZResourceCollection extends PlexusIoCompressedFileResourceCollection { | ||
|
||
@Override | ||
protected PlexusIoResourceAttributes getAttributes(File file) throws IOException { | ||
return new Java7FileAttributes(file, new HashMap<Integer, String>(), new HashMap<Integer, String>()); | ||
} | ||
|
||
@Override | ||
protected String getDefaultExtension() { | ||
return ".xz"; | ||
} | ||
|
||
@Override | ||
protected InputStream getInputStream(File file) throws IOException { | ||
FileInputStream fileIs = new FileInputStream(file); | ||
|
||
return XZUnArchiver.getXZInputStream(fileIs); | ||
|
||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/org/codehaus/plexus/archiver/xz/XZArchiver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/org/codehaus/plexus/archiver/xz/XZCompressor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to throw an
ArchiverException
in case theclose
throws anIOException
.