diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs
new file mode 100644
index 000000000..964fac266
--- /dev/null
+++ b/.git-blame-ignore-revs
@@ -0,0 +1,2 @@
+# Change code style
+13b602af7169a8e49d47edf59f4154e1b834c0d8
diff --git a/.gitignore b/.gitignore
index 50a04dfbd..94a3b6c9f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,4 @@ bin
*.iml
*.iws
.idea
-
-
-
+.DS_Store
diff --git a/pom.xml b/pom.xml
index 8f0e5c194..a9a837e98 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,26 +1,40 @@
-
4.0.0
org.codehaus.plexus
plexus
- 10
+ 14
plexus-archiver
- 4.7.1
+ 4.8.0
Plexus Archiver Component
+ https://codehaus-plexus.github.io/plexus-archiver/
+
+
+
+ Dan Tran
+
+
+ Richard van der Hoff
+
+
+ Tomasz 'Trog' Welman
+ trog@swmud.pl
+
+
+
scm:git:https://github.com/codehaus-plexus/plexus-archiver.git
scm:git:https://github.com/codehaus-plexus/plexus-archiver.git
- http://github.com/codehaus-plexus/plexus-archiver/tree/${project.scm.tag}/
- plexus-archiver-4.7.1
+ plexus-archiver-4.8.0
+ https://github.com/codehaus-plexus/plexus-archiver/tree/${project.scm.tag}/
- jira
+ GitHub
https://github.com/codehaus-plexus/plexus-archiver/issues
@@ -31,26 +45,11 @@
- 8
- 0.3.5
+ 0.9.0.M2
1.7.36
- 5.9.3
- 2023-05-05T22:34:11Z
+ 2023-07-25T07:04:55Z
-
-
- Dan Tran
-
-
- Richard van der Hoff
-
-
- Tomasz 'Trog' Welman
- trog@swmud.pl
-
-
-
@@ -62,7 +61,7 @@
org.codehaus.plexus
plexus-utils
- 3.5.1
+ 4.0.0
org.codehaus.plexus
@@ -73,7 +72,7 @@
commons-io
commons-io
- 2.11.0
+ 2.13.0
org.apache.commons
@@ -100,7 +99,7 @@
com.github.luben
zstd-jni
- 1.5.5-2
+ 1.5.5-5
runtime
@@ -113,19 +112,11 @@
org.junit.jupiter
junit-jupiter-api
- ${junitVersion}
test
org.junit.jupiter
junit-jupiter-params
- ${junitVersion}
- test
-
-
- org.junit.jupiter
- junit-jupiter-engine
- ${junitVersion}
test
@@ -144,7 +135,7 @@
com.google.inject
guice
- 5.1.0
+ 6.0.0
test
@@ -167,11 +158,6 @@
-
- org.apache.maven.plugins
- maven-resources-plugin
- 3.3.1
-
org.eclipse.sisu
sisu-maven-plugin
@@ -190,15 +176,17 @@
org.apache.maven.plugins
maven-scm-publish-plugin
- ${project.reporting.outputDirectory}
+ ${project.reporting.outputDirectory}
+
scm-publish
- site-deploy
+
publish-scm
+ site-deploy
diff --git a/src/main/java/org/codehaus/plexus/archiver/AbstractArchiveFinalizer.java b/src/main/java/org/codehaus/plexus/archiver/AbstractArchiveFinalizer.java
index 92edeb97b..6239677d5 100644
--- a/src/main/java/org/codehaus/plexus/archiver/AbstractArchiveFinalizer.java
+++ b/src/main/java/org/codehaus/plexus/archiver/AbstractArchiveFinalizer.java
@@ -1,23 +1,12 @@
package org.codehaus.plexus.archiver;
-public abstract class AbstractArchiveFinalizer
- implements ArchiveFinalizer
-{
+public abstract class AbstractArchiveFinalizer implements ArchiveFinalizer {
- protected AbstractArchiveFinalizer()
- {
- }
+ protected AbstractArchiveFinalizer() {}
@Override
- public void finalizeArchiveCreation( Archiver archiver )
- throws ArchiverException
- {
- }
+ public void finalizeArchiveCreation(Archiver archiver) throws ArchiverException {}
@Override
- public void finalizeArchiveExtraction( UnArchiver unarchiver )
- throws ArchiverException
- {
- }
-
+ public void finalizeArchiveExtraction(UnArchiver unarchiver) throws ArchiverException {}
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/AbstractArchiver.java b/src/main/java/org/codehaus/plexus/archiver/AbstractArchiver.java
index c6b1b5577..217212ba4 100755
--- a/src/main/java/org/codehaus/plexus/archiver/AbstractArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/AbstractArchiver.java
@@ -16,6 +16,10 @@
*/
package org.codehaus.plexus.archiver;
+import javax.annotation.Nonnull;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
@@ -33,12 +37,10 @@
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
-import javax.annotation.Nonnull;
-import javax.inject.Inject;
-import javax.inject.Provider;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
+import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributeUtils;
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
import org.codehaus.plexus.components.io.attributes.SimpleResourceAttributes;
import org.codehaus.plexus.components.io.functions.ResourceAttributeSupplier;
@@ -55,14 +57,11 @@
import static org.codehaus.plexus.archiver.util.DefaultArchivedFileSet.archivedFileSet;
import static org.codehaus.plexus.archiver.util.DefaultFileSet.fileSet;
-public abstract class AbstractArchiver
- implements Archiver, FinalizerEnabled
-{
+public abstract class AbstractArchiver implements Archiver, FinalizerEnabled {
- private final Logger logger = LoggerFactory.getLogger( getClass() );
+ private final Logger logger = LoggerFactory.getLogger(getClass());
- protected Logger getLogger()
- {
+ protected Logger getLogger() {
return logger;
}
@@ -145,8 +144,7 @@ protected Logger getLogger()
@Inject
private Provider archiverManagerProvider;
- private static class AddedResourceCollection
- {
+ private static class AddedResourceCollection {
private final PlexusIoResourceCollection resources;
@@ -154,26 +152,19 @@ private static class AddedResourceCollection
private final int forcedDirectoryMode;
- public AddedResourceCollection( PlexusIoResourceCollection resources, int forcedFileMode, int forcedDirMode )
- {
+ public AddedResourceCollection(PlexusIoResourceCollection resources, int forcedFileMode, int forcedDirMode) {
this.resources = resources;
this.forcedFileMode = forcedFileMode;
this.forcedDirectoryMode = forcedDirMode;
}
- private int maybeOverridden( int suggestedMode, boolean isDir )
- {
- if ( isDir )
- {
+ private int maybeOverridden(int suggestedMode, boolean isDir) {
+ if (isDir) {
return forcedDirectoryMode >= 0 ? forcedDirectoryMode : suggestedMode;
- }
- else
- {
+ } else {
return forcedFileMode >= 0 ? forcedFileMode : suggestedMode;
-
}
}
-
}
/**
@@ -182,56 +173,43 @@ private int maybeOverridden( int suggestedMode, boolean isDir )
private boolean ignorePermissions = false;
@Override
- public String getDuplicateBehavior()
- {
+ public String getDuplicateBehavior() {
return duplicateBehavior;
}
@Override
- public void setDuplicateBehavior( final String duplicate )
- {
- if ( !Archiver.DUPLICATES_VALID_BEHAVIORS.contains( duplicate ) )
- {
- throw new IllegalArgumentException(
- "Invalid duplicate-file behavior: '" + duplicate + "'. Please specify one of: "
- + Archiver.DUPLICATES_VALID_BEHAVIORS );
+ public void setDuplicateBehavior(final String duplicate) {
+ if (!Archiver.DUPLICATES_VALID_BEHAVIORS.contains(duplicate)) {
+ throw new IllegalArgumentException("Invalid duplicate-file behavior: '" + duplicate
+ + "'. Please specify one of: " + Archiver.DUPLICATES_VALID_BEHAVIORS);
}
duplicateBehavior = duplicate;
}
@Override
- public final void setFileMode( final int mode )
- {
- if ( mode >= 0 )
- {
- forcedFileMode = ( mode & UnixStat.PERM_MASK ) | UnixStat.FILE_FLAG;
- }
- else
- {
+ public final void setFileMode(final int mode) {
+ if (mode >= 0) {
+ forcedFileMode = (mode & UnixStat.PERM_MASK) | UnixStat.FILE_FLAG;
+ } else {
forcedFileMode = -1;
}
}
@Override
- public final void setDefaultFileMode( final int mode )
- {
- defaultFileMode = ( mode & UnixStat.PERM_MASK ) | UnixStat.FILE_FLAG;
+ public final void setDefaultFileMode(final int mode) {
+ defaultFileMode = (mode & UnixStat.PERM_MASK) | UnixStat.FILE_FLAG;
}
@Override
- public final int getOverrideFileMode()
- {
+ public final int getOverrideFileMode() {
return forcedFileMode;
}
@Override
- public final int getFileMode()
- {
- if ( forcedFileMode < 0 )
- {
- if ( defaultFileMode < 0 )
- {
+ public final int getFileMode() {
+ if (forcedFileMode < 0) {
+ if (defaultFileMode < 0) {
return DEFAULT_FILE_MODE;
}
@@ -242,8 +220,7 @@ public final int getFileMode()
}
@Override
- public final int getDefaultFileMode()
- {
+ public final int getDefaultFileMode() {
return defaultFileMode;
}
@@ -251,43 +228,33 @@ public final int getDefaultFileMode()
* @deprecated Use {@link Archiver#getDefaultFileMode()}.
*/
@Deprecated
- public final int getRawDefaultFileMode()
- {
+ public final int getRawDefaultFileMode() {
return getDefaultFileMode();
}
@Override
- public final void setDirectoryMode( final int mode )
- {
- if ( mode >= 0 )
- {
- forcedDirectoryMode = ( mode & UnixStat.PERM_MASK ) | UnixStat.DIR_FLAG;
- }
- else
- {
+ public final void setDirectoryMode(final int mode) {
+ if (mode >= 0) {
+ forcedDirectoryMode = (mode & UnixStat.PERM_MASK) | UnixStat.DIR_FLAG;
+ } else {
forcedDirectoryMode = -1;
}
}
@Override
- public final void setDefaultDirectoryMode( final int mode )
- {
- defaultDirectoryMode = ( mode & UnixStat.PERM_MASK ) | UnixStat.DIR_FLAG;
+ public final void setDefaultDirectoryMode(final int mode) {
+ defaultDirectoryMode = (mode & UnixStat.PERM_MASK) | UnixStat.DIR_FLAG;
}
@Override
- public final int getOverrideDirectoryMode()
- {
+ public final int getOverrideDirectoryMode() {
return forcedDirectoryMode;
}
@Override
- public final int getDirectoryMode()
- {
- if ( forcedDirectoryMode < 0 )
- {
- if ( defaultDirectoryMode < 0 )
- {
+ public final int getDirectoryMode() {
+ if (forcedDirectoryMode < 0) {
+ if (defaultDirectoryMode < 0) {
return DEFAULT_DIR_MODE;
}
@@ -298,243 +265,232 @@ public final int getDirectoryMode()
}
@Override
- public final int getDefaultDirectoryMode()
- {
- if ( defaultDirectoryMode < 0 )
- {
+ public final int getDefaultDirectoryMode() {
+ if (defaultDirectoryMode < 0) {
return DEFAULT_DIR_MODE;
- }
- else
- {
+ } else {
return defaultDirectoryMode;
}
}
@Override
- public boolean getIncludeEmptyDirs()
- {
+ public boolean getIncludeEmptyDirs() {
return includeEmptyDirs;
}
@Override
- public void setIncludeEmptyDirs( final boolean includeEmptyDirs )
- {
+ public void setIncludeEmptyDirs(final boolean includeEmptyDirs) {
this.includeEmptyDirs = includeEmptyDirs;
}
@Override
- public void addDirectory( @Nonnull final File directory )
- throws ArchiverException
- {
- addFileSet(
- fileSet( directory ).prefixed( "" ).includeExclude( null, null ).includeEmptyDirs( includeEmptyDirs ) );
+ public void addDirectory(@Nonnull final File directory) throws ArchiverException {
+ addFileSet(fileSet(directory).prefixed("").includeExclude(null, null).includeEmptyDirs(includeEmptyDirs));
}
@Override
- public void addDirectory( @Nonnull final File directory, final String prefix )
- throws ArchiverException
- {
+ public void addDirectory(@Nonnull final File directory, final String prefix) throws ArchiverException {
addFileSet(
- fileSet( directory ).prefixed( prefix ).includeExclude( null, null ).includeEmptyDirs( includeEmptyDirs ) );
+ fileSet(directory).prefixed(prefix).includeExclude(null, null).includeEmptyDirs(includeEmptyDirs));
}
@Override
- public void addDirectory( @Nonnull final File directory, final String[] includes, final String[] excludes )
- throws ArchiverException
- {
- addFileSet( fileSet( directory ).prefixed( "" ).includeExclude( includes, excludes ).includeEmptyDirs(
- includeEmptyDirs ) );
+ public void addDirectory(@Nonnull final File directory, final String[] includes, final String[] excludes)
+ throws ArchiverException {
+ addFileSet(fileSet(directory)
+ .prefixed("")
+ .includeExclude(includes, excludes)
+ .includeEmptyDirs(includeEmptyDirs));
}
@Override
- public void addDirectory( @Nonnull final File directory, final String prefix, final String[] includes,
- final String[] excludes )
- throws ArchiverException
- {
- addFileSet( fileSet( directory ).prefixed( prefix ).includeExclude( includes, excludes ).includeEmptyDirs(
- includeEmptyDirs ) );
+ public void addDirectory(
+ @Nonnull final File directory, final String prefix, final String[] includes, final String[] excludes)
+ throws ArchiverException {
+ addFileSet(fileSet(directory)
+ .prefixed(prefix)
+ .includeExclude(includes, excludes)
+ .includeEmptyDirs(includeEmptyDirs));
}
@Override
- public void addFileSet( @Nonnull final FileSet fileSet )
- throws ArchiverException
- {
+ public void addFileSet(@Nonnull final FileSet fileSet) throws ArchiverException {
final File directory = fileSet.getDirectory();
- if ( directory == null )
- {
- throw new ArchiverException( "The file sets base directory is null." );
+ if (directory == null) {
+ throw new ArchiverException("The file sets base directory is null.");
}
- if ( !directory.isDirectory() )
- {
- throw new ArchiverException( directory.getAbsolutePath() + " isn't a directory." );
+ if (!directory.isDirectory()) {
+ throw new ArchiverException(directory.getAbsolutePath() + " isn't a directory.");
}
// The PlexusIoFileResourceCollection contains platform-specific File.separatorChar which
// is an interesting cause of grief, see PLXCOMP-192
final PlexusIoFileResourceCollection collection = new PlexusIoFileResourceCollection();
- collection.setFollowingSymLinks( false );
-
- collection.setIncludes( fileSet.getIncludes() );
- collection.setExcludes( fileSet.getExcludes() );
- collection.setBaseDir( directory );
- collection.setFileSelectors( fileSet.getFileSelectors() );
- collection.setIncludingEmptyDirectories( fileSet.isIncludingEmptyDirectories() );
- collection.setPrefix( fileSet.getPrefix() );
- collection.setCaseSensitive( fileSet.isCaseSensitive() );
- collection.setUsingDefaultExcludes( fileSet.isUsingDefaultExcludes() );
- collection.setStreamTransformer( fileSet.getStreamTransformer() );
- collection.setFileMappers( fileSet.getFileMappers() );
- collection.setFilenameComparator( getFilenameComparator() );
-
- if ( getOverrideDirectoryMode() > -1 || getOverrideFileMode() > -1 || getOverrideUid() > -1
- || getOverrideGid() > -1 || getOverrideUserName() != null || getOverrideGroupName() != null )
- {
- collection.setOverrideAttributes( getOverrideUid(), getOverrideUserName(), getOverrideGid(),
- getOverrideGroupName(), getOverrideFileMode(),
- getOverrideDirectoryMode() );
+ collection.setFollowingSymLinks(false);
+
+ collection.setIncludes(fileSet.getIncludes());
+ collection.setExcludes(fileSet.getExcludes());
+ collection.setBaseDir(directory);
+ collection.setFileSelectors(fileSet.getFileSelectors());
+ collection.setIncludingEmptyDirectories(fileSet.isIncludingEmptyDirectories());
+ collection.setPrefix(fileSet.getPrefix());
+ collection.setCaseSensitive(fileSet.isCaseSensitive());
+ collection.setUsingDefaultExcludes(fileSet.isUsingDefaultExcludes());
+ collection.setStreamTransformer(fileSet.getStreamTransformer());
+ collection.setFileMappers(fileSet.getFileMappers());
+ collection.setFilenameComparator(getFilenameComparator());
+
+ if (getOverrideDirectoryMode() > -1
+ || getOverrideFileMode() > -1
+ || getOverrideUid() > -1
+ || getOverrideGid() > -1
+ || getOverrideUserName() != null
+ || getOverrideGroupName() != null) {
+ collection.setOverrideAttributes(
+ getOverrideUid(),
+ getOverrideUserName(),
+ getOverrideGid(),
+ getOverrideGroupName(),
+ getOverrideFileMode(),
+ getOverrideDirectoryMode());
}
- if ( getDefaultDirectoryMode() > -1 || getDefaultFileMode() > -1 )
- {
- collection.setDefaultAttributes( -1, null, -1, null, getDefaultFileMode(), getDefaultDirectoryMode() );
+ if (getDefaultDirectoryMode() > -1 || getDefaultFileMode() > -1) {
+ collection.setDefaultAttributes(-1, null, -1, null, getDefaultFileMode(), getDefaultDirectoryMode());
}
- addResources( collection );
+ addResources(collection);
}
@Override
- public void addFile( @Nonnull final File inputFile, @Nonnull final String destFileName )
- throws ArchiverException
- {
- final int fileMode = getOverrideFileMode();
+ public void addFile(@Nonnull final File inputFile, @Nonnull final String destFileName) throws ArchiverException {
+ int permissions;
+ if (forcedFileMode > 0) {
+ permissions = forcedFileMode;
+ } else {
+ permissions = PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE;
+ try {
+ permissions = PlexusIoResourceAttributeUtils.getFileAttributes(inputFile)
+ .getOctalMode();
+ } catch (IOException ioe) {
+ // ignore
+ }
+ }
- addFile( inputFile, destFileName, fileMode );
+ addFile(inputFile, destFileName, permissions);
}
@Override
- public void addSymlink( String symlinkName, String symlinkDestination )
- throws ArchiverException
- {
+ public void addSymlink(String symlinkName, String symlinkDestination) throws ArchiverException {
final int fileMode = getOverrideFileMode();
- addSymlink( symlinkName, fileMode, symlinkDestination );
+ addSymlink(symlinkName, fileMode, symlinkDestination);
}
@Override
- public void addSymlink( String symlinkName, int permissions, String symlinkDestination )
- throws ArchiverException
- {
+ public void addSymlink(String symlinkName, int permissions, String symlinkDestination) throws ArchiverException {
doAddResource(
- ArchiveEntry.createSymlinkEntry( symlinkName, permissions, symlinkDestination, getDirectoryMode() ) );
- }
-
- private ArchiveEntry updateArchiveEntryAttributes( ArchiveEntry entry )
- {
- if ( getOverrideUid() > -1 || getOverrideGid() > -1 || getOverrideUserName() != null
- || getOverrideGroupName() != null )
- {
- entry.setResourceAttributes( new SimpleResourceAttributes( getOverrideUid(), getOverrideUserName(),
- getOverrideGid(), getOverrideGroupName(),
- entry.getMode() ) );
+ ArchiveEntry.createSymlinkEntry(symlinkName, permissions, symlinkDestination, getDirectoryMode()));
+ }
+
+ private ArchiveEntry updateArchiveEntryAttributes(ArchiveEntry entry) {
+ if (getOverrideUid() > -1
+ || getOverrideGid() > -1
+ || getOverrideUserName() != null
+ || getOverrideGroupName() != null) {
+ entry.setResourceAttributes(new SimpleResourceAttributes(
+ getOverrideUid(),
+ getOverrideUserName(),
+ getOverrideGid(),
+ getOverrideGroupName(),
+ entry.getMode()));
}
return entry;
}
- protected ArchiveEntry asArchiveEntry( @Nonnull final PlexusIoResource resource, final String destFileName,
- int permissions, PlexusIoResourceCollection collection )
- throws ArchiverException
- {
- if ( !resource.isExisting() )
- {
- throw new ArchiverException( resource.getName() + " not found." );
+ protected ArchiveEntry asArchiveEntry(
+ @Nonnull final PlexusIoResource resource,
+ final String destFileName,
+ int permissions,
+ PlexusIoResourceCollection collection)
+ throws ArchiverException {
+ if (!resource.isExisting()) {
+ throw new ArchiverException(resource.getName() + " not found.");
}
- if ( umask > 0 && permissions != PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE )
- {
+ if (umask > 0 && permissions != PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE) {
permissions &= ~umask;
}
ArchiveEntry entry;
- if ( resource.isFile() )
- {
- entry = ArchiveEntry.createFileEntry( destFileName, resource, permissions, collection, getDirectoryMode() );
- }
- else
- {
- entry = ArchiveEntry.createDirectoryEntry( destFileName, resource, permissions, getDirectoryMode() );
+ if (resource.isFile()) {
+ entry = ArchiveEntry.createFileEntry(destFileName, resource, permissions, collection, getDirectoryMode());
+ } else {
+ entry = ArchiveEntry.createDirectoryEntry(destFileName, resource, permissions, getDirectoryMode());
}
- return updateArchiveEntryAttributes( entry );
+ return updateArchiveEntryAttributes(entry);
}
- private ArchiveEntry asArchiveEntry( final AddedResourceCollection collection, final PlexusIoResource resource )
- throws ArchiverException
- {
- final String destFileName = collection.resources.getName( resource );
+ private ArchiveEntry asArchiveEntry(final AddedResourceCollection collection, final PlexusIoResource resource)
+ throws ArchiverException {
+ final String destFileName = collection.resources.getName(resource);
int fromResource = PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE;
- if ( resource instanceof ResourceAttributeSupplier )
- {
- final PlexusIoResourceAttributes attrs = ( (ResourceAttributeSupplier) resource ).getAttributes();
+ if (resource instanceof ResourceAttributeSupplier) {
+ final PlexusIoResourceAttributes attrs = ((ResourceAttributeSupplier) resource).getAttributes();
- if ( attrs != null )
- {
+ if (attrs != null) {
fromResource = attrs.getOctalMode();
}
}
- return asArchiveEntry( resource, destFileName,
- collection.maybeOverridden( fromResource, resource.isDirectory() ),
- collection.resources );
+ return asArchiveEntry(
+ resource,
+ destFileName,
+ collection.maybeOverridden(fromResource, resource.isDirectory()),
+ collection.resources);
}
@Override
- public void addResource( final PlexusIoResource resource, final String destFileName, final int permissions )
- throws ArchiverException
- {
- doAddResource( asArchiveEntry( resource, destFileName, permissions, null ) );
+ public void addResource(final PlexusIoResource resource, final String destFileName, final int permissions)
+ throws ArchiverException {
+ doAddResource(asArchiveEntry(resource, destFileName, permissions, null));
}
@Override
- public void addFile( @Nonnull final File inputFile, @Nonnull String destFileName, int permissions )
- throws ArchiverException
- {
- if ( !inputFile.isFile() || !inputFile.exists() )
- {
- throw new ArchiverException( inputFile.getAbsolutePath() + " isn't a file." );
+ public void addFile(@Nonnull final File inputFile, @Nonnull String destFileName, int permissions)
+ throws ArchiverException {
+ if (!inputFile.isFile() || !inputFile.exists()) {
+ throw new ArchiverException(inputFile.getAbsolutePath() + " isn't a file.");
}
- if ( replacePathSlashesToJavaPaths )
- {
- destFileName = destFileName.replace( '\\', '/' );
+ if (replacePathSlashesToJavaPaths) {
+ destFileName = destFileName.replace('\\', '/');
}
- if ( permissions < 0 )
- {
+ if (permissions < 0) {
permissions = getOverrideFileMode();
}
- try
- {
- // do a null check here, to avoid creating a file stream if there are no filters...
- ArchiveEntry entry =
- ArchiveEntry.createFileEntry( destFileName, inputFile, permissions, getDirectoryMode() );
- doAddResource( updateArchiveEntryAttributes( entry ) );
+ if (umask > 0 && permissions != PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE) {
+ permissions &= ~umask;
}
- catch ( final IOException e )
- {
- throw new ArchiverException( "Failed to determine inclusion status for: " + inputFile, e );
+
+ try {
+ // do a null check here, to avoid creating a file stream if there are no filters...
+ ArchiveEntry entry = ArchiveEntry.createFileEntry(destFileName, inputFile, permissions, getDirectoryMode());
+ doAddResource(updateArchiveEntryAttributes(entry));
+ } catch (final IOException e) {
+ throw new ArchiverException("Failed to determine inclusion status for: " + inputFile, e);
}
}
@Nonnull
@Override
- public ResourceIterator getResources()
- throws ArchiverException
- {
- return new ResourceIterator()
- {
+ public ResourceIterator getResources() throws ArchiverException {
+ return new ResourceIterator() {
private final Iterator
*/
-public class TarFile
- implements ArchiveFile
-{
+public class TarFile implements ArchiveFile {
private final java.io.File file;
@@ -49,8 +47,7 @@ public class TarFile
/**
* Creates a new instance with the given file.
*/
- public TarFile( File file )
- {
+ public TarFile(File file) {
this.file = file;
}
@@ -62,65 +59,48 @@ public TarFile( File file )
* current entry, then entries may be skipped.
*/
@Override
- public Enumeration getEntries()
- throws IOException
- {
- if ( inputStream != null )
- {
+ public Enumeration getEntries() throws IOException {
+ if (inputStream != null) {
close();
}
open();
- return new Enumeration()
- {
+ return new Enumeration() {
boolean currentEntryValid;
@Override
- public boolean hasMoreElements()
- {
- if ( !currentEntryValid )
- {
- try
- {
+ public boolean hasMoreElements() {
+ if (!currentEntryValid) {
+ try {
currentEntry = inputStream.getNextTarEntry();
- }
- catch ( IOException e )
- {
- throw new UndeclaredThrowableException( e );
+ } catch (IOException e) {
+ throw new UndeclaredThrowableException(e);
}
}
return currentEntry != null;
}
@Override
- public org.apache.commons.compress.archivers.ArchiveEntry nextElement()
- {
- if ( currentEntry == null )
- {
+ public org.apache.commons.compress.archivers.ArchiveEntry nextElement() {
+ if (currentEntry == null) {
throw new NoSuchElementException();
}
currentEntryValid = false;
return currentEntry;
}
-
};
}
- public void close()
- throws IOException
- {
- if ( inputStream != null )
- {
+ public void close() throws IOException {
+ if (inputStream != null) {
inputStream.close();
inputStream = null;
}
}
@Override
- public InputStream getInputStream( org.apache.commons.compress.archivers.ArchiveEntry entry )
- throws IOException
- {
- return getInputStream( new TarArchiveEntry( entry.getName() ) );
+ public InputStream getInputStream(org.apache.commons.compress.archivers.ArchiveEntry entry) throws IOException {
+ return getInputStream(new TarArchiveEntry(entry.getName()));
}
/**
@@ -129,86 +109,59 @@ public InputStream getInputStream( org.apache.commons.compress.archivers.Archive
* happens in that case, because an actual close would invalidate
* the underlying {@link TarArchiveInputStream}.
*/
- public InputStream getInputStream( TarArchiveEntry entry )
- throws IOException
- {
- if ( entry.equals( (Object) currentEntry ) && inputStream != null )
- {
- return new FilterInputStream( inputStream )
- {
-
- public void close()
- throws IOException
- {
+ public InputStream getInputStream(TarArchiveEntry entry) throws IOException {
+ if (entry.equals((Object) currentEntry) && inputStream != null) {
+ return new FilterInputStream(inputStream) {
+
+ public void close() throws IOException {
// Does nothing.
}
-
};
}
- return getInputStream( entry, currentEntry );
+ return getInputStream(entry, currentEntry);
}
- protected InputStream getInputStream( File file )
- throws IOException
- {
- return Streams.fileInputStream( file );
+ protected InputStream getInputStream(File file) throws IOException {
+ return Streams.fileInputStream(file);
}
- private InputStream getInputStream( TarArchiveEntry entry, TarArchiveEntry currentEntry )
- throws IOException
- {
- if ( currentEntry == null || inputStream == null )
- {
+ private InputStream getInputStream(TarArchiveEntry entry, TarArchiveEntry currentEntry) throws IOException {
+ if (currentEntry == null || inputStream == null) {
// Search for the entry from the beginning of the file to the end.
- if ( inputStream != null )
- {
+ if (inputStream != null) {
close();
}
open();
- if ( !findEntry( entry, null ) )
- {
- throw new IOException( "Unknown entry: " + entry.getName() );
+ if (!findEntry(entry, null)) {
+ throw new IOException("Unknown entry: " + entry.getName());
}
- }
- else
- {
+ } else {
// Search for the entry from the current position to the end of the file.
- if ( findEntry( entry, null ) )
- {
- return getInputStream( entry );
+ if (findEntry(entry, null)) {
+ return getInputStream(entry);
}
close();
open();
- if ( !findEntry( entry, currentEntry ) )
- {
- throw new IOException( "No such entry: " + entry.getName() );
+ if (!findEntry(entry, currentEntry)) {
+ throw new IOException("No such entry: " + entry.getName());
}
}
- return getInputStream( entry );
+ return getInputStream(entry);
}
- private void open()
- throws IOException
- {
- inputStream = new TarArchiveInputStream( bufferedInputStream( getInputStream( file ) ), "UTF8" );
+ private void open() throws IOException {
+ inputStream = new TarArchiveInputStream(bufferedInputStream(getInputStream(file)), "UTF8");
}
- private boolean findEntry( TarArchiveEntry entry, TarArchiveEntry currentEntry )
- throws IOException
- {
- for ( ;; )
- {
+ private boolean findEntry(TarArchiveEntry entry, TarArchiveEntry currentEntry) throws IOException {
+ for (; ; ) {
this.currentEntry = inputStream.getNextTarEntry();
- if ( this.currentEntry == null
- || ( currentEntry != null && this.currentEntry.equals( currentEntry ) ) )
- {
+ if (this.currentEntry == null || (currentEntry != null && this.currentEntry.equals(currentEntry))) {
return false;
}
- if ( this.currentEntry.equals( entry ) )
- {
+ if (this.currentEntry.equals(entry)) {
return true;
}
}
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/TarGZipArchiver.java b/src/main/java/org/codehaus/plexus/archiver/tar/TarGZipArchiver.java
index 1ee308dab..7dea3cc20 100644
--- a/src/main/java/org/codehaus/plexus/archiver/tar/TarGZipArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarGZipArchiver.java
@@ -23,19 +23,14 @@
*
* @since 4.7.0
*/
-@Named( "tar.gz" )
-public class TarGZipArchiver
- extends TarArchiver
-{
+@Named("tar.gz")
+public class TarGZipArchiver extends TarArchiver {
- public TarGZipArchiver()
- {
+ public TarGZipArchiver() {
this.setupCompressionMethod();
}
- private void setupCompressionMethod()
- {
- this.setCompression( TarCompressionMethod.gzip );
+ private void setupCompressionMethod() {
+ this.setCompression(TarCompressionMethod.gzip);
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/TarGZipUnArchiver.java b/src/main/java/org/codehaus/plexus/archiver/tar/TarGZipUnArchiver.java
index 879c8f0dc..b59f46e3d 100644
--- a/src/main/java/org/codehaus/plexus/archiver/tar/TarGZipUnArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarGZipUnArchiver.java
@@ -25,25 +25,19 @@
*
* @author Dan Tran
*/
-@Named( "tar.gz" )
-public class TarGZipUnArchiver
- extends TarUnArchiver
-{
+@Named("tar.gz")
+public class TarGZipUnArchiver extends TarUnArchiver {
- public TarGZipUnArchiver()
- {
+ public TarGZipUnArchiver() {
this.setupCompressionMethod();
}
- public TarGZipUnArchiver( File sourceFile )
- {
- super( sourceFile );
+ public TarGZipUnArchiver(File sourceFile) {
+ super(sourceFile);
this.setupCompressionMethod();
}
- private void setupCompressionMethod()
- {
- this.setCompression( UntarCompressionMethod.GZIP );
+ private void setupCompressionMethod() {
+ this.setCompression(UntarCompressionMethod.GZIP);
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/TarLongFileMode.java b/src/main/java/org/codehaus/plexus/archiver/tar/TarLongFileMode.java
index 76c1ac50b..8f312cd67 100644
--- a/src/main/java/org/codehaus/plexus/archiver/tar/TarLongFileMode.java
+++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarLongFileMode.java
@@ -19,9 +19,7 @@
/**
* Set of options for long file handling in the task.
*/
-public enum TarLongFileMode
-{
-
+public enum TarLongFileMode {
warn,
fail,
truncate,
@@ -33,57 +31,49 @@ public enum TarLongFileMode
/**
* @return true if value is "truncate".
*/
- public boolean isTruncateMode()
- {
- return truncate.equals( this );
+ public boolean isTruncateMode() {
+ return truncate.equals(this);
}
/**
* @return true if value is "warn".
*/
- public boolean isWarnMode()
- {
- return warn.equals( this );
+ public boolean isWarnMode() {
+ return warn.equals(this);
}
/**
* @return true if value is "gnu".
*/
- public boolean isGnuMode()
- {
- return gnu.equals( this );
+ public boolean isGnuMode() {
+ return gnu.equals(this);
}
/**
* @return true if value is "fail".
*/
- public boolean isFailMode()
- {
- return fail.equals( this );
+ public boolean isFailMode() {
+ return fail.equals(this);
}
/**
* @return true if value is "omit".
*/
- public boolean isOmitMode()
- {
- return omit.equals( this );
+ public boolean isOmitMode() {
+ return omit.equals(this);
}
/**
* @return true if value is "posix".
*/
- public boolean isPosixMode()
- {
- return posix.equals( this );
+ public boolean isPosixMode() {
+ return posix.equals(this);
}
/**
* @return true if value is "posix_warn".
*/
- public boolean isPosixWarnMode()
- {
- return posix_warn.equals( this );
+ public boolean isPosixWarnMode() {
+ return posix_warn.equals(this);
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/TarResource.java b/src/main/java/org/codehaus/plexus/archiver/tar/TarResource.java
index 46541cbad..dc6617d42 100644
--- a/src/main/java/org/codehaus/plexus/archiver/tar/TarResource.java
+++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarResource.java
@@ -1,9 +1,11 @@
package org.codehaus.plexus.archiver.tar;
+import javax.annotation.Nonnull;
+
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import javax.annotation.Nonnull;
+
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
import org.codehaus.plexus.components.io.attributes.SimpleResourceAttributes;
@@ -11,10 +13,7 @@
import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource;
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
-public class TarResource
- extends AbstractPlexusIoResource
- implements ResourceAttributeSupplier
-{
+public class TarResource extends AbstractPlexusIoResource implements ResourceAttributeSupplier {
private final TarFile tarFile;
@@ -22,53 +21,46 @@ public class TarResource
private PlexusIoResourceAttributes attributes;
- public TarResource( TarFile tarFile, TarArchiveEntry entry )
- {
- super( entry.getName(), getLastModifiedTime( entry ),
- entry.isDirectory() ? PlexusIoResource.UNKNOWN_RESOURCE_SIZE : entry.getSize(), !entry.isDirectory(),
- entry.isDirectory(), true );
+ public TarResource(TarFile tarFile, TarArchiveEntry entry) {
+ super(
+ entry.getName(),
+ getLastModifiedTime(entry),
+ entry.isDirectory() ? PlexusIoResource.UNKNOWN_RESOURCE_SIZE : entry.getSize(),
+ !entry.isDirectory(),
+ entry.isDirectory(),
+ true);
this.tarFile = tarFile;
this.entry = entry;
}
- private static long getLastModifiedTime( TarArchiveEntry entry )
- {
+ private static long getLastModifiedTime(TarArchiveEntry entry) {
long l = entry.getModTime().getTime();
return l == -1 ? PlexusIoResource.UNKNOWN_MODIFICATION_DATE : l;
}
@Override
- public synchronized PlexusIoResourceAttributes getAttributes()
- {
- if ( attributes == null )
- {
- attributes = new SimpleResourceAttributes( entry.getUserId(), entry.getUserName(), entry.getGroupId(),
- entry.getGroupName(), entry.getMode() );
-
+ public synchronized PlexusIoResourceAttributes getAttributes() {
+ if (attributes == null) {
+ attributes = new SimpleResourceAttributes(
+ entry.getUserId(), entry.getUserName(), entry.getGroupId(), entry.getGroupName(), entry.getMode());
}
return attributes;
}
- public synchronized void setAttributes( PlexusIoResourceAttributes attributes )
- {
+ public synchronized void setAttributes(PlexusIoResourceAttributes attributes) {
this.attributes = attributes;
}
@Override
- public URL getURL()
- throws IOException
- {
+ public URL getURL() throws IOException {
return null;
}
@Nonnull
@Override
- public InputStream getContents()
- throws IOException
- {
- return tarFile.getInputStream( entry );
+ public InputStream getContents() throws IOException {
+ return tarFile.getInputStream(entry);
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/TarSnappyArchiver.java b/src/main/java/org/codehaus/plexus/archiver/tar/TarSnappyArchiver.java
index 22afff0b9..f6d7b133f 100644
--- a/src/main/java/org/codehaus/plexus/archiver/tar/TarSnappyArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarSnappyArchiver.java
@@ -23,19 +23,14 @@
*
* @since 4.7.0
*/
-@Named( "tar.snappy" )
-public class TarSnappyArchiver
- extends TarArchiver
-{
+@Named("tar.snappy")
+public class TarSnappyArchiver extends TarArchiver {
- public TarSnappyArchiver()
- {
+ public TarSnappyArchiver() {
this.setupCompressionMethod();
}
- private void setupCompressionMethod()
- {
- this.setCompression( TarCompressionMethod.snappy );
+ private void setupCompressionMethod() {
+ this.setCompression(TarCompressionMethod.snappy);
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/TarSnappyUnArchiver.java b/src/main/java/org/codehaus/plexus/archiver/tar/TarSnappyUnArchiver.java
index e20cdfe6e..0d1958e2e 100644
--- a/src/main/java/org/codehaus/plexus/archiver/tar/TarSnappyUnArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarSnappyUnArchiver.java
@@ -24,25 +24,19 @@
* Extract files in tar with snappy compression
*
*/
-@Named( "tar.snappy" )
-public class TarSnappyUnArchiver
- extends TarUnArchiver
-{
+@Named("tar.snappy")
+public class TarSnappyUnArchiver extends TarUnArchiver {
- public TarSnappyUnArchiver()
- {
+ public TarSnappyUnArchiver() {
this.setupCompressionMethod();
}
- public TarSnappyUnArchiver( File sourceFile )
- {
- super( sourceFile );
+ public TarSnappyUnArchiver(File sourceFile) {
+ super(sourceFile);
this.setupCompressionMethod();
}
- private void setupCompressionMethod()
- {
- this.setCompression( UntarCompressionMethod.SNAPPY );
+ private void setupCompressionMethod() {
+ this.setCompression(UntarCompressionMethod.SNAPPY);
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/TarSymlinkResource.java b/src/main/java/org/codehaus/plexus/archiver/tar/TarSymlinkResource.java
index edfbd5966..5310872a7 100644
--- a/src/main/java/org/codehaus/plexus/archiver/tar/TarSymlinkResource.java
+++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarSymlinkResource.java
@@ -16,36 +16,29 @@
package org.codehaus.plexus.archiver.tar;
import java.io.IOException;
+
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier;
/**
* A {@link TarResource} that represents symbolic link.
*/
-public class TarSymlinkResource
- extends TarResource
- implements SymlinkDestinationSupplier
-{
+public class TarSymlinkResource extends TarResource implements SymlinkDestinationSupplier {
private final String symlinkDestination;
- public TarSymlinkResource( TarFile tarFile, TarArchiveEntry entry )
- {
- super( tarFile, entry );
+ public TarSymlinkResource(TarFile tarFile, TarArchiveEntry entry) {
+ super(tarFile, entry);
symlinkDestination = entry.getLinkName();
}
@Override
- public String getSymlinkDestination()
- throws IOException
- {
+ public String getSymlinkDestination() throws IOException {
return symlinkDestination;
}
@Override
- public boolean isSymbolicLink()
- {
+ public boolean isSymbolicLink() {
return true;
}
-
}
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 d88c3dd11..1b0b79509 100644
--- a/src/main/java/org/codehaus/plexus/archiver/tar/TarUnArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarUnArchiver.java
@@ -18,9 +18,6 @@
import javax.inject.Named;
-import static org.codehaus.plexus.archiver.util.Streams.bufferedInputStream;
-import static org.codehaus.plexus.archiver.util.Streams.fileInputStream;
-
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -37,21 +34,19 @@
import org.codehaus.plexus.components.io.filemappers.FileMapper;
import org.iq80.snappy.SnappyFramedInputStream;
+import static org.codehaus.plexus.archiver.util.Streams.bufferedInputStream;
+import static org.codehaus.plexus.archiver.util.Streams.fileInputStream;
+
/**
* @author Emmanuel Venisse
*/
-@Named( "tar" )
-public class TarUnArchiver
- extends AbstractUnArchiver
-{
+@Named("tar")
+public class TarUnArchiver extends AbstractUnArchiver {
- public TarUnArchiver()
- {
- }
+ public TarUnArchiver() {}
- public TarUnArchiver( File sourceFile )
- {
- super( sourceFile );
+ public TarUnArchiver(File sourceFile) {
+ super(sourceFile);
}
/**
@@ -73,60 +68,54 @@ public TarUnArchiver( File sourceFile )
*
* @param method compression method
*/
- public void setCompression( UntarCompressionMethod method )
- {
+ public void setCompression(UntarCompressionMethod method) {
compression = method;
}
/**
* No encoding support in Untar.
*/
- public void setEncoding( String encoding )
- {
- getLogger().warn( "The TarUnArchiver doesn't support the encoding attribute" );
+ public void setEncoding(String encoding) {
+ getLogger().warn("The TarUnArchiver doesn't support the encoding attribute");
}
@Override
- protected void execute()
- throws ArchiverException
- {
- execute( getSourceFile(), getDestDirectory(), getFileMappers() );
+ protected void execute() throws ArchiverException {
+ execute(getSourceFile(), getDestDirectory(), getFileMappers());
}
@Override
- protected void execute( String path, File outputDirectory )
- {
- execute( new File( path ), getDestDirectory(), getFileMappers() );
+ protected void execute(String path, File outputDirectory) {
+ execute(new File(path), getDestDirectory(), getFileMappers());
}
- protected void execute( File sourceFile, File destDirectory, FileMapper[] fileMappers )
- throws ArchiverException
- {
- try
- {
- getLogger().info( "Expanding: " + sourceFile + " into " + destDirectory );
- TarFile tarFile = new TarFile( sourceFile );
- try ( TarArchiveInputStream tis = new TarArchiveInputStream(
- decompress( compression, sourceFile, bufferedInputStream( fileInputStream( sourceFile ) ) ) ) )
- {
+ protected void execute(File sourceFile, File destDirectory, FileMapper[] fileMappers) throws ArchiverException {
+ try {
+ getLogger().info("Expanding: " + sourceFile + " into " + destDirectory);
+ TarFile tarFile = new TarFile(sourceFile);
+ try (TarArchiveInputStream tis = new TarArchiveInputStream(
+ decompress(compression, sourceFile, bufferedInputStream(fileInputStream(sourceFile))))) {
TarArchiveEntry te;
- while ( ( te = tis.getNextTarEntry() ) != null )
- {
- TarResource fileInfo = new TarResource( tarFile, te );
- if ( isSelected( te.getName(), fileInfo ) )
- {
+ while ((te = tis.getNextTarEntry()) != null) {
+ TarResource fileInfo = new TarResource(tarFile, te);
+ if (isSelected(te.getName(), fileInfo)) {
final String symlinkDestination = te.isSymbolicLink() ? te.getLinkName() : null;
- extractFile( sourceFile, destDirectory, tis, te.getName(), te.getModTime(), te.isDirectory(),
- te.getMode() != 0 ? te.getMode() : null, symlinkDestination, fileMappers );
-
+ extractFile(
+ sourceFile,
+ destDirectory,
+ tis,
+ te.getName(),
+ te.getModTime(),
+ te.isDirectory(),
+ te.getMode() != 0 ? te.getMode() : null,
+ symlinkDestination,
+ fileMappers);
}
}
- getLogger().debug( "expand complete" );
+ getLogger().debug("expand complete");
}
- }
- catch ( IOException ioe )
- {
- throw new ArchiverException( "Error while expanding " + sourceFile.getAbsolutePath(), ioe );
+ } catch (IOException ioe) {
+ throw new ArchiverException("Error while expanding " + sourceFile.getAbsolutePath(), ioe);
}
}
@@ -141,28 +130,18 @@ protected void execute( File sourceFile, File destDirectory, FileMapper[] fileMa
*
* @throws IOException thrown by GZIPInputStream constructor
*/
- private InputStream decompress( UntarCompressionMethod compression, final File file, final InputStream istream )
- throws IOException, ArchiverException
- {
- if ( compression == UntarCompressionMethod.GZIP )
- {
- return Streams.bufferedInputStream( new GZIPInputStream( istream ) );
- }
- else if ( compression == UntarCompressionMethod.BZIP2 )
- {
- return new BZip2CompressorInputStream( istream );
- }
- else if ( compression == UntarCompressionMethod.SNAPPY )
- {
- return new SnappyFramedInputStream( istream, true );
- }
- else if ( compression == UntarCompressionMethod.XZ )
- {
- return new XZCompressorInputStream( istream );
- }
- else if ( compression == UntarCompressionMethod.ZSTD )
- {
- return new ZstdCompressorInputStream( istream );
+ private InputStream decompress(UntarCompressionMethod compression, final File file, final InputStream istream)
+ throws IOException, ArchiverException {
+ if (compression == UntarCompressionMethod.GZIP) {
+ return Streams.bufferedInputStream(new GZIPInputStream(istream));
+ } else if (compression == UntarCompressionMethod.BZIP2) {
+ return new BZip2CompressorInputStream(istream);
+ } else if (compression == UntarCompressionMethod.SNAPPY) {
+ return new SnappyFramedInputStream(istream, true);
+ } else if (compression == UntarCompressionMethod.XZ) {
+ return new XZCompressorInputStream(istream);
+ } else if (compression == UntarCompressionMethod.ZSTD) {
+ return new ZstdCompressorInputStream(istream);
}
return istream;
}
@@ -170,26 +149,21 @@ else if ( compression == UntarCompressionMethod.ZSTD )
/**
* Valid Modes for Compression attribute to Untar Task
*/
- public enum UntarCompressionMethod
- {
-
- NONE( "none" ),
- GZIP( "gzip" ),
- BZIP2( "bzip2" ),
- SNAPPY( "snappy" ),
- XZ( "xz" ),
- ZSTD( "zstd" );
+ public enum UntarCompressionMethod {
+ NONE("none"),
+ GZIP("gzip"),
+ BZIP2("bzip2"),
+ SNAPPY("snappy"),
+ XZ("xz"),
+ ZSTD("zstd");
final String value;
/**
* Constructor
*/
- UntarCompressionMethod( String value )
- {
+ UntarCompressionMethod(String value) {
this.value = value;
}
-
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/TarXZArchiver.java b/src/main/java/org/codehaus/plexus/archiver/tar/TarXZArchiver.java
index 754c35ddd..59ef920d2 100644
--- a/src/main/java/org/codehaus/plexus/archiver/tar/TarXZArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarXZArchiver.java
@@ -22,18 +22,14 @@
*
* @since 4.7.0
*/
-@Named( "tar.xz" )
-public class TarXZArchiver extends TarArchiver
-{
+@Named("tar.xz")
+public class TarXZArchiver extends TarArchiver {
- public TarXZArchiver()
- {
+ public TarXZArchiver() {
setupCompressionMethod();
}
- private void setupCompressionMethod()
- {
- setCompression( TarCompressionMethod.xz );
+ private void setupCompressionMethod() {
+ setCompression(TarCompressionMethod.xz);
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/TarXZUnArchiver.java b/src/main/java/org/codehaus/plexus/archiver/tar/TarXZUnArchiver.java
index 0c6160070..eba2fc154 100644
--- a/src/main/java/org/codehaus/plexus/archiver/tar/TarXZUnArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarXZUnArchiver.java
@@ -24,25 +24,20 @@
* @author philip.lourandos
* @since 3.3
*/
-@Named( "tar.xz" )
-public class TarXZUnArchiver extends TarUnArchiver
-{
+@Named("tar.xz")
+public class TarXZUnArchiver extends TarUnArchiver {
- public TarXZUnArchiver()
- {
+ public TarXZUnArchiver() {
setupCompressionMethod();
}
- public TarXZUnArchiver( File sourceFile )
- {
- super( sourceFile );
+ public TarXZUnArchiver(File sourceFile) {
+ super(sourceFile);
setupCompressionMethod();
}
- private void setupCompressionMethod()
- {
- setCompression( TarUnArchiver.UntarCompressionMethod.XZ );
+ private void setupCompressionMethod() {
+ setCompression(TarUnArchiver.UntarCompressionMethod.XZ);
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/TarZstdArchiver.java b/src/main/java/org/codehaus/plexus/archiver/tar/TarZstdArchiver.java
index 28c43c172..c1800174c 100644
--- a/src/main/java/org/codehaus/plexus/archiver/tar/TarZstdArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarZstdArchiver.java
@@ -22,17 +22,14 @@
*
* @since 4.7.0
*/
-@Named( "tar.zst" )
-public class TarZstdArchiver extends TarArchiver
-{
+@Named("tar.zst")
+public class TarZstdArchiver extends TarArchiver {
- public TarZstdArchiver()
- {
+ public TarZstdArchiver() {
setupCompressionMethod();
}
- private final void setupCompressionMethod()
- {
- setCompression( TarCompressionMethod.zstd );
+ private final void setupCompressionMethod() {
+ setCompression(TarCompressionMethod.zstd);
}
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/TarZstdUnArchiver.java b/src/main/java/org/codehaus/plexus/archiver/tar/TarZstdUnArchiver.java
index b144ccfcc..8902bdb37 100644
--- a/src/main/java/org/codehaus/plexus/archiver/tar/TarZstdUnArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/tar/TarZstdUnArchiver.java
@@ -16,30 +16,26 @@
package org.codehaus.plexus.archiver.tar;
import javax.inject.Named;
+
import java.io.File;
/**
* Extract files in tar with zstd compression
*/
-@Named( "tar.zst" )
-public class TarZstdUnArchiver extends TarUnArchiver
-{
+@Named("tar.zst")
+public class TarZstdUnArchiver extends TarUnArchiver {
- public TarZstdUnArchiver()
- {
+ public TarZstdUnArchiver() {
setupCompressionMethod();
}
- public TarZstdUnArchiver( File sourceFile )
- {
- super( sourceFile );
+ public TarZstdUnArchiver(File sourceFile) {
+ super(sourceFile);
setupCompressionMethod();
}
- private final void setupCompressionMethod()
- {
- setCompression( UntarCompressionMethod.ZSTD );
+ private final void setupCompressionMethod() {
+ setCompression(UntarCompressionMethod.ZSTD);
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/XZTarFile.java b/src/main/java/org/codehaus/plexus/archiver/tar/XZTarFile.java
index c35bd96c0..95fcef949 100644
--- a/src/main/java/org/codehaus/plexus/archiver/tar/XZTarFile.java
+++ b/src/main/java/org/codehaus/plexus/archiver/tar/XZTarFile.java
@@ -18,6 +18,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+
import org.codehaus.plexus.archiver.xz.XZUnArchiver;
/**
@@ -25,18 +26,14 @@
* @author philip.lourandos
* @since 3.3
*/
-public class XZTarFile extends TarFile
-{
+public class XZTarFile extends TarFile {
- public XZTarFile( File file )
- {
- super( file );
+ public XZTarFile(File file) {
+ super(file);
}
@Override
- protected InputStream getInputStream( File file ) throws IOException
- {
- return XZUnArchiver.getXZInputStream( super.getInputStream( file ) );
+ protected InputStream getInputStream(File file) throws IOException {
+ return XZUnArchiver.getXZInputStream(super.getInputStream(file));
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/tar/ZstdTarFile.java b/src/main/java/org/codehaus/plexus/archiver/tar/ZstdTarFile.java
index 9a65686c8..97404565c 100644
--- a/src/main/java/org/codehaus/plexus/archiver/tar/ZstdTarFile.java
+++ b/src/main/java/org/codehaus/plexus/archiver/tar/ZstdTarFile.java
@@ -15,27 +15,23 @@
*/
package org.codehaus.plexus.archiver.tar;
-import org.codehaus.plexus.archiver.zstd.ZstdUnArchiver;
-
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import org.codehaus.plexus.archiver.zstd.ZstdUnArchiver;
+
/**
* Extension of {@link org.codehaus.plexus.archiver.tar.TarFile} for zst compressed files.
*/
-public class ZstdTarFile extends TarFile
-{
+public class ZstdTarFile extends TarFile {
- public ZstdTarFile( File file )
- {
- super( file );
+ public ZstdTarFile(File file) {
+ super(file);
}
@Override
- protected InputStream getInputStream( File file ) throws IOException
- {
- return ZstdUnArchiver.getZstdInputStream( super.getInputStream( file ) );
+ protected InputStream getInputStream(File file) throws IOException {
+ return ZstdUnArchiver.getZstdInputStream(super.getInputStream(file));
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/util/AbstractFileSet.java b/src/main/java/org/codehaus/plexus/archiver/util/AbstractFileSet.java
index 0ec6d5966..5c2cde548 100644
--- a/src/main/java/org/codehaus/plexus/archiver/util/AbstractFileSet.java
+++ b/src/main/java/org/codehaus/plexus/archiver/util/AbstractFileSet.java
@@ -16,6 +16,7 @@
package org.codehaus.plexus.archiver.util;
import javax.annotation.Nonnull;
+
import org.codehaus.plexus.archiver.BaseFileSet;
import org.codehaus.plexus.components.io.filemappers.FileMapper;
import org.codehaus.plexus.components.io.fileselectors.FileSelector;
@@ -26,9 +27,7 @@
*
* @since 1.0-alpha-9
*/
-public abstract class AbstractFileSet
- implements BaseFileSet
-{
+public abstract class AbstractFileSet implements BaseFileSet {
private String prefix;
@@ -52,14 +51,12 @@ public abstract class AbstractFileSet
* Sets a string of patterns, which excluded files
* should match.
*/
- public void setExcludes( String[] excludes )
- {
+ public void setExcludes(String[] excludes) {
this.excludes = excludes;
}
@Override
- public String[] getExcludes()
- {
+ public String[] getExcludes() {
return excludes;
}
@@ -67,14 +64,12 @@ public String[] getExcludes()
* Sets a set of file selectors, which should be used
* to select the included files.
*/
- public void setFileSelectors( FileSelector[] fileSelectors )
- {
+ public void setFileSelectors(FileSelector[] fileSelectors) {
this.fileSelectors = fileSelectors;
}
@Override
- public FileSelector[] getFileSelectors()
- {
+ public FileSelector[] getFileSelectors() {
return fileSelectors;
}
@@ -82,14 +77,12 @@ public FileSelector[] getFileSelectors()
* Sets a string of patterns, which included files
* should match.
*/
- public void setIncludes( String[] includes )
- {
+ public void setIncludes(String[] includes) {
this.includes = includes;
}
@Override
- public String[] getIncludes()
- {
+ public String[] getIncludes() {
return includes;
}
@@ -97,14 +90,12 @@ public String[] getIncludes()
* Sets the prefix, which the file sets contents shall
* have.
*/
- public void setPrefix( String prefix )
- {
+ public void setPrefix(String prefix) {
this.prefix = prefix;
}
@Override
- public String getPrefix()
- {
+ public String getPrefix() {
return prefix;
}
@@ -112,14 +103,12 @@ public String getPrefix()
* Sets, whether the include/exclude patterns are
* case sensitive. Defaults to true.
*/
- public void setCaseSensitive( boolean caseSensitive )
- {
+ public void setCaseSensitive(boolean caseSensitive) {
this.caseSensitive = caseSensitive;
}
@Override
- public boolean isCaseSensitive()
- {
+ public boolean isCaseSensitive() {
return caseSensitive;
}
@@ -127,14 +116,12 @@ public boolean isCaseSensitive()
* Sets, whether the default excludes are being
* applied. Defaults to true.
*/
- public void setUsingDefaultExcludes( boolean usingDefaultExcludes )
- {
+ public void setUsingDefaultExcludes(boolean usingDefaultExcludes) {
this.usingDefaultExcludes = usingDefaultExcludes;
}
@Override
- public boolean isUsingDefaultExcludes()
- {
+ public boolean isUsingDefaultExcludes() {
return usingDefaultExcludes;
}
@@ -142,54 +129,45 @@ public boolean isUsingDefaultExcludes()
* Sets, whether empty directories are being included. Defaults
* to true.
*/
- public void setIncludingEmptyDirectories( boolean includingEmptyDirectories )
- {
+ public void setIncludingEmptyDirectories(boolean includingEmptyDirectories) {
this.includingEmptyDirectories = includingEmptyDirectories;
}
@Override
- public boolean isIncludingEmptyDirectories()
- {
+ public boolean isIncludingEmptyDirectories() {
return includingEmptyDirectories;
}
- public T prefixed( String prefix )
- {
- setPrefix( prefix );
+ public T prefixed(String prefix) {
+ setPrefix(prefix);
return (T) this;
}
- public T include( String[] includes )
- {
- setIncludes( includes );
+ public T include(String[] includes) {
+ setIncludes(includes);
return (T) this;
}
- public T exclude( String[] excludes )
- {
- setExcludes( excludes );
+ public T exclude(String[] excludes) {
+ setExcludes(excludes);
return (T) this;
}
- public T includeExclude( String[] includes, String[] excludes )
- {
- return (T) include( includes ).exclude( excludes );
+ public T includeExclude(String[] includes, String[] excludes) {
+ return (T) include(includes).exclude(excludes);
}
- public T includeEmptyDirs( boolean includeEmptyDirectories )
- {
- setIncludingEmptyDirectories( includeEmptyDirectories );
+ public T includeEmptyDirs(boolean includeEmptyDirectories) {
+ setIncludingEmptyDirectories(includeEmptyDirectories);
return (T) this;
}
- public void setStreamTransformer( @Nonnull InputStreamTransformer streamTransformer )
- {
+ public void setStreamTransformer(@Nonnull InputStreamTransformer streamTransformer) {
this.streamTransformer = streamTransformer;
}
@Override
- public InputStreamTransformer getStreamTransformer()
- {
+ public InputStreamTransformer getStreamTransformer() {
return streamTransformer;
}
@@ -197,15 +175,12 @@ public InputStreamTransformer getStreamTransformer()
* Sets a set of file mappers, which should be used
* to change the filename of the included files.
*/
- public void setFileMappers( FileMapper[] fileMappers )
- {
+ public void setFileMappers(FileMapper[] fileMappers) {
this.fileMappers = fileMappers;
}
@Override
- public FileMapper[] getFileMappers()
- {
+ public FileMapper[] getFileMappers() {
return fileMappers;
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/util/ArchiveEntryUtils.java b/src/main/java/org/codehaus/plexus/archiver/util/ArchiveEntryUtils.java
index c4960024a..2bfa36dc2 100644
--- a/src/main/java/org/codehaus/plexus/archiver/util/ArchiveEntryUtils.java
+++ b/src/main/java/org/codehaus/plexus/archiver/util/ArchiveEntryUtils.java
@@ -17,17 +17,16 @@
import java.io.File;
import java.io.IOException;
+
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.components.io.attributes.AttributeUtils;
import org.codehaus.plexus.util.Os;
import org.slf4j.Logger;
-@SuppressWarnings( "JavaDoc" )
-public final class ArchiveEntryUtils
-{
+@SuppressWarnings("JavaDoc")
+public final class ArchiveEntryUtils {
- private ArchiveEntryUtils()
- {
+ private ArchiveEntryUtils() {
// no op
}
@@ -40,10 +39,9 @@ private ArchiveEntryUtils()
* @deprecated Use {@link #chmod(File, int)}
*/
@Deprecated
- public static void chmod( final File file, final int mode, final Logger logger, boolean useJvmChmod )
- throws ArchiverException
- {
- chmod( file, mode );
+ public static void chmod(final File file, final int mode, final Logger logger, boolean useJvmChmod)
+ throws ArchiverException {
+ chmod(file, mode);
}
/**
@@ -54,28 +52,19 @@ public static void chmod( final File file, final int mode, final Logger logger,
* @deprecated Use {@link #chmod(File, int)}
*/
@Deprecated
- public static void chmod( final File file, final int mode, final Logger logger )
- throws ArchiverException
- {
- chmod( file, mode );
+ public static void chmod(final File file, final int mode, final Logger logger) throws ArchiverException {
+ chmod(file, mode);
}
- public static void chmod( final File file, final int mode )
- throws ArchiverException
- {
- if ( !Os.isFamily( Os.FAMILY_UNIX ) )
- {
+ public static void chmod(final File file, final int mode) throws ArchiverException {
+ if (!Os.isFamily(Os.FAMILY_UNIX)) {
return;
}
- try
- {
- AttributeUtils.chmod( file, mode );
- }
- catch ( IOException e )
- {
- throw new ArchiverException( "Failed setting file attributes", e );
+ try {
+ AttributeUtils.chmod(file, mode);
+ } catch (IOException e) {
+ throw new ArchiverException("Failed setting file attributes", e);
}
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/util/Compressor.java b/src/main/java/org/codehaus/plexus/archiver/util/Compressor.java
index 31e801073..79d41af54 100644
--- a/src/main/java/org/codehaus/plexus/archiver/util/Compressor.java
+++ b/src/main/java/org/codehaus/plexus/archiver/util/Compressor.java
@@ -20,17 +20,16 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class Compressor
-{
- private final Logger logger = LoggerFactory.getLogger( getClass() );
+public abstract class Compressor {
+ private final Logger logger = LoggerFactory.getLogger(getClass());
- protected Logger getLogger()
- {
+ protected Logger getLogger() {
return logger;
}
@@ -43,29 +42,25 @@ protected Logger getLogger()
*
* @param compressFile
*/
- public void setDestFile( File compressFile )
- {
+ public void setDestFile(File compressFile) {
this.destFile = compressFile;
}
- public File getDestFile()
- {
+ public File getDestFile() {
return destFile;
}
/**
* The resource to compress; required.
*/
- public void setSource( PlexusIoResource source )
- {
+ public void setSource(PlexusIoResource source) {
this.source = source;
}
/**
* The resource to compress; required.
*/
- public PlexusIoResource getSource()
- {
+ public PlexusIoResource getSource() {
return source;
}
@@ -77,28 +72,21 @@ public PlexusIoResource getSource()
*
* @throws IOException
*/
- private void compressFile( InputStream in, OutputStream zOut )
- throws IOException
- {
- byte[] buffer = new byte[ 8 * 1024 ];
+ private void compressFile(InputStream in, OutputStream zOut) throws IOException {
+ byte[] buffer = new byte[8 * 1024];
int count = 0;
- do
- {
- zOut.write( buffer, 0, count );
- count = in.read( buffer, 0, buffer.length );
- }
- while ( count != -1 );
+ do {
+ zOut.write(buffer, 0, count);
+ count = in.read(buffer, 0, buffer.length);
+ } while (count != -1);
}
/**
* compress a resource to an output stream
*/
- protected void compress( PlexusIoResource resource, OutputStream zOut )
- throws IOException
- {
- try ( InputStream in = Streams.bufferedInputStream( resource.getContents() ) )
- {
- compressFile( in, zOut );
+ protected void compress(PlexusIoResource resource, OutputStream zOut) throws IOException {
+ try (InputStream in = Streams.bufferedInputStream(resource.getContents())) {
+ compressFile(in, zOut);
}
}
@@ -107,15 +95,12 @@ protected void compress( PlexusIoResource resource, OutputStream zOut )
*
* this is public so the process of compression and closing can be dealt with separately.
*/
- public abstract void compress()
- throws ArchiverException;
+ public abstract void compress() throws ArchiverException;
/**
* subclasses must implement this method to cleanup after compression
*
* this is public so the process of compression and closing can be dealt with separately.
*/
- public abstract void close()
- throws ArchiverException;
-
+ public abstract void close() throws ArchiverException;
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/util/DefaultArchivedFileSet.java b/src/main/java/org/codehaus/plexus/archiver/util/DefaultArchivedFileSet.java
index dc59ce1a8..1574e624a 100644
--- a/src/main/java/org/codehaus/plexus/archiver/util/DefaultArchivedFileSet.java
+++ b/src/main/java/org/codehaus/plexus/archiver/util/DefaultArchivedFileSet.java
@@ -1,7 +1,9 @@
package org.codehaus.plexus.archiver.util;
-import java.io.File;
import javax.annotation.Nonnull;
+
+import java.io.File;
+
import org.codehaus.plexus.archiver.ArchivedFileSet;
/**
@@ -9,31 +11,23 @@
*
* @since 1.0-alpha-9
*/
-public class DefaultArchivedFileSet
- extends AbstractFileSet
- implements ArchivedFileSet
-{
+public class DefaultArchivedFileSet extends AbstractFileSet implements ArchivedFileSet {
private final File archive;
- public DefaultArchivedFileSet( @Nonnull File archive )
- {
+ public DefaultArchivedFileSet(@Nonnull File archive) {
this.archive = archive;
}
@Override
- public File getArchive()
- {
+ public File getArchive() {
return archive;
}
- public static DefaultArchivedFileSet archivedFileSet( File archiveFile )
- {
- if ( archiveFile == null )
- {
- throw new IllegalArgumentException( "Archive File cannot be null" );
+ public static DefaultArchivedFileSet archivedFileSet(File archiveFile) {
+ if (archiveFile == null) {
+ throw new IllegalArgumentException("Archive File cannot be null");
}
- return new DefaultArchivedFileSet( archiveFile );
+ return new DefaultArchivedFileSet(archiveFile);
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/util/DefaultFileSet.java b/src/main/java/org/codehaus/plexus/archiver/util/DefaultFileSet.java
index 6b5f55883..158473d44 100644
--- a/src/main/java/org/codehaus/plexus/archiver/util/DefaultFileSet.java
+++ b/src/main/java/org/codehaus/plexus/archiver/util/DefaultFileSet.java
@@ -1,7 +1,9 @@
package org.codehaus.plexus.archiver.util;
-import java.io.File;
import javax.annotation.Nonnull;
+
+import java.io.File;
+
import org.codehaus.plexus.archiver.FileSet;
/**
@@ -9,39 +11,30 @@
*
* @since 1.0-alpha-9
*/
-public class DefaultFileSet
- extends AbstractFileSet
- implements FileSet
-{
+public class DefaultFileSet extends AbstractFileSet implements FileSet {
private File directory;
- public DefaultFileSet( File directory )
- {
+ public DefaultFileSet(File directory) {
this.directory = directory;
}
- public DefaultFileSet()
- {
- }
+ public DefaultFileSet() {}
/**
* Sets the file sets base directory.
*/
- public void setDirectory( @Nonnull File directory )
- {
+ public void setDirectory(@Nonnull File directory) {
this.directory = directory;
}
- @Nonnull public File getDirectory()
- {
+ @Nonnull
+ public File getDirectory() {
return directory;
}
- public static DefaultFileSet fileSet( File directory )
- {
- final DefaultFileSet defaultFileSet = new DefaultFileSet( directory );
+ public static DefaultFileSet fileSet(File directory) {
+ final DefaultFileSet defaultFileSet = new DefaultFileSet(directory);
return defaultFileSet;
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/util/FilePermission.java b/src/main/java/org/codehaus/plexus/archiver/util/FilePermission.java
index 830645173..f8a0bae6e 100644
--- a/src/main/java/org/codehaus/plexus/archiver/util/FilePermission.java
+++ b/src/main/java/org/codehaus/plexus/archiver/util/FilePermission.java
@@ -23,8 +23,7 @@
* @since 1.1
*
*/
-public class FilePermission
-{
+public class FilePermission {
private final boolean executable;
@@ -38,9 +37,13 @@ public class FilePermission
private final boolean writable;
- public FilePermission( boolean executable, boolean ownerOnlyExecutable, boolean ownerOnlyReadable,
- boolean readable, boolean ownerOnlyWritable, boolean writable )
- {
+ public FilePermission(
+ boolean executable,
+ boolean ownerOnlyExecutable,
+ boolean ownerOnlyReadable,
+ boolean readable,
+ boolean ownerOnlyWritable,
+ boolean writable) {
this.executable = executable;
this.ownerOnlyExecutable = ownerOnlyExecutable;
this.ownerOnlyReadable = ownerOnlyReadable;
@@ -49,43 +52,34 @@ public FilePermission( boolean executable, boolean ownerOnlyExecutable, boolean
this.writable = writable;
}
- public boolean isExecutable()
- {
+ public boolean isExecutable() {
return executable;
}
- public boolean isOwnerOnlyExecutable()
- {
+ public boolean isOwnerOnlyExecutable() {
return ownerOnlyExecutable;
}
- public boolean isOwnerOnlyReadable()
- {
+ public boolean isOwnerOnlyReadable() {
return ownerOnlyReadable;
}
- public boolean isReadable()
- {
+ public boolean isReadable() {
return readable;
}
- public boolean isOwnerOnlyWritable()
- {
+ public boolean isOwnerOnlyWritable() {
return ownerOnlyWritable;
}
- public boolean isWritable()
- {
+ public boolean isWritable() {
return writable;
}
@Override
- public String toString()
- {
+ public String toString() {
return "FilePermission [executable=" + executable + ", ownerOnlyExecutable=" + ownerOnlyExecutable
- + ", ownerOnlyReadable=" + ownerOnlyReadable + ", readable=" + readable + ", ownerOnlyWritable="
- + ownerOnlyWritable + ", writable=" + writable + "]";
-
+ + ", ownerOnlyReadable=" + ownerOnlyReadable + ", readable=" + readable + ", ownerOnlyWritable="
+ + ownerOnlyWritable + ", writable=" + writable + "]";
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/util/FilePermissionUtils.java b/src/main/java/org/codehaus/plexus/archiver/util/FilePermissionUtils.java
index c83f5d806..3ac9f54b9 100644
--- a/src/main/java/org/codehaus/plexus/archiver/util/FilePermissionUtils.java
+++ b/src/main/java/org/codehaus/plexus/archiver/util/FilePermissionUtils.java
@@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.List;
+
import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger;
@@ -27,11 +28,9 @@
* @author Olivier Lamy
* @since 1.0.1
*/
-public class FilePermissionUtils
-{
+public class FilePermissionUtils {
- private FilePermissionUtils()
- {
+ private FilePermissionUtils() {
// no op
}
@@ -40,33 +39,31 @@ private FilePermissionUtils()
*
* @return FilePermission associated to the mode (group permission are ignored here)
*/
- public static FilePermission getFilePermissionFromMode( String mode, Logger logger )
- {
- if ( StringUtils.isBlank( mode ) )
- {
- throw new IllegalArgumentException( " file mode cannot be empty" );
+ public static FilePermission getFilePermissionFromMode(String mode, Logger logger) {
+ if (StringUtils.isBlank(mode)) {
+ throw new IllegalArgumentException(" file mode cannot be empty");
}
// 4 characters works on some unix (ie solaris)
- if ( mode.length() != 3 && mode.length() != 4 )
- {
- throw new IllegalArgumentException( " file mode must be 3 or 4 characters" );
+ if (mode.length() != 3 && mode.length() != 4) {
+ throw new IllegalArgumentException(" file mode must be 3 or 4 characters");
}
- List modes = new ArrayList<>( mode.length() );
- for ( int i = 0, size = mode.length(); i < size; i++ )
- {
- modes.add( String.valueOf( mode.charAt( i ) ) );
+ List modes = new ArrayList<>(mode.length());
+ for (int i = 0, size = mode.length(); i < size; i++) {
+ modes.add(String.valueOf(mode.charAt(i)));
}
- boolean executable = false, ownerOnlyExecutable = true, ownerOnlyReadable = true, readable = false,
- ownerOnlyWritable = true, writable = false;
+ boolean executable = false,
+ ownerOnlyExecutable = true,
+ ownerOnlyReadable = true,
+ readable = false,
+ ownerOnlyWritable = true,
+ writable = false;
// handle user perm
- try
- {
- int userMode = Integer.parseInt( modes.get( mode.length() == 4 ? 1 : 0 ) );
- switch ( userMode )
- {
+ try {
+ int userMode = Integer.parseInt(modes.get(mode.length() == 4 ? 1 : 0));
+ switch (userMode) {
case 0:
break;
case 1:
@@ -96,20 +93,16 @@ public static FilePermission getFilePermissionFromMode( String mode, Logger logg
executable = true;
break;
default:
- logger.warn( "ignore file mode " + userMode );
+ logger.warn("ignore file mode " + userMode);
}
- }
- catch ( NumberFormatException e )
- {
- throw new IllegalArgumentException( " file mode must contains only number " + mode );
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(" file mode must contains only number " + mode);
}
// handle all perm
- try
- {
- int allMode = Integer.parseInt( modes.get( mode.length() == 4 ? 3 : 2 ) );
- switch ( allMode )
- {
+ try {
+ int allMode = Integer.parseInt(modes.get(mode.length() == 4 ? 3 : 2));
+ switch (allMode) {
case 0:
break;
case 1:
@@ -151,17 +144,13 @@ public static FilePermission getFilePermissionFromMode( String mode, Logger logg
ownerOnlyWritable = false;
break;
default:
- logger.warn( "ignore file mode " + allMode );
+ logger.warn("ignore file mode " + allMode);
}
- }
- catch ( NumberFormatException e )
- {
- throw new IllegalArgumentException( " file mode must contains only number " + mode );
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(" file mode must contains only number " + mode);
}
- return new FilePermission( executable, ownerOnlyExecutable, ownerOnlyReadable, readable, ownerOnlyWritable,
- writable );
-
+ return new FilePermission(
+ executable, ownerOnlyExecutable, ownerOnlyReadable, readable, ownerOnlyWritable, writable);
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/util/FilterSupport.java b/src/main/java/org/codehaus/plexus/archiver/util/FilterSupport.java
index bc0cd31c4..09b016858 100644
--- a/src/main/java/org/codehaus/plexus/archiver/util/FilterSupport.java
+++ b/src/main/java/org/codehaus/plexus/archiver/util/FilterSupport.java
@@ -2,6 +2,7 @@
import java.io.InputStream;
import java.util.List;
+
import org.codehaus.plexus.archiver.ArchiveFileFilter;
import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.components.io.fileselectors.FileSelector;
@@ -11,36 +12,28 @@
* @deprecated Use {@link FileSelector} and {@link Archiver#addFileSet}.
*/
@Deprecated
-public class FilterSupport
-{
+public class FilterSupport {
private final List filters;
private final Logger logger;
- public FilterSupport( List filters, Logger logger )
- {
+ public FilterSupport(List filters, Logger logger) {
this.filters = filters;
this.logger = logger;
}
- public boolean include( InputStream dataStream, String entryName )
- {
+ public boolean include(InputStream dataStream, String entryName) {
boolean included = true;
- if ( filters != null && !filters.isEmpty() )
- {
- for ( ArchiveFileFilter filter : filters )
- {
- included = filter.include( dataStream, entryName );
-
- if ( !included )
- {
- if ( logger.isDebugEnabled() )
- {
- logger.debug( "Entry: \'" + entryName + "\' excluded by filter: "
- + filter.getClass().getName() );
+ if (filters != null && !filters.isEmpty()) {
+ for (ArchiveFileFilter filter : filters) {
+ included = filter.include(dataStream, entryName);
+ if (!included) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Entry: \'" + entryName + "\' excluded by filter: "
+ + filter.getClass().getName());
}
break;
@@ -50,5 +43,4 @@ public boolean include( InputStream dataStream, String entryName )
return included;
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/util/ResourceUtils.java b/src/main/java/org/codehaus/plexus/archiver/util/ResourceUtils.java
index 4c36792e2..1bd25e01f 100644
--- a/src/main/java/org/codehaus/plexus/archiver/util/ResourceUtils.java
+++ b/src/main/java/org/codehaus/plexus/archiver/util/ResourceUtils.java
@@ -13,14 +13,12 @@
/**
* Utility class for work with {@link PlexusIoResource} instances.
*/
-public class ResourceUtils
-{
+public class ResourceUtils {
/**
* Private constructor, to prevent accidental implementation.
*/
- private ResourceUtils()
- {
+ private ResourceUtils() {
// Does nothing
}
@@ -28,25 +26,21 @@ private ResourceUtils()
* Queries, whether the given source is up-to-date relative to
* the given destination.
*/
- public static boolean isUptodate( PlexusIoResource source, File destination )
- {
- return isUptodate( source, destination.lastModified() );
+ public static boolean isUptodate(PlexusIoResource source, File destination) {
+ return isUptodate(source, destination.lastModified());
}
/**
* Queries, whether the given source is up-to-date relative to
* the given modification date.
*/
- public static boolean isUptodate( PlexusIoResource source, long destinationDate )
- {
+ public static boolean isUptodate(PlexusIoResource source, long destinationDate) {
final long s = source.getLastModified();
- if ( s == PlexusIoResource.UNKNOWN_MODIFICATION_DATE )
- {
+ if (s == PlexusIoResource.UNKNOWN_MODIFICATION_DATE) {
return false;
}
- if ( destinationDate == 0 )
- {
+ if (destinationDate == 0) {
return false;
}
@@ -57,15 +51,12 @@ public static boolean isUptodate( PlexusIoResource source, long destinationDate
* Queries, whether the given source is up-to-date relative to
* the given modification date.
*/
- public static boolean isUptodate( long sourceDate, long destinationDate )
- {
- if ( sourceDate == PlexusIoResource.UNKNOWN_MODIFICATION_DATE )
- {
+ public static boolean isUptodate(long sourceDate, long destinationDate) {
+ if (sourceDate == PlexusIoResource.UNKNOWN_MODIFICATION_DATE) {
return false;
}
- if ( destinationDate == 0 )
- {
+ if (destinationDate == 0) {
return false;
}
@@ -75,47 +66,38 @@ public static boolean isUptodate( long sourceDate, long destinationDate )
/**
* Copies the sources contents to the given destination file.
*/
- public static void copyFile( PlexusIoResource in, File outFile )
- throws IOException
- {
- try ( InputStream input = in.getContents(); OutputStream output = Files.newOutputStream( outFile.toPath() ) )
- {
- IOUtil.copy( input, output );
+ public static void copyFile(PlexusIoResource in, File outFile) throws IOException {
+ try (InputStream input = in.getContents();
+ OutputStream output = Files.newOutputStream(outFile.toPath())) {
+ IOUtil.copy(input, output);
}
}
/**
* Copies the sources contents to the given destination file.
*/
- public static void copyFile( InputStream input, File outFile )
- throws IOException
- {
+ public static void copyFile(InputStream input, File outFile) throws IOException {
OutputStream output = null;
- try
- {
- output = Files.newOutputStream( outFile.toPath() );
- IOUtil.copy( input, output );
+ try {
+ output = Files.newOutputStream(outFile.toPath());
+ IOUtil.copy(input, output);
output.close();
output = null;
input.close();
input = null;
- }
- finally
- {
- IOUtil.close( input );
- IOUtil.close( output );
+ } finally {
+ IOUtil.close(input);
+ IOUtil.close(output);
}
}
/**
* Checks, whether the resource and the file are identical.
*/
- public static boolean isSame( PlexusIoResource resource, File file )
- {
- if ( resource instanceof FileSupplier )
- {
- File resourceFile = ( (FileSupplier) resource ).getFile();
- return file.equals( resourceFile );
+ public static boolean isSame(PlexusIoResource resource, File file) {
+ if (resource instanceof FileSupplier) {
+ File resourceFile = ((FileSupplier) resource).getFile();
+ return file.equals(resourceFile);
}
return false;
}
@@ -125,15 +107,11 @@ public static boolean isSame( PlexusIoResource resource, File file )
* Uses {@link File#getCanonicalFile()} for comparison, which is much
* slower than comparing the files.
*/
- public static boolean isCanonicalizedSame( PlexusIoResource resource, File file )
- throws IOException
- {
- if ( resource instanceof FileSupplier )
- {
- File resourceFile = ( (FileSupplier) resource ).getFile();
- return file.getCanonicalFile().equals( resourceFile.getCanonicalFile() );
+ public static boolean isCanonicalizedSame(PlexusIoResource resource, File file) throws IOException {
+ if (resource instanceof FileSupplier) {
+ File resourceFile = ((FileSupplier) resource).getFile();
+ return file.getCanonicalFile().equals(resourceFile.getCanonicalFile());
}
return false;
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/util/Streams.java b/src/main/java/org/codehaus/plexus/archiver/util/Streams.java
index b37689afe..dbdd71f77 100644
--- a/src/main/java/org/codehaus/plexus/archiver/util/Streams.java
+++ b/src/main/java/org/codehaus/plexus/archiver/util/Streams.java
@@ -15,6 +15,9 @@
*/
package org.codehaus.plexus.archiver.util;
+import javax.annotation.WillClose;
+import javax.annotation.WillNotClose;
+
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
@@ -24,137 +27,87 @@
import java.io.OutputStream;
import java.nio.file.Files;
-import javax.annotation.WillClose;
-import javax.annotation.WillNotClose;
-
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.util.IOUtil;
-public class Streams
-{
-
- public static final InputStream EMPTY_INPUTSTREAM = new ByteArrayInputStream( new byte[0] );
+public class Streams {
- public static BufferedInputStream bufferedInputStream( InputStream is )
- {
- return is instanceof BufferedInputStream
- ? (BufferedInputStream) is
- : new BufferedInputStream( is, 65536 );
+ public static final InputStream EMPTY_INPUTSTREAM = new ByteArrayInputStream(new byte[0]);
+ public static BufferedInputStream bufferedInputStream(InputStream is) {
+ return is instanceof BufferedInputStream ? (BufferedInputStream) is : new BufferedInputStream(is, 65536);
}
- public static BufferedOutputStream bufferedOutputStream( OutputStream os )
- {
- return os instanceof BufferedOutputStream
- ? (BufferedOutputStream) os
- : new BufferedOutputStream( os, 65536 );
-
+ public static BufferedOutputStream bufferedOutputStream(OutputStream os) {
+ return os instanceof BufferedOutputStream ? (BufferedOutputStream) os : new BufferedOutputStream(os, 65536);
}
- public static byte[] cacheBuffer()
- {
- return new byte[ 8 * 1024 ];
+ public static byte[] cacheBuffer() {
+ return new byte[8 * 1024];
}
- public static InputStream fileInputStream( File file )
- throws IOException
- {
- return Files.newInputStream( file.toPath() );
+ public static InputStream fileInputStream(File file) throws IOException {
+ return Files.newInputStream(file.toPath());
}
- public static InputStream fileInputStream( File file, String operation )
- throws ArchiverException
- {
- try
- {
- return Files.newInputStream( file.toPath() );
- }
- catch ( IOException e )
- {
+ public static InputStream fileInputStream(File file, String operation) throws ArchiverException {
+ try {
+ return Files.newInputStream(file.toPath());
+ } catch (IOException e) {
throw new ArchiverException(
- "Problem reading input file for " + operation + " " + file.getParent() + ", " + e.getMessage() );
-
+ "Problem reading input file for " + operation + " " + file.getParent() + ", " + e.getMessage());
}
}
- public static OutputStream fileOutputStream( File file )
- throws IOException
- {
- return Files.newOutputStream( file.toPath() );
+ public static OutputStream fileOutputStream(File file) throws IOException {
+ return Files.newOutputStream(file.toPath());
}
- public static OutputStream fileOutputStream( File file, String operation )
- throws ArchiverException
- {
- try
- {
- return Files.newOutputStream( file.toPath() );
- }
- catch ( IOException e )
- {
+ public static OutputStream fileOutputStream(File file, String operation) throws ArchiverException {
+ try {
+ return Files.newOutputStream(file.toPath());
+ } catch (IOException e) {
throw new ArchiverException(
- "Problem creating output file for " + operation + " " + file.getParent() + ", " + e.getMessage() );
-
+ "Problem creating output file for " + operation + " " + file.getParent() + ", " + e.getMessage());
}
}
- public static void copyFully( @WillClose InputStream zIn, @WillClose OutputStream out, String gzip )
- throws ArchiverException
- {
+ public static void copyFully(@WillClose InputStream zIn, @WillClose OutputStream out, String gzip)
+ throws ArchiverException {
// There must be 1 million libs out there that do this
- try
- {
- copyFullyDontCloseOutput( zIn, out, gzip );
+ try {
+ copyFullyDontCloseOutput(zIn, out, gzip);
out.close();
out = null;
- }
- catch ( final IOException e )
- {
- throw new ArchiverException( "Failure copying.", e );
- }
- finally
- {
- IOUtil.close( out );
+ } catch (final IOException e) {
+ throw new ArchiverException("Failure copying.", e);
+ } finally {
+ IOUtil.close(out);
}
}
- public static void copyFullyDontCloseOutput( @WillClose InputStream zIn, @WillNotClose OutputStream out,
- String gzip )
- throws ArchiverException
- {
+ public static void copyFullyDontCloseOutput(@WillClose InputStream zIn, @WillNotClose OutputStream out, String gzip)
+ throws ArchiverException {
// There must be 1 million libs out there that do this
- try
- {
+ try {
byte[] buffer = cacheBuffer();
int count = 0;
- do
- {
- try
- {
- out.write( buffer, 0, count );
- }
- catch ( IOException e )
- {
+ do {
+ try {
+ out.write(buffer, 0, count);
+ } catch (IOException e) {
throw new ArchiverException(
- "Problem writing to output in " + gzip + " operation " + e.getMessage() );
-
+ "Problem writing to output in " + gzip + " operation " + e.getMessage());
}
- count = zIn.read( buffer, 0, buffer.length );
- }
- while ( count != -1 );
+ count = zIn.read(buffer, 0, buffer.length);
+ } while (count != -1);
zIn.close();
zIn = null;
- }
- catch ( IOException e )
- {
- throw new ArchiverException(
- "Problem reading from source file in " + gzip + " operation " + e.getMessage() );
+ } catch (IOException e) {
+ throw new ArchiverException("Problem reading from source file in " + gzip + " operation " + e.getMessage());
- }
- finally
- {
- IOUtil.close( zIn );
+ } finally {
+ IOUtil.close(zIn);
}
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/war/PlexusIoWarFileResourceCollection.java b/src/main/java/org/codehaus/plexus/archiver/war/PlexusIoWarFileResourceCollection.java
index 360a0f40c..60e76df67 100644
--- a/src/main/java/org/codehaus/plexus/archiver/war/PlexusIoWarFileResourceCollection.java
+++ b/src/main/java/org/codehaus/plexus/archiver/war/PlexusIoWarFileResourceCollection.java
@@ -22,8 +22,5 @@
/**
* Alias for {@link PlexusIoZipFileResourceCollection}.
*/
-@Named( "war" )
-public class PlexusIoWarFileResourceCollection
- extends PlexusIoZipFileResourceCollection
-{
-}
+@Named("war")
+public class PlexusIoWarFileResourceCollection extends PlexusIoZipFileResourceCollection {}
diff --git a/src/main/java/org/codehaus/plexus/archiver/war/WarArchiver.java b/src/main/java/org/codehaus/plexus/archiver/war/WarArchiver.java
index befce726c..2ee06f362 100644
--- a/src/main/java/org/codehaus/plexus/archiver/war/WarArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/war/WarArchiver.java
@@ -20,6 +20,7 @@
import java.io.File;
import java.io.IOException;
+
import org.codehaus.plexus.archiver.ArchiveEntry;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.jar.JarArchiver;
@@ -42,10 +43,8 @@
*
* @see JarArchiver
*/
-@Named( "war" )
-public class WarArchiver
- extends JarArchiver
-{
+@Named("war")
+public class WarArchiver extends JarArchiver {
/**
* our web.xml deployment descriptor
@@ -67,8 +66,7 @@ public class WarArchiver
* @param excpectWebXml true if web xml is *expected* from the client
*/
@Deprecated
- public void setIgnoreWebxml( boolean excpectWebXml )
- {
+ public void setIgnoreWebxml(boolean excpectWebXml) {
expectWebXml = excpectWebXml;
}
@@ -77,13 +75,11 @@ public void setIgnoreWebxml( boolean excpectWebXml )
*
* @param expectWebXml true if web xml is *expected* from the client
*/
- public void setExpectWebXml( boolean expectWebXml )
- {
+ public void setExpectWebXml(boolean expectWebXml) {
this.expectWebXml = expectWebXml;
}
- public WarArchiver()
- {
+ public WarArchiver() {
super();
archiveType = "war";
}
@@ -92,71 +88,48 @@ public WarArchiver()
* set the deployment descriptor to use (WEB-INF/web.xml);
* required unless update=true
*/
- public void setWebxml( File descr )
- throws ArchiverException
- {
+ public void setWebxml(File descr) throws ArchiverException {
deploymentDescriptor = descr;
- if ( !deploymentDescriptor.exists() )
- {
- throw new ArchiverException( "Deployment descriptor: " + deploymentDescriptor + " does not exist." );
+ if (!deploymentDescriptor.exists()) {
+ throw new ArchiverException("Deployment descriptor: " + deploymentDescriptor + " does not exist.");
}
- addFile( descr, "WEB-INF" + File.separatorChar + "web.xml" );
+ addFile(descr, "WEB-INF" + File.separatorChar + "web.xml");
}
/**
* add a file under WEB-INF/lib/
*/
- public void addLib( File fileName )
- throws ArchiverException
- {
- addDirectory( fileName.getParentFile(), "WEB-INF/lib/",
- new String[]
- {
- fileName.getName()
- }, null );
-
+ public void addLib(File fileName) throws ArchiverException {
+ addDirectory(fileName.getParentFile(), "WEB-INF/lib/", new String[] {fileName.getName()}, null);
}
/**
* add files under WEB-INF/lib/
*/
- public void addLibs( File directoryName, String[] includes, String[] excludes )
- throws ArchiverException
- {
- addDirectory( directoryName, "WEB-INF/lib/", includes, excludes );
+ public void addLibs(File directoryName, String[] includes, String[] excludes) throws ArchiverException {
+ addDirectory(directoryName, "WEB-INF/lib/", includes, excludes);
}
/**
* add a file under WEB-INF/lib/
*/
- public void addClass( File fileName )
- throws ArchiverException
- {
- addDirectory( fileName.getParentFile(), "WEB-INF/classes/",
- new String[]
- {
- fileName.getName()
- }, null );
-
+ public void addClass(File fileName) throws ArchiverException {
+ addDirectory(fileName.getParentFile(), "WEB-INF/classes/", new String[] {fileName.getName()}, null);
}
/**
* add files under WEB-INF/classes
*/
- public void addClasses( File directoryName, String[] includes, String[] excludes )
- throws ArchiverException
- {
- addDirectory( directoryName, "WEB-INF/classes/", includes, excludes );
+ public void addClasses(File directoryName, String[] includes, String[] excludes) throws ArchiverException {
+ addDirectory(directoryName, "WEB-INF/classes/", includes, excludes);
}
/**
* files to add under WEB-INF;
*/
- public void addWebinf( File directoryName, String[] includes, String[] excludes )
- throws ArchiverException
- {
- addDirectory( directoryName, "WEB-INF/", includes, excludes );
+ public void addWebinf(File directoryName, String[] includes, String[] excludes) throws ArchiverException {
+ addDirectory(directoryName, "WEB-INF/", includes, excludes);
}
/**
@@ -166,52 +139,43 @@ public void addWebinf( File directoryName, String[] includes, String[] excludes
* @param zOut
*/
@Override
- protected void initZipOutputStream( ConcurrentJarCreator zOut )
- throws ArchiverException, IOException
- {
+ protected void initZipOutputStream(ConcurrentJarCreator zOut) throws ArchiverException, IOException {
// If no webxml file is specified, it's an error.
- if ( expectWebXml && deploymentDescriptor == null && !isInUpdateMode() )
- {
+ if (expectWebXml && deploymentDescriptor == null && !isInUpdateMode()) {
throw new ArchiverException(
- "webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)" );
-
+ "webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)");
}
- super.initZipOutputStream( zOut );
+ super.initZipOutputStream(zOut);
}
/**
* Overridden from ZipArchiver class to deal with web.xml
*/
@Override
- protected void zipFile( ArchiveEntry entry, ConcurrentJarCreator zOut, String vPath )
- throws IOException, ArchiverException
- {
+ protected void zipFile(ArchiveEntry entry, ConcurrentJarCreator zOut, String vPath)
+ throws IOException, ArchiverException {
// If the file being added is WEB-INF/web.xml, we warn if it's
// not the one specified in the "webxml" attribute - or if
// it's being added twice, meaning the same file is specified
// by the "webxml" attribute and in a element.
- if ( vPath.equalsIgnoreCase( "WEB-INF/web.xml" ) )
- {
- if ( descriptorAdded || ( expectWebXml
- && ( deploymentDescriptor == null
- || !ResourceUtils.isCanonicalizedSame( entry.getResource(),
- deploymentDescriptor ) ) ) )
- {
- getLogger().warn( "Warning: selected " + archiveType
- + " files include a WEB-INF/web.xml which will be ignored "
- + "\n(webxml attribute is missing from "
- + archiveType + " task, or ignoreWebxml attribute is specified as 'true')" );
- }
- else
- {
- super.zipFile( entry, zOut, vPath );
+ if (vPath.equalsIgnoreCase("WEB-INF/web.xml")) {
+ if (descriptorAdded
+ || (expectWebXml
+ && (deploymentDescriptor == null
+ || !ResourceUtils.isCanonicalizedSame(
+ entry.getResource(), deploymentDescriptor)))) {
+ getLogger()
+ .warn("Warning: selected " + archiveType
+ + " files include a WEB-INF/web.xml which will be ignored "
+ + "\n(webxml attribute is missing from "
+ + archiveType + " task, or ignoreWebxml attribute is specified as 'true')");
+ } else {
+ super.zipFile(entry, zOut, vPath);
descriptorAdded = true;
}
- }
- else
- {
- super.zipFile( entry, zOut, vPath );
+ } else {
+ super.zipFile(entry, zOut, vPath);
}
}
@@ -220,12 +184,9 @@ protected void zipFile( ArchiveEntry entry, ConcurrentJarCreator zOut, String vP
* gets executed.
*/
@Override
- protected void cleanUp()
- throws IOException
- {
+ protected void cleanUp() throws IOException {
descriptorAdded = false;
expectWebXml = true;
super.cleanUp();
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/war/WarUnArchiver.java b/src/main/java/org/codehaus/plexus/archiver/war/WarUnArchiver.java
index 5cc7afc61..c49a82cfa 100644
--- a/src/main/java/org/codehaus/plexus/archiver/war/WarUnArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/war/WarUnArchiver.java
@@ -25,18 +25,12 @@
/**
* Alias for {@link ZipUnArchiver}.
*/
-@Named( "war" )
-public class WarUnArchiver
- extends ZipUnArchiver
-{
+@Named("war")
+public class WarUnArchiver extends ZipUnArchiver {
- public WarUnArchiver()
- {
- }
+ public WarUnArchiver() {}
- public WarUnArchiver( File sourceFile )
- {
- super( sourceFile );
+ public WarUnArchiver(File sourceFile) {
+ super(sourceFile);
}
-
}
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 cf7666524..b6b39c6e9 100644
--- a/src/main/java/org/codehaus/plexus/archiver/xz/PlexusIoXZResourceCollection.java
+++ b/src/main/java/org/codehaus/plexus/archiver/xz/PlexusIoXZResourceCollection.java
@@ -31,26 +31,21 @@
* @author lore
* @since 3.3
*/
-@Named( "xz" )
-public class PlexusIoXZResourceCollection extends PlexusIoCompressedFileResourceCollection
-{
+@Named("xz")
+public class PlexusIoXZResourceCollection extends PlexusIoCompressedFileResourceCollection {
@Override
- protected PlexusIoResourceAttributes getAttributes( File file ) throws IOException
- {
- return new FileAttributes( file, new HashMap(), new HashMap() );
+ protected PlexusIoResourceAttributes getAttributes(File file) throws IOException {
+ return new FileAttributes(file, new HashMap(), new HashMap());
}
@Override
- protected String getDefaultExtension()
- {
+ protected String getDefaultExtension() {
return ".xz";
}
@Override
- protected InputStream getInputStream( File file ) throws IOException
- {
- return XZUnArchiver.getXZInputStream( Streams.fileInputStream( file ) );
+ protected InputStream getInputStream(File file) throws IOException {
+ return XZUnArchiver.getXZInputStream(Streams.fileInputStream(file));
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/xz/XZArchiver.java b/src/main/java/org/codehaus/plexus/archiver/xz/XZArchiver.java
index 79b7f2ed1..2a778f6e6 100644
--- a/src/main/java/org/codehaus/plexus/archiver/xz/XZArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/xz/XZArchiver.java
@@ -18,6 +18,7 @@
import javax.inject.Named;
import java.io.IOException;
+
import org.codehaus.plexus.archiver.AbstractArchiver;
import org.codehaus.plexus.archiver.ArchiveEntry;
import org.codehaus.plexus.archiver.ArchiverException;
@@ -28,55 +29,44 @@
* @author philiplourandos
* @since 3.3
*/
-@Named( "xz" )
-public class XZArchiver extends AbstractArchiver
-{
+@Named("xz")
+public class XZArchiver extends AbstractArchiver {
private final XZCompressor compressor = new XZCompressor();
- public XZArchiver()
- {
- }
+ public XZArchiver() {}
@Override
- protected void execute() throws ArchiverException, IOException
- {
- if ( !checkForced() )
- {
+ protected void execute() throws ArchiverException, IOException {
+ if (!checkForced()) {
return;
}
ResourceIterator iter = getResources();
- if ( !iter.hasNext() )
- {
- throw new EmptyArchiveException( "archive cannot be empty" );
+ if (!iter.hasNext()) {
+ throw new EmptyArchiveException("archive cannot be empty");
}
ArchiveEntry entry = iter.next();
- if ( iter.hasNext() )
- {
- throw new ArchiverException( "There is more than one file in input." );
+ if (iter.hasNext()) {
+ throw new ArchiverException("There is more than one file in input.");
}
- compressor.setSource( entry.getResource() );
- compressor.setDestFile( getDestFile() );
+ compressor.setSource(entry.getResource());
+ compressor.setDestFile(getDestFile());
compressor.compress();
}
@Override
- public boolean isSupportingForced()
- {
+ public boolean isSupportingForced() {
return true;
}
@Override
- protected void close() throws IOException
- {
+ protected void close() throws IOException {
compressor.close();
}
@Override
- protected String getArchiveType()
- {
+ 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
index 4f70b00b3..c2bab4d7f 100644
--- a/src/main/java/org/codehaus/plexus/archiver/xz/XZCompressor.java
+++ b/src/main/java/org/codehaus/plexus/archiver/xz/XZCompressor.java
@@ -16,9 +16,11 @@
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 static org.codehaus.plexus.archiver.util.Streams.bufferedOutputStream;
import static org.codehaus.plexus.archiver.util.Streams.fileOutputStream;
@@ -26,44 +28,31 @@
* @author philip.lourandos
* @since 3.3
*/
-public class XZCompressor extends Compressor
-{
+public class XZCompressor extends Compressor {
private XZCompressorOutputStream xzOut;
- public XZCompressor()
- {
- }
+ 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 );
+ 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()
- {
- try
- {
- if ( this.xzOut != null )
- {
+ public void close() {
+ try {
+ if (this.xzOut != null) {
this.xzOut.close();
xzOut = null;
}
- }
- catch ( final IOException e )
- {
- throw new ArchiverException( "Failure closing target.", e );
+ } catch (final IOException e) {
+ throw new ArchiverException("Failure closing target.", e);
}
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/xz/XZUnArchiver.java b/src/main/java/org/codehaus/plexus/archiver/xz/XZUnArchiver.java
index a52324dbe..c55fa3ae3 100644
--- a/src/main/java/org/codehaus/plexus/archiver/xz/XZUnArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/xz/XZUnArchiver.java
@@ -15,15 +15,17 @@
*/
package org.codehaus.plexus.archiver.xz;
+import javax.annotation.Nonnull;
+import javax.inject.Named;
+
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import javax.annotation.Nonnull;
-import javax.inject.Named;
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;
@@ -34,54 +36,41 @@
* @author philip.lourandos
* @since 3.3
*/
-@Named( "xz" )
-public class XZUnArchiver extends AbstractUnArchiver
-{
+@Named("xz")
+public class XZUnArchiver extends AbstractUnArchiver {
private static final String OPERATION_XZ = "xz";
- public XZUnArchiver()
- {
- }
+ public XZUnArchiver() {}
- public XZUnArchiver( File source )
- {
- super( source );
+ 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 );
+ 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 );
+ 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" );
-
+ protected void execute(String path, File outputDirectory) throws ArchiverException {
+ throw new UnsupportedOperationException("Targeted execution not supported in xz format");
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipArchiver.java b/src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipArchiver.java
index f1df19cd6..44e9f2ebb 100755
--- a/src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipArchiver.java
@@ -16,9 +16,6 @@
*/
package org.codehaus.plexus.archiver.zip;
-import static org.codehaus.plexus.archiver.util.Streams.bufferedOutputStream;
-import static org.codehaus.plexus.archiver.util.Streams.fileOutputStream;
-
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
@@ -55,10 +52,11 @@
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
import org.codehaus.plexus.util.FileUtils;
-@SuppressWarnings( { "UnusedDeclaration" } )
-public abstract class AbstractZipArchiver
- extends AbstractArchiver
-{
+import static org.codehaus.plexus.archiver.util.Streams.bufferedOutputStream;
+import static org.codehaus.plexus.archiver.util.Streams.fileOutputStream;
+
+@SuppressWarnings({"UnusedDeclaration"})
+public abstract class AbstractZipArchiver extends AbstractArchiver {
private String comment;
@@ -114,54 +112,44 @@ public abstract class AbstractZipArchiver
protected ZipArchiveOutputStream zipArchiveOutputStream;
- public String getComment()
- {
+ public String getComment() {
return comment;
}
- public void setComment( String comment )
- {
+ public void setComment(String comment) {
this.comment = comment;
}
- public String getEncoding()
- {
+ public String getEncoding() {
return encoding;
}
- public void setEncoding( String encoding )
- {
+ public void setEncoding(String encoding) {
this.encoding = encoding;
}
- public void setCompress( boolean compress )
- {
+ public void setCompress(boolean compress) {
this.doCompress = compress;
}
- public boolean isCompress()
- {
+ public boolean isCompress() {
return doCompress;
}
- public boolean isRecompressAddedZips()
- {
+ public boolean isRecompressAddedZips() {
return recompressAddedZips;
}
- public void setRecompressAddedZips( boolean recompressAddedZips )
- {
+ public void setRecompressAddedZips(boolean recompressAddedZips) {
this.recompressAddedZips = recompressAddedZips;
}
- public void setUpdateMode( boolean update )
- {
+ public void setUpdateMode(boolean update) {
this.doUpdate = update;
savedDoUpdate = doUpdate;
}
- public boolean isInUpdateMode()
- {
+ public boolean isInUpdateMode() {
return doUpdate;
}
@@ -171,140 +159,112 @@ public boolean isInUpdateMode()
*
* @param f true to emilate sun jar utility
*/
- public void setFilesonly( boolean f )
- {
+ public void setFilesonly(boolean f) {
doFilesonly = f;
}
- public boolean isFilesonly()
- {
+ public boolean isFilesonly() {
return doFilesonly;
}
@Override
- protected void execute()
- throws ArchiverException, IOException
- {
- if ( !checkForced() )
- {
+ protected void execute() throws ArchiverException, IOException {
+ if (!checkForced()) {
return;
}
- if ( doubleFilePass )
- {
+ if (doubleFilePass) {
skipWriting = true;
createArchiveMain();
skipWriting = false;
createArchiveMain();
- }
- else
- {
+ } else {
createArchiveMain();
}
- finalizeZipOutputStream( zOut );
+ finalizeZipOutputStream(zOut);
}
- protected void finalizeZipOutputStream( ConcurrentJarCreator zOut )
- throws IOException, ArchiverException
- {
- }
+ protected void finalizeZipOutputStream(ConcurrentJarCreator zOut) throws IOException, ArchiverException {}
- private void createArchiveMain()
- throws ArchiverException, IOException
- {
+ private void createArchiveMain() throws ArchiverException, IOException {
//noinspection deprecation
- if ( !Archiver.DUPLICATES_SKIP.equals( duplicate ) )
- {
+ if (!Archiver.DUPLICATES_SKIP.equals(duplicate)) {
//noinspection deprecation
- setDuplicateBehavior( duplicate );
+ setDuplicateBehavior(duplicate);
}
ResourceIterator iter = getResources();
- if ( !iter.hasNext() && !hasVirtualFiles() )
- {
- throw new EmptyArchiveException( "archive cannot be empty" );
+ if (!iter.hasNext() && !hasVirtualFiles()) {
+ throw new EmptyArchiveException("archive cannot be empty");
}
zipFile = getDestFile();
- if ( zipFile == null )
- {
- throw new ArchiverException( "You must set the destination " + archiveType + "file." );
+ if (zipFile == null) {
+ throw new ArchiverException("You must set the destination " + archiveType + "file.");
}
- if ( zipFile.exists() && !zipFile.isFile() )
- {
- throw new ArchiverException( zipFile + " isn't a file." );
+ if (zipFile.exists() && !zipFile.isFile()) {
+ throw new ArchiverException(zipFile + " isn't a file.");
}
- if ( zipFile.exists() && !zipFile.canWrite() )
- {
- throw new ArchiverException( zipFile + " is read-only." );
+ if (zipFile.exists() && !zipFile.canWrite()) {
+ throw new ArchiverException(zipFile + " is read-only.");
}
// Whether or not an actual update is required -
// we don't need to update if the original file doesn't exist
addingNewFiles = true;
- if ( doUpdate && !zipFile.exists() )
- {
+ if (doUpdate && !zipFile.exists()) {
doUpdate = false;
- getLogger().debug( "ignoring update attribute as " + archiveType + " doesn't exist." );
+ getLogger().debug("ignoring update attribute as " + archiveType + " doesn't exist.");
}
success = false;
- if ( doUpdate )
- {
- renamedFile = FileUtils.createTempFile( "zip", ".tmp", zipFile.getParentFile() );
+ if (doUpdate) {
+ renamedFile = FileUtils.createTempFile("zip", ".tmp", zipFile.getParentFile());
renamedFile.deleteOnExit();
- try
- {
- FileUtils.rename( zipFile, renamedFile );
- }
- catch ( SecurityException e )
- {
- getLogger().debug( e.toString() );
+ try {
+ FileUtils.rename(zipFile, renamedFile);
+ } catch (SecurityException e) {
+ getLogger().debug(e.toString());
throw new ArchiverException(
- "Not allowed to rename old file (" + zipFile.getAbsolutePath() + ") to temporary file", e );
- }
- catch ( IOException e )
- {
- getLogger().debug( e.toString() );
+ "Not allowed to rename old file (" + zipFile.getAbsolutePath() + ") to temporary file", e);
+ } catch (IOException e) {
+ getLogger().debug(e.toString());
throw new ArchiverException(
- "Unable to rename old file (" + zipFile.getAbsolutePath() + ") to temporary file", e );
+ "Unable to rename old file (" + zipFile.getAbsolutePath() + ") to temporary file", e);
}
}
String action = doUpdate ? "Updating " : "Building ";
- getLogger().info( action + archiveType + ": " + zipFile.getAbsolutePath() );
+ getLogger().info(action + archiveType + ": " + zipFile.getAbsolutePath());
- if ( !skipWriting )
- {
- zipArchiveOutputStream =
- new ZipArchiveOutputStream( bufferedOutputStream( fileOutputStream( zipFile, "zip" ) ) );
- zipArchiveOutputStream.setEncoding( encoding );
- zipArchiveOutputStream.setCreateUnicodeExtraFields( this.getUnicodeExtraFieldPolicy() );
+ if (!skipWriting) {
+ zipArchiveOutputStream = new ZipArchiveOutputStream(bufferedOutputStream(fileOutputStream(zipFile, "zip")));
+ zipArchiveOutputStream.setEncoding(encoding);
+ zipArchiveOutputStream.setCreateUnicodeExtraFields(this.getUnicodeExtraFieldPolicy());
zipArchiveOutputStream.setMethod(
- doCompress ? ZipArchiveOutputStream.DEFLATED : ZipArchiveOutputStream.STORED );
+ doCompress ? ZipArchiveOutputStream.DEFLATED : ZipArchiveOutputStream.STORED);
- zOut = new ConcurrentJarCreator( recompressAddedZips, Runtime.getRuntime().availableProcessors() );
+ zOut = new ConcurrentJarCreator(
+ recompressAddedZips, Runtime.getRuntime().availableProcessors());
}
- initZipOutputStream( zOut );
+ initZipOutputStream(zOut);
// Add the new files to the archive.
- addResources( iter, zOut );
+ addResources(iter, zOut);
// If we've been successful on an update, delete the
// temporary file
- if ( doUpdate )
- {
- if ( !renamedFile.delete() )
- {
- getLogger().warn( "Warning: unable to delete temporary file " + renamedFile.getName() );
+ if (doUpdate) {
+ if (!renamedFile.delete()) {
+ getLogger().warn("Warning: unable to delete temporary file " + renamedFile.getName());
}
}
success = true;
@@ -319,24 +279,19 @@ private void createArchiveMain()
*
* @see #getEncoding()
*/
- private ZipArchiveOutputStream.UnicodeExtraFieldPolicy getUnicodeExtraFieldPolicy()
- {
+ private ZipArchiveOutputStream.UnicodeExtraFieldPolicy getUnicodeExtraFieldPolicy() {
// Copied from ZipEncodingHelper.isUTF8()
String effectiveEncoding = this.getEncoding();
- if ( effectiveEncoding == null )
- {
+ if (effectiveEncoding == null) {
effectiveEncoding = Charset.defaultCharset().name();
}
- boolean utf8 = StandardCharsets.UTF_8.name().equalsIgnoreCase( effectiveEncoding );
+ boolean utf8 = StandardCharsets.UTF_8.name().equalsIgnoreCase(effectiveEncoding);
- if ( !utf8 )
- {
- for ( String alias : StandardCharsets.UTF_8.aliases() )
- {
- if ( alias.equalsIgnoreCase( effectiveEncoding ) )
- {
+ if (!utf8) {
+ for (String alias : StandardCharsets.UTF_8.aliases()) {
+ if (alias.equalsIgnoreCase(effectiveEncoding)) {
utf8 = true;
break;
}
@@ -348,9 +303,8 @@ private ZipArchiveOutputStream.UnicodeExtraFieldPolicy getUnicodeExtraFieldPolic
// is not encodeable as well. If the effective encoding is not UTF-8, we always add the extra field. If it is
// UTF-8, we never add the extra field.
return utf8
- ? ZipArchiveOutputStream.UnicodeExtraFieldPolicy.NEVER
- : ZipArchiveOutputStream.UnicodeExtraFieldPolicy.ALWAYS;
-
+ ? ZipArchiveOutputStream.UnicodeExtraFieldPolicy.NEVER
+ : ZipArchiveOutputStream.UnicodeExtraFieldPolicy.ALWAYS;
}
/**
@@ -359,38 +313,28 @@ private ZipArchiveOutputStream.UnicodeExtraFieldPolicy getUnicodeExtraFieldPolic
* @param resources the resources to add
* @param zOut the stream to write to
*/
- @SuppressWarnings(
- {
- "JavaDoc"
- } )
- protected final void addResources( ResourceIterator resources, ConcurrentJarCreator zOut )
- throws IOException, ArchiverException
- {
- while ( resources.hasNext() )
- {
+ @SuppressWarnings({"JavaDoc"})
+ protected final void addResources(ResourceIterator resources, ConcurrentJarCreator zOut)
+ throws IOException, ArchiverException {
+ while (resources.hasNext()) {
ArchiveEntry entry = resources.next();
String name = entry.getName();
- name = name.replace( File.separatorChar, '/' );
+ name = name.replace(File.separatorChar, '/');
- if ( "".equals( name ) )
- {
+ if ("".equals(name)) {
continue;
}
- if ( entry.getResource().isDirectory() && !name.endsWith( "/" ) )
- {
+ if (entry.getResource().isDirectory() && !name.endsWith("/")) {
name = name + "/";
}
- addParentDirs( entry, null, name, zOut );
+ addParentDirs(entry, null, name, zOut);
- if ( entry.getResource().isFile() )
- {
- zipFile( entry, zOut, name );
- }
- else
- {
- zipDir( entry.getResource(), zOut, name, entry.getMode(), encoding );
+ if (entry.getResource().isFile()) {
+ zipFile(entry, zOut, name);
+ } else {
+ zipDir(entry.getResource(), zOut, name, entry.getMode(), encoding);
}
}
}
@@ -402,33 +346,24 @@ protected final void addResources( ResourceIterator resources, ConcurrentJarCrea
* we do not *relly* know the entry's connection to the file system so establishing the attributes of the parents can
* be impossible and is not really supported.
*/
- @SuppressWarnings(
- {
- "JavaDoc"
- } )
- private void addParentDirs( ArchiveEntry archiveEntry, File baseDir, String entry, ConcurrentJarCreator zOut )
- throws IOException
- {
- if ( !doFilesonly && getIncludeEmptyDirs() )
- {
- Deque directories = addedDirs.asStringDeque( entry );
-
- while ( !directories.isEmpty() )
- {
+ @SuppressWarnings({"JavaDoc"})
+ private void addParentDirs(ArchiveEntry archiveEntry, File baseDir, String entry, ConcurrentJarCreator zOut)
+ throws IOException {
+ if (!doFilesonly && getIncludeEmptyDirs()) {
+ Deque directories = addedDirs.asStringDeque(entry);
+
+ while (!directories.isEmpty()) {
String dir = directories.pop();
File f;
- if ( baseDir != null )
- {
- f = new File( baseDir, dir );
- }
- else
- {
- f = new File( dir );
+ if (baseDir != null) {
+ f = new File(baseDir, dir);
+ } else {
+ f = new File(dir);
}
// the
// At this point we could do something like read the atr
- final PlexusIoResource res = new AnonymousResource( f );
- zipDir( res, zOut, dir, archiveEntry.getDefaultDirMode(), encoding );
+ final PlexusIoResource res = new AnonymousResource(f);
+ zipDir(res, zOut, dir, archiveEntry.getDefaultDirMode(), encoding);
}
}
}
@@ -446,36 +381,34 @@ private void addParentDirs( ArchiveEntry archiveEntry, File baseDir, String entr
* If set to {@code false} it is added synchronously.
* If the entry is symbolic link this parameter is ignored.
*/
- @SuppressWarnings(
- {
- "JavaDoc"
- } )
- protected void zipFile( InputStreamSupplier in, ConcurrentJarCreator zOut, String vPath,
- long lastModified,
- File fromArchive, int mode, String symlinkDestination, boolean addInParallel )
- throws IOException, ArchiverException
- {
- getLogger().debug( "adding entry " + vPath );
-
- entries.put( vPath, vPath );
-
- if ( !skipWriting )
- {
- ZipArchiveEntry ze = new ZipArchiveEntry( vPath );
- setZipEntryTime( ze, lastModified );
-
- ze.setMethod( doCompress ? ZipArchiveEntry.DEFLATED : ZipArchiveEntry.STORED );
- ze.setUnixMode( UnixStat.FILE_FLAG | mode );
-
- if ( ze.isUnixSymlink() )
- {
- final byte[] bytes = encodeArchiveEntry( symlinkDestination, getEncoding() );
- InputStreamSupplier payload = () -> new ByteArrayInputStream( bytes );
- zOut.addArchiveEntry( ze, payload, true );
- }
- else
- {
- zOut.addArchiveEntry( ze, in, addInParallel );
+ @SuppressWarnings({"JavaDoc"})
+ protected void zipFile(
+ InputStreamSupplier in,
+ ConcurrentJarCreator zOut,
+ String vPath,
+ long lastModified,
+ File fromArchive,
+ int mode,
+ String symlinkDestination,
+ boolean addInParallel)
+ throws IOException, ArchiverException {
+ getLogger().debug("adding entry " + vPath);
+
+ entries.put(vPath, vPath);
+
+ if (!skipWriting) {
+ ZipArchiveEntry ze = new ZipArchiveEntry(vPath);
+ setZipEntryTime(ze, lastModified);
+
+ ze.setMethod(doCompress ? ZipArchiveEntry.DEFLATED : ZipArchiveEntry.STORED);
+ ze.setUnixMode(UnixStat.FILE_FLAG | mode);
+
+ if (ze.isUnixSymlink()) {
+ final byte[] bytes = encodeArchiveEntry(symlinkDestination, getEncoding());
+ InputStreamSupplier payload = () -> new ByteArrayInputStream(bytes);
+ zOut.addArchiveEntry(ze, payload, true);
+ } else {
+ zOut.addArchiveEntry(ze, in, addInParallel);
}
}
}
@@ -489,39 +422,35 @@ protected void zipFile( InputStreamSupplier in, ConcurrentJarCreator zOut, Strin
* @param zOut the stream to write to
* @param vPath the name this entry shall have in the archive
*/
- @SuppressWarnings(
- {
- "JavaDoc"
- } )
- protected void zipFile( final ArchiveEntry entry, ConcurrentJarCreator zOut, String vPath )
- throws IOException, ArchiverException
- {
+ @SuppressWarnings({"JavaDoc"})
+ protected void zipFile(final ArchiveEntry entry, ConcurrentJarCreator zOut, String vPath)
+ throws IOException, ArchiverException {
final PlexusIoResource resource = entry.getResource();
- if ( ResourceUtils.isSame( resource, getDestFile() ) )
- {
- throw new ArchiverException( "A zip file cannot include itself" );
+ if (ResourceUtils.isSame(resource, getDestFile())) {
+ throw new ArchiverException("A zip file cannot include itself");
}
final boolean b = entry.getResource() instanceof SymlinkDestinationSupplier;
- String symlinkTarget = b ? ( (SymlinkDestinationSupplier) entry.getResource() ).getSymlinkDestination() : null;
+ String symlinkTarget = b ? ((SymlinkDestinationSupplier) entry.getResource()).getSymlinkDestination() : null;
InputStreamSupplier in = () -> {
- try
- {
+ try {
return entry.getInputStream();
- }
- catch ( IOException e )
- {
- throw new UncheckedIOException( e );
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
}
};
- try
- {
- zipFile( in, zOut, vPath, resource.getLastModified(), null, entry.getMode(), symlinkTarget,
- !entry.shouldAddSynchronously() );
- }
- catch ( IOException e )
- {
- throw new ArchiverException( "IOException when zipping r" + entry.getName() + ": " + e.getMessage(), e );
+ try {
+ zipFile(
+ in,
+ zOut,
+ vPath,
+ resource.getLastModified(),
+ null,
+ entry.getMode(),
+ symlinkTarget,
+ !entry.shouldAddSynchronously());
+ } catch (IOException e) {
+ throw new ArchiverException("IOException when zipping r" + entry.getName() + ": " + e.getMessage(), e);
}
}
@@ -537,37 +466,30 @@ protected void zipFile( final ArchiveEntry entry, ConcurrentJarCreator zOut, Str
* @param zipEntry to set the last modified time
* @param lastModifiedTime to set in the zip entry only if {@link #getLastModifiedTime()} returns null
*/
- protected void setZipEntryTime( ZipArchiveEntry zipEntry, long lastModifiedTime )
- {
- if ( getLastModifiedTime() != null )
- {
+ protected void setZipEntryTime(ZipArchiveEntry zipEntry, long lastModifiedTime) {
+ if (getLastModifiedTime() != null) {
lastModifiedTime = getLastModifiedTime().toMillis();
}
- zipEntry.setTime( lastModifiedTime + 1999 );
+ zipEntry.setTime(lastModifiedTime + 1999);
}
- protected void zipDir( PlexusIoResource dir, ConcurrentJarCreator zOut, String vPath, int mode,
- String encodingToUse )
- throws IOException
- {
- if ( addedDirs.update( vPath ) )
- {
+ protected void zipDir(PlexusIoResource dir, ConcurrentJarCreator zOut, String vPath, int mode, String encodingToUse)
+ throws IOException {
+ if (addedDirs.update(vPath)) {
return;
}
- getLogger().debug( "adding directory " + vPath );
+ getLogger().debug("adding directory " + vPath);
- if ( !skipWriting )
- {
+ if (!skipWriting) {
final boolean isSymlink = dir instanceof SymlinkDestinationSupplier;
- if ( isSymlink && vPath.endsWith( File.separator ) )
- {
- vPath = vPath.substring( 0, vPath.length() - 1 );
+ if (isSymlink && vPath.endsWith(File.separator)) {
+ vPath = vPath.substring(0, vPath.length() - 1);
}
- ZipArchiveEntry ze = new ZipArchiveEntry( vPath );
+ ZipArchiveEntry ze = new ZipArchiveEntry(vPath);
/*
* ZipOutputStream.putNextEntry expects the ZipEntry to
@@ -576,50 +498,40 @@ protected void zipDir( PlexusIoResource dir, ConcurrentJarCreator zOut, String v
*
* This forces us to process the data twice.
*/
- if ( isSymlink )
- {
+ if (isSymlink) {
mode = UnixStat.LINK_FLAG | mode;
}
- if ( dir != null && dir.isExisting() )
- {
- setZipEntryTime( ze, dir.getLastModified() );
- }
- else
- {
+ if (dir != null && dir.isExisting()) {
+ setZipEntryTime(ze, dir.getLastModified());
+ } else {
// ZIPs store time with a granularity of 2 seconds, round up
- setZipEntryTime( ze, System.currentTimeMillis() );
+ setZipEntryTime(ze, System.currentTimeMillis());
}
- if ( !isSymlink )
- {
- ze.setSize( 0 );
- ze.setMethod( ZipArchiveEntry.STORED );
+ if (!isSymlink) {
+ ze.setSize(0);
+ ze.setMethod(ZipArchiveEntry.STORED);
// This is faintly ridiculous:
- ze.setCrc( EMPTY_CRC );
- }
- ze.setUnixMode( mode );
-
- if ( !isSymlink )
- {
- zOut.addArchiveEntry( ze, () -> Streams.EMPTY_INPUTSTREAM, true );
+ ze.setCrc(EMPTY_CRC);
}
- else
- {
- String symlinkDestination = ( (SymlinkDestinationSupplier) dir ).getSymlinkDestination();
- final byte[] bytes = encodeArchiveEntry( symlinkDestination, encodingToUse );
- ze.setMethod( ZipArchiveEntry.DEFLATED );
- zOut.addArchiveEntry( ze, () -> new ByteArrayInputStream( bytes ), true );
+ ze.setUnixMode(mode);
+
+ if (!isSymlink) {
+ zOut.addArchiveEntry(ze, () -> Streams.EMPTY_INPUTSTREAM, true);
+ } else {
+ String symlinkDestination = ((SymlinkDestinationSupplier) dir).getSymlinkDestination();
+ final byte[] bytes = encodeArchiveEntry(symlinkDestination, encodingToUse);
+ ze.setMethod(ZipArchiveEntry.DEFLATED);
+ zOut.addArchiveEntry(ze, () -> new ByteArrayInputStream(bytes), true);
}
}
}
- private byte[] encodeArchiveEntry( String payload, String encoding )
- throws IOException
- {
- ZipEncoding enc = ZipEncodingHelper.getZipEncoding( encoding );
- ByteBuffer encodedPayloadByteBuffer = enc.encode( payload );
+ private byte[] encodeArchiveEntry(String payload, String encoding) throws IOException {
+ ZipEncoding enc = ZipEncodingHelper.getZipEncoding(encoding);
+ ByteBuffer encodedPayloadByteBuffer = enc.encode(payload);
byte[] encodedPayloadBytes = new byte[encodedPayloadByteBuffer.limit()];
- encodedPayloadByteBuffer.get( encodedPayloadBytes );
+ encodedPayloadByteBuffer.get(encodedPayloadBytes);
return encodedPayloadBytes;
}
@@ -631,32 +543,24 @@ private byte[] encodeArchiveEntry( String payload, String encoding )
*
* @return true for historic reasons
*/
- @SuppressWarnings(
- {
- "JavaDoc"
- } )
- protected boolean createEmptyZip( File zipFile )
- throws ArchiverException
- {
+ @SuppressWarnings({"JavaDoc"})
+ protected boolean createEmptyZip(File zipFile) throws ArchiverException {
// In this case using java.util.zip will not work
// because it does not permit a zero-entry archive.
// Must create it manually.
- getLogger().info( "Note: creating empty " + archiveType + " archive " + zipFile );
+ getLogger().info("Note: creating empty " + archiveType + " archive " + zipFile);
- try ( OutputStream os = Files.newOutputStream( zipFile.toPath() ) )
- {
+ try (OutputStream os = Files.newOutputStream(zipFile.toPath())) {
// Cf. PKZIP specification.
- byte[] empty = new byte[ 22 ];
+ byte[] empty = new byte[22];
empty[0] = 80; // P
empty[1] = 75; // K
empty[2] = 5;
empty[3] = 6;
// remainder zeros
- os.write( empty );
- }
- catch ( IOException ioe )
- {
- throw new ArchiverException( "Could not create empty ZIP archive " + "(" + ioe.getMessage() + ")", ioe );
+ os.write(empty);
+ } catch (IOException ioe) {
+ throw new ArchiverException("Could not create empty ZIP archive " + "(" + ioe.getMessage() + ")", ioe);
}
return true;
}
@@ -676,9 +580,7 @@ protected boolean createEmptyZip( File zipFile )
* @see #reset
*/
@Override
- protected void cleanUp()
- throws IOException
- {
+ protected void cleanUp() throws IOException {
super.cleanUp();
addedDirs.clear();
entries.clear();
@@ -696,10 +598,9 @@ protected void cleanUp()
*
* @see #cleanUp
*/
- public void reset()
- {
- setDestFile( null );
-// duplicate = "add";
+ public void reset() {
+ setDestFile(null);
+ // duplicate = "add";
archiveType = "zip";
doCompress = true;
doUpdate = false;
@@ -712,42 +613,32 @@ public void reset()
*
* @param zOut The output stream
*/
- protected void initZipOutputStream( ConcurrentJarCreator zOut )
- throws ArchiverException, IOException
- {
- }
+ protected void initZipOutputStream(ConcurrentJarCreator zOut) throws ArchiverException, IOException {}
/**
* method for subclasses to override
*/
@Override
- public boolean isSupportingForced()
- {
+ public boolean isSupportingForced() {
return true;
}
@Override
- protected boolean revert( StringBuffer messageBuffer )
- {
+ protected boolean revert(StringBuffer messageBuffer) {
int initLength = messageBuffer.length();
// delete a bogus ZIP file (but only if it's not the original one)
- if ( ( !doUpdate || renamedFile != null ) && !zipFile.delete() )
- {
- messageBuffer.append( " (and the archive is probably corrupt but I could not delete it)" );
+ if ((!doUpdate || renamedFile != null) && !zipFile.delete()) {
+ messageBuffer.append(" (and the archive is probably corrupt but I could not delete it)");
}
- if ( doUpdate && renamedFile != null )
- {
- try
- {
- FileUtils.rename( renamedFile, zipFile );
- }
- catch ( IOException e )
- {
- messageBuffer.append( " (and I couldn't rename the temporary file " );
- messageBuffer.append( renamedFile.getName() );
- messageBuffer.append( " back)" );
+ if (doUpdate && renamedFile != null) {
+ try {
+ FileUtils.rename(renamedFile, zipFile);
+ } catch (IOException e) {
+ messageBuffer.append(" (and I couldn't rename the temporary file ");
+ messageBuffer.append(renamedFile.getName());
+ messageBuffer.append(" back)");
}
}
@@ -755,23 +646,16 @@ protected boolean revert( StringBuffer messageBuffer )
}
@Override
- protected void close()
- throws IOException
- {
+ protected void close() throws IOException {
// Close the output stream.
- try
- {
- if ( zipArchiveOutputStream != null )
- {
- if ( zOut != null )
- {
- zOut.writeTo( zipArchiveOutputStream );
+ try {
+ if (zipArchiveOutputStream != null) {
+ if (zOut != null) {
+ zOut.writeTo(zipArchiveOutputStream);
}
zipArchiveOutputStream.close();
}
- }
- catch ( IOException ex )
- {
+ } catch (IOException ex) {
// If we're in this finally clause because of an
// exception, we don't really care if there's an
// exception when closing the stream. E.g. if it
@@ -781,39 +665,32 @@ protected void close()
// exception. Otherwise, the error that's reported
// will be the close() error, which is not the
// real cause of the problem.
- if ( success )
- {
+ if (success) {
throw ex;
}
- }
- catch ( InterruptedException e )
- {
- IOException ex = new IOException( "InterruptedException exception" );
- ex.initCause( e.getCause() );
+ } catch (InterruptedException e) {
+ IOException ex = new IOException("InterruptedException exception");
+ ex.initCause(e.getCause());
throw ex;
- }
- catch ( ExecutionException e )
- {
- IOException ex = new IOException( "Execution exception" );
- ex.initCause( e.getCause() );
+ } catch (ExecutionException e) {
+ IOException ex = new IOException("Execution exception");
+ ex.initCause(e.getCause());
throw ex;
}
}
@Override
- protected String getArchiveType()
- {
+ protected String getArchiveType() {
return archiveType;
}
@Override
- protected FileTime normalizeLastModifiedTime( FileTime lastModifiedTime )
- {
+ protected FileTime normalizeLastModifiedTime(FileTime lastModifiedTime) {
// timestamp of zip entries at zip storage level ignores timezone: managed in ZipEntry.setTime,
// that turns javaToDosTime: need to revert the operation here to get reproducible
// zip entry time
- return FileTime.fromMillis( dosToJavaTime( lastModifiedTime.toMillis() ) );
+ return FileTime.fromMillis(dosToJavaTime(lastModifiedTime.toMillis()));
}
/**
@@ -822,10 +699,9 @@ protected FileTime normalizeLastModifiedTime( FileTime lastModifiedTime )
* @see java.util.zip.ZipEntry#setTime
* @see java.util.zip.ZipUtils#dosToJavaTime
*/
- private static long dosToJavaTime( long dosTime )
- {
- Calendar cal = Calendar.getInstance( TimeZone.getDefault(), Locale.ROOT );
- cal.setTimeInMillis( dosTime );
- return dosTime - ( cal.get( Calendar.ZONE_OFFSET ) + cal.get( Calendar.DST_OFFSET ) );
+ private static long dosToJavaTime(long dosTime) {
+ Calendar cal = Calendar.getInstance(TimeZone.getDefault(), Locale.ROOT);
+ cal.setTimeInMillis(dosTime);
+ return dosTime - (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET));
}
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipUnArchiver.java b/src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipUnArchiver.java
index c5b046ece..4b2219de8 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipUnArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipUnArchiver.java
@@ -16,13 +16,15 @@
*/
package org.codehaus.plexus.archiver.zip;
+import javax.annotation.Nonnull;
+
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Date;
import java.util.Enumeration;
-import javax.annotation.Nonnull;
+
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.input.BoundedInputStream;
@@ -34,9 +36,7 @@
/**
* @author Emmanuel Venisse
*/
-public abstract class AbstractZipUnArchiver
- extends AbstractUnArchiver
-{
+public abstract class AbstractZipUnArchiver extends AbstractUnArchiver {
private static final String NATIVE_ENCODING = "native-encoding";
@@ -44,13 +44,10 @@ public abstract class AbstractZipUnArchiver
private long maxOutputSize = Long.MAX_VALUE;
- public AbstractZipUnArchiver()
- {
- }
+ public AbstractZipUnArchiver() {}
- public AbstractZipUnArchiver( final File sourceFile )
- {
- super( sourceFile );
+ public AbstractZipUnArchiver(final File sourceFile) {
+ super(sourceFile);
}
/**
@@ -59,10 +56,8 @@ public AbstractZipUnArchiver( final File sourceFile )
* Set to native-encoding
if you want your platform's native encoding, defaults to UTF8.
*
*/
- public void setEncoding( String encoding )
- {
- if ( NATIVE_ENCODING.equals( encoding ) )
- {
+ public void setEncoding(String encoding) {
+ if (NATIVE_ENCODING.equals(encoding)) {
encoding = null;
}
this.encoding = encoding;
@@ -76,152 +71,126 @@ public void setEncoding( String encoding )
* @param maxOutputSize max size of the produced output, in bytes. Must be greater than 0
* @throws IllegalArgumentException if specified output size is less or equal to 0
*/
- public void setMaxOutputSize( long maxOutputSize ) {
- if ( maxOutputSize <= 0 ) {
- throw new IllegalArgumentException( "Invalid max output size specified: " + maxOutputSize );
+ public void setMaxOutputSize(long maxOutputSize) {
+ if (maxOutputSize <= 0) {
+ throw new IllegalArgumentException("Invalid max output size specified: " + maxOutputSize);
}
this.maxOutputSize = maxOutputSize;
}
- private static class ZipEntryFileInfo
- implements PlexusIoResource
- {
+ private static class ZipEntryFileInfo implements PlexusIoResource {
private final org.apache.commons.compress.archivers.zip.ZipFile zipFile;
private final ZipArchiveEntry zipEntry;
- ZipEntryFileInfo( final org.apache.commons.compress.archivers.zip.ZipFile zipFile,
- final ZipArchiveEntry zipEntry )
- {
+ ZipEntryFileInfo(
+ final org.apache.commons.compress.archivers.zip.ZipFile zipFile, final ZipArchiveEntry zipEntry) {
this.zipFile = zipFile;
this.zipEntry = zipEntry;
}
- public String getName()
- {
+ public String getName() {
return zipEntry.getName();
}
@Override
- public boolean isDirectory()
- {
+ public boolean isDirectory() {
return zipEntry.isDirectory();
}
@Override
- public boolean isFile()
- {
+ public boolean isFile() {
return !zipEntry.isDirectory() && !zipEntry.isUnixSymlink();
}
@Override
- public boolean isSymbolicLink()
- {
+ public boolean isSymbolicLink() {
return zipEntry.isUnixSymlink();
}
@Nonnull
@Override
- public InputStream getContents()
- throws IOException
- {
- return zipFile.getInputStream( zipEntry );
+ public InputStream getContents() throws IOException {
+ return zipFile.getInputStream(zipEntry);
}
@Override
- public long getLastModified()
- {
+ public long getLastModified() {
final long l = zipEntry.getTime();
return l == 0 ? PlexusIoResource.UNKNOWN_MODIFICATION_DATE : l;
}
@Override
- public long getSize()
- {
+ public long getSize() {
final long l = zipEntry.getSize();
return l == -1 ? PlexusIoResource.UNKNOWN_RESOURCE_SIZE : l;
}
@Override
- public URL getURL()
- throws IOException
- {
+ public URL getURL() throws IOException {
return null;
}
@Override
- public boolean isExisting()
- {
+ public boolean isExisting() {
return true;
}
-
}
@Override
- protected void execute()
- throws ArchiverException
- {
- execute( "", getDestDirectory() );
+ protected void execute() throws ArchiverException {
+ execute("", getDestDirectory());
}
- private String resolveSymlink( ZipFile zf, ZipArchiveEntry ze )
- throws IOException
- {
- if ( ze.isUnixSymlink() )
- {
- return zf.getUnixSymlink( ze );
- }
- else
- {
+ private String resolveSymlink(ZipFile zf, ZipArchiveEntry ze) throws IOException {
+ if (ze.isUnixSymlink()) {
+ return zf.getUnixSymlink(ze);
+ } else {
return null;
}
}
@Override
- protected void execute( final String path, final File outputDirectory )
- throws ArchiverException
- {
- getLogger().debug( "Expanding: " + getSourceFile() + " into " + outputDirectory );
- try ( ZipFile zipFile = new ZipFile( getSourceFile(), encoding, true ) )
- {
+ protected void execute(final String path, final File outputDirectory) throws ArchiverException {
+ getLogger().debug("Expanding: " + getSourceFile() + " into " + outputDirectory);
+ try (ZipFile zipFile = new ZipFile(getSourceFile(), encoding, true)) {
long remainingSpace = maxOutputSize;
final Enumeration e = zipFile.getEntriesInPhysicalOrder();
- while ( e.hasMoreElements() )
- {
+ while (e.hasMoreElements()) {
final ZipArchiveEntry ze = e.nextElement();
- final ZipEntryFileInfo fileInfo = new ZipEntryFileInfo( zipFile, ze );
- if ( !isSelected( ze.getName(), fileInfo ) )
- {
+ final ZipEntryFileInfo fileInfo = new ZipEntryFileInfo(zipFile, ze);
+ if (!isSelected(ze.getName(), fileInfo)) {
continue;
}
- if ( ze.getName().startsWith( path ) )
- {
- try ( InputStream in = zipFile.getInputStream( ze ) )
- {
- BoundedInputStream bis = new BoundedInputStream( in, remainingSpace + 1 );
- CountingInputStream cis = new CountingInputStream( bis );
- extractFile( getSourceFile(), outputDirectory, cis,
- ze.getName(), new Date( ze.getTime() ), ze.isDirectory(),
- ze.getUnixMode() != 0 ? ze.getUnixMode() : null,
- resolveSymlink( zipFile, ze ), getFileMappers() );
+ if (ze.getName().startsWith(path)) {
+ try (InputStream in = zipFile.getInputStream(ze)) {
+ BoundedInputStream bis = new BoundedInputStream(in, remainingSpace + 1);
+ CountingInputStream cis = new CountingInputStream(bis);
+ extractFile(
+ getSourceFile(),
+ outputDirectory,
+ cis,
+ ze.getName(),
+ new Date(ze.getTime()),
+ ze.isDirectory(),
+ ze.getUnixMode() != 0 ? ze.getUnixMode() : null,
+ resolveSymlink(zipFile, ze),
+ getFileMappers());
remainingSpace -= cis.getByteCount();
- if ( remainingSpace < 0 )
- {
- throw new ArchiverException( "Maximum output size limit reached" );
+ if (remainingSpace < 0) {
+ throw new ArchiverException("Maximum output size limit reached");
}
}
}
}
- getLogger().debug( "expand complete" );
- }
- catch ( final IOException ioe )
- {
- throw new ArchiverException( "Error while expanding " + getSourceFile().getAbsolutePath(), ioe );
+ getLogger().debug("expand complete");
+ } catch (final IOException ioe) {
+ throw new ArchiverException(
+ "Error while expanding " + getSourceFile().getAbsolutePath(), ioe);
}
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zip/AddedDirs.java b/src/main/java/org/codehaus/plexus/archiver/zip/AddedDirs.java
index 4d5438364..00d547630 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zip/AddedDirs.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zip/AddedDirs.java
@@ -25,8 +25,7 @@
/**
* A list of directories that have been added to an archive.
*/
-public class AddedDirs
-{
+public class AddedDirs {
private final Set addedDirs = new HashSet();
@@ -34,52 +33,45 @@ public class AddedDirs
* @deprecated use {@link #asStringDeque(String)} instead.
*/
@Deprecated
- public Stack asStringStack( String entry )
- {
+ public Stack asStringStack(String entry) {
Stack directories = new Stack<>();
// Don't include the last entry itself if it's
// a dir; it will be added on its own.
- int slashPos = entry.length() - ( entry.endsWith( "/" ) ? 1 : 0 );
+ int slashPos = entry.length() - (entry.endsWith("/") ? 1 : 0);
- while ( ( slashPos = entry.lastIndexOf( '/', slashPos - 1 ) ) != -1 )
- {
- String dir = entry.substring( 0, slashPos + 1 );
+ while ((slashPos = entry.lastIndexOf('/', slashPos - 1)) != -1) {
+ String dir = entry.substring(0, slashPos + 1);
- if ( addedDirs.contains( dir ) )
- {
+ if (addedDirs.contains(dir)) {
break;
}
- directories.push( dir );
+ directories.push(dir);
}
return directories;
}
- public Deque asStringDeque( String entry )
- {
+ public Deque asStringDeque(String entry) {
Deque directories = new ArrayDeque<>();
// Don't include the last entry itself if it's
// a dir; it will be added on its own.
- int slashPos = entry.length() - ( entry.endsWith( "/" ) ? 1 : 0 );
+ int slashPos = entry.length() - (entry.endsWith("/") ? 1 : 0);
- while ( ( slashPos = entry.lastIndexOf( '/', slashPos - 1 ) ) != -1 )
- {
- String dir = entry.substring( 0, slashPos + 1 );
+ while ((slashPos = entry.lastIndexOf('/', slashPos - 1)) != -1) {
+ String dir = entry.substring(0, slashPos + 1);
- if ( addedDirs.contains( dir ) )
- {
+ if (addedDirs.contains(dir)) {
break;
}
- directories.push( dir );
+ directories.push(dir);
}
return directories;
}
- public void clear()
- {
+ public void clear() {
addedDirs.clear();
}
@@ -90,14 +82,11 @@ public void clear()
*
* @return true if the path was already present, false if it has been added.
*/
- public boolean update( String vPath )
- {
- return !addedDirs.add( vPath );
+ public boolean update(String vPath) {
+ return !addedDirs.add(vPath);
}
- public Set allAddedDirs()
- {
- return new HashSet( addedDirs );
+ public Set allAddedDirs() {
+ return new HashSet(addedDirs);
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zip/AnonymousResource.java b/src/main/java/org/codehaus/plexus/archiver/zip/AnonymousResource.java
index 65de3dd90..9affe55d7 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zip/AnonymousResource.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zip/AnonymousResource.java
@@ -1,47 +1,39 @@
package org.codehaus.plexus.archiver.zip;
+import javax.annotation.Nonnull;
+
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import javax.annotation.Nonnull;
import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource;
-public class AnonymousResource extends AbstractPlexusIoResource
-{
+public class AnonymousResource extends AbstractPlexusIoResource {
private final File file;
- public AnonymousResource( File file )
- {
- this( file, getName( file ) );
+ public AnonymousResource(File file) {
+ this(file, getName(file));
}
- public AnonymousResource( File file, String name )
- {
- super( name, file.lastModified(), file.length(), file.isFile(), file.isDirectory(), file.exists() );
+ public AnonymousResource(File file, String name) {
+ super(name, file.lastModified(), file.length(), file.isFile(), file.isDirectory(), file.exists());
this.file = file;
}
@Nonnull
@Override
- public InputStream getContents()
- throws IOException
- {
- throw new UnsupportedOperationException( "not supp" );
+ public InputStream getContents() throws IOException {
+ throw new UnsupportedOperationException("not supp");
}
@Override
- public URL getURL()
- throws IOException
- {
+ public URL getURL() throws IOException {
return file.toURI().toURL();
}
- private static String getName( File file )
- {
- return file.getPath().replace( '\\', '/' );
+ private static String getName(File file) {
+ return file.getPath().replace('\\', '/');
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zip/ByteArrayOutputStream.java b/src/main/java/org/codehaus/plexus/archiver/zip/ByteArrayOutputStream.java
index 5f62ab9fc..41a26f0c0 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zip/ByteArrayOutputStream.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zip/ByteArrayOutputStream.java
@@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+
import org.apache.commons.io.input.ClosedInputStream;
/**
@@ -49,13 +50,12 @@
* designed to behave exactly like the original. The only exception is the
* deprecated toString(int) method that has been ignored.
*/
-public class ByteArrayOutputStream extends OutputStream
-{
+public class ByteArrayOutputStream extends OutputStream {
/**
* A singleton empty byte array.
*/
- private static final byte[] EMPTY_BYTE_ARRAY = new byte[ 0 ];
+ private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
/**
* The list of buffers, which grows and never reduces.
@@ -91,9 +91,8 @@ public class ByteArrayOutputStream extends OutputStream
* Creates a new byte array output stream. The buffer capacity is
* initially 1024 bytes, though its size increases if necessary.
*/
- public ByteArrayOutputStream()
- {
- this( 1024 );
+ public ByteArrayOutputStream() {
+ this(1024);
}
/**
@@ -104,15 +103,12 @@ public ByteArrayOutputStream()
*
* @throws IllegalArgumentException if size is negative
*/
- public ByteArrayOutputStream( final int size )
- {
- if ( size < 0 )
- {
- throw new IllegalArgumentException( "Negative initial size: " + size );
+ public ByteArrayOutputStream(final int size) {
+ if (size < 0) {
+ throw new IllegalArgumentException("Negative initial size: " + size);
}
- synchronized ( this )
- {
- needNewBuffer( size );
+ synchronized (this) {
+ needNewBuffer(size);
}
}
@@ -122,36 +118,27 @@ public ByteArrayOutputStream( final int size )
*
* @param newcount the size of the buffer if one is created
*/
- private void needNewBuffer( final int newcount )
- {
- if ( currentBufferIndex < buffers.size() - 1 )
- {
- //Recycling old buffer
+ private void needNewBuffer(final int newcount) {
+ if (currentBufferIndex < buffers.size() - 1) {
+ // Recycling old buffer
filledBufferSum += currentBuffer.length;
currentBufferIndex++;
- currentBuffer = buffers.get( currentBufferIndex );
- }
- else
- {
- //Creating new buffer
+ currentBuffer = buffers.get(currentBufferIndex);
+ } else {
+ // Creating new buffer
int newBufferSize;
- if ( currentBuffer == null )
- {
+ if (currentBuffer == null) {
newBufferSize = newcount;
filledBufferSum = 0;
- }
- else
- {
- newBufferSize = Math.max(
- currentBuffer.length << 1,
- newcount - filledBufferSum );
+ } else {
+ newBufferSize = Math.max(currentBuffer.length << 1, newcount - filledBufferSum);
filledBufferSum += currentBuffer.length;
}
currentBufferIndex++;
- currentBuffer = new byte[ newBufferSize ];
- buffers.add( currentBuffer );
+ currentBuffer = new byte[newBufferSize];
+ buffers.add(currentBuffer);
}
}
@@ -163,33 +150,22 @@ private void needNewBuffer( final int newcount )
* @param len The number of bytes to write
*/
@Override
- public void write( final byte[] b, final int off, final int len )
- {
- if ( ( off < 0 )
- || ( off > b.length )
- || ( len < 0 )
- || ( ( off + len ) > b.length )
- || ( ( off + len ) < 0 ) )
- {
+ public void write(final byte[] b, final int off, final int len) {
+ if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
- }
- else if ( len == 0 )
- {
+ } else if (len == 0) {
return;
}
- synchronized ( this )
- {
+ synchronized (this) {
final int newcount = count + len;
int remaining = len;
int inBufferPos = count - filledBufferSum;
- while ( remaining > 0 )
- {
- final int part = Math.min( remaining, currentBuffer.length - inBufferPos );
- System.arraycopy( b, off + len - remaining, currentBuffer, inBufferPos, part );
+ while (remaining > 0) {
+ final int part = Math.min(remaining, currentBuffer.length - inBufferPos);
+ System.arraycopy(b, off + len - remaining, currentBuffer, inBufferPos, part);
remaining -= part;
- if ( remaining > 0 )
- {
- needNewBuffer( newcount );
+ if (remaining > 0) {
+ needNewBuffer(newcount);
inBufferPos = 0;
}
}
@@ -203,12 +179,10 @@ else if ( len == 0 )
* @param b the byte to write
*/
@Override
- public synchronized void write( final int b )
- {
+ public synchronized void write(final int b) {
int inBufferPos = count - filledBufferSum;
- if ( inBufferPos == currentBuffer.length )
- {
- needNewBuffer( count + 1 );
+ if (inBufferPos == currentBuffer.length) {
+ needNewBuffer(count + 1);
inBufferPos = 0;
}
currentBuffer[inBufferPos] = (byte) b;
@@ -228,22 +202,19 @@ public synchronized void write( final int b )
* @throws java.io.IOException if an I/O error occurs while reading the input stream
* @since 1.4
*/
- public synchronized int write( final InputStream in ) throws IOException
- {
+ public synchronized int write(final InputStream in) throws IOException {
int readCount = 0;
int inBufferPos = count - filledBufferSum;
- int n = in.read( currentBuffer, inBufferPos, currentBuffer.length - inBufferPos );
- while ( n != -1 )
- {
+ int n = in.read(currentBuffer, inBufferPos, currentBuffer.length - inBufferPos);
+ while (n != -1) {
readCount += n;
inBufferPos += n;
count += n;
- if ( inBufferPos == currentBuffer.length )
- {
- needNewBuffer( currentBuffer.length );
+ if (inBufferPos == currentBuffer.length) {
+ needNewBuffer(currentBuffer.length);
inBufferPos = 0;
}
- n = in.read( currentBuffer, inBufferPos, currentBuffer.length - inBufferPos );
+ n = in.read(currentBuffer, inBufferPos, currentBuffer.length - inBufferPos);
}
return readCount;
}
@@ -253,8 +224,7 @@ public synchronized int write( final InputStream in ) throws IOException
*
* @return the current size of the byte array
*/
- public synchronized int size()
- {
+ public synchronized int size() {
return count;
}
@@ -267,30 +237,25 @@ public synchronized int size()
* but it has to now due to backwards compatibility)
*/
@Override
- public void close() throws IOException
- {
- //nop
+ public void close() throws IOException {
+ // nop
}
/**
* @see java.io.ByteArrayOutputStream#reset()
*/
- public synchronized void reset()
- {
+ public synchronized void reset() {
count = 0;
filledBufferSum = 0;
currentBufferIndex = 0;
- if ( reuseBuffers )
- {
- currentBuffer = buffers.get( currentBufferIndex );
- }
- else
- {
- //Throw away old buffers
+ if (reuseBuffers) {
+ currentBuffer = buffers.get(currentBufferIndex);
+ } else {
+ // Throw away old buffers
currentBuffer = null;
- int size = buffers.get( 0 ).length;
+ int size = buffers.get(0).length;
buffers.clear();
- needNewBuffer( size );
+ needNewBuffer(size);
reuseBuffers = true;
}
}
@@ -304,16 +269,13 @@ public synchronized void reset()
* @throws java.io.IOException if an I/O error occurs, such as if the stream is closed
* @see java.io.ByteArrayOutputStream#writeTo(java.io.OutputStream)
*/
- public synchronized void writeTo( final OutputStream out ) throws IOException
- {
+ public synchronized void writeTo(final OutputStream out) throws IOException {
int remaining = count;
- for ( final byte[] buf : buffers )
- {
- final int c = Math.min( buf.length, remaining );
- out.write( buf, 0, c );
+ for (final byte[] buf : buffers) {
+ final int c = Math.min(buf.length, remaining);
+ out.write(buf, 0, c);
remaining -= c;
- if ( remaining == 0 )
- {
+ if (remaining == 0) {
break;
}
}
@@ -342,10 +304,8 @@ public synchronized void writeTo( final OutputStream out ) throws IOException
* @throws java.io.IOException if an I/O error occurs
* @since 2.0
*/
- public static InputStream toBufferedInputStream( final InputStream input )
- throws IOException
- {
- return toBufferedInputStream( input, 1024 );
+ public static InputStream toBufferedInputStream(final InputStream input) throws IOException {
+ return toBufferedInputStream(input, 1024);
}
/**
@@ -372,13 +332,11 @@ public static InputStream toBufferedInputStream( final InputStream input )
* @throws java.io.IOException if an I/O error occurs
* @since 2.5
*/
- public static InputStream toBufferedInputStream( final InputStream input, int size )
- throws IOException
- {
+ public static InputStream toBufferedInputStream(final InputStream input, int size) throws IOException {
// It does not matter if a ByteArrayOutputStream is not closed as close() is a no-op
- @SuppressWarnings( "resource" )
- final ByteArrayOutputStream output = new ByteArrayOutputStream( size );
- output.write( input );
+ @SuppressWarnings("resource")
+ final ByteArrayOutputStream output = new ByteArrayOutputStream(size);
+ output.write(input);
return output.toInputStream();
}
@@ -393,26 +351,22 @@ public static InputStream toBufferedInputStream( final InputStream input, int si
* @see #reset()
* @since 2.5
*/
- public synchronized InputStream toInputStream()
- {
+ public synchronized InputStream toInputStream() {
int remaining = count;
- if ( remaining == 0 )
- {
+ if (remaining == 0) {
return new ClosedInputStream();
}
- final List list = new ArrayList( buffers.size() );
- for ( final byte[] buf : buffers )
- {
- final int c = Math.min( buf.length, remaining );
- list.add( new ByteArrayInputStream( buf, 0, c ) );
+ final List list = new ArrayList(buffers.size());
+ for (final byte[] buf : buffers) {
+ final int c = Math.min(buf.length, remaining);
+ list.add(new ByteArrayInputStream(buf, 0, c));
remaining -= c;
- if ( remaining == 0 )
- {
+ if (remaining == 0) {
break;
}
}
reuseBuffers = false;
- return new SequenceInputStream( Collections.enumeration( list ) );
+ return new SequenceInputStream(Collections.enumeration(list));
}
/**
@@ -423,23 +377,19 @@ public synchronized InputStream toInputStream()
*
* @see java.io.ByteArrayOutputStream#toByteArray()
*/
- public synchronized byte[] toByteArray()
- {
+ public synchronized byte[] toByteArray() {
int remaining = count;
- if ( remaining == 0 )
- {
+ if (remaining == 0) {
return EMPTY_BYTE_ARRAY;
}
- final byte newbuf[] = new byte[ remaining ];
+ final byte newbuf[] = new byte[remaining];
int pos = 0;
- for ( final byte[] buf : buffers )
- {
- final int c = Math.min( buf.length, remaining );
- System.arraycopy( buf, 0, newbuf, pos, c );
+ for (final byte[] buf : buffers) {
+ final int c = Math.min(buf.length, remaining);
+ System.arraycopy(buf, 0, newbuf, pos, c);
pos += c;
remaining -= c;
- if ( remaining == 0 )
- {
+ if (remaining == 0) {
break;
}
}
@@ -457,10 +407,9 @@ public synchronized byte[] toByteArray()
*/
@Override
@Deprecated
- public String toString()
- {
+ public String toString() {
// make explicit the use of the default charset
- return new String( toByteArray(), Charset.defaultCharset() );
+ return new String(toByteArray(), Charset.defaultCharset());
}
/**
@@ -474,9 +423,8 @@ public String toString()
* @throws java.io.UnsupportedEncodingException if the encoding is not supported
* @see java.io.ByteArrayOutputStream#toString(String)
*/
- public String toString( final String enc ) throws UnsupportedEncodingException
- {
- return new String( toByteArray(), enc );
+ public String toString(final String enc) throws UnsupportedEncodingException {
+ return new String(toByteArray(), enc);
}
/**
@@ -490,9 +438,7 @@ public String toString( final String enc ) throws UnsupportedEncodingException
* @see java.io.ByteArrayOutputStream#toString(String)
* @since 2.5
*/
- public String toString( final Charset charset )
- {
- return new String( toByteArray(), charset );
+ public String toString(final Charset charset) {
+ return new String(toByteArray(), charset);
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zip/ConcurrentJarCreator.java b/src/main/java/org/codehaus/plexus/archiver/zip/ConcurrentJarCreator.java
index ecd99f927..5a3c32c5a 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zip/ConcurrentJarCreator.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zip/ConcurrentJarCreator.java
@@ -26,6 +26,7 @@
import java.util.concurrent.Executors;
import java.util.zip.Deflater;
import java.util.zip.ZipEntry;
+
import org.apache.commons.compress.archivers.zip.ParallelScatterZipCreator;
import org.apache.commons.compress.archivers.zip.ScatterZipOutputStream;
import org.apache.commons.compress.archivers.zip.StreamCompressor;
@@ -40,8 +41,7 @@
import static org.apache.commons.compress.archivers.zip.ZipArchiveEntryRequest.createZipArchiveEntryRequest;
-public class ConcurrentJarCreator
-{
+public class ConcurrentJarCreator {
private final boolean compressAddedZips;
@@ -57,33 +57,25 @@ public class ConcurrentJarCreator
private long zipCloseElapsed;
- private static class DeferredSupplier
- implements ScatterGatherBackingStoreSupplier
- {
+ private static class DeferredSupplier implements ScatterGatherBackingStoreSupplier {
private int threshold;
- DeferredSupplier( int threshold )
- {
+ DeferredSupplier(int threshold) {
this.threshold = threshold;
}
@Override
- public ScatterGatherBackingStore get()
- throws IOException
- {
- return new DeferredScatterOutputStream( threshold );
+ public ScatterGatherBackingStore get() throws IOException {
+ return new DeferredScatterOutputStream(threshold);
}
-
}
public static ScatterZipOutputStream createDeferred(
- ScatterGatherBackingStoreSupplier scatterGatherBackingStoreSupplier )
- throws IOException
- {
+ ScatterGatherBackingStoreSupplier scatterGatherBackingStoreSupplier) throws IOException {
ScatterGatherBackingStore bs = scatterGatherBackingStoreSupplier.get();
- StreamCompressor sc = StreamCompressor.create( Deflater.DEFAULT_COMPRESSION, bs );
- return new ScatterZipOutputStream( bs, sc );
+ StreamCompressor sc = StreamCompressor.create(Deflater.DEFAULT_COMPRESSION, bs);
+ return new ScatterZipOutputStream(bs, sc);
}
/**
@@ -98,9 +90,8 @@ public static ScatterZipOutputStream createDeferred(
*
* @throws IOException
*/
- public ConcurrentJarCreator( int nThreads ) throws IOException
- {
- this( true, nThreads );
+ public ConcurrentJarCreator(int nThreads) throws IOException {
+ this(true, nThreads);
}
/**
@@ -121,17 +112,15 @@ public ConcurrentJarCreator( int nThreads ) throws IOException
*
* @throws IOException
*/
- public ConcurrentJarCreator( boolean compressAddedZips, int nThreads ) throws IOException
- {
+ public ConcurrentJarCreator(boolean compressAddedZips, int nThreads) throws IOException {
this.compressAddedZips = compressAddedZips;
- ScatterGatherBackingStoreSupplier defaultSupplier = new DeferredSupplier( 100000000 / nThreads );
- metaInfDir = createDeferred( defaultSupplier );
- manifest = createDeferred( defaultSupplier );
- directories = createDeferred( defaultSupplier );
- synchronousEntries = createDeferred( defaultSupplier );
- parallelScatterZipCreator = new ParallelScatterZipCreator( Executors.newFixedThreadPool( nThreads ),
- defaultSupplier );
-
+ ScatterGatherBackingStoreSupplier defaultSupplier = new DeferredSupplier(100000000 / nThreads);
+ metaInfDir = createDeferred(defaultSupplier);
+ manifest = createDeferred(defaultSupplier);
+ directories = createDeferred(defaultSupplier);
+ synchronousEntries = createDeferred(defaultSupplier);
+ parallelScatterZipCreator =
+ new ParallelScatterZipCreator(Executors.newFixedThreadPool(nThreads), defaultSupplier);
}
/**
@@ -146,51 +135,38 @@ public ConcurrentJarCreator( boolean compressAddedZips, int nThreads ) throws IO
*
* @throws java.io.IOException
*/
- public void addArchiveEntry( final ZipArchiveEntry zipArchiveEntry, final InputStreamSupplier source,
- final boolean addInParallel ) throws IOException
- {
+ public void addArchiveEntry(
+ final ZipArchiveEntry zipArchiveEntry, final InputStreamSupplier source, final boolean addInParallel)
+ throws IOException {
final int method = zipArchiveEntry.getMethod();
- if ( method == -1 )
- {
- throw new IllegalArgumentException( "Method must be set on the supplied zipArchiveEntry" );
+ if (method == -1) {
+ throw new IllegalArgumentException("Method must be set on the supplied zipArchiveEntry");
}
final String zipEntryName = zipArchiveEntry.getName();
- if ( "META-INF".equals( zipEntryName ) || "META-INF/".equals( zipEntryName ) )
- {
+ if ("META-INF".equals(zipEntryName) || "META-INF/".equals(zipEntryName)) {
// TODO This should be enforced because META-INF non-directory does not make any sense?!
- if ( zipArchiveEntry.isDirectory() )
- {
- zipArchiveEntry.setMethod( ZipEntry.STORED );
+ if (zipArchiveEntry.isDirectory()) {
+ zipArchiveEntry.setMethod(ZipEntry.STORED);
}
- metaInfDir.addArchiveEntry( createZipArchiveEntryRequest( zipArchiveEntry, source ) );
- }
- else if ( "META-INF/MANIFEST.MF".equals( zipEntryName ) )
- {
- manifest.addArchiveEntry( createZipArchiveEntryRequest( zipArchiveEntry, source ) );
- }
- else if ( zipArchiveEntry.isDirectory() && !zipArchiveEntry.isUnixSymlink() )
- {
- directories.addArchiveEntry( createZipArchiveEntryRequest( zipArchiveEntry,
- () -> Streams.EMPTY_INPUTSTREAM ) );
- }
- else if ( addInParallel )
- {
- parallelScatterZipCreator.addArchiveEntry( () -> createEntry( zipArchiveEntry, source ) );
- }
- else
- {
- synchronousEntries.addArchiveEntry( createEntry( zipArchiveEntry, source ) );
+ metaInfDir.addArchiveEntry(createZipArchiveEntryRequest(zipArchiveEntry, source));
+ } else if ("META-INF/MANIFEST.MF".equals(zipEntryName)) {
+ manifest.addArchiveEntry(createZipArchiveEntryRequest(zipArchiveEntry, source));
+ } else if (zipArchiveEntry.isDirectory() && !zipArchiveEntry.isUnixSymlink()) {
+ directories.addArchiveEntry(createZipArchiveEntryRequest(zipArchiveEntry, () -> Streams.EMPTY_INPUTSTREAM));
+ } else if (addInParallel) {
+ parallelScatterZipCreator.addArchiveEntry(() -> createEntry(zipArchiveEntry, source));
+ } else {
+ synchronousEntries.addArchiveEntry(createEntry(zipArchiveEntry, source));
}
}
- public void writeTo( ZipArchiveOutputStream targetStream ) throws IOException, ExecutionException,
- InterruptedException
- {
- metaInfDir.writeTo( targetStream );
- manifest.writeTo( targetStream );
- directories.writeTo( targetStream );
- synchronousEntries.writeTo( targetStream );
- parallelScatterZipCreator.writeTo( targetStream );
+ public void writeTo(ZipArchiveOutputStream targetStream)
+ throws IOException, ExecutionException, InterruptedException {
+ metaInfDir.writeTo(targetStream);
+ manifest.writeTo(targetStream);
+ directories.writeTo(targetStream);
+ synchronousEntries.writeTo(targetStream);
+ parallelScatterZipCreator.writeTo(targetStream);
long startAt = System.currentTimeMillis();
targetStream.close();
zipCloseElapsed = System.currentTimeMillis() - startAt;
@@ -205,51 +181,41 @@ public void writeTo( ZipArchiveOutputStream targetStream ) throws IOException, E
*
* @return A string
*/
- public String getStatisticsMessage()
- {
+ public String getStatisticsMessage() {
return parallelScatterZipCreator.getStatisticsMessage() + " Zip Close: " + zipCloseElapsed + "ms";
}
- private ZipArchiveEntryRequest createEntry( final ZipArchiveEntry zipArchiveEntry,
- final InputStreamSupplier inputStreamSupplier )
- {
+ private ZipArchiveEntryRequest createEntry(
+ final ZipArchiveEntry zipArchiveEntry, final InputStreamSupplier inputStreamSupplier) {
// if we re-compress the zip files there is no need to look at the input stream
- if ( compressAddedZips )
- {
- return createZipArchiveEntryRequest( zipArchiveEntry, inputStreamSupplier );
+ if (compressAddedZips) {
+ return createZipArchiveEntryRequest(zipArchiveEntry, inputStreamSupplier);
}
InputStream is = inputStreamSupplier.get();
// otherwise we should inspect the first four bytes to see if the input stream is zip file or not
byte[] header = new byte[4];
- try
- {
- int read = is.read( header );
+ try {
+ int read = is.read(header);
int compressionMethod = zipArchiveEntry.getMethod();
- if ( isZipHeader( header ) )
- {
+ if (isZipHeader(header)) {
compressionMethod = ZipEntry.STORED;
}
- zipArchiveEntry.setMethod( compressionMethod );
+ zipArchiveEntry.setMethod(compressionMethod);
- return createZipArchiveEntryRequest( zipArchiveEntry, prependBytesToStream( header, read, is ) );
- }
- catch ( IOException e )
- {
- IOUtils.closeQuietly( is );
- throw new UncheckedIOException( e );
+ return createZipArchiveEntryRequest(zipArchiveEntry, prependBytesToStream(header, read, is));
+ } catch (IOException e) {
+ IOUtils.closeQuietly(is);
+ throw new UncheckedIOException(e);
}
}
- private boolean isZipHeader( byte[] header )
- {
+ private boolean isZipHeader(byte[] header) {
return header[0] == 0x50 && header[1] == 0x4b && header[2] == 3 && header[3] == 4;
}
- private InputStreamSupplier prependBytesToStream( final byte[] bytes, final int len, final InputStream stream )
- {
- return () -> len > 0 ? new SequenceInputStream( new ByteArrayInputStream( bytes, 0, len ), stream ) : stream;
+ private InputStreamSupplier prependBytesToStream(final byte[] bytes, final int len, final InputStream stream) {
+ return () -> len > 0 ? new SequenceInputStream(new ByteArrayInputStream(bytes, 0, len), stream) : stream;
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zip/DeferredScatterOutputStream.java b/src/main/java/org/codehaus/plexus/archiver/zip/DeferredScatterOutputStream.java
index 730fa6dbe..dda5eb2fe 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zip/DeferredScatterOutputStream.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zip/DeferredScatterOutputStream.java
@@ -20,44 +20,37 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+
import org.apache.commons.compress.parallel.ScatterGatherBackingStore;
-public class DeferredScatterOutputStream implements ScatterGatherBackingStore
-{
+public class DeferredScatterOutputStream implements ScatterGatherBackingStore {
private final OffloadingOutputStream dfos;
- public DeferredScatterOutputStream( int threshold )
- {
- dfos = new OffloadingOutputStream( threshold, "scatterzipfragment", "zip" );
+ public DeferredScatterOutputStream(int threshold) {
+ dfos = new OffloadingOutputStream(threshold, "scatterzipfragment", "zip");
}
@Override
- public InputStream getInputStream() throws IOException
- {
+ public InputStream getInputStream() throws IOException {
return dfos.getInputStream();
}
@Override
- public void writeOut( byte[] data, int offset, int length ) throws IOException
- {
- dfos.write( data, offset, length );
+ public void writeOut(byte[] data, int offset, int length) throws IOException {
+ dfos.write(data, offset, length);
}
@Override
- public void closeForWriting() throws IOException
- {
+ public void closeForWriting() throws IOException {
dfos.close();
}
@Override
- public void close() throws IOException
- {
+ public void close() throws IOException {
File file = dfos.getFile();
- if ( file != null )
- {
+ if (file != null) {
file.delete();
}
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zip/OffloadingOutputStream.java b/src/main/java/org/codehaus/plexus/archiver/zip/OffloadingOutputStream.java
index be56fa274..4fc0abffa 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zip/OffloadingOutputStream.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zip/OffloadingOutputStream.java
@@ -30,8 +30,7 @@
/**
* Offloads to disk when a given memory consumption has been reached
*/
-class OffloadingOutputStream extends ThresholdingOutputStream
-{
+class OffloadingOutputStream extends ThresholdingOutputStream {
// ----------------------------------------------------------- Data members
@@ -74,16 +73,14 @@ class OffloadingOutputStream extends ThresholdingOutputStream
* @param suffix Suffix to use for the temporary file.
* @since 1.4
*/
- public OffloadingOutputStream( int threshold, String prefix, String suffix )
- {
- super( threshold );
+ public OffloadingOutputStream(int threshold, String prefix, String suffix) {
+ super(threshold);
- if ( prefix == null )
- {
- throw new IllegalArgumentException( "Temporary file prefix is missing" );
+ if (prefix == null) {
+ throw new IllegalArgumentException("Temporary file prefix is missing");
}
- memoryOutputStream = new ByteArrayOutputStream( threshold / 10 );
+ memoryOutputStream = new ByteArrayOutputStream(threshold / 10);
currentOutputStream = memoryOutputStream;
this.prefix = prefix;
this.suffix = suffix;
@@ -99,8 +96,7 @@ public OffloadingOutputStream( int threshold, String prefix, String suffix )
* @throws java.io.IOException if an error occurs.
*/
@Override
- protected OutputStream getStream() throws IOException
- {
+ protected OutputStream getStream() throws IOException {
return currentOutputStream;
}
@@ -113,21 +109,18 @@ protected OutputStream getStream() throws IOException
* @throws java.io.IOException if an error occurs.
*/
@Override
- protected void thresholdReached() throws IOException
- {
- outputPath = Files.createTempFile( prefix, suffix );
- currentOutputStream = Files.newOutputStream( outputPath );
+ protected void thresholdReached() throws IOException {
+ outputPath = Files.createTempFile(prefix, suffix);
+ currentOutputStream = Files.newOutputStream(outputPath);
}
- public InputStream getInputStream() throws IOException
- {
+ public InputStream getInputStream() throws IOException {
InputStream memoryAsInput = memoryOutputStream.toInputStream();
- if ( outputPath == null )
- {
+ if (outputPath == null) {
return memoryAsInput;
}
- return new SequenceInputStream( memoryAsInput, Files.newInputStream( outputPath ) );
+ return new SequenceInputStream(memoryAsInput, Files.newInputStream(outputPath));
}
// --------------------------------------------------------- Public methods
@@ -140,10 +133,8 @@ public InputStream getInputStream() throws IOException
* @return The data for this output stream, or null
if no such
* data is available.
*/
- public byte[] getData()
- {
- if ( memoryOutputStream != null )
- {
+ public byte[] getData() {
+ if (memoryOutputStream != null) {
return memoryOutputStream.toByteArray();
}
return null;
@@ -163,8 +154,7 @@ public byte[] getData()
* @return The file for this output stream, or null
if no such
* file exists.
*/
- public File getFile()
- {
+ public File getFile() {
return outputPath != null ? outputPath.toFile() : null;
}
@@ -174,8 +164,7 @@ public File getFile()
* @throws java.io.IOException if an error occurs.
*/
@Override
- public void close() throws IOException
- {
+ public void close() throws IOException {
super.close();
currentOutputStream.close();
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zip/PlexusArchiverZipFileResourceCollection.java b/src/main/java/org/codehaus/plexus/archiver/zip/PlexusArchiverZipFileResourceCollection.java
index dfb2c7608..c0d729554 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zip/PlexusArchiverZipFileResourceCollection.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zip/PlexusArchiverZipFileResourceCollection.java
@@ -9,88 +9,72 @@
import java.nio.charset.StandardCharsets;
import java.util.Enumeration;
import java.util.Iterator;
+
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.codehaus.plexus.components.io.resources.AbstractPlexusIoArchiveResourceCollection;
import org.codehaus.plexus.components.io.resources.EncodingSupported;
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
-@Named( "zip" )
-public class PlexusArchiverZipFileResourceCollection
- extends AbstractPlexusIoArchiveResourceCollection implements EncodingSupported
-{
+@Named("zip")
+public class PlexusArchiverZipFileResourceCollection extends AbstractPlexusIoArchiveResourceCollection
+ implements EncodingSupported {
private Charset charset = StandardCharsets.UTF_8;
@Override
- protected Iterator getEntries()
- throws IOException
- {
+ protected Iterator getEntries() throws IOException {
final File f = getFile();
- if ( f == null )
- {
- throw new IOException( "The tar archive file has not been set." );
+ if (f == null) {
+ throw new IOException("The tar archive file has not been set.");
}
- final ZipFile zipFile = new ZipFile( f, charset != null ? charset.name() : "UTF8" );
- return new CloseableIterator( zipFile );
+ final ZipFile zipFile = new ZipFile(f, charset != null ? charset.name() : "UTF8");
+ return new CloseableIterator(zipFile);
}
@Override
- public boolean isConcurrentAccessSupported()
- {
+ public boolean isConcurrentAccessSupported() {
// Well maybe someday investigate if we can do concurrent zip
return false;
}
- class CloseableIterator
- implements Iterator, Closeable
- {
+ class CloseableIterator implements Iterator, Closeable {
final Enumeration en;
private final ZipFile zipFile;
- public CloseableIterator( ZipFile zipFile )
- {
+ public CloseableIterator(ZipFile zipFile) {
this.en = zipFile.getEntriesInPhysicalOrder();
this.zipFile = zipFile;
}
@Override
- public boolean hasNext()
- {
+ public boolean hasNext() {
return en.hasMoreElements();
}
@Override
- public PlexusIoResource next()
- {
+ public PlexusIoResource next() {
final ZipArchiveEntry entry = en.nextElement();
return entry.isUnixSymlink()
- ? new ZipSymlinkResource( zipFile, entry, getStreamTransformer() )
- : new ZipResource( zipFile, entry, getStreamTransformer() );
-
+ ? new ZipSymlinkResource(zipFile, entry, getStreamTransformer())
+ : new ZipResource(zipFile, entry, getStreamTransformer());
}
@Override
- public void remove()
- {
- throw new UnsupportedOperationException( "Removing isn't implemented." );
+ public void remove() {
+ throw new UnsupportedOperationException("Removing isn't implemented.");
}
@Override
- public void close()
- throws IOException
- {
+ public void close() throws IOException {
zipFile.close();
}
-
}
@Override
- public void setEncoding( Charset charset )
- {
+ public void setEncoding(Charset charset) {
this.charset = charset;
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zip/PlexusIoZipFileResourceCollection.java b/src/main/java/org/codehaus/plexus/archiver/zip/PlexusIoZipFileResourceCollection.java
index 92dd8d37b..b4767ddca 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zip/PlexusIoZipFileResourceCollection.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zip/PlexusIoZipFileResourceCollection.java
@@ -15,8 +15,6 @@
*/
package org.codehaus.plexus.archiver.zip;
-import javax.inject.Named;
-
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
@@ -28,6 +26,7 @@
import java.util.Enumeration;
import java.util.Iterator;
import java.util.jar.JarFile;
+
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier;
@@ -38,70 +37,54 @@
// TODO: there were two components for same name!
// @Named( "zip" )
-public class PlexusIoZipFileResourceCollection
- extends AbstractPlexusIoArchiveResourceCollection
- implements EncodingSupported
-{
+public class PlexusIoZipFileResourceCollection extends AbstractPlexusIoArchiveResourceCollection
+ implements EncodingSupported {
private Charset charset = StandardCharsets.UTF_8;
- public PlexusIoZipFileResourceCollection()
- {
-
- }
+ public PlexusIoZipFileResourceCollection() {}
@Override
- public boolean isConcurrentAccessSupported()
- {
+ public boolean isConcurrentAccessSupported() {
// Maybe we could support concurrent some time in the future
return false;
}
@Override
- protected Iterator getEntries()
- throws IOException
- {
+ protected Iterator getEntries() throws IOException {
final File f = getFile();
- if ( f == null )
- {
- throw new IOException( "The zip file has not been set." );
+ if (f == null) {
+ throw new IOException("The zip file has not been set.");
}
- final URLClassLoader urlClassLoader = new URLClassLoader( new URL[]
- {
- f.toURI().toURL()
- }, null )
- {
-
- @Override
- public URL getResource( String name )
- {
- return findResource( name );
- }
-
- };
-
- final URL url = new URL( "jar:" + f.toURI().toURL() + "!/" );
- final JarFile jarFile = new JarFile( f );
- final ZipFile zipFile = new ZipFile( f, charset != null ? charset.name() : "UTF8" );
+ final URLClassLoader urlClassLoader =
+ new URLClassLoader(new URL[] {f.toURI().toURL()}, null) {
+
+ @Override
+ public URL getResource(String name) {
+ return findResource(name);
+ }
+ };
+
+ final URL url = new URL("jar:" + f.toURI().toURL() + "!/");
+ final JarFile jarFile = new JarFile(f);
+ final ZipFile zipFile = new ZipFile(f, charset != null ? charset.name() : "UTF8");
final Enumeration en = zipFile.getEntriesInPhysicalOrder();
- return new ZipFileResourceIterator( en, url, jarFile, zipFile, urlClassLoader );
+ return new ZipFileResourceIterator(en, url, jarFile, zipFile, urlClassLoader);
}
- private static class ZipFileResourceIterator
- implements Iterator, Closeable
- {
+ private static class ZipFileResourceIterator implements Iterator, Closeable {
- private class ZipFileResource
- extends PlexusIoURLResource
- {
+ private class ZipFileResource extends PlexusIoURLResource {
private final JarFile jarFile;
- private ZipFileResource( JarFile jarFile, ZipArchiveEntry entry )
- {
- super( entry.getName(),
- entry.getTime() == -1 ? PlexusIoResource.UNKNOWN_MODIFICATION_DATE : entry.getTime(),
- entry.isDirectory() ? PlexusIoResource.UNKNOWN_RESOURCE_SIZE : entry.getSize(),
- !entry.isDirectory(), entry.isDirectory(), true );
+ private ZipFileResource(JarFile jarFile, ZipArchiveEntry entry) {
+ super(
+ entry.getName(),
+ entry.getTime() == -1 ? PlexusIoResource.UNKNOWN_MODIFICATION_DATE : entry.getTime(),
+ entry.isDirectory() ? PlexusIoResource.UNKNOWN_RESOURCE_SIZE : entry.getSize(),
+ !entry.isDirectory(),
+ entry.isDirectory(),
+ true);
this.jarFile = jarFile;
}
@@ -122,54 +105,42 @@ public InputStream getContents() throws IOException {
// would not be a problem.
// And we know the URL returned by getURL is part of the JAR
// because that is how we constructed it.
- return jarFile.getInputStream( jarFile.getEntry( getName() ) );
+ return jarFile.getInputStream(jarFile.getEntry(getName()));
}
@Override
- public URL getURL()
- throws IOException
- {
+ public URL getURL() throws IOException {
String spec = getName();
- if ( spec.startsWith( "/" ) )
- {
+ if (spec.startsWith("/")) {
// Code path for PLXCOMP-170. Note that urlClassloader does not seem to produce correct
// urls for this. Which again means files loaded via this path cannot have file names
// requiring url encoding
spec = "./" + spec;
- return new URL( url, spec );
+ return new URL(url, spec);
}
- return urlClassLoader.getResource( spec );
+ return urlClassLoader.getResource(spec);
}
-
}
- private class ZipFileSymlinkResource
- extends ZipFileResource
- implements SymlinkDestinationSupplier
- {
+ private class ZipFileSymlinkResource extends ZipFileResource implements SymlinkDestinationSupplier {
private final ZipArchiveEntry entry;
- private ZipFileSymlinkResource( JarFile jarFile, ZipArchiveEntry entry )
- {
- super( jarFile, entry );
+ private ZipFileSymlinkResource(JarFile jarFile, ZipArchiveEntry entry) {
+ super(jarFile, entry);
this.entry = entry;
}
@Override
- public String getSymlinkDestination()
- throws IOException
- {
- return zipFile.getUnixSymlink( entry );
+ public String getSymlinkDestination() throws IOException {
+ return zipFile.getUnixSymlink(entry);
}
@Override
- public boolean isSymbolicLink()
- {
+ public boolean isSymbolicLink() {
return true;
}
-
}
private final Enumeration en;
@@ -182,9 +153,12 @@ public boolean isSymbolicLink()
private final URLClassLoader urlClassLoader;
- public ZipFileResourceIterator( Enumeration en, URL url, JarFile jarFile, ZipFile zipFile,
- URLClassLoader urlClassLoader )
- {
+ public ZipFileResourceIterator(
+ Enumeration en,
+ URL url,
+ JarFile jarFile,
+ ZipFile zipFile,
+ URLClassLoader urlClassLoader) {
this.en = en;
this.url = url;
this.jarFile = jarFile;
@@ -193,54 +167,39 @@ public ZipFileResourceIterator( Enumeration en, URL url, JarFil
}
@Override
- public boolean hasNext()
- {
+ public boolean hasNext() {
return en.hasMoreElements();
}
@Override
- public PlexusIoResource next()
- {
+ public PlexusIoResource next() {
final ZipArchiveEntry entry = en.nextElement();
return entry.isUnixSymlink()
- ? new ZipFileSymlinkResource( jarFile, entry )
- : new ZipFileResource( jarFile, entry );
-
+ ? new ZipFileSymlinkResource(jarFile, entry)
+ : new ZipFileResource(jarFile, entry);
}
@Override
- public void remove()
- {
- throw new UnsupportedOperationException( "Removing isn't implemented." );
+ public void remove() {
+ throw new UnsupportedOperationException("Removing isn't implemented.");
}
@Override
- public void close()
- throws IOException
- {
- try
- {
+ public void close() throws IOException {
+ try {
urlClassLoader.close();
- }
- finally
- {
- try
- {
+ } finally {
+ try {
zipFile.close();
- } finally
- {
+ } finally {
jarFile.close();
}
-
}
}
-
}
@Override
- public void setEncoding( Charset charset )
- {
+ public void setEncoding(Charset charset) {
this.charset = charset;
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zip/ZipArchiver.java b/src/main/java/org/codehaus/plexus/archiver/zip/ZipArchiver.java
index b19b681e8..6a85ba3ee 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zip/ZipArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zip/ZipArchiver.java
@@ -18,8 +18,5 @@
import javax.inject.Named;
-@Named( "zip" )
-public class ZipArchiver
- extends AbstractZipArchiver
-{
-}
+@Named("zip")
+public class ZipArchiver extends AbstractZipArchiver {}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zip/ZipResource.java b/src/main/java/org/codehaus/plexus/archiver/zip/ZipResource.java
index 2df6ac012..c51f6b6a6 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zip/ZipResource.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zip/ZipResource.java
@@ -1,9 +1,11 @@
package org.codehaus.plexus.archiver.zip;
+import javax.annotation.Nonnull;
+
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import javax.annotation.Nonnull;
+
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.codehaus.plexus.archiver.UnixStat;
@@ -15,9 +17,7 @@
import org.codehaus.plexus.components.io.resources.ClosingInputStream;
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
-public class ZipResource extends AbstractPlexusIoResource
- implements ResourceAttributeSupplier
-{
+public class ZipResource extends AbstractPlexusIoResource implements ResourceAttributeSupplier {
private final org.apache.commons.compress.archivers.zip.ZipFile zipFile;
@@ -27,67 +27,57 @@ public class ZipResource extends AbstractPlexusIoResource
private PlexusIoResourceAttributes attributes;
- public ZipResource( ZipFile zipFile, ZipArchiveEntry entry, InputStreamTransformer streamTransformer )
- {
- super( entry.getName(), getLastModified( entry ),
- entry.isDirectory() ? PlexusIoResource.UNKNOWN_RESOURCE_SIZE : entry.getSize(), !entry.isDirectory(),
- entry.isDirectory(), true );
+ public ZipResource(ZipFile zipFile, ZipArchiveEntry entry, InputStreamTransformer streamTransformer) {
+ super(
+ entry.getName(),
+ getLastModified(entry),
+ entry.isDirectory() ? PlexusIoResource.UNKNOWN_RESOURCE_SIZE : entry.getSize(),
+ !entry.isDirectory(),
+ entry.isDirectory(),
+ true);
this.zipFile = zipFile;
this.entry = entry;
this.streamTransformer = streamTransformer;
}
- private static long getLastModified( ZipArchiveEntry entry )
- {
+ private static long getLastModified(ZipArchiveEntry entry) {
long time = entry.getTime();
return time == -1 ? PlexusIoResource.UNKNOWN_MODIFICATION_DATE : time;
}
@Override
- public synchronized PlexusIoResourceAttributes getAttributes()
- {
+ public synchronized PlexusIoResourceAttributes getAttributes() {
int mode = PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE;
- if ( entry.getPlatform() == ZipArchiveEntry.PLATFORM_UNIX )
- {
+ if (entry.getPlatform() == ZipArchiveEntry.PLATFORM_UNIX) {
mode = entry.getUnixMode();
- if ( ( mode & UnixStat.FILE_FLAG ) == UnixStat.FILE_FLAG )
- {
+ if ((mode & UnixStat.FILE_FLAG) == UnixStat.FILE_FLAG) {
mode = mode & ~UnixStat.FILE_FLAG;
- }
- else
- {
+ } else {
mode = mode & ~UnixStat.DIR_FLAG;
}
}
- if ( attributes == null )
- {
- attributes = new SimpleResourceAttributes( null, null, null, null, mode );
+ if (attributes == null) {
+ attributes = new SimpleResourceAttributes(null, null, null, null, mode);
}
return attributes;
}
- public synchronized void setAttributes( PlexusIoResourceAttributes attributes )
- {
+ public synchronized void setAttributes(PlexusIoResourceAttributes attributes) {
this.attributes = attributes;
}
@Override
- public URL getURL()
- throws IOException
- {
+ public URL getURL() throws IOException {
return null;
}
@Nonnull
@Override
- public InputStream getContents()
- throws IOException
- {
- final InputStream inputStream = zipFile.getInputStream( entry );
- return new ClosingInputStream( streamTransformer.transform( this, inputStream ), inputStream );
+ public InputStream getContents() throws IOException {
+ final InputStream inputStream = zipFile.getInputStream(entry);
+ return new ClosingInputStream(streamTransformer.transform(this, inputStream), inputStream);
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zip/ZipSymlinkResource.java b/src/main/java/org/codehaus/plexus/archiver/zip/ZipSymlinkResource.java
index 1ea6f7c36..9338cba6a 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zip/ZipSymlinkResource.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zip/ZipSymlinkResource.java
@@ -16,6 +16,7 @@
package org.codehaus.plexus.archiver.zip;
import java.io.IOException;
+
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.codehaus.plexus.components.io.functions.InputStreamTransformer;
@@ -24,37 +25,26 @@
/**
* A {@link ZipResource} that represents symbolic link.
*/
-public class ZipSymlinkResource
- extends ZipResource
- implements SymlinkDestinationSupplier
-{
+public class ZipSymlinkResource extends ZipResource implements SymlinkDestinationSupplier {
private final String symlinkDestination;
- public ZipSymlinkResource( ZipFile zipFile, ZipArchiveEntry entry, InputStreamTransformer streamTransformer )
- {
- super( zipFile, entry, streamTransformer );
- try
- {
- symlinkDestination = zipFile.getUnixSymlink( entry );
- }
- catch ( IOException e )
- {
- throw new RuntimeException( e );
+ public ZipSymlinkResource(ZipFile zipFile, ZipArchiveEntry entry, InputStreamTransformer streamTransformer) {
+ super(zipFile, entry, streamTransformer);
+ try {
+ symlinkDestination = zipFile.getUnixSymlink(entry);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
}
@Override
- public String getSymlinkDestination()
- throws IOException
- {
+ public String getSymlinkDestination() throws IOException {
return symlinkDestination;
}
@Override
- public boolean isSymbolicLink()
- {
+ public boolean isSymbolicLink() {
return true;
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zip/ZipUnArchiver.java b/src/main/java/org/codehaus/plexus/archiver/zip/ZipUnArchiver.java
index 4041b6fdf..49af6717c 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zip/ZipUnArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zip/ZipUnArchiver.java
@@ -23,18 +23,12 @@
/**
* @author Emmanuel Venisse
*/
-@Named( "zip" )
-public class ZipUnArchiver
- extends AbstractZipUnArchiver
-{
+@Named("zip")
+public class ZipUnArchiver extends AbstractZipUnArchiver {
- public ZipUnArchiver()
- {
- }
+ public ZipUnArchiver() {}
- public ZipUnArchiver( File sourceFile )
- {
- super( sourceFile );
+ public ZipUnArchiver(File sourceFile) {
+ super(sourceFile);
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zstd/PlexusIoZstdResourceCollection.java b/src/main/java/org/codehaus/plexus/archiver/zstd/PlexusIoZstdResourceCollection.java
index 84a9d0e62..d0ce8ec31 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zstd/PlexusIoZstdResourceCollection.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zstd/PlexusIoZstdResourceCollection.java
@@ -31,26 +31,21 @@
* Implementation of {@link org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection} for
* zstd compressed files.
*/
-@Named( "zst" )
-public class PlexusIoZstdResourceCollection extends PlexusIoCompressedFileResourceCollection
-{
+@Named("zst")
+public class PlexusIoZstdResourceCollection extends PlexusIoCompressedFileResourceCollection {
@Override
- protected PlexusIoResourceAttributes getAttributes( File file ) throws IOException
- {
- return new FileAttributes( file, new HashMap(), new HashMap() );
+ protected PlexusIoResourceAttributes getAttributes(File file) throws IOException {
+ return new FileAttributes(file, new HashMap(), new HashMap());
}
@Override
- protected String getDefaultExtension()
- {
+ protected String getDefaultExtension() {
return ".zst";
}
@Override
- protected InputStream getInputStream( File file ) throws IOException
- {
- return ZstdUnArchiver.getZstdInputStream( Streams.fileInputStream( file ) );
+ protected InputStream getInputStream(File file) throws IOException {
+ return ZstdUnArchiver.getZstdInputStream(Streams.fileInputStream(file));
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zstd/ZstdArchiver.java b/src/main/java/org/codehaus/plexus/archiver/zstd/ZstdArchiver.java
index f2484d746..549740a45 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zstd/ZstdArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zstd/ZstdArchiver.java
@@ -18,6 +18,7 @@
import javax.inject.Named;
import java.io.IOException;
+
import org.codehaus.plexus.archiver.AbstractArchiver;
import org.codehaus.plexus.archiver.ArchiveEntry;
import org.codehaus.plexus.archiver.ArchiverException;
@@ -27,64 +28,51 @@
/**
* Zstd archiver.
*/
-@Named( "zst" )
-public class ZstdArchiver extends AbstractArchiver
-{
+@Named("zst")
+public class ZstdArchiver extends AbstractArchiver {
private final ZstdCompressor compressor = new ZstdCompressor();
- public ZstdArchiver()
- {
- }
+ public ZstdArchiver() {}
/**
* Set compression level
*/
- public void setLevel( Integer level )
- throws ArchiverException
- {
- compressor.setLevel( level );
+ public void setLevel(Integer level) throws ArchiverException {
+ compressor.setLevel(level);
}
@Override
- protected void execute() throws ArchiverException, IOException
- {
- if ( !checkForced() )
- {
+ protected void execute() throws ArchiverException, IOException {
+ if (!checkForced()) {
return;
}
ResourceIterator iter = getResources();
- if ( !iter.hasNext() )
- {
- throw new EmptyArchiveException( "archive cannot be empty" );
+ if (!iter.hasNext()) {
+ throw new EmptyArchiveException("archive cannot be empty");
}
ArchiveEntry entry = iter.next();
- if ( iter.hasNext() )
- {
- throw new ArchiverException( "There is more than one file in input." );
+ if (iter.hasNext()) {
+ throw new ArchiverException("There is more than one file in input.");
}
- compressor.setSource( entry.getResource() );
- compressor.setDestFile( getDestFile() );
+ compressor.setSource(entry.getResource());
+ compressor.setDestFile(getDestFile());
compressor.compress();
}
@Override
- public boolean isSupportingForced()
- {
+ public boolean isSupportingForced() {
return true;
}
@Override
- protected void close() throws IOException
- {
+ protected void close() throws IOException {
compressor.close();
}
@Override
- protected String getArchiveType()
- {
+ protected String getArchiveType() {
return "zstd";
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zstd/ZstdCompressor.java b/src/main/java/org/codehaus/plexus/archiver/zstd/ZstdCompressor.java
index 4dc06d2ea..c41557ab2 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zstd/ZstdCompressor.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zstd/ZstdCompressor.java
@@ -15,72 +15,55 @@
*/
package org.codehaus.plexus.archiver.zstd;
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+
import org.apache.commons.compress.compressors.zstandard.ZstdCompressorOutputStream;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.util.Compressor;
-import java.io.BufferedOutputStream;
-import java.io.IOException;
-
import static org.codehaus.plexus.archiver.util.Streams.bufferedOutputStream;
import static org.codehaus.plexus.archiver.util.Streams.fileOutputStream;
/**
* Zstd compression
*/
-public class ZstdCompressor extends Compressor
-{
+public class ZstdCompressor extends Compressor {
private Integer level;
private ZstdCompressorOutputStream zstdOut;
- public ZstdCompressor()
- {
- }
+ public ZstdCompressor() {}
- public void setLevel( Integer level )
- {
+ public void setLevel(Integer level) {
this.level = level;
}
@Override
- public void compress() throws ArchiverException
- {
- try
- {
- BufferedOutputStream outStream = bufferedOutputStream( fileOutputStream( getDestFile() ) );
- if (level == null)
- {
- zstdOut = new ZstdCompressorOutputStream( outStream );
- }
- else
- {
- zstdOut = new ZstdCompressorOutputStream( outStream, level );
+ public void compress() throws ArchiverException {
+ try {
+ BufferedOutputStream outStream = bufferedOutputStream(fileOutputStream(getDestFile()));
+ if (level == null) {
+ zstdOut = new ZstdCompressorOutputStream(outStream);
+ } else {
+ zstdOut = new ZstdCompressorOutputStream(outStream, level);
}
- compress( getSource(), zstdOut);
- }
- catch ( IOException ioe )
- {
- throw new ArchiverException( "Problem creating zstd " + ioe.getMessage(), ioe );
+ compress(getSource(), zstdOut);
+ } catch (IOException ioe) {
+ throw new ArchiverException("Problem creating zstd " + ioe.getMessage(), ioe);
}
}
@Override
- public void close()
- {
- try
- {
- if ( this.zstdOut != null )
- {
+ public void close() {
+ try {
+ if (this.zstdOut != null) {
this.zstdOut.close();
zstdOut = null;
}
- }
- catch ( final IOException e )
- {
- throw new ArchiverException( "Failure closing target.", e );
+ } catch (final IOException e) {
+ throw new ArchiverException("Failure closing target.", e);
}
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/archiver/zstd/ZstdUnArchiver.java b/src/main/java/org/codehaus/plexus/archiver/zstd/ZstdUnArchiver.java
index 7dcf6c1f5..2a6d4cd96 100644
--- a/src/main/java/org/codehaus/plexus/archiver/zstd/ZstdUnArchiver.java
+++ b/src/main/java/org/codehaus/plexus/archiver/zstd/ZstdUnArchiver.java
@@ -15,16 +15,17 @@
*/
package org.codehaus.plexus.archiver.zstd;
-import org.apache.commons.compress.compressors.zstandard.ZstdCompressorInputStream;
-import org.codehaus.plexus.archiver.AbstractUnArchiver;
-import org.codehaus.plexus.archiver.ArchiverException;
-
import javax.annotation.Nonnull;
import javax.inject.Named;
+
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import org.apache.commons.compress.compressors.zstandard.ZstdCompressorInputStream;
+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;
@@ -34,53 +35,41 @@
/**
* Unarchiver for zstd-compressed files.
*/
-@Named( "zst" )
-public class ZstdUnArchiver extends AbstractUnArchiver
-{
+@Named("zst")
+public class ZstdUnArchiver extends AbstractUnArchiver {
private static final String OPERATION_ZSTD = "zstd";
- public ZstdUnArchiver()
- {
- }
+ public ZstdUnArchiver() {}
- public ZstdUnArchiver( File source )
- {
- super( source );
+ public ZstdUnArchiver(File source) {
+ super(source);
}
@Override
- protected void execute() throws ArchiverException
- {
- if ( getSourceFile().lastModified() > getDestFile().lastModified() )
- {
- getLogger().info( "Expanding " + getSourceFile().getAbsolutePath() + " to "
- + getDestFile().getAbsolutePath() );
-
- copyFully( getZstdInputStream( bufferedInputStream( fileInputStream( getSourceFile(), OPERATION_ZSTD) ) ),
- bufferedOutputStream( fileOutputStream( getDestFile(), OPERATION_ZSTD) ), OPERATION_ZSTD);
+ protected void execute() throws ArchiverException {
+ if (getSourceFile().lastModified() > getDestFile().lastModified()) {
+ getLogger()
+ .info("Expanding " + getSourceFile().getAbsolutePath() + " to "
+ + getDestFile().getAbsolutePath());
+ copyFully(
+ getZstdInputStream(bufferedInputStream(fileInputStream(getSourceFile(), OPERATION_ZSTD))),
+ bufferedOutputStream(fileOutputStream(getDestFile(), OPERATION_ZSTD)),
+ OPERATION_ZSTD);
}
}
- public static @Nonnull
- ZstdCompressorInputStream getZstdInputStream( InputStream in )
- throws ArchiverException
- {
- try
- {
- return new ZstdCompressorInputStream( in );
- }
- catch ( IOException ioe )
- {
- throw new ArchiverException( "Trouble creating Zstd compressor, invalid file ?", ioe );
+ public static @Nonnull ZstdCompressorInputStream getZstdInputStream(InputStream in) throws ArchiverException {
+ try {
+ return new ZstdCompressorInputStream(in);
+ } catch (IOException ioe) {
+ throw new ArchiverException("Trouble creating Zstd compressor, invalid file ?", ioe);
}
}
@Override
- protected void execute( String path, File outputDirectory ) throws ArchiverException
- {
- throw new UnsupportedOperationException( "Targeted execution not supported in zstd format" );
+ protected void execute(String path, File outputDirectory) throws ArchiverException {
+ throw new UnsupportedOperationException("Targeted execution not supported in zstd format");
}
-
}
diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoZipFileResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoZipFileResourceCollection.java
index 3b1e017ad..6825717e0 100644
--- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoZipFileResourceCollection.java
+++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoZipFileResourceCollection.java
@@ -20,8 +20,4 @@
* Make sure maven-assembly-plugin IT's work when you do :)
*/
public class PlexusIoZipFileResourceCollection
- extends org.codehaus.plexus.archiver.zip.PlexusIoZipFileResourceCollection
-
-{
-
-}
+ extends org.codehaus.plexus.archiver.zip.PlexusIoZipFileResourceCollection {}
diff --git a/src/site/apt/index.apt b/src/site/apt/index.apt
index e49b1cd03..071b5fabe 100644
--- a/src/site/apt/index.apt
+++ b/src/site/apt/index.apt
@@ -31,11 +31,12 @@ Plexus Archiver
| | ({{{./apidocs/index.html?org/codehaus/plexus/archiver/tar/TGZArchiver.html}<<>>}}),
| | {{{./apidocs/index.html?org/codehaus/plexus/archiver/tar/TarSnappyArchiver.html}<<>>}},
| | {{{./apidocs/index.html?org/codehaus/plexus/archiver/tar/TarZstdArchiver.html}<<>>}}
+| | ({{{./apidocs/index.html?org/codehaus/plexus/archiver/tar/TZstdArchiver.html}<<>>}}),
| | {{{./apidocs/index.html?org/codehaus/plexus/archiver/tar/TarXZArchiver.html}<<>>}}
| | ({{{./apidocs/index.html?org/codehaus/plexus/archiver/tar/TXZArchiver.html}<<>>}}),
| | {{{./apidocs/index.html?org/codehaus/plexus/archiver/war/WarArchiver.html}<<>>}},
| | {{{./apidocs/index.html?org/codehaus/plexus/archiver/xz/XZArchiver.html}<<>>}},
-| | {{{./apidocs/index.html?org/codehaus/plexus/archiver/zip/ZipArchiver.html}<<>>}}.
+| | {{{./apidocs/index.html?org/codehaus/plexus/archiver/zip/ZipArchiver.html}<<>>}},
| | {{{./apidocs/index.html?org/codehaus/plexus/archiver/zstd/ZstdArchiver.html}<<>>}}
| |
*------------------+-----------------+
@@ -50,6 +51,7 @@ Plexus Archiver
| | ({{{./apidocs/index.html?org/codehaus/plexus/archiver/tar/TGZUnArchiver.html}<<>>}}),
| | {{{./apidocs/index.html?org/codehaus/plexus/archiver/tar/TarSnappyUnArchiver.html}<<>>}}
| | {{{./apidocs/index.html?org/codehaus/plexus/archiver/tar/TarZstdUnArchiver.html}<<>>}}
+| | ({{{./apidocs/index.html?org/codehaus/plexus/archiver/tar/TZstdUnArchiver.html}<<>>}}),
| | {{{./apidocs/index.html?org/codehaus/plexus/archiver/tar/TarXZUnArchiver.html}<<>>}}
| | ({{{./apidocs/index.html?org/codehaus/plexus/archiver/tar/TXZUnArchiver.html}<<>>}}),
| | {{{./apidocs/index.html?org/codehaus/plexus/archiver/xz/XZUnArchiver.html}<<>>}},
diff --git a/src/site/site.xml b/src/site/site.xml
index adc4a6323..97d7f69c6 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -6,10 +6,6 @@
-
-
-
-