getLog().debug(
"This project did not have a META-INF/MANIFEST.MF file before, so a new file was created." );
}
// Read the manifest from disk
Manifest mf = new Manifest( new FileReader( manifestFile ) );
Attribute classPath = mf.getMainSection()
.getAttribute( "Class-Path" );
List<String> classPathElements = new ArrayList<String>();
if ( classPath != null )
{
classPathElements.addAll( Arrays.asList( classPath.getValue()
.split( " " ) ) );
}
else
{
classPath = new Attribute( "Class-Path", "" );
mf.getMainSection().addConfiguredAttribute( classPath );
}
// Modify the classpath entries in the manifest
for ( EarModule o : getModules() )
{
if ( o instanceof JarModule )
{
JarModule jm = ( JarModule ) o;
if ( module.getLibDir() != null )
{
File artifact = new File( new File(
workDirectory, module.getLibDir() ),
jm.getBundleFileName() );
if ( artifact.exists() )
{
if ( !artifact.delete() )
{
getLog().error(
"Could not delete '" + artifact + "'" );
}
}
}
if ( classPathElements.contains( jm.getBundleFileName() ) )
{
classPathElements.set( classPathElements.indexOf( jm
.getBundleFileName() ), jm.getUri() );
}
else
{
classPathElements.add( jm.getUri() );
}
}
}
classPath.setValue( StringUtils.join( classPathElements.iterator(), " " ) );
// Write the manifest to disk
PrintWriter pw = new PrintWriter( manifestFile );
mf.write( pw );
pw.close();
if ( original.isFile() )
{
// Pack up the archive again from the work directory