*/
public Manifest getManifest( MavenProject project, ManifestConfiguration config )
throws ManifestException, DependencyResolutionRequiredException
{
// Added basic entries
Manifest m = new Manifest();
Manifest.Attribute buildAttr = new Manifest.Attribute( "Built-By", System.getProperty( "user.name" ) );
m.addConfiguredAttribute( buildAttr );
Manifest.Attribute createdAttr = new Manifest.Attribute( "Created-By", "Apache Maven" );
m.addConfiguredAttribute( createdAttr );
/* TODO: rethink this, it wasn't working
Artifact projectArtifact = project.getArtifact();
if ( projectArtifact.isSnapshot() )
{
Manifest.Attribute buildNumberAttr = new Manifest.Attribute( "Build-Number", "" +
project.getSnapshotDeploymentBuildNumber() );
m.addConfiguredAttribute( buildNumberAttr );
}
*/
if ( config.getPackageName() != null )
{
Manifest.Attribute packageAttr = new Manifest.Attribute( "Package", config.getPackageName() );
m.addConfiguredAttribute( packageAttr );
}
Manifest.Attribute buildJdkAttr = new Manifest.Attribute( "Build-Jdk", System.getProperty( "java.version" ) );
m.addConfiguredAttribute( buildJdkAttr );
if ( config.isAddClasspath() )
{
StringBuffer classpath = new StringBuffer();
List artifacts = project.getRuntimeClasspathElements();
String classpathPrefix = config.getClasspathPrefix();
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
File f = new File( (String) iter.next() );
if ( f.isFile() )
{
if ( classpath.length() > 0 )
{
classpath.append( " " );
}
classpath.append( classpathPrefix );
classpath.append( f.getName() );
}
}
if ( classpath.length() > 0 )
{
Manifest.Attribute classpathAttr = new Manifest.Attribute( "Class-Path", classpath.toString() );
m.addConfiguredAttribute( classpathAttr );
}
}
// Added supplementary entries
Manifest.Attribute extensionNameAttr = new Manifest.Attribute( "Extension-Name", project.getArtifactId() );
m.addConfiguredAttribute( extensionNameAttr );
if ( project.getDescription() != null )
{
Manifest.Attribute specificationTitleAttr = new Manifest.Attribute( "Specification-Title",
project.getDescription() );
m.addConfiguredAttribute( specificationTitleAttr );
}
if ( project.getOrganization() != null )
{
Manifest.Attribute specificationVendor = new Manifest.Attribute( "Specification-Vendor",
project.getOrganization().getName() );
m.addConfiguredAttribute( specificationVendor );
Manifest.Attribute implementationVendorAttr = new Manifest.Attribute( "Implementation-Vendor",
project.getOrganization().getName() );
m.addConfiguredAttribute( implementationVendorAttr );
}
Manifest.Attribute implementationTitleAttr = new Manifest.Attribute( "Implementation-Title",
project.getArtifactId() );
m.addConfiguredAttribute( implementationTitleAttr );
Manifest.Attribute implementationVersionAttr = new Manifest.Attribute( "Implementation-Version",
project.getVersion() );
m.addConfiguredAttribute( implementationVersionAttr );
String mainClass = config.getMainClass();
if ( mainClass != null && !"".equals( mainClass ) )
{
Manifest.Attribute mainClassAttr = new Manifest.Attribute( "Main-Class", mainClass );
m.addConfiguredAttribute( mainClassAttr );
}
// Added extensions
if ( config.isAddExtensions() )
{
StringBuffer extensionsList = new StringBuffer();
Set artifacts = project.getArtifacts();
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
Artifact artifact = (Artifact) iter.next();
if ( "test".equals( artifact.getScope() ) )
{
continue;
}
// TODO: type of ejb should be added too?
if ( "jar".equals( artifact.getType() ) )
{
if ( extensionsList.length() > 0 )
{
extensionsList.append( " " );
}
extensionsList.append( artifact.getArtifactId() );
}
}
if ( extensionsList.length() > 0 )
{
Manifest.Attribute extensionsListAttr = new Manifest.Attribute( "Extension-List",
extensionsList.toString() );
m.addConfiguredAttribute( extensionsListAttr );
}
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
Artifact artifact = (Artifact) iter.next();
if ( "jar".equals( artifact.getType() ) )
{
Manifest.Attribute archExtNameAttr = new Manifest.Attribute(
artifact.getArtifactId() + "-Extension-Name", artifact.getArtifactId() );
m.addConfiguredAttribute( archExtNameAttr );
String name = artifact.getArtifactId() + "-Implementation-Version";
Manifest.Attribute archImplVersionAttr = new Manifest.Attribute( name, artifact.getVersion() );
m.addConfiguredAttribute( archImplVersionAttr );
if ( artifact.getRepository() != null )
{
// TODO: is this correct
name = artifact.getArtifactId() + "-Implementation-URL";
String url = artifact.getRepository().getUrl() + "/" + artifact.toString();
Manifest.Attribute archImplUrlAttr = new Manifest.Attribute( name, url );
m.addConfiguredAttribute( archImplUrlAttr );
}
}
}
}