1 | /*
|
---|
2 | * Copyright 2000-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 a serialized deployment descriptor given a text file description of the
|
---|
29 | * descriptor in the format supported by WebLogic.
|
---|
30 | *
|
---|
31 | * This ant task is a front end for the weblogic DDCreator tool.
|
---|
32 | *
|
---|
33 | */
|
---|
34 | public class DDCreator extends MatchingTask {
|
---|
35 | /**
|
---|
36 | * The root directory of the tree containing the textual deployment descriptors. The actual
|
---|
37 | * deployment descriptor files are selected using include and exclude constructs
|
---|
38 | * on the EJBC task, as supported by the MatchingTask superclass.
|
---|
39 | */
|
---|
40 | private File descriptorDirectory;
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * The directory where generated serialised deployment descriptors are placed.
|
---|
44 | */
|
---|
45 | private File generatedFilesDirectory;
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * The classpath to be used in the weblogic ejbc calls. It must contain the weblogic
|
---|
49 | * classes necessary fro DDCreator <b>and</b> the implementation classes of the
|
---|
50 | * home and remote interfaces.
|
---|
51 | */
|
---|
52 | private String classpath;
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Do the work.
|
---|
56 | *
|
---|
57 | * The work is actually done by creating a helper task. This approach allows
|
---|
58 | * the classpath of the helper task to be set. Since the weblogic tools require
|
---|
59 | * the class files of the project's home and remote interfaces to be available in
|
---|
60 | * the classpath, this also avoids having to start ant with the class path of the
|
---|
61 | * project it is building.
|
---|
62 | *
|
---|
63 | * @exception BuildException if something goes wrong with the build
|
---|
64 | */
|
---|
65 | public void execute() throws BuildException {
|
---|
66 | if (descriptorDirectory == null
|
---|
67 | || !descriptorDirectory.isDirectory()) {
|
---|
68 | throw new BuildException("descriptors directory "
|
---|
69 | + descriptorDirectory.getPath() + " is not valid");
|
---|
70 | }
|
---|
71 | if (generatedFilesDirectory == null
|
---|
72 | || !generatedFilesDirectory.isDirectory()) {
|
---|
73 | throw new BuildException("dest directory "
|
---|
74 | + generatedFilesDirectory.getPath() + " is not valid");
|
---|
75 | }
|
---|
76 |
|
---|
77 | String args = descriptorDirectory + " " + generatedFilesDirectory;
|
---|
78 |
|
---|
79 | // get all the files in the descriptor directory
|
---|
80 | DirectoryScanner ds = super.getDirectoryScanner(descriptorDirectory);
|
---|
81 |
|
---|
82 | String[] files = ds.getIncludedFiles();
|
---|
83 |
|
---|
84 | for (int i = 0; i < files.length; ++i) {
|
---|
85 | args += " " + files[i];
|
---|
86 | }
|
---|
87 |
|
---|
88 | String systemClassPath = System.getProperty("java.class.path");
|
---|
89 | String execClassPath = getProject().translatePath(systemClassPath + ":" + classpath);
|
---|
90 | Java ddCreatorTask = (Java) getProject().createTask("java");
|
---|
91 | ddCreatorTask.setTaskName(getTaskName());
|
---|
92 | ddCreatorTask.setFork(true);
|
---|
93 | ddCreatorTask.setClassname("org.apache.tools.ant.taskdefs.optional.ejb.DDCreatorHelper");
|
---|
94 | Commandline.Argument arguments = ddCreatorTask.createArg();
|
---|
95 | arguments.setLine(args);
|
---|
96 | ddCreatorTask.setClasspath(new Path(getProject(), execClassPath));
|
---|
97 | if (ddCreatorTask.executeJava() != 0) {
|
---|
98 | throw new BuildException("Execution of ddcreator helper failed");
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Set the directory from where the text descriptions of the deployment descriptors are
|
---|
104 | * to be read.
|
---|
105 | *
|
---|
106 | * @param dirName the name of the directory containing the text deployment descriptor files.
|
---|
107 | */
|
---|
108 | public void setDescriptors(String dirName) {
|
---|
109 | descriptorDirectory = new File(dirName);
|
---|
110 | }
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Set the directory into which the serialized deployment descriptors are to
|
---|
114 | * be written.
|
---|
115 | *
|
---|
116 | * @param dirName the name of the directory into which the serialised deployment
|
---|
117 | * descriptors are written.
|
---|
118 | */
|
---|
119 | public void setDest(String dirName) {
|
---|
120 | generatedFilesDirectory = new File(dirName);
|
---|
121 | }
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * Set the classpath to be used for this compilation.
|
---|
125 | *
|
---|
126 | * @param s the classpath to use for the ddcreator tool.
|
---|
127 | */
|
---|
128 | public void setClasspath(String s) {
|
---|
129 | this.classpath = getProject().translatePath(s);
|
---|
130 | }
|
---|
131 | }
|
---|