Source code: com/thermidor/build/tasks/JlibManifestTask.java
1 package com.thermidor.build.tasks;
2 import org.apache.tools.ant.*;
3 //import org.apache.tools.ant.taskdefs.*;
4 import org.apache.tools.ant.types.*;
5 import java.io.*;
6 import java.util.*;
7 import java.util.jar.*;
8 public class JlibManifestTask extends Task {
9 private File _manifestFile;
10 private String _classpath;
11 private String _mainClass;
12 private boolean _absolute=false;
13 public void setManifest(File manifestFile) {
14 _manifestFile = manifestFile;
15 }
16 public void setClasspathref(String classpath) {
17 _classpath=classpath;
18 }
19 public void execute() {
20 if(_manifestFile==null) {
21 throw new BuildException("'manifest' attribute must be set");
22 }
23 try {
24 Manifest manifest = new Manifest();
25 Attributes mainAttributes=manifest.getMainAttributes();
26 mainAttributes.put(Attributes.Name.MANIFEST_VERSION,"1.0");
27 mainAttributes.put(new Attributes.Name("Created-By"),"1.0 Thermidor JlibManifest");
28 if(_classpath!=null) {
29 Path path=(Path)getProject().getReferences().get(_classpath);
30 if(path ==null) {
31 throw new BuildException("'classpathref' is not valid");
32 }
33 String[] list = path.list();
34 String manifestClasspath="";
35 if(list!=null) {
36 int len = list.length;
37 for(int cnt=0;cnt<len;cnt++) {
38 String name=(new File(list[cnt])).getName();
39 manifestClasspath+=name+" ";
40 }
41 }
42 mainAttributes.put(Attributes.Name.CLASS_PATH,manifestClasspath);
43 }
44 FileOutputStream fos= new FileOutputStream(_manifestFile);
45 manifest.write(fos);
46 fos.flush();
47 fos.close();
48 }
49 catch(IOException ioe ){
50 throw new BuildException("error creating the manifest",ioe);
51 }
52 }
53 }