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