001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.xslt.project.anttasks;
020:
021: import java.io.File;
022: import java.util.ArrayList;
023: import java.util.List;
024:
025: import org.apache.tools.ant.BuildException;
026: import org.apache.tools.ant.Task;
027: import org.apache.tools.ant.AntClassLoader;
028: import org.apache.tools.ant.types.Reference;
029:
030: import java.util.StringTokenizer;
031:
032: import java.util.logging.Logger;
033:
034: import org.netbeans.modules.xslt.project.CommandlineXsltProjectXmlCatalogProvider;
035:
036: /**
037: * Ant task wrapper which invokes the JBI Generation task
038: * @author Vitaly Bychkov
039: * @author Sreenivasan Genipudi
040: */
041: public class GenerateJBIDescriptor extends org.apache.tools.ant.Task {
042:
043: /**
044: * Source directory
045: */
046: private String mSourceDirectory = null;
047: /**
048: * Build directory
049: */
050: private String mBuildDirectory = null;
051: /**
052: * Project classpath
053: */
054: private String mProjectClassPath = null;
055: /**
056: * Classpath Reference
057: */
058: private Reference m_ref = null;
059:
060: /**
061: * Logger instance
062: */
063: private Logger logger = Logger
064: .getLogger(GenerateJBIDescriptor.class.getName());
065:
066: public GenerateJBIDescriptor() {
067: }
068:
069: /**
070: * Set the classpath reference
071: * @param ref Classpath Reference
072: */
073: public void setClasspathRef(Reference ref) {
074: this .m_ref = ref;
075: }
076:
077: /**
078: * Set the build directory
079: * @param buildDir build directory
080: */
081: public void setBuildDirectory(String buildDir) {
082: mBuildDirectory = buildDir;
083: }
084:
085: /**
086: * Get the build directory
087: * @return String value of the build directory
088: */
089: public String getBuildDirectory() {
090: return mBuildDirectory;
091: }
092:
093: /**
094: * Set the source directory
095: * @param srcDir source directory
096: */
097: public void setSourceDirectory(String srcDir) {
098: this .mSourceDirectory = srcDir;
099: }
100:
101: /**
102: * Get the source directory
103: * @return String value of the source directory
104: */
105: public String getSourceDirectory() {
106: return this .mSourceDirectory;
107: }
108:
109: /**
110: * Set the project classpath
111: * @param projectClassPath Project classpath
112: */
113: public void setProjectClassPath(String projectClassPath) {
114: this .mProjectClassPath = projectClassPath;
115: }
116:
117: /**
118: * Invoke the task that generates the JBI.xml
119: */
120: public void execute() throws BuildException {
121: if (this .mSourceDirectory == null) {
122: throw new BuildException(
123: "No directory is set for source files.");
124: }
125:
126: File sourceDirectory = new File(this .mSourceDirectory);
127: File buildDirectory = new File(this .mBuildDirectory);
128:
129: //read project classpath
130: //TODO: refactor this to use wsdl classpath
131: List<File> projectDirs = new ArrayList<File>();
132: if (this .mProjectClassPath != null
133: && !this .mProjectClassPath.trim().equals("")
134: && !this .mProjectClassPath.trim().equals(
135: "${javac.classpath}")) {
136: StringTokenizer st = new StringTokenizer(
137: this .mProjectClassPath, ";");
138: while (st.hasMoreTokens()) {
139: String spath = st.nextToken();
140: try {
141:
142: File sFile = new File(sourceDirectory
143: .getParentFile().getCanonicalPath()
144: + File.separator + spath);
145:
146: File srcFolder = new File(sFile.getParentFile()
147: .getParentFile().getCanonicalFile(), "src");
148: projectDirs.add(srcFolder);
149: } catch (Exception ex) {
150: throw new BuildException(
151: "Failed to create File object for dependent project path "
152: + spath);
153: }
154: }
155: }
156:
157: //find the owner project
158: if (sourceDirectory != null) {
159: List<File> srcList = new ArrayList<File>();
160: srcList.add(sourceDirectory);
161: if (buildDirectory != null) {
162: srcList.add(buildDirectory);
163: }
164:
165: CommandlineXsltProjectXmlCatalogProvider.getInstance()
166: .setSourceDirectory(this .mSourceDirectory);
167: JBIGenerator generator = new JBIGenerator(projectDirs,
168: srcList, mSourceDirectory, mBuildDirectory);
169: generator.generate();
170: }
171:
172: }
173:
174: public static void main(String[] args) {
175: GenerateJBIDescriptor dd = new GenerateJBIDescriptor();
176:
177: }
178: }
|