~ubuntu-branches/ubuntu/jaunty/ant/jaunty-proposed

« back to all changes in this revision

Viewing changes to src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJExport.java

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Gybas
  • Date: 2002-02-14 14:28:48 UTC
  • Revision ID: james.westby@ubuntu.com-20020214142848-2ww7ynmqkj31vlmn
Tags: upstream-1.4.1
ImportĀ upstreamĀ versionĀ 1.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * The Apache Software License, Version 1.1
 
3
 *
 
4
 * Copyright (c) 1999 The Apache Software Foundation.  All rights 
 
5
 * reserved.
 
6
 *
 
7
 * Redistribution and use in source and binary forms, with or without
 
8
 * modification, are permitted provided that the following conditions
 
9
 * are met:
 
10
 *
 
11
 * 1. Redistributions of source code must retain the above copyright
 
12
 *    notice, this list of conditions and the following disclaimer. 
 
13
 *
 
14
 * 2. Redistributions in binary form must reproduce the above copyright
 
15
 *    notice, this list of conditions and the following disclaimer in
 
16
 *    the documentation and/or other materials provided with the
 
17
 *    distribution.
 
18
 *
 
19
 * 3. The end-user documentation included with the redistribution, if
 
20
 *    any, must include the following acknowlegement:  
 
21
 *       "This product includes software developed by the 
 
