diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java index e40a05615..f1cb549d2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java @@ -167,6 +167,11 @@ public class EjbJar extends MatchingTask { * from the descriptor information */ public NamingScheme namingScheme; + + /** + * The Manifest file + */ + public File manifest; }; @@ -304,6 +309,19 @@ public class EjbJar extends MatchingTask { } + /** + * Set the Manifest file to use when jarring. + * + * As of EJB 1.1, manifest files are no longer used to configure the EJB. However, they + * still have a vital importance if the EJB is intended to be packaged in an EAR file. + * By adding "Class-Path" settings to a Manifest file, the EJB can look for classes inside + * the EAR file itself, allowing for easier deployment. This is outlined in the J2EE + * specification, and all J2EE components are meant to support it. + */ + public void setManifest(File manifest) { + config.manifest = manifest; + } + /** * Set the srcdir attribute. The source directory is the directory that contains * the classes that will be added to the EJB jar. Typically this will include the diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java index 10dff4be1..80c143c3e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java @@ -570,7 +570,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool { * This method checks the timestamp on each file listed in the * ejbFiles and compares them to the timestamp on the jarFile * . If the jarFile's timestamp is more recent than - * each EJB file, false is returned. Otherwise, true + * each EJB file, true is returned. Otherwise, false * is returned. * * @param ejbFiles Hashtable of EJB classes (and other) files that will be @@ -581,28 +581,32 @@ public class GenericDeploymentTool implements EJBDeploymentTool { * is up to date */ protected boolean needToRebuild(Hashtable ejbFiles, File jarFile) { - // By default we assume we need to build. - boolean needBuild = true; - if (jarFile.exists()) { - long lastBuild = jarFile.lastModified(); + long lastBuild = jarFile.lastModified(); + if (config.manifest != null && config.manifest.exists() && + config.manifest.lastModified() > lastBuild) { + log("Build needed because manifest " + config.manifest + " is out of date", + Project.MSG_VERBOSE); + return true; + } + + Iterator fileIter = ejbFiles.values().iterator(); - // Set the need build to false until we find out otherwise. - needBuild = false; // Loop through the files seeing if any has been touched // more recently than the destination jar. - while( (needBuild == false) && (fileIter.hasNext()) ) { + while(fileIter.hasNext()) { File currentFile = (File) fileIter.next(); - needBuild = ( lastBuild < currentFile.lastModified() ); - if (needBuild) { + if (lastBuild < currentFile.lastModified()) { log("Build needed because " + currentFile.getPath() + " is out of date", Project.MSG_VERBOSE); + return true; } } + return false; } - return needBuild; + return true; } /** @@ -640,13 +644,36 @@ public class GenericDeploymentTool implements EJBDeploymentTool { jarfile.getParentFile().mkdirs(); jarfile.createNewFile(); - String defaultManifest = "/org/apache/tools/ant/defaultManifest.mf"; - InputStream in = this.getClass().getResourceAsStream(defaultManifest); - if ( in == null ) { - throw new BuildException ( "Could not find: " + defaultManifest ); + InputStream in = null; + Manifest manifest = null; + try { + if (config.manifest != null) { + in = new FileInputStream(config.manifest); + if ( in == null ) { + throw new BuildException("Could not find manifest file: " + config.manifest, + getLocation()); + } + } + else { + String defaultManifest = "/org/apache/tools/ant/defaultManifest.mf"; + in = this.getClass().getResourceAsStream(defaultManifest); + if ( in == null ) { + throw new BuildException("Could not find default manifest: " + defaultManifest, + getLocation()); + } + } + + manifest = new Manifest(in); + } + catch (IOException e) { + throw new BuildException ("Unable to read manifest", e, getLocation()); + } + finally { + if (in != null) { + in.close(); + } } - Manifest manifest = new Manifest(in); // Create the streams necessary to write the jarfile jarStream = new JarOutputStream(new FileOutputStream(jarfile), manifest);