Browse Source

Include any inner classes in the generated Jar file.

Submitted by:	Brian Towles <brian@towles.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268033 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 25 years ago
parent
commit
f688c57ce1
2 changed files with 49 additions and 0 deletions
  1. +26
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java
  2. +23
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/InnerClassFilenameFilter.java

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

@@ -369,6 +369,8 @@ public class GenericDeploymentTool implements EJBDeploymentTool {
Iterator entryIterator = null;
String entryName = null;
File entryFile = null;
File entryDir = null;
String innerfiles[] = null;

try {
/* If the jarfile already exists then whack it and recreate it.
@@ -398,6 +400,27 @@ public class GenericDeploymentTool implements EJBDeploymentTool {
addFileToJar(jarStream,
new FileInputStream(entryFile),
entryName);

// See if there are any inner classes for this class and add them in if there are
InnerClassFilenameFilter flt = new InnerClassFilenameFilter(entryFile.getName());
entryDir = entryFile.getParentFile();
innerfiles = entryDir.list(flt);
for (int i=0, n=innerfiles.length; i < n; i++) {
//get and clean up innerclass name
entryName = entryName.substring(0, entryName.lastIndexOf(entryFile.getName())-1) + File.separatorChar + innerfiles[i];

// link the file
entryFile = new File(srcDir, entryName);

getTask().log("adding innerclass file '" + entryName + "'",
Project.MSG_VERBOSE);

addFileToJar(jarStream,
new FileInputStream(entryFile),
entryName);

}
}
// All done. Close the jar stream.
jarStream.close();
@@ -410,6 +433,9 @@ public class GenericDeploymentTool implements EJBDeploymentTool {
throw new BuildException(msg, ioe);
}
} // end of writeJar



/**


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

@@ -0,0 +1,23 @@
package org.apache.tools.ant.taskdefs.optional.ejb;

import java.io.*;

public class InnerClassFilenameFilter implements FilenameFilter {
private String baseClassName;

InnerClassFilenameFilter(String baseclass){
int extidx = baseclass.lastIndexOf(".class");
if (extidx == -1) {
extidx = baseclass.length()-1;
}
baseClassName = baseclass.substring(0,extidx);
}

public boolean accept (File Dir, String filename){
if ((filename.lastIndexOf(".") != filename.lastIndexOf(".class"))
|| (filename.indexOf(baseClassName + "$") != 0)) {
return false;
}
return true;
}
}

Loading…
Cancel
Save