[14627] | 1 | /*
|
---|
| 2 | * Copyright 2000,2002,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 | */
|
---|
| 17 | package org.apache.tools.ant.taskdefs.optional.ejb;
|
---|
| 18 |
|
---|
| 19 | import java.io.File;
|
---|
| 20 | import org.apache.tools.ant.BuildException;
|
---|
| 21 | import org.apache.tools.ant.DirectoryScanner;
|
---|
| 22 | import org.apache.tools.ant.taskdefs.Java;
|
---|
| 23 | import org.apache.tools.ant.taskdefs.MatchingTask;
|
---|
| 24 | import org.apache.tools.ant.types.Commandline;
|
---|
| 25 | import org.apache.tools.ant.types.Path;
|
---|
| 26 |
|
---|
| 27 | /**
|
---|
| 28 | * Builds EJB support classes using WebLogic's ejbc tool from a directory containing
|
---|
| 29 | * a set of deployment descriptors.
|
---|
| 30 | *
|
---|
| 31 | *
|
---|
| 32 | */
|
---|
| 33 | public class Ejbc extends MatchingTask {
|
---|
| 34 | /**
|
---|
| 35 | * The root directory of the tree containing the serialised deployment desciptors. The actual
|
---|
| 36 | * deployment descriptor files are selected using include and exclude constructs
|
---|
| 37 | * on the ejbc task provided by the MatchingTask superclass.
|
---|
| 38 | */
|
---|
| 39 | private File descriptorDirectory;
|
---|
| 40 |
|
---|
| 41 | /**
|
---|
| 42 | * The directory where generated files are placed.
|
---|
| 43 | */
|
---|
| 44 | private File generatedFilesDirectory;
|
---|
| 45 |
|
---|
| 46 | /**
|
---|
| 47 | * The name of the manifest file generated for the EJB jar.
|
---|
| 48 | */
|
---|
| 49 | private File generatedManifestFile;
|
---|
| 50 |
|
---|
| 51 | /**
|
---|
| 52 | * The classpath to be used in the weblogic ejbc calls. It must contain the weblogic
|
---|
| 53 | * classes <b>and</b> the implementation classes of the home and remote interfaces.
|
---|
| 54 | */
|
---|
| 55 | private String classpath;
|
---|
| 56 |
|
---|
| 57 | /**
|
---|
| 58 | * The source directory for the home and remote interfaces. This is used to determine if
|
---|
| 59 | * the generated deployment classes are out of date.
|
---|
| 60 | */
|
---|
| 61 | private File sourceDirectory;
|
---|
| 62 |
|
---|
| 63 | public boolean keepgenerated;
|
---|
| 64 |
|
---|
| 65 | /**
|
---|
| 66 | * Do the work.
|
---|
| 67 | *
|
---|
| 68 | * The work is actually done by creating a separate JVM to run a helper task.
|
---|
| 69 | * This approach allows the classpath of the helper task to be set. Since the
|
---|
| 70 | * weblogic tools require the class files of the project's home and remote
|
---|
| 71 | * interfaces to be available in the classpath, this also avoids having to
|
---|
| 72 | * start ant with the class path of the project it is building.
|
---|
| 73 | *
|
---|
| 74 | * @exception BuildException if someting goes wrong with the build
|
---|
| 75 | */
|
---|
| 76 | public void execute() throws BuildException {
|
---|
| 77 | if (descriptorDirectory == null
|
---|
| 78 | || !descriptorDirectory.isDirectory()) {
|
---|
| 79 | throw new BuildException("descriptors directory "
|
---|
| 80 | + descriptorDirectory.getPath() + " is not valid");
|
---|
| 81 | }
|
---|
| 82 | if (generatedFilesDirectory == null
|
---|
| 83 | || !generatedFilesDirectory.isDirectory()) {
|
---|
| 84 | throw new BuildException("dest directory "
|
---|
| 85 | + generatedFilesDirectory.getPath() + " is not valid");
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | if (sourceDirectory == null
|
---|
| 89 | || !sourceDirectory.isDirectory()) {
|
---|
| 90 | throw new BuildException("src directory "
|
---|
| 91 | + sourceDirectory.getPath() + " is not valid");
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | String systemClassPath = System.getProperty("java.class.path");
|
---|
| 95 | String execClassPath
|
---|
| 96 | = getProject().translatePath(systemClassPath + ":" + classpath
|
---|
| 97 | + ":" + generatedFilesDirectory);
|
---|
| 98 | // get all the files in the descriptor directory
|
---|
| 99 | DirectoryScanner ds = super.getDirectoryScanner(descriptorDirectory);
|
---|
| 100 |
|
---|
| 101 | String[] files = ds.getIncludedFiles();
|
---|
| 102 |
|
---|
| 103 | Java helperTask = (Java) getProject().createTask("java");
|
---|
| 104 | helperTask.setTaskName(getTaskName());
|
---|
| 105 | helperTask.setFork(true);
|
---|
| 106 | helperTask.setClassname("org.apache.tools.ant.taskdefs.optional.ejb.EjbcHelper");
|
---|
| 107 | String args = "";
|
---|
| 108 | args += " " + descriptorDirectory;
|
---|
| 109 | args += " " + generatedFilesDirectory;
|
---|
| 110 | args += " " + sourceDirectory;
|
---|
| 111 | args += " " + generatedManifestFile;
|
---|
| 112 | args += " " + keepgenerated;
|
---|
| 113 |
|
---|
| 114 | for (int i = 0; i < files.length; ++i) {
|
---|
| 115 | args += " " + files[i];
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | Commandline.Argument arguments = helperTask.createArg();
|
---|
| 119 | arguments.setLine(args);
|
---|
| 120 | helperTask.setClasspath(new Path(getProject(), execClassPath));
|
---|
| 121 | if (helperTask.executeJava() != 0) {
|
---|
| 122 | throw new BuildException("Execution of ejbc helper failed");
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | public boolean getKeepgenerated() {
|
---|
| 127 | return keepgenerated;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | /**
|
---|
| 131 | * Set the directory from where the serialized deployment descriptors are
|
---|
| 132 | * to be read.
|
---|
| 133 | *
|
---|
| 134 | * @param dirName the name of the directory containing the serialised deployment descriptors.
|
---|
| 135 | */
|
---|
| 136 | public void setDescriptors(String dirName) {
|
---|
| 137 | descriptorDirectory = new File(dirName);
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | /**
|
---|
| 141 | * Set the directory into which the support classes, RMI stubs, etc are to be written.
|
---|
| 142 | *
|
---|
| 143 | * @param dirName the name of the directory into which code is generated
|
---|
| 144 | */
|
---|
| 145 | public void setDest(String dirName) {
|
---|
| 146 | generatedFilesDirectory = new File(dirName);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | /**
|
---|
| 150 | * If true, ejbc will keep the
|
---|
| 151 | * intermediate Java files used to build the class files.
|
---|
| 152 | * This can be useful when debugging.
|
---|
| 153 | */
|
---|
| 154 | public void setKeepgenerated(String newKeepgenerated) {
|
---|
| 155 | keepgenerated = Boolean.valueOf(newKeepgenerated.trim()).booleanValue();
|
---|
| 156 |
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | /**
|
---|
| 160 | * Set the name of the generated manifest file.
|
---|
| 161 | *
|
---|
| 162 | * For each EJB that is processed an entry is created in this file. This can then be used
|
---|
| 163 | * to create a jar file for dploying the beans.
|
---|
| 164 | *
|
---|
| 165 | * @param manifestFilename the name of the manifest file to be generated.
|
---|
| 166 | */
|
---|
| 167 | public void setManifest(String manifestFilename) {
|
---|
| 168 | generatedManifestFile = new File(manifestFilename);
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | /**
|
---|
| 172 | * Set the classpath to be used for this compilation.
|
---|
| 173 | */
|
---|
| 174 | public void setClasspath(String s) {
|
---|
| 175 | this.classpath = getProject().translatePath(s);
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | /**
|
---|
| 179 | * Set the directory containing the source code for the home interface, remote interface
|
---|
| 180 | * and public key class definitions.
|
---|
| 181 | *
|
---|
| 182 | * @param dirName the directory containg the source tree for the EJB's interface classes.
|
---|
| 183 | */
|
---|
| 184 | public void setSrc(String dirName) {
|
---|
| 185 | sourceDirectory = new File(dirName);
|
---|
| 186 | }
|
---|
| 187 | }
|
---|