1 package net.sf.jlayercheck.ant;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.net.URL;
8 import java.util.Map;
9 import java.util.TreeMap;
10
11 import javax.xml.parsers.ParserConfigurationException;
12
13 import org.xml.sax.SAXException;
14
15 import net.sf.jlayercheck.util.DependencyVisitor;
16 import net.sf.jlayercheck.util.HTMLOutput;
17 import net.sf.jlayercheck.util.XMLConfiguration;
18 import net.sf.jlayercheck.util.XMLConfigurationParser;
19 import net.sf.jlayercheck.util.model.ClassSource;
20
21
22
23
24
25
26
27
28 public class JLCTask {
29
30
31 public static final String CONFIG = "jlayercheck_test.xml";
32
33
34 public static final String OUTDIR = "jlayercheck-out";
35
36
37 protected File config = new File(CONFIG);
38
39
40 protected File outDir = new File(OUTDIR);
41
42
43
44
45 public File getConfig() {
46 return config;
47 }
48
49 public void setConfig(File config) {
50 this.config = config;
51 }
52
53 public File getOutDir() {
54 return outDir;
55 }
56
57 public void setOutDir(File outDir) {
58 this.outDir = outDir;
59 }
60
61
62
63
64
65
66 public void execute() {
67
68 if (getConfig() == null || getOutDir() == null) {
69 throw new IllegalArgumentException("Config and outDir must be set!");
70 }
71 File config = getConfig();
72 if (!config.exists()) {
73 throw new RuntimeException("Cannot read " + config);
74 }
75
76 try {
77
78 InputStream confIn = new FileInputStream(config);
79 XMLConfiguration xcp = new XMLConfigurationParser().parse(confIn);
80
81
82 File outDir = getOutDir();
83 outDir.mkdirs();
84
85
86 DependencyVisitor dv = new DependencyVisitor();
87 Map<String, URL> javaSources = new TreeMap<String, URL>();
88
89
90 for (ClassSource cs : xcp.getClassSources()) {
91 cs.call(dv);
92 javaSources.putAll(cs.getSourceFiles());
93 }
94
95
96 HTMLOutput html = new HTMLOutput(outDir.getAbsolutePath());
97 html.write(dv, xcp);
98
99 } catch (IOException ioe) {
100 throw new RuntimeException("Error reading configuration " + config
101 + ": " + ioe, ioe);
102 } catch (SAXException e) {
103 throw new RuntimeException("Error reading configuration " + config
104 + ": " + e, e);
105 } catch (ParserConfigurationException e) {
106 throw new RuntimeException("Error reading configuration " + config
107 + ": " + e, e);
108 } catch (Exception e) {
109 throw new RuntimeException("unexpected Exception caught: " + e, e);
110 }
111
112 }
113
114 }