diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/AntClassLoader.java b/proposal/myrmidon/src/main/org/apache/tools/ant/AntClassLoader.java index e7a1ef558..6880707e9 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/AntClassLoader.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/AntClassLoader.java @@ -128,6 +128,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener * value of ${build.sysclasspath} */ public AntClassLoader( Project project, Path classpath ) + throws TaskException { parent = AntClassLoader.class.getClassLoader(); this.project = project; @@ -142,7 +143,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener { addPathElement( (String)pathElements[ i ] ); } - catch( BuildException e ) + catch( TaskException e ) { // ignore path elements which are invalid relative to the project } @@ -162,6 +163,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener */ public AntClassLoader( ClassLoader parent, Project project, Path classpath, boolean parentFirst ) + throws TaskException { this( project, classpath ); if( parent != null ) @@ -182,6 +184,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener * be consulted before trying to load the a class through this loader. */ public AntClassLoader( Project project, Path classpath, boolean parentFirst ) + throws TaskException { this( null, project, classpath, parentFirst ); } @@ -411,10 +414,10 @@ public class AntClassLoader extends ClassLoader implements BuildListener * Add an element to the classpath to be searched * * @param pathElement The feature to be added to the PathElement attribute - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void addPathElement( String pathElement ) - throws BuildException + throws TaskException { File pathComponent = project != null ? FileUtils.newFileUtils().resolveFile( project.getBaseDir(), pathElement ) diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/Launcher.java b/proposal/myrmidon/src/main/org/apache/tools/ant/Launcher.java index 0a220ec89..da548157d 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/Launcher.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/Launcher.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant; + import java.io.File; import java.io.FilenameFilter; import java.lang.reflect.Method; @@ -13,6 +14,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Properties; import java.util.StringTokenizer; +import org.apache.myrmidon.api.TaskException; /** * This is the Ant command line front end to end. This front end works out where @@ -24,6 +26,7 @@ public class Launcher { public static void main( String[] args ) + throws TaskException { File antHome = null; ClassLoader systemClassLoader = Launcher.class.getClassLoader(); @@ -65,7 +68,7 @@ public class Launcher antLoader.initializeClass( mainClass ); final Class[] param = {Class.forName( "[Ljava.lang.String;" ), - Properties.class, ClassLoader.class}; + Properties.class, ClassLoader.class}; final Method startMethod = mainClass.getMethod( "start", param ); final Object[] argument = {args, launchProperties, systemClassLoader}; startMethod.invoke( null, argument ); @@ -78,6 +81,7 @@ public class Launcher } private static void addDirJars( AntClassLoader classLoader, File jarDir ) + throws TaskException { String[] fileList = jarDir.list( new FilenameFilter() @@ -92,7 +96,7 @@ public class Launcher { for( int i = 0; i < fileList.length; ++i ) { - File jarFile = new File( jarDir, fileList[i] ); + File jarFile = new File( jarDir, fileList[ i ] ); classLoader.addPathElement( jarFile.getAbsolutePath() ); } } diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/Main.java b/proposal/myrmidon/src/main/org/apache/tools/ant/Main.java index 3721f72dd..4e3dafae7 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/Main.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/Main.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -107,7 +108,7 @@ public class Main for( int i = 0; i < args.length; i++ ) { - String arg = args[i]; + String arg = args[ i ]; if( arg.equals( "-help" ) ) { @@ -137,7 +138,7 @@ public class Main { try { - File logFile = new File( args[i + 1] ); + File logFile = new File( args[ i + 1 ] ); i++; out = new PrintStream( new FileOutputStream( logFile ) ); err = out; @@ -163,7 +164,7 @@ public class Main { try { - buildFile = new File( args[i + 1] ); + buildFile = new File( args[ i + 1 ] ); i++; } catch( ArrayIndexOutOfBoundsException aioobe ) @@ -178,7 +179,7 @@ public class Main { try { - listeners.addElement( args[i + 1] ); + listeners.addElement( args[ i + 1 ] ); i++; } catch( ArrayIndexOutOfBoundsException aioobe ) @@ -212,7 +213,7 @@ public class Main name = name.substring( 0, posEq ); } else if( i < args.length - 1 ) - value = args[++i]; + value = args[ ++i ]; definedProps.put( name, value ); } @@ -225,12 +226,12 @@ public class Main } try { - loggerClassname = args[++i]; + loggerClassname = args[ ++i ]; } catch( ArrayIndexOutOfBoundsException aioobe ) { System.out.println( "You must specify a classname when " + - "using the -logger argument" ); + "using the -logger argument" ); return; } } @@ -248,7 +249,7 @@ public class Main // eat up next arg if present, default to build.xml if( i < args.length - 1 ) { - searchForThis = args[++i]; + searchForThis = args[ ++i ]; } else { @@ -278,7 +279,7 @@ public class Main if( searchForThis != null ) { buildFile = findBuildFile( System.getProperty( "user.dir" ), - searchForThis ); + searchForThis ); } else { @@ -329,7 +330,7 @@ public class Main catch( IOException ioe ) { throw new TaskException( "Could not load the version information:" - + ioe.getMessage() ); + + ioe.getMessage() ); } catch( NullPointerException npe ) { @@ -339,7 +340,6 @@ public class Main return antVersion; } - /** * Command line entry point. This method kicks off the building of a project * object and executes a build using either a given target or the default @@ -376,9 +376,9 @@ public class Main if( additionalUserProperties != null ) { - for( Enumeration e = additionalUserProperties.keys(); e.hasMoreElements(); ) + for( Enumeration e = additionalUserProperties.keys(); e.hasMoreElements(); ) { - String key = ( String )e.nextElement(); + String key = (String)e.nextElement(); String property = additionalUserProperties.getProperty( key ); m.definedProps.put( key, property ); } @@ -417,7 +417,7 @@ public class Main int res = names.size(); for( int i = 0; i < names.size() && res == names.size(); i++ ) { - if( name.compareTo( ( String )names.elementAt( i ) ) < 0 ) + if( name.compareTo( (String)names.elementAt( i ) ) < 0 ) { res = i; } @@ -474,7 +474,7 @@ public class Main while( ptargets.hasMoreElements() ) { - currentTarget = ( Target )ptargets.nextElement(); + currentTarget = (Target)ptargets.nextElement(); targetName = currentTarget.getName(); targetDescription = currentTarget.getDescription(); // maintain a sorted list of targets @@ -535,7 +535,7 @@ public class Main msg.append( names.elementAt( i ) ); if( descriptions != null ) { - msg.append( spaces.substring( 0, maxlen - ( ( String )names.elementAt( i ) ).length() + 2 ) ); + msg.append( spaces.substring( 0, maxlen - ( (String)names.elementAt( i ) ).length() + 2 ) ); msg.append( descriptions.elementAt( i ) ); } msg.append( lSep ); @@ -576,18 +576,18 @@ public class Main } protected void addBuildListeners( Project project ) + throws TaskException { - // Add the default listener project.addBuildListener( createLogger() ); for( int i = 0; i < listeners.size(); i++ ) { - String className = ( String )listeners.elementAt( i ); + String className = (String)listeners.elementAt( i ); try { BuildListener listener = - ( BuildListener )Class.forName( className ).newInstance(); + (BuildListener)Class.forName( className ).newInstance(); project.addBuildListener( listener ); } catch( Throwable exc ) @@ -631,18 +631,18 @@ public class Main { try { - logger = ( BuildLogger )( Class.forName( loggerClassname ).newInstance() ); + logger = (BuildLogger)( Class.forName( loggerClassname ).newInstance() ); } catch( ClassCastException e ) { System.err.println( "The specified logger class " + loggerClassname + - " does not implement the BuildLogger interface" ); + " does not implement the BuildLogger interface" ); throw new RuntimeException(); } catch( Exception e ) { System.err.println( "Unable to instantiate specified logger class " + - loggerClassname + " : " + e.getClass().getName() ); + loggerClassname + " : " + e.getClass().getName() ); throw new RuntimeException(); } } @@ -765,8 +765,8 @@ public class Main Enumeration e = definedProps.keys(); while( e.hasMoreElements() ) { - String arg = ( String )e.nextElement(); - String value = ( String )definedProps.get( arg ); + String arg = (String)e.nextElement(); + String value = (String)definedProps.get( arg ); project.setUserProperty( arg, value ); } diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Definer.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Definer.java index 6bb9cacae..a2720e50b 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Definer.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Definer.java @@ -6,14 +6,15 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import java.util.Properties; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.AntClassLoader; -import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.Path; @@ -87,7 +88,7 @@ public abstract class Definer extends Task } public void execute() - throws BuildException + throws TaskException { AntClassLoader al = createLoader(); @@ -98,9 +99,9 @@ public abstract class Definer extends Task if( name == null || value == null ) { String msg = "name or classname attributes of " - + getTaskName() + " element " - + "are undefined"; - throw new BuildException( msg ); + + getTaskName() + " element " + + "are undefined"; + throw new TaskException( msg ); } addDefinition( al, name, value ); @@ -113,14 +114,14 @@ public abstract class Definer extends Task if( name != null || value != null ) { String msg = "You must not specify name or value " - + "together with file or resource."; - throw new BuildException( msg ); + + "together with file or resource."; + throw new TaskException( msg ); } if( file != null && resource != null ) { String msg = "You must not specify both, file and resource."; - throw new BuildException( msg ); + throw new TaskException( msg ); } Properties props = new Properties(); @@ -128,7 +129,7 @@ public abstract class Definer extends Task if( file != null ) { log( "Loading definitions from file " + file, - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); is = new FileInputStream( file ); if( is == null ) { @@ -139,13 +140,13 @@ public abstract class Definer extends Task if( resource != null ) { log( "Loading definitions from resource " + resource, - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); is = al.getResourceAsStream( resource ); if( is == null ) { log( "Could not load definitions from resource " + resource + ". It could not be found.", - Project.MSG_WARN ); + Project.MSG_WARN ); } } @@ -155,7 +156,7 @@ public abstract class Definer extends Task Enumeration keys = props.keys(); while( keys.hasMoreElements() ) { - String n = ( String )keys.nextElement(); + String n = (String)keys.nextElement(); String v = props.getProperty( n ); addDefinition( al, n, v ); } @@ -163,7 +164,7 @@ public abstract class Definer extends Task } catch( IOException ex ) { - throw new BuildException( "Error", ex); + throw new TaskException( "Error", ex ); } } } @@ -171,7 +172,7 @@ public abstract class Definer extends Task protected abstract void addDefinition( String name, Class c ); private void addDefinition( ClassLoader al, String name, String value ) - throws BuildException + throws TaskException { try { @@ -183,18 +184,18 @@ public abstract class Definer extends Task { String msg = getTaskName() + " class " + value + " cannot be found"; - throw new BuildException( msg, cnfe ); + throw new TaskException( msg, cnfe ); } catch( NoClassDefFoundError ncdfe ) { String msg = getTaskName() + " class " + value + " cannot be found"; - throw new BuildException( msg, ncdfe ); + throw new TaskException( msg, ncdfe ); } } - private AntClassLoader createLoader() + throws TaskException { AntClassLoader al = null; if( classpath != null ) diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Execute.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Execute.java index 42626602c..c9b0ddf72 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Execute.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Execute.java @@ -16,10 +16,12 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Locale; import java.util.Vector; +import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.framework.Os; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; -import org.apache.myrmidon.framework.Os; +import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.types.Commandline; /** @@ -428,7 +430,7 @@ public class Execute * @exception IOException Description of Exception */ public int execute() - throws IOException + throws IOException, TaskException { CommandLauncher launcher = vmLauncher != null ? vmLauncher : shellLauncher; if( !useVMLauncher ) @@ -547,7 +549,7 @@ public class Execute * @exception IOException Description of Exception */ public Process exec( Project project, String[] cmd, String[] env ) - throws IOException + throws IOException, TaskException { if( project != null ) { @@ -571,7 +573,7 @@ public class Execute * @exception IOException Description of Exception */ public Process exec( Project project, String[] cmd, String[] env, File workingDir ) - throws IOException + throws IOException, TaskException { if( workingDir == null ) { @@ -608,7 +610,7 @@ public class Execute * @exception IOException Description of Exception */ public Process exec( Project project, String[] cmd, String[] env ) - throws IOException + throws IOException, TaskException { return _launcher.exec( project, cmd, env ); } @@ -633,7 +635,7 @@ public class Execute * @exception IOException Description of Exception */ public Process exec( Project project, String[] cmd, String[] env ) - throws IOException + throws IOException, TaskException { // Need to quote arguments with spaces, and to escape quote characters String[] newcmd = new String[ cmd.length ]; @@ -741,7 +743,7 @@ public class Execute * @exception IOException Description of Exception */ public Process exec( Project project, String[] cmd, String[] env, File workingDir ) - throws IOException + throws IOException, TaskException { if( workingDir == null ) { @@ -768,7 +770,6 @@ public class Execute */ private static class PerlScriptCommandLauncher extends CommandLauncherProxy { - private String _script; PerlScriptCommandLauncher( String script, CommandLauncher launcher ) @@ -789,7 +790,7 @@ public class Execute * @exception IOException Description of Exception */ public Process exec( Project project, String[] cmd, String[] env, File workingDir ) - throws IOException + throws IOException, TaskException { if( project == null ) { @@ -806,7 +807,8 @@ public class Execute { throw new IOException( "Cannot locate antRun script: Property 'ant.home' not found" ); } - String antRun = resolveFile( antHome + File.separator + _script ).toString(); + String antRun = FileUtils.newFileUtils(). + resolveFile( project.getBaseDir(), antHome + File.separator + _script ).toString(); // Build the command File commandDir = workingDir; @@ -854,7 +856,7 @@ public class Execute * @exception IOException Description of Exception */ public Process exec( Project project, String[] cmd, String[] env, File workingDir ) - throws IOException + throws IOException, TaskException { if( project == null ) { @@ -871,7 +873,8 @@ public class Execute { throw new IOException( "Cannot locate antRun script: Property 'ant.home' not found" ); } - String antRun = resolveFile( antHome + File.separator + _script ).toString(); + String antRun = FileUtils.newFileUtils(). + resolveFile( project.getBaseDir(), antHome + File.separator + _script ).toString(); // Build the command File commandDir = workingDir; @@ -914,7 +917,7 @@ public class Execute * @exception IOException Description of Exception */ public Process exec( Project project, String[] cmd, String[] env, File workingDir ) - throws IOException + throws IOException, TaskException { File commandDir = workingDir; if( workingDir == null ) diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Property.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Property.java index 0c506bce8..6ec1b4fa7 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Property.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Property.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -13,6 +14,7 @@ import java.io.InputStream; import java.util.Enumeration; import java.util.Properties; import java.util.Vector; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; @@ -144,20 +146,20 @@ public class Property extends Task } public void execute() - throws BuildException + throws TaskException { if( name != null ) { if( value == null && ref == null ) { - throw new BuildException( "You must specify value, location or refid with the name attribute" ); + throw new TaskException( "You must specify value, location or refid with the name attribute" ); } } else { if( file == null && resource == null && env == null ) { - throw new BuildException( "You must specify file, resource or environment when not using the name attribute" ); + throw new TaskException( "You must specify file, resource or environment when not using the name attribute" ); } } @@ -196,8 +198,8 @@ public class Property extends Task Enumeration e = props.keys(); while( e.hasMoreElements() ) { - String name = ( String )e.nextElement(); - String value = ( String )props.getProperty( name ); + String name = (String)e.nextElement(); + String value = (String)props.getProperty( name ); String v = project.replaceProperties( value ); addProperty( name, v ); @@ -230,9 +232,9 @@ public class Property extends Task prefix += "."; log( "Loading Environment " + prefix, Project.MSG_VERBOSE ); Vector osEnv = Execute.getProcEnvironment(); - for( Enumeration e = osEnv.elements(); e.hasMoreElements(); ) + for( Enumeration e = osEnv.elements(); e.hasMoreElements(); ) { - String entry = ( String )e.nextElement(); + String entry = (String)e.nextElement(); int pos = entry.indexOf( '=' ); if( pos == -1 ) { @@ -241,14 +243,14 @@ public class Property extends Task else { props.put( prefix + entry.substring( 0, pos ), - entry.substring( pos + 1 ) ); + entry.substring( pos + 1 ) ); } } addProperties( props ); } protected void loadFile( File file ) - throws BuildException + throws TaskException { Properties props = new Properties(); log( "Loading " + file.getAbsolutePath(), Project.MSG_VERBOSE ); @@ -273,16 +275,17 @@ public class Property extends Task else { log( "Unable to find property file: " + file.getAbsolutePath(), - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); } } catch( IOException ex ) { - throw new BuildException( "Error", ex ); + throw new TaskException( "Error", ex ); } } protected void loadResource( String name ) + throws TaskException { Properties props = new Properties(); log( "Resource Loading " + name, Project.MSG_VERBOSE ); @@ -321,16 +324,16 @@ public class Property extends Task } catch( IOException ex ) { - throw new BuildException( "Error", ex ); + throw new TaskException( "Error", ex ); } } private void resolveAllProperties( Properties props ) - throws BuildException + throws TaskException { - for( Enumeration e = props.keys(); e.hasMoreElements(); ) + for( Enumeration e = props.keys(); e.hasMoreElements(); ) { - String name = ( String )e.nextElement(); + String name = (String)e.nextElement(); String value = props.getProperty( name ); boolean resolved = false; @@ -348,13 +351,13 @@ public class Property extends Task Enumeration j = propertyRefs.elements(); while( i.hasMoreElements() ) { - String fragment = ( String )i.nextElement(); + String fragment = (String)i.nextElement(); if( fragment == null ) { - String propertyName = ( String )j.nextElement(); + String propertyName = (String)j.nextElement(); if( propertyName.equals( name ) ) { - throw new BuildException( "Property " + name + " was circularly defined." ); + throw new TaskException( "Property " + name + " was circularly defined." ); } fragment = getProject().getProperty( propertyName ); if( fragment == null ) diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Rmic.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Rmic.java index 8ce94edeb..947e94329 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Rmic.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Rmic.java @@ -6,12 +6,13 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs; + import java.io.File; import java.io.IOException; import java.rmi.Remote; import java.util.Vector; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.AntClassLoader; -import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.rmic.RmicAdapter; @@ -19,8 +20,8 @@ import org.apache.tools.ant.taskdefs.rmic.RmicAdapterFactory; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; import org.apache.tools.ant.util.FileNameMapper; -import org.apache.tools.ant.util.SourceFileScanner; import org.apache.tools.ant.util.FileUtils; +import org.apache.tools.ant.util.SourceFileScanner; /** * Task to compile RMI stubs and skeletons. This task can take the following @@ -60,7 +61,7 @@ public class Rmic extends MatchingTask { private final static String FAIL_MSG - = "Rmic failed, messages should have been provided."; + = "Rmic failed, messages should have been provided."; private boolean verify = false; private boolean filtering = false; @@ -413,9 +414,9 @@ public class Rmic extends MatchingTask { for( int i = 0; i < interfaces.length; i++ ) { - if( Remote.class.isAssignableFrom( interfaces[i] ) ) + if( Remote.class.isAssignableFrom( interfaces[ i ] ) ) { - return interfaces[i]; + return interfaces[ i ]; } } } @@ -469,18 +470,18 @@ public class Rmic extends MatchingTask catch( ClassNotFoundException e ) { log( "Unable to verify class " + classname + - ". It could not be found.", Project.MSG_WARN ); + ". It could not be found.", Project.MSG_WARN ); } catch( NoClassDefFoundError e ) { log( "Unable to verify class " + classname + - ". It is not defined.", Project.MSG_WARN ); + ". It is not defined.", Project.MSG_WARN ); } catch( Throwable t ) { log( "Unable to verify class " + classname + - ". Loading caused Exception: " + - t.getMessage(), Project.MSG_WARN ); + ". Loading caused Exception: " + + t.getMessage(), Project.MSG_WARN ); } // we only get here if an exception has been thrown return false; @@ -515,15 +516,15 @@ public class Rmic extends MatchingTask } public void execute() - throws BuildException + throws TaskException { if( baseDir == null ) { - throw new BuildException( "base attribute must be set!" ); + throw new TaskException( "base attribute must be set!" ); } if( !baseDir.exists() ) { - throw new BuildException( "base does not exist!" ); + throw new TaskException( "base does not exist!" ); } if( verify ) @@ -552,21 +553,21 @@ public class Rmic extends MatchingTask { // otherwise perform a timestamp comparison - at least scanDir( baseDir, - new String[]{classname.replace( '.', File.separatorChar ) + ".class"}, - adapter.getMapper() ); + new String[]{classname.replace( '.', File.separatorChar ) + ".class"}, + adapter.getMapper() ); } int fileCount = compileList.size(); if( fileCount > 0 ) { log( "RMI Compiling " + fileCount + - " class" + ( fileCount > 1 ? "es" : "" ) + " to " + baseDir, - Project.MSG_INFO ); + " class" + ( fileCount > 1 ? "es" : "" ) + " to " + baseDir, + Project.MSG_INFO ); // finally, lets execute the compiler!! if( !adapter.execute() ) { - throw new BuildException( FAIL_MSG ); + throw new TaskException( FAIL_MSG ); } } @@ -580,7 +581,7 @@ public class Rmic extends MatchingTask if( idl ) { log( "Cannot determine sourcefiles in idl mode, ", - Project.MSG_WARN ); + Project.MSG_WARN ); log( "sourcebase attribute will be ignored.", Project.MSG_WARN ); } else @@ -588,8 +589,8 @@ public class Rmic extends MatchingTask for( int j = 0; j < fileCount; j++ ) { moveGeneratedFile( baseDir, sourceBase, - ( String )compileList.elementAt( j ), - adapter ); + (String)compileList.elementAt( j ), + adapter ); } } } @@ -612,13 +613,13 @@ public class Rmic extends MatchingTask if( idl ) { log( "will leave uptodate test to rmic implementation in idl mode.", - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); } else if( iiop - && iiopopts != null && iiopopts.indexOf( "-always" ) > -1 ) + && iiopopts != null && iiopopts.indexOf( "-always" ) > -1 ) { log( "no uptodate test as -always option has been specified", - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); } else { @@ -628,7 +629,7 @@ public class Rmic extends MatchingTask for( int i = 0; i < newFiles.length; i++ ) { - String classname = newFiles[i].replace( File.separatorChar, '.' ); + String classname = newFiles[ i ].replace( File.separatorChar, '.' ); classname = classname.substring( 0, classname.lastIndexOf( ".class" ) ); compileList.addElement( classname ); } @@ -652,12 +653,12 @@ public class Rmic extends MatchingTask * @param sourceBaseFile Description of Parameter * @param classname Description of Parameter * @param adapter Description of Parameter - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ private void moveGeneratedFile( File baseDir, File sourceBaseFile, String classname, RmicAdapter adapter ) - throws BuildException + throws TaskException { String classFileName = @@ -680,7 +681,8 @@ public class Rmic extends MatchingTask { String msg = "Failed to copy " + oldFile + " to " + newFile + " due to " + ioe.getMessage(); - throw new BuildException( msg, ioe ); + newFile + " due to " + ioe.getMessage(); + throw new TaskException( msg, ioe ); } } } diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/SQLExec.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/SQLExec.java index a242c5489..87c397bc2 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/SQLExec.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/SQLExec.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs; + import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; @@ -30,15 +31,14 @@ import java.util.Properties; import java.util.StringTokenizer; import java.util.Vector; import org.apache.tools.ant.AntClassLoader; -import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; -import org.apache.tools.ant.ProjectHelper; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; +import org.apache.myrmidon.api.TaskException; /** * Reads in a text file containing SQL statements seperated with semicolons and @@ -258,7 +258,6 @@ public class SQLExec extends Task this.output = output; } - /** * Set the password for the DB connection. * @@ -373,7 +372,6 @@ public class SQLExec extends Task return this.classpath.createPath(); } - /** * Set the sql command to execute * @@ -389,10 +387,10 @@ public class SQLExec extends Task /** * Load the sql file and then execute it * - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void execute() - throws BuildException + throws TaskException { sqlCommand = sqlCommand.trim(); @@ -400,7 +398,7 @@ public class SQLExec extends Task { if( transactions.size() == 0 ) { - throw new BuildException( "Source file or fileset, transactions or sql statement must be set!" ); + throw new TaskException( "Source file or fileset, transactions or sql statement must be set!" ); } } else @@ -408,7 +406,7 @@ public class SQLExec extends Task // deal with the filesets for( int i = 0; i < filesets.size(); i++ ) { - FileSet fs = ( FileSet )filesets.elementAt( i ); + FileSet fs = (FileSet)filesets.elementAt( i ); DirectoryScanner ds = fs.getDirectoryScanner( project ); File srcDir = fs.getDir( project ); @@ -418,7 +416,7 @@ public class SQLExec extends Task for( int j = 0; j < srcFiles.length; j++ ) { Transaction t = createTransaction(); - t.setSrc( new File( srcDir, srcFiles[j] ) ); + t.setSrc( new File( srcDir, srcFiles[ j ] ) ); } } @@ -430,23 +428,23 @@ public class SQLExec extends Task if( driver == null ) { - throw new BuildException( "Driver attribute must be set!" ); + throw new TaskException( "Driver attribute must be set!" ); } if( userId == null ) { - throw new BuildException( "User Id attribute must be set!" ); + throw new TaskException( "User Id attribute must be set!" ); } if( password == null ) { - throw new BuildException( "Password attribute must be set!" ); + throw new TaskException( "Password attribute must be set!" ); } if( url == null ) { - throw new BuildException( "Url attribute must be set!" ); + throw new TaskException( "Url attribute must be set!" ); } if( srcFile != null && !srcFile.exists() ) { - throw new BuildException( "Source file does not exist!" ); + throw new TaskException( "Source file does not exist!" ); } Driver driverInstance = null; // Load the driver using the @@ -456,7 +454,7 @@ public class SQLExec extends Task if( classpath != null ) { log( "Loading " + driver + " using AntClassLoader with classpath " + classpath, - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); loader = new AntClassLoader( project, classpath ); dc = loader.loadClass( driver ); @@ -466,19 +464,19 @@ public class SQLExec extends Task log( "Loading " + driver + " using system loader.", Project.MSG_VERBOSE ); dc = Class.forName( driver ); } - driverInstance = ( Driver )dc.newInstance(); + driverInstance = (Driver)dc.newInstance(); } catch( ClassNotFoundException e ) { - throw new BuildException( "Class Not Found: JDBC driver " + driver + " could not be loaded" ); + throw new TaskException( "Class Not Found: JDBC driver " + driver + " could not be loaded" ); } catch( IllegalAccessException e ) { - throw new BuildException( "Illegal Access: JDBC driver " + driver + " could not be loaded" ); + throw new TaskException( "Illegal Access: JDBC driver " + driver + " could not be loaded" ); } catch( InstantiationException e ) { - throw new BuildException( "Instantiation Exception: JDBC driver " + driver + " could not be loaded" ); + throw new TaskException( "Instantiation Exception: JDBC driver " + driver + " could not be loaded" ); } try @@ -513,10 +511,10 @@ public class SQLExec extends Task // Process all transactions for( Enumeration e = transactions.elements(); - e.hasMoreElements(); ) + e.hasMoreElements(); ) { - ( ( Transaction )e.nextElement() ).runTransaction( out ); + ( (Transaction)e.nextElement() ).runTransaction( out ); if( !autocommit ) { log( "Commiting transaction", Project.MSG_VERBOSE ); @@ -541,9 +539,10 @@ public class SQLExec extends Task conn.rollback(); } catch( SQLException ex ) - {} + { + } } - throw new BuildException( "Error", e ); + throw new TaskException( "Error", e ); } catch( SQLException e ) { @@ -554,9 +553,10 @@ public class SQLExec extends Task conn.rollback(); } catch( SQLException ex ) - {} + { + } } - throw new BuildException( "Error", e ); + throw new TaskException( "Error", e ); } finally { @@ -572,11 +572,12 @@ public class SQLExec extends Task } } catch( SQLException e ) - {} + { + } } log( goodSql + " of " + totalSql + - " SQL statements executed successfully" ); + " SQL statements executed successfully" ); } /** @@ -650,7 +651,7 @@ public class SQLExec extends Task if( !statement.execute( sql ) ) { log( statement.getUpdateCount() + " rows affected", - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); } else { @@ -733,7 +734,7 @@ public class SQLExec extends Task line.setLength( 0 ); } } - }while ( statement.getMoreResults() ); + } while( statement.getMoreResults() ); out.println(); } @@ -855,9 +856,9 @@ public class SQLExec extends Task if( tSrcFile != null ) { log( "Executing file: " + tSrcFile.getAbsolutePath(), - Project.MSG_INFO ); + Project.MSG_INFO ); Reader reader = ( encoding == null ) ? new FileReader( tSrcFile ) - : new InputStreamReader( new FileInputStream( tSrcFile ), encoding ); + : new InputStreamReader( new FileInputStream( tSrcFile ), encoding ); runStatements( reader, out ); reader.close(); } diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java index 02abefc30..e2f8835b3 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs.optional; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -17,8 +18,8 @@ import java.net.URL; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.AntClassLoader; -import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; @@ -73,7 +74,7 @@ public class XMLValidateTask extends Task */ protected XMLReader xmlReader = null;// XMLReader used to validation process protected ValidatorErrorHandler errorHandler - = new ValidatorErrorHandler();// to report sax parsing errors + = new ValidatorErrorHandler();// to report sax parsing errors protected Hashtable features = new Hashtable(); /** @@ -102,7 +103,6 @@ public class XMLValidateTask extends Task readerClassName = className; } - /** * Specify the classpath to be searched to load the parser (optional) * @@ -133,7 +133,7 @@ public class XMLValidateTask extends Task /** * Specify how parser error are to be handled.

* - * If set to true (default), throw a buildException if the + * If set to true (default), throw a TaskException if the * parser yields an error. * * @param fail The new FailOnError value @@ -226,13 +226,13 @@ public class XMLValidateTask extends Task } public void execute() - throws BuildException + throws TaskException { int fileProcessed = 0; if( file == null && ( filesets.size() == 0 ) ) { - throw new BuildException( "Specify at least one source - a file or a fileset." ); + throw new TaskException( "Specify at least one source - a file or a fileset." ); } initValidator(); @@ -248,7 +248,7 @@ public class XMLValidateTask extends Task { String errorMsg = "File " + file + " cannot be read"; if( failOnError ) - throw new BuildException( errorMsg ); + throw new TaskException( errorMsg ); else log( errorMsg, Project.MSG_ERR ); } @@ -257,13 +257,13 @@ public class XMLValidateTask extends Task for( int i = 0; i < filesets.size(); i++ ) { - FileSet fs = ( FileSet )filesets.elementAt( i ); + FileSet fs = (FileSet)filesets.elementAt( i ); DirectoryScanner ds = fs.getDirectoryScanner( project ); String[] files = ds.getIncludedFiles(); for( int j = 0; j < files.length; j++ ) { - File srcFile = new File( fs.getDir( project ), files[j] ); + File srcFile = new File( fs.getDir( project ), files[ j ] ); doValidate( srcFile ); fileProcessed++; } @@ -275,9 +275,9 @@ public class XMLValidateTask extends Task { LocalResolver resolver = new LocalResolver(); - for( Enumeration i = dtdLocations.elements(); i.hasMoreElements(); ) + for( Enumeration i = dtdLocations.elements(); i.hasMoreElements(); ) { - DTDLocation location = ( DTDLocation )i.nextElement(); + DTDLocation location = (DTDLocation)i.nextElement(); resolver.registerDTD( location ); } return resolver; @@ -302,7 +302,7 @@ public class XMLValidateTask extends Task log( "Could not set feature '" + feature + "' because the parser doesn't recognize it", - Project.MSG_WARN ); + Project.MSG_WARN ); } catch( SAXNotSupportedException e ) { @@ -310,7 +310,7 @@ public class XMLValidateTask extends Task log( "Could not set feature '" + feature + "' because the parser doesn't support it", - Project.MSG_WARN ); + Project.MSG_WARN ); } return toReturn; } @@ -327,7 +327,7 @@ public class XMLValidateTask extends Task InputSource is = new InputSource( new FileReader( afile ) ); String uri = "file:" + afile.getAbsolutePath().replace( '\\', '/' ); for( int index = uri.indexOf( '#' ); index != -1; - index = uri.indexOf( '#' ) ) + index = uri.indexOf( '#' ) ) { uri = uri.substring( 0, index ) + "%23" + uri.substring( index + 1 ); } @@ -337,17 +337,17 @@ public class XMLValidateTask extends Task catch( SAXException ex ) { if( failOnError ) - throw new BuildException( "Could not validate document " + afile ); + throw new TaskException( "Could not validate document " + afile ); } catch( IOException ex ) { - throw new BuildException( "Could not validate document " + afile, ex ); + throw new TaskException( "Could not validate document " + afile, ex ); } if( errorHandler.getFailure() ) { if( failOnError ) - throw new BuildException( afile + " is not a valid XML document." ); + throw new TaskException( afile + " is not a valid XML document." ); else log( afile + " is not a valid XML document", Project.MSG_ERR ); } @@ -357,6 +357,7 @@ public class XMLValidateTask extends Task * init the parser : load the parser class, and set features if necessary */ private void initValidator() + throws TaskException { try @@ -369,7 +370,7 @@ public class XMLValidateTask extends Task if( classpath != null ) { AntClassLoader loader = new AntClassLoader( project, classpath ); -// loader.addSystemPackageRoot("org.xml"); // needed to avoid conflict + // loader.addSystemPackageRoot("org.xml"); // needed to avoid conflict readerClass = loader.loadClass( readerClassName ); AntClassLoader.initializeClass( readerClass ); } @@ -380,7 +381,7 @@ public class XMLValidateTask extends Task if( XMLReader.class.isAssignableFrom( readerClass ) ) { - xmlReader = ( XMLReader )readerClass.newInstance(); + xmlReader = (XMLReader)readerClass.newInstance(); log( "Using SAX2 reader " + readerClassName, Project.MSG_VERBOSE ); } else @@ -389,29 +390,29 @@ public class XMLValidateTask extends Task // see if it is a SAX1 Parser if( Parser.class.isAssignableFrom( readerClass ) ) { - Parser parser = ( Parser )readerClass.newInstance(); + Parser parser = (Parser)readerClass.newInstance(); xmlReader = new ParserAdapter( parser ); log( "Using SAX1 parser " + readerClassName, Project.MSG_VERBOSE ); } else { - throw new BuildException( INIT_FAILED_MSG - + readerClassName - + " implements nor SAX1 Parser nor SAX2 XMLReader." ); + throw new TaskException( INIT_FAILED_MSG + + readerClassName + + " implements nor SAX1 Parser nor SAX2 XMLReader." ); } } } catch( ClassNotFoundException e ) { - throw new BuildException( INIT_FAILED_MSG + readerClassName, e ); + throw new TaskException( INIT_FAILED_MSG + readerClassName, e ); } catch( InstantiationException e ) { - throw new BuildException( INIT_FAILED_MSG + readerClassName, e ); + throw new TaskException( INIT_FAILED_MSG + readerClassName, e ); } catch( IllegalAccessException e ) { - throw new BuildException( INIT_FAILED_MSG + readerClassName, e ); + throw new TaskException( INIT_FAILED_MSG + readerClassName, e ); } xmlReader.setEntityResolver( getEntityResolver() ); @@ -425,17 +426,17 @@ public class XMLValidateTask extends Task boolean ok = setFeature( "http://xml.org/sax/features/validation", true, true ); if( !ok ) { - throw new BuildException( INIT_FAILED_MSG - + readerClassName - + " doesn't provide validation" ); + throw new TaskException( INIT_FAILED_MSG + + readerClassName + + " doesn't provide validation" ); } } // set other features Enumeration enum = features.keys(); while( enum.hasMoreElements() ) { - String featureId = ( String )enum.nextElement(); - setFeature( featureId, ( ( Boolean )features.get( featureId ) ).booleanValue(), true ); + String featureId = (String)enum.nextElement(); + setFeature( featureId, ( (Boolean)features.get( featureId ) ).booleanValue(), true ); } } } @@ -542,13 +543,15 @@ public class XMLValidateTask extends Task } private class LocalResolver - implements EntityResolver + implements EntityResolver { private Hashtable fileDTDs = new Hashtable(); private Hashtable resourceDTDs = new Hashtable(); private Hashtable urlDTDs = new Hashtable(); - public LocalResolver() { } + public LocalResolver() + { + } public void registerDTD( String publicId, String location ) { @@ -599,7 +602,7 @@ public class XMLValidateTask extends Task public InputSource resolveEntity( String publicId, String systemId ) throws SAXException { - File dtdFile = ( File )fileDTDs.get( publicId ); + File dtdFile = (File)fileDTDs.get( publicId ); if( dtdFile != null ) { try @@ -613,7 +616,7 @@ public class XMLValidateTask extends Task } } - String dtdResourceName = ( String )resourceDTDs.get( publicId ); + String dtdResourceName = (String)resourceDTDs.get( publicId ); if( dtdResourceName != null ) { InputStream is = this.getClass().getResourceAsStream( dtdResourceName ); @@ -624,7 +627,7 @@ public class XMLValidateTask extends Task } } - URL dtdUrl = ( URL )urlDTDs.get( publicId ); + URL dtdUrl = (URL)urlDTDs.get( publicId ); if( dtdUrl != null ) { try @@ -640,7 +643,7 @@ public class XMLValidateTask extends Task } log( "Could not resolve ( publicId: " + publicId + ", systemId: " + systemId + ") to a local entity", - Project.MSG_INFO ); + Project.MSG_INFO ); return null; } diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/depend/Depend.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/depend/Depend.java index 01196c9b7..80632df63 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/depend/Depend.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/depend/Depend.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs.optional.depend; + import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -17,15 +18,14 @@ import java.net.URL; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.AntClassLoader; -import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.MatchingTask; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; - /** * Generate a dependency file for a given set of classes * @@ -152,7 +152,6 @@ public class Depend extends MatchingTask this.dump = dump; } - /** * Set the source dirs to find the source Java files. * @@ -190,10 +189,10 @@ public class Depend extends MatchingTask /** * Does the work. * - * @exception BuildException Thrown in unrecovrable error. + * @exception TaskException Thrown in unrecovrable error. */ public void execute() - throws BuildException + throws TaskException { try { @@ -201,7 +200,7 @@ public class Depend extends MatchingTask String[] srcPathList = srcPath.list(); if( srcPathList.length == 0 ) { - throw new BuildException( "srcdir attribute must be set!" ); + throw new TaskException( "srcdir attribute must be set!" ); } if( destPath == null ) @@ -211,7 +210,7 @@ public class Depend extends MatchingTask if( cache != null && cache.exists() && !cache.isDirectory() ) { - throw new BuildException( "The cache, if specified, must point to a directory" ); + throw new TaskException( "The cache, if specified, must point to a directory" ); } if( cache != null && !cache.exists() ) @@ -224,16 +223,16 @@ public class Depend extends MatchingTask if( dump ) { log( "Reverse Dependency Dump for " + affectedClassMap.size() + - " classes:", Project.MSG_DEBUG ); - for( Enumeration e = affectedClassMap.keys(); e.hasMoreElements(); ) + " classes:", Project.MSG_DEBUG ); + for( Enumeration e = affectedClassMap.keys(); e.hasMoreElements(); ) { - String className = ( String )e.nextElement(); + String className = (String)e.nextElement(); log( " Class " + className + " affects:", Project.MSG_DEBUG ); - Hashtable affectedClasses = ( Hashtable )affectedClassMap.get( className ); - for( Enumeration e2 = affectedClasses.keys(); e2.hasMoreElements(); ) + Hashtable affectedClasses = (Hashtable)affectedClassMap.get( className ); + for( Enumeration e2 = affectedClasses.keys(); e2.hasMoreElements(); ) { - String affectedClass = ( String )e2.nextElement(); - ClassFileInfo info = ( ClassFileInfo )affectedClasses.get( affectedClass ); + String affectedClass = (String)e2.nextElement(); + ClassFileInfo info = (ClassFileInfo)affectedClasses.get( affectedClass ); log( " " + affectedClass + " in " + info.absoluteFile.getPath(), Project.MSG_DEBUG ); } } @@ -241,14 +240,14 @@ public class Depend extends MatchingTask if( classpathDependencies != null ) { log( "Classpath file dependencies (Forward):", Project.MSG_DEBUG ); - for( Enumeration e = classpathDependencies.keys(); e.hasMoreElements(); ) + for( Enumeration e = classpathDependencies.keys(); e.hasMoreElements(); ) { - String className = ( String )e.nextElement(); + String className = (String)e.nextElement(); log( " Class " + className + " depends on:", Project.MSG_DEBUG ); - Hashtable dependencies = ( Hashtable )classpathDependencies.get( className ); - for( Enumeration e2 = dependencies.elements(); e2.hasMoreElements(); ) + Hashtable dependencies = (Hashtable)classpathDependencies.get( className ); + for( Enumeration e2 = dependencies.elements(); e2.hasMoreElements(); ) { - File classpathFile = ( File )e2.nextElement(); + File classpathFile = (File)e2.nextElement(); log( " " + classpathFile.getPath(), Project.MSG_DEBUG ); } } @@ -261,7 +260,7 @@ public class Depend extends MatchingTask outOfDateClasses = new Hashtable(); for( int i = 0; i < srcPathList.length; i++ ) { - File srcDir = ( File )resolveFile( srcPathList[i] ); + File srcDir = (File)resolveFile( srcPathList[ i ] ); if( srcDir.exists() ) { DirectoryScanner ds = this.getDirectoryScanner( srcDir ); @@ -273,25 +272,25 @@ public class Depend extends MatchingTask // now check classpath file dependencies if( classpathDependencies != null ) { - for( Enumeration e = classpathDependencies.keys(); e.hasMoreElements(); ) + for( Enumeration e = classpathDependencies.keys(); e.hasMoreElements(); ) { - String className = ( String )e.nextElement(); + String className = (String)e.nextElement(); if( !outOfDateClasses.containsKey( className ) ) { - ClassFileInfo info = ( ClassFileInfo )classFileInfoMap.get( className ); + ClassFileInfo info = (ClassFileInfo)classFileInfoMap.get( className ); // if we have no info about the class - it may have been deleted already and we // are using cached info. if( info != null ) { - Hashtable dependencies = ( Hashtable )classpathDependencies.get( className ); - for( Enumeration e2 = dependencies.elements(); e2.hasMoreElements(); ) + Hashtable dependencies = (Hashtable)classpathDependencies.get( className ); + for( Enumeration e2 = dependencies.elements(); e2.hasMoreElements(); ) { - File classpathFile = ( File )e2.nextElement(); + File classpathFile = (File)e2.nextElement(); if( classpathFile.lastModified() > info.absoluteFile.lastModified() ) { log( "Class " + className + - " is out of date with respect to " + classpathFile, Project.MSG_DEBUG ); + " is out of date with respect to " + classpathFile, Project.MSG_DEBUG ); outOfDateClasses.put( className, className ); break; } @@ -310,7 +309,7 @@ public class Depend extends MatchingTask } catch( Exception e ) { - throw new BuildException( "Error", e ); + throw new TaskException( "Error", e ); } } @@ -328,14 +327,14 @@ public class Depend extends MatchingTask for( int i = 0; i < files.length; i++ ) { - File srcFile = new File( srcDir, files[i] ); - if( files[i].endsWith( ".java" ) ) + File srcFile = new File( srcDir, files[ i ] ); + if( files[ i ].endsWith( ".java" ) ) { String filePath = srcFile.getPath(); String className = filePath.substring( srcDir.getPath().length() + 1, - filePath.length() - ".java".length() ); + filePath.length() - ".java".length() ); className = ClassFileUtils.convertSlashName( className ); - ClassFileInfo info = ( ClassFileInfo )classFileInfoMap.get( className ); + ClassFileInfo info = (ClassFileInfo)classFileInfoMap.get( className ); if( info == null ) { // there was no class file. add this class to the list @@ -352,7 +351,6 @@ public class Depend extends MatchingTask } } - /** * Get the list of class files we are going to analyse. * @@ -369,7 +367,7 @@ public class Depend extends MatchingTask for( int i = 0; i < classLocationsList.length; ++i ) { - File dir = new File( classLocationsList[i] ); + File dir = new File( classLocationsList[ i ] ); if( dir.isDirectory() ) { addClassFiles( classFileList, dir, dir ); @@ -397,7 +395,7 @@ public class Depend extends MatchingTask for( int i = 0; i < length; ++i ) { - File file = new File( dir, filesInDir[i] ); + File file = new File( dir, filesInDir[ i ] ); if( file.isDirectory() ) { addClassFiles( classFileList, file, root ); @@ -407,7 +405,7 @@ public class Depend extends MatchingTask ClassFileInfo info = new ClassFileInfo(); info.absoluteFile = file; info.relativeName = file.getPath().substring( root.getPath().length() + 1, - file.getPath().length() - 6 ); + file.getPath().length() - 6 ); info.className = ClassFileUtils.convertSlashName( info.relativeName ); classFileList.addElement( info ); } @@ -419,17 +417,17 @@ public class Depend extends MatchingTask { int count = 0; - Hashtable affectedClasses = ( Hashtable )affectedClassMap.get( className ); + Hashtable affectedClasses = (Hashtable)affectedClassMap.get( className ); if( affectedClasses != null ) { - for( Enumeration e = affectedClasses.keys(); e.hasMoreElements(); ) + for( Enumeration e = affectedClasses.keys(); e.hasMoreElements(); ) { - String affectedClassName = ( String )e.nextElement(); - ClassFileInfo affectedClassInfo = ( ClassFileInfo )affectedClasses.get( affectedClassName ); + String affectedClassName = (String)e.nextElement(); + ClassFileInfo affectedClassInfo = (ClassFileInfo)affectedClasses.get( affectedClassName ); if( affectedClassInfo.absoluteFile.exists() ) { log( "Deleting file " + affectedClassInfo.absoluteFile.getPath() + " since " + - className + " out of date", Project.MSG_VERBOSE ); + className + " out of date", Project.MSG_VERBOSE ); affectedClassInfo.absoluteFile.delete(); count++; if( closure ) @@ -445,15 +443,15 @@ public class Depend extends MatchingTask { // need to delete the main class String topLevelClassName - = affectedClassName.substring( 0, affectedClassName.indexOf( "$" ) ); + = affectedClassName.substring( 0, affectedClassName.indexOf( "$" ) ); log( "Top level class = " + topLevelClassName, Project.MSG_VERBOSE ); ClassFileInfo topLevelClassInfo - = ( ClassFileInfo )classFileInfoMap.get( topLevelClassName ); + = (ClassFileInfo)classFileInfoMap.get( topLevelClassName ); if( topLevelClassInfo != null && topLevelClassInfo.absoluteFile.exists() ) { log( "Deleting file " + topLevelClassInfo.absoluteFile.getPath() + " since " + - "one of its inner classes was removed", Project.MSG_VERBOSE ); + "one of its inner classes was removed", Project.MSG_VERBOSE ); topLevelClassInfo.absoluteFile.delete(); count++; if( closure ) @@ -472,11 +470,11 @@ public class Depend extends MatchingTask private int deleteAllAffectedFiles() { int count = 0; - for( Enumeration e = outOfDateClasses.elements(); e.hasMoreElements(); ) + for( Enumeration e = outOfDateClasses.elements(); e.hasMoreElements(); ) { - String className = ( String )e.nextElement(); + String className = (String)e.nextElement(); count += deleteAffectedFiles( className ); - ClassFileInfo classInfo = ( ClassFileInfo )classFileInfoMap.get( className ); + ClassFileInfo classInfo = (ClassFileInfo)classFileInfoMap.get( className ); if( classInfo != null && classInfo.absoluteFile.exists() ) { classInfo.absoluteFile.delete(); @@ -486,7 +484,6 @@ public class Depend extends MatchingTask return count; } - /** * Determine the dependencies between classes. Class dependencies are * determined by examining the class references in a class file to other @@ -495,7 +492,7 @@ public class Depend extends MatchingTask * @exception IOException Description of Exception */ private void determineDependencies() - throws IOException + throws IOException, TaskException { affectedClassMap = new Hashtable(); classFileInfoMap = new Hashtable(); @@ -514,9 +511,9 @@ public class Depend extends MatchingTask depCacheFileExists = depCacheFile.exists(); depCacheFileLastModified = depCacheFile.lastModified(); } - for( Enumeration e = getClassFiles( destPath ).elements(); e.hasMoreElements(); ) + for( Enumeration e = getClassFiles( destPath ).elements(); e.hasMoreElements(); ) { - ClassFileInfo info = ( ClassFileInfo )e.nextElement(); + ClassFileInfo info = (ClassFileInfo)e.nextElement(); log( "Adding class info for " + info.className, Project.MSG_DEBUG ); classFileInfoMap.put( info.className, info ); @@ -529,7 +526,7 @@ public class Depend extends MatchingTask { // depFile exists and is newer than the class file // need to get dependency list from the map. - dependencyList = ( Vector )dependencyMap.get( info.className ); + dependencyList = (Vector)dependencyMap.get( info.className ); } } @@ -562,11 +559,11 @@ public class Depend extends MatchingTask // This class depends on each class in the dependency list. For each // one of those, add this class into their affected classes list - for( Enumeration depEnum = dependencyList.elements(); depEnum.hasMoreElements(); ) + for( Enumeration depEnum = dependencyList.elements(); depEnum.hasMoreElements(); ) { - String dependentClass = ( String )depEnum.nextElement(); + String dependentClass = (String)depEnum.nextElement(); - Hashtable affectedClasses = ( Hashtable )affectedClassMap.get( dependentClass ); + Hashtable affectedClasses = (Hashtable)affectedClassMap.get( dependentClass ); if( affectedClasses == null ) { affectedClasses = new Hashtable(); @@ -586,15 +583,15 @@ public class Depend extends MatchingTask Hashtable classpathFileCache = new Hashtable(); Object nullFileMarker = new Object(); - for( Enumeration e = dependencyMap.keys(); e.hasMoreElements(); ) + for( Enumeration e = dependencyMap.keys(); e.hasMoreElements(); ) { - String className = ( String )e.nextElement(); - Vector dependencyList = ( Vector )dependencyMap.get( className ); + String className = (String)e.nextElement(); + Vector dependencyList = (Vector)dependencyMap.get( className ); Hashtable dependencies = new Hashtable(); classpathDependencies.put( className, dependencies ); - for( Enumeration e2 = dependencyList.elements(); e2.hasMoreElements(); ) + for( Enumeration e2 = dependencyList.elements(); e2.hasMoreElements(); ) { - String dependency = ( String )e2.nextElement(); + String dependency = (String)e2.nextElement(); Object classpathFileObject = classpathFileCache.get( dependency ); if( classpathFileObject == null ) { @@ -621,8 +618,8 @@ public class Depend extends MatchingTask classpathFileObject = new File( classFilePath ); } log( "Class " + className + - " depends on " + classpathFileObject + - " due to " + dependency, Project.MSG_DEBUG ); + " depends on " + classpathFileObject + + " due to " + dependency, Project.MSG_DEBUG ); } } classpathFileCache.put( dependency, classpathFileObject ); @@ -630,7 +627,7 @@ public class Depend extends MatchingTask if( classpathFileObject != null && classpathFileObject != nullFileMarker ) { // we need to add this jar to the list for this class. - File jarFile = ( File )classpathFileObject; + File jarFile = (File)classpathFileObject; dependencies.put( jarFile, jarFile ); } } @@ -713,13 +710,13 @@ public class Depend extends MatchingTask File depFile = new File( cache, CACHE_FILE_NAME ); pw = new PrintWriter( new FileWriter( depFile ) ); - for( Enumeration deps = dependencyMap.keys(); deps.hasMoreElements(); ) + for( Enumeration deps = dependencyMap.keys(); deps.hasMoreElements(); ) { - String className = ( String )deps.nextElement(); + String className = (String)deps.nextElement(); pw.println( CLASSNAME_PREPEND + className ); - Vector dependencyList = ( Vector )dependencyMap.get( className ); + Vector dependencyList = (Vector)dependencyMap.get( className ); int size = dependencyList.size(); for( int x = 0; x < size; x++ ) { diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java index 6343dbbb2..e152ef97e 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs.optional.ejb; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -24,14 +25,13 @@ import java.util.zip.ZipEntry; import javax.xml.parsers.SAXParser; import org.apache.bcel.*; import org.apache.bcel.classfile.*; -import org.apache.tools.ant.*; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Location; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.*; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.util.depend.Dependencies; @@ -39,7 +39,6 @@ import org.apache.tools.ant.util.depend.Filter; import org.xml.sax.InputSource; import org.xml.sax.SAXException; - /** * A deployment tool which creates generic EJB jars. Generic jars contains only * those classes and META-INF entries specified in the EJB 1.1 standard This @@ -133,7 +132,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool this.genericJarSuffix = inString; } - /** * Set the task which owns this tool * @@ -178,7 +176,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool return ddPrefix; } - /** * Configure this tool for use in the ejbjar task. * @@ -227,7 +224,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool // First the regular deployment descriptor ejbFiles.put( META_DIR + EJB_DD, - new File( config.descriptorDir, descriptorFileName ) ); + new File( config.descriptorDir, descriptorFileName ) ); // now the vendor specific files, if any addVendorFiles( ejbFiles, ddPrefix ); @@ -260,7 +257,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool + " with " + String.valueOf( ejbFiles.size() ) + " files", - Project.MSG_INFO ); + Project.MSG_INFO ); // Use helper method to write the jarfile String publicId = getPublicId(); @@ -271,26 +268,26 @@ public class GenericDeploymentTool implements EJBDeploymentTool { // Log that the file is up to date... log( jarFile.toString() + " is up to date.", - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); } } catch( SAXException se ) { String msg = "SAXException while parsing '" - + descriptorFileName.toString() - + "'. This probably indicates badly-formed XML." - + " Details: " - + se.getMessage(); + + descriptorFileName.toString() + + "'. This probably indicates badly-formed XML." + + " Details: " + + se.getMessage(); throw new BuildException( msg, se ); } catch( IOException ioe ) { String msg = "IOException while parsing'" - + descriptorFileName.toString() - + "'. This probably indicates that the descriptor" - + " doesn't exist. Details: " - + ioe.getMessage(); + + descriptorFileName.toString() + + "'. This probably indicates that the descriptor" + + " doesn't exist. Details: " + + ioe.getMessage(); throw new BuildException( msg, ioe ); } } @@ -306,12 +303,11 @@ public class GenericDeploymentTool implements EJBDeploymentTool if( ( destDir == null ) || ( !destDir.isDirectory() ) ) { String msg = "A valid destination directory must be specified " - + "using the \"destdir\" attribute."; + + "using the \"destdir\" attribute."; throw new BuildException( msg ); } } - /** * Returns a Classloader object which parses the passed in generic EjbJar * classpath. The loader is used to dynamically load classes from @@ -320,6 +316,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool * @return The ClassLoaderForBuild value */ protected ClassLoader getClassLoaderForBuild() + throws TaskException { if( classpathLoader != null ) { @@ -382,9 +379,9 @@ public class GenericDeploymentTool implements EJBDeploymentTool registerKnownDTDs( handler ); // register any DTDs supplied by the user - for( Iterator i = getConfig().dtdLocations.iterator(); i.hasNext(); ) + for( Iterator i = getConfig().dtdLocations.iterator(); i.hasNext(); ) { - EjbJar.DTDLocation dtdLocation = ( EjbJar.DTDLocation )i.next(); + EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation)i.next(); handler.registerDTD( dtdLocation.getPublicId(), dtdLocation.getLocation() ); } return handler; @@ -400,7 +397,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool return destDir; } - /** * Using the EJB descriptor file name passed from the ejbjar * task, this method returns the "basename" which will be used to name the @@ -433,7 +429,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool if( lastSeparatorIndex != -1 ) { endBaseName = descriptorFileName.indexOf( config.baseNameTerminator, - lastSeparatorIndex ); + lastSeparatorIndex ); } else { @@ -522,13 +518,13 @@ public class GenericDeploymentTool implements EJBDeploymentTool // Create the file input stream, and buffer everything over // to the jar output stream - byte[] byteBuffer = new byte[2 * 1024]; + byte[] byteBuffer = new byte[ 2 * 1024 ]; int count = 0; do { jStream.write( byteBuffer, 0, count ); count = iStream.read( byteBuffer, 0, byteBuffer.length ); - }while ( count != -1 ); + } while( count != -1 ); //add it to list of files in jar addedfiles.add( logicalFilename ); @@ -537,8 +533,8 @@ public class GenericDeploymentTool implements EJBDeploymentTool catch( IOException ioe ) { log( "WARNING: IOException while adding entry " + - logicalFilename + " to jarfile from " + inputFile.getPath() + " " + - ioe.getClass().getName() + "-" + ioe.getMessage(), Project.MSG_WARN ); + logicalFilename + " to jarfile from " + inputFile.getPath() + " " + + ioe.getClass().getName() + "-" + ioe.getMessage(), Project.MSG_WARN ); } finally { @@ -550,7 +546,8 @@ public class GenericDeploymentTool implements EJBDeploymentTool iStream.close(); } catch( IOException closeException ) - {} + { + } } } } @@ -566,16 +563,16 @@ public class GenericDeploymentTool implements EJBDeploymentTool { // add in support classes if any Project project = task.getProject(); - for( Iterator i = config.supportFileSets.iterator(); i.hasNext(); ) + for( Iterator i = config.supportFileSets.iterator(); i.hasNext(); ) { - FileSet supportFileSet = ( FileSet )i.next(); + FileSet supportFileSet = (FileSet)i.next(); File supportBaseDir = supportFileSet.getDir( project ); DirectoryScanner supportScanner = supportFileSet.getDirectoryScanner( project ); supportScanner.scan(); String[] supportFiles = supportScanner.getIncludedFiles(); for( int j = 0; j < supportFiles.length; ++j ) { - ejbFiles.put( supportFiles[j], new File( supportBaseDir, supportFiles[j] ) ); + ejbFiles.put( supportFiles[ j ], new File( supportBaseDir, supportFiles[ j ] ) ); } } } @@ -591,7 +588,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool // nothing to add for generic tool. }// end of writeJar - /** * Add all available classes, that depend on Remote, Home, Bean, PK * @@ -610,7 +606,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool Iterator i = checkEntries.keySet().iterator(); while( i.hasNext() ) { - String entryName = ( String )i.next(); + String entryName = (String)i.next(); if( entryName.endsWith( ".class" ) ) newSet.add( entryName.substring( 0, entryName.length() - ".class".length() ).replace( File.separatorChar, '/' ) ); } @@ -621,7 +617,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool i = newSet.iterator(); while( i.hasNext() ) { - String fileName = base + ( ( String )i.next() ).replace( '/', File.separatorChar ) + ".class"; + String fileName = base + ( (String)i.next() ).replace( '/', File.separatorChar ) + ".class"; try { @@ -638,22 +634,22 @@ public class GenericDeploymentTool implements EJBDeploymentTool visitor.clearDependencies(); Dependencies.applyFilter( newSet, - new Filter() - { - public boolean accept( Object object ) - { - String fileName = base + ( ( String )object ).replace( '/', File.separatorChar ) + ".class"; - return new File( fileName ).exists(); - } - } ); + new Filter() + { + public boolean accept( Object object ) + { + String fileName = base + ( (String)object ).replace( '/', File.separatorChar ) + ".class"; + return new File( fileName ).exists(); + } + } ); newSet.removeAll( set ); set.addAll( newSet ); - }while ( newSet.size() > 0 ); + } while( newSet.size() > 0 ); i = set.iterator(); while( i.hasNext() ) { - String next = ( ( String )i.next() ).replace( '/', File.separatorChar ); + String next = ( (String)i.next() ).replace( '/', File.separatorChar ); checkEntries.put( next + ".class", new File( base + next + ".class" ) ); log( "dependent class: " + next + ".class" + " - " + base + next + ".class", Project.MSG_VERBOSE ); } @@ -713,7 +709,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool config.manifest.lastModified() > lastBuild ) { log( "Build needed because manifest " + config.manifest + " is out of date", - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); return true; } @@ -723,11 +719,11 @@ public class GenericDeploymentTool implements EJBDeploymentTool // more recently than the destination jar. while( fileIter.hasNext() ) { - File currentFile = ( File )fileIter.next(); + File currentFile = (File)fileIter.next(); if( lastBuild < currentFile.lastModified() ) { log( "Build needed because " + currentFile.getPath() + " is out of date", - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); return true; } } @@ -780,7 +776,8 @@ public class GenericDeploymentTool implements EJBDeploymentTool descriptorStream.close(); } catch( IOException closeException ) - {} + { + } } } @@ -892,13 +889,13 @@ public class GenericDeploymentTool implements EJBDeploymentTool jarStream.setMethod( JarOutputStream.DEFLATED ); // Loop through all the class files found and add them to the jar - for( Iterator entryIterator = files.keySet().iterator(); entryIterator.hasNext(); ) + for( Iterator entryIterator = files.keySet().iterator(); entryIterator.hasNext(); ) { - String entryName = ( String )entryIterator.next(); - File entryFile = ( File )files.get( entryName ); + String entryName = (String)entryIterator.next(); + File entryFile = (File)files.get( entryName ); log( "adding file '" + entryName + "'", - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); addFileToJar( jarStream, entryFile, entryName ); @@ -913,17 +910,17 @@ public class GenericDeploymentTool implements EJBDeploymentTool int entryIndex = entryName.lastIndexOf( entryFile.getName() ) - 1; if( entryIndex < 0 ) { - entryName = innerfiles[i]; + entryName = innerfiles[ i ]; } else { - entryName = entryName.substring( 0, entryIndex ) + File.separatorChar + innerfiles[i]; + entryName = entryName.substring( 0, entryIndex ) + File.separatorChar + innerfiles[ i ]; } // link the file entryFile = new File( config.srcDir, entryName ); log( "adding innerclass file '" + entryName + "'", - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); addFileToJar( jarStream, entryFile, entryName ); @@ -933,9 +930,9 @@ public class GenericDeploymentTool implements EJBDeploymentTool catch( IOException ioe ) { String msg = "IOException while processing ejb-jar file '" - + jarfile.toString() - + "'. Details: " - + ioe.getMessage(); + + jarfile.toString() + + "'. Details: " + + ioe.getMessage(); throw new BuildException( msg, ioe ); } finally @@ -947,12 +944,12 @@ public class GenericDeploymentTool implements EJBDeploymentTool jarStream.close(); } catch( IOException closeException ) - {} + { + } } } } - /** * Get the vendor specific name of the Jar that will be output. The * modification date of this jar will be checked against the dependent bean diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java index cc7d965ad..2a6ab0e07 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs.optional.ejb; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -19,9 +20,10 @@ import java.util.jar.JarFile; import java.util.jar.JarOutputStream; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.AntClassLoader; -import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.taskdefs.Java; import org.apache.tools.ant.types.Path; import org.xml.sax.InputSource; @@ -29,27 +31,27 @@ import org.xml.sax.InputSource; public class WeblogicDeploymentTool extends GenericDeploymentTool { public final static String PUBLICID_EJB11 - = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"; + = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"; public final static String PUBLICID_EJB20 - = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"; + = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"; public final static String PUBLICID_WEBLOGIC_EJB510 - = "-//BEA Systems, Inc.//DTD WebLogic 5.1.0 EJB//EN"; + = "-//BEA Systems, Inc.//DTD WebLogic 5.1.0 EJB//EN"; public final static String PUBLICID_WEBLOGIC_EJB600 - = "-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN"; + = "-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN"; protected final static String DEFAULT_WL51_EJB11_DTD_LOCATION - = "/weblogic/ejb/deployment/xml/ejb-jar.dtd"; + = "/weblogic/ejb/deployment/xml/ejb-jar.dtd"; protected final static String DEFAULT_WL60_EJB11_DTD_LOCATION - = "/weblogic/ejb20/dd/xml/ejb11-jar.dtd"; + = "/weblogic/ejb20/dd/xml/ejb11-jar.dtd"; protected final static String DEFAULT_WL60_EJB20_DTD_LOCATION - = "/weblogic/ejb20/dd/xml/ejb20-jar.dtd"; + = "/weblogic/ejb20/dd/xml/ejb20-jar.dtd"; protected final static String DEFAULT_WL51_DTD_LOCATION - = "/weblogic/ejb/deployment/xml/weblogic-ejb-jar.dtd"; + = "/weblogic/ejb/deployment/xml/weblogic-ejb-jar.dtd"; protected final static String DEFAULT_WL60_51_DTD_LOCATION - = "/weblogic/ejb20/dd/xml/weblogic510-ejb-jar.dtd"; + = "/weblogic/ejb20/dd/xml/weblogic510-ejb-jar.dtd"; protected final static String DEFAULT_WL60_DTD_LOCATION - = "/weblogic/ejb20/dd/xml/weblogic600-ejb-jar.dtd"; + = "/weblogic/ejb20/dd/xml/weblogic600-ejb-jar.dtd"; protected final static String DEFAULT_COMPILER = "default"; @@ -235,7 +237,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool this.alwaysRebuild = rebuild; } - /** * Setter used to store the suffix for the generated weblogic jar file. * @@ -262,7 +263,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool this.weblogicDTD = inString; } - /** * Setter used to store the location of the ejb-jar DTD. This can be a file * on the system or a resource on the classpath. @@ -306,10 +306,10 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool /** * Called to validate that the tool parameters have been configured. * - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void validateConfigured() - throws BuildException + throws TaskException { super.validateConfigured(); } @@ -323,7 +323,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool * @exception IOException Description of Exception */ protected ClassLoader getClassLoaderFromJar( File classjar ) - throws IOException + throws IOException, TaskException { Path lookupPath = new Path( getTask().getProject() ); lookupPath.setLocation( classjar ); @@ -350,7 +350,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool String fileNameWithMETA = currentText; //trim the META_INF\ off of the file name String fileName = fileNameWithMETA.substring( META_DIR.length(), - fileNameWithMETA.length() ); + fileNameWithMETA.length() ); File descriptorFile = new File( srcDir, fileName ); ejbFiles.put( fileNameWithMETA, descriptorFile ); @@ -364,15 +364,14 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool handler.registerDTD( PUBLICID_WEBLOGIC_EJB510, weblogicDTD ); handler.registerDTD( PUBLICID_WEBLOGIC_EJB600, weblogicDTD ); - for( Iterator i = getConfig().dtdLocations.iterator(); i.hasNext(); ) + for( Iterator i = getConfig().dtdLocations.iterator(); i.hasNext(); ) { - EjbJar.DTDLocation dtdLocation = ( EjbJar.DTDLocation )i.next(); + EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation)i.next(); handler.registerDTD( dtdLocation.getPublicId(), dtdLocation.getLocation() ); } return handler; } - /** * Helper method to check to see if a weblogic EBJ1.1 jar needs to be * rebuilt using ejbc. Called from writeJar it sees if the "Bean" classes @@ -398,6 +397,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool * @return The RebuildRequired value */ protected boolean isRebuildRequired( File genericJarFile, File weblogicJarFile ) + throws TaskException { boolean rebuild = false; @@ -409,10 +409,10 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool try { log( "Checking if weblogic Jar needs to be rebuilt for jar " + weblogicJarFile.getName(), - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); // Only go forward if the generic and the weblogic file both exist if( genericJarFile.exists() && genericJarFile.isFile() - && weblogicJarFile.exists() && weblogicJarFile.isFile() ) + && weblogicJarFile.exists() && weblogicJarFile.isFile() ) { //open jar files genericJar = new JarFile( genericJarFile ); @@ -423,31 +423,31 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool Hashtable replaceEntries = new Hashtable(); //get the list of generic jar entries - for( Enumeration e = genericJar.entries(); e.hasMoreElements(); ) + for( Enumeration e = genericJar.entries(); e.hasMoreElements(); ) { - JarEntry je = ( JarEntry )e.nextElement(); + JarEntry je = (JarEntry)e.nextElement(); genericEntries.put( je.getName().replace( '\\', '/' ), je ); } //get the list of weblogic jar entries - for( Enumeration e = wlJar.entries(); e.hasMoreElements(); ) + for( Enumeration e = wlJar.entries(); e.hasMoreElements(); ) { - JarEntry je = ( JarEntry )e.nextElement(); + JarEntry je = (JarEntry)e.nextElement(); wlEntries.put( je.getName(), je ); } //Cycle Through generic and make sure its in weblogic ClassLoader genericLoader = getClassLoaderFromJar( genericJarFile ); - for( Enumeration e = genericEntries.keys(); e.hasMoreElements(); ) + for( Enumeration e = genericEntries.keys(); e.hasMoreElements(); ) { - String filepath = ( String )e.nextElement(); + String filepath = (String)e.nextElement(); if( wlEntries.containsKey( filepath ) ) {// File name/path match // Check files see if same - JarEntry genericEntry = ( JarEntry )genericEntries.get( filepath ); - JarEntry wlEntry = ( JarEntry )wlEntries.get( filepath ); + JarEntry genericEntry = (JarEntry)genericEntries.get( filepath ); + JarEntry wlEntry = (JarEntry)wlEntries.get( filepath ); if( ( genericEntry.getCrc() != wlEntry.getCrc() ) || // Crc's Match - ( genericEntry.getSize() != wlEntry.getSize() ) ) + ( genericEntry.getSize() != wlEntry.getSize() ) ) {// Size Match if( genericEntry.getName().endsWith( ".class" ) ) @@ -504,12 +504,12 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool newJarStream.setLevel( 0 ); //Copy files from old weblogic jar - for( Enumeration e = wlEntries.elements(); e.hasMoreElements(); ) + for( Enumeration e = wlEntries.elements(); e.hasMoreElements(); ) { - byte[] buffer = new byte[1024]; + byte[] buffer = new byte[ 1024 ]; int bytesRead; InputStream is; - JarEntry je = ( JarEntry )e.nextElement(); + JarEntry je = (JarEntry)e.nextElement(); if( je.getCompressedSize() == -1 || je.getCompressedSize() == je.getSize() ) { @@ -525,7 +525,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { log( "Updating Bean class from generic Jar " + je.getName(), Project.MSG_VERBOSE ); // Use the entry from the generic jar - je = ( JarEntry )replaceEntries.get( je.getName() ); + je = (JarEntry)replaceEntries.get( je.getName() ); is = genericJar.getInputStream( je ); } else @@ -555,16 +555,16 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool catch( ClassNotFoundException cnfe ) { String cnfmsg = "ClassNotFoundException while processing ejb-jar file" - + ". Details: " - + cnfe.getMessage(); - throw new BuildException( cnfmsg, cnfe ); + + ". Details: " + + cnfe.getMessage(); + throw new TaskException( cnfmsg, cnfe ); } catch( IOException ioe ) { String msg = "IOException while processing ejb-jar file " - + ". Details: " - + ioe.getMessage(); - throw new BuildException( msg, ioe ); + + ". Details: " + + ioe.getMessage(); + throw new TaskException( msg, ioe ); } finally { @@ -576,7 +576,8 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool genericJar.close(); } catch( IOException closeException ) - {} + { + } } if( wlJar != null ) @@ -586,7 +587,8 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool wlJar.close(); } catch( IOException closeException ) - {} + { + } } if( newJarStream != null ) @@ -596,7 +598,8 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool newJarStream.close(); } catch( IOException closeException ) - {} + { + } weblogicJarFile.delete(); newWLJarFile.renameTo( weblogicJarFile ); @@ -623,12 +626,12 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool if( weblogicDD.exists() ) { ejbFiles.put( META_DIR + WL_DD, - weblogicDD ); + weblogicDD ); } else { log( "Unable to locate weblogic deployment descriptor. It was expected to be in " + - weblogicDD.getPath(), Project.MSG_WARN ); + weblogicDD.getPath(), Project.MSG_WARN ); return; } @@ -636,14 +639,14 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { log( "The old method for locating CMP files has been DEPRECATED.", Project.MSG_VERBOSE ); log( "Please adjust your weblogic descriptor and set newCMP=\"true\" " + - "to use the new CMP descriptor inclusion mechanism. ", Project.MSG_VERBOSE ); + "to use the new CMP descriptor inclusion mechanism. ", Project.MSG_VERBOSE ); // The the weblogic cmp deployment descriptor File weblogicCMPDD = new File( getConfig().descriptorDir, ddPrefix + WL_CMP_DD ); if( weblogicCMPDD.exists() ) { ejbFiles.put( META_DIR + WL_CMP_DD, - weblogicCMPDD ); + weblogicCMPDD ); } } else @@ -654,28 +657,28 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool // mapping tool descriptors. try { - File ejbDescriptor = ( File )ejbFiles.get( META_DIR + EJB_DD ); + File ejbDescriptor = (File)ejbFiles.get( META_DIR + EJB_DD ); SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setValidating( true ); SAXParser saxParser = saxParserFactory.newSAXParser(); DescriptorHandler handler = getWeblogicDescriptorHandler( ejbDescriptor.getParentFile() ); saxParser.parse( new InputSource ( new FileInputStream - ( weblogicDD ) ), - handler ); + ( weblogicDD ) ), + handler ); Hashtable ht = handler.getFiles(); Enumeration e = ht.keys(); while( e.hasMoreElements() ) { - String key = ( String )e.nextElement(); + String key = (String)e.nextElement(); ejbFiles.put( key, ht.get( key ) ); } } catch( Exception e ) { String msg = "Exception while adding Vendor specific files: " + e.toString(); - throw new BuildException( msg, e ); + throw new TaskException( msg, e ); } } } @@ -698,11 +701,11 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool * @param jarFile Description of Parameter * @param files Description of Parameter * @param publicId Description of Parameter - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ protected void writeJar( String baseName, File jarFile, Hashtable files, String publicId ) - throws BuildException + throws TaskException { // need to create a generic jar first. File genericJarFile = super.getVendorOutputJarFile( baseName ); @@ -715,7 +718,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool if( !keepGeneric ) { log( "deleting generic jar " + genericJarFile.toString(), - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); genericJarFile.delete(); } } @@ -751,7 +754,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { try { - getTask().getProject().copyFile( sourceJar, destJar ); + FileUtils.newFileUtils().copyFile( sourceJar, destJar ); if( !keepgenerated ) { sourceJar.delete(); @@ -760,7 +763,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool } catch( IOException e ) { - throw new BuildException( "Unable to write EJB jar", e ); + throw new TaskException( "Unable to write EJB jar", e ); } } @@ -768,7 +771,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool try { - javaTask = ( Java )getTask().getProject().createTask( "java" ); + javaTask = (Java)getTask().getProject().createTask( "java" ); javaTask.setTaskName( "ejbc" ); if( getJvmDebugLevel() != null ) @@ -835,18 +838,18 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool } log( "Calling " + ejbcClassName + " for " + sourceJar.toString(), - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); if( javaTask.executeJava() != 0 ) { - throw new BuildException( "Ejbc reported an error" ); + throw new TaskException( "Ejbc reported an error" ); } } catch( Exception e ) { // Have to catch this because of the semantics of calling main() String msg = "Exception while calling " + ejbcClassName + ". Details: " + e.toString(); - throw new BuildException( msg, e ); + throw new TaskException( msg, e ); } } } diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java index 8272c3e20..abb75100e 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java @@ -6,17 +6,25 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs.optional.ejb; -import java.io.*; -import java.net.*; -import java.util.*; -import java.util.jar.*; -import javax.xml.parsers.*; -import org.apache.tools.ant.*; -import org.apache.tools.ant.taskdefs.*; -import org.apache.tools.ant.taskdefs.ExecTask; -import org.apache.tools.ant.types.*; -import org.xml.sax.*; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.jar.JarOutputStream; +import org.apache.myrmidon.api.TaskException; +import org.apache.tools.ant.AntClassLoader; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Java; +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.EnumeratedAttribute; +import org.apache.tools.ant.types.Environment; +import org.apache.tools.ant.types.Path; /** * Websphere deployment tool that augments the ejbjar task. @@ -27,20 +35,14 @@ import org.xml.sax.*; public class WebsphereDeploymentTool extends GenericDeploymentTool { - - public final static String PUBLICID_EJB11 - - = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"; + = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"; public final static String PUBLICID_EJB20 - - = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"; + = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"; protected final static String SCHEMA_DIR = "Schema/"; - - protected final static String WAS_EXT = "ibm-ejb-jar-ext.xmi"; protected final static String WAS_BND = "ibm-ejb-jar-bnd.xmi"; @@ -49,318 +51,203 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool protected final static String WAS_CMP_SCHEMA = "Schema.dbxmi"; - - /** * Instance variable that stores the suffix for the websphere jarfile. */ - private String jarSuffix = ".jar"; - - /** * Instance variable that determines whether generic ejb jars are kept. */ - - - private boolean keepgenerated = false; - - private String additionalArgs = ""; - - private boolean keepGeneric = false; - - private String compiler = null; - - private boolean alwaysRebuild = true; - - private boolean ejbdeploy = true; - - /** * Indicates if the old CMP location convention is to be used. */ - private boolean newCMP = false; - - /** * The classpath to the websphere classes. */ - private Path wasClasspath = null; - - /** * true - Only output error messages, suppress informational messages */ - private boolean quiet = true; - - /** * the scratchdir for the ejbdeploy operation */ - private String tempdir = "_ejbdeploy_temp"; - - /** * true - Only generate the deployment code, do not run RMIC or Javac */ - private boolean codegen; - - /** * The name of the database to create. (For top-down mapping only) */ - private String dbName; - - /** * The name of the schema to create. (For top-down mappings only) */ - private String dbSchema; - - /** * The DB Vendor name, the EJB is persisted against */ - private String dbVendor; - - /** * Instance variable that stores the location of the ejb 1.1 DTD file. */ - private String ejb11DTD; - - /** * true - Disable informational messages */ - private boolean noinform; - - /** * true - Disable the validation steps */ - private boolean novalidate; - - /** * true - Disable warning and informational messages */ - private boolean nowarn; - - /** * Additional options for RMIC */ - private String rmicOptions; - - /** * true - Enable internal tracing */ - private boolean trace; - - /** * true- Use the WebSphere 3.5 compatible mapping rules */ - private boolean use35MappingRules; - - /** * sets some additional args to send to ejbdeploy. * * @param args The new Args value */ - public void setArgs( String args ) { - this.additionalArgs = args; - } - - /** * (true) Only generate the deployment code, do not run RMIC or Javac * * @param codegen The new Codegen value */ - public void setCodegen( boolean codegen ) { - this.codegen = codegen; - } - - /** * The compiler (switch -compiler) to use * * @param compiler The new Compiler value */ - public void setCompiler( String compiler ) { - this.compiler = compiler; - } - - /** * Sets the name of the Database to create * * @param dbName The new Dbname value */ - public void setDbname( String dbName ) { - this.dbName = dbName; - } - - /** * Sets the name of the schema to create * * @param dbSchema The new Dbschema value */ - public void setDbschema( String dbSchema ) { - this.dbSchema = dbSchema; - } - - /** * Sets the DB Vendor for the Entity Bean mapping * * @param dbvendor The new Dbvendor value */ - public void setDbvendor( DBVendor dbvendor ) { - this.dbVendor = dbvendor.getValue(); - } - - /** * Setter used to store the location of the Sun's Generic EJB DTD. This can * be a file on the system or a resource on the classpath. * * @param inString the string to use as the DTD location. */ - public void setEJBdtd( String inString ) { - this.ejb11DTD = inString; - } - - /** * Decide, wether ejbdeploy should be called or not * * @param ejbdeploy */ - public void setEjbdeploy( boolean ejbdeploy ) { - this.ejbdeploy = ejbdeploy; - } - - /** * Sets whether -keepgenerated is passed to ejbdeploy (that is, the .java * source files are kept). * * @param inValue either 'true' or 'false' */ - public void setKeepgenerated( String inValue ) { - this.keepgenerated = Boolean.valueOf( inValue ).booleanValue(); - } - - /** * Setter used to store the value of keepGeneric * * @param inValue a string, either 'true' or 'false'. */ - public void setKeepgeneric( boolean inValue ) { - this.keepGeneric = inValue; - } - - /** * Set the value of the newCMP scheme. The old CMP scheme locates the * websphere CMP descriptor based on the naming convention where the @@ -371,216 +258,142 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool * * @param newCMP The new NewCMP value */ - public void setNewCMP( boolean newCMP ) { - this.newCMP = newCMP; - } - - /** * (true) Disable informational messages * * @param noinfom The new Noinform value */ - public void setNoinform( boolean noinfom ) { - this.noinform = noinform; - } - - /** * (true) Disable the validation steps * * @param novalidate The new Novalidate value */ - public void setNovalidate( boolean novalidate ) { - this.novalidate = novalidate; - } - - /** * (true) Disable warning and informational messages * * @param nowarn The new Nowarn value */ - public void setNowarn( boolean nowarn ) { - this.nowarn = nowarn; - } - - /** * Set the value of the oldCMP scheme. This is an antonym for newCMP * * @param oldCMP The new OldCMP value */ - public void setOldCMP( boolean oldCMP ) { - this.newCMP = !oldCMP; - } - - /** * (true) Only output error messages, suppress informational messages * * @param quiet The new Quiet value */ - public void setQuiet( boolean quiet ) { - this.quiet = quiet; - } - - /** * Set the rebuild flag to false to only update changes in the jar rather * than rerunning ejbdeploy * * @param rebuild The new Rebuild value */ - public void setRebuild( boolean rebuild ) { - this.alwaysRebuild = rebuild; - } - - - - /** * Setter used to store the suffix for the generated websphere jar file. * * @param inString the string to use as the suffix. */ - public void setSuffix( String inString ) { - this.jarSuffix = inString; - } - - /** * Sets the temporary directory for the ejbdeploy task * * @param tempdir The new Tempdir value */ - public void setTempdir( String tempdir ) { - this.tempdir = tempdir; - } - - /** * (true) Enable internal tracing * * @param trace The new Trace value */ - public void setTrace( boolean trace ) { - this.trace = trace; - } - - /** * (true) Use the WebSphere 3.5 compatible mapping rules * * @param attr The new Use35 value */ - public void setUse35( boolean attr ) { - use35MappingRules = attr; - } - - public void setWASClasspath( Path wasClasspath ) { - this.wasClasspath = wasClasspath; - } - - /** * Get the classpath to the websphere classpaths * * @return Description of the Returned Value */ - public Path createWASClasspath() { - if( wasClasspath == null ) { - wasClasspath = new Path( getTask().getProject() ); - } - return wasClasspath.createPath(); - } - - /** * Called to validate that the tool parameters have been configured. * - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ - public void validateConfigured() - throws BuildException + throws TaskException { - super.validateConfigured(); - } - - /** * Helper method invoked by isRebuildRequired to get a ClassLoader for a Jar * File passed to it. @@ -589,37 +402,21 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool * @return The ClassLoaderFromJar value * @exception IOException Description of Exception */ - protected ClassLoader getClassLoaderFromJar( File classjar ) - throws IOException + throws IOException, TaskException { - Path lookupPath = new Path( getTask().getProject() ); - lookupPath.setLocation( classjar ); - - - Path classpath = getCombinedClasspath(); - if( classpath != null ) { - lookupPath.append( classpath ); - } - - - return new AntClassLoader( getTask().getProject(), lookupPath ); - } - - protected DescriptorHandler getDescriptorHandler( File srcDir ) { - DescriptorHandler handler = new DescriptorHandler( getTask(), srcDir ); // register all the DTDs, both the ones that are known and @@ -628,173 +425,89 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool // any supplied by the user handler.registerDTD( PUBLICID_EJB11, ejb11DTD ); - - - - for( Iterator i = getConfig().dtdLocations.iterator(); i.hasNext(); ) + for( Iterator i = getConfig().dtdLocations.iterator(); i.hasNext(); ) { - - EjbJar.DTDLocation dtdLocation = ( EjbJar.DTDLocation )i.next(); - + EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation)i.next(); handler.registerDTD( dtdLocation.getPublicId(), dtdLocation.getLocation() ); - } - - - return handler; - } - - /** * Gets the options for the EJB Deploy operation * * @return String */ - protected String getOptions() { - // Set the options StringBuffer options = new StringBuffer(); - if( dbVendor != null ) { - options.append( " -dbvendor " ).append( dbVendor ); - } - if( dbName != null ) { - options.append( " -dbname \"" ).append( dbName ).append( "\"" ); - } - - - if( dbSchema != null ) { - options.append( " -dbschema \"" ).append( dbSchema ).append( "\"" ); - } - - - if( codegen ) { - options.append( " -codegen" ); - } - - - if( quiet ) { - options.append( " -quiet" ); - } - - - if( novalidate ) { - options.append( " -novalidate" ); - } - - - if( nowarn ) { - options.append( " -nowarn" ); - } - - - if( noinform ) { - options.append( " -noinform" ); - } - - - if( trace ) { - options.append( " -trace" ); - } - - - if( use35MappingRules ) { - options.append( " -35" ); - } - - - if( rmicOptions != null ) { - options.append( " -rmic \"" ).append( rmicOptions ).append( "\"" ); - } - - - return options.toString(); - } - - protected DescriptorHandler getWebsphereDescriptorHandler( final File srcDir ) { - DescriptorHandler handler = new DescriptorHandler( getTask(), srcDir ) { - - protected void processElement() { } - + protected void processElement() + { + } }; - - - - for( Iterator i = getConfig().dtdLocations.iterator(); i.hasNext(); ) + for( Iterator i = getConfig().dtdLocations.iterator(); i.hasNext(); ) { - - EjbJar.DTDLocation dtdLocation = ( EjbJar.DTDLocation )i.next(); - + EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation)i.next(); handler.registerDTD( dtdLocation.getPublicId(), dtdLocation.getLocation() ); - } - return handler; - } - - - - /** * Helper method to check to see if a websphere EBJ1.1 jar needs to be * rebuilt using ejbdeploy. Called from writeJar it sees if the "Bean" @@ -819,235 +532,141 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool * see if it needs to be rebuilt. * @return The RebuildRequired value */ - protected boolean isRebuildRequired( File genericJarFile, File websphereJarFile ) + throws TaskException { - boolean rebuild = false; - - - JarFile genericJar = null; - JarFile wasJar = null; - File newwasJarFile = null; - JarOutputStream newJarStream = null; - - - try { - log( "Checking if websphere Jar needs to be rebuilt for jar " + websphereJarFile.getName(), - - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); // Only go forward if the generic and the websphere file both exist if( genericJarFile.exists() && genericJarFile.isFile() - - && websphereJarFile.exists() && websphereJarFile.isFile() ) + && websphereJarFile.exists() && websphereJarFile.isFile() ) { - //open jar files genericJar = new JarFile( genericJarFile ); - wasJar = new JarFile( websphereJarFile ); - - - Hashtable genericEntries = new Hashtable(); - Hashtable wasEntries = new Hashtable(); - Hashtable replaceEntries = new Hashtable(); //get the list of generic jar entries - for( Enumeration e = genericJar.entries(); e.hasMoreElements(); ) + for( Enumeration e = genericJar.entries(); e.hasMoreElements(); ) { - - JarEntry je = ( JarEntry )e.nextElement(); - + JarEntry je = (JarEntry)e.nextElement(); genericEntries.put( je.getName().replace( '\\', '/' ), je ); - } //get the list of websphere jar entries - for( Enumeration e = wasJar.entries(); e.hasMoreElements(); ) + for( Enumeration e = wasJar.entries(); e.hasMoreElements(); ) { - - JarEntry je = ( JarEntry )e.nextElement(); - + JarEntry je = (JarEntry)e.nextElement(); wasEntries.put( je.getName(), je ); - } - - //Cycle Through generic and make sure its in websphere ClassLoader genericLoader = getClassLoaderFromJar( genericJarFile ); - - for( Enumeration e = genericEntries.keys(); e.hasMoreElements(); ) + for( Enumeration e = genericEntries.keys(); e.hasMoreElements(); ) { - - String filepath = ( String )e.nextElement(); - + String filepath = (String)e.nextElement(); if( wasEntries.containsKey( filepath ) ) {// File name/path match - - // Check files see if same - - JarEntry genericEntry = ( JarEntry )genericEntries.get( filepath ); - - JarEntry wasEntry = ( JarEntry )wasEntries.get( filepath ); - + JarEntry genericEntry = (JarEntry)genericEntries.get( filepath ); + JarEntry wasEntry = (JarEntry)wasEntries.get( filepath ); if( ( genericEntry.getCrc() != wasEntry.getCrc() ) || // Crc's Match ( genericEntry.getSize() != wasEntry.getSize() ) ) {// Size Match - - if( genericEntry.getName().endsWith( ".class" ) ) { - //File are different see if its an object or an interface - - String classname = genericEntry.getName().replace( File.separatorChar, '.' ); - classname = classname.substring( 0, classname.lastIndexOf( ".class" ) ); - Class genclass = genericLoader.loadClass( classname ); - if( genclass.isInterface() ) { - //Interface changed rebuild jar. log( "Interface " + genclass.getName() + " has changed", Project.MSG_VERBOSE ); - rebuild = true; - break; - } - else { - //Object class Changed update it. - - replaceEntries.put( filepath, genericEntry ); - } - } - else { - // is it the manifest. If so ignore it - if( !genericEntry.getName().equals( "META-INF/MANIFEST.MF" ) ) { - //File other then class changed rebuild log( "Non class file " + genericEntry.getName() + " has changed", Project.MSG_VERBOSE ); - rebuild = true; - } - break; - } - } - } - else {// a file doesnt exist rebuild - - log( "File " + filepath + " not present in websphere jar", Project.MSG_VERBOSE ); - rebuild = true; - break; - } - } - - - if( !rebuild ) { - log( "No rebuild needed - updating jar", Project.MSG_VERBOSE ); - newwasJarFile = new File( websphereJarFile.getAbsolutePath() + ".temp" ); - if( newwasJarFile.exists() ) { - newwasJarFile.delete(); - } - - - newJarStream = new JarOutputStream( new FileOutputStream( newwasJarFile ) ); - newJarStream.setLevel( 0 ); //Copy files from old websphere jar - for( Enumeration e = wasEntries.elements(); e.hasMoreElements(); ) + for( Enumeration e = wasEntries.elements(); e.hasMoreElements(); ) { - - byte[] buffer = new byte[1024]; - + byte[] buffer = new byte[ 1024 ]; int bytesRead; - InputStream is; - - JarEntry je = ( JarEntry )e.nextElement(); - + JarEntry je = (JarEntry)e.nextElement(); if( je.getCompressedSize() == -1 || - je.getCompressedSize() == je.getSize() ) { - newJarStream.setLevel( 0 ); - } - else { - newJarStream.setLevel( 9 ); - } @@ -1056,181 +675,107 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool if( replaceEntries.containsKey( je.getName() ) ) { - log( "Updating Bean class from generic Jar " + je.getName(), - - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); // Use the entry from the generic jar - je = ( JarEntry )replaceEntries.get( je.getName() ); - + je = (JarEntry)replaceEntries.get( je.getName() ); is = genericJar.getInputStream( je ); - } - else {//use fle from original websphere jar is = wasJar.getInputStream( je ); - } - newJarStream.putNextEntry( new JarEntry( je.getName() ) ); - - - while( ( bytesRead = is.read( buffer ) ) != -1 ) { - newJarStream.write( buffer, 0, bytesRead ); - } - is.close(); - } - } - else { - log( "websphere Jar rebuild needed due to changed interface or XML", Project.MSG_VERBOSE ); - } - } - else { - rebuild = true; - } - } - catch( ClassNotFoundException cnfe ) { - String cnfmsg = "ClassNotFoundException while processing ejb-jar file" - - + ". Details: " - - + cnfe.getMessage(); - - throw new BuildException( cnfmsg, cnfe ); - + + ". Details: " + + cnfe.getMessage(); + throw new TaskException( cnfmsg, cnfe ); } - catch( IOException ioe ) { - String msg = "IOException while processing ejb-jar file " - - + ". Details: " - - + ioe.getMessage(); - - throw new BuildException( msg, ioe ); - + + ". Details: " + + ioe.getMessage(); + throw new TaskException( msg, ioe ); } - finally { - // need to close files and perhaps rename output if( genericJar != null ) { - try { - genericJar.close(); - } - catch( IOException closeException ) - {} - + { + } } - - - if( wasJar != null ) { - try { - wasJar.close(); - } - catch( IOException closeException ) - {} - + { + } } - - - if( newJarStream != null ) { - try { - newJarStream.close(); - } - catch( IOException closeException ) - {} - - - + { + } websphereJarFile.delete(); - newwasJarFile.renameTo( websphereJarFile ); - if( !websphereJarFile.exists() ) { - rebuild = true; - } - } - } - - - return rebuild; - } - - /** * Add any vendor specific files which should be included in the EJB Jar. * * @param ejbFiles The feature to be added to the VendorFiles attribute * @param baseName The feature to be added to the VendorFiles attribute */ - protected void addVendorFiles( Hashtable ejbFiles, String baseName ) { - - - String ddPrefix = ( usingBaseJarName() ? "" : baseName ); - String dbPrefix = ( dbVendor == null ) ? "" : dbVendor + "-"; @@ -1238,134 +783,79 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool // Get the Extensions document File websphereEXT = new File( getConfig().descriptorDir, ddPrefix + WAS_EXT ); - if( websphereEXT.exists() ) { - ejbFiles.put( META_DIR + WAS_EXT, - - websphereEXT ); - + websphereEXT ); } else { - log( "Unable to locate websphere extensions. It was expected to be in " + - - websphereEXT.getPath(), Project.MSG_VERBOSE ); - + websphereEXT.getPath(), Project.MSG_VERBOSE ); } - - - File websphereBND = new File( getConfig().descriptorDir, ddPrefix + WAS_BND ); - if( websphereBND.exists() ) { - ejbFiles.put( META_DIR + WAS_BND, - - websphereBND ); - + websphereBND ); } else { - log( "Unable to locate websphere bindings. It was expected to be in " + - - websphereBND.getPath(), Project.MSG_VERBOSE ); - + websphereBND.getPath(), Project.MSG_VERBOSE ); } - - - if( !newCMP ) { - log( "The old method for locating CMP files has been DEPRECATED.", Project.MSG_VERBOSE ); - log( "Please adjust your websphere descriptor and set newCMP=\"true\" " + - - "to use the new CMP descriptor inclusion mechanism. ", Project.MSG_VERBOSE ); - + "to use the new CMP descriptor inclusion mechanism. ", Project.MSG_VERBOSE ); } - else { - // We attempt to put in the MAP and Schema files of CMP beans try { - // Add the Map file File websphereMAP = new File( getConfig().descriptorDir, - - ddPrefix + dbPrefix + WAS_CMP_MAP ); - + ddPrefix + dbPrefix + WAS_CMP_MAP ); if( websphereMAP.exists() ) { - ejbFiles.put( META_DIR + WAS_CMP_MAP, - - websphereMAP ); - + websphereMAP ); } else { - log( "Unable to locate the websphere Map: " + - - websphereMAP.getPath(), Project.MSG_VERBOSE ); - + websphereMAP.getPath(), Project.MSG_VERBOSE ); } - File websphereSchema = new File( getConfig().descriptorDir, - - ddPrefix + dbPrefix + WAS_CMP_SCHEMA ); - + ddPrefix + dbPrefix + WAS_CMP_SCHEMA ); if( websphereSchema.exists() ) { - ejbFiles.put( META_DIR + SCHEMA_DIR + WAS_CMP_SCHEMA, - - websphereSchema ); - + websphereSchema ); } else { - log( "Unable to locate the websphere Schema: " + - - websphereSchema.getPath(), Project.MSG_VERBOSE ); - + websphereSchema.getPath(), Project.MSG_VERBOSE ); } // Theres nothing else to see here...keep moving sonny - - } - catch( Exception e ) { - String msg = "Exception while adding Vendor specific files: " + - e.toString(); - - throw new BuildException( msg, e ); - + throw new TaskException( msg, e ); } - } - } - - /** * Method used to encapsulate the writing of the JAR file. Iterates over the * filenames/java.io.Files in the Hashtable stored on the instance variable @@ -1375,22 +865,17 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool * @param jarFile Description of Parameter * @param files Description of Parameter * @param publicId Description of Parameter - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ - protected void writeJar( String baseName, File jarFile, Hashtable files, String publicId ) - - throws BuildException + throws TaskException { - if( ejbdeploy ) { - // create the -generic.jar, if required File genericJarFile = super.getVendorOutputJarFile( baseName ); - super.writeJar( baseName, genericJarFile, files, publicId ); @@ -1399,32 +884,21 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool if( alwaysRebuild || isRebuildRequired( genericJarFile, jarFile ) ) { - buildWebsphereJar( genericJarFile, jarFile ); - } - if( !keepGeneric ) { - log( "deleting generic jar " + genericJarFile.toString(), - - Project.MSG_VERBOSE ); - + Project.MSG_VERBOSE ); genericJarFile.delete(); - } - } - else { - // create the "undeployed" output .jar, if required super.writeJar( baseName, jarFile, files, publicId ); - } /* @@ -1440,11 +914,8 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool * genericJarFile.delete(); * } */ - } - - /** * Get the vendor specific name of the Jar that will be output. The * modification date of this jar will be checked against the dependent bean @@ -1453,16 +924,11 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool * @param baseName Description of Parameter * @return The VendorOutputJarFile value */ - File getVendorOutputJarFile( String baseName ) { - return new File( getDestDir(), baseName + jarSuffix ); - }// end getOptions - - /** * Helper method invoked by execute() for each websphere jar to be built. * Encapsulates the logic of constructing a java task for calling @@ -1472,30 +938,18 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool * @param destJar java.io.File representing the destination, websphere * jarfile. */ - private void buildWebsphereJar( File sourceJar, File destJar ) { - try { - if( ejbdeploy ) { - String args = - " " + sourceJar.getPath() + - " " + tempdir + - " " + destJar.getPath() + - " " + getOptions(); - - - if( getCombinedClasspath() != null && getCombinedClasspath().toString().length() > 0 ) - args += " -cp " + getCombinedClasspath(); @@ -1503,16 +957,12 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool // Why do my ""'s get stripped away??? log( "EJB Deploy Options: " + args, Project.MSG_VERBOSE ); - - - - Java javaTask = ( Java )getTask().getProject().createTask( "java" ); + Java javaTask = (Java)getTask().getProject().createTask( "java" ); // Set the JvmArgs javaTask.createJvmarg().setValue( "-Xms64m" ); - javaTask.createJvmarg().setValue( "-Xmx128m" ); @@ -1520,11 +970,8 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool // Set the Environment variable Environment.Variable var = new Environment.Variable(); - var.setKey( "websphere.lib.dir" ); - var.setValue( getTask().getProject().getProperty( "websphere.home" ) + "/lib" ); - javaTask.addSysproperty( var ); @@ -1538,73 +985,38 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool // Set the Java class name javaTask.setTaskName( "ejbdeploy" ); - javaTask.setClassname( "com.ibm.etools.ejbdeploy.EJBDeploy" ); - - - Commandline.Argument arguments = javaTask.createArg(); - arguments.setLine( args ); - - - Path classpath = wasClasspath; - if( classpath == null ) { - classpath = getCombinedClasspath(); - } - - - if( classpath != null ) { - javaTask.setClasspath( classpath ); - javaTask.setFork( true ); - } - else { - javaTask.setFork( true ); - } - - - log( "Calling websphere.ejbdeploy for " + sourceJar.toString(), - - Project.MSG_VERBOSE ); - - - + Project.MSG_VERBOSE ); javaTask.execute(); - } - } - catch( Exception e ) { - // Have to catch this because of the semantics of calling main() String msg = "Exception while calling ejbdeploy. Details: " + e.toString(); - - throw new BuildException( msg, e ); - + throw new TaskException( msg, e ); } - } - /** * Enumerated attribute with the values for the database vendor types * @@ -1616,15 +1028,10 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool public String[] getValues() { - return new String[]{ - "SQL92", "SQL99", "DB2UDBWIN_V71", "DB2UDBOS390_V6", "DB2UDBAS400_V4R5", - "ORACLE_V8", "INFORMIX_V92", "SYBASE_V1192", "MSSQLSERVER_V7", "MYSQL_V323" - - }; - + }; } } diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/types/Commandline.java b/proposal/myrmidon/src/main/org/apache/tools/ant/types/Commandline.java index b9b221d84..226e992d0 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/types/Commandline.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/types/Commandline.java @@ -6,12 +6,13 @@ * the LICENSE file. */ package org.apache.tools.ant.types; + import java.io.File; import java.util.StringTokenizer; import java.util.Vector; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.BuildException; - /** * Commandline objects help handling command lines specifying processes to * execute. The class can be used to define a command line as nested elements or @@ -44,10 +45,10 @@ public class Commandline implements Cloneable String[] tmp = translateCommandline( to_process ); if( tmp != null && tmp.length > 0 ) { - setExecutable( tmp[0] ); + setExecutable( tmp[ 0 ] ); for( int i = 1; i < tmp.length; i++ ) { - createArgument().setValue( tmp[i] ); + createArgument().setValue( tmp[ i ] ); } } } @@ -68,6 +69,7 @@ public class Commandline implements Cloneable * @return Description of the Returned Value */ public static String quoteArgument( String argument ) + throws TaskException { if( argument.indexOf( "\"" ) > -1 ) { @@ -104,7 +106,15 @@ public class Commandline implements Cloneable { result.append( ' ' ); } - result.append( quoteArgument( line[i] ) ); + + try + { + result.append( quoteArgument( line[ i ] ) ); + } + catch( TaskException e ) + { + } + } return result.toString(); } @@ -113,7 +123,7 @@ public class Commandline implements Cloneable { if( to_process == null || to_process.length() == 0 ) { - return new String[0]; + return new String[ 0 ]; } // parse with a simple finite state machine @@ -129,50 +139,50 @@ public class Commandline implements Cloneable while( tok.hasMoreTokens() ) { String nextTok = tok.nextToken(); - switch ( state ) + switch( state ) { - case inQuote: - if( "\'".equals( nextTok ) ) - { - state = normal; - } - else - { - current.append( nextTok ); - } - break; - case inDoubleQuote: - if( "\"".equals( nextTok ) ) - { - state = normal; - } - else - { - current.append( nextTok ); - } - break; - default: - if( "\'".equals( nextTok ) ) - { - state = inQuote; - } - else if( "\"".equals( nextTok ) ) - { - state = inDoubleQuote; - } - else if( " ".equals( nextTok ) ) - { - if( current.length() != 0 ) + case inQuote: + if( "\'".equals( nextTok ) ) { - v.addElement( current.toString() ); - current.setLength( 0 ); + state = normal; } - } - else - { - current.append( nextTok ); - } - break; + else + { + current.append( nextTok ); + } + break; + case inDoubleQuote: + if( "\"".equals( nextTok ) ) + { + state = normal; + } + else + { + current.append( nextTok ); + } + break; + default: + if( "\'".equals( nextTok ) ) + { + state = inQuote; + } + else if( "\"".equals( nextTok ) ) + { + state = inDoubleQuote; + } + else if( " ".equals( nextTok ) ) + { + if( current.length() != 0 ) + { + v.addElement( current.toString() ); + current.setLength( 0 ); + } + } + else + { + current.append( nextTok ); + } + break; } } @@ -186,12 +196,11 @@ public class Commandline implements Cloneable throw new BuildException( "unbalanced quotes in " + to_process ); } - String[] args = new String[v.size()]; + String[] args = new String[ v.size() ]; v.copyInto( args ); return args; } - /** * Sets the executable to run. * @@ -205,7 +214,6 @@ public class Commandline implements Cloneable .replace( '\\', File.separatorChar ); } - /** * Returns all arguments defined by addLine, addValue * or the argument object. @@ -217,15 +225,15 @@ public class Commandline implements Cloneable Vector result = new Vector( arguments.size() * 2 ); for( int i = 0; i < arguments.size(); i++ ) { - Argument arg = ( Argument )arguments.elementAt( i ); + Argument arg = (Argument)arguments.elementAt( i ); String[] s = arg.getParts(); for( int j = 0; j < s.length; j++ ) { - result.addElement( s[j] ); + result.addElement( s[ j ] ); } } - String[] res = new String[result.size()]; + String[] res = new String[ result.size() ]; result.copyInto( res ); return res; } @@ -240,24 +248,22 @@ public class Commandline implements Cloneable final String[] args = getArguments(); if( executable == null ) return args; - final String[] result = new String[args.length + 1]; - result[0] = executable; + final String[] result = new String[ args.length + 1 ]; + result[ 0 ] = executable; System.arraycopy( args, 0, result, 1, args.length ); return result; } - public String getExecutable() { return executable; } - public void addArguments( String[] line ) { for( int i = 0; i < line.length; i++ ) { - createArgument().setValue( line[i] ); + createArgument().setValue( line[ i ] ); } } @@ -318,7 +324,6 @@ public class Commandline implements Cloneable return getCommandline().length; } - public String toString() { return toString( getCommandline() ); @@ -421,7 +426,7 @@ public class Commandline implements Cloneable realPos = ( executable == null ? 0 : 1 ); for( int i = 0; i < position; i++ ) { - Argument arg = ( Argument )arguments.elementAt( i ); + Argument arg = (Argument)arguments.elementAt( i ); realPos += arg.getParts().length; } } diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/types/FileSet.java b/proposal/myrmidon/src/main/org/apache/tools/ant/types/FileSet.java index 3662f329e..372a1a765 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/types/FileSet.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/types/FileSet.java @@ -82,7 +82,7 @@ public class FileSet extends DataType implements Cloneable } public void setDir( File dir ) - throws BuildException + throws TaskException { if( isReference() ) { @@ -113,10 +113,10 @@ public class FileSet extends DataType implements Cloneable * Sets the name of the file containing the includes patterns. * * @param excl The file to fetch the exclude patterns from. - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void setExcludesfile( File excl ) - throws BuildException + throws TaskException { if( isReference() ) { @@ -147,10 +147,10 @@ public class FileSet extends DataType implements Cloneable * Sets the name of the file containing the includes patterns. * * @param incl The file to fetch the include patterns from. - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void setIncludesfile( File incl ) - throws BuildException + throws TaskException { if( isReference() ) { @@ -168,7 +168,7 @@ public class FileSet extends DataType implements Cloneable * if you make it a reference.

* * @param r The new Refid value - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void setRefid( Reference r ) throws TaskException diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/types/Mapper.java b/proposal/myrmidon/src/main/org/apache/tools/ant/types/Mapper.java index 33e628dfe..28f126d29 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/types/Mapper.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/types/Mapper.java @@ -6,12 +6,13 @@ * the LICENSE file. */ package org.apache.tools.ant.types; + import java.util.Properties; import java.util.Stack; import org.apache.tools.ant.AntClassLoader; -import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.util.FileNameMapper; +import org.apache.myrmidon.api.TaskException; /** * Element to define a FileNameMapper. @@ -106,10 +107,10 @@ public class Mapper extends DataType implements Cloneable * You must not set any other attribute if you make it a reference.

* * @param r The new Refid value - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void setRefid( Reference r ) - throws BuildException + throws TaskException { if( type != null || from != null || to != null ) { @@ -150,10 +151,10 @@ public class Mapper extends DataType implements Cloneable * Returns a fully configured FileNameMapper implementation. * * @return The Implementation value - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public FileNameMapper getImplementation() - throws BuildException + throws TaskException { if( isReference() ) { @@ -162,12 +163,12 @@ public class Mapper extends DataType implements Cloneable if( type == null && classname == null ) { - throw new BuildException( "one of the attributes type or classname is required" ); + throw new TaskException( "one of the attributes type or classname is required" ); } if( type != null && classname != null ) { - throw new BuildException( "must not specify both type and classname attribute" ); + throw new TaskException( "must not specify both type and classname attribute" ); } try @@ -185,23 +186,23 @@ public class Mapper extends DataType implements Cloneable else { AntClassLoader al = new AntClassLoader( getProject(), - classpath ); + classpath ); c = al.loadClass( classname ); AntClassLoader.initializeClass( c ); } - FileNameMapper m = ( FileNameMapper )c.newInstance(); + FileNameMapper m = (FileNameMapper)c.newInstance(); m.setFrom( from ); m.setTo( to ); return m; } - catch( BuildException be ) + catch( TaskException be ) { throw be; } catch( Throwable t ) { - throw new BuildException( "Error", t ); + throw new TaskException( "Error", t ); } finally { @@ -249,11 +250,11 @@ public class Mapper extends DataType implements Cloneable if( !( o instanceof Mapper ) ) { String msg = ref.getRefId() + " doesn\'t denote a mapper"; - throw new BuildException( msg ); + throw new TaskException( msg ); } else { - return ( Mapper )o; + return (Mapper)o; } } @@ -270,15 +271,15 @@ public class Mapper extends DataType implements Cloneable { implementations = new Properties(); implementations.put( "identity", - "org.apache.tools.ant.util.IdentityMapper" ); + "org.apache.tools.ant.util.IdentityMapper" ); implementations.put( "flatten", - "org.apache.tools.ant.util.FlatFileNameMapper" ); + "org.apache.tools.ant.util.FlatFileNameMapper" ); implementations.put( "glob", - "org.apache.tools.ant.util.GlobPatternMapper" ); + "org.apache.tools.ant.util.GlobPatternMapper" ); implementations.put( "merge", - "org.apache.tools.ant.util.MergingMapper" ); + "org.apache.tools.ant.util.MergingMapper" ); implementations.put( "regexp", - "org.apache.tools.ant.util.RegexpPatternMapper" ); + "org.apache.tools.ant.util.RegexpPatternMapper" ); } public String getImplementation() diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/types/PatternSet.java b/proposal/myrmidon/src/main/org/apache/tools/ant/types/PatternSet.java index 015c78890..55558cbc6 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/types/PatternSet.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/types/PatternSet.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant.types; + import java.io.BufferedReader; import java.io.File; import java.io.FileReader; @@ -14,9 +15,8 @@ import java.util.Enumeration; import java.util.Stack; import java.util.StringTokenizer; import java.util.Vector; -import org.apache.tools.ant.BuildException; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.Project; -import org.apache.tools.ant.ProjectHelper; /** * Named collection of include/exclude tags.

@@ -50,6 +50,7 @@ public class PatternSet extends DataType * @param excludes the string containing the exclude patterns */ public void setExcludes( String excludes ) + throws TaskException { if( isReference() ) { @@ -69,10 +70,10 @@ public class PatternSet extends DataType * Sets the name of the file containing the excludes patterns. * * @param excludesFile The file to fetch the exclude patterns from. - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void setExcludesfile( File excludesFile ) - throws BuildException + throws TaskException { if( isReference() ) { @@ -88,6 +89,7 @@ public class PatternSet extends DataType * @param includes the string containing the include patterns */ public void setIncludes( String includes ) + throws TaskException { if( isReference() ) { @@ -107,10 +109,10 @@ public class PatternSet extends DataType * Sets the name of the file containing the includes patterns. * * @param includesFile The file to fetch the include patterns from. - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void setIncludesfile( File includesFile ) - throws BuildException + throws TaskException { if( isReference() ) { @@ -127,10 +129,10 @@ public class PatternSet extends DataType * if you make it a reference.

* * @param r The new Refid value - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void setRefid( Reference r ) - throws BuildException + throws TaskException { if( !includeList.isEmpty() || !excludeList.isEmpty() ) { @@ -146,6 +148,7 @@ public class PatternSet extends DataType * @return The ExcludePatterns value */ public String[] getExcludePatterns( Project p ) + throws TaskException { if( isReference() ) { @@ -165,6 +168,7 @@ public class PatternSet extends DataType * @return The IncludePatterns value */ public String[] getIncludePatterns( Project p ) + throws TaskException { if( isReference() ) { @@ -184,10 +188,11 @@ public class PatternSet extends DataType * @param p Description of Parameter */ public void append( PatternSet other, Project p ) + throws TaskException { if( isReference() ) { - throw new BuildException( "Cannot append to a reference" ); + throw new TaskException( "Cannot append to a reference" ); } String[] incl = other.getIncludePatterns( p ); @@ -195,7 +200,7 @@ public class PatternSet extends DataType { for( int i = 0; i < incl.length; i++ ) { - createInclude().setName( incl[i] ); + createInclude().setName( incl[ i ] ); } } @@ -204,7 +209,7 @@ public class PatternSet extends DataType { for( int i = 0; i < excl.length; i++ ) { - createExclude().setName( excl[i] ); + createExclude().setName( excl[ i ] ); } } } @@ -215,6 +220,7 @@ public class PatternSet extends DataType * @return Description of the Returned Value */ public NameEntry createExclude() + throws TaskException { if( isReference() ) { @@ -229,6 +235,7 @@ public class PatternSet extends DataType * @return Description of the Returned Value */ public NameEntry createExcludesFile() + throws TaskException { if( isReference() ) { @@ -243,6 +250,7 @@ public class PatternSet extends DataType * @return Description of the Returned Value */ public NameEntry createInclude() + throws TaskException { if( isReference() ) { @@ -257,6 +265,7 @@ public class PatternSet extends DataType * @return Description of the Returned Value */ public NameEntry createIncludesFile() + throws TaskException { if( isReference() ) { @@ -279,7 +288,7 @@ public class PatternSet extends DataType boolean hasPatterns() { return includesFileList.size() > 0 || excludesFileList.size() > 0 - || includeList.size() > 0 || excludeList.size() > 0; + || includeList.size() > 0 || excludeList.size() > 0; } /** @@ -290,6 +299,7 @@ public class PatternSet extends DataType * @return The Ref value */ private PatternSet getRef( Project p ) + throws TaskException { if( !checked ) { @@ -302,11 +312,11 @@ public class PatternSet extends DataType if( !( o instanceof PatternSet ) ) { String msg = ref.getRefId() + " doesn\'t denote a patternset"; - throw new BuildException( msg ); + throw new TaskException( msg ); } else { - return ( PatternSet )o; + return (PatternSet)o; } } @@ -336,9 +346,9 @@ public class PatternSet extends DataType return null; Vector tmpNames = new Vector(); - for( Enumeration e = list.elements(); e.hasMoreElements(); ) + for( Enumeration e = list.elements(); e.hasMoreElements(); ) { - NameEntry ne = ( NameEntry )e.nextElement(); + NameEntry ne = (NameEntry)e.nextElement(); String pattern = ne.evalName( p ); if( pattern != null && pattern.length() > 0 ) { @@ -346,7 +356,7 @@ public class PatternSet extends DataType } } - String result[] = new String[tmpNames.size()]; + String result[] = new String[ tmpNames.size() ]; tmpNames.copyInto( result ); return result; } @@ -357,21 +367,22 @@ public class PatternSet extends DataType * @param p Description of Parameter */ private void readFiles( Project p ) + throws TaskException { if( includesFileList.size() > 0 ) { Enumeration e = includesFileList.elements(); while( e.hasMoreElements() ) { - NameEntry ne = ( NameEntry )e.nextElement(); + NameEntry ne = (NameEntry)e.nextElement(); String fileName = ne.evalName( p ); if( fileName != null ) { File inclFile = resolveFile( fileName ); if( !inclFile.exists() ) - throw new BuildException( "Includesfile " - + inclFile.getAbsolutePath() - + " not found." ); + throw new TaskException( "Includesfile " + + inclFile.getAbsolutePath() + + " not found." ); readPatterns( inclFile, includeList, p ); } } @@ -383,15 +394,15 @@ public class PatternSet extends DataType Enumeration e = excludesFileList.elements(); while( e.hasMoreElements() ) { - NameEntry ne = ( NameEntry )e.nextElement(); + NameEntry ne = (NameEntry)e.nextElement(); String fileName = ne.evalName( p ); if( fileName != null ) { File exclFile = resolveFile( fileName ); if( !exclFile.exists() ) - throw new BuildException( "Excludesfile " - + exclFile.getAbsolutePath() - + " not found." ); + throw new TaskException( "Excludesfile " + + exclFile.getAbsolutePath() + + " not found." ); readPatterns( exclFile, excludeList, p ); } } @@ -406,10 +417,10 @@ public class PatternSet extends DataType * @param patternfile Description of Parameter * @param patternlist Description of Parameter * @param p Description of Parameter - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ private void readPatterns( File patternfile, Vector patternlist, Project p ) - throws BuildException + throws TaskException { BufferedReader patternReader = null; @@ -435,8 +446,8 @@ public class PatternSet extends DataType catch( IOException ioe ) { String msg = "An error occured while reading from pattern file: " - + patternfile; - throw new BuildException( msg, ioe ); + + patternfile; + throw new TaskException( msg, ioe ); } finally { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/AntClassLoader.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/AntClassLoader.java index e7a1ef558..6880707e9 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/AntClassLoader.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/AntClassLoader.java @@ -128,6 +128,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener * value of ${build.sysclasspath} */ public AntClassLoader( Project project, Path classpath ) + throws TaskException { parent = AntClassLoader.class.getClassLoader(); this.project = project; @@ -142,7 +143,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener { addPathElement( (String)pathElements[ i ] ); } - catch( BuildException e ) + catch( TaskException e ) { // ignore path elements which are invalid relative to the project } @@ -162,6 +163,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener */ public AntClassLoader( ClassLoader parent, Project project, Path classpath, boolean parentFirst ) + throws TaskException { this( project, classpath ); if( parent != null ) @@ -182,6 +184,7 @@ public class AntClassLoader extends ClassLoader implements BuildListener * be consulted before trying to load the a class through this loader. */ public AntClassLoader( Project project, Path classpath, boolean parentFirst ) + throws TaskException { this( null, project, classpath, parentFirst ); } @@ -411,10 +414,10 @@ public class AntClassLoader extends ClassLoader implements BuildListener * Add an element to the classpath to be searched * * @param pathElement The feature to be added to the PathElement attribute - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void addPathElement( String pathElement ) - throws BuildException + throws TaskException { File pathComponent = project != null ? FileUtils.newFileUtils().resolveFile( project.getBaseDir(), pathElement ) diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/Launcher.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/Launcher.java index 0a220ec89..da548157d 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/Launcher.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/Launcher.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant; + import java.io.File; import java.io.FilenameFilter; import java.lang.reflect.Method; @@ -13,6 +14,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Properties; import java.util.StringTokenizer; +import org.apache.myrmidon.api.TaskException; /** * This is the Ant command line front end to end. This front end works out where @@ -24,6 +26,7 @@ public class Launcher { public static void main( String[] args ) + throws TaskException { File antHome = null; ClassLoader systemClassLoader = Launcher.class.getClassLoader(); @@ -65,7 +68,7 @@ public class Launcher antLoader.initializeClass( mainClass ); final Class[] param = {Class.forName( "[Ljava.lang.String;" ), - Properties.class, ClassLoader.class}; + Properties.class, ClassLoader.class}; final Method startMethod = mainClass.getMethod( "start", param ); final Object[] argument = {args, launchProperties, systemClassLoader}; startMethod.invoke( null, argument ); @@ -78,6 +81,7 @@ public class Launcher } private static void addDirJars( AntClassLoader classLoader, File jarDir ) + throws TaskException { String[] fileList = jarDir.list( new FilenameFilter() @@ -92,7 +96,7 @@ public class Launcher { for( int i = 0; i < fileList.length; ++i ) { - File jarFile = new File( jarDir, fileList[i] ); + File jarFile = new File( jarDir, fileList[ i ] ); classLoader.addPathElement( jarFile.getAbsolutePath() ); } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/Main.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/Main.java index 3721f72dd..4e3dafae7 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/Main.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/Main.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -107,7 +108,7 @@ public class Main for( int i = 0; i < args.length; i++ ) { - String arg = args[i]; + String arg = args[ i ]; if( arg.equals( "-help" ) ) { @@ -137,7 +138,7 @@ public class Main { try { - File logFile = new File( args[i + 1] ); + File logFile = new File( args[ i + 1 ] ); i++; out = new PrintStream( new FileOutputStream( logFile ) ); err = out; @@ -163,7 +164,7 @@ public class Main { try { - buildFile = new File( args[i + 1] ); + buildFile = new File( args[ i + 1 ] ); i++; } catch( ArrayIndexOutOfBoundsException aioobe ) @@ -178,7 +179,7 @@ public class Main { try { - listeners.addElement( args[i + 1] ); + listeners.addElement( args[ i + 1 ] ); i++; } catch( ArrayIndexOutOfBoundsException aioobe ) @@ -212,7 +213,7 @@ public class Main name = name.substring( 0, posEq ); } else if( i < args.length - 1 ) - value = args[++i]; + value = args[ ++i ]; definedProps.put( name, value ); } @@ -225,12 +226,12 @@ public class Main } try { - loggerClassname = args[++i]; + loggerClassname = args[ ++i ]; } catch( ArrayIndexOutOfBoundsException aioobe ) { System.out.println( "You must specify a classname when " + - "using the -logger argument" ); + "using the -logger argument" ); return; } } @@ -248,7 +249,7 @@ public class Main // eat up next arg if present, default to build.xml if( i < args.length - 1 ) { - searchForThis = args[++i]; + searchForThis = args[ ++i ]; } else { @@ -278,7 +279,7 @@ public class Main if( searchForThis != null ) { buildFile = findBuildFile( System.getProperty( "user.dir" ), - searchForThis ); + searchForThis ); } else { @@ -329,7 +330,7 @@ public class Main catch( IOException ioe ) { throw new TaskException( "Could not load the version information:" - + ioe.getMessage() ); + + ioe.getMessage() ); } catch( NullPointerException npe ) { @@ -339,7 +340,6 @@ public class Main return antVersion; } - /** * Command line entry point. This method kicks off the building of a project * object and executes a build using either a given target or the default @@ -376,9 +376,9 @@ public class Main if( additionalUserProperties != null ) { - for( Enumeration e = additionalUserProperties.keys(); e.hasMoreElements(); ) + for( Enumeration e = additionalUserProperties.keys(); e.hasMoreElements(); ) { - String key = ( String )e.nextElement(); + String key = (String)e.nextElement(); String property = additionalUserProperties.getProperty( key ); m.definedProps.put( key, property ); } @@ -417,7 +417,7 @@ public class Main int res = names.size(); for( int i = 0; i < names.size() && res == names.size(); i++ ) { - if( name.compareTo( ( String )names.elementAt( i ) ) < 0 ) + if( name.compareTo( (String)names.elementAt( i ) ) < 0 ) { res = i; } @@ -474,7 +474,7 @@ public class Main while( ptargets.hasMoreElements() ) { - currentTarget = ( Target )ptargets.nextElement(); + currentTarget = (Target)ptargets.nextElement(); targetName = currentTarget.getName(); targetDescription = currentTarget.getDescription(); // maintain a sorted list of targets @@ -535,7 +535,7 @@ public class Main msg.append( names.elementAt( i ) ); if( descriptions != null ) { - msg.append( spaces.substring( 0, maxlen - ( ( String )names.elementAt( i ) ).length() + 2 ) ); + msg.append( spaces.substring( 0, maxlen - ( (String)names.elementAt( i ) ).length() + 2 ) ); msg.append( descriptions.elementAt( i ) ); } msg.append( lSep ); @@ -576,18 +576,18 @@ public class Main } protected void addBuildListeners( Project project ) + throws TaskException { - // Add the default listener project.addBuildListener( createLogger() ); for( int i = 0; i < listeners.size(); i++ ) { - String className = ( String )listeners.elementAt( i ); + String className = (String)listeners.elementAt( i ); try { BuildListener listener = - ( BuildListener )Class.forName( className ).newInstance(); + (BuildListener)Class.forName( className ).newInstance(); project.addBuildListener( listener ); } catch( Throwable exc ) @@ -631,18 +631,18 @@ public class Main { try { - logger = ( BuildLogger )( Class.forName( loggerClassname ).newInstance() ); + logger = (BuildLogger)( Class.forName( loggerClassname ).newInstance() ); } catch( ClassCastException e ) { System.err.println( "The specified logger class " + loggerClassname + - " does not implement the BuildLogger interface" ); + " does not implement the BuildLogger interface" ); throw new RuntimeException(); } catch( Exception e ) { System.err.println( "Unable to instantiate specified logger class " + - loggerClassname + " : " + e.getClass().getName() ); + loggerClassname + " : " + e.getClass().getName() ); throw new RuntimeException(); } } @@ -765,8 +765,8 @@ public class Main Enumeration e = definedProps.keys(); while( e.hasMoreElements() ) { - String arg = ( String )e.nextElement(); - String value = ( String )definedProps.get( arg ); + String arg = (String)e.nextElement(); + String value = (String)definedProps.get( arg ); project.setUserProperty( arg, value ); } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Definer.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Definer.java index 6bb9cacae..a2720e50b 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Definer.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Definer.java @@ -6,14 +6,15 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import java.util.Properties; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.AntClassLoader; -import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.Path; @@ -87,7 +88,7 @@ public abstract class Definer extends Task } public void execute() - throws BuildException + throws TaskException { AntClassLoader al = createLoader(); @@ -98,9 +99,9 @@ public abstract class Definer extends Task if( name == null || value == null ) { String msg = "name or classname attributes of " - + getTaskName() + " element " - + "are undefined"; - throw new BuildException( msg ); + + getTaskName() + " element " + + "are undefined"; + throw new TaskException( msg ); } addDefinition( al, name, value ); @@ -113,14 +114,14 @@ public abstract class Definer extends Task if( name != null || value != null ) { String msg = "You must not specify name or value " - + "together with file or resource."; - throw new BuildException( msg ); + + "together with file or resource."; + throw new TaskException( msg ); } if( file != null && resource != null ) { String msg = "You must not specify both, file and resource."; - throw new BuildException( msg ); + throw new TaskException( msg ); } Properties props = new Properties(); @@ -128,7 +129,7 @@ public abstract class Definer extends Task if( file != null ) { log( "Loading definitions from file " + file, - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); is = new FileInputStream( file ); if( is == null ) { @@ -139,13 +140,13 @@ public abstract class Definer extends Task if( resource != null ) { log( "Loading definitions from resource " + resource, - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); is = al.getResourceAsStream( resource ); if( is == null ) { log( "Could not load definitions from resource " + resource + ". It could not be found.", - Project.MSG_WARN ); + Project.MSG_WARN ); } } @@ -155,7 +156,7 @@ public abstract class Definer extends Task Enumeration keys = props.keys(); while( keys.hasMoreElements() ) { - String n = ( String )keys.nextElement(); + String n = (String)keys.nextElement(); String v = props.getProperty( n ); addDefinition( al, n, v ); } @@ -163,7 +164,7 @@ public abstract class Definer extends Task } catch( IOException ex ) { - throw new BuildException( "Error", ex); + throw new TaskException( "Error", ex ); } } } @@ -171,7 +172,7 @@ public abstract class Definer extends Task protected abstract void addDefinition( String name, Class c ); private void addDefinition( ClassLoader al, String name, String value ) - throws BuildException + throws TaskException { try { @@ -183,18 +184,18 @@ public abstract class Definer extends Task { String msg = getTaskName() + " class " + value + " cannot be found"; - throw new BuildException( msg, cnfe ); + throw new TaskException( msg, cnfe ); } catch( NoClassDefFoundError ncdfe ) { String msg = getTaskName() + " class " + value + " cannot be found"; - throw new BuildException( msg, ncdfe ); + throw new TaskException( msg, ncdfe ); } } - private AntClassLoader createLoader() + throws TaskException { AntClassLoader al = null; if( classpath != null ) diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Execute.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Execute.java index 42626602c..c9b0ddf72 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Execute.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Execute.java @@ -16,10 +16,12 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Locale; import java.util.Vector; +import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.framework.Os; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; -import org.apache.myrmidon.framework.Os; +import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.types.Commandline; /** @@ -428,7 +430,7 @@ public class Execute * @exception IOException Description of Exception */ public int execute() - throws IOException + throws IOException, TaskException { CommandLauncher launcher = vmLauncher != null ? vmLauncher : shellLauncher; if( !useVMLauncher ) @@ -547,7 +549,7 @@ public class Execute * @exception IOException Description of Exception */ public Process exec( Project project, String[] cmd, String[] env ) - throws IOException + throws IOException, TaskException { if( project != null ) { @@ -571,7 +573,7 @@ public class Execute * @exception IOException Description of Exception */ public Process exec( Project project, String[] cmd, String[] env, File workingDir ) - throws IOException + throws IOException, TaskException { if( workingDir == null ) { @@ -608,7 +610,7 @@ public class Execute * @exception IOException Description of Exception */ public Process exec( Project project, String[] cmd, String[] env ) - throws IOException + throws IOException, TaskException { return _launcher.exec( project, cmd, env ); } @@ -633,7 +635,7 @@ public class Execute * @exception IOException Description of Exception */ public Process exec( Project project, String[] cmd, String[] env ) - throws IOException + throws IOException, TaskException { // Need to quote arguments with spaces, and to escape quote characters String[] newcmd = new String[ cmd.length ]; @@ -741,7 +743,7 @@ public class Execute * @exception IOException Description of Exception */ public Process exec( Project project, String[] cmd, String[] env, File workingDir ) - throws IOException + throws IOException, TaskException { if( workingDir == null ) { @@ -768,7 +770,6 @@ public class Execute */ private static class PerlScriptCommandLauncher extends CommandLauncherProxy { - private String _script; PerlScriptCommandLauncher( String script, CommandLauncher launcher ) @@ -789,7 +790,7 @@ public class Execute * @exception IOException Description of Exception */ public Process exec( Project project, String[] cmd, String[] env, File workingDir ) - throws IOException + throws IOException, TaskException { if( project == null ) { @@ -806,7 +807,8 @@ public class Execute { throw new IOException( "Cannot locate antRun script: Property 'ant.home' not found" ); } - String antRun = resolveFile( antHome + File.separator + _script ).toString(); + String antRun = FileUtils.newFileUtils(). + resolveFile( project.getBaseDir(), antHome + File.separator + _script ).toString(); // Build the command File commandDir = workingDir; @@ -854,7 +856,7 @@ public class Execute * @exception IOException Description of Exception */ public Process exec( Project project, String[] cmd, String[] env, File workingDir ) - throws IOException + throws IOException, TaskException { if( project == null ) { @@ -871,7 +873,8 @@ public class Execute { throw new IOException( "Cannot locate antRun script: Property 'ant.home' not found" ); } - String antRun = resolveFile( antHome + File.separator + _script ).toString(); + String antRun = FileUtils.newFileUtils(). + resolveFile( project.getBaseDir(), antHome + File.separator + _script ).toString(); // Build the command File commandDir = workingDir; @@ -914,7 +917,7 @@ public class Execute * @exception IOException Description of Exception */ public Process exec( Project project, String[] cmd, String[] env, File workingDir ) - throws IOException + throws IOException, TaskException { File commandDir = workingDir; if( workingDir == null ) diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Property.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Property.java index 0c506bce8..6ec1b4fa7 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Property.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Property.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -13,6 +14,7 @@ import java.io.InputStream; import java.util.Enumeration; import java.util.Properties; import java.util.Vector; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; @@ -144,20 +146,20 @@ public class Property extends Task } public void execute() - throws BuildException + throws TaskException { if( name != null ) { if( value == null && ref == null ) { - throw new BuildException( "You must specify value, location or refid with the name attribute" ); + throw new TaskException( "You must specify value, location or refid with the name attribute" ); } } else { if( file == null && resource == null && env == null ) { - throw new BuildException( "You must specify file, resource or environment when not using the name attribute" ); + throw new TaskException( "You must specify file, resource or environment when not using the name attribute" ); } } @@ -196,8 +198,8 @@ public class Property extends Task Enumeration e = props.keys(); while( e.hasMoreElements() ) { - String name = ( String )e.nextElement(); - String value = ( String )props.getProperty( name ); + String name = (String)e.nextElement(); + String value = (String)props.getProperty( name ); String v = project.replaceProperties( value ); addProperty( name, v ); @@ -230,9 +232,9 @@ public class Property extends Task prefix += "."; log( "Loading Environment " + prefix, Project.MSG_VERBOSE ); Vector osEnv = Execute.getProcEnvironment(); - for( Enumeration e = osEnv.elements(); e.hasMoreElements(); ) + for( Enumeration e = osEnv.elements(); e.hasMoreElements(); ) { - String entry = ( String )e.nextElement(); + String entry = (String)e.nextElement(); int pos = entry.indexOf( '=' ); if( pos == -1 ) { @@ -241,14 +243,14 @@ public class Property extends Task else { props.put( prefix + entry.substring( 0, pos ), - entry.substring( pos + 1 ) ); + entry.substring( pos + 1 ) ); } } addProperties( props ); } protected void loadFile( File file ) - throws BuildException + throws TaskException { Properties props = new Properties(); log( "Loading " + file.getAbsolutePath(), Project.MSG_VERBOSE ); @@ -273,16 +275,17 @@ public class Property extends Task else { log( "Unable to find property file: " + file.getAbsolutePath(), - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); } } catch( IOException ex ) { - throw new BuildException( "Error", ex ); + throw new TaskException( "Error", ex ); } } protected void loadResource( String name ) + throws TaskException { Properties props = new Properties(); log( "Resource Loading " + name, Project.MSG_VERBOSE ); @@ -321,16 +324,16 @@ public class Property extends Task } catch( IOException ex ) { - throw new BuildException( "Error", ex ); + throw new TaskException( "Error", ex ); } } private void resolveAllProperties( Properties props ) - throws BuildException + throws TaskException { - for( Enumeration e = props.keys(); e.hasMoreElements(); ) + for( Enumeration e = props.keys(); e.hasMoreElements(); ) { - String name = ( String )e.nextElement(); + String name = (String)e.nextElement(); String value = props.getProperty( name ); boolean resolved = false; @@ -348,13 +351,13 @@ public class Property extends Task Enumeration j = propertyRefs.elements(); while( i.hasMoreElements() ) { - String fragment = ( String )i.nextElement(); + String fragment = (String)i.nextElement(); if( fragment == null ) { - String propertyName = ( String )j.nextElement(); + String propertyName = (String)j.nextElement(); if( propertyName.equals( name ) ) { - throw new BuildException( "Property " + name + " was circularly defined." ); + throw new TaskException( "Property " + name + " was circularly defined." ); } fragment = getProject().getProperty( propertyName ); if( fragment == null ) diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Rmic.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Rmic.java index 8ce94edeb..947e94329 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Rmic.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Rmic.java @@ -6,12 +6,13 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs; + import java.io.File; import java.io.IOException; import java.rmi.Remote; import java.util.Vector; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.AntClassLoader; -import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.rmic.RmicAdapter; @@ -19,8 +20,8 @@ import org.apache.tools.ant.taskdefs.rmic.RmicAdapterFactory; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; import org.apache.tools.ant.util.FileNameMapper; -import org.apache.tools.ant.util.SourceFileScanner; import org.apache.tools.ant.util.FileUtils; +import org.apache.tools.ant.util.SourceFileScanner; /** * Task to compile RMI stubs and skeletons. This task can take the following @@ -60,7 +61,7 @@ public class Rmic extends MatchingTask { private final static String FAIL_MSG - = "Rmic failed, messages should have been provided."; + = "Rmic failed, messages should have been provided."; private boolean verify = false; private boolean filtering = false; @@ -413,9 +414,9 @@ public class Rmic extends MatchingTask { for( int i = 0; i < interfaces.length; i++ ) { - if( Remote.class.isAssignableFrom( interfaces[i] ) ) + if( Remote.class.isAssignableFrom( interfaces[ i ] ) ) { - return interfaces[i]; + return interfaces[ i ]; } } } @@ -469,18 +470,18 @@ public class Rmic extends MatchingTask catch( ClassNotFoundException e ) { log( "Unable to verify class " + classname + - ". It could not be found.", Project.MSG_WARN ); + ". It could not be found.", Project.MSG_WARN ); } catch( NoClassDefFoundError e ) { log( "Unable to verify class " + classname + - ". It is not defined.", Project.MSG_WARN ); + ". It is not defined.", Project.MSG_WARN ); } catch( Throwable t ) { log( "Unable to verify class " + classname + - ". Loading caused Exception: " + - t.getMessage(), Project.MSG_WARN ); + ". Loading caused Exception: " + + t.getMessage(), Project.MSG_WARN ); } // we only get here if an exception has been thrown return false; @@ -515,15 +516,15 @@ public class Rmic extends MatchingTask } public void execute() - throws BuildException + throws TaskException { if( baseDir == null ) { - throw new BuildException( "base attribute must be set!" ); + throw new TaskException( "base attribute must be set!" ); } if( !baseDir.exists() ) { - throw new BuildException( "base does not exist!" ); + throw new TaskException( "base does not exist!" ); } if( verify ) @@ -552,21 +553,21 @@ public class Rmic extends MatchingTask { // otherwise perform a timestamp comparison - at least scanDir( baseDir, - new String[]{classname.replace( '.', File.separatorChar ) + ".class"}, - adapter.getMapper() ); + new String[]{classname.replace( '.', File.separatorChar ) + ".class"}, + adapter.getMapper() ); } int fileCount = compileList.size(); if( fileCount > 0 ) { log( "RMI Compiling " + fileCount + - " class" + ( fileCount > 1 ? "es" : "" ) + " to " + baseDir, - Project.MSG_INFO ); + " class" + ( fileCount > 1 ? "es" : "" ) + " to " + baseDir, + Project.MSG_INFO ); // finally, lets execute the compiler!! if( !adapter.execute() ) { - throw new BuildException( FAIL_MSG ); + throw new TaskException( FAIL_MSG ); } } @@ -580,7 +581,7 @@ public class Rmic extends MatchingTask if( idl ) { log( "Cannot determine sourcefiles in idl mode, ", - Project.MSG_WARN ); + Project.MSG_WARN ); log( "sourcebase attribute will be ignored.", Project.MSG_WARN ); } else @@ -588,8 +589,8 @@ public class Rmic extends MatchingTask for( int j = 0; j < fileCount; j++ ) { moveGeneratedFile( baseDir, sourceBase, - ( String )compileList.elementAt( j ), - adapter ); + (String)compileList.elementAt( j ), + adapter ); } } } @@ -612,13 +613,13 @@ public class Rmic extends MatchingTask if( idl ) { log( "will leave uptodate test to rmic implementation in idl mode.", - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); } else if( iiop - && iiopopts != null && iiopopts.indexOf( "-always" ) > -1 ) + && iiopopts != null && iiopopts.indexOf( "-always" ) > -1 ) { log( "no uptodate test as -always option has been specified", - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); } else { @@ -628,7 +629,7 @@ public class Rmic extends MatchingTask for( int i = 0; i < newFiles.length; i++ ) { - String classname = newFiles[i].replace( File.separatorChar, '.' ); + String classname = newFiles[ i ].replace( File.separatorChar, '.' ); classname = classname.substring( 0, classname.lastIndexOf( ".class" ) ); compileList.addElement( classname ); } @@ -652,12 +653,12 @@ public class Rmic extends MatchingTask * @param sourceBaseFile Description of Parameter * @param classname Description of Parameter * @param adapter Description of Parameter - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ private void moveGeneratedFile( File baseDir, File sourceBaseFile, String classname, RmicAdapter adapter ) - throws BuildException + throws TaskException { String classFileName = @@ -680,7 +681,8 @@ public class Rmic extends MatchingTask { String msg = "Failed to copy " + oldFile + " to " + newFile + " due to " + ioe.getMessage(); - throw new BuildException( msg, ioe ); + newFile + " due to " + ioe.getMessage(); + throw new TaskException( msg, ioe ); } } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/SQLExec.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/SQLExec.java index a242c5489..87c397bc2 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/SQLExec.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/SQLExec.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs; + import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; @@ -30,15 +31,14 @@ import java.util.Properties; import java.util.StringTokenizer; import java.util.Vector; import org.apache.tools.ant.AntClassLoader; -import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; -import org.apache.tools.ant.ProjectHelper; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; +import org.apache.myrmidon.api.TaskException; /** * Reads in a text file containing SQL statements seperated with semicolons and @@ -258,7 +258,6 @@ public class SQLExec extends Task this.output = output; } - /** * Set the password for the DB connection. * @@ -373,7 +372,6 @@ public class SQLExec extends Task return this.classpath.createPath(); } - /** * Set the sql command to execute * @@ -389,10 +387,10 @@ public class SQLExec extends Task /** * Load the sql file and then execute it * - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void execute() - throws BuildException + throws TaskException { sqlCommand = sqlCommand.trim(); @@ -400,7 +398,7 @@ public class SQLExec extends Task { if( transactions.size() == 0 ) { - throw new BuildException( "Source file or fileset, transactions or sql statement must be set!" ); + throw new TaskException( "Source file or fileset, transactions or sql statement must be set!" ); } } else @@ -408,7 +406,7 @@ public class SQLExec extends Task // deal with the filesets for( int i = 0; i < filesets.size(); i++ ) { - FileSet fs = ( FileSet )filesets.elementAt( i ); + FileSet fs = (FileSet)filesets.elementAt( i ); DirectoryScanner ds = fs.getDirectoryScanner( project ); File srcDir = fs.getDir( project ); @@ -418,7 +416,7 @@ public class SQLExec extends Task for( int j = 0; j < srcFiles.length; j++ ) { Transaction t = createTransaction(); - t.setSrc( new File( srcDir, srcFiles[j] ) ); + t.setSrc( new File( srcDir, srcFiles[ j ] ) ); } } @@ -430,23 +428,23 @@ public class SQLExec extends Task if( driver == null ) { - throw new BuildException( "Driver attribute must be set!" ); + throw new TaskException( "Driver attribute must be set!" ); } if( userId == null ) { - throw new BuildException( "User Id attribute must be set!" ); + throw new TaskException( "User Id attribute must be set!" ); } if( password == null ) { - throw new BuildException( "Password attribute must be set!" ); + throw new TaskException( "Password attribute must be set!" ); } if( url == null ) { - throw new BuildException( "Url attribute must be set!" ); + throw new TaskException( "Url attribute must be set!" ); } if( srcFile != null && !srcFile.exists() ) { - throw new BuildException( "Source file does not exist!" ); + throw new TaskException( "Source file does not exist!" ); } Driver driverInstance = null; // Load the driver using the @@ -456,7 +454,7 @@ public class SQLExec extends Task if( classpath != null ) { log( "Loading " + driver + " using AntClassLoader with classpath " + classpath, - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); loader = new AntClassLoader( project, classpath ); dc = loader.loadClass( driver ); @@ -466,19 +464,19 @@ public class SQLExec extends Task log( "Loading " + driver + " using system loader.", Project.MSG_VERBOSE ); dc = Class.forName( driver ); } - driverInstance = ( Driver )dc.newInstance(); + driverInstance = (Driver)dc.newInstance(); } catch( ClassNotFoundException e ) { - throw new BuildException( "Class Not Found: JDBC driver " + driver + " could not be loaded" ); + throw new TaskException( "Class Not Found: JDBC driver " + driver + " could not be loaded" ); } catch( IllegalAccessException e ) { - throw new BuildException( "Illegal Access: JDBC driver " + driver + " could not be loaded" ); + throw new TaskException( "Illegal Access: JDBC driver " + driver + " could not be loaded" ); } catch( InstantiationException e ) { - throw new BuildException( "Instantiation Exception: JDBC driver " + driver + " could not be loaded" ); + throw new TaskException( "Instantiation Exception: JDBC driver " + driver + " could not be loaded" ); } try @@ -513,10 +511,10 @@ public class SQLExec extends Task // Process all transactions for( Enumeration e = transactions.elements(); - e.hasMoreElements(); ) + e.hasMoreElements(); ) { - ( ( Transaction )e.nextElement() ).runTransaction( out ); + ( (Transaction)e.nextElement() ).runTransaction( out ); if( !autocommit ) { log( "Commiting transaction", Project.MSG_VERBOSE ); @@ -541,9 +539,10 @@ public class SQLExec extends Task conn.rollback(); } catch( SQLException ex ) - {} + { + } } - throw new BuildException( "Error", e ); + throw new TaskException( "Error", e ); } catch( SQLException e ) { @@ -554,9 +553,10 @@ public class SQLExec extends Task conn.rollback(); } catch( SQLException ex ) - {} + { + } } - throw new BuildException( "Error", e ); + throw new TaskException( "Error", e ); } finally { @@ -572,11 +572,12 @@ public class SQLExec extends Task } } catch( SQLException e ) - {} + { + } } log( goodSql + " of " + totalSql + - " SQL statements executed successfully" ); + " SQL statements executed successfully" ); } /** @@ -650,7 +651,7 @@ public class SQLExec extends Task if( !statement.execute( sql ) ) { log( statement.getUpdateCount() + " rows affected", - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); } else { @@ -733,7 +734,7 @@ public class SQLExec extends Task line.setLength( 0 ); } } - }while ( statement.getMoreResults() ); + } while( statement.getMoreResults() ); out.println(); } @@ -855,9 +856,9 @@ public class SQLExec extends Task if( tSrcFile != null ) { log( "Executing file: " + tSrcFile.getAbsolutePath(), - Project.MSG_INFO ); + Project.MSG_INFO ); Reader reader = ( encoding == null ) ? new FileReader( tSrcFile ) - : new InputStreamReader( new FileInputStream( tSrcFile ), encoding ); + : new InputStreamReader( new FileInputStream( tSrcFile ), encoding ); runStatements( reader, out ); reader.close(); } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java index 02abefc30..e2f8835b3 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs.optional; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -17,8 +18,8 @@ import java.net.URL; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.AntClassLoader; -import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; @@ -73,7 +74,7 @@ public class XMLValidateTask extends Task */ protected XMLReader xmlReader = null;// XMLReader used to validation process protected ValidatorErrorHandler errorHandler - = new ValidatorErrorHandler();// to report sax parsing errors + = new ValidatorErrorHandler();// to report sax parsing errors protected Hashtable features = new Hashtable(); /** @@ -102,7 +103,6 @@ public class XMLValidateTask extends Task readerClassName = className; } - /** * Specify the classpath to be searched to load the parser (optional) * @@ -133,7 +133,7 @@ public class XMLValidateTask extends Task /** * Specify how parser error are to be handled.

* - * If set to true (default), throw a buildException if the + * If set to true (default), throw a TaskException if the * parser yields an error. * * @param fail The new FailOnError value @@ -226,13 +226,13 @@ public class XMLValidateTask extends Task } public void execute() - throws BuildException + throws TaskException { int fileProcessed = 0; if( file == null && ( filesets.size() == 0 ) ) { - throw new BuildException( "Specify at least one source - a file or a fileset." ); + throw new TaskException( "Specify at least one source - a file or a fileset." ); } initValidator(); @@ -248,7 +248,7 @@ public class XMLValidateTask extends Task { String errorMsg = "File " + file + " cannot be read"; if( failOnError ) - throw new BuildException( errorMsg ); + throw new TaskException( errorMsg ); else log( errorMsg, Project.MSG_ERR ); } @@ -257,13 +257,13 @@ public class XMLValidateTask extends Task for( int i = 0; i < filesets.size(); i++ ) { - FileSet fs = ( FileSet )filesets.elementAt( i ); + FileSet fs = (FileSet)filesets.elementAt( i ); DirectoryScanner ds = fs.getDirectoryScanner( project ); String[] files = ds.getIncludedFiles(); for( int j = 0; j < files.length; j++ ) { - File srcFile = new File( fs.getDir( project ), files[j] ); + File srcFile = new File( fs.getDir( project ), files[ j ] ); doValidate( srcFile ); fileProcessed++; } @@ -275,9 +275,9 @@ public class XMLValidateTask extends Task { LocalResolver resolver = new LocalResolver(); - for( Enumeration i = dtdLocations.elements(); i.hasMoreElements(); ) + for( Enumeration i = dtdLocations.elements(); i.hasMoreElements(); ) { - DTDLocation location = ( DTDLocation )i.nextElement(); + DTDLocation location = (DTDLocation)i.nextElement(); resolver.registerDTD( location ); } return resolver; @@ -302,7 +302,7 @@ public class XMLValidateTask extends Task log( "Could not set feature '" + feature + "' because the parser doesn't recognize it", - Project.MSG_WARN ); + Project.MSG_WARN ); } catch( SAXNotSupportedException e ) { @@ -310,7 +310,7 @@ public class XMLValidateTask extends Task log( "Could not set feature '" + feature + "' because the parser doesn't support it", - Project.MSG_WARN ); + Project.MSG_WARN ); } return toReturn; } @@ -327,7 +327,7 @@ public class XMLValidateTask extends Task InputSource is = new InputSource( new FileReader( afile ) ); String uri = "file:" + afile.getAbsolutePath().replace( '\\', '/' ); for( int index = uri.indexOf( '#' ); index != -1; - index = uri.indexOf( '#' ) ) + index = uri.indexOf( '#' ) ) { uri = uri.substring( 0, index ) + "%23" + uri.substring( index + 1 ); } @@ -337,17 +337,17 @@ public class XMLValidateTask extends Task catch( SAXException ex ) { if( failOnError ) - throw new BuildException( "Could not validate document " + afile ); + throw new TaskException( "Could not validate document " + afile ); } catch( IOException ex ) { - throw new BuildException( "Could not validate document " + afile, ex ); + throw new TaskException( "Could not validate document " + afile, ex ); } if( errorHandler.getFailure() ) { if( failOnError ) - throw new BuildException( afile + " is not a valid XML document." ); + throw new TaskException( afile + " is not a valid XML document." ); else log( afile + " is not a valid XML document", Project.MSG_ERR ); } @@ -357,6 +357,7 @@ public class XMLValidateTask extends Task * init the parser : load the parser class, and set features if necessary */ private void initValidator() + throws TaskException { try @@ -369,7 +370,7 @@ public class XMLValidateTask extends Task if( classpath != null ) { AntClassLoader loader = new AntClassLoader( project, classpath ); -// loader.addSystemPackageRoot("org.xml"); // needed to avoid conflict + // loader.addSystemPackageRoot("org.xml"); // needed to avoid conflict readerClass = loader.loadClass( readerClassName ); AntClassLoader.initializeClass( readerClass ); } @@ -380,7 +381,7 @@ public class XMLValidateTask extends Task if( XMLReader.class.isAssignableFrom( readerClass ) ) { - xmlReader = ( XMLReader )readerClass.newInstance(); + xmlReader = (XMLReader)readerClass.newInstance(); log( "Using SAX2 reader " + readerClassName, Project.MSG_VERBOSE ); } else @@ -389,29 +390,29 @@ public class XMLValidateTask extends Task // see if it is a SAX1 Parser if( Parser.class.isAssignableFrom( readerClass ) ) { - Parser parser = ( Parser )readerClass.newInstance(); + Parser parser = (Parser)readerClass.newInstance(); xmlReader = new ParserAdapter( parser ); log( "Using SAX1 parser " + readerClassName, Project.MSG_VERBOSE ); } else { - throw new BuildException( INIT_FAILED_MSG - + readerClassName - + " implements nor SAX1 Parser nor SAX2 XMLReader." ); + throw new TaskException( INIT_FAILED_MSG + + readerClassName + + " implements nor SAX1 Parser nor SAX2 XMLReader." ); } } } catch( ClassNotFoundException e ) { - throw new BuildException( INIT_FAILED_MSG + readerClassName, e ); + throw new TaskException( INIT_FAILED_MSG + readerClassName, e ); } catch( InstantiationException e ) { - throw new BuildException( INIT_FAILED_MSG + readerClassName, e ); + throw new TaskException( INIT_FAILED_MSG + readerClassName, e ); } catch( IllegalAccessException e ) { - throw new BuildException( INIT_FAILED_MSG + readerClassName, e ); + throw new TaskException( INIT_FAILED_MSG + readerClassName, e ); } xmlReader.setEntityResolver( getEntityResolver() ); @@ -425,17 +426,17 @@ public class XMLValidateTask extends Task boolean ok = setFeature( "http://xml.org/sax/features/validation", true, true ); if( !ok ) { - throw new BuildException( INIT_FAILED_MSG - + readerClassName - + " doesn't provide validation" ); + throw new TaskException( INIT_FAILED_MSG + + readerClassName + + " doesn't provide validation" ); } } // set other features Enumeration enum = features.keys(); while( enum.hasMoreElements() ) { - String featureId = ( String )enum.nextElement(); - setFeature( featureId, ( ( Boolean )features.get( featureId ) ).booleanValue(), true ); + String featureId = (String)enum.nextElement(); + setFeature( featureId, ( (Boolean)features.get( featureId ) ).booleanValue(), true ); } } } @@ -542,13 +543,15 @@ public class XMLValidateTask extends Task } private class LocalResolver - implements EntityResolver + implements EntityResolver { private Hashtable fileDTDs = new Hashtable(); private Hashtable resourceDTDs = new Hashtable(); private Hashtable urlDTDs = new Hashtable(); - public LocalResolver() { } + public LocalResolver() + { + } public void registerDTD( String publicId, String location ) { @@ -599,7 +602,7 @@ public class XMLValidateTask extends Task public InputSource resolveEntity( String publicId, String systemId ) throws SAXException { - File dtdFile = ( File )fileDTDs.get( publicId ); + File dtdFile = (File)fileDTDs.get( publicId ); if( dtdFile != null ) { try @@ -613,7 +616,7 @@ public class XMLValidateTask extends Task } } - String dtdResourceName = ( String )resourceDTDs.get( publicId ); + String dtdResourceName = (String)resourceDTDs.get( publicId ); if( dtdResourceName != null ) { InputStream is = this.getClass().getResourceAsStream( dtdResourceName ); @@ -624,7 +627,7 @@ public class XMLValidateTask extends Task } } - URL dtdUrl = ( URL )urlDTDs.get( publicId ); + URL dtdUrl = (URL)urlDTDs.get( publicId ); if( dtdUrl != null ) { try @@ -640,7 +643,7 @@ public class XMLValidateTask extends Task } log( "Could not resolve ( publicId: " + publicId + ", systemId: " + systemId + ") to a local entity", - Project.MSG_INFO ); + Project.MSG_INFO ); return null; } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/depend/Depend.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/depend/Depend.java index 01196c9b7..80632df63 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/depend/Depend.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/depend/Depend.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs.optional.depend; + import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -17,15 +18,14 @@ import java.net.URL; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.AntClassLoader; -import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.MatchingTask; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; - /** * Generate a dependency file for a given set of classes * @@ -152,7 +152,6 @@ public class Depend extends MatchingTask this.dump = dump; } - /** * Set the source dirs to find the source Java files. * @@ -190,10 +189,10 @@ public class Depend extends MatchingTask /** * Does the work. * - * @exception BuildException Thrown in unrecovrable error. + * @exception TaskException Thrown in unrecovrable error. */ public void execute() - throws BuildException + throws TaskException { try { @@ -201,7 +200,7 @@ public class Depend extends MatchingTask String[] srcPathList = srcPath.list(); if( srcPathList.length == 0 ) { - throw new BuildException( "srcdir attribute must be set!" ); + throw new TaskException( "srcdir attribute must be set!" ); } if( destPath == null ) @@ -211,7 +210,7 @@ public class Depend extends MatchingTask if( cache != null && cache.exists() && !cache.isDirectory() ) { - throw new BuildException( "The cache, if specified, must point to a directory" ); + throw new TaskException( "The cache, if specified, must point to a directory" ); } if( cache != null && !cache.exists() ) @@ -224,16 +223,16 @@ public class Depend extends MatchingTask if( dump ) { log( "Reverse Dependency Dump for " + affectedClassMap.size() + - " classes:", Project.MSG_DEBUG ); - for( Enumeration e = affectedClassMap.keys(); e.hasMoreElements(); ) + " classes:", Project.MSG_DEBUG ); + for( Enumeration e = affectedClassMap.keys(); e.hasMoreElements(); ) { - String className = ( String )e.nextElement(); + String className = (String)e.nextElement(); log( " Class " + className + " affects:", Project.MSG_DEBUG ); - Hashtable affectedClasses = ( Hashtable )affectedClassMap.get( className ); - for( Enumeration e2 = affectedClasses.keys(); e2.hasMoreElements(); ) + Hashtable affectedClasses = (Hashtable)affectedClassMap.get( className ); + for( Enumeration e2 = affectedClasses.keys(); e2.hasMoreElements(); ) { - String affectedClass = ( String )e2.nextElement(); - ClassFileInfo info = ( ClassFileInfo )affectedClasses.get( affectedClass ); + String affectedClass = (String)e2.nextElement(); + ClassFileInfo info = (ClassFileInfo)affectedClasses.get( affectedClass ); log( " " + affectedClass + " in " + info.absoluteFile.getPath(), Project.MSG_DEBUG ); } } @@ -241,14 +240,14 @@ public class Depend extends MatchingTask if( classpathDependencies != null ) { log( "Classpath file dependencies (Forward):", Project.MSG_DEBUG ); - for( Enumeration e = classpathDependencies.keys(); e.hasMoreElements(); ) + for( Enumeration e = classpathDependencies.keys(); e.hasMoreElements(); ) { - String className = ( String )e.nextElement(); + String className = (String)e.nextElement(); log( " Class " + className + " depends on:", Project.MSG_DEBUG ); - Hashtable dependencies = ( Hashtable )classpathDependencies.get( className ); - for( Enumeration e2 = dependencies.elements(); e2.hasMoreElements(); ) + Hashtable dependencies = (Hashtable)classpathDependencies.get( className ); + for( Enumeration e2 = dependencies.elements(); e2.hasMoreElements(); ) { - File classpathFile = ( File )e2.nextElement(); + File classpathFile = (File)e2.nextElement(); log( " " + classpathFile.getPath(), Project.MSG_DEBUG ); } } @@ -261,7 +260,7 @@ public class Depend extends MatchingTask outOfDateClasses = new Hashtable(); for( int i = 0; i < srcPathList.length; i++ ) { - File srcDir = ( File )resolveFile( srcPathList[i] ); + File srcDir = (File)resolveFile( srcPathList[ i ] ); if( srcDir.exists() ) { DirectoryScanner ds = this.getDirectoryScanner( srcDir ); @@ -273,25 +272,25 @@ public class Depend extends MatchingTask // now check classpath file dependencies if( classpathDependencies != null ) { - for( Enumeration e = classpathDependencies.keys(); e.hasMoreElements(); ) + for( Enumeration e = classpathDependencies.keys(); e.hasMoreElements(); ) { - String className = ( String )e.nextElement(); + String className = (String)e.nextElement(); if( !outOfDateClasses.containsKey( className ) ) { - ClassFileInfo info = ( ClassFileInfo )classFileInfoMap.get( className ); + ClassFileInfo info = (ClassFileInfo)classFileInfoMap.get( className ); // if we have no info about the class - it may have been deleted already and we // are using cached info. if( info != null ) { - Hashtable dependencies = ( Hashtable )classpathDependencies.get( className ); - for( Enumeration e2 = dependencies.elements(); e2.hasMoreElements(); ) + Hashtable dependencies = (Hashtable)classpathDependencies.get( className ); + for( Enumeration e2 = dependencies.elements(); e2.hasMoreElements(); ) { - File classpathFile = ( File )e2.nextElement(); + File classpathFile = (File)e2.nextElement(); if( classpathFile.lastModified() > info.absoluteFile.lastModified() ) { log( "Class " + className + - " is out of date with respect to " + classpathFile, Project.MSG_DEBUG ); + " is out of date with respect to " + classpathFile, Project.MSG_DEBUG ); outOfDateClasses.put( className, className ); break; } @@ -310,7 +309,7 @@ public class Depend extends MatchingTask } catch( Exception e ) { - throw new BuildException( "Error", e ); + throw new TaskException( "Error", e ); } } @@ -328,14 +327,14 @@ public class Depend extends MatchingTask for( int i = 0; i < files.length; i++ ) { - File srcFile = new File( srcDir, files[i] ); - if( files[i].endsWith( ".java" ) ) + File srcFile = new File( srcDir, files[ i ] ); + if( files[ i ].endsWith( ".java" ) ) { String filePath = srcFile.getPath(); String className = filePath.substring( srcDir.getPath().length() + 1, - filePath.length() - ".java".length() ); + filePath.length() - ".java".length() ); className = ClassFileUtils.convertSlashName( className ); - ClassFileInfo info = ( ClassFileInfo )classFileInfoMap.get( className ); + ClassFileInfo info = (ClassFileInfo)classFileInfoMap.get( className ); if( info == null ) { // there was no class file. add this class to the list @@ -352,7 +351,6 @@ public class Depend extends MatchingTask } } - /** * Get the list of class files we are going to analyse. * @@ -369,7 +367,7 @@ public class Depend extends MatchingTask for( int i = 0; i < classLocationsList.length; ++i ) { - File dir = new File( classLocationsList[i] ); + File dir = new File( classLocationsList[ i ] ); if( dir.isDirectory() ) { addClassFiles( classFileList, dir, dir ); @@ -397,7 +395,7 @@ public class Depend extends MatchingTask for( int i = 0; i < length; ++i ) { - File file = new File( dir, filesInDir[i] ); + File file = new File( dir, filesInDir[ i ] ); if( file.isDirectory() ) { addClassFiles( classFileList, file, root ); @@ -407,7 +405,7 @@ public class Depend extends MatchingTask ClassFileInfo info = new ClassFileInfo(); info.absoluteFile = file; info.relativeName = file.getPath().substring( root.getPath().length() + 1, - file.getPath().length() - 6 ); + file.getPath().length() - 6 ); info.className = ClassFileUtils.convertSlashName( info.relativeName ); classFileList.addElement( info ); } @@ -419,17 +417,17 @@ public class Depend extends MatchingTask { int count = 0; - Hashtable affectedClasses = ( Hashtable )affectedClassMap.get( className ); + Hashtable affectedClasses = (Hashtable)affectedClassMap.get( className ); if( affectedClasses != null ) { - for( Enumeration e = affectedClasses.keys(); e.hasMoreElements(); ) + for( Enumeration e = affectedClasses.keys(); e.hasMoreElements(); ) { - String affectedClassName = ( String )e.nextElement(); - ClassFileInfo affectedClassInfo = ( ClassFileInfo )affectedClasses.get( affectedClassName ); + String affectedClassName = (String)e.nextElement(); + ClassFileInfo affectedClassInfo = (ClassFileInfo)affectedClasses.get( affectedClassName ); if( affectedClassInfo.absoluteFile.exists() ) { log( "Deleting file " + affectedClassInfo.absoluteFile.getPath() + " since " + - className + " out of date", Project.MSG_VERBOSE ); + className + " out of date", Project.MSG_VERBOSE ); affectedClassInfo.absoluteFile.delete(); count++; if( closure ) @@ -445,15 +443,15 @@ public class Depend extends MatchingTask { // need to delete the main class String topLevelClassName - = affectedClassName.substring( 0, affectedClassName.indexOf( "$" ) ); + = affectedClassName.substring( 0, affectedClassName.indexOf( "$" ) ); log( "Top level class = " + topLevelClassName, Project.MSG_VERBOSE ); ClassFileInfo topLevelClassInfo - = ( ClassFileInfo )classFileInfoMap.get( topLevelClassName ); + = (ClassFileInfo)classFileInfoMap.get( topLevelClassName ); if( topLevelClassInfo != null && topLevelClassInfo.absoluteFile.exists() ) { log( "Deleting file " + topLevelClassInfo.absoluteFile.getPath() + " since " + - "one of its inner classes was removed", Project.MSG_VERBOSE ); + "one of its inner classes was removed", Project.MSG_VERBOSE ); topLevelClassInfo.absoluteFile.delete(); count++; if( closure ) @@ -472,11 +470,11 @@ public class Depend extends MatchingTask private int deleteAllAffectedFiles() { int count = 0; - for( Enumeration e = outOfDateClasses.elements(); e.hasMoreElements(); ) + for( Enumeration e = outOfDateClasses.elements(); e.hasMoreElements(); ) { - String className = ( String )e.nextElement(); + String className = (String)e.nextElement(); count += deleteAffectedFiles( className ); - ClassFileInfo classInfo = ( ClassFileInfo )classFileInfoMap.get( className ); + ClassFileInfo classInfo = (ClassFileInfo)classFileInfoMap.get( className ); if( classInfo != null && classInfo.absoluteFile.exists() ) { classInfo.absoluteFile.delete(); @@ -486,7 +484,6 @@ public class Depend extends MatchingTask return count; } - /** * Determine the dependencies between classes. Class dependencies are * determined by examining the class references in a class file to other @@ -495,7 +492,7 @@ public class Depend extends MatchingTask * @exception IOException Description of Exception */ private void determineDependencies() - throws IOException + throws IOException, TaskException { affectedClassMap = new Hashtable(); classFileInfoMap = new Hashtable(); @@ -514,9 +511,9 @@ public class Depend extends MatchingTask depCacheFileExists = depCacheFile.exists(); depCacheFileLastModified = depCacheFile.lastModified(); } - for( Enumeration e = getClassFiles( destPath ).elements(); e.hasMoreElements(); ) + for( Enumeration e = getClassFiles( destPath ).elements(); e.hasMoreElements(); ) { - ClassFileInfo info = ( ClassFileInfo )e.nextElement(); + ClassFileInfo info = (ClassFileInfo)e.nextElement(); log( "Adding class info for " + info.className, Project.MSG_DEBUG ); classFileInfoMap.put( info.className, info ); @@ -529,7 +526,7 @@ public class Depend extends MatchingTask { // depFile exists and is newer than the class file // need to get dependency list from the map. - dependencyList = ( Vector )dependencyMap.get( info.className ); + dependencyList = (Vector)dependencyMap.get( info.className ); } } @@ -562,11 +559,11 @@ public class Depend extends MatchingTask // This class depends on each class in the dependency list. For each // one of those, add this class into their affected classes list - for( Enumeration depEnum = dependencyList.elements(); depEnum.hasMoreElements(); ) + for( Enumeration depEnum = dependencyList.elements(); depEnum.hasMoreElements(); ) { - String dependentClass = ( String )depEnum.nextElement(); + String dependentClass = (String)depEnum.nextElement(); - Hashtable affectedClasses = ( Hashtable )affectedClassMap.get( dependentClass ); + Hashtable affectedClasses = (Hashtable)affectedClassMap.get( dependentClass ); if( affectedClasses == null ) { affectedClasses = new Hashtable(); @@ -586,15 +583,15 @@ public class Depend extends MatchingTask Hashtable classpathFileCache = new Hashtable(); Object nullFileMarker = new Object(); - for( Enumeration e = dependencyMap.keys(); e.hasMoreElements(); ) + for( Enumeration e = dependencyMap.keys(); e.hasMoreElements(); ) { - String className = ( String )e.nextElement(); - Vector dependencyList = ( Vector )dependencyMap.get( className ); + String className = (String)e.nextElement(); + Vector dependencyList = (Vector)dependencyMap.get( className ); Hashtable dependencies = new Hashtable(); classpathDependencies.put( className, dependencies ); - for( Enumeration e2 = dependencyList.elements(); e2.hasMoreElements(); ) + for( Enumeration e2 = dependencyList.elements(); e2.hasMoreElements(); ) { - String dependency = ( String )e2.nextElement(); + String dependency = (String)e2.nextElement(); Object classpathFileObject = classpathFileCache.get( dependency ); if( classpathFileObject == null ) { @@ -621,8 +618,8 @@ public class Depend extends MatchingTask classpathFileObject = new File( classFilePath ); } log( "Class " + className + - " depends on " + classpathFileObject + - " due to " + dependency, Project.MSG_DEBUG ); + " depends on " + classpathFileObject + + " due to " + dependency, Project.MSG_DEBUG ); } } classpathFileCache.put( dependency, classpathFileObject ); @@ -630,7 +627,7 @@ public class Depend extends MatchingTask if( classpathFileObject != null && classpathFileObject != nullFileMarker ) { // we need to add this jar to the list for this class. - File jarFile = ( File )classpathFileObject; + File jarFile = (File)classpathFileObject; dependencies.put( jarFile, jarFile ); } } @@ -713,13 +710,13 @@ public class Depend extends MatchingTask File depFile = new File( cache, CACHE_FILE_NAME ); pw = new PrintWriter( new FileWriter( depFile ) ); - for( Enumeration deps = dependencyMap.keys(); deps.hasMoreElements(); ) + for( Enumeration deps = dependencyMap.keys(); deps.hasMoreElements(); ) { - String className = ( String )deps.nextElement(); + String className = (String)deps.nextElement(); pw.println( CLASSNAME_PREPEND + className ); - Vector dependencyList = ( Vector )dependencyMap.get( className ); + Vector dependencyList = (Vector)dependencyMap.get( className ); int size = dependencyList.size(); for( int x = 0; x < size; x++ ) { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java index 6343dbbb2..e152ef97e 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs.optional.ejb; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -24,14 +25,13 @@ import java.util.zip.ZipEntry; import javax.xml.parsers.SAXParser; import org.apache.bcel.*; import org.apache.bcel.classfile.*; -import org.apache.tools.ant.*; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Location; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.*; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.util.depend.Dependencies; @@ -39,7 +39,6 @@ import org.apache.tools.ant.util.depend.Filter; import org.xml.sax.InputSource; import org.xml.sax.SAXException; - /** * A deployment tool which creates generic EJB jars. Generic jars contains only * those classes and META-INF entries specified in the EJB 1.1 standard This @@ -133,7 +132,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool this.genericJarSuffix = inString; } - /** * Set the task which owns this tool * @@ -178,7 +176,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool return ddPrefix; } - /** * Configure this tool for use in the ejbjar task. * @@ -227,7 +224,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool // First the regular deployment descriptor ejbFiles.put( META_DIR + EJB_DD, - new File( config.descriptorDir, descriptorFileName ) ); + new File( config.descriptorDir, descriptorFileName ) ); // now the vendor specific files, if any addVendorFiles( ejbFiles, ddPrefix ); @@ -260,7 +257,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool + " with " + String.valueOf( ejbFiles.size() ) + " files", - Project.MSG_INFO ); + Project.MSG_INFO ); // Use helper method to write the jarfile String publicId = getPublicId(); @@ -271,26 +268,26 @@ public class GenericDeploymentTool implements EJBDeploymentTool { // Log that the file is up to date... log( jarFile.toString() + " is up to date.", - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); } } catch( SAXException se ) { String msg = "SAXException while parsing '" - + descriptorFileName.toString() - + "'. This probably indicates badly-formed XML." - + " Details: " - + se.getMessage(); + + descriptorFileName.toString() + + "'. This probably indicates badly-formed XML." + + " Details: " + + se.getMessage(); throw new BuildException( msg, se ); } catch( IOException ioe ) { String msg = "IOException while parsing'" - + descriptorFileName.toString() - + "'. This probably indicates that the descriptor" - + " doesn't exist. Details: " - + ioe.getMessage(); + + descriptorFileName.toString() + + "'. This probably indicates that the descriptor" + + " doesn't exist. Details: " + + ioe.getMessage(); throw new BuildException( msg, ioe ); } } @@ -306,12 +303,11 @@ public class GenericDeploymentTool implements EJBDeploymentTool if( ( destDir == null ) || ( !destDir.isDirectory() ) ) { String msg = "A valid destination directory must be specified " - + "using the \"destdir\" attribute."; + + "using the \"destdir\" attribute."; throw new BuildException( msg ); } } - /** * Returns a Classloader object which parses the passed in generic EjbJar * classpath. The loader is used to dynamically load classes from @@ -320,6 +316,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool * @return The ClassLoaderForBuild value */ protected ClassLoader getClassLoaderForBuild() + throws TaskException { if( classpathLoader != null ) { @@ -382,9 +379,9 @@ public class GenericDeploymentTool implements EJBDeploymentTool registerKnownDTDs( handler ); // register any DTDs supplied by the user - for( Iterator i = getConfig().dtdLocations.iterator(); i.hasNext(); ) + for( Iterator i = getConfig().dtdLocations.iterator(); i.hasNext(); ) { - EjbJar.DTDLocation dtdLocation = ( EjbJar.DTDLocation )i.next(); + EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation)i.next(); handler.registerDTD( dtdLocation.getPublicId(), dtdLocation.getLocation() ); } return handler; @@ -400,7 +397,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool return destDir; } - /** * Using the EJB descriptor file name passed from the ejbjar * task, this method returns the "basename" which will be used to name the @@ -433,7 +429,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool if( lastSeparatorIndex != -1 ) { endBaseName = descriptorFileName.indexOf( config.baseNameTerminator, - lastSeparatorIndex ); + lastSeparatorIndex ); } else { @@ -522,13 +518,13 @@ public class GenericDeploymentTool implements EJBDeploymentTool // Create the file input stream, and buffer everything over // to the jar output stream - byte[] byteBuffer = new byte[2 * 1024]; + byte[] byteBuffer = new byte[ 2 * 1024 ]; int count = 0; do { jStream.write( byteBuffer, 0, count ); count = iStream.read( byteBuffer, 0, byteBuffer.length ); - }while ( count != -1 ); + } while( count != -1 ); //add it to list of files in jar addedfiles.add( logicalFilename ); @@ -537,8 +533,8 @@ public class GenericDeploymentTool implements EJBDeploymentTool catch( IOException ioe ) { log( "WARNING: IOException while adding entry " + - logicalFilename + " to jarfile from " + inputFile.getPath() + " " + - ioe.getClass().getName() + "-" + ioe.getMessage(), Project.MSG_WARN ); + logicalFilename + " to jarfile from " + inputFile.getPath() + " " + + ioe.getClass().getName() + "-" + ioe.getMessage(), Project.MSG_WARN ); } finally { @@ -550,7 +546,8 @@ public class GenericDeploymentTool implements EJBDeploymentTool iStream.close(); } catch( IOException closeException ) - {} + { + } } } } @@ -566,16 +563,16 @@ public class GenericDeploymentTool implements EJBDeploymentTool { // add in support classes if any Project project = task.getProject(); - for( Iterator i = config.supportFileSets.iterator(); i.hasNext(); ) + for( Iterator i = config.supportFileSets.iterator(); i.hasNext(); ) { - FileSet supportFileSet = ( FileSet )i.next(); + FileSet supportFileSet = (FileSet)i.next(); File supportBaseDir = supportFileSet.getDir( project ); DirectoryScanner supportScanner = supportFileSet.getDirectoryScanner( project ); supportScanner.scan(); String[] supportFiles = supportScanner.getIncludedFiles(); for( int j = 0; j < supportFiles.length; ++j ) { - ejbFiles.put( supportFiles[j], new File( supportBaseDir, supportFiles[j] ) ); + ejbFiles.put( supportFiles[ j ], new File( supportBaseDir, supportFiles[ j ] ) ); } } } @@ -591,7 +588,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool // nothing to add for generic tool. }// end of writeJar - /** * Add all available classes, that depend on Remote, Home, Bean, PK * @@ -610,7 +606,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool Iterator i = checkEntries.keySet().iterator(); while( i.hasNext() ) { - String entryName = ( String )i.next(); + String entryName = (String)i.next(); if( entryName.endsWith( ".class" ) ) newSet.add( entryName.substring( 0, entryName.length() - ".class".length() ).replace( File.separatorChar, '/' ) ); } @@ -621,7 +617,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool i = newSet.iterator(); while( i.hasNext() ) { - String fileName = base + ( ( String )i.next() ).replace( '/', File.separatorChar ) + ".class"; + String fileName = base + ( (String)i.next() ).replace( '/', File.separatorChar ) + ".class"; try { @@ -638,22 +634,22 @@ public class GenericDeploymentTool implements EJBDeploymentTool visitor.clearDependencies(); Dependencies.applyFilter( newSet, - new Filter() - { - public boolean accept( Object object ) - { - String fileName = base + ( ( String )object ).replace( '/', File.separatorChar ) + ".class"; - return new File( fileName ).exists(); - } - } ); + new Filter() + { + public boolean accept( Object object ) + { + String fileName = base + ( (String)object ).replace( '/', File.separatorChar ) + ".class"; + return new File( fileName ).exists(); + } + } ); newSet.removeAll( set ); set.addAll( newSet ); - }while ( newSet.size() > 0 ); + } while( newSet.size() > 0 ); i = set.iterator(); while( i.hasNext() ) { - String next = ( ( String )i.next() ).replace( '/', File.separatorChar ); + String next = ( (String)i.next() ).replace( '/', File.separatorChar ); checkEntries.put( next + ".class", new File( base + next + ".class" ) ); log( "dependent class: " + next + ".class" + " - " + base + next + ".class", Project.MSG_VERBOSE ); } @@ -713,7 +709,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool config.manifest.lastModified() > lastBuild ) { log( "Build needed because manifest " + config.manifest + " is out of date", - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); return true; } @@ -723,11 +719,11 @@ public class GenericDeploymentTool implements EJBDeploymentTool // more recently than the destination jar. while( fileIter.hasNext() ) { - File currentFile = ( File )fileIter.next(); + File currentFile = (File)fileIter.next(); if( lastBuild < currentFile.lastModified() ) { log( "Build needed because " + currentFile.getPath() + " is out of date", - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); return true; } } @@ -780,7 +776,8 @@ public class GenericDeploymentTool implements EJBDeploymentTool descriptorStream.close(); } catch( IOException closeException ) - {} + { + } } } @@ -892,13 +889,13 @@ public class GenericDeploymentTool implements EJBDeploymentTool jarStream.setMethod( JarOutputStream.DEFLATED ); // Loop through all the class files found and add them to the jar - for( Iterator entryIterator = files.keySet().iterator(); entryIterator.hasNext(); ) + for( Iterator entryIterator = files.keySet().iterator(); entryIterator.hasNext(); ) { - String entryName = ( String )entryIterator.next(); - File entryFile = ( File )files.get( entryName ); + String entryName = (String)entryIterator.next(); + File entryFile = (File)files.get( entryName ); log( "adding file '" + entryName + "'", - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); addFileToJar( jarStream, entryFile, entryName ); @@ -913,17 +910,17 @@ public class GenericDeploymentTool implements EJBDeploymentTool int entryIndex = entryName.lastIndexOf( entryFile.getName() ) - 1; if( entryIndex < 0 ) { - entryName = innerfiles[i]; + entryName = innerfiles[ i ]; } else { - entryName = entryName.substring( 0, entryIndex ) + File.separatorChar + innerfiles[i]; + entryName = entryName.substring( 0, entryIndex ) + File.separatorChar + innerfiles[ i ]; } // link the file entryFile = new File( config.srcDir, entryName ); log( "adding innerclass file '" + entryName + "'", - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); addFileToJar( jarStream, entryFile, entryName ); @@ -933,9 +930,9 @@ public class GenericDeploymentTool implements EJBDeploymentTool catch( IOException ioe ) { String msg = "IOException while processing ejb-jar file '" - + jarfile.toString() - + "'. Details: " - + ioe.getMessage(); + + jarfile.toString() + + "'. Details: " + + ioe.getMessage(); throw new BuildException( msg, ioe ); } finally @@ -947,12 +944,12 @@ public class GenericDeploymentTool implements EJBDeploymentTool jarStream.close(); } catch( IOException closeException ) - {} + { + } } } } - /** * Get the vendor specific name of the Jar that will be output. The * modification date of this jar will be checked against the dependent bean diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java index cc7d965ad..2a6ab0e07 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs.optional.ejb; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -19,9 +20,10 @@ import java.util.jar.JarFile; import java.util.jar.JarOutputStream; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.AntClassLoader; -import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.taskdefs.Java; import org.apache.tools.ant.types.Path; import org.xml.sax.InputSource; @@ -29,27 +31,27 @@ import org.xml.sax.InputSource; public class WeblogicDeploymentTool extends GenericDeploymentTool { public final static String PUBLICID_EJB11 - = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"; + = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"; public final static String PUBLICID_EJB20 - = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"; + = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"; public final static String PUBLICID_WEBLOGIC_EJB510 - = "-//BEA Systems, Inc.//DTD WebLogic 5.1.0 EJB//EN"; + = "-//BEA Systems, Inc.//DTD WebLogic 5.1.0 EJB//EN"; public final static String PUBLICID_WEBLOGIC_EJB600 - = "-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN"; + = "-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN"; protected final static String DEFAULT_WL51_EJB11_DTD_LOCATION - = "/weblogic/ejb/deployment/xml/ejb-jar.dtd"; + = "/weblogic/ejb/deployment/xml/ejb-jar.dtd"; protected final static String DEFAULT_WL60_EJB11_DTD_LOCATION - = "/weblogic/ejb20/dd/xml/ejb11-jar.dtd"; + = "/weblogic/ejb20/dd/xml/ejb11-jar.dtd"; protected final static String DEFAULT_WL60_EJB20_DTD_LOCATION - = "/weblogic/ejb20/dd/xml/ejb20-jar.dtd"; + = "/weblogic/ejb20/dd/xml/ejb20-jar.dtd"; protected final static String DEFAULT_WL51_DTD_LOCATION - = "/weblogic/ejb/deployment/xml/weblogic-ejb-jar.dtd"; + = "/weblogic/ejb/deployment/xml/weblogic-ejb-jar.dtd"; protected final static String DEFAULT_WL60_51_DTD_LOCATION - = "/weblogic/ejb20/dd/xml/weblogic510-ejb-jar.dtd"; + = "/weblogic/ejb20/dd/xml/weblogic510-ejb-jar.dtd"; protected final static String DEFAULT_WL60_DTD_LOCATION - = "/weblogic/ejb20/dd/xml/weblogic600-ejb-jar.dtd"; + = "/weblogic/ejb20/dd/xml/weblogic600-ejb-jar.dtd"; protected final static String DEFAULT_COMPILER = "default"; @@ -235,7 +237,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool this.alwaysRebuild = rebuild; } - /** * Setter used to store the suffix for the generated weblogic jar file. * @@ -262,7 +263,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool this.weblogicDTD = inString; } - /** * Setter used to store the location of the ejb-jar DTD. This can be a file * on the system or a resource on the classpath. @@ -306,10 +306,10 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool /** * Called to validate that the tool parameters have been configured. * - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void validateConfigured() - throws BuildException + throws TaskException { super.validateConfigured(); } @@ -323,7 +323,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool * @exception IOException Description of Exception */ protected ClassLoader getClassLoaderFromJar( File classjar ) - throws IOException + throws IOException, TaskException { Path lookupPath = new Path( getTask().getProject() ); lookupPath.setLocation( classjar ); @@ -350,7 +350,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool String fileNameWithMETA = currentText; //trim the META_INF\ off of the file name String fileName = fileNameWithMETA.substring( META_DIR.length(), - fileNameWithMETA.length() ); + fileNameWithMETA.length() ); File descriptorFile = new File( srcDir, fileName ); ejbFiles.put( fileNameWithMETA, descriptorFile ); @@ -364,15 +364,14 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool handler.registerDTD( PUBLICID_WEBLOGIC_EJB510, weblogicDTD ); handler.registerDTD( PUBLICID_WEBLOGIC_EJB600, weblogicDTD ); - for( Iterator i = getConfig().dtdLocations.iterator(); i.hasNext(); ) + for( Iterator i = getConfig().dtdLocations.iterator(); i.hasNext(); ) { - EjbJar.DTDLocation dtdLocation = ( EjbJar.DTDLocation )i.next(); + EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation)i.next(); handler.registerDTD( dtdLocation.getPublicId(), dtdLocation.getLocation() ); } return handler; } - /** * Helper method to check to see if a weblogic EBJ1.1 jar needs to be * rebuilt using ejbc. Called from writeJar it sees if the "Bean" classes @@ -398,6 +397,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool * @return The RebuildRequired value */ protected boolean isRebuildRequired( File genericJarFile, File weblogicJarFile ) + throws TaskException { boolean rebuild = false; @@ -409,10 +409,10 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool try { log( "Checking if weblogic Jar needs to be rebuilt for jar " + weblogicJarFile.getName(), - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); // Only go forward if the generic and the weblogic file both exist if( genericJarFile.exists() && genericJarFile.isFile() - && weblogicJarFile.exists() && weblogicJarFile.isFile() ) + && weblogicJarFile.exists() && weblogicJarFile.isFile() ) { //open jar files genericJar = new JarFile( genericJarFile ); @@ -423,31 +423,31 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool Hashtable replaceEntries = new Hashtable(); //get the list of generic jar entries - for( Enumeration e = genericJar.entries(); e.hasMoreElements(); ) + for( Enumeration e = genericJar.entries(); e.hasMoreElements(); ) { - JarEntry je = ( JarEntry )e.nextElement(); + JarEntry je = (JarEntry)e.nextElement(); genericEntries.put( je.getName().replace( '\\', '/' ), je ); } //get the list of weblogic jar entries - for( Enumeration e = wlJar.entries(); e.hasMoreElements(); ) + for( Enumeration e = wlJar.entries(); e.hasMoreElements(); ) { - JarEntry je = ( JarEntry )e.nextElement(); + JarEntry je = (JarEntry)e.nextElement(); wlEntries.put( je.getName(), je ); } //Cycle Through generic and make sure its in weblogic ClassLoader genericLoader = getClassLoaderFromJar( genericJarFile ); - for( Enumeration e = genericEntries.keys(); e.hasMoreElements(); ) + for( Enumeration e = genericEntries.keys(); e.hasMoreElements(); ) { - String filepath = ( String )e.nextElement(); + String filepath = (String)e.nextElement(); if( wlEntries.containsKey( filepath ) ) {// File name/path match // Check files see if same - JarEntry genericEntry = ( JarEntry )genericEntries.get( filepath ); - JarEntry wlEntry = ( JarEntry )wlEntries.get( filepath ); + JarEntry genericEntry = (JarEntry)genericEntries.get( filepath ); + JarEntry wlEntry = (JarEntry)wlEntries.get( filepath ); if( ( genericEntry.getCrc() != wlEntry.getCrc() ) || // Crc's Match - ( genericEntry.getSize() != wlEntry.getSize() ) ) + ( genericEntry.getSize() != wlEntry.getSize() ) ) {// Size Match if( genericEntry.getName().endsWith( ".class" ) ) @@ -504,12 +504,12 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool newJarStream.setLevel( 0 ); //Copy files from old weblogic jar - for( Enumeration e = wlEntries.elements(); e.hasMoreElements(); ) + for( Enumeration e = wlEntries.elements(); e.hasMoreElements(); ) { - byte[] buffer = new byte[1024]; + byte[] buffer = new byte[ 1024 ]; int bytesRead; InputStream is; - JarEntry je = ( JarEntry )e.nextElement(); + JarEntry je = (JarEntry)e.nextElement(); if( je.getCompressedSize() == -1 || je.getCompressedSize() == je.getSize() ) { @@ -525,7 +525,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { log( "Updating Bean class from generic Jar " + je.getName(), Project.MSG_VERBOSE ); // Use the entry from the generic jar - je = ( JarEntry )replaceEntries.get( je.getName() ); + je = (JarEntry)replaceEntries.get( je.getName() ); is = genericJar.getInputStream( je ); } else @@ -555,16 +555,16 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool catch( ClassNotFoundException cnfe ) { String cnfmsg = "ClassNotFoundException while processing ejb-jar file" - + ". Details: " - + cnfe.getMessage(); - throw new BuildException( cnfmsg, cnfe ); + + ". Details: " + + cnfe.getMessage(); + throw new TaskException( cnfmsg, cnfe ); } catch( IOException ioe ) { String msg = "IOException while processing ejb-jar file " - + ". Details: " - + ioe.getMessage(); - throw new BuildException( msg, ioe ); + + ". Details: " + + ioe.getMessage(); + throw new TaskException( msg, ioe ); } finally { @@ -576,7 +576,8 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool genericJar.close(); } catch( IOException closeException ) - {} + { + } } if( wlJar != null ) @@ -586,7 +587,8 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool wlJar.close(); } catch( IOException closeException ) - {} + { + } } if( newJarStream != null ) @@ -596,7 +598,8 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool newJarStream.close(); } catch( IOException closeException ) - {} + { + } weblogicJarFile.delete(); newWLJarFile.renameTo( weblogicJarFile ); @@ -623,12 +626,12 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool if( weblogicDD.exists() ) { ejbFiles.put( META_DIR + WL_DD, - weblogicDD ); + weblogicDD ); } else { log( "Unable to locate weblogic deployment descriptor. It was expected to be in " + - weblogicDD.getPath(), Project.MSG_WARN ); + weblogicDD.getPath(), Project.MSG_WARN ); return; } @@ -636,14 +639,14 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { log( "The old method for locating CMP files has been DEPRECATED.", Project.MSG_VERBOSE ); log( "Please adjust your weblogic descriptor and set newCMP=\"true\" " + - "to use the new CMP descriptor inclusion mechanism. ", Project.MSG_VERBOSE ); + "to use the new CMP descriptor inclusion mechanism. ", Project.MSG_VERBOSE ); // The the weblogic cmp deployment descriptor File weblogicCMPDD = new File( getConfig().descriptorDir, ddPrefix + WL_CMP_DD ); if( weblogicCMPDD.exists() ) { ejbFiles.put( META_DIR + WL_CMP_DD, - weblogicCMPDD ); + weblogicCMPDD ); } } else @@ -654,28 +657,28 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool // mapping tool descriptors. try { - File ejbDescriptor = ( File )ejbFiles.get( META_DIR + EJB_DD ); + File ejbDescriptor = (File)ejbFiles.get( META_DIR + EJB_DD ); SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setValidating( true ); SAXParser saxParser = saxParserFactory.newSAXParser(); DescriptorHandler handler = getWeblogicDescriptorHandler( ejbDescriptor.getParentFile() ); saxParser.parse( new InputSource ( new FileInputStream - ( weblogicDD ) ), - handler ); + ( weblogicDD ) ), + handler ); Hashtable ht = handler.getFiles(); Enumeration e = ht.keys(); while( e.hasMoreElements() ) { - String key = ( String )e.nextElement(); + String key = (String)e.nextElement(); ejbFiles.put( key, ht.get( key ) ); } } catch( Exception e ) { String msg = "Exception while adding Vendor specific files: " + e.toString(); - throw new BuildException( msg, e ); + throw new TaskException( msg, e ); } } } @@ -698,11 +701,11 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool * @param jarFile Description of Parameter * @param files Description of Parameter * @param publicId Description of Parameter - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ protected void writeJar( String baseName, File jarFile, Hashtable files, String publicId ) - throws BuildException + throws TaskException { // need to create a generic jar first. File genericJarFile = super.getVendorOutputJarFile( baseName ); @@ -715,7 +718,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool if( !keepGeneric ) { log( "deleting generic jar " + genericJarFile.toString(), - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); genericJarFile.delete(); } } @@ -751,7 +754,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { try { - getTask().getProject().copyFile( sourceJar, destJar ); + FileUtils.newFileUtils().copyFile( sourceJar, destJar ); if( !keepgenerated ) { sourceJar.delete(); @@ -760,7 +763,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool } catch( IOException e ) { - throw new BuildException( "Unable to write EJB jar", e ); + throw new TaskException( "Unable to write EJB jar", e ); } } @@ -768,7 +771,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool try { - javaTask = ( Java )getTask().getProject().createTask( "java" ); + javaTask = (Java)getTask().getProject().createTask( "java" ); javaTask.setTaskName( "ejbc" ); if( getJvmDebugLevel() != null ) @@ -835,18 +838,18 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool } log( "Calling " + ejbcClassName + " for " + sourceJar.toString(), - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); if( javaTask.executeJava() != 0 ) { - throw new BuildException( "Ejbc reported an error" ); + throw new TaskException( "Ejbc reported an error" ); } } catch( Exception e ) { // Have to catch this because of the semantics of calling main() String msg = "Exception while calling " + ejbcClassName + ". Details: " + e.toString(); - throw new BuildException( msg, e ); + throw new TaskException( msg, e ); } } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java index 8272c3e20..abb75100e 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java @@ -6,17 +6,25 @@ * the LICENSE file. */ package org.apache.tools.ant.taskdefs.optional.ejb; -import java.io.*; -import java.net.*; -import java.util.*; -import java.util.jar.*; -import javax.xml.parsers.*; -import org.apache.tools.ant.*; -import org.apache.tools.ant.taskdefs.*; -import org.apache.tools.ant.taskdefs.ExecTask; -import org.apache.tools.ant.types.*; -import org.xml.sax.*; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.jar.JarOutputStream; +import org.apache.myrmidon.api.TaskException; +import org.apache.tools.ant.AntClassLoader; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Java; +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.EnumeratedAttribute; +import org.apache.tools.ant.types.Environment; +import org.apache.tools.ant.types.Path; /** * Websphere deployment tool that augments the ejbjar task. @@ -27,20 +35,14 @@ import org.xml.sax.*; public class WebsphereDeploymentTool extends GenericDeploymentTool { - - public final static String PUBLICID_EJB11 - - = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"; + = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"; public final static String PUBLICID_EJB20 - - = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"; + = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"; protected final static String SCHEMA_DIR = "Schema/"; - - protected final static String WAS_EXT = "ibm-ejb-jar-ext.xmi"; protected final static String WAS_BND = "ibm-ejb-jar-bnd.xmi"; @@ -49,318 +51,203 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool protected final static String WAS_CMP_SCHEMA = "Schema.dbxmi"; - - /** * Instance variable that stores the suffix for the websphere jarfile. */ - private String jarSuffix = ".jar"; - - /** * Instance variable that determines whether generic ejb jars are kept. */ - - - private boolean keepgenerated = false; - - private String additionalArgs = ""; - - private boolean keepGeneric = false; - - private String compiler = null; - - private boolean alwaysRebuild = true; - - private boolean ejbdeploy = true; - - /** * Indicates if the old CMP location convention is to be used. */ - private boolean newCMP = false; - - /** * The classpath to the websphere classes. */ - private Path wasClasspath = null; - - /** * true - Only output error messages, suppress informational messages */ - private boolean quiet = true; - - /** * the scratchdir for the ejbdeploy operation */ - private String tempdir = "_ejbdeploy_temp"; - - /** * true - Only generate the deployment code, do not run RMIC or Javac */ - private boolean codegen; - - /** * The name of the database to create. (For top-down mapping only) */ - private String dbName; - - /** * The name of the schema to create. (For top-down mappings only) */ - private String dbSchema; - - /** * The DB Vendor name, the EJB is persisted against */ - private String dbVendor; - - /** * Instance variable that stores the location of the ejb 1.1 DTD file. */ - private String ejb11DTD; - - /** * true - Disable informational messages */ - private boolean noinform; - - /** * true - Disable the validation steps */ - private boolean novalidate; - - /** * true - Disable warning and informational messages */ - private boolean nowarn; - - /** * Additional options for RMIC */ - private String rmicOptions; - - /** * true - Enable internal tracing */ - private boolean trace; - - /** * true- Use the WebSphere 3.5 compatible mapping rules */ - private boolean use35MappingRules; - - /** * sets some additional args to send to ejbdeploy. * * @param args The new Args value */ - public void setArgs( String args ) { - this.additionalArgs = args; - } - - /** * (true) Only generate the deployment code, do not run RMIC or Javac * * @param codegen The new Codegen value */ - public void setCodegen( boolean codegen ) { - this.codegen = codegen; - } - - /** * The compiler (switch -compiler) to use * * @param compiler The new Compiler value */ - public void setCompiler( String compiler ) { - this.compiler = compiler; - } - - /** * Sets the name of the Database to create * * @param dbName The new Dbname value */ - public void setDbname( String dbName ) { - this.dbName = dbName; - } - - /** * Sets the name of the schema to create * * @param dbSchema The new Dbschema value */ - public void setDbschema( String dbSchema ) { - this.dbSchema = dbSchema; - } - - /** * Sets the DB Vendor for the Entity Bean mapping * * @param dbvendor The new Dbvendor value */ - public void setDbvendor( DBVendor dbvendor ) { - this.dbVendor = dbvendor.getValue(); - } - - /** * Setter used to store the location of the Sun's Generic EJB DTD. This can * be a file on the system or a resource on the classpath. * * @param inString the string to use as the DTD location. */ - public void setEJBdtd( String inString ) { - this.ejb11DTD = inString; - } - - /** * Decide, wether ejbdeploy should be called or not * * @param ejbdeploy */ - public void setEjbdeploy( boolean ejbdeploy ) { - this.ejbdeploy = ejbdeploy; - } - - /** * Sets whether -keepgenerated is passed to ejbdeploy (that is, the .java * source files are kept). * * @param inValue either 'true' or 'false' */ - public void setKeepgenerated( String inValue ) { - this.keepgenerated = Boolean.valueOf( inValue ).booleanValue(); - } - - /** * Setter used to store the value of keepGeneric * * @param inValue a string, either 'true' or 'false'. */ - public void setKeepgeneric( boolean inValue ) { - this.keepGeneric = inValue; - } - - /** * Set the value of the newCMP scheme. The old CMP scheme locates the * websphere CMP descriptor based on the naming convention where the @@ -371,216 +258,142 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool * * @param newCMP The new NewCMP value */ - public void setNewCMP( boolean newCMP ) { - this.newCMP = newCMP; - } - - /** * (true) Disable informational messages * * @param noinfom The new Noinform value */ - public void setNoinform( boolean noinfom ) { - this.noinform = noinform; - } - - /** * (true) Disable the validation steps * * @param novalidate The new Novalidate value */ - public void setNovalidate( boolean novalidate ) { - this.novalidate = novalidate; - } - - /** * (true) Disable warning and informational messages * * @param nowarn The new Nowarn value */ - public void setNowarn( boolean nowarn ) { - this.nowarn = nowarn; - } - - /** * Set the value of the oldCMP scheme. This is an antonym for newCMP * * @param oldCMP The new OldCMP value */ - public void setOldCMP( boolean oldCMP ) { - this.newCMP = !oldCMP; - } - - /** * (true) Only output error messages, suppress informational messages * * @param quiet The new Quiet value */ - public void setQuiet( boolean quiet ) { - this.quiet = quiet; - } - - /** * Set the rebuild flag to false to only update changes in the jar rather * than rerunning ejbdeploy * * @param rebuild The new Rebuild value */ - public void setRebuild( boolean rebuild ) { - this.alwaysRebuild = rebuild; - } - - - - /** * Setter used to store the suffix for the generated websphere jar file. * * @param inString the string to use as the suffix. */ - public void setSuffix( String inString ) { - this.jarSuffix = inString; - } - - /** * Sets the temporary directory for the ejbdeploy task * * @param tempdir The new Tempdir value */ - public void setTempdir( String tempdir ) { - this.tempdir = tempdir; - } - - /** * (true) Enable internal tracing * * @param trace The new Trace value */ - public void setTrace( boolean trace ) { - this.trace = trace; - } - - /** * (true) Use the WebSphere 3.5 compatible mapping rules * * @param attr The new Use35 value */ - public void setUse35( boolean attr ) { - use35MappingRules = attr; - } - - public void setWASClasspath( Path wasClasspath ) { - this.wasClasspath = wasClasspath; - } - - /** * Get the classpath to the websphere classpaths * * @return Description of the Returned Value */ - public Path createWASClasspath() { - if( wasClasspath == null ) { - wasClasspath = new Path( getTask().getProject() ); - } - return wasClasspath.createPath(); - } - - /** * Called to validate that the tool parameters have been configured. * - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ - public void validateConfigured() - throws BuildException + throws TaskException { - super.validateConfigured(); - } - - /** * Helper method invoked by isRebuildRequired to get a ClassLoader for a Jar * File passed to it. @@ -589,37 +402,21 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool * @return The ClassLoaderFromJar value * @exception IOException Description of Exception */ - protected ClassLoader getClassLoaderFromJar( File classjar ) - throws IOException + throws IOException, TaskException { - Path lookupPath = new Path( getTask().getProject() ); - lookupPath.setLocation( classjar ); - - - Path classpath = getCombinedClasspath(); - if( classpath != null ) { - lookupPath.append( classpath ); - } - - - return new AntClassLoader( getTask().getProject(), lookupPath ); - } - - protected DescriptorHandler getDescriptorHandler( File srcDir ) { - DescriptorHandler handler = new DescriptorHandler( getTask(), srcDir ); // register all the DTDs, both the ones that are known and @@ -628,173 +425,89 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool // any supplied by the user handler.registerDTD( PUBLICID_EJB11, ejb11DTD ); - - - - for( Iterator i = getConfig().dtdLocations.iterator(); i.hasNext(); ) + for( Iterator i = getConfig().dtdLocations.iterator(); i.hasNext(); ) { - - EjbJar.DTDLocation dtdLocation = ( EjbJar.DTDLocation )i.next(); - + EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation)i.next(); handler.registerDTD( dtdLocation.getPublicId(), dtdLocation.getLocation() ); - } - - - return handler; - } - - /** * Gets the options for the EJB Deploy operation * * @return String */ - protected String getOptions() { - // Set the options StringBuffer options = new StringBuffer(); - if( dbVendor != null ) { - options.append( " -dbvendor " ).append( dbVendor ); - } - if( dbName != null ) { - options.append( " -dbname \"" ).append( dbName ).append( "\"" ); - } - - - if( dbSchema != null ) { - options.append( " -dbschema \"" ).append( dbSchema ).append( "\"" ); - } - - - if( codegen ) { - options.append( " -codegen" ); - } - - - if( quiet ) { - options.append( " -quiet" ); - } - - - if( novalidate ) { - options.append( " -novalidate" ); - } - - - if( nowarn ) { - options.append( " -nowarn" ); - } - - - if( noinform ) { - options.append( " -noinform" ); - } - - - if( trace ) { - options.append( " -trace" ); - } - - - if( use35MappingRules ) { - options.append( " -35" ); - } - - - if( rmicOptions != null ) { - options.append( " -rmic \"" ).append( rmicOptions ).append( "\"" ); - } - - - return options.toString(); - } - - protected DescriptorHandler getWebsphereDescriptorHandler( final File srcDir ) { - DescriptorHandler handler = new DescriptorHandler( getTask(), srcDir ) { - - protected void processElement() { } - + protected void processElement() + { + } }; - - - - for( Iterator i = getConfig().dtdLocations.iterator(); i.hasNext(); ) + for( Iterator i = getConfig().dtdLocations.iterator(); i.hasNext(); ) { - - EjbJar.DTDLocation dtdLocation = ( EjbJar.DTDLocation )i.next(); - + EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation)i.next(); handler.registerDTD( dtdLocation.getPublicId(), dtdLocation.getLocation() ); - } - return handler; - } - - - - /** * Helper method to check to see if a websphere EBJ1.1 jar needs to be * rebuilt using ejbdeploy. Called from writeJar it sees if the "Bean" @@ -819,235 +532,141 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool * see if it needs to be rebuilt. * @return The RebuildRequired value */ - protected boolean isRebuildRequired( File genericJarFile, File websphereJarFile ) + throws TaskException { - boolean rebuild = false; - - - JarFile genericJar = null; - JarFile wasJar = null; - File newwasJarFile = null; - JarOutputStream newJarStream = null; - - - try { - log( "Checking if websphere Jar needs to be rebuilt for jar " + websphereJarFile.getName(), - - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); // Only go forward if the generic and the websphere file both exist if( genericJarFile.exists() && genericJarFile.isFile() - - && websphereJarFile.exists() && websphereJarFile.isFile() ) + && websphereJarFile.exists() && websphereJarFile.isFile() ) { - //open jar files genericJar = new JarFile( genericJarFile ); - wasJar = new JarFile( websphereJarFile ); - - - Hashtable genericEntries = new Hashtable(); - Hashtable wasEntries = new Hashtable(); - Hashtable replaceEntries = new Hashtable(); //get the list of generic jar entries - for( Enumeration e = genericJar.entries(); e.hasMoreElements(); ) + for( Enumeration e = genericJar.entries(); e.hasMoreElements(); ) { - - JarEntry je = ( JarEntry )e.nextElement(); - + JarEntry je = (JarEntry)e.nextElement(); genericEntries.put( je.getName().replace( '\\', '/' ), je ); - } //get the list of websphere jar entries - for( Enumeration e = wasJar.entries(); e.hasMoreElements(); ) + for( Enumeration e = wasJar.entries(); e.hasMoreElements(); ) { - - JarEntry je = ( JarEntry )e.nextElement(); - + JarEntry je = (JarEntry)e.nextElement(); wasEntries.put( je.getName(), je ); - } - - //Cycle Through generic and make sure its in websphere ClassLoader genericLoader = getClassLoaderFromJar( genericJarFile ); - - for( Enumeration e = genericEntries.keys(); e.hasMoreElements(); ) + for( Enumeration e = genericEntries.keys(); e.hasMoreElements(); ) { - - String filepath = ( String )e.nextElement(); - + String filepath = (String)e.nextElement(); if( wasEntries.containsKey( filepath ) ) {// File name/path match - - // Check files see if same - - JarEntry genericEntry = ( JarEntry )genericEntries.get( filepath ); - - JarEntry wasEntry = ( JarEntry )wasEntries.get( filepath ); - + JarEntry genericEntry = (JarEntry)genericEntries.get( filepath ); + JarEntry wasEntry = (JarEntry)wasEntries.get( filepath ); if( ( genericEntry.getCrc() != wasEntry.getCrc() ) || // Crc's Match ( genericEntry.getSize() != wasEntry.getSize() ) ) {// Size Match - - if( genericEntry.getName().endsWith( ".class" ) ) { - //File are different see if its an object or an interface - - String classname = genericEntry.getName().replace( File.separatorChar, '.' ); - classname = classname.substring( 0, classname.lastIndexOf( ".class" ) ); - Class genclass = genericLoader.loadClass( classname ); - if( genclass.isInterface() ) { - //Interface changed rebuild jar. log( "Interface " + genclass.getName() + " has changed", Project.MSG_VERBOSE ); - rebuild = true; - break; - } - else { - //Object class Changed update it. - - replaceEntries.put( filepath, genericEntry ); - } - } - else { - // is it the manifest. If so ignore it - if( !genericEntry.getName().equals( "META-INF/MANIFEST.MF" ) ) { - //File other then class changed rebuild log( "Non class file " + genericEntry.getName() + " has changed", Project.MSG_VERBOSE ); - rebuild = true; - } - break; - } - } - } - else {// a file doesnt exist rebuild - - log( "File " + filepath + " not present in websphere jar", Project.MSG_VERBOSE ); - rebuild = true; - break; - } - } - - - if( !rebuild ) { - log( "No rebuild needed - updating jar", Project.MSG_VERBOSE ); - newwasJarFile = new File( websphereJarFile.getAbsolutePath() + ".temp" ); - if( newwasJarFile.exists() ) { - newwasJarFile.delete(); - } - - - newJarStream = new JarOutputStream( new FileOutputStream( newwasJarFile ) ); - newJarStream.setLevel( 0 ); //Copy files from old websphere jar - for( Enumeration e = wasEntries.elements(); e.hasMoreElements(); ) + for( Enumeration e = wasEntries.elements(); e.hasMoreElements(); ) { - - byte[] buffer = new byte[1024]; - + byte[] buffer = new byte[ 1024 ]; int bytesRead; - InputStream is; - - JarEntry je = ( JarEntry )e.nextElement(); - + JarEntry je = (JarEntry)e.nextElement(); if( je.getCompressedSize() == -1 || - je.getCompressedSize() == je.getSize() ) { - newJarStream.setLevel( 0 ); - } - else { - newJarStream.setLevel( 9 ); - } @@ -1056,181 +675,107 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool if( replaceEntries.containsKey( je.getName() ) ) { - log( "Updating Bean class from generic Jar " + je.getName(), - - Project.MSG_VERBOSE ); + Project.MSG_VERBOSE ); // Use the entry from the generic jar - je = ( JarEntry )replaceEntries.get( je.getName() ); - + je = (JarEntry)replaceEntries.get( je.getName() ); is = genericJar.getInputStream( je ); - } - else {//use fle from original websphere jar is = wasJar.getInputStream( je ); - } - newJarStream.putNextEntry( new JarEntry( je.getName() ) ); - - - while( ( bytesRead = is.read( buffer ) ) != -1 ) { - newJarStream.write( buffer, 0, bytesRead ); - } - is.close(); - } - } - else { - log( "websphere Jar rebuild needed due to changed interface or XML", Project.MSG_VERBOSE ); - } - } - else { - rebuild = true; - } - } - catch( ClassNotFoundException cnfe ) { - String cnfmsg = "ClassNotFoundException while processing ejb-jar file" - - + ". Details: " - - + cnfe.getMessage(); - - throw new BuildException( cnfmsg, cnfe ); - + + ". Details: " + + cnfe.getMessage(); + throw new TaskException( cnfmsg, cnfe ); } - catch( IOException ioe ) { - String msg = "IOException while processing ejb-jar file " - - + ". Details: " - - + ioe.getMessage(); - - throw new BuildException( msg, ioe ); - + + ". Details: " + + ioe.getMessage(); + throw new TaskException( msg, ioe ); } - finally { - // need to close files and perhaps rename output if( genericJar != null ) { - try { - genericJar.close(); - } - catch( IOException closeException ) - {} - + { + } } - - - if( wasJar != null ) { - try { - wasJar.close(); - } - catch( IOException closeException ) - {} - + { + } } - - - if( newJarStream != null ) { - try { - newJarStream.close(); - } - catch( IOException closeException ) - {} - - - + { + } websphereJarFile.delete(); - newwasJarFile.renameTo( websphereJarFile ); - if( !websphereJarFile.exists() ) { - rebuild = true; - } - } - } - - - return rebuild; - } - - /** * Add any vendor specific files which should be included in the EJB Jar. * * @param ejbFiles The feature to be added to the VendorFiles attribute * @param baseName The feature to be added to the VendorFiles attribute */ - protected void addVendorFiles( Hashtable ejbFiles, String baseName ) { - - - String ddPrefix = ( usingBaseJarName() ? "" : baseName ); - String dbPrefix = ( dbVendor == null ) ? "" : dbVendor + "-"; @@ -1238,134 +783,79 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool // Get the Extensions document File websphereEXT = new File( getConfig().descriptorDir, ddPrefix + WAS_EXT ); - if( websphereEXT.exists() ) { - ejbFiles.put( META_DIR + WAS_EXT, - - websphereEXT ); - + websphereEXT ); } else { - log( "Unable to locate websphere extensions. It was expected to be in " + - - websphereEXT.getPath(), Project.MSG_VERBOSE ); - + websphereEXT.getPath(), Project.MSG_VERBOSE ); } - - - File websphereBND = new File( getConfig().descriptorDir, ddPrefix + WAS_BND ); - if( websphereBND.exists() ) { - ejbFiles.put( META_DIR + WAS_BND, - - websphereBND ); - + websphereBND ); } else { - log( "Unable to locate websphere bindings. It was expected to be in " + - - websphereBND.getPath(), Project.MSG_VERBOSE ); - + websphereBND.getPath(), Project.MSG_VERBOSE ); } - - - if( !newCMP ) { - log( "The old method for locating CMP files has been DEPRECATED.", Project.MSG_VERBOSE ); - log( "Please adjust your websphere descriptor and set newCMP=\"true\" " + - - "to use the new CMP descriptor inclusion mechanism. ", Project.MSG_VERBOSE ); - + "to use the new CMP descriptor inclusion mechanism. ", Project.MSG_VERBOSE ); } - else { - // We attempt to put in the MAP and Schema files of CMP beans try { - // Add the Map file File websphereMAP = new File( getConfig().descriptorDir, - - ddPrefix + dbPrefix + WAS_CMP_MAP ); - + ddPrefix + dbPrefix + WAS_CMP_MAP ); if( websphereMAP.exists() ) { - ejbFiles.put( META_DIR + WAS_CMP_MAP, - - websphereMAP ); - + websphereMAP ); } else { - log( "Unable to locate the websphere Map: " + - - websphereMAP.getPath(), Project.MSG_VERBOSE ); - + websphereMAP.getPath(), Project.MSG_VERBOSE ); } - File websphereSchema = new File( getConfig().descriptorDir, - - ddPrefix + dbPrefix + WAS_CMP_SCHEMA ); - + ddPrefix + dbPrefix + WAS_CMP_SCHEMA ); if( websphereSchema.exists() ) { - ejbFiles.put( META_DIR + SCHEMA_DIR + WAS_CMP_SCHEMA, - - websphereSchema ); - + websphereSchema ); } else { - log( "Unable to locate the websphere Schema: " + - - websphereSchema.getPath(), Project.MSG_VERBOSE ); - + websphereSchema.getPath(), Project.MSG_VERBOSE ); } // Theres nothing else to see here...keep moving sonny - - } - catch( Exception e ) { - String msg = "Exception while adding Vendor specific files: " + - e.toString(); - - throw new BuildException( msg, e ); - + throw new TaskException( msg, e ); } - } - } - - /** * Method used to encapsulate the writing of the JAR file. Iterates over the * filenames/java.io.Files in the Hashtable stored on the instance variable @@ -1375,22 +865,17 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool * @param jarFile Description of Parameter * @param files Description of Parameter * @param publicId Description of Parameter - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ - protected void writeJar( String baseName, File jarFile, Hashtable files, String publicId ) - - throws BuildException + throws TaskException { - if( ejbdeploy ) { - // create the -generic.jar, if required File genericJarFile = super.getVendorOutputJarFile( baseName ); - super.writeJar( baseName, genericJarFile, files, publicId ); @@ -1399,32 +884,21 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool if( alwaysRebuild || isRebuildRequired( genericJarFile, jarFile ) ) { - buildWebsphereJar( genericJarFile, jarFile ); - } - if( !keepGeneric ) { - log( "deleting generic jar " + genericJarFile.toString(), - - Project.MSG_VERBOSE ); - + Project.MSG_VERBOSE ); genericJarFile.delete(); - } - } - else { - // create the "undeployed" output .jar, if required super.writeJar( baseName, jarFile, files, publicId ); - } /* @@ -1440,11 +914,8 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool * genericJarFile.delete(); * } */ - } - - /** * Get the vendor specific name of the Jar that will be output. The * modification date of this jar will be checked against the dependent bean @@ -1453,16 +924,11 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool * @param baseName Description of Parameter * @return The VendorOutputJarFile value */ - File getVendorOutputJarFile( String baseName ) { - return new File( getDestDir(), baseName + jarSuffix ); - }// end getOptions - - /** * Helper method invoked by execute() for each websphere jar to be built. * Encapsulates the logic of constructing a java task for calling @@ -1472,30 +938,18 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool * @param destJar java.io.File representing the destination, websphere * jarfile. */ - private void buildWebsphereJar( File sourceJar, File destJar ) { - try { - if( ejbdeploy ) { - String args = - " " + sourceJar.getPath() + - " " + tempdir + - " " + destJar.getPath() + - " " + getOptions(); - - - if( getCombinedClasspath() != null && getCombinedClasspath().toString().length() > 0 ) - args += " -cp " + getCombinedClasspath(); @@ -1503,16 +957,12 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool // Why do my ""'s get stripped away??? log( "EJB Deploy Options: " + args, Project.MSG_VERBOSE ); - - - - Java javaTask = ( Java )getTask().getProject().createTask( "java" ); + Java javaTask = (Java)getTask().getProject().createTask( "java" ); // Set the JvmArgs javaTask.createJvmarg().setValue( "-Xms64m" ); - javaTask.createJvmarg().setValue( "-Xmx128m" ); @@ -1520,11 +970,8 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool // Set the Environment variable Environment.Variable var = new Environment.Variable(); - var.setKey( "websphere.lib.dir" ); - var.setValue( getTask().getProject().getProperty( "websphere.home" ) + "/lib" ); - javaTask.addSysproperty( var ); @@ -1538,73 +985,38 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool // Set the Java class name javaTask.setTaskName( "ejbdeploy" ); - javaTask.setClassname( "com.ibm.etools.ejbdeploy.EJBDeploy" ); - - - Commandline.Argument arguments = javaTask.createArg(); - arguments.setLine( args ); - - - Path classpath = wasClasspath; - if( classpath == null ) { - classpath = getCombinedClasspath(); - } - - - if( classpath != null ) { - javaTask.setClasspath( classpath ); - javaTask.setFork( true ); - } - else { - javaTask.setFork( true ); - } - - - log( "Calling websphere.ejbdeploy for " + sourceJar.toString(), - - Project.MSG_VERBOSE ); - - - + Project.MSG_VERBOSE ); javaTask.execute(); - } - } - catch( Exception e ) { - // Have to catch this because of the semantics of calling main() String msg = "Exception while calling ejbdeploy. Details: " + e.toString(); - - throw new BuildException( msg, e ); - + throw new TaskException( msg, e ); } - } - /** * Enumerated attribute with the values for the database vendor types * @@ -1616,15 +1028,10 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool public String[] getValues() { - return new String[]{ - "SQL92", "SQL99", "DB2UDBWIN_V71", "DB2UDBOS390_V6", "DB2UDBAS400_V4R5", - "ORACLE_V8", "INFORMIX_V92", "SYBASE_V1192", "MSSQLSERVER_V7", "MYSQL_V323" - - }; - + }; } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/types/Commandline.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/types/Commandline.java index b9b221d84..226e992d0 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/types/Commandline.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/types/Commandline.java @@ -6,12 +6,13 @@ * the LICENSE file. */ package org.apache.tools.ant.types; + import java.io.File; import java.util.StringTokenizer; import java.util.Vector; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.BuildException; - /** * Commandline objects help handling command lines specifying processes to * execute. The class can be used to define a command line as nested elements or @@ -44,10 +45,10 @@ public class Commandline implements Cloneable String[] tmp = translateCommandline( to_process ); if( tmp != null && tmp.length > 0 ) { - setExecutable( tmp[0] ); + setExecutable( tmp[ 0 ] ); for( int i = 1; i < tmp.length; i++ ) { - createArgument().setValue( tmp[i] ); + createArgument().setValue( tmp[ i ] ); } } } @@ -68,6 +69,7 @@ public class Commandline implements Cloneable * @return Description of the Returned Value */ public static String quoteArgument( String argument ) + throws TaskException { if( argument.indexOf( "\"" ) > -1 ) { @@ -104,7 +106,15 @@ public class Commandline implements Cloneable { result.append( ' ' ); } - result.append( quoteArgument( line[i] ) ); + + try + { + result.append( quoteArgument( line[ i ] ) ); + } + catch( TaskException e ) + { + } + } return result.toString(); } @@ -113,7 +123,7 @@ public class Commandline implements Cloneable { if( to_process == null || to_process.length() == 0 ) { - return new String[0]; + return new String[ 0 ]; } // parse with a simple finite state machine @@ -129,50 +139,50 @@ public class Commandline implements Cloneable while( tok.hasMoreTokens() ) { String nextTok = tok.nextToken(); - switch ( state ) + switch( state ) { - case inQuote: - if( "\'".equals( nextTok ) ) - { - state = normal; - } - else - { - current.append( nextTok ); - } - break; - case inDoubleQuote: - if( "\"".equals( nextTok ) ) - { - state = normal; - } - else - { - current.append( nextTok ); - } - break; - default: - if( "\'".equals( nextTok ) ) - { - state = inQuote; - } - else if( "\"".equals( nextTok ) ) - { - state = inDoubleQuote; - } - else if( " ".equals( nextTok ) ) - { - if( current.length() != 0 ) + case inQuote: + if( "\'".equals( nextTok ) ) { - v.addElement( current.toString() ); - current.setLength( 0 ); + state = normal; } - } - else - { - current.append( nextTok ); - } - break; + else + { + current.append( nextTok ); + } + break; + case inDoubleQuote: + if( "\"".equals( nextTok ) ) + { + state = normal; + } + else + { + current.append( nextTok ); + } + break; + default: + if( "\'".equals( nextTok ) ) + { + state = inQuote; + } + else if( "\"".equals( nextTok ) ) + { + state = inDoubleQuote; + } + else if( " ".equals( nextTok ) ) + { + if( current.length() != 0 ) + { + v.addElement( current.toString() ); + current.setLength( 0 ); + } + } + else + { + current.append( nextTok ); + } + break; } } @@ -186,12 +196,11 @@ public class Commandline implements Cloneable throw new BuildException( "unbalanced quotes in " + to_process ); } - String[] args = new String[v.size()]; + String[] args = new String[ v.size() ]; v.copyInto( args ); return args; } - /** * Sets the executable to run. * @@ -205,7 +214,6 @@ public class Commandline implements Cloneable .replace( '\\', File.separatorChar ); } - /** * Returns all arguments defined by addLine, addValue * or the argument object. @@ -217,15 +225,15 @@ public class Commandline implements Cloneable Vector result = new Vector( arguments.size() * 2 ); for( int i = 0; i < arguments.size(); i++ ) { - Argument arg = ( Argument )arguments.elementAt( i ); + Argument arg = (Argument)arguments.elementAt( i ); String[] s = arg.getParts(); for( int j = 0; j < s.length; j++ ) { - result.addElement( s[j] ); + result.addElement( s[ j ] ); } } - String[] res = new String[result.size()]; + String[] res = new String[ result.size() ]; result.copyInto( res ); return res; } @@ -240,24 +248,22 @@ public class Commandline implements Cloneable final String[] args = getArguments(); if( executable == null ) return args; - final String[] result = new String[args.length + 1]; - result[0] = executable; + final String[] result = new String[ args.length + 1 ]; + result[ 0 ] = executable; System.arraycopy( args, 0, result, 1, args.length ); return result; } - public String getExecutable() { return executable; } - public void addArguments( String[] line ) { for( int i = 0; i < line.length; i++ ) { - createArgument().setValue( line[i] ); + createArgument().setValue( line[ i ] ); } } @@ -318,7 +324,6 @@ public class Commandline implements Cloneable return getCommandline().length; } - public String toString() { return toString( getCommandline() ); @@ -421,7 +426,7 @@ public class Commandline implements Cloneable realPos = ( executable == null ? 0 : 1 ); for( int i = 0; i < position; i++ ) { - Argument arg = ( Argument )arguments.elementAt( i ); + Argument arg = (Argument)arguments.elementAt( i ); realPos += arg.getParts().length; } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/types/FileSet.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/types/FileSet.java index 3662f329e..372a1a765 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/types/FileSet.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/types/FileSet.java @@ -82,7 +82,7 @@ public class FileSet extends DataType implements Cloneable } public void setDir( File dir ) - throws BuildException + throws TaskException { if( isReference() ) { @@ -113,10 +113,10 @@ public class FileSet extends DataType implements Cloneable * Sets the name of the file containing the includes patterns. * * @param excl The file to fetch the exclude patterns from. - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void setExcludesfile( File excl ) - throws BuildException + throws TaskException { if( isReference() ) { @@ -147,10 +147,10 @@ public class FileSet extends DataType implements Cloneable * Sets the name of the file containing the includes patterns. * * @param incl The file to fetch the include patterns from. - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void setIncludesfile( File incl ) - throws BuildException + throws TaskException { if( isReference() ) { @@ -168,7 +168,7 @@ public class FileSet extends DataType implements Cloneable * if you make it a reference.

* * @param r The new Refid value - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void setRefid( Reference r ) throws TaskException diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/types/Mapper.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/types/Mapper.java index 33e628dfe..28f126d29 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/types/Mapper.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/types/Mapper.java @@ -6,12 +6,13 @@ * the LICENSE file. */ package org.apache.tools.ant.types; + import java.util.Properties; import java.util.Stack; import org.apache.tools.ant.AntClassLoader; -import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.util.FileNameMapper; +import org.apache.myrmidon.api.TaskException; /** * Element to define a FileNameMapper. @@ -106,10 +107,10 @@ public class Mapper extends DataType implements Cloneable * You must not set any other attribute if you make it a reference.

* * @param r The new Refid value - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void setRefid( Reference r ) - throws BuildException + throws TaskException { if( type != null || from != null || to != null ) { @@ -150,10 +151,10 @@ public class Mapper extends DataType implements Cloneable * Returns a fully configured FileNameMapper implementation. * * @return The Implementation value - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public FileNameMapper getImplementation() - throws BuildException + throws TaskException { if( isReference() ) { @@ -162,12 +163,12 @@ public class Mapper extends DataType implements Cloneable if( type == null && classname == null ) { - throw new BuildException( "one of the attributes type or classname is required" ); + throw new TaskException( "one of the attributes type or classname is required" ); } if( type != null && classname != null ) { - throw new BuildException( "must not specify both type and classname attribute" ); + throw new TaskException( "must not specify both type and classname attribute" ); } try @@ -185,23 +186,23 @@ public class Mapper extends DataType implements Cloneable else { AntClassLoader al = new AntClassLoader( getProject(), - classpath ); + classpath ); c = al.loadClass( classname ); AntClassLoader.initializeClass( c ); } - FileNameMapper m = ( FileNameMapper )c.newInstance(); + FileNameMapper m = (FileNameMapper)c.newInstance(); m.setFrom( from ); m.setTo( to ); return m; } - catch( BuildException be ) + catch( TaskException be ) { throw be; } catch( Throwable t ) { - throw new BuildException( "Error", t ); + throw new TaskException( "Error", t ); } finally { @@ -249,11 +250,11 @@ public class Mapper extends DataType implements Cloneable if( !( o instanceof Mapper ) ) { String msg = ref.getRefId() + " doesn\'t denote a mapper"; - throw new BuildException( msg ); + throw new TaskException( msg ); } else { - return ( Mapper )o; + return (Mapper)o; } } @@ -270,15 +271,15 @@ public class Mapper extends DataType implements Cloneable { implementations = new Properties(); implementations.put( "identity", - "org.apache.tools.ant.util.IdentityMapper" ); + "org.apache.tools.ant.util.IdentityMapper" ); implementations.put( "flatten", - "org.apache.tools.ant.util.FlatFileNameMapper" ); + "org.apache.tools.ant.util.FlatFileNameMapper" ); implementations.put( "glob", - "org.apache.tools.ant.util.GlobPatternMapper" ); + "org.apache.tools.ant.util.GlobPatternMapper" ); implementations.put( "merge", - "org.apache.tools.ant.util.MergingMapper" ); + "org.apache.tools.ant.util.MergingMapper" ); implementations.put( "regexp", - "org.apache.tools.ant.util.RegexpPatternMapper" ); + "org.apache.tools.ant.util.RegexpPatternMapper" ); } public String getImplementation() diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/types/PatternSet.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/types/PatternSet.java index 015c78890..55558cbc6 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/types/PatternSet.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/types/PatternSet.java @@ -6,6 +6,7 @@ * the LICENSE file. */ package org.apache.tools.ant.types; + import java.io.BufferedReader; import java.io.File; import java.io.FileReader; @@ -14,9 +15,8 @@ import java.util.Enumeration; import java.util.Stack; import java.util.StringTokenizer; import java.util.Vector; -import org.apache.tools.ant.BuildException; +import org.apache.myrmidon.api.TaskException; import org.apache.tools.ant.Project; -import org.apache.tools.ant.ProjectHelper; /** * Named collection of include/exclude tags.

@@ -50,6 +50,7 @@ public class PatternSet extends DataType * @param excludes the string containing the exclude patterns */ public void setExcludes( String excludes ) + throws TaskException { if( isReference() ) { @@ -69,10 +70,10 @@ public class PatternSet extends DataType * Sets the name of the file containing the excludes patterns. * * @param excludesFile The file to fetch the exclude patterns from. - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void setExcludesfile( File excludesFile ) - throws BuildException + throws TaskException { if( isReference() ) { @@ -88,6 +89,7 @@ public class PatternSet extends DataType * @param includes the string containing the include patterns */ public void setIncludes( String includes ) + throws TaskException { if( isReference() ) { @@ -107,10 +109,10 @@ public class PatternSet extends DataType * Sets the name of the file containing the includes patterns. * * @param includesFile The file to fetch the include patterns from. - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void setIncludesfile( File includesFile ) - throws BuildException + throws TaskException { if( isReference() ) { @@ -127,10 +129,10 @@ public class PatternSet extends DataType * if you make it a reference.

* * @param r The new Refid value - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ public void setRefid( Reference r ) - throws BuildException + throws TaskException { if( !includeList.isEmpty() || !excludeList.isEmpty() ) { @@ -146,6 +148,7 @@ public class PatternSet extends DataType * @return The ExcludePatterns value */ public String[] getExcludePatterns( Project p ) + throws TaskException { if( isReference() ) { @@ -165,6 +168,7 @@ public class PatternSet extends DataType * @return The IncludePatterns value */ public String[] getIncludePatterns( Project p ) + throws TaskException { if( isReference() ) { @@ -184,10 +188,11 @@ public class PatternSet extends DataType * @param p Description of Parameter */ public void append( PatternSet other, Project p ) + throws TaskException { if( isReference() ) { - throw new BuildException( "Cannot append to a reference" ); + throw new TaskException( "Cannot append to a reference" ); } String[] incl = other.getIncludePatterns( p ); @@ -195,7 +200,7 @@ public class PatternSet extends DataType { for( int i = 0; i < incl.length; i++ ) { - createInclude().setName( incl[i] ); + createInclude().setName( incl[ i ] ); } } @@ -204,7 +209,7 @@ public class PatternSet extends DataType { for( int i = 0; i < excl.length; i++ ) { - createExclude().setName( excl[i] ); + createExclude().setName( excl[ i ] ); } } } @@ -215,6 +220,7 @@ public class PatternSet extends DataType * @return Description of the Returned Value */ public NameEntry createExclude() + throws TaskException { if( isReference() ) { @@ -229,6 +235,7 @@ public class PatternSet extends DataType * @return Description of the Returned Value */ public NameEntry createExcludesFile() + throws TaskException { if( isReference() ) { @@ -243,6 +250,7 @@ public class PatternSet extends DataType * @return Description of the Returned Value */ public NameEntry createInclude() + throws TaskException { if( isReference() ) { @@ -257,6 +265,7 @@ public class PatternSet extends DataType * @return Description of the Returned Value */ public NameEntry createIncludesFile() + throws TaskException { if( isReference() ) { @@ -279,7 +288,7 @@ public class PatternSet extends DataType boolean hasPatterns() { return includesFileList.size() > 0 || excludesFileList.size() > 0 - || includeList.size() > 0 || excludeList.size() > 0; + || includeList.size() > 0 || excludeList.size() > 0; } /** @@ -290,6 +299,7 @@ public class PatternSet extends DataType * @return The Ref value */ private PatternSet getRef( Project p ) + throws TaskException { if( !checked ) { @@ -302,11 +312,11 @@ public class PatternSet extends DataType if( !( o instanceof PatternSet ) ) { String msg = ref.getRefId() + " doesn\'t denote a patternset"; - throw new BuildException( msg ); + throw new TaskException( msg ); } else { - return ( PatternSet )o; + return (PatternSet)o; } } @@ -336,9 +346,9 @@ public class PatternSet extends DataType return null; Vector tmpNames = new Vector(); - for( Enumeration e = list.elements(); e.hasMoreElements(); ) + for( Enumeration e = list.elements(); e.hasMoreElements(); ) { - NameEntry ne = ( NameEntry )e.nextElement(); + NameEntry ne = (NameEntry)e.nextElement(); String pattern = ne.evalName( p ); if( pattern != null && pattern.length() > 0 ) { @@ -346,7 +356,7 @@ public class PatternSet extends DataType } } - String result[] = new String[tmpNames.size()]; + String result[] = new String[ tmpNames.size() ]; tmpNames.copyInto( result ); return result; } @@ -357,21 +367,22 @@ public class PatternSet extends DataType * @param p Description of Parameter */ private void readFiles( Project p ) + throws TaskException { if( includesFileList.size() > 0 ) { Enumeration e = includesFileList.elements(); while( e.hasMoreElements() ) { - NameEntry ne = ( NameEntry )e.nextElement(); + NameEntry ne = (NameEntry)e.nextElement(); String fileName = ne.evalName( p ); if( fileName != null ) { File inclFile = resolveFile( fileName ); if( !inclFile.exists() ) - throw new BuildException( "Includesfile " - + inclFile.getAbsolutePath() - + " not found." ); + throw new TaskException( "Includesfile " + + inclFile.getAbsolutePath() + + " not found." ); readPatterns( inclFile, includeList, p ); } } @@ -383,15 +394,15 @@ public class PatternSet extends DataType Enumeration e = excludesFileList.elements(); while( e.hasMoreElements() ) { - NameEntry ne = ( NameEntry )e.nextElement(); + NameEntry ne = (NameEntry)e.nextElement(); String fileName = ne.evalName( p ); if( fileName != null ) { File exclFile = resolveFile( fileName ); if( !exclFile.exists() ) - throw new BuildException( "Excludesfile " - + exclFile.getAbsolutePath() - + " not found." ); + throw new TaskException( "Excludesfile " + + exclFile.getAbsolutePath() + + " not found." ); readPatterns( exclFile, excludeList, p ); } } @@ -406,10 +417,10 @@ public class PatternSet extends DataType * @param patternfile Description of Parameter * @param patternlist Description of Parameter * @param p Description of Parameter - * @exception BuildException Description of Exception + * @exception TaskException Description of Exception */ private void readPatterns( File patternfile, Vector patternlist, Project p ) - throws BuildException + throws TaskException { BufferedReader patternReader = null; @@ -435,8 +446,8 @@ public class PatternSet extends DataType catch( IOException ioe ) { String msg = "An error occured while reading from pattern file: " - + patternfile; - throw new BuildException( msg, ioe ); + + patternfile; + throw new TaskException( msg, ioe ); } finally {