Browse Source

Allow the manifest to be specified in the ejbjar task. This adds the given manifest

to the generic jar fed to the appserver ejb compiler.

PR:	980
Submitted by:	robert.watkins@qsipayments.com (Robert Watkins)


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269229 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 24 years ago
parent
commit
a50b60cdd9
2 changed files with 61 additions and 16 deletions
  1. +18
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java
  2. +43
    -16
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java

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

@@ -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


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

@@ -570,7 +570,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool {
* This method checks the timestamp on each file listed in the <code>
* ejbFiles</code> and compares them to the timestamp on the <code>jarFile
* </code>. If the <code>jarFile</code>'s timestamp is more recent than
* each EJB file, <code>false</code> is returned. Otherwise, <code>true
* each EJB file, <code>true</code> is returned. Otherwise, <code>false
* </code> 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);


Loading…
Cancel
Save