1 |
|
package com.wikihouse.wildcats0201.jdbcchart.ant; |
2 |
|
|
3 |
|
import java.io.File; |
4 |
|
import java.text.MessageFormat; |
5 |
|
import java.util.Iterator; |
6 |
|
import java.util.LinkedList; |
7 |
|
import java.util.List; |
8 |
|
|
9 |
|
import org.apache.tools.ant.BuildException; |
10 |
|
import org.apache.tools.ant.DirectoryScanner; |
11 |
|
import org.apache.tools.ant.Project; |
12 |
|
import org.apache.tools.ant.Task; |
13 |
|
import org.apache.tools.ant.loader.AntClassLoader2; |
14 |
|
import org.apache.tools.ant.types.FileSet; |
15 |
|
import org.apache.tools.ant.types.Path; |
16 |
|
import org.apache.tools.ant.types.Reference; |
17 |
|
|
18 |
|
import com.wikihouse.wildcats0201.jdbcchart.XYChartByJDBC; |
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
0 |
public class XyLineChartTask extends Task { |
27 |
|
|
28 |
0 |
private List fileList = new LinkedList(); |
29 |
|
|
30 |
|
private Path classpath; |
31 |
|
|
32 |
|
private String driver; |
33 |
|
|
34 |
|
private String user; |
35 |
|
|
36 |
|
private String password; |
37 |
|
|
38 |
|
private String url; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
public FileSet createFileSet() { |
46 |
0 |
FileSet fs = new FileSet(); |
47 |
0 |
fileList.add(fs); |
48 |
0 |
return fs; |
49 |
|
} |
50 |
|
|
51 |
|
private String[] getUrlPaths() { |
52 |
0 |
List list = new LinkedList(); |
53 |
|
|
54 |
0 |
for (Iterator it = this.fileList.iterator(); it.hasNext();) { |
55 |
0 |
FileSet fileset = (FileSet) it.next(); |
56 |
0 |
DirectoryScanner scanner = fileset |
57 |
|
.getDirectoryScanner(getProject()); |
58 |
0 |
String[] files = scanner.getIncludedFiles(); |
59 |
0 |
StringBuffer sb = new StringBuffer(); |
60 |
0 |
for (int i = 0; i < files.length; i++) { |
61 |
0 |
sb.append(scanner.getBasedir().getAbsolutePath()); |
62 |
0 |
sb.append(File.separatorChar); |
63 |
0 |
sb.append(files[i]); |
64 |
0 |
list.add(sb.toString()); |
65 |
0 |
log(MessageFormat.format("target file [{0}]", new Object[] { sb |
66 |
|
.toString() })); |
67 |
0 |
sb.delete(0, sb.length()); |
68 |
|
} |
69 |
|
} |
70 |
0 |
return (String[]) list.toArray(new String[list.size()]); |
71 |
|
} |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
public void setClasspathRef(Reference r) { |
80 |
0 |
createClasspath().setRefid(r); |
81 |
0 |
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
public void setClasspath(Path classpath) { |
90 |
0 |
if (this.classpath == null) { |
91 |
0 |
this.classpath = classpath; |
92 |
|
} else { |
93 |
0 |
this.classpath.append(classpath); |
94 |
|
} |
95 |
0 |
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
public Path createClasspath() { |
103 |
0 |
if (this.classpath == null) { |
104 |
0 |
this.classpath = new Path(getProject()); |
105 |
|
} |
106 |
0 |
return this.classpath; |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
public void setDriver(String driver) { |
117 |
0 |
this.driver = driver; |
118 |
0 |
} |
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
public void setUrl(String url) { |
128 |
0 |
this.url = url; |
129 |
0 |
} |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
public void setPassword(String password) { |
138 |
0 |
this.password = password; |
139 |
0 |
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
public void setUser(String user) { |
148 |
0 |
this.user = user; |
149 |
0 |
} |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
public void execute() throws BuildException { |
155 |
0 |
AntClassLoader2 loader = (AntClassLoader2) this.getClass() |
156 |
|
.getClassLoader(); |
157 |
0 |
loader.setClassPath(this.classpath); |
158 |
|
|
159 |
0 |
log(loader.getClasspath(), Project.MSG_INFO); |
160 |
|
|
161 |
0 |
String[] files = this.getUrlPaths(); |
162 |
0 |
for (int i = 0; i < files.length; i++) { |
163 |
0 |
XYChartByJDBC xyChartByJDBC = new XYChartByJDBC(); |
164 |
0 |
xyChartByJDBC.execute(files[i], this.driver, class="keyword">this.url, class="keyword">this.user, |
165 |
|
this.password); |
166 |
|
} |
167 |
|
|
168 |
0 |
} |
169 |
|
|
170 |
|
} |