Debian Codegraph @

laf-widget/src/main/java/org/pushingpixels/lafwidget/ant/AugmentContainerGhostingTask.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 image ghosting functionality. Is
42 * based on JiBX ant task (BSD-licensed).
43 *
44 * @author Kirill Grouchnikov.
45 */
46 public class AugmentContainerGhostingTask 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 update.
64 */
65 private List<ContainerGhostingType> 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<ContainerGhostingType>();
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 String[] pathArr = this.getPaths();
122 ContainerGhostingAugmenter augmenter = new ContainerGhostingAugmenter();
123 if (this.m_verbose)
124 augmenter.setVerbose(this.m_verbose);
125
126 for (int i = 0; i < pathArr.length; i++) {
127 augmenter.process(pathArr[0], new File(pathArr[0]),
128 this.m_delegatesToUpdate);
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 * Adds information on a single class-method pair for injecting the
145 * container ghosting code.
146 *
147 * @param containerGhosting
148 * Class-method pair for injecting the container ghosting code.
149 */
150 public void addContainerGhosting(ContainerGhostingType containerGhosting) {
151 this.m_delegatesToUpdate.add(containerGhosting);
152 }
153
154 /**
155 * Returns the current classpath.
156 *
157 * @return Current classpath.
158 */
159 public Path getClasspath() {
160 return this.m_classpath;
161 }
162
163 /**
164 * Sets the classpath for this task. Multiple calls append the new classpath
165 * to the current one, rather than overwriting it.
166 *
167 * @param classpath
168 * The new classpath as a Path object.
169 */
170 public void setClasspath(Path classpath) {
171 if (this.m_classpath == null) {
172 this.m_classpath = classpath;
173 } else {
174 this.m_classpath.append(classpath);
175 }
176 }
177
178 /**
179 * Creates the classpath for this task and returns it. If the classpath has
180 * already been created, the method just returns that one.
181 *
182 * @return The created classpath.
183 */
184 public Path createClasspath() {
185 if (this.m_classpath == null) {
186 this.m_classpath = new Path(this.getProject());
187 }
188
189 return this.m_classpath;
190 }
191
192 /**
193 * @param bool
194 */
195 public void setVerbose(boolean bool) {
196 this.m_verbose = bool;
197 }
198 }