Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #31 - Only jar archiveType is valid #33

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
language: java
# Enable container-based infrastructure
# see http://docs.travis-ci.com/user/workers/container-based-infrastructure/
sudo: false
jdk:
- openjdk7
- oraclejdk8
- openjdk8
- openjdk11
- openjdk13
cache:
directories:
- $HOME/.m2/repository
# Just skip installation step
# cause everything is done
# in script step.
install: yes
env:
- MAVEN_VERSION=3.3.1
- MAVEN_VERSION=3.3.9
- MAVEN_VERSION=3.5.0
- MAVEN_VERSION=3.5.3
- MAVEN_VERSION=3.5.4
- MAVEN_VERSION=3.6.0
- MAVEN_VERSION=3.6.1
- MAVEN_VERSION=3.6.2

install:
- "mvn -N io.takari:maven:wrapper -Dmaven=${MAVEN_VERSION}"

script:
- mvn -Prun-its clean verify
- "./mvnw --show-version --errors --batch-mode -Prun-its clean verify"
22 changes: 12 additions & 10 deletions src/it/setup/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>8</maven.compiler.source>
</properties>


Expand All @@ -24,7 +26,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -47,42 +49,42 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<version>3.2.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -92,7 +94,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<version>3.1.0</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import java.io.File;
import java.io.IOException;

import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
Expand All @@ -13,10 +10,9 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.archiver.jar.ManifestException;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
import org.codehaus.plexus.archiver.tar.TarArchiver;
import org.codehaus.plexus.archiver.util.DefaultFileSet;

/**
Expand All @@ -28,22 +24,18 @@
public class ConfigurationMojo
extends AbstractMultiEnvMojo
{

/**
* The JAR archiver needed for archiving the environments.
*/
@Component( role = Archiver.class, hint = "jar" )
private JarArchiver jarArchiver;

private static final String EXTENSION_TAR = "tar";

@Component
private ArchiverManager manager;

/**
* The kind of archive we should produce {@code zip}, {code jar} etc.
* The kind of archive we should produce {@code zip}, {@code jar} etc.
*/
@Parameter( defaultValue = "jar" )
private String archiveType;

@Override
public void execute()
throws MojoExecutionException, MojoFailureException
{
Expand Down Expand Up @@ -96,21 +88,27 @@ public void execute()
private File createArchiveFile( File targetDirectory, String directory, String archiveExt )
throws NoSuchArchiverException, IOException, MojoExecutionException
{
final MavenArchiver mavenArchiver = new MavenArchiver();

mavenArchiver.setArchiver( jarArchiver );

jarArchiver.addFileSet( new DefaultFileSet( targetDirectory ) );
// jarArchiver.setDuplicateBehavior( duplicate );

File resultArchive = getArchiveFile( getOutputDirectory(), getFinalName(), directory, archiveExt );

mavenArchiver.setOutputFile( resultArchive );

Archiver archiver;
if ( archiveExt.startsWith(EXTENSION_TAR) )
{
archiver = createTarArchiver( archiveExt );
}
else
{
archiver = manager.getArchiver( resultArchive );
}

archiver.addFileSet( new DefaultFileSet( targetDirectory ) );

archiver.setDestFile(resultArchive);

try
{
mavenArchiver.createArchive( getMavenSession(), getMavenProject(), getArchive() );
archiver.createArchive();
}
catch ( ArchiverException | ManifestException | DependencyResolutionRequiredException e )
catch ( ArchiverException e )
{
getLog().error( e.getMessage(), e );
throw new MojoExecutionException( e.getMessage(), e );
Expand All @@ -119,5 +117,42 @@ private File createArchiveFile( File targetDirectory, String directory, String a
return resultArchive;

}

/**
* Create an archiver for tar(.*) formats
* @param archiveExt extension of the archive
* @return the appropriate Archiver
* @throws NoSuchArchiverException
*/
private Archiver createTarArchiver( String archiveExt )
throws NoSuchArchiverException
{
TarArchiver tarArchiver = (TarArchiver) manager.getArchiver(EXTENSION_TAR);
int index = archiveExt.indexOf( '.' );
if ( index >= 0 )
{
TarArchiver.TarCompressionMethod compressionMethod;

String compression = archiveExt.substring( index + 1 );
switch (compression) {
case "gz":
compressionMethod = TarArchiver.TarCompressionMethod.gzip;
break;
case "bz2":
compressionMethod = TarArchiver.TarCompressionMethod.bzip2;
break;
default:
compressionMethod = TarArchiver.TarCompressionMethod.valueOf(compression);
break;
}

if (compressionMethod == null) {
throw new IllegalArgumentException( "Unknown compression format: " + compression );
}

tarArchiver.setCompression( compressionMethod );
}

return tarArchiver;
}
}