- *
- * In this situation, the if-modified-since header is set so that the file
- * is only fetched if it is newer than the local file (or there is no local
- * file) This flag is only valid on HTTP connections, it is ignored in other
- * cases. When the flag is set, the local copy of the downloaded file will
- * also have its timestamp set to the remote file time.
- * Note that remote files of date 1/1/1970 (GMT) are treated as 'no
- * timestamp', and web servers often serve files with a timestamp in the
- * future by replacing their timestamp with that of the current time. Also,
- * inter-computer clock differences can cause no end of grief.
- *
- * @param v "true" to enable file time fetching
- */
- public void setUseTimestamp( boolean v )
- {
- useTimestamp = v;
- }
-
- /**
- * Username for basic auth.
- *
- * @param u username for authentication
- */
- public void setUsername( String u )
- {
- this.uname = u;
- }
-
- /**
- * Be verbose, if set to "true
".
- *
- * @param v if "true" then be verbose
- */
- public void setVerbose( boolean v )
- {
- verbose = v;
- }
-
- /**
- * Does the work.
- *
- * @exception org.apache.myrmidon.api.TaskException Thrown in unrecoverable error.
- */
- public void execute()
- throws TaskException
- {
- if( source == null )
- {
- throw new TaskException( "src attribute is required" );
- }
-
- if( dest == null )
- {
- throw new TaskException( "dest attribute is required" );
- }
-
- if( dest.exists() && dest.isDirectory() )
- {
- throw new TaskException( "The specified destination is a directory" );
- }
-
- if( dest.exists() && !dest.canWrite() )
- {
- throw new TaskException( "Can't write to " + dest.getAbsolutePath() );
- }
-
- try
- {
- getContext().info( "Getting: " + source );
-
- //set the timestamp to the file date.
- long timestamp = 0;
-
- boolean hasTimestamp = false;
- if( useTimestamp && dest.exists() )
- {
- timestamp = dest.lastModified();
- if( verbose )
- {
- Date t = new Date( timestamp );
- getContext().info( "local file date : " + t.toString() );
- }
-
- hasTimestamp = true;
- }
-
- //set up the URL connection
- URLConnection connection = source.openConnection();
- //modify the headers
- //NB: things like user authentication could go in here too.
- if( useTimestamp && hasTimestamp )
- {
- connection.setIfModifiedSince( timestamp );
- }
- // prepare Java 1.1 style credentials
- if( uname != null || pword != null )
- {
- String up = uname + ":" + pword;
- String encoding;
- // check to see if sun's Base64 encoder is available.
- try
- {
- sun.misc.BASE64Encoder encoder =
- (sun.misc.BASE64Encoder)Class.forName( "sun.misc.BASE64Encoder" ).newInstance();
- encoding = encoder.encode( up.getBytes() );
-
- }
- catch( Exception ex )
- {// sun's base64 encoder isn't available
- Base64Converter encoder = new Base64Converter();
- encoding = encoder.encode( up.getBytes() );
- }
- connection.setRequestProperty( "Authorization", "Basic " + encoding );
- }
-
- //connect to the remote site (may take some time)
- connection.connect();
- //next test for a 304 result (HTTP only)
- if( connection instanceof HttpURLConnection )
- {
- HttpURLConnection httpConnection = (HttpURLConnection)connection;
- if( httpConnection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED )
- {
- //not modified so no file download. just return instead
- //and trace out something so the user doesn't think that the
- //download happened when it didnt
- getContext().info( "Not modified - so not downloaded" );
- return;
- }
- // test for 401 result (HTTP only)
- if( httpConnection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED )
- {
- getContext().info( "Not authorized - check " + dest + " for details" );
- return;
- }
-
- }
-
- //REVISIT: at this point even non HTTP connections may support the if-modified-since
- //behaviour -we just check the date of the content and skip the write if it is not
- //newer. Some protocols (FTP) dont include dates, of course.
-
- FileOutputStream fos = new FileOutputStream( dest );
-
- InputStream is = null;
- for( int i = 0; i < 3; i++ )
- {
- try
- {
- is = connection.getInputStream();
- break;
- }
- catch( IOException ex )
- {
- getContext().info( "Error opening connection " + ex );
- }
- }
- if( is == null )
- {
- getContext().info( "Can't get " + source + " to " + dest );
- if( ignoreErrors )
- {
- return;
- }
- throw new TaskException( "Can't get " + source + " to " + dest );
- }
-
- byte[] buffer = new byte[ 100 * 1024 ];
- int length;
-
- while( ( length = is.read( buffer ) ) >= 0 )
- {
- fos.write( buffer, 0, length );
- if( verbose )
- {
- System.out.print( "." );
- }
- }
- if( verbose )
- {
- System.out.println();
- }
- fos.close();
- is.close();
-
- //if (and only if) the use file time option is set, then the
- //saved file now has its timestamp set to that of the downloaded file
- if( useTimestamp )
- {
- long remoteTimestamp = connection.getLastModified();
- if( verbose )
- {
- Date t = new Date( remoteTimestamp );
- getContext().info( "last modified = " + t.toString()
- + ( ( remoteTimestamp == 0 ) ? " - using current time instead" : "" ) );
- }
-
- if( remoteTimestamp != 0 )
- {
- dest.setLastModified( remoteTimestamp );
- }
- }
- }
- catch( IOException ioe )
- {
- getContext().info( "Error getting " + source + " to " + dest );
- if( ignoreErrors )
- {
- return;
- }
- throw new TaskException( "Error", ioe );
- }
- }
-
- /**
- * BASE 64 encoding of a String or an array of bytes. Based on RFC 1421.
- *
- * @author Unknown
- * @author Gautam Guliani
- */
-
- class Base64Converter
- {
-
- public final char[] alphabet = {
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 to 7
- 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 8 to 15
- 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 16 to 23
- 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 24 to 31
- 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 32 to 39
- 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 40 to 47
- 'w', 'x', 'y', 'z', '0', '1', '2', '3', // 48 to 55
- '4', '5', '6', '7', '8', '9', '+', '/'};// 56 to 63
-
- public String encode( String s )
- {
- return encode( s.getBytes() );
- }
-
- public String encode( byte[] octetString )
- {
- int bits24;
- int bits6;
-
- char[] out
- = new char[ ( ( octetString.length - 1 ) / 3 + 1 ) * 4 ];
-
- int outIndex = 0;
- int i = 0;
-
- while( ( i + 3 ) <= octetString.length )
- {
- // store the octets
- bits24 = ( octetString[ i++ ] & 0xFF ) << 16;
- bits24 |= ( octetString[ i++ ] & 0xFF ) << 8;
-
- bits6 = ( bits24 & 0x00FC0000 ) >> 18;
- out[ outIndex++ ] = alphabet[ bits6 ];
- bits6 = ( bits24 & 0x0003F000 ) >> 12;
- out[ outIndex++ ] = alphabet[ bits6 ];
- bits6 = ( bits24 & 0x00000FC0 ) >> 6;
- out[ outIndex++ ] = alphabet[ bits6 ];
- bits6 = ( bits24 & 0x0000003F );
- out[ outIndex++ ] = alphabet[ bits6 ];
- }
-
- if( octetString.length - i == 2 )
- {
- // store the octets
- bits24 = ( octetString[ i ] & 0xFF ) << 16;
- bits24 |= ( octetString[ i + 1 ] & 0xFF ) << 8;
- bits6 = ( bits24 & 0x00FC0000 ) >> 18;
- out[ outIndex++ ] = alphabet[ bits6 ];
- bits6 = ( bits24 & 0x0003F000 ) >> 12;
- out[ outIndex++ ] = alphabet[ bits6 ];
- bits6 = ( bits24 & 0x00000FC0 ) >> 6;
- out[ outIndex++ ] = alphabet[ bits6 ];
-
- // padding
- out[ outIndex++ ] = '=';
- }
- else if( octetString.length - i == 1 )
- {
- // store the octets
- bits24 = ( octetString[ i ] & 0xFF ) << 16;
- bits6 = ( bits24 & 0x00FC0000 ) >> 18;
- out[ outIndex++ ] = alphabet[ bits6 ];
- bits6 = ( bits24 & 0x0003F000 ) >> 12;
- out[ outIndex++ ] = alphabet[ bits6 ];
-
- // padding
- out[ outIndex++ ] = '=';
- out[ outIndex++ ] = '=';
- }
-
- return new String( out );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/IContract.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/IContract.java
deleted file mode 100644
index af5be2eb3..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/IContract.java
+++ /dev/null
@@ -1,1083 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.util.Date;
-import java.util.Properties;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.listeners.AbstractProjectListener;
-import org.apache.myrmidon.listeners.LogEvent;
-import org.apache.tools.todo.taskdefs.Java;
-import org.apache.tools.todo.taskdefs.javac.Javac;
-import org.apache.tools.todo.taskdefs.MatchingTask;
-import org.apache.tools.todo.taskdefs.javac.DefaultCompilerAdapter;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.Path;
-
-/**
- * Instruments Java classes with
- * iContract DBC preprocessor.
- * The task can generate a properties file for iControl , a graphical
- * user interface that lets you turn on/off assertions. iControl generates a
- * control file that you can refer to from this task using the controlfile
- * attribute.
- *
- *
- *
- *
- * Attribute
- *
- *
- *
- * Description
- *
- *
- *
- * Required
- *
- *
- *
- *
- *
- *
- *
- * srcdir
- *
- *
- *
- * Location of the java files.
- *
- *
- *
- * Yes
- *
- *
- *
- *
- *
- *
- *
- * instrumentdir
- *
- *
- *
- * Indicates where the instrumented source files should go.
- *
- *
- *
- * Yes
- *
- *
- *
- *
- *
- *
- *
- * repositorydir
- *
- *
- *
- * Indicates where the repository source files should go.
- *
- *
- *
- * Yes
- *
- *
- *
- *
- *
- *
- *
- * builddir
- *
- *
- *
- * Indicates where the compiled instrumented classes should go.
- * Defaults to the value of instrumentdir. NOTE: Don't
- * use the same directory for compiled instrumented classes and
- * uninstrumented classes. It will break the dependency checking.
- * (Classes will not be reinstrumented if you change them).
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * repositorybuilddir
- *
- *
- *
- * Indicates where the compiled repository classes should go.
- * Defaults to the value of repositorydir.
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * pre
- *
- *
- *
- * Indicates whether or not to instrument for preconditions. Defaults
- * to true
unless controlfile is specified, in which
- * case it defaults to false
.
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * post
- *
- *
- *
- * Indicates whether or not to instrument for postconditions.
- * Defaults to true
unless controlfile is specified, in
- * which case it defaults to false
.
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * invariant
- *
- *
- *
- * Indicates whether or not to instrument for invariants. Defaults to
- * true
unless controlfile is specified, in which case
- * it defaults to false
.
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * failthrowable
- *
- *
- *
- * The full name of the Throwable (Exception) that should be thrown
- * when an assertion is violated. Defaults to java.lang.Error
- *
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * verbosity
- *
- *
- *
- * Indicates the verbosity level of iContract. Any combination of
- * error*,warning*,note*,info*,progress*,debug*
(comma
- * separated) can be used. Defaults to error*
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * quiet
- *
- *
- *
- * Indicates if iContract should be quiet. Turn it off if many your
- * classes extend uninstrumented classes and you don't want warnings
- * about this. Defaults to false
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * updateicontrol
- *
- *
- *
- * If set to true, it indicates that the properties file for iControl
- * in the current directory should be updated (or created if it
- * doesn't exist). Defaults to false
.
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * controlfile
- *
- *
- *
- * The name of the control file to pass to iContract. Consider using
- * iControl to generate the file. Default is not to pass a file.
- *
- *
- *
- *
- * Only if updateicontrol=true
- *
- *
- *
- *
- *
- *
- *
- * classdir
- *
- *
- *
- * Indicates where compiled (unistrumented) classes are located. This
- * is required in order to properly update the icontrol.properties
- * file, not for instrumentation.
- *
- *
- *
- * Only if updateicontrol=true
- *
- *
- *
- *
- *
- *
- *
- * targets
- *
- *
- *
- * Name of the file that will be generated by this task, which lists
- * all the classes that iContract will instrument. If specified, the
- * file will not be deleted after execution. If not specified, a file
- * will still be created, but it will be deleted after execution.
- *
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * Note: iContract will use the java compiler indicated by the
- * project's build.compiler
property. See documentation of the
- * Javac task for more information.
- *
- * Nested includes and excludes are also supported.
- *
- * Example:
- * <icontract
- * srcdir="${build.src}"
- * instrumentdir="${build.instrument}"
- * repositorydir="${build.repository}"
- * builddir="${build.instrclasses}"
- * updateicontrol="true"
- * classdir="${build.classes}"
- * controlfile="control"
- * targets="targets"
- * verbosity="error*,warning*"
- * quiet="true"
- * >
- * <classpath refid="compile-classpath"/>
- * </icontract>
- *
- */
-public class IContract extends MatchingTask
-{
-
- private final static String ICONTROL_PROPERTIES_HEADER =
- " You might want to set classRoot to point to your normal compilation class root directory.";
-
- private final static String ICONTROL_PROPERTIES_MESSAGE =
- "You should probably modify icontrol.properties' classRoot to where comiled (uninstrumented) classes go.";
-
- /**
- * \ on windows, / on linux/unix
- */
- private final static String ps = System.getProperty( "path.separator" );
-
- /**
- * compiler to use for instrumenation
- */
- private String icCompiler = "javac";
-
- /**
- * temporary file with file names of all java files to be instrumented
- */
- private File targets = null;
-
- /**
- * will be set to true if any of the sourca files are newer than the
- * instrumented files
- */
- private boolean dirty = false;
-
- /**
- * set to true if the iContract jar is missing
- */
- private boolean iContractMissing = false;
-
- /**
- * source file root
- */
- private File srcDir = null;
-
- /**
- * instrumentation src root
- */
- private File instrumentDir = null;
-
- /**
- * instrumentation build root
- */
- private File buildDir = null;
-
- /**
- * repository src root
- */
- private File repositoryDir = null;
-
- /**
- * repository build root
- */
- private File repBuildDir = null;
-
- /**
- * classpath
- */
- private Path classpath = null;
-
- /**
- * The class of the Throwable to be thrown on failed assertions
- */
- private String failThrowable = "java.lang.Error";
-
- /**
- * The -v option
- */
- private String verbosity = "error*";
-
- /**
- * The -q option
- */
- private boolean quiet = false;
-
- /**
- * Indicates whether or not to use internal compilation
- */
- private boolean internalcompilation = false;
-
- /**
- * The -m option
- */
- private File controlFile = null;
-
- /**
- * Indicates whether or not to instrument for preconditions
- */
- private boolean pre = true;
- private boolean preModified = false;
-
- /**
- * Indicates whether or not to instrument for postconditions
- */
- private boolean post = true;
- private boolean postModified = false;
-
- /**
- * Indicates whether or not to instrument for invariants
- */
- private boolean invariant = true;
- private boolean invariantModified = false;
-
- /**
- * Indicates whether or not to instrument all files regardless of timestamp
- */
- // can't be explicitly set, is set if control file exists and is newer than any source file
- private boolean instrumentall = false;
-
- /**
- * Indicates the name of a properties file (intentionally for iControl)
- * where the classpath property should be updated.
- */
- private boolean updateIcontrol = false;
-
- /**
- * Regular compilation class root
- */
- private File classDir = null;
-
- /**
- * Sets the build directory for instrumented classes
- *
- * @param buildDir the build directory
- */
- public void setBuilddir( File buildDir )
- {
- this.buildDir = buildDir;
- }
-
- /**
- * Sets the class directory (uninstrumented classes)
- *
- * @param classDir The new Classdir value
- */
- public void setClassdir( File classDir )
- {
- this.classDir = classDir;
- }
-
- /**
- * Sets the classpath to be used for invocation of iContract.
- *
- * @param path The new Classpath value
- * @path the classpath
- */
- public void setClasspath( Path path )
- {
- createClasspath().append( path );
- }
-
- /**
- * Sets the control file to pass to iContract.
- *
- * @param controlFile the control file
- */
- public void setControlfile( File controlFile )
- {
- if( !controlFile.exists() )
- {
- getContext().info( "WARNING: Control file " + controlFile.getAbsolutePath() + " doesn't exist. iContract will be run without control file." );
- }
- this.controlFile = controlFile;
- }
-
- /**
- * Sets the Throwable (Exception) to be thrown on assertion violation
- *
- * @param clazz the fully qualified Throwable class name
- */
- public void setFailthrowable( String clazz )
- {
- this.failThrowable = clazz;
- }
-
- /**
- * Sets the instrumentation directory
- *
- * @param instrumentDir the source directory
- */
- public void setInstrumentdir( File instrumentDir )
- {
- this.instrumentDir = instrumentDir;
- if( this.buildDir == null )
- {
- setBuilddir( instrumentDir );
- }
- }
-
- /**
- * Turns on/off invariant instrumentation
- *
- * @param invariant true turns it on
- */
- public void setInvariant( boolean invariant )
- {
- this.invariant = invariant;
- invariantModified = true;
- }
-
- /**
- * Turns on/off postcondition instrumentation
- *
- * @param post true turns it on
- */
- public void setPost( boolean post )
- {
- this.post = post;
- postModified = true;
- }
-
- /**
- * Turns on/off precondition instrumentation
- *
- * @param pre true turns it on
- */
- public void setPre( boolean pre )
- {
- this.pre = pre;
- preModified = true;
- }
-
- /**
- * Tells iContract to be quiet.
- *
- * @param quiet true if iContract should be quiet.
- */
- public void setQuiet( boolean quiet )
- {
- this.quiet = quiet;
- }
-
- /**
- * Sets the build directory for instrumented classes
- *
- * @param repBuildDir The new Repbuilddir value
- */
- public void setRepbuilddir( File repBuildDir )
- {
- this.repBuildDir = repBuildDir;
- }
-
- /**
- * Sets the build directory for repository classes
- *
- * @param repositoryDir the source directory
- */
- public void setRepositorydir( File repositoryDir )
- {
- this.repositoryDir = repositoryDir;
- if( this.repBuildDir == null )
- {
- setRepbuilddir( repositoryDir );
- }
- }
-
- /**
- * Sets the source directory
- *
- * @param srcDir the source directory
- */
- public void setSrcdir( File srcDir )
- {
- this.srcDir = srcDir;
- }
-
- /**
- * Sets the name of the file where targets will be written. That is the file
- * that tells iContract what files to process.
- *
- * @param targets the targets file name
- */
- public void setTargets( File targets )
- {
- this.targets = targets;
- }
-
- /**
- * Decides whether or not to update iControl properties file
- *
- * @param updateIcontrol true if iControl properties file should be updated
- */
- public void setUpdateicontrol( boolean updateIcontrol )
- {
- this.updateIcontrol = updateIcontrol;
- }
-
- /**
- * Sets the verbosity level of iContract. Any combination of
- * error*,warning*,note*,info*,progress*,debug* (comma separated) can be
- * used. Defaults to error*,warning*
- *
- * @param verbosity verbosity level
- */
- public void setVerbosity( String verbosity )
- {
- this.verbosity = verbosity;
- }
-
- /**
- * Creates a nested classpath element
- *
- * @return the nested classpath element
- */
- public Path createClasspath()
- {
- if( classpath == null )
- {
- classpath = new Path();
- }
- return classpath;
- }
-
- /**
- * Executes the task
- *
- * @exception org.apache.myrmidon.api.TaskException if the instrumentation fails
- */
- public void execute()
- throws TaskException
- {
- preconditions();
- scan();
- if( dirty )
- {
-
- // turn off assertions if we're using controlfile, unless they are not explicitly set.
- boolean useControlFile = ( controlFile != null ) && controlFile.exists();
- if( useControlFile && !preModified )
- {
- pre = false;
- }
- if( useControlFile && !postModified )
- {
- post = false;
- }
- if( useControlFile && !invariantModified )
- {
- invariant = false;
- }
- // issue warning if pre,post or invariant is used together with controlfile
- if( ( pre || post || invariant ) && controlFile != null )
- {
- getContext().info( "WARNING: specifying pre,post or invariant will override control file settings" );
- }
-
-
- // We want to be notified if iContract jar is missing. This makes life easier for the user
- // who didn't understand that iContract is a separate library (duh!)
-
- //addProjectListener( new IContractPresenceDetector() );
-
- // Prepare the directories for iContract. iContract will make them if they
- // don't exist, but for some reason I don't know, it will complain about the REP files
- // afterwards
- instrumentDir.mkdirs();
- buildDir.mkdirs();
- repositoryDir.mkdirs();
-
- // Set the classpath that is needed for regular Javac compilation
- Path baseClasspath = createClasspath();
-
- // Might need to add the core classes if we're not using Sun's Javac (like Jikes)
- String compiler = getContext().getProperty( "build.compiler" ).toString();
- ClasspathHelper classpathHelper = new ClasspathHelper( compiler );
- classpathHelper.modify( baseClasspath );
-
- // Create the classpath required to compile the sourcefiles BEFORE instrumentation
- Path beforeInstrumentationClasspath = ( (Path)baseClasspath.clone() );
- beforeInstrumentationClasspath.append( new Path( srcDir.getAbsolutePath() ) );
-
- // Create the classpath required to compile the sourcefiles AFTER instrumentation
- Path afterInstrumentationClasspath = ( (Path)baseClasspath.clone() );
- afterInstrumentationClasspath.append( new Path( instrumentDir.getAbsolutePath() ) );
- afterInstrumentationClasspath.append( new Path( repositoryDir.getAbsolutePath() ) );
- afterInstrumentationClasspath.append( new Path( srcDir.getAbsolutePath() ) );
- afterInstrumentationClasspath.append( new Path( buildDir.getAbsolutePath() ) );
-
- // Create the classpath required to automatically compile the repository files
- Path repositoryClasspath = ( (Path)baseClasspath.clone() );
- repositoryClasspath.append( new Path( instrumentDir.getAbsolutePath() ) );
- repositoryClasspath.append( new Path( srcDir.getAbsolutePath() ) );
- repositoryClasspath.append( new Path( repositoryDir.getAbsolutePath() ) );
- repositoryClasspath.append( new Path( buildDir.getAbsolutePath() ) );
-
- // Create the classpath required for iContract itself
- Path iContractClasspath = ( (Path)baseClasspath.clone() );
- iContractClasspath.append( new Path( System.getProperty( "java.home" ) + File.separator + ".." + File.separator + "lib" + File.separator + "tools.jar" ) );
- iContractClasspath.append( new Path( srcDir.getAbsolutePath() ) );
- iContractClasspath.append( new Path( repositoryDir.getAbsolutePath() ) );
- iContractClasspath.append( new Path( instrumentDir.getAbsolutePath() ) );
- iContractClasspath.append( new Path( buildDir.getAbsolutePath() ) );
-
- // Create a forked java process
- Java iContract = null;//(Java)getProject().createTask( "java" );
- iContract.setFork( true );
- iContract.setClassname( "com.reliablesystems.iContract.Tool" );
- iContract.setClasspath( iContractClasspath );
-
- // Build the arguments to iContract
- StringBuffer args = new StringBuffer();
- args.append( directiveString() );
- args.append( "-v" ).append( verbosity ).append( " " );
- args.append( "-b" ).append( "\"" ).append( icCompiler ).append( " -classpath " ).append( beforeInstrumentationClasspath ).append( "\" " );
- args.append( "-c" ).append( "\"" ).append( icCompiler ).append( " -classpath " ).append( afterInstrumentationClasspath ).append( " -d " ).append( buildDir ).append( "\" " );
- args.append( "-n" ).append( "\"" ).append( icCompiler ).append( " -classpath " ).append( repositoryClasspath ).append( "\" " );
- args.append( "-d" ).append( failThrowable ).append( " " );
- args.append( "-o" ).append( instrumentDir ).append( File.separator ).append( "@p" ).append( File.separator ).append( "@f.@e " );
- args.append( "-k" ).append( repositoryDir ).append( File.separator ).append( "@p " );
- args.append( quiet ? "-q " : "" );
- args.append( instrumentall ? "-a " : "" );// reinstrument everything if controlFile exists and is newer than any class
- args.append( "@" ).append( targets.getAbsolutePath() );
- iContract.createArg().setLine( args.toString() );
-
- //System.out.println( "JAVA -classpath " + iContractClasspath + " com.reliablesystems.iContract.Tool " + args.toString() );
-
- // update iControlProperties if it's set.
- if( updateIcontrol )
- {
- Properties iControlProps = new Properties();
- try
- {// to read existing propertiesfile
- iControlProps.load( new FileInputStream( "icontrol.properties" ) );
- }
- catch( IOException e )
- {
- getContext().info( "File icontrol.properties not found. That's ok. Writing a default one." );
- }
- iControlProps.setProperty( "sourceRoot", srcDir.getAbsolutePath() );
- iControlProps.setProperty( "classRoot", classDir.getAbsolutePath() );
- iControlProps.setProperty( "classpath", afterInstrumentationClasspath.toString() );
- iControlProps.setProperty( "controlFile", controlFile.getAbsolutePath() );
- iControlProps.setProperty( "targetsFile", targets.getAbsolutePath() );
-
- try
- {// to read existing propertiesfile
- iControlProps.store( new FileOutputStream( "icontrol.properties" ), ICONTROL_PROPERTIES_HEADER );
- getContext().info( "Updated icontrol.properties" );
- }
- catch( IOException e )
- {
- getContext().info( "Couldn't write icontrol.properties." );
- }
- }
-
- // do it!
- int result = iContract.executeJava();
- if( result != 0 )
- {
- if( iContractMissing )
- {
- getContext().info( "iContract can't be found on your classpath. Your classpath is:" );
- getContext().info( classpath.toString() );
- getContext().info( "If you don't have the iContract jar, go get it at http://www.reliable-systems.com/tools/" );
- }
- throw new TaskException( "iContract instrumentation failed. Code=" + result );
- }
-
- }
- else
- {// not dirty
- //log( "Nothing to do. Everything up to date." );
- }
- }
-
- /**
- * Creates the -m option based on the values of controlFile, pre, post and
- * invariant.
- *
- * @return Description of the Returned Value
- */
- private final String directiveString()
- {
- StringBuffer sb = new StringBuffer();
- boolean comma = false;
-
- boolean useControlFile = ( controlFile != null ) && controlFile.exists();
- if( useControlFile || pre || post || invariant )
- {
- sb.append( "-m" );
- }
- if( useControlFile )
- {
- sb.append( "@" ).append( controlFile );
- comma = true;
- }
- if( pre )
- {
- if( comma )
- {
- sb.append( "," );
- }
- sb.append( "pre" );
- comma = true;
- }
- if( post )
- {
- if( comma )
- {
- sb.append( "," );
- }
- sb.append( "post" );
- comma = true;
- }
- if( invariant )
- {
- if( comma )
- {
- sb.append( "," );
- }
- sb.append( "inv" );
- }
- sb.append( " " );
- return sb.toString();
- }
-
- /**
- * Checks that the required attributes are set.
- *
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- private void preconditions()
- throws TaskException
- {
- if( srcDir == null )
- {
- throw new TaskException( "srcdir attribute must be set!" );
- }
- if( !srcDir.exists() )
- {
- throw new TaskException( "srcdir \"" + srcDir.getPath() + "\" does not exist!" );
- }
- if( instrumentDir == null )
- {
- throw new TaskException( "instrumentdir attribute must be set!" );
- }
- if( repositoryDir == null )
- {
- throw new TaskException( "repositorydir attribute must be set!" );
- }
- if( updateIcontrol == true && classDir == null )
- {
- throw new TaskException( "classdir attribute must be specified when updateicontrol=true!" );
- }
- if( updateIcontrol == true && controlFile == null )
- {
- throw new TaskException( "controlfile attribute must be specified when updateicontrol=true!" );
- }
- }
-
- /**
- * Verifies whether any of the source files have changed. Done by comparing
- * date of source/class files. The whole lot is "dirty" if at least one
- * source file or the control file is newer than the instrumented files. If
- * not dirty, iContract will not be executed.
- * Also creates a temporary file with a list of the source files, that will
- * be deleted upon exit.
- *
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- private void scan()
- throws TaskException
- {
- long now = ( new Date() ).getTime();
-
- DirectoryScanner ds = null;
-
- ds = getDirectoryScanner( srcDir );
- String[] files = ds.getIncludedFiles();
-
- FileOutputStream targetOutputStream = null;
- PrintStream targetPrinter = null;
- boolean writeTargets = false;
- try
- {
- if( targets == null )
- {
- targets = new File( "targets" );
- getContext().info( "Warning: targets file not specified. generating file: " + targets.getName() );
- writeTargets = true;
- }
- else if( !targets.exists() )
- {
- getContext().info( "Specified targets file doesn't exist. generating file: " + targets.getName() );
- writeTargets = true;
- }
- if( writeTargets )
- {
- getContext().info( "You should consider using iControl to create a target file." );
- targetOutputStream = new FileOutputStream( targets );
- targetPrinter = new PrintStream( targetOutputStream );
- }
- for( int i = 0; i < files.length; i++ )
- {
- File srcFile = new File( srcDir, files[ i ] );
- if( files[ i ].endsWith( ".java" ) )
- {
- // print the target, while we're at here. (Only if generatetarget=true).
- if( targetPrinter != null )
- {
- targetPrinter.println( srcFile.getAbsolutePath() );
- }
- File classFile = new File( buildDir, files[ i ].substring( 0, files[ i ].indexOf( ".java" ) ) + ".class" );
-
- if( srcFile.lastModified() > now )
- {
- final String message = "Warning: file modified in the future: " + files[ i ];
- getContext().warn( message );
- }
-
- if( !classFile.exists() || srcFile.lastModified() > classFile.lastModified() )
- {
- //log( "Found a file newer than the instrumentDir class file: " + srcFile.getPath() + " newer than " + classFile.getPath() + ". Running iContract again..." );
- dirty = true;
- }
- }
- }
- if( targetPrinter != null )
- {
- targetPrinter.flush();
- targetPrinter.close();
- }
- }
- catch( IOException e )
- {
- throw new TaskException( "Could not create target file:" + e.getMessage() );
- }
-
- // also, check controlFile timestamp
- long controlFileTime = -1;
- try
- {
- if( controlFile != null )
- {
- if( controlFile.exists() && buildDir.exists() )
- {
- controlFileTime = controlFile.lastModified();
- ds = getDirectoryScanner( buildDir );
- files = ds.getIncludedFiles();
- for( int i = 0; i < files.length; i++ )
- {
- File srcFile = new File( srcDir, files[ i ] );
- if( files[ i ].endsWith( ".class" ) )
- {
- if( controlFileTime > srcFile.lastModified() )
- {
- if( !dirty )
- {
- getContext().info( "Control file " + controlFile.getAbsolutePath() + " has been updated. Instrumenting all files..." );
- }
- dirty = true;
- instrumentall = true;
- }
- }
- }
- }
- }
- }
- catch( Throwable t )
- {
- throw new TaskException( "Got an interesting exception:" + t.getMessage() );
- }
- }
-
- /**
- * This class is a helper to set correct classpath for other compilers, like
- * Jikes. It reuses the logic from DefaultCompilerAdapter, which is
- * protected, so we have to subclass it.
- *
- * @author RT
- */
- private class ClasspathHelper extends DefaultCompilerAdapter
- {
- private final String compiler;
-
- public ClasspathHelper( String compiler )
- {
- super();
- this.compiler = compiler;
- }
-
- // dummy implementation. Never called
- public void setJavac( Javac javac )
- {
- }
-
- public boolean execute()
- {
- return true;
- }
-
- // make it public
- public void modify( Path path )
- throws TaskException
- {
- // depending on what compiler to use, set the includeJavaRuntime flag
- if( "jikes".equals( compiler ) )
- {
- icCompiler = compiler;
- m_includeJavaRuntime = true;
- path.append( getCompileClasspath() );
- }
- }
- }
-
- /**
- * BuildListener that sets the iContractMissing flag to true if a message
- * about missing iContract is missing. Used to indicate a more verbose error
- * to the user, with advice about how to solve the problem
- */
- private class IContractPresenceDetector
- extends AbstractProjectListener
- {
- /**
- * Notify listener of log message event.
- */
- public void log( final LogEvent event )
- {
- if( "java.lang.NoClassDefFoundError: com/reliablesystems/iContract/Tool".equals( event.getMessage() ) )
- {
- iContractMissing = true;
- }
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Java.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Java.java
deleted file mode 100644
index 239fd3793..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Java.java
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs;
-
-import java.io.File;
-import java.util.ArrayList;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.tools.todo.types.Argument;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.CommandlineJava;
-import org.apache.tools.todo.types.EnvironmentVariable;
-import org.apache.tools.todo.types.Path;
-
-/**
- * This task acts as a loader for java applications but allows to use the same
- * JVM for the called application thus resulting in much faster operation.
- *
- * @author Stefano Mazzocchi
- * stefano@apache.org
- * @author Stefan Bodewig
- */
-public class Java
- extends AbstractTask
-{
- private CommandlineJava m_cmdl = new CommandlineJava();
- private boolean m_fork;
- private File m_dir;
-
- /**
- * Set the class name.
- */
- public void setClassname( String s )
- {
- m_cmdl.setClassname( s );
- }
-
- /**
- * Add a classpath element.
- */
- public void addClasspath( final Path classpath )
- throws TaskException
- {
- m_cmdl.createClasspath().addPath( classpath );
- }
-
- /**
- * The working directory of the process
- *
- * @param dir The new Dir value
- */
- public void setDir( final File dir )
- {
- m_dir = dir;
- }
-
- /**
- * Set the forking flag.
- */
- public void setFork( final boolean fork )
- {
- m_fork = fork;
- }
-
- /**
- * set the jar name...
- */
- public void setJar( final File jar )
- {
- m_cmdl.setJar( jar.getAbsolutePath() );
- }
-
- /**
- * Set the command used to start the VM (only if fork==false).
- */
- public void setJvm( final String jvm )
- {
- m_cmdl.setVm( jvm );
- }
-
- /**
- * -mx or -Xmx depending on VM version
- */
- public void setMaxmemory( final String max )
- {
- m_cmdl.setMaxmemory( max );
- }
-
- /**
- * Add a nested sysproperty element.
- */
- public void addSysproperty( final EnvironmentVariable sysp )
- {
- m_cmdl.addSysproperty( sysp );
- }
-
- /**
- * Creates a nested arg element.
- */
- public void addArg( final Argument argument )
- {
- m_cmdl.addArgument( argument );
- }
-
- /**
- * Creates a nested jvmarg element.
- */
- public void addJvmarg( final Argument argument )
- {
- m_cmdl.addVmArgument( argument );
- }
-
- public void execute()
- throws TaskException
- {
- final int err = executeJava();
- if( 0 != err )
- {
- throw new TaskException( "Java returned: " + err );
- }
- }
-
- /**
- * Do the execution and return a return code.
- *
- * @return the return code from the execute java class if it was executed in
- * a separate VM (fork = "yes").
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public int executeJava()
- throws TaskException
- {
- final String classname = m_cmdl.getClassname();
- final String jar = m_cmdl.getJar();
- if( classname != null && jar != null )
- {
- throw new TaskException( "Only one of Classname and Jar can be set." );
- }
- else if( classname == null && jar == null )
- {
- throw new TaskException( "Classname must not be null." );
- }
-
- if( !m_fork && jar != null )
- {
- throw new TaskException( "Cannot execute a jar in non-forked mode. Please set fork='true'. " );
- }
-
- if( m_fork )
- {
- getContext().debug( "Forking " + m_cmdl.toString() );
-
- return run( new Commandline( m_cmdl.getCommandline() ) );
- }
- else
- {
- if( m_cmdl.getVmCommand().size() > 1 )
- {
- getContext().warn( "JVM args ignored when same JVM is used." );
- }
- if( m_dir != null )
- {
- getContext().warn( "Working directory ignored when same JVM is used." );
- }
-
- getContext().debug( "Running in same VM " + m_cmdl.getJavaCommand().toString() );
- run( m_cmdl );
- return 0;
- }
- }
-
- /**
- * Executes the given classname with the given arguments as it was a command
- * line application.
- */
- protected void run( final String classname, final ArrayList args )
- throws TaskException
- {
- final CommandlineJava java = new CommandlineJava();
- java.setClassname( classname );
-
- final int size = args.size();
- for( int i = 0; i < size; i++ )
- {
- final String arg = (String)args.get( i );
- java.addArgument( arg );
- }
- run( java );
- }
-
- /**
- * Executes the given classname with the given arguments as it was a command
- * line application.
- */
- private void run( final CommandlineJava command )
- throws TaskException
- {
- final ExecuteJava exe = new ExecuteJava();
- exe.setJavaCommand( command.getJavaCommand() );
- exe.setClasspath( command.getClasspath() );
- exe.setSystemProperties( command.getSystemProperties() );
- exe.execute();
- }
-
- /**
- * Executes the given classname with the given arguments in a separate VM.
- */
- private int run( final Commandline command )
- throws TaskException
- {
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
-
- if( m_dir == null )
- {
- m_dir = getBaseDirectory();
- }
- else if( !m_dir.exists() || !m_dir.isDirectory() )
- {
- final String message = m_dir.getAbsolutePath() + " is not a valid directory";
- throw new TaskException( message );
- }
-
- exe.setWorkingDirectory( m_dir );
- exe.setCommandline( command );
- return exe.execute();
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Javah.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Javah.java
deleted file mode 100644
index 25f61b229..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Javah.java
+++ /dev/null
@@ -1,357 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.StringTokenizer;
-import org.apache.avalon.excalibur.util.StringUtil;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.util.FileUtils;
-import org.apache.tools.todo.taskdefs.ClassArgument;
-
-/**
- * Task to generate JNI header files using javah. This task can take the
- * following arguments:
- *
- * classname - the fully-qualified name of a class
- * outputFile - Concatenates the resulting header or source files for all
- * the classes listed into this file
- * destdir - Sets the directory where javah saves the header files or the
- * stub files
- * classpath
- * bootclasspath
- * force - Specifies that output files should always be written (JDK1.2
- * only)
- * old - Specifies that old JDK1.0-style header files should be generated
- * (otherwise output file contain JNI-style native method function prototypes)
- * (JDK1.2 only)
- * stubs - generate C declarations from the Java object file (used with
- * old)
- * verbose - causes javah to print a message to stdout concerning the
- * status of the generated files
- * extdirs - Override location of installed extensions
- *
- * Of these arguments, either outputFile or destdir is required,
- * but not both. More than one classname may be specified, using a
- * comma-separated list or by using <class name="xxx">
- * elements within the task.
- *
- * When this task executes, it will generate C header and source files that are
- * needed to implement native methods.
- *
- * @author Rick Beton
- * richard.beton@physics.org
- */
-
-public class Javah
- extends AbstractTask
-{
- private final static String FAIL_MSG = "Compile failed, messages should have been provided.";
-
- private ArrayList m_classes = new ArrayList( 2 );
- private Path m_classpath;
- private File m_outputFile;
- private boolean m_verbose;
- private boolean m_force;
- private boolean m_old;
- private boolean m_stubs;
- private Path m_bootclasspath;
- private String m_cls;
- private File m_destDir;
-
- /**
- * Adds an element to the bootclasspath.
- */
- public void addBootclasspath( final Path bootclasspath )
- {
- if( m_bootclasspath == null )
- {
- m_bootclasspath = bootclasspath;
- }
- else
- {
- m_bootclasspath.addPath( bootclasspath );
- }
- }
-
- public void setClass( final String cls )
- {
- m_cls = cls;
- }
-
- /**
- * Adds an element to the classpath.
- */
- public void addClasspath( final Path classpath )
- throws TaskException
- {
- if( m_classpath == null )
- {
- m_classpath = classpath;
- }
- else
- {
- m_classpath.addPath( classpath );
- }
- }
-
- /**
- * Set the destination directory into which the Java source files should be
- * compiled.
- *
- * @param destDir The new Destdir value
- */
- public void setDestdir( final File destDir )
- {
- m_destDir = destDir;
- }
-
- /**
- * Set the force-write flag.
- */
- public void setForce( final boolean force )
- {
- m_force = force;
- }
-
- /**
- * Set the old flag.
- */
- public void setOld( final boolean old )
- {
- m_old = old;
- }
-
- /**
- * Set the output file name.
- */
- public void setOutputFile( final File outputFile )
- {
- m_outputFile = outputFile;
- }
-
- /**
- * Set the stubs flag.
- */
- public void setStubs( final boolean stubs )
- {
- m_stubs = stubs;
- }
-
- /**
- * Set the verbose flag.
- */
- public void setVerbose( final boolean verbose )
- {
- m_verbose = verbose;
- }
-
- public ClassArgument createClass()
- {
- final ClassArgument ga = new ClassArgument();
- m_classes.add( ga );
- return ga;
- }
-
- /**
- * Executes the task.
- */
- public void execute()
- throws TaskException
- {
- validate();
- doClassicCompile();
- }
-
- private void validate() throws TaskException
- {
- if( ( m_cls == null ) && ( m_classes.size() == 0 ) )
- {
- final String message = "class attribute must be set!";
- throw new TaskException( message );
- }
-
- if( ( m_cls != null ) && ( m_classes.size() > 0 ) )
- {
- final String message = "set class attribute or class element, not both.";
- throw new TaskException( message );
- }
-
- if( m_destDir != null )
- {
- if( !m_destDir.isDirectory() )
- {
- final String message = "destination directory \"" + m_destDir +
- "\" does not exist or is not a directory";
- throw new TaskException( message );
- }
- if( m_outputFile != null )
- {
- final String message = "destdir and outputFile are mutually exclusive";
- throw new TaskException( message );
- }
- }
- }
-
- /**
- * Logs the compilation parameters, adds the files to compile and logs the
- * &qout;niceSourceList"
- */
- private void logAndAddFilesToCompile( final Commandline cmd )
- {
- int n = 0;
- getContext().debug( "Compilation args: " + cmd.toString() );
-
- StringBuffer niceClassList = new StringBuffer();
- if( m_cls != null )
- {
- final StringTokenizer tok = new StringTokenizer( m_cls, ",", false );
- while( tok.hasMoreTokens() )
- {
- final String aClass = tok.nextToken().trim();
- cmd.addArgument( aClass );
- niceClassList.append( " " + aClass + StringUtil.LINE_SEPARATOR );
- n++;
- }
- }
-
- final Iterator enum = m_classes.iterator();
- while( enum.hasNext() )
- {
- final ClassArgument arg = (ClassArgument)enum.next();
- final String aClass = arg.getName();
- cmd.addArgument( aClass );
- niceClassList.append( " " + aClass + StringUtil.LINE_SEPARATOR );
- n++;
- }
-
- final StringBuffer prefix = new StringBuffer( "Class" );
- if( n > 1 )
- {
- prefix.append( "es" );
- }
- prefix.append( " to be compiled:" );
- prefix.append( StringUtil.LINE_SEPARATOR );
-
- getContext().debug( prefix.toString() + niceClassList.toString() );
- }
-
- /**
- * Does the command line argument processing common to classic and modern.
- */
- private Commandline setupJavahCommand()
- throws TaskException
- {
- final Commandline cmd = new Commandline();
-
- if( m_destDir != null )
- {
- cmd.addArgument( "-d" );
- cmd.addArgument( m_destDir );
- }
-
- if( m_outputFile != null )
- {
- cmd.addArgument( "-o" );
- cmd.addArgument( m_outputFile );
- }
-
- if( m_classpath != null )
- {
- cmd.addArgument( "-classpath" );
- cmd.addArguments( FileUtils.translateCommandline( m_classpath ) );
- }
-
- if( m_verbose )
- {
- cmd.addArgument( "-verbose" );
- }
- if( m_old )
- {
- cmd.addArgument( "-old" );
- }
- if( m_force )
- {
- cmd.addArgument( "-force" );
- }
-
- if( m_stubs )
- {
- if( !m_old )
- {
- final String message = "stubs only available in old mode.";
- throw new TaskException( message );
- }
- cmd.addArgument( "-stubs" );
- }
- if( m_bootclasspath != null )
- {
- cmd.addArgument( "-bootclasspath" );
- cmd.addArguments( FileUtils.translateCommandline( m_bootclasspath ) );
- }
-
- logAndAddFilesToCompile( cmd );
- return cmd;
- }
-
- /**
- * Peforms a compile using the classic compiler that shipped with JDK 1.1
- * and 1.2.
- *
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
-
- private void doClassicCompile()
- throws TaskException
- {
- Commandline cmd = setupJavahCommand();
-
- // Use reflection to be able to build on all JDKs
- /*
- * / provide the compiler a different message sink - namely our own
- * sun.tools.javac.Main compiler =
- * new sun.tools.javac.Main(new LogOutputStream(this, Project.MSG_WARN), "javac");
- * if (!compiler.compile(cmd.getArguments())) {
- * throw new TaskException("Compile failed");
- * }
- */
- try
- {
- // Javac uses logstr to change the output stream and calls
- // the constructor's invoke method to create a compiler instance
- // dynamically. However, javah has a different interface and this
- // makes it harder, so here's a simple alternative.
- //------------------------------------------------------------------
- com.sun.tools.javah.Main main = new com.sun.tools.javah.Main( cmd.getArguments() );
- main.run();
- }
- //catch (ClassNotFoundException ex) {
- // throw new TaskException("Cannot use javah because it is not available"+
- // " A common solution is to set the environment variable"+
- // " JAVA_HOME to your jdk directory.", location);
- //}
- catch( Exception ex )
- {
- if( ex instanceof TaskException )
- {
- throw (TaskException)ex;
- }
- else
- {
- throw new TaskException( "Error starting javah: ", ex );
- }
- }
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/MatchingTask.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/MatchingTask.java
deleted file mode 100644
index 06c627fbd..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/MatchingTask.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs;
-
-import java.io.File;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.Pattern;
-import org.apache.myrmidon.framework.PatternSet;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.ScannerUtil;
-
-/**
- * This is an abstract task that should be used by all those tasks that require
- * to include or exclude files based on pattern matching.
- *
- * @author Arnout J. Kuiper
- * @author Stefano Mazzocchi
- * @author Sam Ruby
- * @author Jon S. Stevens
- * @author Stefan Bodewig
- */
-public abstract class MatchingTask
- extends AbstractTask
-{
- private FileSet m_fileset = new FileSet();
-
- /**
- * Sets whether default exclusions should be used or not.
- */
- public void setDefaultexcludes( final boolean useDefaultExcludes )
- {
- m_fileset.setDefaultExcludes( useDefaultExcludes );
- }
-
- /**
- * Sets the set of exclude patterns. Patterns may be separated by a comma or
- * a space.
- *
- * @param excludes the string containing the exclude patterns
- */
- public void setExcludes( final String excludes )
- {
- m_fileset.setExcludes( excludes );
- }
-
- /**
- * Sets the set of include patterns. Patterns may be separated by a comma or
- * a space.
- *
- * @param includes the string containing the include patterns
- */
- public void setIncludes( final String includes )
- {
- m_fileset.setIncludes( includes );
- }
-
- /**
- * add a name entry on the exclude list
- */
- public void addExclude( final Pattern pattern )
- {
- m_fileset.addExclude( pattern );
- }
-
- /**
- * add a name entry on the include list
- */
- public void addInclude( final Pattern pattern )
- throws TaskException
- {
- m_fileset.addInclude( pattern );
- }
-
- /**
- * add a set of patterns
- */
- public void addPatternSet( final PatternSet set )
- {
- m_fileset.addPatternSet( set );
- }
-
- /**
- * Returns the directory scanner needed to access the files to process.
- *
- * @param baseDir Description of Parameter
- * @return The DirectoryScanner value
- */
- protected DirectoryScanner getDirectoryScanner( final File baseDir )
- throws TaskException
- {
- m_fileset.setDir( baseDir );
- return ScannerUtil.getDirectoryScanner( m_fileset );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/NetRexxC.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/NetRexxC.java
deleted file mode 100644
index e99b66290..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/NetRexxC.java
+++ /dev/null
@@ -1,770 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.StringTokenizer;
-import netrexx.lang.Rexx;
-import org.apache.avalon.excalibur.io.FileUtil;
-import org.apache.avalon.excalibur.util.StringUtil;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.taskdefs.MatchingTask;
-import org.apache.tools.todo.types.DirectoryScanner;
-
-/**
- * Task to compile NetRexx source files. This task can take the following
- * arguments:
- *
- * binary
- * classpath
- * comments
- * compile
- * console
- * crossref
- * decimal
- * destdir
- * diag
- * explicit
- * format
- * keep
- * logo
- * replace
- * savelog
- * srcdir
- * sourcedir
- * strictargs
- * strictassign
- * strictcase
- * strictimport
- * symbols
- * time
- * trace
- * utf8
- * verbose
- *
- * Of these arguments, the srcdir argument is required.
- *
- * When this task executes, it will recursively scan the srcdir looking for
- * NetRexx source files to compile. This task makes its compile decision based
- * on timestamp.
- *
- * Before files are compiled they and any other file in the srcdir will be
- * copied to the destdir allowing support files to be located properly in the
- * classpath. The reason for copying the source files before the compile is that
- * NetRexxC has only two destinations for classfiles:
- *
- * The current directory, and,
- * The directory the source is in (see sourcedir option)
- *
- *
- *
- * @author dIon Gillard
- * dion@multitask.com.au
- */
-
-public class NetRexxC extends MatchingTask
-{
- private boolean compile = true;
- private boolean decimal = true;
- private boolean logo = true;
- private boolean sourcedir = true;
- private String trace = "trace2";
- private String verbose = "verbose3";
-
- // other implementation variables
- private ArrayList compileList = new ArrayList();
- private Hashtable filecopyList = new Hashtable();
- private String oldClasspath = System.getProperty( "java.class.path" );
-
- // variables to hold arguments
- private boolean binary;
- private String classpath;
- private boolean comments;
- private boolean compact;
- private boolean console;
- private boolean crossref;
- private File destDir;
- private boolean diag;
- private boolean explicit;
- private boolean format;
- private boolean java;
- private boolean keep;
- private boolean replace;
- private boolean savelog;
- private File srcDir;// ?? Should this be the default for ant?
- private boolean strictargs;
- private boolean strictassign;
- private boolean strictcase;
- private boolean strictimport;
- private boolean strictprops;
- private boolean strictsignal;
- private boolean symbols;
- private boolean time;
- private boolean utf8;
-
- /**
- * Set whether literals are treated as binary, rather than NetRexx types
- *
- * @param binary The new Binary value
- */
- public void setBinary( boolean binary )
- {
- this.binary = binary;
- }
-
- /**
- * Set the classpath used for NetRexx compilation
- *
- * @param classpath The new Classpath value
- */
- public void setClasspath( String classpath )
- {
- this.classpath = classpath;
- }
-
- /**
- * Set whether comments are passed through to the generated java source.
- * Valid true values are "on" or "true". Anything else sets the flag to
- * false. The default value is false
- *
- * @param comments The new Comments value
- */
- public void setComments( boolean comments )
- {
- this.comments = comments;
- }
-
- /**
- * Set whether error messages come out in compact or verbose format. Valid
- * true values are "on" or "true". Anything else sets the flag to false. The
- * default value is false
- *
- * @param compact The new Compact value
- */
- public void setCompact( boolean compact )
- {
- this.compact = compact;
- }
-
- /**
- * Set whether the NetRexx compiler should compile the generated java code
- * Valid true values are "on" or "true". Anything else sets the flag to
- * false. The default value is true. Setting this flag to false, will
- * automatically set the keep flag to true.
- *
- * @param compile The new Compile value
- */
- public void setCompile( boolean compile )
- {
- this.compile = compile;
- if( !this.compile && !this.keep )
- {
- this.keep = true;
- }
- }
-
- /**
- * Set whether or not messages should be displayed on the 'console' Valid
- * true values are "on" or "true". Anything else sets the flag to false. The
- * default value is true.
- *
- * @param console The new Console value
- */
- public void setConsole( boolean console )
- {
- this.console = console;
- }
-
- /**
- * Whether variable cross references are generated
- *
- * @param crossref The new Crossref value
- */
- public void setCrossref( boolean crossref )
- {
- this.crossref = crossref;
- }
-
- /**
- * Set whether decimal arithmetic should be used for the netrexx code.
- * Binary arithmetic is used when this flag is turned off. Valid true values
- * are "on" or "true". Anything else sets the flag to false. The default
- * value is true.
- *
- * @param decimal The new Decimal value
- */
- public void setDecimal( boolean decimal )
- {
- this.decimal = decimal;
- }
-
- /**
- * Set the destination directory into which the NetRexx source files should
- * be copied and then compiled.
- *
- * @param destDirName The new DestDir value
- */
- public void setDestDir( File destDirName )
- {
- destDir = destDirName;
- }
-
- /**
- * Whether diagnostic information about the compile is generated
- *
- * @param diag The new Diag value
- */
- public void setDiag( boolean diag )
- {
- this.diag = diag;
- }
-
- /**
- * Sets whether variables must be declared explicitly before use. Valid true
- * values are "on" or "true". Anything else sets the flag to false. The
- * default value is false.
- *
- * @param explicit The new Explicit value
- */
- public void setExplicit( boolean explicit )
- {
- this.explicit = explicit;
- }
-
- /**
- * Whether the generated java code is formatted nicely or left to match
- * NetRexx line numbers for call stack debugging
- *
- * @param format The new Format value
- */
- public void setFormat( boolean format )
- {
- this.format = format;
- }
-
- /**
- * Whether the generated java code is produced Valid true values are "on" or
- * "true". Anything else sets the flag to false. The default value is false.
- *
- * @param java The new Java value
- */
- public void setJava( boolean java )
- {
- this.java = java;
- }
-
- /**
- * Sets whether the generated java source file should be kept after
- * compilation. The generated files will have an extension of .java.keep,
- * not .java Valid true values are "on" or "true". Anything else sets
- * the flag to false. The default value is false.
- *
- * @param keep The new Keep value
- */
- public void setKeep( boolean keep )
- {
- this.keep = keep;
- }
-
- /**
- * Whether the compiler text logo is displayed when compiling
- *
- * @param logo The new Logo value
- */
- public void setLogo( boolean logo )
- {
- this.logo = logo;
- }
-
- /**
- * Whether the generated .java file should be replaced when compiling Valid
- * true values are "on" or "true". Anything else sets the flag to false. The
- * default value is false.
- *
- * @param replace The new Replace value
- */
- public void setReplace( boolean replace )
- {
- this.replace = replace;
- }
-
- /**
- * Sets whether the compiler messages will be written to NetRexxC.log as
- * well as to the console Valid true values are "on" or "true". Anything
- * else sets the flag to false. The default value is false.
- *
- * @param savelog The new Savelog value
- */
- public void setSavelog( boolean savelog )
- {
- this.savelog = savelog;
- }
-
- /**
- * Tells the NetRexx compiler to store the class files in the same directory
- * as the source files. The alternative is the working directory Valid true
- * values are "on" or "true". Anything else sets the flag to false. The
- * default value is true.
- *
- * @param sourcedir The new Sourcedir value
- */
- public void setSourcedir( boolean sourcedir )
- {
- this.sourcedir = sourcedir;
- }
-
- /**
- * Set the source dir to find the source Java files.
- *
- * @param srcDirName The new SrcDir value
- */
- public void setSrcDir( File srcDirName )
- {
- srcDir = srcDirName;
- }
-
- /**
- * Tells the NetRexx compiler that method calls always need parentheses,
- * even if no arguments are needed, e.g. aStringVar.getBytes
- * vs. aStringVar.getBytes()
Valid true values are "on" or
- * "true". Anything else sets the flag to false. The default value is false.
- *
- * @param strictargs The new Strictargs value
- */
- public void setStrictargs( boolean strictargs )
- {
- this.strictargs = strictargs;
- }
-
- /**
- * Tells the NetRexx compile that assignments must match exactly on type
- *
- * @param strictassign The new Strictassign value
- */
- public void setStrictassign( boolean strictassign )
- {
- this.strictassign = strictassign;
- }
-
- /**
- * Specifies whether the NetRexx compiler should be case sensitive or not
- *
- * @param strictcase The new Strictcase value
- */
- public void setStrictcase( boolean strictcase )
- {
- this.strictcase = strictcase;
- }
-
- /**
- * Sets whether classes need to be imported explicitly using an import
- * statement. By default the NetRexx compiler will import certain packages
- * automatically Valid true values are "on" or "true". Anything else sets
- * the flag to false. The default value is false.
- *
- * @param strictimport The new Strictimport value
- */
- public void setStrictimport( boolean strictimport )
- {
- this.strictimport = strictimport;
- }
-
- /**
- * Sets whether local properties need to be qualified explicitly using
- * this
Valid true values are "on" or "true". Anything else
- * sets the flag to false. The default value is false.
- *
- * @param strictprops The new Strictprops value
- */
- public void setStrictprops( boolean strictprops )
- {
- this.strictprops = strictprops;
- }
-
- /**
- * Whether the compiler should force catching of exceptions by explicitly
- * named types
- *
- * @param strictsignal The new Strictsignal value
- */
- public void setStrictsignal( boolean strictsignal )
- {
- this.strictsignal = strictsignal;
- }
-
- /**
- * Sets whether debug symbols should be generated into the class file Valid
- * true values are "on" or "true". Anything else sets the flag to false. The
- * default value is false.
- *
- * @param symbols The new Symbols value
- */
- public void setSymbols( boolean symbols )
- {
- this.symbols = symbols;
- }
-
- /**
- * Asks the NetRexx compiler to print compilation times to the console Valid
- * true values are "on" or "true". Anything else sets the flag to false. The
- * default value is false.
- *
- * @param time The new Time value
- */
- public void setTime( boolean time )
- {
- this.time = time;
- }
-
- /**
- * Turns on or off tracing and directs the resultant trace output Valid
- * values are: "trace", "trace1", "trace2" and "notrace". "trace" and
- * "trace2"
- *
- * @param trace The new Trace value
- */
- public void setTrace( String trace )
- {
- if( trace.equalsIgnoreCase( "trace" )
- || trace.equalsIgnoreCase( "trace1" )
- || trace.equalsIgnoreCase( "trace2" )
- || trace.equalsIgnoreCase( "notrace" ) )
- {
- this.trace = trace;
- }
- else
- {
- throw new TaskException( "Unknown trace value specified: '" + trace + "'" );
- }
- }
-
- /**
- * Tells the NetRexx compiler that the source is in UTF8 Valid true values
- * are "on" or "true". Anything else sets the flag to false. The default
- * value is false.
- *
- * @param utf8 The new Utf8 value
- */
- public void setUtf8( boolean utf8 )
- {
- this.utf8 = utf8;
- }
-
- /**
- * Whether lots of warnings and error messages should be generated
- *
- * @param verbose The new Verbose value
- */
- public void setVerbose( String verbose )
- {
- this.verbose = verbose;
- }
-
- /**
- * Executes the task, i.e. does the actual compiler call
- *
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
-
- // first off, make sure that we've got a srcdir and destdir
- if( srcDir == null || destDir == null )
- {
- throw new TaskException( "srcDir and destDir attributes must be set!" );
- }
-
- // scan source and dest dirs to build up both copy lists and
- // compile lists
- // scanDir(srcDir, destDir);
- DirectoryScanner ds = getDirectoryScanner( srcDir );
-
- String[] files = ds.getIncludedFiles();
-
- scanDir( srcDir, destDir, files );
-
- // copy the source and support files
- copyFilesToDestination();
-
- // compile the source files
- if( compileList.size() > 0 )
- {
- getContext().info( "Compiling " + compileList.size() + " source file"
- + ( compileList.size() == 1 ? "" : "s" )
- + " to " + destDir );
- doNetRexxCompile();
- }
- }
-
- /**
- * Builds the compilation classpath.
- *
- * @return The CompileClasspath value
- */
- private String getCompileClasspath()
- throws TaskException
- {
- StringBuffer classpath = new StringBuffer();
-
- // add dest dir to classpath so that previously compiled and
- // untouched classes are on classpath
- classpath.append( destDir.getAbsolutePath() );
-
- // add our classpath to the mix
- if( this.classpath != null )
- {
- addExistingToClasspath( classpath, this.classpath );
- }
-
- // add the system classpath
- // addExistingToClasspath(classpath,System.getProperty("java.class.path"));
- return classpath.toString();
- }
-
- /**
- * This
- *
- * @return The CompileOptionsAsArray value
- */
- private String[] getCompileOptionsAsArray()
- {
- ArrayList options = new ArrayList();
- options.add( binary ? "-binary" : "-nobinary" );
- options.add( comments ? "-comments" : "-nocomments" );
- options.add( compile ? "-compile" : "-nocompile" );
- options.add( compact ? "-compact" : "-nocompact" );
- options.add( console ? "-console" : "-noconsole" );
- options.add( crossref ? "-crossref" : "-nocrossref" );
- options.add( decimal ? "-decimal" : "-nodecimal" );
- options.add( diag ? "-diag" : "-nodiag" );
- options.add( explicit ? "-explicit" : "-noexplicit" );
- options.add( format ? "-format" : "-noformat" );
- options.add( keep ? "-keep" : "-nokeep" );
- options.add( logo ? "-logo" : "-nologo" );
- options.add( replace ? "-replace" : "-noreplace" );
- options.add( savelog ? "-savelog" : "-nosavelog" );
- options.add( sourcedir ? "-sourcedir" : "-nosourcedir" );
- options.add( strictargs ? "-strictargs" : "-nostrictargs" );
- options.add( strictassign ? "-strictassign" : "-nostrictassign" );
- options.add( strictcase ? "-strictcase" : "-nostrictcase" );
- options.add( strictimport ? "-strictimport" : "-nostrictimport" );
- options.add( strictprops ? "-strictprops" : "-nostrictprops" );
- options.add( strictsignal ? "-strictsignal" : "-nostrictsignal" );
- options.add( symbols ? "-symbols" : "-nosymbols" );
- options.add( time ? "-time" : "-notime" );
- options.add( "-" + trace );
- options.add( utf8 ? "-utf8" : "-noutf8" );
- options.add( "-" + verbose );
- String[] results = new String[ options.size() ];
- options.copyInto( results );
- return results;
- }
-
- /**
- * Takes a classpath-like string, and adds each element of this string to a
- * new classpath, if the components exist. Components that don't exist,
- * aren't added. We do this, because jikes issues warnings for non-existant
- * files/dirs in his classpath, and these warnings are pretty annoying.
- *
- * @param target - target classpath
- * @param source - source classpath to get file objects.
- */
- private void addExistingToClasspath( StringBuffer target, String source )
- throws TaskException
- {
- final StringTokenizer tok = new StringTokenizer( source,
- System.getProperty( "path.separator" ), false );
- while( tok.hasMoreTokens() )
- {
- File f = getContext().resolveFile( tok.nextToken() );
-
- if( f.exists() )
- {
- target.append( File.pathSeparator );
- target.append( f.getAbsolutePath() );
- }
- else
- {
- getContext().debug( "Dropping from classpath: " + f.getAbsolutePath() );
- }
- }
-
- }
-
- /**
- * Copy eligible files from the srcDir to destDir
- */
- private void copyFilesToDestination()
- {
- //FIXME: This should be zapped no ?
- if( filecopyList.size() > 0 )
- {
- getContext().info( "Copying " + filecopyList.size() + " file"
- + ( filecopyList.size() == 1 ? "" : "s" )
- + " to " + destDir.getAbsolutePath() );
- Iterator enum = filecopyList.keySet().iterator();
- while( enum.hasNext() )
- {
- String fromFile = (String)enum.next();
- String toFile = (String)filecopyList.get( fromFile );
- try
- {
- FileUtil.copyFile( new File( fromFile ), new File( toFile ) );
- }
- catch( IOException ioe )
- {
- String msg = "Failed to copy " + fromFile + " to " + toFile
- + " due to " + ioe.getMessage();
- throw new TaskException( msg, ioe );
- }
- }
- }
- }
-
- /**
- * Peforms a copmile using the NetRexx 1.1.x compiler
- *
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- private void doNetRexxCompile()
- throws TaskException
- {
- getContext().debug( "Using NetRexx compiler" );
- String classpath = getCompileClasspath();
- StringBuffer compileOptions = new StringBuffer();
- StringBuffer fileList = new StringBuffer();
-
- // create an array of strings for input to the compiler: one array
- // comes from the compile options, the other from the compileList
- String[] compileOptionsArray = getCompileOptionsAsArray();
- String[] fileListArray = new String[ compileList.size() ];
- Iterator e = compileList.iterator();
- int j = 0;
- while( e.hasNext() )
- {
- fileListArray[ j ] = (String)e.next();
- j++;
- }
- // create a single array of arguments for the compiler
- String compileArgs[] = new String[ compileOptionsArray.length + fileListArray.length ];
- for( int i = 0; i < compileOptionsArray.length; i++ )
- {
- compileArgs[ i ] = compileOptionsArray[ i ];
- }
- for( int i = 0; i < fileListArray.length; i++ )
- {
- compileArgs[ i + compileOptionsArray.length ] = fileListArray[ i ];
- }
-
- // print nice output about what we are doing for the log
- compileOptions.append( "Compilation args: " );
- for( int i = 0; i < compileOptionsArray.length; i++ )
- {
- compileOptions.append( compileOptionsArray[ i ] );
- compileOptions.append( " " );
- }
- getContext().debug( compileOptions.toString() );
-
- StringBuffer niceSourceList = new StringBuffer( "Files to be compiled:" + StringUtil.LINE_SEPARATOR );
-
- for( int i = 0; i < compileList.size(); i++ )
- {
- niceSourceList.append( " " );
- niceSourceList.append( compileList.get( i ).toString() );
- niceSourceList.append( StringUtil.LINE_SEPARATOR );
- }
-
- getContext().debug( niceSourceList.toString() );
-
- // need to set java.class.path property and restore it later
- // since the NetRexx compiler has no option for the classpath
- String currentClassPath = System.getProperty( "java.class.path" );
- Properties currentProperties = System.getProperties();
- currentProperties.put( "java.class.path", classpath );
-
- try
- {
- StringWriter out = new StringWriter();
- int rc =
- COM.ibm.netrexx.process.NetRexxC.main( new Rexx( compileArgs ), new PrintWriter( out ) );
-
- if( rc > 1 )
- {// 1 is warnings from real NetRexxC
- getContext().error( out.toString() );
- String msg = "Compile failed, messages should have been provided.";
- throw new TaskException( msg );
- }
- else if( rc == 1 )
- {
- getContext().warn( out.toString() );
- }
- else
- {
- getContext().info( out.toString() );
- }
- }
- finally
- {
- // need to reset java.class.path property
- // since the NetRexx compiler has no option for the classpath
- currentProperties = System.getProperties();
- currentProperties.put( "java.class.path", currentClassPath );
- }
- }
-
- /**
- * Scans the directory looking for source files to be compiled and support
- * files to be copied.
- *
- * @param srcDir Description of Parameter
- * @param destDir Description of Parameter
- * @param files Description of Parameter
- */
- private void scanDir( File srcDir, File destDir, String[] files )
- {
- for( int i = 0; i < files.length; i++ )
- {
- File srcFile = new File( srcDir, files[ i ] );
- File destFile = new File( destDir, files[ i ] );
- String filename = files[ i ];
- // if it's a non source file, copy it if a later date than the
- // dest
- // if it's a source file, see if the destination class file
- // needs to be recreated via compilation
- if( filename.toLowerCase().endsWith( ".nrx" ) )
- {
- File classFile =
- new File( destDir,
- filename.substring( 0, filename.lastIndexOf( '.' ) ) + ".class" );
-
- if( !compile || srcFile.lastModified() > classFile.lastModified() )
- {
- filecopyList.put( srcFile.getAbsolutePath(), destFile.getAbsolutePath() );
- compileList.add( destFile.getAbsolutePath() );
- }
- }
- else
- {
- if( srcFile.lastModified() > destFile.lastModified() )
- {
- filecopyList.put( srcFile.getAbsolutePath(), destFile.getAbsolutePath() );
- }
- }
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/PathConvert.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/PathConvert.java
deleted file mode 100644
index 5179f53c9..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/PathConvert.java
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs;
-
-import java.io.File;
-import java.util.ArrayList;
-import org.apache.aut.nativelib.Os;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Path;
-
-/**
- * This task converts path and classpath information to a specific target OS
- * format. The resulting formatted path is placed into a specified property.
- *
- * LIMITATION: Currently this implementation groups all machines into one of two
- * types: Unix or Windows. Unix is defined as NOT windows.
- *
- * @author Larry Streepy
- * streepy@healthlanguage.com
- */
-public class PathConvert extends AbstractTask
-{
- private Path m_path;// Path to be converted
- private String m_targetOS;// The target OS type
- private boolean m_targetWindows;// Set when targetOS is set
- private boolean m_onWindows;// Set if we're running on windows
- private String m_property;// The property to receive the results
- private ArrayList m_prefixMap = new ArrayList();// Path prefix map
- private String m_pathSep;// User override on path sep char
- private String m_dirSep;
-
- /**
- * Override the default directory separator string for the target os
- */
- public void setDirSep( final String dirSep )
- {
- m_dirSep = dirSep;
- }
-
- /**
- * Override the default path separator string for the target os
- *
- * @param pathSep The new PathSep value
- */
- public void setPathSep( final String pathSep )
- {
- m_pathSep = pathSep;
- }
-
- /**
- * Set the value of the proprty attribute - this is the property into which
- * our converted path will be placed.
- */
- public void setProperty( final String property )
- {
- m_property = property;
- }
-
- /**
- * Set the value of the targetos attribute
- *
- * @param targetOS The new Targetos value
- */
- public void setTargetos( String targetOS )
- throws TaskException
- {
- m_targetOS = targetOS.toLowerCase();
-
- if( !m_targetOS.equals( "windows" ) && !targetOS.equals( "unix" ) &&
- !m_targetOS.equals( "netware" ) )
- {
- throw new TaskException( "targetos must be one of 'unix', 'netware', or 'windows'" );
- }
-
- // Currently, we deal with only two path formats: Unix and Windows
- // And Unix is everything that is not Windows
-
- // for NetWare, piggy-back on Windows, since in the validateSetup code,
- // the same assumptions can be made as with windows -
- // that ; is the path separator
-
- m_targetWindows = ( m_targetOS.equals( "windows" ) || m_targetOS.equals( "netware" ) );
- }
-
- /**
- * Create a nested MAP element
- */
- public void addMap( final MapEntry entry )
- {
- m_prefixMap.add( entry );
- }
-
- /**
- * Adds a PATH element
- */
- public void addPath( Path path )
- throws TaskException
- {
- if( m_path == null )
- {
- m_path = path;
- }
- else
- {
- m_path.addPath( path );
- }
- }
-
- public void execute()
- throws TaskException
- {
- // If we are a reference, the create a Path from the reference
- validate();// validate our setup
-
- // Currently, we deal with only two path formats: Unix and Windows
- // And Unix is everything that is not Windows
- // (with the exception for NetWare below)
-
- // for NetWare, piggy-back on Windows, since here and in the
- // apply code, the same assumptions can be made as with windows -
- // that \\ is an OK separator, and do comparisons case-insensitive.
- m_onWindows = ( Os.isFamily( Os.OS_FAMILY_WINDOWS ) || Os.isFamily( Os.OS_FAMILY_NETWARE ) );
-
- // Determine the from/to char mappings for dir sep
- char fromDirSep = m_onWindows ? '\\' : '/';
- char toDirSep = m_dirSep.charAt( 0 );
-
- StringBuffer rslt = new StringBuffer( 100 );
-
- // Get the list of path components in canonical form
- String[] elems = m_path.list();
-
- for( int i = 0; i < elems.length; i++ )
- {
- String elem = elems[ i ];
-
- elem = mapElement( elem );// Apply the path prefix map
-
- // Now convert the path and file separator characters from the
- // current os to the target os.
-
- elem = elem.replace( fromDirSep, toDirSep );
-
- if( i != 0 )
- {
- rslt.append( m_pathSep );
- }
- rslt.append( elem );
- }
-
- // Place the result into the specified property
- final String value = rslt.toString();
-
- getContext().debug( "Set property " + m_property + " = " + value );
-
- final String name = m_property;
- getContext().setProperty( name, value );
- }
-
- /**
- * Apply the configured map to a path element. The map is used to convert
- * between Windows drive letters and Unix paths. If no map is configured,
- * then the input string is returned unchanged.
- *
- * @param elem The path element to apply the map to
- * @return String Updated element
- */
- private String mapElement( String elem )
- throws TaskException
- {
- int size = m_prefixMap.size();
-
- if( size != 0 )
- {
-
- // Iterate over the map entries and apply each one. Stop when one of the
- // entries actually changes the element
-
- for( int i = 0; i < size; i++ )
- {
- MapEntry entry = (MapEntry)m_prefixMap.get( i );
- String newElem = entry.apply( elem );
-
- // Note I'm using "!=" to see if we got a new object back from
- // the apply method.
-
- if( newElem != elem )
- {
- elem = newElem;
- break;// We applied one, so we're done
- }
- }
- }
-
- return elem;
- }
-
- /**
- * Validate that all our parameters have been properly initialized.
- *
- * @throws org.apache.myrmidon.api.TaskException if something is not setup properly
- */
- private void validate()
- throws TaskException
- {
-
- if( m_path == null )
- {
- throw new TaskException( "You must specify a path to convert" );
- }
-
- if( m_property == null )
- {
- throw new TaskException( "You must specify a property" );
- }
-
- // Must either have a target OS or both a dirSep and pathSep
-
- if( m_targetOS == null && m_pathSep == null && m_dirSep == null )
- {
- throw new TaskException( "You must specify at least one of targetOS, dirSep, or pathSep" );
- }
-
- // Determine the separator strings. The dirsep and pathsep attributes
- // override the targetOS settings.
- String dsep = File.separator;
- String psep = File.pathSeparator;
-
- if( m_targetOS != null )
- {
- psep = m_targetWindows ? ";" : ":";
- dsep = m_targetWindows ? "\\" : "/";
- }
-
- if( m_pathSep != null )
- {// override with pathsep=
- psep = m_pathSep;
- }
-
- if( m_dirSep != null )
- {// override with dirsep=
- dsep = m_dirSep;
- }
-
- m_pathSep = psep;
- m_dirSep = dsep;
- }
-
- /**
- * Helper class, holds the nested values. Elements will look like
- * this: <map from="d:" to="/foo"/>
- *
- * When running on windows, the prefix comparison will be case insensitive.
- */
- public class MapEntry
- {
- private String m_from;
- private String m_to;
-
- /**
- * Set the "from" attribute of the map entry
- *
- * @param from The new From value
- */
- public void setFrom( final String from )
- {
- m_from = from;
- }
-
- /**
- * Set the "to" attribute of the map entry
- *
- * @param to The new To value
- */
- public void setTo( final String to )
- {
- m_to = to;
- }
-
- /**
- * Apply this map entry to a given path element
- *
- * @param elem Path element to process
- * @return String Updated path element after mapping
- */
- public String apply( String elem )
- throws TaskException
- {
- if( m_from == null || m_to == null )
- {
- throw new TaskException( "Both 'from' and 'to' must be set in a map entry" );
- }
-
- // If we're on windows, then do the comparison ignoring case
- final String cmpElem = m_onWindows ? elem.toLowerCase() : elem;
- final String cmpFrom = m_onWindows ? m_from.toLowerCase() : m_from;
-
- // If the element starts with the configured prefix, then convert the prefix
- // to the configured 'to' value.
-
- if( cmpElem.startsWith( cmpFrom ) )
- {
- final int len = m_from.length();
- if( len >= elem.length() )
- {
- elem = m_to;
- }
- else
- {
- elem = m_to + elem.substring( len );
- }
- }
-
- return elem;
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Property.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Property.java
deleted file mode 100644
index 18e408d93..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Property.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Iterator;
-import java.util.Properties;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.types.PathUtil;
-
-/**
- * Will set a Project property. Used to be a hack in ProjectHelper Will not
- * override values set by the command line or parent projects.
- *
- * @author costin@dnt.ro
- * @author Sam Ruby
- * @author Glenn McAllister
- */
-public class Property
- extends AbstractTask
-{
- private Path m_classpath;
-
- private String m_name;
- private String m_resource;
- private String m_value;
-
- public void addClasspath( Path classpath )
- throws TaskException
- {
- if( m_classpath == null )
- {
- m_classpath = classpath;
- }
- else
- {
- m_classpath.addPath( classpath );
- }
- }
-
- public void setLocation( File location )
- {
- setValue( location.getAbsolutePath() );
- }
-
- public void setName( String name )
- {
- m_name = name;
- }
-
- public void setResource( String resource )
- {
- m_resource = resource;
- }
-
- public void setValue( String value )
- {
- m_value = value;
- }
-
- public void execute()
- throws TaskException
- {
- validate();
-
- if( ( m_name != null ) && ( m_value != null ) )
- {
- final String name = m_name;
- final Object value = m_value;
- getContext().setProperty( name, value );
- }
-
- if( m_resource != null )
- {
- loadResource( m_resource );
- }
- }
-
- private void validate() throws TaskException
- {
- if( m_name != null )
- {
- if( m_value == null )
- {
- throw new TaskException( "You must specify value, location or refid with the name attribute" );
- }
- }
- else
- {
- if( m_resource == null )
- {
- throw new TaskException( "You must specify resource when not using the name attribute" );
- }
- }
- }
-
- public String toString()
- {
- return m_value == null ? "" : m_value;
- }
-
- protected void addProperties( Properties props )
- throws TaskException
- {
- final Iterator e = props.keySet().iterator();
- while( e.hasNext() )
- {
- final String name = (String)e.next();
- final String value = (String)props.getProperty( name );
- getContext().setProperty( name, value );
- }
- }
-
- protected void loadResource( String name )
- throws TaskException
- {
- Properties props = new Properties();
- getContext().debug( "Resource Loading " + name );
- try
- {
- ClassLoader classLoader = null;
-
- if( m_classpath != null )
- {
- final URL[] urls = PathUtil.toURLs( m_classpath );
- classLoader = new URLClassLoader( urls );
- }
- else
- {
- classLoader = ClassLoader.getSystemClassLoader();
- }
- final InputStream is = classLoader.getResourceAsStream( name );
-
- if( is != null )
- {
- props.load( is );
- addProperties( props );
- }
- else
- {
- getContext().warn( "Unable to find resource " + name );
- }
- }
- catch( IOException ex )
- {
- throw new TaskException( "Error", ex );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Rpm.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Rpm.java
deleted file mode 100644
index 602efb473..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Rpm.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs;
-
-import java.io.File;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * @author lucas@collab.net
- */
-public class Rpm
- extends AbstractTask
-{
- /**
- * the rpm command to use
- */
- private String m_command = "-bb";
-
- /**
- * clean BUILD directory
- */
- private boolean m_cleanBuildDir;
-
- /**
- * remove spec file
- */
- private boolean m_removeSpec;
-
- /**
- * remove sources
- */
- private boolean m_removeSource;
-
- /**
- * the spec file
- */
- private String m_specFile;
-
- /**
- * the rpm top dir
- */
- private File m_topDir;
-
- public void setCleanBuildDir( boolean cleanBuildDir )
- {
- m_cleanBuildDir = cleanBuildDir;
- }
-
- public void setCommand( final String command )
- {
- m_command = command;
- }
-
- public void setRemoveSource( final boolean removeSource )
- {
- m_removeSource = removeSource;
- }
-
- public void setRemoveSpec( final boolean removeSpec )
- {
- m_removeSpec = removeSpec;
- }
-
- public void setSpecFile( final String specFile )
- throws TaskException
- {
- if( ( specFile == null ) || ( specFile.trim().equals( "" ) ) )
- {
- throw new TaskException( "You must specify a spec file" );
- }
- m_specFile = specFile;
- }
-
- public void setTopDir( final File topDir )
- {
- m_topDir = topDir;
- }
-
- public void execute()
- throws TaskException
- {
- final Commandline cmd = createCommand();
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
-
- if( m_topDir == null )
- {
- m_topDir = getBaseDirectory();
- }
- exe.setWorkingDirectory( m_topDir );
- exe.setCommandline( cmd );
- exe.setReturnCode( 0 );
-
- final String message = "Building the RPM based on the " + m_specFile + " file";
- getContext().info( message );
- exe.execute();
- }
-
- private Commandline createCommand()
- throws TaskException
- {
- final Commandline cmd = new Commandline();
- cmd.setExecutable( "rpm" );
- if( m_topDir != null )
- {
- cmd.addArgument( "--define" );
- cmd.addArgument( "_topdir" + m_topDir );
- }
-
- cmd.addLine( m_command );
-
- if( m_cleanBuildDir )
- {
- cmd.addArgument( "--clean" );
- }
- if( m_removeSpec )
- {
- cmd.addArgument( "--rmspec" );
- }
- if( m_removeSource )
- {
- cmd.addArgument( "--rmsource" );
- }
-
- cmd.addArgument( "SPECS/" + m_specFile );
- return cmd;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/SQLExec.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/SQLExec.java
deleted file mode 100644
index 5e6847fcc..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/SQLExec.java
+++ /dev/null
@@ -1,858 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs;
-
-import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PrintStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.Driver;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.SQLWarning;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.StringTokenizer;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.EnumeratedAttribute;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.types.PathUtil;
-import org.apache.tools.todo.types.ScannerUtil;
-
-/**
- * Reads in a text file containing SQL statements seperated with semicolons and
- * executes it in a given db. Comments may be created with REM -- or //.
- *
- * @author Jeff Martin
- * @author Michael McCallum
- * @author Tim Stephenson
- */
-public class SQLExec
- extends AbstractTask
-{
- private int goodSql = 0, totalSql = 0;
-
- private ArrayList filesets = new ArrayList();
-
- /**
- * Database connection
- */
- private Connection conn;
-
- /**
- * Autocommit flag. Default value is false
- */
- private boolean autocommit;
-
- /**
- * SQL statement
- */
- private Statement statement;
-
- /**
- * DB driver.
- */
- private String driver;
-
- /**
- * DB url.
- */
- private String url;
-
- /**
- * User name.
- */
- private String userId;
-
- /**
- * Password
- */
- private String password;
-
- /**
- * SQL input file
- */
- private File srcFile;
-
- /**
- * SQL input command
- */
- private String sqlCommand = "";
-
- /**
- * SQL transactions to perform
- */
- private ArrayList transactions = new ArrayList();
-
- /**
- * SQL Statement delimiter
- */
- private String delimiter = ";";
-
- /**
- * The delimiter type indicating whether the delimiter will only be
- * recognized on a line by itself
- */
- private String delimiterType = DelimiterType.NORMAL;
-
- /**
- * Print SQL results.
- */
- private boolean print;
-
- /**
- * Print header columns.
- */
- private boolean showheaders = true;
-
- /**
- * Results Output file.
- */
- private File output;
-
- /**
- * RDBMS Product needed for this SQL.
- */
- private String rdbms;
-
- /**
- * RDBMS Version needed for this SQL.
- */
- private String version;
-
- /**
- * Action to perform if an error is found
- */
- private String onError = "abort";
-
- /**
- * Encoding to use when reading SQL statements from a file
- */
- private String encoding;
-
- private Path classpath;
-
- /**
- * Set the autocommit flag for the DB connection.
- *
- * @param autocommit The new Autocommit value
- */
- public void setAutocommit( boolean autocommit )
- {
- this.autocommit = autocommit;
- }
-
- /**
- * Adds an element to the classpath for loading the driver.
- *
- * @param classpath The new Classpath value
- */
- public void addClasspath( Path classpath )
- throws TaskException
- {
- if( this.classpath == null )
- {
- this.classpath = classpath;
- }
- else
- {
- this.classpath.addPath( classpath );
- }
- }
-
- /**
- * Set the statement delimiter.
- *
- * For example, set this to "go" and delimitertype to "ROW" for Sybase ASE
- * or MS SQL Server.
- *
- * @param delimiter The new Delimiter value
- */
- public void setDelimiter( String delimiter )
- {
- this.delimiter = delimiter;
- }
-
- /**
- * Set the Delimiter type for this sql task. The delimiter type takes two
- * values - normal and row. Normal means that any occurence of the delimiter
- * terminate the SQL command whereas with row, only a line containing just
- * the delimiter is recognized as the end of the command.
- *
- * @param delimiterType The new DelimiterType value
- */
- public void setDelimiterType( DelimiterType delimiterType )
- {
- this.delimiterType = delimiterType.getValue();
- }
-
- /**
- * Set the JDBC driver to be used.
- *
- * @param driver The new Driver value
- */
- public void setDriver( String driver )
- {
- this.driver = driver;
- }
-
- /**
- * Set the file encoding to use on the sql files read in
- *
- * @param encoding the encoding to use on the files
- */
- public void setEncoding( String encoding )
- {
- this.encoding = encoding;
- }
-
- /**
- * Set the action to perform onerror
- *
- * @param action The new Onerror value
- */
- public void setOnerror( OnError action )
- {
- this.onError = action.getValue();
- }
-
- /**
- * Set the output file.
- *
- * @param output The new Output value
- */
- public void setOutput( File output )
- {
- this.output = output;
- }
-
- /**
- * Set the password for the DB connection.
- *
- * @param password The new Password value
- */
- public void setPassword( String password )
- {
- this.password = password;
- }
-
- /**
- * Set the print flag.
- *
- * @param print The new Print value
- */
- public void setPrint( boolean print )
- {
- this.print = print;
- }
-
- /**
- * Set the rdbms required
- *
- * @param vendor The new Rdbms value
- */
- public void setRdbms( String vendor )
- {
- this.rdbms = vendor.toLowerCase();
- }
-
- /**
- * Set the showheaders flag.
- *
- * @param showheaders The new Showheaders value
- */
- public void setShowheaders( boolean showheaders )
- {
- this.showheaders = showheaders;
- }
-
- /**
- * Set the name of the sql file to be run.
- *
- * @param srcFile The new Src value
- */
- public void setSrc( File srcFile )
- {
- this.srcFile = srcFile;
- }
-
- /**
- * Set the DB connection url.
- *
- * @param url The new Url value
- */
- public void setUrl( String url )
- {
- this.url = url;
- }
-
- /**
- * Set the user name for the DB connection.
- *
- * @param userId The new Userid value
- */
- public void setUserid( String userId )
- {
- this.userId = userId;
- }
-
- /**
- * Set the version required
- *
- * @param version The new Version value
- */
- public void setVersion( String version )
- {
- this.version = version.toLowerCase();
- }
-
- /**
- * Adds a set of files (nested fileset attribute).
- *
- * @param set The feature to be added to the Fileset attribute
- */
- public void addFileset( FileSet set )
- {
- filesets.add( set );
- }
-
- /**
- * Set the sql command to execute
- *
- * @param sql The feature to be added to the Text attribute
- */
- public void addContent( String sql )
- {
- this.sqlCommand += sql;
- }
-
- /**
- * Set the sql command to execute
- *
- * @return Description of the Returned Value
- */
- public Transaction createTransaction()
- {
- Transaction t = new Transaction();
- transactions.add( t );
- return t;
- }
-
- /**
- * Load the sql file and then execute it
- *
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- sqlCommand = sqlCommand.trim();
-
- if( srcFile == null && sqlCommand.length() == 0 && filesets.isEmpty() )
- {
- if( transactions.size() == 0 )
- {
- throw new TaskException( "Source file or fileset, transactions or sql statement must be set!" );
- }
- }
- else
- {
- // deal with the filesets
- for( int i = 0; i < filesets.size(); i++ )
- {
- FileSet fs = (FileSet)filesets.get( i );
- DirectoryScanner ds = ScannerUtil.getDirectoryScanner( fs );
- File srcDir = fs.getDir();
-
- String[] srcFiles = ds.getIncludedFiles();
-
- // Make a transaction for each file
- for( int j = 0; j < srcFiles.length; j++ )
- {
- Transaction t = createTransaction();
- t.setSrc( new File( srcDir, srcFiles[ j ] ) );
- }
- }
-
- // Make a transaction group for the outer command
- Transaction t = createTransaction();
- t.setSrc( srcFile );
- t.addContent( sqlCommand );
- }
-
- if( driver == null )
- {
- throw new TaskException( "Driver attribute must be set!" );
- }
- if( userId == null )
- {
- throw new TaskException( "User Id attribute must be set!" );
- }
- if( password == null )
- {
- throw new TaskException( "Password attribute must be set!" );
- }
- if( url == null )
- {
- throw new TaskException( "Url attribute must be set!" );
- }
- if( srcFile != null && !srcFile.exists() )
- {
- throw new TaskException( "Source file does not exist!" );
- }
- Driver driverInstance = null;
- // Load the driver using the
- try
- {
- Class dc;
- if( classpath != null )
- {
- getContext().debug( "Loading " + driver + " using AntClassLoader with classpath " + classpath );
-
- final URL[] urls = PathUtil.toURLs( classpath );
- final ClassLoader classLoader = new URLClassLoader( urls );
- dc = classLoader.loadClass( driver );
- }
- else
- {
- getContext().debug( "Loading " + driver + " using system loader." );
- dc = Class.forName( driver );
- }
- driverInstance = (Driver)dc.newInstance();
- }
- catch( ClassNotFoundException e )
- {
- throw new TaskException( "Class Not Found: JDBC driver " + driver + " could not be loaded" );
- }
- catch( IllegalAccessException e )
- {
- throw new TaskException( "Illegal Access: JDBC driver " + driver + " could not be loaded" );
- }
- catch( InstantiationException e )
- {
- throw new TaskException( "Instantiation Exception: JDBC driver " + driver + " could not be loaded" );
- }
-
- try
- {
- getContext().debug( "connecting to " + url );
- Properties info = new Properties();
- info.put( "user", userId );
- info.put( "password", password );
- conn = driverInstance.connect( url, info );
-
- if( conn == null )
- {
- // Driver doesn't understand the URL
- throw new SQLException( "No suitable Driver for " + url );
- }
-
- if( !isValidRdbms( conn ) )
- {
- return;
- }
-
- conn.setAutoCommit( autocommit );
-
- statement = conn.createStatement();
-
- PrintStream out = System.out;
- try
- {
- if( output != null )
- {
- getContext().debug( "Opening PrintStream to output file " + output );
- out = new PrintStream( new BufferedOutputStream( new FileOutputStream( output ) ) );
- }
-
- // Process all transactions
- for( Iterator e = transactions.iterator();
- e.hasNext(); )
- {
-
- ( (Transaction)e.next() ).runTransaction( out );
- if( !autocommit )
- {
- getContext().debug( "Commiting transaction" );
- conn.commit();
- }
- }
- }
- finally
- {
- if( out != null && out != System.out )
- {
- out.close();
- }
- }
- }
- catch( IOException e )
- {
- if( !autocommit && conn != null && onError.equals( "abort" ) )
- {
- try
- {
- conn.rollback();
- }
- catch( SQLException ex )
- {
- }
- }
- throw new TaskException( "Error", e );
- }
- catch( SQLException e )
- {
- if( !autocommit && conn != null && onError.equals( "abort" ) )
- {
- try
- {
- conn.rollback();
- }
- catch( SQLException ex )
- {
- }
- }
- throw new TaskException( "Error", e );
- }
- finally
- {
- try
- {
- if( statement != null )
- {
- statement.close();
- }
- if( conn != null )
- {
- conn.close();
- }
- }
- catch( SQLException e )
- {
- }
- }
-
- getContext().info( goodSql + " of " + totalSql +
- " SQL statements executed successfully" );
- }
-
- /**
- * Verify if connected to the correct RDBMS
- *
- * @param conn Description of Parameter
- * @return The ValidRdbms value
- */
- protected boolean isValidRdbms( Connection conn )
- {
- if( rdbms == null && version == null )
- {
- return true;
- }
-
- try
- {
- DatabaseMetaData dmd = conn.getMetaData();
-
- if( rdbms != null )
- {
- String theVendor = dmd.getDatabaseProductName().toLowerCase();
-
- getContext().debug( "RDBMS = " + theVendor );
- if( theVendor == null || theVendor.indexOf( rdbms ) < 0 )
- {
- getContext().debug( "Not the required RDBMS: " + rdbms );
- return false;
- }
- }
-
- if( version != null )
- {
- String theVersion = dmd.getDatabaseProductVersion().toLowerCase();
-
- getContext().debug( "Version = " + theVersion );
- if( theVersion == null ||
- !( theVersion.startsWith( version ) ||
- theVersion.indexOf( " " + version ) >= 0 ) )
- {
- getContext().debug( "Not the required version: \"" + version + "\"" );
- return false;
- }
- }
- }
- catch( SQLException e )
- {
- // Could not get the required information
- getContext().error( "Failed to obtain required RDBMS information" );
- return false;
- }
-
- return true;
- }
-
- /**
- * Exec the sql statement.
- *
- * @param sql Description of Parameter
- * @param out Description of Parameter
- * @exception java.sql.SQLException Description of Exception
- */
- protected void execSQL( String sql, PrintStream out )
- throws SQLException
- {
- // Check and ignore empty statements
- if( "".equals( sql.trim() ) )
- {
- return;
- }
-
- try
- {
- totalSql++;
- if( !statement.execute( sql ) )
- {
- getContext().debug( statement.getUpdateCount() + " rows affected" );
- }
- else
- {
- if( print )
- {
- printResults( out );
- }
- }
-
- SQLWarning warning = conn.getWarnings();
- while( warning != null )
- {
- getContext().debug( warning + " sql warning" );
- warning = warning.getNextWarning();
- }
- conn.clearWarnings();
- goodSql++;
- }
- catch( SQLException e )
- {
- getContext().error( "Failed to execute: " + sql );
- if( !onError.equals( "continue" ) )
- {
- throw e;
- }
- getContext().error( e.toString() );
- }
- }
-
- /**
- * print any results in the statement.
- *
- * @param out Description of Parameter
- * @exception java.sql.SQLException Description of Exception
- */
- protected void printResults( PrintStream out )
- throws java.sql.SQLException
- {
- ResultSet rs = null;
- do
- {
- rs = statement.getResultSet();
- if( rs != null )
- {
- getContext().debug( "Processing new result set." );
- ResultSetMetaData md = rs.getMetaData();
- int columnCount = md.getColumnCount();
- StringBuffer line = new StringBuffer();
- if( showheaders )
- {
- for( int col = 1; col < columnCount; col++ )
- {
- line.append( md.getColumnName( col ) );
- line.append( "," );
- }
- line.append( md.getColumnName( columnCount ) );
- out.println( line );
- line.setLength( 0 );
- }
- while( rs.next() )
- {
- boolean first = true;
- for( int col = 1; col <= columnCount; col++ )
- {
- String columnValue = rs.getString( col );
- if( columnValue != null )
- {
- columnValue = columnValue.trim();
- }
-
- if( first )
- {
- first = false;
- }
- else
- {
- line.append( "," );
- }
- line.append( columnValue );
- }
- out.println( line );
- line.setLength( 0 );
- }
- }
- } while( statement.getMoreResults() );
- out.println();
- }
-
- protected void runStatements( Reader reader, PrintStream out )
- throws SQLException, IOException, TaskException
- {
- String sql = "";
- String line = "";
-
- BufferedReader in = new BufferedReader( reader );
-
- try
- {
- while( ( line = in.readLine() ) != null )
- {
- line = line.trim();
- final String value = line;
- line = "" + getContext().resolveValue( value );
- if( line.startsWith( "//" ) )
- {
- continue;
- }
- if( line.startsWith( "--" ) )
- {
- continue;
- }
- StringTokenizer st = new StringTokenizer( line );
- if( st.hasMoreTokens() )
- {
- String token = st.nextToken();
- if( "REM".equalsIgnoreCase( token ) )
- {
- continue;
- }
- }
-
- sql += " " + line;
- sql = sql.trim();
-
- // SQL defines "--" as a comment to EOL
- // and in Oracle it may contain a hint
- // so we cannot just remove it, instead we must end it
- if( line.indexOf( "--" ) >= 0 )
- {
- sql += "\n";
- }
-
- if( delimiterType.equals( DelimiterType.NORMAL ) && sql.endsWith( delimiter ) ||
- delimiterType.equals( DelimiterType.ROW ) && line.equals( delimiter ) )
- {
- getContext().debug( "SQL: " + sql );
- execSQL( sql.substring( 0, sql.length() - delimiter.length() ), out );
- sql = "";
- }
- }
-
- // Catch any statements not followed by ;
- if( !sql.equals( "" ) )
- {
- execSQL( sql, out );
- }
- }
- catch( SQLException e )
- {
- throw e;
- }
-
- }
-
- public static class DelimiterType extends EnumeratedAttribute
- {
- public final static String NORMAL = "normal";
- public final static String ROW = "row";
-
- public String[] getValues()
- {
- return new String[]{NORMAL, ROW};
- }
- }
-
- /**
- * Enumerated attribute with the values "continue", "stop" and "abort" for
- * the onerror attribute.
- *
- * @author RT
- */
- public static class OnError extends EnumeratedAttribute
- {
- public String[] getValues()
- {
- return new String[]{"continue", "stop", "abort"};
- }
- }
-
- /**
- * Contains the definition of a new transaction element. Transactions allow
- * several files or blocks of statements to be executed using the same JDBC
- * connection and commit operation in between.
- *
- * @author RT
- */
- public class Transaction
- {
- private File tSrcFile = null;
- private String tSqlCommand = "";
-
- public void setSrc( File src )
- {
- this.tSrcFile = src;
- }
-
- public void addContent( String sql )
- {
- this.tSqlCommand += sql;
- }
-
- private void runTransaction( PrintStream out )
- throws IOException, SQLException, TaskException
- {
- if( tSqlCommand.length() != 0 )
- {
- getContext().info( "Executing commands" );
- runStatements( new StringReader( tSqlCommand ), out );
- }
-
- if( tSrcFile != null )
- {
- getContext().info( "Executing file: " + tSrcFile.getAbsolutePath() );
- Reader reader = ( encoding == null ) ? new FileReader( tSrcFile )
- : new InputStreamReader( new FileInputStream( tSrcFile ), encoding );
- runStatements( reader, out );
- reader.close();
- }
- }
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Script.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Script.java
deleted file mode 100644
index 78c7167a4..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Script.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs;
-
-import com.ibm.bsf.BSFException;
-import com.ibm.bsf.BSFManager;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Hashtable;
-import java.util.Iterator;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * Execute a script
- *
- * @author Sam Ruby rubys@us.ibm.com
- */
-public class Script extends AbstractTask
-{
- private String script = "";
- private Hashtable beans = new Hashtable();
- private String language;
-
- /**
- * Defines the language (required).
- *
- * @param language The new Language value
- */
- public void setLanguage( String language )
- {
- this.language = language;
- }
-
- /**
- * Load the script from an external file
- *
- * @param fileName The new Src value
- */
- public void setSrc( String fileName )
- {
- File file = new File( fileName );
- if( !file.exists() )
- {
- throw new TaskException( "file " + fileName + " not found." );
- }
-
- int count = (int)file.length();
- byte data[] = new byte[ count ];
-
- try
- {
- FileInputStream inStream = new FileInputStream( file );
- inStream.read( data );
- inStream.close();
- }
- catch( IOException e )
- {
- throw new TaskException( "Error", e );
- }
-
- script += new String( data );
- }
-
- /**
- * Defines the script.
- *
- * @param text The feature to be added to the Text attribute
- */
- public void addContent( String text )
- {
- this.script += text;
- }
-
- /**
- * Do the work.
- *
- * @exception org.apache.myrmidon.api.TaskException if someting goes wrong with the build
- */
- public void execute()
- throws TaskException
- {
- try
- {
- addBeans( getContext().getProperties() );
- //In Ant2 there is no difference between properties and references
- //addBeans( getProject().getReferences() );
-
- beans.put( "context", getContext() );
-
- beans.put( "self", this );
-
- BSFManager manager = new BSFManager();
-
- for( Iterator e = beans.keys(); e.hasNext(); )
- {
- String key = (String)e.next();
- Object value = beans.get( key );
- manager.declareBean( key, value, value.getClass() );
- }
-
- // execute the script
- manager.exec( language, "", 0, 0, script );
- }
- catch( BSFException be )
- {
- Throwable t = be;
- Throwable te = be.getTargetException();
- if( te != null )
- {
- if( te instanceof TaskException )
- {
- throw (TaskException)te;
- }
- else
- {
- t = te;
- }
- }
- throw new TaskException( "Error", t );
- }
- }
-
- /**
- * Add a list of named objects to the list to be exported to the script
- *
- * @param dictionary The feature to be added to the Beans attribute
- */
- private void addBeans( Hashtable dictionary )
- {
- for( Iterator e = dictionary.keys(); e.hasNext(); )
- {
- String key = (String)e.next();
-
- boolean isValid = key.length() > 0 &&
- Character.isJavaIdentifierStart( key.charAt( 0 ) );
-
- for( int i = 1; isValid && i < key.length(); i++ )
- {
- isValid = Character.isJavaIdentifierPart( key.charAt( i ) );
- }
-
- if( isValid )
- {
- beans.put( key, dictionary.get( key ) );
- }
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Tstamp.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Tstamp.java
deleted file mode 100644
index 764d9bda3..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/Tstamp.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs;
-
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.NoSuchElementException;
-import java.util.StringTokenizer;
-import java.util.TimeZone;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.EnumeratedAttribute;
-
-/**
- * Sets TSTAMP, DSTAMP and TODAY
- *
- * @author costin@dnt.ro
- * @author stefano@apache.org
- * @author roxspring@yahoo.com
- * @author conor@cognet.com.au
- * @author Magesh Umasankar
- */
-public class Tstamp
- extends AbstractTask
-{
- private ArrayList customFormats = new ArrayList();
- private String m_prefix = "";
-
- public void setPrefix( String prefix )
- {
- this.m_prefix = prefix;
- if( !this.m_prefix.endsWith( "." ) )
- {
- this.m_prefix += ".";
- }
- }
-
- public CustomFormat createFormat()
- {
- CustomFormat cts = new CustomFormat( m_prefix );
- customFormats.add( cts );
- return cts;
- }
-
- public void execute()
- throws TaskException
- {
- try
- {
- Date d = new Date();
-
- SimpleDateFormat dstamp = new SimpleDateFormat( "yyyyMMdd" );
- final String name = m_prefix + "DSTAMP";
- final Object value = dstamp.format( d );
- getContext().setProperty( name, value );
-
- SimpleDateFormat tstamp = new SimpleDateFormat( "HHmm" );
- final String name1 = m_prefix + "TSTAMP";
- final Object value1 = tstamp.format( d );
- getContext().setProperty( name1, value1 );
-
- SimpleDateFormat today = new SimpleDateFormat( "MMMM d yyyy", Locale.US );
- final String name2 = m_prefix + "TODAY";
- final Object value2 = today.format( d );
- getContext().setProperty( name2, value2 );
-
- Iterator i = customFormats.iterator();
- while( i.hasNext() )
- {
- CustomFormat cts = (CustomFormat)i.next();
- cts.execute( d );
- }
-
- }
- catch( Exception e )
- {
- throw new TaskException( "Error", e );
- }
- }
-
- public static class Unit extends EnumeratedAttribute
- {
-
- private final static String MILLISECOND = "millisecond";
- private final static String SECOND = "second";
- private final static String MINUTE = "minute";
- private final static String HOUR = "hour";
- private final static String DAY = "day";
- private final static String WEEK = "week";
- private final static String MONTH = "month";
- private final static String YEAR = "year";
-
- private final static String[] units = {
- MILLISECOND,
- SECOND,
- MINUTE,
- HOUR,
- DAY,
- WEEK,
- MONTH,
- YEAR
- };
-
- private Hashtable calendarFields = new Hashtable();
-
- public Unit()
- {
- calendarFields.put( MILLISECOND,
- new Integer( Calendar.MILLISECOND ) );
- calendarFields.put( SECOND, new Integer( Calendar.SECOND ) );
- calendarFields.put( MINUTE, new Integer( Calendar.MINUTE ) );
- calendarFields.put( HOUR, new Integer( Calendar.HOUR_OF_DAY ) );
- calendarFields.put( DAY, new Integer( Calendar.DATE ) );
- calendarFields.put( WEEK, new Integer( Calendar.WEEK_OF_YEAR ) );
- calendarFields.put( MONTH, new Integer( Calendar.MONTH ) );
- calendarFields.put( YEAR, new Integer( Calendar.YEAR ) );
- }
-
- public int getCalendarField()
- {
- String key = getValue().toLowerCase();
- Integer i = (Integer)calendarFields.get( key );
- return i.intValue();
- }
-
- public String[] getValues()
- {
- return units;
- }
- }
-
- public class CustomFormat
- {
- private int offset = 0;
- private int field = Calendar.DATE;
- private String prefix = "";
- private String country;
- private String language;
- private String pattern;
- private String propertyName;
- private TimeZone timeZone;
- private String variant;
-
- public CustomFormat( String prefix )
- {
- this.prefix = prefix;
- }
-
- public void setLocale( String locale )
- throws TaskException
- {
- StringTokenizer st = new StringTokenizer( locale, " \t\n\r\f," );
- try
- {
- language = st.nextToken();
- if( st.hasMoreElements() )
- {
- country = st.nextToken();
- if( st.hasMoreElements() )
- {
- country = st.nextToken();
- if( st.hasMoreElements() )
- {
- throw new TaskException( "bad locale format" );
- }
- }
- }
- else
- {
- country = "";
- }
- }
- catch( NoSuchElementException e )
- {
- throw new TaskException( "bad locale format", e );
- }
- }
-
- public void setOffset( int offset )
- {
- this.offset = offset;
- }
-
- public void setPattern( String pattern )
- {
- this.pattern = pattern;
- }
-
- public void setProperty( String propertyName )
- {
- this.propertyName = prefix + propertyName;
- }
-
- public void setTimezone( String id )
- {
- timeZone = TimeZone.getTimeZone( id );
- }
-
- public void setUnit( Unit unit )
- {
- field = unit.getCalendarField();
- }
-
- public void execute( final Date date )
- throws TaskException
- {
- if( propertyName == null )
- {
- throw new TaskException( "property attribute must be provided" );
- }
-
- if( pattern == null )
- {
- throw new TaskException( "pattern attribute must be provided" );
- }
-
- SimpleDateFormat sdf;
- if( language == null )
- {
- sdf = new SimpleDateFormat( pattern );
- }
- else if( variant == null )
- {
- sdf = new SimpleDateFormat( pattern, new Locale( language, country ) );
- }
- else
- {
- sdf = new SimpleDateFormat( pattern, new Locale( language, country, variant ) );
- }
-
- Date time = date;
- if( offset != 0 )
- {
- final Calendar calendar = Calendar.getInstance();
- calendar.setTime( time );
- calendar.add( field, offset );
- time = calendar.getTime();
- }
- if( timeZone != null )
- {
- sdf.setTimeZone( timeZone );
- }
- getContext().setProperty( propertyName, sdf.format( time ) );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/UpToDate.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/UpToDate.java
deleted file mode 100644
index f729eb334..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/UpToDate.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.FileNameMapper;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.ScannerUtil;
-import org.apache.tools.todo.types.SourceFileScanner;
-import org.apache.tools.todo.util.mappers.MergingMapper;
-
-/**
- * Will set the given property if the specified target has a timestamp greater
- * than all of the source files.
- *
- * @author William Ferguson
- * williamf@mincom.com
- * @author Hiroaki Nakamura
- * hnakamur@mc.neweb.ne.jp
- * @author Stefan Bodewig
- */
-public class UpToDate
- extends AbstractTask
-{
- private final ArrayList m_fileSets = new ArrayList();
- private FileNameMapper m_mapper;
-
- private String m_property;
- private File m_targetFile;
- private String m_value;
-
- /**
- * The property to set if the target file is more up to date than each of
- * the source files.
- *
- * @param property the name of the property to set if Target is up to date.
- */
- public void setProperty( final String property )
- {
- m_property = property;
- }
-
- /**
- * The file which must be more up to date than each of the source files if
- * the property is to be set.
- *
- * @param file the file which we are checking against.
- */
- public void setTargetFile( final File file )
- {
- m_targetFile = file;
- }
-
- /**
- * The value to set the named property to if the target file is more up to
- * date than each of the source files. Defaults to 'true'.
- *
- * @param value the value to set the property to if Target is up to date
- */
- public void setValue( final String value )
- {
- m_value = value;
- }
-
- /**
- * Nested <srcfiles> element.
- *
- * @param fs The feature to be added to the Srcfiles attribute
- */
- public void addSrcfiles( final FileSet fs )
- {
- m_fileSets.add( fs );
- }
-
- /**
- * Defines the FileNameMapper to use (nested mapper element).
- */
- public void addMapper( final FileNameMapper mapper )
- throws TaskException
- {
- if( m_mapper != null )
- {
- throw new TaskException( "Cannot define more than one mapper" );
- }
- m_mapper = mapper;
- }
-
- /**
- * Evaluate all target and source files, see if the targets are up-to-date.
- *
- * @return Description of the Returned Value
- */
- public boolean eval()
- throws TaskException
- {
- if( m_fileSets.size() == 0 )
- {
- throw new TaskException( "At least one element must be set" );
- }
-
- if( m_targetFile == null && m_mapper == null )
- {
- throw new TaskException( "The targetfile attribute or a nested mapper element must be set" );
- }
-
- // if not there then it can't be up to date
- if( m_targetFile != null && !m_targetFile.exists() )
- {
- return false;
- }
-
- Iterator enum = m_fileSets.iterator();
- boolean upToDate = true;
- while( upToDate && enum.hasNext() )
- {
- FileSet fs = (FileSet)enum.next();
- DirectoryScanner ds = ScannerUtil.getDirectoryScanner( fs );
- upToDate = upToDate && scanDir( fs.getDir(),
- ds.getIncludedFiles() );
- }
- return upToDate;
- }
-
- /**
- * Sets property to true if target files have a more recent timestamp than
- * each of the corresponding source files.
- *
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- boolean upToDate = eval();
- if( upToDate )
- {
- final String name = m_property;
- final Object value = this.getValue();
- getContext().setProperty( name, value );
- if( m_mapper == null )
- {
- getContext().debug( "File \"" + m_targetFile.getAbsolutePath() + "\" is up to date." );
- }
- else
- {
- getContext().debug( "All target files have been up to date." );
- }
- }
- }
-
- protected boolean scanDir( File srcDir, String files[] )
- throws TaskException
- {
- SourceFileScanner scanner = new SourceFileScanner();
- FileNameMapper mapper = null;
- File dir = srcDir;
- if( m_mapper == null )
- {
- MergingMapper mm = new MergingMapper();
- mm.setTo( m_targetFile.getAbsolutePath() );
- mapper = mm;
- dir = null;
- }
- else
- {
- mapper = m_mapper;
- }
- return scanner.restrict( files, srcDir, dir, mapper, getContext() ).length == 0;
- }
-
- /**
- * Returns the value, or "true" if a specific value wasn't provided.
- *
- * @return The Value value
- */
- private String getValue()
- {
- return ( m_value != null ) ? m_value : "true";
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/WaitFor.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/WaitFor.java
deleted file mode 100644
index c2973dda0..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/WaitFor.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs;
-
-import java.util.Hashtable;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.framework.conditions.AndCondition;
-import org.apache.myrmidon.framework.conditions.Condition;
-import org.apache.tools.todo.types.EnumeratedAttribute;
-
-/**
- * Wait for an external event to occur. Wait for an external process to start or
- * to complete some task. This is useful with the parallel
task to
- * syncronize the execution of tests with server startup. The following
- * attributes can be specified on a waitfor task:
- *
- * maxwait - maximum length of time to wait before giving up
- * maxwaitunit - The unit to be used to interpret maxwait attribute
- *
- * checkevery - amount of time to sleep between each check
- * checkeveryunit - The unit to be used to interpret checkevery attribute
- *
- * timeoutproperty - name of a property to set if maxwait has been
- * exceeded.
- *
- * The maxwaitunit and checkeveryunit are allowed to have the following values:
- * millesond, second, minute, hour, day and week. The default is millisecond.
- *
- * @author Denis Hennessy
- * @author Magesh Umasankar
- */
-
-public class WaitFor
- extends AbstractTask
-{
- private long maxWaitMillis = 1000l * 60l * 3l;// default max wait time
- private long maxWaitMultiplier = 1l;
- private long checkEveryMillis = 500l;
- private long checkEveryMultiplier = 1l;
- private String timeoutProperty;
- private AndCondition m_condition = new AndCondition();
-
- /**
- * Adds a condition.
- */
- public void add( final Condition condition )
- {
- m_condition.add( condition );
- }
-
- /**
- * Set the time between each check
- *
- * @param time The new CheckEvery value
- */
- public void setCheckEvery( long time )
- {
- checkEveryMillis = time;
- }
-
- /**
- * Set the check every time unit
- *
- * @param unit The new CheckEveryUnit value
- */
- public void setCheckEveryUnit( Unit unit )
- {
- checkEveryMultiplier = unit.getMultiplier();
- }
-
- /**
- * Set the maximum length of time to wait
- *
- * @param time The new MaxWait value
- */
- public void setMaxWait( long time )
- {
- maxWaitMillis = time;
- }
-
- /**
- * Set the max wait time unit
- *
- * @param unit The new MaxWaitUnit value
- */
- public void setMaxWaitUnit( Unit unit )
- {
- maxWaitMultiplier = unit.getMultiplier();
- }
-
- /**
- * Set the timeout property.
- *
- * @param p The new TimeoutProperty value
- */
- public void setTimeoutProperty( String p )
- {
- timeoutProperty = p;
- }
-
- /**
- * Check repeatedly for the specified conditions until they become true or
- * the timeout expires.
- *
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- maxWaitMillis *= maxWaitMultiplier;
- checkEveryMillis *= checkEveryMultiplier;
- long start = System.currentTimeMillis();
- long end = start + maxWaitMillis;
-
- while( System.currentTimeMillis() < end )
- {
- if( m_condition.evaluate( getContext() ) )
- {
- return;
- }
- try
- {
- Thread.sleep( checkEveryMillis );
- }
- catch( InterruptedException e )
- {
- }
- }
-
- if( timeoutProperty != null )
- {
- final String name = timeoutProperty;
- getContext().setProperty( name, "true" );
- }
- }
-
- public static class Unit extends EnumeratedAttribute
- {
-
- private final static String MILLISECOND = "millisecond";
- private final static String SECOND = "second";
- private final static String MINUTE = "minute";
- private final static String HOUR = "hour";
- private final static String DAY = "day";
- private final static String WEEK = "week";
-
- private final static String[] units = {
- MILLISECOND, SECOND, MINUTE, HOUR, DAY, WEEK
- };
-
- private Hashtable timeTable = new Hashtable();
-
- public Unit()
- {
- timeTable.put( MILLISECOND, new Long( 1l ) );
- timeTable.put( SECOND, new Long( 1000l ) );
- timeTable.put( MINUTE, new Long( 1000l * 60l ) );
- timeTable.put( HOUR, new Long( 1000l * 60l * 60l ) );
- timeTable.put( DAY, new Long( 1000l * 60l * 60l * 24l ) );
- timeTable.put( WEEK, new Long( 1000l * 60l * 60l * 24l * 7l ) );
- }
-
- public long getMultiplier()
- {
- String key = getValue().toLowerCase();
- Long l = (Long)timeTable.get( key );
- return l.longValue();
- }
-
- public String[] getValues()
- {
- return units;
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Ear.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Ear.java
deleted file mode 100644
index 712c3fe33..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Ear.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.archive;
-
-import java.io.File;
-import java.io.IOException;
-import org.apache.aut.zip.ZipOutputStream;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-
-/**
- * Creates a EAR archive. Based on WAR task
- *
- * @author Stefan Bodewig
- * @author Les Hughes
- */
-public class Ear
- extends Jar
-{
- private File m_appxml;
- private boolean m_descriptorAdded;
-
- public Ear()
- {
- m_archiveType = "ear";
- m_emptyBehavior = "create";
- }
-
- public void setAppxml( final File appxml )
- throws TaskException
- {
- m_appxml = appxml;
- if( !m_appxml.exists() )
- {
- final String message = "Deployment descriptor: " +
- m_appxml + " does not exist.";
- throw new TaskException( message );
- }
-
- addFileAs( m_appxml, "META-INF/application.xml" );
- }
-
- public void addArchives( ZipFileSet fs )
- {
- // We just set the prefix for this fileset, and pass it up.
- // Do we need to do this? LH
- getContext().debug( "addArchives called" );
- fs.setPrefix( "/" );
- super.addFileset( fs );
- }
-
- protected void initZipOutputStream( final ZipOutputStream zOut )
- throws IOException, TaskException
- {
- if( m_appxml == null && !isInUpdateMode() )
- {
- final String message = "appxml attribute is required";
- throw new TaskException( message );
- }
-
- super.initZipOutputStream( zOut );
- }
-
- protected void zipFile( File file, ZipOutputStream zOut, String vPath )
- throws IOException, TaskException
- {
- // If the file being added is WEB-INF/web.xml, we warn if it's not the
- // one specified in the "webxml" attribute - or if it's being added twice,
- // meaning the same file is specified by the "webxml" attribute and in
- // a element.
- if( vPath.equalsIgnoreCase( "META-INF/aplication.xml" ) )
- {
- if( m_appxml == null ||
- !m_appxml.equals( file ) ||
- m_descriptorAdded )
- {
- final String message = "Warning: selected " + m_archiveType +
- " files include a META-INF/application.xml which will be ignored " +
- "(please use appxml attribute to " + m_archiveType + " task)";
- getContext().warn( message );
- }
- else
- {
- super.zipFile( file, zOut, vPath );
- m_descriptorAdded = true;
- }
- }
- else
- {
- super.zipFile( file, zOut, vPath );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Expand.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Expand.java
deleted file mode 100644
index be45d0d22..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Expand.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.archive;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Date;
-import org.apache.avalon.excalibur.io.FileUtil;
-import org.apache.avalon.excalibur.io.IOUtil;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.framework.PatternSet;
-import org.apache.myrmidon.framework.PatternUtil;
-import org.apache.tools.todo.taskdefs.MatchingTask;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.ScannerUtil;
-
-/**
- * Unzip a file.
- *
- * @author costin@dnt.ro
- * @author Stefan Bodewig
- * @author Magesh Umasankar
- */
-public abstract class Expand
- extends MatchingTask
-{
- private boolean m_overwrite = true;
- private ArrayList m_patternsets = new ArrayList();
- private ArrayList m_filesets = new ArrayList();
- private File m_dest;//req
- private File m_src;
-
- /**
- * Set the destination directory. File will be unzipped into the destination
- * directory.
- *
- * @param dest Path to the directory.
- */
- public void setDest( final File dest )
- {
- m_dest = dest;
- }
-
- /**
- * Should we overwrite files in dest, even if they are newer than the
- * corresponding entries in the archive?
- *
- * @param overwrite The new Overwrite value
- */
- public void setOverwrite( final boolean overwrite )
- {
- m_overwrite = overwrite;
- }
-
- /**
- * Set the path to zip-file.
- *
- * @param src Path to zip-file.
- */
- public void setSrc( final File src )
- {
- m_src = src;
- }
-
- /**
- * Add a fileset
- *
- * @param set The feature to be added to the Fileset attribute
- */
- public void addFileset( final FileSet set )
- {
- m_filesets.add( set );
- }
-
- /**
- * Add a patternset
- *
- * @param set The feature to be added to the Patternset attribute
- */
- public void addPatternset( final PatternSet set )
- {
- m_patternsets.add( set );
- }
-
- /**
- * Do the work.
- *
- * @exception org.apache.myrmidon.api.TaskException Thrown in unrecoverable error.
- */
- public void execute()
- throws TaskException
- {
- validate();
-
- if( m_src != null )
- {
- expandFile( m_src, m_dest );
- }
-
- final int size = m_filesets.size();
- if( size > 0 )
- {
- for( int j = 0; j < size; j++ )
- {
- final FileSet fileSet = (FileSet)m_filesets.get( j );
- final DirectoryScanner scanner = ScannerUtil.getDirectoryScanner( fileSet );
- final File fromDir = fileSet.getDir();
-
- final String[] files = scanner.getIncludedFiles();
- for( int i = 0; i < files.length; ++i )
- {
- final File file = new File( fromDir, files[ i ] );
- expandFile( file, m_dest );
- }
- }
- }
- }
-
- private void validate()
- throws TaskException
- {
- if( m_src == null && m_filesets.size() == 0 )
- {
- final String message = "src attribute and/or filesets must be specified";
- throw new TaskException( message );
- }
-
- if( m_dest == null )
- {
- final String message = "Dest attribute must be specified";
- throw new TaskException( message );
- }
-
- if( m_dest.exists() && !m_dest.isDirectory() )
- {
- final String message = "Dest must be a directory.";
- throw new TaskException( message );
- }
-
- if( m_src != null && m_src.isDirectory() )
- {
- final String message = "Src must not be a directory." +
- " Use nested filesets instead.";
- throw new TaskException( message );
- }
- }
-
- /*
- * This method is to be overridden by extending unarchival tasks.
- */
- protected void expandFile( final File src, final File dir )
- throws TaskException
- {
- if( getContext().isInfoEnabled() )
- {
- final String message = "Expanding: " + src + " into " + dir;
- getContext().info( message );
- }
-
- try
- {
- expandArchive( src, dir );
- }
- catch( final IOException ioe )
- {
- final String message = "Error while expanding " + src.getPath();
- throw new TaskException( message, ioe );
- }
-
- if( getContext().isDebugEnabled() )
- {
- final String message = "expand complete";
- getContext().debug( message );
- }
- }
-
- protected abstract void expandArchive( final File src, final File dir )
- throws IOException, TaskException;
-
- protected void extractFile( final File dir,
- final InputStream input,
- final String entryName,
- final Date date,
- final boolean isDirectory )
- throws IOException, TaskException
- {
-
- final int size = m_patternsets.size();
- if( m_patternsets != null && size > 0 )
- {
- boolean included = false;
- for( int i = 0; i < size; i++ )
- {
- PatternSet p = (PatternSet)m_patternsets.get( i );
- final TaskContext context = getContext();
- String[] incls = PatternUtil.getIncludePatterns( p, context );
- if( incls != null )
- {
- for( int j = 0; j < incls.length; j++ )
- {
- boolean isIncl = ScannerUtil.match( incls[ j ], entryName );
- if( isIncl )
- {
- included = true;
- break;
- }
- }
- }
- final TaskContext context1 = getContext();
- String[] excls = PatternUtil.getExcludePatterns( p, context1 );
- if( excls != null )
- {
- for( int j = 0; j < excls.length; j++ )
- {
- boolean isExcl = ScannerUtil.match( excls[ j ], entryName );
- if( isExcl )
- {
- included = false;
- break;
- }
- }
- }
- }
-
- if( !included )
- {
- //Do not process this file
- return;
- }
- }
-
- final File file = FileUtil.resolveFile( dir, entryName );
- try
- {
- if( !m_overwrite && file.exists() &&
- file.lastModified() >= date.getTime() )
- {
- final String message = "Skipping " + file + " as it is up-to-date";
- getContext().debug( message );
- return;
- }
-
- getContext().debug( "expanding " + entryName + " to " + file );
-
- // create intermediary directories - sometimes zip don't add them
- final File parent = file.getParentFile();
- parent.mkdirs();
-
- if( isDirectory )
- {
- file.mkdirs();
- }
- else
- {
- FileOutputStream fos = null;
- try
- {
- fos = new FileOutputStream( file );
- IOUtil.copy( input, fos );
- }
- finally
- {
- IOUtil.shutdownStream( fos );
- }
- }
-
- file.setLastModified( date.getTime() );
- }
- catch( final FileNotFoundException fnfe )
- {
- final String message = "Unable to expand to file " + file.getPath();
- getContext().warn( message );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Jar.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Jar.java
deleted file mode 100644
index 355c730bb..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Jar.java
+++ /dev/null
@@ -1,397 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.archive;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.Reader;
-import java.util.Enumeration;
-import java.util.zip.ZipFile;
-import org.apache.aut.zip.ZipOutputStream;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.taskdefs.manifest.Manifest;
-import org.apache.tools.todo.taskdefs.manifest.ManifestException;
-import org.apache.tools.todo.taskdefs.manifest.ManifestUtil;
-import org.apache.tools.todo.types.FileScanner;
-
-/**
- * Creates a JAR archive.
- *
- * @author James Davidson duncan@x180.com
- */
-public class Jar
- extends Zip
-{
- /**
- * The index file name.
- */
- private final static String INDEX_NAME = "META-INF/INDEX.LIST";
-
- /**
- * true if a manifest has been specified in the task
- */
- private boolean buildFileManifest;
-
- /**
- * jar index is JDK 1.3+ only
- */
- private boolean m_index;
- private Manifest m_execManifest;
- private Manifest m_manifest;
- private File m_manifestFile;
-
- /**
- * constructor
- */
- public Jar()
- {
- super();
- m_archiveType = "jar";
- m_emptyBehavior = "create";
- setEncoding( "UTF8" );
- }
-
- /**
- * Set whether or not to create an index list for classes to speed up
- * classloading.
- *
- * @param flag The new Index value
- */
- public void setIndex( boolean flag )
- {
- m_index = flag;
- }
-
- public void setManifest( File manifestFile )
- throws TaskException
- {
- if( !manifestFile.exists() )
- {
- final String message = "Manifest file: " + manifestFile + " does not exist.";
- throw new TaskException( message );
- }
-
- this.m_manifestFile = manifestFile;
-
- Reader r = null;
- try
- {
- r = new FileReader( manifestFile );
- Manifest newManifest = ManifestUtil.buildManifest( r );
- if( m_manifest == null )
- {
- m_manifest = ManifestUtil.getDefaultManifest();
- }
- m_manifest.merge( newManifest );
- }
- catch( ManifestException e )
- {
- final String message = "Manifest " + manifestFile + " is invalid: " + e.getMessage();
- getContext().error( message );
- throw new TaskException( message, e );
- }
- catch( IOException e )
- {
- final String message = "Unable to read manifest file: " + manifestFile;
- throw new TaskException( message, e );
- }
- finally
- {
- if( r != null )
- {
- try
- {
- r.close();
- }
- catch( IOException e )
- {
- // do nothing
- }
- }
- }
- }
-
- public void setWhenempty( WhenEmpty we )
- {
- final String message = "JARs are never empty, they contain at least a manifest file";
- getContext().warn( message );
- }
-
- public void addManifest( Manifest newManifest )
- throws ManifestException, TaskException
- {
- if( m_manifest == null )
- {
- m_manifest = ManifestUtil.getDefaultManifest();
- }
- m_manifest.merge( newManifest );
- buildFileManifest = true;
- }
-
- public void addMetainf( ZipFileSet fs )
- {
- // We just set the prefix for this fileset, and pass it up.
- fs.setPrefix( "META-INF/" );
- super.addFileset( fs );
- }
-
- /**
- * Check whether the archive is up-to-date;
- *
- * @param scanners list of prepared scanners containing files to archive
- * @param zipFile intended archive file (may or may not exist)
- * @return true if nothing need be done (may have done something already);
- * false if archive creation should proceed
- * @exception org.apache.myrmidon.api.TaskException if it likes
- */
- protected boolean isUpToDate( FileScanner[] scanners, File zipFile )
- throws TaskException
- {
- // need to handle manifest as a special check
- if( buildFileManifest || m_manifestFile == null )
- {
- java.util.zip.ZipFile theZipFile = null;
- try
- {
- theZipFile = new ZipFile( zipFile );
- java.util.zip.ZipEntry entry = theZipFile.getEntry( "META-INF/MANIFEST.MF" );
- if( entry == null )
- {
- getContext().debug( "Updating jar since the current jar has no manifest" );
- return false;
- }
- Manifest currentManifest = ManifestUtil.buildManifest( new InputStreamReader( theZipFile.getInputStream( entry ) ) );
- if( m_manifest == null )
- {
- m_manifest = ManifestUtil.getDefaultManifest();
- }
- if( !currentManifest.equals( m_manifest ) )
- {
- getContext().debug( "Updating jar since jar manifest has changed" );
- return false;
- }
- }
- catch( Exception e )
- {
- // any problems and we will rebuild
- getContext().debug( "Updating jar since cannot read current jar manifest: " + e.getClass().getName() + e.getMessage() );
- return false;
- }
- finally
- {
- if( theZipFile != null )
- {
- try
- {
- theZipFile.close();
- }
- catch( IOException e )
- {
- //ignore
- }
- }
- }
- }
- else if( m_manifestFile.lastModified() > zipFile.lastModified() )
- {
- return false;
- }
- return super.isUpToDate( scanners, zipFile );
- }
-
- protected boolean createEmptyZip( File zipFile )
- {
- // Jar files always contain a manifest and can never be empty
- return false;
- }
-
- protected void finalizeZipOutputStream( ZipOutputStream zOut )
- throws IOException, TaskException
- {
- if( m_index )
- {
- createIndexList( zOut );
- }
- }
-
- protected void initZipOutputStream( ZipOutputStream zOut )
- throws IOException, TaskException
- {
- try
- {
- m_execManifest = ManifestUtil.getDefaultManifest();
-
- if( m_manifest != null )
- {
- m_execManifest.merge( m_manifest );
- }
- /*
- for( Iterator e = m_execManifest.getWarnings(); e.hasNext(); )
- {
- getLogger().warn( "Manifest warning: " + (String)e.next() );
- }
- */
-
- zipDir( null, zOut, "META-INF/" );
- // time to write the manifest
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintWriter writer = new PrintWriter( baos );
- Manifest manifest = m_execManifest;
- ManifestUtil.write( manifest, writer );
- writer.flush();
-
- ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
- super.zipFile( bais, zOut, "META-INF/MANIFEST.MF", System.currentTimeMillis() );
- super.initZipOutputStream( zOut );
- }
- catch( ManifestException e )
- {
- getContext().error( "Manifest is invalid: " + e.getMessage() );
- throw new TaskException( "Invalid Manifest", e );
- }
- }
-
- protected void zipFile( File file, ZipOutputStream zOut, String vPath )
- throws IOException, TaskException
- {
- // If the file being added is META-INF/MANIFEST.MF, we warn if it's not the
- // one specified in the "manifest" attribute - or if it's being added twice,
- // meaning the same file is specified by the "manifeset" attribute and in
- // a element.
- if( vPath.equalsIgnoreCase( "META-INF/MANIFEST.MF" ) )
- {
- final String message = "Warning: selected " + m_archiveType +
- " files include a META-INF/MANIFEST.MF which will be ignored " +
- "(please use manifest attribute to " + m_archiveType + " task)";
- getContext().warn( message );
- }
- else
- {
- super.zipFile( file, zOut, vPath );
- }
-
- }
-
- protected void zipFile( InputStream is, ZipOutputStream zOut, String vPath, long lastModified )
- throws IOException, TaskException
- {
- // If the file being added is META-INF/MANIFEST.MF, we merge it with the
- // current manifest
- if( vPath.equalsIgnoreCase( "META-INF/MANIFEST.MF" ) )
- {
- try
- {
- zipManifestEntry( is );
- }
- catch( IOException e )
- {
- throw new TaskException( "Unable to read manifest file: ", e );
- }
- }
- else
- {
- super.zipFile( is, zOut, vPath, lastModified );
- }
- }
-
- /**
- * Create the index list to speed up classloading. This is a JDK 1.3+
- * specific feature and is enabled by default. {@link
- * http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#JAR%20Index}
- *
- * @param zOut the zip stream representing the jar being built.
- * @throws java.io.IOException thrown if there is an error while creating the index
- * and adding it to the zip stream.
- */
- private void createIndexList( ZipOutputStream zOut )
- throws IOException, TaskException
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- // encoding must be UTF8 as specified in the specs.
- PrintWriter writer = new PrintWriter( new OutputStreamWriter( baos, "UTF8" ) );
-
- // version-info blankline
- writer.println( "JarIndex-Version: 1.0" );
- writer.println();
-
- // header newline
- writer.println( m_file.getName() );
-
- // JarIndex is sorting the directories by ascending order.
- // it's painful to do in JDK 1.1 and it has no value but cosmetic
- // since it will be read into a hashtable by the classloader.
- Enumeration enum = m_addedDirs.keys();
- while( enum.hasMoreElements() )
- {
- String dir = (String)enum.nextElement();
-
- // try to be smart, not to be fooled by a weird directory name
- // @fixme do we need to check for directories starting by ./ ?
- dir = dir.replace( '\\', '/' );
- int pos = dir.lastIndexOf( '/' );
- if( pos != -1 )
- {
- dir = dir.substring( 0, pos );
- }
-
- // looks like nothing from META-INF should be added
- // and the check is not case insensitive.
- // see sun.misc.JarIndex
- if( dir.startsWith( "META-INF" ) )
- {
- continue;
- }
- // name newline
- writer.println( dir );
- }
-
- writer.flush();
- ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
- super.zipFile( bais, zOut, INDEX_NAME, System.currentTimeMillis() );
- }
-
- /**
- * Handle situation when we encounter a manifest file If we haven't been
- * given one, we use this one. If we have, we merge the manifest in,
- * provided it is a new file and not the old one from the JAR we are
- * updating
- *
- * @param is Description of Parameter
- * @exception java.io.IOException Description of Exception
- */
- private void zipManifestEntry( InputStream is )
- throws IOException, TaskException
- {
- try
- {
- if( m_execManifest == null )
- {
- m_execManifest = ManifestUtil.buildManifest( new InputStreamReader( is ) );
- }
- else if( isAddingNewFiles() )
- {
- final Manifest other = ManifestUtil.buildManifest( new InputStreamReader( is ) );
- m_execManifest.merge( other );
- }
- }
- catch( ManifestException e )
- {
- getContext().error( "Manifest is invalid: " + e.getMessage() );
- throw new TaskException( "Invalid Manifest", e );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Tar.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Tar.java
deleted file mode 100644
index f5d5150bb..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Tar.java
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.archive;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import org.apache.aut.tar.TarEntry;
-import org.apache.aut.tar.TarOutputStream;
-import org.apache.avalon.excalibur.io.IOUtil;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.taskdefs.MatchingTask;
-import org.apache.tools.todo.types.ScannerUtil;
-import org.apache.tools.todo.types.SourceFileScanner;
-import org.apache.tools.todo.util.mappers.MergingMapper;
-
-/**
- * Creates a TAR archive.
- *
- * @author Stefano Mazzocchi
- * stefano@apache.org
- * @author Stefan Bodewig
- * @author Magesh Umasankar
- */
-public class Tar
- extends MatchingTask
-{
- private TarLongFileMode longFileMode = createMode();
-
- private TarLongFileMode createMode()
- {
- try
- {
- return new TarLongFileMode();
- }
- catch( TaskException e )
- {
- throw new IllegalStateException( e.getMessage() );
- }
- }
-
- ArrayList filesets = new ArrayList();
- ArrayList fileSetFiles = new ArrayList();
-
- /**
- * Indicates whether the user has been warned about long files already.
- */
- private boolean longWarningGiven = false;
- File baseDir;
-
- File tarFile;
-
- /**
- * This is the base directory to look in for things to tar.
- *
- * @param baseDir The new Basedir value
- */
- public void setBasedir( File baseDir )
- {
- this.baseDir = baseDir;
- }
-
- /**
- * Set how to handle long files. Allowable values are truncate - paths are
- * truncated to the maximum length fail - paths greater than the maximim
- * cause a build exception warn - paths greater than the maximum cause a
- * warning and GNU is used gnu - GNU extensions are used for any paths
- * greater than the maximum. omit - paths greater than the maximum are
- * omitted from the archive
- *
- * @param mode The new Longfile value
- */
- public void setLongfile( TarLongFileMode mode )
- {
- this.longFileMode = mode;
- }
-
- /**
- * This is the name/location of where to create the tar file.
- *
- * @param tarFile The new Tarfile value
- */
- public void setTarfile( File tarFile )
- {
- this.tarFile = tarFile;
- }
-
- public TarFileSet createTarFileSet()
- {
- TarFileSet fileset = new TarFileSet();
- filesets.add( fileset );
- return fileset;
- }
-
- public void execute()
- throws TaskException
- {
- if( tarFile == null )
- {
- throw new TaskException( "tarfile attribute must be set!" );
- }
-
- if( tarFile.exists() && tarFile.isDirectory() )
- {
- throw new TaskException( "tarfile is a directory!" );
- }
-
- if( tarFile.exists() && !tarFile.canWrite() )
- {
- throw new TaskException( "Can not write to the specified tarfile!" );
- }
-
- if( baseDir != null )
- {
- if( !baseDir.exists() )
- {
- throw new TaskException( "basedir does not exist!" );
- }
-
- // add the main fileset to the list of filesets to process.
- final TarFileSet mainFileSet = new TarFileSet( /*fileset*/ );
- mainFileSet.setDir( baseDir );
- filesets.add( mainFileSet );
- }
-
- if( filesets.size() == 0 )
- {
- throw new TaskException( "You must supply either a basdir attribute or some nested filesets." );
- }
-
- // check if tr is out of date with respect to each
- // fileset
- boolean upToDate = true;
- for( Iterator e = filesets.iterator(); e.hasNext(); )
- {
- TarFileSet fs = (TarFileSet)e.next();
- String[] files = ScannerUtil.getFiles( fs );
-
- if( !archiveIsUpToDate( files ) )
- {
- upToDate = false;
- }
-
- for( int i = 0; i < files.length; ++i )
- {
- if( tarFile.equals( new File( fs.getDir(), files[ i ] ) ) )
- {
- throw new TaskException( "A tar file cannot include itself" );
- }
- }
- }
-
- if( upToDate )
- {
- getContext().info( "Nothing to do: " + tarFile.getAbsolutePath() + " is up to date." );
- return;
- }
-
- getContext().info( "Building tar: " + tarFile.getAbsolutePath() );
-
- TarOutputStream tOut = null;
- try
- {
- tOut = new TarOutputStream( new FileOutputStream( tarFile ) );
- if( longFileMode.isTruncateMode() )
- {
- tOut.setLongFileMode( TarOutputStream.LONGFILE_TRUNCATE );
- }
- else if( longFileMode.isFailMode() ||
- longFileMode.isOmitMode() )
- {
- tOut.setLongFileMode( TarOutputStream.LONGFILE_ERROR );
- }
- else
- {
- // warn or GNU
- tOut.setLongFileMode( TarOutputStream.LONGFILE_GNU );
- }
-
- longWarningGiven = false;
- for( Iterator e = filesets.iterator(); e.hasNext(); )
- {
- TarFileSet fs = (TarFileSet)e.next();
- String[] files = ScannerUtil.getFiles( fs );
- for( int i = 0; i < files.length; i++ )
- {
- File f = new File( fs.getDir(), files[ i ] );
- String name = files[ i ].replace( File.separatorChar, '/' );
- tarFile( f, tOut, name, fs );
- }
- }
- }
- catch( IOException ioe )
- {
- String msg = "Problem creating TAR: " + ioe.getMessage();
- throw new TaskException( msg, ioe );
- }
- finally
- {
- if( tOut != null )
- {
- try
- {
- // close up
- tOut.close();
- }
- catch( IOException e )
- {
- }
- }
- }
- }
-
- private boolean archiveIsUpToDate( final String[] files )
- throws TaskException
- {
- final SourceFileScanner scanner = new SourceFileScanner();
- final MergingMapper mapper = new MergingMapper();
- mapper.setTo( tarFile.getAbsolutePath() );
- return scanner.restrict( files, baseDir, null, mapper, getContext() ).length == 0;
- }
-
- private void tarFile( final File file,
- final TarOutputStream output,
- final String path,
- final TarFileSet tarFileSet )
- throws IOException, TaskException
- {
- String storedPath = path;
- // don't add "" to the archive
- if( storedPath.length() <= 0 )
- {
- return;
- }
-
- if( file.isDirectory() && !storedPath.endsWith( "/" ) )
- {
- storedPath += "/";
- }
-
- if( storedPath.length() >= TarEntry.NAMELEN )
- {
- if( longFileMode.isOmitMode() )
- {
- final String message = "Omitting: " + storedPath;
- getContext().info( message );
- return;
- }
- else if( longFileMode.isWarnMode() )
- {
- final String message = "Entry: " + storedPath + " longer than " +
- TarEntry.NAMELEN + " characters.";
- getContext().warn( message );
- if( !longWarningGiven )
- {
- final String message2 = "Resulting tar file can only be processed successfully"
- + " by GNU compatible tar commands";
- getContext().warn( message2 );
- longWarningGiven = true;
- }
- }
- else if( longFileMode.isFailMode() )
- {
- final String message = "Entry: " + storedPath + " longer than " +
- TarEntry.NAMELEN + "characters.";
- throw new TaskException( message );
- }
- }
-
- FileInputStream input = null;
- try
- {
- final TarEntry entry = new TarEntry( storedPath );
- entry.setModTime( file.lastModified() );
- if( !file.isDirectory() )
- {
- entry.setSize( file.length() );
- entry.setMode( tarFileSet.getMode() );
- }
- entry.setUserName( tarFileSet.getUserName() );
- entry.setGroupName( tarFileSet.getGroup() );
-
- output.putNextEntry( entry );
-
- if( !file.isDirectory() )
- {
- input = new FileInputStream( file );
- IOUtil.copy( input, output );
- }
-
- output.closeEntry();
- }
- finally
- {
- IOUtil.shutdownStream( input );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/TarFileSet.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/TarFileSet.java
deleted file mode 100644
index 8cbc4cfaf..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/TarFileSet.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.archive;
-
-import org.apache.tools.todo.types.FileSet;
-
-public class TarFileSet
- extends FileSet
-{
- private int m_mode = 0100644;
- private String m_userName = "";
- private String m_groupName = "";
-
- public void setGroup( final String groupName )
- {
- m_groupName = groupName;
- }
-
- public void setMode( final String octalString )
- {
- m_mode = 0100000 | Integer.parseInt( octalString, 8 );
- }
-
- public void setUserName( final String userName )
- {
- m_userName = userName;
- }
-
- protected String getGroup()
- {
- return m_groupName;
- }
-
- protected int getMode()
- {
- return m_mode;
- }
-
- protected String getUserName()
- {
- return m_userName;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/TarLongFileMode.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/TarLongFileMode.java
deleted file mode 100644
index 0f728f481..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/TarLongFileMode.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.archive;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.EnumeratedAttribute;
-
-/**
- * Valid Modes for LongFile attribute to Tar Task
- *
- * @author Magesh Umasankar
- */
-public class TarLongFileMode
- extends EnumeratedAttribute
-{
- // permissable values for longfile attribute
- public final static String WARN = "warn";
- public final static String FAIL = "fail";
- public final static String TRUNCATE = "truncate";
- public final static String GNU = "gnu";
- public final static String OMIT = "omit";
-
- private final String[] validModes = {WARN, FAIL, TRUNCATE, GNU, OMIT};
-
- public TarLongFileMode()
- throws TaskException
- {
- super();
- setValue( WARN );
- }
-
- public String[] getValues()
- {
- return validModes;
- }
-
- public boolean isFailMode()
- {
- return FAIL.equalsIgnoreCase( getValue() );
- }
-
- public boolean isGnuMode()
- {
- return GNU.equalsIgnoreCase( getValue() );
- }
-
- public boolean isOmitMode()
- {
- return OMIT.equalsIgnoreCase( getValue() );
- }
-
- public boolean isTruncateMode()
- {
- return TRUNCATE.equalsIgnoreCase( getValue() );
- }
-
- public boolean isWarnMode()
- {
- return WARN.equalsIgnoreCase( getValue() );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Untar.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Untar.java
deleted file mode 100644
index 09e814529..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Untar.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.archive;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import org.apache.aut.tar.TarEntry;
-import org.apache.aut.tar.TarInputStream;
-import org.apache.avalon.excalibur.io.IOUtil;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.taskdefs.archive.Expand;
-
-/**
- * Untar a file. Heavily based on the Expand task.
- *
- * @author Stefan Bodewig
- * @author Magesh Umasankar
- */
-public class Untar
- extends Expand
-{
- protected void expandArchive( final File src, final File dir )
- throws IOException, TaskException
- {
- TarInputStream input = null;
- FileInputStream fileInput = null;
- try
- {
- fileInput = new FileInputStream( src );
- input = new TarInputStream( fileInput );
-
- TarEntry entry = null;
- while( ( entry = input.getNextEntry() ) != null )
- {
- extractFile( dir,
- input,
- entry.getName(),
- entry.getModTime(),
- entry.isDirectory() );
- }
- }
- finally
- {
- IOUtil.shutdownStream( fileInput );
- IOUtil.shutdownStream( input );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Unzip.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Unzip.java
deleted file mode 100644
index 0169e4969..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Unzip.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.archive;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Date;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-import org.apache.avalon.excalibur.io.IOUtil;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.taskdefs.archive.Expand;
-
-/**
- * Untar a file. Heavily based on the Expand task.
- *
- * @author Stefan Bodewig
- * @author Magesh Umasankar
- */
-public class Unzip
- extends Expand
-{
- protected void expandArchive( final File src, final File dir )
- throws IOException, TaskException
- {
- ZipInputStream zis = null;
- try
- {
- // code from WarExpand
- zis = new ZipInputStream( new FileInputStream( src ) );
- ZipEntry ze = null;
-
- while( ( ze = zis.getNextEntry() ) != null )
- {
- final Date date = new Date( ze.getTime() );
- extractFile( dir,
- zis,
- ze.getName(),
- date,
- ze.isDirectory() );
- }
- }
- finally
- {
- IOUtil.shutdownStream( zis );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/War.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/War.java
deleted file mode 100644
index 8d46391f1..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/War.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.archive;
-
-import java.io.File;
-import java.io.IOException;
-import org.apache.aut.zip.ZipOutputStream;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.taskdefs.archive.Jar;
-
-/**
- * Creates a WAR archive.
- *
- * @author Stefan Bodewig
- */
-public class War
- extends Jar
-{
- private File m_webxml;
- private boolean m_descriptorAdded;
-
- public War()
- {
- super();
- m_archiveType = "war";
- m_emptyBehavior = "create";
- }
-
- public void setWebxml( final File descr )
- throws TaskException
- {
- m_webxml = descr;
- if( !m_webxml.exists() )
- {
- final String message = "Deployment descriptor: " +
- m_webxml + " does not exist.";
- throw new TaskException( message );
- }
-
- addFileAs( descr, "WEB-INF/web.xml" );
- }
-
- public void addClasses( final ZipFileSet fs )
- {
- // We just set the prefix for this fileset, and pass it up.
- fs.setPrefix( "WEB-INF/classes/" );
- super.addFileset( fs );
- }
-
- public void addLib( final ZipFileSet fs )
- {
- // We just set the prefix for this fileset, and pass it up.
- fs.setPrefix( "WEB-INF/lib/" );
- super.addFileset( fs );
- }
-
- public void addWebinf( final ZipFileSet fs )
- {
- // We just set the prefix for this fileset, and pass it up.
- fs.setPrefix( "WEB-INF/" );
- super.addFileset( fs );
- }
-
- protected void initZipOutputStream( final ZipOutputStream zOut )
- throws IOException, TaskException
- {
- // If no webxml file is specified, it's an error.
- if( m_webxml == null && !isInUpdateMode() )
- {
- throw new TaskException( "webxml attribute is required" );
- }
-
- super.initZipOutputStream( zOut );
- }
-
- protected void zipFile( final File file,
- final ZipOutputStream zOut,
- final String vPath )
- throws IOException, TaskException
- {
- // If the file being added is WEB-INF/web.xml, we warn if it's not the
- // one specified in the "webxml" attribute - or if it's being added twice,
- // meaning the same file is specified by the "webxml" attribute and in
- // a element.
- if( vPath.equalsIgnoreCase( "WEB-INF/web.xml" ) )
- {
- if( m_webxml == null || !m_webxml.equals( file ) || m_descriptorAdded )
- {
- final String message = "Warning: selected " + m_archiveType +
- " files include a WEB-INF/web.xml which will be ignored " +
- "(please use webxml attribute to " + m_archiveType + " task)";
- getContext().warn( message );
- }
- else
- {
- super.zipFile( file, zOut, vPath );
- m_descriptorAdded = true;
- }
- }
- else
- {
- super.zipFile( file, zOut, vPath );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/WhenEmpty.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/WhenEmpty.java
deleted file mode 100644
index f4717545c..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/WhenEmpty.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.archive;
-
-import org.apache.tools.todo.types.EnumeratedAttribute;
-
-/**
- * Possible behaviors when there are no matching files for the task.
- */
-public class WhenEmpty
- extends EnumeratedAttribute
-{
- public String[] getValues()
- {
- return new String[]{"fail", "skip", "create"};
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Zip.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Zip.java
deleted file mode 100644
index b2a5eba4e..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/Zip.java
+++ /dev/null
@@ -1,898 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.archive;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.Stack;
-import java.util.zip.CRC32;
-import java.util.zip.ZipInputStream;
-import org.apache.aut.zip.ZipEntry;
-import org.apache.aut.zip.ZipOutputStream;
-import org.apache.avalon.excalibur.io.IOUtil;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.taskdefs.MatchingTask;
-import org.apache.tools.todo.taskdefs.archive.WhenEmpty;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.FileScanner;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.ScannerUtil;
-import org.apache.tools.todo.types.SourceFileScanner;
-import org.apache.tools.todo.util.mappers.MergingMapper;
-
-/**
- * Create a ZIP archive.
- *
- * @author James Davidson duncan@x180.com
- * @author Jon S. Stevens jon@clearink.com
- * @author Stefan Bodewig
- */
-public class Zip
- extends MatchingTask
-{
- // For directories:
- private final static long EMPTY_CRC = new CRC32().getValue();
- private boolean m_compress = true;
- private boolean m_update;
- private boolean m_filesonly;
- protected String m_archiveType = "zip";
- protected String m_emptyBehavior = "skip";
- private ArrayList m_filesets = new ArrayList();
- protected Hashtable m_addedDirs = new Hashtable();
- private ArrayList m_addedFiles = new ArrayList();
- protected File m_file;
-
- /**
- * true when we are adding new files into the Zip file, as opposed to adding
- * back the unchanged files
- */
- private boolean m_addingNewFiles;
- private File m_baseDir;
-
- /**
- * Encoding to use for filenames, defaults to the platform's default
- * encoding.
- */
- private String m_encoding;
-
- private static String[][] grabFileNames( final FileScanner[] scanners )
- throws TaskException
- {
- String[][] result = new String[ scanners.length ][];
- for( int i = 0; i < scanners.length; i++ )
- {
- String[] files = scanners[ i ].getIncludedFiles();
- String[] dirs = scanners[ i ].getIncludedDirectories();
- result[ i ] = new String[ files.length + dirs.length ];
- System.arraycopy( files, 0, result[ i ], 0, files.length );
- System.arraycopy( dirs, 0, result[ i ], files.length, dirs.length );
- }
- return result;
- }
-
- private static File[] grabFiles( final FileScanner[] scanners,
- final String[][] filenames )
- {
- final ArrayList files = new ArrayList();
- for( int i = 0; i < filenames.length; i++ )
- {
- final File baseDir = scanners[ i ].getBasedir();
- for( int j = 0; j < filenames[ i ].length; j++ )
- {
- files.add( new File( baseDir, filenames[ i ][ j ] ) );
- }
- }
- final File[] toret = new File[ files.size() ];
- return (File[])files.toArray( toret );
- }
-
- /**
- * This is the base directory to look in for things to zip.
- *
- * @param baseDir The new Basedir value
- */
- public void setBasedir( final File baseDir )
- {
- m_baseDir = baseDir;
- }
-
- /**
- * Sets whether we want to compress the files or only store them.
- *
- * @param compress The new Compress value
- */
- public void setCompress( final boolean compress )
- {
- m_compress = compress;
- }
-
- /**
- * Encoding to use for filenames, defaults to the platform's default
- * encoding.
- *
- * For a list of possible values see
- * http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html
- * .
- *
- * @param encoding The new Encoding value
- */
- public void setEncoding( final String encoding )
- {
- m_encoding = encoding;
- }
-
- /**
- * This is the name/location of where to create the .zip file.
- *
- * @param file The new File value
- */
- public void setFile( final File file )
- {
- m_file = file;
- }
-
- /**
- * Emulate Sun's jar utility by not adding parent dirs
- */
- public void setFilesonly( final boolean filesonly )
- {
- m_filesonly = filesonly;
- }
-
- /**
- * Sets whether we want to update the file (if it exists) or create a new
- * one.
- */
- public void setUpdate( final boolean update )
- {
- m_update = update;
- }
-
- /**
- * Sets behavior of the task when no files match. Possible values are:
- * fail
(throw an exception and halt the build); skip
- * (do not create any archive, but issue a warning); create
- * (make an archive with no entries). Default for zip tasks is skip
- * ; for jar tasks, create
.
- *
- * @param we The new Whenempty value
- */
- public void setWhenempty( final WhenEmpty we )
- {
- m_emptyBehavior = we.getValue();
- }
-
- /**
- * Are we updating an existing archive?
- *
- * @return The InUpdateMode value
- */
- protected final boolean isInUpdateMode()
- {
- return m_update;
- }
-
- /**
- * Adds a set of files (nested fileset attribute).
- */
- public void addFileset( final FileSet set )
- {
- m_filesets.add( set );
- }
-
- /**
- * Adds a set of files (nested zipfileset attribute) that can be read from
- * an archive and be given a prefix/fullpath.
- *
- * @param set The feature to be added to the Zipfileset attribute
- */
- public void addZipfileset( final ZipFileSet set )
- {
- m_filesets.add( set );
- }
-
- public void execute()
- throws TaskException
- {
- if( m_baseDir == null && m_filesets.size() == 0 &&
- "zip".equals( m_archiveType ) )
- {
- final String message = "basedir attribute must be set, or at least " +
- "one fileset must be given!";
- throw new TaskException( message );
- }
-
- if( m_file == null )
- {
- final String message = "You must specify the " +
- m_archiveType + " file to create!";
- throw new TaskException( message );
- }
-
- // Renamed version of original file, if it exists
- File renamedFile = null;
- // Whether or not an actual update is required -
- // we don't need to update if the original file doesn't exist
-
- m_addingNewFiles = true;
- m_update = m_update && m_file.exists();
- if( m_update )
- {
- try
- {
- renamedFile = File.createTempFile( "zip", ".tmp",
- m_file.getParentFile() );
- }
- catch( final IOException ioe )
- {
- throw new TaskException( ioe.toString(), ioe );
- }
-
- try
- {
- if( !m_file.renameTo( renamedFile ) )
- {
- throw new TaskException( "Unable to rename old file to temporary file" );
- }
- }
- catch( SecurityException e )
- {
- throw new TaskException( "Not allowed to rename old file to temporary file" );
- }
- }
-
- // Create the scanners to pass to isUpToDate().
- ArrayList dss = new ArrayList();
- if( m_baseDir != null )
- {
- dss.add( getDirectoryScanner( m_baseDir ) );
- }
- final int size = m_filesets.size();
- for( int i = 0; i < size; i++ )
- {
- final FileSet fileSet = (FileSet)m_filesets.get( i );
- final DirectoryScanner scanner = getScanner( fileSet );
- dss.add( scanner );
- }
- int dssSize = dss.size();
- FileScanner[] scanners = new FileScanner[ dssSize ];
- scanners = (FileScanner[])dss.toArray( scanners );
-
- // quick exit if the target is up to date
- // can also handle empty archives
- if( isUpToDate( scanners, m_file ) )
- {
- return;
- }
-
- String action = m_update ? "Updating " : "Building ";
-
- getContext().info( action + m_archiveType + ": " + m_file.getAbsolutePath() );
-
- boolean success = false;
- try
- {
- ZipOutputStream zOut =
- new ZipOutputStream( new FileOutputStream( m_file ) );
- zOut.setEncoding( m_encoding );
- try
- {
- if( m_compress )
- {
- zOut.setMethod( ZipOutputStream.DEFLATED );
- }
- else
- {
- zOut.setMethod( ZipOutputStream.STORED );
- }
- initZipOutputStream( zOut );
-
- // Add the implicit fileset to the archive.
- if( m_baseDir != null )
- {
- addFiles( getDirectoryScanner( m_baseDir ), zOut, "", "" );
- }
- // Add the explicit filesets to the archive.
- addFiles( m_filesets, zOut );
- if( m_update )
- {
- m_addingNewFiles = false;
- ZipFileSet oldFiles = new ZipFileSet();
- oldFiles.setSrc( renamedFile );
-
- StringBuffer exclusionPattern = new StringBuffer();
- final int addedFilesCount = m_addedFiles.size();
- for( int i = 0; i < addedFilesCount; i++ )
- {
- if( i != 0 )
- {
- exclusionPattern.append( "," );
- }
- exclusionPattern.append( (String)m_addedFiles.get( i ) );
- }
- oldFiles.setExcludes( exclusionPattern.toString() );
- ArrayList tmp = new ArrayList();
- tmp.add( oldFiles );
- addFiles( tmp, zOut );
- }
- finalizeZipOutputStream( zOut );
- success = true;
- }
- finally
- {
- // Close the output stream.
- try
- {
- if( zOut != null )
- {
- zOut.close();
- }
- }
- catch( IOException ex )
- {
- // If we're in this finally clause because of an exception, we don't
- // really care if there's an exception when closing the stream. E.g. if it
- // throws "ZIP file must have at least one entry", because an exception happened
- // before we added any files, then we must swallow this exception. Otherwise,
- // the error that's reported will be the close() error, which is not the real
- // cause of the problem.
- if( success )
- {
- throw ex;
- }
- }
- }
- }
- catch( IOException ioe )
- {
- String msg = "Problem creating " + m_archiveType + ": " + ioe.getMessage();
-
- // delete a bogus ZIP file
- if( !m_file.delete() )
- {
- msg += " (and the archive is probably corrupt but I could not delete it)";
- }
-
- if( m_update )
- {
- if( !renamedFile.renameTo( m_file ) )
- {
- msg += " (and I couldn't rename the temporary file " +
- renamedFile.getName() + " back)";
- }
- }
-
- throw new TaskException( msg, ioe );
- }
-
- // If we've been successful on an update, delete the temporary file
- if( success && m_update )
- {
- if( !renamedFile.delete() )
- {
- final String message = "Warning: unable to delete temporary file " +
- renamedFile.getName();
- getContext().warn( message );
- }
- }
- }
-
- private DirectoryScanner getScanner( final FileSet fileSet )
- throws TaskException
- {
- if( fileSet instanceof ZipFileSet )
- {
- final ZipFileSet zipFileSet = (ZipFileSet)fileSet;
- return ScannerUtil.getZipScanner( zipFileSet );
- }
- else
- {
- return ScannerUtil.getDirectoryScanner( fileSet );
- }
- }
-
- protected void addFileAs( final File file, final String name )
- throws TaskException
- {
- // Create a ZipFileSet for this file, and pass it up.
- final ZipFileSet fs = new ZipFileSet();
- fs.setDir( file.getParentFile() );
- fs.setIncludes( file.getName() );
- fs.setFullpath( name );
- addFileset( fs );
- }
-
- /**
- * Indicates if the task is adding new files into the archive as opposed to
- * copying back unchanged files from the backup copy
- *
- * @return The AddingNewFiles value
- */
- protected final boolean isAddingNewFiles()
- {
- return m_addingNewFiles;
- }
-
- /**
- * Check whether the archive is up-to-date; and handle behavior for empty
- * archives.
- *
- * @param scanners list of prepared scanners containing files to archive
- * @param zipFile intended archive file (may or may not exist)
- * @return true if nothing need be done (may have done something already);
- * false if archive creation should proceed
- * @exception org.apache.myrmidon.api.TaskException if it likes
- */
- protected boolean isUpToDate( FileScanner[] scanners, File zipFile )
- throws TaskException
- {
- String[][] fileNames = grabFileNames( scanners );
- File[] files = grabFiles( scanners, fileNames );
- if( files.length == 0 )
- {
- if( m_emptyBehavior.equals( "skip" ) )
- {
- final String message = "Warning: skipping " + m_archiveType + " archive " + zipFile +
- " because no files were included.";
- getContext().warn( message );
- return true;
- }
- else if( m_emptyBehavior.equals( "fail" ) )
- {
- throw new TaskException( "Cannot create " + m_archiveType + " archive " + zipFile +
- ": no files were included." );
- }
- else
- {
- // Create.
- return createEmptyZip( zipFile );
- }
- }
- else
- {
- for( int i = 0; i < files.length; ++i )
- {
- if( files[ i ].equals( zipFile ) )
- {
- throw new TaskException( "A zip file cannot include itself" );
- }
- }
-
- if( !zipFile.exists() )
- {
- return false;
- }
-
- final SourceFileScanner scanner = new SourceFileScanner();
- MergingMapper mm = new MergingMapper();
- mm.setTo( zipFile.getAbsolutePath() );
- for( int i = 0; i < scanners.length; i++ )
- {
- if( scanner.restrict( fileNames[ i ], scanners[ i ].getBasedir(), null,
- mm, getContext() ).length > 0 )
- {
- return false;
- }
- }
- return true;
- }
- }
-
- /**
- * Add all files of the given FileScanner to the ZipOutputStream prependig
- * the given prefix to each filename.
- *
- * Ensure parent directories have been added as well.
- *
- * @param scanner The feature to be added to the Files attribute
- * @param zOut The feature to be added to the Files attribute
- * @param prefix The feature to be added to the Files attribute
- * @param fullpath The feature to be added to the Files attribute
- * @exception java.io.IOException Description of Exception
- */
- protected void addFiles( FileScanner scanner, ZipOutputStream zOut,
- String prefix, String fullpath )
- throws IOException, TaskException
- {
- if( prefix.length() > 0 && fullpath.length() > 0 )
- {
- throw new TaskException( "Both prefix and fullpath attributes may not be set on the same fileset." );
- }
-
- File thisBaseDir = scanner.getBasedir();
-
- // directories that matched include patterns
- String[] dirs = scanner.getIncludedDirectories();
- if( dirs.length > 0 && fullpath.length() > 0 )
- {
- throw new TaskException( "fullpath attribute may only be specified for filesets that specify a single file." );
- }
- for( int i = 0; i < dirs.length; i++ )
- {
- final String dir = dirs[ i ];
- if( "".equals( dir ) )
- {
- continue;
- }
- final String name = getName( dir );
- addParentDirs( thisBaseDir, name, zOut, prefix );
- }
-
- // files that matched include patterns
- String[] files = scanner.getIncludedFiles();
- if( files.length > 1 && fullpath.length() > 0 )
- {
- throw new TaskException( "fullpath attribute may only be specified for filesets that specify a single file." );
- }
- for( int i = 0; i < files.length; i++ )
- {
- File f = new File( thisBaseDir, files[ i ] );
- if( fullpath.length() > 0 )
- {
- // Add this file at the specified location.
- addParentDirs( null, fullpath, zOut, "" );
- zipFile( f, zOut, fullpath );
- }
- else
- {
- // Add this file with the specified prefix.
- String name = files[ i ].replace( File.separatorChar, '/' );
- addParentDirs( thisBaseDir, name, zOut, prefix );
- zipFile( f, zOut, prefix + name );
- }
- }
- }
-
- private String getName( final String dir )
- {
- String name = dir.replace( File.separatorChar, '/' );
- if( !name.endsWith( "/" ) )
- {
- name += "/";
- }
- return name;
- }
-
- /**
- * Iterate over the given ArrayList of (zip)filesets and add all files to the
- * ZipOutputStream using the given prefix or fullpath.
- *
- * @param filesets The feature to be added to the Files attribute
- * @param zOut The feature to be added to the Files attribute
- * @exception java.io.IOException Description of Exception
- */
- protected void addFiles( ArrayList filesets, ZipOutputStream zOut )
- throws IOException, TaskException
- {
- // Add each fileset in the ArrayList.
- final int size = filesets.size();
- for( int i = 0; i < size; i++ )
- {
- FileSet fs = (FileSet)filesets.get( i );
- DirectoryScanner ds = getScanner( fs );
-
- String prefix = "";
- String fullpath = "";
- if( fs instanceof ZipFileSet )
- {
- ZipFileSet zfs = (ZipFileSet)fs;
- prefix = getPrefix( zfs.getPrefix() );
- fullpath = zfs.getFullpath();
- }
-
-
- // Need to manually add either fullpath's parent directory, or
- // the prefix directory, to the archive.
- if( prefix.length() > 0 )
- {
- addParentDirs( null, prefix, zOut, "" );
- zipDir( null, zOut, prefix );
- }
- else if( fullpath.length() > 0 )
- {
- addParentDirs( null, fullpath, zOut, "" );
- }
-
- if( fs instanceof ZipFileSet
- && ( (ZipFileSet)fs ).getSrc() != null )
- {
- addZipEntries( (ZipFileSet)fs, ds, zOut, prefix, fullpath );
- }
- else
- {
- // Add the fileset.
- addFiles( ds, zOut, prefix, fullpath );
- }
- }
- }
-
- private String getPrefix( final String prefix )
- {
- String result = prefix;
- if( result.length() > 0
- && !result.endsWith( "/" )
- && !result.endsWith( "\\" ) )
- {
- result += "/";
- }
- return result;
- }
-
- /**
- * Ensure all parent dirs of a given entry have been added.
- *
- * @param baseDir The feature to be added to the ParentDirs attribute
- * @param entry The feature to be added to the ParentDirs attribute
- * @param zOut The feature to be added to the ParentDirs attribute
- * @param prefix The feature to be added to the ParentDirs attribute
- * @exception java.io.IOException Description of Exception
- */
- protected void addParentDirs( File baseDir, String entry,
- ZipOutputStream zOut, String prefix )
- throws IOException
- {
- if( !m_filesonly )
- {
- Stack directories = new Stack();
- int slashPos = entry.length();
-
- while( ( slashPos = entry.lastIndexOf( '/', slashPos - 1 ) ) != -1 )
- {
- String dir = entry.substring( 0, slashPos + 1 );
- if( m_addedDirs.get( prefix + dir ) != null )
- {
- break;
- }
- directories.push( dir );
- }
-
- while( !directories.isEmpty() )
- {
- String dir = (String)directories.pop();
- File f = null;
- if( baseDir != null )
- {
- f = new File( baseDir, dir );
- }
- else
- {
- f = new File( dir );
- }
- zipDir( f, zOut, prefix + dir );
- }
- }
- }
-
- protected void addZipEntries( ZipFileSet fs, DirectoryScanner ds,
- ZipOutputStream zOut, String prefix, String fullpath )
- throws IOException, TaskException
- {
- if( prefix.length() > 0 && fullpath.length() > 0 )
- {
- throw new TaskException( "Both prefix and fullpath attributes may not be set on the same fileset." );
- }
-
- ZipScanner zipScanner = (ZipScanner)ds;
- File zipSrc = fs.getSrc();
-
- ZipEntry entry;
- java.util.zip.ZipEntry origEntry;
- ZipInputStream in = null;
- try
- {
- in = new ZipInputStream( new FileInputStream( zipSrc ) );
-
- while( ( origEntry = in.getNextEntry() ) != null )
- {
- entry = new ZipEntry( origEntry );
- String vPath = entry.getName();
- if( zipScanner.match( vPath ) )
- {
- if( fullpath.length() > 0 )
- {
- addParentDirs( null, fullpath, zOut, "" );
- zipFile( in, zOut, fullpath, entry.getTime() );
- }
- else
- {
- addParentDirs( null, vPath, zOut, prefix );
- if( !entry.isDirectory() )
- {
- zipFile( in, zOut, prefix + vPath, entry.getTime() );
- }
- }
- }
- }
- }
- finally
- {
- if( in != null )
- {
- in.close();
- }
- }
- }
-
- /**
- * Create an empty zip file
- *
- * @param zipFile Description of Parameter
- * @return true if the file is then considered up to date.
- */
- protected boolean createEmptyZip( File zipFile )
- throws TaskException
- {
- // In this case using java.util.zip will not work
- // because it does not permit a zero-entry archive.
- // Must create it manually.
- getContext().info( "Note: creating empty " + m_archiveType + " archive " + zipFile );
- try
- {
- OutputStream os = new FileOutputStream( zipFile );
- try
- {
- // Cf. PKZIP specification.
- byte[] empty = new byte[ 22 ];
- empty[ 0 ] = 80;// P
- empty[ 1 ] = 75;// K
- empty[ 2 ] = 5;
- empty[ 3 ] = 6;
- // remainder zeros
- os.write( empty );
- }
- finally
- {
- os.close();
- }
- }
- catch( IOException ioe )
- {
- throw new TaskException( "Could not create empty ZIP archive", ioe );
- }
- return true;
- }
-
- protected void finalizeZipOutputStream( ZipOutputStream zOut )
- throws IOException, TaskException
- {
- }
-
- protected void initZipOutputStream( ZipOutputStream zOut )
- throws IOException, TaskException
- {
- }
-
- protected void zipDir( File dir, ZipOutputStream zOut, String vPath )
- throws IOException
- {
- if( m_addedDirs.get( vPath ) != null )
- {
- // don't add directories we've already added.
- // no warning if we try, it is harmless in and of itself
- return;
- }
- m_addedDirs.put( vPath, vPath );
-
- ZipEntry ze = new ZipEntry( vPath );
- if( dir != null && dir.exists() )
- {
- ze.setTime( dir.lastModified() );
- }
- else
- {
- ze.setTime( System.currentTimeMillis() );
- }
- ze.setSize( 0 );
- ze.setMethod( ZipEntry.STORED );
- // This is faintly ridiculous:
- ze.setCrc( EMPTY_CRC );
-
- // this is 040775 | MS-DOS directory flag in reverse byte order
- ze.setExternalAttributes( 0x41FD0010L );
-
- zOut.putNextEntry( ze );
- }
-
- protected void zipFile( final InputStream input,
- final ZipOutputStream output,
- final String path,
- final long lastModified )
- throws IOException, TaskException
- {
- final ZipEntry entry = new ZipEntry( path );
- entry.setTime( lastModified );
-
- /*
- * XXX ZipOutputStream.putEntry expects the ZipEntry to know its
- * size and the CRC sum before you start writing the data when using
- * STORED mode.
- *
- * This forces us to process the data twice.
- *
- * I couldn't find any documentation on this, just found out by try
- * and error.
- */
-
- InputStream inputToStore = input;
- if( !m_compress )
- {
- final CRC32 crc = new CRC32();
- long size = 0;
- if( !inputToStore.markSupported() )
- {
- // Store data into a byte[]
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
- byte[] buffer = new byte[ 8 * 1024 ];
- int count = 0;
- do
- {
- size += count;
- crc.update( buffer, 0, count );
- bos.write( buffer, 0, count );
- count = inputToStore.read( buffer, 0, buffer.length );
- } while( count != -1 );
- inputToStore = new ByteArrayInputStream( bos.toByteArray() );
- }
- else
- {
- inputToStore.mark( Integer.MAX_VALUE );
- byte[] buffer = new byte[ 8 * 1024 ];
- int count = 0;
- do
- {
- size += count;
- crc.update( buffer, 0, count );
- count = inputToStore.read( buffer, 0, buffer.length );
- } while( count != -1 );
- inputToStore.reset();
- }
- entry.setSize( size );
- entry.setCrc( crc.getValue() );
- }
-
- output.putNextEntry( entry );
-
- IOUtil.copy( inputToStore, output );
-
- m_addedFiles.add( path );
- }
-
- protected void zipFile( final File file,
- final ZipOutputStream zOut,
- final String vPath )
- throws IOException, TaskException
- {
- if( file.equals( m_file ) )
- {
- final String message = "A zip file cannot include itself";
- throw new TaskException( message );
- }
-
- final FileInputStream fIn = new FileInputStream( file );
- try
- {
- zipFile( fIn, zOut, vPath, file.lastModified() );
- }
- finally
- {
- IOUtil.shutdownStream( fIn );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/ZipFileSet.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/ZipFileSet.java
deleted file mode 100644
index 054a6a0a8..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/ZipFileSet.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.archive;
-
-import java.io.File;
-import org.apache.tools.todo.types.FileSet;
-
-/**
- * A ZipFileSet is a FileSet with extra attributes useful in the context of
- * Zip/Jar tasks. A ZipFileSet extends FileSets with the ability to extract a
- * subset of the entries of a Zip file for inclusion in another Zip file. It
- * also includes a prefix attribute which is prepended to each entry in the
- * output Zip file. At present, ZipFileSets are not surfaced in the public API.
- * FileSets nested in a Zip task are instantiated as ZipFileSets, and their
- * attributes are only recognized in the context of the the Zip task. It is not
- * possible to define a ZipFileSet outside of the Zip task and refer to it via a
- * refid. However a standard FileSet may be included by reference in the Zip
- * task, and attributes in the refering ZipFileSet can augment FileSet
- * definition.
- *
- * @author Don Ferguson
- */
-public class ZipFileSet
- extends FileSet
-{
- private File m_src;
- private String m_prefix = "";
- private String m_fullpath = "";
-
- /**
- * Set the full pathname of the single entry in this fileset.
- *
- * @param fullpath The new Fullpath value
- */
- public void setFullpath( final String fullpath )
- {
- m_fullpath = fullpath;
- }
-
- /**
- * Prepend this prefix to the path for each zip entry. Does not perform
- * reference test; the referenced file set can be augmented with a prefix.
- *
- * @param prefix The prefix to prepend to entries in the zip file.
- */
- public void setPrefix( final String prefix )
- {
- m_prefix = prefix;
- }
-
- /**
- * Set the source Zip file for the zipfileset. Prevents both "dir" and "src"
- * from being specified.
- *
- * @param srcFile The zip file from which to extract entries.
- */
- public void setSrc( final File src )
- {
- m_src = src;
- }
-
- /**
- * Return the full pathname of the single entry in this fileset.
- *
- * @return The Fullpath value
- */
- public String getFullpath()
- {
- return m_fullpath;
- }
-
- /**
- * Return the prefix prepended to entries in the zip file.
- *
- * @return The Prefix value
- */
- public String getPrefix()
- {
- return m_prefix;
- }
-
- /**
- * Get the zip file from which entries will be extracted. References are not
- * followed, since it is not possible to have a reference to a ZipFileSet,
- * only to a FileSet.
- *
- * @return The Src value
- */
- public File getSrc()
- {
- return m_src;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/ZipScanner.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/ZipScanner.java
deleted file mode 100644
index 01e65dbf9..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/archive/ZipScanner.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.archive;
-
-import java.io.File;
-import org.apache.tools.todo.types.DirectoryScanner;
-
-/**
- * ZipScanner accesses the pattern matching algorithm in DirectoryScanner, which
- * are protected methods that can only be accessed by subclassing. This
- * implementation of FileScanner defines getIncludedFiles to return only the Zip
- * File which is being scanned, not the matching Zip entries. Arguably, it
- * should return the matching entries, however this would complicate existing
- * code which assumes that FileScanners return a set of file system files that
- * can be accessed directly.
- *
- * @author Don Ferguson don@bea.com
- */
-public class ZipScanner
- extends DirectoryScanner
-{
- /**
- * The zip file which should be scanned.
- */
- private File m_src;
-
- /**
- * Sets the srcFile for scanning. This is the jar or zip file that is
- * scanned for matching entries.
- *
- * @param srcFile the (non-null) zip file name for scanning
- */
- public void setSrc( final File srcFile )
- {
- m_src = srcFile;
- }
-
- /**
- * Returns an empty list of directories to create.
- *
- * @return The IncludedDirectories value
- */
- public String[] getIncludedDirectories()
- {
- return new String[ 0 ];
- }
-
- /**
- * Returns the zip file itself, not the matching entries within the zip
- * file. This keeps the uptodate test in the Zip task simple; otherwise we'd
- * need to treat zip filesets specially.
- *
- * @return the source file from which entries will be extracted.
- */
- public String[] getIncludedFiles()
- {
- final String[] result = new String[ 1 ];
- result[ 0 ] = m_src.getAbsolutePath();
- return result;
- }
-
- /**
- * Initialize DirectoryScanner data structures.
- */
- public void init()
- {
- if( getIncludes() == null )
- {
- // No includes supplied, so set it to 'matches all'
- setIncludes( new String[ 1 ] );
- getIncludes()[ 0 ] = "**";
- }
- if( getExcludes() == null )
- {
- setExcludes( new String[ 0 ] );
- }
- }
-
- /**
- * Matches a jar entry against the includes/excludes list, normalizing the
- * path separator.
- *
- * @param path the (non-null) path name to test for inclusion
- * @return true
if the path should be included false
- * otherwise.
- */
- public boolean match( String path )
- {
- final String vpath =
- path.replace( '/', File.separatorChar ).replace( '\\', File.separatorChar );
- return isIncluded( vpath ) && !isExcluded( vpath );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMCheck.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMCheck.java
deleted file mode 100644
index f72a32997..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMCheck.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.ccm;
-
-import java.io.File;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * Class common to all check commands (checkout, checkin,checkin default task);
- *
- * @author Benoit Moussaud benoit.moussaud@criltelecom.com
- */
-public class CCMCheck extends Continuus
-{
-
- /**
- * -comment flag -- comment to attach to the file
- */
- public final static String FLAG_COMMENT = "/comment";
-
- /**
- * -task flag -- associate checckout task with task
- */
- public final static String FLAG_TASK = "/task";
-
- private File _file = null;
- private String _comment = null;
- private String _task = null;
-
- public CCMCheck()
- {
- super();
- }
-
- /**
- * Set the value of comment.
- *
- * @param v Value to assign to comment.
- */
- public void setComment( String v )
- {
- this._comment = v;
- }
-
- /**
- * Set the value of file.
- *
- * @param v Value to assign to file.
- */
- public void setFile( File v )
- {
- this._file = v;
- }
-
- /**
- * Set the value of task.
- *
- * @param v Value to assign to task.
- */
- public void setTask( String v )
- {
- this._task = v;
- }
-
- /**
- * Get the value of comment.
- *
- * @return value of comment.
- */
- public String getComment()
- {
- return _comment;
- }
-
- /**
- * Get the value of file.
- *
- * @return value of file.
- */
- public File getFile()
- {
- return _file;
- }
-
- /**
- * Get the value of task.
- *
- * @return value of task.
- */
- public String getTask()
- {
- return _task;
- }
-
- /**
- * Executes the task.
- *
- * Builds a command line to execute ccm and then calls Exec's run method to
- * execute the command line.
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- Commandline commandLine = new Commandline();
-
- // build the command line from what we got the format is
- // ccm co /t .. files
- // as specified in the CLEARTOOL.EXE help
- commandLine.setExecutable( getCcmCommand() );
- commandLine.addArgument( getCcmAction() );
-
- checkOptions( commandLine );
-
- final int result = run( commandLine, null );
- if( result != 0 )
- {
- final String message = "Failed executing: " + commandLine.toString();
- throw new TaskException( message );
- }
- }
-
- /**
- * Check the command line options.
- *
- * @param cmd Description of Parameter
- */
- private void checkOptions( Commandline cmd )
- {
- if( getComment() != null )
- {
- cmd.addArgument( FLAG_COMMENT );
- cmd.addArgument( getComment() );
- }
-
- if( getTask() != null )
- {
- cmd.addArgument( FLAG_TASK );
- cmd.addArgument( getTask() );
- }// end of if ()
-
- if( getFile() != null )
- {
- cmd.addArgument( _file.getAbsolutePath() );
- }// end of if ()
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMCheckin.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMCheckin.java
deleted file mode 100644
index 4a963c67a..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMCheckin.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.ccm;
-
-import java.util.Date;
-
-/**
- * Task to perform Checkin command to Continuus
- *
- * @author Benoit Moussaud benoit.moussaud@criltelecom.com
- */
-public class CCMCheckin extends CCMCheck
-{
-
- public CCMCheckin()
- {
- super();
- setCcmAction( COMMAND_CHECKIN );
- setComment( "Checkin " + new Date() );
- }
-
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMCheckinDefault.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMCheckinDefault.java
deleted file mode 100644
index ed62a3a76..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMCheckinDefault.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.ccm;
-
-/**
- * Task to perform Checkin Default task command to Continuus
- *
- * @author Benoit Moussaud benoit.moussaud@criltelecom.com
- */
-public class CCMCheckinDefault extends CCMCheck
-{
-
- public final static String DEFAULT_TASK = "default";
-
- public CCMCheckinDefault()
- {
- super();
- setCcmAction( COMMAND_CHECKIN );
- setTask( DEFAULT_TASK );
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMCheckout.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMCheckout.java
deleted file mode 100644
index 67693c058..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMCheckout.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.ccm;
-
-/**
- * Task to perform Checkout command to Continuus
- *
- * @author Benoit Moussaud benoit.moussaud@criltelecom.com
- */
-public class CCMCheckout extends CCMCheck
-{
-
- public CCMCheckout()
- {
- super();
- setCcmAction( COMMAND_CHECKOUT );
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMCreateTask.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMCreateTask.java
deleted file mode 100644
index 6e56dc733..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMCreateTask.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.ccm;
-
-import org.apache.aut.nativelib.ExecOutputHandler;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * Task allows to create new ccm task and set it as the default
- *
- * @author Benoit Moussaud benoit.moussaud@criltelecom.com
- */
-public class CCMCreateTask
- extends Continuus
- implements ExecOutputHandler
-{
- /**
- * /comment -- comments associated to the task
- */
- private final static String FLAG_COMMENT = "/synopsis";
-
- /**
- * /platform flag -- target platform
- */
- private final static String FLAG_PLATFORM = "/plat";
-
- /**
- * /resolver flag
- */
- private final static String FLAG_RESOLVER = "/resolver";
-
- /**
- * /release flag
- */
- private final static String FLAG_RELEASE = "/release";
-
- /**
- * /release flag
- */
- private final static String FLAG_SUBSYSTEM = "/subsystem";
-
- /**
- * -task flag -- associate checckout task with task
- */
- private final static String FLAG_TASK = "/task";
-
- private String m_comment;
- private String m_platform;
- private String m_resolver;
- private String m_release;
- private String m_subSystem;
- private String m_task;
-
- public CCMCreateTask()
- {
- setCcmAction( COMMAND_CREATE_TASK );
- }
-
- /**
- * Set the value of comment.
- *
- * @param v Value to assign to comment.
- */
- public void setComment( final String comment )
- {
- m_comment = comment;
- }
-
- /**
- * Set the value of platform.
- *
- * @param v Value to assign to platform.
- */
- public void setPlatform( final String platform )
- {
- m_platform = platform;
- }
-
- /**
- * Set the value of release.
- *
- * @param v Value to assign to release.
- */
- public void setRelease( final String release )
- {
- m_release = release;
- }
-
- /**
- * Set the value of resolver.
- *
- * @param v Value to assign to resolver.
- */
- public void setResolver( final String resolver )
- {
- m_resolver = resolver;
- }
-
- /**
- * Set the value of subSystem.
- *
- * @param v Value to assign to subSystem.
- */
- public void setSubSystem( final String subSystem )
- {
- m_subSystem = subSystem;
- }
-
- /**
- * Set the value of task.
- *
- * @param v Value to assign to task.
- */
- public void setTask( final String task )
- {
- m_task = task;
- }
-
- /**
- * Executes the task.
- *
- * Builds a command line to execute ccm and then calls Exec's run method to
- * execute the command line.
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- final Commandline commandLine = determineTask();
- if( null == m_task )
- {
- final String message = "Error determining task";
- throw new TaskException( message );
- }
-
- //create task ok, set this task as the default one
- final Commandline cmd = new Commandline();
- cmd.setExecutable( getCcmCommand() );
- cmd.addArgument( COMMAND_DEFAULT_TASK );
- cmd.addArgument( m_task );
-
- getContext().debug( commandLine.toString() );
-
- final int result2 = run( cmd, null );
- if( result2 != 0 )
- {
- final String message = "Failed executing: " + cmd.toString();
- throw new TaskException( message );
- }
- }
-
- private Commandline determineTask()
- throws TaskException
- {
- final Commandline commandLine = new Commandline();
-
- // build the command line from what we got the format
- // as specified in the CCM.EXE help
- commandLine.setExecutable( getCcmCommand() );
- commandLine.addArgument( getCcmAction() );
-
- checkOptions( commandLine );
-
- final int result = run( commandLine, this );
- if( result != 0 )
- {
- final String message = "Failed executing: " + commandLine.toString();
- throw new TaskException( message );
- }
- return commandLine;
- }
-
- /**
- * Check the command line options.
- */
- private void checkOptions( final Commandline cmd )
- {
- if( m_comment != null )
- {
- cmd.addArgument( FLAG_COMMENT );
- cmd.addArgument( "\"" + m_comment + "\"" );
- }
-
- if( m_platform != null )
- {
- cmd.addArgument( FLAG_PLATFORM );
- cmd.addArgument( m_platform );
- }
-
- if( m_resolver != null )
- {
- cmd.addArgument( FLAG_RESOLVER );
- cmd.addArgument( m_resolver );
- }
-
- if( m_subSystem != null )
- {
- cmd.addArgument( FLAG_SUBSYSTEM );
- cmd.addArgument( "\"" + m_subSystem + "\"" );
- }
-
- if( m_release != null )
- {
- cmd.addArgument( FLAG_RELEASE );
- cmd.addArgument( m_release );
- }
- }
-
- /**
- * Receive notification about the process writing
- * to standard output.
- */
- public void stdout( final String line )
- {
- getContext().debug( "buffer:" + line );
- final String task = getTask( line );
-
- setTask( task );
- getContext().debug( "task is " + m_task );
- }
-
- private String getTask( final String line )
- {
- try
- {
- final String task = line.substring( line.indexOf( ' ' ) ).trim();
- return task.substring( 0, task.lastIndexOf( ' ' ) ).trim();
- }
- catch( final Exception e )
- {
- final String message = "error procession stream " + e.getMessage();
- getContext().error( message, e );
- }
-
- return null;
- }
-
- /**
- * Receive notification about the process writing
- * to standard error.
- */
- public void stderr( final String line )
- {
- getContext().debug( "err " + line );
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMReconfigure.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMReconfigure.java
deleted file mode 100644
index 822572dd4..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/CCMReconfigure.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.ccm;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * Task allows to reconfigure a project, recurcively or not
- *
- * @author Benoit Moussaud benoit.moussaud@criltelecom.com
- */
-public class CCMReconfigure
- extends Continuus
-{
- /**
- * /recurse --
- */
- public final static String FLAG_RECURSE = "/recurse";
-
- /**
- * /recurse --
- */
- public final static String FLAG_VERBOSE = "/verbose";
-
- /**
- * /project flag -- target project
- */
- public final static String FLAG_PROJECT = "/project";
-
- private String m_ccmProject;
- private boolean m_recurse;
- private boolean m_verbose;
-
- public CCMReconfigure()
- {
- super();
- setCcmAction( COMMAND_RECONFIGURE );
- }
-
- /**
- * Set the value of project.
- */
- public void setCcmProject( final String ccmProject )
- {
- m_ccmProject = ccmProject;
- }
-
- /**
- * Set the value of recurse.
- */
- public void setRecurse( final boolean recurse )
- {
- m_recurse = recurse;
- }
-
- /**
- * Set the value of verbose.
- */
- public void setVerbose( final boolean verbose )
- {
- m_verbose = verbose;
- }
-
- /**
- * Executes the task.
- *
- * Builds a command line to execute ccm and then calls Exec's run method to
- * execute the command line.
- */
- public void execute()
- throws TaskException
- {
- final Commandline cmd = new Commandline();
-
- // build the command line from what we got the format
- // as specified in the CCM.EXE help
- cmd.setExecutable( getCcmCommand() );
- cmd.addArgument( getCcmAction() );
-
- checkOptions( cmd );
-
- final int result = run( cmd, null );
- if( result != 0 )
- {
- final String message = "Failed executing: " + cmd.toString();
- throw new TaskException( message );
- }
- }
-
- /**
- * Build the command line options.
- */
- private void checkOptions( final Commandline cmd )
- {
- if( m_recurse == true )
- {
- cmd.addArgument( FLAG_RECURSE );
- }
-
- if( m_verbose == true )
- {
- cmd.addArgument( FLAG_VERBOSE );
- }
-
- if( m_ccmProject != null )
- {
- cmd.addArgument( FLAG_PROJECT );
- cmd.addArgument( m_ccmProject );
- }
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/Continuus.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/Continuus.java
deleted file mode 100644
index 1de06e8a0..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/ccm/Continuus.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.ccm;
-
-import java.io.File;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.aut.nativelib.ExecOutputHandler;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * A base class for creating tasks for executing commands on Continuus 5.1
- *
- * The class extends the task as it operates by executing the ccm.exe program
- * supplied with Continuus/Synergy. By default the task expects the ccm
- * executable to be in the path, you can override this be specifying the ccmdir
- * attribute.
- *
- * @author Benoit Moussaud benoit.moussaud@criltelecom.com
- */
-public abstract class Continuus
- extends AbstractTask
-{
- /**
- * Constant for the thing to execute
- */
- private final static String CCM_EXE = "ccm";
-
- /**
- * The 'CreateTask' command
- */
- public final static String COMMAND_CREATE_TASK = "create_task";
- /**
- * The 'Checkout' command
- */
- public final static String COMMAND_CHECKOUT = "co";
- /**
- * The 'Checkin' command
- */
- public final static String COMMAND_CHECKIN = "ci";
- /**
- * The 'Reconfigure' command
- */
- public final static String COMMAND_RECONFIGURE = "reconfigure";
-
- /**
- * The 'Reconfigure' command
- */
- public final static String COMMAND_DEFAULT_TASK = "default_task";
-
- private String m_ccmDir = "";
- private String m_ccmAction = "";
-
- /**
- * Set the directory where the ccm executable is located
- *
- * @param dir the directory containing the ccm executable
- */
- public final void setCcmDir( final File dir )
- {
- m_ccmDir = dir.toString();
- }
-
- /**
- * Set the value of ccmAction.
- *
- * @param ccmAction Value to assign to ccmAction.
- */
- public void setCcmAction( final String ccmAction )
- {
- m_ccmAction = ccmAction;
- }
-
- /**
- * Get the value of ccmAction.
- *
- * @return value of ccmAction.
- */
- public String getCcmAction()
- {
- return m_ccmAction;
- }
-
- /**
- * Builds and returns the command string to execute ccm
- *
- * @return String containing path to the executable
- */
- protected final String getCcmCommand()
- {
- String toReturn = m_ccmDir;
- if( !toReturn.equals( "" ) && !toReturn.endsWith( "/" ) )
- {
- toReturn += "/";
- }
-
- toReturn += CCM_EXE;
-
- return toReturn;
- }
-
- protected int run( final Commandline cmd, final ExecOutputHandler handler )
- throws TaskException
- {
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
- if( null != handler )
- {
- exe.setExecOutputHandler( handler );
- }
- exe.setWorkingDirectory( getBaseDirectory() );
- exe.setCommandline( cmd );
- return exe.execute();
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/clearcase/CCCheckin.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/clearcase/CCCheckin.java
deleted file mode 100644
index efdd6b94b..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/clearcase/CCCheckin.java
+++ /dev/null
@@ -1,444 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.clearcase;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * Task to perform Checkin command to ClearCase.
- *
- * The following attributes are interpreted:
- *
- *
- *
- *
- *
- * Attribute
- *
- *
- *
- * Values
- *
- *
- *
- * Required
- *
- *
- *
- *
- *
- *
- *
- * viewpath
- *
- *
- *
- * Path to the ClearCase view file or directory that the command will
- * operate on
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * comment
- *
- *
- *
- * Specify a comment. Only one of comment or cfile may be used.
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * commentfile
- *
- *
- *
- * Specify a file containing a comment. Only one of comment or
- * cfile may be used.
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * nowarn
- *
- *
- *
- * Suppress warning messages
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * preservetime
- *
- *
- *
- * Preserve the modification time
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * keepcopy
- *
- *
- *
- * Keeps a copy of the file with a .keep extension
- *
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * identical
- *
- *
- *
- * Allows the file to be checked in even if it is
- * identical to the original
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * @author Curtis White
- */
-public class CCCheckin extends ClearCase
-{
-
- /**
- * -c flag -- comment to attach to the file
- */
- public final static String FLAG_COMMENT = "-c";
- /**
- * -cfile flag -- file containing a comment to attach to the file
- */
- public final static String FLAG_COMMENTFILE = "-cfile";
- /**
- * -nc flag -- no comment is specified
- */
- public final static String FLAG_NOCOMMENT = "-nc";
- /**
- * -nwarn flag -- suppresses warning messages
- */
- public final static String FLAG_NOWARN = "-nwarn";
- /**
- * -ptime flag -- preserves the modification time
- */
- public final static String FLAG_PRESERVETIME = "-ptime";
- /**
- * -keep flag -- keeps a copy of the file with a .keep extension
- */
- public final static String FLAG_KEEPCOPY = "-keep";
- /**
- * -identical flag -- allows the file to be checked in even if it is
- * identical to the original
- */
- public final static String FLAG_IDENTICAL = "-identical";
- private String m_Comment = null;
- private String m_Cfile = null;
- private boolean m_Nwarn = false;
- private boolean m_Ptime = false;
- private boolean m_Keep = false;
- private boolean m_Identical = true;
-
- /**
- * Set comment string
- *
- * @param comment the comment string
- */
- public void setComment( String comment )
- {
- m_Comment = comment;
- }
-
- /**
- * Set comment file
- *
- * @param cfile the path to the comment file
- */
- public void setCommentFile( String cfile )
- {
- m_Cfile = cfile;
- }
-
- /**
- * Set the identical flag
- *
- * @param identical the status to set the flag to
- */
- public void setIdentical( boolean identical )
- {
- m_Identical = identical;
- }
-
- /**
- * Set the keepcopy flag
- *
- * @param keep the status to set the flag to
- */
- public void setKeepCopy( boolean keep )
- {
- m_Keep = keep;
- }
-
- /**
- * Set the nowarn flag
- *
- * @param nwarn the status to set the flag to
- */
- public void setNoWarn( boolean nwarn )
- {
- m_Nwarn = nwarn;
- }
-
- /**
- * Set preservetime flag
- *
- * @param ptime the status to set the flag to
- */
- public void setPreserveTime( boolean ptime )
- {
- m_Ptime = ptime;
- }
-
- /**
- * Get comment string
- *
- * @return String containing the comment
- */
- public String getComment()
- {
- return m_Comment;
- }
-
- /**
- * Get comment file
- *
- * @return String containing the path to the comment file
- */
- public String getCommentFile()
- {
- return m_Cfile;
- }
-
- /**
- * Get identical flag status
- *
- * @return boolean containing status of identical flag
- */
- public boolean getIdentical()
- {
- return m_Identical;
- }
-
- /**
- * Get keepcopy flag status
- *
- * @return boolean containing status of keepcopy flag
- */
- public boolean getKeepCopy()
- {
- return m_Keep;
- }
-
- /**
- * Get nowarn flag status
- *
- * @return boolean containing status of nwarn flag
- */
- public boolean getNoWarn()
- {
- return m_Nwarn;
- }
-
- /**
- * Get preservetime flag status
- *
- * @return boolean containing status of preservetime flag
- */
- public boolean getPreserveTime()
- {
- return m_Ptime;
- }
-
- /**
- * Executes the task.
- *
- * Builds a command line to execute cleartool and then calls Exec's run
- * method to execute the command line.
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- Commandline commandLine = new Commandline();
-
- // Default the viewpath to basedir if it is not specified
- if( getViewPath() == null )
- {
- setViewPath( getBaseDirectory().getPath() );
- }
-
- // build the command line from what we got. the format is
- // cleartool checkin [options...] [viewpath ...]
- // as specified in the CLEARTOOL.EXE help
- commandLine.setExecutable( getClearToolCommand() );
- commandLine.addArgument( COMMAND_CHECKIN );
-
- checkOptions( commandLine );
-
- final int result = run( commandLine );
- if( result != 0 )
- {
- final String message = "Failed executing: " + commandLine.toString();
- throw new TaskException( message );
- }
- }
-
- /**
- * Get the 'comment' command
- *
- * @param cmd Description of Parameter
- */
- private void getCommentCommand( Commandline cmd )
- {
- if( getComment() != null )
- {
- /*
- * Had to make two separate commands here because if a space is
- * inserted between the flag and the value, it is treated as a
- * Windows filename with a space and it is enclosed in double
- * quotes ("). This breaks clearcase.
- */
- cmd.addArgument( FLAG_COMMENT );
- cmd.addArgument( getComment() );
- }
- }
-
- /**
- * Get the 'commentfile' command
- *
- * @param cmd Description of Parameter
- */
- private void getCommentFileCommand( Commandline cmd )
- {
- if( getCommentFile() != null )
- {
- /*
- * Had to make two separate commands here because if a space is
- * inserted between the flag and the value, it is treated as a
- * Windows filename with a space and it is enclosed in double
- * quotes ("). This breaks clearcase.
- */
- cmd.addArgument( FLAG_COMMENTFILE );
- cmd.addArgument( getCommentFile() );
- }
- }
-
- /**
- * Check the command line options.
- *
- * @param cmd Description of Parameter
- */
- private void checkOptions( Commandline cmd )
- {
- if( getComment() != null )
- {
- // -c
- getCommentCommand( cmd );
- }
- else
- {
- if( getCommentFile() != null )
- {
- // -cfile
- getCommentFileCommand( cmd );
- }
- else
- {
- cmd.addArgument( FLAG_NOCOMMENT );
- }
- }
-
- if( getNoWarn() )
- {
- // -nwarn
- cmd.addArgument( FLAG_NOWARN );
- }
-
- if( getPreserveTime() )
- {
- // -ptime
- cmd.addArgument( FLAG_PRESERVETIME );
- }
-
- if( getKeepCopy() )
- {
- // -keep
- cmd.addArgument( FLAG_KEEPCOPY );
- }
-
- if( getIdentical() )
- {
- // -identical
- cmd.addArgument( FLAG_IDENTICAL );
- }
-
- // viewpath
- cmd.addArgument( getViewPath() );
- }
-
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/clearcase/CCCheckout.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/clearcase/CCCheckout.java
deleted file mode 100644
index be283d2b6..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/clearcase/CCCheckout.java
+++ /dev/null
@@ -1,596 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.clearcase;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * Task to perform Checkout command to ClearCase.
- *
- * The following attributes are interpretted:
- *
- *
- *
- *
- *
- * Attribute
- *
- *
- *
- * Values
- *
- *
- *
- * Required
- *
- *
- *
- *
- *
- *
- *
- * viewpath
- *
- *
- *
- * Path to the ClearCase view file or directory that the command will
- * operate on
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * reserved
- *
- *
- *
- * Specifies whether to check out the file as reserved or not
- *
- *
- *
- * Yes
- *
- *
- *
- *
- *
- *
- *
- * out
- *
- *
- *
- * Creates a writable file under a different filename
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * nodata
- *
- *
- *
- * Checks out the file but does not create an editable file
- * containing its data
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * branch
- *
- *
- *
- * Specify a branch to check out the file to
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * version
- *
- *
- *
- * Allows checkout of a version other than main latest
- *
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * nowarn
- *
- *
- *
- * Suppress warning messages
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * comment
- *
- *
- *
- * Specify a comment. Only one of comment or
- * cfile may be used.
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * commentfile
- *
- *
- *
- * Specify a file containing a comment.
- * Only one of comment or cfile may be
- * used.
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * @author Curtis White
- */
-public class CCCheckout extends ClearCase
-{
-
- /**
- * -reserved flag -- check out the file as reserved
- */
- public final static String FLAG_RESERVED = "-reserved";
- /**
- * -reserved flag -- check out the file as unreserved
- */
- public final static String FLAG_UNRESERVED = "-unreserved";
- /**
- * -out flag -- create a writable file under a different filename
- */
- public final static String FLAG_OUT = "-out";
- /**
- * -ndata flag -- checks out the file but does not create an editable file
- * containing its data
- */
- public final static String FLAG_NODATA = "-ndata";
- /**
- * -branch flag -- checks out the file on a specified branch
- */
- public final static String FLAG_BRANCH = "-branch";
- /**
- * -version flag -- allows checkout of a version that is not main latest
- */
- public final static String FLAG_VERSION = "-version";
- /**
- * -nwarn flag -- suppresses warning messages
- */
- public final static String FLAG_NOWARN = "-nwarn";
- /**
- * -c flag -- comment to attach to the file
- */
- public final static String FLAG_COMMENT = "-c";
- /**
- * -cfile flag -- file containing a comment to attach to the file
- */
- public final static String FLAG_COMMENTFILE = "-cfile";
- /**
- * -nc flag -- no comment is specified
- */
- public final static String FLAG_NOCOMMENT = "-nc";
- private boolean m_Reserved = true;
- private String m_Out = null;
- private boolean m_Ndata = false;
- private String m_Branch = null;
- private boolean m_Version = false;
- private boolean m_Nwarn = false;
- private String m_Comment = null;
- private String m_Cfile = null;
-
- /**
- * Set branch name
- *
- * @param branch the name of the branch
- */
- public void setBranch( String branch )
- {
- m_Branch = branch;
- }
-
- /**
- * Set comment string
- *
- * @param comment the comment string
- */
- public void setComment( String comment )
- {
- m_Comment = comment;
- }
-
- /**
- * Set comment file
- *
- * @param cfile the path to the comment file
- */
- public void setCommentFile( String cfile )
- {
- m_Cfile = cfile;
- }
-
- /**
- * Set the nodata flag
- *
- * @param ndata the status to set the flag to
- */
- public void setNoData( boolean ndata )
- {
- m_Ndata = ndata;
- }
-
- /**
- * Set the nowarn flag
- *
- * @param nwarn the status to set the flag to
- */
- public void setNoWarn( boolean nwarn )
- {
- m_Nwarn = nwarn;
- }
-
- /**
- * Set out file
- *
- * @param outf the path to the out file
- */
- public void setOut( String outf )
- {
- m_Out = outf;
- }
-
- /**
- * Set reserved flag status
- *
- * @param reserved the status to set the flag to
- */
- public void setReserved( boolean reserved )
- {
- m_Reserved = reserved;
- }
-
- /**
- * Set the version flag
- *
- * @param version the status to set the flag to
- */
- public void setVersion( boolean version )
- {
- m_Version = version;
- }
-
- /**
- * Get branch name
- *
- * @return String containing the name of the branch
- */
- public String getBranch()
- {
- return m_Branch;
- }
-
- /**
- * Get comment string
- *
- * @return String containing the comment
- */
- public String getComment()
- {
- return m_Comment;
- }
-
- /**
- * Get comment file
- *
- * @return String containing the path to the comment file
- */
- public String getCommentFile()
- {
- return m_Cfile;
- }
-
- /**
- * Get nodata flag status
- *
- * @return boolean containing status of ndata flag
- */
- public boolean getNoData()
- {
- return m_Ndata;
- }
-
- /**
- * Get nowarn flag status
- *
- * @return boolean containing status of nwarn flag
- */
- public boolean getNoWarn()
- {
- return m_Nwarn;
- }
-
- /**
- * Get out file
- *
- * @return String containing the path to the out file
- */
- public String getOut()
- {
- return m_Out;
- }
-
- /**
- * Get reserved flag status
- *
- * @return boolean containing status of reserved flag
- */
- public boolean getReserved()
- {
- return m_Reserved;
- }
-
- /**
- * Get version flag status
- *
- * @return boolean containing status of version flag
- */
- public boolean getVersion()
- {
- return m_Version;
- }
-
- /**
- * Executes the task.
- *
- * Builds a command line to execute cleartool and then calls Exec's run
- * method to execute the command line.
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- Commandline commandLine = new Commandline();
-
- // Default the viewpath to basedir if it is not specified
- if( getViewPath() == null )
- {
- setViewPath( getBaseDirectory().getPath() );
- }
-
- // build the command line from what we got the format is
- // cleartool checkout [options...] [viewpath ...]
- // as specified in the CLEARTOOL.EXE help
- commandLine.setExecutable( getClearToolCommand() );
- commandLine.addArgument( COMMAND_CHECKOUT );
-
- checkOptions( commandLine );
-
- final int result = run( commandLine );
- if( result != 0 )
- {
- final String message = "Failed executing: " + commandLine.toString();
- throw new TaskException( message );
- }
- }
-
- /**
- * Get the 'branch' command
- *
- * @param cmd Description of Parameter
- */
- private void getBranchCommand( Commandline cmd )
- {
- if( getBranch() != null )
- {
- /*
- * Had to make two separate commands here because if a space is
- * inserted between the flag and the value, it is treated as a
- * Windows filename with a space and it is enclosed in double
- * quotes ("). This breaks clearcase.
- */
- cmd.addArgument( FLAG_BRANCH );
- cmd.addArgument( getBranch() );
- }
- }
-
- /**
- * Get the 'comment' command
- *
- * @param cmd Description of Parameter
- */
- private void getCommentCommand( Commandline cmd )
- {
- if( getComment() != null )
- {
- /*
- * Had to make two separate commands here because if a space is
- * inserted between the flag and the value, it is treated as a
- * Windows filename with a space and it is enclosed in double
- * quotes ("). This breaks clearcase.
- */
- cmd.addArgument( FLAG_COMMENT );
- cmd.addArgument( getComment() );
- }
- }
-
- /**
- * Get the 'cfile' command
- *
- * @param cmd Description of Parameter
- */
- private void getCommentFileCommand( Commandline cmd )
- {
- if( getCommentFile() != null )
- {
- /*
- * Had to make two separate commands here because if a space is
- * inserted between the flag and the value, it is treated as a
- * Windows filename with a space and it is enclosed in double
- * quotes ("). This breaks clearcase.
- */
- cmd.addArgument( FLAG_COMMENTFILE );
- cmd.addArgument( getCommentFile() );
- }
- }
-
- /**
- * Get the 'out' command
- *
- * @param cmd Description of Parameter
- */
- private void getOutCommand( Commandline cmd )
- {
- if( getOut() != null )
- {
- /*
- * Had to make two separate commands here because if a space is
- * inserted between the flag and the value, it is treated as a
- * Windows filename with a space and it is enclosed in double
- * quotes ("). This breaks clearcase.
- */
- cmd.addArgument( FLAG_OUT );
- cmd.addArgument( getOut() );
- }
- }
-
- /**
- * Check the command line options.
- *
- * @param cmd Description of Parameter
- */
- private void checkOptions( Commandline cmd )
- {
- // ClearCase items
- if( getReserved() )
- {
- // -reserved
- cmd.addArgument( FLAG_RESERVED );
- }
- else
- {
- // -unreserved
- cmd.addArgument( FLAG_UNRESERVED );
- }
-
- if( getOut() != null )
- {
- // -out
- getOutCommand( cmd );
- }
- else
- {
- if( getNoData() )
- {
- // -ndata
- cmd.addArgument( FLAG_NODATA );
- }
-
- }
-
- if( getBranch() != null )
- {
- // -branch
- getBranchCommand( cmd );
- }
- else
- {
- if( getVersion() )
- {
- // -version
- cmd.addArgument( FLAG_VERSION );
- }
-
- }
-
- if( getNoWarn() )
- {
- // -nwarn
- cmd.addArgument( FLAG_NOWARN );
- }
-
- if( getComment() != null )
- {
- // -c
- getCommentCommand( cmd );
- }
- else
- {
- if( getCommentFile() != null )
- {
- // -cfile
- getCommentFileCommand( cmd );
- }
- else
- {
- cmd.addArgument( FLAG_NOCOMMENT );
- }
- }
-
- // viewpath
- cmd.addArgument( getViewPath() );
- }
-
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/clearcase/CCUnCheckout.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/clearcase/CCUnCheckout.java
deleted file mode 100644
index aa0379283..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/clearcase/CCUnCheckout.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.clearcase;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * Task to perform UnCheckout command to ClearCase.
- *
- * The following attributes are interpretted:
- *
- *
- *
- *
- *
- * Attribute
- *
- *
- *
- * Values
- *
- *
- *
- * Required
- *
- *
- *
- *
- *
- *
- *
- * viewpath
- *
- *
- *
- * Path to the ClearCase view file or directory that the command will
- * operate on
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * keepcopy
- *
- *
- *
- * Specifies whether to keep a copy of the file with a .keep extension
- * or not
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * @author Curtis White
- */
-public class CCUnCheckout extends ClearCase
-{
-
- /**
- * -keep flag -- keep a copy of the file with .keep extension
- */
- public final static String FLAG_KEEPCOPY = "-keep";
- /**
- * -rm flag -- remove the copy of the file
- */
- public final static String FLAG_RM = "-rm";
- private boolean m_Keep = false;
-
- /**
- * Set keepcopy flag status
- *
- * @param keep the status to set the flag to
- */
- public void setKeepCopy( boolean keep )
- {
- m_Keep = keep;
- }
-
- /**
- * Get keepcopy flag status
- *
- * @return boolean containing status of keep flag
- */
- public boolean getKeepCopy()
- {
- return m_Keep;
- }
-
- /**
- * Executes the task.
- *
- * Builds a command line to execute cleartool and then calls Exec's run
- * method to execute the command line.
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- Commandline commandLine = new Commandline();
-
- // Default the viewpath to basedir if it is not specified
- if( getViewPath() == null )
- {
- setViewPath( getBaseDirectory().getPath() );
- }
-
- // build the command line from what we got the format is
- // cleartool uncheckout [options...] [viewpath ...]
- // as specified in the CLEARTOOL.EXE help
- commandLine.setExecutable( getClearToolCommand() );
- commandLine.addArgument( COMMAND_UNCHECKOUT );
-
- checkOptions( commandLine );
-
- final int result = run( commandLine );
- if( result != 0 )
- {
- final String message = "Failed executing: " + commandLine.toString();
- throw new TaskException( message );
- }
- }
-
- /**
- * Check the command line options.
- *
- * @param cmd Description of Parameter
- */
- private void checkOptions( Commandline cmd )
- {
- // ClearCase items
- if( getKeepCopy() )
- {
- // -keep
- cmd.addArgument( FLAG_KEEPCOPY );
- }
- else
- {
- // -rm
- cmd.addArgument( FLAG_RM );
- }
-
- // viewpath
- cmd.addArgument( getViewPath() );
- }
-
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/clearcase/CCUpdate.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/clearcase/CCUpdate.java
deleted file mode 100644
index 5e9ee1053..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/clearcase/CCUpdate.java
+++ /dev/null
@@ -1,436 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.clearcase;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * Task to perform an Update command to ClearCase.
- *
- * The following attributes are interpretted:
- *
- *
- *
- *
- *
- * Attribute
- *
- *
- *
- * Values
- *
- *
- *
- * Required
- *
- *
- *
- *
- *
- *
- *
- * viewpath
- *
- *
- *
- * Path to the ClearCase view file or directory that the command will
- * operate on
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * graphical
- *
- *
- *
- * Displays a graphical dialog during the update
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * log
- *
- *
- *
- * Specifies a log file for ClearCase to write to
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * overwrite
- *
- *
- *
- * Specifies whether to overwrite hijacked files or not
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * rename
- *
- *
- *
- * Specifies that hijacked files should be renamed with a
- * .keep extension
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * currenttime
- *
- *
- *
- * Specifies that modification time should be written
- * as the current time. Either currenttime or
- * preservetime can be specified.
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * preservetime
- *
- *
- *
- * Specifies that modification time should
- * preserved from the VOB time. Either currenttime
- * or preservetime can be specified.
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * @author Curtis White
- */
-public class CCUpdate extends ClearCase
-{
-
- /**
- * -graphical flag -- display graphical dialog during update operation
- */
- public final static String FLAG_GRAPHICAL = "-graphical";
- /**
- * -log flag -- file to log status to
- */
- public final static String FLAG_LOG = "-log";
- /**
- * -overwrite flag -- overwrite hijacked files
- */
- public final static String FLAG_OVERWRITE = "-overwrite";
- /**
- * -noverwrite flag -- do not overwrite hijacked files
- */
- public final static String FLAG_NOVERWRITE = "-noverwrite";
- /**
- * -rename flag -- rename hijacked files with .keep extension
- */
- public final static String FLAG_RENAME = "-rename";
- /**
- * -ctime flag -- modified time is written as the current time
- */
- public final static String FLAG_CURRENTTIME = "-ctime";
- /**
- * -ptime flag -- modified time is written as the VOB time
- */
- public final static String FLAG_PRESERVETIME = "-ptime";
- private boolean m_Graphical = false;
- private boolean m_Overwrite = false;
- private boolean m_Rename = false;
- private boolean m_Ctime = false;
- private boolean m_Ptime = false;
- private String m_Log = null;
-
- /**
- * Set modified time based on current time
- *
- * @param ct the status to set the flag to
- */
- public void setCurrentTime( boolean ct )
- {
- m_Ctime = ct;
- }
-
- /**
- * Set graphical flag status
- *
- * @param graphical the status to set the flag to
- */
- public void setGraphical( boolean graphical )
- {
- m_Graphical = graphical;
- }
-
- /**
- * Set log file where cleartool can record the status of the command
- *
- * @param log the path to the log file
- */
- public void setLog( String log )
- {
- m_Log = log;
- }
-
- /**
- * Set overwrite hijacked files status
- *
- * @param ow the status to set the flag to
- */
- public void setOverwrite( boolean ow )
- {
- m_Overwrite = ow;
- }
-
- /**
- * Preserve modified time from the VOB time
- *
- * @param pt the status to set the flag to
- */
- public void setPreserveTime( boolean pt )
- {
- m_Ptime = pt;
- }
-
- /**
- * Set rename hijacked files status
- *
- * @param ren the status to set the flag to
- */
- public void setRename( boolean ren )
- {
- m_Rename = ren;
- }
-
- /**
- * Get current time status
- *
- * @return boolean containing status of current time flag
- */
- public boolean getCurrentTime()
- {
- return m_Ctime;
- }
-
- /**
- * Get graphical flag status
- *
- * @return boolean containing status of graphical flag
- */
- public boolean getGraphical()
- {
- return m_Graphical;
- }
-
- /**
- * Get log file
- *
- * @return String containing the path to the log file
- */
- public String getLog()
- {
- return m_Log;
- }
-
- /**
- * Get overwrite hijacked files status
- *
- * @return boolean containing status of overwrite flag
- */
- public boolean getOverwrite()
- {
- return m_Overwrite;
- }
-
- /**
- * Get preserve time status
- *
- * @return boolean containing status of preserve time flag
- */
- public boolean getPreserveTime()
- {
- return m_Ptime;
- }
-
- /**
- * Get rename hijacked files status
- *
- * @return boolean containing status of rename flag
- */
- public boolean getRename()
- {
- return m_Rename;
- }
-
- /**
- * Executes the task.
- *
- * Builds a command line to execute cleartool and then calls Exec's run
- * method to execute the command line.
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- Commandline commandLine = new Commandline();
-
- // Default the viewpath to basedir if it is not specified
- if( getViewPath() == null )
- {
- setViewPath( getBaseDirectory().getPath() );
- }
-
- // build the command line from what we got the format is
- // cleartool update [options...] [viewpath ...]
- // as specified in the CLEARTOOL.EXE help
- commandLine.setExecutable( getClearToolCommand() );
- commandLine.addArgument( COMMAND_UPDATE );
-
- // Check the command line options
- checkOptions( commandLine );
-
- // For debugging
- System.out.println( commandLine.toString() );
-
- final int result = run( commandLine );
- if( result != 0 )
- {
- final String message = "Failed executing: " + commandLine.toString();
- throw new TaskException( message );
- }
- }
-
- /**
- * Get the 'log' command
- *
- * @param cmd Description of Parameter
- */
- private void getLogCommand( Commandline cmd )
- {
- if( getLog() == null )
- {
- return;
- }
- else
- {
- /*
- * Had to make two separate commands here because if a space is
- * inserted between the flag and the value, it is treated as a
- * Windows filename with a space and it is enclosed in double
- * quotes ("). This breaks clearcase.
- */
- cmd.addArgument( FLAG_LOG );
- cmd.addArgument( getLog() );
- }
- }
-
- /**
- * Check the command line options.
- *
- * @param cmd Description of Parameter
- */
- private void checkOptions( Commandline cmd )
- {
- // ClearCase items
- if( getGraphical() )
- {
- // -graphical
- cmd.addArgument( FLAG_GRAPHICAL );
- }
- else
- {
- if( getOverwrite() )
- {
- // -overwrite
- cmd.addArgument( FLAG_OVERWRITE );
- }
- else
- {
- if( getRename() )
- {
- // -rename
- cmd.addArgument( FLAG_RENAME );
- }
- else
- {
- // -noverwrite
- cmd.addArgument( FLAG_NOVERWRITE );
- }
- }
-
- if( getCurrentTime() )
- {
- // -ctime
- cmd.addArgument( FLAG_CURRENTTIME );
- }
- else
- {
- if( getPreserveTime() )
- {
- // -ptime
- cmd.addArgument( FLAG_PRESERVETIME );
- }
- }
-
- // -log logname
- getLogCommand( cmd );
- }
-
- // viewpath
- cmd.addArgument( getViewPath() );
- }
-
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/clearcase/ClearCase.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/clearcase/ClearCase.java
deleted file mode 100644
index 56fe846a0..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/clearcase/ClearCase.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.clearcase;
-
-import java.io.File;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * A base class for creating tasks for executing commands on ClearCase.
- *
- * The class extends the 'exec' task as it operates by executing the cleartool
- * program supplied with ClearCase. By default the task expects the cleartool
- * executable to be in the path, * you can override this be specifying the
- * cleartooldir attribute.
- *
- * This class provides set and get methods for the 'viewpath' attribute. It also
- * contains constants for the flags that can be passed to cleartool.
- *
- * @author Curtis White
- */
-public abstract class ClearCase extends AbstractTask
-{
-
- /**
- * Constant for the thing to execute
- */
- private final static String CLEARTOOL_EXE = "cleartool";
-
- /**
- * The 'Update' command
- */
- public final static String COMMAND_UPDATE = "update";
- /**
- * The 'Checkout' command
- */
- public final static String COMMAND_CHECKOUT = "checkout";
- /**
- * The 'Checkin' command
- */
- public final static String COMMAND_CHECKIN = "checkin";
- /**
- * The 'UndoCheckout' command
- */
- public final static String COMMAND_UNCHECKOUT = "uncheckout";
- private String m_ClearToolDir = "";
- private String m_viewPath = null;
-
- /**
- * Set the directory where the cleartool executable is located
- *
- * @param dir the directory containing the cleartool executable
- */
- public final void setClearToolDir( final File dir )
- {
- m_ClearToolDir = dir.toString();
- }
-
- /**
- * Set the path to the item in a clearcase view to operate on
- *
- * @param viewPath Path to the view directory or file
- */
- public final void setViewPath( String viewPath )
- {
- m_viewPath = viewPath;
- }
-
- /**
- * Get the path to the item in a clearcase view
- *
- * @return m_viewPath
- */
- public String getViewPath()
- {
- return m_viewPath;
- }
-
- /**
- * Builds and returns the command string to execute cleartool
- *
- * @return String containing path to the executable
- */
- protected final String getClearToolCommand()
- {
- String toReturn = m_ClearToolDir;
- if( !toReturn.equals( "" ) && !toReturn.endsWith( "/" ) )
- {
- toReturn += "/";
- }
-
- toReturn += CLEARTOOL_EXE;
-
- return toReturn;
- }
-
- protected int run( Commandline cmd )
- throws TaskException
- {
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
- exe.setWorkingDirectory( getBaseDirectory() );
- exe.setCommandline( cmd );
- return exe.execute();
- }
-
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/conditions/Equals.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/conditions/Equals.java
deleted file mode 100644
index 6b43b2804..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/conditions/Equals.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package org.apache.tools.todo.taskdefs.conditions;
-
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.conditions.Condition;
-
-/**
- * Simple String comparison condition.
- *
- * @author Stefan Bodewig
- * @version $Revision$
- *
- * @ant:type type="condition" nam="equals"
- */
-public class Equals implements Condition
-{
-
- private String arg1, arg2;
-
- public void setArg1( String a1 )
- {
- arg1 = a1;
- }
-
- public void setArg2( String a2 )
- {
- arg2 = a2;
- }
-
- /**
- * Evaluates this condition.
- *
- * @param context
- * The context to evaluate the condition in.
- */
- public boolean evaluate( final TaskContext context )
- throws TaskException
- {
- if( arg1 == null || arg2 == null )
- {
- throw new TaskException( "both arg1 and arg2 are required in equals" );
- }
- return arg1.equals( arg2 );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/conditions/Http.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/conditions/Http.java
deleted file mode 100644
index 701a1d2bf..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/conditions/Http.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.conditions;
-
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLConnection;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.conditions.Condition;
-
-/**
- * Condition to wait for a HTTP request to succeed. Its attribute(s) are: url -
- * the URL of the request.
- *
- * @author Denis Hennessy
- *
- * @ant:type type="condition" name="http"
- */
-public class Http
- implements Condition
-{
- String spec = null;
-
- public void setUrl( String url )
- {
- spec = url;
- }
-
- /**
- * Evaluates this condition.
- */
- public boolean evaluate( final TaskContext context )
- throws TaskException
- {
- if( spec == null )
- {
- throw new TaskException( "No url specified in HTTP task" );
- }
- context.debug( "Checking for " + spec );
- try
- {
- URL url = new URL( spec );
- try
- {
- URLConnection conn = url.openConnection();
- if( conn instanceof HttpURLConnection )
- {
- HttpURLConnection http = (HttpURLConnection)conn;
- int code = http.getResponseCode();
- context.debug( "Result code for " + spec + " was " + code );
- if( code > 0 && code < 500 )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- catch( java.io.IOException e )
- {
- return false;
- }
- }
- catch( MalformedURLException e )
- {
- throw new TaskException( "Badly formed URL: " + spec, e );
- }
- return true;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/conditions/Socket.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/conditions/Socket.java
deleted file mode 100644
index a93a49e3f..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/conditions/Socket.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.conditions;
-
-import java.io.IOException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.conditions.Condition;
-
-/**
- * Condition to wait for a TCP/IP socket to have a listener. Its attribute(s)
- * are: server - the name of the server. port - the port number of the socket.
- *
- * @author Denis Hennessy
- *
- * @ant:type type="condition" name="socket"
- */
-public class Socket
- implements Condition
-{
- String server = null;
- int port = 0;
-
- public void setPort( int port )
- {
- this.port = port;
- }
-
- public void setServer( String server )
- {
- this.server = server;
- }
-
- /**
- * Evaluates this condition.
- */
- public boolean evaluate( TaskContext context )
- throws TaskException
- {
- if( server == null )
- {
- throw new TaskException( "No server specified in Socket task" );
- }
- if( port == 0 )
- {
- throw new TaskException( "No port specified in Socket task" );
- }
- context.debug( "Checking for listener at " + server + ":" + port );
- try
- {
- java.net.Socket socket = new java.net.Socket( server, port );
- socket.close();
- }
- catch( IOException e )
- {
- return false;
- }
- return true;
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/exec/ExecuteStreamHandler.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/exec/ExecuteStreamHandler.java
deleted file mode 100644
index 33c1b9c57..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/exec/ExecuteStreamHandler.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.exec;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * Used by Execute
to handle input and output stream of
- * subprocesses.
- *
- * @author thomas.haas@softwired-inc.com
- */
-public interface ExecuteStreamHandler
-{
- /**
- * Install a handler for the input stream of the subprocess.
- *
- * @param os output stream to write to the standard input stream of the
- * subprocess
- * @exception java.io.IOException Description of Exception
- */
- void setProcessInputStream( OutputStream os )
- throws IOException;
-
- /**
- * Install a handler for the error stream of the subprocess.
- *
- * @param is input stream to read from the error stream from the subprocess
- * @exception java.io.IOException Description of Exception
- */
- void setProcessErrorStream( InputStream is )
- throws IOException;
-
- /**
- * Install a handler for the output stream of the subprocess.
- *
- * @param is input stream to read from the error stream from the subprocess
- * @exception java.io.IOException Description of Exception
- */
- void setProcessOutputStream( InputStream is )
- throws TaskException, IOException;
-
- /**
- * Start handling of the streams.
- *
- * @exception java.io.IOException Description of Exception
- */
- void start()
- throws IOException;
-
- /**
- * Stop handling of the streams - will not be restarted.
- */
- void stop()
- throws TaskException;
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/i18n/Translate.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/i18n/Translate.java
deleted file mode 100644
index 6f5135266..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/i18n/Translate.java
+++ /dev/null
@@ -1,637 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.i18n;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.Locale;
-import org.apache.avalon.excalibur.io.FileUtil;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.taskdefs.MatchingTask;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.ScannerUtil;
-
-/**
- * Translates text embedded in files using Resource Bundle files.
- *
- * @author Magesh Umasankar
- */
-public class Translate
- extends MatchingTask
-{
- /**
- * ArrayList to hold source file sets.
- */
- private ArrayList filesets = new ArrayList();
- /**
- * Holds key value pairs loaded from resource bundle file
- */
- private Hashtable resourceMap = new Hashtable();
- /**
- * Last Modified Timestamp of resource bundle file being used.
- */
- private long[] bundleLastModified = new long[ 7 ];
- /**
- * Has at least one file from the bundle been loaded?
- */
- private boolean loaded = false;
-
- /**
- * Family name of resource bundle
- */
- private String bundle;
- /**
- * Locale specific country of the resource bundle
- */
- private String bundleCountry;
- /**
- * Resource Bundle file encoding scheme, defaults to srcEncoding
- */
- private String bundleEncoding;
- /**
- * Locale specific language of the resource bundle
- */
- private String bundleLanguage;
- /**
- * Locale specific variant of the resource bundle
- */
- private String bundleVariant;
- /**
- * Destination file encoding scheme
- */
- private String destEncoding;
- /**
- * Last Modified Timestamp of destination file being used.
- */
- private long destLastModified;
- /**
- * Ending token to identify keys
- */
- private String endToken;
- /**
- * Create new destination file? Defaults to false.
- */
- private boolean forceOverwrite;
-
- /**
- * Source file encoding scheme
- */
- private String srcEncoding;
- /**
- * Last Modified Timestamp of source file being used.
- */
- private long srcLastModified;
- /**
- * Starting token to identify keys
- */
- private String startToken;
- /**
- * Destination directory
- */
- private File toDir;
-
- /**
- * Sets Family name of resource bundle
- *
- * @param bundle The new Bundle value
- */
- public void setBundle( String bundle )
- {
- this.bundle = bundle;
- }
-
- /**
- * Sets locale specific country of resource bundle
- *
- * @param bundleCountry The new BundleCountry value
- */
- public void setBundleCountry( String bundleCountry )
- {
- this.bundleCountry = bundleCountry;
- }
-
- /**
- * Sets Resource Bundle file encoding scheme
- *
- * @param bundleEncoding The new BundleEncoding value
- */
- public void setBundleEncoding( String bundleEncoding )
- {
- this.bundleEncoding = bundleEncoding;
- }
-
- /**
- * Sets locale specific language of resource bundle
- *
- * @param bundleLanguage The new BundleLanguage value
- */
- public void setBundleLanguage( String bundleLanguage )
- {
- this.bundleLanguage = bundleLanguage;
- }
-
- /**
- * Sets locale specific variant of resource bundle
- *
- * @param bundleVariant The new BundleVariant value
- */
- public void setBundleVariant( String bundleVariant )
- {
- this.bundleVariant = bundleVariant;
- }
-
- /**
- * Sets destination file encoding scheme. Defaults to source file encoding
- *
- * @param destEncoding The new DestEncoding value
- */
- public void setDestEncoding( String destEncoding )
- {
- this.destEncoding = destEncoding;
- }
-
- /**
- * Sets ending token to identify keys
- *
- * @param endToken The new EndToken value
- */
- public void setEndToken( String endToken )
- {
- this.endToken = endToken;
- }
-
- /**
- * Overwrite existing file irrespective of whether it is newer than the
- * source file as well as the resource bundle file? Defaults to false.
- *
- * @param forceOverwrite The new ForceOverwrite value
- */
- public void setForceOverwrite( boolean forceOverwrite )
- {
- this.forceOverwrite = forceOverwrite;
- }
-
- /**
- * Sets source file encoding scheme
- *
- * @param srcEncoding The new SrcEncoding value
- */
- public void setSrcEncoding( String srcEncoding )
- {
- this.srcEncoding = srcEncoding;
- }
-
- /**
- * Sets starting token to identify keys
- *
- * @param startToken The new StartToken value
- */
- public void setStartToken( String startToken )
- {
- this.startToken = startToken;
- }
-
- /**
- * Sets Destination directory
- *
- * @param toDir The new ToDir value
- */
- public void setToDir( File toDir )
- {
- this.toDir = toDir;
- }
-
- /**
- * Adds a set of files (nested fileset attribute).
- *
- * @param set The feature to be added to the Fileset attribute
- */
- public void addFileset( FileSet set )
- {
- filesets.add( set );
- }
-
- /**
- * Check attributes values, load resource map and translate
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- if( bundle == null )
- {
- throw new TaskException( "The bundle attribute must be set." );
- }
-
- if( startToken == null )
- {
- throw new TaskException( "The starttoken attribute must be set." );
- }
-
- if( startToken.length() != 1 )
- {
- throw new TaskException(
- "The starttoken attribute must be a single character." );
- }
-
- if( endToken == null )
- {
- throw new TaskException( "The endtoken attribute must be set." );
- }
-
- if( endToken.length() != 1 )
- {
- throw new TaskException(
- "The endtoken attribute must be a single character." );
- }
-
- if( bundleLanguage == null )
- {
- Locale l = Locale.getDefault();
- bundleLanguage = l.getLanguage();
- }
-
- if( bundleCountry == null )
- {
- bundleCountry = Locale.getDefault().getCountry();
- }
-
- if( bundleVariant == null )
- {
- Locale l = new Locale( bundleLanguage, bundleCountry );
- bundleVariant = l.getVariant();
- }
-
- if( toDir == null )
- {
- throw new TaskException( "The todir attribute must be set." );
- }
-
- if( !toDir.exists() )
- {
- toDir.mkdirs();
- }
- else
- {
- if( toDir.isFile() )
- {
- throw new TaskException( toDir + " is not a directory" );
- }
- }
-
- if( srcEncoding == null )
- {
- srcEncoding = System.getProperty( "file.encoding" );
- }
-
- if( destEncoding == null )
- {
- destEncoding = srcEncoding;
- }
-
- if( bundleEncoding == null )
- {
- bundleEncoding = srcEncoding;
- }
-
- loadResourceMaps();
-
- translate();
- }
-
- /**
- * Load resourceMap with key value pairs. Values of existing keys are not
- * overwritten. Bundle's encoding scheme is used.
- *
- * @param ins Description of Parameter
- * @exception TaskException Description of Exception
- */
- private void loadResourceMap( FileInputStream ins )
- throws TaskException
- {
- try
- {
- BufferedReader in = null;
- InputStreamReader isr = new InputStreamReader( ins, bundleEncoding );
- in = new BufferedReader( isr );
- String line = null;
- while( ( line = in.readLine() ) != null )
- {
- //So long as the line isn't empty and isn't a comment...
- if( line.trim().length() > 1 &&
- ( '#' != line.charAt( 0 ) || '!' != line.charAt( 0 ) ) )
- {
- //Legal Key-Value separators are :, = and white space.
- int sepIndex = line.indexOf( '=' );
- if( -1 == sepIndex )
- {
- sepIndex = line.indexOf( ':' );
- }
- if( -1 == sepIndex )
- {
- for( int k = 0; k < line.length(); k++ )
- {
- if( Character.isSpaceChar( line.charAt( k ) ) )
- {
- sepIndex = k;
- break;
- }
- }
- }
- //Only if we do have a key is there going to be a value
- if( -1 != sepIndex )
- {
- String key = line.substring( 0, sepIndex ).trim();
- String value = line.substring( sepIndex + 1 ).trim();
- //Handle line continuations, if any
- while( value.endsWith( "\\" ) )
- {
- value = value.substring( 0, value.length() - 1 );
- if( ( line = in.readLine() ) != null )
- {
- value = value + line.trim();
- }
- else
- {
- break;
- }
- }
- if( key.length() > 0 )
- {
- //Has key already been loaded into resourceMap?
- if( resourceMap.get( key ) == null )
- {
- resourceMap.put( key, value );
- }
- }
- }
- }
- }
- if( in != null )
- {
- in.close();
- }
- }
- catch( IOException ioe )
- {
- throw new TaskException( ioe.getMessage() );
- }
- }
-
- /**
- * Load resource maps based on resource bundle encoding scheme. The resource
- * bundle lookup searches for resource files with various suffixes on the
- * basis of (1) the desired locale and (2) the default locale
- * (basebundlename), in the following order from lower-level (more specific)
- * to parent-level (less specific): basebundlename + "_" + language1 + "_" +
- * country1 + "_" + variant1 basebundlename + "_" + language1 + "_" +
- * country1 basebundlename + "_" + language1 basebundlename basebundlename +
- * "_" + language2 + "_" + country2 + "_" + variant2 basebundlename + "_" +
- * language2 + "_" + country2 basebundlename + "_" + language2 To the
- * generated name, a ".properties" string is appeneded and once this file is
- * located, it is treated just like a properties file but with bundle
- * encoding also considered while loading.
- *
- * @exception TaskException Description of Exception
- */
- private void loadResourceMaps()
- throws TaskException
- {
- Locale locale = new Locale( bundleLanguage,
- bundleCountry,
- bundleVariant );
- String language = locale.getLanguage().length() > 0 ?
- "_" + locale.getLanguage() :
- "";
- String country = locale.getCountry().length() > 0 ?
- "_" + locale.getCountry() :
- "";
- String variant = locale.getVariant().length() > 0 ?
- "_" + locale.getVariant() :
- "";
- String bundleFile = bundle + language + country + variant;
- processBundle( bundleFile, 0, false );
-
- bundleFile = bundle + language + country;
- processBundle( bundleFile, 1, false );
-
- bundleFile = bundle + language;
- processBundle( bundleFile, 2, false );
-
- bundleFile = bundle;
- processBundle( bundleFile, 3, false );
-
- //Load default locale bundle files
- //using default file encoding scheme.
- locale = Locale.getDefault();
-
- language = locale.getLanguage().length() > 0 ?
- "_" + locale.getLanguage() :
- "";
- country = locale.getCountry().length() > 0 ?
- "_" + locale.getCountry() :
- "";
- variant = locale.getVariant().length() > 0 ?
- "_" + locale.getVariant() :
- "";
- bundleEncoding = System.getProperty( "file.encoding" );
-
- bundleFile = bundle + language + country + variant;
- processBundle( bundleFile, 4, false );
-
- bundleFile = bundle + language + country;
- processBundle( bundleFile, 5, false );
-
- bundleFile = bundle + language;
- processBundle( bundleFile, 6, true );
- }
-
- /**
- * Process each file that makes up this bundle.
- *
- * @param bundleFile Description of Parameter
- * @param i Description of Parameter
- * @param checkLoaded Description of Parameter
- * @exception TaskException Description of Exception
- */
- private void processBundle( String bundleFile, int i,
- boolean checkLoaded )
- throws TaskException
- {
- bundleFile += ".properties";
- FileInputStream ins = null;
- try
- {
- ins = new FileInputStream( bundleFile );
- loaded = true;
- bundleLastModified[ i ] = new File( bundleFile ).lastModified();
- getContext().debug( "Using " + bundleFile );
- loadResourceMap( ins );
- }
- catch( IOException ioe )
- {
- getContext().debug( bundleFile + " not found." );
- //if all resource files associated with this bundle
- //have been scanned for and still not able to
- //find a single resrouce file, throw exception
- if( !loaded && checkLoaded )
- {
- throw new TaskException( ioe.getMessage() );
- }
- }
- }
-
- /**
- * Reads source file line by line using the source encoding and searches for
- * keys that are sandwiched between the startToken and endToken. The values
- * for these keys are looked up from the hashtable and substituted. If the
- * hashtable doesn't contain the key, they key itself is used as the value.
- * Detination files and directories are created as needed. The destination
- * file is overwritten only if the forceoverwritten attribute is set to true
- * if the source file or any associated bundle resource file is newer than
- * the destination file.
- *
- * @exception TaskException Description of Exception
- */
- private void translate()
- throws TaskException
- {
- for( int i = 0; i < filesets.size(); i++ )
- {
- FileSet fs = (FileSet)filesets.get( i );
- DirectoryScanner ds = ScannerUtil.getDirectoryScanner( fs );
- String[] srcFiles = ds.getIncludedFiles();
- for( int j = 0; j < srcFiles.length; j++ )
- {
- try
- {
- File dest = FileUtil.resolveFile( toDir, srcFiles[ j ] );
- //Make sure parent dirs exist, else, create them.
- try
- {
- File destDir = new File( dest.getParent() );
- if( !destDir.exists() )
- {
- destDir.mkdirs();
- }
- }
- catch( Exception e )
- {
- getContext().debug( "Exception occured while trying to check/create " + " parent directory. " + e.getMessage() );
- }
- destLastModified = dest.lastModified();
- srcLastModified = new File( srcFiles[ i ] ).lastModified();
- //Check to see if dest file has to be recreated
- if( forceOverwrite
- || destLastModified < srcLastModified
- || destLastModified < bundleLastModified[ 0 ]
- || destLastModified < bundleLastModified[ 1 ]
- || destLastModified < bundleLastModified[ 2 ]
- || destLastModified < bundleLastModified[ 3 ]
- || destLastModified < bundleLastModified[ 4 ]
- || destLastModified < bundleLastModified[ 5 ]
- || destLastModified < bundleLastModified[ 6 ] )
- {
- getContext().debug( "Processing " + srcFiles[ j ] );
- FileOutputStream fos = new FileOutputStream( dest );
- BufferedWriter out = new BufferedWriter(
- new OutputStreamWriter( fos,
- destEncoding ) );
- FileInputStream fis = new FileInputStream( srcFiles[ j ] );
- BufferedReader in = new BufferedReader(
- new InputStreamReader( fis,
- srcEncoding ) );
- String line;
- while( ( line = in.readLine() ) != null )
- {
- int startIndex = -1;
- int endIndex = -1;
- outer :
- while( true )
- {
- startIndex = line.indexOf( startToken, endIndex + 1 );
- if( startIndex < 0 ||
- startIndex + 1 >= line.length() )
- {
- break;
- }
- endIndex = line.indexOf( endToken, startIndex + 1 );
- if( endIndex < 0 )
- {
- break;
- }
- String matches = line.substring( startIndex + 1,
- endIndex );
- //If there is a white space or = or :, then
- //it isn't to be treated as a valid key.
- for( int k = 0; k < matches.length(); k++ )
- {
- char c = matches.charAt( k );
- if( c == ':' ||
- c == '=' ||
- Character.isSpaceChar( c ) )
- {
- endIndex = endIndex - 1;
- continue outer;
- }
- }
- String replace = null;
- replace = (String)resourceMap.get( matches );
- //If the key hasn't been loaded into resourceMap,
- //use the key itself as the value also.
- if( replace == null )
- {
- getContext().debug( "Warning: The key: " + matches + " hasn't been defined." );
- replace = matches;
- }
- line = line.substring( 0, startIndex )
- + replace
- + line.substring( endIndex + 1 );
- endIndex = startIndex + replace.length() + 1;
- if( endIndex + 1 >= line.length() )
- {
- break;
- }
- }
- out.write( line );
- out.newLine();
- }
- if( in != null )
- {
- in.close();
- }
- if( out != null )
- {
- out.close();
- }
- }
- else
- {
- getContext().debug( "Skipping " + srcFiles[ j ] + " as destination file is up to date" );
- }
- }
- catch( IOException ioe )
- {
- throw new TaskException( ioe.getMessage() );
- }
- }
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/CompilerAdapter.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/CompilerAdapter.java
deleted file mode 100644
index 0b3b576f2..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/CompilerAdapter.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javac;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-
-/**
- * The interface that all compiler adapters must adher to.
- *
- * A compiler adapter is an adapter that interprets the javac's parameters in
- * preperation to be passed off to the compier this adapter represents. As all
- * the necessary values are stored in the Javac task itself, the only thing all
- * adapters need is the javac task, the execute command and a parameterless
- * constructor (for reflection).
- *
- * @author Jay Dickon Glanville
- * jayglanville@home.com
- */
-
-public interface CompilerAdapter
-{
- void setTaskContext( TaskContext context );
-
- /**
- * Sets the compiler attributes, which are stored in the Javac task.
- *
- * @param attributes The new Javac value
- */
- void setJavac( Javac attributes );
-
- /**
- * Executes the task.
- *
- * @return has the compilation been successful
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- boolean execute()
- throws TaskException;
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/CompilerAdapterFactory.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/CompilerAdapterFactory.java
deleted file mode 100644
index 6f1030bbc..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/CompilerAdapterFactory.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javac;
-
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.taskdefs.javac.CompilerAdapter;
-
-/**
- * Creates the necessary compiler adapter, given basic criteria.
- *
- * @author J D Glanville
- */
-public class CompilerAdapterFactory
-{
-
- /**
- * This is a singlton -- can't create instances!!
- */
- private CompilerAdapterFactory()
- {
- }
-
- /**
- * Based on the parameter passed in, this method creates the necessary
- * factory desired. The current mapping for compiler names are as follows:
- *
- *
- * jikes = jikes compiler
- * classic, javac1.1, javac1.2 = the standard compiler from JDK
- * 1.1/1.2
- * modern, javac1.3 = the new compiler of JDK 1.3
- * jvc, microsoft = the command line compiler from Microsoft's SDK
- * for Java / Visual J++
- * kjc = the kopi compiler
- * gcj = the gcj compiler from gcc
- * a fully quallified classname = the name of a compiler
- * adapter
- *
- *
- *
- * @param compilerType either the name of the desired compiler, or the full
- * classname of the compiler's adapter.
- * @return The Compiler value
- * @throws org.apache.myrmidon.api.TaskException if the compiler type could not be resolved into a
- * compiler adapter.
- */
- public static CompilerAdapter getCompiler( String compilerType,
- TaskContext context )
- throws TaskException
- {
- final CompilerAdapter adaptor = createAdaptor( compilerType, context );
- adaptor.setTaskContext( context );
- return adaptor;
- }
-
- private static CompilerAdapter createAdaptor( String compilerType, TaskContext context ) throws TaskException
- {
- /*
- * If I've done things right, this should be the extent of the
- * conditional statements required.
- */
- if( compilerType.equalsIgnoreCase( "jikes" ) )
- {
- return new Jikes();
- }
- if( compilerType.equalsIgnoreCase( "extJavac" ) )
- {
- return new JavacExternal();
- }
- if( compilerType.equalsIgnoreCase( "classic" ) ||
- compilerType.equalsIgnoreCase( "javac1.1" ) ||
- compilerType.equalsIgnoreCase( "javac1.2" ) )
- {
- return new Javac12();
- }
- if( compilerType.equalsIgnoreCase( "modern" ) ||
- compilerType.equalsIgnoreCase( "javac1.3" ) ||
- compilerType.equalsIgnoreCase( "javac1.4" ) )
- {
- // does the modern compiler exist?
- try
- {
- Class.forName( "com.sun.tools.javac.Main" );
- }
- catch( ClassNotFoundException cnfe )
- {
- final String message = "Modern compiler is not available - using "
- + "classic compiler";
- context.warn( message );
- return new Javac12();
- }
- return new Javac13();
- }
- if( compilerType.equalsIgnoreCase( "jvc" ) ||
- compilerType.equalsIgnoreCase( "microsoft" ) )
- {
- return new Jvc();
- }
- if( compilerType.equalsIgnoreCase( "kjc" ) )
- {
- return new Kjc();
- }
- if( compilerType.equalsIgnoreCase( "gcj" ) )
- {
- return new Gcj();
- }
- if( compilerType.equalsIgnoreCase( "sj" ) ||
- compilerType.equalsIgnoreCase( "symantec" ) )
- {
- return new Sj();
- }
- return resolveClassName( compilerType );
- }
-
- /**
- * Tries to resolve the given classname into a compiler adapter. Throws a
- * fit if it can't.
- *
- * @param className The fully qualified classname to be created.
- * @return Description of the Returned Value
- * @throws org.apache.myrmidon.api.TaskException This is the fit that is thrown if className isn't
- * an instance of CompilerAdapter.
- */
- private static CompilerAdapter resolveClassName( String className )
- throws TaskException
- {
- try
- {
- Class c = Class.forName( className );
- Object o = c.newInstance();
- return (CompilerAdapter)o;
- }
- catch( ClassNotFoundException cnfe )
- {
- throw new TaskException( className + " can\'t be found.", cnfe );
- }
- catch( ClassCastException cce )
- {
- throw new TaskException( className + " isn\'t the classname of "
- + "a compiler adapter.", cce );
- }
- catch( Throwable t )
- {
- // for all other possibilities
- throw new TaskException( className + " caused an interesting "
- + "exception.", t );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java
deleted file mode 100644
index 95d124cd8..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java
+++ /dev/null
@@ -1,442 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javac;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.avalon.excalibur.io.IOUtil;
-import org.apache.avalon.excalibur.util.StringUtil;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.types.PathUtil;
-import org.apache.tools.todo.util.FileUtils;
-import org.apache.tools.todo.taskdefs.javac.CompilerAdapter;
-
-/**
- * This is the default implementation for the CompilerAdapter interface.
- * Currently, this is a cut-and-paste of the original javac task.
- *
- * @author James Davidson duncan@x180.com
- * @author Robin Green greenrd@hotmail.com
- *
- * @author Stefan Bodewig
- * @author J D Glanville
- */
-public abstract class DefaultCompilerAdapter
- implements CompilerAdapter
-{
- protected boolean m_debug;
- protected boolean m_optimize;
- protected boolean m_deprecation;
- protected boolean m_depend;
- protected boolean m_verbose;
-
- protected Javac m_attributes;
- protected Path m_bootclasspath;
- protected Path m_compileClasspath;
-
- protected File[] m_compileList;
- protected File m_destDir;
- protected String m_encoding;
- protected Path m_extdirs;
- protected boolean m_includeAntRuntime;
- protected boolean m_includeJavaRuntime;
- protected String m_memoryInitialSize;
- protected String m_memoryMaximumSize;
- protected File m_baseDir;
-
- /*
- * jdg - TODO - all these attributes are currently protected, but they
- * should probably be private in the near future.
- */
- protected Path src;
- protected String target;
-
- private TaskContext m_taskContext;
-
- public void setTaskContext( final TaskContext context )
- {
- m_taskContext = context;
- }
-
- protected final TaskContext getTaskContext()
- {
- return m_taskContext;
- }
-
- public void setJavac( Javac attributes )
- {
- m_attributes = attributes;
- src = attributes.getSrcdir();
- m_destDir = attributes.getDestdir();
- m_encoding = attributes.getEncoding();
- m_debug = attributes.getDebug();
- m_optimize = attributes.isOptimize();
- m_deprecation = attributes.getDeprecation();
- m_depend = attributes.getDepend();
- m_verbose = attributes.getVerbose();
- target = attributes.getTarget();
- m_bootclasspath = attributes.getBootclasspath();
- m_extdirs = attributes.getExtdirs();
- m_compileList = attributes.getFileList();
- m_compileClasspath = attributes.getClasspath();
- m_baseDir = attributes.getBaseDirectory();
- m_memoryInitialSize = attributes.getMemoryInitialSize();
- m_memoryMaximumSize = attributes.getMemoryMaximumSize();
- }
-
- public Javac getJavac()
- {
- return m_attributes;
- }
-
- protected Commandline setupJavacCommand()
- throws TaskException
- {
- return setupJavacCommand( false );
- }
-
- /**
- * Does the command line argument processing for classic and adds the files
- * to compile as well.
- *
- * @param debugLevelCheck Description of Parameter
- * @return Description of the Returned Value
- */
- protected Commandline setupJavacCommand( boolean debugLevelCheck )
- throws TaskException
- {
- Commandline cmd = new Commandline();
- setupJavacCommandlineSwitches( cmd, debugLevelCheck );
- logAndAddFilesToCompile( cmd );
- return cmd;
- }
-
- /**
- * Does the command line argument processing common to classic and modern.
- * Doesn't add the files to compile.
- *
- * @param cmd Description of Parameter
- * @param useDebugLevel Description of Parameter
- * @return Description of the Returned Value
- */
- protected Commandline setupJavacCommandlineSwitches( Commandline cmd,
- boolean useDebugLevel )
- throws TaskException
- {
- Path classpath = getCompileClasspath();
- String memoryParameterPrefix = "-J-X";
- if( m_memoryInitialSize != null )
- {
- if( !m_attributes.isForkedJavac() )
- {
- final String message = "Since fork is false, ignoring memoryInitialSize setting.";
- getTaskContext().warn( message );
- }
- else
- {
- cmd.addArgument( memoryParameterPrefix + "ms" + m_memoryInitialSize );
- }
- }
-
- if( m_memoryMaximumSize != null )
- {
- if( !m_attributes.isForkedJavac() )
- {
- final String message = "Since fork is false, ignoring memoryMaximumSize setting.";
- getTaskContext().warn( message );
- }
- else
- {
- cmd.addArgument( memoryParameterPrefix + "mx" + m_memoryMaximumSize );
- }
- }
-
- if( m_attributes.getNowarn() )
- {
- cmd.addArgument( "-nowarn" );
- }
-
- if( m_deprecation == true )
- {
- cmd.addArgument( "-deprecation" );
- }
-
- if( m_destDir != null )
- {
- cmd.addArgument( "-d" );
- cmd.addArgument( m_destDir );
- }
-
- cmd.addArgument( "-classpath" );
- cmd.addArguments( FileUtils.translateCommandline( classpath ) );
-
- cmd.addArgument( "-sourcepath" );
- cmd.addArguments( FileUtils.translateCommandline( src ) );
-
- if( target != null )
- {
- cmd.addArgument( "-target" );
- cmd.addArgument( target );
- }
-
- if( m_bootclasspath != null )
- {
- cmd.addArgument( "-bootclasspath" );
- cmd.addArguments( FileUtils.translateCommandline( m_bootclasspath ) );
- }
-
- if( m_extdirs != null )
- {
- cmd.addArgument( "-extdirs" );
- cmd.addArguments( FileUtils.translateCommandline( m_extdirs ) );
- }
-
- if( m_encoding != null )
- {
- cmd.addArgument( "-encoding" );
- cmd.addArgument( m_encoding );
- }
- if( m_debug )
- {
- if( useDebugLevel )
- {
- String debugLevel = m_attributes.getDebugLevel();
- if( debugLevel != null )
- {
- cmd.addArgument( "-g:" + debugLevel );
- }
- else
- {
- cmd.addArgument( "-g" );
- }
- }
- else
- {
- cmd.addArgument( "-g" );
- }
- }
- else
- {
- cmd.addArgument( "-g:none" );
- }
- if( m_optimize )
- {
- cmd.addArgument( "-O" );
- }
-
- if( m_verbose )
- {
- cmd.addArgument( "-verbose" );
- }
-
- addCurrentCompilerArgs( cmd );
-
- return cmd;
- }
-
- /**
- * Does the command line argument processing for modern and adds the files
- * to compile as well.
- *
- * @return Description of the Returned Value
- */
- protected Commandline setupModernJavacCommand()
- throws TaskException
- {
- Commandline cmd = new Commandline();
- setupModernJavacCommandlineSwitches( cmd );
-
- logAndAddFilesToCompile( cmd );
- return cmd;
- }
-
- /**
- * Does the command line argument processing for modern. Doesn't add the
- * files to compile.
- *
- * @param cmd Description of Parameter
- * @return Description of the Returned Value
- */
- protected Commandline setupModernJavacCommandlineSwitches( Commandline cmd )
- throws TaskException
- {
- setupJavacCommandlineSwitches( cmd, true );
- if( m_attributes.getSource() != null )
- {
- cmd.addArgument( "-source" );
- cmd.addArgument( m_attributes.getSource() );
- }
- return cmd;
- }
-
- /**
- * Builds the compilation classpath.
- *
- * @return The CompileClasspath value
- */
- protected Path getCompileClasspath()
- throws TaskException
- {
- Path classpath = new Path();
-
- // add dest dir to classpath so that previously compiled and
- // untouched classes are on classpath
-
- if( m_destDir != null )
- {
- classpath.addLocation( m_destDir );
- }
-
- // add the classpath
- if( m_compileClasspath != null )
- {
- classpath.addExisting( m_compileClasspath );
- }
-
- return classpath;
- }
-
- /**
- * Adds the command line arguments specifc to the current implementation.
- *
- * @param cmd The feature to be added to the CurrentCompilerArgs attribute
- */
- protected void addCurrentCompilerArgs( Commandline cmd )
- {
- cmd.addArguments( getJavac().getCurrentCompilerArgs() );
- }
-
- /**
- * Do the compile with the specified arguments.
- *
- * @param args - arguments to pass to process on command line
- * @param firstFileName - index of the first source file in args
- * @return Description of the Returned Value
- */
- protected int executeExternalCompile( String[] args, int firstFileName )
- throws TaskException
- {
- String[] commandArray = null;
- File tmpFile = null;
-
- try
- {
- /*
- * Many system have been reported to get into trouble with
- * long command lines - no, not only Windows ;-).
- *
- * POSIX seems to define a lower limit of 4k, so use a temporary
- * file if the total length of the command line exceeds this limit.
- */
- if( StringUtil.join( args, " " ).length() > 4096 )
- {
- PrintWriter out = null;
- try
- {
- tmpFile = File.createTempFile( "jikes", "", new File( "." ) );
- out = new PrintWriter( new FileWriter( tmpFile ) );
- for( int i = firstFileName; i < args.length; i++ )
- {
- out.println( args[ i ] );
- }
- out.flush();
- commandArray = new String[ firstFileName + 1 ];
- System.arraycopy( args, 0, commandArray, 0, firstFileName );
- commandArray[ firstFileName ] = "@" + tmpFile.getAbsolutePath();
- }
- catch( final IOException ioe )
- {
- throw new TaskException( "Error creating temporary file", ioe );
- }
- finally
- {
- IOUtil.shutdownWriter( out );
- }
- }
- else
- {
- commandArray = args;
- }
-
- final ExecManager execManager = (ExecManager)m_attributes.getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
- exe.setWorkingDirectory( m_baseDir );
- final String[] commandline = commandArray;
- exe.setCommandline( new Commandline( commandline ) );
- return exe.execute();
- }
- finally
- {
- if( tmpFile != null )
- {
- tmpFile.delete();
- }
- }
- }
-
- /**
- * Logs the compilation parameters, adds the files to compile and logs the
- * &qout;niceSourceList"
- *
- * @param cmd Description of Parameter
- */
- protected void logAndAddFilesToCompile( Commandline cmd )
- {
- getTaskContext().debug( "Compilation args: " + cmd.toString() );
-
- StringBuffer niceSourceList = new StringBuffer( "File" );
- if( m_compileList.length != 1 )
- {
- niceSourceList.append( "s" );
- }
- niceSourceList.append( " to be compiled:" );
-
- niceSourceList.append( StringUtil.LINE_SEPARATOR );
-
- for( int i = 0; i < m_compileList.length; i++ )
- {
- String arg = m_compileList[ i ].getAbsolutePath();
- cmd.addArgument( arg );
- niceSourceList.append( " " + arg + StringUtil.LINE_SEPARATOR );
- }
-
- getTaskContext().debug( niceSourceList.toString() );
- }
-
- /**
- * Emulation of extdirs feature in java >= 1.2. This method adds all files
- * in the given directories (but not in sub-directories!) to the classpath,
- * so that you don't have to specify them all one by one.
- */
- protected void addExtdirs( Path path )
- throws TaskException
- {
- if( m_extdirs == null )
- {
- String extProp = System.getProperty( "java.ext.dirs" );
- if( extProp != null )
- {
- m_extdirs = new Path( extProp );
- }
- else
- {
- return;
- }
- }
-
- PathUtil.addExtdirs( path, m_extdirs );
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Gcj.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Gcj.java
deleted file mode 100644
index a5f95fca1..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Gcj.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javac;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.util.FileUtils;
-import org.apache.tools.todo.taskdefs.javac.DefaultCompilerAdapter;
-
-/**
- * The implementation of the gcj compiler. This is primarily a cut-and-paste
- * from the jikes.
- *
- * @author Takashi Okamoto
- */
-public class Gcj extends DefaultCompilerAdapter
-{
-
- /**
- * Performs a compile using the gcj compiler.
- *
- * @return Description of the Returned Value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- * @author tora@debian.org
- */
- public boolean execute()
- throws TaskException
- {
- Commandline cmd;
- getTaskContext().debug( "Using gcj compiler" );
- cmd = setupGCJCommand();
-
- int firstFileName = cmd.size();
- logAndAddFilesToCompile( cmd );
-
- return executeExternalCompile( cmd.getCommandline(), firstFileName ) == 0;
- }
-
- protected Commandline setupGCJCommand()
- throws TaskException
- {
- Commandline cmd = new Commandline();
- Path classpath = new Path();
-
- // gcj doesn't support bootclasspath dir (-bootclasspath)
- // so we'll emulate it for compatibility and convenience.
- if( m_bootclasspath != null )
- {
- classpath.append( m_bootclasspath );
- }
-
- // gcj doesn't support an extension dir (-extdir)
- // so we'll emulate it for compatibility and convenience.
- addExtdirs( classpath );
-
- if( ( m_bootclasspath == null ) || ( m_bootclasspath.size() == 0 ) )
- {
- // no bootclasspath, therefore, get one from the java runtime
- m_includeJavaRuntime = true;
- }
- classpath.append( getCompileClasspath() );
-
- // Gcj has no option for source-path so we
- // will add it to classpath.
- classpath.append( src );
-
- cmd.setExecutable( "gcj" );
-
- if( m_destDir != null )
- {
- cmd.addArgument( "-d" );
- cmd.addArgument( m_destDir );
-
- if( m_destDir.mkdirs() )
- {
- throw new TaskException( "Can't make output directories. Maybe permission is wrong. " );
- }
- ;
- }
-
- cmd.addArgument( "-classpath" );
- cmd.addArguments( FileUtils.translateCommandline( classpath ) );
-
- if( m_encoding != null )
- {
- cmd.addArgument( "--encoding=" + m_encoding );
- }
- if( m_debug )
- {
- cmd.addArgument( "-g1" );
- }
- if( m_optimize )
- {
- cmd.addArgument( "-O" );
- }
-
- /**
- * gcj should be set for generate class.
- */
- cmd.addArgument( "-C" );
-
- addCurrentCompilerArgs( cmd );
-
- return cmd;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/ImplementationSpecificArgument.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/ImplementationSpecificArgument.java
deleted file mode 100644
index d637e3e0a..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/ImplementationSpecificArgument.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javac;
-
-import org.apache.tools.todo.types.Argument;
-
-/**
- * Adds an "implementation" attribute to Commandline$Attribute used to
- * filter command line attributes based on the current implementation.
- */
-public class ImplementationSpecificArgument
- extends Argument
-{
- private String m_impl;
- private Javac m_javac;
-
- public ImplementationSpecificArgument( Javac javac )
- {
- m_javac = javac;
- }
-
- public void setImplementation( String impl )
- {
- this.m_impl = impl;
- }
-
- public String[] getParts()
- {
- if( m_impl == null || m_impl.equals( m_javac.determineCompiler() ) )
- {
- return super.getParts();
- }
- else
- {
- return new String[ 0 ];
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Javac.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Javac.java
deleted file mode 100644
index 4dda69f76..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Javac.java
+++ /dev/null
@@ -1,765 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javac;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import org.apache.aut.nativelib.Os;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.JavaVersion;
-import org.apache.tools.todo.taskdefs.MatchingTask;
-import org.apache.tools.todo.taskdefs.javac.CompilerAdapter;
-import org.apache.tools.todo.taskdefs.javac.CompilerAdapterFactory;
-import org.apache.tools.todo.taskdefs.javac.ImplementationSpecificArgument;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.types.SourceFileScanner;
-import org.apache.tools.todo.util.mappers.GlobPatternMapper;
-
-/**
- * Task to compile Java source files. This task can take the following
- * arguments:
- *
- * sourcedir
- * destdir
- * deprecation
- * classpath
- * bootclasspath
- * extdirs
- * optimize
- * debug
- * encoding
- * target
- * depend
- * vebose
- * failonerror
- * includeantruntime
- * includejavaruntime
- * source
- *
- * Of these arguments, the sourcedir and destdir are required.
- *
- * When this task executes, it will recursively scan the sourcedir and destdir
- * looking for Java source files to compile. This task makes its compile
- * decision based on timestamp.
- *
- * @author James Davidson duncan@x180.com
- * @author Robin Green greenrd@hotmail.com
- *
- * @author Stefan Bodewig
- * @author J D Glanville
- */
-public class Javac
- extends MatchingTask
-{
- private final static String FAIL_MSG
- = "Compile failed, messages should have been provided.";
-
- private boolean m_debug;
- private boolean m_optimize;
- private boolean m_deprecation;
- private boolean m_depend;
- private boolean m_verbose;
- private boolean m_includeAntRuntime = true;
- private boolean m_includeJavaRuntime;
- private boolean m_fork;
- private String m_forkedExecutable;
- private boolean m_nowarn;
- private ArrayList m_implementationSpecificArgs = new ArrayList();
-
- protected File[] m_compileList = new File[ 0 ];
- private Path m_bootclasspath;
- private Path m_compileClasspath;
- private String m_debugLevel;
- private File m_destDir;
- private String m_encoding;
- private Path m_extdirs;
- private String m_memoryInitialSize;
- private String m_memoryMaximumSize;
- private String m_source;
- private Path m_src;
- private String m_target;
-
- /**
- * Adds an element to the bootclasspath that will be used to compile the
- * classes against.
- */
- public void addBootclasspath( Path bootclasspath )
- {
- if( m_bootclasspath == null )
- {
- m_bootclasspath = bootclasspath;
- }
- else
- {
- m_bootclasspath.addPath( bootclasspath );
- }
- }
-
- /**
- * Adds an element to the classpath to be used for this compilation.
- */
- public void addClasspath( Path classpath )
- {
- if( m_compileClasspath == null )
- {
- m_compileClasspath = classpath;
- }
- else
- {
- m_compileClasspath.addPath( classpath );
- }
- }
-
- /**
- * Set the debug flag.
- */
- public void setDebug( final boolean debug )
- {
- m_debug = debug;
- }
-
- /**
- * Set the value of debugLevel.
- *
- * @param v Value to assign to debugLevel.
- */
- public void setDebugLevel( String v )
- {
- m_debugLevel = v;
- }
-
- /**
- * Set the depend flag.
- *
- * @param depend The new Depend value
- */
- public void setDepend( boolean depend )
- {
- m_depend = depend;
- }
-
- /**
- * Set the deprecation flag.
- *
- * @param deprecation The new Deprecation value
- */
- public void setDeprecation( boolean deprecation )
- {
- m_deprecation = deprecation;
- }
-
- /**
- * Set the destination directory into which the Java source files should be
- * compiled.
- *
- * @param destDir The new Destdir value
- */
- public void setDestdir( File destDir )
- {
- m_destDir = destDir;
- }
-
- /**
- * Set the Java source file encoding name.
- *
- * @param encoding The new Encoding value
- */
- public void setEncoding( String encoding )
- {
- m_encoding = encoding;
- }
-
- /**
- * Adds an element to the extension directories that will be used during
- * the compilation.
- *
- * @param extdirs The new Extdirs value
- */
- public void addExtdirs( Path extdirs )
- throws TaskException
- {
- if( m_extdirs == null )
- {
- m_extdirs = extdirs;
- }
- else
- {
- m_extdirs.addPath( extdirs );
- }
- }
-
- /**
- * Sets whether to fork the javac compiler.
- */
- public void setFork( final boolean fork )
- {
- m_fork = fork;
- if( fork )
- {
- m_forkedExecutable = getSystemJavac();
- }
- }
-
- /**
- * Include ant's own classpath in this task's classpath?
- *
- * @param include The new Includeantruntime value
- */
- public void setIncludeantruntime( boolean include )
- {
- m_includeAntRuntime = include;
- }
-
- /**
- * Sets whether or not to include the java runtime libraries to this task's
- * classpath.
- *
- * @param include The new Includejavaruntime value
- */
- public void setIncludejavaruntime( boolean include )
- {
- m_includeJavaRuntime = include;
- }
-
- /**
- * Set the memoryInitialSize flag.
- *
- * @param memoryInitialSize The new MemoryInitialSize value
- */
- public void setMemoryInitialSize( String memoryInitialSize )
- {
- m_memoryInitialSize = memoryInitialSize;
- }
-
- /**
- * Set the memoryMaximumSize flag.
- *
- * @param memoryMaximumSize The new MemoryMaximumSize value
- */
- public void setMemoryMaximumSize( String memoryMaximumSize )
- {
- m_memoryMaximumSize = memoryMaximumSize;
- }
-
- /**
- * Sets whether the -nowarn option should be used.
- *
- * @param flag The new Nowarn value
- */
- public void setNowarn( boolean flag )
- {
- m_nowarn = flag;
- }
-
- /**
- * Set the optimize flag.
- *
- * @param optimize The new Optimize value
- */
- public void setOptimize( boolean optimize )
- {
- m_optimize = optimize;
- }
-
- /**
- * Set the value of source.
- *
- * @param v Value to assign to source.
- */
- public void setSource( String v )
- {
- m_source = v;
- }
-
- /**
- * Adds an element to the source dirs to find the source Java files.
- *
- * @param srcDir The new Srcdir value
- */
- public void addSrcdir( Path srcDir )
- throws TaskException
- {
- if( m_src == null )
- {
- m_src = srcDir;
- }
- else
- {
- m_src.addPath( srcDir );
- }
- }
-
- /**
- * Sets the target VM that the classes will be compiled for. Valid strings
- * are "1.1", "1.2", and "1.3".
- *
- * @param target The new Target value
- */
- public void setTarget( String target )
- {
- m_target = target;
- }
-
- /**
- * Set the verbose flag.
- *
- * @param verbose The new Verbose value
- */
- public void setVerbose( boolean verbose )
- {
- m_verbose = verbose;
- }
-
- /**
- * Gets the bootclasspath that will be used to compile the classes against.
- *
- * @return The Bootclasspath value
- */
- public Path getBootclasspath()
- {
- return m_bootclasspath;
- }
-
- /**
- * Gets the classpath to be used for this compilation.
- *
- * @return The Classpath value
- */
- public Path getClasspath()
- {
- return m_compileClasspath;
- }
-
- protected File getBaseDir()
- {
- return getBaseDirectory();
- }
-
- /**
- * Get the additional implementation specific command line arguments.
- *
- * @return array of command line arguments, guaranteed to be non-null.
- */
- public String[] getCurrentCompilerArgs()
- {
- ArrayList args = new ArrayList();
- for( Iterator enum = m_implementationSpecificArgs.iterator();
- enum.hasNext();
- )
- {
- String[] curr =
- ( (ImplementationSpecificArgument)enum.next() ).getParts();
- for( int i = 0; i < curr.length; i++ )
- {
- args.add( curr[ i ] );
- }
- }
- final String[] res = new String[ args.size() ];
- return (String[])args.toArray( res );
- }
-
- /**
- * Gets the debug flag.
- *
- * @return The Debug value
- */
- public boolean getDebug()
- {
- return m_debug;
- }
-
- /**
- * Get the value of debugLevel.
- *
- * @return value of debugLevel.
- */
- public String getDebugLevel()
- {
- return m_debugLevel;
- }
-
- /**
- * Gets the depend flag.
- *
- * @return The Depend value
- */
- public boolean getDepend()
- {
- return m_depend;
- }
-
- /**
- * Gets the deprecation flag.
- *
- * @return The Deprecation value
- */
- public boolean getDeprecation()
- {
- return m_deprecation;
- }
-
- /**
- * Gets the destination directory into which the java source files should be
- * compiled.
- *
- * @return The Destdir value
- */
- public File getDestdir()
- {
- return m_destDir;
- }
-
- /**
- * Gets the java source file encoding name.
- *
- * @return The Encoding value
- */
- public String getEncoding()
- {
- return m_encoding;
- }
-
- /**
- * Gets the extension directories that will be used during the compilation.
- *
- * @return The Extdirs value
- */
- public Path getExtdirs()
- {
- return m_extdirs;
- }
-
- /**
- * Gets the list of files to be compiled.
- *
- * @return The FileList value
- */
- public File[] getFileList()
- {
- return m_compileList;
- }
-
- /**
- * Gets whether or not the ant classpath is to be included in the task's
- * classpath.
- *
- * @return The Includeantruntime value
- */
- public boolean getIncludeantruntime()
- {
- return m_includeAntRuntime;
- }
-
- /**
- * Gets whether or not the java runtime should be included in this task's
- * classpath.
- *
- * @return The Includejavaruntime value
- */
- public boolean getIncludejavaruntime()
- {
- return m_includeJavaRuntime;
- }
-
- /**
- * The name of the javac executable to use in fork-mode.
- *
- * @return The JavacExecutable value
- */
- public String getJavacExecutable()
- {
- if( m_forkedExecutable == null && isForkedJavac() )
- {
- m_forkedExecutable = getSystemJavac();
- }
- else if( m_forkedExecutable != null && !isForkedJavac() )
- {
- m_forkedExecutable = null;
- }
- return m_forkedExecutable;
- }
-
- /**
- * Gets the memoryInitialSize flag.
- *
- * @return The MemoryInitialSize value
- */
- public String getMemoryInitialSize()
- {
- return m_memoryInitialSize;
- }
-
- /**
- * Gets the memoryMaximumSize flag.
- *
- * @return The MemoryMaximumSize value
- */
- public String getMemoryMaximumSize()
- {
- return m_memoryMaximumSize;
- }
-
- /**
- * Should the -nowarn option be used.
- *
- * @return The Nowarn value
- */
- public boolean getNowarn()
- {
- return m_nowarn;
- }
-
- /**
- * Gets the optimize flag.
- *
- * @return The Optimize value
- */
- public boolean isOptimize()
- {
- return m_optimize;
- }
-
- /**
- * Get the value of source.
- *
- * @return value of source.
- */
- public String getSource()
- {
- return m_source;
- }
-
- /**
- * Gets the source dirs to find the source java files.
- *
- * @return The Srcdir value
- */
- public Path getSrcdir()
- {
- return m_src;
- }
-
- /**
- * Gets the target VM that the classes will be compiled for.
- *
- * @return The Target value
- */
- public String getTarget()
- {
- return m_target;
- }
-
- /**
- * Gets the verbose flag.
- *
- * @return The Verbose value
- */
- public boolean getVerbose()
- {
- return m_verbose;
- }
-
- /**
- * Is this a forked invocation of JDK's javac?
- *
- * @return The ForkedJavac value
- */
- public boolean isForkedJavac()
- {
- return m_fork;
- }
-
- /**
- * Adds an implementation specific command line argument.
- */
- public ImplementationSpecificArgument createCompilerArg()
- {
- final ImplementationSpecificArgument arg = new ImplementationSpecificArgument( this );
- m_implementationSpecificArgs.add( arg );
- return arg;
- }
-
- /**
- * Executes the task.
- *
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- // first off, make sure that we've got a srcdir
-
- if( m_src == null )
- {
- throw new TaskException( "srcdir attribute must be set!" );
- }
- String[] list = m_src.list();
- if( list.length == 0 )
- {
- throw new TaskException( "srcdir attribute must be set!" );
- }
-
- if( m_destDir != null && !m_destDir.isDirectory() )
- {
- throw new TaskException( "destination directory \"" + m_destDir + "\" does not exist or is not a directory" );
- }
-
- // scan source directories and dest directory to build up
- // compile lists
- resetFileLists();
- for( int i = 0; i < list.length; i++ )
- {
- final String filename = list[ i ];
- File srcDir = (File)getContext().resolveFile( filename );
- if( !srcDir.exists() )
- {
- throw new TaskException( "srcdir \"" + srcDir.getPath() + "\" does not exist!" );
- }
-
- DirectoryScanner ds = getDirectoryScanner( srcDir );
-
- String[] files = ds.getIncludedFiles();
-
- scanDir( srcDir, m_destDir != null ? m_destDir : srcDir, files );
- }
-
- // compile the source files
-
- String compiler = determineCompiler();
-
- if( m_compileList.length > 0 )
- {
-
- CompilerAdapter adapter =
- CompilerAdapterFactory.getCompiler( compiler, getContext() );
- final String message = "Compiling " + m_compileList.length + " source file" +
- ( m_compileList.length == 1 ? "" : "s" ) +
- ( m_destDir != null ? " to " + m_destDir : "" );
- getContext().info( message );
-
- // now we need to populate the compiler adapter
- adapter.setJavac( this );
-
- // finally, lets execute the compiler!!
- if( !adapter.execute() )
- {
- throw new TaskException( FAIL_MSG );
- }
- }
- }
-
- protected String getSystemJavac()
- {
- // This is the most common extension case - exe for windows and OS/2,
- // nothing for *nix.
- String extension = Os.isFamily( Os.OS_FAMILY_DOS ) ? ".exe" : "";
-
- // Look for java in the java.home/../bin directory. Unfortunately
- // on Windows java.home doesn't always refer to the correct location,
- // so we need to fall back to assuming java is somewhere on the
- // PATH.
- File jExecutable =
- new File( System.getProperty( "java.home" ) +
- "/../bin/javac" + extension );
-
- if( jExecutable.exists() && !Os.isFamily( Os.OS_FAMILY_NETWARE ) )
- {
- return jExecutable.getAbsolutePath();
- }
- else
- {
- return "javac";
- }
- }
-
- protected boolean isJdkCompiler( String compiler )
- {
- return "modern".equals( compiler ) ||
- "classic".equals( compiler ) ||
- "javac1.1".equals( compiler ) ||
- "javac1.2".equals( compiler ) ||
- "javac1.3".equals( compiler ) ||
- "javac1.4".equals( compiler );
- }
-
- /**
- * Clear the list of files to be compiled and copied..
- */
- protected void resetFileLists()
- {
- m_compileList = new File[ 0 ];
- }
-
- /**
- * Scans the directory looking for source files to be compiled. The results
- * are returned in the class variable compileList
- *
- * @param srcDir Description of Parameter
- * @param destDir Description of Parameter
- * @param files Description of Parameter
- */
- protected void scanDir( File srcDir, File destDir, String files[] )
- throws TaskException
- {
- GlobPatternMapper m = new GlobPatternMapper();
- m.setFrom( "*.java" );
- m.setTo( "*.class" );
- SourceFileScanner sfs = new SourceFileScanner();
- File[] newFiles = sfs.restrictAsFiles( files, srcDir, destDir, m, getContext() );
-
- if( newFiles.length > 0 )
- {
- File[] newCompileList = new File[ m_compileList.length +
- newFiles.length ];
- System.arraycopy( m_compileList, 0, newCompileList, 0,
- m_compileList.length );
- System.arraycopy( newFiles, 0, newCompileList,
- m_compileList.length, newFiles.length );
- m_compileList = newCompileList;
- }
- }
-
- protected String determineCompiler()
- {
- Object compiler = getContext().getProperty( "build.compiler" );
- if( compiler != null )
- {
- if( isJdkCompiler( compiler.toString() ) )
- {
- final String message = "Since fork is true, ignoring build.compiler setting.";
- getContext().warn( message );
- compiler = "extJavac";
- }
- else
- {
- getContext().warn( "Since build.compiler setting isn't classic or modern, ignoring fork setting." );
- }
- }
- else
- {
- compiler = "extJavac";
- }
-
- if( compiler == null )
- {
- if( JavaVersion.JAVA1_2 != JavaVersion.getCurrentJavaVersion() )
- {
- compiler = "modern";
- }
- else
- {
- compiler = "classic";
- }
- }
- return compiler.toString();
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Javac12.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Javac12.java
deleted file mode 100644
index fb4a0b966..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Javac12.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javac;
-
-import java.io.OutputStream;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.taskdefs.javac.DefaultCompilerAdapter;
-
-/**
- * The implementation of the javac compiler for JDK 1.2 This is primarily a
- * cut-and-paste from the original javac task before it was refactored.
- *
- * @author James Davidson duncan@x180.com
- * @author Robin Green greenrd@hotmail.com
- *
- * @author Stefan Bodewig
- * @author J D Glanville
- */
-public class Javac12 extends DefaultCompilerAdapter
-{
-
- public boolean execute()
- throws TaskException
- {
- getTaskContext().debug( "Using classic compiler" );
- Commandline cmd = setupJavacCommand( true );
-
- try
- {
- // Create an instance of the compiler, redirecting output to
- // the project log
- Class c = Class.forName( "sun.tools.javac.Main" );
- Constructor cons = c.getConstructor( new Class[]{OutputStream.class, String.class} );
- Object compiler = cons.newInstance( new Object[]{System.out, "javac"} );
-
- // Call the compile() method
- Method compile = c.getMethod( "compile", new Class[]{String[].class} );
- Boolean ok = (Boolean)compile.invoke( compiler, new Object[]{cmd.getArguments()} );
- return ok.booleanValue();
- }
- catch( ClassNotFoundException ex )
- {
- throw new TaskException( "Cannot use classic compiler, as it is not available" +
- " A common solution is to set the environment variable" +
- " JAVA_HOME to your jdk directory." );
- }
- catch( Exception ex )
- {
- if( ex instanceof TaskException )
- {
- throw (TaskException)ex;
- }
- else
- {
- throw new TaskException( "Error starting classic compiler: ", ex );
- }
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Javac13.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Javac13.java
deleted file mode 100644
index aa4771b65..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Javac13.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javac;
-
-import java.lang.reflect.Method;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.taskdefs.javac.DefaultCompilerAdapter;
-
-/**
- * The implementation of the javac compiler for JDK 1.3 This is primarily a
- * cut-and-paste from the original javac task before it was refactored.
- *
- * @author James Davidson duncan@x180.com
- * @author Robin Green greenrd@hotmail.com
- *
- * @author Stefan Bodewig
- * @author J D Glanville
- */
-public class Javac13 extends DefaultCompilerAdapter
-{
-
- /**
- * Integer returned by the "Modern" jdk1.3 compiler to indicate success.
- */
- private final static int MODERN_COMPILER_SUCCESS = 0;
-
- public boolean execute()
- throws TaskException
- {
- getTaskContext().debug( "Using modern compiler" );
- Commandline cmd = setupModernJavacCommand();
-
- // Use reflection to be able to build on all JDKs >= 1.1:
- try
- {
- Class c = Class.forName( "com.sun.tools.javac.Main" );
- Object compiler = c.newInstance();
- Method compile = c.getMethod( "compile",
- new Class[]{( new String[]{} ).getClass()} );
- int result = ( (Integer)compile.invoke
- ( compiler, new Object[]{cmd.getArguments()} ) ).intValue();
- return ( result == MODERN_COMPILER_SUCCESS );
- }
- catch( Exception ex )
- {
- if( ex instanceof TaskException )
- {
- throw (TaskException)ex;
- }
- else
- {
- throw new TaskException( "Error starting modern compiler", ex );
- }
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/JavacExternal.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/JavacExternal.java
deleted file mode 100644
index 475290d47..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/JavacExternal.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javac;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.taskdefs.javac.DefaultCompilerAdapter;
-
-/**
- * Performs a compile using javac externally.
- *
- * @author Brian Deitte
- */
-public class JavacExternal extends DefaultCompilerAdapter
-{
-
- /**
- * Performs a compile using the Javac externally.
- *
- * @return Description of the Returned Value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public boolean execute()
- throws TaskException
- {
- getTaskContext().debug( "Using external javac compiler" );
-
- Commandline cmd = new Commandline();
- cmd.setExecutable( getJavac().getJavacExecutable() );
- setupModernJavacCommandlineSwitches( cmd );
- int firstFileName = cmd.size();
- logAndAddFilesToCompile( cmd );
-
- return executeExternalCompile( cmd.getCommandline(), firstFileName ) == 0;
- }
-
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Jikes.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Jikes.java
deleted file mode 100644
index 622aa7565..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Jikes.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javac;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.util.FileUtils;
-import org.apache.tools.todo.taskdefs.javac.DefaultCompilerAdapter;
-
-/**
- * The implementation of the jikes compiler. This is primarily a cut-and-paste
- * from the original javac task before it was refactored.
- *
- * @author James Davidson duncan@x180.com
- * @author Robin Green greenrd@hotmail.com
- *
- * @author Stefan Bodewig
- * @author J D Glanville
- */
-public class Jikes
- extends DefaultCompilerAdapter
-{
-
- /**
- * Performs a compile using the Jikes compiler from IBM.. Mostly of this
- * code is identical to doClassicCompile() However, it does not support all
- * options like bootclasspath, extdirs, deprecation and so on, because there
- * is no option in jikes and I don't understand what they should do. It has
- * been successfully tested with jikes >1.10
- *
- * @return Description of the Returned Value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- * @author skanthak@muehlheim.de
- */
- public boolean execute()
- throws TaskException
- {
- getTaskContext().debug( "Using jikes compiler" );
-
- Path classpath = new Path();
-
- // Jikes doesn't support bootclasspath dir (-bootclasspath)
- // so we'll emulate it for compatibility and convenience.
- if( m_bootclasspath != null )
- {
- classpath.append( m_bootclasspath );
- }
-
- // Jikes doesn't support an extension dir (-extdir)
- // so we'll emulate it for compatibility and convenience.
- addExtdirs( classpath );
-
- if( ( m_bootclasspath == null ) || ( m_bootclasspath.size() == 0 ) )
- {
- // no bootclasspath, therefore, get one from the java runtime
- m_includeJavaRuntime = true;
- }
- else
- {
- // there is a bootclasspath stated. By default, the
- // includeJavaRuntime is false. If the user has stated a
- // bootclasspath and said to include the java runtime, it's on
- // their head!
- }
- classpath.append( getCompileClasspath() );
-
- // Jikes has no option for source-path so we
- // will add it to classpath.
- classpath.append( src );
-
- // if the user has set JIKESPATH we should add the contents as well
- String jikesPath = System.getProperty( "jikes.class.path" );
- if( jikesPath != null )
- {
- classpath.append( new Path( jikesPath ) );
- }
-
- Commandline cmd = new Commandline();
- cmd.setExecutable( "jikes" );
-
- if( m_deprecation == true )
- {
- cmd.addArgument( "-deprecation" );
- }
-
- if( m_destDir != null )
- {
- cmd.addArgument( "-d" );
- cmd.addArgument( m_destDir );
- }
-
- cmd.addArgument( "-classpath" );
- cmd.addArguments( FileUtils.translateCommandline( classpath ) );
-
- if( m_encoding != null )
- {
- cmd.addArgument( "-encoding" );
- cmd.addArgument( m_encoding );
- }
- if( m_debug )
- {
- cmd.addArgument( "-g" );
- }
- if( m_optimize )
- {
- cmd.addArgument( "-O" );
- }
- if( m_verbose )
- {
- cmd.addArgument( "-verbose" );
- }
- if( m_depend )
- {
- cmd.addArgument( "-depend" );
- }
-
- if( m_attributes.getNowarn() )
- {
- /*
- * FIXME later
- *
- * let the magic property win over the attribute for backwards
- * compatibility
- */
- cmd.addArgument( "-nowarn" );
- }
-
- addCurrentCompilerArgs( cmd );
-
- int firstFileName = cmd.size();
- logAndAddFilesToCompile( cmd );
-
- return executeExternalCompile( cmd.getCommandline(), firstFileName ) == 0;
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Jvc.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Jvc.java
deleted file mode 100644
index 422974f8d..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Jvc.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javac;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.util.FileUtils;
-import org.apache.tools.todo.taskdefs.javac.DefaultCompilerAdapter;
-
-/**
- * The implementation of the jvc compiler from microsoft. This is primarily a
- * cut-and-paste from the original javac task before it was refactored.
- *
- * @author James Davidson duncan@x180.com
- * @author Robin Green greenrd@hotmail.com
- *
- * @author Stefan Bodewig
- * @author J D Glanville
- */
-public class Jvc extends DefaultCompilerAdapter
-{
-
- public boolean execute()
- throws TaskException
- {
- getTaskContext().debug( "Using jvc compiler" );
-
- Path classpath = new Path();
-
- // jvc doesn't support bootclasspath dir (-bootclasspath)
- // so we'll emulate it for compatibility and convenience.
- if( m_bootclasspath != null )
- {
- classpath.append( m_bootclasspath );
- }
-
- // jvc doesn't support an extension dir (-extdir)
- // so we'll emulate it for compatibility and convenience.
- addExtdirs( classpath );
-
- if( ( m_bootclasspath == null ) || ( m_bootclasspath.size() == 0 ) )
- {
- // no bootclasspath, therefore, get one from the java runtime
- m_includeJavaRuntime = true;
- }
- else
- {
- // there is a bootclasspath stated. By default, the
- // includeJavaRuntime is false. If the user has stated a
- // bootclasspath and said to include the java runtime, it's on
- // their head!
- }
- classpath.append( getCompileClasspath() );
-
- // jvc has no option for source-path so we
- // will add it to classpath.
- classpath.append( src );
-
- Commandline cmd = new Commandline();
- cmd.setExecutable( "jvc" );
-
- if( m_destDir != null )
- {
- cmd.addArgument( "/d" );
- cmd.addArgument( m_destDir );
- }
-
- // Add the Classpath before the "internal" one.
- cmd.addArgument( "/cp:p" );
- cmd.addArguments( FileUtils.translateCommandline( classpath ) );
-
- // Enable MS-Extensions and ...
- cmd.addArgument( "/x-" );
- // ... do not display a Message about this.
- cmd.addArgument( "/nomessage" );
- // Do not display Logo
- cmd.addArgument( "/nologo" );
-
- if( m_debug )
- {
- cmd.addArgument( "/g" );
- }
- if( m_optimize )
- {
- cmd.addArgument( "/O" );
- }
- if( m_verbose )
- {
- cmd.addArgument( "/verbose" );
- }
-
- addCurrentCompilerArgs( cmd );
-
- int firstFileName = cmd.size();
- logAndAddFilesToCompile( cmd );
-
- return executeExternalCompile( cmd.getCommandline(), firstFileName ) == 0;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Kjc.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Kjc.java
deleted file mode 100644
index c7a0cec7a..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Kjc.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javac;
-
-import java.lang.reflect.Method;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.util.FileUtils;
-import org.apache.tools.todo.taskdefs.javac.DefaultCompilerAdapter;
-
-/**
- * The implementation of the Java compiler for KJC. This is primarily a
- * cut-and-paste from Jikes.java and DefaultCompilerAdapter.
- *
- * @author Takashi Okamoto +
- */
-public class Kjc extends DefaultCompilerAdapter
-{
-
- public boolean execute()
- throws TaskException
- {
- getTaskContext().debug( "Using kjc compiler" );
- Commandline cmd = setupKjcCommand();
-
- try
- {
- Class c = Class.forName( "at.dms.kjc.Main" );
-
- // Call the compile() method
- Method compile = c.getMethod( "compile",
- new Class[]{String[].class} );
- Boolean ok = (Boolean)compile.invoke( null,
- new Object[]{cmd.getArguments()} );
- return ok.booleanValue();
- }
- catch( ClassNotFoundException ex )
- {
- throw new TaskException( "Cannot use kjc compiler, as it is not available" +
- " A common solution is to set the environment variable" +
- " CLASSPATH to your kjc archive (kjc.jar)." );
- }
- catch( Exception ex )
- {
- if( ex instanceof TaskException )
- {
- throw (TaskException)ex;
- }
- else
- {
- throw new TaskException( "Error starting kjc compiler: ", ex );
- }
- }
- }
-
- /**
- * setup kjc command arguments.
- *
- * @return Description of the Returned Value
- */
- protected Commandline setupKjcCommand()
- throws TaskException
- {
- Commandline cmd = new Commandline();
-
- // generate classpath, because kjc does't support sourcepath.
- Path classpath = getCompileClasspath();
-
- if( m_deprecation == true )
- {
- cmd.addArgument( "-deprecation" );
- }
-
- if( m_destDir != null )
- {
- cmd.addArgument( "-d" );
- cmd.addArgument( m_destDir );
- }
-
- // generate the clsspath
- cmd.addArgument( "-classpath" );
-
- Path cp = new Path();
-
- // kjc don't have bootclasspath option.
- if( m_bootclasspath != null )
- {
- cp.append( m_bootclasspath );
- }
-
- if( m_extdirs != null )
- {
- addExtdirs( cp );
- }
-
- cp.append( classpath );
- cp.append( src );
-
- cmd.addArguments( FileUtils.translateCommandline( cp ) );
-
- // kjc-1.5A doesn't support -encoding option now.
- // but it will be supported near the feature.
- if( m_encoding != null )
- {
- cmd.addArgument( "-encoding" );
- cmd.addArgument( m_encoding );
- }
-
- if( m_debug )
- {
- cmd.addArgument( "-g" );
- }
-
- if( m_optimize )
- {
- cmd.addArgument( "-O2" );
- }
-
- if( m_verbose )
- {
- cmd.addArgument( "-verbose" );
- }
-
- addCurrentCompilerArgs( cmd );
-
- logAndAddFilesToCompile( cmd );
- return cmd;
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Sj.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Sj.java
deleted file mode 100644
index 1612304ce..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javac/Sj.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javac;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.taskdefs.javac.DefaultCompilerAdapter;
-
-/**
- * The implementation of the sj compiler. Uses the defaults for
- * DefaultCompilerAdapter
- *
- * @author Don Ferguson
- */
-public class Sj extends DefaultCompilerAdapter
-{
-
- /**
- * Performs a compile using the sj compiler from Symantec.
- *
- * @return Description of the Returned Value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- * @author don@bea.com
- */
- public boolean execute()
- throws TaskException
- {
- getTaskContext().debug( "Using symantec java compiler" );
-
- Commandline cmd = setupJavacCommand();
- cmd.setExecutable( "sj" );
-
- int firstFileName = cmd.size() - m_compileList.length;
-
- return executeExternalCompile( cmd.getCommandline(), firstFileName ) == 0;
- }
-
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javacc/JJTree.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javacc/JJTree.java
deleted file mode 100644
index a4762b45d..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javacc/JJTree.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javacc;
-
-import java.io.File;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.CommandlineJava;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.types.PathUtil;
-
-/**
- * Taskdef for the JJTree compiler compiler.
- *
- * @author thomas.haas@softwired-inc.com
- * @author Michael Saunders michael@amtec.com
- *
- */
-public class JJTree
- extends AbstractTask
-{
- // keys to optional attributes
- private final static String BUILD_NODE_FILES = "BUILD_NODE_FILES";
- private final static String MULTI = "MULTI";
- private final static String NODE_DEFAULT_VOID = "NODE_DEFAULT_VOID";
- private final static String NODE_FACTORY = "NODE_FACTORY";
- private final static String NODE_SCOPE_HOOK = "NODE_SCOPE_HOOK";
- private final static String NODE_USES_PARSER = "NODE_USES_PARSER";
- private final static String STATIC = "STATIC";
- private final static String VISITOR = "VISITOR";
-
- private final static String NODE_PACKAGE = "NODE_PACKAGE";
- private final static String VISITOR_EXCEPTION = "VISITOR_EXCEPTION";
- private final static String NODE_PREFIX = "NODE_PREFIX";
-
- private final Hashtable optionalAttrs = new Hashtable();
-
- // required attributes
- private File outputDirectory = null;
- private File target = null;
- private File javaccHome = null;
-
- private CommandlineJava cmdl = new CommandlineJava();
-
- public JJTree()
- {
- cmdl.setVm( "java" );
- cmdl.setClassname( "COM.sun.labs.jjtree.Main" );
- }
-
- public void setBuildnodefiles( boolean buildNodeFiles )
- {
- optionalAttrs.put( BUILD_NODE_FILES, new Boolean( buildNodeFiles ) );
- }
-
- public void setJavacchome( File javaccHome )
- {
- this.javaccHome = javaccHome;
- }
-
- public void setMulti( boolean multi )
- {
- optionalAttrs.put( MULTI, new Boolean( multi ) );
- }
-
- public void setNodedefaultvoid( boolean nodeDefaultVoid )
- {
- optionalAttrs.put( NODE_DEFAULT_VOID, new Boolean( nodeDefaultVoid ) );
- }
-
- public void setNodefactory( boolean nodeFactory )
- {
- optionalAttrs.put( NODE_FACTORY, new Boolean( nodeFactory ) );
- }
-
- public void setNodepackage( String nodePackage )
- {
- optionalAttrs.put( NODE_PACKAGE, new String( nodePackage ) );
- }
-
- public void setNodeprefix( String nodePrefix )
- {
- optionalAttrs.put( NODE_PREFIX, new String( nodePrefix ) );
- }
-
- public void setNodescopehook( boolean nodeScopeHook )
- {
- optionalAttrs.put( NODE_SCOPE_HOOK, new Boolean( nodeScopeHook ) );
- }
-
- public void setNodeusesparser( boolean nodeUsesParser )
- {
- optionalAttrs.put( NODE_USES_PARSER, new Boolean( nodeUsesParser ) );
- }
-
- public void setOutputdirectory( File outputDirectory )
- {
- this.outputDirectory = outputDirectory;
- }
-
- public void setStatic( boolean staticParser )
- {
- optionalAttrs.put( STATIC, new Boolean( staticParser ) );
- }
-
- public void setTarget( File target )
- {
- this.target = target;
- }
-
- public void setVisitor( boolean visitor )
- {
- optionalAttrs.put( VISITOR, new Boolean( visitor ) );
- }
-
- public void setVisitorException( String visitorException )
- {
- optionalAttrs.put( VISITOR_EXCEPTION, new String( visitorException ) );
- }
-
- public void execute()
- throws TaskException
- {
-
- // load command line with optional attributes
- Enumeration iter = optionalAttrs.keys();
- while( iter.hasMoreElements() )
- {
- String name = (String)iter.nextElement();
- Object value = optionalAttrs.get( name );
- cmdl.addArgument( "-" + name + ":" + value.toString() );
- }
-
- if( target == null || !target.isFile() )
- {
- throw new TaskException( "Invalid target: " + target );
- }
-
- // use the directory containing the target as the output directory
- if( outputDirectory == null )
- {
- outputDirectory = new File( target.getParent() );
- }
- if( !outputDirectory.isDirectory() )
- {
- throw new TaskException( "'outputdirectory' " + outputDirectory + " is not a directory." );
- }
- // convert backslashes to slashes, otherwise jjtree will put this as
- // comments and this seems to confuse javacc
- cmdl.addArgument( "-OUTPUT_DIRECTORY:" + outputDirectory.getAbsolutePath().replace( '\\', '/' ) );
-
- String targetName = target.getName();
- final File javaFile = new File( outputDirectory,
- targetName.substring( 0, targetName.indexOf( ".jjt" ) ) + ".jj" );
- if( javaFile.exists() && target.lastModified() < javaFile.lastModified() )
- {
- getContext().info( "Target is already built - skipping (" + target + ")" );
- return;
- }
- cmdl.addArgument( target.getAbsolutePath() );
-
- if( javaccHome == null || !javaccHome.isDirectory() )
- {
- throw new TaskException( "Javacchome not set." );
- }
- final Path classpath = cmdl.createClasspath();
- classpath.addLocation( new File( javaccHome, "JavaCC.zip" ) );
- PathUtil.addJavaRuntime( classpath );
-
- cmdl.addVmArgument( "-mx140M" );
- cmdl.addVmArgument( "-Dinstall.root=" + javaccHome.getAbsolutePath() );
-
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
- getContext().debug( cmdl.toString() );
- exe.setCommandline( new Commandline( cmdl.getCommandline() ) );
- exe.setReturnCode( 0 );
- exe.execute();
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javacc/JavaCC.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javacc/JavaCC.java
deleted file mode 100644
index ed946fb39..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javacc/JavaCC.java
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javacc;
-
-import java.io.File;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.CommandlineJava;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.types.PathUtil;
-
-/**
- * Taskdef for the JavaCC compiler compiler.
- *
- * @author thomas.haas@softwired-inc.com
- * @author Michael Saunders michael@amtec.com
- *
- */
-public class JavaCC
- extends AbstractTask
-{
-
- // keys to optional attributes
- private final static String LOOKAHEAD = "LOOKAHEAD";
- private final static String CHOICE_AMBIGUITY_CHECK = "CHOICE_AMBIGUITY_CHECK";
- private final static String OTHER_AMBIGUITY_CHECK = "OTHER_AMBIGUITY_CHECK";
-
- private final static String STATIC = "STATIC";
- private final static String DEBUG_PARSER = "DEBUG_PARSER";
- private final static String DEBUG_LOOKAHEAD = "DEBUG_LOOKAHEAD";
- private final static String DEBUG_TOKEN_MANAGER = "DEBUG_TOKEN_MANAGER";
- private final static String OPTIMIZE_TOKEN_MANAGER = "OPTIMIZE_TOKEN_MANAGER";
- private final static String ERROR_REPORTING = "ERROR_REPORTING";
- private final static String JAVA_UNICODE_ESCAPE = "JAVA_UNICODE_ESCAPE";
- private final static String UNICODE_INPUT = "UNICODE_INPUT";
- private final static String IGNORE_CASE = "IGNORE_CASE";
- private final static String COMMON_TOKEN_ACTION = "COMMON_TOKEN_ACTION";
- private final static String USER_TOKEN_MANAGER = "USER_TOKEN_MANAGER";
- private final static String USER_CHAR_STREAM = "USER_CHAR_STREAM";
- private final static String BUILD_PARSER = "BUILD_PARSER";
- private final static String BUILD_TOKEN_MANAGER = "BUILD_TOKEN_MANAGER";
- private final static String SANITY_CHECK = "SANITY_CHECK";
- private final static String FORCE_LA_CHECK = "FORCE_LA_CHECK";
- private final static String CACHE_TOKENS = "CACHE_TOKENS";
-
- private final Hashtable optionalAttrs = new Hashtable();
-
- // required attributes
- private File outputDirectory = null;
- private File target = null;
- private File javaccHome = null;
-
- private CommandlineJava cmdl = new CommandlineJava();
-
- public JavaCC()
- {
- cmdl.setVm( "java" );
- cmdl.setClassname( "COM.sun.labs.javacc.Main" );
- }
-
- public void setBuildparser( boolean buildParser )
- {
- optionalAttrs.put( BUILD_PARSER, new Boolean( buildParser ) );
- }
-
- public void setBuildtokenmanager( boolean buildTokenManager )
- {
- optionalAttrs.put( BUILD_TOKEN_MANAGER, new Boolean( buildTokenManager ) );
- }
-
- public void setCachetokens( boolean cacheTokens )
- {
- optionalAttrs.put( CACHE_TOKENS, new Boolean( cacheTokens ) );
- }
-
- public void setChoiceambiguitycheck( int choiceAmbiguityCheck )
- {
- optionalAttrs.put( CHOICE_AMBIGUITY_CHECK, new Integer( choiceAmbiguityCheck ) );
- }
-
- public void setCommontokenaction( boolean commonTokenAction )
- {
- optionalAttrs.put( COMMON_TOKEN_ACTION, new Boolean( commonTokenAction ) );
- }
-
- public void setDebuglookahead( boolean debugLookahead )
- {
- optionalAttrs.put( DEBUG_LOOKAHEAD, new Boolean( debugLookahead ) );
- }
-
- public void setDebugparser( boolean debugParser )
- {
- optionalAttrs.put( DEBUG_PARSER, new Boolean( debugParser ) );
- }
-
- public void setDebugtokenmanager( boolean debugTokenManager )
- {
- optionalAttrs.put( DEBUG_TOKEN_MANAGER, new Boolean( debugTokenManager ) );
- }
-
- public void setErrorreporting( boolean errorReporting )
- {
- optionalAttrs.put( ERROR_REPORTING, new Boolean( errorReporting ) );
- }
-
- public void setForcelacheck( boolean forceLACheck )
- {
- optionalAttrs.put( FORCE_LA_CHECK, new Boolean( forceLACheck ) );
- }
-
- public void setIgnorecase( boolean ignoreCase )
- {
- optionalAttrs.put( IGNORE_CASE, new Boolean( ignoreCase ) );
- }
-
- public void setJavacchome( File javaccHome )
- {
- this.javaccHome = javaccHome;
- }
-
- public void setJavaunicodeescape( boolean javaUnicodeEscape )
- {
- optionalAttrs.put( JAVA_UNICODE_ESCAPE, new Boolean( javaUnicodeEscape ) );
- }
-
- public void setLookahead( int lookahead )
- {
- optionalAttrs.put( LOOKAHEAD, new Integer( lookahead ) );
- }
-
- public void setOptimizetokenmanager( boolean optimizeTokenManager )
- {
- optionalAttrs.put( OPTIMIZE_TOKEN_MANAGER, new Boolean( optimizeTokenManager ) );
- }
-
- public void setOtherambiguityCheck( int otherAmbiguityCheck )
- {
- optionalAttrs.put( OTHER_AMBIGUITY_CHECK, new Integer( otherAmbiguityCheck ) );
- }
-
- public void setOutputdirectory( File outputDirectory )
- {
- this.outputDirectory = outputDirectory;
- }
-
- public void setSanitycheck( boolean sanityCheck )
- {
- optionalAttrs.put( SANITY_CHECK, new Boolean( sanityCheck ) );
- }
-
- public void setStatic( boolean staticParser )
- {
- optionalAttrs.put( STATIC, new Boolean( staticParser ) );
- }
-
- public void setTarget( File target )
- {
- this.target = target;
- }
-
- public void setUnicodeinput( boolean unicodeInput )
- {
- optionalAttrs.put( UNICODE_INPUT, new Boolean( unicodeInput ) );
- }
-
- public void setUsercharstream( boolean userCharStream )
- {
- optionalAttrs.put( USER_CHAR_STREAM, new Boolean( userCharStream ) );
- }
-
- public void setUsertokenmanager( boolean userTokenManager )
- {
- optionalAttrs.put( USER_TOKEN_MANAGER, new Boolean( userTokenManager ) );
- }
-
- public void execute()
- throws TaskException
- {
-
- // load command line with optional attributes
- Enumeration iter = optionalAttrs.keys();
- while( iter.hasMoreElements() )
- {
- String name = (String)iter.nextElement();
- Object value = optionalAttrs.get( name );
- cmdl.addArgument( "-" + name + ":" + value.toString() );
- }
-
- // check the target is a file
- if( target == null || !target.isFile() )
- {
- throw new TaskException( "Invalid target: " + target );
- }
-
- // use the directory containing the target as the output directory
- if( outputDirectory == null )
- {
- outputDirectory = new File( target.getParent() );
- }
- else if( !outputDirectory.isDirectory() )
- {
- throw new TaskException( "Outputdir not a directory." );
- }
- cmdl.addArgument( "-OUTPUT_DIRECTORY:" + outputDirectory.getAbsolutePath() );
-
- // determine if the generated java file is up-to-date
- final File javaFile = getOutputJavaFile( outputDirectory, target );
- if( javaFile.exists() && target.lastModified() < javaFile.lastModified() )
- {
- getContext().debug( "Target is already built - skipping (" + target + ")" );
- return;
- }
- cmdl.addArgument( target.getAbsolutePath() );
-
- if( javaccHome == null || !javaccHome.isDirectory() )
- {
- throw new TaskException( "Javacchome not set." );
- }
- final Path classpath = cmdl.createClasspath();
- classpath.addLocation( new File( javaccHome, "JavaCC.zip" ) );
- PathUtil.addJavaRuntime( classpath );
-
- cmdl.addVmArgument( "-mx140M" );
- cmdl.addVmArgument( "-Dinstall.root=" + javaccHome.getAbsolutePath() );
-
- runCommand( cmdl );
- }
-
- private void runCommand( final CommandlineJava cmdline )
- throws TaskException
- {
- getContext().debug( cmdline.toString() );
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
- final String[] commandline = cmdline.getCommandline();
- exe.setCommandline( new Commandline( commandline ) );
- exe.setReturnCode( 0 );
- exe.execute();
- }
-
- /**
- * Determines the output Java file to be generated by the given grammar
- * file.
- *
- * @param outputdir Description of Parameter
- * @param srcfile Description of Parameter
- * @return The OutputJavaFile value
- */
- private File getOutputJavaFile( File outputdir, File srcfile )
- {
- String path = srcfile.getPath();
-
- // Extract file's base-name
- int startBasename = path.lastIndexOf( File.separator );
- if( startBasename != -1 )
- {
- path = path.substring( startBasename + 1 );
- }
-
- // Replace the file's extension with '.java'
- int startExtn = path.lastIndexOf( '.' );
- if( startExtn != -1 )
- {
- path = path.substring( 0, startExtn ) + ".java";
- }
- else
- {
- path += ".java";
- }
-
- // Change the directory
- if( outputdir != null )
- {
- path = outputdir + File.separator + path;
- }
-
- return new File( path );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/AccessType.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/AccessType.java
deleted file mode 100644
index 54c44994c..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/AccessType.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javadoc;
-
-import org.apache.tools.todo.types.EnumeratedAttribute;
-
-public class AccessType
- extends EnumeratedAttribute
-{
- public String[] getValues()
- {
- // Protected first so if any GUI tool offers a default
- // based on enum #0, it will be right.
- return new String[]{"protected", "public", "package", "private"};
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/DocletInfo.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/DocletInfo.java
deleted file mode 100644
index 9f3cbec4c..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/DocletInfo.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javadoc;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.Path;
-
-public class DocletInfo
-{
- private ArrayList m_params = new ArrayList();
- private String m_name;
- private Path m_path;
-
- public void setName( final String name )
- {
- m_name = name;
- }
-
- public void setPath( final Path path )
- throws TaskException
- {
- if( m_path == null )
- {
- m_path = path;
- }
- else
- {
- m_path.append( path );
- }
- }
-
- public String getName()
- {
- return m_name;
- }
-
- public Iterator getParams()
- {
- return m_params.iterator();
- }
-
- public Path getPath()
- {
- return m_path;
- }
-
- public DocletParam createParam()
- {
- final DocletParam param = new DocletParam();
- m_params.add( param );
- return param;
- }
-
- public Path createPath()
- throws TaskException
- {
- if( m_path == null )
- {
- m_path = new Path();
- }
- Path path1 = m_path;
- final Path path = new Path();
- path1.addPath( path );
- return path;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/DocletParam.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/DocletParam.java
deleted file mode 100644
index 955a07ac9..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/DocletParam.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javadoc;
-
-public class DocletParam
-{
- private String m_name;
- private String m_value;
-
- public void setName( final String name )
- {
- this.m_name = name;
- }
-
- public void setValue( final String value )
- {
- this.m_value = value;
- }
-
- public String getName()
- {
- return m_name;
- }
-
- public String getValue()
- {
- return m_value;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/GroupArgument.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/GroupArgument.java
deleted file mode 100644
index d66c6179c..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/GroupArgument.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javadoc;
-
-import java.util.ArrayList;
-import java.util.StringTokenizer;
-
-public class GroupArgument
-{
- private ArrayList m_packages = new ArrayList( 3 );
- private Html m_title;
-
- public void setPackages( final String src )
- {
- final StringTokenizer tok = new StringTokenizer( src, "," );
- while( tok.hasMoreTokens() )
- {
- final String p = tok.nextToken();
- final PackageName pn = new PackageName();
- pn.setName( p );
- addPackage( pn );
- }
- }
-
- public void setTitle( final String src )
- {
- final Html h = new Html();
- h.addContent( src );
- addTitle( h );
- }
-
- public String getPackages()
- {
- final StringBuffer p = new StringBuffer();
- for( int i = 0; i < m_packages.size(); i++ )
- {
- if( i > 0 )
- {
- p.append( ":" );
- }
- p.append( m_packages.get( i ).toString() );
- }
- return p.toString();
- }
-
- public String getTitle()
- {
- return m_title != null ? m_title.getText() : null;
- }
-
- public void addPackage( final PackageName pn )
- {
- m_packages.add( pn );
- }
-
- public void addTitle( final Html text )
- {
- m_title = text;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/Html.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/Html.java
deleted file mode 100644
index c6ac22a4c..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/Html.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javadoc;
-
-public class Html
-{
- private StringBuffer m_text = new StringBuffer();
-
- public String getText()
- {
- return m_text.toString();
- }
-
- public void addContent( final String text )
- {
- m_text.append( text );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java
deleted file mode 100644
index d19846993..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java
+++ /dev/null
@@ -1,1061 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javadoc;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.StringTokenizer;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.aut.nativelib.ExecOutputHandler;
-import org.apache.aut.nativelib.Os;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.myrmidon.framework.Pattern;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.types.ScannerUtil;
-import org.apache.tools.todo.util.FileUtils;
-import org.apache.tools.todo.taskdefs.javadoc.AccessType;
-import org.apache.tools.todo.taskdefs.javadoc.DocletInfo;
-import org.apache.tools.todo.taskdefs.javadoc.DocletParam;
-import org.apache.tools.todo.taskdefs.javadoc.GroupArgument;
-import org.apache.tools.todo.taskdefs.javadoc.Html;
-
-/**
- * This task makes it easy to generate Javadoc documentation for a collection of
- * source code.
- *
- * Current known limitations are:
- *
- *
- *
- * patterns must be of the form "xxx.*", every other pattern doesn't
- * work.
- * the java comment-stripper reader is horribly slow
- * there is no control on arguments sanity since they are left to the
- * javadoc implementation.
- * argument J in javadoc1 is not supported (what is that for anyway?)
- *
- *
- *
- *
- * If no doclet
is set, then the version
and author
- * are by default "yes"
.
- *
- * Note: This task is run on another VM because the Javadoc code calls System.exit()
- * which would break Ant functionality.
- *
- * @author Jon S. Stevens jon@clearink.com
- * @author Stefano Mazzocchi
- * stefano@apache.org
- * @author Patrick Chanezon
- * chanezon@netscape.com
- * @author Ernst de Haan ernst@jollem.com
- * @author Stefan Bodewig
- */
-
-public class Javadoc
- extends AbstractTask
- implements ExecOutputHandler
-{
- private Commandline m_command = new Commandline();
-
- private Path m_sourcePath;
- private File m_destDir;
- private ArrayList m_sourceFiles = new ArrayList();
- private ArrayList m_packageNames = new ArrayList( 5 );
- private ArrayList m_excludePackageNames = new ArrayList( 1 );
- private boolean m_author = true;
- private boolean m_version = true;
- private DocletInfo m_doclet;
- private Path m_classpath;
- private Path m_bootclasspath;
- private String m_group;
- private ArrayList m_compileList = new ArrayList( 10 );
- private String m_packageList;
- private ArrayList m_links = new ArrayList( 2 );
- private ArrayList m_groups = new ArrayList( 2 );
- private boolean m_useDefaultExcludes = true;
- private Html m_doctitle;
- private Html m_header;
- private Html m_footer;
- private Html m_bottom;
- private boolean m_useExternalFile;
- private File m_tmpList;
-
- public void setAccess( AccessType at )
- {
- m_command.addArgument( "-" + at.getValue() );
- }
-
- public void setAdditionalparam( String add )
- throws TaskException
- {
- m_command.addLine( add );
- }
-
- public void setAuthor( boolean src )
- {
- m_author = src;
- }
-
- public void setBootclasspath( Path src )
- throws TaskException
- {
- if( m_bootclasspath == null )
- {
- m_bootclasspath = src;
- }
- else
- {
- m_bootclasspath.append( src );
- }
- }
-
- public void setBottom( String src )
- {
- Html h = new Html();
- h.addContent( src );
- addBottom( h );
- }
-
- public void setCharset( String src )
- {
- this.add12ArgIfNotEmpty( "-charset", src );
- }
-
- public void setClasspath( Path src )
- throws TaskException
- {
- if( m_classpath == null )
- {
- m_classpath = src;
- }
- else
- {
- m_classpath.append( src );
- }
- }
-
- /**
- * Sets whether default exclusions should be used or not.
- *
- * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions
- * should be used, "false"|"off"|"no" when they shouldn't be used.
- */
- public void setDefaultexcludes( boolean useDefaultExcludes )
- {
- this.m_useDefaultExcludes = useDefaultExcludes;
- }
-
- public void setDestdir( File dir )
- {
- m_destDir = dir;
- m_command.addArgument( "-d" );
- m_command.addArgument( m_destDir );
- }
-
- public void setDocencoding( String enc )
- {
- m_command.addArgument( "-docencoding" );
- m_command.addArgument( enc );
- }
-
- public void setDoclet( String src )
- {
- if( m_doclet == null )
- {
- m_doclet = new DocletInfo();
- }
- m_doclet.setName( src );
- }
-
- public void setDocletPath( Path src )
- throws TaskException
- {
- if( m_doclet == null )
- {
- m_doclet = new DocletInfo();
- }
- m_doclet.setPath( src );
- }
-
- public void setDoctitle( String src )
- {
- Html h = new Html();
- h.addContent( src );
- addDoctitle( h );
- }
-
- public void setEncoding( String enc )
- {
- m_command.addArgument( "-encoding" );
- m_command.addArgument( enc );
- }
-
- public void setExcludePackageNames( String src )
- {
- StringTokenizer tok = new StringTokenizer( src, "," );
- while( tok.hasMoreTokens() )
- {
- String p = tok.nextToken();
- PackageName pn = new PackageName();
- pn.setName( p );
- addExcludePackage( pn );
- }
- }
-
- public void setExtdirs( String src )
- {
- m_command.addArgument( "-extdirs" );
- m_command.addArgument( src );
- }
-
- public void setFooter( String src )
- {
- Html h = new Html();
- h.addContent( src );
- addFooter( h );
- }
-
- public void setGroup( String src )
- {
- m_group = src;
- }
-
- public void setHeader( String src )
- {
- Html h = new Html();
- h.addContent( src );
- addHeader( h );
- }
-
- public void setHelpfile( File f )
- {
- m_command.addArgument( "-helpfile" );
- m_command.addArgument( f );
- }
-
- public void setLink( String src )
- {
- createLink().setHref( src );
- }
-
- public void setLinkoffline( String src )
- throws TaskException
- {
- LinkArgument le = createLink();
- le.setOffline( true );
- String linkOfflineError = "The linkoffline attribute must include a URL and " +
- "a package-list file location separated by a space";
- if( src.trim().length() == 0 )
- {
- throw new TaskException( linkOfflineError );
- }
- final StringTokenizer tok = new StringTokenizer( src, " ", false );
- le.setHref( tok.nextToken() );
-
- if( !tok.hasMoreTokens() )
- {
- throw new TaskException( linkOfflineError );
- }
- le.setPackagelistLoc( getContext().resolveFile( tok.nextToken() ) );
- }
-
- public void setLocale( String src )
- {
- m_command.addArgument( "-locale" );
- m_command.addArgument( src );
- }
-
- public void setMaxmemory( final String max )
- {
- m_command.addArgument( "-J-Xmx" + max );
- }
-
- public void setNodeprecated( boolean b )
- {
- addArgIf( b, "-nodeprecated" );
- }
-
- public void setNodeprecatedlist( boolean b )
- {
- addArgIf( b, "-nodeprecatedlist" );
- }
-
- public void setNohelp( boolean b )
- {
- addArgIf( b, "-nohelp" );
- }
-
- public void setNoindex( boolean b )
- {
- addArgIf( b, "-noindex" );
- }
-
- public void setNonavbar( boolean b )
- {
- addArgIf( b, "-nonavbar" );
- }
-
- public void setNotree( boolean b )
- {
- addArgIf( b, "-notree" );
- }
-
- public void setOld( boolean b )
- {
- addArgIf( b, "-1.1" );
- }
-
- public void setOverview( File f )
- {
- m_command.addArgument( "-overview" );
- m_command.addArgument( f );
- }
-
- public void setPackage( boolean b )
- {
- addArgIf( b, "-package" );
- }
-
- public void setPackageList( String src )
- {
- m_packageList = src;
- }
-
- public void setPackagenames( String src )
- {
- StringTokenizer tok = new StringTokenizer( src, "," );
- while( tok.hasMoreTokens() )
- {
- String p = tok.nextToken();
- PackageName pn = new PackageName();
- pn.setName( p );
- addPackage( pn );
- }
- }
-
- public void setPrivate( boolean b )
- {
- addArgIf( b, "-private" );
- }
-
- public void setProtected( boolean b )
- {
- addArgIf( b, "-protected" );
- }
-
- public void setPublic( boolean b )
- {
- addArgIf( b, "-public" );
- }
-
- public void setSerialwarn( boolean b )
- {
- addArgIf( b, "-serialwarn" );
- }
-
- public void setSourcefiles( String src )
- throws TaskException
- {
- StringTokenizer tok = new StringTokenizer( src, "," );
- while( tok.hasMoreTokens() )
- {
- final String f = tok.nextToken();
- SourceFile sf = new SourceFile();
- sf.setFile( getContext().resolveFile( f ) );
- addSource( sf );
- }
- }
-
- public void setSourcepath( Path src )
- throws TaskException
- {
- if( m_sourcePath == null )
- {
- m_sourcePath = src;
- }
- else
- {
- m_sourcePath.append( src );
- }
- }
-
- public void setSplitindex( boolean b )
- {
- addArgIf( b, "-splitindex" );
- }
-
- public void setStylesheetfile( File f )
- {
- m_command.addArgument( "-stylesheetfile" );
- m_command.addArgument( f );
- }
-
- public void setUse( boolean b )
- {
- addArgIf( b, "-use" );
- }
-
- /**
- * Work around command line length limit by using an external file for the
- * sourcefiles.
- *
- * @param b The new UseExternalFile value
- */
- public void setUseExternalFile( boolean b )
- {
- m_useExternalFile = b;
- }
-
- public void setVerbose( boolean b )
- {
- addArgIf( b, "-verbose" );
- }
-
- public void setVersion( boolean src )
- {
- m_version = src;
- }
-
- public void setWindowtitle( String src )
- {
- add12ArgIfNotEmpty( "-windowtitle", src );
- }
-
- public void addBottom( Html text )
- {
- m_bottom = text;
- }
-
- public void addDoctitle( Html text )
- {
- m_doctitle = text;
- }
-
- public void addExcludePackage( PackageName pn )
- {
- m_excludePackageNames.add( pn );
- }
-
- public void addFooter( Html text )
- {
- m_footer = text;
- }
-
- public void addHeader( Html text )
- {
- m_header = text;
- }
-
- public void addPackage( PackageName pn )
- {
- m_packageNames.add( pn );
- }
-
- public void addSource( SourceFile sf )
- throws TaskException
- {
- m_sourceFiles.add( sf );
- }
-
- public Path createBootclasspath()
- throws TaskException
- {
- if( m_bootclasspath == null )
- {
- m_bootclasspath = new Path();
- }
- Path path1 = m_bootclasspath;
- final Path path = new Path();
- path1.addPath( path );
- return path;
- }
-
- public Path createClasspath()
- throws TaskException
- {
- if( m_classpath == null )
- {
- m_classpath = new Path();
- }
- Path path1 = m_classpath;
- final Path path = new Path();
- path1.addPath( path );
- return path;
- }
-
- public DocletInfo createDoclet()
- {
- m_doclet = new DocletInfo();
- return m_doclet;
- }
-
- public GroupArgument createGroup()
- {
- GroupArgument ga = new GroupArgument();
- m_groups.add( ga );
- return ga;
- }
-
- public LinkArgument createLink()
- {
- LinkArgument la = new LinkArgument();
- m_links.add( la );
- return la;
- }
-
- public Path createSourcepath()
- throws TaskException
- {
- if( m_sourcePath == null )
- {
- m_sourcePath = new Path();
- }
- Path path1 = m_sourcePath;
- final Path path = new Path();
- path1.addPath( path );
- return path;
- }
-
- public void execute()
- throws TaskException
- {
- if( m_sourcePath == null )
- {
- String msg = "sourcePath attribute must be set!";
- throw new TaskException( msg );
- }
-
- getContext().info( "Generating Javadoc" );
-
- if( m_doctitle != null )
- {
- m_command.addArgument( "-doctitle" );
- m_command.addArgument( m_doctitle.getText() );
- }
- if( m_header != null )
- {
- m_command.addArgument( "-header" );
- m_command.addArgument( m_header.getText() );
- }
- if( m_footer != null )
- {
- m_command.addArgument( "-footer" );
- m_command.addArgument( m_footer.getText() );
- }
- if( m_bottom != null )
- {
- m_command.addArgument( "-bottom" );
- m_command.addArgument( m_bottom.getText() );
- }
-
- Commandline cmd = new Commandline();//(Commandline)m_command.clone();
- cmd.setExecutable( getJavadocExecutableName() );
-
- // ------------------------------------------------ general javadoc arguments
-
- // Build the classpath to pass to Javadoc
- Path classpath = new Path();
- classpath.addPath( m_sourcePath );
- if( m_classpath != null )
- {
- classpath.addPath( m_classpath );
- }
- cmd.addArgument( "-classpath" );
- cmd.addArgument( classpath.toString() );
-
- if( m_version && m_doclet == null )
- {
- cmd.addArgument( "-version" );
- }
- if( m_author && m_doclet == null )
- {
- cmd.addArgument( "-author" );
- }
-
- if( m_doclet == null )
- {
- if( m_destDir == null )
- {
- String msg = "destDir attribute must be set!";
- throw new TaskException( msg );
- }
- }
-
- // --------------------------------- javadoc2 arguments for default doclet
-
- // XXX: how do we handle a custom doclet?
-
- if( m_doclet != null )
- {
- if( m_doclet.getName() == null )
- {
- throw new TaskException( "The doclet name must be specified." );
- }
- else
- {
- cmd.addArgument( "-doclet" );
- cmd.addArgument( m_doclet.getName() );
- if( m_doclet.getPath() != null )
- {
- cmd.addArgument( "-docletpath" );
- cmd.addArguments( FileUtils.translateCommandline( m_doclet.getPath() ) );
- }
- for( Iterator e = m_doclet.getParams(); e.hasNext(); )
- {
- DocletParam param = (DocletParam)e.next();
- if( param.getName() == null )
- {
- throw new TaskException( "Doclet parameters must have a name" );
- }
-
- cmd.addArgument( param.getName() );
- if( param.getValue() != null )
- {
- cmd.addArgument( param.getValue() );
- }
- }
- }
-
- if( m_bootclasspath != null )
- {
- cmd.addArgument( "-bootclasspath" );
- cmd.addArguments( FileUtils.translateCommandline( m_bootclasspath ) );
- }
-
- // add the links arguments
- if( m_links.size() != 0 )
- {
- for( Iterator e = m_links.iterator(); e.hasNext(); )
- {
- LinkArgument la = (LinkArgument)e.next();
-
- if( la.getHref() == null )
- {
- throw new TaskException( "Links must provide the URL to the external class documentation." );
- }
-
- if( la.isLinkOffline() )
- {
- File packageListLocation = la.getPackagelistLoc();
- if( packageListLocation == null )
- {
- throw new TaskException( "The package list location for link " + la.getHref() +
- " must be provided because the link is offline" );
- }
- File packageList = new File( packageListLocation, "package-list" );
- if( packageList.exists() )
- {
- cmd.addArgument( "-linkoffline" );
- cmd.addArgument( la.getHref() );
- cmd.addArgument( packageListLocation.getAbsolutePath() );
- }
- else
- {
- getContext().debug( "Warning: No package list was found at " + packageListLocation );
- }
- }
- else
- {
- cmd.addArgument( "-link" );
- cmd.addArgument( la.getHref() );
- }
- }
- }
-
- // add the single group arguments
- // Javadoc 1.2 rules:
- // Multiple -group args allowed.
- // Each arg includes 3 strings: -group [name] [packagelist].
- // Elements in [packagelist] are colon-delimited.
- // An element in [packagelist] may end with the * wildcard.
-
- // Ant javadoc task rules for group attribute:
- // Args are comma-delimited.
- // Each arg is 2 space-delimited strings.
- // E.g., group="XSLT_Packages org.apache.xalan.xslt*,XPath_Packages org.apache.xalan.xpath*"
- if( m_group != null )
- {
- StringTokenizer tok = new StringTokenizer( m_group, ",", false );
- while( tok.hasMoreTokens() )
- {
- String grp = tok.nextToken().trim();
- int space = grp.indexOf( " " );
- if( space > 0 )
- {
- String name = grp.substring( 0, space );
- String pkgList = grp.substring( space + 1 );
- cmd.addArgument( "-group" );
- cmd.addArgument( name );
- cmd.addArgument( pkgList );
- }
- }
- }
-
- // add the group arguments
- if( m_groups.size() != 0 )
- {
- for( Iterator e = m_groups.iterator(); e.hasNext(); )
- {
- GroupArgument ga = (GroupArgument)e.next();
- String title = ga.getTitle();
- String packages = ga.getPackages();
- if( title == null || packages == null )
- {
- throw new TaskException( "The title and packages must be specified for group elements." );
- }
- cmd.addArgument( "-group" );
- cmd.addArgument( title );
- cmd.addArgument( packages );
- }
- }
-
- }
-
- m_tmpList = null;
- if( m_packageNames.size() > 0 )
- {
- ArrayList packages = new ArrayList();
- Iterator enum = m_packageNames.iterator();
- while( enum.hasNext() )
- {
- PackageName pn = (PackageName)enum.next();
- String name = pn.getName().trim();
- if( name.endsWith( ".*" ) )
- {
- packages.add( name );
- }
- else
- {
- cmd.addArgument( name );
- }
- }
-
- ArrayList excludePackages = new ArrayList();
- if( m_excludePackageNames.size() > 0 )
- {
- enum = m_excludePackageNames.iterator();
- while( enum.hasNext() )
- {
- PackageName pn = (PackageName)enum.next();
- excludePackages.add( pn.getName().trim() );
- }
- }
- if( packages.size() > 0 )
- {
- evaluatePackages( cmd, m_sourcePath, packages, excludePackages );
- }
- }
-
- if( m_sourceFiles.size() > 0 )
- {
- PrintWriter srcListWriter = null;
- try
- {
-
- /**
- * Write sourcefiles to a temporary file if requested.
- */
- if( m_useExternalFile )
- {
- if( m_tmpList == null )
- {
- m_tmpList = File.createTempFile( "javadoc", "", getBaseDirectory() );
- cmd.addArgument( "@" + m_tmpList.getAbsolutePath() );
- }
- srcListWriter = new PrintWriter( new FileWriter( m_tmpList.getAbsolutePath(),
- true ) );
- }
-
- Iterator enum = m_sourceFiles.iterator();
- while( enum.hasNext() )
- {
- SourceFile sf = (SourceFile)enum.next();
- String sourceFileName = sf.getFile().getAbsolutePath();
- if( m_useExternalFile )
- {
- srcListWriter.println( sourceFileName );
- }
- else
- {
- cmd.addArgument( sourceFileName );
- }
- }
-
- }
- catch( IOException e )
- {
- throw new TaskException( "Error creating temporary file", e );
- }
- finally
- {
- if( srcListWriter != null )
- {
- srcListWriter.close();
- }
- }
- }
-
- if( m_packageList != null )
- {
- cmd.addArgument( "@" + m_packageList );
- }
- getContext().debug( "Javadoc args: " + cmd );
-
- getContext().info( "Javadoc execution" );
-
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
- exe.setExecOutputHandler( this );
-
- /*
- * No reason to change the working directory as all filenames and
- * path components have been resolved already.
- *
- * Avoid problems with command line length in some environments.
- */
- exe.setWorkingDirectory( null );
- exe.setCommandline( cmd );
- exe.setReturnCode( 0 );
- try
- {
- exe.execute();
- }
- finally
- {
- if( m_tmpList != null )
- {
- m_tmpList.delete();
- m_tmpList = null;
- }
- }
- }
-
- private String getJavadocExecutableName()
- {
- // This is the most common extension case - exe for windows and OS/2,
- // nothing for *nix.
- String extension = Os.isFamily( Os.OS_FAMILY_DOS ) ? ".exe" : "";
-
- // Look for javadoc in the java.home/../bin directory. Unfortunately
- // on Windows java.home doesn't always refer to the correct location,
- // so we need to fall back to assuming javadoc is somewhere on the
- // PATH.
- File jdocExecutable = new File( System.getProperty( "java.home" ) +
- "/../bin/javadoc" + extension );
-
- if( jdocExecutable.exists() && !Os.isFamily( Os.OS_FAMILY_NETWARE ) )
- {
- return jdocExecutable.getAbsolutePath();
- }
- else
- {
- return "javadoc";
- }
- }
-
- private void add12ArgIfNotEmpty( String key, String value )
- {
- if( value != null && value.length() != 0 )
- {
- m_command.addArgument( key );
- m_command.addArgument( value );
- }
- else
- {
- getContext().warn( "Warning: Leaving out empty argument '" + key + "'" );
- }
- }
-
- private void addArgIf( boolean b, String arg )
- {
- if( b )
- {
- m_command.addArgument( arg );
- }
- }
-
- /**
- * Given a source path, a list of package patterns, fill the given list with
- * the packages found in that path subdirs matching one of the given
- * patterns.
- *
- * @param toExecute Description of Parameter
- * @param sourcePath Description of Parameter
- * @param packages Description of Parameter
- * @param excludePackages Description of Parameter
- */
- private void evaluatePackages( Commandline toExecute, Path sourcePath,
- ArrayList packages, ArrayList excludePackages )
- throws TaskException
- {
- getContext().debug( "Source path = " + sourcePath.toString() );
- StringBuffer msg = new StringBuffer( "Packages = " );
- for( int i = 0; i < packages.size(); i++ )
- {
- if( i > 0 )
- {
- msg.append( "," );
- }
- msg.append( packages.get( i ) );
- }
- getContext().debug( msg.toString() );
-
- msg.setLength( 0 );
- msg.append( "Exclude Packages = " );
- for( int i = 0; i < excludePackages.size(); i++ )
- {
- if( i > 0 )
- {
- msg.append( "," );
- }
- msg.append( excludePackages.get( i ) );
- }
- getContext().debug( msg.toString() );
-
- ArrayList addedPackages = new ArrayList();
-
- String[] list = sourcePath.list();
- if( list == null )
- {
- list = new String[ 0 ];
- }
-
- FileSet fs = new FileSet();
- fs.setDefaultExcludes( m_useDefaultExcludes );
-
- Iterator e = packages.iterator();
- while( e.hasNext() )
- {
- String pkg = (String)e.next();
- pkg = pkg.replace( '.', '/' );
- if( pkg.endsWith( "*" ) )
- {
- pkg += "*";
- }
-
- fs.addInclude( new Pattern( pkg ) );
- }// while
-
- e = excludePackages.iterator();
- while( e.hasNext() )
- {
- String pkg = (String)e.next();
- pkg = pkg.replace( '.', '/' );
- if( pkg.endsWith( "*" ) )
- {
- pkg += "*";
- }
-
- final Pattern pattern = new Pattern( pkg );
- fs.addExclude( pattern );
- }
-
- PrintWriter packageListWriter = null;
- try
- {
- if( m_useExternalFile )
- {
- m_tmpList = File.createTempFile( "javadoc", "", getBaseDirectory() );
- toExecute.addArgument( "@" + m_tmpList.getAbsolutePath() );
- packageListWriter = new PrintWriter( new FileWriter( m_tmpList ) );
- }
-
- for( int j = 0; j < list.length; j++ )
- {
- final String filename = list[ j ];
- final File source = getContext().resolveFile( filename );
- fs.setDir( source );
-
- final DirectoryScanner ds = ScannerUtil.getDirectoryScanner( fs );
- final String[] packageDirs = ds.getIncludedDirectories();
-
- for( int i = 0; i < packageDirs.length; i++ )
- {
- File pd = new File( source, packageDirs[ i ] );
- String[] files = pd.list(
- new FilenameFilter()
- {
- public boolean accept( File dir1, String name )
- {
- if( name.endsWith( ".java" ) )
- {
- return true;
- }
- return false;// ignore dirs
- }
- } );
-
- if( files.length > 0 )
- {
- String pkgDir = packageDirs[ i ].replace( '/', '.' ).replace( '\\', '.' );
- if( !addedPackages.contains( pkgDir ) )
- {
- if( m_useExternalFile )
- {
- packageListWriter.println( pkgDir );
- }
- else
- {
- toExecute.addArgument( pkgDir );
- }
- addedPackages.add( pkgDir );
- }
- }
- }
- }
- }
- catch( IOException ioex )
- {
- throw new TaskException( "Error creating temporary file", ioex );
- }
- finally
- {
- if( packageListWriter != null )
- {
- packageListWriter.close();
- }
- }
- }
-
- /**
- * Receive notification about the process writing
- * to standard output.
- */
- public void stdout( final String line )
- {
- if( line.startsWith( "Generating " ) || line.startsWith( "Building " ) )
- {
- getContext().debug( line );
- }
- else
- {
- getContext().info( line );
- }
- }
-
- /**
- * Receive notification about the process writing
- * to standard error.
- */
- public void stderr( final String line )
- {
- getContext().warn( line );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/LinkArgument.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/LinkArgument.java
deleted file mode 100644
index cb7969199..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/LinkArgument.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javadoc;
-
-import java.io.File;
-
-public class LinkArgument
-{
- private boolean m_offline;
- private String m_href;
- private File m_packagelistLoc;
-
- public void setHref( String hr )
- {
- m_href = hr;
- }
-
- public void setOffline( boolean offline )
- {
- this.m_offline = offline;
- }
-
- public void setPackagelistLoc( File src )
- {
- m_packagelistLoc = src;
- }
-
- public String getHref()
- {
- return m_href;
- }
-
- public File getPackagelistLoc()
- {
- return m_packagelistLoc;
- }
-
- public boolean isLinkOffline()
- {
- return m_offline;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/PackageName.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/PackageName.java
deleted file mode 100644
index 672615e5d..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/PackageName.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javadoc;
-
-public class PackageName
-{
- private String m_name;
-
- public void setName( final String name )
- {
- m_name = name;
- }
-
- public String getName()
- {
- return m_name;
- }
-
- public String toString()
- {
- return getName();
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/SourceFile.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/SourceFile.java
deleted file mode 100644
index 45c1bc319..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/javadoc/SourceFile.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.javadoc;
-
-import java.io.File;
-
-public class SourceFile
-{
- private File m_file;
-
- public void setFile( File file )
- {
- this.m_file = file;
- }
-
- public File getFile()
- {
- return m_file;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jdepend/FormatAttribute.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jdepend/FormatAttribute.java
deleted file mode 100644
index 25b78ecbe..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jdepend/FormatAttribute.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.jdepend;
-
-import org.apache.tools.todo.types.EnumeratedAttribute;
-
-public class FormatAttribute
- extends EnumeratedAttribute
-{
- private String[] m_formats = new String[]{"xml", "text"};
-
- public String[] getValues()
- {
- return m_formats;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jdepend/JDependTask.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jdepend/JDependTask.java
deleted file mode 100644
index a73955b3a..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jdepend/JDependTask.java
+++ /dev/null
@@ -1,332 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.jdepend;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.CommandlineJava;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.util.FileUtils;
-
-/**
- * Ant task to run JDepend tests.
- *
- * JDepend is a tool to generate design quality metrics for each Java package.
- * It has been initially created by Mike Clark. JDepend can be found at
- * http://www.clarkware.com/software/JDepend.html . The current
- * implementation spawn a new Java VM.
- *
- * @author Jerome Lacoste
- * @author Rob Oxspring
- */
-public class JDependTask
- extends AbstractTask
-{
- /**
- * No problems with this test.
- */
- private final static int SUCCESS = 0;
-
- /**
- * An error occured.
- */
- private final static int ERRORS = 1;
-
- private boolean m_fork;
- private String m_jvm;
- private String m_format = "text";
- private Path m_compileClasspath;
- private File m_dir;
- private File m_outputFile;
- private Path m_sourcesPath;
-
- /**
- * Set the classpath to be used for this compilation.
- */
- public void setClasspath( final Path classpath )
- throws TaskException
- {
- if( m_compileClasspath == null )
- {
- m_compileClasspath = classpath;
- }
- else
- {
- m_compileClasspath.append( classpath );
- }
- }
-
- /**
- * The directory to invoke the VM in. Ignored if no JVM is forked.
- *
- * @param dir the directory to invoke the JVM from.
- * @see #setFork(boolean)
- */
- public void setDir( final File dir )
- {
- m_dir = dir;
- }
-
- /**
- * Tells whether a JVM should be forked for the task. Default: false.
- *
- * @param value true if a JVM should be forked, otherwise false
- *
- */
- public void setFork( final boolean fork )
- {
- m_fork = fork;
- }
-
- public void setFormat( final FormatAttribute format )
- {
- m_format = format.getValue();
- }
-
- /**
- * Set a new VM to execute the task. Default is java . Ignored if
- * no JVM is forked.
- *
- * @param value the new VM to use instead of java
- * @see #setFork(boolean)
- */
- public void setJvm( final String jvm )
- {
- m_jvm = jvm;
- }
-
- /*
- * public void setTimeout(Integer value) {
- * _timeout = value;
- * }
- * public Integer getTimeout() {
- * return _timeout;
- * }
- */
- public void setOutputFile( final File outputFile )
- {
- m_outputFile = outputFile;
- }
-
- /**
- * Maybe creates a nested classpath element.
- *
- * @return Description of the Returned Value
- */
- public Path createClasspath()
- {
- if( m_compileClasspath == null )
- {
- m_compileClasspath = new Path();
- }
- Path path1 = m_compileClasspath;
- final Path path = new Path();
- path1.addPath( path );
- return path;
- }
-
- /**
- * Maybe creates a nested classpath element.
- */
- public Path createSourcespath()
- {
- if( m_sourcesPath == null )
- {
- m_sourcesPath = new Path();
- }
- Path path1 = m_sourcesPath;
- final Path path = new Path();
- path1.addPath( path );
- return path;
- }
-
- public void execute()
- throws TaskException
- {
- final CommandlineJava commandline = new CommandlineJava();
-
- if( "text".equals( m_format ) )
- {
- commandline.setClassname( "jdepend.textui.JDepend" );
- }
- else if( "xml".equals( m_format ) )
- {
- commandline.setClassname( "jdepend.xmlui.JDepend" );
- }
-
- if( m_jvm != null )
- {
- commandline.setVm( m_jvm );
- }
-
- if( m_sourcesPath == null )
- {
- throw new TaskException( "Missing Sourcepath required argument" );
- }
-
- // execute the test and get the return code
- int exitValue = JDependTask.ERRORS;
- if( !m_fork )
- {
- exitValue = executeInVM( commandline );
- }
- else
- {
- exitValue = executeAsForked( commandline );
- }
-
- // if there is an error/failure and that it should halt, stop everything otherwise
- // just log a statement
- final boolean errorOccurred = exitValue == JDependTask.ERRORS;
- if( errorOccurred )
- {
- throw new TaskException( "JDepend failed" );
- }
- }
-
-
- /**
- * Execute the task by forking a new JVM. The command will block until it
- * finishes. To know if the process was destroyed or not, use the
- * killedProcess() method of the watchdog class.
- */
- // JL: comment extracted from JUnitTask (and slightly modified)
- private int executeAsForked( final CommandlineJava commandline )
- throws TaskException
- {
- // if not set, auto-create the ClassPath from the project
- createClasspath();
-
- // not sure whether this test is needed but cost nothing to put.
- // hope it will be reviewed by anybody competent
- if( m_compileClasspath.toString().length() > 0 )
- {
- commandline.addVmArgument( "-classpath" );
- commandline.addVmArgument( m_compileClasspath.toString() );
- }
-
- if( m_outputFile != null )
- {
- // having a space between the file and its path causes commandline to add quotes "
- // around the argument thus making JDepend not taking it into account. Thus we split it in two
- commandline.addArgument( "-file" );
- commandline.addArgument( m_outputFile.getPath() );
- // we have to find a cleaner way to put this output
- }
-
- final String[] elements = FileUtils.parsePath( m_sourcesPath.toString() );
- for( int i = 0; i < elements.length; i++ )
- {
- File f = new File( elements[ i ] );
-
- // not necessary as JDepend would fail, but why loose some time?
- if( !f.exists() || !f.isDirectory() )
- {
- throw new TaskException( "\"" + f.getPath() + "\" does not represent a valid directory. JDepend would fail." );
- }
- commandline.addArgument( f.getPath() );
- }
-
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
-
- final String[] commandline1 = commandline.getCommandline();
- exe.setCommandline( new Commandline( commandline1 ) );
- if( m_dir != null )
- {
- exe.setWorkingDirectory( m_dir );
- }
-
- if( m_outputFile != null )
- {
- getContext().info( "Output to be stored in " + m_outputFile.getPath() );
- }
- getContext().debug( "Executing: " + commandline.toString() );
- return exe.execute();
- }
-
-
- // this comment extract from JUnit Task may also apply here
- // "in VM is not very nice since it could probably hang the
- // whole build. IMHO this method should be avoided and it would be best
- // to remove it in future versions. TBD. (SBa)"
-
- /**
- * Execute inside VM.
- *
- * @param commandline Description of Parameter
- * @return Description of the Returned Value
- * @exception TaskException Description of Exception
- */
- public int executeInVM( final CommandlineJava commandline )
- throws TaskException
- {
- jdepend.textui.JDepend jdepend;
-
- if( "xml".equals( m_format ) )
- {
- jdepend = new jdepend.xmlui.JDepend();
- }
- else
- {
- jdepend = new jdepend.textui.JDepend();
- }
-
- if( m_outputFile != null )
- {
- FileWriter fw;
- try
- {
- fw = new FileWriter( m_outputFile.getPath() );
- }
- catch( IOException e )
- {
- String msg = "JDepend Failed when creating the output file: " + e.getMessage();
- getContext().info( msg );
- throw new TaskException( msg );
- }
- jdepend.setWriter( new PrintWriter( fw ) );
- getContext().info( "Output to be stored in " + m_outputFile.getPath() );
- }
-
- final String[] elements = FileUtils.parsePath( m_sourcesPath.toString() );
- for( int i = 0; i < elements.length; i++ )
- {
- File f = new File( elements[ i ] );
-
- // not necessary as JDepend would fail, but why loose some time?
- if( !f.exists() || !f.isDirectory() )
- {
- String msg = "\"" + f.getPath() + "\" does not represent a valid directory. JDepend would fail.";
- getContext().info( msg );
- throw new TaskException( msg );
- }
- try
- {
- jdepend.addDirectory( f.getPath() );
- }
- catch( IOException e )
- {
- String msg = "JDepend Failed when adding a source directory: " + e.getMessage();
- getContext().info( msg );
- throw new TaskException( msg );
- }
- }
- jdepend.analyze();
- return SUCCESS;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/JspC.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/JspC.java
deleted file mode 100644
index be67dbb7e..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/JspC.java
+++ /dev/null
@@ -1,486 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.jsp;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Date;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.taskdefs.MatchingTask;
-import org.apache.tools.todo.taskdefs.jsp.compilers.CompilerAdapter;
-import org.apache.tools.todo.taskdefs.jsp.compilers.CompilerAdapterFactory;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.Path;
-
-/**
- * Ant task to run the jsp compiler.
- *
- * This task takes the given jsp files and compiles them into java files. It is
- * then up to the user to compile the java files into classes.
- *
- * The task requires the srcdir and destdir attributes to be set. This Task is a
- * MatchingTask, so the files to be compiled can be specified using
- * includes/excludes attributes or nested include/exclude elements. Optional
- * attributes are verbose (set the verbosity level passed to jasper), package
- * (name of the destination package for generated java classes and classpath
- * (the classpath to use when running the jsp compiler).
- *
- * This task supports the nested elements classpath (A Path) and classpathref (A
- * Reference) which can be used in preference to the attribute classpath, if the
- * jsp compiler is not already in the ant classpath.
- *
- *
Notes
- *
- * At present, this task only supports the jasper compiler. In future, other
- * compilers will be supported by setting the jsp.compiler property.
- *
- *
Usage
- * <jspc srcdir="${basedir}/src/war"
- * destdir="${basedir}/gensrc"
- * package="com.i3sp.jsp"
- * verbose="9">
- * <include name="**\/*.jsp" />
- * </jspc>
- *
- *
- * @author Matthew Watson
- *
- * Large Amount of cutting and pasting from the Javac task...
- * @author James Davidson duncan@x180.com
- * @author Robin Green greenrd@hotmail.com
- *
- * @author Stefan Bodewig
- * @author J D Glanville
- * @version $Revision$ $Date$
- */
-public class JspC extends MatchingTask
-{
-
- private final static String FAIL_MSG
- = "Compile failed, messages should have been provided.";
- private int verbose = 0;
- protected ArrayList compileList = new ArrayList();
- protected boolean failOnError = true;
- /*
- * ------------------------------------------------------------
- */
- private Path classpath;
- private File destDir;
- private String iepluginid;
- private boolean mapped;
- private String packageName;
- private Path src;
-
- /**
- * -uribase
The uri directory compilations should be relative to
- * (Default is "/")
- */
-
- private File uribase;
-
- /**
- * -uriroot The root directory that uri files should be resolved
- * against,
- */
- private File uriroot;
-
-
- /*
- * ------------------------------------------------------------
- */
- /**
- * Set the classpath to be used for this compilation
- *
- * @param cp The new Classpath value
- */
- public void setClasspath( Path cp )
- throws TaskException
- {
- if( classpath == null )
- {
- classpath = cp;
- }
- else
- {
- classpath.append( cp );
- }
- }
-
- /**
- * Set the destination directory into which the JSP source files should be
- * compiled.
- *
- * @param destDir The new Destdir value
- */
- public void setDestdir( File destDir )
- {
- this.destDir = destDir;
- }
-
- /*
- * ------------------------------------------------------------
- */
- /**
- * Throw a TaskException if compilation fails
- *
- * @param fail The new Failonerror value
- */
- public void setFailonerror( boolean fail )
- {
- failOnError = fail;
- }
-
- /**
- * Set the ieplugin id
- *
- * @param iepluginid_ The new Ieplugin value
- */
- public void setIeplugin( String iepluginid_ )
- {
- iepluginid = iepluginid_;
- }
-
- /**
- * set the mapped flag
- *
- * @param mapped_ The new Mapped value
- */
- public void setMapped( boolean mapped_ )
- {
- mapped = mapped_;
- }
-
- /*
- * ------------------------------------------------------------
- */
- /**
- * Set the name of the package the compiled jsp files should be in
- *
- * @param pkg The new Package value
- */
- public void setPackage( String pkg )
- {
- this.packageName = pkg;
- }
-
- /*
- * ------------------------------------------------------------
- */
- /**
- * Set the source dirs to find the source JSP files.
- *
- * @param srcDir The new Srcdir value
- */
- public void setSrcdir( Path srcDir )
- throws TaskException
- {
- if( src == null )
- {
- src = srcDir;
- }
- else
- {
- src.append( srcDir );
- }
- }
-
- /**
- * -uribase. the uri context of relative URI references in the JSP pages. If
- * it does not exist then it is derived from the location of the file
- * relative to the declared or derived value of -uriroot.
- *
- * @param uribase The new Uribase value
- */
- public void setUribase( File uribase )
- {
- this.uribase = uribase;
- }
-
- /**
- * -uriroot The root directory that uri files should be resolved
- * against, (Default is the directory jspc is invoked from)
- *
- * @param uriroot The new Uribase value
- */
- public void setUriroot( File uriroot )
- {
- this.uriroot = uriroot;
- }
-
- /*
- * ------------------------------------------------------------
- */
- /**
- * Set the verbose level of the compiler
- *
- * @param i The new Verbose value
- */
- public void setVerbose( int i )
- {
- verbose = i;
- }
-
- public Path getClasspath()
- {
- return classpath;
- }
-
- /*
- * ------------------------------------------------------------
- */
- public ArrayList getCompileList()
- {
- return compileList;
- }
-
- public File getDestdir()
- {
- return destDir;
- }
-
- /**
- * Gets the failonerror flag.
- *
- * @return The Failonerror value
- */
- public boolean getFailonerror()
- {
- return failOnError;
- }
-
- /*
- * ------------------------------------------------------------
- */
- public String getIeplugin()
- {
- return iepluginid;
- }
-
- public String getPackage()
- {
- return packageName;
- }
-
- public Path getSrcDir()
- {
- return src;
- }
-
- public File getUribase()
- {
- return uriroot;
- }
-
- public File getUriroot()
- {
- return uriroot;
- }
-
- public int getVerbose()
- {
- return verbose;
- }
-
- /*
- * ------------------------------------------------------------
- */
- public boolean isMapped()
- {
- return mapped;
- }
-
- /**
- * Maybe creates a nested classpath element.
- *
- * @return Description of the Returned Value
- */
- public Path createClasspath()
- throws TaskException
- {
- if( classpath == null )
- {
- classpath = new Path();
- }
- Path path1 = classpath;
- final Path path = new Path();
- path1.addPath( path );
- return path;
- }
-
- /*
- * ------------------------------------------------------------
- */
- public void execute()
- throws TaskException
- {
- // first off, make sure that we've got a srcdir
- if( src == null )
- {
- throw new TaskException( "srcdir attribute must be set!" );
- }
- String[] list = src.list();
- if( list.length == 0 )
- {
- throw new TaskException( "srcdir attribute must be set!" );
- }
-
- if( destDir != null && !destDir.isDirectory() )
- {
- throw new
- TaskException( "destination directory \"" + destDir +
- "\" does not exist or is not a directory" );
- }
-
- // calculate where the files will end up:
- File dest = null;
- if( packageName == null )
- {
- dest = destDir;
- }
- else
- {
- String path = destDir.getPath() + File.separatorChar +
- packageName.replace( '.', File.separatorChar );
- dest = new File( path );
- }
-
- // scan source directories and dest directory to build up both copy
- // lists and compile lists
- resetFileLists();
- int filecount = 0;
- for( int i = 0; i < list.length; i++ )
- {
- final String filename = list[ i ];
- File srcDir = (File)getContext().resolveFile( filename );
- if( !srcDir.exists() )
- {
- throw new TaskException( "srcdir \"" + srcDir.getPath() +
- "\" does not exist!" );
- }
-
- DirectoryScanner ds = this.getDirectoryScanner( srcDir );
-
- String[] files = ds.getIncludedFiles();
- filecount = files.length;
- scanDir( srcDir, dest, files );
- }
-
- // compile the source files
-
- Object compiler = getContext().getProperty( "jsp.compiler" );
- if( compiler == null )
- {
- compiler = "jasper";
- }
- getContext().debug( "compiling " + compileList.size() + " files" );
-
- if( compileList.size() > 0 )
- {
- CompilerAdapter adapter =
- CompilerAdapterFactory.getCompiler( compiler.toString(), getContext() );
- getContext().info( "Compiling " + compileList.size() +
- " source file"
- + ( compileList.size() == 1 ? "" : "s" )
- + ( destDir != null ? " to " + destDir : "" ) );
-
- // now we need to populate the compiler adapter
- adapter.setJspc( this );
-
- // finally, lets execute the compiler!!
- if( !adapter.execute() )
- {
- if( failOnError )
- {
- throw new TaskException( FAIL_MSG );
- }
- else
- {
- getContext().error( FAIL_MSG );
- }
- }
- }
- else
- {
- if( filecount == 0 )
- {
- getContext().info( "there were no files to compile" );
- }
- else
- {
- getContext().debug( "all files are up to date" );
- }
- }
- }
-
- /*
- * ------------------------------------------------------------
- */
- /**
- * Clear the list of files to be compiled and copied..
- */
- protected void resetFileLists()
- {
- compileList.clear();
- }
-
- /*
- * ------------------------------------------------------------
- */
- /**
- * Scans the directory looking for source files to be compiled. The results
- * are returned in the class variable compileList
- *
- * @param srcDir Description of Parameter
- * @param destDir Description of Parameter
- * @param files Description of Parameter
- */
- protected void scanDir( File srcDir, File destDir, String files[] )
- {
-
- long now = ( new Date() ).getTime();
-
- for( int i = 0; i < files.length; i++ )
- {
- File srcFile = new File( srcDir, files[ i ] );
- if( files[ i ].endsWith( ".jsp" ) )
- {
- // drop leading path (if any)
- int fileStart =
- files[ i ].lastIndexOf( File.separatorChar ) + 1;
- File javaFile = new File( destDir, files[ i ].substring( fileStart,
- files[ i ].indexOf( ".jsp" ) ) + ".java" );
-
- if( srcFile.lastModified() > now )
- {
- final String message =
- "Warning: file modified in the future: " + files[ i ];
- getContext().warn( message );
- }
-
- if( !javaFile.exists() ||
- srcFile.lastModified() > javaFile.lastModified() )
- {
- if( !javaFile.exists() )
- {
- getContext().debug( "Compiling " + srcFile.getPath() + " because java file " + javaFile.getPath() + " does not exist" );
- }
- else
- {
- getContext().debug( "Compiling " + srcFile.getPath() + " because it is out of date with respect to " + javaFile.getPath() );
- }
- compileList.add( srcFile.getAbsolutePath() );
- }
- }
- }
- }
- /*
- * ------------------------------------------------------------
- */
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/WLJspc.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/WLJspc.java
deleted file mode 100644
index 239215d0b..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/WLJspc.java
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.jsp;//java imports
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.StringTokenizer;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.taskdefs.Java;
-import org.apache.tools.todo.taskdefs.MatchingTask;
-import org.apache.tools.todo.types.Argument;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.Path;
-
-/**
- * Class to precompile JSP's using weblogic's jsp compiler (weblogic.jspc)
- *
- * @author Avik Sengupta
- * http://www.webteksoftware.com Tested only on Weblogic 4.5.1 - NT4.0 and
- * Solaris 5.7 required attributes src : root of source tree for JSP, ie,
- * the document root for your weblogic server dest : root of destination
- * directory, what you have set as WorkingDir in the weblogic properties
- * package : start package name under which your JSP's would be compiled
- * other attributes classpath A classpath should be set which contains the
- * weblogic classes as well as all application classes referenced by the
- * JSP. The system classpath is also appended when the jspc is called, so
- * you may choose to put everything in the classpath while calling Ant.
- * However, since presumably the JSP's will reference classes being build
- * by Ant, it would be better to explicitly add the classpath in the task
- * The task checks timestamps on the JSP's and the generated classes, and
- * compiles only those files that have changed. It follows the weblogic
- * naming convention of putting classes in _dirName/_fileName.class for
- * dirname/fileName.jsp Limitation: It compiles the files thru the
- * Classic compiler only. Limitation: Since it is my experience that
- * weblogic jspc throws out of memory error on being given too many files
- * at one go, it is called multiple times with one jsp file each.
- * example
- * <target name="jspcompile" depends="compile">
- * <wljspc src="c:\\weblogic\\myserver\\public_html" dest="c:\\weblogic\\myserver\\serverclasses" package="myapp.jsp">
- * <classpath>
- * <pathelement location="${weblogic.classpath}" />
- * <pathelement path="${compile.dest}" />
- * </classpath>
- *
- * </wljspc>
- * </target>
- *
- */
-
-public class WLJspc extends MatchingTask
-{//classpath used to compile the jsp files.
- //private String compilerPath; //fully qualified name for the compiler executable
-
- private String pathToPackage = "";
- private ArrayList filesToDo = new ArrayList();//package under which resultant classes will reside
- private Path compileClasspath;
- //TODO Test on other versions of weblogic
- //TODO add more attributes to the task, to take care of all jspc options
- //TODO Test on Unix
-
- private File destinationDirectory;// root of source files tree
- private String destinationPackage;//root of compiled files tree
- private File sourceDirectory;
-
- /**
- * Set the classpath to be used for this compilation.
- *
- * @param classpath The new Classpath value
- */
- public void setClasspath( Path classpath )
- throws TaskException
- {
- if( compileClasspath == null )
- {
- compileClasspath = classpath;
- }
- else
- {
- compileClasspath.append( classpath );
- }
- }
-
- /**
- * Set the directory containing the source jsp's
- *
- * @param dirName the directory containg the source jsp's
- */
- public void setDest( File dirName )
- {
- destinationDirectory = dirName;
- }
-
- /**
- * Set the package under which the compiled classes go
- *
- * @param packageName the package name for the clases
- */
- public void setPackage( String packageName )
- {
-
- destinationPackage = packageName;
- }
-
- /**
- * Set the directory containing the source jsp's
- *
- * @param dirName the directory containg the source jsp's
- */
- public void setSrc( File dirName )
- {
-
- sourceDirectory = dirName;
- }
-
- /**
- * Maybe creates a nested classpath element.
- *
- * @return Description of the Returned Value
- */
- public Path createClasspath()
- {
- if( compileClasspath == null )
- {
- compileClasspath = new Path();
- }
- return compileClasspath;
- }
-
- public void execute()
- throws TaskException
- {
- if( !destinationDirectory.isDirectory() )
- {
- throw new TaskException( "destination directory " + destinationDirectory.getPath() +
- " is not valid" );
- }
-
- if( !sourceDirectory.isDirectory() )
- {
- throw new TaskException( "src directory " + sourceDirectory.getPath() +
- " is not valid" );
- }
-
- if( destinationPackage == null )
- {
- throw new TaskException( "package attribute must be present." );
- }
-
- pathToPackage = this.destinationPackage.replace( '.', File.separatorChar );
- // get all the files in the sourceDirectory
- DirectoryScanner ds = super.getDirectoryScanner( sourceDirectory );
-
- //use the systemclasspath as well, to include the ant jar
- if( compileClasspath == null )
- {
- compileClasspath = new Path();
- }
-
- // TODO - make sure tools.jar ends up in the classpath
- //compileClasspath.append( Path.systemClasspath );
-
- String[] files = ds.getIncludedFiles();
-
- //Weblogic.jspc calls System.exit() ... have to fork
- // Therefore, takes loads of time
- // Can pass directories at a time (*.jsp) but easily runs out of memory on hefty dirs
- // (even on a Sun)
- Java helperTask = null;//(Java)getProject().createTask( "java" );
- helperTask.setFork( true );
- helperTask.setClassname( "weblogic.jspc" );
- String[] args = new String[ 12 ];
-
- File jspFile = null;
- String parents = "";
- String arg = "";
- int j = 0;
- //XXX this array stuff is a remnant of prev trials.. gotta remove.
- args[ j++ ] = "-d";
- args[ j++ ] = destinationDirectory.getAbsolutePath().trim();
- args[ j++ ] = "-docroot";
- args[ j++ ] = sourceDirectory.getAbsolutePath().trim();
- args[ j++ ] = "-keepgenerated";//TODO: Parameterise ??
- //Call compiler as class... dont want to fork again
- //Use classic compiler -- can be parameterised?
- args[ j++ ] = "-compilerclass";
- args[ j++ ] = "sun.tools.javac.Main";
- //Weblogic jspc does not seem to work unless u explicitly set this...
- // Does not take the classpath from the env....
- // Am i missing something about the Java task??
- args[ j++ ] = "-classpath";
- args[ j++ ] = compileClasspath.toString();
-
- this.scanDir( files );
- getContext().info( "Compiling " + filesToDo.size() + " JSP files" );
-
- for( int i = 0; i < filesToDo.size(); i++ )
- {
- //XXX
- // All this to get package according to weblogic standards
- // Can be written better... this is too hacky!
- // Careful.. similar code in scanDir , but slightly different!!
- jspFile = new File( (String)filesToDo.get( i ) );
- args[ j ] = "-package";
- parents = jspFile.getParent();
- if( ( parents != null ) && ( !( "" ).equals( parents ) ) )
- {
- parents = this.replaceString( parents, File.separator, "_." );
- args[ j + 1 ] = destinationPackage + "." + "_" + parents;
- }
- else
- {
- args[ j + 1 ] = destinationPackage;
- }
-
- args[ j + 2 ] = sourceDirectory + File.separator + (String)filesToDo.get( i );
- arg = "";
-
- for( int x = 0; x < 12; x++ )
- {
- arg += " " + args[ x ];
- }
-
- System.out.println( "arg = " + arg );
-
- //helperTask.clearArgs();
- helperTask.addArg( new Argument( arg ) );
- helperTask.addClasspath( compileClasspath );
- if( helperTask.executeJava() != 0 )
- {
- getContext().warn( files[ i ] + " failed to compile" );
- }
- }
- }
-
- protected String replaceString( String inpString, String escapeChars, String replaceChars )
- {
- String localString = "";
- int numTokens = 0;
- StringTokenizer st = new StringTokenizer( inpString, escapeChars, true );
- numTokens = st.countTokens();
- for( int i = 0; i < numTokens; i++ )
- {
- String test = st.nextToken();
- test = ( test.equals( escapeChars ) ? replaceChars : test );
- localString += test;
- }
- return localString;
- }
-
- protected void scanDir( String files[] )
- {
-
- long now = ( new Date() ).getTime();
- File jspFile = null;
- String parents = null;
- String pack = "";
- for( int i = 0; i < files.length; i++ )
- {
- File srcFile = new File( this.sourceDirectory, files[ i ] );
- //XXX
- // All this to convert source to destination directory according to weblogic standards
- // Can be written better... this is too hacky!
- jspFile = new File( files[ i ] );
- parents = jspFile.getParent();
-
- if( ( parents != null ) && ( !( "" ).equals( parents ) ) )
- {
- parents = this.replaceString( parents, File.separator, "_/" );
- pack = pathToPackage + File.separator + "_" + parents;
- }
- else
- {
- pack = pathToPackage;
- }
-
- String filePath = pack + File.separator + "_";
- int startingIndex
- = files[ i ].lastIndexOf( File.separator ) != -1 ? files[ i ].lastIndexOf( File.separator ) + 1 : 0;
- int endingIndex = files[ i ].indexOf( ".jsp" );
- if( endingIndex == -1 )
- {
- break;
- }
-
- filePath += files[ i ].substring( startingIndex, endingIndex );
- filePath += ".class";
- File classFile = new File( this.destinationDirectory, filePath );
-
- if( srcFile.lastModified() > now )
- {
- final String message = "Warning: file modified in the future: " + files[ i ];
- getContext().warn( message );
- }
- if( srcFile.lastModified() > classFile.lastModified() )
- {
- //log("Files are" + srcFile.getAbsolutePath()+" " +classFile.getAbsolutePath());
- filesToDo.add( files[ i ] );
- getContext().debug( "Recompiling File " + files[ i ] );
- }
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/compilers/CompilerAdapter.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/compilers/CompilerAdapter.java
deleted file mode 100644
index f53c10ce5..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/compilers/CompilerAdapter.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.jsp.compilers;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.taskdefs.jsp.JspC;
-
-/**
- * The interface that all jsp compiler adapters must adher to.
- *
- * A compiler adapter is an adapter that interprets the jspc's parameters in
- * preperation to be passed off to the compier this adapter represents. As all
- * the necessary values are stored in the Jspc task itself, the only thing all
- * adapters need is the jsp task, the execute command and a parameterless
- * constructor (for reflection).
- *
- * @author Jay Dickon Glanville
- * jayglanville@home.com
- * @author Matthew Watson mattw@i3sp.com
- */
-public interface CompilerAdapter
-{
- void setTaskContext( TaskContext context );
-
- /**
- * Sets the compiler attributes, which are stored in the Jspc task.
- *
- * @param attributes The new Jspc value
- */
- void setJspc( JspC attributes );
-
- /**
- * Executes the task.
- *
- * @return has the compilation been successful
- * @exception TaskException Description of Exception
- */
- boolean execute()
- throws TaskException;
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/compilers/CompilerAdapterFactory.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/compilers/CompilerAdapterFactory.java
deleted file mode 100644
index 327ee4644..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/compilers/CompilerAdapterFactory.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.jsp.compilers;
-
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-
-/**
- * Creates the necessary compiler adapter, given basic criteria.
- *
- * @author J D Glanville
- * @author Matthew Watson mattw@i3sp.com
- */
-public class CompilerAdapterFactory
-{
- /**
- * This is a singlton -- can't create instances!!
- */
- private CompilerAdapterFactory()
- {
- }
-
- /**
- * Based on the parameter passed in, this method creates the necessary
- * factory desired. The current mapping for compiler names are as follows:
- *
- *
- * jasper = jasper compiler (the default)
- * a fully quallified classname = the name of a jsp compiler
- * adapter
- *
- *
- *
- * @param compilerType either the name of the desired compiler, or the full
- * classname of the compiler's adapter.
- * @return The Compiler value
- * @throws TaskException if the compiler type could not be resolved into a
- * compiler adapter.
- */
- public static CompilerAdapter getCompiler( String compilerType, TaskContext context )
- throws TaskException
- {
- final CompilerAdapter adapter = createAdapter( compilerType );
- adapter.setTaskContext( context );
- return adapter;
- }
-
- private static CompilerAdapter createAdapter( String compilerType )
- throws TaskException
- {
- /*
- * If I've done things right, this should be the extent of the
- * conditional statements required.
- */
- if( compilerType.equalsIgnoreCase( "jasper" ) )
- {
- return new JasperC();
- }
- return resolveClassName( compilerType );
- }
-
- /**
- * Tries to resolve the given classname into a compiler adapter. Throws a
- * fit if it can't.
- *
- * @param className The fully qualified classname to be created.
- * @return Description of the Returned Value
- * @throws TaskException This is the fit that is thrown if className isn't
- * an instance of CompilerAdapter.
- */
- private static CompilerAdapter resolveClassName( String className )
- throws TaskException
- {
- try
- {
- Class c = Class.forName( className );
- Object o = c.newInstance();
- return (CompilerAdapter)o;
- }
- catch( ClassNotFoundException cnfe )
- {
- throw new TaskException( className + " can\'t be found.", cnfe );
- }
- catch( ClassCastException cce )
- {
- throw new TaskException( className + " isn\'t the classname of "
- + "a compiler adapter.", cce );
- }
- catch( Throwable t )
- {
- // for all other possibilities
- throw new TaskException( className + " caused an interesting "
- + "exception.", t );
- }
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/compilers/DefaultCompilerAdapter.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/compilers/DefaultCompilerAdapter.java
deleted file mode 100644
index 98b6237cd..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/compilers/DefaultCompilerAdapter.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.jsp.compilers;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import org.apache.avalon.excalibur.util.StringUtil;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.taskdefs.jsp.JspC;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * This is the default implementation for the CompilerAdapter interface. This is
- * currently very light on the ground since only one compiler type is supported.
- *
- * @author Matthew Watson mattw@i3sp.com
- */
-public abstract class DefaultCompilerAdapter
- implements CompilerAdapter
-{
- private JspC m_attributes;
- private TaskContext m_taskContext;
-
- public void setTaskContext( final TaskContext context )
- {
- m_taskContext = context;
- }
-
- protected final TaskContext getTaskContext()
- {
- return m_taskContext;
- }
-
- public void setJspc( final JspC attributes )
- {
- this.m_attributes = attributes;
- }
-
- public JspC getJspc()
- {
- return m_attributes;
- }
-
- /*
- * ------------------------------------------------------------
- */
- /**
- * Logs the compilation parameters, adds the files to compile and logs the
- * &qout;niceSourceList"
- *
- * @param jspc Description of Parameter
- * @param compileList Description of Parameter
- * @param cmd Description of Parameter
- */
- protected void logAndAddFilesToCompile( JspC jspc,
- ArrayList compileList,
- Commandline cmd )
- {
- getTaskContext().debug( "Compilation args: " + cmd.toString() );
-
- StringBuffer niceSourceList = new StringBuffer( "File" );
- if( compileList.size() != 1 )
- {
- niceSourceList.append( "s" );
- }
- niceSourceList.append( " to be compiled:" );
-
- niceSourceList.append( StringUtil.LINE_SEPARATOR );
-
- Iterator enum = compileList.iterator();
- while( enum.hasNext() )
- {
- String arg = (String)enum.next();
- cmd.addArgument( arg );
- niceSourceList.append( " " + arg + StringUtil.LINE_SEPARATOR );
- }
-
- getTaskContext().debug( niceSourceList.toString() );
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/compilers/JasperC.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/compilers/JasperC.java
deleted file mode 100644
index 20d0948e8..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/jsp/compilers/JasperC.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.jsp.compilers;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.taskdefs.Java;
-import org.apache.tools.todo.taskdefs.jsp.JspC;
-import org.apache.tools.todo.types.Argument;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * The implementation of the jasper compiler. This is a cut-and-paste of the
- * original Jspc task.
- *
- * @author Matthew Watson mattw@i3sp.com
- */
-public class JasperC
- extends DefaultCompilerAdapter
-{
- /*
- * ------------------------------------------------------------
- */
- public boolean execute()
- throws TaskException
- {
- getTaskContext().debug( "Using jasper compiler" );
- Commandline cmd = setupJasperCommand();
-
- try
- {
- // Create an instance of the compiler, redirecting output to
- // the project log
- //FIXME
- Java java = null;//(Java)( getJspc().getProject() ).createTask( "java" );
- if( getJspc().getClasspath() != null )
- {
- java.addClasspath( getJspc().getClasspath() );
- }
- java.setClassname( "org.apache.jasper.JspC" );
- String args[] = cmd.getArguments();
- for( int i = 0; i < args.length; i++ )
- {
- java.addArg( new Argument( args[ i ] ) );
- }
- java.execute();
- return true;
- }
- catch( Exception ex )
- {
- if( ex instanceof TaskException )
- {
- throw (TaskException)ex;
- }
- else
- {
- throw new TaskException( "Error running jsp compiler: ",
- ex );
- }
- }
- }
-
- /*
- * ------------------------------------------------------------
- */
- private Commandline setupJasperCommand()
- {
- Commandline cmd = new Commandline();
- JspC jspc = getJspc();
- if( jspc.getDestdir() != null )
- {
- cmd.addArgument( "-d" );
- cmd.addArgument( jspc.getDestdir() );
- }
- if( jspc.getPackage() != null )
- {
- cmd.addArgument( "-p" );
- cmd.addArgument( jspc.getPackage() );
- }
- if( jspc.getVerbose() != 0 )
- {
- cmd.addArgument( "-v" + jspc.getVerbose() );
- }
- if( jspc.isMapped() )
- {
- cmd.addArgument( "-mapped" );
- }
- if( jspc.getIeplugin() != null )
- {
- cmd.addArgument( "-ieplugin" );
- cmd.addArgument( jspc.getIeplugin() );
- }
- if( jspc.getUriroot() != null )
- {
- cmd.addArgument( "-uriroot" );
- cmd.addArgument( jspc.getUriroot().toString() );
- }
- if( jspc.getUribase() != null )
- {
- cmd.addArgument( "-uribase" );
- cmd.addArgument( jspc.getUribase().toString() );
- }
- logAndAddFilesToCompile( getJspc(), getJspc().getCompileList(), cmd );
- return cmd;
- }
- /*
- * ------------------------------------------------------------
- */
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/AggregateTransformer.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/AggregateTransformer.java
deleted file mode 100644
index 041d5ffec..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/AggregateTransformer.java
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import org.apache.avalon.excalibur.io.FileUtil;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.EnumeratedAttribute;
-import org.w3c.dom.Document;
-
-/**
- * Transform a JUnit xml report. The default transformation generates an html
- * report in either framed or non-framed style. The non-framed style is
- * convenient to have a concise report via mail, the framed report is much more
- * convenient if you want to browse into different packages or testcases since
- * it is a Javadoc like report.
- *
- * @author Stephane Bailliez
- */
-public class AggregateTransformer
-{
- public final static String FRAMES = "frames";
-
- public final static String NOFRAMES = "noframes";
-
- /**
- * XML Parser factory
- */
- private final static DocumentBuilderFactory c_dbfactory = DocumentBuilderFactory.newInstance();
-
- /**
- * the xml document to process
- */
- private Document m_document;
-
- /**
- * the format to use for the report. Must be FRAMES or NOFRAMES
- *
- */
- private String m_format;
-
- /**
- * the style directory. XSLs should be read from here if necessary
- */
- private File m_styleDir;
-
- private AbstractTask m_task;
-
- /**
- * the destination directory, this is the root from where html should be
- * generated
- */
- private File m_toDir;
-
- public AggregateTransformer( AbstractTask task )
- {
- m_task = task;
- }
-
- public void setFormat( Format format )
- {
- m_format = format.getValue();
- }
-
- /**
- * set the style directory. It is optional and will override the default xsl
- * used.
- *
- * @param styledir the directory containing the xsl files if the user would
- * like to override with its own style.
- */
- public void setStyledir( File styledir )
- {
- m_styleDir = styledir;
- }
-
- /**
- * set the destination directory
- *
- * @param todir The new Todir value
- */
- public void setTodir( File todir )
- {
- m_toDir = todir;
- }
-
- public void setXmlDocument( Document doc )
- {
- m_document = doc;
- }
-
- public void transform()
- throws TaskException
- {
- checkOptions();
- try
- {
- XalanExecutor executor = XalanExecutor.newInstance( this );
- executor.execute();
- }
- catch( Exception e )
- {
- throw new TaskException( "Errors while applying transformations", e );
- }
- //task.getLogger().info( "Transform time: " + dt + "ms" );
- }
-
- /**
- * Set the xml file to be processed. This is a helper if you want to set the
- * file directly. Much more for testing purposes.
- *
- * @param xmlfile xml file to be processed
- * @exception TaskException Description of Exception
- */
- protected void setXmlfile( File xmlfile )
- throws TaskException
- {
- try
- {
- DocumentBuilder builder = c_dbfactory.newDocumentBuilder();
- InputStream in = new FileInputStream( xmlfile );
- try
- {
- Document doc = builder.parse( in );
- setXmlDocument( doc );
- }
- finally
- {
- in.close();
- }
- }
- catch( Exception e )
- {
- throw new TaskException( "Error while parsing document: " + xmlfile, e );
- }
- }
-
- /**
- * Get the systemid of the appropriate stylesheet based on its name and
- * styledir. If no styledir is defined it will load it as a java resource in
- * the xsl child package, otherwise it will get it from the given directory.
- *
- * @return The StylesheetSystemId value
- * @throws IOException thrown if the requested stylesheet does not exist.
- */
- protected String getStylesheetSystemId()
- throws IOException
- {
- String xslname = "junit-frames.xsl";
- if( NOFRAMES.equals( m_format ) )
- {
- xslname = "junit-noframes.xsl";
- }
- URL url = null;
- if( m_styleDir == null )
- {
- url = getClass().getResource( "xsl/" + xslname );
- if( url == null )
- {
- throw new FileNotFoundException( "Could not find jar resource " + xslname );
- }
- }
- else
- {
- File file = new File( m_styleDir, xslname );
- if( !file.exists() )
- {
- throw new FileNotFoundException( "Could not find file '" + file + "'" );
- }
- url = new URL( "file", "", file.getAbsolutePath() );
- }
- return url.toExternalForm();
- }
-
- /**
- * check for invalid options
- *
- * @exception TaskException Description of Exception
- */
- protected void checkOptions()
- throws TaskException
- {
- // set the destination directory relative from the project if needed.
- if( m_toDir == null )
- {
- m_toDir = FileUtil.resolveFile( m_task.getBaseDirectory(), "." );
- }
- else if( !m_toDir.isAbsolute() )
- {
- m_toDir = FileUtil.resolveFile( m_task.getBaseDirectory(), m_toDir.getPath() );
- }
- }
-
- protected Document getDocument()
- {
- return m_document;
- }
-
- protected String getFormat()
- {
- return m_format;
- }
-
- protected File getToDir()
- {
- return m_toDir;
- }
-
- public static class Format extends EnumeratedAttribute
- {
- public String[] getValues()
- {
- return new String[]{FRAMES, NOFRAMES};
- }
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/BaseTest.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/BaseTest.java
deleted file mode 100644
index e7ded0010..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/BaseTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.io.File;
-import java.util.ArrayList;
-
-/**
- * Baseclass for BatchTest and JUnitTest.
- *
- * @author Stefan Bodewig
- * @author Stephane Bailliez
- */
-public abstract class BaseTest
-{
- protected boolean m_haltOnError = false;
- protected boolean m_haltOnFail = false;
- protected boolean m_filtertrace = true;
- protected boolean fork = false;
- protected String ifProperty = null;
- protected String unlessProperty = null;
- protected ArrayList formatters = new ArrayList();
- /**
- * destination directory
- */
- protected File destDir = null;
- protected String errorProperty;
-
- protected String failureProperty;
-
- public void setErrorProperty( String errorProperty )
- {
- this.errorProperty = errorProperty;
- }
-
- public void setFailureProperty( String failureProperty )
- {
- this.failureProperty = failureProperty;
- }
-
- public void setFiltertrace( boolean value )
- {
- m_filtertrace = value;
- }
-
- public void setFork( boolean value )
- {
- fork = value;
- }
-
- public void setHaltonerror( boolean value )
- {
- m_haltOnError = value;
- }
-
- public void setHaltonfailure( boolean value )
- {
- m_haltOnFail = value;
- }
-
- public void setIf( String propertyName )
- {
- ifProperty = propertyName;
- }
-
- /**
- * Sets the destination directory.
- *
- * @param destDir The new Todir value
- */
- public void setTodir( File destDir )
- {
- this.destDir = destDir;
- }
-
- public void setUnless( String propertyName )
- {
- unlessProperty = propertyName;
- }
-
- public java.lang.String getErrorProperty()
- {
- return errorProperty;
- }
-
- public java.lang.String getFailureProperty()
- {
- return failureProperty;
- }
-
- public boolean getFiltertrace()
- {
- return m_filtertrace;
- }
-
- public boolean getFork()
- {
- return fork;
- }
-
- public boolean getHaltonerror()
- {
- return m_haltOnError;
- }
-
- public boolean getHaltonfailure()
- {
- return m_haltOnFail;
- }
-
- /**
- * @return the destination directory as an absolute path if it exists
- * otherwise return null
- */
- public String getTodir()
- {
- if( destDir != null )
- {
- return destDir.getAbsolutePath();
- }
- return null;
- }
-
- public void addFormatter( FormatterElement elem )
- {
- formatters.add( elem );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/BatchTest.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/BatchTest.java
deleted file mode 100644
index 161776154..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/BatchTest.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.ScannerUtil;
-
-/**
- *
- *
- * Create then run JUnitTest
's based on the list of files given by
- * the fileset attribute.
- *
- * Every .java
or .class
file in the fileset is
- * assumed to be a testcase. A JUnitTest
is created for each of
- * these named classes with basic setup inherited from the parent BatchTest
- * .
- *
- * @author Jeff Martin
- * @author Stefan Bodewig
- * @author Stephane Bailliez
- * @see JUnitTest
- */
-public final class BatchTest extends BaseTest
-{
- /**
- * the list of filesets containing the testcase filename rules
- */
- private ArrayList filesets = new ArrayList();
-
- /**
- * Convenient method to convert a pathname without extension to a fully
- * qualified classname. For example org/apache/Whatever will be
- * converted to org.apache.Whatever
- *
- * @param filename the filename to "convert" to a classname.
- * @return the classname matching the filename.
- */
- public static final String javaToClass( String filename )
- {
- return filename.replace( File.separatorChar, '.' );
- }
-
- /**
- * Return all JUnitTest instances obtain by applying the fileset
- * rules.
- *
- * @return an enumeration of all elements of this batchtest that are a
- * JUnitTest instance.
- */
- public final Iterator iterator()
- throws TaskException
- {
- final JUnitTest[] tests = createAllJUnitTest();
- return Arrays.asList( tests ).iterator();
- }
-
- /**
- * Add a new fileset instance to this batchtest. Whatever the fileset is,
- * only filename that are .java or .class will be
- * considered as 'candidates'.
- *
- * @param fs the new fileset containing the rules to get the testcases.
- */
- public void addFileSet( FileSet fs )
- {
- filesets.add( fs );
- }
-
- /**
- * Convenient method to merge the JUnitTest s of this batchtest to
- * a ArrayList .
- *
- * @param v the vector to which should be added all individual tests of this
- * batch test.
- */
- final void addTestsTo( ArrayList v )
- throws TaskException
- {
- final JUnitTest[] tests = createAllJUnitTest();
- v.ensureCapacity( v.size() + tests.length );
- for( int i = 0; i < tests.length; i++ )
- {
- v.add( tests[ i ] );
- }
- }
-
- /**
- * Iterate over all filesets and return the filename of all files that end
- * with .java or .class . This is to avoid wrapping a
- * JUnitTest over an xml file for example. A Testcase is obviously a
- * java file (compiled or not).
- *
- * @return an array of filenames without their extension. As they should
- * normally be taken from their root, filenames should match their
- * fully qualified class name (If it is not the case it will fail when
- * running the test). For the class org/apache/Whatever.class
- * it will return org/apache/Whatever .
- */
- private String[] getFilenames()
- throws TaskException
- {
- ArrayList v = new ArrayList();
- final int size = this.filesets.size();
- for( int j = 0; j < size; j++ )
- {
- FileSet fs = (FileSet)filesets.get( j );
- DirectoryScanner ds = ScannerUtil.getDirectoryScanner( fs );
- ds.scan();
- String[] f = ds.getIncludedFiles();
- for( int k = 0; k < f.length; k++ )
- {
- String pathname = f[ k ];
- if( pathname.endsWith( ".java" ) )
- {
- v.add( pathname.substring( 0, pathname.length() - ".java".length() ) );
- }
- else if( pathname.endsWith( ".class" ) )
- {
- v.add( pathname.substring( 0, pathname.length() - ".class".length() ) );
- }
- }
- }
-
- return (String[])v.toArray( new String[ v.size() ] );
- }
-
- /**
- * Create all JUnitTest s based on the filesets. Each instance is
- * configured to match this instance properties.
- *
- * @return the array of all JUnitTest s that belongs to this batch.
- */
- private JUnitTest[] createAllJUnitTest()
- throws TaskException
- {
- String[] filenames = getFilenames();
- JUnitTest[] tests = new JUnitTest[ filenames.length ];
- for( int i = 0; i < tests.length; i++ )
- {
- String classname = javaToClass( filenames[ i ] );
- tests[ i ] = createJUnitTest( classname );
- }
- return tests;
- }
-
- /**
- * Create a JUnitTest that has the same property as this
- * BatchTest instance.
- *
- * @param classname the name of the class that should be run as a
- * JUnitTest . It must be a fully qualified name.
- * @return the JUnitTest over the given classname.
- */
- private JUnitTest createJUnitTest( String classname )
- {
- JUnitTest test = new JUnitTest();
- test.setName( classname );
- test.setHaltonerror( this.m_haltOnError );
- test.setHaltonfailure( this.m_haltOnFail );
- test.setFiltertrace( this.m_filtertrace );
- test.setFork( this.fork );
- test.setIf( this.ifProperty );
- test.setUnless( this.unlessProperty );
- test.setTodir( this.destDir );
- test.setFailureProperty( failureProperty );
- test.setErrorProperty( errorProperty );
- Iterator list = this.formatters.iterator();
- while( list.hasNext() )
- {
- test.addFormatter( (FormatterElement)list.next() );
- }
- return test;
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/BriefJUnitResultFormatter.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/BriefJUnitResultFormatter.java
deleted file mode 100644
index 0b2113c40..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/BriefJUnitResultFormatter.java
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import org.apache.avalon.excalibur.util.StringUtil;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * Prints plain text output of the test to a specified Writer. Inspired by the
- * PlainJUnitResultFormatter.
- *
- * @author Robert Watkins
- * @see FormatterElement
- * @see PlainJUnitResultFormatter
- */
-public class BriefJUnitResultFormatter implements JUnitResultFormatter
-{
-
- /**
- * Formatter for timings.
- */
- private java.text.NumberFormat m_numberFormat = java.text.NumberFormat.getInstance();
-
- /**
- * Output suite has written to System.out
- */
- private String systemOutput = null;
-
- /**
- * Output suite has written to System.err
- */
- private String systemError = null;
-
- /**
- * Where to write the log to.
- */
- private java.io.OutputStream m_out;
-
- /**
- * Used for writing the results.
- */
- private java.io.PrintWriter m_output;
-
- /**
- * Used for writing formatted results to.
- */
- private java.io.PrintWriter m_resultWriter;
-
- /**
- * Used as part of formatting the results.
- */
- private java.io.StringWriter m_results;
-
- public BriefJUnitResultFormatter()
- {
- m_results = new java.io.StringWriter();
- m_resultWriter = new java.io.PrintWriter( m_results );
- }
-
- /**
- * Sets the stream the formatter is supposed to write its results to.
- *
- * @param out The new Output value
- */
- public void setOutput( java.io.OutputStream out )
- {
- m_out = out;
- m_output = new java.io.PrintWriter( out );
- }
-
- public void setSystemError( String err )
- {
- systemError = err;
- }
-
- public void setSystemOutput( String out )
- {
- systemOutput = out;
- }
-
- /**
- * A test caused an error.
- *
- * @param test The feature to be added to the Error attribute
- * @param error The feature to be added to the Error attribute
- */
- public void addError( Test test, Throwable error )
- {
- formatError( "\tCaused an ERROR", test, error );
- }
-
- /**
- * Interface TestListener for JUnit <= 3.4.
- *
- * A Test failed.
- *
- * @param test The feature to be added to the Failure attribute
- * @param t The feature to be added to the Failure attribute
- */
- public void addFailure( Test test, Throwable t )
- {
- formatError( "\tFAILED", test, t );
- }
-
- /**
- * Interface TestListener for JUnit > 3.4.
- *
- * A Test failed.
- *
- * @param test The feature to be added to the Failure attribute
- * @param t The feature to be added to the Failure attribute
- */
- public void addFailure( Test test, AssertionFailedError t )
- {
- addFailure( test, (Throwable)t );
- }
-
- /**
- * A test ended.
- *
- * @param test Description of Parameter
- */
- public void endTest( Test test )
- {
- }
-
- /**
- * The whole testsuite ended.
- *
- * @param suite Description of Parameter
- * @exception TaskException Description of Exception
- */
- public void endTestSuite( JUnitTest suite )
- throws TaskException
- {
- final StringBuffer sb = new StringBuffer( "Testsuite: " );
- sb.append( suite.getName() );
- sb.append( StringUtil.LINE_SEPARATOR );
- sb.append( "Tests run: " );
- sb.append( suite.runCount() );
- sb.append( ", Failures: " );
- sb.append( suite.failureCount() );
- sb.append( ", Errors: " );
- sb.append( suite.errorCount() );
- sb.append( ", Time elapsed: " );
- sb.append( m_numberFormat.format( suite.getRunTime() / 1000.0 ) );
- sb.append( " sec" );
- sb.append( StringUtil.LINE_SEPARATOR );
- sb.append( StringUtil.LINE_SEPARATOR );
-
- // append the err and output streams to the log
- if( systemOutput != null && systemOutput.length() > 0 )
- {
- sb.append( "------------- Standard Output ---------------" )
- .append( StringUtil.LINE_SEPARATOR )
- .append( systemOutput )
- .append( "------------- ---------------- ---------------" )
- .append( StringUtil.LINE_SEPARATOR );
- }
-
- if( systemError != null && systemError.length() > 0 )
- {
- sb.append( "------------- Standard Error -----------------" )
- .append( StringUtil.LINE_SEPARATOR )
- .append( systemError )
- .append( "------------- ---------------- ---------------" )
- .append( StringUtil.LINE_SEPARATOR );
- }
-
- if( output() != null )
- {
- try
- {
- output().write( sb.toString() );
- resultWriter().close();
- output().write( m_results.toString() );
- output().flush();
- }
- finally
- {
- if( m_out != (Object)System.out &&
- m_out != (Object)System.err )
- {
- try
- {
- m_out.close();
- }
- catch( java.io.IOException e )
- {
- }
- }
- }
- }
- }
-
- /**
- * A test started.
- *
- * @param test Description of Parameter
- */
- public void startTest( Test test )
- {
- }
-
- /**
- * The whole testsuite started.
- *
- * @param suite Description of Parameter
- * @exception TaskException Description of Exception
- */
- public void startTestSuite( JUnitTest suite )
- throws TaskException
- {
- }
-
- /**
- * Format an error and print it.
- *
- * @param type Description of Parameter
- * @param test Description of Parameter
- * @param error Description of Parameter
- */
- protected synchronized void formatError( String type, Test test,
- Throwable error )
- {
- if( test != null )
- {
- endTest( test );
- }
-
- resultWriter().println( formatTest( test ) + type );
- resultWriter().println( error.getMessage() );
- String strace = JUnitTestRunner.getFilteredTrace( error );
- resultWriter().println( strace );
- resultWriter().println( "" );
- }
-
- /**
- * Format the test for printing..
- *
- * @param test Description of Parameter
- * @return Description of the Returned Value
- */
- protected String formatTest( Test test )
- {
- if( test == null )
- {
- return "Null Test: ";
- }
- else
- {
- return "Testcase: " + test.toString() + ":";
- }
- }
-
- protected java.io.PrintWriter output()
- {
- return m_output;
- }
-
- protected java.io.PrintWriter resultWriter()
- {
- return m_resultWriter;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/CompoundIterator.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/CompoundIterator.java
deleted file mode 100644
index 7ae384c43..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/CompoundIterator.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- * Convenient enumeration over an array of enumeration. For example:
- * Iterator e1 = v1.iterator();
- * while (e1.hasNext()){
- * // do something
- * }
- * Iterator e2 = v2.iterator();
- * while (e2.hasNext()){
- * // do the same thing
- * }
- * can be written as:
- * Iterator[] enums = { v1.iterator(), v2.iterator() };
- * Iterator e = Iterators.fromCompound(enums);
- * while (e.hasNext()){
- * // do something
- * }
- * Note that the enumeration will skip null elements in the array. The
- * following is thus possible:
- * Iterator[] enums = { v1.iterator(), null, v2.iterator() }; // a null enumeration in the array
- * Iterator e = Iterators.fromCompound(enums);
- * while (e.hasNext()){
- * // do something
- * }
- *
- *
- * @author Stephane Bailliez
- */
-class CompoundIterator
- implements Iterator
-{
- /**
- * index in the enums array
- */
- private int index = 0;
-
- /**
- * enumeration array
- */
- private Iterator[] enumArray;
-
- public CompoundIterator( Iterator[] enumarray )
- {
- this.enumArray = enumarray;
- }
-
- /**
- * Tests if this enumeration contains more elements.
- *
- * @return true
if and only if this enumeration object contains
- * at least one more element to provide; false
otherwise.
- */
- public boolean hasNext()
- {
- while( index < enumArray.length )
- {
- if( enumArray[ index ] != null && enumArray[ index ].hasNext() )
- {
- return true;
- }
- index++;
- }
- return false;
- }
-
- /**
- * Returns the next element of this enumeration if this enumeration object
- * has at least one more element to provide.
- *
- * @return the next element of this enumeration.
- * @throws NoSuchElementException if no more elements exist.
- */
- public Object next()
- throws NoSuchElementException
- {
- if( hasNext() )
- {
- return enumArray[ index ].next();
- }
- throw new NoSuchElementException();
- }
-
- public void remove()
- throws UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/DOMElementWriter.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/DOMElementWriter.java
deleted file mode 100644
index 962e4c264..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/DOMElementWriter.java
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.io.IOException;
-import java.io.Writer;
-import org.apache.avalon.excalibur.util.StringUtil;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
-
-/**
- * Writes a DOM tree to a given Writer.
- *
- * Utility class used by {@link org.apache.tools.ant.XmlLogger XmlLogger} and
- * org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter
- * XMLJUnitResultFormatter}.
- *
- * @author The original author of XmlLogger
- * @author Stefan Bodewig
- * @author Stephane Bailliez
- */
-public class DOMElementWriter
-{
- private StringBuffer sb = new StringBuffer();
-
- /**
- * Don't try to be too smart but at least recognize the predefined entities.
- */
- protected String[] knownEntities = {"gt", "amp", "lt", "apos", "quot"};
-
- /**
- * Is the given argument a character or entity reference?
- *
- * @param ent Description of Parameter
- * @return The Reference value
- */
- public boolean isReference( String ent )
- {
- if( !( ent.charAt( 0 ) == '&' ) || !ent.endsWith( ";" ) )
- {
- return false;
- }
-
- if( ent.charAt( 1 ) == '#' )
- {
- if( ent.charAt( 2 ) == 'x' )
- {
- try
- {
- Integer.parseInt( ent.substring( 3, ent.length() - 1 ), 16 );
- return true;
- }
- catch( NumberFormatException nfe )
- {
- return false;
- }
- }
- else
- {
- try
- {
- Integer.parseInt( ent.substring( 2, ent.length() - 1 ) );
- return true;
- }
- catch( NumberFormatException nfe )
- {
- return false;
- }
- }
- }
-
- String name = ent.substring( 1, ent.length() - 1 );
- for( int i = 0; i < knownEntities.length; i++ )
- {
- if( name.equals( knownEntities[ i ] ) )
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Escape <, > & ' and " as their entities.
- *
- * @param value Description of Parameter
- * @return Description of the Returned Value
- */
- public String encode( String value )
- {
- sb.setLength( 0 );
- for( int i = 0; i < value.length(); i++ )
- {
- char c = value.charAt( i );
- switch( c )
- {
- case '<':
- sb.append( "<" );
- break;
- case '>':
- sb.append( ">" );
- break;
- case '\'':
- sb.append( "'" );
- break;
- case '\"':
- sb.append( """ );
- break;
- case '&':
- int nextSemi = value.indexOf( ";", i );
- if( nextSemi < 0
- || !isReference( value.substring( i, nextSemi + 1 ) ) )
- {
- sb.append( "&" );
- }
- else
- {
- sb.append( '&' );
- }
- break;
- default:
- sb.append( c );
- break;
- }
- }
- return sb.toString();
- }
-
- /**
- * Writes a DOM tree to a stream.
- *
- * @param element the Root DOM element of the tree
- * @param out where to send the output
- * @param indent number of
- * @param indentWith strings, that should be used to indent the
- * corresponding tag.
- * @exception IOException Description of Exception
- */
- public void write( Element element, Writer out, int indent,
- String indentWith )
- throws IOException
- {
-
- // Write indent characters
- for( int i = 0; i < indent; i++ )
- {
- out.write( indentWith );
- }
-
- // Write element
- out.write( "<" );
- out.write( element.getTagName() );
-
- // Write attributes
- NamedNodeMap attrs = element.getAttributes();
- for( int i = 0; i < attrs.getLength(); i++ )
- {
- Attr attr = (Attr)attrs.item( i );
- out.write( " " );
- out.write( attr.getName() );
- out.write( "=\"" );
- out.write( encode( attr.getValue() ) );
- out.write( "\"" );
- }
- out.write( ">" );
-
- // Write child elements and text
- boolean hasChildren = false;
- NodeList children = element.getChildNodes();
- for( int i = 0; i < children.getLength(); i++ )
- {
- Node child = children.item( i );
-
- switch( child.getNodeType() )
- {
-
- case Node.ELEMENT_NODE:
- if( !hasChildren )
- {
- out.write( StringUtil.LINE_SEPARATOR );
- hasChildren = true;
- }
- write( (Element)child, out, indent + 1, indentWith );
- break;
- case Node.TEXT_NODE:
- out.write( encode( child.getNodeValue() ) );
- break;
- case Node.CDATA_SECTION_NODE:
- out.write( "" );
- break;
- case Node.ENTITY_REFERENCE_NODE:
- out.write( '&' );
- out.write( child.getNodeName() );
- out.write( ';' );
- break;
- case Node.PROCESSING_INSTRUCTION_NODE:
- out.write( "" );
- out.write( child.getNodeName() );
- String data = child.getNodeValue();
- if( data != null && data.length() > 0 )
- {
- out.write( ' ' );
- out.write( data );
- }
- out.write( "?>" );
- break;
- }
- }
-
- // If we had child elements, we need to indent before we close
- // the element, otherwise we're on the same line and don't need
- // to indent
- if( hasChildren )
- {
- for( int i = 0; i < indent; i++ )
- {
- out.write( indentWith );
- }
- }
-
- // Write element close
- out.write( "" );
- out.write( element.getTagName() );
- out.write( ">" );
- out.write( StringUtil.LINE_SEPARATOR );
- out.flush();
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/DOMUtil.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/DOMUtil.java
deleted file mode 100644
index 4b1c8e72b..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/DOMUtil.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.CDATASection;
-import org.w3c.dom.Comment;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.ProcessingInstruction;
-import org.w3c.dom.Text;
-
-/**
- * Some utilities that might be useful when manipulating DOM trees.
- *
- * @author Stephane Bailliez
- */
-public final class DOMUtil
-{
-
- /**
- * unused constructor
- */
- private DOMUtil()
- {
- }
-
- /**
- * Iterate over the children of a given node and return the first node that
- * has a specific name.
- *
- * @param parent the node to search child from. Can be null .
- * @param tagname the child name we are looking for. Cannot be null
- * .
- * @return the first child that matches the given name or null if
- * the parent is null or if a child does not match the given
- * name.
- */
- public static Element getChildByTagName( Node parent, String tagname )
- {
- if( parent == null )
- {
- return null;
- }
- NodeList childList = parent.getChildNodes();
- final int len = childList.getLength();
- for( int i = 0; i < len; i++ )
- {
- Node child = childList.item( i );
- if( child != null && child.getNodeType() == Node.ELEMENT_NODE &&
- child.getNodeName().equals( tagname ) )
- {
- return (Element)child;
- }
- }
- return null;
- }
-
- /**
- * return the attribute value of an element.
- *
- * @param node the node to get the attribute from.
- * @param name the name of the attribute we are looking for the value.
- * @return the value of the requested attribute or null if the
- * attribute was not found or if node is not an Element
- * .
- */
- public static String getNodeAttribute( Node node, String name )
- {
- if( node instanceof Element )
- {
- Element element = (Element)node;
- return element.getAttribute( name );
- }
- return null;
- }
-
- /**
- * Simple tree walker that will clone recursively a node. This is to avoid
- * using parser-specific API such as Sun's changeNodeOwner when we
- * are dealing with DOM L1 implementations since cloneNode(boolean)
- * will not change the owner document. changeNodeOwner is much
- * faster and avoid the costly cloning process. importNode is in
- * the DOM L2 interface.
- *
- * @param parent the node parent to which we should do the import to.
- * @param child the node to clone recursively. Its clone will be appended to
- * parent .
- * @return the cloned node that is appended to parent
- */
- public static final Node importNode( Node parent, Node child )
- {
- Node copy = null;
- final Document doc = parent.getOwnerDocument();
-
- switch( child.getNodeType() )
- {
- case Node.CDATA_SECTION_NODE:
- copy = doc.createCDATASection( ( (CDATASection)child ).getData() );
- break;
- case Node.COMMENT_NODE:
- copy = doc.createComment( ( (Comment)child ).getData() );
- break;
- case Node.DOCUMENT_FRAGMENT_NODE:
- copy = doc.createDocumentFragment();
- break;
- case Node.ELEMENT_NODE:
- final Element elem = doc.createElement( ( (Element)child ).getTagName() );
- copy = elem;
- final NamedNodeMap attributes = child.getAttributes();
- if( attributes != null )
- {
- final int size = attributes.getLength();
- for( int i = 0; i < size; i++ )
- {
- final Attr attr = (Attr)attributes.item( i );
- elem.setAttribute( attr.getName(), attr.getValue() );
- }
- }
- break;
- case Node.ENTITY_REFERENCE_NODE:
- copy = doc.createEntityReference( child.getNodeName() );
- break;
- case Node.PROCESSING_INSTRUCTION_NODE:
- final ProcessingInstruction pi = (ProcessingInstruction)child;
- copy = doc.createProcessingInstruction( pi.getTarget(), pi.getData() );
- break;
- case Node.TEXT_NODE:
- copy = doc.createTextNode( ( (Text)child ).getData() );
- break;
- default:
- // this should never happen
- throw new IllegalStateException( "Invalid node type: " + child.getNodeType() );
- }
-
- // okay we have a copy of the child, now the child becomes the parent
- // and we are iterating recursively over its children.
- try
- {
- final NodeList children = child.getChildNodes();
- if( children != null )
- {
- final int size = children.getLength();
- for( int i = 0; i < size; i++ )
- {
- final Node newChild = children.item( i );
- if( newChild != null )
- {
- importNode( copy, newChild );
- }
- }
- }
- }
- catch( DOMException ignored )
- {
- }
-
- // bingo append it. (this should normally not be done here)
- parent.appendChild( copy );
- return copy;
- }
-
- /**
- * list a set of node that match a specific filter. The list can be made
- * recursively or not.
- *
- * @param parent the parent node to search from
- * @param filter the filter that children should match.
- * @param recurse true if you want the list to be made recursively
- * otherwise false .
- * @return Description of the Returned Value
- */
- public static NodeList listChildNodes( Node parent, NodeFilter filter, boolean recurse )
- {
- NodeListImpl matches = new NodeListImpl();
- NodeList children = parent.getChildNodes();
- if( children != null )
- {
- final int len = children.getLength();
- for( int i = 0; i < len; i++ )
- {
- Node child = children.item( i );
- if( filter.accept( child ) )
- {
- matches.add( child );
- }
- if( recurse )
- {
- NodeList recmatches = listChildNodes( child, filter, recurse );
- final int reclength = matches.getLength();
- for( int j = 0; j < reclength; j++ )
- {
- matches.add( recmatches.item( i ) );
- }
- }
- }
- }
- return matches;
- }
-
- /**
- * Filter interface to be applied when iterating over a DOM tree. Just think
- * of it like a FileFilter clone.
- *
- * @author RT
- */
- public interface NodeFilter
- {
- /**
- * @param node the node to check for acceptance.
- * @return true if the node is accepted by this filter,
- * otherwise false
- */
- boolean accept( Node node );
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/FormatterElement.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/FormatterElement.java
deleted file mode 100644
index 5d20a1a87..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/FormatterElement.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.OutputStream;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.EnumeratedAttribute;
-
-/**
- *
- *
- * A wrapper for the implementations of JUnitResultFormatter
. In
- * particular, used as a nested <formatter>
element in a
- * <junit>
task.
- *
- * For example,
- * <junit printsummary="no" haltonfailure="yes" fork="false">
- * <formatter type="plain" usefile="false" />
- * <test name="org.apache.ecs.InternationalCharTest" />
- * </junit>
adds a plain
type
- * implementation (PlainJUnitResultFormatter
) to display the
- * results of the test.
- *
- * Either the type
or the classname
attribute must be
- * set.
- *
- * @author Stefan Bodewig
- * @see JUnitTask
- * @see XMLJUnitResultFormatter
- * @see BriefJUnitResultFormatter
- * @see PlainJUnitResultFormatter
- * @see JUnitResultFormatter
- */
-public class FormatterElement
-{
- private OutputStream out = System.out;
- private boolean useFile = true;
-
- private String classname;
- private String extension;
- private File outFile;
-
- /**
- *
- *
- * Set name of class to be used as the formatter.
- *
- * This class must implement JUnitResultFormatter
- *
- * @param classname The new Classname value
- */
- public void setClassname( String classname )
- {
- this.classname = classname;
- }
-
- public void setExtension( String ext )
- {
- this.extension = ext;
- }
-
- /**
- *
- *
- * Set output stream for formatter to use.
- *
- * Defaults to standard out.
- *
- * @param out The new Output value
- */
- public void setOutput( OutputStream out )
- {
- this.out = out;
- }
-
- /**
- *
- *
- * Quick way to use a standard formatter.
- *
- * At the moment, there are three supported standard formatters.
- *
- * The xml
type uses a XMLJUnitResultFormatter
- * .
- * The brief
type uses a BriefJUnitResultFormatter
- * .
- * The plain
type (the default) uses a PlainJUnitResultFormatter
- * .
- *
- *
- *
- * Sets classname
attribute - so you can't use that attribute
- * if you use this one.
- *
- * @param type The new Type value
- */
- public void setType( TypeAttribute type )
- {
- if( "xml".equals( type.getValue() ) )
- {
- setClassname( "org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter" );
- setExtension( ".xml" );
- }
- else
- {
- if( "brief".equals( type.getValue() ) )
- {
- setClassname( "org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter" );
- }
- else
- {// must be plain, ensured by TypeAttribute
- setClassname( "org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter" );
- }
- setExtension( ".txt" );
- }
- }
-
- /**
- * Set whether the formatter should log to file.
- *
- * @param useFile The new UseFile value
- */
- public void setUseFile( boolean useFile )
- {
- this.useFile = useFile;
- }
-
- /**
- * Get name of class to be used as the formatter.
- *
- * @return The Classname value
- */
- public String getClassname()
- {
- return classname;
- }
-
- public String getExtension()
- {
- return extension;
- }
-
- /**
- *
- *
- * Set the file which the formatte should log to.
- *
- * Note that logging to file must be enabled .
- *
- * @param out The new Outfile value
- */
- void setOutfile( File out )
- {
- this.outFile = out;
- }
-
- /**
- * Get whether the formatter should log to file.
- *
- * @return The UseFile value
- */
- boolean getUseFile()
- {
- return useFile;
- }
-
- JUnitResultFormatter createFormatter()
- throws TaskException
- {
- if( classname == null )
- {
- throw new TaskException( "you must specify type or classname" );
- }
-
- Class f = null;
- try
- {
- f = Class.forName( classname );
- }
- catch( ClassNotFoundException e )
- {
- throw new TaskException( "Error", e );
- }
-
- Object o = null;
- try
- {
- o = f.newInstance();
- }
- catch( InstantiationException e )
- {
- throw new TaskException( "Error", e );
- }
- catch( IllegalAccessException e )
- {
- throw new TaskException( "Error", e );
- }
-
- if( !( o instanceof JUnitResultFormatter ) )
- {
- throw new TaskException( classname + " is not a JUnitResultFormatter" );
- }
-
- JUnitResultFormatter r = (JUnitResultFormatter)o;
-
- if( useFile && outFile != null )
- {
- try
- {
- out = new FileOutputStream( outFile );
- }
- catch( java.io.IOException e )
- {
- throw new TaskException( "Error", e );
- }
- }
- r.setOutput( out );
- return r;
- }
-
- /**
- *
- *
- * Enumerated attribute with the values "plain", "xml" and "brief".
- *
- * Use to enumerate options for type
attribute.
- *
- * @author RT
- */
- public static class TypeAttribute extends EnumeratedAttribute
- {
- public String[] getValues()
- {
- return new String[]{"plain", "xml", "brief"};
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/JUnitResultFormatter.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/JUnitResultFormatter.java
deleted file mode 100644
index b77246588..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/JUnitResultFormatter.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.io.OutputStream;
-import junit.framework.TestListener;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * This Interface describes classes that format the results of a JUnit testrun.
- *
- * @author Stefan Bodewig
- */
-public interface JUnitResultFormatter extends TestListener
-{
- /**
- * The whole testsuite started.
- *
- * @param suite Description of Parameter
- * @exception TaskException Description of Exception
- */
- void startTestSuite( JUnitTest suite )
- throws TaskException;
-
- /**
- * The whole testsuite ended.
- *
- * @param suite Description of Parameter
- * @exception TaskException Description of Exception
- */
- void endTestSuite( JUnitTest suite )
- throws TaskException;
-
- /**
- * Sets the stream the formatter is supposed to write its results to.
- *
- * @param out The new Output value
- */
- void setOutput( OutputStream out );
-
- /**
- * This is what the test has written to System.out
- *
- * @param out The new SystemOutput value
- */
- void setSystemOutput( String out );
-
- /**
- * This is what the test has written to System.err
- *
- * @param err The new SystemError value
- */
- void setSystemError( String err );
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/JUnitTask.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/JUnitTask.java
deleted file mode 100644
index d430a8e63..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/JUnitTask.java
+++ /dev/null
@@ -1,759 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Random;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.tools.todo.types.Argument;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.CommandlineJava;
-import org.apache.tools.todo.types.EnumeratedAttribute;
-import org.apache.tools.todo.types.EnvironmentVariable;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.types.PathUtil;
-import org.apache.tools.todo.types.SysProperties;
-
-/**
- * Ant task to run JUnit tests.
- *
- * JUnit is a framework to create unit test. It has been initially created by
- * Erich Gamma and Kent Beck. JUnit can be found at http://www.junit.org .
- *
- * JUnitTask
can run a single specific JUnitTest
using
- * the test
element. For example, the following target
- * <target name="test-int-chars" depends="jar-test">
- * <echo message="testing international characters"/>
- * <junit printsummary="no" haltonfailure="yes" fork="false">
- * <classpath refid="classpath"/>
- * <formatter type="plain" usefile="false" />
- * <test name="org.apache.ecs.InternationalCharTest" />
- * </junit>
- * </target>
- *
runs a single junit test (org.apache.ecs.InternationalCharTest
- * ) in the current VM using the path with id classpath
as
- * classpath and presents the results formatted using the standard plain
- * formatter on the command line.
- *
- * This task can also run batches of tests. The batchtest
element
- * creates a BatchTest
based on a fileset. This allows, for
- * example, all classes found in directory to be run as testcases. For example,
- *
- * <target name="run-tests" depends="dump-info,compile-tests" if="junit.present">
- * <junit printsummary="no" haltonfailure="yes" fork="${junit.fork}">
- * <jvmarg value="-classic"/>
- * <classpath refid="tests-classpath"/>
- * <sysproperty key="build.tests" value="${build.tests}"/>
- * <formatter type="brief" usefile="false" />
- * <batchtest>
- * <fileset dir="${tests.dir}">
- * <include name="**/*Test*" />
- * </fileset>
- * </batchtest>
- * </junit>
- * </target>
- *
this target finds any classes with a test
- * directory anywhere in their path (under the top ${tests.dir}
, of
- * course) and creates JUnitTest
's for each one.
- *
- * Of course, <junit>
and <batch>
elements
- * can be combined for more complex tests. For an example, see the ant build.xml
- * target run-tests
(the second example is an edited version).
- *
- * To spawn a new Java VM to prevent interferences between different testcases,
- * you need to enable fork
. A number of attributes and elements
- * allow you to set up how this JVM runs.
- *
- * {@link #setTimeout} property sets the maximum time allowed before a
- * test is 'timed out'
- * {@link #setMaxmemory} property sets memory assignment for the forked
- * jvm
- * {@link #setJvm} property allows the jvm to be specified
- * The <jvmarg>
element sets arguements to be passed
- * to the forked jvm
- *
- *
- *
- * @author Thomas Haas
- * @author Stefan Bodewig
- * @author Stephane Bailliez
- * @author Gerrit Riessen
- * @author Erik Hatcher
- * @see JUnitTest
- * @see BatchTest
- */
-public class JUnitTask extends AbstractTask
-{
-
- private CommandlineJava commandline = new CommandlineJava();
- private ArrayList tests = new ArrayList();
- private ArrayList batchTests = new ArrayList();
- private ArrayList formatters = new ArrayList();
- private File dir = null;
-
- private Integer timeout = null;
- private boolean summary = false;
- private String summaryValue = "";
- private JUnitTestRunner runner = null;
-
- /**
- * Creates a new JUnitRunner and enables fork of a new Java VM.
- *
- * @exception Exception Description of Exception
- */
- public JUnitTask()
- throws Exception
- {
- commandline.setClassname( "org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" );
- }
-
- /**
- * The directory to invoke the VM in. Ignored if no JVM is forked.
- *
- * @param dir the directory to invoke the JVM from.
- * @see #setFork(boolean)
- */
- public void setDir( File dir )
- {
- this.dir = dir;
- }
-
- /**
- * Tells this task to set the named property to "true" when there is a error
- * in a test. This property is applied on all BatchTest (batchtest) and
- * JUnitTest (test), however, it can possibly be overriden by their own
- * properties.
- *
- * @param propertyName The new ErrorProperty value
- */
- public void setErrorProperty( String propertyName )
- {
- Iterator enum = allTests();
- while( enum.hasNext() )
- {
- BaseTest test = (BaseTest)enum.next();
- test.setErrorProperty( propertyName );
- }
- }
-
- /**
- * Tells this task to set the named property to "true" when there is a
- * failure in a test. This property is applied on all BatchTest (batchtest)
- * and JUnitTest (test), however, it can possibly be overriden by their own
- * properties.
- *
- * @param propertyName The new FailureProperty value
- */
- public void setFailureProperty( String propertyName )
- {
- Iterator enum = allTests();
- while( enum.hasNext() )
- {
- BaseTest test = (BaseTest)enum.next();
- test.setFailureProperty( propertyName );
- }
- }
-
- /**
- * Tells this task whether to smartly filter the stack frames of JUnit
- * testcase errors and failures before reporting them. This property is
- * applied on all BatchTest (batchtest) and JUnitTest (test) however it can
- * possibly be overridden by their own properties.
- *
- * @param value false if it should not filter, otherwise true
- *
- */
- public void setFiltertrace( boolean value )
- {
- Iterator enum = allTests();
- while( enum.hasNext() )
- {
- BaseTest test = (BaseTest)enum.next();
- test.setFiltertrace( value );
- }
- }
-
- /**
- * Tells whether a JVM should be forked for each testcase. It avoids
- * interference between testcases and possibly avoids hanging the build.
- * this property is applied on all BatchTest (batchtest) and JUnitTest
- * (test) however it can possibly be overridden by their own properties.
- *
- * @param value true if a JVM should be forked, otherwise false
- *
- * @see #setTimeout
- */
- public void setFork( boolean value )
- {
- Iterator enum = allTests();
- while( enum.hasNext() )
- {
- BaseTest test = (BaseTest)enum.next();
- test.setFork( value );
- }
- }
-
- /**
- * Tells this task to halt when there is an error in a test. this property
- * is applied on all BatchTest (batchtest) and JUnitTest (test) however it
- * can possibly be overridden by their own properties.
- *
- * @param value true if it should halt, otherwise false
- */
- public void setHaltonerror( boolean value )
- {
- Iterator enum = allTests();
- while( enum.hasNext() )
- {
- BaseTest test = (BaseTest)enum.next();
- test.setHaltonerror( value );
- }
- }
-
- /**
- * Tells this task to halt when there is a failure in a test. this property
- * is applied on all BatchTest (batchtest) and JUnitTest (test) however it
- * can possibly be overridden by their own properties.
- *
- * @param value true if it should halt, otherwise false
- */
- public void setHaltonfailure( boolean value )
- {
- Iterator enum = allTests();
- while( enum.hasNext() )
- {
- BaseTest test = (BaseTest)enum.next();
- test.setHaltonfailure( value );
- }
- }
-
- /**
- * Set a new VM to execute the testcase. Default is java . Ignored
- * if no JVM is forked.
- *
- * @param value the new VM to use instead of java
- * @see #setFork(boolean)
- */
- public void setJvm( String value )
- {
- commandline.setVm( value );
- }
-
- /**
- * Set the maximum memory to be used by all forked JVMs.
- *
- * @param max the value as defined by -mx or -Xmx in the
- * java command line options.
- */
- public void setMaxmemory( String max )
- {
- commandline.addVmArgument( "-Xmx" + max );
- }
-
- /**
- * Tells whether the task should print a short summary of the task.
- *
- * @param value true to print a summary, withOutAndErr to
- * include the test's output as well, false otherwise.
- * @see SummaryJUnitResultFormatter
- */
- public void setPrintsummary( SummaryAttribute value )
- {
- summaryValue = value.getValue();
- summary = value.asBoolean();
- }
-
- /**
- * Set the timeout value (in milliseconds). If the test is running for more
- * than this value, the test will be canceled. (works only when in 'fork'
- * mode).
- *
- * @param value the maximum time (in milliseconds) allowed before declaring
- * the test as 'timed-out'
- * @see #setFork(boolean)
- */
- public void setTimeout( Integer value )
- {
- timeout = value;
- }
-
- /**
- * Add a new formatter to all tests of this task.
- *
- * @param fe The feature to be added to the Formatter attribute
- */
- public void addFormatter( FormatterElement fe )
- {
- formatters.add( fe );
- }
-
- /**
- * Add a nested sysproperty element. This might be useful to tranfer Ant
- * properties to the testcases when JVM forking is not enabled.
- *
- * @param sysp The feature to be added to the Sysproperty attribute
- */
- public void addSysproperty( EnvironmentVariable sysp )
- {
- commandline.addSysproperty( sysp );
- }
-
- /**
- * Add a new single testcase.
- *
- * @param test a new single testcase
- * @see JUnitTest
- */
- public void addTest( JUnitTest test )
- {
- tests.add( test );
- }
-
- /**
- * Create a new set of testcases (also called ..batchtest) and add it to the
- * list.
- *
- * @return a new instance of a batch test.
- * @see BatchTest
- */
- public BatchTest createBatchTest()
- {
- BatchTest test = new BatchTest();
- batchTests.add( test );
- return test;
- }
-
- /**
- * <classpath>
allows classpath to be set for tests.
- *
- * @return Description of the Returned Value
- */
- public Path createClasspath()
- {
- Path path1 = commandline.createClasspath();
- final Path path = new Path();
- path1.addPath( path );
- return path;
- }
-
- /**
- * Create a new JVM argument. Ignored if no JVM is forked.
- *
- * @see #setFork(boolean)
- */
- public void addJvmarg( final Argument argument )
- {
- commandline.addVmArgument( argument );
- }
-
- /**
- * Runs the testcase.
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- /*
- * Adds the jars or directories containing Ant, this task and JUnit to the
- * classpath - this should make the forked JVM work without having to
- * specify them directly.
- */
- addClasspathEntry( "/junit/framework/TestCase.class" );
- addClasspathEntry( "/org/apache/tools/ant/Task.class" );
- addClasspathEntry( "/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.class" );
-
- Iterator list = getIndividualTests();
- while( list.hasNext() )
- {
- JUnitTest test = (JUnitTest)list.next();
- final TaskContext context = getContext();
- if( test.shouldRun( context ) )
- {
- execute( test );
- }
- }
- }
-
- /**
- * Merge all individual tests from the batchtest with all individual tests
- * and return an enumeration over all JUnitTest .
- *
- * @return The IndividualTests value
- */
- protected Iterator getIndividualTests()
- throws TaskException
- {
- Iterator[] enums = new Iterator[ batchTests.size() + 1 ];
- for( int i = 0; i < batchTests.size(); i++ )
- {
- BatchTest batchtest = (BatchTest)batchTests.get( i );
- enums[ i ] = batchtest.iterator();
- }
- enums[ enums.length - 1 ] = tests.iterator();
- return new CompoundIterator( enums );
- }
-
- /**
- * return the file or null if does not use a file
- *
- * @param fe Description of Parameter
- * @param test Description of Parameter
- * @return The Output value
- */
- protected File getOutput( FormatterElement fe, JUnitTest test )
- throws TaskException
- {
- if( fe.getUseFile() )
- {
- String filename = test.getOutfile() + fe.getExtension();
- File destFile = new File( test.getTodir(), filename );
- final String absFilename = destFile.getAbsolutePath();
- return getContext().resolveFile( absFilename );
- }
- return null;
- }
-
- /**
- * Search for the given resource and add the directory or archive that
- * contains it to the classpath.
- *
- * Doesn't work for archives in JDK 1.1 as the URL returned by getResource
- * doesn't contain the name of the archive.
- *
- * @param resource The feature to be added to the ClasspathEntry attribute
- */
- protected void addClasspathEntry( String resource )
- {
- URL url = getClass().getResource( resource );
- if( url != null )
- {
- String u = url.toString();
- if( u.startsWith( "jar:file:" ) )
- {
- int pling = u.indexOf( "!" );
- String jarName = u.substring( 9, pling );
- getContext().debug( "Implicitly adding " + jarName + " to classpath" );
- createClasspath().addLocation( new File( jarName ) );
- }
- else if( u.startsWith( "file:" ) )
- {
- int tail = u.indexOf( resource );
- String dirName = u.substring( 5, tail );
- getContext().debug( "Implicitly adding " + dirName + " to classpath" );
- createClasspath().addLocation( new File( dirName ) );
- }
- else
- {
- getContext().debug( "Don\'t know how to handle resource URL " + u );
- }
- }
- else
- {
- getContext().debug( "Couldn\'t find " + resource );
- }
- }
-
- protected Iterator allTests()
- {
- Iterator[] enums = {tests.iterator(), batchTests.iterator()};
- return new CompoundIterator( enums );
- }
-
- /**
- * Run the tests.
- *
- * @param test Description of Parameter
- * @exception TaskException Description of Exception
- */
- protected void execute( JUnitTest test )
- throws TaskException
- {
- // set the default values if not specified
- //@todo should be moved to the test class instead.
- if( test.getTodir() == null )
- {
- test.setTodir( getBaseDirectory() );
- }
-
- if( test.getOutfile() == null )
- {
- test.setOutfile( "TEST-" + test.getName() );
- }
-
- // execute the test and get the return code
- int exitValue = JUnitTestRunner.ERRORS;
- boolean wasKilled = false;
- if( !test.getFork() )
- {
- exitValue = executeInVM( test );
- }
- else
- {
- exitValue = executeAsForked( test );
- }
-
- // if there is an error/failure and that it should halt, stop everything otherwise
- // just log a statement
- boolean errorOccurredHere = exitValue == JUnitTestRunner.ERRORS;
- boolean failureOccurredHere = exitValue != JUnitTestRunner.SUCCESS;
- if( errorOccurredHere || failureOccurredHere )
- {
- if( errorOccurredHere && test.getHaltonerror()
- || failureOccurredHere && test.getHaltonfailure() )
- {
- throw new TaskException( "Test " + test.getName() + " failed"
- + ( wasKilled ? " (timeout)" : "" ) );
- }
- else
- {
- final String message = "TEST " + test.getName() + " FAILED" +
- ( wasKilled ? " (timeout)" : "" );
- getContext().error( message );
- if( errorOccurredHere && test.getErrorProperty() != null )
- {
- final String name = test.getErrorProperty();
- getContext().setProperty( name, "true" );
- }
- if( failureOccurredHere && test.getFailureProperty() != null )
- {
- final String name = test.getFailureProperty();
- getContext().setProperty( name, "true" );
- }
- }
- }
- }
-
- protected void handleErrorOutput( String line )
- {
- if( runner != null )
- {
- runner.handleErrorOutput( line );
- }
- else
- {
- //super.handleErrorOutput( line );
- }
- }
-
- // in VM is not very nice since it could probably hang the
- // whole build. IMHO this method should be avoided and it would be best
- // to remove it in future versions. TBD. (SBa)
-
-
- protected void handleOutput( String line )
- {
- if( runner != null )
- {
- runner.handleOutput( line );
- }
- else
- {
- //super.handleOutput( line );
- }
- }
-
- /**
- * Execute a testcase by forking a new JVM. The command will block until it
- * finishes. To know if the process was destroyed or not, use the
- * killedProcess() method of the watchdog class.
- *
- * @param test the testcase to execute.
- */
- private int executeAsForked( JUnitTest test )
- throws TaskException
- {
- CommandlineJava cmd = commandline;//(CommandlineJava)commandline.clone();
-
- cmd.setClassname( "org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" );
- cmd.addArgument( test.getName() );
- cmd.addArgument( "filtertrace=" + test.getFiltertrace() );
- cmd.addArgument( "haltOnError=" + test.getHaltonerror() );
- cmd.addArgument( "haltOnFailure=" + test.getHaltonfailure() );
- if( summary )
- {
- getContext().info( "Running " + test.getName() );
- cmd.addArgument( "formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter" );
- }
-
- StringBuffer formatterArg = new StringBuffer( 128 );
- final FormatterElement[] feArray = mergeFormatters( test );
- for( int i = 0; i < feArray.length; i++ )
- {
- FormatterElement fe = feArray[ i ];
- formatterArg.append( "formatter=" );
- formatterArg.append( fe.getClassname() );
- File outFile = getOutput( fe, test );
- if( outFile != null )
- {
- formatterArg.append( "," );
- formatterArg.append( outFile );
- }
- cmd.addArgument( formatterArg.toString() );
- formatterArg.setLength( 0 );
- }
-
- // Create a temporary file to pass the Ant properties to the forked test
- File propsFile = new File( "junit" + ( new Random( System.currentTimeMillis() ) ).nextLong() + ".properties" );
- cmd.addArgument( "propsfile=" + propsFile.getAbsolutePath() );
- Map p = getContext().getProperties();
- Properties props = new Properties();
- for( Iterator enum = p.keySet().iterator(); enum.hasNext(); )
- {
- final Object key = enum.next();
- props.put( key, p.get( key ) );
- }
- try
- {
- final FileOutputStream outstream = new FileOutputStream( propsFile );
- props.save( outstream, "Ant JUnitTask generated properties file" );
- outstream.close();
- }
- catch( IOException ioe )
- {
- throw new TaskException( "Error creating temporary properties file.", ioe );
- }
-
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
- exe.setCommandline( new Commandline( cmd.getCommandline() ) );
- if( dir != null )
- {
- exe.setWorkingDirectory( dir );
- }
-
- getContext().debug( "Executing: " + cmd.toString() );
- try
- {
- return exe.execute();
- }
- finally
- {
- if( !propsFile.delete() )
- {
- throw new TaskException( "Could not delete temporary properties file." );
- }
- }
- }
-
- /**
- * Execute inside VM.
- */
- private int executeInVM( JUnitTest test )
- throws TaskException
- {
- test.setProperties( getContext().getProperties() );
- if( dir != null )
- {
- getContext().warn( "dir attribute ignored if running in the same VM" );
- }
-
- SysProperties sysProperties = commandline.getSystemProperties();
- if( sysProperties != null )
- {
- sysProperties.setSystem();
- }
- try
- {
- getContext().debug( "Using System properties " + System.getProperties() );
- ClassLoader classLoader = null;
- Path classpath = commandline.getClasspath();
- if( classpath != null )
- {
- getContext().debug( "Using CLASSPATH " + classpath );
- final URL[] urls = PathUtil.toURLs( classpath );
- classLoader = new URLClassLoader( urls );
- }
- runner = new JUnitTestRunner( test,
- test.getHaltonerror(),
- test.getFiltertrace(),
- test.getHaltonfailure(),
- classLoader );
- if( summary )
- {
- getContext().info( "Running " + test.getName() );
-
- SummaryJUnitResultFormatter f =
- new SummaryJUnitResultFormatter();
- f.setWithOutAndErr( "withoutanderr".equalsIgnoreCase( summaryValue ) );
- f.setOutput( System.out );
- runner.addFormatter( f );
- }
-
- final FormatterElement[] feArray = mergeFormatters( test );
- for( int i = 0; i < feArray.length; i++ )
- {
- FormatterElement fe = feArray[ i ];
- File outFile = getOutput( fe, test );
- if( outFile != null )
- {
- fe.setOutfile( outFile );
- }
- else
- {
- fe.setOutput( System.out );
- }
- runner.addFormatter( fe.createFormatter() );
- }
-
- runner.run();
- return runner.getRetCode();
- }
- finally
- {
- if( sysProperties != null )
- {
- sysProperties.restoreSystem();
- }
- }
- }
-
- private FormatterElement[] mergeFormatters( JUnitTest test )
- {
- final ArrayList feArrayList = (ArrayList)formatters.clone();
- test.addFormattersTo( feArrayList );
- return (FormatterElement[])feArrayList.toArray( new FormatterElement[ feArrayList.size() ] );
- }
-
- /**
- * Print summary enumeration values.
- *
- * @author RT
- */
- public static class SummaryAttribute extends EnumeratedAttribute
- {
- public String[] getValues()
- {
- return new String[]{"true", "yes", "false", "no",
- "on", "off", "withOutAndErr"};
- }
-
- public boolean asBoolean()
- {
- final String value = getValue();
- return "true".equals( value ) ||
- "on".equals( value ) ||
- "yes".equals( value ) ||
- "withOutAndErr".equals( value );
- }
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/JUnitTest.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/JUnitTest.java
deleted file mode 100644
index 87d457e53..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/JUnitTest.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-import org.apache.myrmidon.api.TaskContext;
-
-/**
- *
- *
- * Run a single JUnit test.
- *
- * The JUnit test is actually run by {@link JUnitTestRunner}. So read the doc
- * comments for that class :)
- *
- * @author Thomas Haas
- * @author Stefan Bodewig ,
- * @author Stephane Bailliez
- * @see JUnitTask
- * @see JUnitTestRunner
- */
-public class JUnitTest extends BaseTest
-{
- /**
- * the name of the test case
- */
- private String m_name;
-
- /**
- * the name of the result file
- */
- private String m_outfile;
-
- // Snapshot of the system properties
- private Properties m_props;
-
- private long m_runTime;
-
- // @todo this is duplicating TestResult information. Only the time is not
- // part of the result. So we'd better derive a new class from TestResult
- // and deal with it. (SB)
- private long m_runs;
- private long m_failures;
- private long m_errors;
-
- public JUnitTest()
- {
- }
-
- public JUnitTest( String name )
- {
- m_name = name;
- }
-
- public JUnitTest( final String name,
- final boolean haltOnError,
- final boolean haltOnFailure,
- final boolean filtertrace )
- {
- m_name = name;
- m_haltOnError = haltOnError;
- m_haltOnFail = haltOnFailure;
- m_filtertrace = filtertrace;
- }
-
- public void setCounts( long runs, long failures, long errors )
- {
- m_runs = runs;
- m_failures = failures;
- m_errors = errors;
- }
-
- /**
- * Set the name of the test class.
- */
- public void setName( final String value )
- {
- m_name = value;
- }
-
- /**
- * Set the name of the output file.
- */
- public void setOutfile( final String value )
- {
- m_outfile = value;
- }
-
- public void setProperties( final Map properties )
- {
- m_props = new Properties();
- final Iterator enum = properties.keySet().iterator();
- while( enum.hasNext() )
- {
- final Object key = enum.next();
- final Object value = properties.get( key );
- m_props.put( key, value );
- }
- }
-
- public void setRunTime( final long runTime )
- {
- m_runTime = runTime;
- }
-
- public FormatterElement[] getFormatters()
- {
- return (FormatterElement[])formatters.toArray( new FormatterElement[ formatters.size() ] );
- }
-
- /**
- * Get the name of the test class.
- *
- * @return The Name value
- */
- public String getName()
- {
- return m_name;
- }
-
- /**
- * Get the name of the output file
- *
- * @return the name of the output file.
- */
- public String getOutfile()
- {
- return m_outfile;
- }
-
- public Properties getProperties()
- {
- return m_props;
- }
-
- public long getRunTime()
- {
- return m_runTime;
- }
-
- public long errorCount()
- {
- return m_errors;
- }
-
- public long failureCount()
- {
- return m_failures;
- }
-
- public long runCount()
- {
- return m_runs;
- }
-
- public boolean shouldRun( final TaskContext context )
- {
- if( ifProperty != null && context.getProperty( ifProperty ) == null )
- {
- return false;
- }
- else if( unlessProperty != null &&
- context.getProperty( unlessProperty ) != null )
- {
- return false;
- }
-
- return true;
- }
-
- /**
- * Convenient method to add formatters to a vector
- */
- void addFormattersTo( ArrayList v )
- {
- v.addAll( formatters );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/JUnitTestRunner.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/JUnitTestRunner.java
deleted file mode 100644
index 6910a74ce..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/JUnitTestRunner.java
+++ /dev/null
@@ -1,643 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.Properties;
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import junit.framework.TestListener;
-import junit.framework.TestResult;
-import junit.framework.TestSuite;
-import org.apache.avalon.framework.ExceptionUtil;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * Simple Testrunner for JUnit that runs all tests of a testsuite.
- *
- * This TestRunner expects a name of a TestCase class as its argument. If this
- * class provides a static suite() method it will be called and the resulting
- * Test will be run. So, the signature should be
- * public static junit.framework.Test suite()
- *
- *
- * If no such method exists, all public methods starting with "test" and taking
- * no argument will be run.
- *
- * Summary output is generated at the end.
- *
- * @author Stefan Bodewig
- * @author Erik Hatcher
- */
-public class JUnitTestRunner
- implements TestListener
-{
- /**
- * No problems with this test.
- */
- public final static int SUCCESS = 0;
-
- /**
- * Some tests failed.
- */
- public final static int FAILURES = 1;
-
- /**
- * An error occured.
- */
- public final static int ERRORS = 2;
-
- /**
- * Do we filter junit.*.* stack frames out of failure and error exceptions.
- */
- private static boolean filtertrace = true;
-
- private final static String[] DEFAULT_TRACE_FILTERS = new String[]
- {
- "junit.framework.TestCase",
- "junit.framework.TestResult",
- "junit.framework.TestSuite",
- "junit.framework.Assert.", // don't filter AssertionFailure
- "junit.swingui.TestRunner",
- "junit.awtui.TestRunner",
- "junit.textui.TestRunner",
- "java.lang.reflect.Method.invoke(",
- "org.apache.tools.ant."
- };
-
- private static ArrayList m_fromCmdLine = new ArrayList();
-
- /**
- * Holds the registered formatters.
- */
- private ArrayList m_formatters = new ArrayList();
-
- /**
- * Do we stop on errors.
- */
- private boolean m_haltOnError;
-
- /**
- * Do we stop on test failures.
- */
- private boolean m_haltOnFailure;
-
- /**
- * The corresponding testsuite.
- */
- private Test m_suite;
-
- /**
- * Returncode
- */
- private int m_retCode = SUCCESS;
-
- /**
- * Exception caught in constructor.
- */
- private Exception m_exception;
-
- /**
- * The TestSuite we are currently running.
- */
- private JUnitTest m_junitTest;
-
- /**
- * Collects TestResults.
- */
- private TestResult m_res;
-
- /**
- * output written during the test
- */
- private PrintStream m_systemError;
-
- /**
- * Error output during the test
- */
- private PrintStream m_systemOut;
-
- /**
- * Constructor for fork=true or when the user hasn't specified a classpath.
- *
- * @param test Description of Parameter
- * @param haltOnError Description of Parameter
- * @param filtertrace Description of Parameter
- * @param haltOnFailure Description of Parameter
- */
- public JUnitTestRunner( final JUnitTest test,
- final boolean haltOnError,
- final boolean filtertrace,
- final boolean haltOnFailure )
- {
- this( test, haltOnError, filtertrace, haltOnFailure, null );
- }
-
- /**
- * Constructor to use when the user has specified a classpath.
- *
- * @param test Description of Parameter
- * @param haltOnError Description of Parameter
- * @param filtertrace Description of Parameter
- * @param haltOnFailure Description of Parameter
- * @param loader Description of Parameter
- */
- public JUnitTestRunner( JUnitTest test, boolean haltOnError, boolean filtertrace,
- boolean haltOnFailure, ClassLoader loader )
- {
- //JUnitTestRunner.filtertrace = filtertrace;
- this.filtertrace = filtertrace;
- this.m_junitTest = test;
- this.m_haltOnError = haltOnError;
- this.m_haltOnFailure = haltOnFailure;
-
- try
- {
- Class testClass = null;
- if( loader == null )
- {
- testClass = Class.forName( test.getName() );
- }
- else
- {
- testClass = loader.loadClass( test.getName() );
- }
-
- Method suiteMethod = null;
- try
- {
- // check if there is a suite method
- suiteMethod = testClass.getMethod( "suite", new Class[ 0 ] );
- }
- catch( Exception e )
- {
- // no appropriate suite method found. We don't report any
- // error here since it might be perfectly normal. We don't
- // know exactly what is the cause, but we're doing exactly
- // the same as JUnit TestRunner do. We swallow the exceptions.
- }
- if( suiteMethod != null )
- {
- // if there is a suite method available, then try
- // to extract the suite from it. If there is an error
- // here it will be caught below and reported.
- m_suite = (Test)suiteMethod.invoke( null, new Class[ 0 ] );
- }
- else
- {
- // try to extract a test suite automatically
- // this will generate warnings if the class is no suitable Test
- m_suite = new TestSuite( testClass );
- }
-
- }
- catch( Exception e )
- {
- m_retCode = ERRORS;
- m_exception = e;
- }
- }
-
- /**
- * Returns a filtered stack trace. This is ripped out of
- * junit.runner.BaseTestRunner. Scott M. Stirling.
- *
- * @param t Description of Parameter
- * @return The FilteredTrace value
- */
- public static String getFilteredTrace( Throwable t )
- {
- final String trace = ExceptionUtil.printStackTrace( t );
- return JUnitTestRunner.filterStack( trace );
- }
-
- /**
- * Filters stack frames from internal JUnit and Ant classes
- *
- * @param stack Description of Parameter
- * @return Description of the Returned Value
- */
- public static String filterStack( String stack )
- {
- if( !filtertrace )
- {
- return stack;
- }
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter( sw );
- StringReader sr = new StringReader( stack );
- BufferedReader br = new BufferedReader( sr );
-
- String line;
- try
- {
- while( ( line = br.readLine() ) != null )
- {
- if( !filterLine( line ) )
- {
- pw.println( line );
- }
- }
- }
- catch( Exception IOException )
- {
- return stack;// return the stack unfiltered
- }
- return sw.toString();
- }
-
- /**
- * Entry point for standalone (forked) mode. Parameters: testcaseclassname
- * plus parameters in the format key=value, none of which is required.
- *
- *
- *
- *
- *
- *
- * key
- *
- *
- *
- * description
- *
- *
- *
- * default value
- *
- *
- *
- *
- *
- *
- *
- * haltOnError
- *
- *
- *
- * halt test on errors?
- *
- *
- *
- * false
- *
- *
- *
- *
- *
- *
- *
- * haltOnFailure
- *
- *
- *
- * halt test on failures?
- *
- *
- *
- * false
- *
- *
- *
- *
- *
- *
- *
- * formatter
- *
- *
- *
- * A JUnitResultFormatter given as classname,filename. If filename is
- * ommitted, System.out is assumed.
- *
- *
- *
- * none
- *
- *
- *
- *
- *
- *
- *
- * @param args The command line arguments
- * @exception IOException Description of Exception
- */
- public static void main( String[] args )
- throws IOException, TaskException
- {
- boolean exitAtEnd = true;
- boolean haltError = false;
- boolean haltFail = false;
- boolean stackfilter = true;
- Properties props = new Properties();
-
- if( args.length == 0 )
- {
- System.err.println( "required argument TestClassName missing" );
- System.exit( ERRORS );
- }
-
- for( int i = 1; i < args.length; i++ )
- {
- if( args[ i ].startsWith( "haltOnError=" ) )
- {
- haltError = "true".equals( args[ i ].substring( 12 ) );
- }
- else if( args[ i ].startsWith( "haltOnFailure=" ) )
- {
- haltFail = "true".equals( args[ i ].substring( 14 ) );
- }
- else if( args[ i ].startsWith( "filtertrace=" ) )
- {
- stackfilter = "true".equals( args[ i ].substring( 12 ) );
- }
- else if( args[ i ].startsWith( "formatter=" ) )
- {
- try
- {
- createAndStoreFormatter( args[ i ].substring( 10 ) );
- }
- catch( TaskException be )
- {
- System.err.println( be.getMessage() );
- System.exit( ERRORS );
- }
- }
- else if( args[ i ].startsWith( "propsfile=" ) )
- {
- FileInputStream in = new FileInputStream( args[ i ].substring( 10 ) );
- props.load( in );
- in.close();
- }
- }
-
- JUnitTest t = new JUnitTest( args[ 0 ] );
-
- // Add/overlay system properties on the properties from the Ant project
- Hashtable p = System.getProperties();
- props.putAll( p );
- t.setProperties( props );
-
- JUnitTestRunner runner = new JUnitTestRunner( t, haltError, stackfilter, haltFail );
- transferFormatters( runner );
- runner.run();
- System.exit( runner.getRetCode() );
- }
-
- /**
- * Line format is: formatter=(,
- *
- * )?
- *
- * @param line Description of Parameter
- * @exception TaskException Description of Exception
- */
- private static void createAndStoreFormatter( String line )
- throws TaskException
- {
- FormatterElement fe = new FormatterElement();
- int pos = line.indexOf( ',' );
- if( pos == -1 )
- {
- fe.setClassname( line );
- }
- else
- {
- fe.setClassname( line.substring( 0, pos ) );
- fe.setOutfile( new File( line.substring( pos + 1 ) ) );
- }
- m_fromCmdLine.add( fe.createFormatter() );
- }
-
- private static boolean filterLine( String line )
- {
- for( int i = 0; i < DEFAULT_TRACE_FILTERS.length; i++ )
- {
- if( line.indexOf( DEFAULT_TRACE_FILTERS[ i ] ) > 0 )
- {
- return true;
- }
- }
- return false;
- }
-
- private static void transferFormatters( JUnitTestRunner runner )
- {
- for( int i = 0; i < m_fromCmdLine.size(); i++ )
- {
- runner.addFormatter( (JUnitResultFormatter)m_fromCmdLine.get( i ) );
- }
- }
-
- /**
- * Returns what System.exit() would return in the standalone version.
- *
- * @return 2 if errors occurred, 1 if tests failed else 0.
- */
- public int getRetCode()
- {
- return m_retCode;
- }
-
- /**
- * Interface TestListener.
- *
- * An error occured while running the test.
- *
- * @param test The feature to be added to the Error attribute
- * @param t The feature to be added to the Error attribute
- */
- public void addError( Test test, Throwable t )
- {
- if( m_haltOnError )
- {
- m_res.stop();
- }
- }
-
- /**
- * Interface TestListener for JUnit <= 3.4.
- *
- * A Test failed.
- *
- * @param test The feature to be added to the Failure attribute
- * @param t The feature to be added to the Failure attribute
- */
- public void addFailure( Test test, Throwable t )
- {
- if( m_haltOnFailure )
- {
- m_res.stop();
- }
- }
-
- /**
- * Interface TestListener for JUnit > 3.4.
- *
- * A Test failed.
- *
- * @param test The feature to be added to the Failure attribute
- * @param t The feature to be added to the Failure attribute
- */
- public void addFailure( Test test, AssertionFailedError t )
- {
- addFailure( test, (Throwable)t );
- }
-
- public void addFormatter( JUnitResultFormatter f )
- {
- m_formatters.add( f );
- }
-
- /**
- * Interface TestListener.
- *
- * A Test is finished.
- *
- * @param test Description of Parameter
- */
- public void endTest( Test test )
- {
- }
-
- public void run()
- throws TaskException
- {
- m_res = new TestResult();
- m_res.addListener( this );
- for( int i = 0; i < m_formatters.size(); i++ )
- {
- final TestListener listener = (TestListener)m_formatters.get( i );
- m_res.addListener( listener );
- }
-
- long start = System.currentTimeMillis();
-
- fireStartTestSuite();
- if( m_exception != null )
- {// had an exception in the constructor
- for( int i = 0; i < m_formatters.size(); i++ )
- {
- ( (TestListener)m_formatters.get( i ) ).addError( null,
- m_exception );
- }
- m_junitTest.setCounts( 1, 0, 1 );
- m_junitTest.setRunTime( 0 );
- }
- else
- {
-
- ByteArrayOutputStream errStrm = new ByteArrayOutputStream();
- m_systemError = new PrintStream( errStrm );
-
- ByteArrayOutputStream outStrm = new ByteArrayOutputStream();
- m_systemOut = new PrintStream( outStrm );
-
- try
- {
- m_suite.run( m_res );
- }
- finally
- {
- m_systemError.close();
- m_systemError = null;
- m_systemOut.close();
- m_systemOut = null;
- sendOutAndErr( new String( outStrm.toByteArray() ),
- new String( errStrm.toByteArray() ) );
-
- m_junitTest.setCounts( m_res.runCount(), m_res.failureCount(),
- m_res.errorCount() );
- m_junitTest.setRunTime( System.currentTimeMillis() - start );
- }
- }
- fireEndTestSuite();
-
- if( m_retCode != SUCCESS || m_res.errorCount() != 0 )
- {
- m_retCode = ERRORS;
- }
- else if( m_res.failureCount() != 0 )
- {
- m_retCode = FAILURES;
- }
- }
-
- /**
- * Interface TestListener.
- *
- * A new Test is started.
- */
- public void startTest( Test t )
- {
- }
-
- protected void handleErrorOutput( String line )
- {
- if( m_systemError != null )
- {
- m_systemError.println( line );
- }
- }
-
- protected void handleOutput( String line )
- {
- if( m_systemOut != null )
- {
- m_systemOut.println( line );
- }
- }
-
- private void fireEndTestSuite()
- throws TaskException
- {
- final int size = m_formatters.size();
- for( int i = 0; i < size; i++ )
- {
- final JUnitResultFormatter formatter =
- (JUnitResultFormatter)m_formatters.get( i );
- formatter.endTestSuite( m_junitTest );
- }
- }
-
- private void fireStartTestSuite()
- throws TaskException
- {
- final int size = m_formatters.size();
- for( int i = 0; i < size; i++ )
- {
- final JUnitResultFormatter formatter = (JUnitResultFormatter)m_formatters.get( i );
- formatter.startTestSuite( m_junitTest );
- }
- }
-
- private void sendOutAndErr( String out, String err )
- {
- final int size = m_formatters.size();
- for( int i = 0; i < size; i++ )
- {
- final JUnitResultFormatter formatter =
- (JUnitResultFormatter)m_formatters.get( i );
-
- formatter.setSystemOutput( out );
- formatter.setSystemError( err );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/JUnitVersionHelper.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/JUnitVersionHelper.java
deleted file mode 100644
index 9bfe0a4a1..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/JUnitVersionHelper.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.lang.reflect.Method;
-import junit.framework.Test;
-import junit.framework.TestCase;
-
-/**
- * Work around for some changes to the public JUnit API between different JUnit
- * releases.
- *
- * @author Stefan Bodewig
- * @version $Revision$
- */
-public class JUnitVersionHelper
-{
-
- private static Method testCaseName = null;
-
- static
- {
- try
- {
- testCaseName = TestCase.class.getMethod( "getName", new Class[ 0 ] );
- }
- catch( NoSuchMethodException e )
- {
- // pre JUnit 3.7
- try
- {
- testCaseName = TestCase.class.getMethod( "name", new Class[ 0 ] );
- }
- catch( NoSuchMethodException e2 )
- {
- }
- }
- }
-
- /**
- * JUnit 3.7 introduces TestCase.getName() and subsequent versions of JUnit
- * remove the old name() method. This method provides access to the name of
- * a TestCase via reflection that is supposed to work with version before
- * and after JUnit 3.7.
- *
- * @param t Description of Parameter
- * @return The TestCaseName value
- */
- public static String getTestCaseName( Test t )
- {
- if( t instanceof TestCase && testCaseName != null )
- {
- try
- {
- return (String)testCaseName.invoke( t, new Object[ 0 ] );
- }
- catch( Throwable e )
- {
- }
- }
- return "unknown";
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/NodeListImpl.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/NodeListImpl.java
deleted file mode 100644
index a2f7f1368..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/NodeListImpl.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.util.ArrayList;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * custom implementation of a nodelist
- */
-public class NodeListImpl
- extends ArrayList
- implements NodeList
-{
- public int getLength()
- {
- return size();
- }
-
- public Node item( final int i )
- {
- try
- {
- return (Node)get( i );
- }
- catch( final ArrayIndexOutOfBoundsException aioobe )
- {
- return null;// conforming to NodeList interface
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/PlainJUnitResultFormatter.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/PlainJUnitResultFormatter.java
deleted file mode 100644
index 41ca0f71f..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/PlainJUnitResultFormatter.java
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.text.NumberFormat;
-import java.util.Hashtable;
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import org.apache.avalon.excalibur.util.StringUtil;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * Prints plain text output of the test to a specified Writer.
- *
- * @author Stefan Bodewig
- */
-
-public class PlainJUnitResultFormatter implements JUnitResultFormatter
-{
-
- /**
- * Formatter for timings.
- */
- private NumberFormat nf = NumberFormat.getInstance();
- /**
- * Timing helper.
- */
- private Hashtable testStarts = new Hashtable();
- /**
- * Suppress endTest if testcase failed.
- */
- private Hashtable failed = new Hashtable();
-
- private String systemOutput = null;
- private String systemError = null;
- /**
- * Helper to store intermediate output.
- */
- private StringWriter inner;
- /**
- * Where to write the log to.
- */
- private OutputStream out;
- /**
- * Convenience layer on top of {@link #inner inner}.
- */
- private PrintWriter wri;
-
- public PlainJUnitResultFormatter()
- {
- inner = new StringWriter();
- wri = new PrintWriter( inner );
- }
-
- public void setOutput( OutputStream out )
- {
- this.out = out;
- }
-
- public void setSystemError( String err )
- {
- systemError = err;
- }
-
- public void setSystemOutput( String out )
- {
- systemOutput = out;
- }
-
- /**
- * Interface TestListener.
- *
- * An error occured while running the test.
- *
- * @param test The feature to be added to the Error attribute
- * @param t The feature to be added to the Error attribute
- */
- public void addError( Test test, Throwable t )
- {
- formatError( "\tCaused an ERROR", test, t );
- }
-
- /**
- * Interface TestListener for JUnit <= 3.4.
- *
- * A Test failed.
- *
- * @param test The feature to be added to the Failure attribute
- * @param t The feature to be added to the Failure attribute
- */
- public void addFailure( Test test, Throwable t )
- {
- formatError( "\tFAILED", test, t );
- }
-
- /**
- * Interface TestListener for JUnit > 3.4.
- *
- * A Test failed.
- *
- * @param test The feature to be added to the Failure attribute
- * @param t The feature to be added to the Failure attribute
- */
- public void addFailure( Test test, AssertionFailedError t )
- {
- addFailure( test, (Throwable)t );
- }
-
- /**
- * Interface TestListener.
- *
- * A Test is finished.
- *
- * @param test Description of Parameter
- */
- public void endTest( Test test )
- {
- synchronized( wri )
- {
- wri.print( "Testcase: "
- + JUnitVersionHelper.getTestCaseName( test ) );
- if( Boolean.TRUE.equals( failed.get( test ) ) )
- {
- return;
- }
- Long l = (Long)testStarts.get( test );
- wri.println( " took "
- + nf.format( ( System.currentTimeMillis() - l.longValue() )
- / 1000.0 )
- + " sec" );
- }
- }
-
- /**
- * The whole testsuite ended.
- */
- public void endTestSuite( JUnitTest suite )
- throws TaskException
- {
- StringBuffer sb = new StringBuffer( "Testsuite: " );
- sb.append( suite.getName() );
- sb.append( StringUtil.LINE_SEPARATOR );
- sb.append( "Tests run: " );
- sb.append( suite.runCount() );
- sb.append( ", Failures: " );
- sb.append( suite.failureCount() );
- sb.append( ", Errors: " );
- sb.append( suite.errorCount() );
- sb.append( ", Time elapsed: " );
- sb.append( nf.format( suite.getRunTime() / 1000.0 ) );
- sb.append( " sec" );
- sb.append( StringUtil.LINE_SEPARATOR );
-
- // append the err and output streams to the log
- if( systemOutput != null && systemOutput.length() > 0 )
- {
- sb.append( "------------- Standard Output ---------------" )
- .append( StringUtil.LINE_SEPARATOR )
- .append( systemOutput )
- .append( "------------- ---------------- ---------------" )
- .append( StringUtil.LINE_SEPARATOR );
- }
-
- if( systemError != null && systemError.length() > 0 )
- {
- sb.append( "------------- Standard Error -----------------" )
- .append( StringUtil.LINE_SEPARATOR )
- .append( systemError )
- .append( "------------- ---------------- ---------------" )
- .append( StringUtil.LINE_SEPARATOR );
- }
-
- sb.append( StringUtil.LINE_SEPARATOR );
-
- if( out != null )
- {
- try
- {
- out.write( sb.toString().getBytes() );
- wri.close();
- out.write( inner.toString().getBytes() );
- out.flush();
- }
- catch( IOException ioex )
- {
- throw new TaskException( "Unable to write output", ioex );
- }
- finally
- {
- if( out != System.out && out != System.err )
- {
- try
- {
- out.close();
- }
- catch( IOException e )
- {
- }
- }
- }
- }
- }
-
- /**
- * Interface TestListener.
- *
- * A new Test is started.
- *
- * @param t Description of Parameter
- */
- public void startTest( Test t )
- {
- testStarts.put( t, new Long( System.currentTimeMillis() ) );
- failed.put( t, Boolean.FALSE );
- }
-
- /**
- * Empty.
- *
- * @param suite Description of Parameter
- */
- public void startTestSuite( JUnitTest suite )
- {
- }
-
- private void formatError( String type, Test test, Throwable t )
- {
- synchronized( wri )
- {
- if( test != null )
- {
- endTest( test );
- failed.put( test, Boolean.TRUE );
- }
-
- wri.println( type );
- wri.println( t.getMessage() );
- String strace = JUnitTestRunner.getFilteredTrace( t );
- wri.print( strace );
- wri.println( "" );
- }
- }
-
-}// PlainJUnitResultFormatter
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/SummaryJUnitResultFormatter.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/SummaryJUnitResultFormatter.java
deleted file mode 100644
index 62ecdaf9d..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/SummaryJUnitResultFormatter.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.text.NumberFormat;
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import org.apache.avalon.excalibur.util.StringUtil;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * Prints short summary output of the test to Ant's logging system.
- *
- * @author Stefan Bodewig
- */
-
-public class SummaryJUnitResultFormatter implements JUnitResultFormatter
-{
-
- /**
- * Formatter for timings.
- */
- private NumberFormat nf = NumberFormat.getInstance();
-
- private boolean withOutAndErr = false;
- private String systemOutput = null;
- private String systemError = null;
- /**
- * OutputStream to write to.
- */
- private OutputStream out;
-
- /**
- * Empty
- */
- public SummaryJUnitResultFormatter()
- {
- }
-
- public void setOutput( OutputStream out )
- {
- this.out = out;
- }
-
- public void setSystemError( String err )
- {
- systemError = err;
- }
-
- public void setSystemOutput( String out )
- {
- systemOutput = out;
- }
-
- /**
- * Should the output to System.out and System.err be written to the summary.
- *
- * @param value The new WithOutAndErr value
- */
- public void setWithOutAndErr( boolean value )
- {
- withOutAndErr = value;
- }
-
- /**
- * Empty
- *
- * @param test The feature to be added to the Error attribute
- * @param t The feature to be added to the Error attribute
- */
- public void addError( Test test, Throwable t )
- {
- }
-
- /**
- * Empty
- *
- * @param test The feature to be added to the Failure attribute
- * @param t The feature to be added to the Failure attribute
- */
- public void addFailure( Test test, Throwable t )
- {
- }
-
- /**
- * Interface TestListener for JUnit > 3.4.
- *
- * A Test failed.
- *
- * @param test The feature to be added to the Failure attribute
- * @param t The feature to be added to the Failure attribute
- */
- public void addFailure( Test test, AssertionFailedError t )
- {
- addFailure( test, (Throwable)t );
- }
-
- /**
- * Empty
- *
- * @param test Description of Parameter
- */
- public void endTest( Test test )
- {
- }
-
- /**
- * The whole testsuite ended.
- *
- * @param suite Description of Parameter
- * @exception TaskException Description of Exception
- */
- public void endTestSuite( JUnitTest suite )
- throws TaskException
- {
- StringBuffer sb = new StringBuffer( "Tests run: " );
- sb.append( suite.runCount() );
- sb.append( ", Failures: " );
- sb.append( suite.failureCount() );
- sb.append( ", Errors: " );
- sb.append( suite.errorCount() );
- sb.append( ", Time elapsed: " );
- sb.append( nf.format( suite.getRunTime() / 1000.0 ) );
- sb.append( " sec" );
- sb.append( StringUtil.LINE_SEPARATOR );
-
- if( withOutAndErr )
- {
- if( systemOutput != null && systemOutput.length() > 0 )
- {
- sb.append( "Output:" ).append( StringUtil.LINE_SEPARATOR ).append( systemOutput )
- .append( StringUtil.LINE_SEPARATOR );
- }
-
- if( systemError != null && systemError.length() > 0 )
- {
- sb.append( "Error: " ).append( StringUtil.LINE_SEPARATOR ).append( systemError )
- .append( StringUtil.LINE_SEPARATOR );
- }
- }
-
- try
- {
- out.write( sb.toString().getBytes() );
- out.flush();
- }
- catch( IOException ioex )
- {
- throw new TaskException( "Unable to write summary output", ioex );
- }
- finally
- {
- if( out != System.out && out != System.err )
- {
- try
- {
- out.close();
- }
- catch( IOException e )
- {
- }
- }
- }
- }
-
- /**
- * Empty
- *
- * @param t Description of Parameter
- */
- public void startTest( Test t )
- {
- }
-
- /**
- * Empty
- *
- * @param suite Description of Parameter
- */
- public void startTestSuite( JUnitTest suite )
- {
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/XMLConstants.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/XMLConstants.java
deleted file mode 100644
index 1421c6dd8..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/XMLConstants.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-/**
- *
- *
- * Interface groups XML constants. Interface that groups all constants used
- * throughout the XML documents that are generated by the
- * XMLJUnitResultFormatter As of now the DTD is:
- * <-----------------
- *
- * @author Stephane Bailliez
- * @see XMLJUnitResultFormatter
- * @see XMLResultAggregator
- * @todo describe DTDs ---------------------->
- */
-public interface XMLConstants
-{
- /**
- * the testsuites element for the aggregate document
- */
- String TESTSUITES = "testsuites";
-
- /**
- * the testsuite element
- */
- String TESTSUITE = "testsuite";
-
- /**
- * the testcase element
- */
- String TESTCASE = "testcase";
-
- /**
- * the error element
- */
- String ERROR = "error";
-
- /**
- * the failure element
- */
- String FAILURE = "failure";
-
- /**
- * the system-err element
- */
- String SYSTEM_ERR = "system-err";
-
- /**
- * the system-out element
- */
- String SYSTEM_OUT = "system-out";
-
- /**
- * package attribute for the aggregate document
- */
- String ATTR_PACKAGE = "package";
-
- /**
- * name attribute for property, testcase and testsuite elements
- */
- String ATTR_NAME = "name";
-
- /**
- * time attribute for testcase and testsuite elements
- */
- String ATTR_TIME = "time";
-
- /**
- * errors attribute for testsuite elements
- */
- String ATTR_ERRORS = "errors";
-
- /**
- * failures attribute for testsuite elements
- */
- String ATTR_FAILURES = "failures";
-
- /**
- * tests attribute for testsuite elements
- */
- String ATTR_TESTS = "tests";
-
- /**
- * type attribute for failure and error elements
- */
- String ATTR_TYPE = "type";
-
- /**
- * message attribute for failure elements
- */
- String ATTR_MESSAGE = "message";
-
- /**
- * the properties element
- */
- String PROPERTIES = "properties";
-
- /**
- * the property element
- */
- String PROPERTY = "property";
-
- /**
- * value attribute for property elements
- */
- String ATTR_VALUE = "value";
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/XMLJUnitResultFormatter.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/XMLJUnitResultFormatter.java
deleted file mode 100644
index 141986ddb..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/XMLJUnitResultFormatter.java
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Properties;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import org.apache.myrmidon.api.TaskException;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Text;
-
-/**
- * Prints XML output of the test to a specified Writer.
- *
- * @author Stefan Bodewig
- * @author Erik Hatcher
- * @see FormatterElement
- */
-
-public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstants
-{
- /**
- * Element for the current test.
- */
- private Hashtable testElements = new Hashtable();
- /**
- * Timing helper.
- */
- private Hashtable testStarts = new Hashtable();
-
- /**
- * The XML document.
- */
- private Document doc;
- /**
- * Where to write the log to.
- */
- private OutputStream out;
- /**
- * The wrapper for the whole testsuite.
- */
- private Element rootElement;
-
- public XMLJUnitResultFormatter()
- {
- }
-
- private static DocumentBuilder getDocumentBuilder()
- {
- try
- {
- return DocumentBuilderFactory.newInstance().newDocumentBuilder();
- }
- catch( Exception exc )
- {
- throw new ExceptionInInitializerError( exc );
- }
- }
-
- public void setOutput( OutputStream out )
- {
- this.out = out;
- }
-
- public void setSystemError( String out )
- {
- formatOutput( SYSTEM_ERR, out );
- }
-
- public void setSystemOutput( String out )
- {
- formatOutput( SYSTEM_OUT, out );
- }
-
- /**
- * Interface TestListener.
- *
- * An error occured while running the test.
- *
- * @param test The feature to be added to the Error attribute
- * @param t The feature to be added to the Error attribute
- */
- public void addError( Test test, Throwable t )
- {
- formatError( ERROR, test, t );
- }
-
- /**
- * Interface TestListener for JUnit <= 3.4.
- *
- * A Test failed.
- *
- * @param test The feature to be added to the Failure attribute
- * @param t The feature to be added to the Failure attribute
- */
- public void addFailure( Test test, Throwable t )
- {
- formatError( FAILURE, test, t );
- }
-
- /**
- * Interface TestListener for JUnit > 3.4.
- *
- * A Test failed.
- *
- * @param test The feature to be added to the Failure attribute
- * @param t The feature to be added to the Failure attribute
- */
- public void addFailure( Test test, AssertionFailedError t )
- {
- addFailure( test, (Throwable)t );
- }
-
- /**
- * Interface TestListener.
- *
- * A Test is finished.
- *
- * @param test Description of Parameter
- */
- public void endTest( Test test )
- {
- Element currentTest = (Element)testElements.get( test );
- Long l = (Long)testStarts.get( test );
- currentTest.setAttribute( ATTR_TIME,
- "" + ( ( System.currentTimeMillis() - l.longValue() )
- / 1000.0 ) );
- }
-
- /**
- * The whole testsuite ended.
- *
- * @param suite Description of Parameter
- * @exception TaskException Description of Exception
- */
- public void endTestSuite( JUnitTest suite )
- throws TaskException
- {
- rootElement.setAttribute( ATTR_TESTS, "" + suite.runCount() );
- rootElement.setAttribute( ATTR_FAILURES, "" + suite.failureCount() );
- rootElement.setAttribute( ATTR_ERRORS, "" + suite.errorCount() );
- rootElement.setAttribute( ATTR_TIME, "" + ( suite.getRunTime() / 1000.0 ) );
- if( out != null )
- {
- Writer wri = null;
- try
- {
- wri = new OutputStreamWriter( out, "UTF8" );
- wri.write( "\n" );
- ( new DOMElementWriter() ).write( rootElement, wri, 0, " " );
- wri.flush();
- }
- catch( IOException exc )
- {
- throw new TaskException( "Unable to write log file", exc );
- }
- finally
- {
- if( out != System.out && out != System.err )
- {
- if( wri != null )
- {
- try
- {
- wri.close();
- }
- catch( IOException e )
- {
- }
- }
- }
- }
- }
- }
-
- /**
- * Interface TestListener.
- *
- * A new Test is started.
- *
- * @param t Description of Parameter
- */
- public void startTest( Test t )
- {
- testStarts.put( t, new Long( System.currentTimeMillis() ) );
-
- Element currentTest = doc.createElement( TESTCASE );
- currentTest.setAttribute( ATTR_NAME,
- JUnitVersionHelper.getTestCaseName( t ) );
- rootElement.appendChild( currentTest );
- testElements.put( t, currentTest );
- }
-
- /**
- * The whole testsuite started.
- *
- * @param suite Description of Parameter
- */
- public void startTestSuite( JUnitTest suite )
- {
- doc = getDocumentBuilder().newDocument();
- rootElement = doc.createElement( TESTSUITE );
- rootElement.setAttribute( ATTR_NAME, suite.getName() );
-
- // Output properties
- Element propsElement = doc.createElement( PROPERTIES );
- rootElement.appendChild( propsElement );
- Properties props = suite.getProperties();
- if( props != null )
- {
- final Iterator e = props.keySet().iterator();
- while( e.hasNext() )
- {
- final String name = (String)e.next();
- final String value = props.getProperty( name );
- final Element propElement = doc.createElement( PROPERTY );
- propElement.setAttribute( ATTR_NAME, name );
- propElement.setAttribute( ATTR_VALUE, value );
- propsElement.appendChild( propElement );
- }
- }
- }
-
- private void formatError( String type, Test test, Throwable t )
- {
- if( test != null )
- {
- endTest( test );
- }
-
- Element nested = doc.createElement( type );
- Element currentTest = null;
- if( test != null )
- {
- currentTest = (Element)testElements.get( test );
- }
- else
- {
- currentTest = rootElement;
- }
-
- currentTest.appendChild( nested );
-
- String message = t.getMessage();
- if( message != null && message.length() > 0 )
- {
- nested.setAttribute( ATTR_MESSAGE, t.getMessage() );
- }
- nested.setAttribute( ATTR_TYPE, t.getClass().getName() );
-
- String strace = JUnitTestRunner.getFilteredTrace( t );
- Text trace = doc.createTextNode( strace );
- nested.appendChild( trace );
- }
-
- private void formatOutput( String type, String output )
- {
- Element nested = doc.createElement( type );
- rootElement.appendChild( nested );
- Text content = doc.createTextNode( output );
- nested.appendChild( content );
- }
-
-}// XMLJUnitResultFormatter
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/XMLResultAggregator.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/XMLResultAggregator.java
deleted file mode 100644
index e24a8c84d..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/XMLResultAggregator.java
+++ /dev/null
@@ -1,336 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import org.apache.avalon.framework.ExceptionUtil;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.ScannerUtil;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.xml.sax.SAXException;
-
-/**
- *
- *
- * This is an helper class that will aggregate all testsuites under a specific
- * directory and create a new single document. It is not particulary clean but
- * should be helpful while I am thinking about another technique.
- *
- * The main problem is due to the fact that a JVM can be forked for a testcase
- * thus making it impossible to aggregate all testcases since the listener is
- * (obviously) in the forked JVM. A solution could be to write a TestListener
- * that will receive events from the TestRunner via sockets. This is IMHO the
- * simplest way to do it to avoid this file hacking thing.
- *
- * @author Stephane Bailliez
- */
-public class XMLResultAggregator
- extends AbstractTask
- implements XMLConstants
-{
- /**
- * the default directory: . . It is resolved from the project
- * directory
- */
- public final static String DEFAULT_DIR = ".";
-
- /**
- * the default file name: TESTS-TestSuites.xml
- */
- public final static String DEFAULT_FILENAME = "TESTS-TestSuites.xml";
-
- /**
- * the list of all filesets, that should contains the xml to aggregate
- */
- protected ArrayList filesets = new ArrayList();
-
- protected ArrayList transformers = new ArrayList();
-
- /**
- * the directory to write the file to
- */
- protected File toDir;
-
- /**
- * the name of the result file
- */
- protected String toFile;
-
- /**
- * Create a new document builder. Will issue an
- * ExceptionInitializerError if something is going wrong. It is fatal
- * anyway.
- *
- * @return a new document builder to create a DOM
- * @todo factorize this somewhere else. It is duplicated code.
- */
- private static DocumentBuilder getDocumentBuilder()
- {
- try
- {
- return DocumentBuilderFactory.newInstance().newDocumentBuilder();
- }
- catch( Exception exc )
- {
- throw new ExceptionInInitializerError( exc );
- }
- }
-
- /**
- * Set the destination directory where the results should be written. If not
- * set if will use {@link #DEFAULT_DIR}. When given a relative directory it
- * will resolve it from the project directory.
- *
- * @param value the directory where to write the results, absolute or
- * relative.
- */
- public void setTodir( File value )
- {
- toDir = value;
- }
-
- /**
- * Set the name of the file aggregating the results. It must be relative
- * from the todir attribute. If not set it will use {@link
- * #DEFAULT_FILENAME}
- *
- * @param value the name of the file.
- * @see #setTodir(File)
- */
- public void setTofile( String value )
- {
- toFile = value;
- }
-
- /**
- * Add a new fileset containing the xml results to aggregate
- *
- * @param fs the new fileset of xml results.
- */
- public void addFileSet( FileSet fs )
- {
- filesets.add( fs );
- }
-
- public AggregateTransformer createReport()
- {
- AggregateTransformer transformer = new AggregateTransformer( this );
- transformers.add( transformer );
- return transformer;
- }
-
- /**
- * Aggregate all testsuites into a single document and write it to the
- * specified directory and file.
- *
- * @throws TaskException thrown if there is a serious error while writing
- * the document.
- */
- public void execute()
- throws TaskException
- {
- final Element rootElement = createDocument();
- File destFile = getDestinationFile();
- // write the document
- try
- {
- writeDOMTree( rootElement.getOwnerDocument(), destFile );
- }
- catch( IOException e )
- {
- throw new TaskException( "Unable to write test aggregate to '" + destFile + "'", e );
- }
- // apply transformation
- Iterator enum = transformers.iterator();
- while( enum.hasNext() )
- {
- AggregateTransformer transformer =
- (AggregateTransformer)enum.next();
- transformer.setXmlDocument( rootElement.getOwnerDocument() );
- transformer.transform();
- }
- }
-
- /**
- * Get the full destination file where to write the result. It is made of
- * the todir and tofile attributes.
- *
- * @return the destination file where should be written the result file.
- */
- protected File getDestinationFile()
- throws TaskException
- {
- if( toFile == null )
- {
- toFile = DEFAULT_FILENAME;
- }
- if( toDir == null )
- {
- toDir = getContext().resolveFile( DEFAULT_DIR );
- }
- return new File( toDir, toFile );
- }
-
- /**
- * Get all .xml
files in the fileset.
- *
- * @return all files in the fileset that end with a '.xml'.
- */
- protected File[] getFiles()
- throws TaskException
- {
- final ArrayList v = new ArrayList();
- final int size = filesets.size();
- for( int i = 0; i < size; i++ )
- {
- final FileSet fileSet = (FileSet)filesets.get( i );
- final DirectoryScanner scanner = ScannerUtil.getDirectoryScanner( fileSet );
- scanner.scan();
- final String[] includes = scanner.getIncludedFiles();
- for( int j = 0; j < includes.length; j++ )
- {
- final String pathname = includes[ j ];
- if( pathname.endsWith( ".xml" ) )
- {
- File file = new File( scanner.getBasedir(), pathname );
- file = getContext().resolveFile( file.getPath() );
- v.add( file );
- }
- }
- }
-
- return (File[])v.toArray( new File[ v.size() ] );
- }
-
- /**
- *
- *
- * Add a new testsuite node to the document. The main difference is that it
- * split the previous fully qualified name into a package and a name.
- *
- * For example: org.apache.Whatever will be split into
- * org.apache and Whatever .
- *
- * @param root the root element to which the testsuite node should
- * be appended.
- * @param testsuite the element to append to the given root. It will
- * slightly modify the original node to change the name attribute and
- * add a package one.
- */
- protected void addTestSuite( Element root, Element testsuite )
- {
- String fullclassname = testsuite.getAttribute( ATTR_NAME );
- int pos = fullclassname.lastIndexOf( '.' );
-
- // a missing . might imply no package at all. Don't get fooled.
- String pkgName = ( pos == -1 ) ? "" : fullclassname.substring( 0, pos );
- String classname = ( pos == -1 ) ? fullclassname : fullclassname.substring( pos + 1 );
- Element copy = (Element)DOMUtil.importNode( root, testsuite );
-
- // modify the name attribute and set the package
- copy.setAttribute( ATTR_NAME, classname );
- copy.setAttribute( ATTR_PACKAGE, pkgName );
- }
-
- /**
- *
- *
- * Create a DOM tree. Has 'testsuites' as firstchild and aggregates all
- * testsuite results that exists in the base directory.
- *
- * @return the root element of DOM tree that aggregates all testsuites.
- */
- protected Element createDocument()
- throws TaskException
- {
- // create the dom tree
- DocumentBuilder builder = getDocumentBuilder();
- Document doc = builder.newDocument();
- Element rootElement = doc.createElement( TESTSUITES );
- doc.appendChild( rootElement );
-
- // get all files and add them to the document
- final File[] files = getFiles();
- for( int i = 0; i < files.length; i++ )
- {
- try
- {
- getContext().debug( "Parsing file: '" + files[ i ] + "'" );
- //XXX there seems to be a bug in xerces 1.3.0 that doesn't like file object
- // will investigate later. It does not use the given directory but
- // the vm dir instead ? Works fine with crimson.
- Document testsuiteDoc = builder.parse( "file:///" + files[ i ].getAbsolutePath() );
- Element elem = testsuiteDoc.getDocumentElement();
- // make sure that this is REALLY a testsuite.
- if( TESTSUITE.equals( elem.getNodeName() ) )
- {
- addTestSuite( rootElement, elem );
- }
- else
- {
- // issue a warning.
- getContext().warn( "the file " + files[ i ] + " is not a valid testsuite XML document" );
- }
- }
- catch( SAXException e )
- {
- // a testcase might have failed and write a zero-length document,
- // It has already failed, but hey.... mm. just put a warning
- getContext().warn( "The file " + files[ i ] + " is not a valid XML document. It is possibly corrupted." );
- getContext().debug( ExceptionUtil.printStackTrace( e ) );
- }
- catch( IOException e )
- {
- getContext().error( "Error while accessing file " + files[ i ] + ": " + e.getMessage() );
- }
- }
- return rootElement;
- }
-
- //----- from now, the methods are all related to DOM tree manipulation
-
- /**
- * Write the DOM tree to a file.
- *
- * @param doc the XML document to dump to disk.
- * @param file the filename to write the document to. Should obviouslly be a
- * .xml file.
- * @throws IOException thrown if there is an error while writing the
- * content.
- */
- protected void writeDOMTree( Document doc, File file )
- throws IOException
- {
- OutputStream out = new FileOutputStream( file );
- PrintWriter wri = new PrintWriter( new OutputStreamWriter( out, "UTF8" ) );
- wri.write( "\n" );
- ( new DOMElementWriter() ).write( doc.getDocumentElement(), wri, 0, " " );
- wri.flush();
- wri.close();
- // writers do not throw exceptions, so check for them.
- if( wri.checkError() )
- {
- throw new IOException( "Error while writing DOM content" );
- }
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/Xalan1Executor.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/Xalan1Executor.java
deleted file mode 100644
index 8ae1662e5..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/Xalan1Executor.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.io.OutputStream;
-import org.apache.xalan.xslt.XSLTInputSource;
-import org.apache.xalan.xslt.XSLTProcessor;
-import org.apache.xalan.xslt.XSLTProcessorFactory;
-import org.apache.xalan.xslt.XSLTResultTarget;
-
-/**
- * Xalan 1 executor. It will need a lot of things in the classpath: xerces for
- * the serialization, xalan and bsf for the extension.
- *
- * @author RT
- * @todo do everything via reflection to avoid compile problems ?
- */
-public class Xalan1Executor extends XalanExecutor
-{
- void execute()
- throws Exception
- {
- XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
- // need to quote otherwise it breaks because of "extra illegal tokens"
- processor.setStylesheetParam( "output.dir", "'" + caller.getToDir().getAbsolutePath() + "'" );
- XSLTInputSource xml_src = new XSLTInputSource( caller.getDocument() );
- String system_id = caller.getStylesheetSystemId();
- XSLTInputSource xsl_src = new XSLTInputSource( system_id );
- OutputStream os = getOutputStream();
- XSLTResultTarget target = new XSLTResultTarget( os );
- processor.process( xml_src, xsl_src, target );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/Xalan2Executor.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/Xalan2Executor.java
deleted file mode 100644
index 84b1bbddb..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/Xalan2Executor.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.io.OutputStream;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
-/**
- * Xalan executor via JAXP. Nothing special must exists in the classpath besides
- * of course, a parser, jaxp and xalan.
- *
- * @author RT
- */
-public class Xalan2Executor extends XalanExecutor
-{
- void execute()
- throws Exception
- {
- TransformerFactory tfactory = TransformerFactory.newInstance();
- String system_id = caller.getStylesheetSystemId();
- Source xsl_src = new StreamSource( system_id );
- Transformer tformer = tfactory.newTransformer( xsl_src );
- Source xml_src = new DOMSource( caller.getDocument() );
- OutputStream os = getOutputStream();
- tformer.setParameter( "output.dir", caller.getToDir().getAbsolutePath() );
- Result result = new StreamResult( os );
- tformer.transform( xml_src, result );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/XalanExecutor.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/XalanExecutor.java
deleted file mode 100644
index b5df22b60..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/junit/XalanExecutor.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.junit;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.reflect.Field;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * Command class that encapsulate specific behavior for each Xalan version. The
- * right executor will be instantiated at runtime via class lookup. For
- * instance, it will check first for Xalan2, then for Xalan1.
- *
- * @author RT
- */
-abstract class XalanExecutor
-{
- /**
- * the transformer caller
- */
- protected AggregateTransformer caller;
-
- /**
- * Create a valid Xalan executor. It checks first if Xalan2 is present, if
- * not it checks for xalan1. If none is available, it fails.
- *
- * @param caller object containing the transformation information.
- * @return Description of the Returned Value
- * @throws TaskException thrown if it could not find a valid xalan
- * executor.
- */
- static XalanExecutor newInstance( AggregateTransformer caller )
- throws TaskException
- {
- Class procVersion = null;
- XalanExecutor executor = null;
- try
- {
- procVersion = Class.forName( "org.apache.xalan.processor.XSLProcessorVersion" );
- executor = new Xalan2Executor();
- }
- catch( Exception xalan2missing )
- {
- try
- {
- procVersion = Class.forName( "org.apache.xalan.xslt.XSLProcessorVersion" );
- executor = (XalanExecutor)Class.forName(
- "org.apache.tools.ant.taskdefs.optional.junit.Xalan1Executor" ).newInstance();
- }
- catch( Exception xalan1missing )
- {
- throw new TaskException( "Could not find xalan2 nor xalan1 in the classpath. Check http://xml.apache.org/xalan-j" );
- }
- }
- String version = getXalanVersion( procVersion );
- //caller.task.getLogger().info( "Using Xalan version: " + version );
- executor.setCaller( caller );
- return executor;
- }
-
- /**
- * pretty useful data (Xalan version information) to display.
- *
- * @param procVersion Description of Parameter
- * @return The XalanVersion value
- */
- private static String getXalanVersion( Class procVersion )
- {
- try
- {
- Field f = procVersion.getField( "S_VERSION" );
- return f.get( null ).toString();
- }
- catch( Exception e )
- {
- return "?";
- }
- }
-
- /**
- * get the appropriate stream based on the format (frames/noframes)
- *
- * @return The OutputStream value
- * @exception IOException Description of Exception
- */
- protected OutputStream getOutputStream()
- throws IOException
- {
- if( caller.FRAMES.equals( caller.getFormat() ) )
- {
- // dummy output for the framed report
- // it's all done by extension...
- return new ByteArrayOutputStream();
- }
- else
- {
- return new FileOutputStream( new File( caller.getToDir(), "junit-noframes.html" ) );
- }
- }
-
- /**
- * override to perform transformation
- *
- * @exception Exception Description of Exception
- */
- abstract void execute()
- throws Exception;
-
- /**
- * set the caller for this object.
- *
- * @param caller The new Caller value
- */
- private final void setCaller( AggregateTransformer caller )
- {
- this.caller = caller;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/Attribute.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/Attribute.java
deleted file mode 100644
index c8744ae5e..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/Attribute.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.manifest;
-
-/**
- * Class to hold manifest attributes
- *
- * @author Peter Donald
- * @author Conor MacNeill
- * @author Stefan Bodewig
- * @version $Revision$ $Date$
- */
-public class Attribute
-{
- /**
- * The attribute's name
- */
- private String m_name;
-
- /**
- * The attribute's value
- */
- private String m_value;
-
- /**
- * Construct an empty attribute
- */
- public Attribute()
- {
- }
-
- /**
- * Construct a manifest by specifying its name and value
- *
- * @param name the attribute's name
- * @param value the Attribute's value
- */
- public Attribute( final String name, final String value )
- {
- m_name = name;
- m_value = value;
- }
-
- /**
- * Set the Attribute's name
- *
- * @param name the attribute's name
- */
- public void setName( final String name )
- {
- m_name = name;
- }
-
- /**
- * Set the Attribute's value
- *
- * @param value the attribute's value
- */
- public void setValue( final String value )
- {
- m_value = value;
- }
-
- /**
- * Get the Attribute's name
- *
- * @return the attribute's name.
- */
- public String getName()
- {
- return m_name;
- }
-
- /**
- * Get the Attribute's value
- *
- * @return the attribute's value.
- */
- public String getValue()
- {
- return m_value;
- }
-
- /**
- * Add a continuation line from the Manifest file When lines are too
- * long in a manifest, they are continued on the next line by starting
- * with a space. This method adds the continuation data to the attribute
- * value by skipping the first character.
- *
- * @param line The feature to be added to the Continuation attribute
- */
- public void addContinuation( final String line )
- {
- m_value += line.substring( 1 );
- }
-
- public boolean equals( Object object )
- {
- if( !( object instanceof Attribute ) )
- {
- return false;
- }
-
- final Attribute other = (Attribute)object;
- final String name = other.m_name;
- return
- ( null != m_name && null != name &&
- m_name.toLowerCase().equals( name.toLowerCase() ) &&
- null != m_value && m_value.equals( other.m_value ) );
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/Manifest.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/Manifest.java
deleted file mode 100644
index 4b2fdbafd..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/Manifest.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.manifest;
-
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Set;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * Class to manage Manifest information
- *
- * @author Peter Donald
- * @author Conor MacNeill
- * @author Stefan Bodewig
- * @version $Revision$ $Date$
- */
-public class Manifest
-{
- /**
- * The version of this manifest
- */
- private String m_manifestVersion = ManifestUtil.DEFAULT_MANIFEST_VERSION;
-
- /**
- * The main section of this manifest
- */
- private Section m_mainSection = new Section();
-
- /**
- * The named sections of this manifest
- */
- private Hashtable m_sections = new Hashtable();
-
- public void setManifestVersion( final String manifestVersion )
- {
- m_manifestVersion = manifestVersion;
- }
-
- public void setMainSection( final Section mainSection )
- {
- m_mainSection = mainSection;
- }
-
- public void addAttribute( final Attribute attribute )
- throws ManifestException
- {
- m_mainSection.addAttribute( attribute );
- }
-
- public void addSection( final Section section )
- throws ManifestException
- {
- if( section.getName() == null )
- {
- final String message = "Sections must have a name";
- throw new ManifestException( message );
- }
- m_sections.put( section.getName().toLowerCase(), section );
- }
-
- public String[] getSectionNames( final Manifest other )
- {
- final Set keys = other.m_sections.keySet();
- return (String[])keys.toArray( new String[ keys.size() ] );
- }
-
- public String getManifestVersion()
- {
- return m_manifestVersion;
- }
-
- public Section getMainSection()
- {
- return m_mainSection;
- }
-
- public Section getSection( final String name )
- {
- return (Section)m_sections.get( name );
- }
-
- public Section[] getSections()
- {
- final Collection sections = m_sections.values();
- return (Section[])sections.toArray( new Section[ sections.size() ] );
- }
-
- /**
- * Merge the contents of the given manifest into this manifest
- *
- * @param other the Manifest to be merged with this one.
- * @throws org.apache.tools.todo.taskdefs.manifest.ManifestException if there is a problem merging the manfest
- * according to the Manifest spec.
- */
- public void merge( final Manifest other )
- throws ManifestException
- {
- if( other.m_manifestVersion != null )
- {
- m_manifestVersion = other.m_manifestVersion;
- }
- m_mainSection.merge( other.m_mainSection );
-
- mergeSections( other );
- }
-
- public boolean equals( final Object object )
- {
- if( !( object instanceof Manifest ) )
- {
- return false;
- }
-
- final Manifest other = (Manifest)object;
- if( m_manifestVersion == null && other.m_manifestVersion != null )
- {
- return false;
- }
- else if( !m_manifestVersion.equals( other.m_manifestVersion ) )
- {
- return false;
- }
- if( m_sections.size() != other.m_sections.size() )
- {
- return false;
- }
-
- if( !m_mainSection.equals( other.m_mainSection ) )
- {
- return false;
- }
-
- final Iterator e = m_sections.values().iterator();
- while( e.hasNext() )
- {
- final Section section = (Section)e.next();
- final String key = section.getName().toLowerCase();
- final Section otherSection = (Section)other.m_sections.get( key );
- if( !section.equals( otherSection ) )
- {
- return false;
- }
- }
-
- return true;
- }
-
- private void mergeSections( final Manifest other )
- throws ManifestException
- {
- final String[] sections = getSectionNames( other );
- for( int i = 0; i < sections.length; i++ )
- {
- final String sectionName = sections[ i ];
- final Section section = getSection( sectionName );
- final Section otherSection = other.getSection( sectionName );
- if( section == null )
- {
- m_sections.put( sectionName.toLowerCase(), otherSection );
- }
- else
- {
- section.merge( otherSection );
- }
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/ManifestException.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/ManifestException.java
deleted file mode 100644
index 30ee6567d..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/ManifestException.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.manifest;
-
-/**
- * ManifestException is thrown when there is a problem parsing, generating or
- * handling a Manifest.
- *
- * @author Peter Donald
- * @version $Revision$ $Date$
- */
-public class ManifestException
- extends Exception
-{
- /**
- * The Throwable that caused this exception to be thrown.
- */
- private final Throwable m_throwable;
-
- /**
- * Basic constructor for exception that does not specify a message
- */
- public ManifestException()
- {
- this( "", null );
- }
-
- /**
- * Basic constructor with a message
- *
- * @param message the message
- */
- public ManifestException( final String message )
- {
- this( message, null );
- }
-
- /**
- * Constructor that builds cascade so that other exception information can be retained.
- *
- * @param message the message
- * @param throwable the throwable
- */
- public ManifestException( final String message, final Throwable throwable )
- {
- super( message );
- m_throwable = throwable;
- }
-
- /**
- * Retrieve root cause of the exception.
- *
- * @return the root cause
- */
- public final Throwable getCause()
- {
- return m_throwable;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/ManifestMode.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/ManifestMode.java
deleted file mode 100644
index 2d03de74e..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/ManifestMode.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.manifest;
-
-import org.apache.tools.todo.types.EnumeratedAttribute;
-
-/**
- * Helper class for Manifest's mode attribute.
- *
- * @author Conor MacNeill
- * @author Stefan Bodewig
- * @author Peter Donald
- * @version $Revision$ $Date$
- */
-public class ManifestMode
- extends EnumeratedAttribute
-{
- public String[] getValues()
- {
- return new String[]{"update", "replace"};
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/ManifestTask.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/ManifestTask.java
deleted file mode 100644
index 5b7b7c3c7..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/ManifestTask.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.manifest;
-
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import org.apache.avalon.excalibur.io.IOUtil;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.taskdefs.manifest.Manifest;
-import org.apache.tools.todo.taskdefs.manifest.Section;
-
-/**
- * Class to manage Manifest information
- *
- * @author Peter Donald
- * @author Conor MacNeill
- * @author Stefan Bodewig
- * @version $Revision$ $Date$
- */
-public class ManifestTask
- extends AbstractTask
-{
- private File m_destFile;
- private ManifestMode m_mode;
- private Manifest m_manifest = new Manifest();
-
- /**
- * Construct an empty manifest
- */
- public ManifestTask()
- throws TaskException
- {
- m_mode = new ManifestMode();
- m_mode.setValue( "replace" );
- }
-
- /**
- * The name of the manifest file to write.
- */
- public void setDestFile( final File destFile )
- {
- m_destFile = destFile;
- }
-
- /**
- * Shall we update or replace an existing manifest?
- */
- public void setMode( final ManifestMode mode )
- {
- m_mode = mode;
- }
-
- public void setManifestVersion( String manifestVersion )
- {
- m_manifest.setManifestVersion( manifestVersion );
- }
-
- public void addMainSection( Section mainSection )
- throws Exception
- {
- m_manifest.setMainSection( mainSection );
- }
-
- /**
- * Get the warnings for this manifest.
- *
- * @return an enumeration of warning strings
- */
- public Iterator getWarnings()
- {
- ArrayList warnings = new ArrayList();
-
- for( Iterator e2 = m_manifest.getMainSection().getWarnings(); e2.hasNext(); )
- {
- warnings.add( e2.next() );
- }
-
- final Section[] sections = m_manifest.getSections();
- for( int i = 0; i < sections.length; i++ )
- {
- final Section section = sections[ i ];
- for( Iterator e2 = section.getWarnings(); e2.hasNext(); )
- {
- warnings.add( e2.next() );
- }
- }
-
- return warnings.iterator();
- }
-
- public void addAttribute( final Attribute attribute )
- throws ManifestException, TaskException
- {
- m_manifest.addAttribute( attribute );
- }
-
- public void addSection( final Section section )
- throws TaskException
- {
- try
- {
- m_manifest.addSection( section );
- }
- catch( final ManifestException me )
- {
- throw new TaskException( me.getMessage(), me );
- }
- }
-
- /**
- * Create or update the Manifest when used as a task.
- *
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- if( null == m_destFile )
- {
- throw new TaskException( "the file attribute is required" );
- }
-
- Manifest toWrite = getDefaultManifest();
-
- if( m_mode.getValue().equals( "update" ) && m_destFile.exists() )
- {
- FileReader f = null;
- try
- {
- f = new FileReader( m_destFile );
- final Manifest other = ManifestUtil.buildManifest( f );
- toWrite.merge( other );
- }
- catch( ManifestException m )
- {
- throw new TaskException( "Existing manifest " + m_destFile
- + " is invalid", m );
- }
- catch( IOException e )
- {
- throw new
- TaskException( "Failed to read " + m_destFile, e );
- }
- finally
- {
- IOUtil.shutdownReader( f );
- }
- }
-
- try
- {
- toWrite.merge( m_manifest );
- }
- catch( ManifestException m )
- {
- throw new TaskException( "Manifest is invalid", m );
- }
-
- PrintWriter w = null;
- try
- {
- w = new PrintWriter( new FileWriter( m_destFile ) );
- ManifestUtil.write( toWrite, w );
- }
- catch( IOException e )
- {
- throw new TaskException( "Failed to write " + m_destFile, e );
- }
- finally
- {
- IOUtil.shutdownWriter( w );
- }
- }
-
- private Manifest getDefaultManifest()
- throws TaskException
- {
- try
- {
- return ManifestUtil.getDefaultManifest();
- }
- catch( final ManifestException me )
- {
- throw new TaskException( me.getMessage(), me );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/ManifestUtil.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/ManifestUtil.java
deleted file mode 100644
index 7756908ef..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/ManifestUtil.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.manifest;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-import java.util.jar.Attributes;
-import org.apache.tools.todo.taskdefs.manifest.Manifest;
-import org.apache.tools.todo.taskdefs.manifest.Section;
-import org.apache.tools.todo.taskdefs.manifest.Attribute;
-
-/**
- * Utility methods for manifest stuff.
- *
- * @author Conor MacNeill
- * @author Stefan Bodewig
- * @author Peter Donald
- * @version $Revision$ $Date$
- */
-public final class ManifestUtil
-{
- /**
- * The Name Attribute is the first in a named section
- */
- public final static String ATTRIBUTE_NAME = "Name";
- /**
- * The From Header is disallowed in a Manifest
- */
- public final static String ATTRIBUTE_FROM = "From";
- /**
- * The Class-Path Header is special - it can be duplicated
- */
- public final static String ATTRIBUTE_CLASSPATH = Attributes.Name.CLASS_PATH.toString();
- /**
- * Default Manifest version if one is not specified
- */
- public final static String DEFAULT_MANIFEST_VERSION = "1.0";
- /**
- * The max length of a line in a Manifest
- */
- public final static int MAX_LINE_LENGTH = 70;
-
- public static Attribute buildAttribute( final String line )
- throws ManifestException
- {
- final Attribute attribute = new Attribute();
- parse( attribute, line );
- return attribute;
- }
-
- public static Manifest buildManifest( final Reader reader )
- throws ManifestException, IOException
- {
- final Manifest manifest = new Manifest();
- BufferedReader bufferedReader = new BufferedReader( reader );
- // This should be the manifest version
- final Section mainSection = manifest.getMainSection();
- String nextSectionName = mainSection.read( bufferedReader );
- final String readManifestVersion =
- mainSection.getAttributeValue( Attributes.Name.MANIFEST_VERSION.toString() );
- if( readManifestVersion != null )
- {
- manifest.setManifestVersion( readManifestVersion );
- mainSection.removeAttribute( Attributes.Name.MANIFEST_VERSION.toString() );
- }
-
- String line = null;
- while( ( line = bufferedReader.readLine() ) != null )
- {
- if( line.length() == 0 )
- {
- continue;
- }
-
- Section section = new Section();
- if( nextSectionName == null )
- {
- Attribute sectionName = ManifestUtil.buildAttribute( line );
- if( !sectionName.getName().equalsIgnoreCase( ManifestUtil.ATTRIBUTE_NAME ) )
- {
- throw new ManifestException( "Manifest sections should start with a \"" + ManifestUtil.ATTRIBUTE_NAME +
- "\" attribute and not \"" + sectionName.getName() + "\"" );
- }
- nextSectionName = sectionName.getValue();
- }
- else
- {
- // we have already started reading this section
- // this line is the first attribute. set it and then let the normal
- // read handle the rest
- Attribute firstAttribute = ManifestUtil.buildAttribute( line );
- section.addAttributeAndCheck( firstAttribute );
- }
-
- section.setName( nextSectionName );
- nextSectionName = section.read( bufferedReader );
- manifest.addSection( section );
- }
-
- return manifest;
- }
-
- /**
- * Construct a manifest from Ant's default manifest file.
- */
- public static Manifest getDefaultManifest()
- throws ManifestException
- {
- try
- {
- final InputStream input = getInputStream();
- final InputStreamReader reader = getReader( input );
- return buildManifest( reader );
- }
- catch( final IOException ioe )
- {
- throw new ManifestException( "Unable to read default manifest", ioe );
- }
- }
-
- private static InputStream getInputStream()
- throws ManifestException
- {
- final String location = "default.mf";
- final InputStream input = ManifestUtil.class.getResourceAsStream( location );
- if( null == input )
- {
- throw new ManifestException( "Could not find default manifest: " + location );
- }
- return input;
- }
-
- private static InputStreamReader getReader( final InputStream input )
- {
- try
- {
- return new InputStreamReader( input, "ASCII" );
- }
- catch( final UnsupportedEncodingException uee )
- {
- return new InputStreamReader( input );
- }
- }
-
- /**
- * Parse a line into name and value pairs
- *
- * @param line the line to be parsed
- * @throws org.apache.tools.todo.taskdefs.manifest.ManifestException if the line does not contain a colon
- * separating the name and value
- */
- public static void parse( final Attribute attribute, final String line )
- throws ManifestException
- {
- final int index = line.indexOf( ": " );
- if( index == -1 )
- {
- throw new ManifestException( "Manifest line \"" + line + "\" is not valid as it does not " +
- "contain a name and a value separated by ': ' " );
- }
- final String name = line.substring( 0, index );
- final String value = line.substring( index + 2 );
- attribute.setName( name );
- attribute.setValue( value );
- }
-
- public static void write( final Attribute attribute, final PrintWriter writer )
- throws IOException
- {
- final String name = attribute.getName();
- final String value = attribute.getValue();
- String line = name + ": " + value;
- while( line.getBytes().length > MAX_LINE_LENGTH )
- {
- // try to find a MAX_LINE_LENGTH byte section
- int breakIndex = MAX_LINE_LENGTH;
- String section = line.substring( 0, breakIndex );
- while( section.getBytes().length > MAX_LINE_LENGTH && breakIndex > 0 )
- {
- breakIndex--;
- section = line.substring( 0, breakIndex );
- }
- if( breakIndex == 0 )
- {
- throw new IOException( "Unable to write manifest line " + name + ": " + value );
- }
- writer.println( section );
- line = " " + line.substring( breakIndex );
- }
- writer.println( line );
- }
-
- /**
- * Write the manifest out to a print writer.
- *
- * @param writer the Writer to which the manifest is written
- * @throws java.io.IOException if the manifest cannot be written
- */
- public static void write( Manifest manifest, PrintWriter writer )
- throws IOException
- {
- final String sigVersionKey = Attributes.Name.SIGNATURE_VERSION.toString();
-
- writer.println( Attributes.Name.MANIFEST_VERSION + ": " + manifest.getManifestVersion() );
-
- final String signatureVersion =
- manifest.getMainSection().getAttributeValue( sigVersionKey );
- if( signatureVersion != null )
- {
- writer.println( Attributes.Name.SIGNATURE_VERSION + ": " + signatureVersion );
- manifest.getMainSection().removeAttribute( sigVersionKey );
- }
- manifest.getMainSection().write( writer );
- if( signatureVersion != null )
- {
- try
- {
- manifest.getMainSection().addAttribute( new Attribute( sigVersionKey, signatureVersion ) );
- }
- catch( ManifestException e )
- {
- // shouldn't happen - ignore
- }
- }
-
- final Section[] sections = manifest.getSections();
- for( int i = 0; i < sections.length; i++ )
- {
- sections[ i ].write( writer );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/Section.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/Section.java
deleted file mode 100644
index 7c76919a8..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/Section.java
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.manifest;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Iterator;
-
-/**
- * Class to represent an individual section in the Manifest. A section
- * consists of a set of attribute values, separated from other sections by a
- * blank line.
- *
- * @author Conor MacNeill
- * @author Stefan Bodewig
- * @author Peter Donald
- * @version $Revision$ $Date$
- */
-public class Section
-{
- private final ArrayList m_warnings = new ArrayList();
-
- /**
- * The section's name if any. The main section in a manifest is unnamed.
- */
- private String m_name;
-
- /**
- * The section's attributes.
- */
- private final Hashtable m_attributes = new Hashtable();
-
- /**
- * Set the Section's name
- *
- * @param name the section's name
- */
- public void setName( final String name )
- {
- m_name = name;
- }
-
- /**
- * Get the value of the attribute with the name given.
- *
- * @param attributeName the name of the attribute to be returned.
- * @return the attribute's value or null if the attribute does not exist
- * in the section
- */
- public String getAttributeValue( final String attributeName )
- {
- final Object attributeObject = m_attributes.get( attributeName.toLowerCase() );
- if( null == attributeObject )
- {
- return null;
- }
- else if( attributeObject instanceof Attribute )
- {
- final Attribute attribute = (Attribute)attributeObject;
- return attribute.getValue();
- }
- else
- {
- String value = "";
- final ArrayList attributes = (ArrayList)attributeObject;
- Iterator e = attributes.iterator();
- while( e.hasNext() )
- {
- final Attribute classpathAttribute = (Attribute)e.next();
- value += classpathAttribute.getValue() + " ";
- }
- return value.trim();
- }
- }
-
- /**
- * Get the Section's name
- *
- * @return the section's name.
- */
- public String getName()
- {
- return m_name;
- }
-
- public Iterator getWarnings()
- {
- return m_warnings.iterator();
- }
-
- /**
- * Add an attribute to the section
- *
- * @param attribute the attribute to be added.
- * @return the value of the attribute if it is a name attribute - null
- * other wise
- * @throws org.apache.tools.todo.taskdefs.manifest.ManifestException if the attribute already exists in this
- * section.
- */
- public String addAttributeAndCheck( Attribute attribute )
- throws ManifestException
- {
- if( attribute.getName() == null || attribute.getValue() == null )
- {
- throw new ManifestException( "Attributes must have name and value" );
- }
- if( attribute.getName().equalsIgnoreCase( ManifestUtil.ATTRIBUTE_NAME ) )
- {
- m_warnings.add( "\"" + ManifestUtil.ATTRIBUTE_NAME + "\" attributes should not occur in the " +
- "main section and must be the first element in all " +
- "other sections: \"" + attribute.getName() + ": " + attribute.getValue() + "\"" );
- return attribute.getValue();
- }
-
- if( attribute.getName().toLowerCase().startsWith( ManifestUtil.ATTRIBUTE_FROM.toLowerCase() ) )
- {
- m_warnings.add( "Manifest attributes should not start with \"" +
- ManifestUtil.ATTRIBUTE_FROM + "\" in \"" + attribute.getName() + ": " + attribute.getValue() + "\"" );
- }
- else
- {
- // classpath attributes go into a vector
- String attributeName = attribute.getName().toLowerCase();
- if( attributeName.equals( ManifestUtil.ATTRIBUTE_CLASSPATH ) )
- {
- ArrayList classpathAttrs = (ArrayList)m_attributes.get( attributeName );
- if( classpathAttrs == null )
- {
- classpathAttrs = new ArrayList();
- m_attributes.put( attributeName, classpathAttrs );
- }
- classpathAttrs.add( attribute );
- }
- else if( m_attributes.containsKey( attributeName ) )
- {
- throw new ManifestException( "The attribute \"" + attribute.getName() + "\" may not " +
- "occur more than once in the same section" );
- }
- else
- {
- m_attributes.put( attributeName, attribute );
- }
- }
- return null;
- }
-
- public void addAttribute( final Attribute attribute )
- throws ManifestException
- {
- String check = addAttributeAndCheck( attribute );
- if( check != null )
- {
- throw new ManifestException( "Specify the section name using the \"name\" attribute of the element rather " +
- "than using a \"Name\" manifest attribute" );
- }
- }
-
- public boolean equals( Object rhs )
- {
- if( !( rhs instanceof Section ) )
- {
- return false;
- }
-
- Section rhsSection = (Section)rhs;
- if( m_attributes.size() != rhsSection.m_attributes.size() )
- {
- return false;
- }
-
- for( Enumeration e = m_attributes.elements(); e.hasMoreElements(); )
- {
- Attribute attribute = (Attribute)e.nextElement();
- Attribute rshAttribute = (Attribute)rhsSection.m_attributes.get( attribute.getName().toLowerCase() );
- if( !attribute.equals( rshAttribute ) )
- {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Merge in another section
- *
- * @param section the section to be merged with this one.
- * @throws org.apache.tools.todo.taskdefs.manifest.ManifestException if the sections cannot be merged.
- */
- public void merge( Section section )
- throws ManifestException
- {
- if( m_name == null && section.getName() != null ||
- m_name != null && !( m_name.equalsIgnoreCase( section.getName() ) ) )
- {
- throw new ManifestException( "Unable to merge sections with different names" );
- }
-
- for( Enumeration e = section.m_attributes.keys(); e.hasMoreElements(); )
- {
- String attributeName = (String)e.nextElement();
- if( attributeName.equals( ManifestUtil.ATTRIBUTE_CLASSPATH ) &&
- m_attributes.containsKey( attributeName ) )
- {
- // classpath entries are vetors which are merged
- ArrayList classpathAttrs = (ArrayList)section.m_attributes.get( attributeName );
- ArrayList ourClasspathAttrs = (ArrayList)m_attributes.get( attributeName );
- for( Iterator e2 = classpathAttrs.iterator(); e2.hasNext(); )
- {
- ourClasspathAttrs.add( e2.next() );
- }
- }
- else
- {
- // the merge file always wins
- m_attributes.put( attributeName, section.m_attributes.get( attributeName ) );
- }
- }
-
- // add in the warnings
- for( Iterator e = section.m_warnings.iterator(); e.hasNext(); )
- {
- m_warnings.add( e.next() );
- }
- }
-
- /**
- * Read a section through a reader
- *
- * @param reader the reader from which the section is read
- * @return the name of the next section if it has been read as part of
- * this section - This only happens if the Manifest is malformed.
- * @throws org.apache.tools.todo.taskdefs.manifest.ManifestException if the section is not valid according to
- * the JAR spec
- * @throws java.io.IOException if the section cannot be read from the reader.
- */
- public String read( BufferedReader reader )
- throws ManifestException, IOException
- {
- Attribute attribute = null;
- while( true )
- {
- String line = reader.readLine();
- if( line == null || line.length() == 0 )
- {
- return null;
- }
- if( line.charAt( 0 ) == ' ' )
- {
- // continuation line
- if( attribute == null )
- {
- if( m_name != null )
- {
- // a continuation on the first line is a continuation of the name - concatenate
- // this line and the name
- m_name += line.substring( 1 );
- }
- else
- {
- throw new ManifestException( "Can't start an attribute with a continuation line " + line );
- }
- }
- else
- {
- attribute.addContinuation( line );
- }
- }
- else
- {
- attribute = ManifestUtil.buildAttribute( line );
- String nameReadAhead = addAttributeAndCheck( attribute );
- if( nameReadAhead != null )
- {
- return nameReadAhead;
- }
- }
- }
- }
-
- /**
- * Remove tge given attribute from the section
- *
- * @param attributeName the name of the attribute to be removed.
- */
- public void removeAttribute( String attributeName )
- {
- m_attributes.remove( attributeName.toLowerCase() );
- }
-
- /**
- * Write the section out to a print writer.
- *
- * @param writer the Writer to which the section is written
- * @throws java.io.IOException if the section cannot be written
- */
- public void write( PrintWriter writer )
- throws IOException
- {
- if( m_name != null )
- {
- Attribute nameAttr = new Attribute( ManifestUtil.ATTRIBUTE_NAME, m_name );
- ManifestUtil.write( nameAttr, writer );
- }
- for( Enumeration e = m_attributes.elements(); e.hasMoreElements(); )
- {
- Object object = e.nextElement();
- if( object instanceof Attribute )
- {
- Attribute attribute = (Attribute)object;
- ManifestUtil.write( attribute, writer );
- }
- else
- {
- ArrayList attrList = (ArrayList)object;
- for( Iterator e2 = attrList.iterator(); e2.hasNext(); )
- {
- Attribute attribute = (Attribute)e2.next();
- ManifestUtil.write( attribute, writer );
- }
- }
- }
- writer.println();
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/default.mf b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/default.mf
deleted file mode 100644
index 1dc733da7..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/manifest/default.mf
+++ /dev/null
@@ -1,3 +0,0 @@
-Manifest-Version: 1.0
-Created-By: Apache Ant @VERSION@
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/AbstractMetamataTask.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/AbstractMetamataTask.java
deleted file mode 100644
index d7d1b326d..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/AbstractMetamataTask.java
+++ /dev/null
@@ -1,387 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.metamata;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Random;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.tools.todo.types.Argument;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.CommandlineJava;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.types.ScannerUtil;
-
-/**
- * Somewhat abstract framework to be used for other metama 2.0 tasks. This
- * should include, audit, metrics, cover and mparse. For more information, visit
- * the website at www.metamata.com
- *
- * @author Stephane Bailliez
- */
-public abstract class AbstractMetamataTask
- extends AbstractTask
-{
- /**
- * The user classpath to be provided. It matches the -classpath of the
- * command line. The classpath must includes both the .class and
- * the .java files for accurate audit.
- */
- private Path m_classPath;
-
- /**
- * the path to the source file
- */
- private Path m_sourcePath;
-
- /**
- * Metamata home directory. It will be passed as a metamata.home
- * property and should normally matches the environment property
- * META_HOME set by the Metamata installer.
- */
- private File m_metamataHome;
-
- /**
- * the command line used to run MAudit
- */
- private CommandlineJava m_cmdl = new CommandlineJava();
-
- /**
- * the set of files to be audited
- */
- private ArrayList m_fileSets = new ArrayList();
-
- /**
- * the options file where are stored the command line options
- */
- private File m_optionsFile;
-
- // this is used to keep track of which files were included. It will
- // be set when calling scanFileSets();
- private Hashtable m_includedFiles;
-
- public AbstractMetamataTask()
- {
- }
-
- /**
- * initialize the task with the classname of the task to run
- *
- * @param className Description of Parameter
- */
- protected AbstractMetamataTask( String className )
- {
- m_cmdl.setVm( "java" );
- m_cmdl.setClassname( className );
- }
-
- /**
- * convenient method for JDK 1.1. Will copy all elements from src to dest
- *
- * @param dest The feature to be added to the AllArrayList attribute
- * @param files The feature to be added to the AllArrayList attribute
- */
- protected static final void addAllArrayList( ArrayList dest, Iterator files )
- {
- while( files.hasNext() )
- {
- dest.add( files.next() );
- }
- }
-
- protected static final File createTmpFile()
- {
- // must be compatible with JDK 1.1 !!!!
- final long rand = ( new Random( System.currentTimeMillis() ) ).nextLong();
- File file = new File( "metamata" + rand + ".tmp" );
- return file;
- }
-
- /**
- * -mx or -Xmx depending on VM version
- *
- * @param max The new Maxmemory value
- */
- public void setMaxmemory( String max )
- {
- m_cmdl.addVmArgument( "-Xmx" + max );
- }
-
- /**
- * the metamata.home property to run all tasks.
- */
- public void setMetamatahome( final File metamataHome )
- {
- this.m_metamataHome = metamataHome;
- }
-
- /**
- * The java files or directory to be audited
- */
- public void addFileSet( final FileSet fileSet )
- {
- m_fileSets.add( fileSet );
- }
-
- /**
- * user classpath
- */
- public Path createClasspath()
- {
- if( m_classPath == null )
- {
- m_classPath = new Path();
- }
- return m_classPath;
- }
-
- /**
- * Creates a nested jvmarg element.
- */
- public void addJvmarg( final Argument argument )
- {
- m_cmdl.addVmArgument( argument );
- }
-
- /**
- * create the source path for this task
- */
- public Path createSourcepath()
- {
- if( m_sourcePath == null )
- {
- m_sourcePath = new Path();
- }
- return m_sourcePath;
- }
-
- /**
- * execute the command line
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- try
- {
- setUp();
- execute0();
- }
- finally
- {
- cleanUp();
- }
- }
-
- /**
- * check the options and build the command line
- */
- protected void setUp()
- throws TaskException
- {
- validate();
-
- // set the classpath as the jar file
- File jar = getMetamataJar( m_metamataHome );
- final Path classPath = m_cmdl.createClasspath();
- classPath.addLocation( jar );
-
- // set the metamata.home property
- m_cmdl.addVmArgument( "-Dmetamata.home=" + m_metamataHome.getAbsolutePath() );
-
- // retrieve all the files we want to scan
- m_includedFiles = scanFileSets();
- getContext().debug( m_includedFiles.size() + " files added for audit" );
-
- // write all the options to a temp file and use it ro run the process
- ArrayList options = getOptions();
- m_optionsFile = createTmpFile();
- generateOptionsFile( m_optionsFile, options );
- m_cmdl.addArgument( "-arguments " );
- m_cmdl.addArgument( m_optionsFile.getAbsolutePath() );
- }
-
- /**
- * return the location of the jar file used to run
- */
- protected final File getMetamataJar( File home )
- {
- return new File( new File( home.getAbsolutePath() ), "lib/metamata.jar" );
- }
-
- protected Hashtable getFileMapping()
- {
- return m_includedFiles;
- }
-
- /**
- * return all options of the command line as string elements
- */
- protected abstract ArrayList getOptions()
- throws TaskException;
-
- /**
- * validate options set
- *
- * @exception TaskException Description of Exception
- */
- protected void validate()
- throws TaskException
- {
- // do some validation first
- if( m_metamataHome == null || !m_metamataHome.exists() )
- {
- throw new TaskException( "'metamatahome' must point to Metamata home directory." );
- }
- m_metamataHome = getContext().resolveFile( m_metamataHome.getPath() );
- File jar = getMetamataJar( m_metamataHome );
- if( !jar.exists() )
- {
- throw new TaskException( jar + " does not exist. Check your metamata installation." );
- }
- }
-
- /**
- * clean up all the mess that we did with temporary objects
- */
- protected void cleanUp()
- throws TaskException
- {
- if( m_optionsFile != null )
- {
- m_optionsFile.delete();
- m_optionsFile = null;
- }
- }
-
- /**
- * execute the process with a specific handler
- *
- * @param handler Description of Parameter
- * @exception TaskException Description of Exception
- */
- protected void execute0()
- throws TaskException
- {
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
- getContext().debug( m_cmdl.toString() );
- final String[] commandline = m_cmdl.getCommandline();
- exe.setCommandline( new Commandline( commandline ) );
- exe.setReturnCode( 0 );
- exe.execute();
- }
-
- protected void generateOptionsFile( File tofile, ArrayList options )
- throws TaskException
- {
- FileWriter fw = null;
- try
- {
- fw = new FileWriter( tofile );
- PrintWriter pw = new PrintWriter( fw );
- final int size = options.size();
- for( int i = 0; i < size; i++ )
- {
- pw.println( options.get( i ) );
- }
- pw.flush();
- }
- catch( IOException e )
- {
- throw new TaskException( "Error while writing options file " + tofile, e );
- }
- finally
- {
- if( fw != null )
- {
- try
- {
- fw.close();
- }
- catch( IOException ignored )
- {
- }
- }
- }
- }
-
- /**
- * @return the list of .java files (as their absolute path) that should be
- * audited.
- */
- protected Hashtable scanFileSets()
- throws TaskException
- {
- Hashtable files = new Hashtable();
- for( int i = 0; i < m_fileSets.size(); i++ )
- {
- FileSet fs = (FileSet)m_fileSets.get( i );
- DirectoryScanner ds = ScannerUtil.getDirectoryScanner( fs );
- ds.scan();
- String[] f = ds.getIncludedFiles();
- getContext().debug( i + ") Adding " + f.length + " files from directory " + ds.getBasedir() );
- for( int j = 0; j < f.length; j++ )
- {
- String pathname = f[ j ];
- if( pathname.endsWith( ".java" ) )
- {
- File file = new File( ds.getBasedir(), pathname );
- // file = project.resolveFile(file.getAbsolutePath());
- String classname = pathname.substring( 0, pathname.length() - ".java".length() );
- classname = classname.replace( File.separatorChar, '.' );
- files.put( file.getAbsolutePath(), classname );// it's a java file, add it.
- }
- }
- }
- return files;
- }
-
- protected ArrayList getFileSets()
- {
- return m_fileSets;
- }
-
- protected Hashtable getIncludedFiles()
- {
- return m_includedFiles;
- }
-
- protected Path getClassPath()
- {
- return m_classPath;
- }
-
- protected void setClassPath( Path classPath )
- {
- m_classPath = classPath;
- }
-
- protected Path getSourcePath()
- {
- return m_sourcePath;
- }
-
- protected void setSourcePath( Path sourcePath )
- {
- m_sourcePath = sourcePath;
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/MAudit.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/MAudit.java
deleted file mode 100644
index 0244bd940..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/MAudit.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.metamata;
-
-import java.io.File;
-import java.util.ArrayList;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Path;
-
-/**
- * Metamata Audit evaluates Java code for programming errors, weaknesses, and
- * style violation.
- *
- * Metamata Audit exists in three versions:
- *
- * The Lite version evaluates about 15 built-in rules.
- * The Pro version evaluates about 50 built-in rules.
- * The Enterprise version allows you to add your own customized rules via
- * the API.
- * For more information, visit the website at www.metamata.com
- *
- * @author Stephane Bailliez
- */
-public class MAudit
- extends AbstractMetamataTask
-{
- /*
- * As of Metamata 2.0, the command line of MAudit is as follows:
- * Usage
- * maudit ... ... [-unused ...]
- * Parameters
- * path File or directory to audit.
- * search-path File or directory to search for declaration uses.
- * Options
- * -arguments -A Includes command line arguments from file.
- * -classpath -cp Sets class path (also source path unless one
- * explicitly set). Overrides METAPATH/CLASSPATH.
- * -exit -x Exits after the first error.
- * -fix -f Automatically fixes certain errors.
- * -fullpath Prints full path for locations.
- * -help -h Prints help and exits.
- * -list -l Creates listing file for each audited file.
- * -offsets -off Offset and length for locations.
- * -output -o Prints output to file.
- * -quiet -q Suppresses copyright and summary messages.
- * -sourcepath Sets source path. Overrides SOURCEPATH.
- * -tab -t Prints a tab character after first argument.
- * -unused -u Finds declarations unused in search paths.
- * -verbose -v Prints all messages.
- * -version -V Prints version and exits.
- */
- //---------------------- PUBLIC METHODS ------------------------------------
-
- /**
- * pattern used by maudit to report the error for a file
- */
- /**
- * RE does not seems to support regexp pattern with comments so i'm
- * stripping it
- */
- // (?:file:)?((?#filepath).+):((?#line)\\d+)\\s*:\\s+((?#message).*)
- final static String AUDIT_PATTERN = "(?:file:)?(.+):(\\d+)\\s*:\\s+(.*)";
-
- private File m_outFile;
- private Path m_searchPath;
- private boolean m_fix;
- private boolean m_list;
- private boolean m_unused;
-
- /**
- * default constructor
- */
- public MAudit()
- {
- super( "com.metamata.gui.rc.MAudit" );
- }
-
- public void setFix( final boolean fix )
- {
- m_fix = fix;
- }
-
- public void setList( final boolean list )
- {
- m_list = list;
- }
-
- /**
- * set the destination file which should be an xml file
- */
- public void setTofile( final File outFile )
- {
- m_outFile = outFile;
- }
-
- public void setUnused( final boolean unused )
- {
- m_unused = unused;
- }
-
- public Path createSearchpath()
- {
- if( m_searchPath == null )
- {
- m_searchPath = new Path();
- }
- return m_searchPath;
- }
-
- protected ArrayList getOptions()
- throws TaskException
- {
- ArrayList options = new ArrayList( 512 );
- // there is a bug in Metamata 2.0 build 37. The sourcepath argument does
- // not work. So we will use the sourcepath prepended to classpath. (order
- // is important since Metamata looks at .class and .java)
- if( getSourcePath() != null )
- {
- getSourcePath().append( getClassPath() );// srcpath is prepended
- setClassPath( getSourcePath() );
- setSourcePath( null );// prevent from using -sourcepath
- }
-
- // don't forget to modify the pattern if you change the options reporting
- if( getClassPath() != null )
- {
- options.add( "-classpath" );
- options.add( getClassPath().toString() );
- }
- // suppress copyright msg when running, we will let it so that this
- // will be the only output to the console if in xml mode
- // options.add("-quiet");
- if( m_fix )
- {
- options.add( "-fix" );
- }
- options.add( "-fullpath" );
-
- // generate .maudit files much more detailed than the report
- // I don't like it very much, I think it could be interesting
- // to get all .maudit files and include them in the XML.
- if( m_list )
- {
- options.add( "-list" );
- }
- if( getSourcePath() != null )
- {
- options.add( "-sourcepath" );
- options.add( getSourcePath().toString() );
- }
-
- if( m_unused )
- {
- options.add( "-unused" );
- options.add( m_searchPath.toString() );
- }
- addAllArrayList( options, getIncludedFiles().keySet().iterator() );
- return options;
- }
-
- protected void validate()
- throws TaskException
- {
- super.validate();
- if( m_unused && m_searchPath == null )
- {
- throw new TaskException( "'searchpath' element must be set when looking for 'unused' declarations." );
- }
- if( !m_unused && m_searchPath != null )
- {
- getContext().warn( "'searchpath' element ignored. 'unused' attribute is disabled." );
- }
- }
-
- protected void cleanUp()
- throws TaskException
- {
- super.cleanUp();
- // at this point if -list is used, we should move
- // the .maudit file since we cannot choose their location :(
- // the .maudit files match the .java files
- // we'll use includedFiles to get the .maudit files.
-
- /*
- * if (out != null){
- * / close it if not closed by the handler...
- * }
- */
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/MMetrics.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/MMetrics.java
deleted file mode 100644
index d9c6ffd4b..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/MMetrics.java
+++ /dev/null
@@ -1,282 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.metamata;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.taskdefs.exec.ExecuteStreamHandler;
-import org.apache.tools.todo.types.Path;
-
-/**
- * Calculates global complexity and quality metrics on Java source code. You
- * will not be able to use this task with the evaluation version since as of
- * Metamata 2.0, Metrics does not support command line :-( For more information,
- * visit the website at www.metamata.com
- *
- * @author Stephane Bailliez
- */
-public class MMetrics extends AbstractMetamataTask
-{
- /*
- * The command line options as of Metamata 2.0 are as follows:
- * Usage
- * mmetrics ... ...
- * Parameters
- * path File or directory to measure.
- * Options
- * -arguments -A Includes command line arguments from file.
- * -classpath -cp Sets class path (also source path unless one
- * explicitly set). Overrides METAPATH/CLASSPATH.
- * -compilation-units Measure compilation units.
- * -files Measure compilation units.
- * -format -f Sets output format, default output file type.
- * -help -h Prints help and exits.
- * -indent -i Sets string used to indent labels one level.
- * -methods Measure methods, types, and compilation units.
- * -output -o Sets output file name.
- * -quiet -q Suppresses copyright message.
- * -sourcepath Sets source path. Overrides SOURCEPATH.
- * -types Measure types and compilation units.
- * -verbose -v Prints all messages.
- * -version -V Prints version and exits.
- * Format Options
- * comma csv Format output as comma-separated text.
- * html htm Format output as an HTML table.
- * tab tab-separated tsv Format output as tab-separated text.
- * text txt Format output as space-aligned text.
- */
- /**
- * the granularity mode. Should be one of 'files', 'methods' and 'types'.
- */
- protected String granularity = null;
-
- /**
- * the XML output file
- */
- protected File outFile = null;
-
- /**
- * the location of the temporary txt report
- */
- protected File tmpFile = createTmpFile();
-
- protected Path path = null;
-
- //--------------------------- PUBLIC METHODS -------------------------------
-
- /**
- * default constructor
- */
- public MMetrics()
- {
- super( "com.metamata.sc.MMetrics" );
- }
-
- /**
- * set the granularity of the audit. Should be one of 'files', 'methods' or
- * 'types'.
- *
- * @param granularity the audit reporting mode.
- */
- public void setGranularity( String granularity )
- {
- this.granularity = granularity;
- }
-
- /**
- * Set the output XML file
- *
- * @param file the xml file to write the XML report to.
- */
- public void setTofile( File file )
- {
- this.outFile = file;
- }
-
- /**
- * Set a new path (directory) to measure metrics from.
- *
- * @return the path instance to use.
- */
- public Path createPath()
- {
- if( path == null )
- {
- path = new Path();
- }
- return path;
- }
-
- protected ArrayList getOptions()
- throws TaskException
- {
- ArrayList options = new ArrayList( 512 );
- // there is a bug in Metamata 2.0 build 37. The sourcepath argument does
- // not work. So we will use the sourcepath prepended to classpath. (order
- // is important since Metamata looks at .class and .java)
- if( getSourcePath() != null )
- {
- getSourcePath().append( getClassPath() );// srcpath is prepended
- setClassPath( getSourcePath() );
- setSourcePath( null );// prevent from using -sourcepath
- }
-
- // don't forget to modify the pattern if you change the options reporting
- if( getClassPath() != null )
- {
- options.add( "-classpath" );
- options.add( getClassPath() );
- }
- options.add( "-output" );
- options.add( tmpFile.toString() );
-
- options.add( "-" + granularity );
-
- // display the metamata copyright
- // options.add( "-quiet");
- options.add( "-format" );
-
- // need this because that's what the handler is using, it's
- // way easier to process than any other separator
- options.add( "tab" );
-
- // specify a / as the indent character, used by the handler.
- options.add( "-i" );
- options.add( "/" );
-
- // directories
- final String[] dirs = path.list();
- for( int i = 0; i < dirs.length; i++ )
- {
- options.add( dirs[ i ] );
- }
- // files next.
- addAllArrayList( options, getIncludedFiles().keySet().iterator() );
- return options;
- }
-
- //------------------- PROTECTED / PRIVATE METHODS --------------------------
-
-
- // check for existing options and outfile, all other are optional
- protected void validate()
- throws TaskException
- {
- super.validate();
-
- if( !"files".equals( granularity ) && !"methods".equals( granularity )
- && !"types".equals( granularity ) )
- {
- throw new TaskException( "Metrics reporting granularity is invalid. Must be one of 'files', 'methods', 'types'" );
- }
- if( outFile == null )
- {
- throw new TaskException( "Output XML file must be set via 'tofile' attribute." );
- }
- if( path == null && getFileSets().size() == 0 )
- {
- throw new TaskException( "Must set either paths (path element) or files (fileset element)" );
- }
- // I don't accept dirs and files at the same time, I cannot recognize the semantic in the result
- if( path != null && getFileSets().size() > 0 )
- {
- throw new TaskException( "Cannot set paths (path element) and files (fileset element) at the same time" );
- }
- }
-
- /**
- * cleanup the temporary txt report
- *
- * @exception TaskException Description of Exception
- */
- protected void cleanUp()
- throws TaskException
- {
- try
- {
- super.cleanUp();
- }
- finally
- {
- if( tmpFile != null )
- {
- tmpFile.delete();
- tmpFile = null;
- }
- }
- }
-
- protected void execute0()
- throws TaskException
- {
- super.execute0();
- transformFile();
- }
-
- /**
- * transform the generated file via the handler This function can either be
- * called if the result is written to the output file via -output or we
- * could use the handler directly on stdout if not.
- *
- * @exception TaskException Description of Exception
- * @see #createStreamHandler()
- */
- protected void transformFile()
- throws TaskException
- {
- FileInputStream tmpStream = null;
- try
- {
- tmpStream = new FileInputStream( tmpFile );
- }
- catch( IOException e )
- {
- throw new TaskException( "Error reading temporary file: " + tmpFile, e );
- }
- FileOutputStream xmlStream = null;
- try
- {
- xmlStream = new FileOutputStream( outFile );
- ExecuteStreamHandler xmlHandler = new MMetricsStreamHandler( xmlStream );
- xmlHandler.setProcessOutputStream( tmpStream );
- xmlHandler.start();
- xmlHandler.stop();
- }
- catch( IOException e )
- {
- throw new TaskException( "Error creating output file: " + outFile, e );
- }
- finally
- {
- if( xmlStream != null )
- {
- try
- {
- xmlStream.close();
- }
- catch( IOException ignored )
- {
- }
- }
- if( tmpStream != null )
- {
- try
- {
- tmpStream.close();
- }
- catch( IOException ignored )
- {
- }
- }
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/MMetricsStreamHandler.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/MMetricsStreamHandler.java
deleted file mode 100644
index 8b09d798d..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/MMetricsStreamHandler.java
+++ /dev/null
@@ -1,478 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.metamata;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.text.DecimalFormat;
-import java.text.NumberFormat;
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.EmptyStackException;
-import java.util.Iterator;
-import java.util.Stack;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.sax.SAXTransformerFactory;
-import javax.xml.transform.sax.TransformerHandler;
-import javax.xml.transform.stream.StreamResult;
-import org.apache.tools.todo.taskdefs.exec.ExecuteStreamHandler;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.AttributesImpl;
-
-/**
- * A handy metrics handler. Most of this code was done only with the screenshots
- * on the documentation since the evaluation version as of this writing does not
- * allow to save metrics or to run it via command line.
- *
- * This class can be used to transform a text file or to process the output
- * stream directly.
- *
- * @author Stephane Bailliez
- */
-public class MMetricsStreamHandler
- implements ExecuteStreamHandler
-{
- /**
- * CLASS construct, it should be named something like 'MyClass'
- */
- protected final static String CLASS = "class";
-
- /**
- * package construct, it should be look like 'com.mycompany.something'
- */
- protected final static String PACKAGE = "package";
-
- /**
- * FILE construct, it should look like something 'MyClass.java' or
- * 'MyClass.class'
- */
- protected final static String FILE = "file";
-
- /**
- * METHOD construct, it should looke like something 'doSomething(...)' or
- * 'doSomething()'
- */
- protected final static String METHOD = "method";
-
- protected final static String[] ATTRIBUTES = {"name", "vg", "loc",
- "dit", "noa", "nrm", "nlm", "wmc", "rfc", "dac", "fanout", "cbo", "lcom", "nocl"
- };
-
- /**
- * the stack where are stored the metrics element so that they we can know
- * if we have to close an element or not.
- */
- protected Stack stack = new Stack();
-
- /**
- * metrics handler
- */
- protected TransformerHandler metricsHandler;
-
- /**
- * reader for stdout
- */
- protected InputStream metricsOutput;
-
- /**
- * this is where the XML output will go, should mostly be a file the caller
- * is responsible for flushing and closing this stream
- */
- protected OutputStream xmlOutputStream;
-
- MMetricsStreamHandler( OutputStream xmlOut )
- {
- this.xmlOutputStream = xmlOut;
- }
-
- /**
- * Ignore.
- *
- * @param p1 The new ProcessErrorStream value
- * @exception IOException Description of Exception
- */
- public void setProcessErrorStream( InputStream p1 )
- throws IOException
- {
- }
-
- /**
- * Ignore.
- *
- * @param p1 The new ProcessInputStream value
- * @exception IOException Description of Exception
- */
- public void setProcessInputStream( OutputStream p1 )
- throws IOException
- {
- }
-
- /**
- * Set the inputstream
- *
- * @param is The new ProcessOutputStream value
- * @exception IOException Description of Exception
- */
- public void setProcessOutputStream( InputStream is )
- throws IOException
- {
- metricsOutput = is;
- }
-
- public void start()
- throws IOException
- {
- // create the transformer handler that will be used to serialize
- // the output.
- TransformerFactory factory = TransformerFactory.newInstance();
- if( !factory.getFeature( SAXTransformerFactory.FEATURE ) )
- {
- throw new IllegalStateException( "Invalid Transformer factory feature" );
- }
- try
- {
- metricsHandler = ( (SAXTransformerFactory)factory ).newTransformerHandler();
- metricsHandler.setResult( new StreamResult( new OutputStreamWriter( xmlOutputStream, "UTF-8" ) ) );
- Transformer transformer = metricsHandler.getTransformer();
- transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
-
- // start the document with a 'metrics' root
- metricsHandler.startDocument();
- AttributesImpl attr = new AttributesImpl();
- attr.addAttribute( "", "company", "company", "CDATA", "metamata" );
- metricsHandler.startElement( "", "metrics", "metrics", attr );
-
- // now parse the whole thing
- parseOutput();
-
- }
- catch( Exception e )
- {
- throw new IOException( e.getMessage() );
- }
- }
-
- /**
- * Pretty dangerous business here.
- */
- public void stop()
- {
- try
- {
- // we need to pop everything and close elements that have not been
- // closed yet.
- while( stack.size() > 0 )
- {
- ElementEntry elem = (ElementEntry)stack.pop();
- metricsHandler.endElement( "", elem.getType(), elem.getType() );
- }
- // close the root
- metricsHandler.endElement( "", "metrics", "metrics" );
- // document is finished for good
- metricsHandler.endDocument();
- }
- catch( SAXException e )
- {
- e.printStackTrace();
- throw new IllegalStateException( e.getMessage() );
- }
- }
-
- /**
- * return the construct type of the element. We can hardly recognize the
- * type of a metrics element, so we are kind of forced to do some black
- * magic based on the name and indentation to recognize the type.
- *
- * @param elem the metrics element to guess for its type.
- * @return the type of the metrics element, either PACKAGE, FILE, CLASS or
- * METHOD.
- */
- protected String getConstructType( MetricsElement elem )
- {
- // ok no doubt, it's a file
- if( elem.isCompilationUnit() )
- {
- return FILE;
- }
-
- // same, we're sure it's a method
- if( elem.isMethod() )
- {
- return METHOD;
- }
-
- // if it's empty, and none of the above it should be a package
- if( stack.size() == 0 )
- {
- return PACKAGE;
- }
-
- // ok, this is now black magic time, we will guess the type based on
- // the previous type and its indent...
- final ElementEntry previous = (ElementEntry)stack.peek();
- final String prevType = previous.getType();
- final int prevIndent = previous.getIndent();
- final int indent = elem.getIndent();
- // we're just under a file with a bigger indent so it's a class
- if( prevType.equals( FILE ) && indent > prevIndent )
- {
- return CLASS;
- }
-
- // we're just under a class with a greater or equals indent, it's a class
- // (there might be several classes in a compilation unit and inner classes as well)
- if( prevType.equals( CLASS ) && indent >= prevIndent )
- {
- return CLASS;
- }
-
- // we assume the other are package
- return PACKAGE;
- }
-
- /**
- * Create all attributes of a MetricsElement skipping those who have an
- * empty string
- *
- * @param elem
- * @return Description of the Returned Value
- */
- protected Attributes createAttributes( MetricsElement elem )
- {
- AttributesImpl impl = new AttributesImpl();
- int i = 0;
- String name = ATTRIBUTES[ i++ ];
- impl.addAttribute( "", name, name, "CDATA", elem.getName() );
- Iterator metrics = elem.getMetrics();
- for( ; metrics.hasNext(); i++ )
- {
- String value = (String)metrics.next();
- if( value.length() > 0 )
- {
- name = ATTRIBUTES[ i ];
- impl.addAttribute( "", name, name, "CDATA", value );
- }
- }
- return impl;
- }
-
- /**
- * read each line and process it
- *
- * @exception IOException Description of Exception
- * @exception SAXException Description of Exception
- */
- protected void parseOutput()
- throws IOException, SAXException, ParseException
- {
- BufferedReader br = new BufferedReader( new InputStreamReader( metricsOutput ) );
- String line = null;
- while( ( line = br.readLine() ) != null )
- {
- processLine( line );
- }
- }
-
- /**
- * Process a metrics line. If the metrics is invalid and that this is not
- * the header line, it is display as info.
- *
- * @param line the line to process, it is normally a line full of metrics.
- * @exception SAXException Description of Exception
- */
- protected void processLine( String line )
- throws SAXException, ParseException
- {
- if( line.startsWith( "Construct\tV(G)\tLOC\tDIT\tNOA\tNRM\tNLM\tWMC\tRFC\tDAC\tFANOUT\tCBO\tLCOM\tNOCL" ) )
- {
- return;
- }
- MetricsElement elem = MetricsElement.parse( line );
- startElement( elem );
- }
-
- /**
- * Start a new construct. Elements are popped until we are on the same
- * parent node, then the element type is guessed and pushed on the stack.
- *
- * @param elem the element to process.
- * @throws SAXException thrown if there is a problem when sending SAX
- * events.
- */
- protected void startElement( MetricsElement elem )
- throws SAXException
- {
- // if there are elements in the stack we possibly need to close one or
- // more elements previous to this one until we got its parent
- int indent = elem.getIndent();
- if( stack.size() > 0 )
- {
- ElementEntry previous = (ElementEntry)stack.peek();
- // close nodes until you got the parent.
- try
- {
- while( indent <= previous.getIndent() && stack.size() > 0 )
- {
- stack.pop();
- metricsHandler.endElement( "", previous.getType(), previous.getType() );
- previous = (ElementEntry)stack.peek();
- }
- }
- catch( EmptyStackException ignored )
- {
- }
- }
-
- // ok, now start the new construct
- String type = getConstructType( elem );
- Attributes attrs = createAttributes( elem );
- metricsHandler.startElement( "", type, type, attrs );
-
- // make sure we keep track of what we did, that's history
- stack.push( new ElementEntry( type, indent ) );
- }
-
- /**
- * helper class to keep track of elements via its type and indent that's all
- * we need to guess a type.
- *
- * @author RT
- */
- private final static class ElementEntry
- {
- private int indent;
- private String type;
-
- ElementEntry( String type, int indent )
- {
- this.type = type;
- this.indent = indent;
- }
-
- public int getIndent()
- {
- return indent;
- }
-
- public String getType()
- {
- return type;
- }
- }
-}
-
-class MetricsElement
-{
-
- private final static NumberFormat METAMATA_NF;
-
- private final static NumberFormat NEUTRAL_NF;
-
- private String construct;
-
- private int indent;
-
- private ArrayList metrics;
-
- static
- {
- METAMATA_NF = NumberFormat.getInstance();
- METAMATA_NF.setMaximumFractionDigits( 1 );
- NEUTRAL_NF = NumberFormat.getInstance();
- if( NEUTRAL_NF instanceof DecimalFormat )
- {
- ( (DecimalFormat)NEUTRAL_NF ).applyPattern( "###0.###;-###0.###" );
- }
- NEUTRAL_NF.setMaximumFractionDigits( 1 );
- }
-
- MetricsElement( int indent, String construct, ArrayList metrics )
- {
- this.indent = indent;
- this.construct = construct;
- this.metrics = metrics;
- }
-
- public static MetricsElement parse( String line )
- throws ParseException
- {
- final ArrayList metrics = new ArrayList();
- int pos;
-
- // i'm using indexOf since I need to know if there are empty strings
- // between tabs and I find it easier than with StringTokenizer
- while( ( pos = line.indexOf( '\t' ) ) != -1 )
- {
- String token = line.substring( 0, pos );
- // only parse what coudl be a valid number. ie not constructs nor no value
- /*
- * if (metrics.size() != 0 || token.length() != 0){
- * Number num = METAMATA_NF.parse(token); // parse with Metamata NF
- * token = NEUTRAL_NF.format(num.doubleValue()); // and format with a neutral NF
- * }
- */
- metrics.add( token );
- line = line.substring( pos + 1 );
- }
- metrics.add( line );
-
- // there should be exactly 14 tokens (1 name + 13 metrics), if not, there is a problem !
- if( metrics.size() != 14 )
- {
- throw new ParseException( "Could not parse the following line as a metrics: -->" + line + "<--", -1 );
- }
-
- // remove the first token it's made of the indentation string and the
- // construct name, we'll need all this to figure out what type of
- // construct it is since we lost all semantics :(
- // (#indent[/]*)(#construct.*)
- String name = (String)metrics.get( 0 );
- metrics.remove( 0 );
- int indent = 0;
- pos = name.lastIndexOf( '/' );
- if( pos != -1 )
- {
- name = name.substring( pos + 1 );
- indent = pos + 1;// indentation is last position of token + 1
- }
- return new MetricsElement( indent, name, metrics );
- }
-
- public int getIndent()
- {
- return indent;
- }
-
- public Iterator getMetrics()
- {
- return metrics.iterator();
- }
-
- public String getName()
- {
- return construct;
- }
-
- public boolean isCompilationUnit()
- {
- return ( construct.endsWith( ".java" ) || construct.endsWith( ".class" ) );
- }
-
- public boolean isMethod()
- {
- return ( construct.endsWith( "(...)" ) || construct.endsWith( "()" ) );
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/MParse.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/MParse.java
deleted file mode 100644
index 493863d36..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/MParse.java
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.metamata;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Random;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.avalon.excalibur.io.IOUtil;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.tools.todo.types.Argument;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.CommandlineJava;
-import org.apache.tools.todo.types.Path;
-
-/**
- * Simple Metamata MParse task based on the original written by Thomas Haas This version was
- * written for Metamata 2.0 available at
- * http://www.metamata.com
- *
- * @author Stephane Bailliez
- */
-public class MParse
- extends AbstractTask
-{
- private Path m_classpath;
- private Path m_sourcepath;
- private File m_metahome;
- private File m_target;
- private boolean m_verbose;
- private boolean m_debugparser;
- private boolean m_debugscanner;
- private boolean m_cleanup;
- private CommandlineJava m_cmdl = new CommandlineJava();
- private File m_optionsFile;
-
- public MParse()
- {
- m_cmdl.setVm( "java" );
- m_cmdl.setClassname( "com.metamata.jj.MParse" );
- }
-
- /**
- * create a temporary file in the current directory
- *
- * @return Description of the Returned Value
- */
- protected static final File createTmpFile()
- {
- // must be compatible with JDK 1.1 !!!!
- final long rand = ( new Random( System.currentTimeMillis() ) ).nextLong();
- File file = new File( "metamata" + rand + ".tmp" );
- return file;
- }
-
- /**
- * set the hack to cleanup the temp file
- *
- * @param value The new Cleanup value
- */
- public void setCleanup( boolean value )
- {
- m_cleanup = value;
- }
-
- /**
- * set parser debug mode
- *
- * @param flag The new Debugparser value
- */
- public void setDebugparser( boolean flag )
- {
- m_debugparser = flag;
- }
-
- /**
- * set scanner debug mode
- *
- * @param flag The new Debugscanner value
- */
- public void setDebugscanner( boolean flag )
- {
- m_debugscanner = flag;
- }
-
- /**
- * -mx or -Xmx depending on VM version
- *
- * @param max The new Maxmemory value
- */
- public void setMaxmemory( String max )
- {
- m_cmdl.addVmArgument( "-Xmx" + max );
- }
-
- /**
- * location of metamata dev environment
- *
- * @param metamatahome The new Metamatahome value
- */
- public void setMetamatahome( File metamatahome )
- {
- this.m_metahome = metamatahome;
- }
-
- /**
- * the .jj file to process
- *
- * @param target The new Target value
- */
- public void setTarget( File target )
- {
- this.m_target = target;
- }
-
- /**
- * set verbose mode
- *
- * @param flag The new Verbose value
- */
- public void setVerbose( boolean flag )
- {
- m_verbose = flag;
- }
-
- /**
- * create a classpath entry
- *
- * @return Description of the Returned Value
- */
- public Path createClasspath()
- {
- if( m_classpath == null )
- {
- m_classpath = new Path();
- }
- return m_classpath;
- }
-
- /**
- * Creates a nested jvmarg element.
- */
- public void addJvmarg( final Argument argument )
- {
- m_cmdl.addVmArgument( argument );
- }
-
- /**
- * creates a sourcepath entry
- *
- * @return Description of the Returned Value
- */
- public Path createSourcepath()
- {
- if( m_sourcepath == null )
- {
- m_sourcepath = new Path();
- }
- return m_sourcepath;
- }
-
- /**
- * execute the command line
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- try
- {
- setUp();
- doExecute();
- }
- finally
- {
- cleanUp();
- }
- }
-
- /**
- * check the options and build the command line
- *
- * @exception TaskException Description of Exception
- */
- protected void setUp()
- throws TaskException
- {
- checkOptions();
-
- // set the classpath as the jar files
- File[] jars = getMetamataLibs();
- final Path classPath = m_cmdl.createClasspath();
- for( int i = 0; i < jars.length; i++ )
- {
- classPath.addLocation( jars[ i ] );
- }
-
- // set the metamata.home property
- m_cmdl.addVmArgument( "-Dmetamata.home=" + m_metahome.getAbsolutePath() );
-
- // write all the options to a temp file and use it ro run the process
- String[] options = getOptions();
- m_optionsFile = createTmpFile();
- generateOptionsFile( m_optionsFile, options );
- m_cmdl.addArgument( "-arguments" );
- m_cmdl.addArgument( m_optionsFile.getAbsolutePath() );
- }
-
- /**
- * return an array of files containing the path to the needed libraries to
- * run metamata. The file are not checked for existence. You should do this
- * yourself if needed or simply let the forked process do it for you.
- *
- * @return array of jars/zips needed to run metamata.
- */
- protected File[] getMetamataLibs()
- {
- final ArrayList files = new ArrayList();
- files.add( new File( m_metahome, "lib/metamata.jar" ) );
- files.add( new File( m_metahome, "bin/lib/JavaCC.zip" ) );
-
- return (File[])files.toArray( new File[ files.size() ] );
- }
-
- /**
- * return all options of the command line as string elements
- *
- * @return The Options value
- */
- protected String[] getOptions()
- {
- ArrayList options = new ArrayList();
- if( m_verbose )
- {
- options.add( "-verbose" );
- }
- if( m_debugscanner )
- {
- options.add( "-ds" );
- }
- if( m_debugparser )
- {
- options.add( "-dp" );
- }
- if( m_classpath != null )
- {
- options.add( "-classpath" );
- options.add( m_classpath.toString() );
- }
- if( m_sourcepath != null )
- {
- options.add( "-sourcepath" );
- options.add( m_sourcepath.toString() );
- }
- options.add( m_target.getAbsolutePath() );
-
- return (String[])options.toArray( new String[ options.size() ] );
- }
-
- /**
- * execute the process with a specific handler
- */
- protected void doExecute()
- throws TaskException
- {
- // target has been checked as a .jj, see if there is a matching
- // java file and if it is needed to run to process the grammar
- String pathname = m_target.getAbsolutePath();
- int pos = pathname.length() - ".jj".length();
- pathname = pathname.substring( 0, pos ) + ".java";
- File javaFile = new File( pathname );
- if( javaFile.exists() && m_target.lastModified() < javaFile.lastModified() )
- {
- getContext().info( "Target is already build - skipping (" + m_target + ")" );
- return;
- }
-
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
- getContext().debug( m_cmdl.toString() );
- final String[] commandline = m_cmdl.getCommandline();
- exe.setCommandline( new Commandline( commandline ) );
- exe.setReturnCode( 0 );
- exe.execute();
- }
-
- /**
- * validate options set and resolve files and paths
- *
- * @throws TaskException thrown if an option has an incorrect state.
- */
- protected void checkOptions()
- throws TaskException
- {
- // check that the home is ok.
- if( m_metahome == null || !m_metahome.exists() )
- {
- throw new TaskException( "'metamatahome' must point to Metamata home directory." );
- }
- m_metahome = getContext().resolveFile( m_metahome.getPath() );
-
- // check that the needed jar exists.
- File[] jars = getMetamataLibs();
- for( int i = 0; i < jars.length; i++ )
- {
- if( !jars[ i ].exists() )
- {
- throw new TaskException( jars[ i ] + " does not exist. Check your metamata installation." );
- }
- }
-
- // check that the target is ok and resolve it.
- if( m_target == null || !m_target.isFile() || !m_target.getName().endsWith( ".jj" ) )
- {
- throw new TaskException( "Invalid target: " + m_target );
- }
- m_target = getContext().resolveFile( m_target.getPath() );
- }
-
- /**
- * clean up all the mess that we did with temporary objects
- */
- protected void cleanUp()
- {
- if( m_optionsFile != null )
- {
- m_optionsFile.delete();
- m_optionsFile = null;
- }
- if( m_cleanup )
- {
- String name = m_target.getName();
- int pos = name.length() - ".jj".length();
- name = "__jj" + name.substring( 0, pos ) + ".sunjj";
- final File sunjj = new File( m_target.getParent(), name );
- if( sunjj.exists() )
- {
- getContext().info( "Removing stale file: " + sunjj.getName() );
- sunjj.delete();
- }
- }
- }
-
- /**
- * write all options to a file with one option / line
- *
- * @param tofile the file to write the options to.
- * @param options the array of options element to write to the file.
- * @throws TaskException thrown if there is a problem while writing to the
- * file.
- */
- protected void generateOptionsFile( File tofile, String[] options )
- throws TaskException
- {
- FileWriter fw = null;
- try
- {
- fw = new FileWriter( tofile );
- PrintWriter pw = new PrintWriter( fw );
- for( int i = 0; i < options.length; i++ )
- {
- pw.println( options[ i ] );
- }
- pw.flush();
- }
- catch( IOException e )
- {
- throw new TaskException( "Error while writing options file " + tofile, e );
- }
- finally
- {
- IOUtil.shutdownWriter( fw );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/Violation.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/Violation.java
deleted file mode 100644
index cdcd369de..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/metamata/Violation.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.metamata;
-
-/**
- * the class used to report violation information
- */
-final class Violation
-{
- private final String m_error;
- private final int m_line;
-
- public Violation( final String error, final int line )
- {
- m_error = error;
- m_line = line;
- }
-
- protected String getError()
- {
- return m_error;
- }
-
- protected int getLine()
- {
- return m_line;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/Action.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/Action.java
deleted file mode 100644
index 741b57f49..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/Action.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.net;
-
-import java.util.Locale;
-import org.apache.tools.todo.types.EnumeratedAttribute;
-
-public class Action
- extends EnumeratedAttribute
-{
- private final static String[] validActions = new String[]
- {
- "send", "put", "recv", "get", "del", "delete", "list", "mkdir"
- };
-
- public int getAction()
- {
- String actionL = getValue().toLowerCase( Locale.US );
- if( actionL.equals( "send" ) ||
- actionL.equals( "put" ) )
- {
- return FTP.SEND_FILES;
- }
- else if( actionL.equals( "recv" ) ||
- actionL.equals( "get" ) )
- {
- return FTP.GET_FILES;
- }
- else if( actionL.equals( "del" ) ||
- actionL.equals( "delete" ) )
- {
- return FTP.DEL_FILES;
- }
- else if( actionL.equals( "list" ) )
- {
- return FTP.LIST_FILES;
- }
- else if( actionL.equals( "mkdir" ) )
- {
- return FTP.MK_DIR;
- }
- return FTP.SEND_FILES;
- }
-
- public String[] getValues()
- {
- return validActions;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/AntTelnetClient.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/AntTelnetClient.java
deleted file mode 100644
index 3eddb954e..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/AntTelnetClient.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.net;
-
-import com.oroinc.net.telnet.TelnetClient;
-import java.io.InputStream;
-import java.io.OutputStream;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * This class handles the abstraction of the telnet protocol. Currently it
- * is a wrapper around ORO 's NetComponents
- */
-public class AntTelnetClient
- extends TelnetClient
-{
- private TelnetTask m_task;
-
- public AntTelnetClient( final TelnetTask task )
- {
- m_task = task;
- }
-
- /**
- * Write this string to the telnet session.
- */
- public void sendString( final String string, final boolean echoString )
- throws TaskException
- {
- final OutputStream output = this.getOutputStream();
- m_task.doSendString( output, string, echoString );
- }
-
- /**
- * Read from the telnet session until the string we are waiting for is
- * found
- */
- public void waitForString( final String string )
- throws TaskException
- {
- waitForString( string, null );
- }
-
- /**
- * Read from the telnet session until the string we are waiting for is
- * found or the timeout has been reached
- *
- * @parm s The string to wait on
- * @parm timeout The maximum number of seconds to wait
- */
- public void waitForString( final String string,
- final Integer timeout )
- throws TaskException
- {
- final InputStream input = this.getInputStream();
- m_task.doWaitForString( input, string, timeout );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/FTP.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/FTP.java
deleted file mode 100644
index b1bc204c2..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/FTP.java
+++ /dev/null
@@ -1,898 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.net;
-
-import com.oroinc.net.ftp.FTPClient;
-import com.oroinc.net.ftp.FTPFile;
-import com.oroinc.net.ftp.FTPReply;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import org.apache.avalon.excalibur.io.FileUtil;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.FileScanner;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.ScannerUtil;
-
-/**
- * Basic FTP client that performs the following actions:
- *
- * send - send files to a remote server. This is the
- * default action.
- * get - retrive files from a remote server.
- * del - delete files from a remote server.
- * list - create a file listing.
- *
- * Note: Some FTP servers - notably the Solaris server - seem
- * to hold data ports open after a "retr" operation, allowing them to timeout
- * instead of shutting them down cleanly. This happens in active or passive
- * mode, and the ports will remain open even after ending the FTP session. FTP
- * "send" operations seem to close ports immediately. This behavior may cause
- * problems on some systems when downloading large sets of files.
- *
- * @author Roger Vaughn
- * rvaughn@seaconinc.com
- * @author Glenn McAllister glennm@ca.ibm.com
- *
- * @author Magesh Umasankar
- */
-public class FTP
- extends AbstractTask
-{
- protected final static int SEND_FILES = 0;
- protected final static int GET_FILES = 1;
- protected final static int DEL_FILES = 2;
- protected final static int LIST_FILES = 3;
- protected final static int MK_DIR = 4;
-
- protected final static String[] ACTION_STRS = new String[]
- {
- "sending",
- "getting",
- "deleting",
- "listing",
- "making directory"
- };
-
- protected final static String[] COMPLETED_ACTION_STRS = new String[]
- {
- "sent",
- "retrieved",
- "deleted",
- "listed",
- "created directory"
- };
-
- private boolean m_binary = true;
- private boolean m_passive;
- private boolean m_verbose;
- private boolean m_newerOnly;
- private int m_action = SEND_FILES;
- private ArrayList m_filesets = new ArrayList();
- private ArrayList m_dirCache = new ArrayList();
- private int m_transferred;
- private String m_remoteFileSep = "/";
- private int m_port = 21;
- private boolean m_skipFailedTransfers;
- private int m_skipped;
- private boolean m_ignoreNoncriticalErrors;
- private File m_listing;
- private String m_password;
- private String m_remotedir;
- private String m_server;
- private String m_userid;
-
- /**
- * Sets the FTP action to be taken. Currently accepts "put", "get", "del",
- * "mkdir" and "list".
- *
- * @param action The new Action value
- * @exception TaskException Description of Exception
- */
- public void setAction( Action action )
- throws TaskException
- {
- m_action = action.getAction();
- }
-
- /**
- * Specifies whether to use binary-mode or text-mode transfers. Set to true
- * to send binary mode. Binary mode is enabled by default.
- *
- * @param binary The new Binary value
- */
- public void setBinary( boolean binary )
- {
- m_binary = binary;
- }
-
- /**
- * A synonym for setNewer. Set to true to transmit only new or changed
- * files.
- *
- * @param depends The new Depends value
- */
- public void setDepends( boolean depends )
- {
- m_newerOnly = depends;
- }
-
- /**
- * set the flag to skip errors on dir creation (and maybe later other server
- * specific errors)
- *
- * @param ignoreNoncriticalErrors The new IgnoreNoncriticalErrors value
- */
- public void setIgnoreNoncriticalErrors( boolean ignoreNoncriticalErrors )
- {
- m_ignoreNoncriticalErrors = ignoreNoncriticalErrors;
- }
-
- /**
- * The output file for the "list" action. This attribute is ignored for any
- * other actions.
- *
- * @param listing The new Listing value
- * @exception TaskException Description of Exception
- */
- public void setListing( File listing )
- throws TaskException
- {
- m_listing = listing;
- }
-
- /**
- * Set to true to transmit only files that are new or changed from their
- * remote counterparts. The default is to transmit all files.
- *
- * @param newer The new Newer value
- */
- public void setNewer( boolean newer )
- {
- m_newerOnly = newer;
- }
-
- /**
- * Specifies whether to use passive mode. Set to true if you are behind a
- * firewall and cannot connect without it. Passive mode is disabled by
- * default.
- *
- * @param passive The new Passive value
- */
- public void setPassive( boolean passive )
- {
- m_passive = passive;
- }
-
- /**
- * Sets the login password for the given user id.
- *
- * @param password The new Password value
- */
- public void setPassword( String password )
- {
- m_password = password;
- }
-
- /**
- * Sets the FTP port used by the remote server.
- *
- * @param port The new Port value
- */
- public void setPort( int port )
- {
- m_port = port;
- }
-
- /**
- * Sets the remote directory where files will be placed. This may be a
- * relative or absolute path, and must be in the path syntax expected by the
- * remote server. No correction of path syntax will be performed.
- *
- * @param dir The new Remotedir value
- */
- public void setRemotedir( String dir )
- {
- m_remotedir = dir;
- }
-
- /**
- * Sets the remote file separator character. This normally defaults to the
- * Unix standard forward slash, but can be manually overridden using this
- * call if the remote server requires some other separator. Only the first
- * character of the string is used.
- *
- * @param separator The new Separator value
- */
- public void setSeparator( String separator )
- {
- m_remoteFileSep = separator;
- }
-
- /**
- * Sets the FTP server to send files to.
- *
- * @param server The new Server value
- */
- public void setServer( String server )
- {
- m_server = server;
- }
-
- /**
- * set the failed transfer flag
- *
- * @param skipFailedTransfers The new SkipFailedTransfers value
- */
- public void setSkipFailedTransfers( boolean skipFailedTransfers )
- {
- m_skipFailedTransfers = skipFailedTransfers;
- }
-
- /**
- * Sets the login user id to use on the specified server.
- *
- * @param userid The new Userid value
- */
- public void setUserid( String userid )
- {
- m_userid = userid;
- }
-
- /**
- * Set to true to receive notification about each file as it is transferred.
- *
- * @param verbose The new Verbose value
- */
- public void setVerbose( boolean verbose )
- {
- m_verbose = verbose;
- }
-
- /**
- * Adds a set of files (nested fileset attribute).
- *
- * @param set The feature to be added to the Fileset attribute
- */
- public void addFileset( FileSet set )
- {
- m_filesets.add( set );
- }
-
- /**
- * Runs the task.
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- validate();
-
- FTPClient ftp = null;
-
- try
- {
- getContext().debug( "Opening FTP connection to " + m_server );
-
- ftp = new FTPClient();
-
- ftp.connect( m_server, m_port );
- if( !FTPReply.isPositiveCompletion( ftp.getReplyCode() ) )
- {
- throw new TaskException( "FTP connection failed: " + ftp.getReplyString() );
- }
-
- getContext().debug( "connected" );
- getContext().debug( "logging in to FTP server" );
-
- if( !ftp.login( m_userid, m_password ) )
- {
- throw new TaskException( "Could not login to FTP server" );
- }
-
- getContext().debug( "login succeeded" );
-
- if( m_binary )
- {
- ftp.setFileType( com.oroinc.net.ftp.FTP.IMAGE_FILE_TYPE );
- if( !FTPReply.isPositiveCompletion( ftp.getReplyCode() ) )
- {
- throw new TaskException(
- "could not set transfer type: " +
- ftp.getReplyString() );
- }
- }
-
- if( m_passive )
- {
- getContext().debug( "entering passive mode" );
- ftp.enterLocalPassiveMode();
- if( !FTPReply.isPositiveCompletion( ftp.getReplyCode() ) )
- {
- throw new TaskException(
- "could not enter into passive mode: " +
- ftp.getReplyString() );
- }
- }
-
- // If the action is MK_DIR, then the specified remote directory is the
- // directory to create.
-
- if( m_action == MK_DIR )
- {
-
- makeRemoteDir( ftp, m_remotedir );
-
- }
- else
- {
- if( m_remotedir != null )
- {
- getContext().debug( "changing the remote directory" );
- ftp.changeWorkingDirectory( m_remotedir );
- if( !FTPReply.isPositiveCompletion( ftp.getReplyCode() ) )
- {
- throw new TaskException(
- "could not change remote directory: " +
- ftp.getReplyString() );
- }
- }
- getContext().info( ACTION_STRS[ m_action ] + " files" );
- transferFiles( ftp );
- }
-
- }
- catch( IOException ex )
- {
- throw new TaskException( "error during FTP transfer: " + ex );
- }
- finally
- {
- if( ftp != null && ftp.isConnected() )
- {
- try
- {
- getContext().debug( "disconnecting" );
- ftp.logout();
- ftp.disconnect();
- }
- catch( IOException ex )
- {
- // ignore it
- }
- }
- }
- }
-
- /**
- * Retrieve a single file to the remote host. filename
may
- * contain a relative path specification. The file will then be retreived
- * using the entire relative path spec - no attempt is made to change
- * directories. It is anticipated that this may eventually cause problems
- * with some FTP servers, but it simplifies the coding.
- *
- * @param ftp Description of Parameter
- * @param dir Description of Parameter
- * @param filename Description of Parameter
- * @exception IOException Description of Exception
- * @exception TaskException Description of Exception
- */
- protected void getFile( FTPClient ftp, String dir, String filename )
- throws IOException, TaskException
- {
- OutputStream outstream = null;
- try
- {
- final String filename1 = dir;
- File result;
- result = getContext().resolveFile( filename1 );
- final File file = FileUtil.resolveFile( result, filename );
-
- if( m_newerOnly && isUpToDate( ftp, file, remoteResolveFile( filename ) ) )
- {
- return;
- }
-
- if( m_verbose )
- {
- getContext().info( "transferring " + filename + " to " + file.getAbsolutePath() );
- }
-
- final File parent = file.getParentFile();
- if( !parent.exists() )
- {
- parent.mkdirs();
- }
- outstream = new BufferedOutputStream( new FileOutputStream( file ) );
- ftp.retrieveFile( remoteResolveFile( filename ), outstream );
-
- if( !FTPReply.isPositiveCompletion( ftp.getReplyCode() ) )
- {
- String s = "could not get file: " + ftp.getReplyString();
- if( m_skipFailedTransfers == true )
- {
- getContext().warn( s );
- m_skipped++;
- }
- else
- {
- throw new TaskException( s );
- }
-
- }
- else
- {
- getContext().debug( "File " + file.getAbsolutePath() + " copied from " + m_server );
- m_transferred++;
- }
- }
- finally
- {
- if( outstream != null )
- {
- try
- {
- outstream.close();
- }
- catch( IOException ex )
- {
- // ignore it
- }
- }
- }
- }
-
- /**
- * Checks to see if the remote file is current as compared with the local
- * file. Returns true if the remote file is up to date.
- */
- protected boolean isUpToDate( FTPClient ftp, File localFile, String remoteFile )
- throws IOException, TaskException
- {
- getContext().debug( "checking date for " + remoteFile );
-
- FTPFile[] files = ftp.listFiles( remoteFile );
-
- // For Microsoft's Ftp-Service an Array with length 0 is
- // returned if configured to return listings in "MS-DOS"-Format
- if( files == null || files.length == 0 )
- {
- // If we are sending files, then assume out of date.
- // If we are getting files, then throw an error
-
- if( m_action == SEND_FILES )
- {
- getContext().debug( "Could not date test remote file: " + remoteFile + "assuming out of date." );
- return false;
- }
- else
- {
- throw new TaskException( "could not date test remote file: " +
- ftp.getReplyString() );
- }
- }
-
- long remoteTimestamp = files[ 0 ].getTimestamp().getTime().getTime();
- long localTimestamp = localFile.lastModified();
- if( m_action == SEND_FILES )
- {
- return remoteTimestamp > localTimestamp;
- }
- else
- {
- return localTimestamp > remoteTimestamp;
- }
- }
-
- /**
- * Checks to see that all required parameters are set.
- *
- * @exception TaskException Description of Exception
- */
- private void validate()
- throws TaskException
- {
- if( m_server == null )
- {
- throw new TaskException( "server attribute must be set!" );
- }
- if( m_userid == null )
- {
- throw new TaskException( "userid attribute must be set!" );
- }
- if( m_password == null )
- {
- throw new TaskException( "password attribute must be set!" );
- }
-
- if( ( m_action == LIST_FILES ) && ( m_listing == null ) )
- {
- throw new TaskException( "listing attribute must be set for list action!" );
- }
-
- if( m_action == MK_DIR && m_remotedir == null )
- {
- throw new TaskException( "remotedir attribute must be set for mkdir action!" );
- }
- }
-
- /**
- * Creates all parent directories specified in a complete relative pathname.
- * Attempts to create existing directories will not cause errors.
- */
- protected void createParents( FTPClient ftp, String filename )
- throws IOException, TaskException
- {
- ArrayList parents = new ArrayList();
- File dir = new File( filename );
- String dirname;
-
- while( ( dirname = dir.getParent() ) != null )
- {
- dir = new File( dirname );
- parents.add( dir );
- }
-
- for( int i = parents.size() - 1; i >= 0; i-- )
- {
- dir = (File)parents.get( i );
- if( !m_dirCache.contains( dir ) )
- {
- getContext().debug( "creating remote directory " + remoteResolveFile( dir.getPath() ) );
- ftp.makeDirectory( remoteResolveFile( dir.getPath() ) );
- // Both codes 550 and 553 can be produced by FTP Servers
- // to indicate that an attempt to create a directory has
- // failed because the directory already exists.
- int result = ftp.getReplyCode();
- if( !FTPReply.isPositiveCompletion( result ) &&
- ( result != 550 ) && ( result != 553 ) &&
- !m_ignoreNoncriticalErrors )
- {
- throw new TaskException(
- "could not create directory: " +
- ftp.getReplyString() );
- }
- m_dirCache.add( dir );
- }
- }
- }
-
- /**
- * Delete a file from the remote host.
- */
- protected void delFile( FTPClient ftp, String filename )
- throws IOException, TaskException
- {
- if( m_verbose )
- {
- getContext().info( "deleting " + filename );
- }
-
- if( !ftp.deleteFile( remoteResolveFile( filename ) ) )
- {
- String s = "could not delete file: " + ftp.getReplyString();
- if( m_skipFailedTransfers == true )
- {
- getContext().warn( s );
- m_skipped++;
- }
- else
- {
- throw new TaskException( s );
- }
- }
- else
- {
- getContext().debug( "File " + filename + " deleted from " + m_server );
- m_transferred++;
- }
- }
-
- /**
- * List information about a single file from the remote host. filename
- * may contain a relative path specification. The file listing will then be
- * retrieved using the entire relative path spec - no attempt is made to
- * change directories. It is anticipated that this may eventually cause
- * problems with some FTP servers, but it simplifies the coding.
- */
- protected void listFile( FTPClient ftp, BufferedWriter bw, String filename )
- throws IOException, TaskException
- {
- if( m_verbose )
- {
- getContext().info( "listing " + filename );
- }
-
- FTPFile ftpfile = ftp.listFiles( remoteResolveFile( filename ) )[ 0 ];
- bw.write( ftpfile.toString() );
- bw.newLine();
-
- m_transferred++;
- }
-
- /**
- * Create the specified directory on the remote host.
- *
- * @param ftp The FTP client connection
- * @param dir The directory to create (format must be correct for host type)
- * @exception IOException Description of Exception
- * @exception TaskException Description of Exception
- */
- protected void makeRemoteDir( FTPClient ftp, String dir )
- throws IOException, TaskException
- {
- if( m_verbose )
- {
- getContext().info( "creating directory: " + dir );
- }
-
- if( !ftp.makeDirectory( dir ) )
- {
- // codes 521, 550 and 553 can be produced by FTP Servers
- // to indicate that an attempt to create a directory has
- // failed because the directory already exists.
-
- int rc = ftp.getReplyCode();
- if( !( m_ignoreNoncriticalErrors && ( rc == 550 || rc == 553 || rc == 521 ) ) )
- {
- throw new TaskException( "could not create directory: " +
- ftp.getReplyString() );
- }
-
- if( m_verbose )
- {
- getContext().info( "directory already exists" );
- }
- }
- else
- {
- if( m_verbose )
- {
- getContext().info( "directory created OK" );
- }
- }
- }
-
- /**
- * Correct a file path to correspond to the remote host requirements. This
- * implementation currently assumes that the remote end can handle
- * Unix-style paths with forward-slash separators. This can be overridden
- * with the separator
task parameter. No attempt is made to
- * determine what syntax is appropriate for the remote host.
- *
- * @param file Description of Parameter
- * @return Description of the Returned Value
- */
- protected String remoteResolveFile( final String file )
- {
- return file.replace( System.getProperty( "file.separator" ).charAt( 0 ),
- m_remoteFileSep.charAt( 0 ) );
- }
-
- /**
- * Sends a single file to the remote host. filename
may contain
- * a relative path specification. When this is the case, sendFile
- * will attempt to create any necessary parent directories before sending
- * the file. The file will then be sent using the entire relative path spec
- * - no attempt is made to change directories. It is anticipated that this
- * may eventually cause problems with some FTP servers, but it simplifies
- * the coding.
- *
- * @param ftp Description of Parameter
- * @param dir Description of Parameter
- * @param filename Description of Parameter
- * @exception IOException Description of Exception
- * @exception TaskException Description of Exception
- */
- protected void sendFile( FTPClient ftp, final String dir, final String filename )
- throws IOException, TaskException
- {
- InputStream instream = null;
- try
- {
- File file = getContext().resolveFile( new File( dir, filename ).getPath() );
-
- if( m_newerOnly && isUpToDate( ftp, file, remoteResolveFile( filename ) ) )
- {
- return;
- }
-
- if( m_verbose )
- {
- getContext().info( "transferring " + file.getAbsolutePath() );
- }
-
- instream = new BufferedInputStream( new FileInputStream( file ) );
-
- createParents( ftp, filename );
-
- ftp.storeFile( remoteResolveFile( filename ), instream );
- boolean success = FTPReply.isPositiveCompletion( ftp.getReplyCode() );
- if( !success )
- {
- String s = "could not put file: " + ftp.getReplyString();
- if( m_skipFailedTransfers == true )
- {
- getContext().warn( s );
- m_skipped++;
- }
- else
- {
- throw new TaskException( s );
- }
-
- }
- else
- {
-
- getContext().debug( "File " + file.getAbsolutePath() + " copied to " + m_server );
- m_transferred++;
- }
- }
- finally
- {
- if( instream != null )
- {
- try
- {
- instream.close();
- }
- catch( IOException ex )
- {
- // ignore it
- }
- }
- }
- }
-
- /**
- * For each file in the fileset, do the appropriate action: send, get,
- * delete, or list.
- *
- * @param ftp Description of Parameter
- * @param fs Description of Parameter
- * @return Description of the Returned Value
- * @exception IOException Description of Exception
- * @exception TaskException Description of Exception
- */
- protected int transferFiles( FTPClient ftp, FileSet fs )
- throws IOException, TaskException
- {
- FileScanner ds;
-
- if( m_action == SEND_FILES )
- {
- ds = ScannerUtil.getDirectoryScanner( fs );
- }
- else
- {
- ds = new FTPDirectoryScanner( ftp );
- final FileScanner ds1 = ds;
- final TaskContext context = getContext();
- ScannerUtil.setupDirectoryScanner( fs, ds1, context );
- ds.scan();
- }
-
- String[] dsfiles = ds.getIncludedFiles();
- String dir = null;
- if( ( ds.getBasedir() == null ) && ( ( m_action == SEND_FILES ) || ( m_action == GET_FILES ) ) )
- {
- throw new TaskException( "the dir attribute must be set for send and get actions" );
- }
- else
- {
- if( ( m_action == SEND_FILES ) || ( m_action == GET_FILES ) )
- {
- dir = ds.getBasedir().getAbsolutePath();
- }
- }
-
- // If we are doing a listing, we need the output stream created now.
- BufferedWriter bw = null;
- if( m_action == LIST_FILES )
- {
- File pd = new File( m_listing.getParent() );
- if( !pd.exists() )
- {
- pd.mkdirs();
- }
- bw = new BufferedWriter( new FileWriter( m_listing ) );
- }
-
- for( int i = 0; i < dsfiles.length; i++ )
- {
- switch( m_action )
- {
- case SEND_FILES:
- {
- sendFile( ftp, dir, dsfiles[ i ] );
- break;
- }
-
- case GET_FILES:
- {
- getFile( ftp, dir, dsfiles[ i ] );
- break;
- }
-
- case DEL_FILES:
- {
- delFile( ftp, dsfiles[ i ] );
- break;
- }
-
- case LIST_FILES:
- {
- listFile( ftp, bw, dsfiles[ i ] );
- break;
- }
-
- default:
- {
- throw new TaskException( "unknown ftp action " + m_action );
- }
- }
- }
-
- if( m_action == LIST_FILES )
- {
- bw.close();
- }
-
- return dsfiles.length;
- }
-
- /**
- * Sends all files specified by the configured filesets to the remote
- * server.
- *
- * @param ftp Description of Parameter
- * @exception IOException Description of Exception
- * @exception TaskException Description of Exception
- */
- protected void transferFiles( FTPClient ftp )
- throws IOException, TaskException
- {
- m_transferred = 0;
- m_skipped = 0;
-
- if( m_filesets.size() == 0 )
- {
- throw new TaskException( "at least one fileset must be specified." );
- }
- else
- {
- // get files from filesets
- for( int i = 0; i < m_filesets.size(); i++ )
- {
- FileSet fs = (FileSet)m_filesets.get( i );
- if( fs != null )
- {
- transferFiles( ftp, fs );
- }
- }
- }
-
- getContext().info( m_transferred + " files " + COMPLETED_ACTION_STRS[ m_action ] );
- if( m_skipped != 0 )
- {
- getContext().info( m_skipped + " files were not successfully " + COMPLETED_ACTION_STRS[ m_action ] );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/FTPDirectoryScanner.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/FTPDirectoryScanner.java
deleted file mode 100644
index 3919cca0f..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/FTPDirectoryScanner.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.net;
-
-import com.oroinc.net.ftp.FTPClient;
-import com.oroinc.net.ftp.FTPFile;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.DirectoryScanner;
-
-class FTPDirectoryScanner
- extends DirectoryScanner
-{
- protected final FTPClient m_ftp;
-
- public FTPDirectoryScanner( final FTPClient ftp )
- {
- super();
- m_ftp = ftp;
- }
-
- public void scan()
- throws TaskException
- {
- if( getIncludes() == null )
- {
- // No includes supplied, so set it to 'matches all'
- setIncludes( new String[ 1 ] );
- getIncludes()[ 0 ] = "**";
- }
- if( getExcludes() == null )
- {
- setExcludes( new String[ 0 ] );
- }
-
- setFilesIncluded( new ArrayList() );
- setFilesNotIncluded( new ArrayList() );
- setFilesExcluded( new ArrayList() );
- setDirsIncluded( new ArrayList() );
- setDirsNotIncluded( new ArrayList() );
- setDirsExcluded( new ArrayList() );
-
- try
- {
- String cwd = m_ftp.printWorkingDirectory();
- scandir( ".", "", true );// always start from the current ftp working dir
- m_ftp.changeWorkingDirectory( cwd );
- }
- catch( IOException e )
- {
- throw new TaskException( "Unable to scan FTP server: ", e );
- }
- }
-
- protected void scandir( String dir, String vpath, boolean fast )
- throws TaskException
- {
- try
- {
- if( !m_ftp.changeWorkingDirectory( dir ) )
- {
- return;
- }
-
- FTPFile[] newfiles = m_ftp.listFiles();
- if( newfiles == null )
- {
- m_ftp.changeToParentDirectory();
- return;
- }
-
- for( int i = 0; i < newfiles.length; i++ )
- {
- FTPFile file = newfiles[ i ];
- if( !file.getName().equals( "." ) && !file.getName().equals( ".." ) )
- {
- if( file.isDirectory() )
- {
- String name = file.getName();
- if( isIncluded( name ) )
- {
- if( !isExcluded( name ) )
- {
- getDirsIncluded().add( name );
- if( fast )
- {
- scandir( name, vpath + name + File.separator, fast );
- }
- }
- else
- {
- getDirsExcluded().add( name );
- }
- }
- else
- {
- getDirsNotIncluded().add( name );
- if( fast && couldHoldIncluded( name ) )
- {
- scandir( name, vpath + name + File.separator, fast );
- }
- }
- if( !fast )
- {
- scandir( name, vpath + name + File.separator, fast );
- }
- }
- else
- {
- if( file.isFile() )
- {
- String name = vpath + file.getName();
- if( isIncluded( name ) )
- {
- if( !isExcluded( name ) )
- {
- getFilesIncluded().add( name );
- }
- else
- {
- getFilesExcluded().add( name );
- }
- }
- else
- {
- getFilesNotIncluded().add( name );
- }
- }
- }
- }
- }
- m_ftp.changeToParentDirectory();
- }
- catch( IOException e )
- {
- throw new TaskException( "Error while communicating with FTP server: ", e );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/MimeMail.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/MimeMail.java
deleted file mode 100644
index d4e291ab5..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/MimeMail.java
+++ /dev/null
@@ -1,401 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.net;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Properties;
-import javax.activation.DataHandler;
-import javax.activation.FileDataSource;
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.Transport;
-import javax.mail.internet.AddressException;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeBodyPart;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeMultipart;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.ScannerUtil;
-
-/**
- * A task to send SMTP email. This version has near identical syntax to the
- * SendEmail task, but is MIME aware. It also requires Sun's mail.jar and
- * activation.jar to compile and execute, which puts it clearly into the very
- * optional category.
- *
- * @author glenn_twiggs@bmc.com
- * @author steve_l@iseran.com steve loughran
- * @author ehatcher@apache.org Erik Hatcher
- * @author paulo.gaspar@krankikom.de Paulo Gaspar
- * @created 01 May 2001
- */
-public class MimeMail extends AbstractTask
-{
- /**
- * failure flag
- */
- private boolean failOnError = true;
-
- /**
- * sender
- */
- private String from = null;
-
- /**
- * host running SMTP
- */
- private String mailhost = "localhost";
-
- /**
- * any text
- */
- private String message = null;
-
- /**
- * message file (mutually exclusive from message)
- */
- private File messageFile = null;
-
- /**
- * TO recipients
- */
- private String toList = null;
-
- /**
- * CC (Carbon Copy) recipients
- */
- protected String ccList = null;
-
- /**
- * BCC (Blind Carbon Copy) recipients
- */
- protected String bccList = null;
-
- /**
- * subject field
- */
- private String subject = null;
-
- /**
- * file list
- */
- private ArrayList filesets = new ArrayList();
-
- /**
- * type of the text message, plaintext by default but text/html or text/xml
- * is quite feasible
- */
- private String messageMimeType = "text/plain";
-
- /**
- * Creates new instance
- */
- public MimeMail()
- {
- }
-
- // helper method to add recipients
- private static void addRecipients( MimeMessage msg,
- Message.RecipientType recipType,
- String addrUserName,
- String addrList
- )
- throws MessagingException, TaskException
- {
- if( ( null == addrList ) || ( addrList.trim().length() <= 0 ) )
- {
- return;
- }
-
- try
- {
- InternetAddress[] addrArray = InternetAddress.parse( addrList );
-
- if( ( null == addrArray ) || ( 0 == addrArray.length ) )
- {
- throw new TaskException( "Empty " + addrUserName + " recipients list was specified" );
- }
-
- msg.setRecipients( recipType, addrArray );
- }
- catch( AddressException ae )
- {
- throw new TaskException( "Invalid " + addrUserName + " recipient list" );
- }
- }
-
- /**
- * Sets the toList parameter of this build task.
- *
- * @param bccList The new BccList value
- */
- public void setBccList( String bccList )
- {
- this.bccList = bccList;
- }
-
- /**
- * Sets the toList parameter of this build task.
- *
- * @param ccList The new CcList value
- */
- public void setCcList( String ccList )
- {
- this.ccList = ccList;
- }
-
- /**
- * Sets the FailOnError attribute of the MimeMail object
- *
- * @param failOnError The new FailOnError value
- */
- public void setFailOnError( boolean failOnError )
- {
- this.failOnError = failOnError;
- }
-
- /**
- * Sets the "from" parameter of this build task.
- *
- * @param from Email address of sender.
- */
- public void setFrom( String from )
- {
- this.from = from;
- }
-
- /**
- * Sets the mailhost parameter of this build task.
- *
- * @param mailhost Mail host name.
- */
- public void setMailhost( String mailhost )
- {
- this.mailhost = mailhost;
- }
-
- /**
- * Sets the message parameter of this build task.
- *
- * @param message Message body of this email.
- */
- public void setMessage( String message )
- {
- this.message = message;
- }
-
- public void setMessageFile( File messageFile )
- {
- this.messageFile = messageFile;
- }
-
- /**
- * set type of the text message, plaintext by default but text/html or
- * text/xml is quite feasible
- *
- * @param type The new MessageMimeType value
- */
- public void setMessageMimeType( String type )
- {
- this.messageMimeType = type;
- }
-
- /**
- * Sets the subject parameter of this build task.
- *
- * @param subject Subject of this email.
- */
- public void setSubject( String subject )
- {
- this.subject = subject;
- }
-
- /**
- * Sets the toList parameter of this build task.
- *
- * @param toList Comma-separated list of email recipient addreses.
- */
- public void setToList( String toList )
- {
- this.toList = toList;
- }
-
- /**
- * Adds a set of files (nested fileset attribute).
- *
- * @param set The feature to be added to the Fileset attribute
- */
- public void addFileset( FileSet set )
- {
- filesets.add( set );
- }
-
- /**
- * here is where the mail is sent
- *
- * @exception MessagingException Description of Exception
- * @exception AddressException Description of Exception
- * @exception TaskException Description of Exception
- */
- public void doMail()
- throws MessagingException, AddressException, TaskException
- {
- Properties props = new Properties();
- props.put( "mail.smtp.host", mailhost );
-
- //Aside, the JDK is clearly unaware of the scottish 'session', which
- //involves excessive quantities of alcohol :-)
- Session sesh = Session.getDefaultInstance( props, null );
-
- //create the message
- MimeMessage msg = new MimeMessage( sesh );
-
- //set the sender
- getContext().debug( "message sender: " + from );
- msg.setFrom( new InternetAddress( from ) );
-
- // add recipient lists
- addRecipients( msg, Message.RecipientType.TO, "To", toList );
- addRecipients( msg, Message.RecipientType.CC, "Cc", ccList );
- addRecipients( msg, Message.RecipientType.BCC, "Bcc", bccList );
-
- if( subject != null )
- {
- getContext().debug( "subject: " + subject );
- msg.setSubject( subject );
- }
-
- //now the complex bit; adding multiple mime objects. And guessing
- //the file type
- MimeMultipart attachments = new MimeMultipart();
-
- //first a message
- if( messageFile != null )
- {
- int size = (int)messageFile.length();
- byte data[] = new byte[ size ];
-
- try
- {
- FileInputStream inStream = new FileInputStream( messageFile );
- inStream.read( data );
- inStream.close();
- message = new String( data );
- }
- catch( IOException e )
- {
- throw new TaskException( "Error", e );
- }
- }
-
- if( message != null )
- {
- MimeBodyPart textbody = new MimeBodyPart();
- textbody.setContent( message, messageMimeType );
- attachments.addBodyPart( textbody );
- }
-
- for( int i = 0; i < filesets.size(); i++ )
- {
- FileSet fs = (FileSet)filesets.get( i );
- if( fs != null )
- {
- DirectoryScanner ds = ScannerUtil.getDirectoryScanner( fs );
- String[] dsfiles = ds.getIncludedFiles();
- File baseDir = ds.getBasedir();
-
- for( int j = 0; j < dsfiles.length; j++ )
- {
- File file = new File( baseDir, dsfiles[ j ] );
- MimeBodyPart body;
- body = new MimeBodyPart();
- if( !file.exists() || !file.canRead() )
- {
- throw new TaskException( "File \"" + file.getAbsolutePath()
- + "\" does not exist or is not readable." );
- }
- getContext().debug( "Attaching " + file.toString() + " - " + file.length() + " bytes" );
- FileDataSource fileData = new FileDataSource( file );
- DataHandler fileDataHandler = new DataHandler( fileData );
- body.setDataHandler( fileDataHandler );
- body.setFileName( file.getName() );
- attachments.addBodyPart( body );
- }// for j
- }// if (fs != null)
- }// for i
-
- msg.setContent( attachments );
- getContext().info( "sending email " );
- Transport.send( msg );
- }
-
- /**
- * Executes this build task. throws org.apache.tools.ant.TaskException if
- * there is an error during task execution.
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- try
- {
- validate();
- doMail();
- }
- catch( Exception e )
- {
- if( failOnError )
- {
- throw new TaskException( "Error", e );
- }
- else
- {
- String text = e.toString();
- getContext().error( text );
- }
- }
- }
-
- /**
- * verify parameters
- *
- * @throws TaskException if something is invalid
- */
- public void validate()
- {
- if( from == null )
- {
- throw new TaskException( "Attribute \"from\" is required." );
- }
-
- if( ( toList == null ) && ( ccList == null ) && ( bccList == null ) )
- {
- throw new TaskException( "Attribute \"toList\", \"ccList\" or \"bccList\" is required." );
- }
-
- if( message == null && filesets.isEmpty() && messageFile == null )
- {
- throw new TaskException( "FileSet, \"message\", or \"messageFile\" is required." );
- }
-
- if( message != null && messageFile != null )
- {
- throw new TaskException( "Only one of \"message\" or \"messageFile\" may be specified." );
- }
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/TelnetRead.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/TelnetRead.java
deleted file mode 100644
index 9e1680c7b..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/TelnetRead.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.net;
-
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * This class reads the output from the connected server until the required
- * string is found.
- */
-public class TelnetRead
- extends TelnetSubTask
-{
- private Integer m_timeout;
-
- /**
- * Sets the default timeout if none has been set already
- */
- public void setDefaultTimeout( final Integer defaultTimeout )
- {
- if( m_timeout == null )
- {
- m_timeout = defaultTimeout;
- }
- }
-
- /**
- * Override any default timeouts
- */
- public void setTimeout( final Integer timeout )
- {
- m_timeout = timeout;
- }
-
- public void execute( final AntTelnetClient telnet )
- throws TaskException
- {
- telnet.waitForString( getTaskString(), m_timeout );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/TelnetSubTask.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/TelnetSubTask.java
deleted file mode 100644
index 6337962f4..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/TelnetSubTask.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.net;
-
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * This class is the parent of the Read and Write tasks. It handles the
- * common attributes for both.
- */
-public abstract class TelnetSubTask
-{
- private String m_taskString = "";
-
- public void setString( final String string )
- {
- m_taskString += string;
- }
-
- public void addContent( final String string )
- {
- setString( string );
- }
-
- public void execute( AntTelnetClient telnet )
- throws TaskException
- {
- throw new TaskException( "Shouldn't be able instantiate a SubTask directly" );
- }
-
- protected final String getTaskString()
- {
- return m_taskString;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/TelnetTask.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/TelnetTask.java
deleted file mode 100644
index 81dbd184d..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/TelnetTask.java
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.net;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Iterator;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-
-/**
- * Class to provide automated telnet protocol support for the Ant build tool
- *
- * @author Peter Donald
- * @author ScottCarlson@email.com
- * @version $Revision$
- */
-public class TelnetTask
- extends AbstractTask
-{
- /**
- * The userid to login with, if automated login is used
- */
- private String m_userid;
-
- /**
- * The password to login with, if automated login is used
- */
- private String m_password;
-
- /**
- * The server to connect to.
- */
- private String m_server;
-
- /**
- * The tcp port to connect to.
- */
- private int m_port = 23;
-
- /**
- * The list of read/write commands for this session
- */
- private ArrayList m_telnetTasks = new ArrayList();
-
- /**
- * If true, adds a CR to beginning of login script
- */
- private boolean m_addCarriageReturn;
-
- /**
- * Default time allowed for waiting for a valid response for all child
- * reads. A value of 0 means no limit.
- */
- private Integer m_defaultTimeout;
-
- /**
- * Set the tcp port to connect to attribute
- */
- public void setInitialCR( final boolean addCarriageReturn )
- {
- m_addCarriageReturn = addCarriageReturn;
- }
-
- /**
- * Set the password attribute
- */
- public void setPassword( final String password )
- {
- m_password = password;
- }
-
- /**
- * Set the tcp port to connect to attribute
- */
- public void setPort( final int port )
- {
- m_port = port;
- }
-
- /**
- * Set the server address attribute
- */
- public void setServer( final String server )
- {
- m_server = server;
- }
-
- /**
- * Change the default timeout to wait for valid responses
- */
- public void setTimeout( final Integer defaultTimeout )
- {
- m_defaultTimeout = defaultTimeout;
- }
-
- /**
- * Set the userid attribute
- */
- public void setUserid( final String userid )
- {
- m_userid = userid;
- }
-
- /**
- * A subTask <read> tag was found. Create the object, Save it in our
- * list, and return it.
- */
- public void addRead( final TelnetRead read )
- {
- m_telnetTasks.add( read );
- }
-
- /**
- * A subTask <write> tag was found. Create the object, Save it in our
- * list, and return it.
- */
- public void addWrite( final TelnetWrite write )
- {
- m_telnetTasks.add( write );
- }
-
- /**
- * Verify that all parameters are included. Connect and possibly login
- * Iterate through the list of Reads and writes
- */
- public void execute()
- throws TaskException
- {
- validate();
-
- /**
- * Create the telnet client object
- */
- final AntTelnetClient telnet = new AntTelnetClient( this );
- try
- {
- telnet.connect( m_server, m_port );
- }
- catch( final IOException ioe )
- {
- throw new TaskException( "Can't connect to " + m_server, ioe );
- }
- /**
- * Login if userid and password were specified
- */
- if( m_userid != null && m_password != null )
- {
- login( telnet );
- }
-
- processTasks( telnet );
- }
-
- /**
- * Process each sub command
- */
- private void processTasks( final AntTelnetClient telnet )
- throws TaskException
- {
- final Iterator tasks = m_telnetTasks.iterator();
- while( tasks != null && tasks.hasNext() )
- {
- final TelnetSubTask task = (TelnetSubTask)tasks.next();
- if( task instanceof TelnetRead && m_defaultTimeout != null )
- {
- ( (TelnetRead)task ).setDefaultTimeout( m_defaultTimeout );
- }
- task.execute( telnet );
- }
- }
-
- private void validate()
- throws TaskException
- {
- //A server name is required to continue
- if( m_server == null )
- {
- throw new TaskException( "No Server Specified" );
- }
-
- //A userid and password must appear together if they appear. They are
- //not required.
- if( m_userid == null && m_password != null )
- {
- throw new TaskException( "No Userid Specified" );
- }
- if( m_password == null && m_userid != null )
- {
- throw new TaskException( "No Password Specified" );
- }
- }
-
- /**
- * Process a 'typical' login. If it differs, use the read and write tasks
- * explicitely
- */
- private void login( final AntTelnetClient telnet )
- throws TaskException
- {
- if( m_addCarriageReturn )
- {
- telnet.sendString( "\n", true );
- }
- telnet.waitForString( "ogin:" );
- telnet.sendString( m_userid, true );
- telnet.waitForString( "assword:" );
- telnet.sendString( m_password, false );
- }
-
- protected void doSendString( final OutputStream output,
- final String string,
- final boolean echoString )
- throws TaskException
- {
- try
- {
- output.write( ( string + "\n" ).getBytes() );
- if( echoString )
- {
- getContext().info( string );
- }
- output.flush();
- }
- catch( final Exception e )
- {
- throw new TaskException( e.getMessage(), e );
- }
- }
-
- protected void doWaitForString( final InputStream input,
- final String string,
- final Integer timeout )
- throws TaskException
- {
- try
- {
- final StringBuffer sb = new StringBuffer();
- if( timeout == null || timeout.intValue() == 0 )
- {
- while( sb.toString().indexOf( string ) == -1 )
- {
- sb.append( (char)input.read() );
- }
- }
- else
- {
- final Calendar endTime = Calendar.getInstance();
- endTime.add( Calendar.SECOND, timeout.intValue() );
- while( sb.toString().indexOf( string ) == -1 )
- {
- while( Calendar.getInstance().before( endTime ) &&
- input.available() == 0 )
- {
- Thread.sleep( 250 );
- }
- if( input.available() == 0 )
- {
- throw new TaskException( "Response Timed-Out" );
- }
- sb.append( (char)input.read() );
- }
- }
- getContext().info( sb.toString() );
- }
- catch( final TaskException te )
- {
- throw te;
- }
- catch( final Exception e )
- {
- throw new TaskException( e.getMessage(), e );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/TelnetWrite.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/TelnetWrite.java
deleted file mode 100644
index 6b6998bac..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/net/TelnetWrite.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.net;
-
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * This class sends text to the connected server
- */
-public class TelnetWrite
- extends TelnetSubTask
-{
- private boolean m_echo = true;
-
- public void setEcho( final boolean echo )
- {
- m_echo = echo;
- }
-
- public void execute( final AntTelnetClient telnet )
- throws TaskException
- {
- telnet.sendString( getTaskString(), m_echo );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Add.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Add.java
deleted file mode 100644
index 40ce0b667..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Add.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.perforce;
-
-import java.io.File;
-import java.util.ArrayList;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.ScannerUtil;
-
-/**
- * P4Add - add the specified files to perforce. Example Usage:
- *
- *
- *
- * Function
- *
- *
- *
- * Command
- *
- *
- *
- *
- *
- * Add files using P4USER, P4PORT and P4CLIENT settings specified
- *
- *
- *
- * <P4add
- * P4view="//projects/foo/main/source/..."
- * P4User="fbloggs"
- * P4Port="km01:1666"
- * P4Client="fbloggsclient">
- * <fileset basedir="dir" includes="**/*.java">
- * </p4add>
- *
- *
- *
- *
- *
- *
- *
- * Add files using P4USER, P4PORT and P4CLIENT settings defined in
- * environment
- *
- *
- *
- * <P4add P4view="//projects/foo/main/source/..." />
- * <fileset basedir="dir" includes="**/*.java">
- * </p4add>
- *
- *
- *
- *
- *
- *
- *
- * Specify the length of command line arguments to pass to each invocation
- * of p4
- *
- *
- *
- * <p4add Commandlength="450">
- *
- *
- *
- *
- *
- *
- *
- * @author Les Hughes
- * @author Anli Shundi
- */
-public class P4Add extends P4Base
-{
- private String addCmd = "";
- private ArrayList filesets = new ArrayList();
- private int m_cmdLength = 450;
-
- private int m_changelist;
-
- public void setChangelist( int changelist )
- throws TaskException
- {
- if( changelist <= 0 )
- {
- throw new TaskException( "P4Add: Changelist# should be a positive number" );
- }
-
- this.m_changelist = changelist;
- }
-
- public void setCommandlength( int len )
- throws TaskException
- {
- if( len <= 0 )
- {
- throw new TaskException( "P4Add: Commandlength should be a positive number" );
- }
- this.m_cmdLength = len;
- }
-
- public void addFileset( FileSet set )
- {
- filesets.add( set );
- }
-
- public void execute()
- throws TaskException
- {
-
- if( m_p4View != null )
- {
- addCmd = m_p4View;
- }
-
- m_p4CmdOpts = ( m_changelist > 0 ) ? ( "-c " + m_changelist ) : "";
-
- StringBuffer filelist = new StringBuffer();
-
- for( int i = 0; i < filesets.size(); i++ )
- {
- FileSet fs = (FileSet)filesets.get( i );
- DirectoryScanner ds = ScannerUtil.getDirectoryScanner( fs );
- //File fromDir = fs.getDir(project);
-
- String[] srcFiles = ds.getIncludedFiles();
- if( srcFiles != null )
- {
- for( int j = 0; j < srcFiles.length; j++ )
- {
- File f = new File( ds.getBasedir(), srcFiles[ j ] );
- filelist.append( " " ).append( '"' ).append( f.getAbsolutePath() ).append( '"' );
- if( filelist.length() > m_cmdLength )
- {
- execP4Add( filelist );
- filelist.setLength( 0 );
- }
- }
- if( filelist.length() > 0 )
- {
- execP4Add( filelist );
- }
- }
- else
- {
- getContext().warn( "No files specified to add!" );
- }
- }
-
- }
-
- private void execP4Add( final StringBuffer list )
- throws TaskException
- {
- if( getContext().isInfoEnabled() )
- {
- final String message = "Execing add " + m_p4CmdOpts + " " + addCmd + list;
- getContext().info( message );
- }
-
- final String command = "-s add " + m_p4CmdOpts + " " + addCmd + list;
- execP4Command( command, null );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Base.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Base.java
deleted file mode 100644
index 71ac06008..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Base.java
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.perforce;
-
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.aut.nativelib.ExecOutputHandler;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.oro.text.perl.Perl5Util;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * Base class for Perforce (P4) ANT tasks. See individual task for example
- * usage.
- *
- * @author Les Hughes
- * @see P4Sync
- * @see P4Have
- * @see P4Change
- * @see P4Edit
- * @see P4Submit
- * @see P4Label
- */
-public abstract class P4Base
- extends AbstractTask
- implements ExecOutputHandler
-{
- /**
- * Perl5 regexp in Java - cool eh?
- */
- protected Perl5Util util;
-
- //P4 runtime directives
- /**
- * Perforce Server Port (eg KM01:1666)
- */
- protected String m_p4Port = "";
- /**
- * Perforce Client (eg myclientspec)
- */
- protected String m_p4Client = "";
- /**
- * Perforce User (eg fbloggs)
- */
- protected String m_p4User = "";
- /**
- * Perforce view for commands (eg //projects/foobar/main/source/... )
- */
- protected String m_p4View = "";
-
- //P4 g-opts and cmd opts (rtfm)
- /**
- * Perforce 'global' opts. Forms half of low level API
- */
- protected String P4Opts = "";
- /**
- * Perforce command opts. Forms half of low level API
- */
- protected String m_p4CmdOpts = "";
- /**
- * The OS shell to use (cmd.exe or /bin/sh)
- */
- protected String shell;
-
- private TaskException m_error;
-
- public void setClient( String P4Client )
- {
- this.m_p4Client = "-c" + P4Client;
- }
-
- public void setCmdopts( String P4CmdOpts )
- {
- this.m_p4CmdOpts = P4CmdOpts;
- }
-
- //Setters called by Ant
- public void setPort( String P4Port )
- {
- this.m_p4Port = "-p" + P4Port;
- }
-
- public void setUser( String P4User )
- {
- this.m_p4User = "-u" + P4User;
- }
-
- public void setView( String P4View )
- {
- this.m_p4View = P4View;
- }
-
- private void prepare()
- {
- util = new Perl5Util();
-
- //Get default P4 settings from environment - Mark would have done something cool with
- //introspection here.....:-)
- Object tmpprop;
- if( ( tmpprop = getContext().getProperty( "p4.port" ) ) != null )
- {
- setPort( tmpprop.toString() );
- }
- if( ( tmpprop = getContext().getProperty( "p4.client" ) ) != null )
- {
- setClient( tmpprop.toString() );
- }
- if( ( tmpprop = getContext().getProperty( "p4.user" ) ) != null )
- {
- setUser( tmpprop.toString() );
- }
- }
-
- public void execute()
- throws TaskException
- {
- //Setup task before executing it
- prepare();
- }
-
- /**
- * Execute P4 command assembled by subclasses.
- */
- protected void execP4Command( final String command,
- ExecOutputHandler handler )
- throws TaskException
- {
- try
- {
- final Commandline cmd = new Commandline();
- cmd.setExecutable( "p4" );
-
- //Check API for these - it's how CVS does it...
- if( m_p4Port != null && m_p4Port.length() != 0 )
- {
- cmd.addArgument( m_p4Port );
- }
- if( m_p4User != null && m_p4User.length() != 0 )
- {
- cmd.addArgument( m_p4User );
- }
- if( m_p4Client != null && m_p4Client.length() != 0 )
- {
- cmd.addArgument( m_p4Client );
- }
- cmd.addLine( command );
-
- String[] cmdline = cmd.getCommandline();
- String cmdl = "";
- for( int i = 0; i < cmdline.length; i++ )
- {
- cmdl += cmdline[ i ] + " ";
- }
-
- getContext().debug( "Execing " + cmdl );
- if( handler == null )
- {
- handler = this;
- }
-
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
- exe.setExecOutputHandler( handler );
- exe.setCommandline( cmd );
-
- exe.execute();
- if( null != m_error )
- {
- throw m_error;
- }
- }
- catch( TaskException te )
- {
- throw te;
- }
- catch( Exception e )
- {
- throw new TaskException( "Problem exec'ing P4 command: " + e.getMessage() );
- }
- }
-
- protected final void registerError( final TaskException error )
- {
- m_error = error;
- m_error.fillInStackTrace();
- }
-
- /**
- * Receive notification about the process writing
- * to standard output.
- */
- public void stdout( final String line )
- {
- if( util.match( "/^exit/", line ) )
- {
- return;
- }
-
- //Throw exception on errors (except up-to-date)
- //p4 -s is unpredicatable. For example a server down
- //does not return error: markup
- //
- //Some forms producing commands (p4 -s change -o) do tag the output
- //others don't.....
- //Others mark errors as info, for example edit a file
- //which is already open for edit.....
- //Just look for error: - catches most things....
-
- if( util.match( "/error:/", line ) && !util.match( "/up-to-date/", line ) )
- {
- registerError( new TaskException( line ) );
- }
-
- getContext().info( util.substitute( "s/^.*: //", line ) );
- }
-
- public void stderr( final String line )
- {
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Change.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Change.java
deleted file mode 100644
index f1308ee5b..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Change.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.perforce;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-
-/**
- * P4Change - grab a new changelist from Perforce. P4Change creates a new
- * changelist in perforce. P4Change sets the property ${p4.change} with the new
- * changelist number. This should then be passed into p4edit and p4submit.
- *
- * @author Les Hughes
- * @see P4Edit
- * @see P4Submit
- */
-public class P4Change
- extends P4Base
-{
- private String m_emptyChangeList;
- private String m_description = "AutoSubmit By Ant";
- private final StringBuffer m_changelistData = new StringBuffer();
- private boolean m_changelist;
-
- /*
- * Set Description Variable.
- */
- public void setDescription( final String description )
- {
- m_description = description;
- }
-
- private String getEmptyChangeList()
- throws TaskException
- {
- m_changelist = true;
- execP4Command( "change -o", null );
- m_changelist = false;
-
- return m_changelistData.toString();
- }
-
- /**
- * Receive notification about the process writing
- * to standard output.
- */
- public void stdout( final String line )
- {
- if( m_changelist )
- {
- changelist_stdout( line );
- }
- else
- {
- change_stdout( line );
- }
- }
-
- public void execute()
- throws TaskException
- {
- if( m_emptyChangeList == null )
- {
- m_emptyChangeList = getEmptyChangeList();
- }
-
- //handler.setOutput( m_emptyChangeList );
-
- execP4Command( "change -i", null );
- }
-
- /**
- * Ensure that a string is backslashing slashes so that it does not confuse
- * them with Perl substitution delimiter in Oro. Backslashes are always
- * backslashes in a string unless they escape the delimiter.
- *
- * @param value the string to backslash for slashes
- * @return the backslashed string
- * @see < a href="http://jakarta.apache.org/oro/api/org/apache/oro/text/perl/Perl5Util.html#substitute(java.lang.String,%20java.lang.String)">
- * Oro
- */
- private String backslash( String value )
- {
- final StringBuffer buf = new StringBuffer( value.length() );
- final int len = value.length();
- for( int i = 0; i < len; i++ )
- {
- char c = value.charAt( i );
- if( c == '/' )
- {
- buf.append( '\\' );
- }
- buf.append( c );
- }
- return buf.toString();
- }
-
- private void changelist_stdout( String line )
- {
- if( !util.match( "/^#/", line ) )
- {
- if( util.match( "/error/", line ) )
- {
- getContext().debug( "Client Error" );
- registerError( new TaskException( "Perforce Error, check client settings and/or server" ) );
- }
- else if( util.match( "//", line ) )
- {
-
- // we need to escape the description in case there are /
- m_description = backslash( m_description );
- line = util.substitute( "s//" + m_description + "/", line );
-
- }
- else if( util.match( "/\\/\\//", line ) )
- {
- //Match "//" for begining of depot filespec
- return;
- }
-
- m_changelistData.append( line );
- m_changelistData.append( "\n" );
- }
- }
-
- private void change_stdout( String line )
- {
- if( util.match( "/Change/", line ) )
- {
- //Remove any non-numerical chars - should leave the change number
- line = util.substitute( "s/[^0-9]//g", line );
-
- final int changenumber = Integer.parseInt( line );
- getContext().info( "Change Number is " + changenumber );
- try
- {
- getContext().setProperty( "p4.change", "" + changenumber );
- }
- catch( final TaskException te )
- {
- registerError( te );
- }
- }
- else if( util.match( "/error/", line ) )
- {
- final String message = "Perforce Error, check client settings and/or server";
- registerError( new TaskException( message ) );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Counter.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Counter.java
deleted file mode 100644
index 0ae30e3ef..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Counter.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.perforce;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-
-/**
- * P4Counter - Obtain or set the value of a counter. P4Counter can be used to
- * either print the value of a counter to the output stream for the project (by
- * setting the "name" attribute only), to set a property based on the value of a
- * counter (by setting the "property" attribute) or to set the counter on the
- * perforce server (by setting the "value" attribute). Example Usage:
- * <p4counter name="${p4.counter}" property=${p4.change}"/>
- *
- * @author Kirk Wylie
- */
-public class P4Counter
- extends P4Base
-{
- private String m_counter;
- private String m_property;
- private boolean m_shouldSetValue;
- private int m_value;
-
- public void setName( final String counter )
- {
- m_counter = counter;
- }
-
- public void setProperty( final String property )
- {
- m_property = property;
- }
-
- public void setValue( final int value )
- {
- m_value = value;
- m_shouldSetValue = true;
- }
-
- public void execute()
- throws TaskException
- {
- validate();
-
- String command = "counter " + m_p4CmdOpts + " " + m_counter;
- if( !shouldSetProperty() )
- {
- // NOTE kirk@radik.com 04-April-2001 -- If you put in the -s, you
- // have to start running through regular expressions here. Much easier
- // to just not include the scripting information than to try to add it
- // and strip it later.
- command = "-s " + command;
- }
- if( m_shouldSetValue )
- {
- command += " " + m_value;
- }
-
- execP4Command( command, null );
- }
-
- public void stdout( final String line )
- {
- if( shouldSetProperty() )
- {
- super.stdout( line );
- }
- else
- {
- getContext().debug( "P4Counter retrieved line \"" + line + "\"" );
- try
- {
- m_value = Integer.parseInt( line );
- final String name = m_property;
- final Object value = "" + m_value;
- getContext().setProperty( name, value );
- }
- catch( final TaskException te )
- {
- registerError( te );
- }
- catch( NumberFormatException nfe )
- {
- final String message = "Perforce error. Could not retrieve counter value.";
- registerError( new TaskException( message ) );
- }
- }
- }
-
- private void validate()
- throws TaskException
- {
- if( ( m_counter == null ) || m_counter.length() == 0 )
- {
- throw new TaskException( "No counter specified to retrieve" );
- }
-
- if( m_shouldSetValue && shouldSetProperty() )
- {
- throw new TaskException( "Cannot both set the value of the property and retrieve the value of the property." );
- }
- }
-
- private boolean shouldSetProperty()
- {
- return ( null == m_property );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Delete.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Delete.java
deleted file mode 100644
index 0550d636c..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Delete.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.perforce;
-
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * P4Delete - checkout file(s) for delete. Example Usage:
- * <p4delete change="${p4.change}" view="//depot/project/foo.txt" />
- * Simple re-write of P4Edit changing 'edit' to 'delete'.
- * ToDo: What to do if file is already open in one of our changelists perhaps
- * (See also {@link P4Edit P4Edit})?
- *
- *
- * @author Mike Roberts , Les Hughes
- */
-public class P4Delete extends P4Base
-{
-
- public String change = null;
-
- public void setChange( String change )
- {
- this.change = change;
- }
-
- public void execute()
- throws TaskException
- {
- if( change != null )
- {
- m_p4CmdOpts = "-c " + change;
- }
- if( m_p4View == null )
- {
- throw new TaskException( "No view specified to delete" );
- }
-
- final String command = "-s delete " + m_p4CmdOpts + " " + m_p4View;
- execP4Command( command, null );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Edit.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Edit.java
deleted file mode 100644
index 94f765c23..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Edit.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.perforce;
-
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * P4Edit - checkout file(s) for edit. Example Usage:
- * <p4edit change="${p4.change}" view="//depot/project/foo.txt" />
- *
- * @author Les Hughes ToDo: Should
- * call reopen if file is already open in one of our changelists perhaps?
- */
-
-public class P4Edit extends P4Base
-{
-
- public String change = null;
-
- public void setChange( String change )
- {
- this.change = change;
- }
-
- public void execute()
- throws TaskException
- {
- if( change != null )
- {
- m_p4CmdOpts = "-c " + change;
- }
- if( m_p4View == null )
- {
- throw new TaskException( "No view specified to edit" );
- }
-
- final String command = "-s edit " + m_p4CmdOpts + " " + m_p4View;
- execP4Command( command, null );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Have.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Have.java
deleted file mode 100644
index 44d46417e..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Have.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.perforce;
-
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * P4Have - lists files currently on client. P4Have simply dumps the current
- * file version info into the Ant log (or stdout).
- *
- * @author Les Hughes
- */
-public class P4Have
- extends P4Base
-{
- public void execute()
- throws TaskException
- {
- final String command = "have " + m_p4CmdOpts + " " + m_p4View;
- execP4Command( command, null );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Label.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Label.java
deleted file mode 100644
index e311b69e8..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Label.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.perforce;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-
-/**
- * P4Label - create a Perforce Label. P4Label inserts a label into perforce
- * reflecting the current client contents. Label name defaults to AntLabel if
- * none set. Example Usage:
- * <P4Label name="MyLabel-${TSTAMP}-${DSTAMP}" desc="Auto Build Label" />
- *
- *
- * @author Les Hughes
- */
-public class P4Label
- extends P4Base
-{
- private String m_description;
- private String m_lock;
- private String m_name;
- private boolean m_getLabelSpec;
- private StringBuffer m_labelSpec;
-
- public void setDesc( final String description )
- {
- m_description = description;
- }
-
- public void setLock( final String lock )
- {
- m_lock = lock;
- }
-
- public void setName( final String name )
- {
- m_name = name;
- }
-
- public void stdout( String line )
- {
- getContext().debug( line );
-
- if( null != m_labelSpec )
- {
- if( util.match( "/^Options:/", line ) )
- {
- line = "Options: " + m_lock;
- }
-
- m_labelSpec.append( line + "\n" );
- }
- }
-
- public void execute()
- throws TaskException
- {
- getContext().info( "P4Label exec:" );
-
- validate();
-
- //We have to create a unlocked label first
- String newLabel =
- "Label: " + m_name + "\n" +
- "Description: " + m_description + "\n" +
- "Options: unlocked\n" +
- "View: " + m_p4View + "\n";
-
- //handler.setOutput( newLabel );
- execP4Command( "label -i", null );
- execP4Command( "labelsync -l " + m_name, null );
-
- getContext().info( "Created Label " + m_name + " (" + m_description + ")" );
-
- //Now lock if required
- if( m_lock != null && m_lock.equalsIgnoreCase( "locked" ) )
- {
-
- getContext().info( "Modifying lock status to 'locked'" );
-
- //Read back the label spec from perforce,
- //Replace Options
- //Submit back to Perforce
-
- m_labelSpec = new StringBuffer();
- execP4Command( "label -o " + m_name, null );
- final String labelSpec = m_labelSpec.toString();
- getContext().debug( labelSpec );
-
- //reset labelSpec to null so output is not written to it anymore
- m_labelSpec = null;
-
- getContext().debug( "Now locking label..." );
- //handler.setOutput( labelSpec );
- execP4Command( "label -i", null );
- }
- }
-
- private void validate()
- {
- if( m_p4View == null || m_p4View.length() < 1 )
- {
- getContext().warn( "View not set, assuming //depot/..." );
- m_p4View = "//depot/...";
- }
-
- if( m_description == null || m_description.length() < 1 )
- {
- getContext().warn( "Label Description not set, assuming 'AntLabel'" );
- m_description = "AntLabel";
- }
-
- if( m_lock != null && !m_lock.equalsIgnoreCase( "locked" ) )
- {
- getContext().warn( "lock attribute invalid - ignoring" );
- }
-
- if( m_name == null || m_name.length() < 1 )
- {
- SimpleDateFormat formatter = new SimpleDateFormat( "yyyy.MM.dd-hh:mm" );
- Date now = new Date();
- m_name = "AntLabel-" + formatter.format( now );
- getContext().warn( "name not set, assuming '" + m_name + "'" );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Reopen.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Reopen.java
deleted file mode 100644
index 6bef84a5b..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Reopen.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.perforce;
-
-import org.apache.myrmidon.api.TaskException;
-
-/*
- * P4Reopen - move files to a new changelist
- *
- * @author Les Hughes
- */
-public class P4Reopen
- extends P4Base
-{
- private String m_toChange = "";
-
- public void setToChange( final String toChange )
- throws TaskException
- {
- if( toChange == null && !toChange.equals( "" ) )
- {
- throw new TaskException( "P4Reopen: tochange cannot be null or empty" );
- }
-
- m_toChange = toChange;
- }
-
- public void execute()
- throws TaskException
- {
- if( m_p4View == null )
- {
- throw new TaskException( "No view specified to reopen" );
- }
- final String message = "-s reopen -c " + m_toChange + " " + m_p4View;
- execP4Command( message, null );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Revert.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Revert.java
deleted file mode 100644
index ca1093d59..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Revert.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.perforce;
-
-import org.apache.myrmidon.api.TaskException;
-
-/*
- * P4Revert - revert open files or files in a changelist
- *
- * @author Les Hughes
- */
-public class P4Revert
- extends P4Base
-{
- private String m_revertChange;
- private boolean m_onlyUnchanged;
-
- public void setChange( final String revertChange )
- throws TaskException
- {
- if( revertChange == null && !revertChange.equals( "" ) )
- {
- throw new TaskException( "P4Revert: change cannot be null or empty" );
- }
-
- m_revertChange = revertChange;
- }
-
- public void setRevertOnlyUnchanged( boolean onlyUnchanged )
- {
- this.m_onlyUnchanged = onlyUnchanged;
- }
-
- public void execute()
- throws TaskException
- {
- /*
- * Here we can either revert any unchanged files in a changelist
- * or
- * any files regardless of whether they have been changed or not
- *
- *
- * The whole process also accepts a p4 filespec
- */
- String p4cmd = "-s revert";
- if( m_onlyUnchanged )
- {
- p4cmd += " -a";
- }
-
- if( m_revertChange != null )
- {
- p4cmd += " -c " + m_revertChange;
- }
-
- final String command = p4cmd + " " + m_p4View;
- execP4Command( command, null );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Submit.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Submit.java
deleted file mode 100644
index 9b9cbbe15..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Submit.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.perforce;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-
-/**
- * P4Submit - submit a numbered changelist to Perforce. Note: P4Submit
- * cannot (yet) submit the default changelist. This shouldn't be a problem with
- * the ANT API as the usual flow is P4Change to create a new numbered change
- * followed by P4Edit then P4Submit. Example Usage:-
- * <p4submit change="${p4.change}" />
- *
- * @author Les Hughes
- */
-public class P4Submit
- extends P4Base
-{
- //ToDo: If dealing with default cl need to parse out
- private String m_change;
-
- public void setChange( final String change )
- {
- m_change = change;
- }
-
- /**
- * Receive notification about the process writing
- * to standard output.
- */
- public void stdout( final String line )
- {
- getContext().debug( line );
- }
-
- public void execute()
- throws TaskException
- {
- if( m_change != null )
- {
- execP4Command( "submit -c " + m_change, this );
- }
- else
- {
- //here we'd parse the output from change -o into submit -i
- //in order to support default change.
- throw new TaskException( "No change specified (no support for default change yet...." );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Sync.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Sync.java
deleted file mode 100644
index e920c2464..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/P4Sync.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.perforce;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-
-/**
- * P4Sync - synchronise client space to a perforce depot view. The API allows
- * additional functionality of the "p4 sync" command (such as "p4 sync -f
- * //...#have" or other exotic invocations).
Example Usage:
- *
- *
- *
- * Function
- *
- *
- *
- * Command
- *
- *
- *
- *
- *
- * Sync to head using P4USER, P4PORT and P4CLIENT settings specified
- *
- *
- *
- * <P4Sync
- * P4view="//projects/foo/main/source/..."
- * P4User="fbloggs"
- * P4Port="km01:1666"
- * P4Client="fbloggsclient" />
- *
- *
- *
- *
- *
- *
- *
- * Sync to head using P4USER, P4PORT and P4CLIENT settings defined in
- * environment
- *
- *
- *
- * <P4Sync P4view="//projects/foo/main/source/..." />
- *
- *
- *
- *
- *
- *
- *
- * Force a re-sync to head, refreshing all files
- *
- *
- *
- * <P4Sync force="yes" P4view="//projects/foo/main/source/..." />
- *
- *
- *
- *
- *
- *
- *
- *
- * Sync to a label
- *
- *
- *
- * <P4Sync label="myPerforceLabel" />
- *
- *
- *
- *
- *
- * ToDo: Add decent label error handling for non-exsitant labels
- *
- * @author Les Hughes
- */
-public class P4Sync
- extends P4Base
-{
- private String m_syncCmd = "";
- private String m_label;
-
- public void setForce( final boolean force )
- throws TaskException
- {
- if( force )
- {
- m_p4CmdOpts = "-f";
- }
- }
-
- public void setLabel( String label )
- throws TaskException
- {
- if( label == null && !label.equals( "" ) )
- {
- throw new TaskException( "P4Sync: Labels cannot be Null or Empty" );
- }
-
- m_label = label;
- }
-
- public void execute()
- throws TaskException
- {
- if( m_p4View != null )
- {
- m_syncCmd = m_p4View;
- }
-
- if( m_label != null && !m_label.equals( "" ) )
- {
- m_syncCmd = m_syncCmd + "@" + m_label;
- }
-
- final String message = "Execing sync " + m_p4CmdOpts + " " + m_syncCmd;
- getContext().debug( message );
-
- final String command = "-s sync " + m_p4CmdOpts + " " + m_syncCmd;
- execP4Command( command, null );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/package.html b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/package.html
deleted file mode 100644
index 125fc2aaf..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/perforce/package.html
+++ /dev/null
@@ -1,26 +0,0 @@
-
-ANT Tasks for Perforce integration.
-
-These tasks provide basic P4 capabilities to automated ANT-based build systems. Note:
-the tasks in this package are linked against the Jakarta ORO 2.0 library which
-brings the power of Perl 5 regular expressions to Java.
-
-These tasks also require you to have the p4 (or p4.exe) client in your path.
-
-@see Jakarta Project
-@see Perforce
-
-@see org.apache.tools.ant.taskdefs.optional.perforce.P4Sync
-@see org.apache.tools.ant.taskdefs.optional.perforce.P4Label
-@see org.apache.tools.ant.taskdefs.optional.perforce.P4Have
-@see org.apache.tools.ant.taskdefs.optional.perforce.P4Change
-@see org.apache.tools.ant.taskdefs.optional.perforce.P4Edit
-@see org.apache.tools.ant.taskdefs.optional.perforce.P4Submit
-@see org.apache.tools.ant.taskdefs.optional.perforce.P4Counter
-
-
-
-@author Les Hughes
-
-
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/pvcs/Pvcs.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/pvcs/Pvcs.java
deleted file mode 100644
index 2b4a359d5..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/pvcs/Pvcs.java
+++ /dev/null
@@ -1,486 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.pvcs;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.text.MessageFormat;
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.aut.nativelib.ExecOutputHandler;
-import org.apache.avalon.excalibur.io.IOUtil;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * A task that fetches source files from a PVCS archive 19-04-2001
- *
- * The task now has a more robust parser. It allows for platform independant
- * file paths and supports file names with () . Thanks to Erik Husby for
- * bringing the bug to my attention. 27-04-2001
- *
- * UNC paths are now handled properly. Fix provided by Don Jeffery. He also
- * added an UpdateOnly flag that, when true, conditions the PVCS get
- * using the -U option to only update those files that have a modification time
- * (in PVCS) that is newer than the existing workfile.
- *
- * @author Thomas Christensen
- * @author Don Jeffery
- * @author Steven E. Newton
- */
-public class Pvcs
- extends AbstractTask
- implements ExecOutputHandler
-{
- /**
- * Constant for the thing to execute
- */
- private final static String PCLI_EXE = "pcli";
-
- /**
- * Constant for the PCLI listversionedfiles recursive i a format "get"
- * understands
- */
- private final static String PCLI_LVF_ARGS = "lvf -z -aw";
-
- /**
- * Constant for the thing to execute
- */
- private final static String GET_EXE = "get";
- private String m_filenameFormat;
- private boolean m_force;
- private boolean m_ignoreReturnCode;
- private String m_label;
- private String m_lineStart;
- private String m_promotiongroup;
- private String m_pvcsProject;
- private ArrayList m_pvcsProjects;
- private String m_pvcsbin;
- private String m_repository;
- private boolean m_updateOnly;
- private String m_workspace;
- private FileOutputStream m_output;
-
- /**
- * Creates a Pvcs object
- */
- public Pvcs()
- {
- m_pvcsProjects = new ArrayList();
- m_lineStart = "\"P:";
- m_filenameFormat = "{0}_arc({1})";
- }
-
- public void setFilenameFormat( final String filenameFormat )
- {
- m_filenameFormat = filenameFormat;
- }
-
- /**
- * Specifies the value of the force argument
- */
- public void setForce( final boolean force )
- {
- m_force = force;
- }
-
- /**
- * If set to true the return value from executing the pvcs commands are
- * ignored.
- */
- public void setIgnoreReturnCode( final boolean ignoreReturnCode )
- {
- m_ignoreReturnCode = ignoreReturnCode;
- }
-
- /**
- * Specifies the name of the label argument
- */
- public void setLabel( final String label )
- {
- m_label = label;
- }
-
- public void setLineStart( final String lineStart )
- {
- m_lineStart = lineStart;
- }
-
- /**
- * Specifies the name of the promotiongroup argument
- */
- public void setPromotiongroup( final String promotiongroup )
- {
- m_promotiongroup = promotiongroup;
- }
-
- /**
- * Specifies the location of the PVCS bin directory
- */
- public void setPvcsbin( final String pvcsbin )
- {
- m_pvcsbin = pvcsbin;
- }
-
- /**
- * Specifies the name of the project in the PVCS repository
- */
- public void setPvcsproject( final String pvcsProject )
- {
- m_pvcsProject = pvcsProject;
- }
-
- /**
- * Specifies the network name of the PVCS repository
- */
- public void setRepository( final String repository )
- {
- m_repository = repository;
- }
-
- /**
- * If set to true files are gotten only if newer than existing local files.
- */
- public void setUpdateOnly( final boolean updateOnly )
- {
- m_updateOnly = updateOnly;
- }
-
- /**
- * Specifies the name of the workspace to store retrieved files
- */
- public void setWorkspace( final String workspace )
- {
- m_workspace = workspace;
- }
-
- /**
- * handles <pvcsproject> subelements
- */
- public void addPvcsproject( final PvcsProject pvcsProject )
- {
- m_pvcsProjects.add( pvcsProject );
- }
-
- public void execute()
- throws TaskException
- {
- int result = 0;
-
- validate();
-
- final File filelist = getFileList();
-
- final Commandline cmd = buildGetCommand( filelist );
- getContext().info( "Getting files" );
- getContext().debug( "Executing " + cmd.toString() );
- try
- {
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
- exe.setWorkingDirectory( getBaseDirectory() );
- exe.setCommandline( cmd );
- result = exe.execute();
- checkResultCode( result, cmd );
- }
- finally
- {
- if( filelist != null )
- {
- filelist.delete();
- }
- }
- }
-
- private Commandline buildGetCommand( final File filelist )
- {
- final Commandline cmd = new Commandline();
- cmd.setExecutable( getExecutable( GET_EXE ) );
-
- if( m_force )
- {
- cmd.addArgument( "-Y" );
- }
- else
- {
- cmd.addArgument( "-N" );
- }
-
- if( null != m_promotiongroup )
- {
- cmd.addArgument( "-G" + m_promotiongroup );
- }
- else if( null != m_label )
- {
- cmd.addArgument( "-r" + m_label );
- }
-
- if( m_updateOnly )
- {
- cmd.addArgument( "-U" );
- }
-
- cmd.addArgument( "@" + filelist.getAbsolutePath() );
- return cmd;
- }
-
- private void checkResultCode( final int result, final Commandline cmd )
- throws TaskException
- {
- if( result != 0 && !m_ignoreReturnCode )
- {
- final String message = "Failed executing: " + cmd.toString() +
- ". Return code was " + result;
- throw new TaskException( message );
- }
- }
-
- private File getFileList()
- throws TaskException
- {
- // Check workspace exists
- // Launch PCLI listversionedfiles -z -aw
- // Capture output
- // build the command line from what we got the format is
- final Commandline cmd = buildPCLICommand();
- getContext().debug( "Executing " + cmd.toString() );
-
- File tmp = null;
-
- try
- {
- tmp = File.createTempFile( "pvcs_ant_", ".log" );
- final File fileList = File.createTempFile( "pvcs_ant_", ".log" );
-
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
- exe.setExecOutputHandler( this );
- m_output = new FileOutputStream( tmp );
- exe.setWorkingDirectory( getBaseDirectory() );
- exe.setCommandline( cmd );
- final int result = exe.execute();
- checkResultCode( result, cmd );
-
- if( !tmp.exists() )
- {
- final String message = "Communication between ant and pvcs failed. No output " +
- "generated from executing PVCS commandline interface \"pcli\" and \"get\"";
- throw new TaskException( message );
- }
-
- // Create folders in workspace
- getContext().info( "Creating folders" );
- createFolders( tmp );
-
- // Massage PCLI lvf output transforming '\' to '/' so get command works appropriately
- massagePCLI( tmp, fileList );
- return fileList;
- }
- catch( final ParseException pe )
- {
- final String message = "Failed executing: " +
- cmd.toString() + ". Exception: " + pe.getMessage();
- throw new TaskException( message );
- }
- catch( final IOException ioe )
- {
- final String message = "Failed executing: " +
- cmd.toString() + ". Exception: " + ioe.getMessage();
- throw new TaskException( message );
- }
- finally
- {
- IOUtil.shutdownStream( m_output );
- if( null != tmp )
- {
- tmp.delete();
- }
- }
- }
-
- /**
- * Receive notification about the process writing
- * to standard output.
- */
- public void stdout( final String line )
- {
- try
- {
- m_output.write( line.getBytes() );
- }
- catch( final IOException ioe )
- {
- final String message = "Failed to write to output stream";
- getContext().error( message );
- }
- }
-
- /**
- * Receive notification about the process writing
- * to standard error.
- */
- public void stderr( final String line )
- {
- getContext().warn( line );
- }
-
- private Commandline buildPCLICommand()
- throws TaskException
- {
- final Commandline cmd = new Commandline();
- cmd.setExecutable( getExecutable( PCLI_EXE ) );
-
- cmd.addArgument( "lvf" );
- cmd.addArgument( "-z" );
- cmd.addArgument( "-aw" );
- if( m_workspace != null )
- {
- cmd.addArgument( "-sp" + m_workspace );
- }
- cmd.addArgument( "-pr" + m_repository );
-
- if( m_pvcsProject != null )
- {
- cmd.addArgument( m_pvcsProject );
- }
-
- if( !m_pvcsProjects.isEmpty() )
- {
- Iterator e = m_pvcsProjects.iterator();
- while( e.hasNext() )
- {
- final PvcsProject project = (PvcsProject)e.next();
- final String name = project.getName();
- if( name == null || ( name.trim() ).equals( "" ) )
- {
- final String message = "name is a required attribute of pvcsproject";
- throw new TaskException( message );
- }
- cmd.addArgument( name );
- }
- }
- return cmd;
- }
-
- private void validate()
- throws TaskException
- {
- if( m_repository == null || m_repository.trim().equals( "" ) )
- {
- throw new TaskException( "Required argument repository not specified" );
- }
-
- // default pvcs project is "/"
- if( m_pvcsProject == null && m_pvcsProjects.isEmpty() )
- {
- m_pvcsProject = "/";
- }
- }
-
- private String getExecutable( final String exe )
- {
- final StringBuffer correctedExe = new StringBuffer();
- if( null != m_pvcsbin )
- {
- if( m_pvcsbin.endsWith( File.separator ) )
- {
- correctedExe.append( m_pvcsbin );
- }
- else
- {
- correctedExe.append( m_pvcsbin ).append( File.separator );
- }
- }
- return correctedExe.append( exe ).toString();
- }
-
- /**
- * Parses the file and creates the folders specified in the output section
- */
- private void createFolders( final File file )
- throws IOException, ParseException
- {
- final BufferedReader in = new BufferedReader( new FileReader( file ) );
- final MessageFormat mf = new MessageFormat( m_filenameFormat );
- String line = in.readLine();
- while( line != null )
- {
- getContext().debug( "Considering \"" + line + "\"" );
- if( line.startsWith( "\"\\" ) ||
- line.startsWith( "\"/" ) ||
- line.startsWith( m_lineStart ) )
- {
- Object[] objs = mf.parse( line );
- String f = (String)objs[ 1 ];
- // Extract the name of the directory from the filename
- int index = f.lastIndexOf( File.separator );
- if( index > -1 )
- {
- File dir = new File( f.substring( 0, index ) );
- if( !dir.exists() )
- {
- getContext().debug( "Creating " + dir.getAbsolutePath() );
- if( dir.mkdirs() )
- {
- getContext().info( "Created " + dir.getAbsolutePath() );
- }
- else
- {
- getContext().info( "Failed to create " + dir.getAbsolutePath() );
- }
- }
- else
- {
- getContext().debug( dir.getAbsolutePath() + " exists. Skipping" );
- }
- }
- else
- {
- final String message = "File separator problem with " + line;
- getContext().warn( message );
- }
- }
- else
- {
- getContext().debug( "Skipped \"" + line + "\"" );
- }
- line = in.readLine();
- }
- }
-
- /**
- * Simple hack to handle the PVCS command-line tools botch when handling UNC
- * notation.
- */
- private void massagePCLI( final File in, final File out )
- throws FileNotFoundException, IOException
- {
- final BufferedReader inReader = new BufferedReader( new FileReader( in ) );
- final BufferedWriter outWriter = new BufferedWriter( new FileWriter( out ) );
- String s = null;
- while( ( s = inReader.readLine() ) != null )
- {
- final String sNormal = s.replace( '\\', '/' );
- outWriter.write( sNormal );
- outWriter.newLine();
- }
- inReader.close();
- outWriter.close();
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/pvcs/PvcsProject.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/pvcs/PvcsProject.java
deleted file mode 100644
index 83e567f00..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/pvcs/PvcsProject.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.pvcs;
-
-/**
- * class to handle <pvcsprojec> elements
- *
- * @author RT
- */
-public class PvcsProject
-{
- private String name;
-
- public PvcsProject()
- {
- super();
- }
-
- public void setName( String name )
- {
- PvcsProject.this.name = name;
- }
-
- public String getName()
- {
- return name;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/DefaultRmicAdapter.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/DefaultRmicAdapter.java
deleted file mode 100644
index d409bc50a..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/DefaultRmicAdapter.java
+++ /dev/null
@@ -1,414 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.rmic;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Random;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.FileNameMapper;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.util.FileUtils;
-
-/**
- * This is the default implementation for the RmicAdapter interface. Currently,
- * this is a cut-and-paste of the original rmic task and
- * DefaultCopmpilerAdapter.
- *
- * @author duncan@x180.com
- * @author ludovic.claude@websitewatchers.co.uk
- * @author David Maclean david@cm.co.za
- * @author Stefan Bodewig
- * @author Takashi Okamoto
- */
-public abstract class DefaultRmicAdapter
- implements RmicAdapter
-{
-
- private final static Random rand = new Random();
-
- private Rmic attributes;
- private FileNameMapper mapper;
-
- private TaskContext m_taskContext;
-
- public void setTaskContext( final TaskContext context )
- {
- m_taskContext = context;
- }
-
- protected final TaskContext getTaskContext()
- {
- return m_taskContext;
- }
-
- public void setRmic( Rmic attributes )
- {
- this.attributes = attributes;
- mapper = new RmicFileNameMapper();
- }
-
- /**
- * The CLASSPATH this rmic process will use.
- *
- * @return The Classpath value
- */
- public Path getClasspath()
- throws TaskException
- {
- return getCompileClasspath();
- }
-
- /**
- * This implementation maps *.class to *getStubClassSuffix().class and - if
- * stubversion is not 1.2 - to *getSkelClassSuffix().class.
- *
- * @return The Mapper value
- */
- public FileNameMapper getMapper()
- {
- return mapper;
- }
-
- public Rmic getRmic()
- {
- return attributes;
- }
-
- /**
- * setup rmic argument for rmic.
- *
- * @return Description of the Returned Value
- */
- protected Commandline setupRmicCommand()
- throws TaskException
- {
- return setupRmicCommand( null );
- }
-
- /**
- * setup rmic argument for rmic.
- *
- * @param options additional parameters needed by a specific implementation.
- * @return Description of the Returned Value
- */
- protected Commandline setupRmicCommand( String[] options )
- throws TaskException
- {
- Commandline cmd = new Commandline();
-
- if( options != null )
- {
- for( int i = 0; i < options.length; i++ )
- {
- cmd.addArgument( options[ i ] );
- }
- }
-
- Path classpath = getCompileClasspath();
-
- cmd.addArgument( "-d" );
- cmd.addArgument( attributes.getBase() );
-
- if( attributes.getExtdirs() != null )
- {
- cmd.addArgument( "-extdirs" );
- cmd.addArguments( FileUtils.translateCommandline( attributes.getExtdirs() ) );
- }
-
- cmd.addArgument( "-classpath" );
- cmd.addArguments( FileUtils.translateCommandline( classpath ) );
-
- String stubVersion = attributes.getStubVersion();
- if( null != stubVersion )
- {
- if( "1.1".equals( stubVersion ) )
- {
- cmd.addArgument( "-v1.1" );
- }
- else if( "1.2".equals( stubVersion ) )
- {
- cmd.addArgument( "-v1.2" );
- }
- else
- {
- cmd.addArgument( "-vcompat" );
- }
- }
-
- if( null != attributes.getSourceBase() )
- {
- cmd.addArgument( "-keepgenerated" );
- }
-
- if( attributes.getIiop() )
- {
- getTaskContext().info( "IIOP has been turned on." );
- cmd.addArgument( "-iiop" );
- if( attributes.getIiopopts() != null )
- {
- getTaskContext().info( "IIOP Options: " + attributes.getIiopopts() );
- cmd.addArgument( attributes.getIiopopts() );
- }
- }
-
- if( attributes.getIdl() )
- {
- cmd.addArgument( "-idl" );
- getTaskContext().info( "IDL has been turned on." );
- if( attributes.getIdlopts() != null )
- {
- cmd.addArgument( attributes.getIdlopts() );
- getTaskContext().info( "IDL Options: " + attributes.getIdlopts() );
- }
- }
-
- if( attributes.getDebug() )
- {
- cmd.addArgument( "-g" );
- }
-
- logAndAddFilesToCompile( cmd );
- return cmd;
- }
-
- /**
- * Builds the compilation classpath.
- *
- * @return The CompileClasspath value
- */
- protected Path getCompileClasspath()
- throws TaskException
- {
- // add dest dir to classpath so that previously compiled and
- // untouched classes are on classpath
- Path classpath = new Path();
- classpath.addLocation( attributes.getBase() );
-
- // add the classpath
- if( attributes.getClasspath() != null )
- {
- classpath.addExisting( attributes.getClasspath() );
- }
-
- return classpath;
- }
-
- protected String getSkelClassSuffix()
- {
- return "_Skel";
- }
-
- protected String getStubClassSuffix()
- {
- return "_Stub";
- }
-
- protected String getTieClassSuffix()
- {
- return "_Tie";
- }
-
- /**
- * Logs the compilation parameters, adds the files to compile and logs the
- * &qout;niceSourceList"
- *
- * @param cmd Description of Parameter
- */
- protected void logAndAddFilesToCompile( Commandline cmd )
- {
- ArrayList compileList = attributes.getCompileList();
-
- getTaskContext().debug( "Compilation args: " + cmd.toString() );
-
- StringBuffer niceSourceList = new StringBuffer( "File" );
- if( compileList.size() != 1 )
- {
- niceSourceList.append( "s" );
- }
- niceSourceList.append( " to be compiled:" );
-
- for( int i = 0; i < compileList.size(); i++ )
- {
- String arg = (String)compileList.get( i );
- cmd.addArgument( arg );
- niceSourceList.append( " " + arg );
- }
-
- getTaskContext().debug( niceSourceList.toString() );
- }
-
- /**
- * Mapper that possibly returns two file names, *_Stub and *_Skel.
- *
- * @author RT
- */
- private class RmicFileNameMapper implements FileNameMapper
- {
-
- RmicFileNameMapper()
- {
- }
-
- /**
- * Empty implementation.
- *
- * @param s The new From value
- */
- public void setFrom( String s )
- {
- }
-
- /**
- * Empty implementation.
- *
- * @param s The new To value
- */
- public void setTo( String s )
- {
- }
-
- public String[] mapFileName( String name, TaskContext context )
- {
- if( name == null
- || !name.endsWith( ".class" )
- || name.endsWith( getStubClassSuffix() + ".class" )
- || name.endsWith( getSkelClassSuffix() + ".class" )
- || name.endsWith( getTieClassSuffix() + ".class" ) )
- {
- // Not a .class file or the one we'd generate
- return null;
- }
-
- String base = name.substring( 0, name.indexOf( ".class" ) );
- String classname = base.replace( File.separatorChar, '.' );
- if( attributes.getVerify() &&
- !attributes.isValidRmiRemote( classname ) )
- {
- return null;
- }
-
- /*
- * fallback in case we have trouble loading the class or
- * don't know how to handle it (there is no easy way to
- * know what IDL mode would generate.
- *
- * This is supposed to make Ant always recompile the
- * class, as a file of that name should not exist.
- */
- String[] target = new String[]{name + ".tmp." + rand.nextLong()};
-
- if( !attributes.getIiop() && !attributes.getIdl() )
- {
- // JRMP with simple naming convention
- if( "1.2".equals( attributes.getStubVersion() ) )
- {
- target = new String[]{
- base + getStubClassSuffix() + ".class"
- };
- }
- else
- {
- target = new String[]{
- base + getStubClassSuffix() + ".class",
- base + getSkelClassSuffix() + ".class",
- };
- }
- }
- else if( !attributes.getIdl() )
- {
- int lastSlash = base.lastIndexOf( File.separatorChar );
-
- String dirname = "";
- /*
- * I know, this is not necessary, but I prefer it explicit (SB)
- */
- int index = -1;
- if( lastSlash == -1 )
- {
- // no package
- index = 0;
- }
- else
- {
- index = lastSlash + 1;
- dirname = base.substring( 0, index );
- }
-
- String filename = base.substring( index );
-
- try
- {
- Class c = attributes.getLoader().loadClass( classname );
-
- if( c.isInterface() )
- {
- // only stub, no tie
- target = new String[]{
- dirname + "_" + filename + getStubClassSuffix()
- + ".class"
- };
- }
- else
- {
- /*
- * stub is derived from implementation,
- * tie from interface name.
- */
- Class interf = attributes.getRemoteInterface( c );
- String iName = interf.getName();
- String iDir = "";
- int iIndex = -1;
- int lastDot = iName.lastIndexOf( "." );
- if( lastDot == -1 )
- {
- // no package
- iIndex = 0;
- }
- else
- {
- iIndex = lastDot + 1;
- iDir = iName.substring( 0, iIndex );
- iDir = iDir.replace( '.', File.separatorChar );
- }
-
- target = new String[]{
- dirname + "_" + filename + getTieClassSuffix()
- + ".class",
- iDir + "_" + iName.substring( iIndex )
- + getStubClassSuffix() + ".class"
- };
- }
- }
- catch( ClassNotFoundException e )
- {
- final String message = "Unable to verify class " + classname
- + ". It could not be found.";
- getTaskContext().warn( message );
- }
- catch( NoClassDefFoundError e )
- {
- final String message = "Unable to verify class " + classname
- + ". It is not defined.";
- getTaskContext().warn( message );
- }
- catch( Throwable t )
- {
- final String message = "Unable to verify class " + classname
- + ". Loading caused Exception: "
- + t.getMessage();
- getTaskContext().warn( message );
- }
- }
- return target;
- }
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/KaffeRmic.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/KaffeRmic.java
deleted file mode 100644
index cc6925c49..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/KaffeRmic.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.rmic;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.taskdefs.rmic.DefaultRmicAdapter;
-
-/**
- * The implementation of the rmic for Kaffe
- *
- * @author Takashi Okamoto
- */
-public class KaffeRmic extends DefaultRmicAdapter
-{
-
- public boolean execute()
- throws TaskException
- {
- getTaskContext().debug( "Using Kaffe rmic" );
- Commandline cmd = setupRmicCommand();
-
- try
- {
-
- Class c = Class.forName( "kaffe.rmi.rmic.RMIC" );
- Constructor cons = c.getConstructor( new Class[]{String[].class} );
- Object rmic = cons.newInstance( new Object[]{cmd.getArguments()} );
- Method doRmic = c.getMethod( "run", null );
- String str[] = cmd.getArguments();
- Boolean ok = (Boolean)doRmic.invoke( rmic, null );
-
- return ok.booleanValue();
- }
- catch( ClassNotFoundException ex )
- {
- throw new TaskException( "Cannot use Kaffe rmic, as it is not available" +
- " A common solution is to set the environment variable" +
- " JAVA_HOME or CLASSPATH." );
- }
- catch( Exception ex )
- {
- if( ex instanceof TaskException )
- {
- throw (TaskException)ex;
- }
- else
- {
- throw new TaskException( "Error starting Kaffe rmic: ", ex );
- }
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/Rmic.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/Rmic.java
deleted file mode 100644
index 46f28cbf5..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/Rmic.java
+++ /dev/null
@@ -1,628 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.rmic;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.rmi.Remote;
-import java.util.ArrayList;
-import org.apache.avalon.excalibur.io.FileUtil;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.FileNameMapper;
-import org.apache.tools.todo.taskdefs.MatchingTask;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.types.PathUtil;
-import org.apache.tools.todo.types.SourceFileScanner;
-
-/**
- * Task to compile RMI stubs and skeletons. This task can take the following
- * arguments:
- *
- * base: The base directory for the compiled stubs and skeletons
- * class: The name of the class to generate the stubs from
- * stubVersion: The version of the stub prototol to use (1.1, 1.2,
- * compat)
- * sourceBase: The base directory for the generated stubs and skeletons
- *
- * classpath: Additional classpath, appended before the system classpath
- *
- * iiop: Generate IIOP compatable output
- * iiopopts: Include IIOP options
- * idl: Generate IDL output
- * idlopts: Include IDL options
- * includeantruntime
- * includejavaruntime
- * extdirs
- *
- * Of these arguments, base is required.
- *
- * If classname is specified then only that classname will be compiled. If it is
- * absent, then base is traversed for classes according to patterns.
- *
- *
- *
- * @author duncan@x180.com
- * @author ludovic.claude@websitewatchers.co.uk
- * @author David Maclean david@cm.co.za
- * @author Stefan Bodewig
- * @author Takashi Okamoto tokamoto@rd.nttdata.co.jp
- */
-
-public class Rmic extends MatchingTask
-{
-
- private final static String FAIL_MSG
- = "Rmic failed, messages should have been provided.";
- private boolean verify;
-
- private boolean iiop;
- private boolean idl;
- private boolean debug;
- private boolean includeAntRuntime;
- private boolean includeJavaRuntime;
-
- private ArrayList compileList = new ArrayList();
-
- private ClassLoader loader;
-
- private File baseDir;
- private String classname;
- private Path compileClasspath;
- private Path extdirs;
- private String idlopts;
- private String iiopopts;
- private File sourceBase;
- private String stubVersion;
-
- /**
- * Sets the base directory to output generated class.
- *
- * @param base The new Base value
- */
- public void setBase( File base )
- {
- this.baseDir = base;
- }
-
- /**
- * Sets the class name to compile.
- *
- * @param classname The new Classname value
- */
- public void setClassname( String classname )
- {
- this.classname = classname;
- }
-
- /**
- * Add an element to the classpath to be used for this compilation.
- *
- * @param classpath The new Classpath value
- */
- public void addClasspath( Path classpath )
- throws TaskException
- {
- if( compileClasspath == null )
- {
- compileClasspath = classpath;
- }
- else
- {
- compileClasspath.addPath( classpath );
- }
- }
-
- /**
- * Sets the debug flag.
- *
- * @param debug The new Debug value
- */
- public void setDebug( boolean debug )
- {
- this.debug = debug;
- }
-
- /**
- * Adds an element to the extension directories that will be used during
- * the compilation.
- *
- * @param extdirs The new Extdirs value
- */
- public void addExtdirs( Path extdirs )
- throws TaskException
- {
- if( this.extdirs == null )
- {
- this.extdirs = extdirs;
- }
- else
- {
- this.extdirs.addPath( extdirs );
- }
- }
-
- /**
- * Indicates that IDL output should be generated. This defaults to false if
- * not set.
- *
- * @param idl The new Idl value
- */
- public void setIdl( boolean idl )
- {
- this.idl = idl;
- }
-
- /**
- * pass additional arguments for idl compile
- *
- * @param idlopts The new Idlopts value
- */
- public void setIdlopts( String idlopts )
- {
- this.idlopts = idlopts;
- }
-
- /**
- * Indicates that IIOP compatible stubs should be generated. This defaults
- * to false if not set.
- *
- * @param iiop The new Iiop value
- */
- public void setIiop( boolean iiop )
- {
- this.iiop = iiop;
- }
-
- /**
- * pass additional arguments for iiop
- *
- * @param iiopopts The new Iiopopts value
- */
- public void setIiopopts( String iiopopts )
- {
- this.iiopopts = iiopopts;
- }
-
- /**
- * Include ant's own classpath in this task's classpath?
- *
- * @param include The new Includeantruntime value
- */
- public void setIncludeantruntime( boolean include )
- {
- includeAntRuntime = include;
- }
-
- /**
- * Sets whether or not to include the java runtime libraries to this task's
- * classpath.
- *
- * @param include The new Includejavaruntime value
- */
- public void setIncludejavaruntime( boolean include )
- {
- includeJavaRuntime = include;
- }
-
- /**
- * Sets the source dirs to find the source java files.
- *
- * @param sourceBase The new SourceBase value
- */
- public void setSourceBase( File sourceBase )
- {
- this.sourceBase = sourceBase;
- }
-
- /**
- * Sets the stub version.
- *
- * @param stubVersion The new StubVersion value
- */
- public void setStubVersion( String stubVersion )
- {
- this.stubVersion = stubVersion;
- }
-
- /**
- * Indicates that the classes found by the directory match should be checked
- * to see if they implement java.rmi.Remote. This defaults to false if not
- * set.
- *
- * @param verify The new Verify value
- */
- public void setVerify( boolean verify )
- {
- this.verify = verify;
- }
-
- /**
- * Gets the base directory to output generated class.
- *
- * @return The Base value
- */
- public File getBase()
- {
- return this.baseDir;
- }
-
- /**
- * Gets the class name to compile.
- *
- * @return The Classname value
- */
- public String getClassname()
- {
- return classname;
- }
-
- /**
- * Gets the classpath.
- *
- * @return The Classpath value
- */
- public Path getClasspath()
- {
- return compileClasspath;
- }
-
- public ArrayList getCompileList()
- {
- return compileList;
- }
-
- /**
- * Gets the debug flag.
- *
- * @return The Debug value
- */
- public boolean getDebug()
- {
- return debug;
- }
-
- /**
- * Gets the extension directories that will be used during the compilation.
- *
- * @return The Extdirs value
- */
- public Path getExtdirs()
- {
- return extdirs;
- }
-
- /*
- * Gets IDL flags.
- */
- public boolean getIdl()
- {
- return idl;
- }
-
- /**
- * Gets additional arguments for idl compile.
- *
- * @return The Idlopts value
- */
- public String getIdlopts()
- {
- return idlopts;
- }
-
- /**
- * Gets iiop flags.
- *
- * @return The Iiop value
- */
- public boolean getIiop()
- {
- return iiop;
- }
-
- /**
- * Gets additional arguments for iiop.
- *
- * @return The Iiopopts value
- */
- public String getIiopopts()
- {
- return iiopopts;
- }
-
- /**
- * Gets whether or not the ant classpath is to be included in the task's
- * classpath.
- *
- * @return The Includeantruntime value
- */
- public boolean getIncludeantruntime()
- {
- return includeAntRuntime;
- }
-
- /**
- * Gets whether or not the java runtime should be included in this task's
- * classpath.
- *
- * @return The Includejavaruntime value
- */
- public boolean getIncludejavaruntime()
- {
- return includeJavaRuntime;
- }
-
- /**
- * Classloader for the user-specified classpath.
- *
- * @return The Loader value
- */
- public ClassLoader getLoader()
- {
- return loader;
- }
-
- /**
- * Returns the topmost interface that extends Remote for a given class - if
- * one exists.
- *
- * @param testClass Description of Parameter
- * @return The RemoteInterface value
- */
- public Class getRemoteInterface( Class testClass )
- {
- if( Remote.class.isAssignableFrom( testClass ) )
- {
- Class[] interfaces = testClass.getInterfaces();
- if( interfaces != null )
- {
- for( int i = 0; i < interfaces.length; i++ )
- {
- if( Remote.class.isAssignableFrom( interfaces[ i ] ) )
- {
- return interfaces[ i ];
- }
- }
- }
- }
- return null;
- }
-
- /**
- * Gets the source dirs to find the source java files.
- *
- * @return The SourceBase value
- */
- public File getSourceBase()
- {
- return sourceBase;
- }
-
- public String getStubVersion()
- {
- return stubVersion;
- }
-
- /**
- * Get verify flag.
- *
- * @return The Verify value
- */
- public boolean getVerify()
- {
- return verify;
- }
-
- /**
- * Load named class and test whether it can be rmic'ed
- *
- * @param classname Description of Parameter
- * @return The ValidRmiRemote value
- */
- public boolean isValidRmiRemote( String classname )
- {
- try
- {
- Class testClass = loader.loadClass( classname );
- // One cannot RMIC an interface for "classic" RMI (JRMP)
- if( testClass.isInterface() && !iiop && !idl )
- {
- return false;
- }
- return isValidRmiRemote( testClass );
- }
- catch( ClassNotFoundException e )
- {
- final String message = "Unable to verify class " + classname +
- ". It could not be found.";
- getContext().warn( message );
- }
- catch( NoClassDefFoundError e )
- {
- final String message = "Unable to verify class " + classname +
- ". It is not defined.";
- getContext().warn( message );
- }
- catch( Throwable t )
- {
- final String message = "Unable to verify class " + classname +
- ". Loading caused Exception: " +
- t.getMessage();
- getContext().warn( message );
- }
- // we only get here if an exception has been thrown
- return false;
- }
-
- public void execute()
- throws TaskException
- {
- if( baseDir == null )
- {
- throw new TaskException( "base attribute must be set!" );
- }
- if( !baseDir.exists() )
- {
- throw new TaskException( "base does not exist!" );
- }
-
- if( verify )
- {
- getContext().info( "Verify has been turned on." );
- }
-
- String compiler = getContext().getProperty( "build.rmic" ).toString();
- RmicAdapter adapter = RmicAdapterFactory.getRmic( compiler, getContext() );
-
- // now we need to populate the compiler adapter
- adapter.setRmic( this );
-
- Path classpath = adapter.getClasspath();
- final URL[] urls = PathUtil.toURLs( classpath );
- loader = new URLClassLoader( urls );
-
- // scan base dirs to build up compile lists only if a
- // specific classname is not given
- if( classname == null )
- {
- DirectoryScanner ds = this.getDirectoryScanner( baseDir );
- String[] files = ds.getIncludedFiles();
- scanDir( baseDir, files, adapter.getMapper() );
- }
- else
- {
- // otherwise perform a timestamp comparison - at least
- scanDir( baseDir,
- new String[]{classname.replace( '.', File.separatorChar ) + ".class"},
- adapter.getMapper() );
- }
-
- int fileCount = compileList.size();
- if( fileCount > 0 )
- {
- getContext().info( "RMI Compiling " + fileCount + " class" + ( fileCount > 1 ? "es" : "" ) + " to " + baseDir );
-
- // finally, lets execute the compiler!!
- if( !adapter.execute() )
- {
- throw new TaskException( FAIL_MSG );
- }
- }
-
- /*
- * Move the generated source file to the base directory. If
- * base directory and sourcebase are the same, the generated
- * sources are already in place.
- */
- if( null != sourceBase && !baseDir.equals( sourceBase ) )
- {
- if( idl )
- {
- getContext().warn( "Cannot determine sourcefiles in idl mode, " );
- getContext().warn( "sourcebase attribute will be ignored." );
- }
- else
- {
- for( int j = 0; j < fileCount; j++ )
- {
- moveGeneratedFile( baseDir, sourceBase,
- (String)compileList.get( j ),
- adapter );
- }
- }
- }
- compileList.clear();
- }
-
- /**
- * Scans the directory looking for class files to be compiled. The result is
- * returned in the class variable compileList.
- *
- * @param baseDir Description of Parameter
- * @param files Description of Parameter
- * @param mapper Description of Parameter
- */
- protected void scanDir( File baseDir, String files[],
- FileNameMapper mapper )
- throws TaskException
- {
-
- String[] newFiles = files;
- if( idl )
- {
- getContext().debug( "will leave uptodate test to rmic implementation in idl mode." );
- }
- else if( iiop
- && iiopopts != null && iiopopts.indexOf( "-always" ) > -1 )
- {
- getContext().debug( "no uptodate test as -always option has been specified" );
- }
- else
- {
- final SourceFileScanner scanner = new SourceFileScanner();
- newFiles = scanner.restrict( files, baseDir, baseDir, mapper, getContext() );
- }
-
- for( int i = 0; i < newFiles.length; i++ )
- {
- String classname = newFiles[ i ].replace( File.separatorChar, '.' );
- classname = classname.substring( 0, classname.lastIndexOf( ".class" ) );
- compileList.add( classname );
- }
- }
-
- /**
- * Check to see if the class or (super)interfaces implement java.rmi.Remote.
- *
- * @param testClass Description of Parameter
- * @return The ValidRmiRemote value
- */
- private boolean isValidRmiRemote( Class testClass )
- {
- return getRemoteInterface( testClass ) != null;
- }
-
- /**
- * Move the generated source file(s) to the base directory
- */
- private void moveGeneratedFile( File baseDir, File sourceBaseFile,
- String classname,
- RmicAdapter adapter )
- throws TaskException
- {
-
- String classFileName =
- classname.replace( '.', File.separatorChar ) + ".class";
- String[] generatedFiles =
- adapter.getMapper().mapFileName( classFileName, getContext() );
-
- for( int i = 0; i < generatedFiles.length; i++ )
- {
- String sourceFileName =
- classFileName.substring( 0, classFileName.length() - 6 ) + ".java";
- File oldFile = new File( baseDir, sourceFileName );
- File newFile = new File( sourceBaseFile, sourceFileName );
- try
- {
- FileUtil.copyFile( oldFile, newFile );
- oldFile.delete();
- }
- catch( IOException ioe )
- {
- String msg = "Failed to copy " + oldFile + " to " +
- newFile + " due to " + ioe.getMessage();
- throw new TaskException( msg, ioe );
- }
- }
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/RmicAdapter.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/RmicAdapter.java
deleted file mode 100644
index 3a0a4d9a9..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/RmicAdapter.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.rmic;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.FileNameMapper;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.taskdefs.rmic.Rmic;
-
-/**
- * The interface that all rmic adapters must adher to.
- *
- * A rmic adapter is an adapter that interprets the rmic's parameters in
- * preperation to be passed off to the compiler this adapter represents. As all
- * the necessary values are stored in the Rmic task itself, the only thing all
- * adapters need is the rmic task, the execute command and a parameterless
- * constructor (for reflection).
- *
- * @author Takashi Okamoto
- * @author Stefan Bodewig
- */
-public interface RmicAdapter
-{
- void setTaskContext( TaskContext context );
-
- /**
- * Sets the rmic attributes, which are stored in the Rmic task.
- *
- * @param attributes The new Rmic value
- */
- void setRmic( Rmic attributes );
-
- /**
- * Executes the task.
- *
- * @return has the compilation been successful
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- boolean execute()
- throws TaskException;
-
- /**
- * Maps source class files to the files generated by this rmic
- * implementation.
- *
- * @return The Mapper value
- */
- FileNameMapper getMapper();
-
- /**
- * The CLASSPATH this rmic process will use.
- *
- * @return The Classpath value
- */
- Path getClasspath()
- throws TaskException;
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/RmicAdapterFactory.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/RmicAdapterFactory.java
deleted file mode 100644
index 41f58cb93..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/RmicAdapterFactory.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.rmic;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.taskdefs.rmic.KaffeRmic;
-import org.apache.tools.todo.taskdefs.rmic.RmicAdapter;
-
-/**
- * Creates the necessary rmic adapter, given basic criteria.
- *
- * @author Takashi Okamoto
- * @author J D Glanville
- */
-public class RmicAdapterFactory
-{
-
- /**
- * This is a singlton -- can't create instances!!
- */
- private RmicAdapterFactory()
- {
- }
-
- /**
- * Based on the parameter passed in, this method creates the necessary
- * factory desired. The current mapping for rmic names are as follows:
- *
- * sun = SUN's rmic
- * kaffe = Kaffe's rmic
- * a fully quallified classname = the name of a rmic adapter
- *
- *
- *
- *
- * @param rmicType either the name of the desired rmic, or the full
- * classname of the rmic's adapter.
- * @return The Rmic value
- * @throws org.apache.myrmidon.api.TaskException if the rmic type could not be resolved into a rmic
- * adapter.
- */
- public static RmicAdapter getRmic( final String rmicType, final TaskContext context )
- throws TaskException
- {
- final RmicAdapter adaptor = createAdaptor( rmicType );
- adaptor.setTaskContext( context );
- return adaptor;
- }
-
- private static RmicAdapter createAdaptor( String rmicType ) throws TaskException
- {
- if( rmicType == null )
- {
- /*
- * When not specified rmicType, search SUN's rmic and
- * Kaffe's rmic.
- */
- try
- {
- Class.forName( "sun.rmi.rmic.Main" );
- rmicType = "sun";
- }
- catch( ClassNotFoundException cnfe )
- {
- try
- {
- Class.forName( "kaffe.rmi.rmic.RMIC" );
- Class.forName( "kaffe.tools.compiler.Compiler" );
- rmicType = "kaffe";
- }
- catch( ClassNotFoundException cnfk )
- {
- throw new TaskException( "Couldn\'t guess rmic implementation" );
- }
- }
- }
-
- if( rmicType.equalsIgnoreCase( "sun" ) )
- {
- return new SunRmic();
- }
- else if( rmicType.equalsIgnoreCase( "kaffe" ) )
- {
- return new KaffeRmic();
- }
- else if( rmicType.equalsIgnoreCase( "weblogic" ) )
- {
- return new WLRmic();
- }
- return resolveClassName( rmicType );
- }
-
- /**
- * Tries to resolve the given classname into a rmic adapter. Throws a fit if
- * it can't.
- *
- * @param className The fully qualified classname to be created.
- * @return Description of the Returned Value
- * @throws org.apache.myrmidon.api.TaskException This is the fit that is thrown if className isn't
- * an instance of RmicAdapter.
- */
- private static RmicAdapter resolveClassName( String className )
- throws TaskException
- {
- try
- {
- Class c = Class.forName( className );
- Object o = c.newInstance();
- return (RmicAdapter)o;
- }
- catch( ClassNotFoundException cnfe )
- {
- throw new TaskException( className + " can\'t be found.", cnfe );
- }
- catch( ClassCastException cce )
- {
- throw new TaskException( className + " isn\'t the classname of "
- + "a rmic adapter.", cce );
- }
- catch( Throwable t )
- {
- // for all other possibilities
- throw new TaskException( className + " caused an interesting "
- + "exception.", t );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/SunRmic.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/SunRmic.java
deleted file mode 100644
index 3bf027272..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/SunRmic.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.rmic;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.taskdefs.rmic.DefaultRmicAdapter;
-
-/**
- * The implementation of the rmic for SUN's JDK.
- *
- * @author Takashi Okamoto
- */
-public class SunRmic extends DefaultRmicAdapter
-{
-
- public boolean execute()
- throws TaskException
- {
- getTaskContext().debug( "Using SUN rmic compiler" );
- Commandline cmd = setupRmicCommand();
-
- // Create an instance of the rmic, redirecting output to
- // the project log
- try
- {
- Class c = Class.forName( "sun.rmi.rmic.Main" );
- Constructor cons = c.getConstructor( new Class[]
- {OutputStream.class, String.class} );
- Object rmic = cons.newInstance( new Object[]{System.out, "rmic"} );
-
- Method doRmic = c.getMethod( "compile",
- new Class[]{String[].class} );
- Boolean ok = (Boolean)doRmic.invoke( rmic,
- ( new Object[]{cmd.getArguments()} ) );
- return ok.booleanValue();
- }
- catch( ClassNotFoundException ex )
- {
- throw new TaskException( "Cannot use SUN rmic, as it is not available" +
- " A common solution is to set the environment variable" +
- " JAVA_HOME or CLASSPATH." );
- }
- catch( Exception ex )
- {
- if( ex instanceof TaskException )
- {
- throw (TaskException)ex;
- }
- else
- {
- throw new TaskException( "Error starting SUN rmic: ", ex );
- }
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/WLRmic.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/WLRmic.java
deleted file mode 100644
index c58a6096d..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/rmic/WLRmic.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.rmic;
-
-import java.lang.reflect.Method;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.taskdefs.rmic.DefaultRmicAdapter;
-
-/**
- * The implementation of the rmic for WebLogic
- *
- * @author Takashi Okamoto
- */
-public class WLRmic extends DefaultRmicAdapter
-{
-
- /**
- * Get the suffix for the rmic skeleton classes
- *
- * @return The SkelClassSuffix value
- */
- public String getSkelClassSuffix()
- {
- return "_WLSkel";
- }
-
- /**
- * Get the suffix for the rmic stub classes
- *
- * @return The StubClassSuffix value
- */
- public String getStubClassSuffix()
- {
- return "_WLStub";
- }
-
- public boolean execute()
- throws TaskException
- {
- getTaskContext().debug( "Using WebLogic rmic" );
- Commandline cmd = setupRmicCommand( new String[]{"-noexit"} );
-
- try
- {
- // Create an instance of the rmic
- Class c = Class.forName( "weblogic.rmic" );
- Method doRmic = c.getMethod( "main",
- new Class[]{String[].class} );
- doRmic.invoke( null, new Object[]{cmd.getArguments()} );
- return true;
- }
- catch( ClassNotFoundException ex )
- {
- throw new TaskException( "Cannot use WebLogic rmic, as it is not available" +
- " A common solution is to set the environment variable" +
- " CLASSPATH." );
- }
- catch( Exception ex )
- {
- if( ex instanceof TaskException )
- {
- throw (TaskException)ex;
- }
- else
- {
- throw new TaskException( "Error starting WebLogic rmic: ", ex );
- }
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/scm/AntStarTeamCheckOut.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/scm/AntStarTeamCheckOut.java
deleted file mode 100644
index 30f233c26..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/scm/AntStarTeamCheckOut.java
+++ /dev/null
@@ -1,1113 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.scm;
-
-import com.starbase.starteam.Folder;
-import com.starbase.starteam.Item;
-import com.starbase.starteam.Property;
-import com.starbase.starteam.Server;
-import com.starbase.starteam.StarTeamFinder;
-import com.starbase.starteam.Type;
-import com.starbase.starteam.View;
-import com.starbase.util.Platform;
-import java.util.StringTokenizer;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.ScannerUtil;
-
-/**
- * Checks out files from a specific StarTeam server, project, view, and folder.
- *
- *
- * This program logs in to a StarTeam server and opens up the specified project
- * and view. Then, it searches through that view for the given folder (or, if
- * you prefer, it uses the root folder). Beginning with that folder and
- * optionally continuing recursivesly, AntStarTeamCheckOut compares each file
- * with your include and exclude filters and checks it out only if appropriate.
- *
- *
- * Checked out files go to a directory you specify under the subfolder named for
- * the default StarTeam path to the view. That is, if you entered
- * /home/cpovirk/work as the target folder, your project was named "OurProject,"
- * the given view was named "TestView," and that view is stored by default at
- * "C:\projects\Test," your files would be checked out to
- * /home/cpovirk/work/Test." I avoided using the project name in the path
- * because you may want to keep several versions of the same project on your
- * computer, and I didn't want to use the view name, as there may be many "Test"
- * or "Version 1.0" views, for example. This system's success, of course,
- * depends on what you set the default path to in StarTeam.
- *
- * You can set AntStarTeamCheckOut to verbose or quiet mode. Also, it has a
- * safeguard against overwriting the files on your computer: If the target
- * directory you specify already exists, the program will throw a
- * TaskException. To override the exception, set force
to true.
- *
- *
- * This program makes use of functions from the StarTeam API. As a result
- * AntStarTeamCheckOut is available only to licensed users of StarTeam and
- * requires the StarTeam SDK to function. You must have starteam-sdk.jar
- * in your classpath to run this program. For more information about the
- * StarTeam API and how to license it, see the link below.
- *
- * @author Chris Povirk
- * @author JC Mann
- * @author Jeff Gettle
- * @author Steve Cohen
- * @version 1.0
- * @see StarBase Web Site
- */
-public class AntStarTeamCheckOut
- extends AbstractTask
-{
- /**
- * This constant sets the filter to include all files. This default has the
- * same result as setIncludes("*")
.
- *
- * @see #getIncludes()
- * @see #setIncludes(String includes)
- */
- public final static String DEFAULT_INCLUDESETTING = "*";
-
- /**
- * This disables the exclude filter by default. In other words, no files are
- * excluded. This setting is equivalent to setExcludes(null)
.
- *
- * @see #getExcludes()
- * @see #setExcludes(String excludes)
- */
- public final static String DEFAULT_EXCLUDESETTING = null;
-
- /**
- * The default folder to search; the root folder. Since AntStarTeamCheckOut
- * searches subfolders, by default it processes an entire view.
- *
- * @see #getFolderName()
- * @see #setFolderName(String folderName)
- */
- public final static String DEFAULT_FOLDERSETTING = null;
-
- /**
- * This is used when formatting the output. The directory name is displayed
- * only when it changes.
- */
- private Folder prevFolder = null;
-
- /**
- * This field keeps count of the number of files checked out.
- */
- private int checkedOut = 0;
-
- // Change these through their GET and SET methods.
-
- /**
- * The name of the server you wish to connect to.
- */
- private String serverName = null;
-
- /**
- * The port on the server used for StarTeam.
- */
- private int serverPort = -1;
-
- /**
- * The name of your project.
- */
- private String projectName = null;
-
- /**
- * The name of the folder you want to check out files from. All subfolders
- * will be searched, as well.
- */
- private String folderName = DEFAULT_FOLDERSETTING;
-
- /**
- * The view that the files you want are in.
- */
- private String viewName = null;
-
- /**
- * Your username on the StarTeam server.
- */
- private String username = null;
-
- /**
- * Your StarTeam password.
- */
- private String password = null;
-
- /**
- * The path to the root folder you want to check out to. This is a local
- * directory.
- */
- private String targetFolder = null;
-
- /**
- * If force set to true, AntStarTeamCheckOut will overwrite files in the
- * target directory.
- */
- private boolean force = false;
-
- /**
- * When verbose is true, the program will display all files and directories
- * as they are checked out.
- */
- private boolean verbose = false;
-
- /**
- * Set recursion to false to check out files in only the given folder and
- * not in its subfolders.
- */
- private boolean recursion = true;
-
- // These fields deal with includes and excludes
-
- /**
- * All files that fit this pattern are checked out.
- */
- private String includes = DEFAULT_INCLUDESETTING;
-
- /**
- * All files fitting this pattern are ignored.
- */
- private String excludes = DEFAULT_EXCLUDESETTING;
-
- /**
- * The file delimitor on the user's system.
- */
- private String delim = Platform.getFilePathDelim();
-
- /**
- * whether to use the Starteam "default folder" when calculating the target
- * paths to which files are checked out (false) or if targetFolder
- * represents an absolute mapping to folderName.
- */
- private boolean targetFolderAbsolute = false;
-
- /**
- * convenient method to check for conditions
- *
- * @param value Description of Parameter
- * @param msg Description of Parameter
- * @exception TaskException Description of Exception
- */
- private static void assertTrue( boolean value, String msg )
- throws TaskException
- {
- if( !value )
- {
- throw new TaskException( msg );
- }
- }
-
- /**
- * Sets the exclude filter. When filtering files, AntStarTeamCheckOut uses
- * an unmodified version of DirectoryScanner
's match
- * method, so here are the patterns straight from the Ant source code:
- *
- * Matches a string against a pattern. The pattern contains two special
- * characters:
- * '*' which means zero or more characters,
- * '?' which means one and only one character.
- *
- * Separate multiple exlcude filters by spaces , not commas as Ant
- * uses. For example, if you want to check out all files except .XML and
- * .HTML files, you would put the following line in your program: setExcludes("*.XML *.HTML");
- * Finally, note that filters have no effect on the directories that
- * are scanned; you could not skip over all files in directories whose names
- * begin with "project," for instance.
- *
- * Treatment of overlapping inlcudes and excludes: To give a simplistic
- * example suppose that you set your include filter to "*.htm *.html" and
- * your exclude filter to "index.*". What happens to index.html?
- * AntStarTeamCheckOut will not check out index.html, as it matches an
- * exclude filter ("index.*"), even though it matches the include filter, as
- * well.
- *
- * Please also read the following sections before using filters:
- *
- * @param excludes A string of filter patterns to exclude. Separate the
- * patterns by spaces.
- * @see #setIncludes(String includes)
- * @see #getIncludes()
- * @see #getExcludes()
- */
- public void setExcludes( String excludes )
- {
- this.excludes = excludes;
- }
-
- /**
- * Sets the folderName
attribute to the given value. To search
- * the root folder, use a slash or backslash, or simply don't set a folder
- * at all.
- *
- * @param folderName The subfolder from which to check out files.
- * @see #getFolderName()
- */
- public void setFolderName( String folderName )
- {
- this.folderName = folderName;
- }
-
- /**
- * Sets the force
attribute to the given value.
- *
- * @param force if true, it overwrites files in the target directory. By
- * default it set to false as a safeguard. Note that if the target
- * directory does not exist, this setting has no effect.
- * @see #getForce()
- */
- public void setForce( boolean force )
- {
- this.force = force;
- }
-
- // Begin filter getters and setters
-
- /**
- * Sets the include filter. When filtering files, AntStarTeamCheckOut uses
- * an unmodified version of DirectoryScanner
's match
- * method, so here are the patterns straight from the Ant source code:
- *
- * Matches a string against a pattern. The pattern contains two special
- * characters:
- * '*' which means zero or more characters,
- * '?' which means one and only one character.
- *
- * Separate multiple inlcude filters by spaces , not commas as Ant
- * uses. For example, if you want to check out all .java and .class\ files,
- * you would put the following line in your program: setIncludes("*.java *.class");
- * Finally, note that filters have no effect on the directories that
- * are scanned; you could not check out files from directories with names
- * beginning only with "build," for instance. Of course, you could limit
- * AntStarTeamCheckOut to a particular folder and its subfolders with the
- * setFolderName(String folderName)
command.
- *
- * Treatment of overlapping inlcudes and excludes: To give a simplistic
- * example suppose that you set your include filter to "*.htm *.html" and
- * your exclude filter to "index.*". What happens to index.html?
- * AntStarTeamCheckOut will not check out index.html, as it matches an
- * exclude filter ("index.*"), even though it matches the include filter, as
- * well.
- *
- * Please also read the following sections before using filters:
- *
- * @param includes A string of filter patterns to include. Separate the
- * patterns by spaces.
- * @see #getIncludes()
- * @see #setExcludes(String excludes)
- * @see #getExcludes()
- */
- public void setIncludes( String includes )
- {
- this.includes = includes;
- }
-
- /**
- * Sets the password
attribute to the given value.
- *
- * @param password Your password for the specified StarTeam server.
- * @see #getPassword()
- */
- public void setPassword( String password )
- {
- this.password = password;
- }
-
- /**
- * Sets the projectName
attribute to the given value.
- *
- * @param projectName The StarTeam project to search.
- * @see #getProjectName()
- */
- public void setProjectName( String projectName )
- {
- this.projectName = projectName;
- }
-
- /**
- * Turns recursion on or off.
- *
- * @param recursion if it is true, the default, subfolders are searched
- * recursively for files to check out. Otherwise, only files specified
- * by folderName
are scanned.
- * @see #getRecursion()
- */
- public void setRecursion( boolean recursion )
- {
- this.recursion = recursion;
- }
-
- // Begin SET and GET methods
-
- /**
- * Sets the serverName
attribute to the given value.
- *
- * @param serverName The name of the server you wish to connect to.
- * @see #getServerName()
- */
- public void setServerName( String serverName )
- {
- this.serverName = serverName;
- }
-
- /**
- * Sets the serverPort
attribute to the given value. The given
- * value must be a valid integer, but it must be a string object.
- *
- * @param serverPort A string containing the port on the StarTeam server to
- * use.
- * @see #getServerPort()
- */
- public void setServerPort( int serverPort )
- {
- this.serverPort = serverPort;
- }
-
- /**
- * Sets the targetFolder
attribute to the given value.
- *
- * @param targetFolder The new TargetFolder value
- * @see #getTargetFolder()
- */
- public void setTargetFolder( String targetFolder )
- {
- this.targetFolder = targetFolder;
- }
-
- /**
- * sets the property that indicates whether or not the Star Team "default
- * folder" is to be used when calculation paths for items on the target
- * (false) or if targetFolder is an absolute mapping to the root folder
- * named by foldername.
- *
- * @param targetFolderAbsolute true if the absolute mapping is to
- * be used. false (the default) if the "default folder" is to
- * be factored in.
- * @see #getTargetFolderAbsolute()
- */
- public void setTargetFolderAbsolute( boolean targetFolderAbsolute )
- {
- this.targetFolderAbsolute = targetFolderAbsolute;
- }
-
- /**
- * Sets the username
attribute to the given value.
- *
- * @param username Your username for the specified StarTeam server.
- * @see #getUsername()
- */
- public void setUsername( String username )
- {
- this.username = username;
- }
-
- /**
- * Sets the verbose
attribute to the given value.
- *
- * @param verbose whether to display all files as it checks them out. By
- * default it is false, so the program only displays the total number
- * of files unless you override this default.
- * @see #getVerbose()
- */
- public void setVerbose( boolean verbose )
- {
- this.verbose = verbose;
- }
-
- /**
- * Sets the viewName
attribute to the given value.
- *
- * @param viewName The view to find the specified folder in.
- * @see #getViewName()
- */
- public void setViewName( String viewName )
- {
- this.viewName = viewName;
- }
-
- /**
- * Gets the patterns from the exclude filter. Rather that duplicate the
- * details of AntStarTeanCheckOut's filtering here, refer to these links:
- *
- * @return A string of filter patterns separated by spaces.
- * @see #setExcludes(String excludes)
- * @see #setIncludes(String includes)
- * @see #getIncludes()
- */
- public String getExcludes()
- {
- return excludes;
- }
-
- /**
- * Gets the folderName
attribute.
- *
- * @return The subfolder from which to check out files. All subfolders will
- * be searched, as well.
- * @see #setFolderName(String folderName)
- */
- public String getFolderName()
- {
- return folderName;
- }
-
- /**
- * Gets the force
attribute.
- *
- * @return whether to continue if the target directory exists.
- * @see #setForce(boolean)
- */
- public boolean getForce()
- {
- return force;
- }
-
- /**
- * Gets the patterns from the include filter. Rather that duplicate the
- * details of AntStarTeanCheckOut's filtering here, refer to these links:
- *
- * @return A string of filter patterns separated by spaces.
- * @see #setIncludes(String includes)
- * @see #setExcludes(String excludes)
- * @see #getExcludes()
- */
- public String getIncludes()
- {
- return includes;
- }
-
- /**
- * Gets the password
attribute.
- *
- * @return The password given by the user.
- * @see #setPassword(String password)
- */
- public String getPassword()
- {
- return password;
- }
-
- /**
- * Gets the projectName
attribute.
- *
- * @return The StarTeam project to search.
- * @see #setProjectName(String projectName)
- */
- public String getProjectName()
- {
- return projectName;
- }
-
- /**
- * Gets the recursion
attribute, which tells
- * AntStarTeamCheckOut whether to search subfolders when checking out files.
- *
- * @return whether to search subfolders when checking out files.
- * @see #setRecursion(boolean)
- */
- public boolean getRecursion()
- {
- return recursion;
- }
-
- /**
- * Gets the serverName
attribute.
- *
- * @return The StarTeam server to log in to.
- * @see #setServerName(String serverName)
- */
- public String getServerName()
- {
- return serverName;
- }
-
- /**
- * Gets the serverPort
attribute.
- *
- * @return A string containing the port on the StarTeam server to use.
- * @see #setServerPort(int)
- */
- public int getServerPort()
- {
- return serverPort;
- }
-
- /**
- * Gets the targetFolder
attribute.
- *
- * @return The target path on the local machine to check out to.
- * @see #setTargetFolder(String targetFolder)
- */
- public String getTargetFolder()
- {
- return targetFolder;
- }
-
- /**
- * returns whether the StarTeam default path is factored into calculated
- * target path locations (false) or whether targetFolder is an absolute
- * mapping to the root folder named by folderName
- *
- * @return returns true if absolute mapping is used, false if it is not
- * used.
- * @see #setTargetFolderAbsolute(boolean)
- */
- public boolean getTargetFolderAbsolute()
- {
- return this.targetFolderAbsolute;
- }
-
- /**
- * Gets the username
attribute.
- *
- * @return The username given by the user.
- * @see #setUsername(String username)
- */
- public String getUsername()
- {
- return username;
- }
-
- /**
- * Gets the verbose
attribute.
- *
- * @return whether to display all files as it checks them out.
- * @see #setVerbose(boolean verbose)
- */
- public boolean getVerbose()
- {
- return verbose;
- }
-
- /**
- * Gets the viewName
attribute.
- *
- * @return The view to find the specified folder in.
- * @see #setViewName(String viewName)
- */
- public String getViewName()
- {
- return viewName;
- }
-
- /**
- * Do the execution.
- *
- * @exception TaskException
- */
- public void execute()
- throws TaskException
- {
- // Connect to the StarTeam server, and log on.
- Server s = getServer();
-
- try
- {
- // Search the items on this server.
- runServer( s );
- }
- finally
- {
- // Disconnect from the server.
- s.disconnect();
- }
- // after you are all of the properties are ok, do your thing
- // with StarTeam. If there are any kind of exceptions then
- // send the message to the project log.
-
- // Tell how many files were checked out.
- getContext().info( checkedOut + " files checked out." );
- }
-
- /**
- * Get the primary descriptor of the given item type. Returns null if there
- * isn't one. In practice, all item types have a primary descriptor.
- *
- * @param t An item type. At this point it will always be "file".
- * @return The specified item's primary descriptor.
- */
- protected Property getPrimaryDescriptor( Type t )
- {
- Property[] properties = t.getProperties();
- for( int i = 0; i < properties.length; i++ )
- {
- Property p = properties[ i ];
- if( p.isPrimaryDescriptor() )
- {
- return p;
- }
- }
- return null;
- }
-
- /**
- * Get the secondary descriptor of the given item type. Returns null if
- * there isn't one.
- *
- * @param t An item type. At this point it will always be "file".
- * @return The specified item's secondary descriptor. There may not be one
- * for every file.
- */
- protected Property getSecondaryDescriptor( Type t )
- {
- Property[] properties = t.getProperties();
- for( int i = 0; i < properties.length; i++ )
- {
- Property p = properties[ i ];
- if( p.isDescriptor() && !p.isPrimaryDescriptor() )
- {
- return p;
- }
- }
- return null;
- }
-
- /**
- * Creates and logs in to a StarTeam server.
- *
- * @return A StarTeam server.
- */
- protected Server getServer()
- {
- // Simplest constructor, uses default encryption algorithm and compression level.
- Server s = new Server( getServerName(), getServerPort() );
-
- // Optional; logOn() connects if necessary.
- s.connect();
-
- // Logon using specified user name and password.
- s.logOn( getUsername(), getPassword() );
-
- return s;
- }
-
- protected void checkParameters()
- throws TaskException
- {
- // Check all of the properties that are required.
- assertTrue( getServerName() != null, "ServerName must be set." );
- assertTrue( getServerPort() != -1, "ServerPort must be set." );
- assertTrue( getProjectName() != null, "ProjectName must be set." );
- assertTrue( getViewName() != null, "ViewName must be set." );
- assertTrue( getUsername() != null, "Username must be set." );
- assertTrue( getPassword() != null, "Password must be set." );
- assertTrue( getTargetFolder() != null, "TargetFolder must be set." );
-
- // Because of the way I create the full target path, there
- // must be NO slash at the end of targetFolder and folderName
- // However, if the slash or backslash is the only character, leave it alone
- if( ( getTargetFolder().endsWith( "/" ) ||
- getTargetFolder().endsWith( "\\" ) ) && getTargetFolder().length() > 1 )
- {
- setTargetFolder( getTargetFolder().substring( 0, getTargetFolder().length() - 1 ) );
- }
-
- // Check to see if the target directory exists.
- java.io.File dirExist = new java.io.File( getTargetFolder() );
- if( dirExist.isDirectory() && !getForce() )
- {
- throw new TaskException( "Target directory exists. Set \"force\" to \"true\" " +
- "to continue anyway." );
- }
- }
-
- /**
- * Formats a property value for display to the user.
- *
- * @param p An item property to format.
- * @param value
- * @return A string containing the property, which is truncated to 35
- * characters for display.
- */
- protected String formatForDisplay( Property p, Object value )
- {
- if( p.getTypeCode() == Property.Types.TEXT )
- {
- String str = value.toString();
- if( str.length() > 35 )
- {
- str = str.substring( 0, 32 ) + "...";
- }
- return "\"" + str + "\"";
- }
- else
- {
- if( p.getTypeCode() == Property.Types.ENUMERATED )
- {
- return "\"" + p.getEnumDisplayName( ( (Integer)value ).intValue() ) + "\"";
- }
- else
- {
- return value.toString();
- }
- }
- }
-
- /**
- * Convenient method to see if a string match a one pattern in given set of
- * space-separated patterns.
- *
- * @param patterns the space-separated list of patterns.
- * @param pName the name to look for matching.
- * @return whether the name match at least one pattern.
- */
- protected boolean matchPatterns( String patterns, String pName )
- {
- if( patterns == null )
- {
- return false;
- }
- StringTokenizer exStr = new StringTokenizer( patterns, " " );
- while( exStr.hasMoreTokens() )
- {
- if( ScannerUtil.match( exStr.nextToken(), pName ) )
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Searches for files in the given folder. This method is recursive and thus
- * searches all subfolders.
- *
- * @param s A StarTeam server.
- * @param p A valid project on the server.
- * @param v A view name from the specified project.
- * @param t An item type which is currently always "file".
- * @param f The folder to search.
- * @param tgt Target folder on local machine
- */
- protected void runFolder( Server s,
- com.starbase.starteam.Project p,
- View v,
- Type t,
- Folder f,
- java.io.File tgt )
- {
- // Process all items in this folder.
- Item[] items = f.getItems( t.getName() );
- for( int i = 0; i < items.length; i++ )
- {
- runItem( s, p, v, t, f, items[ i ], tgt );
- }
-
- // Process all subfolders recursively if recursion is on.
- if( getRecursion() )
- {
- Folder[] subfolders = f.getSubFolders();
- for( int i = 0; i < subfolders.length; i++ )
- {
- runFolder( s, p, v, t, subfolders[ i ], new java.io.File( tgt, subfolders[ i ].getName() ) );
- }
- }
- }
-
- /**
- * Check out one file if it matches the include filter but not the exclude
- * filter.
- *
- * @param s A StarTeam server.
- * @param p A valid project on the server.
- * @param v A view name from the specified project.
- * @param t An item type which is currently always "file".
- * @param f The folder the file is localed in.
- * @param item The file to check out.
- * @param tgt target folder on local machine
- */
- protected void runItem( Server s,
- com.starbase.starteam.Project p,
- View v,
- Type t,
- Folder f,
- Item item,
- java.io.File tgt )
- {
- // Get descriptors for this item type.
- Property p1 = getPrimaryDescriptor( t );
- Property p2 = getSecondaryDescriptor( t );
-
- String pName = (String)item.get( p1.getName() );
- if( !shouldCheckout( pName ) )
- {
- return;
- }
-
- // VERBOSE MODE ONLY
- if( getVerbose() )
- {
- // Show folder only if changed.
- boolean bShowHeader = ( f != prevFolder );
- if( bShowHeader )
- {
- // We want to display the folder the same way you would
- // enter it on the command line ... so we remove the
- // View name (which is also the name of the root folder,
- // and therefore shows up at the start of the path).
- String strFolder = f.getFolderHierarchy();
- int i = strFolder.indexOf( delim );
- if( i >= 0 )
- {
- strFolder = strFolder.substring( i + 1 );
- }
- getContext().info( " Folder: \"" + strFolder + "\"" );
- prevFolder = f;
-
- // If we displayed the project, view, item type, or folder,
- // then show the list of relevant item properties.
- StringBuffer header = new StringBuffer( " Item" );
- header.append( ",\t" ).append( p1.getDisplayName() );
- if( p2 != null )
- {
- header.append( ",\t" ).append( p2.getDisplayName() );
- }
- getContext().info( header.toString() );
- }
-
- // Finally, show the Item properties ...
- // Always show the ItemID.
- StringBuffer itemLine = new StringBuffer( " " );
- itemLine.append( item.getItemID() );
-
- // Show the primary descriptor.
- // There should always be one.
- itemLine.append( ",\t" ).append( formatForDisplay( p1, item.get( p1.getName() ) ) );
-
- // Show the secondary descriptor, if there is one.
- // Some item types have one, some don't.
- if( p2 != null )
- {
- itemLine.append( ",\t" ).append( formatForDisplay( p2, item.get( p2.getName() ) ) );
- }
-
- // Show if the file is locked.
- int locker = item.getLocker();
- if( locker > -1 )
- {
- itemLine.append( ",\tLocked by " ).append( locker );
- }
- else
- {
- itemLine.append( ",\tNot locked" );
- }
- getContext().info( itemLine.toString() );
- }
- // END VERBOSE ONLY
-
- // Check it out; also ugly.
-
- // Change the item to be checked out to a StarTeam File.
- com.starbase.starteam.File remote = (com.starbase.starteam.File)item;
-
- // The local file name is simply the local target path (tgt) which has
- // been passed recursively down from the top of the tree, with the item's name appended.
- java.io.File local = new java.io.File( tgt, (String)item.get( p1.getName() ) );
-
- try
- {
- remote.checkoutTo( local, Item.LockType.UNCHANGED, false, true, true );
- checkedOut++;
- }
- catch( Exception e )
- {
- throw new TaskException( "Failed to checkout '" + local + "'", e );
- }
- }
-
- /**
- * Searches for the given view in the project.
- *
- * @param s A StarTeam server.
- * @param p A valid project on the given server.
- */
- protected void runProject( Server s, com.starbase.starteam.Project p )
- {
- View[] views = p.getViews();
- for( int i = 0; i < views.length; i++ )
- {
- View v = views[ i ];
- if( v.getName().equals( getViewName() ) )
- {
- if( getVerbose() )
- {
- getContext().info( "Found " + getProjectName() + delim + getViewName() + delim );
- }
- runType( s, p, v, s.typeForName( (String)s.getTypeNames().FILE ) );
- break;
- }
- }
- }
-
- /**
- * Searches for the specified project on the server.
- *
- * @param s A StarTeam server.
- */
- protected void runServer( Server s )
- {
- com.starbase.starteam.Project[] projects = s.getProjects();
- for( int i = 0; i < projects.length; i++ )
- {
- com.starbase.starteam.Project p = projects[ i ];
-
- if( p.getName().equals( getProjectName() ) )
- {
- if( getVerbose() )
- {
- getContext().info( "Found " + getProjectName() + delim );
- }
- runProject( s, p );
- break;
- }
- }
- }
-
- /**
- * Searches for folders in the given view.
- *
- * @param s A StarTeam server.
- * @param p A valid project on the server.
- * @param v A view name from the specified project.
- * @param t An item type which is currently always "file".
- */
- protected void runType( Server s, com.starbase.starteam.Project p, View v, Type t )
- {
- // This is ugly; checking for the root folder.
- Folder f = v.getRootFolder();
- if( getFolderName() != null )
- {
- if( getFolderName().equals( "\\" ) || getFolderName().equals( "/" ) )
- {
- setFolderName( null );
- }
- else
- {
- f = StarTeamFinder.findFolder( v.getRootFolder(), getFolderName() );
- assertTrue( null != f, "ERROR: " + getProjectName() + delim + getViewName() + delim +
- v.getRootFolder() + delim + getFolderName() + delim +
- " does not exist." );
- }
- }
-
- if( getVerbose() && getFolderName() != null )
- {
- getContext().info( "Found " + getProjectName() + delim + getViewName() +
- delim + getFolderName() + delim + "\n" );
- }
-
- // For performance reasons, it is important to pre-fetch all the
- // properties we'll need for all the items we'll be searching.
-
- // We always display the ItemID (OBJECT_ID) and primary descriptor.
- int nProperties = 2;
-
- // We'll need this item type's primary descriptor.
- Property p1 = getPrimaryDescriptor( t );
-
- // Does this item type have a secondary descriptor?
- // If so, we'll need it.
- Property p2 = getSecondaryDescriptor( t );
- if( p2 != null )
- {
- nProperties++;
- }
-
- // Now, build an array of the property names.
- String[] strNames = new String[ nProperties ];
- int iProperty = 0;
- strNames[ iProperty++ ] = s.getPropertyNames().OBJECT_ID;
- strNames[ iProperty++ ] = p1.getName();
- if( p2 != null )
- {
- strNames[ iProperty++ ] = p2.getName();
- }
-
- // Pre-fetch the item properties and cache them.
- f.populateNow( t.getName(), strNames, -1 );
-
- // Now, search for items in the selected folder.
- runFolder( s, p, v, t, f, calcTargetFolder( v, f ) );
-
- // Free up the memory used by the cached items.
- f.discardItems( t.getName(), -1 );
- }
-
- /**
- * Look if the file should be checked out. Don't check it out if It fits no
- * include filters and It fits an exclude filter.
- *
- * @param pName the item name to look for being included.
- * @return whether the file should be checked out or not.
- */
- protected boolean shouldCheckout( String pName )
- {
- boolean includeIt = matchPatterns( getIncludes(), pName );
- boolean excludeIt = matchPatterns( getExcludes(), pName );
- return ( includeIt && !excludeIt );
- }
-
- /**
- * returns a file object that defines the root of the local checkout tree
- * Depending on the value of targetFolderAbsolute, this will be either the
- * targetFolder exactly as set by the user or the path formed by appending
- * the default folder onto the specified target folder.
- *
- * @param v view from which the file is checked out, supplies the "default
- * folder"
- * @param rootSourceFolder root folder of the checkout operation in Star
- * Team
- * @return an object referencing the local file
- * @see getTargetFolderAbsolute()
- */
- private java.io.File calcTargetFolder( View v, Folder rootSourceFolder )
- {
- java.io.File root = new java.io.File( getTargetFolder() );
- if( !getTargetFolderAbsolute() )
- {
- // Create a variable dir that contains the name of
- // the StarTeam folder that is the root folder in this view.
- // Get the default path to the current view.
- String defaultPath = v.getDefaultPath();
-
- // convert whatever separator char is in starteam to that of the target system.
- defaultPath = defaultPath.replace( '/', java.io.File.separatorChar );
- defaultPath = defaultPath.replace( '\\', java.io.File.separatorChar );
-
- java.io.File dir = new java.io.File( defaultPath );
- String dirName = dir.getName();
-
- // If it ends with separator then strip it off
- if( dirName.endsWith( delim ) )
- {
- dirName = dirName.substring( 0, dirName.length() - 1 );
- }
-
- // Replace the projectName in the file's absolute path to the viewName.
- // This makes the root target of a checkout operation equal to:
- // targetFolder + dirName
- StringTokenizer pathTokenizer = new StringTokenizer( rootSourceFolder.getFolderHierarchy(), delim );
- String currentToken = null;
- boolean foundRoot = false;
- while( pathTokenizer.hasMoreTokens() )
- {
- currentToken = pathTokenizer.nextToken();
- if( currentToken.equals( getProjectName() ) && !foundRoot )
- {
- currentToken = dirName;
- foundRoot = true;// only want to do this the first time
- }
- root = new java.io.File( root, currentToken );
- }
- }
-
- return root;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/CovMerge.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/CovMerge.java
deleted file mode 100644
index e51cc3e17..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/CovMerge.java
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Random;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.ScannerUtil;
-
-/**
- * Convenient task to run the snapshot merge utility for JProbe Coverage.
- *
- * @author Stephane Bailliez
- */
-public class CovMerge
- extends AbstractTask
-{
- /**
- * coverage home, it is mandatory
- */
- private File home = null;
-
- /**
- * the name of the output snapshot
- */
- private File tofile = null;
-
- /**
- * the filesets that will get all snapshots to merge
- */
- private ArrayList filesets = new ArrayList();
-
- private boolean verbose;
-
- //---------------- the tedious job begins here
-
- public CovMerge()
- {
- }
-
- /**
- * set the coverage home. it must point to JProbe coverage directories where
- * are stored native librairies and jars
- *
- * @param value The new Home value
- */
- public void setHome( File value )
- {
- this.home = value;
- }
-
- /**
- * Set the output snapshot file
- *
- * @param value The new Tofile value
- */
- public void setTofile( File value )
- {
- this.tofile = value;
- }
-
- /**
- * run the merging in verbose mode
- *
- * @param flag The new Verbose value
- */
- public void setVerbose( boolean flag )
- {
- this.verbose = flag;
- }
-
- /**
- * add a fileset containing the snapshots to include/exclude
- *
- * @param fs The feature to be added to the Fileset attribute
- */
- public void addFileset( FileSet fs )
- {
- filesets.add( fs );
- }
-
- /**
- * execute the jpcovmerge by providing a parameter file
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- checkOptions();
-
- File paramfile = createParamFile();
- try
- {
- Commandline cmdl = new Commandline();
- cmdl.setExecutable( new File( home, "jpcovmerge" ).getAbsolutePath() );
- if( verbose )
- {
- cmdl.addArgument( "-v" );
- }
- cmdl.addArgument( "-jp_paramfile=" + paramfile.getAbsolutePath() );
-
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
- getContext().debug( cmdl.toString() );
- exe.setCommandline( cmdl );
-
- // JProbe process always return 0 so we will not be
- // able to check for failure ! :-(
- int exitValue = exe.execute();
- if( exitValue != 0 )
- {
- throw new TaskException( "JProbe Coverage Merging failed (" + exitValue + ")" );
- }
- }
- catch( IOException e )
- {
- throw new TaskException( "Failed to run JProbe Coverage Merge: " + e );
- }
- finally
- {
- //@todo should be removed once switched to JDK1.2
- paramfile.delete();
- }
- }
-
- /**
- * get the snapshots from the filesets
- *
- * @return The Snapshots value
- */
- protected File[] getSnapshots()
- throws TaskException
- {
- ArrayList v = new ArrayList();
- final int size = filesets.size();
- for( int i = 0; i < size; i++ )
- {
- FileSet fs = (FileSet)filesets.get( i );
- DirectoryScanner ds = ScannerUtil.getDirectoryScanner( fs );
- ds.scan();
- String[] f = ds.getIncludedFiles();
- for( int j = 0; j < f.length; j++ )
- {
- String pathname = f[ j ];
- final File file = new File( ds.getBasedir(), pathname );
- file = getContext().resolveFile( file.getPath() );
- v.add( file );
- }
- }
-
- return (File[])v.toArray( new File[ v.size() ] );
- }
-
- /**
- * check for mandatory options
- *
- * @exception TaskException Description of Exception
- */
- protected void checkOptions()
- throws TaskException
- {
- if( tofile == null )
- {
- throw new TaskException( "'tofile' attribute must be set." );
- }
-
- // check coverage home
- if( home == null || !home.isDirectory() )
- {
- throw new TaskException( "Invalid home directory. Must point to JProbe home directory" );
- }
- home = new File( home, "coverage" );
- File jar = new File( home, "coverage.jar" );
- if( !jar.exists() )
- {
- throw new TaskException( "Cannot find Coverage directory: " + home );
- }
- }
-
- /**
- * create the parameters file that contains all file to merge and the output
- * filename.
- *
- * @return Description of the Returned Value
- * @exception TaskException Description of Exception
- */
- protected File createParamFile()
- throws TaskException
- {
- File[] snapshots = getSnapshots();
- File file = createTmpFile();
- FileWriter fw = null;
- try
- {
- fw = new FileWriter( file );
- PrintWriter pw = new PrintWriter( fw );
- for( int i = 0; i < snapshots.length; i++ )
- {
- pw.println( snapshots[ i ].getAbsolutePath() );
- }
- // last file is the output snapshot
- pw.println( getContext().resolveFile( tofile.getPath() ) );
- pw.flush();
- }
- catch( IOException e )
- {
- throw new TaskException( "I/O error while writing to " + file, e );
- }
- finally
- {
- if( fw != null )
- {
- try
- {
- fw.close();
- }
- catch( IOException ignored )
- {
- }
- }
- }
- return file;
- }
-
- /**
- * create a temporary file in the current dir (For JDK1.1 support)
- *
- * @return Description of the Returned Value
- */
- protected File createTmpFile()
- {
- final long rand = ( new Random( System.currentTimeMillis() ) ).nextLong();
- File file = new File( "jpcovmerge" + rand + ".tmp" );
- return file;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/CovReport.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/CovReport.java
deleted file mode 100644
index 657f0311c..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/CovReport.java
+++ /dev/null
@@ -1,435 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.EnumeratedAttribute;
-import org.apache.tools.todo.types.Path;
-import org.w3c.dom.Document;
-
-/**
- * Convenient task to run the snapshot merge utility for JProbe Coverage 3.0.
- *
- * @author Stephane Bailliez
- */
-public class CovReport
- extends AbstractTask
-{
- /*
- * jpcoverport [options] -output=file -snapshot=snapshot.jpc
- * jpcovreport [options] [-paramfile=file] -output= -snapshot=
- * Generate a report based on the indicated snapshot
- * -paramfile=file
- * A text file containing the report generation options.
- * -format=(html|text|xml) defaults to html
- * The format of the generated report.
- * -type=(executive|summary|detailed|verydetailed) defaults to detailed
- * The type of report to be generated. For -format=xml,
- * use -type=verydetailed to include source code lines.
- * Note: A very detailed report can be VERY large.
- * -percent=num Min 1 Max 101 Default 101
- * An integer representing a percentage of coverage.
- * Only methods with test case coverage less than the
- * percentage are included in reports.
- * -filters=string
- * A comma-separated list of filters in the form
- * .:V, where V can be I for Include or
- * E for Exclude. For the default package, omit .
- * -filters_method=string
- * Optional. A comma-separated list of methods that
- * correspond one-to-one with the entries in -filters.
- * -output=string Must be specified
- * The absolute path and file name for the generated
- * report file.
- * -snapshot=string Must be specified
- * The absolute path and file name of the snapshot file.
- * -inc_src_text=(on|off) defaults to on
- * Include text of the source code lines.
- * Only applies for -format=xml and -type=verydetailed.
- * -sourcepath=string defaults to .
- * A semicolon-separated list of source paths.
- * *
- * ** coverage home, mandatory
- */
- private File home = null;
-
- /**
- * format of generated report, optional
- */
- private String format = null;
-
- /**
- * the name of the output snapshot, mandatory
- */
- private File tofile = null;
-
- /**
- * type of report, optional
- */
- private String type = null;
-
- /**
- * threshold value for printing methods, optional
- */
- private Integer percent = null;
-
- /**
- * comma separated list of filters (???)
- */
- private String filters = null;
-
- /**
- * name of the snapshot file to create report from
- */
- private File snapshot = null;
-
- /**
- * sourcepath to use
- */
- private Path sourcePath = null;
-
- /**
- * include the text for each line of code (xml report verydetailed)
- */
- private boolean includeSource = true;
-
- private Path coveragePath = null;
-
- /**
- */
- private Reference reference = null;
-
- public CovReport()
- {
- }
-
- /**
- * set the filters
- *
- * @param values The new Filters value
- */
- public void setFilters( String values )
- {
- this.filters = values;
- }
-
- /**
- * set the format of the report html|text|xml
- *
- * @param value The new Format value
- */
- public void setFormat( ReportFormat value )
- {
- this.format = value.getValue();
- }
-
- /**
- * Set the coverage home. it must point to JProbe coverage directories where
- * are stored native libraries and jars.
- *
- * @param value The new Home value
- */
- public void setHome( File value )
- {
- this.home = value;
- }
-
- /**
- * include source code lines. XML report only
- *
- * @param value The new Includesource value
- */
- public void setIncludesource( boolean value )
- {
- this.includeSource = value;
- }
-
- /**
- * sets the threshold printing method 0-100
- *
- * @param value The new Percent value
- */
- public void setPercent( Integer value )
- {
- this.percent = value;
- }
-
- public void setSnapshot( File value )
- {
- this.snapshot = value;
- }
-
- /**
- * Set the output snapshot file
- *
- * @param value The new Tofile value
- */
- public void setTofile( File value )
- {
- this.tofile = value;
- }
-
- /**
- * sets the report type executive|summary|detailed|verydetailed
- *
- * @param value The new Type value
- */
- public void setType( ReportType value )
- {
- this.type = value.getValue();
- }
-
- //@todo to remove
- public Path createCoveragepath()
- {
- if( coveragePath == null )
- {
- coveragePath = new Path();
- }
- Path path1 = coveragePath;
- final Path path = new Path();
- path1.addPath( path );
- return path;
- }
-
- public Reference createReference()
- {
- if( reference == null )
- {
- reference = new Reference();
- }
- return reference;
- }
-
- public Path createSourcepath()
- {
- if( sourcePath == null )
- {
- sourcePath = new Path();
- }
- Path path1 = sourcePath;
- final Path path = new Path();
- path1.addPath( path );
- return path;
- }
-
- public void execute()
- throws TaskException
- {
- checkOptions();
- try
- {
- Commandline cmdl = new Commandline();
- // we need to run Coverage from his directory due to dll/jar issues
- cmdl.setExecutable( new File( home, "jpcovreport" ).getAbsolutePath() );
- String[] params = getParameters();
- for( int i = 0; i < params.length; i++ )
- {
- cmdl.addArgument( params[ i ] );
- }
-
- // use the custom handler for stdin issues
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
- getContext().debug( cmdl.toString() );
- exe.setCommandline( cmdl );
- int exitValue = exe.execute();
- if( exitValue != 0 )
- {
- throw new TaskException( "JProbe Coverage Report failed (" + exitValue + ")" );
- }
- getContext().debug( "coveragePath: " + coveragePath );
- getContext().debug( "format: " + format );
- if( reference != null && "xml".equals( format ) )
- {
- reference.createEnhancedXMLReport();
- }
-
- }
- catch( IOException e )
- {
- throw new TaskException( "Failed to execute JProbe Coverage Report.", e );
- }
- }
-
- protected String[] getParameters()
- throws TaskException
- {
- ArrayList v = new ArrayList();
- if( format != null )
- {
- v.add( "-format=" + format );
- }
- if( type != null )
- {
- v.add( "-type=" + type );
- }
- if( percent != null )
- {
- v.add( "-percent=" + percent );
- }
- if( filters != null )
- {
- v.add( "-filters=" + filters );
- }
- v.add( "-output=" + getContext().resolveFile( tofile.getPath() ) );
- v.add( "-snapshot=" + getContext().resolveFile( snapshot.getPath() ) );
- // as a default -sourcepath use . in JProbe, so use project .
- if( sourcePath == null )
- {
- sourcePath = new Path();
- Path path1 = sourcePath;
- final Path path = new Path();
- path1.addPath( path );
- path.setLocation( getBaseDirectory() );
- }
- v.add( "-sourcepath=" + sourcePath );
-
- if( "verydetailed".equalsIgnoreCase( format ) && "xml".equalsIgnoreCase( type ) )
- {
- v.add( "-inc_src_text=" + ( includeSource ? "on" : "off" ) );
- }
-
- return (String[])v.toArray( new String[ v.size() ] );
- }
-
- /**
- * check for mandatory options
- *
- * @exception TaskException Description of Exception
- */
- protected void checkOptions()
- throws TaskException
- {
- if( tofile == null )
- {
- throw new TaskException( "'tofile' attribute must be set." );
- }
- if( snapshot == null )
- {
- throw new TaskException( "'snapshot' attribute must be set." );
- }
- if( home == null )
- {
- throw new TaskException( "'home' attribute must be set to JProbe home directory" );
- }
- home = new File( home, "coverage" );
- File jar = new File( home, "coverage.jar" );
- if( !jar.exists() )
- {
- throw new TaskException( "Cannot find Coverage directory: " + home );
- }
- if( reference != null && !"xml".equals( format ) )
- {
- getContext().info( "Ignored reference. It cannot be used in non XML report." );
- reference = null;// nullify it so that there is no ambiguity
- }
-
- }
-
- public static class ReportFormat extends EnumeratedAttribute
- {
- public String[] getValues()
- {
- return new String[]{"html", "text", "xml"};
- }
- }
-
- public static class ReportType extends EnumeratedAttribute
- {
- public String[] getValues()
- {
- return new String[]{"executive", "summary", "detailed", "verydetailed"};
- }
- }
-
- public class Reference
- {
- protected Path classPath;
- protected ReportFilters filters;
-
- public Path createClasspath()
- {
- if( classPath == null )
- {
- classPath = new Path();
- }
- Path path1 = classPath;
- final Path path = new Path();
- path1.addPath( path );
- return path;
- }
-
- public ReportFilters createFilters()
- {
- if( filters == null )
- {
- filters = new ReportFilters();
- }
- return filters;
- }
-
- protected void createEnhancedXMLReport()
- throws TaskException
- {
- // we need a classpath element
- if( classPath == null )
- {
- throw new TaskException( "Need a 'classpath' element." );
- }
- // and a valid one...
- String[] paths = classPath.list();
- if( paths.length == 0 )
- {
- throw new TaskException( "Coverage path is invalid. It does not contain any existing path." );
- }
- // and we need at least one filter include/exclude.
- if( filters == null || filters.size() == 0 )
- {
- createFilters();
- getContext().debug( "Adding default include filter to *.*()" );
- Include include = new Include();
- filters.addInclude( include );
- }
- try
- {
- getContext().debug( "Creating enhanced XML report" );
- XMLReport report = new XMLReport( CovReport.this, tofile );
- report.setReportFilters( filters );
- report.setJProbehome( new File( home.getParent() ) );
- Document doc = report.createDocument( paths );
- TransformerFactory tfactory = TransformerFactory.newInstance();
- Transformer transformer = tfactory.newTransformer();
- transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
- transformer.setOutputProperty( OutputKeys.METHOD, "xml" );
- Source src = new DOMSource( doc );
- Result res = new StreamResult( "file:///" + tofile.toString() );
- transformer.transform( src, res );
- }
- catch( Exception e )
- {
- throw new TaskException( "Error while performing enhanced XML report from file " + tofile, e );
- }
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Coverage.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Coverage.java
deleted file mode 100644
index 698728a30..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Coverage.java
+++ /dev/null
@@ -1,457 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.tools.todo.types.Argument;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.CommandlineJava;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.Path;
-
-/**
- * Convenient task to run Sitraka JProbe Coverage from Ant. Options are pretty
- * numerous, you'd better check the manual for a full descriptions of options.
- * (not that simple since they differ from the online help, from the usage
- * command line and from the examples...)
- *
- * For additional information, visit
- * www.sitraka.com
- *
- * @author Stephane Bailliez
- */
-public class Coverage
- extends AbstractTask
-{
- protected Commandline cmdl = new Commandline();
- protected CommandlineJava cmdlJava = new CommandlineJava();
-
- /**
- * this is a somewhat annoying thing, set it to never
- */
- private String m_exitPrompt = "never";
-
- private Filters m_filters = new Filters();
- private String m_finalSnapshot = "coverage";
- private String m_recordFromStart = "coverage";
- private boolean m_trackNatives;
- private int m_warnLevel = 0;
- private ArrayList m_filesets = new ArrayList();
- private File m_home;
- private File m_inputFile;
- private File m_javaExe;
- private String m_seedName;
- private File m_snapshotDir;
- private Socket m_socket;
- private Triggers m_triggers;
- private String m_vm;
- private File m_workingDir;
-
- /**
- * classname to run as standalone or runner for filesets
- *
- * @param value The new Classname value
- */
- public void setClassname( String value )
- {
- cmdlJava.setClassname( value );
- }
-
- /**
- * always, error, never
- *
- * @param value The new Exitprompt value
- */
- public void setExitprompt( String value )
- {
- m_exitPrompt = value;
- }
-
- /**
- * none, coverage, all. can be null, default to none
- *
- * @param value The new Finalsnapshot value
- */
- public void setFinalsnapshot( String value )
- {
- m_finalSnapshot = value;
- }
-
- /**
- * set the coverage home directory where are libraries, jars and jplauncher
- *
- * @param value The new Home value
- */
- public void setHome( File value )
- {
- m_home = value;
- }
-
- public void setInputfile( File value )
- {
- m_inputFile = value;
- }
-
- public void setJavaexe( File value )
- {
- m_javaExe = value;
- }
-
- /**
- * all, coverage, none
- *
- * @param value The new Recordfromstart value
- */
- public void setRecordfromstart( Recordfromstart value )
- {
- m_recordFromStart = value.getValue();
- }
-
- /**
- * seed name for snapshot file. can be null, default to snap
- *
- * @param value The new Seedname value
- */
- public void setSeedname( String value )
- {
- m_seedName = value;
- }
-
- public void setSnapshotdir( File value )
- {
- m_snapshotDir = value;
- }
-
- public void setTracknatives( boolean value )
- {
- m_trackNatives = value;
- }
-
- /**
- * jdk117, jdk118 or java2, can be null, default to java2
- *
- * @param value The new Vm value
- */
- public void setVm( Javavm value )
- {
- m_vm = value.getValue();
- }
-
- public void setWarnlevel( Integer value )
- {
- m_warnLevel = value.intValue();
- }
-
- public void setWorkingdir( File value )
- {
- m_workingDir = value;
- }
-
- /**
- * the classnames to execute
- *
- * @param fs The feature to be added to the Fileset attribute
- */
- public void addFileset( FileSet fs )
- {
- m_filesets.add( fs );
- }
-
- /**
- * the command arguments
- */
- public void addArg( final Argument argument )
- {
- cmdlJava.addArgument( argument );
- }
-
- /**
- * classpath to run the files
- *
- * @return Description of the Returned Value
- */
- public Path createClasspath()
- {
- Path path1 = cmdlJava.createClasspath();
- final Path path = new Path();
- path1.addPath( path );
- return path;
- }
-
- public Filters createFilters()
- {
- return m_filters;
- }
-
- /**
- * the jvm arguments
- */
- public void addJvmarg( final Argument argument )
- {
- cmdlJava.addVmArgument( argument );
- }
-
- public Socket createSocket()
- {
- if( m_socket == null )
- {
- m_socket = new Socket();
- }
- return m_socket;
- }
-
- public Triggers createTriggers()
- {
- if( m_triggers == null )
- {
- m_triggers = new Triggers();
- }
- return m_triggers;
- }
-
- /**
- * execute the jplauncher by providing a parameter file
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- File paramfile = null;
- // if an input file is used, all other options are ignored...
- if( m_inputFile == null )
- {
- checkOptions();
- paramfile = createParamFile();
- }
- else
- {
- paramfile = m_inputFile;
- }
- try
- {
- // we need to run Coverage from his directory due to dll/jar issues
- cmdl.setExecutable( new File( m_home, "jplauncher" ).getAbsolutePath() );
- cmdl.addArgument( "-jp_input=" + paramfile.getAbsolutePath() );
-
- // use the custom handler for stdin issues
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
- getContext().debug( cmdl.toString() );
- exe.setCommandline( cmdl );
- int exitValue = exe.execute();
- if( exitValue != 0 )
- {
- throw new TaskException( "JProbe Coverage failed (" + exitValue + ")" );
- }
- }
- catch( IOException e )
- {
- throw new TaskException( "Failed to execute JProbe Coverage.", e );
- }
- finally
- {
- //@todo should be removed once switched to JDK1.2
- if( m_inputFile == null && paramfile != null )
- {
- paramfile.delete();
- }
- }
- }
-
- /**
- * return the command line parameters. Parameters can either be passed to
- * the command line and stored to a file (then use the
- * -jp_input=<filename>) if they are too numerous.
- *
- * @return The Parameters value
- */
- protected String[] getParameters()
- throws TaskException
- {
- ArrayList params = new ArrayList();
- params.add( "-jp_function=coverage" );
- if( m_vm != null )
- {
- params.add( "-jp_vm=" + m_vm );
- }
- if( m_javaExe != null )
- {
- params.add( "-jp_java_exe=" + getContext().resolveFile( m_javaExe.getPath() ) );
- }
- params.add( "-jp_working_dir=" + m_workingDir.getPath() );
- params.add( "-jp_snapshot_dir=" + m_snapshotDir.getPath() );
- params.add( "-jp_record_from_start=" + m_recordFromStart );
- params.add( "-jp_warn=" + m_warnLevel );
- if( m_seedName != null )
- {
- params.add( "-jp_output_file=" + m_seedName );
- }
- params.add( "-jp_filter=" + m_filters.toString() );
- if( m_triggers != null )
- {
- params.add( "-jp_trigger=" + m_triggers.toString() );
- }
- if( m_finalSnapshot != null )
- {
- params.add( "-jp_final_snapshot=" + m_finalSnapshot );
- }
- params.add( "-jp_exit_prompt=" + m_exitPrompt );
- //params.add("-jp_append=" + append);
- params.add( "-jp_track_natives=" + m_trackNatives );
- //.... now the jvm
- // arguments
- String[] vmargs = cmdlJava.getVmCommand().getArguments();
- for( int i = 0; i < vmargs.length; i++ )
- {
- params.add( vmargs[ i ] );
- }
- // classpath
- Path classpath = cmdlJava.getClasspath();
- if( classpath != null && classpath.size() > 0 )
- {
- params.add( "-classpath " + classpath.toString() );
- }
- // classname (runner or standalone)
- if( cmdlJava.getClassname() != null )
- {
- params.add( cmdlJava.getClassname() );
- }
- // arguments for classname
- String[] args = cmdlJava.getJavaCommand().getArguments();
- for( int i = 0; i < args.length; i++ )
- {
- params.add( args[ i ] );
- }
-
- return (String[])params.toArray( new String[ params.size() ] );
- }
-
- /**
- * wheck what is necessary to check, Coverage will do the job for us
- *
- * @exception TaskException Description of Exception
- */
- protected void checkOptions()
- throws TaskException
- {
- // check coverage home
- if( m_home == null || !m_home.isDirectory() )
- {
- throw new TaskException( "Invalid home directory. Must point to JProbe home directory" );
- }
- m_home = new File( m_home, "coverage" );
- File jar = new File( m_home, "coverage.jar" );
- if( !jar.exists() )
- {
- throw new TaskException( "Cannot find Coverage directory: " + m_home );
- }
-
- // make sure snapshot dir exists and is resolved
- if( m_snapshotDir == null )
- {
- m_snapshotDir = new File( "." );
- }
- m_snapshotDir = getContext().resolveFile( m_snapshotDir.getPath() );
- if( !m_snapshotDir.isDirectory() || !m_snapshotDir.exists() )
- {
- throw new TaskException( "Snapshot directory does not exists :" + m_snapshotDir );
- }
- if( m_workingDir == null )
- {
- m_workingDir = new File( "." );
- }
- m_workingDir = getContext().resolveFile( m_workingDir.getPath() );
-
- // check for info, do your best to select the java executable.
- // JProbe 3.0 fails if there is no javaexe option. So
- if( m_javaExe == null && ( m_vm == null || "java2".equals( m_vm ) ) )
- {
- String version = System.getProperty( "java.version" );
- // make we are using 1.2+, if it is, then do your best to
- // get a javaexe
- if( !version.startsWith( "1.1" ) )
- {
- if( m_vm == null )
- {
- m_vm = "java2";
- }
- // if we are here obviously it is java2
- String home = System.getProperty( "java.home" );
- boolean isUnix = File.separatorChar == '/';
- m_javaExe = isUnix ? new File( home, "bin/java" ) : new File( home, "/bin/java.exe" );
- }
- }
- }
-
- /**
- * create the parameter file from the given options. The file is created
- * with a random name in the current directory.
- *
- * @return the file object where are written the configuration to run JProbe
- * Coverage
- * @throws TaskException thrown if something bad happens while writing the
- * arguments to the file.
- */
- protected File createParamFile()
- throws TaskException
- {
- //@todo change this when switching to JDK 1.2 and use File.createTmpFile()
- File file = File.createTempFile( "jpcoverage", "tmp" );
- getContext().debug( "Creating parameter file: " + file );
-
- // options need to be one per line in the parameter file
- // so write them all in a single string
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter( sw );
- String[] params = getParameters();
- for( int i = 0; i < params.length; i++ )
- {
- pw.println( params[ i ] );
- }
- pw.flush();
- getContext().debug( "JProbe Coverage parameters:\n" + sw.toString() );
-
- // now write them to the file
- FileWriter fw = null;
- try
- {
- fw = new FileWriter( file );
- fw.write( sw.toString() );
- fw.flush();
- }
- catch( IOException e )
- {
- throw new TaskException( "Could not write parameter file " + file, e );
- }
- finally
- {
- if( fw != null )
- {
- try
- {
- fw.close();
- }
- catch( IOException ignored )
- {
- }
- }
- }
- return file;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Exclude.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Exclude.java
deleted file mode 100644
index 07677d6ff..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Exclude.java
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka;
-
-/**
- * concrete exclude class
- */
-public class Exclude
- extends FilterElement
-{
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/FilterElement.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/FilterElement.java
deleted file mode 100644
index f45d5c16b..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/FilterElement.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka;
-
-/**
- * default abstract filter element class
- */
-public abstract class FilterElement
-{
- protected String clazz = "*";// default is all classes
- protected String method = "*";// default is all methods
-
- public void setClass( String value )
- {
- clazz = value;
- }
-
- public void setMethod( String value )
- {
- method = value;
- }
-
- public String getAsPattern()
- {
- StringBuffer buf = new StringBuffer( toString() );
- replace( buf, ".", "\\." );
- replace( buf, "*", ".*" );
- replace( buf, "(", "\\(" );
- replace( buf, ")", "\\)" );
- return buf.toString();
- }
-
- public String toString()
- {
- return clazz + "." + method + "()";
- }
-
- /**
- * Replaces all occurences of find with replacement in the
- * source StringBuffer.
- *
- * @param src the original string buffer to modify.
- * @param find the string to be replaced.
- * @param replacement the replacement string for find matches.
- */
- public static void replace( StringBuffer src, String find, String replacement )
- {
- int index = 0;
- while( index < src.length() )
- {
- index = src.toString().indexOf( find, index );
- if( index == -1 )
- {
- break;
- }
- src.delete( index, index + find.length() );
- src.insert( index, replacement );
- index += replacement.length() + 1;
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Filters.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Filters.java
deleted file mode 100644
index 3f56e9c08..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Filters.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka;
-
-import java.util.ArrayList;
-
-/**
- * Filters information from coverage, somewhat similar to a FileSet .
- *
- * @author Stephane Bailliez
- */
-public class Filters
-{
-
- /**
- * default regexp to exclude everything
- */
- public final static String DEFAULT_EXCLUDE = "*.*():E";
-
- /**
- * say whether we should use the default excludes or not
- */
- protected boolean defaultExclude = true;
-
- /**
- * user defined filters
- */
- protected ArrayList filters = new ArrayList();
-
- public Filters()
- {
- }
-
- public void setDefaultExclude( boolean value )
- {
- defaultExclude = value;
- }
-
- public void addExclude( Exclude excl )
- {
- filters.add( excl );
- }
-
- public void addInclude( Include incl )
- {
- filters.add( incl );
- }
-
- public String toString()
- {
- StringBuffer buf = new StringBuffer();
- final int size = filters.size();
- if( defaultExclude )
- {
- buf.append( DEFAULT_EXCLUDE );
- if( size > 0 )
- {
- buf.append( ',' );
- }
- }
- for( int i = 0; i < size; i++ )
- {
- buf.append( filters.get( i ).toString() );
- if( i < size - 1 )
- {
- buf.append( ',' );
- }
- }
- return buf.toString();
- }
-
- public static class Exclude extends FilterElement
- {
- public String toString()
- {
- return super.toString() + ":E" + ( enabled ? "" : "#" );
- }
- }
-
- public abstract static class FilterElement
- {
- protected String method = "*";// default is all methods
- protected boolean enabled = true;
- protected String clazz;
-
- public void setClass( String value )
- {
- clazz = value;
- }
-
- public void setEnabled( boolean value )
- {
- enabled = value;
- }
-
- public void setMethod( String value )
- {
- method = value;
- }// default is enable
-
- public void setName( String value )
- {// this one is deprecated.
- clazz = value;
- }
-
- public String toString()
- {
- return clazz + "." + method + "()";
- }
- }
-
- public static class Include extends FilterElement
- {
- public String toString()
- {
- return super.toString() + ":I" + ( enabled ? "" : "#" );
- }
- }
-}
-
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Finalsnapshot.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Finalsnapshot.java
deleted file mode 100644
index 6e2d86ea4..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Finalsnapshot.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka;
-
-import org.apache.tools.todo.types.EnumeratedAttribute;
-
-public class Finalsnapshot
- extends EnumeratedAttribute
-{
- public String[] getValues()
- {
- return new String[]{"coverage", "none", "all"};
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Include.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Include.java
deleted file mode 100644
index 0807d1c96..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Include.java
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka;
-
-/**
- * concrete include class
- */
-public class Include
- extends FilterElement
-{
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Javavm.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Javavm.java
deleted file mode 100644
index 84bf8a7c7..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Javavm.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka;
-
-import org.apache.tools.todo.types.EnumeratedAttribute;
-
-public class Javavm
- extends EnumeratedAttribute
-{
- public String[] getValues()
- {
- return new String[]{"java2", "jdk118", "jdk117"};
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Recordfromstart.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Recordfromstart.java
deleted file mode 100644
index 272fbf981..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Recordfromstart.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka;
-
-import org.apache.tools.todo.types.EnumeratedAttribute;
-
-public class Recordfromstart
- extends EnumeratedAttribute
-{
- public String[] getValues()
- {
- return new String[]{"coverage", "none", "all"};
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/ReportFilters.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/ReportFilters.java
deleted file mode 100644
index a0c4f35f8..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/ReportFilters.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka;
-
-import java.util.ArrayList;
-import org.apache.tools.todo.util.regexp.RegexpMatcher;
-import org.apache.tools.todo.util.regexp.RegexpMatcherFactory;
-
-/**
- * Filters information from coverage, somewhat similar to a FileSet .
- *
- * @author Stephane Bailliez
- */
-public class ReportFilters
-{
- /**
- * user defined filters
- */
- private ArrayList filters = new ArrayList();
-
- /**
- * cached matcher for each filter
- */
- private ArrayList m_matchers;
-
- /**
- * Check whether a given <classname><method>() is accepted by
- * the list of filters or not.
- *
- * @param methodname the full method name in the format
- * <classname><method>()
- * @return Description of the Returned Value
- */
- public boolean accept( String methodname )
- {
- // I'm deferring matcher instantiations at runtime to avoid computing
- // the filters at parsing time
- if( m_matchers == null )
- {
- createMatchers();
- }
- boolean result = false;
- // assert filters.size() == matchers.size()
- final int size = filters.size();
- for( int i = 0; i < size; i++ )
- {
- FilterElement filter = (FilterElement)filters.get( i );
- RegexpMatcher matcher = (RegexpMatcher)m_matchers.get( i );
- if( filter instanceof Include )
- {
- result = result || matcher.matches( methodname );
- }
- else if( filter instanceof Exclude )
- {
- result = result && !matcher.matches( methodname );
- }
- else
- {
- //not possible
- throw new IllegalArgumentException( "Invalid filter element: " + filter.getClass().getName() );
- }
- }
- return result;
- }
-
- public void addExclude( Exclude excl )
- {
- filters.add( excl );
- }
-
- public void addInclude( Include incl )
- {
- filters.add( incl );
- }
-
- public int size()
- {
- return filters.size();
- }
-
- /**
- * should be called only once to cache matchers
- */
- protected void createMatchers()
- {
- RegexpMatcherFactory factory = new RegexpMatcherFactory();
- final int size = filters.size();
- m_matchers = new ArrayList();
- for( int i = 0; i < size; i++ )
- {
- FilterElement filter = (FilterElement)filters.get( i );
- RegexpMatcher matcher = factory.newRegexpMatcher();
- String pattern = filter.getAsPattern();
- matcher.setPattern( pattern );
- m_matchers.add( matcher );
- }
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Socket.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Socket.java
deleted file mode 100644
index bbac393c7..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Socket.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka;
-
-/**
- * Socket element for connection. <socket/> defaults to host
- * 127.0.0.1 and port 4444 Otherwise it requires the host and port attributes to
- * be set: <socket host="e;175.30.12.1"e;
- * port="e;4567"e;/>
- *
- * @author RT
- */
-public class Socket
-{
-
- /**
- * default to localhost
- */
- private String host = "127.0.0.1";
-
- /**
- * default to 4444
- */
- private int port = 4444;
-
- public void setHost( String value )
- {
- host = value;
- }
-
- public void setPort( Integer value )
- {
- port = value.intValue();
- }
-
- /**
- * if no host is set, returning ':<port>', will take localhost
- *
- * @return Description of the Returned Value
- */
- public String toString()
- {
- return host + ":" + port;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Triggers.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Triggers.java
deleted file mode 100644
index ed8be3907..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/Triggers.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka;
-
-import java.util.ArrayList;
-import java.util.Hashtable;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * Trigger information. It will return as a command line argument by calling the
- * toString() method.
- *
- * @author Stephane Bailliez
- */
-public class Triggers
-{
-
- /**
- * mapping of actions to cryptic command line mnemonics
- */
- private final static Hashtable actionMap = new Hashtable( 3 );
-
- /**
- * mapping of events to cryptic command line mnemonics
- */
- private final static Hashtable eventMap = new Hashtable( 3 );
-
- protected ArrayList triggers = new ArrayList();
-
- static
- {
- actionMap.put( "enter", "E" );
- actionMap.put( "exit", "X" );
- // clear|pause|resume|snapshot|suspend|exit
- eventMap.put( "clear", "C" );
- eventMap.put( "pause", "P" );
- eventMap.put( "resume", "R" );
- eventMap.put( "snapshot", "S" );
- eventMap.put( "suspend", "A" );
- eventMap.put( "exit", "X" );
- }
-
- public Triggers()
- {
- }
-
- public void addMethod( Method method )
- {
- triggers.add( method );
- }
-
- // -jp_trigger=ClassName.*():E:S,ClassName.MethodName():X:X
- public String toString()
- {
- StringBuffer buf = new StringBuffer();
- final int size = triggers.size();
- for( int i = 0; i < size; i++ )
- {
- buf.append( triggers.get( i ).toString() );
- if( i < size - 1 )
- {
- buf.append( ',' );
- }
- }
- return buf.toString();
- }
-
- public static class Method
- {
- protected String action;
- protected String event;
- protected String name;
- protected String param;
-
- public void setAction( String value )
- throws TaskException
- {
- if( actionMap.get( value ) == null )
- {
- throw new TaskException( "Invalid action, must be one of " + actionMap );
- }
- action = value;
- }
-
- public void setEvent( String value )
- {
- if( eventMap.get( value ) == null )
- {
- throw new TaskException( "Invalid event, must be one of " + eventMap );
- }
- event = value;
- }
-
- public void setName( String value )
- {
- name = value;
- }
-
- public void setParam( String value )
- {
- param = value;
- }
-
- // return ::[:param]
- public String toString()
- {
- StringBuffer buf = new StringBuffer();
- buf.append( name ).append( ":" );//@todo name must not be null, check for it
- buf.append( eventMap.get( event ) ).append( ":" );
- buf.append( actionMap.get( action ) );
- if( param != null )
- {
- buf.append( ":" ).append( param );
- }
- return buf.toString();
- }
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/XMLReport.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/XMLReport.java
deleted file mode 100644
index a3286bf93..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/XMLReport.java
+++ /dev/null
@@ -1,675 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.taskdefs.sitraka.bytecode.ClassFile;
-import org.apache.tools.todo.taskdefs.sitraka.bytecode.ClassPathLoader;
-import org.apache.tools.todo.taskdefs.sitraka.bytecode.MethodInfo;
-import org.apache.tools.todo.taskdefs.sitraka.bytecode.Utils;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-
-/**
- * Little hack to process XML report from JProbe. It will fix some reporting
- * errors from JProbe 3.0 and makes use of a reference classpath to add
- * classes/methods that were not reported by JProbe as being used (ie loaded)
- *
- * @author Stephane Bailliez
- */
-public class XMLReport
-{
-
- /**
- * mapping of class names to ClassFile
s from the reference
- * classpath. It is used to filter the JProbe report.
- */
- protected Hashtable classFiles;
-
- /**
- * mapping classname / class node for faster access
- */
- protected Hashtable classMap;
-
- /**
- * the XML file to process just from CovReport
- */
- protected File file;
-
- /**
- * method filters
- */
- protected ReportFilters filters;
-
- /**
- * jprobe home path. It is used to get the DTD
- */
- protected File jprobeHome;
-
- /**
- * mapping package name / package node for faster access
- */
- protected Hashtable pkgMap;
-
- /**
- * parsed document
- */
- protected Document report;
- /**
- * task caller, can be null, used for logging purpose
- */
- protected AbstractTask task;
-
- /**
- * create a new XML report, logging will be on stdout
- *
- * @param file Description of Parameter
- */
- public XMLReport( File file )
- {
- this( null, file );
- }
-
- /**
- * create a new XML report, logging done on the task
- *
- * @param task Description of Parameter
- * @param file Description of Parameter
- */
- public XMLReport( AbstractTask task, File file )
- {
- this.file = file;
- this.task = task;
- }
-
- private static DocumentBuilder newBuilder()
- {
- try
- {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setIgnoringComments( true );
- factory.setValidating( false );
- return factory.newDocumentBuilder();
- }
- catch( Exception e )
- {
- throw new ExceptionInInitializerError( e );
- }
- }
-
- /**
- * set the JProbe home path. Used to get the DTD
- *
- * @param home The new JProbehome value
- */
- public void setJProbehome( File home )
- {
- jprobeHome = home;
- }
-
- /**
- * set the
- *
- * @param filters The new ReportFilters value
- */
- public void setReportFilters( ReportFilters filters )
- {
- this.filters = filters;
- }
-
- /**
- * create the whole new document
- *
- * @param classPath Description of Parameter
- * @return Description of the Returned Value
- * @exception Exception Description of Exception
- */
- public Document createDocument( String[] classPath )
- throws Exception
- {
-
- // Iterate over the classpath to identify reference classes
- classFiles = new Hashtable();
- ClassPathLoader cpl = new ClassPathLoader( classPath );
- Iterator enum = cpl.loaders();
- while( enum.hasNext() )
- {
- ClassPathLoader.FileLoader fl = (ClassPathLoader.FileLoader)enum.next();
- ClassFile[] classes = fl.getClasses();
- log( "Processing " + classes.length + " classes in " + fl.getFile() );
- // process all classes
- for( int i = 0; i < classes.length; i++ )
- {
- classFiles.put( classes[ i ].getFullName(), classes[ i ] );
- }
- }
-
- // Load the JProbe coverage XML report
- DocumentBuilder dbuilder = newBuilder();
- InputSource is = new InputSource( new FileInputStream( file ) );
- if( jprobeHome != null )
- {
- File dtdDir = new File( jprobeHome, "dtd" );
- is.setSystemId( "file:///" + dtdDir.getAbsolutePath() + "/" );
- }
- report = dbuilder.parse( is );
- report.normalize();
-
- // create maps for faster node access (also filters out unwanted nodes)
- createNodeMaps();
-
- // Make sure each class from the reference path ends up in the report
- Iterator classes = classFiles.iterator();
- while( classes.hasNext() )
- {
- ClassFile cf = (ClassFile)classes.next();
- serializeClass( cf );
- }
- // update the document with the stats
- update();
- return report;
- }
-
- public void log( String message )
- {
- if( task == null )
- {
- //System.out.println(message);
- }
- else
- {
- task.getContext().debug( message );
- }
- }
-
- protected Element[] getClasses( Element pkg )
- {
- ArrayList v = new ArrayList();
- NodeList children = pkg.getChildNodes();
- int len = children.getLength();
- for( int i = 0; i < len; i++ )
- {
- Node child = children.item( i );
- if( child.getNodeType() == Node.ELEMENT_NODE )
- {
- Element elem = (Element)child;
- if( "class".equals( elem.getNodeName() ) )
- {
- v.add( elem );
- }
- }
- }
- Element[] elems = new Element[ v.size() ];
- v.copyInto( elems );
- return elems;
- }
-
- protected Element getCovDataChild( Element parent )
- {
- NodeList children = parent.getChildNodes();
- int len = children.getLength();
- for( int i = 0; i < len; i++ )
- {
- Node child = children.item( i );
- if( child.getNodeType() == Node.ELEMENT_NODE )
- {
- Element elem = (Element)child;
- if( "cov.data".equals( elem.getNodeName() ) )
- {
- return elem;
- }
- }
- }
- throw new NoSuchElementException( "Could not find 'cov.data' element in parent '" + parent.getNodeName() + "'" );
- }
-
- protected ArrayList getFilteredMethods( ClassFile classFile )
- {
- MethodInfo[] methodlist = classFile.getMethods();
- ArrayList methods = new ArrayList( methodlist.length );
- for( int i = 0; i < methodlist.length; i++ )
- {
- MethodInfo method = methodlist[ i ];
- String signature = getMethodSignature( classFile, method );
- if( filters.accept( signature ) )
- {
- methods.add( method );
- log( "keeping " + signature );
- }
- else
- {
- // log("discarding " + signature);
- }
- }
- return methods;
- }
-
- /**
- * JProbe does not put the java.lang prefix for classes in this package, so
- * used this nice method so that I have the same signature for methods
- *
- * @param method Description of Parameter
- * @return The MethodSignature value
- */
- protected String getMethodSignature( MethodInfo method )
- {
- StringBuffer buf = new StringBuffer( method.getName() );
- buf.append( "(" );
- String[] params = method.getParametersType();
- for( int i = 0; i < params.length; i++ )
- {
- String type = params[ i ];
- int pos = type.lastIndexOf( '.' );
- if( pos != -1 )
- {
- String pkg = type.substring( 0, pos );
- if( "java.lang".equals( pkg ) )
- {
- params[ i ] = type.substring( pos + 1 );
- }
- }
- buf.append( params[ i ] );
- if( i != params.length - 1 )
- {
- buf.append( ", " );
- }
- }
- buf.append( ")" );
- return buf.toString();
- }
-
- /**
- * Convert to a CovReport-like signature ie,
- * <classname>.<method>()
- *
- * @param clazz Description of Parameter
- * @param method Description of Parameter
- * @return The MethodSignature value
- */
- protected String getMethodSignature( ClassFile clazz, MethodInfo method )
- {
- StringBuffer buf = new StringBuffer( clazz.getFullName() );
- buf.append( "." );
- buf.append( method.getName() );
- buf.append( "()" );
- return buf.toString();
- }
-
- protected Hashtable getMethods( Element clazz )
- {
- Hashtable map = new Hashtable();
- NodeList children = clazz.getChildNodes();
- int len = children.getLength();
- for( int i = 0; i < len; i++ )
- {
- Node child = children.item( i );
- if( child.getNodeType() == Node.ELEMENT_NODE )
- {
- Element elem = (Element)child;
- if( "method".equals( elem.getNodeName() ) )
- {
- String name = elem.getAttribute( "name" );
- map.put( name, elem );
- }
- }
- }
- return map;
- }
-
- protected Element[] getPackages( Element snapshot )
- {
- ArrayList v = new ArrayList();
- NodeList children = snapshot.getChildNodes();
- int len = children.getLength();
- for( int i = 0; i < len; i++ )
- {
- Node child = children.item( i );
- if( child.getNodeType() == Node.ELEMENT_NODE )
- {
- Element elem = (Element)child;
- if( "package".equals( elem.getNodeName() ) )
- {
- v.add( elem );
- }
- }
- }
- Element[] elems = new Element[ v.size() ];
- v.copyInto( elems );
- return elems;
- }
-
- /**
- * create an empty class element with its default cov.data (0)
- *
- * @param classFile Description of Parameter
- * @return Description of the Returned Value
- */
- protected Element createClassElement( ClassFile classFile )
- {
- // create the class element
- Element classElem = report.createElement( "class" );
- classElem.setAttribute( "name", classFile.getName() );
- // source file possibly does not exist in the bytecode
- if( null != classFile.getSourceFile() )
- {
- classElem.setAttribute( "source", classFile.getSourceFile() );
- }
- // create the cov.data elem
- Element classData = report.createElement( "cov.data" );
- classElem.appendChild( classData );
- // create the class cov.data element
- classData.setAttribute( "calls", "0" );
- classData.setAttribute( "hit_methods", "0" );
- classData.setAttribute( "total_methods", "0" );
- classData.setAttribute( "hit_lines", "0" );
- classData.setAttribute( "total_lines", "0" );
- return classElem;
- }
-
- /**
- * create an empty method element with its cov.data values
- *
- * @param method Description of Parameter
- * @return Description of the Returned Value
- */
- protected Element createMethodElement( MethodInfo method )
- {
- String methodsig = getMethodSignature( method );
- Element methodElem = report.createElement( "method" );
- methodElem.setAttribute( "name", methodsig );
- // create the method cov.data element
- Element methodData = report.createElement( "cov.data" );
- methodElem.appendChild( methodData );
- methodData.setAttribute( "calls", "0" );
- methodData.setAttribute( "hit_lines", "0" );
- methodData.setAttribute( "total_lines", String.valueOf( method.getNumberOfLines() ) );
- return methodElem;
- }
-
- /**
- * create node maps so that we can access node faster by their name
- */
- protected void createNodeMaps()
- {
- pkgMap = new Hashtable();
- classMap = new Hashtable();
- // create a map index of all packages by their name
- // @todo can be done faster by direct access.
- NodeList packages = report.getElementsByTagName( "package" );
- final int pkglen = packages.getLength();
- log( "Indexing " + pkglen + " packages" );
- for( int i = pkglen - 1; i > -1; i-- )
- {
- Element pkg = (Element)packages.item( i );
- String pkgname = pkg.getAttribute( "name" );
-
- int nbclasses = 0;
- // create a map index of all classes by their fully
- // qualified name.
- NodeList classes = pkg.getElementsByTagName( "class" );
- final int classlen = classes.getLength();
- log( "Indexing " + classlen + " classes in package " + pkgname );
- for( int j = classlen - 1; j > -1; j-- )
- {
- Element clazz = (Element)classes.item( j );
- String classname = clazz.getAttribute( "name" );
- if( pkgname != null && pkgname.length() != 0 )
- {
- classname = pkgname + "." + classname;
- }
-
- int nbmethods = 0;
- NodeList methods = clazz.getElementsByTagName( "method" );
- final int methodlen = methods.getLength();
- for( int k = methodlen - 1; k > -1; k-- )
- {
- Element meth = (Element)methods.item( k );
- StringBuffer methodname = new StringBuffer( meth.getAttribute( "name" ) );
- methodname.delete( methodname.toString().indexOf( "(" ), methodname.toString().length() );
- String signature = classname + "." + methodname + "()";
- if( filters.accept( signature ) )
- {
- log( "kept method:" + signature );
- nbmethods++;
- }
- else
- {
- clazz.removeChild( meth );
- }
- }
- // if we don't keep any method, we don't keep the class
- if( nbmethods != 0 && classFiles.containsKey( classname ) )
- {
- log( "Adding class '" + classname + "'" );
- classMap.put( classname, clazz );
- nbclasses++;
- }
- else
- {
- pkg.removeChild( clazz );
- }
- }
- if( nbclasses != 0 )
- {
- log( "Adding package '" + pkgname + "'" );
- pkgMap.put( pkgname, pkg );
- }
- else
- {
- pkg.getParentNode().removeChild( pkg );
- }
- }
- log( "Indexed " + classMap.size() + " classes in " + pkgMap.size() + " packages" );
- }
-
- /**
- * create an empty package element with its default cov.data (0)
- *
- * @param pkgname Description of Parameter
- * @return Description of the Returned Value
- */
- protected Element createPackageElement( String pkgname )
- {
- Element pkgElem = report.createElement( "package" );
- pkgElem.setAttribute( "name", pkgname );
- // create the package cov.data element / default
- // must be updated at the end of the whole process
- Element pkgData = report.createElement( "cov.data" );
- pkgElem.appendChild( pkgData );
- pkgData.setAttribute( "calls", "0" );
- pkgData.setAttribute( "hit_methods", "0" );
- pkgData.setAttribute( "total_methods", "0" );
- pkgData.setAttribute( "hit_lines", "0" );
- pkgData.setAttribute( "total_lines", "0" );
- return pkgElem;
- }
-
- /**
- * Do additional work on an element to remove abstract methods that are
- * reported by JProbe 3.0
- *
- * @param classFile Description of Parameter
- * @param classNode Description of Parameter
- */
- protected void removeAbstractMethods( ClassFile classFile, Element classNode )
- {
- MethodInfo[] methods = classFile.getMethods();
- Hashtable methodNodeList = getMethods( classNode );
- // assert xmlMethods.size() == methods.length()
- final int size = methods.length;
- for( int i = 0; i < size; i++ )
- {
- MethodInfo method = methods[ i ];
- String methodSig = getMethodSignature( method );
- Element methodNode = (Element)methodNodeList.get( methodSig );
- if( methodNode != null &&
- Utils.isAbstract( method.getAccessFlags() ) )
- {
- log( "\tRemoving abstract method " + methodSig );
- classNode.removeChild( methodNode );
- }
- }
- }
-
- /**
- * serialize a classfile into XML
- *
- * @param classFile Description of Parameter
- */
- protected void serializeClass( ClassFile classFile )
- {
- // the class already is reported so ignore it
- String fullclassname = classFile.getFullName();
- log( "Looking for '" + fullclassname + "'" );
- Element clazz = (Element)classMap.get( fullclassname );
-
- // ignore classes that are already reported, all the information is
- // already there.
- if( clazz != null )
- {
- log( "Ignoring " + fullclassname );
- removeAbstractMethods( classFile, clazz );
- return;
- }
-
- // ignore interfaces files, there is no code in there to cover.
- if( Utils.isInterface( classFile.getAccess() ) )
- {
- return;
- }
-
- ArrayList methods = getFilteredMethods( classFile );
- // no need to process, there are no methods to add for this class.
- if( methods.size() == 0 )
- {
- return;
- }
-
- String pkgname = classFile.getPackage();
- // System.out.println("Looking for package " + pkgname);
- Element pkgElem = (Element)pkgMap.get( pkgname );
- if( pkgElem == null )
- {
- pkgElem = createPackageElement( pkgname );
- report.getDocumentElement().appendChild( pkgElem );
- pkgMap.put( pkgname, pkgElem );// add the pkg to the map
- }
- // this is a brand new class, so we have to create a new node
-
- // create the class element
- Element classElem = createClassElement( classFile );
- pkgElem.appendChild( classElem );
-
- int total_lines = 0;
- int total_methods = 0;
- for( int i = 0; i < methods.size(); i++ )
- {
- // create the method element
- MethodInfo method = (MethodInfo)methods.get( i );
- if( Utils.isAbstract( method.getAccessFlags() ) )
- {
- continue;// no need to report abstract methods
- }
- Element methodElem = createMethodElement( method );
- classElem.appendChild( methodElem );
- total_lines += method.getNumberOfLines();
- total_methods++;
- }
- // create the class cov.data element
- Element classData = getCovDataChild( classElem );
- classData.setAttribute( "total_methods", String.valueOf( total_methods ) );
- classData.setAttribute( "total_lines", String.valueOf( total_lines ) );
-
- // add itself to the node map
- classMap.put( fullclassname, classElem );
- }
-
- /**
- * update the count of the XML, that is accumulate the stats on methods,
- * classes and package so that the numbers are valid according to the info
- * that was appended to the XML.
- */
- protected void update()
- {
- int calls = 0;
- int hit_methods = 0;
- int total_methods = 0;
- int hit_lines = 0;
- int total_lines = 0;
-
- // use the map for access, all nodes should be there
- Iterator enum = pkgMap.iterator();
- while( enum.hasNext() )
- {
- Element pkgElem = (Element)enum.next();
- String pkgname = pkgElem.getAttribute( "name" );
- Element[] classes = getClasses( pkgElem );
- int pkg_calls = 0;
- int pkg_hit_methods = 0;
- int pkg_total_methods = 0;
- int pkg_hit_lines = 0;
- int pkg_total_lines = 0;
- //System.out.println("Processing package '" + pkgname + "': " + classes.length + " classes");
- for( int j = 0; j < classes.length; j++ )
- {
- Element clazz = classes[ j ];
- String classname = clazz.getAttribute( "name" );
- if( pkgname != null && pkgname.length() != 0 )
- {
- classname = pkgname + "." + classname;
- }
- // there's only cov.data as a child so bet on it
- Element covdata = getCovDataChild( clazz );
- try
- {
- pkg_calls += Integer.parseInt( covdata.getAttribute( "calls" ) );
- pkg_hit_methods += Integer.parseInt( covdata.getAttribute( "hit_methods" ) );
- pkg_total_methods += Integer.parseInt( covdata.getAttribute( "total_methods" ) );
- pkg_hit_lines += Integer.parseInt( covdata.getAttribute( "hit_lines" ) );
- pkg_total_lines += Integer.parseInt( covdata.getAttribute( "total_lines" ) );
- }
- catch( NumberFormatException e )
- {
- log( "Error parsing '" + classname + "' (" + j + "/" + classes.length + ") in package '" + pkgname + "'" );
- throw e;
- }
- }
- Element covdata = getCovDataChild( pkgElem );
- covdata.setAttribute( "calls", String.valueOf( pkg_calls ) );
- covdata.setAttribute( "hit_methods", String.valueOf( pkg_hit_methods ) );
- covdata.setAttribute( "total_methods", String.valueOf( pkg_total_methods ) );
- covdata.setAttribute( "hit_lines", String.valueOf( pkg_hit_lines ) );
- covdata.setAttribute( "total_lines", String.valueOf( pkg_total_lines ) );
- calls += pkg_calls;
- hit_methods += pkg_hit_methods;
- total_methods += pkg_total_methods;
- hit_lines += pkg_hit_lines;
- total_lines += pkg_total_lines;
- }
- Element covdata = getCovDataChild( report.getDocumentElement() );
- covdata.setAttribute( "calls", String.valueOf( calls ) );
- covdata.setAttribute( "hit_methods", String.valueOf( hit_methods ) );
- covdata.setAttribute( "total_methods", String.valueOf( total_methods ) );
- covdata.setAttribute( "hit_lines", String.valueOf( hit_lines ) );
- covdata.setAttribute( "total_lines", String.valueOf( total_lines ) );
- }
-
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/bytecode/ClassFile.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/bytecode/ClassFile.java
deleted file mode 100644
index c40bd3bf0..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/bytecode/ClassFile.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka.bytecode;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import org.apache.tools.ant.taskdefs.optional.depend.constantpool.ClassCPInfo;
-import org.apache.tools.ant.taskdefs.optional.depend.constantpool.ConstantPool;
-import org.apache.tools.ant.taskdefs.optional.depend.constantpool.Utf8CPInfo;
-import org.apache.tools.todo.taskdefs.sitraka.bytecode.attributes.AttributeInfo;
-
-/**
- * Object representing a class. Information are kept to the strict minimum for
- * JProbe reports so that not too many objects are created for a class,
- * otherwise the JVM can quickly run out of memory when analyzing a great deal
- * of classes and keeping them in memory for global analysis.
- *
- * @author Stephane Bailliez
- */
-public final class ClassFile
-{
-
- private int access_flags;
-
- private String fullname;
-
- private MethodInfo[] methods;
-
- private String sourceFile;
-
- public ClassFile( InputStream is )
- throws IOException
- {
- DataInputStream dis = new DataInputStream( is );
- ConstantPool constantPool = new ConstantPool();
-
- int magic = dis.readInt();// 0xCAFEBABE
- int minor = dis.readShort();
- int major = dis.readShort();
-
- constantPool.read( dis );
- constantPool.resolve();
-
- // class information
- access_flags = dis.readShort();
- int this_class = dis.readShort();
- fullname = ( (ClassCPInfo)constantPool.getEntry( this_class ) ).getClassName().replace( '/', '.' );
- int super_class = dis.readShort();
-
- // skip interfaces...
- int count = dis.readShort();
- dis.skipBytes( count * 2 );// short
-
- // skip fields...
- int numFields = dis.readShort();
- for( int i = 0; i < numFields; i++ )
- {
- // 3 short: access flags, name index, descriptor index
- dis.skip( 2 * 3 );
- // attribute list...
- int attributes_count = dis.readUnsignedShort();
- for( int j = 0; j < attributes_count; j++ )
- {
- dis.skipBytes( 2 );// skip attr_id (short)
- int len = dis.readInt();
- dis.skipBytes( len );
- }
- }
-
- // read methods
- int method_count = dis.readShort();
- methods = new MethodInfo[ method_count ];
- for( int i = 0; i < method_count; i++ )
- {
- methods[ i ] = new MethodInfo();
- methods[ i ].read( constantPool, dis );
- }
-
- // get interesting attributes.
- int attributes_count = dis.readUnsignedShort();
- for( int j = 0; j < attributes_count; j++ )
- {
- int attr_id = dis.readShort();
- int len = dis.readInt();
- String attr_name = Utils.getUTF8Value( constantPool, attr_id );
- if( AttributeInfo.SOURCE_FILE.equals( attr_name ) )
- {
- int name_index = dis.readShort();
- sourceFile = ( (Utf8CPInfo)constantPool.getEntry( name_index ) ).getValue();
- }
- else
- {
- dis.skipBytes( len );
- }
- }
- }
-
- public int getAccess()
- {
- return access_flags;
- }
-
- public String getFullName()
- {
- return fullname;
- }
-
- public MethodInfo[] getMethods()
- {
- return methods;
- }
-
- public String getName()
- {
- String name = getFullName();
- int pos = name.lastIndexOf( '.' );
- if( pos == -1 )
- {
- return "";
- }
- return name.substring( pos + 1 );
- }
-
- public String getPackage()
- {
- String name = getFullName();
- int pos = name.lastIndexOf( '.' );
- if( pos == -1 )
- {
- return "";
- }
- return name.substring( 0, pos );
- }
-
- public String getSourceFile()
- {
- return sourceFile;
- }
-
-}
-
-
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/bytecode/ClassPathLoader.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/bytecode/ClassPathLoader.java
deleted file mode 100644
index 8479fb677..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/bytecode/ClassPathLoader.java
+++ /dev/null
@@ -1,434 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka.bytecode;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-import java.util.StringTokenizer;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-
-/**
- * Core of the bytecode analyzer. It loads classes from a given classpath.
- *
- * @author Stephane Bailliez
- */
-public class ClassPathLoader
-{
-
- public final static FileLoader NULL_LOADER = new NullLoader();
-
- /**
- * the list of files to look for
- */
- protected File[] files;
-
- /**
- * create a new instance with a given classpath. It must be urls separated
- * by the platform specific path separator.
- *
- * @param classPath the classpath to load all the classes from.
- */
- public ClassPathLoader( String classPath )
- {
- StringTokenizer st = new StringTokenizer( classPath, File.pathSeparator );
- ArrayList entries = new ArrayList();
- while( st.hasMoreTokens() )
- {
- File file = new File( st.nextToken() );
- entries.add( file );
- }
- files = new File[ entries.size() ];
- entries.copyInto( files );
- }
-
- /**
- * create a new instance with a given set of urls.
- *
- * @param entries valid file urls (either .jar, .zip or directory)
- */
- public ClassPathLoader( String[] entries )
- {
- files = new File[ entries.length ];
- for( int i = 0; i < entries.length; i++ )
- {
- files[ i ] = new File( entries[ i ] );
- }
- }
-
- /**
- * create a new instance with a given set of urls
- *
- * @param entries file urls to look for classes (.jar, .zip or directory)
- */
- public ClassPathLoader( File[] entries )
- {
- files = entries;
- }
-
- /**
- * useful methods to read the whole input stream in memory so that it can be
- * accessed faster. Processing rt.jar and tools.jar from JDK 1.3.1 brings
- * time from 50s to 7s.
- *
- * @param is Description of Parameter
- * @return The CachedStream value
- * @exception IOException Description of Exception
- */
- public static InputStream getCachedStream( InputStream is )
- throws IOException
- {
- is = new BufferedInputStream( is );
- byte[] buffer = new byte[ 8192 ];
- ByteArrayOutputStream baos = new ByteArrayOutputStream( 2048 );
- int n;
- baos.reset();
- while( ( n = is.read( buffer, 0, buffer.length ) ) != -1 )
- {
- baos.write( buffer, 0, n );
- }
- is.close();
- return new ByteArrayInputStream( baos.toByteArray() );
- }
-
- /**
- * return the whole set of classes in the classpath. Note that this method
- * can be very resource demanding since it must load all bytecode from all
- * classes in all resources in the classpath at a time. To process it in a
- * less resource demanding way, it is maybe better to use the loaders()
- * that will return loader one by one.
- *
- * @return the hashtable containing ALL classes that are found in the given
- * classpath. Note that the first entry of a given classname will
- * shadow classes with the same name (as a classloader does)
- * @exception IOException Description of Exception
- */
- public Hashtable getClasses()
- throws IOException
- {
- Hashtable map = new Hashtable();
- Iterator enum = loaders();
- while( enum.hasNext() )
- {
- FileLoader loader = (FileLoader)enum.next();
- System.out.println( "Processing " + loader.getFile() );
- long t0 = System.currentTimeMillis();
- ClassFile[] classes = loader.getClasses();
- long dt = System.currentTimeMillis() - t0;
- System.out.println( "" + classes.length + " classes loaded in " + dt + "ms" );
- for( int j = 0; j < classes.length; j++ )
- {
- String name = classes[ j ].getFullName();
- // do not allow duplicates entries to preserve 'classpath' behavior
- // first class in wins
- if( !map.containsKey( name ) )
- {
- map.put( name, classes[ j ] );
- }
- }
- }
- return map;
- }
-
- /**
- * @return the set of FileLoader loaders matching the given
- * classpath.
- */
- public Iterator loaders()
- {
- return new LoaderIterator();
- }
-
- /**
- * the interface to implement to look up for specific resources
- *
- * @author RT
- */
- public interface FileLoader
- {
- /**
- * the file url that is looked for .class files
- *
- * @return The File value
- */
- public File getFile();
-
- /**
- * return the set of classes found in the file
- *
- * @return The Classes value
- * @exception IOException Description of Exception
- */
- public ClassFile[] getClasses()
- throws IOException;
- }
-
- /**
- * the loader enumeration that will return loaders
- *
- * @author RT
- */
- protected class LoaderIterator implements Iterator
- {
- protected int index = 0;
-
- public boolean hasNext()
- {
- return index < files.length;
- }
-
- public Object next()
- {
- if( index >= files.length )
- {
- throw new NoSuchElementException();
- }
- File file = files[ index++ ];
- if( !file.exists() )
- {
- return new NullLoader( file );
- }
- if( file.isDirectory() )
- {
- // it's a directory
- return new DirectoryLoader( file );
- }
- else if( file.getName().endsWith( ".zip" ) || file.getName().endsWith( ".jar" ) )
- {
- // it's a jar/zip file
- return new JarLoader( file );
- }
- return new NullLoader( file );
- }
- }
-}
-
-/**
- * a null loader to return when the file is not valid
- *
- * @author RT
- */
-class NullLoader implements ClassPathLoader.FileLoader
-{
-
- private File file;
-
- NullLoader()
- {
- this( null );
- }
-
- NullLoader( File file )
- {
- this.file = file;
- }
-
- public ClassFile[] getClasses()
- throws IOException
- {
- return new ClassFile[ 0 ];
- }
-
- public File getFile()
- {
- return file;
- }
-}
-
-/**
- * jar loader specified in looking for classes in jar and zip
- *
- * @author RT
- * @todo read the jar manifest in case there is a Class-Path entry.
- */
-class JarLoader implements ClassPathLoader.FileLoader
-{
-
- private File file;
-
- JarLoader( File file )
- {
- this.file = file;
- }
-
- public ClassFile[] getClasses()
- throws IOException
- {
- ZipFile zipFile = new ZipFile( file );
- ArrayList v = new ArrayList();
- Iterator entries = zipFile.entries();
- while( entries.hasNext() )
- {
- ZipEntry entry = (ZipEntry)entries.next();
- if( entry.getName().endsWith( ".class" ) )
- {
- InputStream is = ClassPathLoader.getCachedStream( zipFile.getInputStream( entry ) );
- ClassFile classFile = new ClassFile( is );
- is.close();
- v.add( classFile );
- }
- }
- ClassFile[] classes = new ClassFile[ v.size() ];
- v.copyInto( classes );
- return classes;
- }
-
- public File getFile()
- {
- return file;
- }
-}
-
-/**
- * directory loader that will look all classes recursively
- *
- * @author RT
- * @todo should discard classes which package name does not match the directory
- * ?
- */
-class DirectoryLoader implements ClassPathLoader.FileLoader
-{
-
- private File directory;
-
- DirectoryLoader( File dir )
- {
- directory = dir;
- }
-
- /**
- * List files that obeys to a specific filter recursively from a given base
- * directory.
- *
- * @param directory the directory where to list the files from.
- * @param filter the file filter to apply
- * @param recurse tells whether or not the listing is recursive.
- * @return the list of File objects that applies to the given
- * filter.
- */
- public static ArrayList listFiles( File directory, FilenameFilter filter, boolean recurse )
- {
- if( !directory.isDirectory() )
- {
- throw new IllegalArgumentException( directory + " is not a directory" );
- }
- ArrayList list = new ArrayList();
- listFilesTo( list, directory, filter, recurse );
- return list;
- }
-
- /**
- * List and add files to a given list. As a convenience it sends back the
- * instance of the list given as a parameter.
- *
- * @param list the list of files where the filtered files should be added
- * @param directory the directory where to list the files from.
- * @param filter the file filter to apply
- * @param recurse tells whether or not the listing is recursive.
- * @return the list instance that was passed as the list argument.
- */
- private static ArrayList listFilesTo( ArrayList list, File directory, FilenameFilter filter, boolean recurse )
- {
- String[] files = directory.list( filter );
- for( int i = 0; i < files.length; i++ )
- {
- list.add( new File( directory, files[ i ] ) );
- }
- files = null;// we don't need it anymore
- if( recurse )
- {
- String[] subdirs = directory.list( new DirectoryFilter() );
- for( int i = 0; i < subdirs.length; i++ )
- {
- listFilesTo( list, new File( directory, subdirs[ i ] ), filter, recurse );
- }
- }
- return list;
- }
-
- public ClassFile[] getClasses()
- throws IOException
- {
- ArrayList v = new ArrayList();
- ArrayList files = listFiles( directory, new ClassFilter(), true );
- for( int i = 0; i < files.size(); i++ )
- {
- File file = (File)files.get( i );
- InputStream is = null;
- try
- {
- is = ClassPathLoader.getCachedStream( new FileInputStream( file ) );
- ClassFile classFile = new ClassFile( is );
- is.close();
- is = null;
- v.add( classFile );
- }
- finally
- {
- if( is != null )
- {
- try
- {
- is.close();
- }
- catch( IOException ignored )
- {
- }
- }
- }
- }
- ClassFile[] classes = new ClassFile[ v.size() ];
- v.copyInto( classes );
- return classes;
- }
-
- public File getFile()
- {
- return directory;
- }
-
-}
-
-/**
- * Convenient filter that accepts only directory File
- *
- * @author RT
- */
-class DirectoryFilter implements FilenameFilter
-{
-
- public boolean accept( File directory, String name )
- {
- File pathname = new File( directory, name );
- return pathname.isDirectory();
- }
-}
-
-/**
- * convenient filter to accept only .class files
- *
- * @author RT
- */
-class ClassFilter implements FilenameFilter
-{
-
- public boolean accept( File dir, String name )
- {
- return name.endsWith( ".class" );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/bytecode/MethodInfo.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/bytecode/MethodInfo.java
deleted file mode 100644
index c6109d2f4..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/bytecode/MethodInfo.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka.bytecode;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import org.apache.tools.ant.taskdefs.optional.depend.constantpool.ConstantPool;
-import org.apache.tools.todo.taskdefs.sitraka.bytecode.attributes.AttributeInfo;
-
-/**
- * Method info structure.
- *
- * @author Stephane Bailliez
- * @todo give a more appropriate name to methods.
- */
-public final class MethodInfo
-{
- private int loc = -1;
- private int access_flags;
- private String descriptor;
- private String name;
-
- public MethodInfo()
- {
- }
-
- public String getAccess()
- {
- return Utils.getMethodAccess( access_flags );
- }
-
- public int getAccessFlags()
- {
- return access_flags;
- }
-
- public String getDescriptor()
- {
- return descriptor;
- }
-
- public String getFullSignature()
- {
- return getReturnType() + " " + getShortSignature();
- }
-
- public String getName()
- {
- return name;
- }
-
- public int getNumberOfLines()
- {
- return loc;
- }
-
- public String[] getParametersType()
- {
- return Utils.getMethodParams( getDescriptor() );
- }
-
- public String getReturnType()
- {
- return Utils.getMethodReturnType( getDescriptor() );
- }
-
- public String getShortSignature()
- {
- StringBuffer buf = new StringBuffer( getName() );
- buf.append( "(" );
- String[] params = getParametersType();
- for( int i = 0; i < params.length; i++ )
- {
- buf.append( params[ i ] );
- if( i != params.length - 1 )
- {
- buf.append( ", " );
- }
- }
- buf.append( ")" );
- return buf.toString();
- }
-
- public void read( ConstantPool constantPool, DataInputStream dis )
- throws IOException
- {
- access_flags = dis.readShort();
-
- int name_index = dis.readShort();
- name = Utils.getUTF8Value( constantPool, name_index );
-
- int descriptor_index = dis.readShort();
- descriptor = Utils.getUTF8Value( constantPool, descriptor_index );
-
- int attributes_count = dis.readUnsignedShort();
- for( int i = 0; i < attributes_count; i++ )
- {
- int attr_id = dis.readShort();
- String attr_name = Utils.getUTF8Value( constantPool, attr_id );
- int len = dis.readInt();
- if( AttributeInfo.CODE.equals( attr_name ) )
- {
- readCode( constantPool, dis );
- }
- else
- {
- dis.skipBytes( len );
- }
- }
-
- }
-
- public String toString()
- {
- StringBuffer sb = new StringBuffer();
- sb.append( "Method: " ).append( getAccess() ).append( " " );
- sb.append( getFullSignature() );
- return sb.toString();
- }
-
- protected void readCode( ConstantPool constantPool, DataInputStream dis )
- throws IOException
- {
- // skip max_stack (short), max_local (short)
- dis.skipBytes( 2 * 2 );
-
- // skip bytecode...
- int bytecode_len = dis.readInt();
- dis.skip( bytecode_len );
-
- // skip exceptions... 1 exception = 4 short.
- int exception_count = dis.readShort();
- dis.skipBytes( exception_count * 4 * 2 );
-
- // read attributes...
- int attributes_count = dis.readUnsignedShort();
- for( int i = 0; i < attributes_count; i++ )
- {
- int attr_id = dis.readShort();
- String attr_name = Utils.getUTF8Value( constantPool, attr_id );
- int len = dis.readInt();
- if( AttributeInfo.LINE_NUMBER_TABLE.equals( attr_name ) )
- {
- // we're only interested in lines of code...
- loc = dis.readShort();
- // skip the table which is 2*loc*short
- dis.skip( loc * 2 * 2 );
- }
- else
- {
- dis.skipBytes( len );
- }
- }
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/bytecode/Utils.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/bytecode/Utils.java
deleted file mode 100644
index dc5cd460a..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/bytecode/Utils.java
+++ /dev/null
@@ -1,489 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka.bytecode;
-
-import java.util.ArrayList;
-import org.apache.tools.ant.taskdefs.optional.depend.constantpool.ConstantPool;
-import org.apache.tools.ant.taskdefs.optional.depend.constantpool.Utf8CPInfo;
-
-/**
- * Utilities mostly to manipulate methods and access flags.
- *
- * @author Stephane Bailliez
- */
-public class Utils
-{
- /**
- * public access flag
- */
- public final static short ACC_PUBLIC = 1;
- /**
- * private access flag
- */
- public final static short ACC_PRIVATE = 2;
- /**
- * protected access flag
- */
- public final static short ACC_PROTECTED = 4;
- /**
- * static access flag
- */
- public final static short ACC_STATIC = 8;
- /**
- * final access flag
- */
- public final static short ACC_FINAL = 16;
- /**
- * super access flag
- */
- public final static short ACC_SUPER = 32;
- /**
- * synchronized access flag
- */
- public final static short ACC_SYNCHRONIZED = 32;
- /**
- * volatile access flag
- */
- public final static short ACC_VOLATILE = 64;
- /**
- * transient access flag
- */
- public final static short ACC_TRANSIENT = 128;
- /**
- * native access flag
- */
- public final static short ACC_NATIVE = 256;
- /**
- * interface access flag
- */
- public final static short ACC_INTERFACE = 512;
- /**
- * abstract access flag
- */
- public final static short ACC_ABSTRACT = 1024;
- /**
- * strict access flag
- */
- public final static short ACC_STRICT = 2048;
-
- /**
- * private constructor
- */
- private Utils()
- {
- }
-
- /**
- * return the class access flag as java modifiers
- *
- * @param access_flags access flags
- * @return the access flags as modifier strings
- */
- public static String getClassAccess( int access_flags )
- {
- StringBuffer sb = new StringBuffer();
- if( isPublic( access_flags ) )
- {
- sb.append( "public " );
- }
- else if( isProtected( access_flags ) )
- {
- sb.append( "protected " );
- }
- else if( isPrivate( access_flags ) )
- {
- sb.append( "private " );
- }
- if( isFinal( access_flags ) )
- {
- sb.append( "final " );
- }
- if( isSuper( access_flags ) )
- {
- sb.append( "/*super*/ " );
- }
- if( isInterface( access_flags ) )
- {
- sb.append( "interface " );
- }
- if( isAbstract( access_flags ) )
- {
- sb.append( "abstract " );
- }
- if( isClass( access_flags ) )
- {
- sb.append( "class " );
- }
- return sb.toString().trim();
- }
-
- /**
- * return the field access flag as java modifiers
- *
- * @param access_flags access flags
- * @return the access flags as modifier strings
- */
- public static String getFieldAccess( int access_flags )
- {
- StringBuffer sb = new StringBuffer();
- if( isPublic( access_flags ) )
- {
- sb.append( "public " );
- }
- else if( isPrivate( access_flags ) )
- {
- sb.append( "private " );
- }
- else if( isProtected( access_flags ) )
- {
- sb.append( "protected " );
- }
- if( isFinal( access_flags ) )
- {
- sb.append( "final " );
- }
- if( isStatic( access_flags ) )
- {
- sb.append( "static " );
- }
- if( isVolatile( access_flags ) )
- {
- sb.append( "volatile " );
- }
- if( isTransient( access_flags ) )
- {
- sb.append( "transient " );
- }
- return sb.toString().trim();
- }
-
- /**
- * return the method access flag as java modifiers
- *
- * @param access_flags access flags
- * @return the access flags as modifier strings
- */
- public static String getMethodAccess( int access_flags )
- {
- StringBuffer sb = new StringBuffer();
- if( isPublic( access_flags ) )
- {
- sb.append( "public " );
- }
- else if( isPrivate( access_flags ) )
- {
- sb.append( "private " );
- }
- else if( isProtected( access_flags ) )
- {
- sb.append( "protected " );
- }
- if( isFinal( access_flags ) )
- {
- sb.append( "final " );
- }
- if( isStatic( access_flags ) )
- {
- sb.append( "static " );
- }
- if( isSynchronized( access_flags ) )
- {
- sb.append( "synchronized " );
- }
- if( isNative( access_flags ) )
- {
- sb.append( "native " );
- }
- if( isAbstract( access_flags ) )
- {
- sb.append( "abstract " );
- }
- return sb.toString().trim();
- }
-
- /**
- * parse all parameters from a descritor into fields of java name.
- *
- * @param descriptor of a method.
- * @return the parameter list of a given method descriptor. Each string
- * represent a java object with its fully qualified classname or the
- * primitive name such as int, long, ...
- */
- public static String[] getMethodParams( String descriptor )
- {
- int i = 0;
- if( descriptor.charAt( i ) != '(' )
- {
- throw new IllegalArgumentException( "Method descriptor should start with a '('" );
- }
- ArrayList params = new ArrayList();
- StringBuffer param = new StringBuffer();
- i++;
- while( ( i = descriptor2java( descriptor, i, param ) ) < descriptor.length() )
- {
- params.add( param.toString() );
- param.setLength( 0 );// reset
- if( descriptor.charAt( i ) == ')' )
- {
- i++;
- break;
- }
- }
- String[] array = new String[ params.size() ];
- params.copyInto( array );
- return array;
- }
-
- /**
- * return the object type of a return type.
- *
- * @param descriptor
- * @return get the return type objet of a given descriptor
- */
- public static String getMethodReturnType( String descriptor )
- {
- int pos = descriptor.indexOf( ')' );
- StringBuffer rettype = new StringBuffer();
- descriptor2java( descriptor, pos + 1, rettype );
- return rettype.toString();
- }
-
- /**
- * return an UTF8 value from the pool located a a specific index.
- *
- * @param pool the constant pool to look at
- * @param index index of the UTF8 value in the constant pool
- * @return the value of the string if it exists
- * @throws ClassCastException if the index is not an UTF8 constant.
- */
- public static String getUTF8Value( ConstantPool pool, int index )
- {
- return ( (Utf8CPInfo)pool.getEntry( index ) ).getValue();
- }
-
- /**
- * check for abstract access
- *
- * @param access_flags access flags
- * @return The Abstract value
- */
- public static boolean isAbstract( int access_flags )
- {
- return ( access_flags & ACC_ABSTRACT ) != 0;
- }
-
- /**
- * check for class access
- *
- * @param access_flags access flags
- * @return The Class value
- */
- public static boolean isClass( int access_flags )
- {
- return !isInterface( access_flags );
- }
-
- /**
- * chck for final flag
- *
- * @param access_flags access flags
- * @return The Final value
- */
- public static boolean isFinal( int access_flags )
- {
- return ( access_flags & ACC_FINAL ) != 0;
- }
-
- /**
- * check for interface access
- *
- * @param access_flags access flags
- * @return The Interface value
- */
- public static boolean isInterface( int access_flags )
- {
- return ( access_flags & ACC_INTERFACE ) != 0;
- }
-
- /**
- * check for native access
- *
- * @param access_flags access flags
- * @return The Native value
- */
- public static boolean isNative( int access_flags )
- {
- return ( access_flags & ACC_NATIVE ) != 0;
- }
-
- /**
- * check for private access
- *
- * @param access_flags access flags
- * @return The Private value
- */
- public static boolean isPrivate( int access_flags )
- {
- return ( access_flags & ACC_PRIVATE ) != 0;
- }
-
- /**
- * check for protected flag
- *
- * @param access_flags access flags
- * @return The Protected value
- */
- public static boolean isProtected( int access_flags )
- {
- return ( access_flags & ACC_PROTECTED ) != 0;
- }
-
- /**
- * check for public access
- *
- * @param access_flags access flags
- * @return The Public value
- */
- public static boolean isPublic( int access_flags )
- {
- return ( access_flags & ACC_PUBLIC ) != 0;
- }
-
- /**
- * check for a static access
- *
- * @param access_flags access flags
- * @return The Static value
- */
- public static boolean isStatic( int access_flags )
- {
- return ( access_flags & ACC_STATIC ) != 0;
- }
-
- /**
- * check for strict access
- *
- * @param access_flags access flags
- * @return The Strict value
- */
- public static boolean isStrict( int access_flags )
- {
- return ( access_flags & ACC_STRICT ) != 0;
- }
-
- /**
- * check for super flag
- *
- * @param access_flags access flag
- * @return The Super value
- */
- public static boolean isSuper( int access_flags )
- {
- return ( access_flags & ACC_SUPER ) != 0;
- }
-
- /**
- * check for synchronized flag
- *
- * @param access_flags access flags
- * @return The Synchronized value
- */
- public static boolean isSynchronized( int access_flags )
- {
- return ( access_flags & ACC_SYNCHRONIZED ) != 0;
- }
-
- /**
- * check for transient flag
- *
- * @param access_flags access flags
- * @return The Transient value
- */
- public static boolean isTransient( int access_flags )
- {
- return ( access_flags & ACC_TRANSIENT ) != 0;
- }
-
- /**
- * check for volatile flag
- *
- * @param access_flags access flags
- * @return The Volatile value
- */
- public static boolean isVolatile( int access_flags )
- {
- return ( access_flags & ACC_VOLATILE ) != 0;
- }
-
- /**
- * Parse a single descriptor symbol and returns it java equivalent.
- *
- * @param descriptor the descriptor symbol.
- * @param i the index to look at the symbol in the descriptor string
- * @param sb the stringbuffer to return the java equivalent of the symbol
- * @return the index after the descriptor symbol
- */
- public static int descriptor2java( String descriptor, int i, StringBuffer sb )
- {
- // get the dimension
- StringBuffer dim = new StringBuffer();
- for( ; descriptor.charAt( i ) == '['; i++ )
- {
- dim.append( "[]" );
- }
- // now get the type
- switch( descriptor.charAt( i ) )
- {
- case 'B':
- sb.append( "byte" );
- break;
- case 'C':
- sb.append( "char" );
- break;
- case 'D':
- sb.append( "double" );
- break;
- case 'F':
- sb.append( "float" );
- break;
- case 'I':
- sb.append( "int" );
- break;
- case 'J':
- sb.append( "long" );
- break;
- case 'S':
- sb.append( "short" );
- break;
- case 'Z':
- sb.append( "boolean" );
- break;
- case 'V':
- sb.append( "void" );
- break;
- case 'L':
- // it is a class
- int pos = descriptor.indexOf( ';', i + 1 );
- String classname = descriptor.substring( i + 1, pos ).replace( '/', '.' );
- sb.append( classname );
- i = pos;
- break;
- default:
- //@todo, yeah this happens because I got things like:
- // ()Ljava/lang/Object; and it will return and ) will be here
- // think about it.
-
- //ooooops should never happen
- //throw new IllegalArgumentException("Invalid descriptor symbol: '" + i + "' in '" + descriptor + "'");
- }
- sb.append( dim.toString() );
- return ++i;
- }
-}
-
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/bytecode/attributes/AttributeInfo.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/bytecode/attributes/AttributeInfo.java
deleted file mode 100644
index 52ee74d67..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/sitraka/bytecode/attributes/AttributeInfo.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.sitraka.bytecode.attributes;
-
-/**
- * Attribute info structure that provides base methods
- *
- * @author Stephane Bailliez
- */
-public interface AttributeInfo
-{
-
- public final static String SOURCE_FILE = "SourceFile";
-
- public final static String CONSTANT_VALUE = "ConstantValue";
-
- public final static String CODE = "Code";
-
- public final static String EXCEPTIONS = "Exceptions";
-
- public final static String LINE_NUMBER_TABLE = "LineNumberTable";
-
- public final static String LOCAL_VARIABLE_TABLE = "LocalVariableTable";
-
- public final static String INNER_CLASSES = "InnerClasses";
-
- public final static String SOURCE_DIR = "SourceDir";
-
- public final static String SYNTHETIC = "Synthetic";
-
- public final static String DEPRECATED = "Deprecated";
-
- public final static String UNKNOWN = "Unknown";
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/stylebook/StyleBook.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/stylebook/StyleBook.java
deleted file mode 100644
index f8d0a8d71..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/stylebook/StyleBook.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.stylebook;
-
-import java.io.File;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.taskdefs.Java;
-import org.apache.tools.todo.types.Argument;
-
-/**
- * Basic task for apache stylebook.
- *
- * @author Peter Donald
- * @author Marcus
- * Börger
- */
-public class StyleBook
- extends Java
-{
- private File m_book;
- private String m_loaderConfig;
- private File m_skinDirectory;
- private File m_targetDirectory;
-
- public StyleBook()
- {
- setClassname( "org.apache.stylebook.StyleBook" );
- setFork( true );
- }
-
- public void setBook( final File book )
- {
- m_book = book;
- }
-
- public void setLoaderConfig( final String loaderConfig )
- {
- m_loaderConfig = loaderConfig;
- }
-
- public void setSkinDirectory( final File skinDirectory )
- {
- m_skinDirectory = skinDirectory;
- }
-
- public void setTargetDirectory( final File targetDirectory )
- {
- m_targetDirectory = targetDirectory;
- }
-
- public void execute()
- throws TaskException
- {
- validate();
-
- addArg( new Argument( "targetDirectory=" + m_targetDirectory ) );
- addArg( new Argument( m_book.toString() ) );
- addArg( new Argument( m_skinDirectory.toString() ) );
- if( null != m_loaderConfig )
- {
- addArg( new Argument( "loaderConfig=" + m_loaderConfig ) );
- }
-
- super.execute();
- }
-
- private void validate() throws TaskException
- {
- if( null == m_targetDirectory )
- {
- throw new TaskException( "TargetDirectory attribute not set." );
- }
-
- if( null == m_skinDirectory )
- {
- throw new TaskException( "SkinDirectory attribute not set." );
- }
-
- if( null == m_book )
- {
- throw new TaskException( "book attribute not set." );
- }
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/AddAsisRemove.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/AddAsisRemove.java
deleted file mode 100644
index 82937c9c5..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/AddAsisRemove.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.text;
-
-import org.apache.tools.todo.types.EnumeratedAttribute;
-
-/**
- * Enumerated attribute with the values "asis", "add" and "remove".
- */
-public class AddAsisRemove
- extends EnumeratedAttribute
-{
- public String[] getValues()
- {
- return new String[]{"add", "asis", "remove"};
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/CrLf.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/CrLf.java
deleted file mode 100644
index 221874a3d..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/CrLf.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.text;
-
-import org.apache.tools.todo.types.EnumeratedAttribute;
-
-/**
- * Enumerated attribute with the values "asis", "cr", "lf" and "crlf".
- */
-public class CrLf
- extends EnumeratedAttribute
-{
- public String[] getValues()
- {
- return new String[]{"asis", "cr", "lf", "crlf"};
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/FixCRLF.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/FixCRLF.java
deleted file mode 100644
index 5266db92c..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/FixCRLF.java
+++ /dev/null
@@ -1,1109 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.text;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-import org.apache.aut.nativelib.Os;
-import org.apache.avalon.excalibur.io.FileUtil;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.taskdefs.MatchingTask;
-import org.apache.tools.todo.taskdefs.text.AddAsisRemove;
-import org.apache.tools.todo.taskdefs.text.CrLf;
-import org.apache.tools.todo.types.DirectoryScanner;
-
-/**
- * Task to convert text source files to local OS formatting conventions, as well
- * as repair text files damaged by misconfigured or misguided editors or file
- * transfer programs.
- *
- * This task can take the following arguments:
- *
- * srcdir
- * destdir
- * include
- * exclude
- * cr
- * eol
- * tab
- * eof
- * encoding
- *
- * Of these arguments, only sourcedir is required.
- *
- * When this task executes, it will scan the srcdir based on the include and
- * exclude properties.
- *
- * This version generalises the handling of EOL characters, and allows for
- * CR-only line endings (which I suspect is the standard on Macs.) Tab handling
- * has also been generalised to accommodate any tabwidth from 2 to 80,
- * inclusive. Importantly, it will leave untouched any literal TAB characters
- * embedded within string or character constants.
- *
- * Warning: do not run on binary files. Caution: run with care
- * on carefully formatted files. This may sound obvious, but if you don't
- * specify asis, presume that your files are going to be modified. If "tabs" is
- * "add" or "remove", whitespace characters may be added or removed as
- * necessary. Similarly, for CR's - in fact "eol"="crlf" or cr="add" can result
- * in cr characters being removed in one special case accommodated, i.e., CRCRLF
- * is regarded as a single EOL to handle cases where other programs have
- * converted CRLF into CRCRLF.
- *
- * @author Sam Ruby rubys@us.ibm.com
- * @author Peter B. West
- * @version $Revision$ $Name$
- */
-public class FixCRLF
- extends MatchingTask
-{
- private final static int UNDEF = -1;
- private final static int NOTJAVA = 0;
- private final static int LOOKING = 1;
- private final static int IN_CHAR_CONST = 2;
- private final static int IN_STR_CONST = 3;
- private final static int IN_SINGLE_COMMENT = 4;
- private final static int IN_MULTI_COMMENT = 5;
-
- private final static int ASIS = 0;
- private final static int CR = 1;
- private final static int LF = 2;
- private final static int CRLF = 3;
- private final static int ADD = 1;
- private final static int REMOVE = -1;
- private final static int SPACES = -1;
- private final static int TABS = 1;
-
- private final static int INBUFLEN = 8192;
- private final static int LINEBUFLEN = 200;
-
- private final static char CTRLZ = '\u001A';
-
- private int tablength = 8;
- private String spaces = " ";
- private StringBuffer linebuf = new StringBuffer( 1024 );
- private StringBuffer linebuf2 = new StringBuffer( 1024 );
- private boolean javafiles = false;
- private File destDir = null;
-
- /**
- * Encoding to assume for the files
- */
- private String encoding = null;
- private int ctrlz;
- private int eol;
- private String eolstr;
-
- private File srcDir;
- private int tabs;
-
- /**
- * Defaults the properties based on the system type.
- *
- * Unix: eol="LF" tab="asis" eof="remove"
- * Mac: eol="CR" tab="asis" eof="remove"
- * DOS: eol="CRLF" tab="asis" eof="asis"
- *
- *
- */
- public FixCRLF()
- {
- tabs = ASIS;
- if( Os.isFamily( Os.OS_FAMILY_WINDOWS) )
- {
- ctrlz = ASIS;
- eol = CRLF;
- eolstr = "\r\n";
- }
- else if( Os.isFamily( Os.OS_FAMILY_MAC ) )
- {
- ctrlz = REMOVE;
- eol = CR;
- eolstr = "\r";
- }
- else
- {
- ctrlz = REMOVE;
- eol = LF;
- eolstr = "\n";
- }
- }
-
- /**
- * Set the destination where the fixed files should be placed. Default is to
- * replace the original file.
- *
- * @param destDir The new Destdir value
- */
- public void setDestdir( File destDir )
- {
- this.destDir = destDir;
- }
-
- /**
- * Specifies the encoding Ant expects the files to be in - defaults to the
- * platforms default encoding.
- *
- * @param encoding The new Encoding value
- */
- public void setEncoding( String encoding )
- {
- this.encoding = encoding;
- }
-
- /**
- * Specify how DOS EOF (control-z) charaters are to be handled
- *
- * @param attr The new Eof value
- */
- public void setEof( AddAsisRemove attr )
- {
- String option = attr.getValue();
- if( option.equals( "remove" ) )
- {
- ctrlz = REMOVE;
- }
- else if( option.equals( "asis" ) )
- {
- ctrlz = ASIS;
- }
- else
- {
- // must be "add"
- ctrlz = ADD;
- }
- }
-
- /**
- * Specify how EndOfLine characters are to be handled
- *
- * @param attr The new Eol value
- */
- public void setEol( CrLf attr )
- {
- String option = attr.getValue();
- if( option.equals( "asis" ) )
- {
- eol = ASIS;
- }
- else if( option.equals( "cr" ) )
- {
- eol = CR;
- eolstr = "\r";
- }
- else if( option.equals( "lf" ) )
- {
- eol = LF;
- eolstr = "\n";
- }
- else
- {
- // Must be "crlf"
- eol = CRLF;
- eolstr = "\r\n";
- }
- }
-
- /**
- * Fixing Java source files?
- *
- * @param javafiles The new Javafiles value
- */
- public void setJavafiles( boolean javafiles )
- {
- this.javafiles = javafiles;
- }
-
- /**
- * Set the source dir to find the source text files.
- *
- * @param srcDir The new Srcdir value
- */
- public void setSrcdir( File srcDir )
- {
- this.srcDir = srcDir;
- }
-
- /**
- * Specify how tab characters are to be handled
- *
- * @param attr The new Tab value
- */
- public void setTab( AddAsisRemove attr )
- {
- String option = attr.getValue();
- if( option.equals( "remove" ) )
- {
- tabs = SPACES;
- }
- else if( option.equals( "asis" ) )
- {
- tabs = ASIS;
- }
- else
- {
- // must be "add"
- tabs = TABS;
- }
- }
-
- /**
- * Specify tab length in characters
- *
- * @param tlength specify the length of tab in spaces,
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public void setTablength( int tlength )
- throws TaskException
- {
- if( tlength < 2 || tlength > 80 )
- {
- throw new TaskException( "tablength must be between 2 and 80" );
- }
- tablength = tlength;
- StringBuffer sp = new StringBuffer();
- for( int i = 0; i < tablength; i++ )
- {
- sp.append( ' ' );
- }
- spaces = sp.toString();
- }
-
- /**
- * Executes the task.
- *
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- // first off, make sure that we've got a srcdir and destdir
-
- if( srcDir == null )
- {
- throw new TaskException( "srcdir attribute must be set!" );
- }
- if( !srcDir.exists() )
- {
- throw new TaskException( "srcdir does not exist!" );
- }
- if( !srcDir.isDirectory() )
- {
- throw new TaskException( "srcdir is not a directory!" );
- }
- if( destDir != null )
- {
- if( !destDir.exists() )
- {
- throw new TaskException( "destdir does not exist!" );
- }
- if( !destDir.isDirectory() )
- {
- throw new TaskException( "destdir is not a directory!" );
- }
- }
-
- // log options used
- getContext().debug( "options:" +
- " eol=" +
- ( eol == ASIS ? "asis" : eol == CR ? "cr" : eol == LF ? "lf" : "crlf" ) +
- " tab=" + ( tabs == TABS ? "add" : tabs == ASIS ? "asis" : "remove" ) +
- " eof=" + ( ctrlz == ADD ? "add" : ctrlz == ASIS ? "asis" : "remove" ) +
- " tablength=" + tablength +
- " encoding=" + ( encoding == null ? "default" : encoding ) );
-
- DirectoryScanner ds = super.getDirectoryScanner( srcDir );
- String[] files = ds.getIncludedFiles();
-
- for( int i = 0; i < files.length; i++ )
- {
- processFile( files[ i ] );
- }
- }
-
- /**
- * Creates a Reader reading from a given file an taking the user defined
- * encoding into account.
- *
- * @param f Description of Parameter
- * @return The Reader value
- * @exception java.io.IOException Description of Exception
- */
- private Reader getReader( File f )
- throws IOException
- {
- return ( encoding == null ) ? new FileReader( f )
- : new InputStreamReader( new FileInputStream( f ), encoding );
- }
-
- /**
- * Scan a BufferLine forward from the 'next' pointer for the end of a
- * character constant. Set 'lookahead' pointer to the character following
- * the terminating quote.
- *
- * @param bufline Description of Parameter
- * @param terminator Description of Parameter
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- private void endOfCharConst( OneLiner.BufferLine bufline, char terminator )
- throws TaskException
- {
- int ptr = bufline.getNext();
- int eol = bufline.length();
- char c;
- ptr++;// skip past initial quote
- while( ptr < eol )
- {
- if( ( c = bufline.getChar( ptr++ ) ) == '\\' )
- {
- ptr++;
- }
- else
- {
- if( c == terminator )
- {
- bufline.setLookahead( ptr );
- return;
- }
- }
- }// end of while (ptr < eol)
- // Must have fallen through to the end of the line
- throw new TaskException( "endOfCharConst: unterminated char constant" );
- }
-
- /**
- * Scan a BufferLine for the next state changing token: the beginning of a
- * single or multi-line comment, a character or a string constant. As a
- * side-effect, sets the buffer state to the next state, and sets field
- * lookahead to the first character of the state-changing token, or to the
- * next eol character.
- *
- * @param bufline Description of Parameter
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- private void nextStateChange( OneLiner.BufferLine bufline )
- throws TaskException
- {
- int eol = bufline.length();
- int ptr = bufline.getNext();
-
- // Look for next single or double quote, double slash or slash star
- while( ptr < eol )
- {
- switch( bufline.getChar( ptr++ ) )
- {
- case '\'':
- bufline.setState( IN_CHAR_CONST );
- bufline.setLookahead( --ptr );
- return;
- case '\"':
- bufline.setState( IN_STR_CONST );
- bufline.setLookahead( --ptr );
- return;
- case '/':
- if( ptr < eol )
- {
- if( bufline.getChar( ptr ) == '*' )
- {
- bufline.setState( IN_MULTI_COMMENT );
- bufline.setLookahead( --ptr );
- return;
- }
- else if( bufline.getChar( ptr ) == '/' )
- {
- bufline.setState( IN_SINGLE_COMMENT );
- bufline.setLookahead( --ptr );
- return;
- }
- }
- break;
- }// end of switch (bufline.getChar(ptr++))
-
- }// end of while (ptr < eol)
- // Eol is the next token
- bufline.setLookahead( ptr );
- }
-
- /**
- * Process a BufferLine string which is not part of of a string constant.
- * The start position of the string is given by the 'next' field. Sets the
- * 'next' and 'column' fields in the BufferLine.
- *
- * @param bufline Description of Parameter
- * @param end Description of Parameter
- * @param outWriter Description of Parameter
- */
- private void notInConstant( OneLiner.BufferLine bufline, int end,
- BufferedWriter outWriter )
- throws TaskException
- {
- // N.B. both column and string index are zero-based
- // Process a string not part of a constant;
- // i.e. convert tabs<->spaces as required
- // This is NOT called for ASIS tab handling
- int nextTab;
- int nextStop;
- int tabspaces;
- String line = bufline.substring( bufline.getNext(), end );
- int place = 0;// Zero-based
- int col = bufline.getColumn();// Zero-based
-
- // process sequences of white space
- // first convert all tabs to spaces
- linebuf.setLength( 0 );
- while( ( nextTab = line.indexOf( (int)'\t', place ) ) >= 0 )
- {
- linebuf.append( line.substring( place, nextTab ) );// copy to the TAB
- col += nextTab - place;
- tabspaces = tablength - ( col % tablength );
- linebuf.append( spaces.substring( 0, tabspaces ) );
- col += tabspaces;
- place = nextTab + 1;
- }// end of while
- linebuf.append( line.substring( place, line.length() ) );
- // if converting to spaces, all finished
- String linestring = new String( linebuf.toString() );
- if( tabs == REMOVE )
- {
- try
- {
- outWriter.write( linestring );
- }
- catch( IOException e )
- {
- throw new TaskException( "Error", e );
- }// end of try-catch
- }
- else
- {// tabs == ADD
- int tabCol;
- linebuf2.setLength( 0 );
- place = 0;
- col = bufline.getColumn();
- int placediff = col - 0;
- // for the length of the string, cycle through the tab stop
- // positions, checking for a space preceded by at least one
- // other space at the tab stop. if so replace the longest possible
- // preceding sequence of spaces with a tab.
- nextStop = col + ( tablength - col % tablength );
- if( nextStop - col < 2 )
- {
- linebuf2.append( linestring.substring(
- place, nextStop - placediff ) );
- place = nextStop - placediff;
- nextStop += tablength;
- }
-
- for( ; nextStop - placediff <= linestring.length()
- ; nextStop += tablength )
- {
- for( tabCol = nextStop;
- --tabCol - placediff >= place
- && linestring.charAt( tabCol - placediff ) == ' '
- ; )
- {
- ;// Loop for the side-effects
- }
- // tabCol is column index of the last non-space character
- // before the next tab stop
- if( nextStop - tabCol > 2 )
- {
- linebuf2.append( linestring.substring(
- place, ++tabCol - placediff ) );
- linebuf2.append( '\t' );
- }
- else
- {
- linebuf2.append( linestring.substring(
- place, nextStop - placediff ) );
- }// end of else
-
- place = nextStop - placediff;
- }// end of for (nextStop ... )
-
- // pick up that last bit, if any
- linebuf2.append( linestring.substring( place, linestring.length() ) );
-
- try
- {
- outWriter.write( linebuf2.toString() );
- }
- catch( IOException e )
- {
- throw new TaskException( "Error", e );
- }// end of try-catch
-
- }// end of else tabs == ADD
-
- // Set column position as modified by this method
- bufline.setColumn( bufline.getColumn() + linestring.length() );
- bufline.setNext( end );
-
- }
-
- private void processFile( String file )
- throws TaskException
- {
- File srcFile = new File( srcDir, file );
- File destD = destDir == null ? srcDir : destDir;
- File tmpFile = null;
- BufferedWriter outWriter;
- OneLiner.BufferLine line;
-
- // read the contents of the file
- OneLiner lines = new OneLiner( srcFile );
-
- try
- {
- // Set up the output Writer
- try
- {
- tmpFile = File.createTempFile( "fixcrlf", "", destD );
- Writer writer = ( encoding == null ) ? new FileWriter( tmpFile )
- : new OutputStreamWriter( new FileOutputStream( tmpFile ), encoding );
- outWriter = new BufferedWriter( writer );
- }
- catch( IOException e )
- {
- throw new TaskException( "Error", e );
- }
-
- while( lines.hasNext() )
- {
- // In-line states
- int endComment;
-
- try
- {
- line = (OneLiner.BufferLine)lines.next();
- }
- catch( NoSuchElementException e )
- {
- throw new TaskException( "Error", e );
- }
-
- String lineString = line.getLineString();
- int linelen = line.length();
-
- // Note - all of the following processing NOT done for
- // tabs ASIS
-
- if( tabs == ASIS )
- {
- // Just copy the body of the line across
- try
- {
- outWriter.write( lineString );
- }
- catch( IOException e )
- {
- throw new TaskException( "Error", e );
- }// end of try-catch
-
- }
- else
- {// (tabs != ASIS)
- while( line.getNext() < linelen )
- {
-
- switch( lines.getState() )
- {
-
- case NOTJAVA:
- notInConstant( line, line.length(), outWriter );
- break;
- case IN_MULTI_COMMENT:
- if( ( endComment =
- lineString.indexOf( "*/", line.getNext() )
- ) >= 0 )
- {
- // End of multiLineComment on this line
- endComment += 2;// Include the end token
- lines.setState( LOOKING );
- }
- else
- {
- endComment = linelen;
- }
-
- notInConstant( line, endComment, outWriter );
- break;
- case IN_SINGLE_COMMENT:
- notInConstant( line, line.length(), outWriter );
- lines.setState( LOOKING );
- break;
- case IN_CHAR_CONST:
- case IN_STR_CONST:
- // Got here from LOOKING by finding an opening "\'"
- // next points to that quote character.
- // Find the end of the constant. Watch out for
- // backslashes. Literal tabs are left unchanged, and
- // the column is adjusted accordingly.
-
- int begin = line.getNext();
- char terminator = ( lines.getState() == IN_STR_CONST
- ? '\"'
- : '\'' );
- endOfCharConst( line, terminator );
- while( line.getNext() < line.getLookahead() )
- {
- if( line.getNextCharInc() == '\t' )
- {
- line.setColumn(
- line.getColumn() +
- tablength -
- line.getColumn() % tablength );
- }
- else
- {
- line.incColumn();
- }
- }
-
- // Now output the substring
- try
- {
- outWriter.write( line.substring( begin, line.getNext() ) );
- }
- catch( IOException e )
- {
- throw new TaskException( "Error", e );
- }
-
- lines.setState( LOOKING );
-
- break;
-
- case LOOKING:
- nextStateChange( line );
- notInConstant( line, line.getLookahead(), outWriter );
- break;
- }// end of switch (state)
-
- }// end of while (line.getNext() < linelen)
-
- }// end of else (tabs != ASIS)
-
- try
- {
- outWriter.write( eolstr );
- }
- catch( IOException e )
- {
- throw new TaskException( "Error", e );
- }// end of try-catch
-
- }// end of while (lines.hasNext())
-
- try
- {
- // Handle CTRLZ
- if( ctrlz == ASIS )
- {
- outWriter.write( lines.getEofStr() );
- }
- else if( ctrlz == ADD )
- {
- outWriter.write( CTRLZ );
- }
- }
- catch( IOException e )
- {
- throw new TaskException( "Error", e );
- }
- finally
- {
- try
- {
- outWriter.close();
- }
- catch( IOException e )
- {
- throw new TaskException( "Error", e );
- }
- }
-
- File destFile = new File( destD, file );
-
- try
- {
- lines.close();
- lines = null;
- }
- catch( IOException e )
- {
- throw new TaskException( "Unable to close source file " + srcFile );
- }
-
- if( destFile.exists() )
- {
- // Compare the destination with the temp file
- getContext().debug( "destFile exists" );
- boolean result = FileUtil.contentEquals( destFile, tmpFile );
- if( !result )
- {
- getContext().debug( destFile + " is being written" );
- if( !destFile.delete() )
- {
- throw new TaskException( "Unable to delete "
- + destFile );
- }
- if( !tmpFile.renameTo( destFile ) )
- {
- throw new TaskException(
- "Failed to transform " + srcFile
- + " to " + destFile
- + ". Couldn't rename temporary file: "
- + tmpFile );
- }
-
- }
- else
- {// destination is equal to temp file
- getContext().debug( destFile + " is not written, as the contents are identical" );
- if( !tmpFile.delete() )
- {
- throw new TaskException( "Unable to delete "
- + tmpFile );
- }
- }
- }
- else
- {// destFile does not exist - write the temp file
- ///XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- getContext().debug( "destFile does not exist" );
- if( !tmpFile.renameTo( destFile ) )
- {
- throw new TaskException(
- "Failed to transform " + srcFile
- + " to " + destFile
- + ". Couldn't rename temporary file: "
- + tmpFile );
- }
- }
-
- tmpFile = null;
-
- }
- catch( IOException e )
- {
- throw new TaskException( "Error", e );
- }
- finally
- {
- try
- {
- if( lines != null )
- {
- lines.close();
- }
- }
- catch( IOException io )
- {
- getContext().error( "Error closing " + srcFile );
- }// end of catch
-
- if( tmpFile != null )
- {
- tmpFile.delete();
- }
- }// end of finally
- }
-
- class OneLiner
- implements Iterator
- {
-
- private int state = javafiles ? LOOKING : NOTJAVA;
-
- private StringBuffer eolStr = new StringBuffer( LINEBUFLEN );
- private StringBuffer eofStr = new StringBuffer();
- private StringBuffer line = new StringBuffer();
- private boolean reachedEof = false;
-
- private BufferedReader reader;
-
- public OneLiner( File srcFile )
- throws TaskException
- {
- try
- {
- reader = new BufferedReader
- ( getReader( srcFile ), INBUFLEN );
- nextLine();
- }
- catch( IOException e )
- {
- throw new TaskException( "Error", e );
- }
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
-
- public void setState( int state )
- {
- this.state = state;
- }
-
- public String getEofStr()
- {
- return eofStr.toString();
- }
-
- public int getState()
- {
- return state;
- }
-
- public void close()
- throws IOException
- {
- if( reader != null )
- {
- reader.close();
- }
- }
-
- public boolean hasNext()
- {
- return !reachedEof;
- }
-
- public Object next()
- throws NoSuchElementException
- {
- if( !hasNext() )
- {
- throw new NoSuchElementException( "OneLiner" );
- }
-
- try
- {
- BufferLine tmpLine =
- new BufferLine( line.toString(), eolStr.toString() );
- nextLine();
- return tmpLine;
- }
- catch( TaskException e )
- {
- throw new NoSuchElementException();
- }
- }
-
- protected void nextLine()
- throws TaskException
- {
- int ch = -1;
- int eolcount = 0;
-
- eolStr.setLength( 0 );
- line.setLength( 0 );
-
- try
- {
- ch = reader.read();
- while( ch != -1 && ch != '\r' && ch != '\n' )
- {
- line.append( (char)ch );
- ch = reader.read();
- }
-
- if( ch == -1 && line.length() == 0 )
- {
- // Eof has been reached
- reachedEof = true;
- return;
- }
-
- switch( (char)ch )
- {
- case '\r':
- // Check for \r, \r\n and \r\r\n
- // Regard \r\r not followed by \n as two lines
- ++eolcount;
- eolStr.append( '\r' );
- switch( (char)( ch = reader.read() ) )
- {
- case '\r':
- if( (char)( ch = reader.read() ) == '\n' )
- {
- eolcount += 2;
- eolStr.append( "\r\n" );
- }
- break;
- case '\n':
- ++eolcount;
- eolStr.append( '\n' );
- break;
- }// end of switch ((char)(ch = reader.read()))
- break;
- case '\n':
- ++eolcount;
- eolStr.append( '\n' );
- break;
- }// end of switch ((char) ch)
-
- // if at eolcount == 0 and trailing characters of string
- // are CTRL-Zs, set eofStr
- if( eolcount == 0 )
- {
- int i = line.length();
- while( --i >= 0 && line.charAt( i ) == CTRLZ )
- {
- // keep searching for the first ^Z
- }
- if( i < line.length() - 1 )
- {
- // Trailing characters are ^Zs
- // Construct new line and eofStr
- eofStr.append( line.toString().substring( i + 1 ) );
- if( i < 0 )
- {
- line.setLength( 0 );
- reachedEof = true;
- }
- else
- {
- line.setLength( i + 1 );
- }
- }
-
- }// end of if (eolcount == 0)
-
- }
- catch( IOException e )
- {
- throw new TaskException( "Error", e );
- }
- }
-
- class BufferLine
- {
- private int next = 0;
- private int column = 0;
- private int lookahead = UNDEF;
- private String eolStr;
- private String line;
-
- public BufferLine( String line, String eolStr )
- throws TaskException
- {
- next = 0;
- column = 0;
- this.line = line;
- this.eolStr = eolStr;
- }
-
- public void setColumn( int col )
- {
- column = col;
- }
-
- public void setLookahead( int lookahead )
- {
- this.lookahead = lookahead;
- }
-
- public void setNext( int next )
- {
- this.next = next;
- }
-
- public void setState( int state )
- {
- OneLiner.this.setState( state );
- }
-
- public char getChar( int i )
- {
- return line.charAt( i );
- }
-
- public int getColumn()
- {
- return column;
- }
-
- public String getEol()
- {
- return eolStr;
- }
-
- public int getEolLength()
- {
- return eolStr.length();
- }
-
- public String getLineString()
- {
- return line;
- }
-
- public int getLookahead()
- {
- return lookahead;
- }
-
- public int getNext()
- {
- return next;
- }
-
- public char getNextChar()
- {
- return getChar( next );
- }
-
- public char getNextCharInc()
- {
- return getChar( next++ );
- }
-
- public int getState()
- {
- return OneLiner.this.getState();
- }
-
- public int incColumn()
- {
- return column++;
- }
-
- public int length()
- {
- return line.length();
- }
-
- public String substring( int begin )
- {
- return line.substring( begin );
- }
-
- public String substring( int begin, int end )
- {
- return line.substring( begin, end );
- }
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/Native2Ascii.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/Native2Ascii.java
deleted file mode 100644
index 6ed1ca1ae..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/Native2Ascii.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.text;
-
-import java.io.File;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.FileNameMapper;
-import org.apache.tools.todo.taskdefs.MatchingTask;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.SourceFileScanner;
-import org.apache.tools.todo.util.mappers.IdentityMapper;
-
-/**
- * Convert files from native encodings to ascii.
- *
- * @author Drew Sudell
- * @author Stefan Bodewig
- */
-public class Native2Ascii
- extends MatchingTask
-{
- private boolean m_reverse;// convert from ascii back to native
- private String m_encoding;// encoding to convert to/from
- private File m_srcDir;// Where to find input files
- private File m_destDir;// Where to put output files
- private FileNameMapper m_mapper;
-
- /**
- * Set the destination dirctory to place converted files into.
- *
- * @param destDir directory to place output file into.
- */
- public void setDest( final File destDir )
- {
- m_destDir = destDir;
- }
-
- /**
- * Set the encoding to translate to/from. If unset, the default encoding for
- * the JVM is used.
- *
- * @param encoding String containing the name of the Native encoding to
- * convert from or to.
- */
- public void setEncoding( final String encoding )
- {
- m_encoding = encoding;
- }
-
- /**
- * Flag the conversion to run in the reverse sense, that is Ascii to Native
- * encoding.
- *
- * @param reverse True if the conversion is to be reversed, otherwise false;
- */
- public void setReverse( boolean reverse )
- {
- m_reverse = reverse;
- }
-
- /**
- * Set the source directory in which to find files to convert.
- *
- * @param srcDir Direcrory to find input file in.
- */
- public void setSrc( final File srcDir )
- {
- m_srcDir = srcDir;
- }
-
- /**
- * Defines the FileNameMapper to use (nested mapper element).
- */
- public void createMapper( final FileNameMapper mapper )
- throws TaskException
- {
- if( m_mapper != null )
- {
- throw new TaskException( "Cannot define more than one mapper" );
- }
- m_mapper = mapper;
- }
-
- public void execute()
- throws TaskException
- {
- validate();
-
- final DirectoryScanner scanner = getDirectoryScanner( m_srcDir );
- String[] files = scanner.getIncludedFiles();
-
- final SourceFileScanner sfs = new SourceFileScanner();
- final FileNameMapper mapper = buildMapper();
- files = sfs.restrict( files, m_srcDir, m_destDir, mapper, getContext() );
- int count = files.length;
- if( count == 0 )
- {
- return;
- }
-
- final String message = "Converting " + count + " file" +
- ( count != 1 ? "s" : "" ) + " from " + m_srcDir + " to " +
- m_destDir;
- getContext().info( message );
-
- for( int i = 0; i < files.length; i++ )
- {
- final String name = mapper.mapFileName( files[ i ], getContext() )[ 0 ];
- convert( files[ i ], name );
- }
- }
-
- private FileNameMapper buildMapper()
- throws TaskException
- {
- FileNameMapper mapper = null;
- if( m_mapper == null )
- {
- mapper = new IdentityMapper();
- }
- else
- {
- mapper = m_mapper;
- }
-
- return mapper;
- }
-
- private void validate()
- throws TaskException
- {
- // Require destDir
- if( m_destDir == null )
- {
- throw new TaskException( "The dest attribute must be set." );
- }
-
- // if src and dest dirs are the same, require the extension
- // to be set, so we don't stomp every file. One could still
- // include a file with the same extension, but ....
- if( m_srcDir.equals( m_destDir ) && m_mapper == null )
- {
- throw new TaskException( "A mapper must be specified if" +
- " src and dest dirs are the same." );
- }
-
- // default srcDir to basedir
- if( m_srcDir == null )
- {
- m_srcDir = getBaseDirectory();
- }
- }
-
- /**
- * Convert a single file.
- *
- * @param srcName Description of Parameter
- * @param destName Description of Parameter
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- private void convert( String srcName, String destName )
- throws TaskException
- {
- // Build the full file names
- final File srcFile = new File( m_srcDir, srcName );
- final File destFile = new File( m_destDir, destName );
-
- // Make sure we're not about to clobber something
- if( srcFile.equals( destFile ) )
- {
- throw new TaskException( "file " + srcFile
- + " would overwrite its self" );
- }
-
- final Commandline cmd = buildCommand( srcFile, destFile );
-
- // Make intermediate directories if needed
- // XXX JDK 1.1 dosen't have File.getParentFile,
- final File parent = destFile.getParentFile();
- if( parent != null )
- {
- if( ( !parent.exists() ) && ( !parent.mkdirs() ) )
- {
- throw new TaskException( "cannot create parent directory " + parent );
- }
- }
-
- getContext().debug( "converting " + srcName );
- sun.tools.native2ascii.Main n2a = new sun.tools.native2ascii.Main();
- if( !n2a.convert( cmd.getArguments() ) )
- {
- throw new TaskException( "conversion failed" );
- }
- }
-
- private Commandline buildCommand( final File srcFile,
- final File destFile )
- {
- final Commandline cmd = new Commandline();// Command line to run
- // Set up the basic args (this could be done once, but
- // it's cleaner here)
- if( m_reverse )
- {
- cmd.addArgument( "-reverse" );
- }
-
- if( m_encoding != null )
- {
- cmd.addArgument( "-encoding" );
- cmd.addArgument( m_encoding );
- }
-
- cmd.addArgument( srcFile );
- cmd.addArgument( destFile );
- return cmd;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/NestedString.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/NestedString.java
deleted file mode 100644
index 32165ece9..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/NestedString.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.text;
-
-public class NestedString
-{
- private String m_text = "";
-
- public String getText()
- {
- return m_text;
- }
-
- public void addContent( final String text )
- {
- m_text = text;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/RegularExpression.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/RegularExpression.java
deleted file mode 100644
index 3b12fca26..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/RegularExpression.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.text;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.util.regexp.Regexp;
-import org.apache.tools.todo.util.regexp.RegexpFactory;
-
-/**
- * A regular expression datatype. Keeps an instance of the compiled expression
- * for speed purposes. This compiled expression is lazily evaluated (it is
- * compiled the first time it is needed). The syntax is the dependent on which
- * regular expression type you are using. The system property
- * "ant.regexp.regexpimpl" will be the classname of the implementation that will
- * be used.
- * For jdk <= 1.3, there are two available implementations:
- * org.apache.tools.ant.util.regexp.JakartaOroRegexp (the default)
- * Based on the jakarta-oro package
- *
- * org.apache.tools.ant.util.regexp.JakartaRegexpRegexp
- * Based on the jakarta-regexp package
- *
- * For jdk >= 1.4 an additional implementation is available:
- * org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp
- * Based on the jdk 1.4 built in regular expression package.
- *
- * <regularexpression [ [id="id"] pattern="expression" | refid="id" ]
- * />
- *
- *
- * @author Matthew Inger
- * mattinger@mindless.com
- * @see org.apache.oro.regex.Perl5Compiler
- * @see org.apache.regexp.RE
- * @see java.util.regex.Pattern
- * @see org.apache.tools.todo.util.regexp.Regexp
- */
-public class RegularExpression
-{
- // The regular expression factory
- private final static RegexpFactory factory = new RegexpFactory();
-
- private Regexp m_regexp;
-
- public RegularExpression()
- throws TaskException
- {
- m_regexp = factory.newRegexp();
- }
-
- public void setPattern( final String pattern )
- throws TaskException
- {
- m_regexp.setPattern( pattern );
- }
-
- /**
- * Gets the pattern string for this RegularExpression in the given project.
- */
- public String getPattern()
- throws TaskException
- {
- return m_regexp.getPattern();
- }
-
- public Regexp getRegexp()
- {
- return m_regexp;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/Replace.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/Replace.java
deleted file mode 100644
index 188602618..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/Replace.java
+++ /dev/null
@@ -1,473 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.text;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Properties;
-import org.apache.avalon.excalibur.io.IOUtil;
-import org.apache.avalon.excalibur.util.StringUtil;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.taskdefs.MatchingTask;
-import org.apache.tools.todo.taskdefs.text.NestedString;
-import org.apache.tools.todo.types.DirectoryScanner;
-
-/**
- * Replaces all occurrences of one or more string tokens with given values in
- * the indicated files. Each value can be either a string or the value of a
- * property available in a designated property file.
- *
- * @author Stefano Mazzocchi
- * stefano@apache.org
- * @author Erik Langenbach
- */
-public class Replace
- extends MatchingTask
-{
- private File m_src;
- private NestedString m_token;
- private NestedString m_value = new NestedString();
-
- private File m_propertyFile;
- private Properties m_properties;
- private ArrayList m_replacefilters = new ArrayList();
-
- private File m_dir;
- private boolean m_summary;
-
- /**
- * The encoding used to read and write files - if null, uses default
- */
- private String m_encoding;
-
- private int m_fileCount;
- private int m_replaceCount;
-
- /**
- * Set the source files path when using matching tasks.
- *
- * @param dir The new Dir value
- */
- public void setDir( File dir )
- {
- m_dir = dir;
- }
-
- /**
- * Set the file encoding to use on the files read and written by replace
- *
- * @param encoding the encoding to use on the files
- */
- public void setEncoding( String encoding )
- {
- m_encoding = encoding;
- }
-
- /**
- * Set the source file.
- *
- * @param file The new File value
- */
- public void setFile( File file )
- {
- m_src = file;
- }
-
- /**
- * Sets a file to be searched for property values.
- *
- * @param filename The new PropertyFile value
- */
- public void setPropertyFile( File filename )
- {
- m_propertyFile = filename;
- }
-
- /**
- * Request a summary
- *
- * @param summary true if you would like a summary logged of the replace
- * operation
- */
- public void setSummary( boolean summary )
- {
- m_summary = summary;
- }
-
- /**
- * Set the string token to replace.
- *
- * @param token The new Token value
- */
- public void setToken( String token )
- {
- createReplaceToken().addContent( token );
- }
-
- /**
- * Set the string value to use as token replacement.
- *
- * @param value The new Value value
- */
- public void setValue( String value )
- {
- createReplaceValue().addContent( value );
- }
-
- public Properties getProperties( File propertyFile )
- throws TaskException
- {
- Properties properties = new Properties();
-
- try
- {
- properties.load( new FileInputStream( propertyFile ) );
- }
- catch( FileNotFoundException e )
- {
- String message = "Property file (" + propertyFile.getPath() + ") not found.";
- throw new TaskException( message );
- }
- catch( IOException e )
- {
- String message = "Property file (" + propertyFile.getPath() + ") cannot be loaded.";
- throw new TaskException( message );
- }
-
- return properties;
- }
-
- /**
- * Nested <replacetoken> element.
- *
- * @return Description of the Returned Value
- */
- public NestedString createReplaceToken()
- {
- if( m_token == null )
- {
- m_token = new NestedString();
- }
- return m_token;
- }
-
- /**
- * Nested <replacevalue> element.
- *
- * @return Description of the Returned Value
- */
- public NestedString createReplaceValue()
- {
- return m_value;
- }
-
- /**
- * Add nested <replacefilter> element.
- *
- * @return Description of the Returned Value
- */
- public Replacefilter createReplacefilter()
- {
- Replacefilter filter = new Replacefilter( this );
- m_replacefilters.add( filter );
- return filter;
- }
-
- /**
- * Do the execution.
- *
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- validateAttributes();
-
- if( m_propertyFile != null )
- {
- m_properties = getProperties( m_propertyFile );
- }
-
- validateReplacefilters();
- m_fileCount = 0;
- m_replaceCount = 0;
-
- if( m_src != null )
- {
- processFile( m_src );
- }
-
- if( m_dir != null )
- {
- DirectoryScanner ds = super.getDirectoryScanner( m_dir );
- String[] srcs = ds.getIncludedFiles();
-
- for( int i = 0; i < srcs.length; i++ )
- {
- File file = new File( m_dir, srcs[ i ] );
- processFile( file );
- }
- }
-
- if( m_summary )
- {
- getContext().info( "Replaced " + m_replaceCount + " occurrences in " + m_fileCount + " files." );
- }
- }
-
- /**
- * Validate attributes provided for this task in .xml build file.
- *
- * @exception org.apache.myrmidon.api.TaskException if any supplied attribute is invalid or any
- * mandatory attribute is missing
- */
- public void validateAttributes()
- throws TaskException
- {
- if( m_src == null && m_dir == null )
- {
- String message = "Either the file or the dir attribute " + "must be specified";
- throw new TaskException( message );
- }
- if( m_propertyFile != null && !m_propertyFile.exists() )
- {
- String message = "Property file " + m_propertyFile.getPath() + " does not exist.";
- throw new TaskException( message );
- }
- if( m_token == null && m_replacefilters.size() == 0 )
- {
- String message = "Either token or a nested replacefilter "
- + "must be specified";
- throw new TaskException( message );
- }
- if( m_token != null && "".equals( m_token.getText() ) )
- {
- String message = "The token attribute must not be an empty string.";
- throw new TaskException( message );
- }
- }
-
- /**
- * Validate nested elements.
- *
- * @exception org.apache.myrmidon.api.TaskException if any supplied attribute is invalid or any
- * mandatory attribute is missing
- */
- public void validateReplacefilters()
- throws TaskException
- {
- for( int i = 0; i < m_replacefilters.size(); i++ )
- {
- Replacefilter element = (Replacefilter)m_replacefilters.get( i );
- element.validate();
- }
- }
-
- /**
- * Perform the replacement on the given file. The replacement is performed
- * on a temporary file which then replaces the original file.
- *
- * @param src the source file
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- private void processFile( File src )
- throws TaskException
- {
- if( !src.exists() )
- {
- throw new TaskException( "Replace: source file " + src.getPath() + " doesn't exist" );
- }
-
- File temp = null;
- try
- {
- temp = File.createTempFile( "rep", ".tmp", src.getParentFile() );
- }
- catch( IOException ioe )
- {
- throw new TaskException( ioe.toString(), ioe );
- }
-
- Reader reader = null;
- Writer writer = null;
- try
- {
- reader = m_encoding == null ? new FileReader( src )
- : new InputStreamReader( new FileInputStream( src ), m_encoding );
- writer = m_encoding == null ? new FileWriter( temp )
- : new OutputStreamWriter( new FileOutputStream( temp ), m_encoding );
-
- BufferedReader br = new BufferedReader( reader );
- BufferedWriter bw = new BufferedWriter( writer );
-
- // read the entire file into a StringBuffer
- // size of work buffer may be bigger than needed
- // when multibyte characters exist in the source file
- // but then again, it might be smaller than needed on
- // platforms like Windows where length can't be trusted
- int fileLengthInBytes = (int)( src.length() );
- StringBuffer tmpBuf = new StringBuffer( fileLengthInBytes );
- int readChar = 0;
- int totread = 0;
- while( true )
- {
- readChar = br.read();
- if( readChar < 0 )
- {
- break;
- }
- tmpBuf.append( (char)readChar );
- totread++;
- }
-
- // create a String so we can use indexOf
- String buf = tmpBuf.toString();
-
- //Preserve original string (buf) so we can compare the result
- String newString = new String( buf );
-
- if( m_token != null )
- {
- // line separators in values and tokens are "\n"
- // in order to compare with the file contents, replace them
- // as needed
- final String val = stringReplace( m_value.getText(), "\n", StringUtil.LINE_SEPARATOR );
- final String tok = stringReplace( m_token.getText(), "\n", StringUtil.LINE_SEPARATOR );
-
- // for each found token, replace with value
- getContext().debug( "Replacing in " + src.getPath() + ": " + m_token.getText() + " --> " + m_value.getText() );
- newString = stringReplace( newString, tok, val );
- }
-
- if( m_replacefilters.size() > 0 )
- {
- newString = processReplacefilters( newString, src.getPath() );
- }
-
- boolean changes = !newString.equals( buf );
- if( changes )
- {
- bw.write( newString, 0, newString.length() );
- bw.flush();
- }
-
- // cleanup
- bw.close();
- writer = null;
- br.close();
- reader = null;
-
- // If there were changes, move the new one to the old one;
- // otherwise, delete the new one
- if( changes )
- {
- ++m_fileCount;
- src.delete();
- temp.renameTo( src );
- temp = null;
- }
- }
- catch( IOException ioe )
- {
- throw new TaskException( "IOException in " + src + " - " +
- ioe.getClass().getName() + ":" + ioe.getMessage(), ioe );
- }
- finally
- {
- IOUtil.shutdownReader( reader );
- IOUtil.shutdownWriter( writer );
- if( temp != null )
- {
- temp.delete();
- }
- }
-
- }
-
- private String processReplacefilters( String buffer, String filename )
- {
- String newString = new String( buffer );
-
- for( int i = 0; i < m_replacefilters.size(); i++ )
- {
- Replacefilter filter = (Replacefilter)m_replacefilters.get( i );
-
- //for each found token, replace with value
- getContext().debug( "Replacing in " + filename + ": " + filter.getToken() + " --> " + filter.getReplaceValue() );
- newString = stringReplace( newString, filter.getToken(), filter.getReplaceValue() );
- }
-
- return newString;
- }
-
- /**
- * Replace occurrences of str1 in string str with str2
- */
- private String stringReplace( String str, String str1, String str2 )
- {
- StringBuffer ret = new StringBuffer();
- int start = 0;
- int found = str.indexOf( str1 );
- while( found >= 0 )
- {
- // write everything up to the found str1
- if( found > start )
- {
- ret.append( str.substring( start, found ) );
- }
-
- // write the replacement str2
- if( str2 != null )
- {
- ret.append( str2 );
- }
-
- // search again
- start = found + str1.length();
- found = str.indexOf( str1, start );
- ++m_replaceCount;
- }
-
- // write the remaining characters
- if( str.length() > start )
- {
- ret.append( str.substring( start, str.length() ) );
- }
-
- return ret.toString();
- }
-
- public NestedString getValue()
- {
- return m_value;
- }
-
- public File getPropertyFile()
- {
- return m_propertyFile;
- }
-
- public Properties getProperties()
- {
- return m_properties;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/ReplaceRegExp.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/ReplaceRegExp.java
deleted file mode 100644
index e911cf62b..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/ReplaceRegExp.java
+++ /dev/null
@@ -1,400 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.text;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.LineNumberReader;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.ScannerUtil;
-import org.apache.tools.todo.util.regexp.Regexp;
-import org.apache.tools.todo.taskdefs.text.RegularExpression;
-
-/**
- *
- * Task to do regular expression string replacements in a text
- * file. The input file(s) must be able to be properly processed by
- * a Reader instance. That is, they must be text only, no binary.
- *
- * The syntax of the regular expression depends on the implemtation that
- * you choose to use. The system property ant.regexp.regexpimpl
- * will be the classname of the implementation that will be used (the default is
- * org.apache.tools.ant.util.regexp.JakartaOroRegexp
and requires
- * the Jakarta Oro Package).
- * For jdk <= 1.3, there are two available implementations:
- * org.apache.tools.ant.util.regexp.JakartaOroRegexp (the default)
- * Requires the jakarta-oro package
- *
- * org.apache.tools.ant.util.regexp.JakartaRegexpRegexp
- * Requires the jakarta-regexp package
- *
- * For jdk >= 1.4 an additional implementation is available:
- * org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp
- * Requires the jdk 1.4 built in regular expression package.
- * Usage: Call Syntax: <replaceregexp file="file" match="pattern"
- * replace="pattern" flags="options"? byline="true|false"? >
- * regularexpression? substitution? fileset* </replaceregexp> NOTE: You
- * must have either the file attribute specified, or at least one fileset
- * subelement to operation on. You may not have the file attribute specified if
- * you nest fileset elements inside this task. Also, you cannot specify both
- * match and a regular expression subelement at the same time, nor can you
- * specify the replace attribute and the substitution subelement at the same
- * time. Attributes: file --> A single file to operation on (mutually
- * exclusive with the fileset subelements) match --> The Regular expression
- * to match replace --> The Expression replacement string flags --> The
- * options to give to the replacement g = Substitute all occurrences. default is
- * to replace only the first one i = Case insensitive match byline --> Should
- * this file be processed a single line at a time (default is false) "true"
- * indicates to perform replacement on a line by line basis "false" indicates to
- * perform replacement on the whole file at once. Example: The following call
- * could be used to replace an old property name in a ".properties" file with a
- * new name. In the replace attribute, you can refer to any part of the match
- * expression in parenthesis using backslash followed by a number like '\1'.
- * <replaceregexp file="test.properties" match="MyProperty=(.*)"
- * replace="NewProperty=\1" byline="true" />
- *
- * @author Matthew Inger
- */
-public class ReplaceRegExp
- extends AbstractTask
-{
- private boolean byline;
-
- private File file;
- private ArrayList filesets;
- private String flags;// Keep jdk 1.1 compliant so others can use this
- private RegularExpression regex;
- private Substitution subs;
-
- /**
- * Default Constructor
- */
- public ReplaceRegExp()
- {
- super();
- this.file = null;
- this.filesets = new ArrayList();
- this.flags = "";
- this.byline = false;
-
- this.regex = null;
- this.subs = null;
- }
-
- public void setByLine( String byline )
- {
- Boolean res = Boolean.valueOf( byline );
- if( res == null )
- {
- res = Boolean.FALSE;
- }
- this.byline = res.booleanValue();
- }
-
- public void setFile( File file )
- {
- this.file = file;
- }
-
- public void setFlags( String flags )
- {
- this.flags = flags;
- }
-
- public void setMatch( String match )
- throws TaskException
- {
- if( regex != null )
- {
- throw new TaskException( "Only one regular expression is allowed" );
- }
-
- regex = new RegularExpression();
- regex.setPattern( match );
- }
-
- public void setReplace( String replace )
- throws TaskException
- {
- if( subs != null )
- {
- throw new TaskException( "Only one substitution expression is allowed" );
- }
-
- subs = new Substitution();
- subs.setExpression( replace );
- }
-
- public void addFileset( FileSet set )
- {
- filesets.add( set );
- }
-
- public RegularExpression createRegularExpression()
- throws TaskException
- {
- if( regex != null )
- {
- throw new TaskException( "Only one regular expression is allowed." );
- }
-
- regex = new RegularExpression();
- return regex;
- }
-
- public Substitution createSubstitution()
- throws TaskException
- {
- if( subs != null )
- {
- throw new TaskException( "Only one substitution expression is allowed" );
- }
-
- subs = new Substitution();
- return subs;
- }
-
- public void execute()
- throws TaskException
- {
- if( regex == null )
- {
- throw new TaskException( "No expression to match." );
- }
- if( subs == null )
- {
- throw new TaskException( "Nothing to replace expression with." );
- }
-
- if( file != null && filesets.size() > 0 )
- {
- throw new TaskException( "You cannot supply the 'file' attribute and filesets at the same time." );
- }
-
- int options = 0;
-
- if( flags.indexOf( 'g' ) != -1 )
- {
- options |= Regexp.REPLACE_ALL;
- }
-
- if( flags.indexOf( 'i' ) != -1 )
- {
- options |= Regexp.MATCH_CASE_INSENSITIVE;
- }
-
- if( flags.indexOf( 'm' ) != -1 )
- {
- options |= Regexp.MATCH_MULTILINE;
- }
-
- if( flags.indexOf( 's' ) != -1 )
- {
- options |= Regexp.MATCH_SINGLELINE;
- }
-
- if( file != null && file.exists() )
- {
- try
- {
- doReplace( file, options );
- }
- catch( IOException e )
- {
- final String message = "An error occurred processing file: '" +
- file.getAbsolutePath() + "': " + e.toString();
- getContext().error( message, e );
- }
- }
- else if( file != null )
- {
- final String message =
- "The following file is missing: '" + file.getAbsolutePath() + "'";
- getContext().error( message );
- }
-
- int sz = filesets.size();
- for( int i = 0; i < sz; i++ )
- {
- FileSet fs = (FileSet)( filesets.get( i ) );
- DirectoryScanner ds = ScannerUtil.getDirectoryScanner( fs );
-
- String files[] = ds.getIncludedFiles();
- for( int j = 0; j < files.length; j++ )
- {
- File f = new File( files[ j ] );
- if( f.exists() )
- {
- try
- {
- doReplace( f, options );
- }
- catch( Exception e )
- {
- final String message = "An error occurred processing file: '" + f.getAbsolutePath() +
- "': " + e.toString();
- getContext().error( message );
- }
- }
- else
- {
- final String message = "The following file is missing: '" + file.getAbsolutePath() + "'";
- getContext().error( message );
- }
- }
- }
- }
-
- protected String doReplace( RegularExpression r,
- Substitution s,
- String input,
- int options )
- throws TaskException
- {
- String res = input;
- Regexp regexp = r.getRegexp();
-
- if( regexp.matches( input, options ) )
- {
- res = regexp.substitute( input, s.getExpression(), options );
- }
-
- return res;
- }
-
- /**
- * Perform the replace on the entire file
- *
- * @param f Description of Parameter
- * @param options Description of Parameter
- * @exception java.io.IOException Description of Exception
- */
- protected void doReplace( File f, int options )
- throws IOException, TaskException
- {
- File parentDir = new File( new File( f.getAbsolutePath() ).getParent() );
- File temp = File.createTempFile( "replace", ".txt", parentDir );
-
- FileReader r = null;
- FileWriter w = null;
-
- try
- {
- r = new FileReader( f );
- w = new FileWriter( temp );
-
- BufferedReader br = new BufferedReader( r );
- BufferedWriter bw = new BufferedWriter( w );
- PrintWriter pw = new PrintWriter( bw );
-
- boolean changes = false;
-
- final String message = "Replacing pattern '" + regex.getPattern() +
- "' with '" + subs.getExpression() +
- "' in '" + f.getPath() + "'" +
- ( byline ? " by line" : "" ) +
- ( flags.length() > 0 ? " with flags: '" + flags + "'" : "" ) +
- ".";
- getContext().warn( message );
-
- if( byline )
- {
- LineNumberReader lnr = new LineNumberReader( br );
- String line = null;
-
- while( ( line = lnr.readLine() ) != null )
- {
- String res = doReplace( regex, subs, line, options );
- if( !res.equals( line ) )
- {
- changes = true;
- }
-
- pw.println( res );
- }
- pw.flush();
- }
- else
- {
- int flen = (int)( f.length() );
- char tmpBuf[] = new char[ flen ];
- int numread = 0;
- int totread = 0;
- while( numread != -1 && totread < flen )
- {
- numread = br.read( tmpBuf, totread, flen );
- totread += numread;
- }
-
- String buf = new String( tmpBuf );
-
- String res = doReplace( regex, subs, buf, options );
- if( !res.equals( buf ) )
- {
- changes = true;
- }
-
- pw.println( res );
- pw.flush();
- }
-
- r.close();
- r = null;
- w.close();
- w = null;
-
- if( changes )
- {
- f.delete();
- temp.renameTo( f );
- }
- else
- {
- temp.delete();
- }
- }
- finally
- {
- try
- {
- if( r != null )
- {
- r.close();
- }
- }
- catch( Exception e )
- {
- }
- ;
-
- try
- {
- if( w != null )
- {
- r.close();
- }
- }
- catch( Exception e )
- {
- }
- ;
- }
- }
-
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/Replacefilter.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/Replacefilter.java
deleted file mode 100644
index 00759abac..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/Replacefilter.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.text;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.taskdefs.text.Replace;
-
-public class Replacefilter
-{
- private String m_property;
- private String m_token;
- private String m_value;
- private Replace m_replace;
-
- public Replacefilter( Replace replace )
- {
- m_replace = replace;
- }
-
- public void setProperty( final String property )
- {
- this.m_property = property;
- }
-
- public void setToken( String token )
- {
- this.m_token = token;
- }
-
- public void setValue( String value )
- {
- this.m_value = value;
- }
-
- public String getProperty()
- {
- return m_property;
- }
-
- public String getReplaceValue()
- {
- if( m_property != null )
- {
- return (String)m_replace.getProperties().getProperty( m_property );
- }
- else if( m_value != null )
- {
- return m_value;
- }
- else if( m_replace.getValue() != null )
- {
- return m_replace.getValue().getText();
- }
- else
- {
- //Default is empty string
- return "";
- }
- }
-
- public String getToken()
- {
- return m_token;
- }
-
- public String getValue()
- {
- return m_value;
- }
-
- public void validate()
- throws TaskException
- {
- //Validate mandatory attributes
- if( m_token == null )
- {
- String message = "token is a mandatory attribute " + "of replacefilter.";
- throw new TaskException( message );
- }
-
- if( "".equals( m_token ) )
- {
- String message = "The token attribute must not be an empty string.";
- throw new TaskException( message );
- }
-
- //value and property are mutually exclusive attributes
- if( ( m_value != null ) && ( m_property != null ) )
- {
- String message = "Either value or property " + "can be specified, but a replacefilter " + "element cannot have both.";
- throw new TaskException( message );
- }
-
- if( ( m_property != null ) )
- {
- //the property attribute must have access to a property file
- if( m_replace.getPropertyFile() == null )
- {
- String message = "The replacefilter's property attribute " +
- "can only be used with the replacetask's propertyFile attribute.";
- throw new TaskException( message );
- }
-
- //Make sure property exists in property file
- if( m_replace.getProperties() == null ||
- m_replace.getProperties().getProperty( m_property ) == null )
- {
- String message = "property \"" + m_property + "\" was not found in " + m_replace.getPropertyFile().getPath();
- throw new TaskException( message );
- }
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/Substitution.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/Substitution.java
deleted file mode 100644
index d7b315a8c..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/text/Substitution.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.text;
-
-/**
- * A regular expression substitution datatype. It is an expression that is meant
- * to replace a regular expression.
- * <substitition [ [id="id"] expression="expression" | refid="id" ]
- * />
- *
- *
- * @author Matthew Inger
- * mattinger@mindless.com
- * @see org.apache.oro.text.regex.Perl5Substitition
- */
-public class Substitution
-{
- private String m_expression;
-
- public void setExpression( final String expression )
- {
- m_expression = expression;
- }
-
- /**
- * Gets the pattern string for this RegularExpression in the given project.
- */
- public String getExpression()
- {
- return m_expression;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSS.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSS.java
deleted file mode 100644
index 2a5d7c4c9..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSS.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.vss;
-
-import java.io.File;
-import java.util.Properties;
-import org.apache.aut.nativelib.ExecManager;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.Execute;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * A base class for creating tasks for executing commands on Visual SourceSafe.
- *
- *
- * The class extends the 'exec' task as it operates by executing the ss.exe
- * program supplied with SourceSafe. By default the task expects ss.exe to be in
- * the path, you can override this be specifying the ssdir attribute.
- *
- * This class provides set and get methods for 'login' and 'vsspath' attributes.
- * It also contains constants for the flags that can be passed to SS.
- *
- * @author Craig Cottingham
- * @author Andrew Everitt
- */
-public abstract class MSVSS
- extends AbstractTask
-{
- /**
- * Constant for the thing to execute
- */
- private final static String SS_EXE = "ss";
- /**
- */
- public final static String PROJECT_PREFIX = "$";
-
- /**
- * The 'Get' command
- */
- public final static String COMMAND_GET = "Get";
- /**
- * The 'Checkout' command
- */
- public final static String COMMAND_CHECKOUT = "Checkout";
- /**
- * The 'Checkin' command
- */
- public final static String COMMAND_CHECKIN = "Checkin";
- /**
- * The 'Label' command
- */
- public final static String COMMAND_LABEL = "Label";
- /**
- * The 'History' command
- */
- public final static String COMMAND_HISTORY = "History";
-
- /**
- */
- public final static String FLAG_LOGIN = "-Y";
- /**
- */
- public final static String FLAG_OVERRIDE_WORKING_DIR = "-GL";
- /**
- */
- public final static String FLAG_AUTORESPONSE_DEF = "-I-";
- /**
- */
- public final static String FLAG_AUTORESPONSE_YES = "-I-Y";
- /**
- */
- public final static String FLAG_AUTORESPONSE_NO = "-I-N";
- /**
- */
- public final static String FLAG_RECURSION = "-R";
- /**
- */
- public final static String FLAG_VERSION = "-V";
- /**
- */
- public final static String FLAG_VERSION_DATE = "-Vd";
- /**
- */
- public final static String FLAG_VERSION_LABEL = "-VL";
- /**
- */
- public final static String FLAG_WRITABLE = "-W";
- /**
- */
- public final static String VALUE_NO = "-N";
- /**
- */
- public final static String VALUE_YES = "-Y";
- /**
- */
- public final static String FLAG_QUIET = "-O-";
-
- private String m_SSDir = "";
- private String m_vssLogin = null;
- private String m_vssPath = null;
- private String m_serverPath = null;
-
- /**
- * Set the login to use when accessing vss.
- *
- * Should be formatted as username,password
- *
- * @param login the login string to use
- */
- public final void setLogin( String login )
- {
- m_vssLogin = login;
- }
-
- /**
- * Set the path to the location of the ss.ini
- *
- * @param serverPath
- */
- public final void setServerpath( String serverPath )
- {
- m_serverPath = serverPath;
- }
-
- /**
- * Set the directory where ss.exe is located
- *
- * @param dir the directory containing ss.exe
- */
- public final void setSsdir( final File dir )
- {
- m_SSDir = dir.toString();
- }
-
- /**
- * Set the path to the item in vss to operate on
- *
- * Ant can't cope with a '$' sign in an attribute so we have to add it here.
- * Also we strip off any 'vss://' prefix which is an XMS special and should
- * probably be removed!
- *
- * @param vssPath
- */
- public final void setVsspath( String vssPath )
- {
- if( vssPath.startsWith( "vss://" ) )
- {
- m_vssPath = PROJECT_PREFIX + vssPath.substring( 5 );
- }
- else
- {
- m_vssPath = PROJECT_PREFIX + vssPath;
- }
- }
-
- /**
- * Builds and returns the command string to execute ss.exe
- *
- * @return The SSCommand value
- */
- public final String getSSCommand()
- {
- String toReturn = m_SSDir;
- if( !toReturn.equals( "" ) && !toReturn.endsWith( "\\" ) )
- {
- toReturn += "\\";
- }
- toReturn += SS_EXE;
-
- return toReturn;
- }
-
- /**
- * @param cmd Description of Parameter
- */
- public void getLoginCommand( Commandline cmd )
- {
- if( m_vssLogin == null )
- {
- return;
- }
- else
- {
- cmd.addArgument( FLAG_LOGIN + m_vssLogin );
- }
- }
-
- /**
- * @return m_vssPath
- */
- public String getVsspath()
- {
- return m_vssPath;
- }
-
- protected int run( Commandline cmd )
- throws TaskException
- {
- final ExecManager execManager = (ExecManager)getService( ExecManager.class );
- final Execute exe = new Execute( execManager );
-
- // If location of ss.ini is specified we need to set the
- // environment-variable SSDIR to this value
- if( m_serverPath != null )
- {
- final Properties env = new Properties();
- env.setProperty( "SSDIR", m_serverPath );
- exe.setEnvironment( env );
- }
-
- exe.setWorkingDirectory( getBaseDirectory() );
- exe.setCommandline( cmd );
- return exe.execute();
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKIN.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKIN.java
deleted file mode 100644
index 1ed640dd4..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKIN.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.vss;
-
-import java.io.File;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.Path;
-
-/**
- * Task to perform CheckIn commands to Microsoft Visual Source Safe.
- *
- * @author Martin Poeschl
- */
-public class MSVSSCHECKIN
- extends MSVSS
-{
- private String m_localPath;
- private boolean m_recursive;
- private boolean m_writable;
- private String m_autoResponse;
- private String m_comment = "-";
-
- /**
- * Set behaviour, used in get command to make files that are 'got' writable
- */
- public final void setWritable( final boolean writable )
- {
- m_writable = writable;
- }
-
- public void setAutoresponse( final String autoResponse )
- {
- if( autoResponse.equals( "" ) || autoResponse.equals( "null" ) )
- {
- m_autoResponse = null;
- }
- else
- {
- m_autoResponse = autoResponse;
- }
- }
-
- /**
- * Set the comment to apply in SourceSafe
- *
- * If this is null or empty, it will be replaced with "-" which is what
- * SourceSafe uses for an empty comment.
- */
- public void setComment( final String comment )
- {
- if( comment.equals( "" ) || comment.equals( "null" ) )
- {
- m_comment = "-";
- }
- else
- {
- m_comment = comment;
- }
- }
-
- /**
- * Set the local path.
- */
- public void setLocalpath( final Path localPath )
- {
- m_localPath = localPath.toString();
- }
-
- /**
- * Set behaviour recursive or non-recursive
- */
- public void setRecursive( final boolean recursive )
- {
- m_recursive = recursive;
- }
-
- /**
- * Checks the value set for the autoResponse. if it equals "Y" then we
- * return -I-Y if it equals "N" then we return -I-N otherwise we return -I
- */
- public void getAutoresponse( final Commandline cmd )
- {
- if( null == m_autoResponse )
- {
- cmd.addArgument( FLAG_AUTORESPONSE_DEF );
- }
- else if( m_autoResponse.equalsIgnoreCase( "Y" ) )
- {
- cmd.addArgument( FLAG_AUTORESPONSE_YES );
-
- }
- else if( m_autoResponse.equalsIgnoreCase( "N" ) )
- {
- cmd.addArgument( FLAG_AUTORESPONSE_NO );
- }
- else
- {
- cmd.addArgument( FLAG_AUTORESPONSE_DEF );
- }
- }
-
- /**
- * Builds and returns the -GL flag command if required
- *
- * The localpath is created if it didn't exist
- */
- private void getLocalpathCommand( final Commandline cmd )
- throws TaskException
- {
- if( m_localPath == null )
- {
- return;
- }
- else
- {
- // make sure m_LocalDir exists, create it if it doesn't
- final File dir = getContext().resolveFile( m_localPath );
- if( !dir.exists() )
- {
- final boolean done = dir.mkdirs();
- if( !done )
- {
- final String message =
- "Directory " + m_localPath + " creation was not " +
- "succesful for an unknown reason";
- throw new TaskException( message );
- }
-
- final String message = "Created dir: " + dir.getAbsolutePath();
- getContext().info( message );
- }
-
- cmd.addArgument( FLAG_OVERRIDE_WORKING_DIR + m_localPath );
- }
- }
-
- private void getRecursiveCommand( final Commandline cmd )
- {
- if( !m_recursive )
- {
- return;
- }
- else
- {
- cmd.addArgument( FLAG_RECURSION );
- }
- }
-
- private void getWritableCommand( final Commandline cmd )
- {
- if( !m_writable )
- {
- return;
- }
- else
- {
- cmd.addArgument( FLAG_WRITABLE );
- }
- }
-
- /**
- * Executes the task.
- *
- * Builds a command line to execute ss and then calls Exec's run method to
- * execute the command line.
- */
- public void execute()
- throws TaskException
- {
- final Commandline commandLine = new Commandline();
-
- // first off, make sure that we've got a command and a vssdir ...
- final String vsspath = getVsspath();
- if( null == vsspath )
- {
- final String message = "vsspath attribute must be set!";
- throw new TaskException( message );
- }
-
- // now look for illegal combinations of things ...
-
- // build the command line from what we got the format is
- // ss Checkin VSS items [-H] [-C] [-I-] [-N] [-O] [-R] [-W] [-Y] [-?]
- // as specified in the SS.EXE help
- commandLine.setExecutable( getSSCommand() );
- commandLine.addArgument( COMMAND_CHECKIN );
-
- // VSS items
- commandLine.addArgument( vsspath );
- // -GL
- getLocalpathCommand( commandLine );
- // -I- or -I-Y or -I-N
- getAutoresponse( commandLine );
- // -R
- getRecursiveCommand( commandLine );
- // -W
- getWritableCommand( commandLine );
- // -Y
- getLoginCommand( commandLine );
- // -C
- commandLine.addArgument( "-C" + m_comment );
-
- final int result = run( commandLine );
- if( result != 0 )
- {
- final String message = "Failed executing: " + commandLine.toString();
- throw new TaskException( message );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKOUT.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKOUT.java
deleted file mode 100644
index 48323fb77..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKOUT.java
+++ /dev/null
@@ -1,261 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.vss;
-
-import java.io.File;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.Path;
-
-/**
- * Task to perform CheckOut commands to Microsoft Visual Source Safe.
- *
- * @author Martin Poeschl
- */
-public class MSVSSCHECKOUT
- extends MSVSS
-{
- private String m_localPath;
- private boolean m_recursive;
- private String m_version;
- private String m_date;
- private String m_label;
- private String m_autoResponse;
-
- public void setAutoresponse( final String response )
- {
- if( response.equals( "" ) || response.equals( "null" ) )
- {
- m_autoResponse = null;
- }
- else
- {
- m_autoResponse = response;
- }
- }
-
- /**
- * Set the stored date string
- *
- * Note we assume that if the supplied string has the value "null" that
- * something went wrong and that the string value got populated from a null
- * object. This happens if a ant variable is used e.g. date="${date}" when
- * date has not been defined to ant!
- */
- public void setDate( final String date )
- {
- if( date.equals( "" ) || date.equals( "null" ) )
- {
- m_date = null;
- }
- else
- {
- m_date = date;
- }
- }
-
- /**
- * Set the labeled version to operate on in SourceSafe
- *
- * Note we assume that if the supplied string has the value "null" that
- * something went wrong and that the string value got populated from a null
- * object. This happens if a ant variable is used e.g.
- * label="${label_server}" when label_server has not been defined to ant!
- */
- public void setLabel( final String label )
- {
- if( label.equals( "" ) || label.equals( "null" ) )
- {
- m_label = null;
- }
- else
- {
- m_label = label;
- }
- }
-
- /**
- * Set the local path.
- */
- public void setLocalpath( final Path localPath )
- {
- m_localPath = localPath.toString();
- }
-
- /**
- * Set behaviour recursive or non-recursive
- */
- public void setRecursive( final boolean recursive )
- {
- m_recursive = recursive;
- }
-
- /**
- * Set the stored version string
- *
- * Note we assume that if the supplied string has the value "null" that
- * something went wrong and that the string value got populated from a null
- * object. This happens if a ant variable is used e.g.
- * version="${ver_server}" when ver_server has not been defined to ant!
- */
- public void setVersion( final String version )
- {
- if( version.equals( "" ) || version.equals( "null" ) )
- {
- m_version = null;
- }
- else
- {
- m_version = version;
- }
- }
-
- /**
- * Checks the value set for the autoResponse. if it equals "Y" then we
- * return -I-Y if it equals "N" then we return -I-N otherwise we return -I
- */
- public void getAutoresponse( final Commandline cmd )
- {
- if( m_autoResponse == null )
- {
- cmd.addArgument( FLAG_AUTORESPONSE_DEF );
- }
- else if( m_autoResponse.equalsIgnoreCase( "Y" ) )
- {
- cmd.addArgument( FLAG_AUTORESPONSE_YES );
-
- }
- else if( m_autoResponse.equalsIgnoreCase( "N" ) )
- {
- cmd.addArgument( FLAG_AUTORESPONSE_NO );
- }
- else
- {
- cmd.addArgument( FLAG_AUTORESPONSE_DEF );
- }
- }
-
- /**
- * Builds and returns the -GL flag command if required
- *
- * The localpath is created if it didn't exist
- */
- public void getLocalpathCommand( final Commandline cmd )
- throws TaskException
- {
- if( m_localPath == null )
- {
- return;
- }
- else
- {
- // make sure m_LocalDir exists, create it if it doesn't
- final File dir = getContext().resolveFile( m_localPath );
- if( !dir.exists() )
- {
- if( !dir.mkdirs() )
- {
- final String message =
- "Directory " + m_localPath + " creation was not " +
- "succesful for an unknown reason";
- throw new TaskException( message );
- }
- else
- {
- final String message = "Created dir: " + dir.getAbsolutePath();
- getContext().info( message );
- }
- }
-
- cmd.addArgument( FLAG_OVERRIDE_WORKING_DIR + m_localPath );
- }
- }
-
- private void getRecursiveCommand( final Commandline cmd )
- {
- if( !m_recursive )
- {
- return;
- }
- else
- {
- cmd.addArgument( FLAG_RECURSION );
- }
- }
-
- /**
- * Simple order of priority. Returns the first specified of version, date,
- * label If none of these was specified returns ""
- */
- private void getVersionCommand( final Commandline cmd )
- {
- if( null != m_version )
- {
- cmd.addArgument( FLAG_VERSION + m_version );
- }
- else if( null != m_date )
- {
- cmd.addArgument( FLAG_VERSION_DATE + m_date );
- }
- else if( null != m_label )
- {
- cmd.addArgument( FLAG_VERSION_LABEL + m_label );
- }
- }
-
- /**
- * Executes the task.
- *
- * Builds a command line to execute ss and then calls Exec's run method to
- * execute the command line.
- */
- public void execute()
- throws TaskException
- {
- final Commandline commandLine = new Commandline();
-
- // first off, make sure that we've got a command and a vssdir ...
- final String vsspath = getVsspath();
- if( null == vsspath )
- {
- final String message = "vsspath attribute must be set!";
- throw new TaskException( message );
- }
-
- // now look for illegal combinations of things ...
-
- // build the command line from what we got the format is
- // ss Checkout VSS items [-G] [-C] [-H] [-I-] [-N] [-O] [-R] [-V] [-Y] [-?]
- // as specified in the SS.EXE help
- commandLine.setExecutable( getSSCommand() );
- commandLine.addArgument( COMMAND_CHECKOUT );
-
- // VSS items
- commandLine.addArgument( vsspath );
- // -GL
- getLocalpathCommand( commandLine );
- // -I- or -I-Y or -I-N
- getAutoresponse( commandLine );
- // -R
- getRecursiveCommand( commandLine );
- // -V
- getVersionCommand( commandLine );
- // -Y
- getLoginCommand( commandLine );
-
- final int result = run( commandLine );
- if( result != 0 )
- {
- final String message = "Failed executing: " + commandLine.toString();
- throw new TaskException( message );
- }
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSSGET.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSSGET.java
deleted file mode 100644
index ff808ebd6..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSSGET.java
+++ /dev/null
@@ -1,517 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.vss;
-
-import java.io.File;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.api.AbstractTask;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.Path;
-
-/**
- * Task to perform GET commands to Microsoft Visual Source Safe.
- *
- * The following attributes are interpretted:
- *
- *
- *
- *
- *
- * Attribute
- *
- *
- *
- * Values
- *
- *
- *
- * Required
- *
- *
- *
- *
- *
- *
- *
- * login
- *
- *
- *
- * username,password
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * vsspath
- *
- *
- *
- * SourceSafe path
- *
- *
- *
- * Yes
- *
- *
- *
- *
- *
- *
- *
- * localpath
- *
- *
- *
- * Override the working directory and get to the specified path
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * writable
- *
- *
- *
- * true or false
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * recursive
- *
- *
- *
- * true or false
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * version
- *
- *
- *
- * a version number to get
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * date
- *
- *
- *
- * a date stamp to get at
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * label
- *
- *
- *
- * a label to get for
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * quiet
- *
- *
- *
- * suppress output (off by default)
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * autoresponse
- *
- *
- *
- * What to respond with (sets the -I option). By default, -I- is used;
- * values of Y or N will be appended to this.
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * Note that only one of version, date or label should be specified
- *
- * @author Craig Cottingham
- * @author Andrew Everitt
- */
-public class MSVSSGET extends MSVSS
-{
-
- private String m_LocalPath = null;
- private boolean m_Recursive = false;
- private boolean m_Writable = false;
- private String m_Version = null;
- private String m_Date = null;
- private String m_Label = null;
- private String m_AutoResponse = null;
- private boolean m_Quiet = false;
-
- /**
- * Sets/clears quiet mode
- *
- * @param quiet The new Quiet value
- */
- public final void setQuiet( boolean quiet )
- {
- this.m_Quiet = quiet;
- }
-
- /**
- * Set behaviour, used in get command to make files that are 'got' writable
- *
- * @param argWritable The new Writable value
- */
- public final void setWritable( boolean argWritable )
- {
- m_Writable = argWritable;
- }
-
- public void setAutoresponse( String response )
- {
- if( response.equals( "" ) || response.equals( "null" ) )
- {
- m_AutoResponse = null;
- }
- else
- {
- m_AutoResponse = response;
- }
- }
-
- /**
- * Set the stored date string
- *
- * Note we assume that if the supplied string has the value "null" that
- * something went wrong and that the string value got populated from a null
- * object. This happens if a ant variable is used e.g. date="${date}" when
- * date has not been defined to ant!
- *
- * @param date The new Date value
- */
- public void setDate( String date )
- {
- if( date.equals( "" ) || date.equals( "null" ) )
- {
- m_Date = null;
- }
- else
- {
- m_Date = date;
- }
- }
-
- /**
- * Set the labeled version to operate on in SourceSafe
- *
- * Note we assume that if the supplied string has the value "null" that
- * something went wrong and that the string value got populated from a null
- * object. This happens if a ant variable is used e.g.
- * label="${label_server}" when label_server has not been defined to ant!
- *
- * @param label The new Label value
- */
- public void setLabel( String label )
- {
- if( label.equals( "" ) || label.equals( "null" ) )
- {
- m_Label = null;
- }
- else
- {
- m_Label = label;
- }
- }
-
- /**
- * Set the local path.
- *
- * @param localPath The new Localpath value
- */
- public void setLocalpath( Path localPath )
- {
- m_LocalPath = localPath.toString();
- }
-
- /**
- * Set behaviour recursive or non-recursive
- *
- * @param recursive The new Recursive value
- */
- public void setRecursive( boolean recursive )
- {
- m_Recursive = recursive;
- }
-
- /**
- * Set the stored version string
- *
- * Note we assume that if the supplied string has the value "null" that
- * something went wrong and that the string value got populated from a null
- * object. This happens if a ant variable is used e.g.
- * version="${ver_server}" when ver_server has not been defined to ant!
- *
- * @param version The new Version value
- */
- public void setVersion( String version )
- {
- if( version.equals( "" ) || version.equals( "null" ) )
- {
- m_Version = null;
- }
- else
- {
- m_Version = version;
- }
- }
-
- /**
- * Checks the value set for the autoResponse. if it equals "Y" then we
- * return -I-Y if it equals "N" then we return -I-N otherwise we return -I
- *
- * @param cmd Description of Parameter
- */
- public void getAutoresponse( Commandline cmd )
- {
-
- if( m_AutoResponse == null )
- {
- cmd.addArgument( FLAG_AUTORESPONSE_DEF );
- }
- else if( m_AutoResponse.equalsIgnoreCase( "Y" ) )
- {
- cmd.addArgument( FLAG_AUTORESPONSE_YES );
-
- }
- else if( m_AutoResponse.equalsIgnoreCase( "N" ) )
- {
- cmd.addArgument( FLAG_AUTORESPONSE_NO );
- }
- else
- {
- cmd.addArgument( FLAG_AUTORESPONSE_DEF );
- }// end of else
-
- }
-
- /**
- * Builds and returns the -GL flag command if required
- *
- * The localpath is created if it didn't exist
- *
- * @param cmd Description of Parameter
- */
- public void getLocalpathCommand( Commandline cmd )
- throws TaskException
- {
- if( m_LocalPath == null )
- {
- return;
- }
- else
- {
- // make sure m_LocalDir exists, create it if it doesn't
- File dir = getContext().resolveFile( m_LocalPath );
- if( !dir.exists() )
- {
- boolean done = dir.mkdirs();
- if( done == false )
- {
- String msg = "Directory " + m_LocalPath + " creation was not " +
- "successful for an unknown reason";
- throw new TaskException( msg );
- }
- getContext().info( "Created dir: " + dir.getAbsolutePath() );
- }
-
- cmd.addArgument( FLAG_OVERRIDE_WORKING_DIR + m_LocalPath );
- }
- }
-
- public void getQuietCommand( Commandline cmd )
- {
- if( m_Quiet )
- {
- cmd.addArgument( FLAG_QUIET );
- }
- }
-
- /**
- * @param cmd Description of Parameter
- */
- public void getRecursiveCommand( Commandline cmd )
- {
- if( !m_Recursive )
- {
- return;
- }
- else
- {
- cmd.addArgument( FLAG_RECURSION );
- }
- }
-
- /**
- * Simple order of priority. Returns the first specified of version, date,
- * label If none of these was specified returns ""
- *
- * @param cmd Description of Parameter
- */
- public void getVersionCommand( Commandline cmd )
- {
-
- if( m_Version != null )
- {
- cmd.addArgument( FLAG_VERSION + m_Version );
- }
- else if( m_Date != null )
- {
- cmd.addArgument( FLAG_VERSION_DATE + m_Date );
- }
- else if( m_Label != null )
- {
- cmd.addArgument( FLAG_VERSION_LABEL + m_Label );
- }
- }
-
- /**
- * @param cmd Description of Parameter
- */
- public void getWritableCommand( Commandline cmd )
- {
- if( !m_Writable )
- {
- return;
- }
- else
- {
- cmd.addArgument( FLAG_WRITABLE );
- }
- }
-
- /**
- * Executes the task.
- *
- * Builds a command line to execute ss and then calls Exec's run method to
- * execute the command line.
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- Commandline commandLine = new Commandline();
- int result = 0;
-
- // first off, make sure that we've got a command and a vssdir ...
- if( getVsspath() == null )
- {
- String msg = "vsspath attribute must be set!";
- throw new TaskException( msg );
- }
-
- // now look for illegal combinations of things ...
-
- // build the command line from what we got the format is
- // ss Get VSS items [-G] [-H] [-I-] [-N] [-O] [-R] [-V] [-W] [-Y] [-?]
- // as specified in the SS.EXE help
- commandLine.setExecutable( getSSCommand() );
- commandLine.addArgument( COMMAND_GET );
-
- // VSS items
- commandLine.addArgument( getVsspath() );
- // -GL
- getLocalpathCommand( commandLine );
- // -I- or -I-Y or -I-N
- getAutoresponse( commandLine );
- // -O-
- getQuietCommand( commandLine );
- // -R
- getRecursiveCommand( commandLine );
- // -V
- getVersionCommand( commandLine );
- // -W
- getWritableCommand( commandLine );
- // -Y
- getLoginCommand( commandLine );
-
- result = run( commandLine );
- if( result != 0 )
- {
- String msg = "Failed executing: " + commandLine.toString();
- throw new TaskException( msg );
- }
- }
-
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSSHISTORY.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSSHISTORY.java
deleted file mode 100644
index 933870823..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSSHISTORY.java
+++ /dev/null
@@ -1,441 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.vss;
-
-import java.io.File;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.Commandline;
-import org.apache.tools.todo.types.EnumeratedAttribute;
-
-/**
- * Task to perform HISTORY commands to Microsoft Visual Source Safe.
- *
- * @author Balazs Fejes 2
- * @author Glenn_Twiggs@bmc.com
- */
-
-public class MSVSSHISTORY extends MSVSS
-{
-
- public final static String VALUE_FROMDATE = "~d";
- public final static String VALUE_FROMLABEL = "~L";
-
- public final static String FLAG_OUTPUT = "-O";
- public final static String FLAG_USER = "-U";
-
- private String m_FromDate = null;
- private String m_ToDate = null;
- private DateFormat m_DateFormat =
- DateFormat.getDateInstance( DateFormat.SHORT );
-
- private String m_FromLabel = null;
- private String m_ToLabel = null;
- private String m_OutputFileName = null;
- private String m_User = null;
- private int m_NumDays = Integer.MIN_VALUE;
- private String m_Style = "";
- private boolean m_Recursive = false;
-
- /**
- * Set the Start Date for the Comparison of two versions in SourceSafe
- * History
- *
- * @param dateFormat The new DateFormat value
- */
- public void setDateFormat( String dateFormat )
- {
- if( !( dateFormat.equals( "" ) || dateFormat == null ) )
- {
- m_DateFormat = new SimpleDateFormat( dateFormat );
- }
- }
-
- /**
- * Set the Start Date for the Comparison of two versions in SourceSafe
- * History
- *
- * @param fromDate The new FromDate value
- */
- public void setFromDate( String fromDate )
- {
- if( fromDate.equals( "" ) || fromDate == null )
- {
- m_FromDate = null;
- }
- else
- {
- m_FromDate = fromDate;
- }
- }
-
- /**
- * Set the Start Label
- *
- * @param fromLabel The new FromLabel value
- */
- public void setFromLabel( String fromLabel )
- {
- if( fromLabel.equals( "" ) || fromLabel == null )
- {
- m_FromLabel = null;
- }
- else
- {
- m_FromLabel = fromLabel;
- }
- }
-
- /**
- * Set the number of days to go back for Comparison
- *
- * The default value is 2 days.
- *
- * @param numd The new Numdays value
- */
- public void setNumdays( int numd )
- {
- m_NumDays = numd;
- }
-
- /**
- * Set the output file name for SourceSafe output
- *
- * @param outfile The new Output value
- */
- public void setOutput( File outfile )
- {
- if( outfile == null )
- {
- m_OutputFileName = null;
- }
- else
- {
- m_OutputFileName = outfile.getAbsolutePath();
- }
- }
-
- /**
- * Set behaviour recursive or non-recursive
- *
- * @param recursive The new Recursive value
- */
- public void setRecursive( boolean recursive )
- {
- m_Recursive = recursive;
- }
-
- /**
- * Specify the detail of output
- *
- * @param attr The new Style value
- */
- public void setStyle( BriefCodediffNofile attr )
- throws TaskException
- {
- String option = attr.getValue();
- if( option.equals( "brief" ) )
- {
- m_Style = "-B";
- }
- else if( option.equals( "codediff" ) )
- {
- m_Style = "-D";
- }
- else if( option.equals( "default" ) )
- {
- m_Style = "";
- }
- else if( option.equals( "nofile" ) )
- {
- m_Style = "-F-";
- }
- else
- {
- throw new TaskException( "Style " + attr + " unknown." );
- }
- }
-
- /**
- * Set the End Date for the Comparison of two versions in SourceSafe History
- *
- * @param toDate The new ToDate value
- */
- public void setToDate( String toDate )
- {
- if( toDate.equals( "" ) || toDate == null )
- {
- m_ToDate = null;
- }
- else
- {
- m_ToDate = toDate;
- }
- }
-
- /**
- * Set the End Label
- *
- * @param toLabel The new ToLabel value
- */
- public void setToLabel( String toLabel )
- {
- if( toLabel.equals( "" ) || toLabel == null )
- {
- m_ToLabel = null;
- }
- else
- {
- m_ToLabel = toLabel;
- }
- }
-
- /**
- * Set the Username of the user whose changes we would like to see.
- *
- * @param user The new User value
- */
- public void setUser( String user )
- {
- m_User = user;
- }
-
- /**
- * Executes the task.
- *
- * Builds a command line to execute ss and then calls Exec's run method to
- * execute the command line.
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- Commandline commandLine = new Commandline();
- int result = 0;
-
- // first off, make sure that we've got a command and a vssdir and a label ...
- if( getVsspath() == null )
- {
- String msg = "vsspath attribute must be set!";
- throw new TaskException( msg );
- }
-
- // now look for illegal combinations of things ...
-
- // build the command line from what we got the format is
- // ss History elements [-H] [-L] [-N] [-O] [-V] [-Y] [-#] [-?]
- // as specified in the SS.EXE help
- commandLine.setExecutable( getSSCommand() );
- commandLine.addArgument( COMMAND_HISTORY );
-
- // VSS items
- commandLine.addArgument( getVsspath() );
-
- // -I-
- commandLine.addArgument( "-I-" );// ignore all errors
-
- // -V
- // Label an existing file or project version
- getVersionDateCommand( commandLine );
- getVersionLabelCommand( commandLine );
-
- // -R
- if( m_Recursive )
- {
- commandLine.addArgument( FLAG_RECURSION );
- }
-
- // -B / -D / -F-
- if( m_Style.length() > 0 )
- {
- commandLine.addArgument( m_Style );
- }
-
- // -Y
- getLoginCommand( commandLine );
-
- // -O
- getOutputCommand( commandLine );
-
- System.out.println( "***: " + commandLine );
-
- result = run( commandLine );
- if( result != 0 )
- {
- String msg = "Failed executing: " + commandLine.toString();
- throw new TaskException( msg );
- }
-
- }
-
- /**
- * Builds the version date command.
- *
- * @param cmd the commandline the command is to be added to
- */
- private void getOutputCommand( Commandline cmd )
- {
- if( m_OutputFileName != null )
- {
- cmd.addArgument( FLAG_OUTPUT + m_OutputFileName );
- }
- }
-
- /**
- * @param cmd Description of Parameter
- */
- private void getRecursiveCommand( Commandline cmd )
- {
- if( !m_Recursive )
- {
- return;
- }
- else
- {
- cmd.addArgument( FLAG_RECURSION );
- }
- }
-
- /**
- * Builds the User command.
- *
- * @param cmd the commandline the command is to be added to
- */
- private void getUserCommand( Commandline cmd )
- {
- if( m_User != null )
- {
- cmd.addArgument( FLAG_USER + m_User );
- }
- }
-
- /**
- * Builds the version date command.
- *
- * @param cmd the commandline the command is to be added to
- * @exception TaskException Description of Exception
- */
- private void getVersionDateCommand( Commandline cmd )
- throws TaskException
- {
- if( m_FromDate == null && m_ToDate == null && m_NumDays == Integer.MIN_VALUE )
- {
- return;
- }
-
- if( m_FromDate != null && m_ToDate != null )
- {
- cmd.addArgument( FLAG_VERSION_DATE + m_ToDate + VALUE_FROMDATE + m_FromDate );
- }
- else if( m_ToDate != null && m_NumDays != Integer.MIN_VALUE )
- {
- String startDate = null;
- try
- {
- startDate = calcDate( m_ToDate, m_NumDays );
- }
- catch( ParseException ex )
- {
- String msg = "Error parsing date: " + m_ToDate;
- throw new TaskException( msg );
- }
- cmd.addArgument( FLAG_VERSION_DATE + m_ToDate + VALUE_FROMDATE + startDate );
- }
- else if( m_FromDate != null && m_NumDays != Integer.MIN_VALUE )
- {
- String endDate = null;
- try
- {
- endDate = calcDate( m_FromDate, m_NumDays );
- }
- catch( ParseException ex )
- {
- String msg = "Error parsing date: " + m_FromDate;
- throw new TaskException( msg );
- }
- cmd.addArgument( FLAG_VERSION_DATE + endDate + VALUE_FROMDATE + m_FromDate );
- }
- else
- {
- if( m_FromDate != null )
- {
- cmd.addArgument( FLAG_VERSION + VALUE_FROMDATE + m_FromDate );
- }
- else
- {
- cmd.addArgument( FLAG_VERSION_DATE + m_ToDate );
- }
- }
- }
-
- /**
- * Builds the version date command.
- *
- * @param cmd the commandline the command is to be added to
- * @exception TaskException Description of Exception
- */
- private void getVersionLabelCommand( Commandline cmd )
- throws TaskException
- {
- if( m_FromLabel == null && m_ToLabel == null )
- {
- return;
- }
-
- if( m_FromLabel != null && m_ToLabel != null )
- {
- cmd.addArgument( FLAG_VERSION_LABEL + m_ToLabel + VALUE_FROMLABEL + m_FromLabel );
- }
- else if( m_FromLabel != null )
- {
- cmd.addArgument( FLAG_VERSION + VALUE_FROMLABEL + m_FromLabel );
- }
- else
- {
- cmd.addArgument( FLAG_VERSION_LABEL + m_ToLabel );
- }
- }
-
- /**
- * Calculates the start date for version comparison.
- *
- * Calculates the date numDay days earlier than startdate.
- *
- * @param fromDate Description of Parameter
- * @param numDays Description of Parameter
- * @return Description of the Returned Value
- * @exception ParseException Description of Exception
- */
- private String calcDate( String fromDate, int numDays )
- throws ParseException
- {
- String toDate = null;
- Date currdate = new Date();
- Calendar calend = new GregorianCalendar();
- currdate = m_DateFormat.parse( fromDate );
- calend.setTime( currdate );
- calend.add( Calendar.DATE, numDays );
- toDate = m_DateFormat.format( calend.getTime() );
- return toDate;
- }
-
- public static class BriefCodediffNofile extends EnumeratedAttribute
- {
- public String[] getValues()
- {
- return new String[]{"brief", "codediff", "nofile", "default"};
- }
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSSLABEL.java b/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSSLABEL.java
deleted file mode 100644
index b361b4bdd..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/taskdefs/vss/MSVSSLABEL.java
+++ /dev/null
@@ -1,376 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.taskdefs.vss;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * Task to perform LABEL commands to Microsoft Visual Source Safe.
- *
- * The following attributes are interpreted:
- *
- *
- *
- *
- *
- * Attribute
- *
- *
- *
- * Values
- *
- *
- *
- * Required
- *
- *
- *
- *
- *
- *
- *
- * login
- *
- *
- *
- * username,password
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * vsspath
- *
- *
- *
- * SourceSafe path
- *
- *
- *
- * Yes
- *
- *
- *
- *
- *
- *
- *
- * ssdir
- *
- *
- *
- * directory where ss.exe
resides. By default the task
- * expects it to be in the PATH.
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * label
- *
- *
- *
- * A label to apply to the hierarchy
- *
- *
- *
- * Yes
- *
- *
- *
- *
- *
- *
- *
- * version
- *
- *
- *
- * An existing file or project version to label
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * autoresponse
- *
- *
- *
- * What to respond with (sets the -I option). By default, -I- is used;
- * values of Y or N will be appended to this.
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * comment
- *
- *
- *
- * The comment to use for this label. Empty or '-' for no comment.
- *
- *
- *
- * No
- *
- *
- *
- *
- *
- *
- *
- * @author Phillip Wells
- */
-public class MSVSSLABEL extends MSVSS
-{
-
- public final static String FLAG_LABEL = "-L";
- private String m_AutoResponse = null;
- private String m_Label = null;
- private String m_Version = null;
- private String m_Comment = "-";
-
- public void setAutoresponse( String response )
- {
- if( response.equals( "" ) || response.equals( "null" ) )
- {
- m_AutoResponse = null;
- }
- else
- {
- m_AutoResponse = response;
- }
- }
-
- /**
- * Set the comment to apply in SourceSafe
- *
- * If this is null or empty, it will be replaced with "-" which is what
- * SourceSafe uses for an empty comment.
- *
- * @param comment The new Comment value
- */
- public void setComment( String comment )
- {
- if( comment.equals( "" ) || comment.equals( "null" ) )
- {
- m_Comment = "-";
- }
- else
- {
- m_Comment = comment;
- }
- }
-
- /**
- * Set the label to apply in SourceSafe
- *
- * Note we assume that if the supplied string has the value "null" that
- * something went wrong and that the string value got populated from a null
- * object. This happens if a ant variable is used e.g.
- * label="${label_server}" when label_server has not been defined to ant!
- *
- * @param label The new Label value
- */
- public void setLabel( String label )
- {
- if( label.equals( "" ) || label.equals( "null" ) )
- {
- m_Label = null;
- }
- else
- {
- m_Label = label;
- }
- }
-
- /**
- * Set the stored version string
- *
- * Note we assume that if the supplied string has the value "null" that
- * something went wrong and that the string value got populated from a null
- * object. This happens if a ant variable is used e.g.
- * version="${ver_server}" when ver_server has not been defined to ant!
- *
- * @param version The new Version value
- */
- public void setVersion( String version )
- {
- if( version.equals( "" ) || version.equals( "null" ) )
- {
- m_Version = null;
- }
- else
- {
- m_Version = version;
- }
- }
-
- /**
- * Checks the value set for the autoResponse. if it equals "Y" then we
- * return -I-Y if it equals "N" then we return -I-N otherwise we return -I
- *
- * @param cmd Description of Parameter
- */
- public void getAutoresponse( Commandline cmd )
- {
-
- if( m_AutoResponse == null )
- {
- cmd.addArgument( FLAG_AUTORESPONSE_DEF );
- }
- else if( m_AutoResponse.equalsIgnoreCase( "Y" ) )
- {
- cmd.addArgument( FLAG_AUTORESPONSE_YES );
-
- }
- else if( m_AutoResponse.equalsIgnoreCase( "N" ) )
- {
- cmd.addArgument( FLAG_AUTORESPONSE_NO );
- }
- else
- {
- cmd.addArgument( FLAG_AUTORESPONSE_DEF );
- }// end of else
-
- }
-
- /**
- * Gets the comment to be applied.
- *
- * @return the comment to be applied.
- */
- public String getComment()
- {
- return m_Comment;
- }
-
- /**
- * Gets the label to be applied.
- *
- * @return the label to be applied.
- */
- public String getLabel()
- {
- return m_Label;
- }
-
- /**
- * Builds the label command.
- *
- * @param cmd the commandline the command is to be added to
- */
- public void getLabelCommand( Commandline cmd )
- {
- if( m_Label != null )
- {
- cmd.addArgument( FLAG_LABEL + m_Label );
- }
- }
-
- /**
- * Builds the version command.
- *
- * @param cmd the commandline the command is to be added to
- */
- public void getVersionCommand( Commandline cmd )
- {
- if( m_Version != null )
- {
- cmd.addArgument( FLAG_VERSION + m_Version );
- }
- }
-
- /**
- * Executes the task.
- *
- * Builds a command line to execute ss and then calls Exec's run method to
- * execute the command line.
- *
- * @exception TaskException Description of Exception
- */
- public void execute()
- throws TaskException
- {
- Commandline commandLine = new Commandline();
- int result = 0;
-
- // first off, make sure that we've got a command and a vssdir and a label ...
- if( getVsspath() == null )
- {
- String msg = "vsspath attribute must be set!";
- throw new TaskException( msg );
- }
- if( getLabel() == null )
- {
- String msg = "label attribute must be set!";
- throw new TaskException( msg );
- }
-
- // now look for illegal combinations of things ...
-
- // build the command line from what we got the format is
- // ss Label VSS items [-C] [-H] [-I-] [-Llabel] [-N] [-O] [-V] [-Y] [-?]
- // as specified in the SS.EXE help
- commandLine.setExecutable( getSSCommand() );
- commandLine.addArgument( COMMAND_LABEL );
-
- // VSS items
- commandLine.addArgument( getVsspath() );
-
- // -C
- commandLine.addArgument( "-C" + getComment() );
-
- // -I- or -I-Y or -I-N
- getAutoresponse( commandLine );
-
- // -L
- // Specify the new label on the command line (instead of being prompted)
- getLabelCommand( commandLine );
-
- // -V
- // Label an existing file or project version
- getVersionCommand( commandLine );
-
- // -Y
- getLoginCommand( commandLine );
-
- result = run( commandLine );
- if( result != 0 )
- {
- String msg = "Failed executing: " + commandLine.toString();
- throw new TaskException( msg );
- }
-
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/Argument.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/Argument.java
deleted file mode 100644
index f3f381d73..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/Argument.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types;
-
-import java.io.File;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.util.FileUtils;
-
-/**
- * Used for nested xml command line definitions.
- */
-public class Argument
-{
- private String[] m_parts;
-
- public Argument()
- {
- }
-
- public Argument( final String value )
- {
- setValue( value );
- }
-
- public Argument( final File file )
- {
- setFile( file );
- }
-
- /**
- * Sets a single commandline argument to the absolute filename of the
- * given file.
- *
- * @param value a single commandline argument.
- */
- public void setFile( final File value )
- {
- m_parts = new String[]{value.getAbsolutePath()};
- }
-
- /**
- * Line to split into several commandline arguments.
- *
- * @param line line to split into several commandline arguments
- */
- public void setLine( final String line )
- throws TaskException
- {
- m_parts = FileUtils.translateCommandline( line );
- }
-
- /**
- * Sets a single commandline argument and treats it like a PATH -
- * ensures the right separator for the local platform is used.
- *
- * @param value a single commandline argument.
- */
- public void setPath( final Path value )
- {
- m_parts = new String[]{value.toString()};
- }
-
- /**
- * Sets a single commandline argument.
- *
- * @param value a single commandline argument.
- */
- public void setValue( final String value )
- {
- m_parts = new String[]{value};
- }
-
- /**
- * Returns the parts this Argument consists of.
- *
- * @return The Parts value
- */
- public String[] getParts()
- {
- return m_parts;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/Commandline.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/Commandline.java
deleted file mode 100644
index 3bd6c698b..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/Commandline.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types;
-
-import java.io.File;
-import java.util.ArrayList;
-import org.apache.avalon.excalibur.util.StringUtil;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.util.FileUtils;
-import org.apache.tools.todo.types.Argument;
-
-/**
- * Commandline objects help handling command lines specifying processes to
- * execute. The class can be used to define a command line as nested elements or
- * as a helper to define a command line by an application.
- *
- *
- * <someelement>
- * <acommandline executable="/executable/to/run">
- * <argument value="argument 1" />
- * <argument line="argument_1 argument_2 argument_3"
- * />
- * <argument value="argument 4" />
- * </acommandline>
- * </someelement>
- *
The element someelement
must provide a method createAcommandline
- * which returns an instance of this class.
- *
- * @author thomas.haas@softwired-inc.com
- * @author Stefan Bodewig
- */
-public class Commandline
-{
- protected final ArrayList m_arguments = new ArrayList();
- private String m_executable;
-
- public Commandline()
- {
- }
-
- public Commandline( final String[] command )
- {
- if( 0 == command.length )
- {
- throw new IllegalArgumentException( "command" );
- }
-
- m_executable = command[ 0 ];
- for( int i = 1; i < command.length; i++ )
- {
- addArgument( command[ i ] );
- }
- }
-
- /**
- * Sets the executable to run.
- */
- public void setExecutable( final String executable )
- {
- if( executable == null || executable.length() == 0 )
- {
- return;
- }
- m_executable = executable.replace( '/', File.separatorChar )
- .replace( '\\', File.separatorChar );
- }
-
- /**
- * Returns all arguments defined by addLine
, addValue
- * or the argument object.
- *
- * @return The Arguments value
- */
- public String[] getArguments()
- {
- final int size = m_arguments.size();
- final ArrayList result = new ArrayList( size * 2 );
- for( int i = 0; i < size; i++ )
- {
- final Argument arg = (Argument)m_arguments.get( i );
- final String[] s = arg.getParts();
- for( int j = 0; j < s.length; j++ )
- {
- result.add( s[ j ] );
- }
- }
-
- final String[] res = new String[ result.size() ];
- return (String[])result.toArray( res );
- }
-
- /**
- * Returns the executable and all defined arguments.
- */
- public String[] getCommandline()
- {
- final String[] args = getArguments();
- if( m_executable == null )
- {
- return args;
- }
- final String[] result = new String[ args.length + 1 ];
- result[ 0 ] = m_executable;
- System.arraycopy( args, 0, result, 1, args.length );
- return result;
- }
-
- public String getExecutable()
- {
- return m_executable;
- }
-
- public void addArguments( final String[] args )
- {
- for( int i = 0; i < args.length; i++ )
- {
- addArgument( args[ i ] );
- }
- }
-
- public void addArgument( final File argument )
- {
- addArgument( new Argument( argument ) );
- }
-
- public void addArgument( final String argument )
- {
- addArgument( new Argument( argument ) );
- }
-
- public void addArgument( final Argument argument )
- {
- m_arguments.add( argument );
- }
-
- public void addLine( final String line )
- throws TaskException
- {
- final String[] parts = FileUtils.translateCommandline( line );
- for( int i = 0; i < parts.length; i++ )
- {
- addArgument( parts[ i ] );
- }
- }
-
- public int size()
- {
- return getCommandline().length;
- }
-
- public String toString()
- {
- return StringUtil.join( getCommandline(), " " );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/CommandlineJava.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/CommandlineJava.java
deleted file mode 100644
index 35e0e7961..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/CommandlineJava.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types;
-
-import java.io.File;
-import org.apache.aut.nativelib.Os;
-import org.apache.avalon.excalibur.util.StringUtil;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.Argument;
-import org.apache.tools.todo.types.Commandline;
-
-/**
- * A representation of a Java command line that is nothing more than a composite
- * of 2 Commandline . 1 for the vm/options and 1 for the
- * classname/arguments. It provides specific methods for a java command line.
- *
- * @author thomas.haas@softwired-inc.com
- * @author Stephane Bailliez
- */
-public class CommandlineJava
- implements Cloneable
-{
- private Commandline m_vmCommand = new Commandline();
- private Commandline m_javaCommand = new Commandline();
- private SysProperties m_sysProperties = new SysProperties();
- private Path m_classpath;
- private String m_maxMemory;
-
- /**
- * Indicate whether it will execute a jar file or not, in this case the
- * first vm option must be a -jar and the 'executable' is a jar file.
- */
- private boolean executeJar;
-
- public CommandlineJava()
- {
- setVm( getJavaExecutableName() );
- }
-
- /**
- * set the classname to execute
- *
- * @param classname the fully qualified classname.
- */
- public void setClassname( String classname )
- {
- m_javaCommand.setExecutable( classname );
- executeJar = false;
- }
-
- /**
- * set a jar file to execute via the -jar option.
- *
- * @param jarpathname The new Jar value
- */
- public void setJar( String jarpathname )
- {
- m_javaCommand.setExecutable( jarpathname );
- executeJar = true;
- }
-
- /**
- * -mx or -Xmx depending on VM version
- *
- * @param max The new Maxmemory value
- */
- public void setMaxmemory( String max )
- {
- this.m_maxMemory = max;
- }
-
- public void setSystemProperties()
- throws TaskException
- {
- m_sysProperties.setSystem();
- }
-
- public void setVm( String vm )
- {
- m_vmCommand.setExecutable( vm );
- }
-
- /**
- * @return the name of the class to run or null if there is no
- * class.
- * @see #getJar()
- */
- public String getClassname()
- {
- if( !executeJar )
- {
- return m_javaCommand.getExecutable();
- }
- return null;
- }
-
- public Path getClasspath()
- {
- return m_classpath;
- }
-
- /**
- * get the command line to run a java vm.
- *
- * @return the list of all arguments necessary to run the vm.
- */
- public String[] getCommandline()
- throws TaskException
- {
- String[] result = new String[ size() ];
- int pos = 0;
- String[] vmArgs = getActualVMCommand().getCommandline();
- // first argument is the java.exe path...
- result[ pos++ ] = vmArgs[ 0 ];
-
- // -jar must be the first option in the command line.
- if( executeJar )
- {
- result[ pos++ ] = "-jar";
- }
- // next follows the vm options
- System.arraycopy( vmArgs, 1, result, pos, vmArgs.length - 1 );
- pos += vmArgs.length - 1;
- // properties are part of the vm options...
- if( m_sysProperties.size() > 0 )
- {
- System.arraycopy( m_sysProperties.getJavaVariables(), 0,
- result, pos, m_sysProperties.size() );
- pos += m_sysProperties.size();
- }
- // classpath is a vm option too..
- if( m_classpath != null && m_classpath.toString().trim().length() > 0 )
- {
- result[ pos++ ] = "-classpath";
- result[ pos++ ] = m_classpath.toString();
- }
- // this is the classname to run as well as its arguments.
- // in case of 'executeJar', the executable is a jar file.
- System.arraycopy( m_javaCommand.getCommandline(), 0,
- result, pos, m_javaCommand.size() );
- return result;
- }
-
- /**
- * @return the pathname of the jar file to run via -jar option or null
- * if there is no jar to run.
- * @see #getClassname()
- */
- public String getJar()
- {
- if( executeJar )
- {
- return m_javaCommand.getExecutable();
- }
- return null;
- }
-
- public Commandline getJavaCommand()
- {
- return m_javaCommand;
- }
-
- public SysProperties getSystemProperties()
- {
- return m_sysProperties;
- }
-
- public Commandline getVmCommand()
- {
- return getActualVMCommand();
- }
-
- public void addSysproperty( EnvironmentVariable sysp )
- {
- m_sysProperties.addVariable( sysp );
- }
-
- public void addArgument( final String argument )
- {
- m_javaCommand.addArgument( argument );
- }
-
- public void addArgument( final Argument argument )
- {
- m_javaCommand.addArgument( argument );
- }
-
- public Path createClasspath()
- {
- if( m_classpath == null )
- {
- m_classpath = new Path();
- }
- return m_classpath;
- }
-
- public void addVmArgument( final String argument )
- {
- m_vmCommand.addArgument( argument );
- }
-
- public void addVmArgument( final Argument argument )
- {
- m_vmCommand.addArgument( argument );
- }
-
- public void restoreSystemProperties()
- throws TaskException
- {
- m_sysProperties.restoreSystem();
- }
-
- /**
- * The size of the java command line.
- *
- * @return the total number of arguments in the java command line.
- * @see #getCommandline()
- */
- public int size()
- throws TaskException
- {
- int size = getActualVMCommand().size() + m_javaCommand.size() + m_sysProperties.size();
- // classpath is "-classpath " -> 2 args
- if( m_classpath != null && m_classpath.toString().trim().length() > 0 )
- {
- size += 2;
- }
- // jar execution requires an additional -jar option
- if( executeJar )
- {
- size++;
- }
- return size;
- }
-
- public String toString()
- {
- try
- {
- final String[] line = getCommandline();
- return StringUtil.join( line, " " );
- }
- catch( TaskException e )
- {
- return e.toString();
- }
- }
-
- private Commandline getActualVMCommand()
- {
- Commandline actualVMCommand = new Commandline();
- //(Commandline)vmCommand.clone();
- if( m_maxMemory != null )
- {
- actualVMCommand.addArgument( "-Xmx" + m_maxMemory );
- }
- return actualVMCommand;
- }
-
- private String getJavaExecutableName()
- {
- // This is the most common extension case - exe for windows and OS/2,
- // nothing for *nix.
- String extension = Os.isFamily( Os.OS_FAMILY_DOS ) ? ".exe" : "";
-
- // Look for java in the java.home/../bin directory. Unfortunately
- // on Windows java.home doesn't always refer to the correct location,
- // so we need to fall back to assuming java is somewhere on the
- // PATH.
- File jExecutable =
- new File( System.getProperty( "java.home" ) +
- "/../bin/java" + extension );
-
- if( jExecutable.exists() && !Os.isFamily( Os.OS_FAMILY_NETWARE ) )
- {
- // NetWare may have a "java" in that directory, but 99% of
- // the time, you don't want to execute it -- Jeff Tulley
- //
- return jExecutable.getAbsolutePath();
- }
- else
- {
- return "java";
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/DirectoryScanner.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/DirectoryScanner.java
deleted file mode 100644
index 45117aa12..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/DirectoryScanner.java
+++ /dev/null
@@ -1,732 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types;
-
-import java.io.File;
-import java.util.ArrayList;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * Class for scanning a directory for files/directories that match a certain
- * criteria.
- *
- * These criteria consist of a set of include and exclude patterns. With these
- * patterns, you can select which files you want to have included, and which
- * files you want to have excluded.
- *
- * The idea is simple. A given directory is recursively scanned for all files
- * and directories. Each file/directory is matched against a set of include and
- * exclude patterns. Only files/directories that match at least one pattern of
- * the include pattern list, and don't match a pattern of the exclude pattern
- * list will be placed in the list of files/directories found.
- *
- * When no list of include patterns is supplied, "**" will be used, which means
- * that everything will be matched. When no list of exclude patterns is
- * supplied, an empty list is used, such that nothing will be excluded.
- *
- * The pattern matching is done as follows: The name to be matched is split up
- * in path segments. A path segment is the name of a directory or file, which is
- * bounded by File.separator
('/' under UNIX, '\' under Windows).
- * E.g. "abc/def/ghi/xyz.java" is split up in the segments "abc", "def", "ghi"
- * and "xyz.java". The same is done for the pattern against which should be
- * matched.
- *
- * Then the segments of the name and the pattern will be matched against each
- * other. When '**' is used for a path segment in the pattern, then it matches
- * zero or more path segments of the name.
- *
- * There are special case regarding the use of File.separator
s at
- * the beginningof the pattern and the string to match:
- * When a pattern starts with a File.separator
, the string to match
- * must also start with a File.separator
. When a pattern does not
- * start with a File.separator
, the string to match may not start
- * with a File.separator
. When one of these rules is not obeyed,
- * the string will not match.
- *
- * When a name path segment is matched against a pattern path segment, the
- * following special characters can be used: '*' matches zero or more
- * characters, '?' matches one character.
- *
- * Examples:
- *
- * "**\*.class" matches all .class files/dirs in a directory tree.
- *
- * "test\a??.java" matches all files/dirs which start with an 'a', then two more
- * characters and then ".java", in a directory called test.
- *
- * "**" matches everything in a directory tree.
- *
- * "**\test\**\XYZ*" matches all files/dirs that start with "XYZ" and where
- * there is a parent directory called test (e.g. "abc\test\def\ghi\XYZ123").
- *
- * Case sensitivity may be turned off if necessary. By default, it is turned on.
- *
- *
- * Example of usage:
- * String[] includes = {"**\\*.class"};
- * String[] excludes = {"modules\\*\\**"};
- * ds.setIncludes(includes);
- * ds.setExcludes(excludes);
- * ds.setBasedir(new File("test"));
- * ds.setCaseSensitive(true);
- * ds.scan();
- *
- * System.out.println("FILES:");
- * String[] files = ds.getIncludedFiles();
- * for (int i = 0; i < files.length;i++) {
- * System.out.println(files[i]);
- * }
- * This will scan a directory called test for .class files, but excludes
- * all .class files in all directories under a directory called "modules"
- *
- * @author Arnout J. Kuiper ajkuiper@wxs.nl
- * @author Magesh Umasankar
- */
-public class DirectoryScanner
- implements FileScanner
-{
-
- /**
- * Have the ArrayLists holding our results been built by a slow scan?
- */
- private boolean m_haveSlowResults;
-
- /**
- * Should the file system be treated as a case sensitive one?
- */
- private boolean m_isCaseSensitive = true;
-
- /**
- * Is everything we've seen so far included?
- */
- private boolean m_everythingIncluded = true;
-
- /**
- * The base directory which should be scanned.
- */
- private File m_basedir;
-
- /**
- * The files that where found and matched at least one includes, and also
- * matched at least one excludes.
- */
- private ArrayList m_dirsExcluded;
-
- /**
- * The directories that where found and matched at least one includes, and
- * matched no excludes.
- */
- private ArrayList m_dirsIncluded;
-
- /**
- * The directories that where found and did not match any includes.
- */
- private ArrayList m_dirsNotIncluded;
-
- /**
- * The patterns for the files that should be excluded.
- */
- private String[] m_excludes;
-
- /**
- * The files that where found and matched at least one includes, and also
- * matched at least one excludes.
- */
- private ArrayList m_filesExcluded;
-
- /**
- * The files that where found and matched at least one includes, and matched
- * no excludes.
- */
- private ArrayList m_filesIncluded;
-
- /**
- * The files that where found and did not match any includes.
- */
- private ArrayList m_filesNotIncluded;
-
- /**
- * The patterns for the files that should be included.
- */
- private String[] m_includes;
-
- /**
- * Sets the basedir for scanning. This is the directory that is scanned
- * recursively. All '/' and '\' characters are replaced by File.separatorChar
- * . So the separator used need not match File.separatorChar
.
- *
- * @param basedir the (non-null) basedir for scanning
- */
- public void setBasedir( final String basedir )
- {
- setBasedir( new File( basedir.replace( '/', File.separatorChar ).replace( '\\', File.separatorChar ) ) );
- }
-
- /**
- * Sets the basedir for scanning. This is the directory that is scanned
- * recursively.
- *
- * @param basedir the basedir for scanning
- */
- public void setBasedir( final File basedir )
- {
- m_basedir = basedir;
- }
-
- /**
- * Sets the case sensitivity of the file system
- *
- * @param isCaseSensitive The new CaseSensitive value
- */
- public void setCaseSensitive( final boolean isCaseSensitive )
- {
- m_isCaseSensitive = isCaseSensitive;
- }
-
- /**
- * Sets the set of exclude patterns to use. All '/' and '\' characters are
- * replaced by File.separatorChar
. So the separator used need
- * not match File.separatorChar
.
- *
- * When a pattern ends with a '/' or '\', "**" is appended.
- *
- * @param excludes list of exclude patterns
- */
- public void setExcludes( final String[] excludes )
- {
- if( excludes == null )
- {
- m_excludes = null;
- }
- else
- {
- m_excludes = new String[ excludes.length ];
- for( int i = 0; i < excludes.length; i++ )
- {
- String pattern;
- pattern = excludes[ i ].replace( '/', File.separatorChar ).replace( '\\', File.separatorChar );
- if( pattern.endsWith( File.separator ) )
- {
- pattern += "**";
- }
- m_excludes[ i ] = pattern;
- }
- }
- }
-
- /**
- * Sets the set of include patterns to use. All '/' and '\' characters are
- * replaced by File.separatorChar
. So the separator used need
- * not match File.separatorChar
.
- *
- * When a pattern ends with a '/' or '\', "**" is appended.
- *
- * @param includes list of include patterns
- */
- public void setIncludes( final String[] includes )
- {
- if( includes == null )
- {
- m_includes = null;
- }
- else
- {
- m_includes = new String[ includes.length ];
- for( int i = 0; i < includes.length; i++ )
- {
- String pattern;
- pattern = includes[ i ].replace( '/', File.separatorChar ).replace( '\\', File.separatorChar );
- if( pattern.endsWith( File.separator ) )
- {
- pattern += "**";
- }
- m_includes[ i ] = pattern;
- }
- }
- }
-
- /**
- * Gets the basedir that is used for scanning. This is the directory that is
- * scanned recursively.
- *
- * @return the basedir that is used for scanning
- */
- public File getBasedir()
- {
- return m_basedir;
- }
-
- /**
- * Get the names of the directories that matched at least one of the include
- * patterns, an matched also at least one of the exclude patterns. The names
- * are relative to the basedir.
- *
- * @return the names of the directories
- */
- public String[] getExcludedDirectories()
- throws TaskException
- {
- slowScan();
- int count = m_dirsExcluded.size();
- String[] directories = new String[ count ];
- for( int i = 0; i < count; i++ )
- {
- directories[ i ] = (String)m_dirsExcluded.get( i );
- }
- return directories;
- }
-
- /**
- * Get the names of the files that matched at least one of the include
- * patterns, an matched also at least one of the exclude patterns. The names
- * are relative to the basedir.
- *
- * @return the names of the files
- */
- public String[] getExcludedFiles()
- throws TaskException
- {
- slowScan();
- int count = m_filesExcluded.size();
- String[] files = new String[ count ];
- for( int i = 0; i < count; i++ )
- {
- files[ i ] = (String)m_filesExcluded.get( i );
- }
- return files;
- }
-
- /**
- * Get the names of the directories that matched at least one of the include
- * patterns, an matched none of the exclude patterns. The names are relative
- * to the basedir.
- *
- * @return the names of the directories
- */
- public String[] getIncludedDirectories()
- {
- int count = m_dirsIncluded.size();
- String[] directories = new String[ count ];
- for( int i = 0; i < count; i++ )
- {
- directories[ i ] = (String)m_dirsIncluded.get( i );
- }
- return directories;
- }
-
- /**
- * Get the names of the files that matched at least one of the include
- * patterns, and matched none of the exclude patterns. The names are
- * relative to the basedir.
- *
- * @return the names of the files
- */
- public String[] getIncludedFiles()
- {
- int count = m_filesIncluded.size();
- String[] files = new String[ count ];
- for( int i = 0; i < count; i++ )
- {
- files[ i ] = (String)m_filesIncluded.get( i );
- }
- return files;
- }
-
- /**
- * Get the names of the directories that matched at none of the include
- * patterns. The names are relative to the basedir.
- *
- * @return the names of the directories
- */
- public String[] getNotIncludedDirectories()
- throws TaskException
- {
- slowScan();
- int count = m_dirsNotIncluded.size();
- String[] directories = new String[ count ];
- for( int i = 0; i < count; i++ )
- {
- directories[ i ] = (String)m_dirsNotIncluded.get( i );
- }
- return directories;
- }
-
- /**
- * Get the names of the files that matched at none of the include patterns.
- * The names are relative to the basedir.
- *
- * @return the names of the files
- */
- public String[] getNotIncludedFiles()
- throws TaskException
- {
- slowScan();
- int count = m_filesNotIncluded.size();
- String[] files = new String[ count ];
- for( int i = 0; i < count; i++ )
- {
- files[ i ] = (String)m_filesNotIncluded.get( i );
- }
- return files;
- }
-
- /**
- * Has the scanner excluded or omitted any files or directories it came
- * accross?
- *
- * @return true if all files and directories that have been found, are
- * included.
- */
- public boolean isEverythingIncluded()
- {
- return m_everythingIncluded;
- }
-
- /**
- * Adds the array with default exclusions to the current exclusions set.
- */
- public void addDefaultExcludes()
- {
- int excludesLength = m_excludes == null ? 0 : m_excludes.length;
- String[] newExcludes;
- newExcludes = new String[ excludesLength + ScannerUtil.DEFAULTEXCLUDES.length ];
- if( excludesLength > 0 )
- {
- System.arraycopy( m_excludes, 0, newExcludes, 0, excludesLength );
- }
- for( int i = 0; i < ScannerUtil.DEFAULTEXCLUDES.length; i++ )
- {
- newExcludes[ i + excludesLength ] = ScannerUtil.DEFAULTEXCLUDES[ i ].replace( '/', File.separatorChar ).replace( '\\', File.separatorChar );
- }
- m_excludes = newExcludes;
- }
-
- /**
- * Scans the base directory for files that match at least one include
- * pattern, and don't match any exclude patterns.
- *
- */
- public void scan()
- throws TaskException
- {
- if( m_basedir == null )
- {
- throw new IllegalStateException( "No basedir set" );
- }
- if( !m_basedir.exists() )
- {
- throw new IllegalStateException( "basedir " + m_basedir
- + " does not exist" );
- }
- if( !m_basedir.isDirectory() )
- {
- throw new IllegalStateException( "basedir " + m_basedir
- + " is not a directory" );
- }
-
- if( m_includes == null )
- {
- // No includes supplied, so set it to 'matches all'
- m_includes = new String[ 1 ];
- m_includes[ 0 ] = "**";
- }
- if( m_excludes == null )
- {
- m_excludes = new String[ 0 ];
- }
-
- m_filesIncluded = new ArrayList();
- m_filesNotIncluded = new ArrayList();
- m_filesExcluded = new ArrayList();
- m_dirsIncluded = new ArrayList();
- m_dirsNotIncluded = new ArrayList();
- m_dirsExcluded = new ArrayList();
-
- if( isIncluded( "" ) )
- {
- if( !isExcluded( "" ) )
- {
- m_dirsIncluded.add( "" );
- }
- else
- {
- m_dirsExcluded.add( "" );
- }
- }
- else
- {
- m_dirsNotIncluded.add( "" );
- }
- scandir( m_basedir, "", true );
- }
-
- /**
- * Tests whether a name matches against at least one exclude pattern.
- *
- * @param name the name to match
- * @return true
when the name matches against at least one
- * exclude pattern, false
otherwise.
- */
- protected boolean isExcluded( String name )
- {
- for( int i = 0; i < m_excludes.length; i++ )
- {
- if( ScannerUtil.matchPath( m_excludes[ i ], name, m_isCaseSensitive ) )
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Tests whether a name matches against at least one include pattern.
- *
- * @param name the name to match
- * @return true
when the name matches against at least one
- * include pattern, false
otherwise.
- */
- protected boolean isIncluded( final String name )
- {
- for( int i = 0; i < m_includes.length; i++ )
- {
- if( ScannerUtil.matchPath( m_includes[ i ], name, m_isCaseSensitive ) )
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Tests whether a name matches the start of at least one include pattern.
- *
- * @param name the name to match
- * @return true
when the name matches against at least one
- * include pattern, false
otherwise.
- */
- protected boolean couldHoldIncluded( final String name )
- {
- for( int i = 0; i < m_includes.length; i++ )
- {
- if( ScannerUtil.matchPatternStart( m_includes[ i ], name, m_isCaseSensitive ) )
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Scans the passed dir for files and directories. Found files and
- * directories are placed in their respective collections, based on the
- * matching of includes and excludes. When a directory is found, it is
- * scanned recursively.
- *
- * @param dir the directory to scan
- * @param vpath the path relative to the basedir (needed to prevent problems
- * with an absolute path when using dir)
- * @param fast Description of Parameter
- * @see #filesIncluded
- * @see #filesNotIncluded
- * @see #filesExcluded
- * @see #dirsIncluded
- * @see #dirsNotIncluded
- * @see #dirsExcluded
- */
- protected void scandir( final File dir, final String vpath, final boolean fast )
- throws TaskException
- {
- String[] newfiles = dir.list();
-
- if( newfiles == null )
- {
- /*
- * two reasons are mentioned in the API docs for File.list
- * (1) dir is not a directory. This is impossible as
- * we wouldn't get here in this case.
- * (2) an IO error occurred (why doesn't it throw an exception
- * then???)
- */
- throw new TaskException( "IO error scanning directory "
- + dir.getAbsolutePath() );
- }
-
- for( int i = 0; i < newfiles.length; i++ )
- {
- String name = vpath + newfiles[ i ];
- File file = new File( dir, newfiles[ i ] );
- if( file.isDirectory() )
- {
- if( isIncluded( name ) )
- {
- if( !isExcluded( name ) )
- {
- m_dirsIncluded.add( name );
- if( fast )
- {
- scandir( file, name + File.separator, fast );
- }
- }
- else
- {
- m_everythingIncluded = false;
- m_dirsExcluded.add( name );
- if( fast && couldHoldIncluded( name ) )
- {
- scandir( file, name + File.separator, fast );
- }
- }
- }
- else
- {
- m_everythingIncluded = false;
- m_dirsNotIncluded.add( name );
- if( fast && couldHoldIncluded( name ) )
- {
- scandir( file, name + File.separator, fast );
- }
- }
- if( !fast )
- {
- scandir( file, name + File.separator, fast );
- }
- }
- else if( file.isFile() )
- {
- if( isIncluded( name ) )
- {
- if( !isExcluded( name ) )
- {
- m_filesIncluded.add( name );
- }
- else
- {
- m_everythingIncluded = false;
- m_filesExcluded.add( name );
- }
- }
- else
- {
- m_everythingIncluded = false;
- m_filesNotIncluded.add( name );
- }
- }
- }
- }
-
- /**
- * Toplevel invocation for the scan.
- *
- * Returns immediately if a slow scan has already been requested.
- */
- protected void slowScan()
- throws TaskException
- {
- if( m_haveSlowResults )
- {
- return;
- }
-
- String[] excl = new String[ m_dirsExcluded.size() ];
- excl = (String[])m_dirsExcluded.toArray( excl );
-
- String[] notIncl = new String[ m_dirsNotIncluded.size() ];
- notIncl = (String[])m_dirsNotIncluded.toArray( notIncl );
-
- for( int i = 0; i < excl.length; i++ )
- {
- if( !couldHoldIncluded( excl[ i ] ) )
- {
- scandir( new File( m_basedir, excl[ i ] ),
- excl[ i ] + File.separator, false );
- }
- }
-
- for( int i = 0; i < notIncl.length; i++ )
- {
- if( !couldHoldIncluded( notIncl[ i ] ) )
- {
- scandir( new File( m_basedir, notIncl[ i ] ),
- notIncl[ i ] + File.separator, false );
- }
- }
-
- m_haveSlowResults = true;
- }
-
- public ArrayList getDirsExcluded()
- {
- return m_dirsExcluded;
- }
-
- public void setDirsExcluded( ArrayList dirsExcluded )
- {
- m_dirsExcluded = dirsExcluded;
- }
-
- public ArrayList getDirsIncluded()
- {
- return m_dirsIncluded;
- }
-
- public void setDirsIncluded( ArrayList dirsIncluded )
- {
- m_dirsIncluded = dirsIncluded;
- }
-
- public ArrayList getDirsNotIncluded()
- {
- return m_dirsNotIncluded;
- }
-
- public void setDirsNotIncluded( ArrayList dirsNotIncluded )
- {
- m_dirsNotIncluded = dirsNotIncluded;
- }
-
- public String[] getExcludes()
- {
- return m_excludes;
- }
-
- public ArrayList getFilesExcluded()
- {
- return m_filesExcluded;
- }
-
- public void setFilesExcluded( ArrayList filesExcluded )
- {
- m_filesExcluded = filesExcluded;
- }
-
- public ArrayList getFilesIncluded()
- {
- return m_filesIncluded;
- }
-
- public void setFilesIncluded( ArrayList filesIncluded )
- {
- m_filesIncluded = filesIncluded;
- }
-
- public ArrayList getFilesNotIncluded()
- {
- return m_filesNotIncluded;
- }
-
- public void setFilesNotIncluded( ArrayList filesNotIncluded )
- {
- m_filesNotIncluded = filesNotIncluded;
- }
-
- public String[] getIncludes()
- {
- return m_includes;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/EnumeratedAttribute.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/EnumeratedAttribute.java
deleted file mode 100644
index 919a9e5f9..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/EnumeratedAttribute.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types;
-
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * Helper class for attributes that can only take one of a fixed list of values.
- *
- *
- * See {@link org.apache.tools.ant.taskdefs.FixCRLF FixCRLF} for an example.
- *
- * @author Stefan Bodewig
- */
-public abstract class EnumeratedAttribute
-{
- private String m_value;
-
- /**
- * Invoked by {@link org.apache.tools.ant.IntrospectionHelper
- * IntrospectionHelper}.
- *
- * @param value The new Value value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public final void setValue( final String value )
- throws TaskException
- {
- if( !containsValue( value ) )
- {
- throw new TaskException( value + " is not a legal value for this attribute" );
- }
- this.m_value = value;
- }
-
- /**
- * Retrieves the value.
- *
- * @return The Value value
- */
- public final String getValue()
- {
- return m_value;
- }
-
- /**
- * This is the only method a subclass needs to implement.
- *
- * @return an array holding all possible values of the enumeration.
- */
- public abstract String[] getValues();
-
- /**
- * Is this value included in the enumeration?
- */
- public final boolean containsValue( final String value )
- {
- final String[] values = getValues();
- if( values == null || value == null )
- {
- return false;
- }
-
- for( int i = 0; i < values.length; i++ )
- {
- if( value.equals( values[ i ] ) )
- {
- return true;
- }
- }
- return false;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/EnvironmentData.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/EnvironmentData.java
deleted file mode 100644
index d14bde470..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/EnvironmentData.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types;
-
-import java.util.ArrayList;
-import java.util.Properties;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * Wrapper for environment variables.
- *
- * @author Stefan Bodewig
- */
-public class EnvironmentData
-{
- protected final ArrayList m_variables = new ArrayList();
-
- public Properties getVariables()
- throws TaskException
- {
- final Properties environment = new Properties();
- final int size = m_variables.size();
- for( int i = 0; i < size; i++ )
- {
- final EnvironmentVariable variable = (EnvironmentVariable)m_variables.get( i );
- environment.setProperty( variable.getKey(), variable.getValue() );
- }
- return environment;
- }
-
- public void addVariable( EnvironmentVariable var )
- {
- m_variables.add( var );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/EnvironmentVariable.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/EnvironmentVariable.java
deleted file mode 100644
index bfe5439a3..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/EnvironmentVariable.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types;
-
-import java.io.File;
-
-public class EnvironmentVariable
-{
- private String m_key;
- private String m_value;
-
- public void setFile( final File file )
- {
- m_value = file.getAbsolutePath();
- }
-
- public void setKey( final String key )
- {
- m_key = key;
- }
-
- public void setPath( final Path path )
- {
- m_value = path.toString();
- }
-
- public void setValue( final String value )
- {
- m_value = value;
- }
-
- public String getKey()
- {
- return m_key;
- }
-
- public String getValue()
- {
- return m_value;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/FileList.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/FileList.java
deleted file mode 100644
index 9b762e5ab..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/FileList.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.StringTokenizer;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * FileList represents an explicitly named list of files. FileLists are useful
- * when you want to capture a list of files regardless of whether they currently
- * exist. By contrast, FileSet operates as a filter, only returning the name of
- * a matched file if it currently exists in the file system.
- *
- * @author Craeg Strong
- * @version $Revision$ $Date$
- */
-public class FileList
-{
- private final ArrayList m_filenames = new ArrayList();
- private File m_dir;
-
- public FileList()
- {
- }
-
- public void setDir( File dir )
- {
- m_dir = dir;
- }
-
- public void setFiles( String filenames )
- {
- if( filenames != null && filenames.length() > 0 )
- {
- StringTokenizer tok = new StringTokenizer( filenames, ", \t\n\r\f", false );
- while( tok.hasMoreTokens() )
- {
- m_filenames.add( tok.nextToken() );
- }
- }
- }
-
- public File getDir()
- {
- return m_dir;
- }
-
- /**
- * Returns the list of files represented by this FileList.
- */
- public String[] getFiles()
- throws TaskException
- {
- if( m_dir == null )
- {
- throw new TaskException( "No directory specified for filelist." );
- }
-
- if( m_filenames.size() == 0 )
- {
- throw new TaskException( "No files specified for filelist." );
- }
-
- return (String[])m_filenames.toArray( new String[ m_filenames.size() ] );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/FileScanner.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/FileScanner.java
deleted file mode 100644
index 29bb12c5d..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/FileScanner.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types;
-
-import java.io.File;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * An interface used to describe the actions required by any type of directory
- * scanner.
- */
-public interface FileScanner
-{
- /**
- * Adds an array with default exclusions to the current exclusions set.
- */
- void addDefaultExcludes();
-
- /**
- * Gets the basedir that is used for scanning. This is the directory that is
- * scanned recursively.
- *
- * @return the basedir that is used for scanning
- */
- File getBasedir();
-
- /**
- * Get the names of the directories that matched at least one of the include
- * patterns, an matched also at least one of the exclude patterns. The names
- * are relative to the basedir.
- *
- * @return the names of the directories
- */
- String[] getExcludedDirectories() throws TaskException;
-
- /**
- * Get the names of the files that matched at least one of the include
- * patterns, an matched also at least one of the exclude patterns. The names
- * are relative to the basedir.
- *
- * @return the names of the files
- */
- String[] getExcludedFiles() throws TaskException;
-
- /**
- * Get the names of the directories that matched at least one of the include
- * patterns, an matched none of the exclude patterns. The names are relative
- * to the basedir.
- *
- * @return the names of the directories
- */
- String[] getIncludedDirectories();
-
- /**
- * Get the names of the files that matched at least one of the include
- * patterns, an matched none of the exclude patterns. The names are relative
- * to the basedir.
- *
- * @return the names of the files
- */
- String[] getIncludedFiles() throws TaskException;
-
- /**
- * Get the names of the directories that matched at none of the include
- * patterns. The names are relative to the basedir.
- *
- * @return the names of the directories
- */
- String[] getNotIncludedDirectories() throws TaskException;
-
- /**
- * Get the names of the files that matched at none of the include patterns.
- * The names are relative to the basedir.
- *
- * @return the names of the files
- */
- String[] getNotIncludedFiles() throws TaskException;
-
- /**
- * Scans the base directory for files that match at least one include
- * pattern, and don't match any exclude patterns.
- *
- */
- void scan()
- throws TaskException;
-
- /**
- * Sets the basedir for scanning. This is the directory that is scanned
- * recursively.
- *
- * @param basedir the (non-null) basedir for scanning
- */
- void setBasedir( String basedir );
-
- /**
- * Sets the basedir for scanning. This is the directory that is scanned
- * recursively.
- *
- * @param basedir the basedir for scanning
- */
- void setBasedir( File basedir );
-
- /**
- * Sets the set of exclude patterns to use.
- *
- * @param excludes list of exclude patterns
- */
- void setExcludes( String[] excludes );
-
- /**
- * Sets the set of include patterns to use.
- *
- * @param includes list of include patterns
- */
- void setIncludes( String[] includes );
-
- /**
- * Sets the case sensitivity of the file system
- *
- * @param isCaseSensitive The new CaseSensitive value
- */
- void setCaseSensitive( boolean isCaseSensitive );
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/FileSet.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/FileSet.java
deleted file mode 100644
index d81545427..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/FileSet.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types;
-
-/**
- * Moved out of MatchingTask to make it a standalone object that could be
- * referenced (by scripts for example).
- *
- * @author Arnout J. Kuiper ajkuiper@wxs.nl
- * @author Stefano Mazzocchi
- * stefano@apache.org
- * @author Sam Ruby rubys@us.ibm.com
- * @author Jon S. Stevens jon@clearink.com
- * @author Stefan Bodewig
- * @author Magesh Umasankar
- */
-public class FileSet
- extends org.apache.myrmidon.framework.FileSet
-{
- private boolean m_isCaseSensitive = true;
-
- /**
- * Sets case sensitivity of the file system
- */
- public void setCaseSensitive( final boolean isCaseSensitive )
- {
- m_isCaseSensitive = isCaseSensitive;
- }
-
- public boolean isCaseSensitive()
- {
- return m_isCaseSensitive;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/Path.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/Path.java
deleted file mode 100644
index ea254bbf7..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/Path.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types;
-
-import java.io.File;
-import java.util.ArrayList;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.DataType;
-import org.apache.tools.todo.util.FileUtils;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.FileSet;
-
-/**
- * This object represents a path as used by CLASSPATH or PATH environment
- * variable.
- *
- *
- * <sometask>
- * <somepath>
- * <pathelement location="/path/to/file.jar" />
- *
- * <pathelement
- * path="/path/to/file2.jar:/path/to/class2;/path/to/class3" />
- * <pathelement location="/path/to/file3.jar" />
- *
- * <pathelement location="/path/to/file4.jar" />
- *
- * </somepath>
- * </sometask>
- *
- *
- * The object implemention sometask
must provide a method called
- * createSomepath
which returns an instance of Path
.
- * Nested path definitions are handled by the Path object and must be labeled
- * pathelement
.
- *
- * The path element takes a parameter path
which will be parsed and
- * split into single elements. It will usually be used to define a path from an
- * environment variable.
- *
- * @author Thomas.Haas@softwired-inc.com
- * @author Stefan Bodewig
- */
-public class Path
- implements DataType
-{
- private ArrayList m_elements = new ArrayList();
- private File m_baseDirectory;
-
- /**
- * Invoked by IntrospectionHelper for setXXX(Path p)
attribute
- * setters.
- */
- public Path( final String path )
- {
- final PathElement pathElement = new PathElement();
- m_elements.add( pathElement );
- pathElement.setPath( path );
- }
-
- public Path()
- {
- }
-
- /**
- * Adds a String to the ArrayList if it isn't already included.
- */
- private void addUnlessPresent( final ArrayList list, final String entry )
- {
- if( !list.contains( entry ) )
- {
- list.add( entry );
- }
- }
-
- /**
- * Sets the base directory for this path.
- */
- public void setBaseDirectory( final File baseDir )
- {
- m_baseDirectory = baseDir;
- }
-
- /**
- * Adds a element definition to the path.
- *
- * @param location the location of the element to add (must not be null
- * nor empty.
- */
- public void addLocation( final File location )
- {
- final PathElement pathElement = new PathElement();
- m_elements.add( pathElement );
- pathElement.setLocation( location );
- }
-
- /**
- * Adds the components on the given path which exist to this Path.
- * Components that don't exist, aren't added.
- *
- * @param source - source path whose components are examined for existence
- */
- public void addExisting( final Path source )
- throws TaskException
- {
- final String[] list = source.list();
- for( int i = 0; i < list.length; i++ )
- {
- final File file = new File( list[ i ] );
- if( file.exists() )
- {
- addLocation( file );
- }
- }
- }
-
- /**
- * Adds a nested <fileset>
element.
- */
- public void addFileset( final FileSet fileSet )
- {
- m_elements.add( fileSet );
- }
-
- /**
- * Append the contents of the other Path instance to this.
- */
- public void append( final Path other )
- throws TaskException
- {
- if( null == other )
- {
- throw new NullPointerException( "other" );
- }
-
- final String[] list = other.list();
- for( int i = 0; i < list.length; i++ )
- {
- final String file = list[ i ];
- if( m_elements.contains( file ) )
- {
- m_elements.add( file );
- }
- }
- }
-
- /**
- * Creates a nested <path>
element.
- */
- public void addPath( final Path path )
- {
- m_elements.add( path );
- }
-
- /**
- * Returns all path elements defined by this and nested path objects.
- * The paths returned by this method are absolute.
- */
- public String[] list()
- throws TaskException
- {
- ArrayList result = new ArrayList( 2 * m_elements.size() );
- for( int i = 0; i < m_elements.size(); i++ )
- {
- Object o = m_elements.get( i );
- if( o instanceof String )
- {
- // obtained via append
- addUnlessPresent( result, (String)o );
- }
- else if( o instanceof PathElement )
- {
- final PathElement element = (PathElement)o;
- final String[] parts = element.getParts( m_baseDirectory );
- if( parts == null )
- {
- throw new NullPointerException( "You must either set location or path on " );
- }
- for( int j = 0; j < parts.length; j++ )
- {
- addUnlessPresent( result, parts[ j ] );
- }
- }
- else if( o instanceof Path )
- {
- Path p = (Path)o;
- String[] parts = p.list();
- for( int j = 0; j < parts.length; j++ )
- {
- addUnlessPresent( result, parts[ j ] );
- }
- }
- else if( o instanceof FileSet )
- {
- final FileSet fs = (FileSet)o;
- final DirectoryScanner ds = ScannerUtil.getDirectoryScanner( fs );
- final String[] s = ds.getIncludedFiles();
- final File dir = fs.getDir();
- for( int j = 0; j < s.length; j++ )
- {
- File f = new File( dir, s[ j ] );
- String absolutePath = f.getAbsolutePath();
- addUnlessPresent( result, FileUtils.translateFile( absolutePath ) );
- }
- }
- }
- return (String[])result.toArray( new String[ result.size() ] );
- }
-
- /**
- * How many parts does this Path instance consist of.
- */
- public int size()
- throws TaskException
- {
- return list().length;
- }
-
- /**
- * Returns a textual representation of the path, which can be used as
- * CLASSPATH or PATH environment variable definition.
- *
- * @return a textual representation of the path.
- */
- public String toString()
- {
- try
- {
- final String[] list = list();
-
- // empty path return empty string
- if( list.length == 0 )
- {
- return "";
- }
-
- // path containing one or more elements
- final StringBuffer result = new StringBuffer( list[ 0 ].toString() );
- for( int i = 1; i < list.length; i++ )
- {
- result.append( File.pathSeparatorChar );
- result.append( list[ i ] );
- }
-
- return result.toString();
- }
- catch( final TaskException te )
- {
- throw new Error( te.toString() );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/PathElement.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/PathElement.java
deleted file mode 100644
index e2be50975..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/PathElement.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types;
-
-import java.io.File;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.util.FileUtils;
-
-/**
- * Helper class, holds <>
values.
- */
-class PathElement
-{
- private String m_location;
- private String m_path;
-
- public void setLocation( final File location )
- {
- m_location = location.getAbsolutePath();
- }
-
- public void setPath( String path )
- {
- m_path = path;
- }
-
- protected String[] getParts( final File baseDirectory )
- throws TaskException
- {
- if( m_location != null )
- {
- return new String[]{m_location};
- }
- return FileUtils.translatePath( baseDirectory, m_path );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/PathUtil.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/PathUtil.java
deleted file mode 100644
index ba683e97e..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/PathUtil.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Locale;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.FileSet;
-import org.apache.tools.todo.types.Path;
-
-/**
- * Utilities for operating on Path objects.
- *
- * @author Peter Donald
- * @version $Revision$ $Date$
- */
-public class PathUtil
-{
- /**
- * Returns an array of URLs - useful for building a ClassLoader.
- */
- public static URL[] toURLs( final Path path )
- throws TaskException
- {
- try
- {
- final String[] list = path.list();
-
- final URL[] result = new URL[ list.length ];
-
- // path containing one or more elements
- for( int i = 0; i < list.length; i++ )
- {
- result[ i ] = new File( list[ i ] ).toURL();
- }
-
- return result;
- }
- catch( final IOException ioe )
- {
- final String message = "Malformed path entry. Reason:" + ioe;
- throw new TaskException( message, ioe );
- }
- }
-
- public static void addJavaRuntime( final Path path )
- throws TaskException
- {
- if( System.getProperty( "java.vendor" ).toLowerCase( Locale.US ).indexOf( "microsoft" ) >= 0 )
- {
- // Pull in *.zip from packages directory
- FileSet msZipFiles = new FileSet();
- msZipFiles.setDir( new File( System.getProperty( "java.home" ) + File.separator + "Packages" ) );
- msZipFiles.setIncludes( "*.ZIP" );
- path.addFileset( msZipFiles );
- }
- else if( "Kaffe".equals( System.getProperty( "java.vm.name" ) ) )
- {
- FileSet kaffeJarFiles = new FileSet();
- kaffeJarFiles.setDir( new File( System.getProperty( "java.home" )
- + File.separator + "share"
- + File.separator + "kaffe" ) );
-
- kaffeJarFiles.setIncludes( "*.jar" );
- path.addFileset( kaffeJarFiles );
- }
- else
- {
- // JDK > 1.1 seems to set java.home to the JRE directory.
- final String rt = System.getProperty( "java.home" ) +
- File.separator + "lib" + File.separator + "rt.jar";
- path.addExisting( new Path( rt ) );
- // Just keep the old version as well and let addExisting
- // sort it out.
- final String rt2 = System.getProperty( "java.home" ) +
- File.separator + "jre" + File.separator + "lib" +
- File.separator + "rt.jar";
- path.addExisting( new Path( rt2 ) );
-
- // Added for MacOS X
- final String classes = System.getProperty( "java.home" ) +
- File.separator + ".." + File.separator + "Classes" +
- File.separator + "classes.jar";
- path.addExisting( new Path( classes ) );
- final String ui = System.getProperty( "java.home" ) +
- File.separator + ".." + File.separator + "Classes" +
- File.separator + "ui.jar";
- path.addExisting( new Path( ui ) );
- }
- }
-
- public static void addExtdirs( final Path toPath, final Path extDirs )
- throws TaskException
- {
- final String[] dirs = extDirs.list();
- for( int i = 0; i < dirs.length; i++ )
- {
- final File dir = new File( dirs[ i ] );
- if( dir.exists() && dir.isDirectory() )
- {
- final FileSet fileSet = new FileSet();
- fileSet.setDir( dir );
- fileSet.setIncludes( "*" );
- toPath.addFileset( fileSet );
- }
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/ScannerUtil.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/ScannerUtil.java
deleted file mode 100644
index 4ba81346f..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/ScannerUtil.java
+++ /dev/null
@@ -1,687 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.StringTokenizer;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.PatternUtil;
-import org.apache.tools.todo.taskdefs.archive.TarFileSet;
-import org.apache.tools.todo.taskdefs.archive.ZipFileSet;
-import org.apache.tools.todo.taskdefs.archive.ZipScanner;
-import org.apache.tools.todo.types.DirectoryScanner;
-import org.apache.tools.todo.types.FileScanner;
-import org.apache.tools.todo.types.FileSet;
-
-/**
- *
- *
- * @author Peter Donald
- * @author Arnout J. Kuiper ajkuiper@wxs.nl
- * @author Magesh Umasankar
- * @version $Revision$ $Date$
- */
-public class ScannerUtil
-{
- /**
- * Patterns that should be excluded by default.
- */
- public final static String[] DEFAULTEXCLUDES = new String[]
- {
- "**/*~",
- "**/#*#",
- "**/.#*",
- "**/%*%",
- "**/CVS",
- "**/CVS/**",
- "**/.cvsignore",
- "**/SCCS",
- "**/SCCS/**",
- "**/vssver.scc"
- };
-
- /**
- * Matches a string against a pattern. The pattern contains two special
- * characters: '*' which means zero or more characters, '?' which means one
- * and only one character.
- *
- * @param pattern the (non-null) pattern to match against
- * @param str the (non-null) string that must be matched against the pattern
- * @return true
when the string matches against the pattern,
- * false
otherwise.
- */
- public static boolean match( final String pattern, final String str )
- {
- return match( pattern, str, true );
- }
-
- /**
- * Matches a string against a pattern. The pattern contains two special
- * characters: '*' which means zero or more characters, '?' which means one
- * and only one character.
- *
- * @param pattern the (non-null) pattern to match against
- * @param str the (non-null) string that must be matched against the pattern
- * @param isCaseSensitive Description of Parameter
- * @return true
when the string matches against the pattern,
- * false
otherwise.
- */
- protected static boolean match( final String pattern,
- final String str,
- final boolean isCaseSensitive )
- {
- char[] patArr = pattern.toCharArray();
- char[] strArr = str.toCharArray();
- int patIdxStart = 0;
- int patIdxEnd = patArr.length - 1;
- int strIdxStart = 0;
- int strIdxEnd = strArr.length - 1;
- char ch;
-
- boolean containsStar = false;
- for( int i = 0; i < patArr.length; i++ )
- {
- if( patArr[ i ] == '*' )
- {
- containsStar = true;
- break;
- }
- }
-
- if( !containsStar )
- {
- // No '*'s, so we make a shortcut
- if( patIdxEnd != strIdxEnd )
- {
- return false;// Pattern and string do not have the same size
- }
- for( int i = 0; i <= patIdxEnd; i++ )
- {
- ch = patArr[ i ];
- if( ch != '?' )
- {
- if( isCaseSensitive && ch != strArr[ i ] )
- {
- return false;// Character mismatch
- }
- if( !isCaseSensitive && Character.toUpperCase( ch ) !=
- Character.toUpperCase( strArr[ i ] ) )
- {
- return false;// Character mismatch
- }
- }
- }
- return true;// String matches against pattern
- }
-
- if( patIdxEnd == 0 )
- {
- return true;// Pattern contains only '*', which matches anything
- }
-
- // Process characters before first star
- while( ( ch = patArr[ patIdxStart ] ) != '*' && strIdxStart <= strIdxEnd )
- {
- if( ch != '?' )
- {
- if( isCaseSensitive && ch != strArr[ strIdxStart ] )
- {
- return false;// Character mismatch
- }
- if( !isCaseSensitive && Character.toUpperCase( ch ) !=
- Character.toUpperCase( strArr[ strIdxStart ] ) )
- {
- return false;// Character mismatch
- }
- }
- patIdxStart++;
- strIdxStart++;
- }
- if( strIdxStart > strIdxEnd )
- {
- // All characters in the string are used. Check if only '*'s are
- // left in the pattern. If so, we succeeded. Otherwise failure.
- for( int i = patIdxStart; i <= patIdxEnd; i++ )
- {
- if( patArr[ i ] != '*' )
- {
- return false;
- }
- }
- return true;
- }
-
- // Process characters after last star
- while( ( ch = patArr[ patIdxEnd ] ) != '*' && strIdxStart <= strIdxEnd )
- {
- if( ch != '?' )
- {
- if( isCaseSensitive && ch != strArr[ strIdxEnd ] )
- {
- return false;// Character mismatch
- }
- if( !isCaseSensitive && Character.toUpperCase( ch ) !=
- Character.toUpperCase( strArr[ strIdxEnd ] ) )
- {
- return false;// Character mismatch
- }
- }
- patIdxEnd--;
- strIdxEnd--;
- }
- if( strIdxStart > strIdxEnd )
- {
- // All characters in the string are used. Check if only '*'s are
- // left in the pattern. If so, we succeeded. Otherwise failure.
- for( int i = patIdxStart; i <= patIdxEnd; i++ )
- {
- if( patArr[ i ] != '*' )
- {
- return false;
- }
- }
- return true;
- }
-
- // process pattern between stars. padIdxStart and patIdxEnd point
- // always to a '*'.
- while( patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd )
- {
- int patIdxTmp = -1;
- for( int i = patIdxStart + 1; i <= patIdxEnd; i++ )
- {
- if( patArr[ i ] == '*' )
- {
- patIdxTmp = i;
- break;
- }
- }
- if( patIdxTmp == patIdxStart + 1 )
- {
- // Two stars next to each other, skip the first one.
- patIdxStart++;
- continue;
- }
- // Find the pattern between padIdxStart & padIdxTmp in str between
- // strIdxStart & strIdxEnd
- int patLength = ( patIdxTmp - patIdxStart - 1 );
- int strLength = ( strIdxEnd - strIdxStart + 1 );
- int foundIdx = -1;
- strLoop :
- for( int i = 0; i <= strLength - patLength; i++ )
- {
- for( int j = 0; j < patLength; j++ )
- {
- ch = patArr[ patIdxStart + j + 1 ];
- if( ch != '?' )
- {
- if( isCaseSensitive && ch != strArr[ strIdxStart + i + j ] )
- {
- continue strLoop;
- }
- if( !isCaseSensitive && Character.toUpperCase( ch ) !=
- Character.toUpperCase( strArr[ strIdxStart + i + j ] ) )
- {
- continue strLoop;
- }
- }
- }
-
- foundIdx = strIdxStart + i;
- break;
- }
-
- if( foundIdx == -1 )
- {
- return false;
- }
-
- patIdxStart = patIdxTmp;
- strIdxStart = foundIdx + patLength;
- }
-
- // All characters in the string are used. Check if only '*'s are left
- // in the pattern. If so, we succeeded. Otherwise failure.
- for( int i = patIdxStart; i <= patIdxEnd; i++ )
- {
- if( patArr[ i ] != '*' )
- {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Matches a path against a pattern.
- *
- * @param pattern the (non-null) pattern to match against
- * @param str the (non-null) string (path) to match
- * @return true
when the pattern matches against the string.
- * false
otherwise.
- */
- protected static boolean matchPath( final String pattern, final String str )
- {
- return matchPath( pattern, str, true );
- }
-
- /**
- * Matches a path against a pattern.
- *
- * @param pattern the (non-null) pattern to match against
- * @param str the (non-null) string (path) to match
- * @param isCaseSensitive must a case sensitive match be done?
- * @return true
when the pattern matches against the string.
- * false
otherwise.
- */
- protected static boolean matchPath( final String pattern,
- final String str,
- final boolean isCaseSensitive )
- {
- // When str starts with a File.separator, pattern has to start with a
- // File.separator.
- // When pattern starts with a File.separator, str has to start with a
- // File.separator.
- if( str.startsWith( File.separator ) !=
- pattern.startsWith( File.separator ) )
- {
- return false;
- }
-
- ArrayList patDirs = new ArrayList();
- StringTokenizer st = new StringTokenizer( pattern, File.separator );
- while( st.hasMoreTokens() )
- {
- patDirs.add( st.nextToken() );
- }
-
- ArrayList strDirs = new ArrayList();
- st = new StringTokenizer( str, File.separator );
- while( st.hasMoreTokens() )
- {
- strDirs.add( st.nextToken() );
- }
-
- int patIdxStart = 0;
- int patIdxEnd = patDirs.size() - 1;
- int strIdxStart = 0;
- int strIdxEnd = strDirs.size() - 1;
-
- // up to first '**'
- while( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd )
- {
- String patDir = (String)patDirs.get( patIdxStart );
- if( patDir.equals( "**" ) )
- {
- break;
- }
- if( !match( patDir, (String)strDirs.get( strIdxStart ), isCaseSensitive ) )
- {
- return false;
- }
- patIdxStart++;
- strIdxStart++;
- }
- if( strIdxStart > strIdxEnd )
- {
- // String is exhausted
- for( int i = patIdxStart; i <= patIdxEnd; i++ )
- {
- if( !patDirs.get( i ).equals( "**" ) )
- {
- return false;
- }
- }
- return true;
- }
- else
- {
- if( patIdxStart > patIdxEnd )
- {
- // String not exhausted, but pattern is. Failure.
- return false;
- }
- }
-
- // up to last '**'
- while( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd )
- {
- String patDir = (String)patDirs.get( patIdxEnd );
- if( patDir.equals( "**" ) )
- {
- break;
- }
- if( !match( patDir, (String)strDirs.get( strIdxEnd ), isCaseSensitive ) )
- {
- return false;
- }
- patIdxEnd--;
- strIdxEnd--;
- }
- if( strIdxStart > strIdxEnd )
- {
- // String is exhausted
- for( int i = patIdxStart; i <= patIdxEnd; i++ )
- {
- if( !patDirs.get( i ).equals( "**" ) )
- {
- return false;
- }
- }
- return true;
- }
-
- while( patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd )
- {
- int patIdxTmp = -1;
- for( int i = patIdxStart + 1; i <= patIdxEnd; i++ )
- {
- if( patDirs.get( i ).equals( "**" ) )
- {
- patIdxTmp = i;
- break;
- }
- }
- if( patIdxTmp == patIdxStart + 1 )
- {
- // '**/**' situation, so skip one
- patIdxStart++;
- continue;
- }
- // Find the pattern between padIdxStart & padIdxTmp in str between
- // strIdxStart & strIdxEnd
- int patLength = ( patIdxTmp - patIdxStart - 1 );
- int strLength = ( strIdxEnd - strIdxStart + 1 );
- int foundIdx = -1;
- strLoop :
- for( int i = 0; i <= strLength - patLength; i++ )
- {
- for( int j = 0; j < patLength; j++ )
- {
- String subPat = (String)patDirs.get( patIdxStart + j + 1 );
- String subStr = (String)strDirs.get( strIdxStart + i + j );
- if( !match( subPat, subStr, isCaseSensitive ) )
- {
- continue strLoop;
- }
- }
-
- foundIdx = strIdxStart + i;
- break;
- }
-
- if( foundIdx == -1 )
- {
- return false;
- }
-
- patIdxStart = patIdxTmp;
- strIdxStart = foundIdx + patLength;
- }
-
- for( int i = patIdxStart; i <= patIdxEnd; i++ )
- {
- if( !patDirs.get( i ).equals( "**" ) )
- {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Does the path match the start of this pattern up to the first "**".
- *
- * This is not a general purpose test and should only be used if you can
- * live with false positives.
- *
- * pattern=**\\a
and str=b
will yield true.
- *
- * @param pattern the (non-null) pattern to match against
- * @param str the (non-null) string (path) to match
- * @return Description of the Returned Value
- */
- protected static boolean matchPatternStart( final String pattern, final String str )
- {
- return matchPatternStart( pattern, str, true );
- }
-
- /**
- * Does the path match the start of this pattern up to the first "**".
- *
- * This is not a general purpose test and should only be used if you can
- * live with false positives.
- *
- * pattern=**\\a
and str=b
will yield true.
- *
- * @param pattern the (non-null) pattern to match against
- * @param str the (non-null) string (path) to match
- * @param isCaseSensitive must matches be case sensitive?
- * @return Description of the Returned Value
- */
- protected static boolean matchPatternStart( final String pattern,
- final String str,
- final boolean isCaseSensitive )
- {
- // When str starts with a File.separator, pattern has to start with a
- // File.separator.
- // When pattern starts with a File.separator, str has to start with a
- // File.separator.
- if( str.startsWith( File.separator ) !=
- pattern.startsWith( File.separator ) )
- {
- return false;
- }
-
- ArrayList patDirs = new ArrayList();
- StringTokenizer st = new StringTokenizer( pattern, File.separator );
- while( st.hasMoreTokens() )
- {
- patDirs.add( st.nextToken() );
- }
-
- ArrayList strDirs = new ArrayList();
- st = new StringTokenizer( str, File.separator );
- while( st.hasMoreTokens() )
- {
- strDirs.add( st.nextToken() );
- }
-
- int patIdxStart = 0;
- int patIdxEnd = patDirs.size() - 1;
- int strIdxStart = 0;
- int strIdxEnd = strDirs.size() - 1;
-
- // up to first '**'
- while( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd )
- {
- String patDir = (String)patDirs.get( patIdxStart );
- if( patDir.equals( "**" ) )
- {
- break;
- }
- if( !match( patDir, (String)strDirs.get( strIdxStart ), isCaseSensitive ) )
- {
- return false;
- }
- patIdxStart++;
- strIdxStart++;
- }
-
- if( strIdxStart > strIdxEnd )
- {
- // String is exhausted
- return true;
- }
- else if( patIdxStart > patIdxEnd )
- {
- // String not exhausted, but pattern is. Failure.
- return false;
- }
- else
- {
- // pattern now holds ** while string is not exhausted
- // this will generate false positives but we can live with that.
- return true;
- }
- }
-
- public static void setupDirectoryScanner( final org.apache.myrmidon.framework.FileSet set,
- final FileScanner scanner,
- final TaskContext context )
- throws TaskException
- {
- if( null == scanner )
- {
- final String message = "ds cannot be null";
- throw new IllegalArgumentException( message );
- }
-
- scanner.setBasedir( set.getDir() );
-
- /*final String message = "FileSet: Setup file scanner in dir " +
- set.getDir() + " with " + set;
- getLogger().debug( message );*/
-
- scanner.setIncludes( PatternUtil.getIncludePatterns( set, context ) );
- scanner.setExcludes( PatternUtil.getExcludePatterns( set, context ) );
- if( set.includeDefaultExcludes() )
- {
- scanner.addDefaultExcludes();
- }
- scanner.setCaseSensitive( true );
- }
-
- public static void setupDirectoryScanner( final FileSet set,
- final FileScanner scanner,
- final TaskContext context )
- throws TaskException
- {
- if( null == scanner )
- {
- final String message = "ds cannot be null";
- throw new IllegalArgumentException( message );
- }
-
- scanner.setBasedir( set.getDir() );
-
- /*final String message = "FileSet: Setup file scanner in dir " +
- set.getDir() + " with " + set;
- getLogger().debug( message );*/
-
- scanner.setIncludes( PatternUtil.getIncludePatterns( set, context ) );
- scanner.setExcludes( PatternUtil.getExcludePatterns( set, context ) );
- if( set.includeDefaultExcludes() )
- {
- scanner.addDefaultExcludes();
- }
- scanner.setCaseSensitive( set.isCaseSensitive() );
- }
-
- public static DirectoryScanner getDirectoryScanner( final FileSet set )
- throws TaskException
- {
- final File dir = set.getDir();
- if( null == dir )
- {
- final String message = "No directory specified for fileset.";
- throw new TaskException( message );
- }
-
- if( !dir.exists() )
- {
- final String message = dir.getAbsolutePath() + " not found.";
- throw new TaskException( message );
- }
- if( !dir.isDirectory() )
- {
- final String message = dir.getAbsolutePath() + " is not a directory.";
- throw new TaskException( message );
- }
-
- final DirectoryScanner scanner = new DirectoryScanner();
- setupDirectoryScanner( set, scanner, null );
- scanner.scan();
- return scanner;
- }
-
- public static DirectoryScanner getDirectoryScanner( final org.apache.myrmidon.framework.FileSet set )
- throws TaskException
- {
- final File dir = set.getDir();
- if( null == dir )
- {
- final String message = "No directory specified for fileset.";
- throw new TaskException( message );
- }
-
- if( !dir.exists() )
- {
- final String message = dir.getAbsolutePath() + " not found.";
- throw new TaskException( message );
- }
- if( !dir.isDirectory() )
- {
- final String message = dir.getAbsolutePath() + " is not a directory.";
- throw new TaskException( message );
- }
-
- final DirectoryScanner scanner = new DirectoryScanner();
- setupDirectoryScanner( set, scanner, null );
- scanner.scan();
- return scanner;
- }
-
- public static DirectoryScanner getZipScanner( final ZipFileSet set )
- throws TaskException
- {
- final File dir = set.getDir();
- final File src = set.getSrc();
-
- if( null != dir && null != src )
- {
- throw new TaskException( "Cannot set both dir and src attributes" );
- }
-
- if( null != src )
- {
- final ZipScanner scanner = new ZipScanner();
- scanner.setSrc( src );
- set.setDir( null );
- setupDirectoryScanner( set, scanner, null );
- scanner.init();
- return scanner;
- }
- else
- {
- return getDirectoryScanner( set );
- }
- }
-
- /**
- * Get a list of files and directories specified in the fileset.
- *
- * @return a list of file and directory names, relative to the baseDir
- * for the project.
- */
- public static String[] getFiles( final TarFileSet set )
- throws TaskException
- {
- final DirectoryScanner scanner = getDirectoryScanner( set );
- final String[] directories = scanner.getIncludedDirectories();
- final String[] filesPerSe = scanner.getIncludedFiles();
- final String[] files = new String[ directories.length + filesPerSe.length ];
- System.arraycopy( directories, 0, files, 0, directories.length );
- System.arraycopy( filesPerSe, 0, files, directories.length,
- filesPerSe.length );
- return files;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/SourceFileScanner.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/SourceFileScanner.java
deleted file mode 100644
index 6b3b3a6e0..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/SourceFileScanner.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Date;
-import org.apache.aut.nativelib.Os;
-import org.apache.avalon.excalibur.io.FileUtil;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.FileNameMapper;
-
-/**
- * Utility class that collects the functionality of the various scanDir methods
- * that have been scattered in several tasks before.
- *
- * The only method returns an array of source files. The array is a subset of
- * the files given as a parameter and holds only those that are newer than their
- * corresponding target files.
- *
- * @author Stefan Bodewig
- */
-public class SourceFileScanner
-{
- /**
- * Restrict the given set of files to those that are newer than their
- * corresponding target files.
- *
- * @param files the original set of files
- * @param srcDir all files are relative to this directory
- * @param destDir target files live here. if null file names returned by the
- * mapper are assumed to be absolute.
- * @param mapper knows how to construct a target file names from source file
- * names.
- */
- public String[] restrict( final String[] files,
- final File srcDir,
- final File destDir,
- final FileNameMapper mapper,
- final TaskContext context )
- throws TaskException
- {
-
- long now = ( new Date() ).getTime();
- StringBuffer targetList = new StringBuffer();
-
- /*
- * If we're on Windows, we have to munge the time up to 2 secs to
- * be able to check file modification times.
- * (Windows has a max resolution of two secs for modification times)
- * Actually this is a feature of the FAT file system, NTFS does
- * not have it, so if we could reliably passively test for an NTFS
- * file systems we could turn this off...
- */
- if( Os.isFamily( Os.OS_FAMILY_WINDOWS ) )
- {
- now += 2000;
- }
-
- final ArrayList v = new ArrayList();
- for( int i = 0; i < files.length; i++ )
- {
- final String[] targets = mapper.mapFileName( files[ i ], context );
- if( targets == null || targets.length == 0 )
- {
- final String message = files[ i ] + " skipped - don\'t know how to handle it";
- context.debug( message );
- continue;
- }
-
- final File src = FileUtil.resolveFile( srcDir, files[ i ] );
- if( src.lastModified() > now )
- {
- final String message = "Warning: " + files[ i ] + " modified in the future.";
- context.warn( message );
- }
-
- boolean added = false;
- targetList.setLength( 0 );
- for( int j = 0; !added && j < targets.length; j++ )
- {
- File dest = FileUtil.resolveFile( destDir, targets[ j ] );
-
- if( !dest.exists() )
- {
- final String message =
- files[ i ] + " added as " + dest.getAbsolutePath() + " doesn\'t exist.";
- context.debug( message );
- v.add( files[ i ] );
- added = true;
- }
- else if( src.lastModified() > dest.lastModified() )
- {
- final String message =
- files[ i ] + " added as " + dest.getAbsolutePath() + " is outdated.";
- context.debug( message );
- v.add( files[ i ] );
- added = true;
- }
- else
- {
- if( targetList.length() > 0 )
- {
- targetList.append( ", " );
- }
- targetList.append( dest.getAbsolutePath() );
- }
- }
-
- if( !added )
- {
- final String message = files[ i ] + " omitted as " + targetList.toString() +
- ( targets.length == 1 ? " is" : " are " ) + " up to date.";
- context.debug( message );
- }
-
- }
- final String[] result = new String[ v.size() ];
- return (String[])v.toArray( result );
- }
-
- /**
- * Convinience layer on top of restrict that returns the source files as
- * File objects (containing absolute paths if srcDir is absolute).
- */
- public File[] restrictAsFiles( final String[] files,
- final File srcDir,
- final File destDir,
- final FileNameMapper mapper,
- final TaskContext context )
- throws TaskException
- {
- final String[] res = restrict( files, srcDir, destDir, mapper, context );
- final File[] result = new File[ res.length ];
- for( int i = 0; i < res.length; i++ )
- {
- result[ i ] = new File( srcDir, res[ i ] );
- }
- return result;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/SysProperties.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/SysProperties.java
deleted file mode 100644
index bd7c61dcc..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/SysProperties.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Properties;
-import org.apache.aut.nativelib.ExecException;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.EnvironmentData;
-import org.apache.tools.todo.types.EnvironmentVariable;
-
-/**
- * Specialized EnvironmentData class for System properties
- */
-public class SysProperties
- extends EnvironmentData
- implements Cloneable
-{
- private Properties m_system;
-
- public void setSystem()
- throws TaskException
- {
- try
- {
- Properties p = new Properties( m_system = System.getProperties() );
-
- for( Iterator e = m_variables.iterator(); e.hasNext(); )
- {
- EnvironmentVariable v = (EnvironmentVariable)e.next();
- p.put( v.getKey(), v.getValue() );
- }
- System.setProperties( p );
- }
- catch( SecurityException e )
- {
- throw new TaskException( "Cannot modify system properties", e );
- }
- }
-
- public String[] getJavaVariables()
- throws TaskException
- {
- String props[] = new String[ 0 ];
- try
- {
- props = toNativeFormat( super.getVariables() );
- }
- catch( final ExecException ee )
- {
- throw new TaskException( ee.getMessage(), ee );
- }
-
- if( props == null )
- {
- return null;
- }
-
- for( int i = 0; i < props.length; i++ )
- {
- props[ i ] = "-D" + props[ i ];
- }
- return props;
- }
-
- public Object clone()
- {
- try
- {
- SysProperties c = (SysProperties)super.clone();
- c.m_variables.addAll( (ArrayList)m_variables.clone() );
- return c;
- }
- catch( CloneNotSupportedException e )
- {
- return null;
- }
- }
-
- public void restoreSystem()
- throws TaskException
- {
- if( m_system == null )
- {
- throw new TaskException( "Unbalanced nesting of SysProperties" );
- }
-
- try
- {
- System.setProperties( m_system );
- m_system = null;
- }
- catch( SecurityException e )
- {
- throw new TaskException( "Cannot modify system properties", e );
- }
- }
-
- public int size()
- {
- return m_variables.size();
- }
-
- private String[] toNativeFormat( final Properties environment )
- throws ExecException
- {
- final ArrayList newEnvironment = new ArrayList();
-
- final Iterator keys = environment.keySet().iterator();
- while( keys.hasNext() )
- {
- final String key = (String)keys.next();
- final String value = environment.getProperty( key );
- newEnvironment.add( key + '=' + value );
- }
-
- return (String[])newEnvironment.toArray( new String[ newEnvironment.size() ] );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/types/converters/StringToPathConverter.java b/proposal/myrmidon/src/main/org/apache/tools/todo/types/converters/StringToPathConverter.java
deleted file mode 100644
index 403e1609b..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/types/converters/StringToPathConverter.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.types.converters;
-
-import org.apache.aut.converter.AbstractConverter;
-import org.apache.aut.converter.ConverterException;
-import org.apache.tools.todo.types.Path;
-
-/**
- * A converter from String to Path.
- *
- * @author Adam Murdoch
- */
-public class StringToPathConverter
- extends AbstractConverter
-{
- /**
- * Constructors a converter.
- */
- public StringToPathConverter()
- {
- super( String.class, Path.class );
- }
-
- /**
- * Converts from String to Path
- *
- * @param original the original Object
- * @param context the context in which to convert
- * @return the converted object
- * @exception java.lang.Exception if an error occurs
- */
- protected Object convert( Object original, Object context )
- throws ConverterException
- {
- /*
- String path = (String)original;
- TaskContext taskContext = (TaskContext)context;
-
- Path retval = new Path( path );
- retval.setBaseDirectory( taskContext.getBaseDirectory() );
- return retval;
- */
- return null;
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/FileUtils.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/FileUtils.java
deleted file mode 100644
index 2b7ab4e57..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/FileUtils.java
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Stack;
-import java.util.StringTokenizer;
-import org.apache.avalon.excalibur.io.FileUtil;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.types.Path;
-import org.apache.tools.todo.util.PathTokenizer;
-
-/**
- * This class also encapsulates methods which allow Files to be refered to using
- * abstract path names which are translated to native system file paths at
- * runtime as well as copying files or setting there last modification time.
- *
- * @author duncan@x180.com
- * @author Conor MacNeill
- * @author Stefan Bodewig
- * @version $Revision$
- */
-public class FileUtils
-{
- /**
- * Parse out a path as appropriate for current OS.
- */
- public static String[] parsePath( final String path )
- {
- final PathTokenizer elements = new PathTokenizer( path );
-
- final ArrayList result = new ArrayList();
- while( elements.hasNext() )
- {
- result.add( elements.next() );
- }
-
- return (String[])result.toArray( new String[ result.size() ] );
- }
-
- /**
- * "normalize" the given absolute path.
- *
- * This includes:
- *
- * Uppercase the drive letter if there is one.
- * Remove redundant slashes after the drive spec.
- * resolve all ./, .\, ../ and ..\ sequences.
- * DOS style paths that start with a drive letter will have \ as the
- * separator.
- *
- *
- *
- * @param path Description of Parameter
- * @return Description of the Returned Value
- * @throws java.lang.NullPointerException if the file path is equal to null.
- */
- public static File normalize( String path )
- throws TaskException
- {
- String orig = path;
-
- path = path.replace( '/', File.separatorChar )
- .replace( '\\', File.separatorChar );
-
- // make sure we are dealing with an absolute path
- if( !path.startsWith( File.separator ) &&
- !( path.length() >= 2 &&
- Character.isLetter( path.charAt( 0 ) ) &&
- path.charAt( 1 ) == ':' )
- )
- {
- String msg = path + " is not an absolute path";
- throw new TaskException( msg );
- }
-
- boolean dosWithDrive = false;
- String root = null;
- // Eliminate consecutive slashes after the drive spec
- if( path.length() >= 2 &&
- Character.isLetter( path.charAt( 0 ) ) &&
- path.charAt( 1 ) == ':' )
- {
-
- dosWithDrive = true;
-
- char[] ca = path.replace( '/', '\\' ).toCharArray();
- StringBuffer sb = new StringBuffer();
- sb.append( Character.toUpperCase( ca[ 0 ] ) ).append( ':' );
-
- for( int i = 2; i < ca.length; i++ )
- {
- if( ( ca[ i ] != '\\' ) ||
- ( ca[ i ] == '\\' && ca[ i - 1 ] != '\\' )
- )
- {
- sb.append( ca[ i ] );
- }
- }
-
- path = sb.toString().replace( '\\', File.separatorChar );
- if( path.length() == 2 )
- {
- root = path;
- path = "";
- }
- else
- {
- root = path.substring( 0, 3 );
- path = path.substring( 3 );
- }
-
- }
- else
- {
- if( path.length() == 1 )
- {
- root = File.separator;
- path = "";
- }
- else if( path.charAt( 1 ) == File.separatorChar )
- {
- // UNC drive
- root = File.separator + File.separator;
- path = path.substring( 2 );
- }
- else
- {
- root = File.separator;
- path = path.substring( 1 );
- }
- }
-
- Stack s = new Stack();
- s.push( root );
- StringTokenizer tok = new StringTokenizer( path, File.separator );
- while( tok.hasMoreTokens() )
- {
- String thisToken = tok.nextToken();
- if( ".".equals( thisToken ) )
- {
- continue;
- }
- else if( "..".equals( thisToken ) )
- {
- if( s.size() < 2 )
- {
- throw new TaskException( "Cannot resolve path " + orig );
- }
- else
- {
- s.pop();
- }
- }
- else
- {// plain component
- s.push( thisToken );
- }
- }
-
- StringBuffer sb = new StringBuffer();
- for( int i = 0; i < s.size(); i++ )
- {
- if( i > 1 )
- {
- // not before the filesystem root and not after it, since root
- // already contains one
- sb.append( File.separatorChar );
- }
- sb.append( s.get( i ) );
- }
-
- path = sb.toString();
- if( dosWithDrive )
- {
- path = path.replace( '/', '\\' );
- }
- return new File( path );
- }
-
- /**
- * Put quotes around the given String if necessary.
- *
- * If the argument doesn't include spaces or quotes, return it as is. If it
- * contains double quotes, use single quotes - else surround the argument by
- * double quotes.
- *
- * @param argument Description of Parameter
- * @return Description of the Returned Value
- */
- public static String quoteArgument( String argument )
- throws TaskException
- {
- if( argument.indexOf( "\"" ) > -1 )
- {
- if( argument.indexOf( "\'" ) > -1 )
- {
- throw new TaskException( "Can\'t handle single and double quotes in same argument" );
- }
- else
- {
- return '\'' + argument + '\'';
- }
- }
- else if( argument.indexOf( "\'" ) > -1 || argument.indexOf( " " ) > -1 )
- {
- return '\"' + argument + '\"';
- }
- else
- {
- return argument;
- }
- }
-
- public static String[] translateCommandline( Path to_process )
- throws TaskException
- {
- return translateCommandline( to_process.toString() );
- }
-
- public static String[] translateCommandline( String to_process )
- throws TaskException
- {
- if( to_process == null || to_process.length() == 0 )
- {
- return new String[ 0 ];
- }
-
- // parse with a simple finite state machine
-
- final int normal = 0;
- final int inQuote = 1;
- final int inDoubleQuote = 2;
- int state = normal;
- StringTokenizer tok = new StringTokenizer( to_process, "\"\' ", true );
- ArrayList v = new ArrayList();
- StringBuffer current = new StringBuffer();
-
- while( tok.hasMoreTokens() )
- {
- String nextTok = tok.nextToken();
- 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 )
- {
- v.add( current.toString() );
- current.setLength( 0 );
- }
- }
- else
- {
- current.append( nextTok );
- }
- break;
- }
- }
-
- if( current.length() != 0 )
- {
- v.add( current.toString() );
- }
-
- if( state == inQuote || state == inDoubleQuote )
- {
- throw new TaskException( "unbalanced quotes in " + to_process );
- }
-
- final String[] args = new String[ v.size() ];
- return (String[])v.toArray( args );
- }
-
- /**
- * Returns its argument with all file separator characters replaced so that
- * they match the local OS conventions.
- */
- public static String translateFile( final String source )
- {
- if( source == null )
- {
- return "";
- }
-
- final StringBuffer result = new StringBuffer( source );
- translateFileSep( result );
- return result.toString();
- }
-
- /**
- * Translates all occurrences of / or \ to correct separator of the current
- * platform and returns whether it had to do any replacements.
- */
- public static void translateFileSep( StringBuffer buffer )
- {
- int len = buffer.length();
- for( int pos = 0; pos < len; pos++ )
- {
- char ch = buffer.charAt( pos );
- if( ch == '/' || ch == '\\' )
- {
- buffer.setCharAt( pos, File.separatorChar );
- }
- }
- }
-
- /**
- * Splits a PATH (with : or ; as separators) into its parts.
- */
- public static String[] translatePath( final File baseDirectory,
- String source )
- throws TaskException
- {
- final ArrayList result = new ArrayList();
- if( source == null )
- {
- return new String[ 0 ];
- }
-
- final String[] elements = parsePath( source );
- StringBuffer element = new StringBuffer();
- for( int i = 0; i < elements.length; i++ )
- {
- // Resolve the file relative to the base directory
- element.setLength( 0 );
- final String pathElement = elements[ i ];
- element.append( resolveFile( baseDirectory, pathElement ) );
-
- // Tidy up the separators
- translateFileSep( element );
- result.add( element.toString() );
- }
-
- return (String[])result.toArray( new String[ result.size() ] );
- }
-
- /**
- * Resolve a filename with Project's help - if we know one that is.
- *
- * Assume the filename is absolute if project is null.
- */
- public static String resolveFile( final File baseDirectory, final String relativeName )
- throws TaskException
- {
- if( null != baseDirectory )
- {
- final File file = FileUtil.resolveFile( baseDirectory, relativeName );
- return file.getAbsolutePath();
- }
- return relativeName;
- }
-}
-
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/PathTokenizer.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/PathTokenizer.java
deleted file mode 100644
index e00b87490..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/PathTokenizer.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util;
-
-import java.io.File;
-import java.util.NoSuchElementException;
-import java.util.StringTokenizer;
-
-/**
- * A Path tokenizer takes a path and returns the components that make up that
- * path. The path can use path separators of either ':' or ';' and file
- * separators of either '/' or '\'
- *
- * @author Conor MacNeill (conor@ieee.org)
- */
-class PathTokenizer
-{
- /**
- * A String which stores any path components which have been read ahead.
- */
- private String m_lookahead;
-
- /**
- * Flag to indicate whether we are running on a platform with a DOS style
- * filesystem
- */
- private boolean m_dosStyleFilesystem;
- /**
- * A tokenizer to break the string up based on the ':' or ';' separators.
- */
- private StringTokenizer m_tokenizer;
-
- public PathTokenizer( String path )
- {
- m_tokenizer = new StringTokenizer( path, ":;", false );
- m_dosStyleFilesystem = File.pathSeparatorChar == ';';
- }
-
- public boolean hasNext()
- {
- if( m_lookahead != null )
- {
- return true;
- }
-
- return m_tokenizer.hasMoreTokens();
- }
-
- public String next()
- throws NoSuchElementException
- {
- String token = null;
- if( m_lookahead != null )
- {
- token = m_lookahead;
- m_lookahead = null;
- }
- else
- {
- token = m_tokenizer.nextToken().trim();
- }
-
- if( token.length() == 1 && Character.isLetter( token.charAt( 0 ) )
- && m_dosStyleFilesystem
- && m_tokenizer.hasMoreTokens() )
- {
- // we are on a dos style system so this path could be a drive
- // spec. We look at the next token
- String nextToken = m_tokenizer.nextToken().trim();
- if( nextToken.startsWith( "\\" ) || nextToken.startsWith( "/" ) )
- {
- // we know we are on a DOS style platform and the next path starts with a
- // slash or backslash, so we know this is a drive spec
- token += ":" + nextToken;
- }
- else
- {
- // store the token just read for next time
- m_lookahead = nextToken;
- }
- }
-
- return token;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/depend/Dependencies.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/depend/Dependencies.java
deleted file mode 100644
index b4fa1daec..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/depend/Dependencies.java
+++ /dev/null
@@ -1,366 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.depend;
-
-import java.io.File;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.TreeSet;
-import org.apache.bcel.classfile.ClassParser;
-import org.apache.bcel.classfile.Code;
-import org.apache.bcel.classfile.CodeException;
-import org.apache.bcel.classfile.Constant;
-import org.apache.bcel.classfile.ConstantClass;
-import org.apache.bcel.classfile.ConstantDouble;
-import org.apache.bcel.classfile.ConstantFieldref;
-import org.apache.bcel.classfile.ConstantFloat;
-import org.apache.bcel.classfile.ConstantInteger;
-import org.apache.bcel.classfile.ConstantInterfaceMethodref;
-import org.apache.bcel.classfile.ConstantLong;
-import org.apache.bcel.classfile.ConstantMethodref;
-import org.apache.bcel.classfile.ConstantNameAndType;
-import org.apache.bcel.classfile.ConstantPool;
-import org.apache.bcel.classfile.ConstantString;
-import org.apache.bcel.classfile.ConstantUtf8;
-import org.apache.bcel.classfile.ConstantValue;
-import org.apache.bcel.classfile.Deprecated;
-import org.apache.bcel.classfile.ExceptionTable;
-import org.apache.bcel.classfile.Field;
-import org.apache.bcel.classfile.InnerClass;
-import org.apache.bcel.classfile.InnerClasses;
-import org.apache.bcel.classfile.JavaClass;
-import org.apache.bcel.classfile.LineNumber;
-import org.apache.bcel.classfile.LineNumberTable;
-import org.apache.bcel.classfile.LocalVariable;
-import org.apache.bcel.classfile.LocalVariableTable;
-import org.apache.bcel.classfile.Method;
-import org.apache.bcel.classfile.SourceFile;
-import org.apache.bcel.classfile.StackMap;
-import org.apache.bcel.classfile.StackMapEntry;
-import org.apache.bcel.classfile.Synthetic;
-import org.apache.bcel.classfile.Unknown;
-import org.apache.bcel.classfile.Visitor;
-
-public class Dependencies implements Visitor
-{
- private boolean verbose = false;
- private Set dependencies = new HashSet();
- private ConstantPool constantPool;
-
- private JavaClass javaClass;
-
- public static void applyFilter( Collection collection, Filter filter )
- {
- Iterator i = collection.iterator();
- while( i.hasNext() )
- {
- Object next = i.next();
- if( !filter.accept( next ) )
- {
- i.remove();
- }
- }
- }
-
- public static void main( String[] args )
- {
- try
- {
- Dependencies visitor = new Dependencies();
-
- Set set = new TreeSet();
- Set newSet = new HashSet();
-
- int o = 0;
- String arg = null;
- if( "-base".equals( args[ 0 ] ) )
- {
- arg = args[ 1 ];
- if( !arg.endsWith( File.separator ) )
- {
- arg = arg + File.separator;
- }
- o = 2;
- }
- final String base = arg;
-
- for( int i = o; i < args.length; i++ )
- {
- String fileName = args[ i ].substring( 0, args[ i ].length() - ".class".length() );
- if( base != null && fileName.startsWith( base ) )
- {
- fileName = fileName.substring( base.length() );
- }
- newSet.add( fileName );
- }
- set.addAll( newSet );
-
- do
- {
- Iterator i = newSet.iterator();
- while( i.hasNext() )
- {
- String fileName = i.next() + ".class";
-
- if( base != null )
- {
- fileName = base + fileName;
- }
-
- JavaClass javaClass = new ClassParser( fileName ).parse();
- javaClass.accept( visitor );
- }
- newSet.clear();
- newSet.addAll( visitor.getDependencies() );
- visitor.clearDependencies();
-
- applyFilter( newSet,
- new Filter()
- {
- public boolean accept( Object object )
- {
- String fileName = object + ".class";
- if( base != null )
- {
- fileName = base + fileName;
- }
- return new File( fileName ).exists();
- }
- } );
- newSet.removeAll( set );
- set.addAll( newSet );
- } while( newSet.size() > 0 );
-
- Iterator i = set.iterator();
- while( i.hasNext() )
- {
- System.out.println( i.next() );
- }
- }
- catch( Exception e )
- {
- System.err.println( e.getMessage() );
- e.printStackTrace( System.err );
- }
- }
-
- public Set getDependencies()
- {
- return dependencies;
- }
-
- public void clearDependencies()
- {
- dependencies.clear();
- }
-
- public void visitCode( Code obj )
- {
- }
-
- public void visitCodeException( CodeException obj )
- {
- }
-
- public void visitConstantClass( ConstantClass obj )
- {
- if( verbose )
- {
- System.out.println( "visit ConstantClass" );
- System.out.println( obj.getConstantValue( constantPool ) );
- }
- dependencies.add( "" + obj.getConstantValue( constantPool ) );
- }
-
- public void visitConstantDouble( ConstantDouble obj )
- {
- }
-
- public void visitConstantFieldref( ConstantFieldref obj )
- {
- }
-
- public void visitConstantFloat( ConstantFloat obj )
- {
- }
-
- public void visitConstantInteger( ConstantInteger obj )
- {
- }
-
- public void visitConstantInterfaceMethodref( ConstantInterfaceMethodref obj )
- {
- }
-
- public void visitConstantLong( ConstantLong obj )
- {
- }
-
- public void visitConstantMethodref( ConstantMethodref obj )
- {
- }
-
- public void visitConstantNameAndType( ConstantNameAndType obj )
- {
- }
-
- public void visitConstantPool( ConstantPool obj )
- {
- if( verbose )
- {
- System.out.println( "visit ConstantPool" );
- }
- this.constantPool = obj;
-
- // visit constants
- for( int idx = 0; idx < constantPool.getLength(); idx++ )
- {
- Constant c = constantPool.getConstant( idx );
- if( c != null )
- {
- c.accept( this );
- }
- }
- }
-
- public void visitConstantString( ConstantString obj )
- {
- }
-
- public void visitConstantUtf8( ConstantUtf8 obj )
- {
- }
-
- public void visitConstantValue( ConstantValue obj )
- {
- }
-
- public void visitDeprecated( Deprecated obj )
- {
- }
-
- public void visitExceptionTable( ExceptionTable obj )
- {
- }
-
- public void visitField( Field obj )
- {
- if( verbose )
- {
- System.out.println( "visit Field" );
- System.out.println( obj.getSignature() );
- }
- addClasses( obj.getSignature() );
- }
-
- public void visitInnerClass( InnerClass obj )
- {
- }
-
- public void visitInnerClasses( InnerClasses obj )
- {
- }
-
- public void visitJavaClass( JavaClass obj )
- {
- if( verbose )
- {
- System.out.println( "visit JavaClass" );
- }
-
- this.javaClass = obj;
- dependencies.add( javaClass.getClassName().replace( '.', '/' ) );
-
- // visit constant pool
- javaClass.getConstantPool().accept( this );
-
- // visit fields
- Field[] fields = obj.getFields();
- for( int i = 0; i < fields.length; i++ )
- {
- fields[ i ].accept( this );
- }
-
- // visit methods
- Method[] methods = obj.getMethods();
- for( int i = 0; i < methods.length; i++ )
- {
- methods[ i ].accept( this );
- }
- }
-
- public void visitLineNumber( LineNumber obj )
- {
- }
-
- public void visitLineNumberTable( LineNumberTable obj )
- {
- }
-
- public void visitLocalVariable( LocalVariable obj )
- {
- }
-
- public void visitLocalVariableTable( LocalVariableTable obj )
- {
- }
-
- public void visitMethod( Method obj )
- {
- if( verbose )
- {
- System.out.println( "visit Method" );
- System.out.println( obj.getSignature() );
- }
- String signature = obj.getSignature();
- int pos = signature.indexOf( ")" );
- addClasses( signature.substring( 1, pos ) );
- addClasses( signature.substring( pos + 1 ) );
- }
-
- public void visitSourceFile( SourceFile obj )
- {
- }
-
- public void visitStackMap( StackMap obj )
- {
- }
-
- public void visitStackMapEntry( StackMapEntry obj )
- {
- }
-
- public void visitSynthetic( Synthetic obj )
- {
- }
-
- public void visitUnknown( Unknown obj )
- {
- }
-
- void addClass( String string )
- {
- int pos = string.indexOf( 'L' );
- if( pos != -1 )
- {
- dependencies.add( string.substring( pos + 1 ) );
- }
- }
-
- void addClasses( String string )
- {
- StringTokenizer tokens = new StringTokenizer( string, ";" );
- while( tokens.hasMoreTokens() )
- {
- addClass( tokens.nextToken() );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/depend/Filter.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/depend/Filter.java
deleted file mode 100644
index d66601388..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/depend/Filter.java
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.depend;
-
-public interface Filter
-{
- boolean accept( Object object );
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/mappers/GlobPatternMapper.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/mappers/GlobPatternMapper.java
deleted file mode 100644
index ebbd3e92d..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/mappers/GlobPatternMapper.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.mappers;
-
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.FileNameMapper;
-
-/**
- * Implementation of FileNameMapper that does simple wildcard pattern
- * replacements.
- *
- * This does simple translations like *.foo -> *.bar where the prefix to .foo
- * will be left unchanged. It only handles a single * character, use regular
- * expressions for more complicated situations.
- *
- * This is one of the more useful Mappers, it is used by javac for example.
- *
- * @author Stefan Bodewig
- *
- * @ant:type type="mapper" name="glob"
- */
-public class GlobPatternMapper
- implements FileNameMapper
-{
- /**
- * Part of "from" pattern before the *.
- */
- private String m_fromPrefix;
-
- /**
- * Part of "from" pattern after the *.
- */
- private String m_fromPostfix;
-
- /**
- * Part of "to" pattern before the *.
- */
- private String m_toPrefix;
-
- /**
- * Part of "to" pattern after the *.
- */
- private String m_toPostfix;
-
- /**
- * Length of the postfix ("from" pattern).
- */
- private int m_postfixLength;
-
- /**
- * Length of the prefix ("from" pattern).
- */
- private int m_prefixLength;
-
- /**
- * Sets the "from" pattern. Required.
- *
- * @param from The new From value
- */
- public void setFrom( final String from )
- {
- final int index = from.lastIndexOf( "*" );
- if( index == -1 )
- {
- m_fromPrefix = from;
- m_fromPostfix = "";
- }
- else
- {
- m_fromPrefix = from.substring( 0, index );
- m_fromPostfix = from.substring( index + 1 );
- }
- m_prefixLength = m_fromPrefix.length();
- m_postfixLength = m_fromPostfix.length();
- }
-
- /**
- * Sets the "to" pattern. Required.
- *
- * @param to The new To value
- */
- public void setTo( final String to )
- {
- final int index = to.lastIndexOf( "*" );
- if( index == -1 )
- {
- m_toPrefix = to;
- m_toPostfix = "";
- }
- else
- {
- m_toPrefix = to.substring( 0, index );
- m_toPostfix = to.substring( index + 1 );
- }
- }
-
- /**
- * Returns null if the source file name doesn't match the "from"
- * pattern, an one-element array containing the translated file otherwise.
- *
- * @param sourceFileName Description of Parameter
- * @return Description of the Returned Value
- */
- public String[] mapFileName( final String sourceFileName, TaskContext context )
- {
- if( m_fromPrefix == null ||
- !sourceFileName.startsWith( m_fromPrefix ) ||
- !sourceFileName.endsWith( m_fromPostfix ) )
- {
- return null;
- }
- else
- {
- final String result = m_toPrefix +
- extractVariablePart( sourceFileName ) + m_toPostfix;
- return new String[]{result};
- }
- }
-
- /**
- * Returns the part of the given string that matches the * in the
- * "from" pattern.
- *
- * @param name Description of Parameter
- * @return Description of the Returned Value
- */
- private String extractVariablePart( final String name )
- {
- return name.substring( m_prefixLength,
- name.length() - m_postfixLength );
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/mappers/IdentityMapper.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/mappers/IdentityMapper.java
deleted file mode 100644
index 5f82165ee..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/mappers/IdentityMapper.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.mappers;
-
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.framework.FileNameMapper;
-
-/**
- * Implementation of FileNameMapper that always returns the source file name.
- *
- *
- * @author Stefan Bodewig
- *
- * @ant:type type="mapper" name="identity"
- */
-public class IdentityMapper
- implements FileNameMapper
-{
- /**
- * Returns an one-element array containing the source file name.
- *
- * @param sourceFileName Description of Parameter
- * @return Description of the Returned Value
- */
- public String[] mapFileName( final String sourceFileName, TaskContext context )
- {
- return new String[]{ sourceFileName };
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/mappers/MergingMapper.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/mappers/MergingMapper.java
deleted file mode 100644
index 690d0208d..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/mappers/MergingMapper.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.mappers;
-
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.FileNameMapper;
-
-/**
- * Implementation of FileNameMapper that always returns the same target file
- * name.
- *
- * @author Stefan Bodewig
- *
- * @ant:type type="mapper" name="merge"
- */
-public class MergingMapper
- implements FileNameMapper
-{
- private String[] m_mergedFile;
-
- /**
- * Sets the name of the merged file.
- *
- * @param to The new To value
- */
- public void setTo( final String to )
- {
- m_mergedFile = new String[]{ to };
- }
-
- /**
- * Returns an one-element array containing the file name set via setTo.
- *
- * @param sourceFileName Description of Parameter
- * @return Description of the Returned Value
- */
- public String[] mapFileName( final String sourceFileName, TaskContext context )
- throws TaskException
- {
- if( m_mergedFile == null )
- {
- throw new TaskException( "Destination file was not specified." );
- }
- return m_mergedFile;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/mappers/RegexpPatternMapper.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/mappers/RegexpPatternMapper.java
deleted file mode 100644
index ad3e2d3a8..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/mappers/RegexpPatternMapper.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.mappers;
-
-import java.util.ArrayList;
-import org.apache.myrmidon.api.TaskContext;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.FileNameMapper;
-import org.apache.tools.todo.util.regexp.RegexpMatcher;
-import org.apache.tools.todo.util.regexp.RegexpMatcherFactory;
-
-/**
- * Implementation of FileNameMapper that does regular expression replacements.
- *
- * @author Stefan Bodewig
- *
- * @ant:type type="mapper" name="regexp"
- */
-public class RegexpPatternMapper
- implements FileNameMapper
-{
- private RegexpMatcher m_matcher;
- private char[] m_to;
- private StringBuffer m_result = new StringBuffer();
-
- public RegexpPatternMapper()
- throws TaskException
- {
- m_matcher = ( new RegexpMatcherFactory() ).newRegexpMatcher();
- }
-
- /**
- * Sets the "from" pattern. Required.
- */
- public void setFrom( final String from )
- throws TaskException
- {
- try
- {
- m_matcher.setPattern( from );
- }
- catch( NoClassDefFoundError e )
- {
- // depending on the implementation the actual RE won't
- // get instantiated in the constructor.
- throw new TaskException( "Cannot load regular expression matcher", e );
- }
- }
-
- /**
- * Sets the "to" pattern. Required.
- *
- * @param to The new To value
- */
- public void setTo( final String to )
- {
- m_to = to.toCharArray();
- }
-
- /**
- * Returns null if the source file name doesn't match the "from"
- * pattern, an one-element array containing the translated file otherwise.
- *
- * @param sourceFileName Description of Parameter
- * @return Description of the Returned Value
- */
- public String[] mapFileName( final String sourceFileName, TaskContext context )
- throws TaskException
- {
- if( m_matcher == null || m_to == null ||
- !m_matcher.matches( sourceFileName ) )
- {
- return null;
- }
- else
- {
- return new String[]{replaceReferences( sourceFileName )};
- }
- }
-
- /**
- * Replace all backreferences in the to pattern with the matched groups of
- * the source.
- */
- private String replaceReferences( final String source )
- throws TaskException
- {
- final ArrayList groups = m_matcher.getGroups( source );
-
- m_result.setLength( 0 );
- for( int i = 0; i < m_to.length; i++ )
- {
- if( m_to[ i ] == '\\' )
- {
- if( ++i < m_to.length )
- {
- final int value = Character.digit( m_to[ i ], 10 );
- if( value > -1 )
- {
- m_result.append( (String)groups.get( value ) );
- }
- else
- {
- m_result.append( m_to[ i ] );
- }
- }
- else
- {
- // XXX - should throw an exception instead?
- m_result.append( '\\' );
- }
- }
- else
- {
- m_result.append( m_to[ i ] );
- }
- }
- return m_result.toString();
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/JakartaOroMatcher.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/JakartaOroMatcher.java
deleted file mode 100644
index fe7493511..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/JakartaOroMatcher.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.regexp;
-
-import java.util.ArrayList;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.oro.text.regex.MatchResult;
-import org.apache.oro.text.regex.Pattern;
-import org.apache.oro.text.regex.Perl5Compiler;
-import org.apache.oro.text.regex.Perl5Matcher;
-
-/**
- * Implementation of RegexpMatcher for Jakarta-ORO.
- *
- * @author Stefan Bodewig
- * @author Matthew Inger
- */
-public class JakartaOroMatcher implements RegexpMatcher
-{
- protected final Perl5Compiler compiler = new Perl5Compiler();
- protected final Perl5Matcher matcher = new Perl5Matcher();
-
- private String pattern;
-
- public JakartaOroMatcher()
- {
- }
-
- /**
- * Set the regexp pattern from the String description.
- *
- * @param pattern The new Pattern value
- */
- public void setPattern( String pattern )
- {
- this.pattern = pattern;
- }
-
- /**
- * Returns a ArrayList of matched groups found in the argument.
- *
- * Group 0 will be the full match, the rest are the parenthesized
- * subexpressions
.
- *
- * @param argument Description of Parameter
- * @return The Groups value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public ArrayList getGroups( String argument )
- throws TaskException
- {
- return getGroups( argument, MATCH_DEFAULT );
- }
-
- /**
- * Returns a ArrayList of matched groups found in the argument.
- *
- * Group 0 will be the full match, the rest are the parenthesized
- * subexpressions
.
- *
- * @param input Description of Parameter
- * @param options Description of Parameter
- * @return The Groups value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public ArrayList getGroups( String input, int options )
- throws TaskException
- {
- if( !matches( input, options ) )
- {
- return null;
- }
- ArrayList v = new ArrayList();
- MatchResult mr = matcher.getMatch();
- int cnt = mr.groups();
- for( int i = 0; i < cnt; i++ )
- {
- v.add( mr.group( i ) );
- }
- return v;
- }
-
- /**
- * Get a String representation of the regexp pattern
- *
- * @return The Pattern value
- */
- public String getPattern()
- {
- return this.pattern;
- }
-
- /**
- * Does the given argument match the pattern?
- *
- * @param argument Description of Parameter
- * @return Description of the Returned Value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public boolean matches( String argument )
- throws TaskException
- {
- return matches( argument, MATCH_DEFAULT );
- }
-
- /**
- * Does the given argument match the pattern?
- *
- * @param input Description of Parameter
- * @param options Description of Parameter
- * @return Description of the Returned Value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public boolean matches( String input, int options )
- throws TaskException
- {
- Pattern p = getCompiledPattern( options );
- return matcher.contains( input, p );
- }
-
- /**
- * Get a compiled representation of the regexp pattern
- *
- * @param options Description of Parameter
- * @return The CompiledPattern value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- protected Pattern getCompiledPattern( int options )
- throws TaskException
- {
- try
- {
- // compute the compiler options based on the input options first
- Pattern p = compiler.compile( pattern, getCompilerOptions( options ) );
- return p;
- }
- catch( Exception e )
- {
- throw new TaskException( "Error", e );
- }
- }
-
- protected int getCompilerOptions( int options )
- {
- int cOptions = Perl5Compiler.DEFAULT_MASK;
-
- if( RegexpUtil.hasFlag( options, MATCH_CASE_INSENSITIVE ) )
- {
- cOptions |= Perl5Compiler.CASE_INSENSITIVE_MASK;
- }
- if( RegexpUtil.hasFlag( options, MATCH_MULTILINE ) )
- {
- cOptions |= Perl5Compiler.MULTILINE_MASK;
- }
- if( RegexpUtil.hasFlag( options, MATCH_SINGLELINE ) )
- {
- cOptions |= Perl5Compiler.SINGLELINE_MASK;
- }
-
- return cOptions;
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/JakartaOroRegexp.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/JakartaOroRegexp.java
deleted file mode 100644
index 7e0a8d588..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/JakartaOroRegexp.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.regexp;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.oro.text.regex.Perl5Substitution;
-import org.apache.oro.text.regex.Substitution;
-import org.apache.oro.text.regex.Util;
-import org.apache.tools.todo.util.regexp.JakartaOroMatcher;
-
-/**
- * Regular expression implementation using the Jakarta Oro package
- *
- * @author Matthew Inger
- * mattinger@mindless.com
- */
-public class JakartaOroRegexp extends JakartaOroMatcher implements Regexp
-{
-
- public JakartaOroRegexp()
- {
- super();
- }
-
- public String substitute( String input, String argument, int options )
- throws TaskException
- {
- // translate \1 to $1 so that the Perl5Substitution will work
- StringBuffer subst = new StringBuffer();
- for( int i = 0; i < argument.length(); i++ )
- {
- char c = argument.charAt( i );
- if( c == '\\' )
- {
- if( ++i < argument.length() )
- {
- c = argument.charAt( i );
- int value = Character.digit( c, 10 );
- if( value > -1 )
- {
- subst.append( "$" ).append( value );
- }
- else
- {
- subst.append( c );
- }
- }
- else
- {
- // XXX - should throw an exception instead?
- subst.append( '\\' );
- }
- }
- else
- {
- subst.append( c );
- }
- }
-
- // Do the substitution
- Substitution s =
- new Perl5Substitution( subst.toString(),
- Perl5Substitution.INTERPOLATE_ALL );
- return Util.substitute( matcher,
- getCompiledPattern( options ),
- s,
- input,
- getSubsOptions( options ) );
- }
-
- protected int getSubsOptions( int options )
- {
- boolean replaceAll = RegexpUtil.hasFlag( options, REPLACE_ALL );
- int subsOptions = 1;
- if( replaceAll )
- {
- subsOptions = Util.SUBSTITUTE_ALL;
- }
- return subsOptions;
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/JakartaRegexpMatcher.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/JakartaRegexpMatcher.java
deleted file mode 100644
index f2a93b2cf..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/JakartaRegexpMatcher.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.regexp;
-
-import java.util.ArrayList;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.regexp.RE;
-import org.apache.regexp.RESyntaxException;
-
-/**
- * Implementation of RegexpMatcher for Jakarta-Regexp.
- *
- * @author Stefan Bodewig
- * @author Matthew Inger
- * mattinger@mindless.com
- */
-public class JakartaRegexpMatcher implements RegexpMatcher
-{
-
- private String pattern;
-
- /**
- * Set the regexp pattern from the String description.
- *
- * @param pattern The new Pattern value
- */
- public void setPattern( String pattern )
- {
- this.pattern = pattern;
- }
-
- /**
- * Returns a ArrayList of matched groups found in the argument.
- *
- * Group 0 will be the full match, the rest are the parenthesized
- * subexpressions
.
- *
- * @param argument Description of Parameter
- * @return The Groups value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public ArrayList getGroups( String argument )
- throws TaskException
- {
- return getGroups( argument, MATCH_DEFAULT );
- }
-
- public ArrayList getGroups( String input, int options )
- throws TaskException
- {
- RE reg = getCompiledPattern( options );
- if( !matches( input, reg ) )
- {
- return null;
- }
- ArrayList v = new ArrayList();
- int cnt = reg.getParenCount();
- for( int i = 0; i < cnt; i++ )
- {
- v.add( reg.getParen( i ) );
- }
- return v;
- }
-
- /**
- * Get a String representation of the regexp pattern
- *
- * @return The Pattern value
- */
- public String getPattern()
- {
- return pattern;
- }
-
- /**
- * Does the given argument match the pattern?
- *
- * @param argument Description of Parameter
- * @return Description of the Returned Value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public boolean matches( String argument )
- throws TaskException
- {
- return matches( argument, MATCH_DEFAULT );
- }
-
- /**
- * Does the given argument match the pattern?
- *
- * @param input Description of Parameter
- * @param options Description of Parameter
- * @return Description of the Returned Value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public boolean matches( String input, int options )
- throws TaskException
- {
- return matches( input, getCompiledPattern( options ) );
- }
-
- protected RE getCompiledPattern( int options )
- throws TaskException
- {
- int cOptions = getCompilerOptions( options );
- try
- {
- RE reg = new RE( pattern );
- reg.setMatchFlags( cOptions );
- return reg;
- }
- catch( RESyntaxException e )
- {
- throw new TaskException( e );
- }
- }
-
- protected int getCompilerOptions( int options )
- {
- int cOptions = RE.MATCH_NORMAL;
-
- if( RegexpUtil.hasFlag( options, MATCH_CASE_INSENSITIVE ) )
- {
- cOptions |= RE.MATCH_CASEINDEPENDENT;
- }
- if( RegexpUtil.hasFlag( options, MATCH_MULTILINE ) )
- {
- cOptions |= RE.MATCH_MULTILINE;
- }
- if( RegexpUtil.hasFlag( options, MATCH_SINGLELINE ) )
- {
- cOptions |= RE.MATCH_SINGLELINE;
- }
-
- return cOptions;
- }
-
- private boolean matches( String input, RE reg )
- {
- return reg.match( input );
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/JakartaRegexpRegexp.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/JakartaRegexpRegexp.java
deleted file mode 100644
index e2053afb7..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/JakartaRegexpRegexp.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.regexp;
-
-import java.util.ArrayList;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.regexp.RE;
-import org.apache.tools.todo.util.regexp.JakartaRegexpMatcher;
-
-/**
- * Regular expression implementation using the Jakarta Regexp package
- *
- * @author Matthew Inger
- * mattinger@mindless.com
- */
-public class JakartaRegexpRegexp extends JakartaRegexpMatcher implements Regexp
-{
-
- public JakartaRegexpRegexp()
- {
- super();
- }
-
- public String substitute( String input, String argument, int options )
- throws TaskException
- {
- ArrayList v = getGroups( input, options );
-
- // replace \1 with the corresponding group
- StringBuffer result = new StringBuffer();
- for( int i = 0; i < argument.length(); i++ )
- {
- char c = argument.charAt( i );
- if( c == '\\' )
- {
- if( ++i < argument.length() )
- {
- c = argument.charAt( i );
- int value = Character.digit( c, 10 );
- if( value > -1 )
- {
- result.append( (String)v.get( value ) );
- }
- else
- {
- result.append( c );
- }
- }
- else
- {
- // XXX - should throw an exception instead?
- result.append( '\\' );
- }
- }
- else
- {
- result.append( c );
- }
- }
- argument = result.toString();
-
- RE reg = getCompiledPattern( options );
- int sOptions = getSubsOptions( options );
- return reg.subst( input, argument, sOptions );
- }
-
- protected int getSubsOptions( int options )
- {
- int subsOptions = RE.REPLACE_FIRSTONLY;
- if( RegexpUtil.hasFlag( options, REPLACE_ALL ) )
- {
- subsOptions = RE.REPLACE_ALL;
- }
- return subsOptions;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/Jdk14RegexpMatcher.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/Jdk14RegexpMatcher.java
deleted file mode 100644
index 38ab56ba0..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/Jdk14RegexpMatcher.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.regexp;
-
-import java.util.ArrayList;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * Implementation of RegexpMatcher for the built-in regexp matcher of JDK 1.4.
- *
- * @author Stefan Bodewig
- * @author Matthew Inger
- * mattinger@mindless.com
- */
-public class Jdk14RegexpMatcher implements RegexpMatcher
-{
-
- private String pattern;
-
- public Jdk14RegexpMatcher()
- {
- }
-
- /**
- * Set the regexp pattern from the String description.
- *
- * @param pattern The new Pattern value
- */
- public void setPattern( String pattern )
- {
- this.pattern = pattern;
- }
-
- /**
- * Returns a ArrayList of matched groups found in the argument.
- *
- * Group 0 will be the full match, the rest are the parenthesized
- * subexpressions
.
- *
- * @param argument Description of Parameter
- * @return The Groups value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public ArrayList getGroups( String argument )
- throws TaskException
- {
- return getGroups( argument, MATCH_DEFAULT );
- }
-
- /**
- * Returns a ArrayList of matched groups found in the argument.
- *
- * Group 0 will be the full match, the rest are the parenthesized
- * subexpressions
.
- *
- * @param input Description of Parameter
- * @param options Description of Parameter
- * @return The Groups value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public ArrayList getGroups( String input, int options )
- throws TaskException
- {
- Pattern p = getCompiledPattern( options );
- Matcher matcher = p.matcher( input );
- if( !matcher.find() )
- {
- return null;
- }
- ArrayList v = new ArrayList();
- int cnt = matcher.groupCount();
- for( int i = 0; i <= cnt; i++ )
- {
- v.add( matcher.group( i ) );
- }
- return v;
- }
-
- /**
- * Get a String representation of the regexp pattern
- *
- * @return The Pattern value
- */
- public String getPattern()
- {
- return pattern;
- }
-
- /**
- * Does the given argument match the pattern?
- *
- * @param argument Description of Parameter
- * @return Description of the Returned Value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public boolean matches( String argument )
- throws TaskException
- {
- return matches( argument, MATCH_DEFAULT );
- }
-
- /**
- * Does the given argument match the pattern?
- *
- * @param input Description of Parameter
- * @param options Description of Parameter
- * @return Description of the Returned Value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public boolean matches( String input, int options )
- throws TaskException
- {
- try
- {
- Pattern p = getCompiledPattern( options );
- return p.matcher( input ).find();
- }
- catch( Exception e )
- {
- throw new TaskException( "Error", e );
- }
- }
-
- protected Pattern getCompiledPattern( int options )
- throws TaskException
- {
- int cOptions = getCompilerOptions( options );
- try
- {
- Pattern p = Pattern.compile( this.pattern, cOptions );
- return p;
- }
- catch( PatternSyntaxException e )
- {
- throw new TaskException( e );
- }
- }
-
- protected int getCompilerOptions( int options )
- {
- int cOptions = 0;
-
- if( RegexpUtil.hasFlag( options, MATCH_CASE_INSENSITIVE ) )
- {
- cOptions |= Pattern.CASE_INSENSITIVE;
- }
- if( RegexpUtil.hasFlag( options, MATCH_MULTILINE ) )
- {
- cOptions |= Pattern.MULTILINE;
- }
- if( RegexpUtil.hasFlag( options, MATCH_SINGLELINE ) )
- {
- cOptions |= Pattern.DOTALL;
- }
-
- return cOptions;
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/Jdk14RegexpRegexp.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/Jdk14RegexpRegexp.java
deleted file mode 100644
index e98a2a83e..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/Jdk14RegexpRegexp.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.regexp;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.util.regexp.Jdk14RegexpMatcher;
-
-/**
- * Regular expression implementation using the JDK 1.4 regular expression
- * package
- *
- * @author Matthew Inger
- * mattinger@mindless.com
- */
-public class Jdk14RegexpRegexp extends Jdk14RegexpMatcher implements Regexp
-{
-
- public Jdk14RegexpRegexp()
- {
- super();
- }
-
- public String substitute( String input, String argument, int options )
- throws TaskException
- {
- // translate \1 to $(1) so that the Matcher will work
- StringBuffer subst = new StringBuffer();
- for( int i = 0; i < argument.length(); i++ )
- {
- char c = argument.charAt( i );
- if( c == '\\' )
- {
- if( ++i < argument.length() )
- {
- c = argument.charAt( i );
- int value = Character.digit( c, 10 );
- if( value > -1 )
- {
- subst.append( "$" ).append( value );
- }
- else
- {
- subst.append( c );
- }
- }
- else
- {
- // XXX - should throw an exception instead?
- subst.append( '\\' );
- }
- }
- else
- {
- subst.append( c );
- }
- }
- argument = subst.toString();
-
- int sOptions = getSubsOptions( options );
- Pattern p = getCompiledPattern( options );
- StringBuffer sb = new StringBuffer();
-
- Matcher m = p.matcher( input );
- if( RegexpUtil.hasFlag( sOptions, REPLACE_ALL ) )
- {
- sb.append( m.replaceAll( argument ) );
- }
- else
- {
- boolean res = m.find();
- if( res )
- {
- m.appendReplacement( sb, argument );
- m.appendTail( sb );
- }
- else
- {
- sb.append( input );
- }
- }
-
- return sb.toString();
- }
-
- protected int getSubsOptions( int options )
- {
- int subsOptions = REPLACE_FIRST;
- if( RegexpUtil.hasFlag( options, REPLACE_ALL ) )
- {
- subsOptions = REPLACE_ALL;
- }
- return subsOptions;
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/Regexp.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/Regexp.java
deleted file mode 100644
index cf6db2a98..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/Regexp.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.regexp;
-
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * Interface which represents a regular expression, and the operations that can
- * be performed on it.
- *
- * @author Matthew Inger
- */
-public interface Regexp
- extends RegexpMatcher
-{
- /**
- * Replace only the first occurance of the regular expression
- */
- int REPLACE_FIRST = 0x00000001;
-
- /**
- * Replace all occurances of the regular expression
- */
- int REPLACE_ALL = 0x00000010;
-
- /**
- * Perform a substitution on the regular expression.
- *
- * @param input The string to substitute on
- * @param argument The string which defines the substitution
- * @param options The list of options for the match and replace. See the
- * MATCH_ and REPLACE_ constants above.
- * @return Description of the Returned Value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- String substitute( String input, String argument, int options )
- throws TaskException;
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/RegexpFactory.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/RegexpFactory.java
deleted file mode 100644
index b1c2ece8c..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/RegexpFactory.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.regexp;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.util.regexp.Regexp;
-
-/**
- * Regular expression factory, which will create Regexp objects. The actual
- * implementation class depends on the System or Ant Property: ant.regexp.regexpimpl
- * .
- *
- * @author Matthew Inger
- * mattinger@mindless.com
- * @version $Revision$
- */
-public class RegexpFactory
- extends RegexpMatcherFactory
-{
- /**
- * Create a new regular expression matcher instance.
- */
- public Regexp newRegexp()
- throws TaskException
- {
- final String systemDefault = System.getProperty( "ant.regexp.regexpimpl" );
- if( systemDefault != null )
- {
- return createRegexpInstance( systemDefault );
- // XXX should we silently catch possible exceptions and try to
- // load a different implementation?
- }
-
- try
- {
- return createRegexpInstance( JDK14_REGEXP );
- }
- catch( TaskException be )
- {
- }
-
- try
- {
- return createRegexpInstance( JAKARTA_ORO );
- }
- catch( TaskException be )
- {
- }
-
- try
- {
- return createRegexpInstance( JAKARTA_REGEXP );
- }
- catch( TaskException be )
- {
- }
-
- final String message = "No supported regular expression matcher found";
- throw new TaskException( message );
- }
-
- /**
- * Wrapper over {@seee RegexpMatcherFactory#createInstance createInstance}
- * that ensures that we are dealing with a Regexp implementation.
- *
- * @param classname Description of Parameter
- * @return Description of the Returned Value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- * @since 1.3
- */
- private Regexp createRegexpInstance( final String classname )
- throws TaskException
- {
- final RegexpMatcher m = createInstance( classname );
- if( m instanceof Regexp )
- {
- return (Regexp)m;
- }
- else
- {
- throw new TaskException( classname + " doesn't implement the Regexp interface" );
- }
- }
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/RegexpMatcher.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/RegexpMatcher.java
deleted file mode 100644
index 680c876de..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/RegexpMatcher.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.regexp;
-
-import java.util.ArrayList;
-import org.apache.myrmidon.api.TaskException;
-
-/**
- * Interface describing a regular expression matcher.
- *
- * @author Stefan Bodewig
- * @author Matthew Inger
- */
-public interface RegexpMatcher
-{
-
- /**
- * Default Mask (case insensitive, neither multiline nor singleline
- * specified).
- */
- int MATCH_DEFAULT = 0x00000000;
-
- /**
- * Perform a case insenstive match
- */
- int MATCH_CASE_INSENSITIVE = 0x00000100;
-
- /**
- * Treat the input as a multiline input
- */
- int MATCH_MULTILINE = 0x00001000;
-
- /**
- * Treat the input as singleline input ('.' matches newline)
- */
- int MATCH_SINGLELINE = 0x00010000;
-
- /**
- * Set the regexp pattern from the String description.
- *
- * @param pattern The new Pattern value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- void setPattern( String pattern )
- throws TaskException;
-
- /**
- * Get a String representation of the regexp pattern
- *
- * @return The Pattern value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- String getPattern()
- throws TaskException;
-
- /**
- * Does the given argument match the pattern?
- *
- * @param argument Description of Parameter
- * @return Description of the Returned Value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- boolean matches( String argument )
- throws TaskException;
-
- /**
- * Returns a ArrayList of matched groups found in the argument.
- *
- * Group 0 will be the full match, the rest are the parenthesized
- * subexpressions
.
- *
- * @param argument Description of Parameter
- * @return The Groups value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- ArrayList getGroups( String argument )
- throws TaskException;
-
- /**
- * Does this regular expression match the input, given certain options
- *
- * @param input The string to check for a match
- * @param options The list of options for the match. See the MATCH_
- * constants above.
- * @return Description of the Returned Value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- boolean matches( String input, int options )
- throws TaskException;
-
- /**
- * Get the match groups from this regular expression. The return type of the
- * elements is always String.
- *
- * @param input The string to check for a match
- * @param options The list of options for the match. See the MATCH_
- * constants above.
- * @return The Groups value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- ArrayList getGroups( String input, int options )
- throws TaskException;
-
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/RegexpMatcherFactory.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/RegexpMatcherFactory.java
deleted file mode 100644
index 36b7bebf0..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/RegexpMatcherFactory.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.regexp;
-
-import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.todo.util.regexp.RegexpMatcher;
-
-/**
- * Simple Factory Class that produces an implementation of RegexpMatcher based
- * on the system property ant.regexp.matcherimpl
and the classes
- * available.
- *
- * In a more general framework this class would be abstract and have a static
- * newInstance method.
- *
- * @author Stefan Bodewig
- */
-public class RegexpMatcherFactory
-{
- protected final static String JAKARTA_REGEXP = "org.apache.tools.ant.util.regexp.JakartaRegexpRegexp";
- protected final static String JAKARTA_ORO = "org.apache.tools.ant.util.regexp.JakartaOroRegexp";
- protected final static String JDK14_REGEXP = "org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp";
-
- /**
- * Create a new regular expression instance.
- *
- * @param p Project whose ant.regexp.regexpimpl property will be used.
- * @return Description of the Returned Value
- * @exception org.apache.myrmidon.api.TaskException Description of Exception
- */
- public RegexpMatcher newRegexpMatcher()
- throws TaskException
- {
- final String systemDefault = System.getProperty( "ant.regexp.regexpimpl" );
- if( systemDefault != null )
- {
- return createInstance( systemDefault );
- // XXX should we silently catch possible exceptions and try to
- // load a different implementation?
- }
-
- try
- {
- return createInstance( JDK14_REGEXP );
- }
- catch( TaskException be )
- {
- }
-
- try
- {
- return createInstance( JAKARTA_ORO );
- }
- catch( TaskException be )
- {
- }
-
- try
- {
- return createInstance( JAKARTA_REGEXP );
- }
- catch( TaskException be )
- {
- }
-
- final String message = "No supported regular expression matcher found";
- throw new TaskException( message );
- }
-
- protected RegexpMatcher createInstance( final String className )
- throws TaskException
- {
- try
- {
- Class implClass = Class.forName( className );
- return (RegexpMatcher)implClass.newInstance();
- }
- catch( Throwable t )
- {
- throw new TaskException( "Error", t );
- }
- }
-}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/RegexpUtil.java b/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/RegexpUtil.java
deleted file mode 100644
index fe3ebb631..000000000
--- a/proposal/myrmidon/src/main/org/apache/tools/todo/util/regexp/RegexpUtil.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
- *
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE.txt file.
- */
-package org.apache.tools.todo.util.regexp;
-
-/**
- * Regular expression utilities class which handles flag operations
- *
- * @author Matthew Inger
- */
-public class RegexpUtil extends Object
-{
- public static final boolean hasFlag( int options, int flag )
- {
- return ( ( options & flag ) > 0 );
- }
-
- public static final int removeFlag( int options, int flag )
- {
- return ( options & ( 0xFFFFFFFF - flag ) );
- }
-}