Skip to content

Commit 1d7ff06

Browse files
Add Archiver aliases for tar.*
We have UnArchiver for tar.* so we can also have corresponding Archiver
1 parent 54b75e9 commit 1d7ff06

File tree

13 files changed

+561
-147
lines changed

13 files changed

+561
-147
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@
116116
<version>${junitVersion}</version>
117117
<scope>test</scope>
118118
</dependency>
119+
<dependency>
120+
<groupId>org.junit.jupiter</groupId>
121+
<artifactId>junit-jupiter-params</artifactId>
122+
<version>${junitVersion}</version>
123+
<scope>test</scope>
124+
</dependency>
119125
<dependency>
120126
<groupId>org.junit.jupiter</groupId>
121127
<artifactId>junit-jupiter-engine</artifactId>

src/main/java/org/codehaus/plexus/archiver/manager/ArchiverManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package org.codehaus.plexus.archiver.manager;
1818

1919
import java.io.File;
20+
import java.util.Collection;
21+
2022
import javax.annotation.Nonnull;
2123
import org.codehaus.plexus.archiver.Archiver;
2224
import org.codehaus.plexus.archiver.UnArchiver;
@@ -35,6 +37,9 @@ Archiver getArchiver( @Nonnull String archiverName )
3537
Archiver getArchiver( @Nonnull File file )
3638
throws NoSuchArchiverException;
3739

40+
@Nonnull
41+
Collection<String> getAvailableArchivers();
42+
3843
@Nonnull
3944
UnArchiver getUnArchiver( @Nonnull String unArchiverName )
4045
throws NoSuchArchiverException;
@@ -43,6 +48,9 @@ UnArchiver getUnArchiver( @Nonnull String unArchiverName )
4348
UnArchiver getUnArchiver( @Nonnull File file )
4449
throws NoSuchArchiverException;
4550

51+
@Nonnull
52+
Collection<String> getAvailableUnArchivers();
53+
4654
@Nonnull
4755
PlexusIoResourceCollection getResourceCollection( @Nonnull File file )
4856
throws NoSuchArchiverException;
@@ -51,4 +59,6 @@ PlexusIoResourceCollection getResourceCollection( @Nonnull File file )
5159
PlexusIoResourceCollection getResourceCollection( String unArchiverName )
5260
throws NoSuchArchiverException;
5361

62+
@Nonnull
63+
Collection<String> getAvailableResourceCollections();
5464
}

src/main/java/org/codehaus/plexus/archiver/manager/DefaultArchiverManager.java

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.codehaus.plexus.archiver.manager;
1818

1919
import java.io.File;
20+
import java.util.Collection;
2021
import java.util.Locale;
2122
import java.util.Map;
2223

@@ -29,7 +30,6 @@
2930
import org.codehaus.plexus.archiver.Archiver;
3031
import org.codehaus.plexus.archiver.UnArchiver;
3132
import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection;
32-
import org.codehaus.plexus.util.FileUtils;
3333
import org.codehaus.plexus.util.StringUtils;
3434

3535
import static java.util.Objects.requireNonNull;
@@ -101,49 +101,67 @@ PlexusIoResourceCollection getResourceCollection( String resourceCollectionName
101101
}
102102

