Browse Source

Support setting of the ejbc compiler class.

I also added some code to determine the compiler to use based on the publicID
of the DTD referenced in the descriptor.

Submitted by:	Ted Kandell [tkandell@verticalnet.com]


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268823 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 24 years ago
parent
commit
8a21be4984
4 changed files with 97 additions and 27 deletions
  1. +27
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java
  2. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java
  3. +4
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java
  4. +64
    -18
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java

+ 27
- 4
src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java View File

@@ -61,6 +61,8 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.AttributeList;

import org.apache.tools.ant.*;

/**
* Inner class used by EjbJar to facilitate the parsing of deployment
* descriptors and the capture of appropriate information. Extends
@@ -70,6 +72,10 @@ import org.xml.sax.AttributeList;
* list can then be accessed through the getFiles() method.
*/
public class DescriptorHandler extends org.xml.sax.HandlerBase {
private Task owningTask;
private String publicId = null;
/**
* Bunch of constants used for storing entries in a hashtable, and for
* constructing the filenames of various parts of the ejb jar.
@@ -111,7 +117,8 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase {
*/
private File srcDir;

public DescriptorHandler(File srcDir) {
public DescriptorHandler(Task task, File srcDir) {
this.owningTask = task;
this.srcDir = srcDir;
}
@@ -122,22 +129,28 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase {
File fileDTD = new File(location);
if (fileDTD.exists()) {
fileDTDs.put(publicId, fileDTD);
if (publicId != null) {
fileDTDs.put(publicId, fileDTD);
}
return;
}
if (getClass().getResource(location) != null) {
resourceDTDs.put(publicId, location);
if (publicId != null) {
resourceDTDs.put(publicId, location);
}
}
}

public InputSource resolveEntity(String publicId, String systemId)
throws SAXException
{
this.publicId = publicId;
File dtdFile = (File) fileDTDs.get(publicId);
if (dtdFile != null) {
try {
owningTask.log("Resolved " + publicId + " to local file " + dtdFile, Project.MSG_VERBOSE);
return new InputSource(new FileInputStream(dtdFile));
} catch( FileNotFoundException ex ) {
// ignore
@@ -148,10 +161,14 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase {
if (dtdResourceName != null) {
InputStream is = this.getClass().getResourceAsStream(dtdResourceName);
if( is != null ) {
owningTask.log("Resolved " + publicId + " to local resource " + dtdResourceName, Project.MSG_VERBOSE);
return new InputSource(is);
}
}
owningTask.log("Could not resolve ( publicId: " + publicId + ", systemId: " + systemId + ") to a local entity",
Project.MSG_INFO);
return null;
}

@@ -162,7 +179,13 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase {
return (ejbFiles == null) ? new Hashtable() : ejbFiles;
}


/**
* Get the publicId of the DTD
*/
public String getPublicId() {
return publicId;
}
/**
* SAX parser call-back method that is used to initialize the values of some
* instance variables to ensure safe operation.


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java View File

@@ -104,8 +104,8 @@ import org.apache.tools.ant.types.*;
public class EjbJar extends MatchingTask {
public static class DTDLocation {
private String publicId;
private String location;
private String publicId = null;
private String location = null;
public void setPublicId(String publicId) {
this.publicId = publicId;


+ 4
- 3
src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java View File

@@ -270,7 +270,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool {
}

protected DescriptorHandler getDescriptorHandler(File srcDir) {
return new DescriptorHandler(srcDir);
return new DescriptorHandler(task, srcDir);
}
public void processDescriptor(String descriptorFileName, SAXParser saxParser) {
@@ -380,7 +380,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool {
Project.MSG_INFO);
// Use helper method to write the jarfile
writeJar(baseName, jarFile, ejbFiles);
writeJar(baseName, jarFile, ejbFiles, handler.getPublicId());

}
else {
@@ -438,7 +438,8 @@ public class GenericDeploymentTool implements EJBDeploymentTool {
* filenames/java.io.Files in the Hashtable stored on the instance variable
* ejbFiles.
*/
protected void writeJar(String baseName, File jarfile, Hashtable files) throws BuildException{
protected void writeJar(String baseName, File jarfile, Hashtable files,
String publicId) throws BuildException{

JarOutputStream jarStream = null;
try {


+ 64
- 18
src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java View File

@@ -71,10 +71,11 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
= "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN";
public static final String PUBLICID_EJB20
= "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN";

public static final String PUBLICID_WEBLOGIC_EJB
public static final String PUBLICID_WEBLOGIC_EJB510
= "-//BEA Systems, Inc.//DTD WebLogic 5.1.0 EJB//EN";
public static final String PUBLICID_WEBLOGIC_EJB600
= "-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN";

protected static final String DEFAULT_WL51_EJB11_DTD_LOCATION
= "/weblogic/ejb/deployment/xml/ejb-jar.dtd";
protected static final String DEFAULT_WL60_EJB11_DTD_LOCATION
@@ -82,12 +83,19 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
protected static final String DEFAULT_WL60_EJB20_DTD_LOCATION
= "/weblogic/ejb20/dd/xml/ejb20-jar.dtd";

protected static final String DEFAULT_WL_DTD_LOCATION
protected static final String DEFAULT_WL51_DTD_LOCATION
= "/weblogic/ejb/deployment/xml/weblogic-ejb-jar.dtd";
protected static final String DEFAULT_WL60_51_DTD_LOCATION
= "/weblogic/ejb20/dd/xml/weblogic510-ejb-jar.dtd";
protected static final String DEFAULT_WL60_DTD_LOCATION
= "/weblogic/ejb20/dd/xml/weblogic600-ejb-jar.dtd";

protected static final String WL_DD = "weblogic-ejb-jar.xml";
protected static final String WL_CMP_DD = "weblogic-cmp-rdbms-jar.xml";

protected static final String COMPILER_EJB11 = "weblogic.ejbc";
protected static final String COMPILER_EJB20 = "weblogic.ejbc20";
/** Instance variable that stores the suffix for the weblogic jarfile. */
private String jarSuffix = ".jar";

@@ -98,9 +106,11 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
private String ejb11DTD;
/** Instance variable that determines whether generic ejb jars are kept. */

private boolean keepgenerated = false;

/** Instance variable that stores the fully qualified classname of the weblogic EJBC compiler */
private String ejbcClass = null;

private String additionalArgs = "";

private boolean keepGeneric = false;
@@ -179,7 +189,23 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
this.additionalArgs = args;
}
/**
* Set the classname of the ejbc compiler
*/
public void setEjbcClass(String ejbcClass)
{
this.ejbcClass = ejbcClass;
}
/**
* Get the ejbc compiler class
*/
public String getEjbcClass()
{
return ejbcClass;
}
/**
* Setter used to store the location of the ejb-jar DTD. This can be a file on the system
* or a resource on the classpath.
@@ -231,7 +257,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {

protected DescriptorHandler getDescriptorHandler(File srcDir) {
DescriptorHandler handler = new DescriptorHandler(srcDir);
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, DEFAULT_WL51_EJB11_DTD_LOCATION);
@@ -239,10 +265,10 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
handler.registerDTD(PUBLICID_EJB11, ejb11DTD);
handler.registerDTD(PUBLICID_EJB20, DEFAULT_WL60_EJB20_DTD_LOCATION);
for (Iterator i = getConfig().dtdLocations.iterator(); i.hasNext();) {
EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation)i.next();
handler.registerDTD(dtdLocation.getPublicId(), dtdLocation.getLocation());
handler.registerDTD(dtdLocation.getPublicId(),
dtdLocation.getLocation());
}
return handler;
@@ -250,7 +276,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {

protected DescriptorHandler getWeblogicDescriptorHandler(final File srcDir) {
DescriptorHandler handler =
new DescriptorHandler(srcDir) {
new DescriptorHandler(getTask(), srcDir) {
protected void processElement() {
if (currentElement.equals("type-storage")) {
// Get the filename of vendor specific descriptor
@@ -265,8 +291,11 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
}
};

handler.registerDTD(PUBLICID_WEBLOGIC_EJB,
weblogicDTD == null ? DEFAULT_WL_DTD_LOCATION : weblogicDTD);
handler.registerDTD(PUBLICID_WEBLOGIC_EJB510, DEFAULT_WL51_DTD_LOCATION);
handler.registerDTD(PUBLICID_WEBLOGIC_EJB510, DEFAULT_WL60_51_DTD_LOCATION);
handler.registerDTD(PUBLICID_WEBLOGIC_EJB600, DEFAULT_WL60_DTD_LOCATION);
handler.registerDTD(PUBLICID_WEBLOGIC_EJB510, weblogicDTD);
handler.registerDTD(PUBLICID_WEBLOGIC_EJB600, weblogicDTD);
for (Iterator i = getConfig().dtdLocations.iterator(); i.hasNext();) {
EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation)i.next();
@@ -354,9 +383,11 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
* @param destJar java.io.File representing the destination, WebLogic
* jarfile.
*/
private void buildWeblogicJar(File sourceJar, File destJar) {
private void buildWeblogicJar(File sourceJar, File destJar, String publicId) {
org.apache.tools.ant.taskdefs.Java javaTask = null;
String ejbcClassName = ejbcClass;
try {
String args = additionalArgs;
if (keepgenerated) {
@@ -371,7 +402,21 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
javaTask = (Java) getTask().getProject().createTask("java");
javaTask.setTaskName("ejbc");
javaTask.setClassname("weblogic.ejbc");
if (ejbcClassName == null) {
// try to determine it from publicId
if (PUBLICID_EJB11.equals(publicId)) {
ejbcClassName = COMPILER_EJB11;
}
else if (PUBLICID_EJB20.equals(publicId)) {
ejbcClassName = COMPILER_EJB20;
}
else {
log("Unrecognized publicId " + publicId + " - using EJB 1.1 compiler", Project.MSG_WARN);
ejbcClassName = COMPILER_EJB11;
}
}
javaTask.setClassname(ejbcClassName);
Commandline.Argument arguments = javaTask.createArg();
arguments.setLine(args);
Path classpath = wlClasspath;
@@ -388,14 +433,14 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
}

log("Calling weblogic.ejbc for " + sourceJar.toString(),
log("Calling " + ejbcClassName + " 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 ejbc. Details: " + e.toString();
String msg = "Exception while calling " + ejbcClassName + ". Details: " + e.toString();
throw new BuildException(msg, e);
}
}
@@ -405,14 +450,15 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
* filenames/java.io.Files in the Hashtable stored on the instance variable
* ejbFiles.
*/
protected void writeJar(String baseName, File jarFile, Hashtable files) throws BuildException {
protected void writeJar(String baseName, File jarFile, Hashtable files,
String publicId) throws BuildException {
// need to create a generic jar first.
File genericJarFile = super.getVendorOutputJarFile(baseName);
super.writeJar(baseName, genericJarFile, files);
super.writeJar(baseName, genericJarFile, files, publicId);
if (alwaysRebuild || isRebuildRequired(genericJarFile, jarFile))
{
buildWeblogicJar(genericJarFile, jarFile);
buildWeblogicJar(genericJarFile, jarFile, publicId);
}
if (!keepGeneric) {
log("deleting generic jar " + genericJarFile.toString(),


Loading…
Cancel
Save