source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJImport.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 6.9 KB
Line 
1/*
2 * Copyright 2001-2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17package org.apache.tools.ant.taskdefs.optional.ide;
18
19
20import java.util.Enumeration;
21import java.util.Vector;
22import org.apache.tools.ant.BuildException;
23import org.apache.tools.ant.DirectoryScanner;
24import org.apache.tools.ant.types.FileSet;
25
26/**
27 * Import source, class files, and resources to the Visual Age for Java
28 * workspace.
29 * <p>
30 * Example:
31 * <pre>
32 * &lt;vajimport project="MyVAProject"&gt;
33 * &lt;fileset dir="src"&gt;
34 * &lt;include name="org/foo/subsystem1/**" /&gt;
35 * &lt;exclude name="/org/foo/subsystem1/test/**" /&gt;
36 * &lt;/fileset&gt;
37 * &lt;/vajexport&gt;
38 * </pre>
39 * import all source and resource files from the "src" directory
40 * which start with 'org.foo.subsystem1', except of these starting with
41 * 'org.foo.subsystem1.test' into the project MyVAProject.
42 * </p>
43 * <p>If MyVAProject isn't loaded into the Workspace, a new edition is
44 * created in the repository and automatically loaded into the Workspace.
45 * There has to be at least one nested FileSet element.
46 * </p>
47 * <p>Parameters:
48 * <table border="1" cellpadding="2" cellspacing="0">
49 * <tr>
50 * <td valign="top"><b>Attribute</b></td>
51 * <td valign="top"><b>Description</b></td>
52 * <td align="center" valign="top"><b>Required</b></td>
53 * </tr>
54 * <tr>
55 * <td valign="top">project</td>
56 * <td valign="top">the name of the Project to import to</td>
57 * <td align="center" valign="top">Yes</td>
58 * </tr>
59 * <tr>
60 * <td valign="top">importSources</td>
61 * <td valign="top">import Java sources, defaults to "yes"</td>
62 * <td align="center" valign="top">No</td>
63 * </tr>
64 * <tr>
65 * <td valign="top">importResources</td>
66 * <td valign="top">import resource files (anything that doesn't
67 * end with .java or .class), defaults to "yes"</td>
68 * <td align="center" valign="top">No</td>
69 * </tr>
70 * <tr>
71 * <td valign="top">importClasses</td>
72 * <td valign="top">import class files, defaults to "no"</td>
73 * <td align="center" valign="top">No</td>
74 * </tr>
75 * <tr>
76 * <td valign="top">remote</td>
77 * <td valign="top">remote tool server to run this command against
78 * (format: &lt;servername&gt; : &lt;port no&gt;)</td>
79 * <td align="center" valign="top">No</td>
80 * </tr>
81 * <tr>
82 * <td valign="top">haltonerror</td>
83 * <td valign="top">stop the build process if an error occurs,
84 * defaults to "yes"</td>
85 * <td align="center" valign="top">No</td>
86 * </tr>
87 * </table>
88 *
89 */
90public class VAJImport extends VAJTask {
91 protected Vector filesets = new Vector();
92 protected boolean importSources = true;
93 protected boolean importResources = true;
94 protected boolean importClasses = false;
95 protected String importProject = null;
96 protected boolean useDefaultExcludes = true;
97
98
99 /**
100 * Extended DirectoryScanner that has accessors for the
101 * includes and excludes fields.
102 *
103 * This is kindof a hack to get includes and excludes
104 * from the directory scanner. In order to keep
105 * the URLs short we only want to send the patterns to the
106 * remote tool server and let him figure out the files.
107 *
108 * This replaces the former reflection hack that
109 * didn't compile for old JDKs.
110 *
111 * @see VAJImport#importFileSet(FileSet)
112 */
113 private static class LocalDirectoryScanner extends DirectoryScanner {
114 public String[] getIncludes() { return includes; }
115 public String[] getExcludes() { return excludes; }
116 }
117
118 /**
119 * The VisualAge for Java Project name to import into.
120 */
121 public void setProject(String projectName) {
122 this.importProject = projectName;
123 }
124
125 /**
126 * Adds a set of files (nested fileset attribute).
127 */
128 public void addFileset(FileSet set) {
129 filesets.addElement(set);
130 }
131
132 /**
133 * Flag to import .class files; optional, default false.
134 */
135 public void setImportClasses(boolean importClasses) {
136 this.importClasses = importClasses;
137 }
138
139 /**
140 * Import resource files (anything that doesn't end in
141 * .class or .java); optional, default true.
142 */
143 public void setImportResources(boolean importResources) {
144 this.importResources = importResources;
145 }
146
147 /**
148 * Import .java files; optional, default true.
149 */
150 public void setImportSources(boolean importSources) {
151 this.importSources = importSources;
152 }
153
154 /**
155 * Sets whether default exclusions should be used or not.
156 *
157 * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions
158 * should be used, "false"|"off"|"no" when they
159 * shouldn't be used.
160 */
161 public void setDefaultexcludes(boolean useDefaultExcludes) {
162 this.useDefaultExcludes = useDefaultExcludes;
163 }
164
165 /**
166 * Do the import.
167 */
168 public void execute() throws BuildException {
169 if (filesets.size() == 0) {
170 throw new BuildException("At least one fileset is required!");
171 }
172
173 if (importProject == null || "".equals(importProject)) {
174 throw new BuildException("The VisualAge for Java Project name is required!");
175 }
176
177 try {
178 for (Enumeration e = filesets.elements(); e.hasMoreElements();) {
179 importFileset((FileSet) e.nextElement());
180 }
181 } catch (BuildException ex) {
182 if (haltOnError) {
183 throw ex;
184 } else {
185 log(ex.toString());
186 }
187 }
188 }
189
190 /**
191 * Import all files from the fileset into the Project in the
192 * Workspace.
193 */
194 protected void importFileset(FileSet fileset) {
195 LocalDirectoryScanner ds = new LocalDirectoryScanner();
196 fileset.setupDirectoryScanner(ds, this.getProject());
197 ds.scan();
198 if (ds.getIncludedFiles().length == 0) {
199 return;
200 }
201
202 String[] includes = ds.getIncludes();
203 String[] excludes = ds.getExcludes();
204
205 getUtil().importFiles(importProject, ds.getBasedir(),
206 includes, excludes,
207 importClasses, importResources, importSources,
208 useDefaultExcludes);
209 }
210}
Note: See TracBrowser for help on using the repository browser.