| 1615 |
mhunt |
1 |
package com.erggroup.mass.ant;
|
|
|
2 |
|
|
|
3 |
import java.io.File;
|
|
|
4 |
import java.util.ArrayList;
|
|
|
5 |
import java.util.Iterator;
|
|
|
6 |
import org.apache.tools.ant.BuildException;
|
|
|
7 |
import org.apache.tools.ant.FileScanner;
|
|
|
8 |
import org.apache.tools.ant.Project;
|
|
|
9 |
import org.apache.tools.ant.taskdefs.Jar;
|
|
|
10 |
import org.apache.tools.ant.taskdefs.Manifest;
|
|
|
11 |
import org.apache.tools.ant.taskdefs.ManifestException;
|
|
|
12 |
import org.apache.tools.ant.types.FileSet;
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
public class ManifestElement implements JatsElement
|
|
|
16 |
{
|
|
|
17 |
private static final String MANIFEST_NAME = "META-INF/MANIFEST.MF";
|
|
|
18 |
|
|
|
19 |
static final String TASK_NAME = "manifest";
|
|
|
20 |
|
|
|
21 |
private String implementationVersion;
|
|
|
22 |
|
|
|
23 |
private ArrayList filesets = new ArrayList();
|
|
|
24 |
|
|
|
25 |
public FileSet createFileset()
|
|
|
26 |
{
|
|
|
27 |
FileSet fileset = new FileSet();
|
|
|
28 |
filesets.add( fileset );
|
|
|
29 |
return fileset;
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
public void setImplementationVersion(String value)
|
|
|
33 |
{
|
|
|
34 |
this.implementationVersion = value;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
public void execute(Jats parent)
|
|
|
38 |
{
|
|
|
39 |
if ( filesets.size() == 0 )
|
|
|
40 |
{
|
|
|
41 |
throw new BuildException("At least one fileset must be provided");
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
for ( Iterator i=filesets.iterator(); i.hasNext(); )
|
|
|
45 |
{
|
|
|
46 |
FileSet fileset = (FileSet)i.next();
|
|
|
47 |
FileScanner scanner = fileset.getDirectoryScanner( parent.getProject() );
|
|
|
48 |
String[] files = scanner.getIncludedFiles();
|
|
|
49 |
File basedir = scanner.getBasedir();
|
|
|
50 |
for ( int j=0; j<files.length; j++ )
|
|
|
51 |
{
|
|
|
52 |
//log( "Updating manifest for file " + files[j], Project.MSG_VERBOSE );
|
|
|
53 |
File file = new File( basedir, files[j] );
|
|
|
54 |
updateManifest( file, parent.getProject() );
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
protected void updateManifest( File jarFile, Project p )
|
|
|
60 |
{
|
|
|
61 |
Jar jar = new Jar();
|
|
|
62 |
jar.setDestFile(jarFile);
|
|
|
63 |
jar.setUpdate(true);
|
|
|
64 |
|
|
|
65 |
try
|
|
|
66 |
{
|
|
|
67 |
Manifest newManifest = new Manifest();
|
|
|
68 |
if ( implementationVersion != null )
|
|
|
69 |
newManifest.addConfiguredAttribute( new Manifest.Attribute( "Implementation-Version", implementationVersion ) );
|
|
|
70 |
newManifest.addConfiguredAttribute( new Manifest.Attribute( "Implementation-Vendor", "ERG Transit Systems" ) );
|
|
|
71 |
jar.addConfiguredManifest(newManifest);
|
|
|
72 |
}
|
|
|
73 |
catch ( ManifestException x )
|
|
|
74 |
{
|
|
|
75 |
throw new BuildException("Manifest creation error.",x);
|
|
|
76 |
}
|
|
|
77 |
jar.setProject(p);
|
|
|
78 |
jar.execute();
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
public String getElementType()
|
|
|
82 |
{
|
|
|
83 |
return TASK_NAME;
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
}
|