22
 *        Apache Software Foundation (http://www.apache.org/)."
 
23
 *    Alternately, this acknowlegement may appear in the software itself,
 
24
 *    if and wherever such third-party acknowlegements normally appear.
 
25
 *
 
26
 * 4. The names "The Jakarta Project", "Ant", and "Apache Software
 
27
 *    Foundation" must not be used to endorse or promote products derived
 
28
 *    from this software without prior written permission. For written 
 
29
 *    permission, please contact apache@apache.org.
 
30
 *
 
31
 * 5. Products derived from this software may not be called "Apache"
 
32
 *    nor may "Apache" appear in their names without prior written
 
33
 *    permission of the Apache Group.
 
34
 *
 
35
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 
36
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
37
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
38
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 
39
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
40
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
41
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 
42
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
43
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
44
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 
45
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
46
 * SUCH DAMAGE.
 
47
 * ====================================================================
 
48
 *
 
49
 * This software consists of voluntary contributions made by many
 
50
 * individuals on behalf of the Apache Software Foundation.  For more
 
51
 * information on the Apache Software Foundation, please see
 
52
 * <http://www.apache.org/>.
 
53
 */
 
54
 
 
55
package org.apache.tools.ant.taskdefs.optional.ide;
 
56
 
 
57
 
 
58
 
 
59
 
 
60
import com.ibm.ivj.util.base.ExportCodeSpec;
 
61
import com.ibm.ivj.util.base.IvjException;
 
62
import com.ibm.ivj.util.base.Package;
 
63
import java.io.File;
 
64
import java.util.Enumeration;
 
65
import java.util.Vector;
 
66
import org.apache.tools.ant.BuildException;
 
67
import org.apache.tools.ant.Project;
 
68
import org.apache.tools.ant.Task;
 
69
import org.apache.tools.ant.types.PatternSet;
 
70
 
 
71
/**
 
72
 * Export packages from the Visual Age for Java workspace. 
 
73
 * The packages are specified similar to all other MatchingTasks. 
 
74
 * Since the VA Workspace is not file based, this task is simulating 
 
75
 * a directory hierarchy for the workspace:
 
76
 * The 'root' contains all project 'dir's, and the projects contain 
 
77
 * their respective package 'dir's.
 
78
 * Example:  
 
79
 * <blockquote> 
 
80
 * &lt;vajexport destdir="C:/builddir/source">
 
81
 * &nbsp;&lt;include name="/MyVAProject/org/foo/subsystem1/**" />
 
82
 * &nbsp;&lt;exclude name="/MyVAProject/org/foo/subsystem1/test/**"/>
 
83
 * &lt;/vajexport>
 
84
 * </blockquote>
 
85
 * exports all packages in the project MyVAProject which start with
 
86
 * 'org.foo.subsystem1' except of these starting with 
 
87
 * 'org.foo.subsystem1.test'.
 
88
 *
 
89
 * There are flags to choose which items to export:
 
90
 * exportSources:   export Java sources
 
91
 * exportResources: export project resources
 
92
 * exportClasses:   export class files
 
93
 * exportDebugInfo: export class files with debug info (use with exportClasses)
 
94
 * default is exporting Java files and resources.
 
95
 *
 
96
 * @author Wolf Siberski, TUI Infotec GmbH
 
97
 */
 
98
 
 
99
public class VAJExport extends Task {
 
100
    protected File destDir;
 
101
    protected boolean exportSources = true;
 
102
    protected boolean exportResources = true;
 
103
    protected boolean exportClasses = false;
 
104
    protected boolean exportDebugInfo = false;
 
105
    protected boolean useDefaultExcludes = true;
 
106
 
 
107
    protected PatternSet patternSet = new PatternSet();
 
108
 
 
109
    /**
 
110
     * add a name entry on the exclude list
 
111
     */
 
112
    public PatternSet.NameEntry createExclude() {
 
113
        return patternSet.createExclude();
 
114
    }
 
115
 
 
116
    /**
 
117
     * add a name entry on the include list
 
118
     */
 
119
    public PatternSet.NameEntry createInclude() {
 
120
        return patternSet.createInclude();
 
121
    }
 
122
 
 
123
    /**
 
124
     * do the export
 
125
     */
 
126
    public void execute() throws BuildException {
 
127
        // first off, make sure that we've got a destdir
 
128
        if (destDir == null) {
 
129
            throw new BuildException("destdir attribute must be set!");
 
130
        }
 
131
 
 
132
        VAJWorkspaceScanner ds = this.getWorkspaceScanner();
 
133
 
 
134
        Package[] packages = ds.getIncludedPackages();
 
135
 
 
136
        export(packages);
 
137
    }
 
138
 
 
139
    /**
 
140
     * export the array of Packages
 
141
     */
 
142
    public void export(Package[] packages) {
 
143
        try {
 
144
            String dest = destDir.getAbsolutePath();
 
145
 
 
146
            log("Exporting " + packages.length + " package(s) to " + dest);
 
147
            for (int i = 0; i < packages.length; i++) {
 
148
                log("    " + packages[i].getName(), Project.MSG_VERBOSE);
 
149
            }
 
150
 
 
151
            ExportCodeSpec exportSpec = new ExportCodeSpec();
 
152
 
 
153
            exportSpec.setPackages(packages);
 
154
            exportSpec.includeJava(exportSources);
 
155
            exportSpec.includeClass(exportClasses);
 
156
            exportSpec.includeResources(exportResources);
 
157
            exportSpec.includeClassDebugInfo(exportDebugInfo);
 
158
            exportSpec.useSubdirectories(true);
 
159
            exportSpec.overwriteFiles(true);
 
160
            exportSpec.setExportDirectory(dest);
 
161
            VAJUtil.getWorkspace().exportData(exportSpec);
 
162
        } catch (IvjException ex) {
 
163
            throw VAJUtil.createBuildException("Exporting failed!", ex);
 
164
        }
 
165
    }
 
166
 
 
167
    /**
 
168
     * Returns the directory scanner needed to access the files to process.
 
169
     */
 
170
    protected VAJWorkspaceScanner getWorkspaceScanner() {
 
171
        VAJWorkspaceScanner scanner = new VAJWorkspaceScanner();
 
172
        scanner.setIncludes(patternSet.getIncludePatterns(getProject()));
 
173
        scanner.setExcludes(patternSet.getExcludePatterns(getProject()));
 
174
        if (useDefaultExcludes)
 
175
            scanner.addDefaultExcludes();
 
176
        scanner.scan();
 
177
        return scanner;
 
178
    }
 
179
 
 
180
    /**
 
181
     * Sets whether default exclusions should be used or not.
 
182
     *
 
183
     * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions 
 
184
     *                           should be used, "false"|"off"|"no" when they
 
185
     *                           shouldn't be used.
 
186
     */
 
187
    public void setDefaultexcludes(boolean useDefaultExcludes) {
 
188
        this.useDefaultExcludes = useDefaultExcludes;
 
189
    }
 
190
 
 
191
    /**
 
192
     * Set the destination directory into which the Java source
 
193
     * files should be compiled.
 
194
     */
 
195
    public void setDestdir(File destDir) {
 
196
        this.destDir = destDir;
 
197
    }
 
198
 
 
199
    /**
 
200
     * Sets the set of exclude patterns. Patterns may be separated by a comma
 
201
     * or a space.
 
202
     *
 
203
     * @param excludes the string containing the exclude patterns
 
204
     */
 
205
    public void setExcludes(String excludes) {
 
206
        patternSet.setExcludes(excludes);
 
207
    }
 
208
 
 
209
    /**
 
210
     */
 
211
    public void setExportClasses(boolean doExport) {
 
212
        exportClasses = doExport;
 
213
    }
 
214
 
 
215
    /**
 
216
     */
 
217
    public void setExportDebugInfo(boolean doExport) {
 
218
        exportDebugInfo = doExport;
 
219
    }
 
220
 
 
221
    /**
 
222
     */
 
223
    public void setExportResources(boolean doExport) {
 
224
        exportResources = doExport;
 
225
    }
 
226
 
 
227
    /**
 
228
     */
 
229
    public void setExportSources(boolean doExport) {
 
230
        exportSources = doExport;
 
231
    }
 
232
    /**
 
233
     * Sets the set of include patterns. Patterns may be separated by a comma
 
234
     * or a space.
 
235
     *
 
236
     * @param includes the string containing the include patterns
 
237
     */
 
238
    public void setIncludes(String includes) {
 
239
        patternSet.setIncludes(includes);
 
240
    }
 
241
}