FileDocCategorySizeDatePackage
ConcatManifest.javaAPI DocExample5407Tue May 29 16:56:28 BST 2007taskdefs

ConcatManifest

public final class ConcatManifest extends org.apache.tools.ant.taskdefs.Taskdef
This Ant task concats manifest information from multiple jar files.
author
Arun Gupta

Fields Summary
private File
tempdir
private File
manifest
private org.apache.tools.ant.types.FileSet
fileset
Constructors Summary
Methods Summary
public voidaddConfiguredFileset(org.apache.tools.ant.types.FileSet fileset)

        this.fileset = fileset;
    
public voidexecute()

        if (!getManifest().isFile())
            throw new BuildException("manifest must be a file.");

        Expand expand = newExpand();
        if (!getTempdir().isDirectory())
            throw new BuildException("tempdir must be a directory.");
        expand.setDest(tempdir);

        final File m = new File(tempdir + File.separator + "META-INF/MANIFEST.MF");
        Delete delete = newDelete();
        delete.setFile(m);

        BufferedWriter bw;
        try {
            bw = new BufferedWriter(new FileWriter(getManifest(), true));
            DirectoryScanner ds = fileset.getDirectoryScanner(this.project);
            for (String file : ds.getIncludedFiles()) {
                delete.execute();
                expand.setSrc(new File(ds.getBasedir() + File.separator + file));
                expand.execute();
                writeManifest(bw, file, m);
            }
            bw.flush();
            bw.close();
        } catch (IOException e) {
            throw new BuildException(e);
        }
    
public java.io.FilegetManifest()

        return manifest;
    
public java.io.FilegetTempdir()

        return tempdir;
    
private org.apache.tools.ant.taskdefs.DeletenewDelete()

        Delete delete = new Delete();
        delete.setProject(this.project);
        delete.setFailOnError(false);
        delete.setQuiet(true);

        return delete;
    
private org.apache.tools.ant.taskdefs.ExpandnewExpand()

        Expand expand = new Expand();
        expand.setProject(this.project);

        return expand;
    
public voidsetManifest(java.io.File manifest)

        this.manifest = manifest;
    
public voidsetTempdir(java.io.File tempdir)

        this.tempdir = tempdir;
    
private voidwriteManifest(java.io.BufferedWriter bw, java.lang.String file, java.io.File m)

        bw.write("\nName: " + file + "\n");
        BufferedReader br;
        try {
            br = new BufferedReader(new FileReader(m));
        } catch (FileNotFoundException e) {
            log("No manifest found for " + file, Project.MSG_WARN);

            // ignore this exception and continue
            return;
        }
        String line = br.readLine();
        log("\nManifest for " + file, Project.MSG_DEBUG);
        while (line != null) {
            log(line, Project.MSG_DEBUG);
            bw.write(line + "\n");
            line = br.readLine();
        }
        bw.write("\n");