103103
private static @Nonnull
104-
String getFileExtention( @Nonnull File file )
104+
String getFileExtension( @Nonnull File file )
105105
{
106-
String path = file.getAbsolutePath();
107106

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

110-
if ( "gz".equals( archiveExt )
111-
|| "bz2".equals( archiveExt )
112-
|| "xz".equals( archiveExt )
113-
|| "zst".equals( archiveExt )
114-
|| "snappy".equals( archiveExt ) )
115-
{
116-
String[] tokens = StringUtils.split( path, "." );
110+
String archiveExt = "";
117111

118-
if ( tokens.length > 2 && "tar".equals( tokens[tokens.length - 2].toLowerCase( Locale.ENGLISH ) ) )
119-
{
120-
archiveExt = "tar." + archiveExt;
121-
}
112+
if ( tokens.length == 2 ) {
113+
archiveExt = tokens[1];
114+
}
115+
else if ( tokens.length > 2 && "tar".equals( tokens[tokens.length - 2] ) )
116+
{
117+
archiveExt = "tar." + tokens[tokens.length - 1];
118+
}
119+
else if ( tokens.length > 2 ) {
120+
archiveExt = tokens[tokens.length-1];
122121
}
123122

124123
return archiveExt;
125-
126124
}
127125

128126
@Override
129127
@Nonnull public Archiver getArchiver( @Nonnull File file )
130128
throws NoSuchArchiverException
131129
{
132-
return getArchiver( getFileExtention( file ) );
130+
return getArchiver( getFileExtension( file ) );
131+
}
132+
133+
@Override
134+
public Collection<String> getAvailableArchivers()
135+
{
136+
return archivers.keySet();
133137
}
134138

135139
@Override
136140
@Nonnull public UnArchiver getUnArchiver( @Nonnull File file )
137141
throws NoSuchArchiverException
138142
{
139-
return getUnArchiver( getFileExtention( file ) );
143+
return getUnArchiver( getFileExtension( file ) );
144+
}
145+
146+
@Nonnull
147+
@Override
148+
public Collection<String> getAvailableUnArchivers()
149+
{
150+
return unArchivers.keySet();
140151
}
141152

142153
@Override
143154
@Nonnull public PlexusIoResourceCollection getResourceCollection( @Nonnull File file )
144155
throws NoSuchArchiverException
145156
{
146-
return getResourceCollection( getFileExtention( file ) );
157+
return getResourceCollection( getFileExtension( file ) );
158+
}
159+
160+
@Nonnull
161+
@Override
162+
public Collection<String> getAvailableResourceCollections()
163+
{
164+
return plexusIoResourceCollections.keySet();
147165
}
148166

149167
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
*
3+
* Copyright 2004 The Apache Software Foundation
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.codehaus.plexus.archiver.tar;
18+
19+
import javax.inject.Named;
20+
21+
/**
22+
* Alias for {@link TarBZip2Archiver}.
23+
*
24+
* @since 4.7.0
25+
*/
26+
@Named( "tbz2" )
27+
public class TBZ2Archiver
28+
extends TarBZip2Archiver
29+
{
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
*
3+
* Copyright 2004 The Apache Software Foundation
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.codehaus.plexus.archiver.tar;
18+
19+
import javax.inject.Named;
20+
21+
/**
22+
* Alias for {@link TarGZipArchiver}.
23+
*
24+
* @since 4.7.0
25+
*/
26+
@Named( "tgz" )
27+
public class TGZArchiver
28+
extends TarGZipArchiver
29+
{
30+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2016 Codehaus.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.codehaus.plexus.archiver.tar;
17+
18+
import javax.inject.Named;
19+
20+
/**
21+
* Alias for {@link TarXZArchiver}.
22+
*
23+
* @since 4.7.0
24+
*/
25+
@Named( "txz" )
26+
public class TXZArchiver extends TarXZArchiver
27+
{
28+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
*
3+
* Copyright 2004 The Apache Software Foundation
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.codehaus.plexus.archiver.tar;
18+
19+
import javax.inject.Named;
20+
21+
/**
22+
* Create tar with bzip2 compression.
23+
*
24+
* @since 4.7.0
25+
*/
26+
@Named( "tar.bz2" )
27+
public class TarBZip2Archiver
28+
extends TarArchiver
29+
{
30+
31+
public TarBZip2Archiver()
32+
{
33+
this.setupCompressionMethod();
34+
}
35+
36+
private void setupCompressionMethod()
37+
{
38+
this.setCompression( TarCompressionMethod.bzip2 );
39+
}
40+
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
*
3+
* Copyright 2004 The Apache Software Foundation
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.codehaus.plexus.archiver.tar;
18+
19+
import javax.inject.Named;
20+
21+
/**
22+
* Create tar with gzip compression.
23+
*
24+
* @since 4.7.0
25+
*/
26+
@Named( "tar.gz" )
27+
public class TarGZipArchiver
28+
extends TarArchiver
29+
{
30+
31+
public TarGZipArchiver()
32+
{
33+
this.setupCompressionMethod();
34+
}
35+
36+
private void setupCompressionMethod()
37+
{
38+
this.setCompression( TarCompressionMethod.gzip );
39+
}
40+
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
*
3+
* Copyright 2004 The Apache Software Foundation
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.codehaus.plexus.archiver.tar;
18+
19+
import javax.inject.Named;
20+
21+
/**
22+
* Create tar with snappy compression.
23+
*
24+
* @since 4.7.0
25+
*/
26+
@Named( "tar.snappy" )
27+
public class TarSnappyArchiver
28+
extends TarArchiver
29+
{
30+
31+
public TarSnappyArchiver()
32+
{
33+
this.setupCompressionMethod();
34+
}
35+
36+
private void setupCompressionMethod()
37+
{
38+
this.setCompression( TarCompressionMethod.snappy );
39+
}
40+
41+
}

0 commit comments

Comments
 (0)