Skip to content

Commit

Permalink
Add Archiver aliases for tar.*
Browse files Browse the repository at this point in the history
We have UnArchiver for tar.* so we can also have corresponding Archiver
  • Loading branch information
slawekjaranowski committed May 1, 2023
1 parent 54b75e9 commit 1d7ff06
Show file tree
Hide file tree
Showing 13 changed files with 561 additions and 147 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@
<version>${junitVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junitVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.codehaus.plexus.archiver.manager;

import java.io.File;
import java.util.Collection;

import javax.annotation.Nonnull;
import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.UnArchiver;
Expand All @@ -35,6 +37,9 @@ Archiver getArchiver( @Nonnull String archiverName )
Archiver getArchiver( @Nonnull File file )
throws NoSuchArchiverException;

@Nonnull
Collection<String> getAvailableArchivers();

@Nonnull
UnArchiver getUnArchiver( @Nonnull String unArchiverName )
throws NoSuchArchiverException;
Expand All @@ -43,6 +48,9 @@ UnArchiver getUnArchiver( @Nonnull String unArchiverName )
UnArchiver getUnArchiver( @Nonnull File file )
throws NoSuchArchiverException;

@Nonnull
Collection<String> getAvailableUnArchivers();

@Nonnull
PlexusIoResourceCollection getResourceCollection( @Nonnull File file )
throws NoSuchArchiverException;
Expand All @@ -51,4 +59,6 @@ PlexusIoResourceCollection getResourceCollection( @Nonnull File file )
PlexusIoResourceCollection getResourceCollection( String unArchiverName )
throws NoSuchArchiverException;

@Nonnull
Collection<String> getAvailableResourceCollections();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.codehaus.plexus.archiver.manager;

import java.io.File;
import java.util.Collection;
import java.util.Locale;
import java.util.Map;

Expand All @@ -29,7 +30,6 @@
import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.UnArchiver;
import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -101,49 +101,67 @@ PlexusIoResourceCollection getResourceCollection( String resourceCollectionName
}

private static @Nonnull
String getFileExtention( @Nonnull File file )
String getFileExtension( @Nonnull File file )
{
String path = file.getAbsolutePath();

String archiveExt = FileUtils.getExtension( path ).toLowerCase( Locale.ENGLISH );
String fileName = file.getName().toLowerCase( Locale.ROOT );
String[] tokens = StringUtils.split( fileName, "." );

if ( "gz".equals( archiveExt )
|| "bz2".equals( archiveExt )
|| "xz".equals( archiveExt )
|| "zst".equals( archiveExt )
|| "snappy".equals( archiveExt ) )
{
String[] tokens = StringUtils.split( path, "." );
String archiveExt = "";

if ( tokens.length > 2 && "tar".equals( tokens[tokens.length - 2].toLowerCase( Locale.ENGLISH ) ) )
{
archiveExt = "tar." + archiveExt;
}
if ( tokens.length == 2 ) {
archiveExt = tokens[1];
}
else if ( tokens.length > 2 && "tar".equals( tokens[tokens.length - 2] ) )
{
archiveExt = "tar." + tokens[tokens.length - 1];
}
else if ( tokens.length > 2 ) {
archiveExt = tokens[tokens.length-1];
}

return archiveExt;

}

@Override
@Nonnull public Archiver getArchiver( @Nonnull File file )
throws NoSuchArchiverException
{
return getArchiver( getFileExtention( file ) );
return getArchiver( getFileExtension( file ) );
}

@Override
public Collection<String> getAvailableArchivers()
{
return archivers.keySet();
}

@Override
@Nonnull public UnArchiver getUnArchiver( @Nonnull File file )
throws NoSuchArchiverException
{
return getUnArchiver( getFileExtention( file ) );
return getUnArchiver( getFileExtension( file ) );
}

@Nonnull
@Override
public Collection<String> getAvailableUnArchivers()
{
return unArchivers.keySet();
}

@Override
@Nonnull public PlexusIoResourceCollection getResourceCollection( @Nonnull File file )
throws NoSuchArchiverException
{
return getResourceCollection( getFileExtention( file ) );
return getResourceCollection( getFileExtension( file ) );
}

@Nonnull
@Override
public Collection<String> getAvailableResourceCollections()
{
return plexusIoResourceCollections.keySet();
}

}
30 changes: 30 additions & 0 deletions src/main/java/org/codehaus/plexus/archiver/tar/TBZ2Archiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.plexus.archiver.tar;

import javax.inject.Named;

/**
* Alias for {@link TarBZip2Archiver}.
*
* @since 4.7.0
*/
@Named( "tbz2" )
public class TBZ2Archiver
extends TarBZip2Archiver
{
}
30 changes: 30 additions & 0 deletions src/main/java/org/codehaus/plexus/archiver/tar/TGZArchiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.plexus.archiver.tar;

import javax.inject.Named;

/**
* Alias for {@link TarGZipArchiver}.
*
* @since 4.7.0
*/
@Named( "tgz" )
public class TGZArchiver
extends TarGZipArchiver
{
}
28 changes: 28 additions & 0 deletions src/main/java/org/codehaus/plexus/archiver/tar/TXZArchiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2016 Codehaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.plexus.archiver.tar;

import javax.inject.Named;

/**
* Alias for {@link TarXZArchiver}.
*
* @since 4.7.0
*/
@Named( "txz" )
public class TXZArchiver extends TarXZArchiver
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.plexus.archiver.tar;

import javax.inject.Named;

/**
* Create tar with bzip2 compression.
*
* @since 4.7.0
*/
@Named( "tar.bz2" )
public class TarBZip2Archiver
extends TarArchiver
{

public TarBZip2Archiver()
{
this.setupCompressionMethod();
}

private void setupCompressionMethod()
{
this.setCompression( TarCompressionMethod.bzip2 );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.plexus.archiver.tar;

import javax.inject.Named;

/**
* Create tar with gzip compression.
*
* @since 4.7.0
*/
@Named( "tar.gz" )
public class TarGZipArchiver
extends TarArchiver
{

public TarGZipArchiver()
{
this.setupCompressionMethod();
}

private void setupCompressionMethod()
{
this.setCompression( TarCompressionMethod.gzip );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.plexus.archiver.tar;

import javax.inject.Named;

/**
* Create tar with snappy compression.
*
* @since 4.7.0
*/
@Named( "tar.snappy" )
public class TarSnappyArchiver
extends TarArchiver
{

public TarSnappyArchiver()
{
this.setupCompressionMethod();
}

private void setupCompressionMethod()
{
this.setCompression( TarCompressionMethod.snappy );
}

}
Loading

0 comments on commit 1d7ff06

Please sign in to comment.