From 45c25ba3706117e30db4c78139493daef272be37 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Sun, 19 Nov 2000 08:59:23 +0000 Subject: [PATCH] Allow keepgenerated flag to be controlled from the ejbc task. It defaults to false. To keep genrated code, use the keepgenerated="true" Submitted by: William Turnbull git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268208 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/ant/taskdefs/optional/ejb/Ejbc.java | 23 ++++++--- .../ant/taskdefs/optional/ejb/EjbcHelper.java | 49 ++++++++++++------- 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/Ejbc.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/Ejbc.java index 2f6844d2c..4f165d4e7 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/Ejbc.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/Ejbc.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -53,7 +53,6 @@ */ package org.apache.tools.ant.taskdefs.optional.ejb; - import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; @@ -99,6 +98,8 @@ public class Ejbc extends MatchingTask { */ private File sourceDirectory; + public boolean keepgenerated; + /** * Do the work. * @@ -144,6 +145,8 @@ public class Ejbc extends MatchingTask { args += " " + generatedFilesDirectory; args += " " + sourceDirectory; args += " " + generatedManifestFile; + args += " " + keepgenerated; + for (int i = 0; i < files.length; ++i) { args += " " + files[i]; } @@ -154,7 +157,11 @@ public class Ejbc extends MatchingTask { throw new BuildException("Execution of ejbc helper failed"); } } - + + public boolean getKeepgenerated() { + return keepgenerated; + } + /** * Set the directory from where the serialised deployment descriptors are * to be read. @@ -173,7 +180,12 @@ public class Ejbc extends MatchingTask { public void setDest(String dirName) { generatedFilesDirectory = new File(dirName); } - + + public void setKeepgenerated(String newKeepgenerated) { + keepgenerated = Boolean.valueOf(newKeepgenerated.trim()).booleanValue(); + + } + /** * Set the generated manifest file. * @@ -192,7 +204,7 @@ public class Ejbc extends MatchingTask { 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. @@ -202,5 +214,4 @@ public class Ejbc extends MatchingTask { public void setSrc(String dirName) { sourceDirectory = new File(dirName); } - } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbcHelper.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbcHelper.java index 262ff887a..d9ab5121b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbcHelper.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbcHelper.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -53,12 +53,8 @@ */ package org.apache.tools.ant.taskdefs.optional.ejb; -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 java.io.*; +import java.util.*; import javax.ejb.deployment.EntityDescriptor; import javax.ejb.deployment.DeploymentDescriptor; @@ -103,7 +99,9 @@ public class EjbcHelper { /** * The names of the serialised deployment descriptors */ - String[] descriptors; + String[] descriptors; + + private boolean keepGenerated; /** * Command line interface for the ejbc helper task. @@ -112,7 +110,7 @@ public class EjbcHelper { EjbcHelper helper = new EjbcHelper(args); helper.process(); } - + /** * Initialise the EjbcHelper by reading the command arguments. */ @@ -122,12 +120,31 @@ public class EjbcHelper { generatedFilesDirectory = new File(args[index++]); sourceDirectory = new File(args[index++]); manifestFile = new File(args[index++]); + keepGenerated = Boolean.valueOf(args[index++]).booleanValue(); descriptors = new String[args.length - index]; for (int i = 0; index < args.length; ++i) { descriptors[i] = args[index++]; } } + + private String[] getCommandLine(boolean debug, File descriptorFile) { + Vector v = new Vector(); + if (!debug) { + v.add("-noexit"); + } + if (keepGenerated) { + v.add("-keepgenerated"); + } + v.add("-d"); + v.add(generatedFilesDirectory.getPath()); + v.add(descriptorFile.getPath()); + + String[] args = new String[v.size()]; + v.copyInto(args); + System.out.println("args: "+args); + return args; + } /** * Determine if the weblogic EJB support classes need to be regenerated @@ -222,7 +239,7 @@ public class EjbcHelper { return false; } - + /** * Process the descriptors in turn generating support classes for each and a manifest * file for all of the beans. @@ -249,7 +266,7 @@ public class EjbcHelper { fw.flush(); fw.close(); } - + /** * Perform the weblogic.ejbc call to regenerate the support classes. * @@ -259,19 +276,15 @@ public class EjbcHelper { private void regenerateSupportClasses(File descriptorFile) throws Exception { // create a Java task to do the rebuild - String[] args = {"-noexit", - "-keepgenerated", - "-d", generatedFilesDirectory.getPath(), - descriptorFile.getPath()}; + + String[] args = getCommandLine(false,descriptorFile); try { weblogic.ejbc.main(args); } catch (Exception e) { // run with no exit for better reporting - String[] newArgs = {"-keepgenerated", - "-d", generatedFilesDirectory.getPath(), - descriptorFile.getPath()}; + String[] newArgs = getCommandLine(true, descriptorFile); weblogic.ejbc.main(newArgs); } }