getLog().info( "Building EJB " + jarName + " with EJB version " + ejbVersion );
}
File jarFile = getEJBJarFile( basedir, jarName, classifier );
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver( jarArchiver );
archiver.setOutputFile( jarFile );
File deploymentDescriptor = new File( outputDirectory, ejbJar );
/* test EJB version compliance */
if ( !ejbVersion.matches( "\\A[2-3]\\.[0-9]\\z" ) )
{
throw new MojoExecutionException( "ejbVersion is not valid: " + ejbVersion
+ ". Must be 2.x or 3.x (where x is a digit)" );
}
if ( ejbVersion.matches( "\\A2\\.[0-9]\\z" ) && !deploymentDescriptor.exists() )
{
throw new MojoExecutionException( "Error assembling EJB: " + ejbJar + " is required for ejbVersion 2.x" );
}
try
{
// TODO: This should be handled different.
String[] mainJarExcludes = new String[] { ejbJar, "**/package.html" };
if ( excludes != null && !excludes.isEmpty() )
{
excludes.add( ejbJar );
mainJarExcludes = (String[]) excludes.toArray( new String[excludes.size()] );
}
archiver.getArchiver().addDirectory( outputDirectory, DEFAULT_INCLUDES, mainJarExcludes );
if ( deploymentDescriptor.exists() )
{
// EJB-34 Filter ejb-jar.xml
if ( filterDeploymentDescriptor )
{
getLog().debug( "Filtering deployment descriptor." );
MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution();
mavenResourcesExecution.setEscapeString( escapeString );
List<FilterWrapper> filterWrappers =
mavenFileFilter.getDefaultFilterWrappers( project, filters, escapeBackslashesInFilePath,
this.session, mavenResourcesExecution );
// Create a temporary file that we can copy-and-filter
File unfilteredDeploymentDescriptor = new File( outputDirectory, ejbJar + ".unfiltered" );
FileUtils.copyFile( deploymentDescriptor, unfilteredDeploymentDescriptor );
mavenFileFilter.copyFile( unfilteredDeploymentDescriptor, deploymentDescriptor, true,
filterWrappers, getEncoding( unfilteredDeploymentDescriptor ) );
// Remove the temporary file
FileUtils.forceDelete( unfilteredDeploymentDescriptor );
}
archiver.getArchiver().addFile( deploymentDescriptor, ejbJar );
}
// create archive
archiver.createArchive( session, project, archive );
}
catch ( ArchiverException e )
{
throw new MojoExecutionException( "There was a problem creating the EJB archive: " + e.getMessage(), e );
}
catch ( ManifestException e )
{
throw new MojoExecutionException( "There was a problem creating the EJB archive: " + e.getMessage(), e );
}
catch ( IOException e )
{
throw new MojoExecutionException( "There was a problem creating the EJB archive: " + e.getMessage(), e );
}
catch ( DependencyResolutionRequiredException e )
{
throw new MojoExecutionException( "There was a problem creating the EJB archive: " + e.getMessage(), e );
}
catch ( MavenFilteringException e )
{
throw new MojoExecutionException( "There was a problem filtering the deployment descriptor: "
+ e.getMessage(), e );
}
// Handle the classifier if necessary
if ( classifier != null )
{
projectHelper.attachArtifact( project, "ejb", classifier, jarFile );
}
else
{
project.getArtifact().setFile( jarFile );
}
if ( generateClient )
{
String clientJarName = jarName;
if ( classifier != null )
{
clientJarName += "-" + classifier;
}
getLog().info( "Building EJB client " + clientJarName + "-client" );
String[] excludes = DEFAULT_CLIENT_EXCLUDES;
String[] includes = DEFAULT_INCLUDES;
if ( clientIncludes != null && !clientIncludes.isEmpty() )
{
includes = (String[]) clientIncludes.toArray( new String[clientIncludes.size()] );
}
if ( clientExcludes != null && !clientExcludes.isEmpty() )
{
excludes = (String[]) clientExcludes.toArray( new String[clientExcludes.size()] );
}
File clientJarFile = new File( basedir, clientJarName + "-client.jar" );
MavenArchiver clientArchiver = new MavenArchiver();
clientArchiver.setArchiver( clientJarArchiver );
clientArchiver.setOutputFile( clientJarFile );
try
{
clientArchiver.getArchiver().addDirectory( outputDirectory, includes, excludes );
// create archive
clientArchiver.createArchive( session, project, archive );
}
catch ( ArchiverException e )
{
throw new MojoExecutionException( "There was a problem creating the EJB client archive: "