Debian Codegraph @

laf-widget/src/main/java/org/pushingpixels/lafwidget/ant/AugmentMainTask.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.*;
34
35 import org.apache.tools.ant.BuildException;
36 import org.apache.tools.ant.Task;
37 import org.apache.tools.ant.types.FileSet;
38 import org.apache.tools.ant.types.Path;
39
40 /**
41 * Ant task for augmenting main LAF class. Is based on JiBX ant task
42 * (BSD-licensed).
43 *
44 * @author Kirill Grouchnikov.
45 */
46 public class AugmentMainTask extends Task {
47 /**
48 * Verbosty indication.
49 */
50 private boolean m_verbose;
51
52 /**
53 * Classpath.
54 */
55 private Path m_classpath;
56
57 /**
58 * Fileset.
59 */
60 private List<FileSet> m_fileSet;
61
62 /**
63 * Main LAF classname.
64 */
65 private String m_mainLafClassName;
66
67 /**
68 * List of delegates to create.
69 */
70 private List<UiDelegateType> m_delegatesToCreate;
71
72 /*
73 * (non-Javadoc)
74 *
75 * @see org.apache.tools.ant.Task#init()
76 */
77 @Override
78 public void init() throws BuildException {
79 super.init();
80 this.m_fileSet = new ArrayList<FileSet>();
81 this.m_delegatesToCreate = new ArrayList<UiDelegateType>();
82 }
83
84 /**
85 * Returns an array of paths of all the files specified by the
86 * &lt;classpath&gt; or &lt;classpathset&gt; tags. Note that the
87 * &lt;classpath&gt; and &lt;classpathset&gt; tags cannot both be specified.
88 *
89 * @return Array of file paths.
90 */
91 private String[] getPaths() {
92 String[] pathArray = null;
93 if (this.m_classpath != null) {
94 //
95 // If a <classpath> tag has been set, m_classpath will
96 // not be null. In this case, just return the array of
97 // paths directly.
98 //
99 pathArray = this.m_classpath.list();
100 } else {
101 //
102 // Store the directory paths specified by each of the
103 // <classpathset> tags.
104 //
105 pathArray = new String[this.m_fileSet.size()];
106
107 for (int i = 0; i < this.m_fileSet.size(); i++) {
108 FileSet fileSet = this.m_fileSet.get(i);
109 File directory = fileSet.getDir(this.getProject());
110 pathArray[i] = directory.getAbsolutePath();
111 }
112 }
113 return pathArray;
114 }
115
116 /*
117 * (non-Javadoc)
118 *
119 * @see org.apache.tools.ant.Task#execute()
120 */
121 @Override
122 public void execute() throws BuildException {
123 try {
124 // System.out.println(this.m_verbose + ", " + this.m_pattern);
125 //
126
127 for (Iterator<UiDelegateType> it = this.m_delegatesToCreate
128 .iterator(); it.hasNext();) {
129 UiDelegateType dtc = it.next();
130 if (this.m_verbose)
131 System.out.println("Will create forwarding delegate for : "
132 + dtc.getName());
133 }
134
135 String[] pathArr = this.getPaths();
136 LafMainClassAugmenter augmenter = new LafMainClassAugmenter();
137 if (this.m_verbose)
138 augmenter.setVerbose(this.m_verbose);
139
140 for (int i = 0; i < pathArr.length; i++) {
141 String[] delegates = new String[this.m_delegatesToCreate.size()];
142 int count = 0;
143 for (Iterator<UiDelegateType> it = this.m_delegatesToCreate.iterator(); it
144 .hasNext();) {
145 UiDelegateType dtc = it.next();
146 delegates[count++] = dtc.getName();
147 }
148 augmenter.setDelegatesToAdd(delegates);
149 augmenter.process(pathArr[0], new File(pathArr[0]),
150 this.m_mainLafClassName);
151 }
152 } catch (AugmentException ae) {
153 throw new BuildException(ae);
154 }
155 // process(this.m_classpath, new File(args[0]), p);
156 }
157
158 /**
159 * @param fSet
160 */
161 public void addClassPathSet(FileSet fSet) {
162 this.m_fileSet.add(fSet);
163 }
164
165 /**
166 * @param delegate
167 */
168 public void addDelegate(UiDelegateType delegate) {
169 this.m_delegatesToCreate.add(delegate);
170 }
171
172 /**
173 * Returns the current classpath.
174 *
175 * @return Current classpath.
176 */
177 public Path getClasspath() {
178 return this.m_classpath;
179 }
180
181 /**
182 * Sets the classpath for this task. Multiple calls append the new classpath
183 * to the current one, rather than overwriting it.
184 *
185 * @param classpath
186 * The new classpath as a Path object.
187 */
188 public void setClasspath(Path classpath) {
189 if (this.m_classpath == null) {
190 this.m_classpath = classpath;
191 } else {
192 this.m_classpath.append(classpath);
193 }
194 }
195
196 /**
197 * Creates the classpath for this task and returns it. If the classpath has
198 * already been created, the method just returns that one.
199 *
200 * @return The created classpath.
201 */
202 public Path createClasspath() {
203 if (this.m_classpath == null) {
204 this.m_classpath = new Path(this.getProject());
205 }
206
207 return this.m_classpath;
208 }
209
210 /**
211 * @param string
212 */
213 public void setMainlafclassname(String string) {
214 this.m_mainLafClassName = string;
215 }
216
217 /**
218 * @param bool
219 */
220 public void setVerbose(boolean bool) {
221 this.m_verbose = bool;
222 }
223 }