git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@578882 13f79535-47bb-0310-9956-ffa450edef68master
@@ -263,21 +263,6 @@ | |||
<filename name="${optional.package}/NetRexxC*"/> | |||
</selector> | |||
<selector id="needs.weblogic.ejbc"> | |||
<filename name="${optional.package}/ejb/Ejbc*"/> | |||
</selector> | |||
<selector id="needs.weblogic.ddcreator"> | |||
<filename name="${optional.package}/ejb/DDCreator*"/> | |||
</selector> | |||
<selector id="needs.weblogic.server"> | |||
<or> | |||
<filename name="${optional.package}/ejb/WLRun*"/> | |||
<filename name="${optional.package}/ejb/WLStop*"/> | |||
</or> | |||
</selector> | |||
<selector id="needs.commons-net"> | |||
<or> | |||
<filename name="${optional.package}/net/FTP*"/> | |||
@@ -408,15 +393,6 @@ | |||
<available property="xalan2.present" | |||
classname="org.apache.xalan.transformer.TransformerImpl" | |||
classpathref="classpath"/> | |||
<available property="ejb.ejbc.present" | |||
classname="weblogic.ejbc" | |||
classpathref="classpath"/> | |||
<available property="ejb.DDCreator.present" | |||
classname="weblogic.ejb.utils.DDCreator" | |||
classpathref="classpath"/> | |||
<available property="ejb.wls.present" | |||
classname="weblogic.Server" | |||
classpathref="classpath"/> | |||
<available property="junit.present" | |||
classname="junit.framework.TestCase" | |||
classpathref="classpath"/> | |||
@@ -657,10 +633,6 @@ | |||
<selector refid="needs.stylebook" unless="stylebook.present"/> | |||
<selector refid="needs.javamail" unless="javamail.complete"/> | |||
<selector refid="needs.netrexx" unless="netrexx.present"/> | |||
<selector refid="needs.weblogic.ejbc" unless="ejb.ejbc.present"/> | |||
<selector refid="needs.weblogic.ddcreator" | |||
unless="ejb.DDCreator.present"/> | |||
<selector refid="needs.weblogic.server" unless="ejb.wls.present"/> | |||
<selector refid="needs.commons-net" unless="commons.net.present"/> | |||
<selector refid="needs.starteam" unless="starteam.present"/> | |||
<selector refid="needs.antlr" unless="antlr.present"/> | |||
@@ -840,9 +812,6 @@ | |||
<selector refid="needs.stylebook"/> | |||
<selector refid="needs.javamail"/> | |||
<selector refid="needs.netrexx"/> | |||
<selector refid="needs.weblogic.ejbc"/> | |||
<selector refid="needs.weblogic.ddcreator"/> | |||
<selector refid="needs.weblogic.server"/> | |||
<selector refid="needs.commons-net"/> | |||
<selector refid="needs.starteam"/> | |||
<selector refid="needs.antlr"/> | |||
@@ -893,17 +862,6 @@ | |||
<optional-jar dep="jsch"/> | |||
<optional-jar dep="jdepend"/> | |||
<jar destfile="${build.lib}/${optional.jars.prefix}-weblogic.jar" | |||
basedir="${build.classes}" | |||
manifest="${manifest.tmp}" | |||
whenmanifestonly="${optional.jars.whenmanifestonly}"> | |||
<or> | |||
<selector refid="needs.weblogic.ejbc"/> | |||
<selector refid="needs.weblogic.ddcreator"/> | |||
<selector refid="needs.weblogic.server"/> | |||
</or> | |||
</jar> | |||
</target> | |||
<!-- Creates jar of test utility classes --> | |||
@@ -1,132 +0,0 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
* | |||
*/ | |||
package org.apache.tools.ant.taskdefs.optional.ejb; | |||
import java.io.File; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.DirectoryScanner; | |||
import org.apache.tools.ant.taskdefs.Java; | |||
import org.apache.tools.ant.taskdefs.MatchingTask; | |||
import org.apache.tools.ant.types.Commandline; | |||
import org.apache.tools.ant.types.Path; | |||
import org.apache.tools.ant.util.FileUtils; | |||
/** | |||
* Builds a serialized deployment descriptor given a text file description of the | |||
* descriptor in the format supported by WebLogic. | |||
* | |||
* This ant task is a front end for the weblogic DDCreator tool. | |||
* | |||
*/ | |||
public class DDCreator extends MatchingTask { | |||
/** | |||
* The root directory of the tree containing the textual deployment descriptors. The actual | |||
* deployment descriptor files are selected using include and exclude constructs | |||
* on the EJBC task, as supported by the MatchingTask superclass. | |||
*/ | |||
private File descriptorDirectory; | |||
/** | |||
* The directory where generated serialised deployment descriptors are placed. | |||
*/ | |||
private File generatedFilesDirectory; | |||
/** | |||
* The classpath to be used in the weblogic ejbc calls. It must contain the weblogic | |||
* classes necessary fro DDCreator <b>and</b> the implementation classes of the | |||
* home and remote interfaces. | |||
*/ | |||
private String classpath; | |||
/** | |||
* Do the work. | |||
* | |||
* The work is actually done by creating a helper task. This approach allows | |||
* the classpath of the helper task to be set. Since the weblogic tools require | |||
* the class files of the project's home and remote interfaces to be available in | |||
* the classpath, this also avoids having to start ant with the class path of the | |||
* project it is building. | |||
* | |||
* @exception BuildException if something goes wrong with the build | |||
*/ | |||
public void execute() throws BuildException { | |||
if (descriptorDirectory == null | |||
|| !descriptorDirectory.isDirectory()) { | |||
throw new BuildException("descriptors directory " | |||
+ descriptorDirectory + " is not valid"); | |||
} | |||
if (generatedFilesDirectory == null | |||
|| !generatedFilesDirectory.isDirectory()) { | |||
throw new BuildException("dest directory " | |||
+ generatedFilesDirectory + " is not valid"); | |||
} | |||
String args = descriptorDirectory + " " + generatedFilesDirectory; | |||
// get all the files in the descriptor directory | |||
DirectoryScanner ds = super.getDirectoryScanner(descriptorDirectory); | |||
String[] files = ds.getIncludedFiles(); | |||
for (int i = 0; i < files.length; ++i) { | |||
args += " " + files[i]; | |||
} | |||
String systemClassPath = System.getProperty("java.class.path"); | |||
String execClassPath = FileUtils.translatePath(systemClassPath + ":" + classpath); | |||
Java ddCreatorTask = new Java(this); | |||
ddCreatorTask.setFork(true); | |||
ddCreatorTask.setClassname("org.apache.tools.ant.taskdefs.optional.ejb.DDCreatorHelper"); | |||
Commandline.Argument arguments = ddCreatorTask.createArg(); | |||
arguments.setLine(args); | |||
ddCreatorTask.setClasspath(new Path(getProject(), execClassPath)); | |||
if (ddCreatorTask.executeJava() != 0) { | |||
throw new BuildException("Execution of ddcreator helper failed"); | |||
} | |||
} | |||
/** | |||
* Set the directory from where the text descriptions of the deployment descriptors are | |||
* to be read. | |||
* | |||
* @param dirName the name of the directory containing the text deployment descriptor files. | |||
*/ | |||
public void setDescriptors(String dirName) { | |||
descriptorDirectory = new File(dirName); | |||
} | |||
/** | |||
* Set the directory into which the serialized deployment descriptors are to | |||
* be written. | |||
* | |||
* @param dirName the name of the directory into which the serialised deployment | |||
* descriptors are written. | |||
*/ | |||
public void setDest(String dirName) { | |||
generatedFilesDirectory = new File(dirName); | |||
} | |||
/** | |||
* Set the classpath to be used for this compilation. | |||
* | |||
* @param s the classpath to use for the ddcreator tool. | |||
*/ | |||
public void setClasspath(String s) { | |||
this.classpath = FileUtils.translatePath(s); | |||
} | |||
} |
@@ -1,145 +0,0 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
* | |||
*/ | |||
package org.apache.tools.ant.taskdefs.optional.ejb; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.io.ObjectInputStream; | |||
import javax.ejb.deployment.DeploymentDescriptor; | |||
/** | |||
* A helper class which performs the actual work of the ddcreator task. | |||
* | |||
* This class is run with a classpath which includes the weblogic tools and the home and remote | |||
* interface class files referenced in the deployment descriptors being built. | |||
* | |||
*/ | |||
public final class DDCreatorHelper { | |||
/** | |||
* The root directory of the tree containing the textual deployment descriptors. | |||
*/ | |||
private File descriptorDirectory; | |||
/** | |||
* The directory where generated serialised deployment descriptors are written. | |||
*/ | |||
private File generatedFilesDirectory; | |||
// CheckStyle:VisibilityModifier OFF - bc | |||
/** | |||
* The descriptor text files for which a serialised descriptor is to be created. | |||
*/ | |||
String[] descriptors; | |||
// CheckStyle:VisibilityModifier ON | |||
/** | |||
* The main method. | |||
* | |||
* The main method creates an instance of the DDCreatorHelper, passing it the | |||
* args which it then processes. | |||
* @param args the arguments | |||
* @throws Exception on error | |||
*/ | |||
public static void main(String[] args) throws Exception { | |||
DDCreatorHelper helper = new DDCreatorHelper(args); | |||
helper.process(); | |||
} | |||
/** | |||
* Initialise the helper with the command arguments. | |||
* | |||
*/ | |||
private DDCreatorHelper(String[] args) { | |||
int index = 0; | |||
descriptorDirectory = new File(args[index++]); | |||
generatedFilesDirectory = new File(args[index++]); | |||
descriptors = new String[args.length - index]; | |||
for (int i = 0; index < args.length; ++i) { | |||
descriptors[i] = args[index++]; | |||
} | |||
} | |||
/** | |||
* Do the actual work. | |||
* | |||
* The work proceeds by examining each descriptor given. If the serialised | |||
* file does not exist or is older than the text description, the weblogic | |||
* DDCreator tool is invoked directly to build the serialised descriptor. | |||
*/ | |||
private void process() throws Exception { | |||
for (int i = 0; i < descriptors.length; ++i) { | |||
String descriptorName = descriptors[i]; | |||
File descriptorFile = new File(descriptorDirectory, descriptorName); | |||
int extIndex = descriptorName.lastIndexOf("."); | |||
String serName = null; | |||
if (extIndex != -1) { | |||
serName = descriptorName.substring(0, extIndex) + ".ser"; | |||
} else { | |||
serName = descriptorName + ".ser"; | |||
} | |||
File serFile = new File(generatedFilesDirectory, serName); | |||
// do we need to regenerate the file | |||
if (!serFile.exists() || serFile.lastModified() < descriptorFile.lastModified() | |||
|| regenerateSerializedFile(serFile)) { | |||
String[] args = {"-noexit", | |||
"-d", serFile.getParent(), | |||
"-outputfile", serFile.getName(), | |||
descriptorFile.getPath()}; | |||
try { | |||
weblogic.ejb.utils.DDCreator.main(args); | |||
} catch (Exception e) { | |||
// there was an exception - run with no exit to get proper error | |||
String[] newArgs = {"-d", generatedFilesDirectory.getPath(), | |||
"-outputfile", serFile.getName(), | |||
descriptorFile.getPath()}; | |||
weblogic.ejb.utils.DDCreator.main(newArgs); | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* EJBC will fail if the serialized descriptor file does not match the bean classes. | |||
* You can test for this by trying to load the deployment descriptor. If it fails, | |||
* the serialized file needs to be regenerated because the associated class files | |||
* don't match. | |||
*/ | |||
private boolean regenerateSerializedFile(File serFile) { | |||
try { | |||
FileInputStream fis = new FileInputStream(serFile); | |||
ObjectInputStream ois = new ObjectInputStream(fis); | |||
DeploymentDescriptor dd = (DeploymentDescriptor) ois.readObject(); | |||
fis.close(); | |||
// Since the descriptor read properly, everything should be o.k. | |||
return false; | |||
} catch (Exception e) { | |||
// Weblogic will throw an error if the deployment descriptor does | |||
// not match the class files. | |||
return true; | |||
} | |||
} | |||
} |
@@ -1,197 +0,0 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
* | |||
*/ | |||
package org.apache.tools.ant.taskdefs.optional.ejb; | |||
import java.io.File; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.DirectoryScanner; | |||
import org.apache.tools.ant.taskdefs.Java; | |||
import org.apache.tools.ant.taskdefs.MatchingTask; | |||
import org.apache.tools.ant.types.Commandline; | |||
import org.apache.tools.ant.types.Path; | |||
import org.apache.tools.ant.util.FileUtils; | |||
/** | |||
* Builds EJB support classes using WebLogic's ejbc tool from a directory containing | |||
* a set of deployment descriptors. | |||
* | |||
* | |||
*/ | |||
public class Ejbc extends MatchingTask { | |||
/** | |||
* The root directory of the tree containing the serialised deployment desciptors. The actual | |||
* deployment descriptor files are selected using include and exclude constructs | |||
* on the ejbc task provided by the MatchingTask superclass. | |||
*/ | |||
private File descriptorDirectory; | |||
/** | |||
* The directory where generated files are placed. | |||
*/ | |||
private File generatedFilesDirectory; | |||
/** | |||
* The name of the manifest file generated for the EJB jar. | |||
*/ | |||
private File generatedManifestFile; | |||
/** | |||
* The classpath to be used in the weblogic ejbc calls. It must contain the weblogic | |||
* classes <b>and</b> the implementation classes of the home and remote interfaces. | |||
*/ | |||
private String classpath; | |||
/** | |||
* The source directory for the home and remote interfaces. This is used to determine if | |||
* the generated deployment classes are out of date. | |||
*/ | |||
private File sourceDirectory; | |||
// CheckStyle:VisibilityModifier OFF - bc | |||
/** Whether to keep the generated files */ | |||
public boolean keepgenerated; | |||
// CheckStyle:VisibilityModifier ON | |||
/** | |||
* Do the work. | |||
* | |||
* The work is actually done by creating a separate JVM to run a helper task. | |||
* This approach allows the classpath of the helper task to be set. Since the | |||
* weblogic tools require the class files of the project's home and remote | |||
* interfaces to be available in the classpath, this also avoids having to | |||
* start ant with the class path of the project it is building. | |||
* | |||
* @exception BuildException if someting goes wrong with the build | |||
*/ | |||
public void execute() throws BuildException { | |||
if (descriptorDirectory == null | |||
|| !descriptorDirectory.isDirectory()) { | |||
throw new BuildException("descriptors directory " | |||
+ descriptorDirectory + " is not valid"); | |||
} | |||
if (generatedFilesDirectory == null | |||
|| !generatedFilesDirectory.isDirectory()) { | |||
throw new BuildException("dest directory " | |||
+ generatedFilesDirectory + " is not valid"); | |||
} | |||
if (sourceDirectory == null | |||
|| !sourceDirectory.isDirectory()) { | |||
throw new BuildException("src directory " | |||
+ sourceDirectory + " is not valid"); | |||
} | |||
String systemClassPath = System.getProperty("java.class.path"); | |||
String execClassPath | |||
= FileUtils.translatePath(systemClassPath + ":" + classpath | |||
+ ":" + generatedFilesDirectory); | |||
// get all the files in the descriptor directory | |||
DirectoryScanner ds = super.getDirectoryScanner(descriptorDirectory); | |||
String[] files = ds.getIncludedFiles(); | |||
Java helperTask = new Java(this); | |||
helperTask.setFork(true); | |||
helperTask.setClassname("org.apache.tools.ant.taskdefs.optional.ejb.EjbcHelper"); | |||
String args = ""; | |||
args += " " + descriptorDirectory; | |||
args += " " + generatedFilesDirectory; | |||
args += " " + sourceDirectory; | |||
args += " " + generatedManifestFile; | |||
args += " " + keepgenerated; | |||
for (int i = 0; i < files.length; ++i) { | |||
args += " " + files[i]; | |||
} | |||
Commandline.Argument arguments = helperTask.createArg(); | |||
arguments.setLine(args); | |||
helperTask.setClasspath(new Path(getProject(), execClassPath)); | |||
if (helperTask.executeJava() != 0) { | |||
throw new BuildException("Execution of ejbc helper failed"); | |||
} | |||
} | |||
/** | |||
* get the keep generated attribute. | |||
* @return the attribute. | |||
*/ | |||
public boolean getKeepgenerated() { | |||
return keepgenerated; | |||
} | |||
/** | |||
* Set the directory from where the serialized deployment descriptors are | |||
* to be read. | |||
* | |||
* @param dirName the name of the directory containing the serialised deployment descriptors. | |||
*/ | |||
public void setDescriptors(String dirName) { | |||
descriptorDirectory = new File(dirName); | |||
} | |||
/** | |||
* Set the directory into which the support classes, RMI stubs, etc are to be written. | |||
* | |||
* @param dirName the name of the directory into which code is generated | |||
*/ | |||
public void setDest(String dirName) { | |||
generatedFilesDirectory = new File(dirName); | |||
} | |||
/** | |||
* If true, ejbc will keep the | |||
* intermediate Java files used to build the class files. | |||
* This can be useful when debugging. | |||
* @param newKeepgenerated a boolean as a string. | |||
*/ | |||
public void setKeepgenerated(String newKeepgenerated) { | |||
keepgenerated = Boolean.valueOf(newKeepgenerated.trim()).booleanValue(); | |||
} | |||
/** | |||
* Set the name of the generated manifest file. | |||
* | |||
* For each EJB that is processed an entry is created in this file. This can then be used | |||
* to create a jar file for dploying the beans. | |||
* | |||
* @param manifestFilename the name of the manifest file to be generated. | |||
*/ | |||
public void setManifest(String manifestFilename) { | |||
generatedManifestFile = new File(manifestFilename); | |||
} | |||
/** | |||
* Set the classpath to be used for this compilation. | |||
* @param s the classpath (as a string) to use. | |||
*/ | |||
public void setClasspath(String s) { | |||
this.classpath = FileUtils.translatePath(s); | |||
} | |||
/** | |||
* Set the directory containing the source code for the home interface, remote interface | |||
* and public key class definitions. | |||
* | |||
* @param dirName the directory containg the source tree for the EJB's interface classes. | |||
*/ | |||
public void setSrc(String dirName) { | |||
sourceDirectory = new File(dirName); | |||
} | |||
} |
@@ -1,259 +0,0 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
* | |||
*/ | |||
package org.apache.tools.ant.taskdefs.optional.ejb; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.io.FileWriter; | |||
import java.io.IOException; | |||
import java.io.ObjectInputStream; | |||
import java.io.PrintWriter; | |||
import java.util.Vector; | |||
import javax.ejb.deployment.DeploymentDescriptor; | |||
import javax.ejb.deployment.EntityDescriptor; | |||
/** | |||
* A helper class which performs the actual work of the ejbc task. | |||
* | |||
* This class is run with a classpath which includes the weblogic tools and the home and remote | |||
* interface class files referenced in the deployment descriptors being processed. | |||
* | |||
*/ | |||
public final class EjbcHelper { | |||
/** | |||
* The root directory of the tree containing the serialised deployment desciptors. | |||
*/ | |||
private File descriptorDirectory; | |||
/** | |||
* The directory where generated files are placed. | |||
*/ | |||
private File generatedFilesDirectory; | |||
/** | |||
* The name of the manifest file generated for the EJB jar. | |||
*/ | |||
private File manifestFile; | |||
/** | |||
* The source directory for the home and remote interfaces. This is used to determine if | |||
* the generated deployment classes are out of date. | |||
*/ | |||
private File sourceDirectory; | |||
// CheckStyle:VisibilityModifier OFF - bc | |||
/** | |||
* The names of the serialised deployment descriptors | |||
*/ | |||
String[] descriptors; | |||
// CheckStyle:VisibilityModifier ON | |||
private boolean keepGenerated; | |||
/** | |||
* Command line interface for the ejbc helper task. | |||
* @param args command line arguments. | |||
* @throws Exception if there is a problem. | |||
*/ | |||
public static void main(String[] args) throws Exception { | |||
EjbcHelper helper = new EjbcHelper(args); | |||
helper.process(); | |||
} | |||
/** | |||
* Initialise the EjbcHelper by reading the command arguments. | |||
*/ | |||
private EjbcHelper(String[] args) { | |||
int index = 0; | |||
descriptorDirectory = new File(args[index++]); | |||
generatedFilesDirectory = new File(args[index++]); | |||
sourceDirectory = new File(args[index++]); | |||
manifestFile = new File(args[index++]); | |||
keepGenerated = Boolean.valueOf(args[index++]).booleanValue(); | |||
descriptors = new String[args.length - index]; | |||
for (int i = 0; index < args.length; ++i) { | |||
descriptors[i] = args[index++]; | |||
} | |||
} | |||
private String[] getCommandLine(boolean debug, File descriptorFile) { | |||
Vector v = new Vector(); | |||
if (!debug) { | |||
v.addElement("-noexit"); | |||
} | |||
if (keepGenerated) { | |||
v.addElement("-keepgenerated"); | |||
} | |||
v.addElement("-d"); | |||
v.addElement(generatedFilesDirectory.getPath()); | |||
v.addElement(descriptorFile.getPath()); | |||
String[] args = new String[v.size()]; | |||
v.copyInto(args); | |||
return args; | |||
} | |||
/** | |||
* Determine if the weblogic EJB support classes need to be regenerated | |||
* for a given deployment descriptor. | |||
* | |||
* This process attempts to determine if the support classes need to be | |||
* rebuilt. It does this by examining only some of the support classes | |||
* which are typically generated. If the ejbc task is interrupted generating | |||
* the support classes for a bean, all of the support classes should be removed | |||
* to force regeneration of the support classes. | |||
* | |||
* @param descriptorFile the serialised deployment descriptor | |||
* | |||
* @return true if the support classes need to be regenerated. | |||
* | |||
* @throws IOException if the descriptor file cannot be closed. | |||
*/ | |||
private boolean isRegenRequired(File descriptorFile) throws IOException { | |||
// read in the descriptor. Under weblogic, the descriptor is a weblogic | |||
// specific subclass which has references to the implementation classes. | |||
// These classes must, therefore, be in the classpath when the deployment | |||
// descriptor is loaded from the .ser file | |||
FileInputStream fis = null; | |||
try { | |||
fis = new FileInputStream(descriptorFile); | |||
ObjectInputStream ois = new ObjectInputStream(fis); | |||
DeploymentDescriptor dd = (DeploymentDescriptor) ois.readObject(); | |||
fis.close(); | |||
String homeInterfacePath | |||
= dd.getHomeInterfaceClassName().replace('.', '/') + ".java"; | |||
String remoteInterfacePath | |||
= dd.getRemoteInterfaceClassName().replace('.', '/') + ".java"; | |||
String primaryKeyClassPath = null; | |||
if (dd instanceof EntityDescriptor) { | |||
primaryKeyClassPath | |||
= ((EntityDescriptor) dd).getPrimaryKeyClassName(); | |||
primaryKeyClassPath | |||
= primaryKeyClassPath.replace('.', '/') + ".java"; | |||
} | |||
File homeInterfaceSource = new File(sourceDirectory, homeInterfacePath); | |||
File remoteInterfaceSource = new File(sourceDirectory, remoteInterfacePath); | |||
File primaryKeyClassSource = null; | |||
if (primaryKeyClassPath != null) { | |||
primaryKeyClassSource = new File(sourceDirectory, remoteInterfacePath); | |||
} | |||
// are any of the above out of date. | |||
// we find the implementation classes and see if they are older than any | |||
// of the above or the .ser file itself. | |||
String beanClassBase = dd.getEnterpriseBeanClassName().replace('.', '/'); | |||
File ejbImplentationClass | |||
= new File(generatedFilesDirectory, beanClassBase + "EOImpl.class"); | |||
File homeImplementationClass | |||
= new File(generatedFilesDirectory, beanClassBase + "HomeImpl.class"); | |||
File beanStubClass | |||
= new File(generatedFilesDirectory, beanClassBase + "EOImpl_WLStub.class"); | |||
// if the implementation classes don;t exist regenerate | |||
if (!ejbImplentationClass.exists() | |||
|| !homeImplementationClass.exists() | |||
|| !beanStubClass.exists()) { | |||
return true; | |||
} | |||
// Is the ser file or any of the source files newer then the class files. | |||
// firstly find the oldest of the two class files. | |||
long classModificationTime = ejbImplentationClass.lastModified(); | |||
if (homeImplementationClass.lastModified() < classModificationTime) { | |||
classModificationTime = homeImplementationClass.lastModified(); | |||
} | |||
if (beanStubClass.lastModified() < classModificationTime) { | |||
classModificationTime = beanStubClass.lastModified(); | |||
} | |||
if (descriptorFile.lastModified() > classModificationTime | |||
|| homeInterfaceSource.lastModified() > classModificationTime | |||
|| remoteInterfaceSource.lastModified() > classModificationTime) { | |||
return true; | |||
} | |||
if (primaryKeyClassSource != null | |||
&& primaryKeyClassSource.lastModified() > classModificationTime) { | |||
return true; | |||
} | |||
} catch (Throwable descriptorLoadException) { | |||
System.out.println("Exception occurred reading " | |||
+ descriptorFile.getName() + " - continuing"); | |||
// any problems - just regenerate | |||
return true; | |||
} finally { | |||
if (fis != null) { | |||
fis.close(); | |||
} | |||
} | |||
return false; | |||
} | |||
/** | |||
* Process the descriptors in turn generating support classes for each and a manifest | |||
* file for all of the beans. | |||
*/ | |||
private void process() throws Exception { | |||
String manifest = "Manifest-Version: 1.0\n\n"; | |||
for (int i = 0; i < descriptors.length; ++i) { | |||
String descriptorName = descriptors[i]; | |||
File descriptorFile = new File(descriptorDirectory, descriptorName); | |||
if (isRegenRequired(descriptorFile)) { | |||
System.out.println("Running ejbc for " + descriptorFile.getName()); | |||
regenerateSupportClasses(descriptorFile); | |||
} else { | |||
System.out.println(descriptorFile.getName() + " is up to date"); | |||
} | |||
manifest += "Name: " + descriptorName.replace('\\', '/') | |||
+ "\nEnterprise-Bean: True\n\n"; | |||
} | |||
FileWriter fw = new FileWriter(manifestFile); | |||
PrintWriter pw = new PrintWriter(fw); | |||
pw.print(manifest); | |||
fw.flush(); | |||
fw.close(); | |||
} | |||
/** | |||
* Perform the weblogic.ejbc call to regenerate the support classes. | |||
* | |||
* Note that this method relies on an undocumented -noexit option to the | |||
* ejbc tool to stop the ejbc tool exiting the VM altogether. | |||
*/ | |||
private void regenerateSupportClasses(File descriptorFile) throws Exception { | |||
// create a Java task to do the rebuild | |||
String[] args = getCommandLine(false, descriptorFile); | |||
try { | |||
weblogic.ejbc.main(args); | |||
} catch (Exception e) { | |||
// run with no exit for better reporting | |||
String[] newArgs = getCommandLine(true, descriptorFile); | |||
weblogic.ejbc.main(newArgs); | |||
} | |||
} | |||
} |
@@ -1,421 +0,0 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
* | |||
*/ | |||
package org.apache.tools.ant.taskdefs.optional.ejb; | |||
import java.io.File; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.Task; | |||
import org.apache.tools.ant.taskdefs.Java; | |||
import org.apache.tools.ant.types.Path; | |||
/** | |||
* Starts a WebLogic server. | |||
* A number of parameters are used to control the operation of the weblogic | |||
* instance. Note that the task, and hence ant, will not complete until the | |||
* weblogic instance is stopped.</p> | |||
* | |||
*/ | |||
public class WLRun extends Task { | |||
protected static final String DEFAULT_WL51_POLICY_FILE = "weblogic.policy"; | |||
protected static final String DEFAULT_WL60_POLICY_FILE = "lib/weblogic.policy"; | |||
protected static final String DEFAULT_PROPERTIES_FILE = "weblogic.properties"; | |||
/** | |||
* The classpath to be used when running the Java VM. It must contain the | |||
* weblogic classes <b>and</b> the implementation classes of the home and | |||
* remote interfaces. | |||
*/ | |||
private Path classpath; | |||
/** | |||
* The weblogic classpath to the be used when running weblogic. | |||
*/ | |||
private Path weblogicClasspath; | |||
private String weblogicMainClass = "weblogic.Server"; | |||
/** | |||
* Addional arguments to pass to the JVM used to run weblogic | |||
*/ | |||
private String additionalArgs = ""; | |||
/** | |||
* The security policy to use when running the weblogic server | |||
*/ | |||
private String securityPolicy; | |||
/** | |||
* The weblogic system home directory | |||
*/ | |||
private File weblogicSystemHome; | |||
/** | |||
* The weblogic domain | |||
*/ | |||
private String weblogicDomainName; | |||
/** | |||
* The name of the weblogic server - used to select the server's directory in the | |||
* weblogic home directory. | |||
*/ | |||
private String weblogicSystemName = "myserver"; | |||
/** | |||
* The file containing the weblogic properties for this server. | |||
*/ | |||
private String weblogicPropertiesFile = null; | |||
/** | |||
* additional args to pass to the spawned jvm | |||
*/ | |||
private String additionalJvmArgs = ""; | |||
/** | |||
* The location of the BEA Home under which this server is run. | |||
* WL6 only | |||
*/ | |||
private File beaHome = null; | |||
/** | |||
* The management username | |||
*/ | |||
private String managementUsername = "system"; | |||
/** | |||
* The management password | |||
*/ | |||
private String managementPassword = null; | |||
/** | |||
* The provate key password - used for SSL | |||
*/ | |||
private String pkPassword = null; | |||
/** | |||
* Add the classpath for the user classes | |||
* @return a path to be configured | |||
*/ | |||
public Path createClasspath() { | |||
if (classpath == null) { | |||
classpath = new Path(getProject()); | |||
} | |||
return classpath.createPath(); | |||
} | |||
/** | |||
* Get the classpath to the weblogic classpaths | |||
* @return a path to be configured | |||
*/ | |||
public Path createWLClasspath() { | |||
if (weblogicClasspath == null) { | |||
weblogicClasspath = new Path(getProject()); | |||
} | |||
return weblogicClasspath.createPath(); | |||
} | |||
/** | |||
* Do the work. | |||
* | |||
* The work is actually done by creating a separate JVM to run a helper task. | |||
* This approach allows the classpath of the helper task to be set. Since the | |||
* weblogic tools require the class files of the project's home and remote | |||
* interfaces to be available in the classpath, this also avoids having to | |||
* start ant with the class path of the project it is building. | |||
* | |||
* @exception BuildException if someting goes wrong with the build | |||
*/ | |||
public void execute() throws BuildException { | |||
if (weblogicSystemHome == null) { | |||
throw new BuildException("weblogic home must be set"); | |||
} | |||
if (!weblogicSystemHome.isDirectory()) { | |||
throw new BuildException("weblogic home directory " | |||
+ weblogicSystemHome.getPath() + " is not valid"); | |||
} | |||
if (beaHome != null) { | |||
executeWLS6(); | |||
} else { | |||
executeWLS(); | |||
} | |||
} | |||
private File findSecurityPolicyFile(String defaultSecurityPolicy) { | |||
String securityPolicy = this.securityPolicy; | |||
if (securityPolicy == null) { | |||
securityPolicy = defaultSecurityPolicy; | |||
} | |||
File securityPolicyFile = new File(weblogicSystemHome, securityPolicy); | |||
// If an explicit securityPolicy file was specified, it maybe an | |||
// absolute path. Use the project to resolve it. | |||
if (this.securityPolicy != null && !securityPolicyFile.exists()) { | |||
securityPolicyFile = getProject().resolveFile(securityPolicy); | |||
} | |||
// If we still can't find it, complain | |||
if (!securityPolicyFile.exists()) { | |||
throw new BuildException("Security policy " + securityPolicy | |||
+ " was not found."); | |||
} | |||
return securityPolicyFile; | |||
} | |||
private void executeWLS6() { | |||
File securityPolicyFile | |||
= findSecurityPolicyFile(DEFAULT_WL60_POLICY_FILE); | |||
if (!beaHome.isDirectory()) { | |||
throw new BuildException("BEA home " + beaHome.getPath() | |||
+ " is not valid"); | |||
} | |||
File configFile = new File(weblogicSystemHome, "config/" | |||
+ weblogicDomainName + "/config.xml"); | |||
if (!configFile.exists()) { | |||
throw new BuildException("Server config file " + configFile | |||
+ " not found."); | |||
} | |||
if (managementPassword == null) { | |||
throw new BuildException("You must supply a management password " | |||
+ "to start the server"); | |||
} | |||
Java weblogicServer = new Java(this); | |||
weblogicServer.setTaskName(getTaskName()); | |||
weblogicServer.setFork(true); | |||
weblogicServer.setDir(weblogicSystemHome); | |||
weblogicServer.setClassname(weblogicMainClass); | |||
String jvmArgs = additionalJvmArgs; | |||
jvmArgs += " -Dweblogic.Domain=" + weblogicDomainName; | |||
jvmArgs += " -Dweblogic.Name=" + weblogicSystemName; | |||
jvmArgs += " -Dweblogic.system.home=" + weblogicSystemHome; | |||
jvmArgs += " -Dbea.home=" + beaHome; | |||
jvmArgs += " -Djava.security.policy==" + securityPolicyFile; | |||
jvmArgs += " -Dweblogic.management.username=" + managementUsername; | |||
jvmArgs += " -Dweblogic.management.password=" + managementPassword; | |||
if (pkPassword != null) { | |||
jvmArgs += " -Dweblogic.pkpassword=" + pkPassword; | |||
} | |||
weblogicServer.createJvmarg().setLine(jvmArgs); | |||
weblogicServer.createArg().setLine(additionalArgs); | |||
if (classpath != null) { | |||
weblogicServer.setClasspath(classpath); | |||
} | |||
if (weblogicServer.executeJava() != 0) { | |||
throw new BuildException("Execution of weblogic server failed"); | |||
} | |||
} | |||
private void executeWLS() { | |||
File securityPolicyFile | |||
= findSecurityPolicyFile(DEFAULT_WL51_POLICY_FILE); | |||
File propertiesFile = null; | |||
if (weblogicPropertiesFile == null) { | |||
weblogicPropertiesFile = DEFAULT_PROPERTIES_FILE; | |||
} | |||
propertiesFile = new File(weblogicSystemHome, weblogicPropertiesFile); | |||
if (!propertiesFile.exists()) { | |||
// OK, properties file may be absolute | |||
propertiesFile = getProject().resolveFile(weblogicPropertiesFile); | |||
if (!propertiesFile.exists()) { | |||
throw new BuildException("Properties file " | |||
+ weblogicPropertiesFile | |||
+ " not found in weblogic home " + weblogicSystemHome | |||
+ " or as absolute file"); | |||
} | |||
} | |||
Java weblogicServer = new Java(this); | |||
weblogicServer.setFork(true); | |||
weblogicServer.setClassname(weblogicMainClass); | |||
String jvmArgs = additionalJvmArgs; | |||
if (weblogicClasspath != null) { | |||
jvmArgs += " -Dweblogic.class.path=" + weblogicClasspath; | |||
} | |||
jvmArgs += " -Djava.security.manager -Djava.security.policy==" + securityPolicyFile; | |||
jvmArgs += " -Dweblogic.system.home=" + weblogicSystemHome; | |||
jvmArgs += " -Dweblogic.system.name=" + weblogicSystemName; | |||
jvmArgs += " -Dweblogic.system.propertiesFile=" + weblogicPropertiesFile; | |||
weblogicServer.createJvmarg().setLine(jvmArgs); | |||
weblogicServer.createArg().setLine(additionalArgs); | |||
if (classpath != null) { | |||
weblogicServer.setClasspath(classpath); | |||
} | |||
if (weblogicServer.executeJava() != 0) { | |||
throw new BuildException("Execution of weblogic server failed"); | |||
} | |||
} | |||
/** | |||
* The classpath to be used with the Java Virtual Machine that runs the Weblogic | |||
* Server; required. Prior to Weblogic 6.0, this is typically set to the Weblogic | |||
* boot classpath. Under Weblogic 6.0 this should include all the | |||
* weblogic jars | |||
* | |||
* @param classpath the classpath to use when executing the weblogic server. | |||
*/ | |||
public void setClasspath(Path classpath) { | |||
this.classpath = classpath; | |||
} | |||
/** | |||
* Set the weblogic classpath used by the Weblogic Server; | |||
* optional, and only applicable to WL4.5.1 | |||
* | |||
* The weblogic classpath is used by weblogic to support dynamic class loading. | |||
* | |||
* @param weblogicClasspath the weblogic classpath | |||
*/ | |||
public void setWlclasspath(Path weblogicClasspath) { | |||
this.weblogicClasspath = weblogicClasspath; | |||
} | |||
/** | |||
* The name of the security policy file within the weblogic home directory that | |||
* is to be used. If not specified, the default policy file <code>weblogic.policy</code> | |||
* is used. | |||
* | |||
* @param securityPolicy the security policy to use. | |||
*/ | |||
public void setPolicy(String securityPolicy) { | |||
this.securityPolicy = securityPolicy; | |||
} | |||
/** | |||
* The location where weblogic lives. | |||
* Required. This is the absolute location, not relative to | |||
* BEA home. | |||
* @param weblogicHome the home directory of weblogic. | |||
* | |||
*/ | |||
public void setHome(File weblogicHome) { | |||
weblogicSystemHome = weblogicHome; | |||
} | |||
/** | |||
* The location of the BEA Home; implicitly | |||
* selects Weblogic 6.0; optional. | |||
* | |||
* @param beaHome the BEA Home directory. | |||
* | |||
*/ | |||
public void setBEAHome(File beaHome) { | |||
this.beaHome = beaHome; | |||
} | |||
/** | |||
* The name of the weblogic server within the weblogic home which is to be run. | |||
* Optiona, defaults to "myserver" | |||
* | |||
* @param serverName the name of the server. | |||
*/ | |||
public void setName(String serverName) { | |||
this.weblogicSystemName = serverName; | |||
} | |||
/** | |||
* Set the Domain to run in; required for WL6.0 | |||
* | |||
* @param domain the domain | |||
*/ | |||
public void setDomain(String domain) { | |||
this.weblogicDomainName = domain; | |||
} | |||
/** | |||
* The name of the server's properties file within the weblogic home directory | |||
* used to control the weblogic instance; | |||
* required for WL4.5.1 | |||
* | |||
* | |||
* @param propertiesFilename the properties file name | |||
*/ | |||
public void setProperties(String propertiesFilename) { | |||
this.weblogicPropertiesFile = propertiesFilename; | |||
} | |||
/** | |||
* Set the additional arguments to pass to the weblogic JVM | |||
* @param args the arguments to be passed to the JVM | |||
*/ | |||
public void setJvmargs(String args) { | |||
this.additionalJvmArgs = args; | |||
} | |||
/** | |||
* Set the management username to run the server; | |||
* optional and only applicable to WL6.0. | |||
* | |||
* @param username the management username of the server. | |||
*/ | |||
public void setUsername(String username) { | |||
this.managementUsername = username; | |||
} | |||
/** | |||
* Set the management password of the server; | |||
* optional and only applicable to WL6.0. | |||
* @param password the management pasword of the server. | |||
*/ | |||
public void setPassword(String password) { | |||
this.managementPassword = password; | |||
} | |||
/** | |||
* Set the private key password so the server can decrypt the SSL private key file; | |||
* optional and only applicable to WL6.0. | |||
* @param pkpassword the private key password, | |||
*/ | |||
public void setPKPassword(String pkpassword) { | |||
this.pkPassword = pkpassword; | |||
} | |||
/** | |||
* Additional argument string passed to the Weblogic instance; | |||
* optional. | |||
* @param args the argument string | |||
*/ | |||
public void setArgs(String args) { | |||
additionalArgs = args; | |||
} | |||
/** | |||
* name of the main class for weblogic; optional. | |||
* @param c the name of the class | |||
*/ | |||
public void setWeblogicMainClass(String c) { | |||
weblogicMainClass = c; | |||
} | |||
} |
@@ -1,175 +0,0 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* contributor license agreements. See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||
* (the "License"); you may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
* | |||
*/ | |||
package org.apache.tools.ant.taskdefs.optional.ejb; | |||
import java.io.File; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.Task; | |||
import org.apache.tools.ant.taskdefs.Java; | |||
import org.apache.tools.ant.types.Path; | |||
/** | |||
* Shuts down a WebLogic server. | |||
* To shut down an instance you must supply both a username and | |||
* a password. | |||
* | |||
*/ | |||
public class WLStop extends Task { | |||
/** | |||
* The classpath to be used. It must contains the weblogic.Admin class. | |||
*/ | |||
private Path classpath; | |||
/** | |||
* The weblogic username to use to request the shutdown. | |||
*/ | |||
private String username; | |||
/** | |||
* The password to use to shutdown the weblogic server. | |||
*/ | |||
private String password; | |||
/** | |||
* The URL which the weblogic server is listening on. | |||
*/ | |||
private String serverURL; | |||
/** | |||
* The delay (in seconds) to wait before shutting down. | |||
*/ | |||
private int delay = 0; | |||
/** | |||
* The location of the BEA Home under which this server is run. | |||
* WL6 only | |||
*/ | |||
private File beaHome = null; | |||
/** | |||
* Do the work. | |||
* | |||
* The work is actually done by creating a separate JVM to run the weblogic admin task | |||
* This approach allows the classpath of the helper task to be set. | |||
* | |||
* @exception BuildException if someting goes wrong with the build | |||
*/ | |||
public void execute() throws BuildException { | |||
if (username == null || password == null) { | |||
throw new BuildException("weblogic username and password must both be set"); | |||
} | |||
if (serverURL == null) { | |||
throw new BuildException("The url of the weblogic server must be provided."); | |||
} | |||
Java weblogicAdmin = new Java(this); | |||
weblogicAdmin.setFork(true); | |||
weblogicAdmin.setClassname("weblogic.Admin"); | |||
String args; | |||
if (beaHome == null) { | |||
args = serverURL + " SHUTDOWN " + username + " " + password + " " + delay; | |||
} else { | |||
args = " -url " + serverURL | |||
+ " -username " + username | |||
+ " -password " + password | |||
+ " SHUTDOWN " + " " + delay; | |||
} | |||
weblogicAdmin.createArg().setLine(args); | |||
weblogicAdmin.setClasspath(classpath); | |||
weblogicAdmin.execute(); | |||
} | |||
/** | |||
* The classpath to be used with the Java Virtual Machine that runs the Weblogic | |||
* Shutdown command; | |||
* | |||
* @param path the classpath to use when executing the weblogic admin task. | |||
*/ | |||
public void setClasspath(Path path) { | |||
this.classpath = path; | |||
} | |||
/** | |||
* The classpath to be used with the Java Virtual Machine that runs the Weblogic | |||
* Shutdown command; | |||
* @return the path to be configured. | |||
*/ | |||
public Path createClasspath() { | |||
if (classpath == null) { | |||
classpath = new Path(getProject()); | |||
} | |||
return classpath.createPath(); | |||
} | |||
/** | |||
* The username of the account which will be used to shutdown the server; | |||
* required. | |||
* | |||
* @param s the username. | |||
*/ | |||
public void setUser(String s) { | |||
this.username = s; | |||
} | |||
/** | |||
* The password for the account specified in the | |||
* user parameter; required | |||
* | |||
* @param s the password. | |||
*/ | |||
public void setPassword(String s) { | |||
this.password = s; | |||
} | |||
/** | |||
* Set the URL to which the weblogic server is listening | |||
* for T3 connections; required. | |||
* | |||
* @param s the url. | |||
*/ | |||
public void setUrl(String s) { | |||
this.serverURL = s; | |||
} | |||
/** | |||
* Set the delay (in seconds) before shutting down the server; | |||
* optional. | |||
* | |||
* @param s the selay. | |||
*/ | |||
public void setDelay(String s) { | |||
delay = Integer.parseInt(s); | |||
} | |||
/** | |||
* The location of the BEA Home; implicitly | |||
* selects Weblogic 6.0 shutdown; optional. | |||
* | |||
* @param beaHome the BEA Home directory. | |||
* | |||
*/ | |||
public void setBEAHome(File beaHome) { | |||
this.beaHome = beaHome; | |||
} | |||
} |