Browse Source

Roll back EJBC changes to the separate helper run in a separate VM. The use of

the class loader was causing some users problems which arise when the system
classpath and the classloader's classpath overlap.

This will remove Jikes support from the ejbc task, but I think the stability of
the task, going into the 1.2 release is more important.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268108 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 24 years ago
parent
commit
34b083983d
2 changed files with 100 additions and 198 deletions
  1. +36
    -51
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/Ejbc.java
  2. +64
    -147
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbcHelper.java

+ 36
- 51
src/main/org/apache/tools/ant/taskdefs/optional/ejb/Ejbc.java View File

@@ -54,7 +54,9 @@
package org.apache.tools.ant.taskdefs.optional.ejb;


import org.apache.tools.ant.*;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.*;
import org.apache.tools.ant.types.Path;

@@ -68,19 +70,6 @@ import java.io.File;
* @author <a href="mailto:conor@cortexebusiness.com.au">Conor MacNeill</a>, Cortex ebusiness Pty Limited
*/
public class Ejbc extends MatchingTask {
static public interface Helper {
public void initialize(Ejbc ejbcTask);
public void setDescriptorDir(File dir);
public void setDest(File dir);
public void setManifest(File manifestFile);
public void setClasspath(Path classpath);
public void setSrc(File dir);
public void setDescriptors(String[] descriptors);
public void execute();
}
/**
* The root directory of the tree containing the serialised deployment desciptors. The actual
* deployment descriptor files are selected using include and exclude constructs
@@ -102,7 +91,7 @@ public class Ejbc extends MatchingTask {
* The classpath to be used in the weblogic ejbc calls. It must contain the weblogic
* classes <b>and</b> the implementation classes of the home and remote interfaces.
*/
private Path classpath;
private String classpath;
/**
* The source directory for the home and remote interfaces. This is used to determine if
@@ -140,53 +129,49 @@ public class Ejbc extends MatchingTask {
}
String systemClassPath = System.getProperty("java.class.path");
Path execClassPath = new Path(project, classpath + ":" + generatedFilesDirectory + ":" + systemClassPath);
String execClassPath = project.translatePath(systemClassPath + ":" + classpath +
":" + generatedFilesDirectory);
// get all the files in the descriptor directory
DirectoryScanner ds = super.getDirectoryScanner(descriptorDirectory);
String[] descriptorNames = ds.getIncludedFiles();
String[] files = ds.getIncludedFiles();

// create an class loader
AntClassLoader loader = new AntClassLoader(project, execClassPath, false);
loader.addSystemPackageRoot("org.apache.tools.ant");
loader.addSystemPackageRoot("javax");
try {
Helper helper = (Helper)(loader.forceLoadClass("org.apache.tools.ant.taskdefs.optional.ejb.EjbcHelper").newInstance());
helper.initialize(this);
helper.setDescriptorDir(descriptorDirectory);
helper.setDest(generatedFilesDirectory);
helper.setManifest(generatedManifestFile);
helper.setSrc(sourceDirectory);
helper.setDescriptors(descriptorNames);
helper.setClasspath(execClassPath);
helper.execute();
helper = null;
Java helperTask = (Java)project.createTask("java");
helperTask.setFork(true);
helperTask.setClassname("org.apache.tools.ant.taskdefs.optional.ejb.EjbcHelper");
String args = "";
args += " " + descriptorDirectory;
args += " " + generatedFilesDirectory;
args += " " + sourceDirectory;
args += " " + generatedManifestFile;
for (int i = 0; i < files.length; ++i) {
args += " " + files[i];
}
catch (Exception e) {
throw new BuildException(e);
helperTask.setArgs(args);
helperTask.setClasspath(new Path(project, execClassPath));
if (helperTask.executeJava() != 0) {
throw new BuildException("Execution of ejbc helper failed");
}
loader = null;
}

/**
* Set the directory from where the serialised deployment descriptors are
* to be read.
*
* @param dir the directory containing the serialised deployment descriptors.
* @param dirName the name of the directory containing the serialised deployment descriptors.
*/
public void setDescriptors(File dir) {
descriptorDirectory = dir;
public void setDescriptors(String dirName) {
descriptorDirectory = new File(dirName);
}
/**
* Set the directory into which the support classes, RMI stubs, etc are to be written
*
* @param dir the directory into which code is generated
* @param dirName the name of the directory into which code is generated
*/
public void setDest(File dir) {
generatedFilesDirectory = dir;
public void setDest(String dirName) {
generatedFilesDirectory = new File(dirName);
}

/**
@@ -195,27 +180,27 @@ public class Ejbc extends MatchingTask {
* For each EJB that is processed an entry is created in this file. This can then be used
* to create a jar file for dploying the beans.
*
* @param manfestFilename the manifest file to be generated.
* @param manfestFilename the name of the manifest file to be generated.
*/
public void setManifest(File manifestFile) {
generatedManifestFile = manifestFile;
public void setManifest(String manifestFilename) {
generatedManifestFile = new File(manifestFilename);
}
/**
* Set the classpath to be used for this compilation.
*/
public void setClasspath(Path classpath) {
this.classpath = classpath;
public void setClasspath(String s) {
this.classpath = project.translatePath(s);
}

/**
* Set the directory containing the source code for the home interface, remote interface
* and public key class definitions.
*
* @param dir the directory containg the source tree for the EJB's interface classes.
* @param dirName the directory containg the source tree for the EJB's interface classes.
*/
public void setSrc(File dir) {
sourceDirectory = dir;
public void setSrc(String dirName) {
sourceDirectory = new File(dirName);
}
}

+ 64
- 147
src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbcHelper.java View File

@@ -53,13 +53,16 @@
*/
package org.apache.tools.ant.taskdefs.optional.ejb;

import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.FileWriter;

import javax.ejb.deployment.EntityDescriptor;
import javax.ejb.deployment.DeploymentDescriptor;

import org.apache.tools.ant.*;
import org.apache.tools.ant.types.Path;

/**
* A helper class which performs the actual work of the ejbc task.
@@ -69,7 +72,7 @@ import org.apache.tools.ant.types.Path;
*
* @author <a href="mailto:conor@cortexebusiness.com.au">Conor MacNeill</a>, Cortex ebusiness Pty Limited
*/
public class EjbcHelper implements Ejbc.Helper {
public class EjbcHelper {
/**
* The root directory of the tree containing the serialised deployment desciptors.
*/
@@ -89,127 +92,43 @@ public class EjbcHelper implements Ejbc.Helper {
* The classpath to be used in the weblogic ejbc calls. It must contain the weblogic
* classes <b>and</b> the implementation classes of the home and remote interfaces.
*/
private Path classpath;
private String classpath;
/**
* The source directory for the home and remote interfaces. This is used to determine if
* the generated deployment classes are out of date.
*/
private File sourceDirectory;

/**
* The array of descriptor filenames to be processed
*/
private String[] files;

/**
* The Ejbc task that this helper is helping
*/
private Ejbc ejbcTask;
/**
* The names of the serialised deployment descriptors
*/
String[] descriptors;

public EjbcHelper() {
}
public void initialize(Ejbc ejbcTask) {
this.ejbcTask = ejbcTask;
}

/**
* Set the directory from where the serialised deployment descriptors are
* to be read.
*
* @param dir the directory containing the serialised deployment descriptors.
*/
public void setDescriptorDir(File dir) {
descriptorDirectory = dir;
}
/**
* Set the directory into which the support classes, RMI stubs, etc are to be written
*
* @param dir the directory into which code is generated
*/
public void setDest(File dir) {
generatedFilesDirectory = dir;
}

/**
* Set the generated manifest file.
*
* For each EJB that is processed an entry is created in this file. This can then be used
* to create a jar file for dploying the beans.
*
* @param manfestFilename the manifest file to be generated.
*/
public void setManifest(File manifestFile) {
this.manifestFile = manifestFile;
}
/**
* Set the classpath to be used for this compilation.
*/
public void setClasspath(Path classpath) {
this.classpath = classpath;
}

/**
* Set the list of desciptors which ar eto be processed.
*
* @param descriptors an array of serialised deployment descriptor filenames to be processed.
*/
public void setDescriptors(String[] descriptors) {
this.descriptors = descriptors;
* Command line interface for the ejbc helper task.
*/
public static void main(String[] args) throws Exception {
EjbcHelper helper = new EjbcHelper(args);
helper.process();
}



/**
* Set the directory containing the source code for the home interface, remote interface
* and public key class definitions.
*
* @param dir the directory containg the source tree for the EJB's interface classes.
*/
public void setSrc(File dir) {
sourceDirectory = dir;
}

/**
* Perform the weblogic compiles.
*/
public void execute() throws BuildException {
try {
String manifest = "Manifest-Version: 1.0\n\n";
for (int i = 0; i < descriptors.length; ++i) {
String descriptorName = descriptors[i];
File descriptorFile = new File(descriptorDirectory, descriptorName);
if (isRegenRequired(descriptorFile)) {
ejbcTask.log("Running ejbc for " + descriptorFile.getName(), Project.MSG_INFO);
regenerateSupportClasses(descriptorFile);
}
else {
ejbcTask.log(descriptorFile.getName() + " is up to date", Project.MSG_VERBOSE);
}
manifest += "Name: " + descriptorFile.getName() + "\nEnterprise-Bean: True\n\n";
}
FileWriter fw = new FileWriter(manifestFile);
PrintWriter pw = new PrintWriter(fw);
pw.print(manifest);
fw.flush();
fw.close();
}
catch (IOException e) {
throw new BuildException(e);
* Initialise the EjbcHelper by reading the command arguments.
*/
private EjbcHelper(String[] args) {
int index = 0;
descriptorDirectory = new File(args[index++]);
generatedFilesDirectory = new File(args[index++]);
sourceDirectory = new File(args[index++]);
manifestFile = new File(args[index++]);
descriptors = new String[args.length - index];
for (int i = 0; index < args.length; ++i) {
descriptors[i] = args[index++];
}
}


/**
* Determine if the weblogic EJB support classes need to be regenerated
* for a given deployment descriptor.
@@ -291,8 +210,7 @@ public class EjbcHelper implements Ejbc.Helper {
}
}
catch (Throwable descriptorLoadException) {
ejbcTask.log("Exception occurred reading " + descriptorFile.getName() + " - continuing",
Project.MSG_WARN);
System.out.println("Exception occurred reading " + descriptorFile.getName() + " - continuing");
// any problems - just regenerate
return true;
}
@@ -305,57 +223,56 @@ public class EjbcHelper implements Ejbc.Helper {
return false;
}

/**
* Process the descriptors in turn generating support classes for each and a manifest
* file for all of the beans.
*/
private void process() throws Exception {
String manifest = "Manifest-Version: 1.0\n\n";
for (int i = 0; i < descriptors.length; ++i) {
String descriptorName = descriptors[i];
File descriptorFile = new File(descriptorDirectory, descriptorName);
if (isRegenRequired(descriptorFile)) {
System.out.println("Running ejbc for " + descriptorFile.getName());
regenerateSupportClasses(descriptorFile);
}
else {
System.out.println(descriptorFile.getName() + " is up to date");
}
manifest += "Name: " + descriptorFile.getName() + "\nEnterprise-Bean: True\n\n";
}
FileWriter fw = new FileWriter(manifestFile);
PrintWriter pw = new PrintWriter(fw);
pw.print(manifest);
fw.flush();
fw.close();
}

/**
* Perform the weblogic.ejbc call to regenerate the support classes.
*
* Note that this method relies on an undocumented -noexit option to the
* ejbc tool to stop the ejbc tool exiting the VM altogether.
*/
private void regenerateSupportClasses(File descriptorFile) {
Project project = ejbcTask.getProject();
String javaHome = System.getProperty("java.home");
private void regenerateSupportClasses(File descriptorFile) throws Exception {
// create a Java task to do the rebuild

String compiler = project.getProperty("build.compiler");
String[] args = null;
String[] args = {"-noexit",
"-keepgenerated",
"-d", generatedFilesDirectory.getPath(),
descriptorFile.getPath()};
if (compiler != null && compiler.equalsIgnoreCase("jikes")) {
Path execClassPath = new Path(project);
if (Project.getJavaVersion() == Project.JAVA_1_1) {
execClassPath.addExisting(new Path(project, System.getProperty("java.home")
+ "/lib/classes.zip"));
} else {
execClassPath.addExisting(new Path(project,
System.getProperty("java.home")
+ "/lib/rt.jar"));
// Just keep the old version as well and let addExisting
// sort it out.
execClassPath.addExisting(new Path(project,
System.getProperty("java.home")
+ "/jre/lib/rt.jar"));
}
execClassPath.append(classpath);
args = new String[] {"-noexit",
"-keepgenerated",
"-compiler", "Jikes",
"-d", generatedFilesDirectory.getPath(),
"-classpath", execClassPath.toString(),
descriptorFile.getPath()};
}
else {
args = new String[]{"-noexit",
"-keepgenerated",
"-d", generatedFilesDirectory.getPath(),
"-classpath", classpath.toString(),
descriptorFile.getPath()};
}
try {
weblogic.ejbc.main(args);
}
catch (Exception e) {
e.printStackTrace();
throw new BuildException(e);
// run with no exit for better reporting
String[] newArgs = {"-keepgenerated",
"-d", generatedFilesDirectory.getPath(),
descriptorFile.getPath()};
weblogic.ejbc.main(newArgs);
}
}
}

Loading…
Cancel
Save