KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > kirkk > analyzer > textui > JarAnalyzerTask


1 package com.kirkk.analyzer.textui;
2
3 import java.io.File JavaDoc;
4
5 import org.apache.tools.ant.BuildException;
6 import org.apache.tools.ant.Task;
7
8 /*
9  * Very simple ant task for the JarAnalyzer
10  * http://www.kirkk.com/wiki/wiki.php/Main/JarAnalyzer
11  */

12 public class JarAnalyzerTask extends Task
13 {
14     private File JavaDoc srcdir;
15     private File JavaDoc destfile;
16     private String JavaDoc packageFilter;
17     private String JavaDoc jarFilter;
18     private String JavaDoc summaryclass;
19
20
21     public void setJarFilter(String JavaDoc jarFilter) {
22         this.jarFilter = jarFilter;
23     }
24
25     public void setPackageFilter(String JavaDoc packageFilter) {
26         this.packageFilter = packageFilter;
27     }
28
29     public void setSrcdir(File JavaDoc srcdir)
30     {
31         this.srcdir = srcdir;
32     }
33
34     public void setDestfile(File JavaDoc destfile)
35     {
36         this.destfile = destfile;
37     }
38
39     public void setSummaryclass(String JavaDoc summaryclass)
40     {
41         this.summaryclass = summaryclass;
42     }
43
44     public void execute() throws BuildException
45     {
46         validateAttributes();
47         try
48         {
49             Class JavaDoc clazz = Class.forName(summaryclass);
50             Summary summary = (Summary)clazz.newInstance();
51             summary.createSummary(srcdir, destfile, packageFilter, jarFilter);
52             log(destfile + " successfully created");
53         }
54         catch(Exception JavaDoc exc)
55         {
56             throw new BuildException(exc);
57         }
58     }
59
60     private void validateAttributes()
61     {
62         if(null == srcdir)
63         {
64             throw new BuildException("Missing srcdir");
65         }
66         if(null == destfile)
67         {
68             throw new BuildException("Missing destfile");
69         }
70         if(!(srcdir.exists() && srcdir.isDirectory()))
71         {
72             throw new BuildException("srcdir must be a valid directory");
73         }
74         if(destfile.isDirectory())
75         {
76             throw new BuildException("srcdir must be a file");
77         }
78         if(null == summaryclass)
79         {
80             throw new BuildException("Missing summaryclass");
81         }
82     }
83 }
84
Popular Tags