Debian Codegraph @

laf-widget/src/main/java/org/pushingpixels/lafwidget/ant/AugmentIconGhostingTask.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 LAF classes with icon ghosting functionality. Is
42 * based on JiBX ant task (BSD-licensed).
43 *
44 * @author Kirill Grouchnikov.
45 */
46 public class AugmentIconGhostingTask 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 * List of delegates to create.
64 */
65 private List<IconGhostingType> m_delegatesToUpdate;
66
67 /*
68 * (non-Javadoc)
69 *
70 * @see org.apache.tools.ant.Task#init()
71 */
72 @Override
73 public void init() throws BuildException {
74 super.init();
75 this.m_fileSet = new ArrayList<FileSet>();
76 this.m_delegatesToUpdate = new ArrayList<IconGhostingType>();
77 }
78
79 /**
80 * Returns an array of paths of all the files specified by the
81 * &lt;classpath&gt; or &lt;classpathset&gt; tags. Note that the
82 * &lt;classpath&gt; and &lt;classpathset&gt; tags cannot both be specified.
83 *
84 * @return Array of file paths.
85 */
86 private String[] getPaths() {
87 String[] pathArray = null;
88 if (this.m_classpath != null) {
89 //
90 // If a <classpath> tag has been set, m_classpath will
91 // not be null. In this case, just return the array of
92 // paths directly.
93 //
94 pathArray = this.m_classpath.list();
95 } else {
96 //
97 // Store the directory paths specified by each of the
98 // <classpathset> tags.
99 //
100 pathArray = new String[this.m_fileSet.size()];
101
102 for (int i = 0; i < this.m_fileSet.size(); i++) {
103 FileSet fileSet = this.m_fileSet.get(i);
104 File directory = fileSet.getDir(this.getProject());
105 pathArray[i] = directory.getAbsolutePath();
106 }
107 }
108 return pathArray;
109 }
110
111 /*
112 * (non-Javadoc)
113 *
114 * @see org.apache.tools.ant.Task#execute()
115 */
116 @Override
117 public void execute() throws BuildException {
118 try {
119 // System.out.println(this.m_verbose + ", " + this.m_pattern);
120 //
121
122 for (Iterator<IconGhostingType> it = this.m_delegatesToUpdate
123 .iterator(); it.hasNext();) {
124 IconGhostingType igt = it.next();
125 if (this.m_verbose)
126 System.out.println("Will inject icon ghosting code in "
127 + igt.getClassName() + "." + igt.getMethodName());
128 }
129
130 String[] pathArr = this.getPaths();
131 IconGhostingAugmenter augmenter = new IconGhostingAugmenter();
132 if (this.m_verbose)
133 augmenter.setVerbose(this.m_verbose);
134
135 for (int i = 0; i < pathArr.length; i++) {
136 augmenter.process(pathArr[0], new File(pathArr[0]),
137 this.m_delegatesToUpdate);
138 }
139 } catch (AugmentException ae) {
140 throw new BuildException(ae);
141 }
142 // process(this.m_classpath, new File(args[0]), p);
143 }
144
145 /**
146 * @param fSet
147 */
148 public void addClassPathSet(FileSet fSet) {
149 this.m_fileSet.add(fSet);
150 }
151
152 /**
153 * Adds information on a single class-method pair for injecting the icon
154 * ghosting code.
155 *
156 * @param iconGhosting
157 * Class-method pair for injecting the icon ghosting code.
158 */
159 public void addIconGhosting(IconGhostingType iconGhosting) {
160 this.m_delegatesToUpdate.add(iconGhosting);
161 }
162
163 /**
164 * Returns the current classpath.
165 *
166 * @return Current classpath.
167 */
168 public Path getClasspath() {
169 return this.m_classpath;
170 }
171
172 /**
173 * Sets the classpath for this task. Multiple calls append the new classpath
174 * to the current one, rather than overwriting it.
175 *
176 * @param classpath
177 * The new classpath as a Path object.
178 */
179 public void setClasspath(Path classpath) {
180 if (this.m_classpath == null) {
181 this.m_classpath = classpath;
182 } else {
183 this.m_classpath.append(classpath);
184 }
185 }
186
187 /**
188 * Creates the classpath for this task and returns it. If the classpath has
189 * already been created, the method just returns that one.
190 *
191 * @return The created classpath.
192 */
193 public Path createClasspath() {
194 if (this.m_classpath == null) {
195 this.m_classpath = new Path(this.getProject());
196 }
197
198 return this.m_classpath;
199 }
200
201 /**
202 * @param bool
203 */
204 public void setVerbose(boolean bool) {
205 this.m_verbose = bool;
206 }
207 }