Mercurial > cgi-bin > hgweb.cgi > JpegWasher
comparison lib/mod/src/de/masters_of_disaster/ant/tasks/calculatesize/CalculateSize.java @ 33:3d86f0391168
Work on improving the build system.
author | David Barts <davidb@stashtea.com> |
---|---|
date | Fri, 24 Apr 2020 19:45:57 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
32:c06edc56669b | 33:3d86f0391168 |
---|---|
1 package de.masters_of_disaster.ant.tasks.calculatesize; | |
2 | |
3 import java.io.File; | |
4 import java.util.Enumeration; | |
5 import java.util.Vector; | |
6 import org.apache.tools.ant.BuildException; | |
7 import org.apache.tools.ant.taskdefs.MatchingTask; | |
8 import 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 */ | |
15 public class CalculateSize extends MatchingTask { | |
16 String realSizeProperty = null; | |
17 String diskSizeProperty = null; | |
18 Vector fileSets = new Vector(); | |
19 File baseDir; | |
20 | |
21 /** | |
22 * Add a new fileset | |
23 * | |
24 * @return the fileset to be used as the nested element. | |
25 */ | |
26 public FileSet createFileSet() { | |
27 FileSet fileSet = new FileSet(); | |
28 fileSets.addElement(fileSet); | |
29 return fileSet; | |
30 } | |
31 | |
32 /** | |
33 * This is the base directory to look in for things to include. | |
34 * | |
35 * @param baseDir the base directory. | |
36 */ | |
37 public void setBaseDir(File baseDir) { | |
38 this.baseDir = baseDir; | |
39 fileset.setDir(baseDir); | |
40 } | |
41 | |
42 /** | |
43 * This is the property to set to the real size. | |
44 * | |
45 * @param realSizeProperty The property to set to the real size | |
46 */ | |
47 public void setRealSizeProperty(String realSizeProperty) { | |
48 this.realSizeProperty = realSizeProperty; | |
49 } | |
50 | |
51 /** | |
52 * This is the property to set to the disk size. | |
53 * | |
54 * @param diskSizeProperty The property to set to the disk size | |
55 */ | |
56 public void setDiskSizeProperty(String diskSizeProperty) { | |
57 this.diskSizeProperty = diskSizeProperty; | |
58 } | |
59 | |
60 /** | |
61 * do the business | |
62 * | |
63 * @throws BuildException on error | |
64 */ | |
65 public void execute() throws BuildException { | |
66 if ((null == realSizeProperty) && (null == diskSizeProperty)) { | |
67 throw new BuildException("realSizeProperty or diskSizeProperty must be set for <CalculateSize>"); | |
68 } | |
69 | |
70 if (null != baseDir) { | |
71 // add the main fileset to the list of filesets to process. | |
72 fileSets.addElement(fileset); | |
73 } | |
74 | |
75 long realSize = 0; | |
76 long diskSize = 0; | |
77 for (Enumeration e=fileSets.elements() ; e.hasMoreElements() ; ) { | |
78 FileSet fileSet = (FileSet)e.nextElement(); | |
79 String[] files = fileSet.getDirectoryScanner(getProject()).getIncludedFiles(); | |
80 File fileSetDir = fileSet.getDir(getProject()); | |
81 for (int i=0, c=files.length ; i<c ; i++) { | |
82 long fileLength = new File(fileSetDir,files[i]).length(); | |
83 realSize += fileLength / 1024; | |
84 diskSize += (fileLength / 4096 + 1) * 4; | |
85 } | |
86 } | |
87 if (null != realSizeProperty) { | |
88 getProject().setNewProperty(realSizeProperty,Long.toString(realSize)); | |
89 } | |
90 if (null != diskSizeProperty) { | |
91 getProject().setNewProperty(diskSizeProperty,Long.toString(diskSize)); | |
92 } | |
93 } | |
94 } |