001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.tools.ant.taskdefs.optional.ejb;
019:
020: import java.io.File;
021: import org.apache.tools.ant.BuildException;
022: import org.apache.tools.ant.DirectoryScanner;
023: import org.apache.tools.ant.taskdefs.Java;
024: import org.apache.tools.ant.taskdefs.MatchingTask;
025: import org.apache.tools.ant.types.Commandline;
026: import org.apache.tools.ant.types.Path;
027: import org.apache.tools.ant.util.FileUtils;
028:
029: /**
030: * Builds a serialized deployment descriptor given a text file description of the
031: * descriptor in the format supported by WebLogic.
032: *
033: * This ant task is a front end for the weblogic DDCreator tool.
034: *
035: */
036: public class DDCreator extends MatchingTask {
037: /**
038: * The root directory of the tree containing the textual deployment descriptors. The actual
039: * deployment descriptor files are selected using include and exclude constructs
040: * on the EJBC task, as supported by the MatchingTask superclass.
041: */
042: private File descriptorDirectory;
043:
044: /**
045: * The directory where generated serialised deployment descriptors are placed.
046: */
047: private File generatedFilesDirectory;
048:
049: /**
050: * The classpath to be used in the weblogic ejbc calls. It must contain the weblogic
051: * classes necessary fro DDCreator <b>and</b> the implementation classes of the
052: * home and remote interfaces.
053: */
054: private String classpath;
055:
056: /**
057: * Do the work.
058: *
059: * The work is actually done by creating a helper task. This approach allows
060: * the classpath of the helper task to be set. Since the weblogic tools require
061: * the class files of the project's home and remote interfaces to be available in
062: * the classpath, this also avoids having to start ant with the class path of the
063: * project it is building.
064: *
065: * @exception BuildException if something goes wrong with the build
066: */
067: public void execute() throws BuildException {
068: if (descriptorDirectory == null
069: || !descriptorDirectory.isDirectory()) {
070: throw new BuildException("descriptors directory "
071: + descriptorDirectory.getPath() + " is not valid");
072: }
073: if (generatedFilesDirectory == null
074: || !generatedFilesDirectory.isDirectory()) {
075: throw new BuildException("dest directory "
076: + generatedFilesDirectory.getPath()
077: + " is not valid");
078: }
079:
080: String args = descriptorDirectory + " "
081: + generatedFilesDirectory;
082:
083: // get all the files in the descriptor directory
084: DirectoryScanner ds = super
085: .getDirectoryScanner(descriptorDirectory);
086:
087: String[] files = ds.getIncludedFiles();
088:
089: for (int i = 0; i < files.length; ++i) {
090: args += " " + files[i];
091: }
092:
093: String systemClassPath = System.getProperty("java.class.path");
094: String execClassPath = FileUtils.translatePath(systemClassPath
095: + ":" + classpath);
096: Java ddCreatorTask = new Java(this );
097: ddCreatorTask.setFork(true);
098: ddCreatorTask
099: .setClassname("org.apache.tools.ant.taskdefs.optional.ejb.DDCreatorHelper");
100: Commandline.Argument arguments = ddCreatorTask.createArg();
101: arguments.setLine(args);
102: ddCreatorTask
103: .setClasspath(new Path(getProject(), execClassPath));
104: if (ddCreatorTask.executeJava() != 0) {
105: throw new BuildException(
106: "Execution of ddcreator helper failed");
107: }
108: }
109:
110: /**
111: * Set the directory from where the text descriptions of the deployment descriptors are
112: * to be read.
113: *
114: * @param dirName the name of the directory containing the text deployment descriptor files.
115: */
116: public void setDescriptors(String dirName) {
117: descriptorDirectory = new File(dirName);
118: }
119:
120: /**
121: * Set the directory into which the serialized deployment descriptors are to
122: * be written.
123: *
124: * @param dirName the name of the directory into which the serialised deployment
125: * descriptors are written.
126: */
127: public void setDest(String dirName) {
128: generatedFilesDirectory = new File(dirName);
129: }
130:
131: /**
132: * Set the classpath to be used for this compilation.
133: *
134: * @param s the classpath to use for the ddcreator tool.
135: */
136: public void setClasspath(String s) {
137: this.classpath = FileUtils.translatePath(s);
138: }
139: }
|