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

[MEAR-194] Use ear archiver instead of jar archiver #9

Closed
wants to merge 8 commits into from
38 changes: 33 additions & 5 deletions src/main/java/org/apache/maven/plugins/ear/EarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.UnArchiver;
import org.codehaus.plexus.archiver.ear.EarArchiver;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.archiver.jar.Manifest;
import org.codehaus.plexus.archiver.jar.Manifest.Attribute;
Expand Down Expand Up @@ -207,6 +208,12 @@ public class EarMojo
@Parameter( defaultValue = "false" )
private boolean skinnyWars;

/**
* The Ear archiver.
*/
@Component( role = Archiver.class, hint = "ear" )
private EarArchiver earArchiver;

/**
* The Jar archiver.
*/
Expand Down Expand Up @@ -382,9 +389,19 @@ public FileVisitResult visitFile( Path file, BasicFileAttributes attrs )
{
File earFile = getEarFile( outputDirectory, finalName, classifier );
final MavenArchiver archiver = new EarMavenArchiver( getModules() );
final JarArchiver theJarArchiver = getJarArchiver();
getLog().debug( "Jar archiver implementation [" + theJarArchiver.getClass().getName() + "]" );
archiver.setArchiver( theJarArchiver );
JarArchiver theArchiver;
if ( ddFile.exists() )
{
final EarArchiver earArchiver = getEarArchiver();
earArchiver.setAppxml( ddFile );
theArchiver = earArchiver;
}
else
{
theArchiver = getJarArchiver();
}
getLog().debug( "Archiver implementation [" + theArchiver.getClass().getName() + "]" );
archiver.setArchiver( theArchiver );
archiver.setOutputFile( earFile );

archiver.setCreatedBy( "Maven EAR Plugin", "org.apache.maven.plugins", "maven-ear-plugin" );
Expand All @@ -397,7 +414,6 @@ public FileVisitResult visitFile( Path file, BasicFileAttributes attrs )

archiver.getArchiver().addDirectory( getWorkDirectory(), getPackagingIncludes(), getPackagingExcludes() );
archiver.createArchive( session, getProject(), archive );

if ( classifier != null )
{
projectHelper.attachArtifact( getProject(), "ear", classifier, earFile );
Expand Down Expand Up @@ -686,12 +702,24 @@ public String getMappedFileName( String pName )
}

/**
* Returns the {@link JarArchiver} implementation used to package the EAR file.
* Returns the {@link EarArchiver} implementation used to package the EAR file.
*
* By default the archiver is obtained from the Plexus container.
*
* @return the archiver
*/
protected EarArchiver getEarArchiver()
santik marked this conversation as resolved.
Show resolved Hide resolved
{
return earArchiver;
}

/**
* Returns the {@link JarArchiver} implementation used to package the EAR file.
*
* By default the archiver is obtained from the Plexus container.
*
* @return the archiver
*/
protected JarArchiver getJarArchiver()
{
return jarArchiver;
Expand Down