super.execute();
zipArchiver.setUseJvmChmod( useJvmChmod );
zipUnArchiver.setUseJvmChmod( useJvmChmod );
final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion( version );
// Initializes unpack types
List<String> unpackTypesList = new ArrayList<String>();
if ( unpackTypes != null )
{
unpackTypesList = Arrays.asList( unpackTypes.split( "," ) );
for ( String type : unpackTypesList )
{
if ( !EarModuleFactory.STANDARD_ARTIFACT_TYPE.contains( type ) )
{
throw new MojoExecutionException( "Invalid type [" + type + "] supported types are "
+ EarModuleFactory.STANDARD_ARTIFACT_TYPE );
}
}
getLog().debug( "Initialized unpack types " + unpackTypesList );
}
// Copy modules
try
{
// TODO: With the next major release the modules
// should be identified by a unique id instead of the
// the artifactId's only which means this
// check can be removed.
checkModuleUniqueness();
for ( EarModule module : getModules() )
{
if ( module instanceof JavaModule )
{
getLog().warn( "JavaModule is deprecated (" + module + "), please use JarModule instead." );
}
if ( module instanceof Ejb3Module )
{
getLog().warn( "Ejb3Module is deprecated (" + module + "), please use EjbModule instead." );
}
final File sourceFile = module.getArtifact().getFile();
final File destinationFile = buildDestinationFile( getWorkDirectory(), module.getUri() );
if ( !sourceFile.isFile() )
{
throw new MojoExecutionException( "Cannot copy a directory: " + sourceFile.getAbsolutePath()
+ "; Did you package/install " + module.getArtifact() + "?" );
}
if ( destinationFile.getCanonicalPath().equals( sourceFile.getCanonicalPath() ) )
{
getLog().info( "Skipping artifact [" + module + "], as it already exists at [" + module.getUri()
+ "]" );
continue;
}
// If the module is within the unpack list, make sure that no unpack wasn't forced (null or true)
// If the module is not in the unpack list, it should be true
// CHECKSTYLE_OFF: LineLength
if ( ( unpackTypesList.contains( module.getType() ) && ( module.shouldUnpack() == null || module.shouldUnpack() ) )
|| ( module.shouldUnpack() != null && module.shouldUnpack() ) )
// CHECKSTYLE_ON: LineLength
{
getLog().info( "Copying artifact [" + module + "] to [" + module.getUri() + "] (unpacked)" );
// Make sure that the destination is a directory to avoid plexus nasty stuff :)
destinationFile.mkdirs();
unpack( sourceFile, destinationFile );
if ( skinnyWars && module.changeManifestClasspath() )
{
changeManifestClasspath( module, destinationFile );
}
}
else
{
if ( sourceFile.lastModified() > destinationFile.lastModified() )
{
getLog().info( "Copying artifact [" + module + "] to [" + module.getUri() + "]" );
FileUtils.copyFile( sourceFile, destinationFile );
if ( skinnyWars && module.changeManifestClasspath() )
{
changeManifestClasspath( module, destinationFile );
}
}
else
{
getLog().debug( "Skipping artifact [" + module + "], as it is already up to date at ["
+ module.getUri() + "]" );
}
}
}
}
catch ( IOException e )
{
throw new MojoExecutionException( "Error copying EAR modules", e );
}
catch ( ArchiverException e )
{
throw new MojoExecutionException( "Error unpacking EAR modules", e );
}
catch ( NoSuchArchiverException e )
{
throw new MojoExecutionException( "No Archiver found for EAR modules", e );
}
// Copy source files
try
{
File earSourceDir = earSourceDirectory;
if ( earSourceDir.exists() )
{
getLog().info( "Copy ear sources to " + getWorkDirectory().getAbsolutePath() );
String[] fileNames = getEarFiles( earSourceDir );
for ( String fileName : fileNames )
{
copyFile( new File( earSourceDir, fileName ), new File( getWorkDirectory(), fileName ) );
}
}
if ( applicationXml != null && !"".equals( applicationXml ) )
{
// rename to application.xml
getLog().info( "Including custom application.xml[" + applicationXml + "]" );
File metaInfDir = new File( getWorkDirectory(), META_INF );
copyFile( new File( applicationXml ), new File( metaInfDir, "/application.xml" ) );
}
}
catch ( IOException e )
{
throw new MojoExecutionException( "Error copying EAR sources", e );
}
catch ( MavenFilteringException e )
{
throw new MojoExecutionException( "Error filtering EAR sources", e );
}
// Check if deployment descriptor is there
File ddFile = new File( getWorkDirectory(), APPLICATION_XML_URI );
if ( !ddFile.exists() && ( javaEEVersion.lt( JavaEEVersion.FIVE ) ) )
{
// CHECKSTYLE_OFF: LineLength
throw new MojoExecutionException( "Deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist." );
// CHECKSTYLE_ON: LineLength
}