diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ANTLR.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ANTLR.java deleted file mode 100644 index e56b7e133..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ANTLR.java +++ /dev/null @@ -1,197 +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.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.net.URL; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.java.ExecuteJava; -import org.apache.myrmidon.framework.nativelib.Argument; -import org.apache.myrmidon.framework.file.Path; - -/** - * ANTLR task. - * - * @author Erik Meade - * @author - * - * 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( final 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" ); - m_exe.getClassPath().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" ); - m_exe.getClassPath().addLocation( new File( dirName ) ); - } - else - { - getContext().debug( "Don\'t know how to handle resource URL " + u ); - } - } - else - { - getContext().debug( "Couldn\'t find " + resource ); - } - } - - private File getGeneratedFile() - throws TaskException - { - String generatedFileName = null; - try - { - BufferedReader in = new BufferedReader( new FileReader( m_target ) ); - String line; - while( ( line = in.readLine() ) != null ) - { - int extendsIndex = line.indexOf( " extends " ); - if( line.startsWith( "class " ) && extendsIndex > -1 ) - { - generatedFileName = line.substring( 6, extendsIndex ).trim(); - break; - } - } - in.close(); - } - catch( Exception e ) - { - throw new TaskException( "Unable to determine generated class", e ); - } - if( generatedFileName == null ) - { - throw new TaskException( "Unable to determine generated class" ); - } - return new File( m_outputDirectory, generatedFileName + ".java" ); - } - - private void validateAttributes() - throws TaskException - { - if( m_target == null || !m_target.isFile() ) - { - throw new TaskException( "Invalid target: " + m_target ); - } - - // if no output directory is specified, used the target's directory - if( m_outputDirectory == null ) - { - m_outputDirectory = m_target.getParentFile(); - } - if( !m_outputDirectory.isDirectory() ) - { - throw new TaskException( "Invalid output directory: " + m_outputDirectory ); - } - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Cab.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Cab.java deleted file mode 100644 index 4947df053..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Cab.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.taskdefs; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Iterator; -import org.apache.aut.nativelib.Os; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.nativelib.Execute; -import org.apache.myrmidon.framework.FileSet; -import org.apache.myrmidon.framework.nativelib.Commandline; -import org.apache.tools.todo.types.DirectoryScanner; -import org.apache.tools.todo.types.ScannerUtil; - -/** - * Create a CAB archive. - * - * @author
Roger Vaughn - */ -public class Cab - extends MatchingTask -{ - private ArrayList m_filesets = new ArrayList(); - private boolean m_compress = true; - private File m_baseDir; - private File m_cabFile; - private String m_options; - - /** - * This is the base directory to look in for things to cab. - * - * @param baseDir The new Basedir value - */ - public void setBasedir( final File baseDir ) - { - m_baseDir = baseDir; - } - - /** - * This is the name/location of where to create the .cab file. - * - * @param cabFile The new Cabfile value - */ - public void setCabfile( final File cabFile ) - { - m_cabFile = cabFile; - } - - /** - * 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; - } - - /** - * Sets additional cabarc options that aren't supported directly. - * - * @param options The new Options value - */ - public void setOptions( final String options ) - { - m_options = options; - } - - /** - * Adds a set of files (nested fileset attribute). - * - * @param set The feature to be added to the Fileset attribute - */ - public void addFileset( final FileSet set ) - { - m_filesets.add( set ); - } - - public void execute() - throws TaskException - { - checkConfiguration(); - - final ArrayList files = getFileList(); - - // quick exit if the target is up to date - if( isUpToDate( files ) ) - { - return; - } - - getContext().info( "Building cab: " + m_cabFile.getAbsolutePath() ); - - if( !Os.isFamily( Os.OS_FAMILY_WINDOWS ) ) - { - getContext().debug( "Using listcab/libcabinet" ); - - final StringBuffer sb = new StringBuffer(); - - final Iterator e = files.iterator(); - while( e.hasNext() ) - { - sb.append( e.next() ).append( "\n" ); - } - sb.append( "\n" ).append( m_cabFile.getAbsolutePath() ).append( "\n" ); - - try - { - Process p = Runtime.getRuntime().exec( "listcab" ); - OutputStream out = p.getOutputStream(); - out.write( sb.toString().getBytes() ); - out.flush(); - out.close(); - } - catch( IOException ex ) - { - String msg = "Problem creating " + m_cabFile + " " + ex.getMessage(); - throw new TaskException( msg ); - } - } - else - { - try - { - File listFile = createListFile( files ); - Execute exe = new Execute(); - exe.setWorkingDirectory( m_baseDir ); - createCommand( exe, listFile ); - exe.execute( getContext() ); - - listFile.delete(); - } - catch( final IOException ioe ) - { - final String message = - "Problem creating " + m_cabFile + " " + ioe.getMessage(); - throw new TaskException( message ); - } - } - } - - /** - * Get the complete list of files to be included in the cab. Filenames are - * gathered from filesets if any have been added, otherwise from the - * traditional include parameters. - */ - protected ArrayList getFileList() - throws TaskException - { - ArrayList files = new ArrayList(); - - if( m_filesets.size() == 0 ) - { - // get files from old methods - includes and nested include - appendFiles( files, super.getDirectoryScanner( m_baseDir ) ); - } - else - { - // get files from filesets - for( int i = 0; i < m_filesets.size(); i++ ) - { - FileSet fs = (FileSet)m_filesets.get( i ); - if( fs != null ) - { - appendFiles( files, ScannerUtil.getDirectoryScanner( fs ) ); - } - } - } - - return files; - } - - /** - * Check to see if the target is up to date with respect to input files. - * - * @param files Description of Parameter - * @return true if the cab file is newer than its dependents. - */ - protected boolean isUpToDate( ArrayList files ) - { - boolean upToDate = true; - for( int i = 0; i < files.size() && upToDate; i++ ) - { - String file = files.get( i ).toString(); - if( new File( m_baseDir, file ).lastModified() > - m_cabFile.lastModified() ) - { - upToDate = false; - } - } - return upToDate; - } - - /** - * Append all files found by a directory scanner to a vector. - * - * @param files Description of Parameter - * @param ds Description of Parameter - */ - protected void appendFiles( ArrayList files, DirectoryScanner ds ) - { - String[] dsfiles = ds.getIncludedFiles(); - - for( int i = 0; i < dsfiles.length; i++ ) - { - files.add( dsfiles[ i ] ); - } - } - - /* - * I'm not fond of this pattern: "sub-method expected to throw - * task-cancelling exceptions". It feels too much like programming - * for side-effects to me... - */ - protected void checkConfiguration() - throws TaskException - { - if( m_baseDir == null ) - { - throw new TaskException( "basedir attribute must be set!" ); - } - if( !m_baseDir.exists() ) - { - throw new TaskException( "basedir does not exist!" ); - } - if( m_cabFile == null ) - { - throw new TaskException( "cabfile attribute must be set!" ); - } - } - - /** - * Create the cabarc command line to use. - */ - protected void createCommand( final Commandline cmd, final File listFile ) - throws TaskException - { - cmd.setExecutable( "cabarc" ); - cmd.addArgument( "-r" ); - cmd.addArgument( "-p" ); - - if( !m_compress ) - { - cmd.addArgument( "-m" ); - cmd.addArgument( "none" ); - } - - if( m_options != null ) - { - cmd.addLine( m_options ); - } - - cmd.addArgument( "n" ); - cmd.addArgument( m_cabFile ); - cmd.addArgument( "@" + listFile.getAbsolutePath() ); - } - - /** - * Creates a list file. This temporary file contains a list of all files to - * be included in the cab, one file per line. - * - * @param files Description of Parameter - * @return Description of the Returned Value - * @exception java.io.IOException Description of Exception - */ - protected File createListFile( ArrayList files ) - throws IOException - { - File listFile = File.createTempFile( "ant", "", getBaseDirectory() ); - - PrintWriter writer = new PrintWriter( new FileOutputStream( listFile ) ); - - for( int i = 0; i < files.size(); i++ ) - { - writer.println( files.get( i ).toString() ); - } - writer.close(); - - return listFile; - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ClassArgument.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ClassArgument.java deleted file mode 100644 index 1b8323d3f..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/ClassArgument.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; - -public class ClassArgument -{ - private String m_name; - - public void setName( String name ) - { - m_name = name; - } - - public String getName() - { - return m_name; - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/DependSet.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/DependSet.java deleted file mode 100644 index 01149fad7..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/DependSet.java +++ /dev/null @@ -1,303 +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.Date; -import java.util.Iterator; -import org.apache.aut.nativelib.Os; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.FileSet; -import org.apache.tools.todo.types.DirectoryScanner; -import org.apache.tools.todo.types.ScannerUtil; -import org.apache.tools.todo.types.SimpleFileList; - -/** - * A Task to record explicit dependencies. If any of the target files are out of - * date with respect to any of the source files, all target files are removed. - * This is useful where dependencies cannot be computed (for example, - * dynamically interpreted parameters or files that need to stay in synch but - * are not directly linked) or where the ant task in question could compute them - * but does not (for example, the linked DTD for an XML file using the style - * task). nested arguments: - * - * At least one instance of either a fileset or filelist for both source and - * target are required.

- * - * This task will examine each of the source files against each of the target - * files. If any target files are out of date with respect to any of the source - * files, all targets are removed. If any files named in a (src or target) - * filelist do not exist, all targets are removed. Hint: If missing files should - * be ignored, specify them as include patterns in filesets, rather than using - * filelists.

- * - * This task attempts to optimize speed of dependency checking. It will stop - * after the first out of date file is found and remove all targets, rather than - * exhaustively checking every source vs target combination unnecessarily.

- *

- * - * Example uses: - *

- * - * - * @author Craeg Strong - * @version $Revision$ $Date$ - */ -public class DependSet extends MatchingTask -{ - - private ArrayList sourceFileSets = new ArrayList(); - private ArrayList sourceFileLists = new ArrayList(); - private ArrayList targetFileSets = new ArrayList(); - private ArrayList targetFileLists = new ArrayList(); - - /** - * Creates a new DependSet Task. - */ - public DependSet() - { - } - - /** - * Nested <srcfilelist> element. - * - * @param fl The feature to be added to the Srcfilelist attribute - */ - public void addSrcfilelist( SimpleFileList fl ) - { - sourceFileLists.add( fl ); - }//-- DependSet - - /** - * Nested <srcfileset> element. - * - * @param fs The feature to be added to the Srcfileset attribute - */ - public void addSrcfileset( FileSet fs ) - { - sourceFileSets.add( fs ); - } - - /** - * Nested <targetfilelist> element. - * - * @param fl The feature to be added to the Targetfilelist attribute - */ - public void addTargetfilelist( SimpleFileList fl ) - { - targetFileLists.add( fl ); - } - - /** - * Nested <targetfileset> element. - * - * @param fs The feature to be added to the Targetfileset attribute - */ - public void addTargetfileset( FileSet fs ) - { - targetFileSets.add( fs ); - } - - /** - * Executes the task. - * - * @exception org.apache.myrmidon.api.TaskException Description of Exception - */ - public void execute() - throws TaskException - { - if( ( sourceFileSets.size() == 0 ) && ( sourceFileLists.size() == 0 ) ) - { - throw new TaskException( "At least one or element must be set" ); - } - - if( ( targetFileSets.size() == 0 ) && ( targetFileLists.size() == 0 ) ) - { - throw new TaskException( "At least one or element must be set" ); - } - - long now = ( new Date() ).getTime(); - /* - * 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) - */ - if( Os.isFamily( Os.OS_FAMILY_WINDOWS ) ) - { - now += 2000; - } - - // - // Grab all the target files specified via filesets - // - ArrayList allTargets = new ArrayList(); - Iterator enumTargetSets = targetFileSets.iterator(); - while( enumTargetSets.hasNext() ) - { - - FileSet targetFS = (FileSet)enumTargetSets.next(); - DirectoryScanner targetDS = ScannerUtil.getDirectoryScanner( targetFS ); - String[] targetFiles = targetDS.getIncludedFiles(); - - for( int i = 0; i < targetFiles.length; i++ ) - { - - File dest = new File( targetFS.getDir(), targetFiles[ i ] ); - allTargets.add( dest ); - - if( dest.lastModified() > now ) - { - getContext().warn( "Warning: " + targetFiles[ i ] + " modified in the future." ); - } - } - } - - // - // Grab all the target files specified via filelists - // - boolean upToDate = true; - Iterator enumTargetLists = targetFileLists.iterator(); - while( enumTargetLists.hasNext() ) - { - - SimpleFileList targetFL = (SimpleFileList)enumTargetLists.next(); - String[] targetFiles = targetFL.getFiles(); - - for( int i = 0; i < targetFiles.length; i++ ) - { - - File dest = new File( targetFL.getDir(), targetFiles[ i ] ); - if( !dest.exists() ) - { - getContext().debug( targetFiles[ i ] + " does not exist." ); - upToDate = false; - continue; - } - else - { - allTargets.add( dest ); - } - if( dest.lastModified() > now ) - { - getContext().warn( "Warning: " + targetFiles[ i ] + " modified in the future." ); - } - } - } - - // - // Check targets vs source files specified via filesets - // - if( upToDate ) - { - Iterator enumSourceSets = sourceFileSets.iterator(); - while( upToDate && enumSourceSets.hasNext() ) - { - - FileSet sourceFS = (FileSet)enumSourceSets.next(); - DirectoryScanner sourceDS = ScannerUtil.getDirectoryScanner( sourceFS ); - String[] sourceFiles = sourceDS.getIncludedFiles(); - - for( int i = 0; upToDate && i < sourceFiles.length; i++ ) - { - File src = new File( sourceFS.getDir(), sourceFiles[ i ] ); - - if( src.lastModified() > now ) - { - getContext().warn( "Warning: " + sourceFiles[ i ] + " modified in the future." ); - } - - Iterator enumTargets = allTargets.iterator(); - while( upToDate && enumTargets.hasNext() ) - { - - File dest = (File)enumTargets.next(); - if( src.lastModified() > dest.lastModified() ) - { - getContext().debug( dest.getPath() + " is out of date with respect to " + sourceFiles[ i ] ); - upToDate = false; - - } - } - } - } - } - - // - // Check targets vs source files specified via filelists - // - if( upToDate ) - { - Iterator enumSourceLists = sourceFileLists.iterator(); - while( upToDate && enumSourceLists.hasNext() ) - { - - SimpleFileList sourceFL = (SimpleFileList)enumSourceLists.next(); - String[] sourceFiles = sourceFL.getFiles(); - - int i = 0; - do - { - File src = new File( sourceFL.getDir(), sourceFiles[ i ] ); - - if( src.lastModified() > now ) - { - getContext().warn( "Warning: " + sourceFiles[ i ] + " modified in the future." ); - } - - if( !src.exists() ) - { - getContext().debug( sourceFiles[ i ] + " does not exist." ); - upToDate = false; - break; - } - - Iterator enumTargets = allTargets.iterator(); - while( upToDate && enumTargets.hasNext() ) - { - - File dest = (File)enumTargets.next(); - - if( src.lastModified() > dest.lastModified() ) - { - getContext().debug( dest.getPath() + " is out of date with respect to " + sourceFiles[ i ] ); - upToDate = false; - - } - } - } while( upToDate && ( ++i < sourceFiles.length ) ); - } - } - - if( !upToDate ) - { - getContext().debug( "Deleting all target files. " ); - for( Iterator e = allTargets.iterator(); e.hasNext(); ) - { - File fileToRemove = (File)e.next(); - getContext().debug( "Deleting file " + fileToRemove.getAbsolutePath() ); - fileToRemove.delete(); - } - } - - }//-- execute - -}//-- DependSet.java diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Echo.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Echo.java deleted file mode 100644 index 3adcb2780..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Echo.java +++ /dev/null @@ -1,108 +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.FileWriter; -import java.io.IOException; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskException; - -/** - * Log - * - * @author costin@dnt.ro - */ -public class Echo - extends AbstractTask -{ - private String m_message = "";// required - private File m_file; - private boolean m_append; - - /** - * Shall we append to an existing file? - * - * @param append The new Append value - */ - public void setAppend( final boolean append ) - { - m_append = append; - } - - /** - * Sets the file attribute. - * - * @param file The new File value - */ - public void setFile( final File file ) - { - m_file = file; - } - - /** - * Sets the message variable. - * - * @param msg Sets the value for the message variable. - */ - public void setMessage( final String message ) - { - m_message = message; - } - - /** - * Set a multiline message. - * - * @param msg The feature to be added to the Text attribute - */ - public void addContent( final String message ) - throws TaskException - { - m_message = message; - } - - /** - * Does the work. - * - * @exception org.apache.myrmidon.api.TaskException if someting goes wrong with the build - */ - public void execute() - throws TaskException - { - if( m_file == null ) - { - throw new TaskException( "Echo only used to write to files now !" ); - } - else - { - FileWriter out = null; - try - { - out = new FileWriter( m_file.getAbsolutePath(), m_append ); - out.write( m_message, 0, m_message.length() ); - } - catch( IOException ioe ) - { - throw new TaskException( "Error", ioe ); - } - finally - { - if( out != null ) - { - try - { - out.close(); - } - catch( IOException ioex ) - { - } - } - } - } - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Entry.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Entry.java deleted file mode 100644 index a715ca8a6..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Entry.java +++ /dev/null @@ -1,488 +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.DateFormat; -import java.text.DecimalFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Properties; -import org.apache.myrmidon.api.TaskException; -import org.apache.tools.todo.types.EnumeratedAttribute; - -/** - * Instance of this class represents nested elements of a task propertyfile. - */ -public class Entry -{ - final static String NOW_VALUE_ = "now"; - final static String NULL_VALUE_ = "never"; - - private final static int DEFAULT_INT_VALUE = 1; - private final static GregorianCalendar - DEFAULT_DATE_VALUE = new GregorianCalendar(); - - private String m_key; - private int m_type = Type.STRING_TYPE; - private int m_operation = Operation.EQUALS_OPER; - private String m_value = ""; - private String m_default; - private String m_pattern; - - public void setDefault( String value ) - { - this.m_default = value; - } - - public void setKey( String value ) - { - this.m_key = value; - } - - public void setOperation( Operation value ) - { - int newOperation = Operation.toOperation( value.getValue() ); - if( newOperation == Operation.NOW_VALUE ) - { - this.m_operation = Operation.EQUALS_OPER; - this.setValue( this.NOW_VALUE_ ); - } - else if( newOperation == Operation.NULL_VALUE ) - { - this.m_operation = Operation.EQUALS_OPER; - this.setValue( this.NULL_VALUE_ ); - } - else - { - this.m_operation = newOperation; - } - } - - public void setPattern( String value ) - { - this.m_pattern = value; - } - - public void setType( Type value ) - { - this.m_type = Type.toType( value.getValue() ); - } - - public void setValue( String value ) - { - this.m_value = value; - } - - protected void executeOn( Properties props ) - throws TaskException - { - checkParameters(); - - // m_type may be null because it wasn't set - try - { - if( m_type == Type.INTEGER_TYPE ) - { - executeInteger( (String)props.get( m_key ) ); - } - else if( m_type == Type.DATE_TYPE ) - { - executeDate( (String)props.get( m_key ) ); - } - else if( m_type == Type.STRING_TYPE ) - { - executeString( (String)props.get( m_key ) ); - } - else - { - throw new TaskException( "Unknown operation type: " + m_type + "" ); - } - } - catch( NullPointerException npe ) - { - // Default to string type - // which means do nothing - npe.printStackTrace(); - } - // Insert as a string by default - props.put( m_key, m_value ); - - } - - /** - * Check if parameter combinations can be supported - * - * @exception org.apache.myrmidon.api.TaskException Description of Exception - */ - private void checkParameters() - throws TaskException - { - if( m_type == Type.STRING_TYPE && - m_operation == Operation.DECREMENT_OPER ) - { - throw new TaskException( "- is not suported for string properties (key:" + m_key + ")" ); - } - if( m_value == null && m_default == null ) - { - throw new TaskException( "value and/or default must be specified (key:" + m_key + ")" ); - } - if( m_key == null ) - { - throw new TaskException( "key is mandatory" ); - } - if( m_type == Type.STRING_TYPE && - m_pattern != null ) - { - throw new TaskException( "pattern is not suported for string properties (key:" + m_key + ")" ); - } - } - - /** - * Handle operations for type date. - * - * @param oldValue the current value read from the property file or - * null if the key was not contained in - * the property file. - * @exception org.apache.myrmidon.api.TaskException Description of Exception - */ - private void executeDate( String oldValue ) - throws TaskException - { - GregorianCalendar value = new GregorianCalendar(); - GregorianCalendar newValue = new GregorianCalendar(); - - if( m_pattern == null ) - { - m_pattern = "yyyy/MM/dd HH:mm"; - } - DateFormat fmt = new SimpleDateFormat( m_pattern ); - - // special case - if( m_default != null && - NOW_VALUE_.equals( m_default.toLowerCase() ) && - ( m_operation == Operation.INCREMENT_OPER || - m_operation == Operation.DECREMENT_OPER ) ) - { - oldValue = null; - } - - if( oldValue != null ) - { - try - { - value.setTime( fmt.parse( oldValue ) ); - } - catch( ParseException pe ) - { - /* - * swollow - */ - } - } - - if( m_value != null ) - { - if( NOW_VALUE_.equals( m_value.toLowerCase() ) ) - { - value.setTime( new Date() ); - } - else if( NULL_VALUE_.equals( m_value.toLowerCase() ) ) - { - value = null; - } - else - { - try - { - value.setTime( fmt.parse( m_value ) ); - } - catch( Exception ex ) - { - // obviously not a date, try a simple int - try - { - int offset = Integer.parseInt( m_value ); - value.clear(); - value.set( Calendar.DAY_OF_YEAR, offset ); - } - catch( Exception ex_ ) - { - value.clear(); - value.set( Calendar.DAY_OF_YEAR, 1 ); - } - } - - } - } - - if( m_default != null && oldValue == null ) - { - if( NOW_VALUE_.equals( m_default.toLowerCase() ) ) - { - value.setTime( new Date() ); - } - else if( NULL_VALUE_.equals( m_default.toLowerCase() ) ) - { - value = null; - } - else - { - try - { - value.setTime( fmt.parse( m_default ) ); - } - catch( ParseException pe ) - { - /* - * swollow - */ - } - } - } - - if( m_operation == Operation.EQUALS_OPER ) - { - newValue = value; - } - else if( m_operation == Operation.INCREMENT_OPER ) - { - newValue.add( Calendar.SECOND, value.get( Calendar.SECOND ) ); - newValue.add( Calendar.MINUTE, value.get( Calendar.MINUTE ) ); - newValue.add( Calendar.HOUR_OF_DAY, value.get( Calendar.HOUR_OF_DAY ) ); - newValue.add( Calendar.DAY_OF_YEAR, value.get( Calendar.DAY_OF_YEAR ) ); - } - else if( m_operation == Operation.DECREMENT_OPER ) - { - newValue.add( Calendar.SECOND, -1 * value.get( Calendar.SECOND ) ); - newValue.add( Calendar.MINUTE, -1 * value.get( Calendar.MINUTE ) ); - newValue.add( Calendar.HOUR_OF_DAY, -1 * value.get( Calendar.HOUR_OF_DAY ) ); - newValue.add( Calendar.DAY_OF_YEAR, -1 * value.get( Calendar.DAY_OF_YEAR ) ); - } - if( newValue != null ) - { - m_value = fmt.format( newValue.getTime() ); - } - else - { - m_value = ""; - } - } - - /** - * Handle operations for type int. - * - * @param oldValue the current value read from the property file or - * null if the key was not contained in - * the property file. - * @exception org.apache.myrmidon.api.TaskException Description of Exception - */ - private void executeInteger( String oldValue ) - throws TaskException - { - int value = 0; - int newValue = 0; - - DecimalFormat fmt = ( m_pattern != null ) ? new DecimalFormat( m_pattern ) - : new DecimalFormat(); - - if( oldValue != null ) - { - try - { - value = fmt.parse( oldValue ).intValue(); - } - catch( NumberFormatException nfe ) - { - /* - * swollow - */ - } - catch( ParseException pe ) - { - /* - * swollow - */ - } - } - if( m_value != null ) - { - try - { - value = fmt.parse( m_value ).intValue(); - } - catch( NumberFormatException nfe ) - { - /* - * swollow - */ - } - catch( ParseException pe ) - { - /* - * swollow - */ - } - } - if( m_default != null && oldValue == null ) - { - try - { - value = fmt.parse( m_default ).intValue(); - } - catch( NumberFormatException nfe ) - { - /* - * swollow - */ - } - catch( ParseException pe ) - { - /* - * swollow - */ - } - } - - if( m_operation == Operation.EQUALS_OPER ) - { - newValue = value; - } - else if( m_operation == Operation.INCREMENT_OPER ) - { - newValue = ++value; - } - else if( m_operation == Operation.DECREMENT_OPER ) - { - newValue = --value; - } - m_value = fmt.format( newValue ); - } - - /** - * Handle operations for type string. - * - * @param oldValue the current value read from the property file or - * null if the key was not contained in - * the property file. - * @exception org.apache.myrmidon.api.TaskException Description of Exception - */ - private void executeString( String oldValue ) - throws TaskException - { - String value = ""; - String newValue = ""; - - // the order of events is, of course, very important here - // default initially to the old value - if( oldValue != null ) - { - value = oldValue; - } - // but if a value is specified, use it - if( m_value != null ) - { - value = m_value; - } - // even if value is specified, ignore it and set to the default - // value if it is specified and there is no previous value - if( m_default != null && oldValue == null ) - { - value = m_default; - } - - if( m_operation == Operation.EQUALS_OPER ) - { - newValue = value; - } - else if( m_operation == Operation.INCREMENT_OPER ) - { - newValue += value; - } - m_value = newValue; - } - - /** - * Enumerated attribute with the values "+", "-", "=", "now" and - * "never". - * - * @author RT - */ - public static class Operation extends EnumeratedAttribute - { - - // Property type operations - public final static int INCREMENT_OPER = 0; - public final static int DECREMENT_OPER = 1; - public final static int EQUALS_OPER = 2; - - // Special values - public final static int NOW_VALUE = 3; - public final static int NULL_VALUE = 4; - - public static int toOperation( String oper ) - { - if( "+".equals( oper ) ) - { - return INCREMENT_OPER; - } - else if( "-".equals( oper ) ) - { - return DECREMENT_OPER; - } - else if( NOW_VALUE_.equals( oper ) ) - { - return NOW_VALUE; - } - else if( NULL_VALUE_.equals( oper ) ) - { - return NULL_VALUE; - } - return EQUALS_OPER; - } - - public String[] getValues() - { - return new String[]{"+", "-", "=", NOW_VALUE_, NULL_VALUE_}; - } - } - - /** - * Enumerated attribute with the values "int", "date" and "string". - * - * @author RT - */ - public static class Type extends EnumeratedAttribute - { - - // Property types - public final static int INTEGER_TYPE = 0; - public final static int DATE_TYPE = 1; - public final static int STRING_TYPE = 2; - - public static int toType( String type ) - { - if( "int".equals( type ) ) - { - return INTEGER_TYPE; - } - else if( "date".equals( type ) ) - { - return DATE_TYPE; - } - return STRING_TYPE; - } - - public String[] getValues() - { - return new String[]{"int", "date", "string"}; - } - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/FileDir.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/FileDir.java deleted file mode 100644 index bd3afb3e1..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/FileDir.java +++ /dev/null @@ -1,36 +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 org.apache.tools.todo.types.EnumeratedAttribute; - -public class FileDir - extends EnumeratedAttribute -{ - private final static String[] values = {"file", "dir"}; - - public String[] getValues() - { - return values; - } - - public boolean isDir() - { - return "dir".equalsIgnoreCase( getValue() ); - } - - public boolean isFile() - { - return "file".equalsIgnoreCase( getValue() ); - } - - public String toString() - { - return getValue(); - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Get.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Get.java deleted file mode 100644 index f97baa1d6..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Get.java +++ /dev/null @@ -1,381 +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.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; -import java.util.Date; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.TaskContext; - -/** - * Get a particular file from a URL source. Options include verbose reporting, - * timestamp based fetches and controlling actions on failures. NB: access - * through a firewall only works if the whole Java runtime is correctly - * configured. - * - * @author costin@dnt.ro - * @author gg@grtmail.com (Added Java 1.1 style HTTP basic auth) - */ -public class Get extends AbstractTask -{// required - private boolean verbose = false; - private boolean useTimestamp = false;//off by default - private boolean ignoreErrors = false; - private String uname = null; - private String pword = null;// required - private File dest; - private URL source; - - /** - * Where to copy the source file. - * - * @param dest Path to file. - */ - public void setDest( File dest ) - { - this.dest = dest; - } - - /** - * Don't stop if get fails if set to "true". - * - * @param v if "true" then don't report download errors up to ant - */ - public void setIgnoreErrors( boolean v ) - { - ignoreErrors = v; - } - - /** - * password for the basic auth. - * - * @param p password for authentication - */ - public void setPassword( String p ) - { - this.pword = p; - } - - /** - * Set the URL. - * - * @param u URL for the file. - */ - public void setSrc( URL u ) - { - this.source = u; - } - - /** - * Use timestamps, if set to "true".

- * - * 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().verbose( "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().verbose( "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().verbose( "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/todo/org/apache/tools/todo/taskdefs/IContract.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/IContract.java deleted file mode 100644 index 72805db02..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/IContract.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; - -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.listeners.AbstractProjectListener; -import org.apache.myrmidon.listeners.LogEvent; -import org.apache.tools.todo.taskdefs.javac.DefaultCompilerAdapter; -import org.apache.tools.todo.taskdefs.javac.Javac; -import org.apache.tools.todo.types.DirectoryScanner; -import org.apache.myrmidon.framework.file.Path; -import org.apache.myrmidon.framework.file.FileListUtil; -import org.apache.antlib.java.JavaTask; - -/** - * 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.

- * - * Thanks to Rainer Schmitz for enhancements and comments. - * - * @author Aslak Hellesøy

- * - * - * - * - * - * - * - * 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."; - - /** - * 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; - - /** - * 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( final Path path ) - { - createClasspath().add( 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 = new Path(); - beforeInstrumentationClasspath.add( baseClasspath ); - beforeInstrumentationClasspath.addLocation( srcDir ); - - // Create the classpath required to compile the sourcefiles AFTER instrumentation - Path afterInstrumentationClasspath = new Path(); - afterInstrumentationClasspath.add( baseClasspath ); - afterInstrumentationClasspath.addLocation( instrumentDir ); - afterInstrumentationClasspath.addLocation( repositoryDir ); - afterInstrumentationClasspath.addLocation( srcDir ); - afterInstrumentationClasspath.addLocation( buildDir ); - - // Create the classpath required to automatically compile the repository files - Path repositoryClasspath = new Path(); - repositoryClasspath.add( baseClasspath ); - repositoryClasspath.addLocation( instrumentDir ); - repositoryClasspath.addLocation( srcDir ); - repositoryClasspath.addLocation( repositoryDir ); - repositoryClasspath.addLocation( buildDir ); - - // Create the classpath required for iContract itself - Path iContractClasspath = new Path(); - iContractClasspath.add( baseClasspath ); - iContractClasspath.addLocation( new File(System.getProperty( "java.home" ) + File.separator + ".." + File.separator + "lib" + File.separator + "tools.jar" ) ); - iContractClasspath.addLocation( srcDir ); - iContractClasspath.addLocation( repositoryDir ); - iContractClasspath.addLocation( instrumentDir ); - iContractClasspath.addLocation( buildDir ); - - // Create a forked java process - JavaTask 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() ); - final String classpath = FileListUtil.formatPath( afterInstrumentationClasspath, getContext() ); - iControlProps.setProperty( "classpath", classpath ); - 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! - iContract.executeJava(); - } - 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; - addCompileClasspath( path ); - } - } - } - - /** - * 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/todo/org/apache/tools/todo/taskdefs/Javah.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Javah.java deleted file mode 100644 index 3d7adf4b3..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Javah.java +++ /dev/null @@ -1,358 +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.framework.file.FileListUtil; -import org.apache.myrmidon.framework.file.Path; -import org.apache.myrmidon.framework.nativelib.ArgumentList; -import org.apache.tools.todo.util.FileUtils; - -/** - * 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.add( 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.add( 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 ArgumentList cmd ) - throws TaskException - { - final String[] args = cmd.getArguments(); - getContext().debug( "Compilation args: " + FileUtils.formatCommandLine( args ) ); - - int n = 0; - 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 ArgumentList setupJavahCommand() - throws TaskException - { - final ArgumentList cmd = new ArgumentList(); - - 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.addArgument( FileListUtil.formatPath( m_classpath, getContext() ) ); - } - - 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.addArgument( FileListUtil.formatPath( m_bootclasspath, getContext() ) ); - } - - 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 - { - ArgumentList 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/todo/org/apache/tools/todo/taskdefs/MatchingTask.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/MatchingTask.java deleted file mode 100644 index e48a8e937..000000000 --- a/proposal/myrmidon/src/todo/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.myrmidon.framework.FileSet; -import org.apache.tools.todo.types.DirectoryScanner; -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/todo/org/apache/tools/todo/taskdefs/NetRexxC.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/NetRexxC.java deleted file mode 100644 index e99b66290..000000000 --- a/proposal/myrmidon/src/todo/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: - *

    - *
  1. The current directory, and,
  2. - *
  3. 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/todo/org/apache/tools/todo/taskdefs/PathConvert.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/PathConvert.java deleted file mode 100644 index a33997c74..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/PathConvert.java +++ /dev/null @@ -1,323 +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.framework.file.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.add( 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.listFiles( getContext() ); - - 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/todo/org/apache/tools/todo/taskdefs/Property.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Property.java deleted file mode 100644 index 21c997ee0..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Property.java +++ /dev/null @@ -1,141 +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.util.Iterator; -import java.util.Properties; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.file.Path; -import org.apache.myrmidon.framework.file.FileListUtil; - -/** - * 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 = new Path(); - - private String m_name; - private String m_resource; - private String m_value; - - public void addClasspath( final Path classpath ) - throws TaskException - { - m_classpath.add( 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 - { - final ClassLoader classLoader = FileListUtil.createClassLoader( m_classpath, getContext() ); - 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/todo/org/apache/tools/todo/taskdefs/Rpm.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Rpm.java deleted file mode 100644 index 0df160e25..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Rpm.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.taskdefs; - -import java.io.File; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.nativelib.Execute; -import org.apache.myrmidon.framework.nativelib.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 Execute exe = createCommand(); - exe.setWorkingDirectory( m_topDir ); - - final String message = "Building the RPM based on the " + m_specFile + " file"; - getContext().info( message ); - exe.execute( getContext() ); - } - - private Execute createCommand() - throws TaskException - { - final Execute cmd = new Execute(); - 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/todo/org/apache/tools/todo/taskdefs/SQLExec.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/SQLExec.java deleted file mode 100644 index da59f16e1..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/SQLExec.java +++ /dev/null @@ -1,836 +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.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.framework.file.Path; -import org.apache.myrmidon.framework.file.FileListUtil; -import org.apache.myrmidon.framework.FileSet; -import org.apache.tools.todo.types.DirectoryScanner; -import org.apache.tools.todo.types.EnumeratedAttribute; -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 = new Path(); - - /** - * 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( final Path classpath ) - throws TaskException - { - this.classpath.add( 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 - { - final ClassLoader classLoader = FileListUtil.createClassLoader( classpath, getContext() ); - final Class dc = classLoader.loadClass( 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/todo/org/apache/tools/todo/taskdefs/Script.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Script.java deleted file mode 100644 index 78c7167a4..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/Tstamp.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/Tstamp.java deleted file mode 100644 index a814eacdf..000000000 --- a/proposal/myrmidon/src/todo/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 MacNeill - * @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/todo/org/apache/tools/todo/taskdefs/WaitFor.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/WaitFor.java deleted file mode 100644 index c2973dda0..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/archive/Ear.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/Ear.java deleted file mode 100644 index bda13d110..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/Ear.java +++ /dev/null @@ -1,97 +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.excalibur.zip.ZipOutputStream; -import org.apache.myrmidon.api.TaskException; - -/** - * 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/todo/org/apache/tools/todo/taskdefs/archive/Expand.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/Expand.java deleted file mode 100644 index 56dd88e9f..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/Expand.java +++ /dev/null @@ -1,286 +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.framework.FileSet; -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.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/todo/org/apache/tools/todo/taskdefs/archive/Jar.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/Jar.java deleted file mode 100644 index 666a236f6..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/Jar.java +++ /dev/null @@ -1,395 +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.myrmidon.api.TaskException; -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; -import org.apache.excalibur.zip.ZipOutputStream; - -/** - * 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/todo/org/apache/tools/todo/taskdefs/archive/Tar.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/Tar.java deleted file mode 100644 index 07a216007..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/Tar.java +++ /dev/null @@ -1,306 +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.avalon.excalibur.io.IOUtil; -import org.apache.excalibur.tar.TarEntry; -import org.apache.excalibur.tar.TarOutputStream; -import org.apache.myrmidon.api.TaskException; -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/todo/org/apache/tools/todo/taskdefs/archive/TarFileSet.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/TarFileSet.java deleted file mode 100644 index 3cfd7fda2..000000000 --- a/proposal/myrmidon/src/todo/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.myrmidon.framework.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/todo/org/apache/tools/todo/taskdefs/archive/TarLongFileMode.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/TarLongFileMode.java deleted file mode 100644 index 0f728f481..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/archive/Untar.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/Untar.java deleted file mode 100644 index fe58b655e..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/Untar.java +++ /dev/null @@ -1,53 +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.avalon.excalibur.io.IOUtil; -import org.apache.excalibur.tar.TarEntry; -import org.apache.excalibur.tar.TarInputStream; -import org.apache.myrmidon.api.TaskException; - -/** - * 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/todo/org/apache/tools/todo/taskdefs/archive/Unzip.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/Unzip.java deleted file mode 100644 index 0169e4969..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/archive/War.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/War.java deleted file mode 100644 index b11a8ec21..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/War.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.taskdefs.archive; - -import java.io.File; -import java.io.IOException; -import org.apache.myrmidon.api.TaskException; -import org.apache.excalibur.zip.ZipOutputStream; - -/** - * 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/todo/org/apache/tools/todo/taskdefs/archive/WhenEmpty.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/WhenEmpty.java deleted file mode 100644 index f4717545c..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/archive/Zip.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/Zip.java deleted file mode 100644 index 89c26915f..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/Zip.java +++ /dev/null @@ -1,895 +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.avalon.excalibur.io.IOUtil; -import org.apache.excalibur.zip.ZipEntry; -import org.apache.excalibur.zip.ZipOutputStream; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.FileSet; -import org.apache.tools.todo.taskdefs.MatchingTask; -import org.apache.tools.todo.types.DirectoryScanner; -import org.apache.tools.todo.types.FileScanner; -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 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/todo/org/apache/tools/todo/taskdefs/archive/ZipFileSet.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/ZipFileSet.java deleted file mode 100644 index 29f8be309..000000000 --- a/proposal/myrmidon/src/todo/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.myrmidon.framework.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 src 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/todo/org/apache/tools/todo/taskdefs/archive/ZipScanner.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/archive/ZipScanner.java deleted file mode 100644 index 01e65dbf9..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/conditions/Http.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/conditions/Http.java deleted file mode 100644 index 5a5a0229d..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/conditions/Socket.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/conditions/Socket.java deleted file mode 100644 index 562cc3c0a..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/exec/ExecuteStreamHandler.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/exec/ExecuteStreamHandler.java deleted file mode 100644 index 33c1b9c57..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/i18n/Translate.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/i18n/Translate.java deleted file mode 100644 index 0c4540ab3..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/i18n/Translate.java +++ /dev/null @@ -1,635 +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.framework.FileSet; -import org.apache.tools.todo.taskdefs.MatchingTask; -import org.apache.tools.todo.types.DirectoryScanner; -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/todo/org/apache/tools/todo/taskdefs/javac/CompilerAdapter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/CompilerAdapter.java deleted file mode 100644 index 0b3b576f2..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/javac/CompilerAdapterFactory.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/CompilerAdapterFactory.java deleted file mode 100644 index 6f1030bbc..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java deleted file mode 100644 index 6232bf975..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/DefaultCompilerAdapter.java +++ /dev/null @@ -1,468 +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.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.nativelib.Execute; -import org.apache.myrmidon.framework.FileSet; -import org.apache.myrmidon.framework.nativelib.Commandline; -import org.apache.myrmidon.framework.nativelib.ArgumentList; -import org.apache.myrmidon.framework.file.Path; -import org.apache.myrmidon.framework.file.FileListUtil; -import org.apache.tools.todo.util.FileUtils; -import org.apache.aut.nativelib.PathUtil; - -/** - * 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; - - /* - * 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_memoryInitialSize = attributes.getMemoryInitialSize(); - m_memoryMaximumSize = attributes.getMemoryMaximumSize(); - } - - public Javac getJavac() - { - return m_attributes; - } - - protected ArgumentList 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 ArgumentList setupJavacCommand( boolean debugLevelCheck ) - throws TaskException - { - ArgumentList cmd = new ArgumentList(); - setupJavacCommandlineSwitches( cmd, debugLevelCheck ); - logFilesToCompile( cmd ); - addFilesToCompile( 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 ArgumentList setupJavacCommandlineSwitches( ArgumentList cmd, - boolean useDebugLevel ) - throws TaskException - { - Path classpath = new Path(); - addCompileClasspath( classpath ); - 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.addArgument( FileListUtil.formatPath( classpath, getTaskContext() ) ); - - cmd.addArgument( "-sourcepath" ); - cmd.addArgument( FileListUtil.formatPath( src, getTaskContext() ) ); - - if( target != null ) - { - cmd.addArgument( "-target" ); - cmd.addArgument( target ); - } - - final String[] bootclasspath = m_bootclasspath.listFiles( getTaskContext() ); - if( bootclasspath.length > 0 ) - { - cmd.addArgument( "-bootclasspath" ); - cmd.addArgument( PathUtil.formatPath( bootclasspath ) ); - } - - if( m_extdirs != null ) - { - cmd.addArgument( "-extdirs" ); - cmd.addArgument( FileListUtil.formatPath( m_extdirs, getTaskContext() ) ); - } - - 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 ArgumentList setupModernJavacCommand() - throws TaskException - { - ArgumentList cmd = new ArgumentList(); - setupModernJavacCommandlineSwitches( cmd ); - - logFilesToCompile( cmd ); - addFilesToCompile( 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 ArgumentList setupModernJavacCommandlineSwitches( ArgumentList cmd ) - throws TaskException - { - setupJavacCommandlineSwitches( cmd, true ); - if( m_attributes.getSource() != null ) - { - cmd.addArgument( "-source" ); - cmd.addArgument( m_attributes.getSource() ); - } - return cmd; - } - - /** - * Adds the compilation classpath to a path. - */ - protected void addCompileClasspath( final Path classpath ) - throws TaskException - { - // 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.add( m_compileClasspath ); - } - } - - /** - * Adds the command line arguments specifc to the current implementation. - * - * @param cmd The feature to be added to the CurrentCompilerArgs attribute - */ - protected void addCurrentCompilerArgs( ArgumentList cmd ) - { - cmd.addArguments( getJavac().getCurrentCompilerArgs() ); - } - - /** - * Do the compile with the specified arguments. - * - * @param cmd - the command line, to which the names of the files to - * compile are added. - */ - protected boolean executeExternalCompile( final Commandline cmd ) - throws TaskException - { - logFilesToCompile( cmd ); - - 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. - */ - try - { - tmpFile = File.createTempFile( "javac", "", new File( "." ) ); - final FileWriter fout = new FileWriter( tmpFile ); - try - { - final PrintWriter out = new PrintWriter( fout ); - for( int i = 0; i < m_compileList.length; i++ ) - { - File file = m_compileList[i ]; - out.println( file.getAbsolutePath() ); - } - out.close(); - } - finally - { - IOUtil.shutdownWriter( fout ); - } - } - catch( final IOException ioe ) - { - throw new TaskException( "Error creating temporary file", ioe ); - } - - cmd.addArgument( "@" + tmpFile.getAbsolutePath() ); - - final Execute exe = new Execute(); - exe.setIgnoreReturnCode( true ); - exe.setCommandline( cmd ); - return exe.execute( getTaskContext() ) == 0; - } - 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 logFilesToCompile( final ArgumentList cmd ) - throws TaskException - { - final String[] cmdline = cmd.getArguments(); - getTaskContext().debug( "Compilation args: " + FileUtils.formatCommandLine( cmdline ) ); - - 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(); - niceSourceList.append( " " + arg + StringUtil.LINE_SEPARATOR ); - } - - getTaskContext().debug( niceSourceList.toString() ); - } - - /** - * Adds the files to compile to a command-line - */ - protected void addFilesToCompile( final ArgumentList cmd ) - { - for( int i = 0; i < m_compileList.length; i++ ) - { - File file = m_compileList[i ]; - cmd.addArgument( file ); - } - } - - /** - * 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; - } - } - - addExtdirs( path, m_extdirs, getTaskContext() ); - } - - /** - * Adds the contents of a set of directories to a path. - */ - public static void addExtdirs( final Path toPath, - final Path extDirs, - final TaskContext context ) - throws TaskException - { - final String[] dirs = extDirs.listFiles( context ); - 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/todo/org/apache/tools/todo/taskdefs/javac/Gcj.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Gcj.java deleted file mode 100644 index 36290095e..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Gcj.java +++ /dev/null @@ -1,107 +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.framework.nativelib.Commandline; -import org.apache.myrmidon.framework.file.Path; -import org.apache.myrmidon.framework.file.FileListUtil; - -/** - * The implementation of the gcj compiler. This is primarily a cut-and-paste - * from the jikes. - * - * @author Takashi Okamoto - * @author tora@debian.org - */ -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 - */ - public boolean execute() - throws TaskException - { - Commandline cmd; - getTaskContext().debug( "Using gcj compiler" ); - cmd = setupGCJCommand(); - - return executeExternalCompile( cmd ); - } - - 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. - final String[] bootclasspath = m_bootclasspath.listFiles( getTaskContext() ); - classpath.add( bootclasspath ); - - // gcj doesn't support an extension dir (-extdir) - // so we'll emulate it for compatibility and convenience. - addExtdirs( classpath ); - - if( bootclasspath.length == 0 ) - { - // no bootclasspath, therefore, get one from the java runtime - m_includeJavaRuntime = true; - } - - addCompileClasspath( classpath ); - - // Gcj has no option for source-path so we - // will add it to classpath. - classpath.add( 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.addArgument( FileListUtil.formatPath( classpath, getTaskContext() ) ); - - 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/todo/org/apache/tools/todo/taskdefs/javac/ImplementationSpecificArgument.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/ImplementationSpecificArgument.java deleted file mode 100644 index ed98c98cd..000000000 --- a/proposal/myrmidon/src/todo/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.myrmidon.framework.nativelib.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/todo/org/apache/tools/todo/taskdefs/javac/Javac.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Javac.java deleted file mode 100644 index aa0493309..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Javac.java +++ /dev/null @@ -1,753 +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.framework.JavaVersion; -import org.apache.tools.todo.taskdefs.MatchingTask; -import org.apache.tools.todo.types.DirectoryScanner; -import org.apache.myrmidon.framework.file.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 = new Path(); - 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( final Path bootclasspath ) - { - m_bootclasspath.add( 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.add( 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.add( 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.add( 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.listFiles( getContext() ); - 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/todo/org/apache/tools/todo/taskdefs/javac/Javac12.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Javac12.java deleted file mode 100644 index 96fe13256..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Javac12.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.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.myrmidon.framework.nativelib.Commandline; -import org.apache.myrmidon.framework.nativelib.ArgumentList; -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" ); - ArgumentList 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/todo/org/apache/tools/todo/taskdefs/javac/Javac13.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Javac13.java deleted file mode 100644 index 3b43b3ccf..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Javac13.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.javac; - -import java.lang.reflect.Method; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.TaskContext; -import org.apache.myrmidon.framework.nativelib.Commandline; -import org.apache.myrmidon.framework.nativelib.ArgumentList; -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" ); - ArgumentList 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/todo/org/apache/tools/todo/taskdefs/javac/JavacExternal.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/JavacExternal.java deleted file mode 100644 index 25a5675ce..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/JavacExternal.java +++ /dev/null @@ -1,42 +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.myrmidon.framework.nativelib.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 ); - - return executeExternalCompile( cmd ); - } - -} - diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Jikes.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Jikes.java deleted file mode 100644 index 97d7d64a4..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Jikes.java +++ /dev/null @@ -1,134 +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.framework.nativelib.Commandline; -import org.apache.myrmidon.framework.file.Path; -import org.apache.myrmidon.framework.file.FileListUtil; - -/** - * 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 - * @author skanthak@muehlheim.de - */ -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 - */ - 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. - final String[] bootclasspath = m_bootclasspath.listFiles( getTaskContext() ); - classpath.add( bootclasspath ); - - // Jikes doesn't support an extension dir (-extdir) - // so we'll emulate it for compatibility and convenience. - addExtdirs( classpath ); - - if( bootclasspath.length == 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! - - addCompileClasspath( classpath ); - - // Jikes has no option for source-path so we - // will add it to classpath. - classpath.add( 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.add( 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.addArgument( FileListUtil.formatPath( classpath, getTaskContext() ) ); - - 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 ); - - return executeExternalCompile( cmd ); - } - -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Jvc.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Jvc.java deleted file mode 100644 index 9eaad06d2..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Jvc.java +++ /dev/null @@ -1,97 +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.framework.nativelib.Commandline; -import org.apache.myrmidon.framework.file.Path; -import org.apache.myrmidon.framework.file.FileListUtil; - -/** - * 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. - final String[] bootclasspath = m_bootclasspath.listFiles( getTaskContext() ); - classpath.add( bootclasspath ); - - // jvc doesn't support an extension dir (-extdir) - // so we'll emulate it for compatibility and convenience. - addExtdirs( classpath ); - - if( bootclasspath.length == 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! - - addCompileClasspath( classpath ); - - // jvc has no option for source-path so we - // will add it to classpath. - classpath.add( 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.addArgument( FileListUtil.formatPath( classpath, getTaskContext() ) ); - - // 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 ); - - return executeExternalCompile( cmd ); - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Kjc.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Kjc.java deleted file mode 100644 index ca0f3bb76..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Kjc.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.javac; - -import java.lang.reflect.Method; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.nativelib.Commandline; -import org.apache.myrmidon.framework.nativelib.ArgumentList; -import org.apache.myrmidon.framework.file.Path; -import org.apache.myrmidon.framework.file.FileListUtil; - -/** - * 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" ); - ArgumentList 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 ArgumentList setupKjcCommand() - throws TaskException - { - ArgumentList cmd = new Commandline(); - - // generate classpath, because kjc does't support sourcepath. - Path classpath = new Path(); - addCompileClasspath( classpath ); - - 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. - cp.add( m_bootclasspath ); - - if( m_extdirs != null ) - { - addExtdirs( cp ); - } - - cp.add( classpath ); - cp.add( src ); - - cmd.addArgument( FileListUtil.formatPath( cp, getTaskContext() ) ); - - // 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 ); - - logFilesToCompile( cmd ); - addFilesToCompile( cmd ); - return cmd; - } -} - diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Sj.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Sj.java deleted file mode 100644 index 851febb74..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javac/Sj.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.myrmidon.framework.nativelib.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 = new Commandline(); - setupJavacCommandlineSwitches( cmd, false ); - cmd.setExecutable( "sj" ); - - return executeExternalCompile( cmd ); - } - -} - diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JJTree.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JJTree.java deleted file mode 100644 index 74ece1de8..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JJTree.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.javacc; - -import java.io.File; -import java.util.Enumeration; -import java.util.Hashtable; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.java.ExecuteJava; -import org.apache.myrmidon.framework.file.Path; - -/** - * 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; - - 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 - { - final ExecuteJava exe = new ExecuteJava(); - exe.setClassName( "COM.sun.labs.jjtree.Main" ); - - // load command line with optional attributes - Enumeration iter = optionalAttrs.keys(); - while( iter.hasMoreElements() ) - { - String name = (String)iter.nextElement(); - Object value = optionalAttrs.get( name ); - exe.getArguments().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 = target.getParentFile(); - } - 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 - exe.getArguments().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().verbose( "Target is already built - skipping (" + target + ")" ); - return; - } - exe.getArguments().addArgument( target ); - - if( javaccHome == null || !javaccHome.isDirectory() ) - { - throw new TaskException( "Javacchome not set." ); - } - final Path classpath = exe.getClassPath(); - classpath.addLocation( new File( javaccHome, "JavaCC.zip" ) ); - - exe.setMaxMemory( "140M" ); - exe.getSysProperties().addVariable( "install.root", javaccHome.getAbsolutePath() ); - - exe.executeForked( getContext() ); - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JavaCC.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JavaCC.java deleted file mode 100644 index 08a5610b0..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javacc/JavaCC.java +++ /dev/null @@ -1,269 +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.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.java.ExecuteJava; -import org.apache.myrmidon.framework.file.Path; - -/** - * 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; - - 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 - { - // 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 = target.getParentFile(); - } - if( !outputDirectory.isDirectory() ) - { - throw new TaskException( "Outputdir not a directory." ); - } - - if( javaccHome == null || !javaccHome.isDirectory() ) - { - throw new TaskException( "Javacchome not set." ); - } - - // 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; - } - - ExecuteJava exe = new ExecuteJava(); - exe.setClassName( "COM.sun.labs.javacc.Main" ); - - // load command line with optional attributes - Enumeration iter = optionalAttrs.keys(); - while( iter.hasMoreElements() ) - { - String name = (String)iter.nextElement(); - Object value = optionalAttrs.get( name ); - exe.getArguments().addArgument( "-" + name + ":" + value.toString() ); - } - - exe.getArguments().addArgument( "-OUTPUT_DIRECTORY:" + outputDirectory.getAbsolutePath() ); - - exe.getArguments().addArgument( target ); - - final Path classpath = exe.getClassPath(); - classpath.addLocation( new File( javaccHome, "JavaCC.zip" ) ); - - exe.setMaxMemory( "140M" ); - exe.getSysProperties().addVariable( "install.root", javaccHome.getAbsolutePath() ); - - exe.executeForked( getContext() ); - } - - /** - * 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/todo/org/apache/tools/todo/taskdefs/javadoc/AccessType.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/AccessType.java deleted file mode 100644 index 54c44994c..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/javadoc/DocletInfo.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/DocletInfo.java deleted file mode 100644 index 4dd38137d..000000000 --- a/proposal/myrmidon/src/todo/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.myrmidon.framework.file.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.add( 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.add( path ); - return path; - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/DocletParam.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/DocletParam.java deleted file mode 100644 index 955a07ac9..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/javadoc/GroupArgument.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/GroupArgument.java deleted file mode 100644 index d66c6179c..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/javadoc/Html.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/Html.java deleted file mode 100644 index c6ac22a4c..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java deleted file mode 100644 index 2ec094d23..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/Javadoc.java +++ /dev/null @@ -1,1020 +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.ExecOutputHandler; -import org.apache.aut.nativelib.Os; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.nativelib.Execute; -import org.apache.myrmidon.framework.FileSet; -import org.apache.myrmidon.framework.Pattern; -import org.apache.myrmidon.framework.file.FileListUtil; -import org.apache.myrmidon.framework.file.Path; -import org.apache.myrmidon.framework.nativelib.ArgumentList; -import org.apache.tools.todo.types.DirectoryScanner; -import org.apache.tools.todo.types.ScannerUtil; - -/** - * 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 Execute m_command = new Execute(); - - 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 String m_packageList; - private ArrayList m_links = new ArrayList( 2 ); - private ArrayList m_groups = new ArrayList( 2 ); - private boolean m_useDefaultExcludes = true; - 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.add( 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.add( 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; - } - - 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.add( 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_command.addArgument( "-bottom" ); - m_command.addArgument( text.getText() ); - } - - public void addDoctitle( Html text ) - { - m_command.addArgument( "-doctitle" ); - m_command.addArgument( text.getText() ); - } - - public void addExcludePackage( PackageName pn ) - { - m_excludePackageNames.add( pn ); - } - - public void addFooter( Html text ) - { - m_command.addArgument( "-footer" ); - m_command.addArgument( text.getText() ); - } - - public void addHeader( Html text ) - { - m_command.addArgument( "-header" ); - m_command.addArgument( text.getText() ); - } - - 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.add( 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.add( 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.add( 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" ); - - m_command.setExecutable( getJavadocExecutableName() ); - - // ------------------------------------------------ general javadoc arguments - - // Build the classpath to pass to Javadoc - Path classpath = new Path(); - classpath.add( m_sourcePath ); - if( m_classpath != null ) - { - classpath.add( m_classpath ); - } - m_command.addArgument( "-classpath" ); - m_command.addArgument( FileListUtil.formatPath( classpath, getContext() ) ); - - if( m_version && m_doclet == null ) - { - m_command.addArgument( "-version" ); - } - if( m_author && m_doclet == null ) - { - m_command.addArgument( "-author" ); - } - - if( m_doclet == null ) - { - if( m_destDir == null ) - { - String msg = "destDir attribute must be set!"; - throw new TaskException( msg ); - } - } - if( m_destDir != null ) - { - m_command.addArgument( "-d" ); - m_command.addArgument( m_destDir ); - } - - // --------------------------------- 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 - { - m_command.addArgument( "-doclet" ); - m_command.addArgument( m_doclet.getName() ); - if( m_doclet.getPath() != null ) - { - m_command.addArgument( "-docletpath" ); - m_command.addArgument( FileListUtil.formatPath( m_doclet.getPath(), getContext() ) ); - } - 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" ); - } - - m_command.addArgument( param.getName() ); - if( param.getValue() != null ) - { - m_command.addArgument( param.getValue() ); - } - } - } - - if( m_bootclasspath != null ) - { - m_command.addArgument( "-bootclasspath" ); - m_command.addArgument( FileListUtil.formatPath( m_bootclasspath, getContext() ) ); - } - - // 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() ) - { - m_command.addArgument( "-linkoffline" ); - m_command.addArgument( la.getHref() ); - m_command.addArgument( packageListLocation.getAbsolutePath() ); - } - else - { - getContext().debug( "Warning: No package list was found at " + packageListLocation ); - } - } - else - { - m_command.addArgument( "-link" ); - m_command.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 ); - m_command.addArgument( "-group" ); - m_command.addArgument( name ); - m_command.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." ); - } - m_command.addArgument( "-group" ); - m_command.addArgument( title ); - m_command.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 - { - m_command.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( m_command, 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() ); - m_command.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 - { - m_command.addArgument( sourceFileName ); - } - } - - } - catch( IOException e ) - { - throw new TaskException( "Error creating temporary file", e ); - } - finally - { - if( srcListWriter != null ) - { - srcListWriter.close(); - } - } - } - - if( m_packageList != null ) - { - m_command.addArgument( "@" + m_packageList ); - } - getContext().debug( "Javadoc args: " + m_command ); - - m_command.setExecOutputHandler( this ); - try - { - m_command.execute( getContext() ); - } - 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( ArgumentList toExecute, Path sourcePath, - ArrayList packages, ArrayList excludePackages ) - throws TaskException - { - getContext().debug( "Source path = " + FileListUtil.formatPath( sourcePath, getContext() ) ); - 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.listFiles( getContext() ); - 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().verbose( 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/todo/org/apache/tools/todo/taskdefs/javadoc/LinkArgument.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/LinkArgument.java deleted file mode 100644 index cb7969199..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/javadoc/PackageName.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/PackageName.java deleted file mode 100644 index 672615e5d..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/javadoc/SourceFile.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/javadoc/SourceFile.java deleted file mode 100644 index 45c1bc319..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/jdepend/FormatAttribute.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jdepend/FormatAttribute.java deleted file mode 100644 index 25b78ecbe..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/jdepend/JDependTask.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jdepend/JDependTask.java deleted file mode 100644 index a0e3c70e3..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jdepend/JDependTask.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.jdepend; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.java.ExecuteJava; -import org.apache.myrmidon.framework.file.Path; - -/** - * 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 -{ - private boolean m_fork; - private String m_jvm; - private String m_format = "text"; - private Path m_compileClasspath = new Path(); - 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 - { - addClasspath( 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 fork 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 jvm 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; - } - - /** - * Adds a nested classpath element. - */ - public void addClasspath( final Path path ) - { - m_compileClasspath.add( 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.add( path ); - return path; - } - - public void execute() - throws TaskException - { - if( m_sourcesPath == null ) - { - throw new TaskException( "Missing Sourcepath required argument" ); - } - - // execute the test and get the return code - if( !m_fork ) - { - executeInVM(); - } - else - { - executeAsForked(); - } - } - - - /** - * 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 void executeAsForked() - throws TaskException - { - final ExecuteJava exe = new ExecuteJava(); - exe.setWorkingDirectory( m_dir ); - - if( "text".equals( m_format ) ) - { - exe.setClassName( "jdepend.textui.JDepend" ); - } - else - { - exe.setClassName( "jdepend.xmlui.JDepend" ); - } - - if( m_jvm != null ) - { - exe.setJvm( m_jvm ); - } - - exe.getClassPath().add( m_compileClasspath ); - - 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 - exe.getArguments().addArgument( "-file" ); - exe.getArguments().addArgument( m_outputFile ); - getContext().info( "Output to be stored in " + m_outputFile.getPath() ); - } - - final String[] elements = m_sourcesPath.listFiles( getContext() ); - 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." ); - } - exe.getArguments().addArgument( f ); - } - - exe.executeForked( getContext() ); - } - - - // 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. - */ - private void executeInVM() - 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(); - throw new TaskException( msg ); - } - jdepend.setWriter( new PrintWriter( fw ) ); - getContext().info( "Output to be stored in " + m_outputFile.getPath() ); - } - - final String[] elements = m_sourcesPath.listFiles( getContext() ); - 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."; - throw new TaskException( msg ); - } - try - { - jdepend.addDirectory( f.getPath() ); - } - catch( IOException e ) - { - String msg = "JDepend Failed when adding a source directory: " + e.getMessage(); - throw new TaskException( msg ); - } - } - jdepend.analyze(); - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/JspC.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/JspC.java deleted file mode 100644 index 7054b6935..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/JspC.java +++ /dev/null @@ -1,484 +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.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.myrmidon.framework.file.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.add( 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.add( 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.add( 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.listFiles( getContext() ); - 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().verbose( "there were no files to compile" ); - } - else - { - getContext().verbose( "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/todo/org/apache/tools/todo/taskdefs/jsp/WLJspc.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/WLJspc.java deleted file mode 100644 index 5a887b032..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/WLJspc.java +++ /dev/null @@ -1,294 +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.myrmidon.framework.java.ExecuteJava; -import org.apache.tools.todo.taskdefs.MatchingTask; -import org.apache.tools.todo.types.DirectoryScanner; -import org.apache.myrmidon.framework.file.Path; -import org.apache.myrmidon.framework.file.FileListUtil; - -/** - * 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.add( 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) - String[] args = new String[ 12 ]; - - File jspFile = null; - String parents = ""; - 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++ ] = FileListUtil.formatPath( compileClasspath, getContext() ); - - 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 ); - - ExecuteJava helperTask = new ExecuteJava(); - helperTask.setClassName( "weblogic.jspc" ); - helperTask.getArguments().addArguments( args ); - helperTask.getClassPath().add( compileClasspath ); - helperTask.executeForked( getContext() ); - } - } - - 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/todo/org/apache/tools/todo/taskdefs/jsp/compilers/CompilerAdapter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/compilers/CompilerAdapter.java deleted file mode 100644 index f53c10ce5..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/jsp/compilers/CompilerAdapterFactory.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/compilers/CompilerAdapterFactory.java deleted file mode 100644 index 327ee4644..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/jsp/compilers/DefaultCompilerAdapter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/compilers/DefaultCompilerAdapter.java deleted file mode 100644 index e417fc37d..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/compilers/DefaultCompilerAdapter.java +++ /dev/null @@ -1,91 +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.myrmidon.api.TaskException; -import org.apache.tools.todo.taskdefs.jsp.JspC; -import org.apache.myrmidon.framework.nativelib.Commandline; -import org.apache.myrmidon.framework.nativelib.ArgumentList; -import org.apache.tools.todo.util.FileUtils; - -/** - * 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, - ArgumentList cmd ) - throws TaskException - { - final String[] args = cmd.getArguments(); - getTaskContext().debug( "Compilation args: " + FileUtils.formatCommandLine( args ) ); - - 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/todo/org/apache/tools/todo/taskdefs/jsp/compilers/JasperC.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/compilers/JasperC.java deleted file mode 100644 index e6ebb085c..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/jsp/compilers/JasperC.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.jsp.compilers; - -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.java.ExecuteJava; -import org.apache.tools.todo.taskdefs.jsp.JspC; -import org.apache.myrmidon.framework.nativelib.Commandline; -import org.apache.myrmidon.framework.nativelib.ArgumentList; - -/** - * 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" ); - - final ExecuteJava exe = new ExecuteJava(); - exe.setClassName( "org.apache.jasper.JspC" ); - if( getJspc().getClasspath() != null ) - { - exe.getClassPath().add( getJspc().getClasspath() ); - } - - setupJasperCommand( exe.getArguments() ); - - // Create an instance of the compiler, redirecting output to - // the project log - exe.execute( getTaskContext() ); - return true; - } - - /* - * ------------------------------------------------------------ - */ - private void setupJasperCommand( final ArgumentList cmd ) - throws TaskException - { - 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 ); - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/AggregateTransformer.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/AggregateTransformer.java deleted file mode 100644 index 2a5a7903a..000000000 --- a/proposal/myrmidon/src/todo/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.TaskContext; -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 TaskContext m_context; - - /** - * the destination directory, this is the root from where html should be - * generated - */ - private File m_toDir; - - public AggregateTransformer( TaskContext context ) - { - m_context = context; - } - - 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_context.getBaseDirectory(), "." ); - } - else if( !m_toDir.isAbsolute() ) - { - m_toDir = FileUtil.resolveFile( m_context.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/todo/org/apache/tools/todo/taskdefs/junit/BaseTest.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/BaseTest.java deleted file mode 100644 index e7ded0010..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/junit/BatchTest.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/BatchTest.java deleted file mode 100644 index bdea85616..000000000 --- a/proposal/myrmidon/src/todo/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.myrmidon.framework.FileSet; -import org.apache.tools.todo.types.DirectoryScanner; -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/todo/org/apache/tools/todo/taskdefs/junit/BriefJUnitResultFormatter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/BriefJUnitResultFormatter.java deleted file mode 100644 index 0b2113c40..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/junit/CompoundIterator.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/CompoundIterator.java deleted file mode 100644 index 7ae384c43..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/junit/DOMElementWriter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/DOMElementWriter.java deleted file mode 100644 index 962e4c264..000000000 --- a/proposal/myrmidon/src/todo/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( " 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( StringUtil.LINE_SEPARATOR ); - out.flush(); - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/DOMUtil.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/DOMUtil.java deleted file mode 100644 index 4b1c8e72b..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/junit/FormatterElement.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/FormatterElement.java deleted file mode 100644 index 5d20a1a87..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/junit/JUnitResultFormatter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitResultFormatter.java deleted file mode 100644 index b77246588..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/junit/JUnitTask.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTask.java deleted file mode 100644 index c5046076b..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTask.java +++ /dev/null @@ -1,717 +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.util.ArrayList; -import java.util.Iterator; -import java.util.Properties; -import java.util.Random; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskContext; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.file.Path; -import org.apache.myrmidon.framework.file.FileListUtil; -import org.apache.myrmidon.framework.java.ExecuteJava; -import org.apache.myrmidon.framework.nativelib.Argument; -import org.apache.myrmidon.framework.nativelib.Commandline; -import org.apache.tools.todo.types.EnumeratedAttribute; -import org.apache.myrmidon.framework.nativelib.EnvironmentData; -import org.apache.myrmidon.framework.nativelib.EnvironmentVariable; -import org.apache.tools.todo.types.SysProperties; -import org.apache.myrmidon.framework.nativelib.ArgumentList; - -/** - * 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 ArrayList tests = new ArrayList(); - private ArrayList batchTests = new ArrayList(); - private ArrayList formatters = new ArrayList(); - - private Integer timeout = null; - private boolean summary = false; - private String summaryValue = ""; - private JUnitTestRunner runner = null; - private File dir; - private String jvm; - private String maxMem; - private EnvironmentData sysProperties = new EnvironmentData(); - private Path classPath = new Path(); - private ArgumentList vmArgs = new Commandline(); - - /** - * 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 ) - { - 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( final String value ) - { - jvm = 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( final String max ) - { - maxMem = 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 ) - { - sysProperties.addVariable( 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. - */ - public void addBatchTest( final BatchTest test ) - { - batchTests.add( test ); - } - - /** - * <classpath> allows classpath to be set for tests. - */ - public void addClasspath( final Path path ) - { - classPath.add( path ); - } - - /** - * Create a new JVM argument. Ignored if no JVM is forked. - * - * @see #setFork(boolean) - */ - public void addJvmarg( final Argument argument ) - { - vmArgs.addArgument( 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" ); - classPath.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" ); - classPath.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( final 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 - { - ExecuteJava cmd = new ExecuteJava(); - cmd.setJvm( jvm ); - cmd.setIgnoreReturnCode( true ); - cmd.setWorkingDirectory( dir ); - cmd.setMaxMemory( maxMem ); - cmd.getClassPath().add( classPath ); - cmd.getVmArguments().addArguments( vmArgs ); - cmd.getSysProperties().addVariables( sysProperties ); - - cmd.setClassName( "org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" ); - cmd.getArguments().addArgument( test.getName() ); - cmd.getArguments().addArgument( "filtertrace=" + test.getFiltertrace() ); - cmd.getArguments().addArgument( "haltOnError=" + test.getHaltonerror() ); - cmd.getArguments().addArgument( "haltOnFailure=" + test.getHaltonfailure() ); - if( summary ) - { - getContext().info( "Running " + test.getName() ); - cmd.getArguments().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.getArguments().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.getArguments().addArgument( "propsfile=" + propsFile.getAbsolutePath() ); - Properties props = new Properties(); - props.putAll( getContext().getProperties() ); - try - { - final FileOutputStream outstream = new FileOutputStream( propsFile ); - props.store( outstream, "Ant JUnitTask generated properties file" ); - outstream.close(); - } - catch( IOException ioe ) - { - throw new TaskException( "Error creating temporary properties file.", ioe ); - } - - try - { - return cmd.executeForked( getContext() ); - } - 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() ); - - SysProperties.setSystem( sysProperties ); - - try - { - getContext().debug( "Using System properties " + System.getProperties() ); - final ClassLoader classLoader = FileListUtil.createClassLoader( classPath, getContext() ); - - 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 - { - 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/todo/org/apache/tools/todo/taskdefs/junit/JUnitTest.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTest.java deleted file mode 100644 index 87d457e53..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/junit/JUnitTestRunner.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitTestRunner.java deleted file mode 100644 index 6910a74ce..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/junit/JUnitVersionHelper.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/JUnitVersionHelper.java deleted file mode 100644 index 9bfe0a4a1..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/junit/NodeListImpl.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/NodeListImpl.java deleted file mode 100644 index a2f7f1368..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/junit/PlainJUnitResultFormatter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/PlainJUnitResultFormatter.java deleted file mode 100644 index 41ca0f71f..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/junit/SummaryJUnitResultFormatter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/SummaryJUnitResultFormatter.java deleted file mode 100644 index 62ecdaf9d..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/junit/XMLConstants.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/XMLConstants.java deleted file mode 100644 index 1421c6dd8..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/junit/XMLJUnitResultFormatter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/XMLJUnitResultFormatter.java deleted file mode 100644 index 141986ddb..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/junit/XMLResultAggregator.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/XMLResultAggregator.java deleted file mode 100644 index 01e4b7e04..000000000 --- a/proposal/myrmidon/src/todo/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.myrmidon.framework.FileSet; -import org.apache.tools.todo.types.DirectoryScanner; -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( getContext() ); - 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/todo/org/apache/tools/todo/taskdefs/junit/Xalan1Executor.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/Xalan1Executor.java deleted file mode 100644 index 8ae1662e5..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/junit/Xalan2Executor.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/Xalan2Executor.java deleted file mode 100644 index 84b1bbddb..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/junit/XalanExecutor.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/junit/XalanExecutor.java deleted file mode 100644 index b5df22b60..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/manifest/Attribute.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/manifest/Attribute.java deleted file mode 100644 index b92602176..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/manifest/Manifest.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/manifest/Manifest.java deleted file mode 100644 index 397bf780f..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/manifest/ManifestException.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/manifest/ManifestException.java deleted file mode 100644 index 30ee6567d..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/manifest/ManifestMode.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/manifest/ManifestMode.java deleted file mode 100644 index 77df088b8..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/manifest/ManifestTask.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/manifest/ManifestTask.java deleted file mode 100644 index 2a6909b89..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/manifest/ManifestUtil.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/manifest/ManifestUtil.java deleted file mode 100644 index 00bb29ec4..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/manifest/Section.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/manifest/Section.java deleted file mode 100644 index b1653b045..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/manifest/default.mf b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/manifest/default.mf deleted file mode 100644 index 1dc733da7..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/net/Action.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/net/Action.java deleted file mode 100644 index 741b57f49..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/net/AntTelnetClient.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/net/AntTelnetClient.java deleted file mode 100644 index 3eddb954e..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/net/FTP.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/net/FTP.java deleted file mode 100644 index 231911c74..000000000 --- a/proposal/myrmidon/src/todo/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.myrmidon.framework.FileSet; -import org.apache.tools.todo.types.FileScanner; -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().verbose( "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().verbose( "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().verbose( "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().verbose( "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().verbose( "directory already exists" ); - } - } - else - { - if( m_verbose ) - { - getContext().verbose( "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().verbose( "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/todo/org/apache/tools/todo/taskdefs/net/FTPDirectoryScanner.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/net/FTPDirectoryScanner.java deleted file mode 100644 index 3919cca0f..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/net/MimeMail.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/net/MimeMail.java deleted file mode 100644 index 05ed3110e..000000000 --- a/proposal/myrmidon/src/todo/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.myrmidon.framework.FileSet; -import org.apache.tools.todo.types.DirectoryScanner; -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/todo/org/apache/tools/todo/taskdefs/net/TelnetRead.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/net/TelnetRead.java deleted file mode 100644 index 9e1680c7b..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/net/TelnetSubTask.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/net/TelnetSubTask.java deleted file mode 100644 index 6337962f4..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/net/TelnetTask.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/net/TelnetTask.java deleted file mode 100644 index 81dbd184d..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/net/TelnetWrite.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/net/TelnetWrite.java deleted file mode 100644 index 6b6998bac..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/rmic/DefaultRmicAdapter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/DefaultRmicAdapter.java deleted file mode 100644 index c5a852b1d..000000000 --- a/proposal/myrmidon/src/todo/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.myrmidon.framework.file.FileListUtil; -import org.apache.myrmidon.framework.file.Path; -import org.apache.myrmidon.framework.nativelib.ArgumentList; -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 ArgumentList 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 ArgumentList setupRmicCommand( String[] options ) - throws TaskException - { - ArgumentList cmd = new ArgumentList(); - - if( options != null ) - { - cmd.addArguments( options ); - } - - Path classpath = getCompileClasspath(); - - cmd.addArgument( "-d" ); - cmd.addArgument( attributes.getBase() ); - - if( attributes.getExtdirs() != null ) - { - cmd.addArgument( "-extdirs" ); - cmd.addArgument( FileListUtil.formatPath( attributes.getExtdirs(), getTaskContext() ) ); - } - - cmd.addArgument( "-classpath" ); - cmd.addArgument( FileListUtil.formatPath( classpath, getTaskContext() ) ); - - 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().verbose( "IIOP has been turned on." ); - cmd.addArgument( "-iiop" ); - if( attributes.getIiopopts() != null ) - { - getTaskContext().verbose( "IIOP Options: " + attributes.getIiopopts() ); - cmd.addArgument( attributes.getIiopopts() ); - } - } - - if( attributes.getIdl() ) - { - cmd.addArgument( "-idl" ); - getTaskContext().verbose( "IDL has been turned on." ); - if( attributes.getIdlopts() != null ) - { - cmd.addArgument( attributes.getIdlopts() ); - getTaskContext().verbose( "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.add( 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( final ArgumentList cmd ) - throws TaskException - { - ArrayList compileList = attributes.getCompileList(); - - final String[] args = cmd.getArguments(); - getTaskContext().debug( "Compilation args: " + FileUtils.formatCommandLine( args ) ); - - 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/todo/org/apache/tools/todo/taskdefs/rmic/KaffeRmic.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/KaffeRmic.java deleted file mode 100644 index 3192bc692..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/KaffeRmic.java +++ /dev/null @@ -1,62 +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.myrmidon.framework.nativelib.Commandline; -import org.apache.myrmidon.framework.nativelib.ArgumentList; -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" ); - ArgumentList 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/todo/org/apache/tools/todo/taskdefs/rmic/Rmic.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/Rmic.java deleted file mode 100644 index bf0bf69ea..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/Rmic.java +++ /dev/null @@ -1,623 +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.rmi.Remote; -import java.util.ArrayList; -import org.apache.avalon.excalibur.io.FileUtil; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.FileNameMapper; -import org.apache.myrmidon.framework.file.Path; -import org.apache.myrmidon.framework.file.FileListUtil; -import org.apache.tools.todo.taskdefs.MatchingTask; -import org.apache.tools.todo.types.DirectoryScanner; -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.add( 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.add( 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().verbose( "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(); - loader = FileListUtil.createClassLoader( classpath, getContext() ); - - // 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/todo/org/apache/tools/todo/taskdefs/rmic/RmicAdapter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/RmicAdapter.java deleted file mode 100644 index 036297c62..000000000 --- a/proposal/myrmidon/src/todo/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.myrmidon.framework.file.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/todo/org/apache/tools/todo/taskdefs/rmic/RmicAdapterFactory.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/RmicAdapterFactory.java deleted file mode 100644 index 41f58cb93..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/rmic/SunRmic.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/SunRmic.java deleted file mode 100644 index 3b4a8c2b1..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/SunRmic.java +++ /dev/null @@ -1,67 +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.myrmidon.framework.nativelib.Commandline; -import org.apache.myrmidon.framework.nativelib.ArgumentList; -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" ); - ArgumentList 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/todo/org/apache/tools/todo/taskdefs/rmic/WLRmic.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/WLRmic.java deleted file mode 100644 index c155cec64..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/rmic/WLRmic.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.rmic; - -import java.lang.reflect.Method; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.TaskContext; -import org.apache.myrmidon.framework.java.ExecuteJava; -import org.apache.myrmidon.framework.nativelib.Commandline; -import org.apache.myrmidon.framework.nativelib.ArgumentList; -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" ); - - final ExecuteJava exe = new ExecuteJava(); - exe.setClassName( "weblogic.rmic" ); - final ArgumentList cmd = setupRmicCommand( new String[]{"-noexit"} ); - exe.getArguments().addArguments( cmd ); - - exe.execute( getTaskContext() ); - return true; - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/stylebook/StyleBook.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/stylebook/StyleBook.java deleted file mode 100644 index 33191c7b9..000000000 --- a/proposal/myrmidon/src/todo/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.antlib.java.JavaTask; -import org.apache.myrmidon.framework.nativelib.Argument; - -/** - * Basic task for apache stylebook. - * - * @author Peter Donald - * @author Marcus - * Börger - */ -public class StyleBook - extends JavaTask -{ - 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 ) ); - addArg( new Argument( m_skinDirectory ) ); - 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/todo/org/apache/tools/todo/taskdefs/text/AddAsisRemove.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/text/AddAsisRemove.java deleted file mode 100644 index 82937c9c5..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/text/CrLf.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/text/CrLf.java deleted file mode 100644 index 221874a3d..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/text/FixCRLF.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/text/FixCRLF.java deleted file mode 100644 index 5266db92c..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/text/Native2Ascii.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/text/Native2Ascii.java deleted file mode 100644 index da7ba5b2b..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/text/Native2Ascii.java +++ /dev/null @@ -1,223 +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.framework.FileNameMapper; -import org.apache.tools.todo.taskdefs.MatchingTask; -import org.apache.tools.todo.types.DirectoryScanner; -import org.apache.tools.todo.types.SourceFileScanner; -import org.apache.myrmidon.framework.nativelib.ArgumentList; -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 ArgumentList 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 ArgumentList buildCommand( final File srcFile, - final File destFile ) - { - final ArgumentList cmd = new ArgumentList();// 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/todo/org/apache/tools/todo/taskdefs/text/NestedString.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/text/NestedString.java deleted file mode 100644 index 32165ece9..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/text/RegularExpression.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/text/RegularExpression.java deleted file mode 100644 index 3b12fca26..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/text/Replace.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/text/Replace.java deleted file mode 100644 index 188602618..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/text/ReplaceRegExp.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/text/ReplaceRegExp.java deleted file mode 100644 index 5795daf35..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/text/ReplaceRegExp.java +++ /dev/null @@ -1,398 +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.framework.FileSet; -import org.apache.tools.todo.types.DirectoryScanner; -import org.apache.tools.todo.types.ScannerUtil; -import org.apache.tools.todo.util.regexp.Regexp; - -/** - *
- * 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().info( 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/todo/org/apache/tools/todo/taskdefs/text/Replacefilter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/text/Replacefilter.java deleted file mode 100644 index 00759abac..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/text/Substitution.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/text/Substitution.java deleted file mode 100644 index d7b315a8c..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/taskdefs/vss/MSVSS.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSS.java deleted file mode 100644 index 214ff0050..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSS.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 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.nativelib.Execute; -import org.apache.myrmidon.framework.nativelib.Commandline; -import org.apache.myrmidon.framework.nativelib.ArgumentList; - -/** - * 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( ArgumentList cmd ) - { - if( m_vssLogin == null ) - { - return; - } - else - { - cmd.addArgument( FLAG_LOGIN + m_vssLogin ); - } - } - - /** - * @return m_vssPath - */ - public String getVsspath() - { - return m_vssPath; - } - - protected void run( final Execute exe ) - throws TaskException - { - // 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.execute( getContext() ); - } -} - diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKIN.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKIN.java deleted file mode 100644 index f5a25a801..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKIN.java +++ /dev/null @@ -1,206 +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.framework.nativelib.ArgumentList; -import org.apache.myrmidon.framework.nativelib.Execute; - -/** - * Task to perform CheckIn commands to Microsoft Visual Source Safe. - * - * @author Martin Poeschl - */ -public class MSVSSCHECKIN - extends MSVSS -{ - private File 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 File localPath ) - { - m_localPath = localPath; - } - - /** - * 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 ArgumentList 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 ArgumentList cmd ) - throws TaskException - { - if( m_localPath == null ) - { - return; - } - - // make sure m_LocalDir exists, create it if it doesn't - if( !m_localPath.exists() ) - { - if( !m_localPath.mkdirs() ) - { - final String message = - "Directory " + m_localPath + " creation was not " + - "succesful for an unknown reason"; - throw new TaskException( message ); - } - - final String message = "Created dir: " + m_localPath.getAbsolutePath(); - getContext().info( message ); - } - cmd.addArgument( FLAG_OVERRIDE_WORKING_DIR + m_localPath ); - } - - private void getRecursiveCommand( final ArgumentList cmd ) - { - if( !m_recursive ) - { - return; - } - else - { - cmd.addArgument( FLAG_RECURSION ); - } - } - - private void getWritableCommand( final ArgumentList 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 Execute exe = new Execute(); - - // 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 - exe.setExecutable( getSSCommand() ); - exe.addArgument( COMMAND_CHECKIN ); - - // VSS items - exe.addArgument( vsspath ); - // -GL - getLocalpathCommand( exe ); - // -I- or -I-Y or -I-N - getAutoresponse( exe ); - // -R - getRecursiveCommand( exe ); - // -W - getWritableCommand( exe ); - // -Y - getLoginCommand( exe ); - // -C - exe.addArgument( "-C" + m_comment ); - - run( exe ); - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKOUT.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKOUT.java deleted file mode 100644 index 30a3e5115..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSCHECKOUT.java +++ /dev/null @@ -1,246 +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.framework.nativelib.ArgumentList; -import org.apache.myrmidon.framework.nativelib.Execute; - -/** - * Task to perform CheckOut commands to Microsoft Visual Source Safe. - * - * @author Martin Poeschl - */ -public class MSVSSCHECKOUT - extends MSVSS -{ - private File 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 File localPath ) - { - m_localPath = localPath; - } - - /** - * 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 ArgumentList 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 ArgumentList cmd ) - throws TaskException - { - // make sure m_LocalDir exists, create it if it doesn't - if( m_localPath == null ) - { - return; - } - if( !m_localPath.exists() ) - { - if( !m_localPath.mkdirs() ) - { - final String message = - "Directory " + m_localPath + " creation was not " + - "succesful for an unknown reason"; - throw new TaskException( message ); - } - final String message = "Created dir: " + m_localPath.getAbsolutePath(); - getContext().info( message ); - } - cmd.addArgument( FLAG_OVERRIDE_WORKING_DIR + m_localPath ); - } - - private void getRecursiveCommand( final ArgumentList 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 ArgumentList 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 Execute exe = new Execute(); - - // 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 - exe.setExecutable( getSSCommand() ); - exe.addArgument( COMMAND_CHECKOUT ); - - // VSS items - exe.addArgument( vsspath ); - // -GL - getLocalpathCommand( exe ); - // -I- or -I-Y or -I-N - getAutoresponse( exe ); - // -R - getRecursiveCommand( exe ); - // -V - getVersionCommand( exe ); - // -Y - getLoginCommand( exe ); - - run( exe ); - } -} - diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSGET.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSGET.java deleted file mode 100644 index a3ba4446f..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSGET.java +++ /dev/null @@ -1,508 +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.framework.nativelib.ArgumentList; -import org.apache.myrmidon.framework.nativelib.Execute; - -/** - * 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 File 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( final File localPath ) - { - m_LocalPath = localPath; - } - - /** - * 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( ArgumentList 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( ArgumentList cmd ) - throws TaskException - { - if( m_LocalPath == null ) - { - return; - } - else - { - // make sure m_LocalDir exists, create it if it doesn't - if( !m_LocalPath.exists() ) - { - boolean done = m_LocalPath.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: " + m_LocalPath.getAbsolutePath() ); - } - - cmd.addArgument( FLAG_OVERRIDE_WORKING_DIR + m_LocalPath ); - } - } - - public void getQuietCommand( ArgumentList cmd ) - { - if( m_Quiet ) - { - cmd.addArgument( FLAG_QUIET ); - } - } - - /** - * @param cmd Description of Parameter - */ - public void getRecursiveCommand( ArgumentList 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( ArgumentList 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( ArgumentList 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 - { - Execute exe = new Execute(); - - // 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 - exe.setExecutable( getSSCommand() ); - exe.addArgument( COMMAND_GET ); - - // VSS items - exe.addArgument( getVsspath() ); - // -GL - getLocalpathCommand( exe ); - // -I- or -I-Y or -I-N - getAutoresponse( exe ); - // -O- - getQuietCommand( exe ); - // -R - getRecursiveCommand( exe ); - // -V - getVersionCommand( exe ); - // -W - getWritableCommand( exe ); - // -Y - getLoginCommand( exe ); - - run( exe ); - } - -} - diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSHISTORY.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSHISTORY.java deleted file mode 100644 index 37bab71ac..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSHISTORY.java +++ /dev/null @@ -1,405 +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.myrmidon.framework.nativelib.ArgumentList; -import org.apache.myrmidon.framework.nativelib.Execute; -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 - { - Execute exe = new Execute(); - - // 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 - exe.setExecutable( getSSCommand() ); - exe.addArgument( COMMAND_HISTORY ); - - // VSS items - exe.addArgument( getVsspath() ); - - // -I- - exe.addArgument( "-I-" );// ignore all errors - - // -V - // Label an existing file or project version - getVersionDateCommand( exe ); - getVersionLabelCommand( exe ); - - // -R - if( m_Recursive ) - { - exe.addArgument( FLAG_RECURSION ); - } - - // -B / -D / -F- - if( m_Style.length() > 0 ) - { - exe.addArgument( m_Style ); - } - - // -Y - getLoginCommand( exe ); - - // -O - getOutputCommand( exe ); - - run( exe ); - } - - /** - * Builds the version date command. - * - * @param cmd the commandline the command is to be added to - */ - private void getOutputCommand( ArgumentList cmd ) - { - if( m_OutputFileName != null ) - { - cmd.addArgument( FLAG_OUTPUT + m_OutputFileName ); - } - } - - /** - * Builds the version date command. - * - * @param cmd the commandline the command is to be added to - * @exception TaskException Description of Exception - */ - private void getVersionDateCommand( ArgumentList 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( ArgumentList 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/todo/org/apache/tools/todo/taskdefs/vss/MSVSSLABEL.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSLABEL.java deleted file mode 100644 index 9ffdebb36..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/taskdefs/vss/MSVSSLABEL.java +++ /dev/null @@ -1,370 +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.myrmidon.framework.nativelib.ArgumentList; -import org.apache.myrmidon.framework.nativelib.Execute; - -/** - * 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( ArgumentList 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( ArgumentList 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( ArgumentList 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 - { - Execute exe = new Execute(); - - // 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 - exe.setExecutable( getSSCommand() ); - exe.addArgument( COMMAND_LABEL ); - - // VSS items - exe.addArgument( getVsspath() ); - - // -C - exe.addArgument( "-C" + getComment() ); - - // -I- or -I-Y or -I-N - getAutoresponse( exe ); - - // -L - // Specify the new label on the command line (instead of being prompted) - getLabelCommand( exe ); - - // -V - // Label an existing file or project version - getVersionCommand( exe ); - - // -Y - getLoginCommand( exe ); - - run( exe ); - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/DirectoryScanner.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/DirectoryScanner.java deleted file mode 100644 index 45117aa12..000000000 --- a/proposal/myrmidon/src/todo/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.separators 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/todo/org/apache/tools/todo/types/EnumeratedAttribute.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/EnumeratedAttribute.java deleted file mode 100644 index 919a9e5f9..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/types/FileScanner.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/FileScanner.java deleted file mode 100644 index 29bb12c5d..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/types/ScannerUtil.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/ScannerUtil.java deleted file mode 100644 index ddc58fa15..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/ScannerUtil.java +++ /dev/null @@ -1,634 +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.myrmidon.framework.FileSet; -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; - -/** - * - * - * @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 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 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 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/todo/org/apache/tools/todo/types/SimpleFileList.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/SimpleFileList.java deleted file mode 100644 index cf996add3..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/SimpleFileList.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 SimpleFileList -{ - private final ArrayList m_filenames = new ArrayList(); - private File m_dir; - - public SimpleFileList() - { - } - - 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/todo/org/apache/tools/todo/types/SourceFileScanner.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/SourceFileScanner.java deleted file mode 100644 index 6b3b3a6e0..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/types/SysProperties.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/types/SysProperties.java deleted file mode 100644 index f13b66b03..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/types/SysProperties.java +++ /dev/null @@ -1,120 +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 java.util.Map; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.nativelib.EnvironmentData; - -/** - * A utility class for handling System properties - * - * @todo move this to AUT - */ -final public class SysProperties -{ - private static Properties m_system; - - private SysProperties() - { - } - - /** - * Sets system properties. The current set of system properties can be - * restored using {@link #restoreSystem}. - */ - public static void setSystem( final EnvironmentData properties ) - throws TaskException - { - setSystem( properties.getVariables() ); - } - - /** - * Sets system properties. The current set of system properties can be - * restored using {@link #restoreSystem}. - */ - public synchronized static void setSystem( final Map properties ) - throws TaskException - { - if( properties.size() == 0 ) - { - return; - } - if( m_system != null ) - { - throw new TaskException( "System properties have not been restored." ); - } - - final Properties sysProps; - try - { - sysProps = System.getProperties(); - Properties allProps = new Properties( sysProps ); - allProps.putAll( properties ); - System.setProperties( allProps ); - } - catch( final SecurityException e ) - { - throw new TaskException( "Cannot modify system properties.", e ); - } - - m_system = sysProps; - } - - /** - * Restores the system properties to what they were before the last - * call to {@link #setSystem}. - */ - public static synchronized void restoreSystem() - throws TaskException - { - if( m_system == null ) - { - return; - } - - try - { - System.setProperties( m_system ); - m_system = null; - } - catch( final SecurityException e ) - { - throw new TaskException( "Cannot modify system properties.", e ); - } - } - - /** - * Converts a set of properties to their -D command-line equivalent. - */ - public static String[] getJavaVariables( final EnvironmentData environment ) - { - return getJavaVariables( environment.getVariables() ); - } - - /** - * Converts a set of properties to their -D command-line equivalent. - */ - public static String[] getJavaVariables( final Map environment ) - { - final ArrayList vars = new ArrayList(); - - final Iterator keys = environment.keySet().iterator(); - while( keys.hasNext() ) - { - final String key = (String)keys.next(); - final Object value = environment.get( key ); - vars.add( "-D" + key + '=' + value ); - } - - return (String[])vars.toArray( new String[ vars.size() ] ); - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/todo/util/FileUtils.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/FileUtils.java deleted file mode 100644 index 079611d6f..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/todo/util/FileUtils.java +++ /dev/null @@ -1,404 +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; - -/** - * 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 ); - } - - /** - * Builds a command-line from an array of individual arguments, quoting - * the arguments as necessary. - * - * @todo Move to {@link org.apache.aut.nativelib.Os}, and get rid of the - * exception. - */ - public static String formatCommandLine( final String[] arguments ) - throws TaskException - { - final StringBuffer cmd = new StringBuffer(); - for( int i = 0; i < arguments.length; i++ ) - { - String arg = arguments[ i ]; - if( i > 0 ) - { - cmd.append( ' ' ); - } - cmd.append( quoteArgument( arg ) ); - } - - return cmd.toString(); - } - - /** - * 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.

- * - * @todo Move to {@link org.apache.aut.nativelib.Os}, and get rid of the - * exception. - */ - public static String quoteArgument( final 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( final 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/todo/org/apache/tools/todo/util/PathTokenizer.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/PathTokenizer.java deleted file mode 100644 index d8e7bfd41..000000000 --- a/proposal/myrmidon/src/todo/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 - */ -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/todo/org/apache/tools/todo/util/depend/Dependencies.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/depend/Dependencies.java deleted file mode 100644 index b4fa1daec..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/util/depend/Filter.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/depend/Filter.java deleted file mode 100644 index d66601388..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/util/mappers/GlobPatternMapper.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/mappers/GlobPatternMapper.java deleted file mode 100644 index 7a2b2f6bd..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/util/mappers/IdentityMapper.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/mappers/IdentityMapper.java deleted file mode 100644 index 2498633f5..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/util/mappers/MergingMapper.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/mappers/MergingMapper.java deleted file mode 100644 index 7788c03c5..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/util/mappers/RegexpPatternMapper.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/mappers/RegexpPatternMapper.java deleted file mode 100644 index fd6a72bd4..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/util/regexp/JakartaOroMatcher.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/regexp/JakartaOroMatcher.java deleted file mode 100644 index fe7493511..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/util/regexp/JakartaOroRegexp.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/regexp/JakartaOroRegexp.java deleted file mode 100644 index 7e0a8d588..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/util/regexp/JakartaRegexpMatcher.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/regexp/JakartaRegexpMatcher.java deleted file mode 100644 index 83ebb6d3b..000000000 --- a/proposal/myrmidon/src/todo/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.toString(), 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/todo/org/apache/tools/todo/util/regexp/JakartaRegexpRegexp.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/regexp/JakartaRegexpRegexp.java deleted file mode 100644 index e2053afb7..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/util/regexp/Jdk14RegexpMatcher.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/regexp/Jdk14RegexpMatcher.java deleted file mode 100644 index 38ab56ba0..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/util/regexp/Jdk14RegexpRegexp.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/regexp/Jdk14RegexpRegexp.java deleted file mode 100644 index e98a2a83e..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/util/regexp/Regexp.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/regexp/Regexp.java deleted file mode 100644 index cf6db2a98..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/util/regexp/RegexpFactory.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/regexp/RegexpFactory.java deleted file mode 100644 index b1c2ece8c..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/util/regexp/RegexpMatcher.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/regexp/RegexpMatcher.java deleted file mode 100644 index 680c876de..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/util/regexp/RegexpMatcherFactory.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/regexp/RegexpMatcherFactory.java deleted file mode 100644 index 36b7bebf0..000000000 --- a/proposal/myrmidon/src/todo/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/todo/org/apache/tools/todo/util/regexp/RegexpUtil.java b/proposal/myrmidon/src/todo/org/apache/tools/todo/util/regexp/RegexpUtil.java deleted file mode 100644 index fe3ebb631..000000000 --- a/proposal/myrmidon/src/todo/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 ) ); - } -}