Fields Summary |
---|
public static final String | PUBLICID_EJB11ID for ejb 1.1 |
public static final String | PUBLICID_EJB20ID for ejb 2.0 |
protected static final String | SCHEMA_DIRSchema directory |
protected static final String | WAS_EXT |
protected static final String | WAS_BND |
protected static final String | WAS_CMP_MAP |
protected static final String | WAS_CMP_SCHEMA |
private static final org.apache.tools.ant.util.FileUtils | FILE_UTILS |
private String | jarSuffixInstance variable that stores the suffix for the websphere jarfile. |
private String | ejb11DTDInstance variable that stores the location of the ejb 1.1 DTD file. |
private boolean | keepGenericInstance variable that determines whether generic ejb jars are kept. |
private boolean | alwaysRebuild |
private boolean | ejbdeploy |
private boolean | newCMPIndicates if the old CMP location convention is to be used. |
private org.apache.tools.ant.types.Path | wasClasspathThe classpath to the websphere classes. |
private String | dbVendorThe DB Vendor name, the EJB is persisted against |
private String | dbNameThe name of the database to create. (For top-down mapping only) |
private String | dbSchemaThe name of the schema to create. (For top-down mappings only) |
private boolean | codegentrue - Only generate the deployment code, do not run RMIC or Javac |
private boolean | quiettrue - Only output error messages, suppress informational messages |
private boolean | novalidatetrue - Disable the validation steps |
private boolean | nowarntrue - Disable warning and informational messages |
private boolean | noinformtrue - Disable informational messages |
private boolean | tracetrue - Enable internal tracing |
private String | rmicOptionsAdditional options for RMIC |
private boolean | use35MappingRulestrue- Use the WebSphere 3.5 compatible mapping rules |
private String | tempdirthe scratchdir for the ejbdeploy operation |
private File | websphereHomethe home directory for websphere |
Methods Summary |
---|
protected void | addVendorFiles(java.util.Hashtable ejbFiles, java.lang.String baseName)Add any vendor specific files which should be included in the EJB Jar.
String ddPrefix = (usingBaseJarName() ? "" : baseName);
String dbPrefix = (dbVendor == null) ? "" : dbVendor + "-";
// Get the Extensions document
File websphereEXT = new File(getConfig().descriptorDir, ddPrefix + WAS_EXT);
if (websphereEXT.exists()) {
ejbFiles.put(META_DIR + WAS_EXT,
websphereEXT);
} else {
log("Unable to locate websphere extensions. "
+ "It was expected to be in "
+ websphereEXT.getPath(), Project.MSG_VERBOSE);
}
File websphereBND = new File(getConfig().descriptorDir, ddPrefix + WAS_BND);
if (websphereBND.exists()) {
ejbFiles.put(META_DIR + WAS_BND,
websphereBND);
} else {
log("Unable to locate websphere bindings. "
+ "It was expected to be in "
+ websphereBND.getPath(), Project.MSG_VERBOSE);
}
if (!newCMP) {
log("The old method for locating CMP files has been DEPRECATED.",
Project.MSG_VERBOSE);
log("Please adjust your websphere descriptor and set "
+ "newCMP=\"true\" to use the new CMP descriptor "
+ "inclusion mechanism. ", Project.MSG_VERBOSE);
} else {
// We attempt to put in the MAP and Schema files of CMP beans
try {
// Add the Map file
File websphereMAP = new File(getConfig().descriptorDir,
ddPrefix + dbPrefix + WAS_CMP_MAP);
if (websphereMAP.exists()) {
ejbFiles.put(META_DIR + WAS_CMP_MAP,
websphereMAP);
} else {
log("Unable to locate the websphere Map: "
+ websphereMAP.getPath(), Project.MSG_VERBOSE);
}
File websphereSchema = new File(getConfig().descriptorDir,
ddPrefix + dbPrefix + WAS_CMP_SCHEMA);
if (websphereSchema.exists()) {
ejbFiles.put(META_DIR + SCHEMA_DIR + WAS_CMP_SCHEMA,
websphereSchema);
} else {
log("Unable to locate the websphere Schema: "
+ websphereSchema.getPath(), Project.MSG_VERBOSE);
}
// Theres nothing else to see here...keep moving sonny
} catch (Exception e) {
String msg = "Exception while adding Vendor specific files: "
+ e.toString();
throw new BuildException(msg, e);
}
}
|
private void | buildWebsphereJar(java.io.File sourceJar, java.io.File destJar)Helper method invoked by execute() for each websphere jar to be built.
Encapsulates the logic of constructing a java task for calling
websphere.ejbdeploy and executing it.
try {
if (ejbdeploy) {
Java javaTask = new Java(getTask());
// Set the JvmArgs
javaTask.createJvmarg().setValue("-Xms64m");
javaTask.createJvmarg().setValue("-Xmx128m");
// Set the Environment variable
Environment.Variable var = new Environment.Variable();
var.setKey("websphere.lib.dir");
File libdir = new File(websphereHome, "lib");
var.setValue(libdir.getAbsolutePath());
javaTask.addSysproperty(var);
// Set the working directory
javaTask.setDir(websphereHome);
// Set the Java class name
javaTask.setTaskName("ejbdeploy");
javaTask.setClassname("com.ibm.etools.ejbdeploy.EJBDeploy");
javaTask.createArg().setValue(sourceJar.getPath());
javaTask.createArg().setValue(tempdir);
javaTask.createArg().setValue(destJar.getPath());
javaTask.createArg().setLine(getOptions());
if (getCombinedClasspath() != null
&& getCombinedClasspath().toString().length() > 0) {
javaTask.createArg().setValue("-cp");
javaTask.createArg().setValue(getCombinedClasspath().toString());
}
Path classpath = wasClasspath;
if (classpath == null) {
classpath = getCombinedClasspath();
}
if (classpath != null) {
javaTask.setClasspath(classpath);
javaTask.setFork(true);
} else {
javaTask.setFork(true);
}
log("Calling websphere.ejbdeploy for " + sourceJar.toString(),
Project.MSG_VERBOSE);
javaTask.execute();
}
} catch (Exception e) {
// Have to catch this because of the semantics of calling main()
String msg = "Exception while calling ejbdeploy. Details: " + e.toString();
throw new BuildException(msg, e);
}
|
public org.apache.tools.ant.types.Path | createWASClasspath()Get the classpath to the websphere classpaths.
if (wasClasspath == null) {
wasClasspath = new Path(getTask().getProject());
}
return wasClasspath.createPath();
|
protected java.lang.ClassLoader | getClassLoaderFromJar(java.io.File classjar)Helper method invoked by isRebuildRequired to get a ClassLoader for a
Jar File passed to it.
Path lookupPath = new Path(getTask().getProject());
lookupPath.setLocation(classjar);
Path classpath = getCombinedClasspath();
if (classpath != null) {
lookupPath.append(classpath);
}
return getTask().getProject().createClassLoader(lookupPath);
|
protected DescriptorHandler | getDescriptorHandler(java.io.File srcDir){@inheritDoc}.
DescriptorHandler handler = new DescriptorHandler(getTask(), srcDir);
// register all the DTDs, both the ones that are known and
// any supplied by the user
handler.registerDTD(PUBLICID_EJB11, ejb11DTD);
for (Iterator i = getConfig().dtdLocations.iterator(); i.hasNext();) {
EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation) i.next();
handler.registerDTD(dtdLocation.getPublicId(), dtdLocation.getLocation());
}
return handler;
|
protected java.lang.String | getOptions()Gets the options for the EJB Deploy operation
// Set the options
StringBuffer options = new StringBuffer();
if (dbVendor != null) {
options.append(" -dbvendor ").append(dbVendor);
}
if (dbName != null) {
options.append(" -dbname \"").append(dbName).append("\"");
}
if (dbSchema != null) {
options.append(" -dbschema \"").append(dbSchema).append("\"");
}
if (codegen) {
options.append(" -codegen");
}
if (quiet) {
options.append(" -quiet");
}
if (novalidate) {
options.append(" -novalidate");
}
if (nowarn) {
options.append(" -nowarn");
}
if (noinform) {
options.append(" -noinform");
}
if (trace) {
options.append(" -trace");
}
if (use35MappingRules) {
options.append(" -35");
}
if (rmicOptions != null) {
options.append(" -rmic \"").append(rmicOptions).append("\"");
}
return options.toString();
|
java.io.File | getVendorOutputJarFile(java.lang.String baseName)Get the vendor specific name of the Jar that will be output. The
modification date of this jar will be checked against the dependent
bean classes.
return new File(getDestDir(), baseName + jarSuffix);
|
protected DescriptorHandler | getWebsphereDescriptorHandler(java.io.File srcDir)Get a description handler.
DescriptorHandler handler =
new DescriptorHandler(getTask(), srcDir) {
protected void processElement() {
}
};
for (Iterator i = getConfig().dtdLocations.iterator(); i.hasNext();) {
EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation) i.next();
handler.registerDTD(dtdLocation.getPublicId(), dtdLocation.getLocation());
}
return handler;
|
protected boolean | isRebuildRequired(java.io.File genericJarFile, java.io.File websphereJarFile)Helper method to check to see if a websphere EBJ1.1 jar needs to be
rebuilt using ejbdeploy. Called from writeJar it sees if the "Bean"
classes are the only thing that needs to be updated and either updates
the Jar with the Bean classfile or returns true, saying that the whole
websphere jar needs to be regened with ejbdeploy. This allows faster
build times for working developers.
The way websphere ejbdeploy works is it creates wrappers for the
publicly defined methods as they are exposed in the remote interface.
If the actual bean changes without changing the the method signatures
then only the bean classfile needs to be updated and the rest of the
websphere jar file can remain the same. If the Interfaces, ie. the
method signatures change or if the xml deployment descriptors changed,
the whole jar needs to be rebuilt with ejbdeploy. This is not strictly
true for the xml files. If the JNDI name changes then the jar doesnt
have to be rebuild, but if the resources references change then it
does. At this point the websphere jar gets rebuilt if the xml files
change at all.
boolean rebuild = false;
JarFile genericJar = null;
JarFile wasJar = null;
File newwasJarFile = null;
JarOutputStream newJarStream = null;
try {
log("Checking if websphere Jar needs to be rebuilt for jar "
+ websphereJarFile.getName(), Project.MSG_VERBOSE);
// Only go forward if the generic and the websphere file both exist
if (genericJarFile.exists() && genericJarFile.isFile()
&& websphereJarFile.exists() && websphereJarFile.isFile()) {
//open jar files
genericJar = new JarFile(genericJarFile);
wasJar = new JarFile(websphereJarFile);
Hashtable genericEntries = new Hashtable();
Hashtable wasEntries = new Hashtable();
Hashtable replaceEntries = new Hashtable();
//get the list of generic jar entries
for (Enumeration e = genericJar.entries(); e.hasMoreElements();) {
JarEntry je = (JarEntry) e.nextElement();
genericEntries.put(je.getName().replace('\\", '/"), je);
}
//get the list of websphere jar entries
for (Enumeration e = wasJar.entries(); e.hasMoreElements();) {
JarEntry je = (JarEntry) e.nextElement();
wasEntries.put(je.getName(), je);
}
//Cycle Through generic and make sure its in websphere
ClassLoader genericLoader = getClassLoaderFromJar(genericJarFile);
for (Enumeration e = genericEntries.keys(); e.hasMoreElements();) {
String filepath = (String) e.nextElement();
if (wasEntries.containsKey(filepath)) {
// File name/path match
// Check files see if same
JarEntry genericEntry = (JarEntry) genericEntries.get(filepath);
JarEntry wasEntry = (JarEntry) wasEntries.get(filepath);
if ((genericEntry.getCrc() != wasEntry.getCrc())
|| (genericEntry.getSize() != wasEntry.getSize())) {
if (genericEntry.getName().endsWith(".class")) {
//File are different see if its an object or an interface
String classname
= genericEntry.getName().replace(File.separatorChar, '.");
classname = classname.substring(0, classname.lastIndexOf(".class"));
Class genclass = genericLoader.loadClass(classname);
if (genclass.isInterface()) {
//Interface changed rebuild jar.
log("Interface " + genclass.getName()
+ " has changed", Project.MSG_VERBOSE);
rebuild = true;
break;
} else {
//Object class Changed update it.
replaceEntries.put(filepath, genericEntry);
}
} else {
// is it the manifest. If so ignore it
if (!genericEntry.getName().equals("META-INF/MANIFEST.MF")) {
//File other then class changed rebuild
log("Non class file " + genericEntry.getName()
+ " has changed", Project.MSG_VERBOSE);
rebuild = true;
}
break;
}
}
} else {
// a file doesn't exist rebuild
log("File " + filepath + " not present in websphere jar",
Project.MSG_VERBOSE);
rebuild = true;
break;
}
}
if (!rebuild) {
log("No rebuild needed - updating jar", Project.MSG_VERBOSE);
newwasJarFile = new File(websphereJarFile.getAbsolutePath() + ".temp");
if (newwasJarFile.exists()) {
newwasJarFile.delete();
}
newJarStream = new JarOutputStream(new FileOutputStream(newwasJarFile));
newJarStream.setLevel(0);
//Copy files from old websphere jar
for (Enumeration e = wasEntries.elements(); e.hasMoreElements();) {
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int bytesRead;
InputStream is;
JarEntry je = (JarEntry) e.nextElement();
if (je.getCompressedSize() == -1
|| je.getCompressedSize() == je.getSize()) {
newJarStream.setLevel(0);
} else {
newJarStream.setLevel(JAR_COMPRESS_LEVEL);
}
// Update with changed Bean class
if (replaceEntries.containsKey(je.getName())) {
log("Updating Bean class from generic Jar " + je.getName(),
Project.MSG_VERBOSE);
// Use the entry from the generic jar
je = (JarEntry) replaceEntries.get(je.getName());
is = genericJar.getInputStream(je);
} else {
//use fle from original websphere jar
is = wasJar.getInputStream(je);
}
newJarStream.putNextEntry(new JarEntry(je.getName()));
while ((bytesRead = is.read(buffer)) != -1) {
newJarStream.write(buffer, 0, bytesRead);
}
is.close();
}
} else {
log("websphere Jar rebuild needed due to changed "
+ "interface or XML", Project.MSG_VERBOSE);
}
} else {
rebuild = true;
}
} catch (ClassNotFoundException cnfe) {
String cnfmsg = "ClassNotFoundException while processing ejb-jar file"
+ ". Details: "
+ cnfe.getMessage();
throw new BuildException(cnfmsg, cnfe);
} catch (IOException ioe) {
String msg = "IOException while processing ejb-jar file "
+ ". Details: "
+ ioe.getMessage();
throw new BuildException(msg, ioe);
} finally {
// need to close files and perhaps rename output
if (genericJar != null) {
try {
genericJar.close();
} catch (IOException closeException) {
// Ignore
}
}
if (wasJar != null) {
try {
wasJar.close();
} catch (IOException closeException) {
// Ignore
}
}
if (newJarStream != null) {
try {
newJarStream.close();
} catch (IOException closeException) {
// Ignore
}
try {
FILE_UTILS.rename(newwasJarFile, websphereJarFile);
} catch (IOException renameException) {
log(renameException.getMessage(), Project.MSG_WARN);
rebuild = true;
}
}
}
return rebuild;
|
public void | setCodegen(boolean codegen)Flag, default false, to only generate the deployment
code, do not run RMIC or Javac
this.codegen = codegen;
|
public void | setDbname(java.lang.String dbName)Sets the name of the Database to create; optional.
this.dbName = dbName;
|
public void | setDbschema(java.lang.String dbSchema)Sets the name of the schema to create; optional.
this.dbSchema = dbSchema;
|
public void | setDbvendor(java.lang.String dbvendor)Sets the DB Vendor for the Entity Bean mapping ; optional.
Valid options can be obtained by running the following command:
<WAS_HOME>/bin/EJBDeploy.[sh/bat] -help
This is also used to determine the name of the Map.mapxmi and
Schema.dbxmi files, for example Account-DB2UDB_V81-Map.mapxmi
and Account-DB2UDB_V81-Schema.dbxmi.
this.dbVendor = dbvendor;
|
public void | setEJBdtd(java.lang.String inString)Setter used to store the location of the Sun's Generic EJB DTD. This
can be a file on the system or a resource on the classpath.
this.ejb11DTD = inString;
|
public void | setEjbdeploy(boolean ejbdeploy)Decide, wether ejbdeploy should be called or not;
optional, default true.
this.ejbdeploy = ejbdeploy;
|
public void | setKeepgeneric(boolean inValue)This controls whether the generic file used as input to
ejbdeploy is retained; optional, default false.
this.keepGeneric = inValue;
|
public void | setNewCMP(boolean newCMP)Set the value of the newCMP scheme. The old CMP scheme locates the
websphere CMP descriptor based on the naming convention where the
websphere CMP file is expected to be named with the bean name as the
prefix. Under this scheme the name of the CMP descriptor does not match
the name actually used in the main websphere EJB descriptor. Also,
descriptors which contain multiple CMP references could not be used.
this.newCMP = newCMP;
|
public void | setNoinform(boolean noinform)Flag to disable informational messages; optional, default false.
this.noinform = noinform;
|
public void | setNovalidate(boolean novalidate)Flag to disable the validation steps; optional, default false.
this.novalidate = novalidate;
|
public void | setNowarn(boolean nowarn)Flag to disable warning and informational messages; optional, default false.
this.nowarn = nowarn;
|
public void | setOldCMP(boolean oldCMP)Set the value of the oldCMP scheme. This is an antonym for newCMP
this.newCMP = !oldCMP;
|
public void | setQuiet(boolean quiet)Flag, default true, to only output error messages.
this.quiet = quiet;
|
public void | setRebuild(boolean rebuild)Set the rebuild flag to false to only update changes in the jar rather
than rerunning ejbdeploy; optional, default true.
this.alwaysRebuild = rebuild;
|
public void | setRmicoptions(java.lang.String options)Set the rmic options.
this.rmicOptions = options;
|
public void | setSuffix(java.lang.String inString)String value appended to the basename of the deployment
descriptor to create the filename of the WebLogic EJB
jar file. Optional, default '.jar'.
this.jarSuffix = inString;
|
public void | setTempdir(java.lang.String tempdir)The directory, where ejbdeploy will write temporary files;
optional, defaults to '_ejbdeploy_temp'.
this.tempdir = tempdir;
|
public void | setTrace(boolean trace)Flag to enable internal tracing when set, optional, default false.
this.trace = trace;
|
public void | setUse35(boolean attr)Flag to use the WebSphere 3.5 compatible mapping rules ; optional, default false.
use35MappingRules = attr;
|
public void | setWASClasspath(org.apache.tools.ant.types.Path wasClasspath)Set the websphere classpath.
this.wasClasspath = wasClasspath;
|
public void | validateConfigured()Called to validate that the tool parameters have been configured.
super.validateConfigured();
if (ejbdeploy) {
String home = getTask().getProject().getProperty("websphere.home");
if (home == null) {
throw new BuildException("The 'websphere.home' property must "
+ "be set when 'ejbdeploy=true'");
}
websphereHome = getTask().getProject().resolveFile(home);
}
|
protected void | writeJar(java.lang.String baseName, java.io.File jarFile, java.util.Hashtable files, java.lang.String publicId){@inheritDoc}.
if (ejbdeploy) {
// create the -generic.jar, if required
File genericJarFile = super.getVendorOutputJarFile(baseName);
super.writeJar(baseName, genericJarFile, files, publicId);
// create the output .jar, if required
if (alwaysRebuild || isRebuildRequired(genericJarFile, jarFile)) {
buildWebsphereJar(genericJarFile, jarFile);
}
if (!keepGeneric) {
log("deleting generic jar " + genericJarFile.toString(),
Project.MSG_VERBOSE);
genericJarFile.delete();
}
} else {
// create the "undeployed" output .jar, if required
super.writeJar(baseName, jarFile, files, publicId);
}
|