introduces a namign attribnute which can take one of four values ejb-name - use the ejb-name in the deployment descriptor to name the jar descriptor - name the jar based on the name of the deployment descriptor file basejarname - name the jars based on the given basejarname attribute directory - the directory containing the deployment descriptor is used ejb-name handling based on code submitted by Trevor Stewart <TREVORSTEWART@UP.COM> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269224 13f79535-47bb-0310-9956-ffa450edef68master
@@ -240,7 +240,7 @@ public class BorlandDeploymentTool extends GenericDeploymentTool | |||||
* Add any vendor specific files which should be included in the | * Add any vendor specific files which should be included in the | ||||
* EJB Jar. | * EJB Jar. | ||||
*/ | */ | ||||
protected void addVendorFiles(Hashtable ejbFiles, String baseName, String descriptorFileName) { | |||||
protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) { | |||||
File borlandDD = new File(getConfig().descriptorDir,META_DIR+BAS_DD); | File borlandDD = new File(getConfig().descriptorDir,META_DIR+BAS_DD); | ||||
if (borlandDD.exists()) { | if (borlandDD.exists()) { | ||||
@@ -72,6 +72,12 @@ import org.apache.tools.ant.*; | |||||
* list can then be accessed through the getFiles() method. | * list can then be accessed through the getFiles() method. | ||||
*/ | */ | ||||
public class DescriptorHandler extends org.xml.sax.HandlerBase { | public class DescriptorHandler extends org.xml.sax.HandlerBase { | ||||
static private final int STATE_LOOKING_EJBJAR = 1; | |||||
static private final int STATE_IN_EJBJAR = 2; | |||||
static private final int STATE_IN_BEANS = 3; | |||||
static private final int STATE_IN_SESSION = 4; | |||||
static private final int STATE_IN_ENTITY = 5; | |||||
private Task owningTask; | private Task owningTask; | ||||
private String publicId = null; | private String publicId = null; | ||||
@@ -80,11 +86,20 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { | |||||
* Bunch of constants used for storing entries in a hashtable, and for | * Bunch of constants used for storing entries in a hashtable, and for | ||||
* constructing the filenames of various parts of the ejb jar. | * constructing the filenames of various parts of the ejb jar. | ||||
*/ | */ | ||||
private static final String EJB_REF = "ejb-ref"; | |||||
private static final String HOME_INTERFACE = "home"; | private static final String HOME_INTERFACE = "home"; | ||||
private static final String REMOTE_INTERFACE = "remote"; | private static final String REMOTE_INTERFACE = "remote"; | ||||
private static final String BEAN_CLASS = "ejb-class"; | private static final String BEAN_CLASS = "ejb-class"; | ||||
private static final String PK_CLASS = "prim-key-class"; | private static final String PK_CLASS = "prim-key-class"; | ||||
private static final String EJB_NAME = "ejb-name"; | |||||
private static final String EJB_JAR = "ejb-jar"; | |||||
private static final String ENTERPRISE_BEANS = "enterprise-beans"; | |||||
private static final String ENTITY_BEAN = "entity"; | |||||
private static final String SESSION_BEAN = "session"; | |||||
/** | |||||
* The state of the parsing | |||||
*/ | |||||
private int parseState = STATE_LOOKING_EJBJAR; | |||||
/** | /** | ||||
* Instance variable used to store the name of the current element being | * Instance variable used to store the name of the current element being | ||||
@@ -105,12 +120,15 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { | |||||
*/ | */ | ||||
protected Hashtable ejbFiles = null; | protected Hashtable ejbFiles = null; | ||||
/** | |||||
* Instance variable that stores the value found in the <ejb-name> element | |||||
*/ | |||||
protected String ejbName = null; | |||||
private Hashtable fileDTDs = new Hashtable(); | private Hashtable fileDTDs = new Hashtable(); | ||||
private Hashtable resourceDTDs = new Hashtable(); | private Hashtable resourceDTDs = new Hashtable(); | ||||
private boolean inEJBRef = false; | |||||
/** | /** | ||||
* The directory containing the bean classes and interfaces. This is | * The directory containing the bean classes and interfaces. This is | ||||
* used for performing dependency file lookups. | * used for performing dependency file lookups. | ||||
@@ -188,6 +206,13 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { | |||||
return publicId; | return publicId; | ||||
} | } | ||||
/** | |||||
* Getter method that returns the value of the <ejb-name> element. | |||||
*/ | |||||
public String getEjbName() { | |||||
return ejbName; | |||||
} | |||||
/** | /** | ||||
* SAX parser call-back method that is used to initialize the values of some | * SAX parser call-back method that is used to initialize the values of some | ||||
* instance variables to ensure safe operation. | * instance variables to ensure safe operation. | ||||
@@ -195,7 +220,6 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { | |||||
public void startDocument() throws SAXException { | public void startDocument() throws SAXException { | ||||
this.ejbFiles = new Hashtable(10, 1); | this.ejbFiles = new Hashtable(10, 1); | ||||
this.currentElement = null; | this.currentElement = null; | ||||
inEJBRef = false; | |||||
} | } | ||||
@@ -210,8 +234,17 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { | |||||
throws SAXException { | throws SAXException { | ||||
this.currentElement = name; | this.currentElement = name; | ||||
currentText = ""; | currentText = ""; | ||||
if (name.equals(EJB_REF)) { | |||||
inEJBRef = true; | |||||
if (parseState == STATE_LOOKING_EJBJAR && name.equals(EJB_JAR)) { | |||||
parseState = STATE_IN_EJBJAR; | |||||
} | |||||
else if (parseState == STATE_IN_EJBJAR && name.equals(ENTERPRISE_BEANS)) { | |||||
parseState = STATE_IN_BEANS; | |||||
} | |||||
else if (parseState == STATE_IN_BEANS && name.equals(SESSION_BEAN)) { | |||||
parseState = STATE_IN_SESSION; | |||||
} | |||||
else if (parseState == STATE_IN_BEANS && name.equals(ENTITY_BEAN )) { | |||||
parseState = STATE_IN_ENTITY; | |||||
} | } | ||||
} | } | ||||
@@ -229,8 +262,17 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { | |||||
processElement(); | processElement(); | ||||
currentText = ""; | currentText = ""; | ||||
this.currentElement = ""; | this.currentElement = ""; | ||||
if (name.equals(EJB_REF)) { | |||||
inEJBRef = false; | |||||
if (parseState == STATE_IN_ENTITY && name.equals(ENTITY_BEAN )) { | |||||
parseState = STATE_IN_BEANS; | |||||
} | |||||
else if (parseState == STATE_IN_SESSION && name.equals(SESSION_BEAN)) { | |||||
parseState = STATE_IN_BEANS; | |||||
} | |||||
else if (parseState == STATE_IN_BEANS && name.equals(ENTERPRISE_BEANS)) { | |||||
parseState = STATE_IN_EJBJAR; | |||||
} | |||||
else if (parseState == STATE_IN_EJBJAR && name.equals(EJB_JAR)) { | |||||
parseState = STATE_LOOKING_EJBJAR; | |||||
} | } | ||||
} | } | ||||
@@ -257,7 +299,7 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { | |||||
protected void processElement() { | protected void processElement() { | ||||
if (inEJBRef) { | |||||
if (parseState != STATE_IN_ENTITY && parseState != STATE_IN_SESSION) { | |||||
return; | return; | ||||
} | } | ||||
@@ -281,5 +323,12 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { | |||||
ejbFiles.put(className, classFile); | ejbFiles.put(className, classFile); | ||||
} | } | ||||
} | } | ||||
// Get the value of the <ejb-name> tag. Only the first occurence. | |||||
if (currentElement.equals(EJB_NAME)) { | |||||
if ( ejbName == null ) { | |||||
ejbName = currentText.trim(); | |||||
} | |||||
} | |||||
} | } | ||||
} | } |
@@ -161,8 +161,25 @@ public class EjbJar extends MatchingTask { | |||||
* The list of configured DTD locations | * The list of configured DTD locations | ||||
*/ | */ | ||||
public ArrayList dtdLocations = new ArrayList(); | public ArrayList dtdLocations = new ArrayList(); | ||||
/** | |||||
* The naming scheme used to determine the generated jar name | |||||
* from the descriptor information | |||||
*/ | |||||
public NamingScheme namingScheme; | |||||
}; | }; | ||||
public static class NamingScheme extends EnumeratedAttribute { | |||||
static public final String EJB_NAME = "ejb-name"; | |||||
static public final String DIRECTORY = "directory"; | |||||
static public final String DESCRIPTOR = "descriptor"; | |||||
static public final String BASEJARNAME = "basejarname"; | |||||
public String[] getValues() { | |||||
return new String[] {EJB_NAME, DIRECTORY, DESCRIPTOR, BASEJARNAME}; | |||||
} | |||||
} | |||||
private Config config = new Config(); | private Config config = new Config(); | ||||
@@ -321,8 +338,32 @@ public class EjbJar extends MatchingTask { | |||||
*/ | */ | ||||
public void setBasejarname(String inValue) { | public void setBasejarname(String inValue) { | ||||
config.baseJarName = inValue; | config.baseJarName = inValue; | ||||
if (config.namingScheme == null) { | |||||
config.namingScheme = new NamingScheme(); | |||||
config.namingScheme.setValue(NamingScheme.BASEJARNAME); | |||||
} | |||||
else if (!config.namingScheme.getValue().equals(NamingScheme.BASEJARNAME)) { | |||||
throw new BuildException("The basejarname attribute is not compatible with the " + | |||||
config.namingScheme.getValue() + " naming scheme"); | |||||
} | |||||
} | } | ||||
/** | |||||
* Set the naming scheme used to determine the name of the generated jars | |||||
* from the deployment descriptor | |||||
* | |||||
* @param NamingScheme the namign scheme to be used | |||||
*/ | |||||
public void setNaming(NamingScheme namingScheme) { | |||||
config.namingScheme = namingScheme; | |||||
if (!config.namingScheme.getValue().equals(NamingScheme.BASEJARNAME) && | |||||
config.baseJarName != null) { | |||||
throw new BuildException("The basejarname attribute is not compatible with the " + | |||||
config.namingScheme.getValue() + " naming scheme"); | |||||
} | |||||
} | |||||
/** | /** | ||||
* Set the destination directory. | * Set the destination directory. | ||||
* | * | ||||
@@ -399,6 +440,16 @@ public class EjbJar extends MatchingTask { | |||||
if (config.descriptorDir == null) { | if (config.descriptorDir == null) { | ||||
config.descriptorDir = config.srcDir; | config.descriptorDir = config.srcDir; | ||||
} | } | ||||
if (config.namingScheme == null) { | |||||
config.namingScheme = new NamingScheme(); | |||||
config.namingScheme.setValue(NamingScheme.DESCRIPTOR); | |||||
} | |||||
else if (config.namingScheme.getValue().equals(NamingScheme.BASEJARNAME) && | |||||
config.baseJarName == null) { | |||||
throw new BuildException("The basejarname attribute must be specified " + | |||||
"with the basejarname naming scheme"); | |||||
} | |||||
} | } | ||||
/** | /** | ||||
@@ -469,13 +520,6 @@ public class EjbJar extends MatchingTask { | |||||
throw new BuildException(msg, pce); | throw new BuildException(msg, pce); | ||||
} | } | ||||
} // end of execute() | } // end of execute() | ||||
public static class NamignScheme extends EnumeratedAttribute { | |||||
public String[] getValues() { | |||||
return new String[] {"ejb-name", "directory", "descriptor"}; | |||||
} | |||||
} | |||||
} | } | ||||
@@ -306,6 +306,8 @@ public class GenericDeploymentTool implements EJBDeploymentTool { | |||||
checkConfiguration(descriptorFileName, saxParser); | checkConfiguration(descriptorFileName, saxParser); | ||||
try { | try { | ||||
handler = getDescriptorHandler(config.srcDir); | |||||
// Retrive the files to be added to JAR from EJB descriptor | // Retrive the files to be added to JAR from EJB descriptor | ||||
Hashtable ejbFiles = parseEjbFiles(descriptorFileName, saxParser); | Hashtable ejbFiles = parseEjbFiles(descriptorFileName, saxParser); | ||||
@@ -315,12 +317,14 @@ public class GenericDeploymentTool implements EJBDeploymentTool { | |||||
// Determine the JAR filename (without filename extension) | // Determine the JAR filename (without filename extension) | ||||
String baseName = getJarBaseName(descriptorFileName); | String baseName = getJarBaseName(descriptorFileName); | ||||
String ddPrefix = getVendorDDPrefix(baseName, descriptorFileName); | |||||
// First the regular deployment descriptor | // First the regular deployment descriptor | ||||
ejbFiles.put(META_DIR + EJB_DD, | ejbFiles.put(META_DIR + EJB_DD, | ||||
new File(config.descriptorDir, descriptorFileName)); | new File(config.descriptorDir, descriptorFileName)); | ||||
// now the vendor specific files, if any | // now the vendor specific files, if any | ||||
addVendorFiles(ejbFiles, baseName, descriptorFileName); | |||||
addVendorFiles(ejbFiles, ddPrefix); | |||||
// add any inherited files | // add any inherited files | ||||
checkAndAddInherited(ejbFiles); | checkAndAddInherited(ejbFiles); | ||||
@@ -423,7 +427,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool { | |||||
Hashtable ejbFiles = null; | Hashtable ejbFiles = null; | ||||
try { | try { | ||||
handler = getDescriptorHandler(config.srcDir); | |||||
/* Parse the ejb deployment descriptor. While it may not | /* Parse the ejb deployment descriptor. While it may not | ||||
* look like much, we use a SAXParser and an inner class to | * look like much, we use a SAXParser and an inner class to | ||||
@@ -484,14 +487,14 @@ public class GenericDeploymentTool implements EJBDeploymentTool { | |||||
String baseName = ""; | String baseName = ""; | ||||
// Work out what the base name is | // Work out what the base name is | ||||
if (config.baseJarName != null) { | |||||
if (config.namingScheme.getValue().equals(EjbJar.NamingScheme.BASEJARNAME)) { | |||||
String canonicalDescriptor = descriptorFileName.replace('\\', '/'); | String canonicalDescriptor = descriptorFileName.replace('\\', '/'); | ||||
int index = canonicalDescriptor.lastIndexOf('/'); | int index = canonicalDescriptor.lastIndexOf('/'); | ||||
if (index != -1) { | if (index != -1) { | ||||
baseName = descriptorFileName.substring(0, index + 1); | baseName = descriptorFileName.substring(0, index + 1); | ||||
} | } | ||||
baseName += config.baseJarName; | baseName += config.baseJarName; | ||||
} else { | |||||
} else if (config.namingScheme.getValue().equals(EjbJar.NamingScheme.DESCRIPTOR)) { | |||||
int lastSeparatorIndex = descriptorFileName.lastIndexOf(File.separator); | int lastSeparatorIndex = descriptorFileName.lastIndexOf(File.separator); | ||||
int endBaseName = -1; | int endBaseName = -1; | ||||
if (lastSeparatorIndex != -1) { | if (lastSeparatorIndex != -1) { | ||||
@@ -505,17 +508,52 @@ public class GenericDeploymentTool implements EJBDeploymentTool { | |||||
baseName = descriptorFileName.substring(0, endBaseName); | baseName = descriptorFileName.substring(0, endBaseName); | ||||
} | } | ||||
baseName = descriptorFileName.substring(0, endBaseName); | baseName = descriptorFileName.substring(0, endBaseName); | ||||
} else if (config.namingScheme.getValue().equals(EjbJar.NamingScheme.DIRECTORY)) { | |||||
int lastSeparatorIndex = descriptorFileName.lastIndexOf(File.separator); | |||||
String dirName = descriptorFileName.substring(0, lastSeparatorIndex); | |||||
int dirSeparatorIndex = dirName.lastIndexOf(File.separator); | |||||
if (dirSeparatorIndex != -1) { | |||||
dirName = dirName.substring(dirSeparatorIndex + 1); | |||||
} | |||||
baseName = dirName; | |||||
} else if (config.namingScheme.getValue().equals(EjbJar.NamingScheme.EJB_NAME)) { | |||||
baseName = handler.getEjbName(); | |||||
} | } | ||||
return baseName; | return baseName; | ||||
} | } | ||||
/** | |||||
* Get the prefix for vendor deployment descriptors. | |||||
* | |||||
* This will contain the path and the start of the descriptor name, | |||||
* depending on the naming scheme | |||||
*/ | |||||
public String getVendorDDPrefix(String baseName, String descriptorFileName) { | |||||
String ddPrefix = null; | |||||
if (config.namingScheme.getValue().equals(EjbJar.NamingScheme.DESCRIPTOR)) { | |||||
ddPrefix = baseName + config.baseNameTerminator; | |||||
} else if (config.namingScheme.getValue().equals(EjbJar.NamingScheme.BASEJARNAME) || | |||||
config.namingScheme.getValue().equals(EjbJar.NamingScheme.EJB_NAME) || | |||||
config.namingScheme.getValue().equals(EjbJar.NamingScheme.DIRECTORY)) { | |||||
String canonicalDescriptor = descriptorFileName.replace('\\', '/'); | |||||
int index = canonicalDescriptor.lastIndexOf('/'); | |||||
if (index == -1) { | |||||
ddPrefix = ""; | |||||
} | |||||
else { | |||||
ddPrefix = descriptorFileName.substring(0, index + 1); | |||||
} | |||||
} | |||||
return ddPrefix; | |||||
} | |||||
/** | /** | ||||
* Add any vendor specific files which should be included in the | * Add any vendor specific files which should be included in the | ||||
* EJB Jar. | * EJB Jar. | ||||
*/ | */ | ||||
protected void addVendorFiles(Hashtable ejbFiles, String baseName, String descriptorFileName) { | |||||
protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) { | |||||
// nothing to add for generic tool. | // nothing to add for generic tool. | ||||
} | } | ||||
@@ -334,7 +334,7 @@ public class IPlanetDeploymentTool extends GenericDeploymentTool { | |||||
* @param baseName String name of the EJB JAR file to be written (without | * @param baseName String name of the EJB JAR file to be written (without | ||||
* a filename extension). | * a filename extension). | ||||
*/ | */ | ||||
protected void addVendorFiles(Hashtable ejbFiles, String baseName, String descriptorFileName) { | |||||
protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) { | |||||
ejbFiles.put(META_DIR + IAS_DD, new File(getConfig().descriptorDir, | ejbFiles.put(META_DIR + IAS_DD, new File(getConfig().descriptorDir, | ||||
getIasDescriptorName())); | getIasDescriptorName())); | ||||
} | } | ||||
@@ -77,9 +77,7 @@ public class JbossDeploymentTool extends GenericDeploymentTool { | |||||
* Add any vendor specific files which should be included in the | * Add any vendor specific files which should be included in the | ||||
* EJB Jar. | * EJB Jar. | ||||
*/ | */ | ||||
protected void addVendorFiles(Hashtable ejbFiles, String baseName, String descriptorFileName) { | |||||
String ddPrefix = (usingBaseJarName() ? "" : baseName + getConfig().baseNameTerminator); | |||||
protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) { | |||||
File jbossDD = new File(getConfig().descriptorDir, ddPrefix + JBOSS_DD); | File jbossDD = new File(getConfig().descriptorDir, ddPrefix + JBOSS_DD); | ||||
if (jbossDD.exists()) { | if (jbossDD.exists()) { | ||||
ejbFiles.put(META_DIR + JBOSS_DD, jbossDD); | ejbFiles.put(META_DIR + JBOSS_DD, jbossDD); | ||||
@@ -297,21 +297,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { | |||||
* Add any vendor specific files which should be included in the | * Add any vendor specific files which should be included in the | ||||
* EJB Jar. | * EJB Jar. | ||||
*/ | */ | ||||
protected void addVendorFiles(Hashtable ejbFiles, String baseName, String descriptorFileName) { | |||||
String ddPrefix = null; | |||||
if (!usingBaseJarName()) { | |||||
ddPrefix = baseName + getConfig().baseNameTerminator; | |||||
} | |||||
else { | |||||
String canonicalDescriptor = descriptorFileName.replace('\\', '/'); | |||||
int index = canonicalDescriptor.lastIndexOf('/'); | |||||
if (index == -1) { | |||||
ddPrefix = ""; | |||||
} | |||||
else { | |||||
ddPrefix = descriptorFileName.substring(0, index + 1); | |||||
} | |||||
} | |||||
protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) { | |||||
File weblogicDD = new File(getConfig().descriptorDir, ddPrefix + WL_DD); | File weblogicDD = new File(getConfig().descriptorDir, ddPrefix + WL_DD); | ||||
if (weblogicDD.exists()) { | if (weblogicDD.exists()) { | ||||
@@ -102,22 +102,14 @@ public class WeblogicTOPLinkDeploymentTool extends WeblogicDeploymentTool { | |||||
* Add any vendor specific files which should be included in the | * Add any vendor specific files which should be included in the | ||||
* EJB Jar. | * EJB Jar. | ||||
*/ | */ | ||||
protected void addVendorFiles(Hashtable ejbFiles, String baseName, String descriptorFileName) { | |||||
super.addVendorFiles(ejbFiles, baseName, descriptorFileName); | |||||
protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) { | |||||
super.addVendorFiles(ejbFiles, ddPrefix); | |||||
// Then the toplink deployment descriptor | // Then the toplink deployment descriptor | ||||
// Setup a naming standard here?. | // Setup a naming standard here?. | ||||
File toplinkDD = null; | |||||
if (usingBaseJarName()) { | |||||
toplinkDD = new File(getConfig().descriptorDir, toplinkDescriptor); | |||||
} | |||||
else { | |||||
String ddPrefix = baseName + getConfig().baseNameTerminator; | |||||
File actualDir = (new File(getConfig().descriptorDir, ddPrefix)).getParentFile(); | |||||
toplinkDD = new File(actualDir, toplinkDescriptor); | |||||
} | |||||
File toplinkDD = new File(getConfig().descriptorDir, ddPrefix + toplinkDescriptor); | |||||
if (toplinkDD.exists()) { | if (toplinkDD.exists()) { | ||||
ejbFiles.put(META_DIR + toplinkDescriptor, | ejbFiles.put(META_DIR + toplinkDescriptor, | ||||