PageRenderTime 244ms CodeModel.GetById 240ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/de/masters_of_disaster/ant/tasks/deb/CalculateInstalledSizeForDeb.java

#
Java | 76 lines | 42 code | 8 blank | 26 comment | 6 complexity | dd5169d84209170125fa7dbab6d1b853 MD5 | raw file
 1package de.masters_of_disaster.ant.tasks.deb;
 2
 3import java.io.File;
 4import java.util.Enumeration;
 5import java.util.Vector;
 6import org.apache.tools.ant.BuildException;
 7import org.apache.tools.ant.taskdefs.MatchingTask;
 8import org.apache.tools.ant.types.FileSet;
 9
10/**
11 * Calculates the "Installed-Size" of a deb package for the "control"-file.
12 *
13 * @ant.task category="packaging"
14 */
15public class CalculateInstalledSizeForDeb extends MatchingTask {
16    String property = null;
17    Vector fileSets = new Vector();
18    File baseDir;
19
20    /**
21     * Add a new fileset
22     * 
23     * @return the fileset to be used as the nested element.
24     */
25    public FileSet createFileSet() {
26        FileSet fileSet = new FileSet();
27        fileSets.addElement(fileSet);
28        return fileSet;
29    }
30
31    /**
32     * This is the base directory to look in for things to include.
33     * 
34     * @param baseDir the base directory.
35     */
36    public void setBaseDir(File baseDir) {
37        this.baseDir = baseDir;
38        fileset.setDir(baseDir);
39    }
40
41    /**
42     * This is the base directory to look in for things to include.
43     * 
44     * @param baseDir the base directory.
45     */
46    public void setProperty(String property) {
47        this.property = property;
48    }
49
50    /**
51     * do the business
52     * 
53     * @throws BuildException on error
54     */
55    public void execute() throws BuildException {
56        if (null == property) {
57            throw new BuildException("property must be set for <CalculateInstalledSizeForDeb>");
58        }
59
60        if (null != baseDir) {
61            // add the main fileset to the list of filesets to process.
62            fileSets.addElement(fileset);
63        }
64
65        long totalSize = 0;
66        for (Enumeration e=fileSets.elements() ; e.hasMoreElements() ; ) {
67            FileSet fileSet = (FileSet)e.nextElement();
68            String[] files = fileSet.getDirectoryScanner(getProject()).getIncludedFiles();
69            File fileSetDir = fileSet.getDir(getProject());
70            for (int i=0, c=files.length ; i<c ; i++) {
71                totalSize += new File(fileSetDir,files[i]).length() / 1024;
72            }
73        }
74        getProject().setNewProperty(property,Long.toString(totalSize));
75    }
76}