throws MojoExecutionException, MojoFailureException
{
// Initializes ear modules
super.execute();
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.standardArtifactTypes.contains( type ) )
{
throw new MojoExecutionException(
"Invalid type [" + type + "] supported types are " + EarModuleFactory.standardArtifactTypes );
}
}
getLog().debug( "Initialized unpack types " + unpackTypesList );
}
// Copy modules
try
{
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
if ( ( unpackTypesList.contains( module.getType() ) &&
( module.shouldUnpack() == null || module.shouldUnpack().booleanValue() ) ) ||
( module.shouldUnpack() != null && module.shouldUnpack().booleanValue() ) )
{
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 ( int i = 0; i < fileNames.length; i++ )
{
copyFile( new File( earSourceDir, fileNames[i] ), new File( getWorkDirectory(), fileNames[i] ) );
}
}
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 ) ) )
{
throw new MojoExecutionException(
"Deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist." );
}