Debian Codegraph @

laf-widget/src/main/java/org/pushingpixels/lafwidget/ant/AugmentTask.java

raw
1 /*
2 * Copyright (c) 2005-2010 Laf-Widget Kirill Grouchnikov. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * o Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * o Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * o Neither the name of Laf-Widget Kirill Grouchnikov nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 package org.pushingpixels.lafwidget.ant;
31
32 import java.io.File;
33 import java.util.ArrayList;
34 import java.util.List;
35 import java.util.regex.Pattern;
36
37 import org.apache.tools.ant.BuildException;
38 import org.apache.tools.ant.Task;
39 import org.apache.tools.ant.types.FileSet;
40 import org.apache.tools.ant.types.Path;
41
42 /**
43 * Ant task for augmenting UI delegates. Is based on JiBX ant task
44 * (BSD-licensed).
45 *
46 * @author Kirill Grouchnikov.
47 */
48 public class AugmentTask extends Task {
49 /**
50 * Pattern for matching the UI delegates.
51 */
52 private String m_pattern;
53
54 /**
55 * Verbosity indication.
56 */
57 private boolean m_verbose;
58
59 /**
60 * Classpath.
61 */
62 private Path m_classpath;
63
64 /**
65 * Fileset.
66 */
67 private List<FileSet> m_fileSet;
68
69 /*
70 * (non-Javadoc)
71 *
72 * @see org.apache.tools.ant.Task#init()
73 */
74 @Override
75 public void init() throws BuildException {
76 super.init();
77 this.m_fileSet = new ArrayList<FileSet>();
78 }
79
80 /**
81 * Returns an array of paths of all the files specified by the
82 * &lt;classpath&gt; or &lt;classpathset&gt; tags. Note that the
83 * &lt;classpath&gt; and &lt;classpathset&gt; tags cannot both be specified.
84 *
85 * @return Array of file paths.
86 */
87 private String[] getPaths() {
88 String[] pathArray = null;
89 if (this.m_classpath != null) {
90 //
91 // If a <classpath> tag has been set, m_classpath will
92 // not be null. In this case, just return the array of
93 // paths directly.
94 //
95 pathArray = this.m_classpath.list();
96 } else {
97 //
98 // Store the directory paths specified by each of the
99 // <classpathset> tags.
100 //
101 pathArray = new String[this.m_fileSet.size()];
102
103 for (int i = 0; i < this.m_fileSet.size(); i++) {
104 FileSet fileSet = this.m_fileSet.get(i);
105 File directory = fileSet.getDir(this.getProject());
106 pathArray[i] = directory.getAbsolutePath();
107 }
108 }
109 return pathArray;
110 }
111
112 /*
113 * (non-Javadoc)
114 *
115 * @see org.apache.tools.ant.Task#execute()
116 */
117 @Override
118 public void execute() throws BuildException {
119 try {
120 String[] pathArr = this.getPaths();
121 UiDelegateAugmenter augmenter = new UiDelegateAugmenter();
122 if (this.m_verbose)
123 augmenter.setVerbose(this.m_verbose);
124
125 Pattern p = Pattern.compile(this.m_pattern);
126
127 for (int i = 0; i < pathArr.length; i++) {
128 augmenter.process(pathArr[0], new File(pathArr[0]), p);
129 }
130 } catch (AugmentException ae) {
131 throw new BuildException(ae);
132 }
133 // process(this.m_classpath, new File(args[0]), p);
134 }
135
136 /**
137 * @param fSet
138 */
139 public void addClassPathSet(FileSet fSet) {
140 this.m_fileSet.add(fSet);
141 }
142
143 /**
144 * Returns the current classpath.
145 *
146 * @return The current classpath.
147 */
148 public Path getClasspath() {
149 return this.m_classpath;
150 }
151
152 /**
153 * Sets the classpath for this task. Multiple calls append the new classpath
154 * to the current one, rather than overwriting it.
155 *
156 * @param classpath
157 * The new classpath as a Path object.
158 */
159 public void setClasspath(Path classpath) {
160 if (this.m_classpath == null) {
161 this.m_classpath = classpath;
162 } else {
163 this.m_classpath.append(classpath);
164 }
165 }
166
167 /**
168 * Creates the classpath for this task and returns it. If the classpath has
169 * already been created, the method just returns that one.
170 *
171 * @return The created classpath.
172 */
173 public Path createClasspath() {
174 if (this.m_classpath == null) {
175 this.m_classpath = new Path(this.getProject());
176 }
177
178 return this.m_classpath;
179 }
180
181 /**
182 * @param string
183 */
184 public void setPattern(String string) {
185 this.m_pattern = string;
186 }
187
188 /**
189 * @param bool
190 */
191 public void setVerbose(boolean bool) {
192 this.m_verbose = bool;
193 }
194 }