From 05bcfa85d3ca58b3f14a8b5cabb8fc299ef6862a Mon Sep 17 00:00:00 2001
From: glennm
+ * Example:
+ *
+ * <vajexport destdir="C:/builddir/source">
+ * <include name="/MyVAProject/org/foo/subsystem1/**" />
+ * <exclude name="/MyVAProject/org/foo/subsystem1/test/**"/>
+ * </vajexport>
+ *
+ * exports all packages in the project MyVAProject which start with
+ * 'org.foo.subsystem1' except of these starting with
+ * 'org.foo.subsystem1.test'.
+ *
+ * There are flags to choose which items to export:
+ * exportSources: export Java sources
+ * exportResources: export project resources
+ * exportClasses: export class files
+ * exportDebugInfo: export class files with debug info (use with exportClasses)
+ * default is exporting Java files and resources.
+ *
+ * @author Wolf Siberski, TUI Infotec GmbH
+ */
+
+public class VAJExport extends Task {
+ protected File destDir;
+ protected boolean exportSources = true;
+ protected boolean exportResources = true;
+ protected boolean exportClasses = false;
+ protected boolean exportDebugInfo = false;
+ protected boolean useDefaultExcludes = true;
+
+ protected PatternSet patternSet = new PatternSet();
+
+ /**
+ * add a name entry on the exclude list
+ */
+ public PatternSet.NameEntry createExclude() {
+ return patternSet.createExclude();
+ }
+
+ /**
+ * add a name entry on the include list
+ */
+ public PatternSet.NameEntry createInclude() {
+ return patternSet.createInclude();
+ }
+
+ /**
+ * do the export
+ */
+ public void execute() throws BuildException {
+ // first off, make sure that we've got a destdir
+ if (destDir == null) {
+ throw new BuildException("destdir attribute must be set!");
+ }
+
+ VAJWorkspaceScanner ds = this.getWorkspaceScanner();
+
+ Package[] packages = ds.getIncludedPackages();
+
+ export(packages);
+ }
+
+ /**
+ * export the array of Packages
+ */
+ public void export(Package[] packages) {
+ try {
+ String dest = destDir.getAbsolutePath();
+
+ log("Exporting " + packages.length + " package(s) to " + dest);
+ for (int i = 0; i < packages.length; i++) {
+ log(" " + packages[i].getName(), Project.MSG_VERBOSE);
+ }
+
+ ExportCodeSpec exportSpec = new ExportCodeSpec();
+
+ exportSpec.setPackages(packages);
+ exportSpec.includeJava(exportSources);
+ exportSpec.includeClass(exportClasses);
+ exportSpec.includeResources(exportResources);
+ exportSpec.includeClassDebugInfo(exportDebugInfo);
+ exportSpec.useSubdirectories(true);
+ exportSpec.overwriteFiles(true);
+ exportSpec.setExportDirectory(dest);
+ VAJUtil.getWorkspace().exportData(exportSpec);
+ } catch (IvjException ex) {
+ throw VAJUtil.createBuildException("Exporting failed!", ex);
+ }
+ }
+
+ /**
+ * Returns the directory scanner needed to access the files to process.
+ */
+ protected VAJWorkspaceScanner getWorkspaceScanner() {
+ VAJWorkspaceScanner scanner = new VAJWorkspaceScanner();
+ scanner.setIncludes(patternSet.getIncludePatterns(getProject()));
+ scanner.setExcludes(patternSet.getExcludePatterns(getProject()));
+ if (useDefaultExcludes)
+ scanner.addDefaultExcludes();
+ scanner.scan();
+ return scanner;
+ }
+
+ /**
+ * Sets whether default exclusions should be used or not.
+ *
+ * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions
+ * should be used, "false"|"off"|"no" when they
+ * shouldn't be used.
+ */
+ public void setDefaultexcludes(boolean useDefaultExcludes) {
+ this.useDefaultExcludes = useDefaultExcludes;
+ }
+
+ /**
+ * Set the destination directory into which the Java source
+ * files should be compiled.
+ */
+ public void setDestdir(File destDir) {
+ this.destDir = destDir;
+ }
+
+ /**
+ * Sets the set of exclude patterns. Patterns may be separated by a comma
+ * or a space.
+ *
+ * @param excludes the string containing the exclude patterns
+ */
+ public void setExcludes(String excludes) {
+ patternSet.setExcludes(excludes);
+ }
+
+ /**
+ */
+ public void setExportClasses(boolean doExport) {
+ exportClasses = doExport;
+ }
+
+ /**
+ */
+ public void setExportDebugInfo(boolean doExport) {
+ exportDebugInfo = doExport;
+ }
+
+ /**
+ */
+ public void setExportResources(boolean doExport) {
+ exportResources = doExport;
+ }
+
+ /**
+ */
+ public void setExportSources(boolean doExport) {
+ exportSources = doExport;
+ }
+ /**
+ * Sets the set of include patterns. Patterns may be separated by a comma
+ * or a space.
+ *
+ * @param includes the string containing the include patterns
+ */
+ public void setIncludes(String includes) {
+ patternSet.setIncludes(includes);
+ }
+}
\ No newline at end of file
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJImport.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJImport.java
new file mode 100644
index 000000000..6405f236b
--- /dev/null
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJImport.java
@@ -0,0 +1,322 @@
+package org.apache.tools.ant.taskdefs.optional.ide;
+
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ *
+ * <vajimport project="MyVAProject">
+ * <fileset dir="src">
+ * <include name="org/foo/subsystem1/**" />
+ * <exclude name="/org/foo/subsystem1/test/**" />
+ * </fileset>
+ * </vajexport>
+ *
+ * import all source and resource files from the "src" directory
+ * which start with 'org.foo.subsystem1', except of these starting with
+ * 'org.foo.subsystem1.test' into the project MyVAProject.
+ *
If MyVAProject isn't loaded into the Workspace, a new edition is + * created in the repository and automatically loaded into the Workspace. + * There has to be at least one nested FileSet element. + *
+ *There are attributes to choose which items to export: + *
Attribute | + *Description | + *Required | + *
project | + *the name of the Project to import to | + *Yes | + *
importSources | + *import Java sources, defaults to "yes" | + *No | + *
importResources | + *import resource files (anything that doesn't + * end with .java or .class), defaults to "yes" | + *No | + *
importClasses | + *import class files, defaults to "no" | + *No | + *
+ * <vajload> + * <project name="MyVAProject" version="2.1"/> + * <project name="Apache Xerces" version="1.2.0"/> + * </vajload> + *+ * + * @author Wolf Siberski, TUI Infotec GmbH + */ + +public class VAJLoadProjects extends Task { + Vector projectDescriptions = new Vector(); + Vector expandedProjectDescriptions = new Vector(); + + /** + * Class to maintain VisualAge for Java Workspace Project descriptions. + */ + public class VAJProjectDescription { + private String name; + private String version; + private boolean projectFound; + + public VAJProjectDescription() { + } + + public VAJProjectDescription(String n, String v) { + name = n; + version = v; + } + + public String getName() { + return name; + } + + public String getVersion() { + return version; + } + + public boolean projectFound() { + return projectFound; + } + + public void setName(String newName) { + if (newName == null || newName.equals("")) { + throw new BuildException("name attribute must be set"); + } + name = newName; + } + + public void setVersion(String newVersion) { + if (newVersion == null || newVersion.equals("")) { + throw new BuildException("version attribute must be set"); + } + version = newVersion; + } + + public void setProjectFound() { + projectFound = true; + } + } + + /** + * Add a project description entry on the project list. + */ + public VAJProjectDescription createProject() { + VAJProjectDescription d = new VAJProjectDescription(); + projectDescriptions.addElement(d); + return d; + } + /** + * Load specified projects. + */ + public void execute() { + expandDescriptions(); + log( + "Loading " + expandedProjectDescriptions.size() + " project(s) into workspace"); + for (Enumeration e = expandedProjectDescriptions.elements(); + e.hasMoreElements(); + ) { + VAJProjectDescription d = (VAJProjectDescription) e.nextElement(); + + ProjectEdition pe = findProjectEdition(d.getName(), d.getVersion()); + try { + log( + "Loading " + d.getName() + ", Version " + d.getVersion() + ", into Workspace", + Project.MSG_VERBOSE); + pe.loadIntoWorkspace(); + } catch (IvjException ex) { + throw VAJUtil.createBuildException( + "Project " + d.getName() + " could not be loaded.", + ex); + } + } + } + + /** + */ + public void expandDescriptions() { + String[] projectNames; + try { + projectNames = VAJUtil.getWorkspace().getRepository().getProjectNames(); + } catch (IvjException e) { + throw VAJUtil.createBuildException("VA Exception occured: ", e); + } + + for (int i = 0; i < projectNames.length; i++) { + for (Enumeration e = projectDescriptions.elements(); e.hasMoreElements();) { + VAJProjectDescription d = (VAJProjectDescription) e.nextElement(); + String pattern = d.getName(); + if (VAJWorkspaceScanner.match(pattern, projectNames[i])) { + d.setProjectFound(); + expandedProjectDescriptions.addElement( + new VAJProjectDescription(projectNames[i], d.getVersion())); + break; + } + } + } + + for (Enumeration e = projectDescriptions.elements(); e.hasMoreElements();) { + VAJProjectDescription d = (VAJProjectDescription) e.nextElement(); + if (!d.projectFound()) { + log("No Projects match the name " + d.getName(), Project.MSG_WARN); + } + } + } + + /** + */ + public static Vector findMatchingProjects(String pattern) { + String[] projectNames; + try { + projectNames = VAJUtil.getWorkspace().getRepository().getProjectNames(); + } catch (IvjException e) { + throw VAJUtil.createBuildException("VA Exception occured: ", e); + } + + Vector matchingProjects = new Vector(); + for (int i = 0; i < projectNames.length; i++) { + if (VAJWorkspaceScanner.match(pattern, projectNames[i])) { + matchingProjects.addElement(projectNames[i]); + } + } + + return matchingProjects; + } + + /** + * Finds a specific project edition in the repository. + * + * @param name project name + * @param versionName project version name + * @return com.ibm.ivj.util.base.ProjectEdition + */ + public static ProjectEdition findProjectEdition( + String name, + String versionName) { + try { + ProjectEdition[] editions = null; + editions = VAJUtil.getWorkspace().getRepository().getProjectEditions(name); + + if (editions == null) { + throw new BuildException("Project " + name + " doesn't exist"); + } + + ProjectEdition pe = null; + + for (int i = 0; i < editions.length && pe == null; i++) { + if (versionName.equals(editions[i].getVersionName())) { + pe = editions[i]; + } + } + if (pe == null) { + throw new BuildException( + "Version " + versionName + " of Project " + name + " doesn't exist"); + } + return pe; + + } catch (IvjException e) { + throw VAJUtil.createBuildException("VA Exception occured: ", e); + } + + } +} \ No newline at end of file diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJUtil.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJUtil.java new file mode 100644 index 000000000..10852dc9f --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJUtil.java @@ -0,0 +1,108 @@ +package org.apache.tools.ant.taskdefs.optional.ide; + +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + *
+ * These criteria consist of a set of include and exclude patterns. With these + * patterns, you can select which packages you want to have included, and which + * packages you want to have excluded. You can add patterns to be excluded by + * default with the addDefaultExcludes method. The patters that are excluded + * by default include + *
+ * This class works like DirectoryScanner.
+ *
+ * @see org.apache.tools.ant.DirectoryScanner
+ *
+ * @author Wolf Siberski, TUI Infotec (based on Arnout J. Kuipers DirectoryScanner)
+ */
+public class VAJWorkspaceScanner extends DirectoryScanner {
+
+ /**
+ * Patterns that should be excluded by default.
+ *
+ * @see #addDefaultExcludes()
+ */
+ private final static String[] DEFAULTEXCLUDES =
+ {
+ "IBM*/**",
+ "Java class libraries/**",
+ "Sun class libraries*/**",
+ "JSP Page Compile Generated Code/**",
+ "VisualAge*/**",
+ };
+
+ /**
+ * The packages that where found and matched at least one includes, and
+ * matched no excludes.
+ */
+ private Vector packagesIncluded = new Vector();
+
+ /**
+ * Adds the array with default exclusions to the current exclusions set.
+ */
+ public void addDefaultExcludes() {
+ int excludesLength = excludes == null ? 0 : excludes.length;
+ String[] newExcludes;
+ newExcludes = new String[excludesLength + DEFAULTEXCLUDES.length];
+ if (excludesLength > 0) {
+ System.arraycopy(excludes, 0, newExcludes, 0, excludesLength);
+ }
+ for (int i = 0; i < DEFAULTEXCLUDES.length; i++) {
+ newExcludes[i + excludesLength] =
+ DEFAULTEXCLUDES[i].replace('/', File.separatorChar).replace(
+ '\\',
+ File.separatorChar);
+ }
+ excludes = newExcludes;
+ }
+
+ /**
+ * Finds all Projects specified in include patterns.
+ *
+ * @return the projects
+ */
+ public Vector findMatchingProjects() {
+ Project[] projects = VAJUtil.getWorkspace().getProjects();
+
+ Vector matchingProjects = new Vector();
+
+ boolean allProjectsMatch = false;
+ for (int i = 0; i < projects.length; i++) {
+ Project project = projects[i];
+ for (int j = 0; j < includes.length && !allProjectsMatch; j++) {
+ StringTokenizer tok = new StringTokenizer(includes[j], File.separator);
+ String projectNamePattern = tok.nextToken();
+ if (projectNamePattern.equals("**")) {
+ // if an include pattern starts with '**',
+ // all projects match
+ allProjectsMatch = true;
+ } else
+ if (match(projectNamePattern, project.getName())) {
+ matchingProjects.addElement(project);
+ break;
+ }
+ }
+ }
+
+ if (allProjectsMatch) {
+ matchingProjects = new Vector();
+ for (int i = 0; i < projects.length; i++) {
+ matchingProjects.addElement(projects[i]);
+ }
+ }
+
+ return matchingProjects;
+ }
+
+ /**
+ * Get the names of the packages that matched at least one of the include
+ * patterns, and didn't match one of the exclude patterns.
+ *
+ * @return the matching packages
+ */
+ public Package[] getIncludedPackages() {
+ int count = packagesIncluded.size();
+ Package[] packages = new Package[count];
+ for (int i = 0; i < count; i++) {
+ packages[i] = (Package) packagesIncluded.elementAt(i);
+ }
+ return packages;
+ }
+
+ /**
+ * Matches a string against a pattern. The pattern contains two special
+ * characters:
+ * '*' which means zero or more characters,
+ * '?' which means one and only one character.
+ *
+ * @param pattern the (non-null) pattern to match against
+ * @param str the (non-null) string that must be matched against the
+ * pattern
+ *
+ * @return true
when the string matches against the pattern,
+ * false
otherwise.
+ */
+ protected static boolean match(String pattern, String str) {
+ return DirectoryScanner.match(pattern, str);
+ }
+ /**
+ * Scans the workspace for packages that match at least one include
+ * pattern, and don't match any exclude patterns.
+ *
+ */
+ public void scan() {
+ if (includes == null) {
+ // No includes supplied, so set it to 'matches all'
+ includes = new String[1];
+ includes[0] = "**";
+ }
+ if (excludes == null) {
+ excludes = new String[0];
+ }
+
+ // only scan projects which are included in at least one include pattern
+ Vector matchingProjects = findMatchingProjects();
+ for (Enumeration e = matchingProjects.elements(); e.hasMoreElements();) {
+ Project project = (Project) e.nextElement();
+ scanProject(project);
+ }
+ }
+
+ /**
+ * Scans a project for packages that match at least one include
+ * pattern, and don't match any exclude patterns.
+ *
+ */
+ public void scanProject(Project project) {
+ try {
+ Package[] packages = project.getPackages();
+ if (packages != null) {
+ for (int i = 0; i < packages.length; i++) {
+ Package item = packages[i];
+ // replace '.' by file seperator because the patterns are
+ // using file seperator syntax (and we can use the match
+ // methods this way).
+ String name =
+ project.getName()
+ + File.separator
+ + item.getName().replace('.', File.separatorChar);
+ if (isIncluded(name) && !isExcluded(name)) {
+ packagesIncluded.addElement(item);
+ }
+ }
+ }
+ } catch (IvjException e) {
+ throw VAJUtil.createBuildException("VA Exception occured: ", e);
+ }
+ }
+}
\ No newline at end of file