00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 package org.objectweb.jonas.ant;
00056
00057
00058 import java.io.File;
00059 import java.util.ArrayList;
00060 import java.util.Iterator;
00061 import java.util.List;
00062 import javax.xml.parsers.ParserConfigurationException;
00063 import javax.xml.parsers.SAXParser;
00064 import javax.xml.parsers.SAXParserFactory;
00065 import org.apache.tools.ant.BuildException;
00066 import org.apache.tools.ant.DirectoryScanner;
00067 import org.apache.tools.ant.Project;
00068 import org.apache.tools.ant.taskdefs.MatchingTask;
00069 import org.apache.tools.ant.types.EnumeratedAttribute;
00070 import org.apache.tools.ant.types.FileSet;
00071 import org.apache.tools.ant.types.Path;
00072 import org.xml.sax.SAXException;
00073
00096 public class EjbJar extends MatchingTask {
00097
00101 public static class DTDLocation
00102 extends org.apache.tools.ant.types.DTDLocation {
00103 }
00104
00109 static class Config {
00114 public File srcDir;
00115
00120 public File descriptorDir;
00121
00123 public String baseNameTerminator = "-";
00124
00126 public String baseJarName;
00127
00132 public boolean flatDestDir = false;
00133
00137 public Path classpath;
00138
00142 public List supportFileSets = new ArrayList();
00143
00147 public ArrayList dtdLocations = new ArrayList();
00148
00153 public NamingScheme namingScheme;
00154
00158 public File manifest;
00159
00163 public String analyzer;
00164 }
00165
00170 public static class NamingScheme extends EnumeratedAttribute {
00175 public static final String EJB_NAME = "ejb-name";
00176
00181 public static final String DIRECTORY = "directory";
00182
00187 public static final String DESCRIPTOR = "descriptor";
00188
00193 public static final String BASEJARNAME = "basejarname";
00194
00200 public String[] getValues() {
00201 return new String[] {EJB_NAME, DIRECTORY, DESCRIPTOR, BASEJARNAME};
00202 }
00203 }
00204
00210 public static class CMPVersion extends EnumeratedAttribute {
00211 public static final String CMP1_0 = "1.0";
00212 public static final String CMP2_0 = "2.0";
00213 public String[] getValues() {
00214 return new String[]{
00215 CMP1_0,
00216 CMP2_0,
00217 };
00218 }
00219 }
00224 private Config config = new Config();
00225
00226
00233 private File destDir;
00234
00236 private String genericJarSuffix = "-generic.jar";
00237
00239 private String cmpVersion = CMPVersion.CMP1_0;
00240
00242 private ArrayList deploymentTools = new ArrayList();
00243
00251 protected void addDeploymentTool(EJBDeploymentTool deploymentTool) {
00252 deploymentTool.setTask(this);
00253 deploymentTools.add(deploymentTool);
00254 }
00255
00261 public JonasDeploymentTool createJonas() {
00262 log("JOnAS deployment tools", Project.MSG_VERBOSE);
00263
00264 JonasDeploymentTool tool = new JonasDeploymentTool();
00265 addDeploymentTool(tool);
00266 return tool;
00267 }
00268
00275 public Path createClasspath() {
00276 if (config.classpath == null) {
00277 config.classpath = new Path(getProject());
00278 }
00279 return config.classpath.createPath();
00280 }
00281
00289 public DTDLocation createDTD() {
00290 DTDLocation dtdLocation = new DTDLocation();
00291 config.dtdLocations.add(dtdLocation);
00292
00293 return dtdLocation;
00294 }
00295
00301 public FileSet createSupport() {
00302 FileSet supportFileSet = new FileSet();
00303 config.supportFileSets.add(supportFileSet);
00304 return supportFileSet;
00305 }
00306
00307
00319 public void setManifest(File manifest) {
00320 config.manifest = manifest;
00321 }
00322
00330 public void setSrcdir(File inDir) {
00331 config.srcDir = inDir;
00332 }
00333
00343 public void setDescriptordir(File inDir) {
00344 config.descriptorDir = inDir;
00345 }
00346
00352 public void setDependency(String analyzer) {
00353 config.analyzer = analyzer;
00354 }
00355
00363 public void setBasejarname(String inValue) {
00364 config.baseJarName = inValue;
00365 if (config.namingScheme == null) {
00366 config.namingScheme = new NamingScheme();
00367 config.namingScheme.setValue(NamingScheme.BASEJARNAME);
00368 } else if (!config.namingScheme.getValue().equals(NamingScheme.BASEJARNAME)) {
00369 throw new BuildException("The basejarname attribute is not "
00370 + "compatible with the "
00371 + config.namingScheme.getValue() + " naming scheme");
00372 }
00373 }
00374
00381 public void setNaming(NamingScheme namingScheme) {
00382 config.namingScheme = namingScheme;
00383 if (!config.namingScheme.getValue().equals(NamingScheme.BASEJARNAME)
00384 && config.baseJarName != null) {
00385 throw new BuildException("The basejarname attribute is not "
00386 + "compatible with the "
00387 + config.namingScheme.getValue() + " naming scheme");
00388 }
00389 }
00390
00397 public File getDestdir() {
00398 return this.destDir;
00399 }
00400
00411 public void setDestdir(File inDir) {
00412 this.destDir = inDir;
00413 }
00414
00421 public String getCmpversion() {
00422 return this.cmpVersion;
00423 }
00424
00434 public void setCmpversion(CMPVersion version) {
00435 this.cmpVersion = version.getValue();
00436 }
00437
00443 public void setClasspath(Path classpath) {
00444 config.classpath = classpath;
00445 }
00446
00458 public void setFlatdestdir(boolean inValue) {
00459 config.flatDestDir = inValue;
00460 }
00461
00471 public void setGenericjarsuffix(String inString) {
00472 this.genericJarSuffix = inString;
00473 }
00474
00484 public void setBasenameterminator(String inValue) {
00485 config.baseNameTerminator = inValue;
00486 }
00487
00493 private void validateConfig() throws BuildException {
00494 if (config.srcDir == null) {
00495 throw new BuildException("The srcDir attribute must be specified");
00496 }
00497
00498 if (config.descriptorDir == null) {
00499 config.descriptorDir = config.srcDir;
00500 }
00501
00502 if (config.namingScheme == null) {
00503 config.namingScheme = new NamingScheme();
00504 config.namingScheme.setValue(NamingScheme.DESCRIPTOR);
00505 } else if (config.namingScheme.getValue().equals(NamingScheme.BASEJARNAME)
00506 && config.baseJarName == null) {
00507 throw new BuildException("The basejarname attribute must "
00508 + "be specified with the basejarname naming scheme");
00509 }
00510 }
00511
00527 public void execute() throws BuildException {
00528 validateConfig();
00529
00530 if (deploymentTools.size() == 0) {
00531 GenericDeploymentTool genericTool = new GenericDeploymentTool();
00532 genericTool.setTask(this);
00533 genericTool.setDestdir(destDir);
00534 genericTool.setGenericJarSuffix(genericJarSuffix);
00535 deploymentTools.add(genericTool);
00536 }
00537
00538 for (Iterator i = deploymentTools.iterator(); i.hasNext();) {
00539 EJBDeploymentTool tool = (EJBDeploymentTool) i.next();
00540 tool.configure(config);
00541 tool.validateConfigured();
00542 }
00543
00544 try {
00545
00546 SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
00547 saxParserFactory.setValidating(true);
00548 saxParserFactory.setNamespaceAware(true);
00549 SAXParser saxParser = saxParserFactory.newSAXParser();
00550
00551
00552 DirectoryScanner ds = getDirectoryScanner(config.descriptorDir);
00553 ds.scan();
00554 String[] files = ds.getIncludedFiles();
00555
00556 log(files.length + " deployment descriptors located.",
00557 Project.MSG_VERBOSE);
00558
00559
00560
00561 for (int index = 0; index < files.length; ++index) {
00562
00563 for (Iterator i = deploymentTools.iterator(); i.hasNext();) {
00564 EJBDeploymentTool tool = (EJBDeploymentTool) i.next();
00565 tool.processDescriptor(files[index], saxParser);
00566 }
00567 }
00568 } catch (SAXException se) {
00569 String msg = "SAXException while creating parser."
00570 + " Details: "
00571 + se.getMessage();
00572 throw new BuildException(msg, se);
00573 } catch (ParserConfigurationException pce) {
00574 String msg = "ParserConfigurationException while creating parser. "
00575 + "Details: " + pce.getMessage();
00576 throw new BuildException(msg, pce);
00577 }
00578 }
00579
00580 }
00581
00582
00583
00584
00585
00586
00587