git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270155 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -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 file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.util.Enumeration; | |||
| import java.util.Vector; | |||
| import org.apache.tools.ant.types.PatternSet; | |||
| /** | |||
| * This task will compile and load a new taskdef all in one step. At times, this | |||
| * is useful for eliminating ordering dependencies which otherwise would require | |||
| * multiple executions of Ant. | |||
| * | |||
| * @author Sam Ruby <a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a> | |||
| * @deprecated use <taskdef> elements nested into <target>s instead | |||
| */ | |||
| public class CompileTask extends Javac | |||
| { | |||
| protected Vector taskList = new Vector(); | |||
| /** | |||
| * add a new task entry on the task list | |||
| * | |||
| * @return Description of the Returned Value | |||
| */ | |||
| public Taskdef createTaskdef() | |||
| { | |||
| Taskdef task = new Taskdef(); | |||
| taskList.addElement( task ); | |||
| return task; | |||
| } | |||
| /** | |||
| * have execute do nothing | |||
| */ | |||
| public void execute() { } | |||
| /** | |||
| * do all the real work in init | |||
| */ | |||
| public void init() | |||
| { | |||
| log( "!! CompileTask is deprecated. !!" ); | |||
| log( "Use <taskdef> elements nested into <target>s instead" ); | |||
| // create all the include entries from the task defs | |||
| for( Enumeration e = taskList.elements(); e.hasMoreElements(); ) | |||
| { | |||
| Taskdef task = ( Taskdef )e.nextElement(); | |||
| String source = task.getClassname().replace( '.', '/' ) + ".java"; | |||
| PatternSet.NameEntry include = super.createInclude(); | |||
| include.setName( "**/" + source ); | |||
| } | |||
| // execute Javac | |||
| super.init(); | |||
| super.execute(); | |||
| // now define all the new tasks | |||
| for( Enumeration e = taskList.elements(); e.hasMoreElements(); ) | |||
| { | |||
| Taskdef task = ( Taskdef )e.nextElement(); | |||
| task.init(); | |||
| } | |||
| } | |||
| } | |||
| @@ -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 file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.util.Enumeration; | |||
| import java.util.Hashtable; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.DirectoryScanner; | |||
| /** | |||
| * Copies a directory. | |||
| * | |||
| * @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a> | |||
| * @deprecated The copydir task is deprecated. Use copy instead. | |||
| */ | |||
| public class Copydir extends MatchingTask | |||
| { | |||
| private boolean filtering = false; | |||
| private boolean flatten = false; | |||
| private boolean forceOverwrite = false; | |||
| private Hashtable filecopyList = new Hashtable(); | |||
| private File destDir; | |||
| private File srcDir; | |||
| public void setDest( File dest ) | |||
| { | |||
| destDir = dest; | |||
| } | |||
| public void setFiltering( boolean filter ) | |||
| { | |||
| filtering = filter; | |||
| } | |||
| public void setFlatten( boolean flatten ) | |||
| { | |||
| this.flatten = flatten; | |||
| } | |||
| public void setForceoverwrite( boolean force ) | |||
| { | |||
| forceOverwrite = force; | |||
| } | |||
| public void setSrc( File src ) | |||
| { | |||
| srcDir = src; | |||
| } | |||
| public void execute() | |||
| throws BuildException | |||
| { | |||
| log( "DEPRECATED - The copydir task is deprecated. Use copy instead." ); | |||
| if( srcDir == null ) | |||
| { | |||
| throw new BuildException( "src attribute must be set!", | |||
| location ); | |||
| } | |||
| if( !srcDir.exists() ) | |||
| { | |||
| throw new BuildException( "srcdir " + srcDir.toString() | |||
| + " does not exist!", location ); | |||
| } | |||
| if( destDir == null ) | |||
| { | |||
| throw new BuildException( "The dest attribute must be set.", location ); | |||
| } | |||
| if( srcDir.equals( destDir ) ) | |||
| { | |||
| log( "Warning: src == dest" ); | |||
| } | |||
| DirectoryScanner ds = super.getDirectoryScanner( srcDir ); | |||
| String[] files = ds.getIncludedFiles(); | |||
| scanDir( srcDir, destDir, files ); | |||
| if( filecopyList.size() > 0 ) | |||
| { | |||
| log( "Copying " + filecopyList.size() + " file" | |||
| + ( filecopyList.size() == 1 ? "" : "s" ) | |||
| + " to " + destDir.getAbsolutePath() ); | |||
| Enumeration enum = filecopyList.keys(); | |||
| while( enum.hasMoreElements() ) | |||
| { | |||
| String fromFile = ( String )enum.nextElement(); | |||
| String toFile = ( String )filecopyList.get( fromFile ); | |||
| try | |||
| { | |||
| project.copyFile( fromFile, toFile, filtering, | |||
| forceOverwrite ); | |||
| } | |||
| catch( IOException ioe ) | |||
| { | |||
| String msg = "Failed to copy " + fromFile + " to " + toFile | |||
| + " due to " + ioe.getMessage(); | |||
| throw new BuildException( msg, ioe, location ); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| private void scanDir( File from, File to, String[] files ) | |||
| { | |||
| for( int i = 0; i < files.length; i++ ) | |||
| { | |||
| String filename = files[i]; | |||
| File srcFile = new File( from, filename ); | |||
| File destFile; | |||
| if( flatten ) | |||
| { | |||
| destFile = new File( to, new File( filename ).getName() ); | |||
| } | |||
| else | |||
| { | |||
| destFile = new File( to, filename ); | |||
| } | |||
| if( forceOverwrite || | |||
| ( srcFile.lastModified() > destFile.lastModified() ) ) | |||
| { | |||
| filecopyList.put( srcFile.getAbsolutePath(), | |||
| destFile.getAbsolutePath() ); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -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 file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| * Copies a file. | |||
| * | |||
| * @author duncan@x180.com | |||
| * @deprecated The copyfile task is deprecated. Use copy instead. | |||
| */ | |||
| public class Copyfile extends Task | |||
| { | |||
| private boolean filtering = false; | |||
| private boolean forceOverwrite = false; | |||
| private File destFile; | |||
| private File srcFile; | |||
| public void setDest( File dest ) | |||
| { | |||
| destFile = dest; | |||
| } | |||
| public void setFiltering( String filter ) | |||
| { | |||
| filtering = Project.toBoolean( filter ); | |||
| } | |||
| public void setForceoverwrite( boolean force ) | |||
| { | |||
| forceOverwrite = force; | |||
| } | |||
| public void setSrc( File src ) | |||
| { | |||
| srcFile = src; | |||
| } | |||
| public void execute() | |||
| throws BuildException | |||
| { | |||
| log( "DEPRECATED - The copyfile task is deprecated. Use copy instead." ); | |||
| if( srcFile == null ) | |||
| { | |||
| throw new BuildException( "The src attribute must be present.", location ); | |||
| } | |||
| if( !srcFile.exists() ) | |||
| { | |||
| throw new BuildException( "src " + srcFile.toString() | |||
| + " does not exist.", location ); | |||
| } | |||
| if( destFile == null ) | |||
| { | |||
| throw new BuildException( "The dest attribute must be present.", location ); | |||
| } | |||
| if( srcFile.equals( destFile ) ) | |||
| { | |||
| log( "Warning: src == dest" ); | |||
| } | |||
| if( forceOverwrite || srcFile.lastModified() > destFile.lastModified() ) | |||
| { | |||
| try | |||
| { | |||
| project.copyFile( srcFile, destFile, filtering, forceOverwrite ); | |||
| } | |||
| catch( IOException ioe ) | |||
| { | |||
| String msg = "Error copying file: " + srcFile.getAbsolutePath() | |||
| + " due to " + ioe.getMessage(); | |||
| throw new BuildException( msg ); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -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 file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| * @author duncan@x180.com | |||
| * @deprecated The deltree task is deprecated. Use delete instead. | |||
| */ | |||
| public class Deltree extends Task | |||
| { | |||
| private File dir; | |||
| public void setDir( File dir ) | |||
| { | |||
| this.dir = dir; | |||
| } | |||
| public void execute() | |||
| throws BuildException | |||
| { | |||
| log( "DEPRECATED - The deltree task is deprecated. Use delete instead." ); | |||
| if( dir == null ) | |||
| { | |||
| throw new BuildException( "dir attribute must be set!", location ); | |||
| } | |||
| if( dir.exists() ) | |||
| { | |||
| if( !dir.isDirectory() ) | |||
| { | |||
| if( !dir.delete() ) | |||
| { | |||
| throw new BuildException( "Unable to delete directory " | |||
| + dir.getAbsolutePath(), | |||
| location ); | |||
| } | |||
| return; | |||
| // String msg = "Given dir: " + dir.getAbsolutePath() + | |||
| // " is not a dir"; | |||
| // throw new BuildException(msg); | |||
| } | |||
| log( "Deleting: " + dir.getAbsolutePath() ); | |||
| try | |||
| { | |||
| removeDir( dir ); | |||
| } | |||
| catch( IOException ioe ) | |||
| { | |||
| String msg = "Unable to delete " + dir.getAbsolutePath(); | |||
| throw new BuildException( msg, location ); | |||
| } | |||
| } | |||
| } | |||
| private void removeDir( File dir ) | |||
| throws IOException | |||
| { | |||
| // check to make sure that the given dir isn't a symlink | |||
| // the comparison of absolute path and canonical path | |||
| // catches this | |||
| // if (dir.getCanonicalPath().equals(dir.getAbsolutePath())) { | |||
| // (costin) It will not work if /home/costin is symlink to /da0/home/costin ( taz | |||
| // for example ) | |||
| String[] list = dir.list(); | |||
| for( int i = 0; i < list.length; i++ ) | |||
| { | |||
| String s = list[i]; | |||
| File f = new File( dir, s ); | |||
| if( f.isDirectory() ) | |||
| { | |||
| removeDir( f ); | |||
| } | |||
| else | |||
| { | |||
| if( !f.delete() ) | |||
| { | |||
| throw new BuildException( "Unable to delete file " + f.getAbsolutePath() ); | |||
| } | |||
| } | |||
| } | |||
| if( !dir.delete() ) | |||
| { | |||
| throw new BuildException( "Unable to delete directory " + dir.getAbsolutePath() ); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,252 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.BufferedReader; | |||
| import java.io.File; | |||
| import java.io.FileWriter; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.io.InputStreamReader; | |||
| import java.io.PrintWriter; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| * Executes a given command if the os platform is appropriate. | |||
| * | |||
| * @author duncan@x180.com | |||
| * @author rubys@us.ibm.com | |||
| * @deprecated Instead of using this class, please extend ExecTask or delegate | |||
| * to Execute. | |||
| */ | |||
| public class Exec extends Task | |||
| { | |||
| private final static int BUFFER_SIZE = 512; | |||
| protected PrintWriter fos = null; | |||
| private boolean failOnError = false; | |||
| private String command; | |||
| private File dir; | |||
| private String os; | |||
| private String out; | |||
| public void setCommand( String command ) | |||
| { | |||
| this.command = command; | |||
| } | |||
| public void setDir( String d ) | |||
| { | |||
| this.dir = project.resolveFile( d ); | |||
| } | |||
| public void setFailonerror( boolean fail ) | |||
| { | |||
| failOnError = fail; | |||
| } | |||
| public void setOs( String os ) | |||
| { | |||
| this.os = os; | |||
| } | |||
| public void setOutput( String out ) | |||
| { | |||
| this.out = out; | |||
| } | |||
| public void execute() | |||
| throws BuildException | |||
| { | |||
| run( command ); | |||
| } | |||
| protected void logFlush() | |||
| { | |||
| if( fos != null ) | |||
| fos.close(); | |||
| } | |||
| protected void outputLog( String line, int messageLevel ) | |||
| { | |||
| if( fos == null ) | |||
| { | |||
| log( line, messageLevel ); | |||
| } | |||
| else | |||
| { | |||
| fos.println( line ); | |||
| } | |||
| } | |||
| protected int run( String command ) | |||
| throws BuildException | |||
| { | |||
| int err = -1;// assume the worst | |||
| // test if os match | |||
| String myos = System.getProperty( "os.name" ); | |||
| log( "Myos = " + myos, Project.MSG_VERBOSE ); | |||
| if( ( os != null ) && ( os.indexOf( myos ) < 0 ) ) | |||
| { | |||
| // this command will be executed only on the specified OS | |||
| log( "Not found in " + os, Project.MSG_VERBOSE ); | |||
| return 0; | |||
| } | |||
| // default directory to the project's base directory | |||
| if( dir == null ) | |||
| dir = project.getBaseDir(); | |||
| if( myos.toLowerCase().indexOf( "windows" ) >= 0 ) | |||
| { | |||
| if( !dir.equals( project.resolveFile( "." ) ) ) | |||
| { | |||
| if( myos.toLowerCase().indexOf( "nt" ) >= 0 ) | |||
| { | |||
| command = "cmd /c cd " + dir + " && " + command; | |||
| } | |||
| else | |||
| { | |||
| String ant = project.getProperty( "ant.home" ); | |||
| if( ant == null ) | |||
| { | |||
| throw new BuildException( "Property 'ant.home' not found", location ); | |||
| } | |||
| String antRun = project.resolveFile( ant + "/bin/antRun.bat" ).toString(); | |||
| command = antRun + " " + dir + " " + command; | |||
| } | |||
| } | |||
| } | |||
| else | |||
| { | |||
| String ant = project.getProperty( "ant.home" ); | |||
| if( ant == null ) | |||
| throw new BuildException( "Property 'ant.home' not found", location ); | |||
| String antRun = project.resolveFile( ant + "/bin/antRun" ).toString(); | |||
| command = antRun + " " + dir + " " + command; | |||
| } | |||
| try | |||
| { | |||
| // show the command | |||
| log( command, Project.MSG_VERBOSE ); | |||
| // exec command on system runtime | |||
| Process proc = Runtime.getRuntime().exec( command ); | |||
| if( out != null ) | |||
| { | |||
| fos = new PrintWriter( new FileWriter( out ) ); | |||
| log( "Output redirected to " + out, Project.MSG_VERBOSE ); | |||
| } | |||
| // copy input and error to the output stream | |||
| StreamPumper inputPumper = | |||
| new StreamPumper( proc.getInputStream(), Project.MSG_INFO, this ); | |||
| StreamPumper errorPumper = | |||
| new StreamPumper( proc.getErrorStream(), Project.MSG_WARN, this ); | |||
| // starts pumping away the generated output/error | |||
| inputPumper.start(); | |||
| errorPumper.start(); | |||
| // Wait for everything to finish | |||
| proc.waitFor(); | |||
| inputPumper.join(); | |||
| errorPumper.join(); | |||
| proc.destroy(); | |||
| // close the output file if required | |||
| logFlush(); | |||
| // check its exit value | |||
| err = proc.exitValue(); | |||
| if( err != 0 ) | |||
| { | |||
| if( failOnError ) | |||
| { | |||
| throw new BuildException( "Exec returned: " + err, location ); | |||
| } | |||
| else | |||
| { | |||
| log( "Result: " + err, Project.MSG_ERR ); | |||
| } | |||
| } | |||
| } | |||
| catch( IOException ioe ) | |||
| { | |||
| throw new BuildException( "Error exec: " + command, ioe, location ); | |||
| } | |||
| catch( InterruptedException ex ) | |||
| {} | |||
| return err; | |||
| } | |||
| // Inner class for continually pumping the input stream during | |||
| // Process's runtime. | |||
| class StreamPumper extends Thread | |||
| { | |||
| private boolean endOfStream = false; | |||
| private int SLEEP_TIME = 5; | |||
| private BufferedReader din; | |||
| private int messageLevel; | |||
| private Exec parent; | |||
| public StreamPumper( InputStream is, int messageLevel, Exec parent ) | |||
| { | |||
| this.din = new BufferedReader( new InputStreamReader( is ) ); | |||
| this.messageLevel = messageLevel; | |||
| this.parent = parent; | |||
| } | |||
| public void pumpStream() | |||
| throws IOException | |||
| { | |||
| byte[] buf = new byte[BUFFER_SIZE]; | |||
| if( !endOfStream ) | |||
| { | |||
| String line = din.readLine(); | |||
| if( line != null ) | |||
| { | |||
| outputLog( line, messageLevel ); | |||
| } | |||
| else | |||
| { | |||
| endOfStream = true; | |||
| } | |||
| } | |||
| } | |||
| public void run() | |||
| { | |||
| try | |||
| { | |||
| try | |||
| { | |||
| while( !endOfStream ) | |||
| { | |||
| pumpStream(); | |||
| sleep( SLEEP_TIME ); | |||
| } | |||
| } | |||
| catch( InterruptedException ie ) | |||
| {} | |||
| din.close(); | |||
| } | |||
| catch( IOException ioe ) | |||
| {} | |||
| } | |||
| } | |||
| } | |||
| @@ -1,95 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.IOException; | |||
| import java.io.OutputStream; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| * Serves as an output stream to Javac. This let's us print messages out to the | |||
| * log and detect whether or not Javac had an error while compiling. | |||
| * | |||
| * @author James Duncan Davidson (duncan@x180.com) | |||
| * @deprecated use returnvalue of compile to detect compilation failure. | |||
| */ | |||
| class JavacOutputStream extends OutputStream | |||
| { | |||
| private boolean errorFlag = false; | |||
| private StringBuffer line; | |||
| private Task task; | |||
| /** | |||
| * Constructs a new JavacOutputStream with the given task as the output | |||
| * source for messages. | |||
| * | |||
| * @param task Description of Parameter | |||
| */ | |||
| JavacOutputStream( Task task ) | |||
| { | |||
| this.task = task; | |||
| line = new StringBuffer(); | |||
| } | |||
| /** | |||
| * Write a character to the output stream. This method looks to make sure | |||
| * that there isn't an error being reported and will flush each line of | |||
| * input out to the project's log stream. | |||
| * | |||
| * @param c Description of Parameter | |||
| * @exception IOException Description of Exception | |||
| */ | |||
| public void write( int c ) | |||
| throws IOException | |||
| { | |||
| char cc = ( char )c; | |||
| if( cc == '\r' || cc == '\n' ) | |||
| { | |||
| // line feed | |||
| if( line.length() > 0 ) | |||
| { | |||
| processLine(); | |||
| } | |||
| } | |||
| else | |||
| { | |||
| line.append( cc ); | |||
| } | |||
| } | |||
| /** | |||
| * Returns the error status of the compile. If no errors occured, this | |||
| * method will return false, else this method will return true. | |||
| * | |||
| * @return The ErrorFlag value | |||
| */ | |||
| boolean getErrorFlag() | |||
| { | |||
| return errorFlag; | |||
| } | |||
| /** | |||
| * Processes a line of input and determines if an error occured. | |||
| */ | |||
| private void processLine() | |||
| { | |||
| String s = line.toString(); | |||
| if( s.indexOf( "error" ) > -1 ) | |||
| { | |||
| errorFlag = true; | |||
| } | |||
| task.log( s ); | |||
| line = new StringBuffer(); | |||
| } | |||
| } | |||
| @@ -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 file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.File; | |||
| import java.io.FileWriter; | |||
| import java.io.IOException; | |||
| import java.io.PrintWriter; | |||
| import java.util.Random; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| /** | |||
| * Encapsulates a Jikes compiler, by directly executing an external process. | |||
| * | |||
| * @author skanthak@muehlheim.de | |||
| * @deprecated merged into the class Javac. | |||
| */ | |||
| public class Jikes | |||
| { | |||
| protected String command; | |||
| protected JikesOutputParser jop; | |||
| protected Project project; | |||
| /** | |||
| * Constructs a new Jikes obect. | |||
| * | |||
| * @param jop - Parser to send jike's output to | |||
| * @param command - name of jikes executeable | |||
| * @param project Description of Parameter | |||
| */ | |||
| protected Jikes( JikesOutputParser jop, String command, Project project ) | |||
| { | |||
| super(); | |||
| this.jop = jop; | |||
| this.command = command; | |||
| this.project = project; | |||
| } | |||
| /** | |||
| * Do the compile with the specified arguments. | |||
| * | |||
| * @param args - arguments to pass to process on command line | |||
| */ | |||
| protected void compile( String[] args ) | |||
| { | |||
| String[] commandArray = null; | |||
| File tmpFile = null; | |||
| try | |||
| { | |||
| String myos = System.getProperty( "os.name" ); | |||
| // Windows has a 32k limit on total arg size, so | |||
| // create a temporary file to store all the arguments | |||
| // There have been reports that 300 files could be compiled | |||
| // so 250 is a conservative approach | |||
| if( myos.toLowerCase().indexOf( "windows" ) >= 0 | |||
| && args.length > 250 ) | |||
| { | |||
| PrintWriter out = null; | |||
| try | |||
| { | |||
| tmpFile = new File( "jikes" + ( new Random( System.currentTimeMillis() ) ).nextLong() ); | |||
| out = new PrintWriter( new FileWriter( tmpFile ) ); | |||
| for( int i = 0; i < args.length; i++ ) | |||
| { | |||
| out.println( args[i] ); | |||
| } | |||
| out.flush(); | |||
| commandArray = new String[]{command, | |||
| "@" + tmpFile.getAbsolutePath()}; | |||
| } | |||
| catch( IOException e ) | |||
| { | |||
| throw new BuildException( "Error creating temporary file", e ); | |||
| } | |||
| finally | |||
| { | |||
| if( out != null ) | |||
| { | |||
| try | |||
| { | |||
| out.close(); | |||
| } | |||
| catch( Throwable t ) | |||
| {} | |||
| } | |||
| } | |||
| } | |||
| else | |||
| { | |||
| commandArray = new String[args.length + 1]; | |||
| commandArray[0] = command; | |||
| System.arraycopy( args, 0, commandArray, 1, args.length ); | |||
| } | |||
| // We assume, that everything jikes writes goes to | |||
| // standard output, not to standard error. The option | |||
| // -Xstdout that is given to Jikes in Javac.doJikesCompile() | |||
| // should guarantee this. At least I hope so. :) | |||
| try | |||
| { | |||
| Execute exe = new Execute( jop ); | |||
| exe.setAntRun( project ); | |||
| exe.setWorkingDirectory( project.getBaseDir() ); | |||
| exe.setCommandline( commandArray ); | |||
| exe.execute(); | |||
| } | |||
| catch( IOException e ) | |||
| { | |||
| throw new BuildException( "Error running Jikes compiler", e ); | |||
| } | |||
| } | |||
| finally | |||
| { | |||
| if( tmpFile != null ) | |||
| { | |||
| tmpFile.delete(); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,174 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.BufferedReader; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.io.InputStreamReader; | |||
| import java.io.OutputStream; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| * Parses output from jikes and passes errors and warnings into the right | |||
| * logging channels of Project. TODO: Parsing could be much better | |||
| * | |||
| * @author skanthak@muehlheim.de | |||
| * @deprecated use Jikes' exit value to detect compilation failure. | |||
| */ | |||
| public class JikesOutputParser implements ExecuteStreamHandler | |||
| { | |||
| protected boolean errorFlag = false; | |||
| protected boolean error = false; | |||
| protected BufferedReader br; | |||
| protected boolean emacsMode;// no errors so far | |||
| protected int errors, warnings; | |||
| protected Task task; | |||
| /** | |||
| * Construct a new Parser object | |||
| * | |||
| * @param task - task in whichs context we are called | |||
| * @param emacsMode Description of Parameter | |||
| */ | |||
| protected JikesOutputParser( Task task, boolean emacsMode ) | |||
| { | |||
| super(); | |||
| this.task = task; | |||
| this.emacsMode = emacsMode; | |||
| } | |||
| /** | |||
| * Ignore. | |||
| * | |||
| * @param is The new ProcessErrorStream value | |||
| */ | |||
| public void setProcessErrorStream( InputStream is ) { } | |||
| /** | |||
| * Ignore. | |||
| * | |||
| * @param os The new ProcessInputStream value | |||
| */ | |||
| public void setProcessInputStream( OutputStream os ) { } | |||
| /** | |||
| * Set the inputstream | |||
| * | |||
| * @param is The new ProcessOutputStream value | |||
| * @exception IOException Description of Exception | |||
| */ | |||
| public void setProcessOutputStream( InputStream is ) | |||
| throws IOException | |||
| { | |||
| br = new BufferedReader( new InputStreamReader( is ) ); | |||
| } | |||
| /** | |||
| * Invokes parseOutput. | |||
| * | |||
| * @exception IOException Description of Exception | |||
| */ | |||
| public void start() | |||
| throws IOException | |||
| { | |||
| parseOutput( br ); | |||
| } | |||
| /** | |||
| * Ignore. | |||
| */ | |||
| public void stop() { } | |||
| /** | |||
| * Indicate if there were errors during the compile | |||
| * | |||
| * @return if errors ocured | |||
| */ | |||
| protected boolean getErrorFlag() | |||
| { | |||
| return errorFlag; | |||
| } | |||
| /** | |||
| * Parse the output of a jikes compiler | |||
| * | |||
| * @param reader - Reader used to read jikes's output | |||
| * @exception IOException Description of Exception | |||
| */ | |||
| protected void parseOutput( BufferedReader reader ) | |||
| throws IOException | |||
| { | |||
| if( emacsMode ) | |||
| parseEmacsOutput( reader ); | |||
| else | |||
| parseStandardOutput( reader ); | |||
| } | |||
| private void setError( boolean err ) | |||
| { | |||
| error = err; | |||
| if( error ) | |||
| errorFlag = true; | |||
| } | |||
| private void log( String line ) | |||
| { | |||
| if( !emacsMode ) | |||
| { | |||
| task.log( "", ( error ? Project.MSG_ERR : Project.MSG_WARN ) ); | |||
| } | |||
| task.log( line, ( error ? Project.MSG_ERR : Project.MSG_WARN ) ); | |||
| } | |||
| private void parseEmacsOutput( BufferedReader reader ) | |||
| throws IOException | |||
| { | |||
| // This may change, if we add advanced parsing capabilities. | |||
| parseStandardOutput( reader ); | |||
| } | |||
| private void parseStandardOutput( BufferedReader reader ) | |||
| throws IOException | |||
| { | |||
| String line; | |||
| String lower; | |||
| // We assume, that every output, jike does, stands for an error/warning | |||
| // XXX | |||
| // Is this correct? | |||
| // TODO: | |||
| // A warning line, that shows code, which contains a variable | |||
| // error will cause some trouble. The parser should definitely | |||
| // be much better. | |||
| while( ( line = reader.readLine() ) != null ) | |||
| { | |||
| lower = line.toLowerCase(); | |||
| if( line.trim().equals( "" ) ) | |||
| continue; | |||
| if( lower.indexOf( "error" ) != -1 ) | |||
| setError( true ); | |||
| else if( lower.indexOf( "warning" ) != -1 ) | |||
| setError( false ); | |||
| else | |||
| { | |||
| // If we don't know the type of the line | |||
| // and we are in emacs mode, it will be | |||
| // an error, because in this mode, jikes won't | |||
| // always print "error", but sometimes other | |||
| // keywords like "Syntax". We should look for | |||
| // all those keywords. | |||
| if( emacsMode ) | |||
| setError( true ); | |||
| } | |||
| log( line ); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,202 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| 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.util.Hashtable; | |||
| import java.util.StringTokenizer; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| * Keyword substitution. Input file is written to output file. Do not make input | |||
| * file same as output file. Keywords in input files look like this: | |||
| * | |||
| * @author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a> | |||
| * @foo@. See the docs for the setKeys method to understand how to do the | |||
| * substitutions. | |||
| * @deprecated KeySubst is deprecated. Use Filter + CopyDir instead. | |||
| */ | |||
| public class KeySubst extends Task | |||
| { | |||
| private File source = null; | |||
| private File dest = null; | |||
| private String sep = "*"; | |||
| private Hashtable replacements = new Hashtable(); | |||
| public static void main( String[] args ) | |||
| { | |||
| try | |||
| { | |||
| Hashtable hash = new Hashtable(); | |||
| hash.put( "VERSION", "1.0.3" ); | |||
| hash.put( "b", "ffff" ); | |||
| System.out.println( KeySubst.replace( "$f ${VERSION} f ${b} jj $", hash ) ); | |||
| } | |||
| catch( Exception e ) | |||
| { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| /** | |||
| * Does replacement on text using the hashtable of keys. | |||
| * | |||
| * @param origString Description of Parameter | |||
| * @param keys Description of Parameter | |||
| * @return Description of the Returned Value | |||
| * @exception BuildException Description of Exception | |||
| * @returns the string with the replacements in it. | |||
| */ | |||
| public static String replace( String origString, Hashtable keys ) | |||
| throws BuildException | |||
| { | |||
| StringBuffer finalString = new StringBuffer(); | |||
| int index = 0; | |||
| int i = 0; | |||
| String key = null; | |||
| while( ( index = origString.indexOf( "${", i ) ) > -1 ) | |||
| { | |||
| key = origString.substring( index + 2, origString.indexOf( "}", index + 3 ) ); | |||
| finalString.append( origString.substring( i, index ) ); | |||
| if( keys.containsKey( key ) ) | |||
| { | |||
| finalString.append( keys.get( key ) ); | |||
| } | |||
| else | |||
| { | |||
| finalString.append( "${" ); | |||
| finalString.append( key ); | |||
| finalString.append( "}" ); | |||
| } | |||
| i = index + 3 + key.length(); | |||
| } | |||
| finalString.append( origString.substring( i ) ); | |||
| return finalString.toString(); | |||
| } | |||
| /** | |||
| * Set the destination file. | |||
| * | |||
| * @param dest The new Dest value | |||
| */ | |||
| public void setDest( File dest ) | |||
| { | |||
| this.dest = dest; | |||
| } | |||
| /** | |||
| * Format string is like this: <p> | |||
| * | |||
| * name=value*name2=value <p> | |||
| * | |||
| * Names are case sensitive. <p> | |||
| * | |||
| * Use the setSep() method to change the * to something else if you need to | |||
| * use * as a name or value. | |||
| * | |||
| * @param keys The new Keys value | |||
| */ | |||
| public void setKeys( String keys ) | |||
| { | |||
| if( keys != null && keys.length() > 0 ) | |||
| { | |||
| StringTokenizer tok = | |||
| new StringTokenizer( keys, this.sep, false ); | |||
| while( tok.hasMoreTokens() ) | |||
| { | |||
| String token = tok.nextToken().trim(); | |||
| StringTokenizer itok = | |||
| new StringTokenizer( token, "=", false ); | |||
| String name = itok.nextToken(); | |||
| String value = itok.nextToken(); | |||
| // log ( "Name: " + name ); | |||
| // log ( "Value: " + value ); | |||
| replacements.put( name, value ); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * Sets the seperator between name=value arguments in setKeys(). By default | |||
| * it is "*". | |||
| * | |||
| * @param sep The new Sep value | |||
| */ | |||
| public void setSep( String sep ) | |||
| { | |||
| this.sep = sep; | |||
| } | |||
| /** | |||
| * Set the source file. | |||
| * | |||
| * @param s The new Src value | |||
| */ | |||
| public void setSrc( File s ) | |||
| { | |||
| this.source = s; | |||
| } | |||
| /** | |||
| * Do the execution. | |||
| * | |||
| * @exception BuildException Description of Exception | |||
| */ | |||
| public void execute() | |||
| throws BuildException | |||
| { | |||
| log( "!! KeySubst is deprecated. Use Filter + CopyDir instead. !!" ); | |||
| log( "Performing Substitions" ); | |||
| if( source == null || dest == null ) | |||
| { | |||
| log( "Source and destinations must not be null" ); | |||
| return; | |||
| } | |||
| BufferedReader br = null; | |||
| BufferedWriter bw = null; | |||
| try | |||
| { | |||
| br = new BufferedReader( new FileReader( source ) ); | |||
| dest.delete(); | |||
| bw = new BufferedWriter( new FileWriter( dest ) ); | |||
| String line = null; | |||
| String newline = null; | |||
| int length; | |||
| line = br.readLine(); | |||
| while( line != null ) | |||
| { | |||
| if( line.length() == 0 ) | |||
| { | |||
| bw.newLine(); | |||
| } | |||
| else | |||
| { | |||
| newline = KeySubst.replace( line, replacements ); | |||
| bw.write( newline ); | |||
| bw.newLine(); | |||
| } | |||
| line = br.readLine(); | |||
| } | |||
| bw.flush(); | |||
| bw.close(); | |||
| br.close(); | |||
| } | |||
| catch( IOException ioe ) | |||
| { | |||
| ioe.printStackTrace(); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,92 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.File; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| * Renames a file. | |||
| * | |||
| * @author haas@softwired.ch | |||
| * @deprecated The rename task is deprecated. Use move instead. | |||
| */ | |||
| public class Rename extends Task | |||
| { | |||
| private boolean replace = true; | |||
| private File dest; | |||
| private File src; | |||
| /** | |||
| * Sets the new name of the file. | |||
| * | |||
| * @param dest the new name of the file. | |||
| */ | |||
| public void setDest( File dest ) | |||
| { | |||
| this.dest = dest; | |||
| } | |||
| /** | |||
| * Sets wheter an existing file should be replaced. | |||
| * | |||
| * @param replace <code>on</code>, if an existing file should be replaced. | |||
| */ | |||
| public void setReplace( String replace ) | |||
| { | |||
| this.replace = project.toBoolean( replace ); | |||
| } | |||
| /** | |||
| * Sets the file to be renamed. | |||
| * | |||
| * @param src the file to rename | |||
| */ | |||
| public void setSrc( File src ) | |||
| { | |||
| this.src = src; | |||
| } | |||
| /** | |||
| * Renames the file <code>src</code> to <code>dest</code> | |||
| * | |||
| * @exception BuildException Description of Exception | |||
| */ | |||
| public void execute() | |||
| throws BuildException | |||
| { | |||
| log( "DEPRECATED - The rename task is deprecated. Use move instead." ); | |||
| if( dest == null ) | |||
| { | |||
| throw new BuildException( "dest attribute is required", location ); | |||
| } | |||
| if( src == null ) | |||
| { | |||
| throw new BuildException( "src attribute is required", location ); | |||
| } | |||
| if( replace && dest.exists() ) | |||
| { | |||
| if( !dest.delete() ) | |||
| { | |||
| throw new BuildException( "Unable to remove existing file " + | |||
| dest ); | |||
| } | |||
| } | |||
| if( !src.renameTo( dest ) ) | |||
| { | |||
| throw new BuildException( "Unable to rename " + src + " to " + | |||
| dest ); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,84 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.IOException; | |||
| import java.io.OutputStream; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| * Redirects text written to a stream thru the standard ant logging mechanism. | |||
| * This class is useful for integrating with tools that write to System.out and | |||
| * System.err. For example, the following will cause all text written to | |||
| * System.out to be logged with "info" priority: <pre>System.setOut(new PrintStream(new TaskOutputStream(project, Project.MSG_INFO)));</pre> | |||
| * | |||
| * @author James Duncan Davidson (duncan@x180.com) | |||
| * @deprecated use LogOutputStream instead. | |||
| */ | |||
| public class TaskOutputStream extends OutputStream | |||
| { | |||
| private StringBuffer line; | |||
| private int msgOutputLevel; | |||
| private Task task; | |||
| /** | |||
| * Constructs a new JavacOutputStream with the given project as the output | |||
| * source for messages. | |||
| * | |||
| * @param task Description of Parameter | |||
| * @param msgOutputLevel Description of Parameter | |||
| */ | |||
| TaskOutputStream( Task task, int msgOutputLevel ) | |||
| { | |||
| this.task = task; | |||
| this.msgOutputLevel = msgOutputLevel; | |||
| line = new StringBuffer(); | |||
| } | |||
| /** | |||
| * Write a character to the output stream. This method looks to make sure | |||
| * that there isn't an error being reported and will flush each line of | |||
| * input out to the project's log stream. | |||
| * | |||
| * @param c Description of Parameter | |||
| * @exception IOException Description of Exception | |||
| */ | |||
| public void write( int c ) | |||
| throws IOException | |||
| { | |||
| char cc = ( char )c; | |||
| if( cc == '\r' || cc == '\n' ) | |||
| { | |||
| // line feed | |||
| if( line.length() > 0 ) | |||
| { | |||
| processLine(); | |||
| } | |||
| } | |||
| else | |||
| { | |||
| line.append( cc ); | |||
| } | |||
| } | |||
| /** | |||
| * Processes a line of input and determines if an error occured. | |||
| */ | |||
| private void processLine() | |||
| { | |||
| String s = line.toString(); | |||
| task.log( s, msgOutputLevel ); | |||
| line = new StringBuffer(); | |||
| } | |||
| } | |||
| @@ -1,131 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.optional; | |||
| import java.io.File; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.taskdefs.MatchingTask; | |||
| import org.apache.tools.ant.taskdefs.Move; | |||
| import org.apache.tools.ant.types.Mapper; | |||
| /** | |||
| * @author dIon Gillard <a href="mailto:dion@multitask.com.au"> | |||
| * dion@multitask.com.au</a> | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| * @version 1.2 | |||
| */ | |||
| public class RenameExtensions extends MatchingTask | |||
| { | |||
| private String fromExtension = ""; | |||
| private String toExtension = ""; | |||
| private boolean replace = false; | |||
| private Mapper.MapperType globType; | |||
| private File srcDir; | |||
| /** | |||
| * Creates new RenameExtensions | |||
| */ | |||
| public RenameExtensions() | |||
| { | |||
| super(); | |||
| globType = new Mapper.MapperType(); | |||
| globType.setValue( "glob" ); | |||
| } | |||
| /** | |||
| * store fromExtension * | |||
| * | |||
| * @param from The new FromExtension value | |||
| */ | |||
| public void setFromExtension( String from ) | |||
| { | |||
| fromExtension = from; | |||
| } | |||
| /** | |||
| * store replace attribute - this determines whether the target file should | |||
| * be overwritten if present | |||
| * | |||
| * @param replace The new Replace value | |||
| */ | |||
| public void setReplace( boolean replace ) | |||
| { | |||
| this.replace = replace; | |||
| } | |||
| /** | |||
| * Set the source dir to find the files to be renamed. | |||
| * | |||
| * @param srcDir The new SrcDir value | |||
| */ | |||
| public void setSrcDir( File srcDir ) | |||
| { | |||
| this.srcDir = srcDir; | |||
| } | |||
| /** | |||
| * store toExtension * | |||
| * | |||
| * @param to The new ToExtension value | |||
| */ | |||
| public void setToExtension( String to ) | |||
| { | |||
| toExtension = to; | |||
| } | |||
| /** | |||
| * Executes the task, i.e. does the actual compiler call | |||
| * | |||
| * @exception BuildException Description of Exception | |||
| */ | |||
| public void execute() | |||
| throws BuildException | |||
| { | |||
| // first off, make sure that we've got a from and to extension | |||
| if( fromExtension == null || toExtension == null || srcDir == null ) | |||
| { | |||
| throw new BuildException( "srcDir, fromExtension and toExtension " + | |||
| "attributes must be set!" ); | |||
| } | |||
| log( "DEPRECATED - The renameext task is deprecated. Use move instead.", | |||
| Project.MSG_WARN ); | |||
| log( "Replace this with:", Project.MSG_INFO ); | |||
| log( "<move todir=\"" + srcDir + "\" overwrite=\"" + replace + "\">", | |||
| Project.MSG_INFO ); | |||
| log( " <fileset dir=\"" + srcDir + "\" />", Project.MSG_INFO ); | |||
| log( " <mapper type=\"glob\"", Project.MSG_INFO ); | |||
| log( " from=\"*" + fromExtension + "\"", Project.MSG_INFO ); | |||
| log( " to=\"*" + toExtension + "\" />", Project.MSG_INFO ); | |||
| log( "</move>", Project.MSG_INFO ); | |||
| log( "using the same patterns on <fileset> as you\'ve used here", | |||
| Project.MSG_INFO ); | |||
| Move move = ( Move )project.createTask( "move" ); | |||
| move.setOwningTarget( target ); | |||
| move.setTaskName( getTaskName() ); | |||
| move.setLocation( getLocation() ); | |||
| move.setTodir( srcDir ); | |||
| move.setOverwrite( replace ); | |||
| fileset.setDir( srcDir ); | |||
| move.addFileset( fileset ); | |||
| Mapper me = move.createMapper(); | |||
| me.setType( globType ); | |||
| me.setFrom( "*" + fromExtension ); | |||
| me.setTo( "*" + toExtension ); | |||
| move.execute(); | |||
| } | |||
| } | |||
| @@ -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 file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.util.Enumeration; | |||
| import java.util.Vector; | |||
| import org.apache.tools.ant.types.PatternSet; | |||
| /** | |||
| * This task will compile and load a new taskdef all in one step. At times, this | |||
| * is useful for eliminating ordering dependencies which otherwise would require | |||
| * multiple executions of Ant. | |||
| * | |||
| * @author Sam Ruby <a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a> | |||
| * @deprecated use <taskdef> elements nested into <target>s instead | |||
| */ | |||
| public class CompileTask extends Javac | |||
| { | |||
| protected Vector taskList = new Vector(); | |||
| /** | |||
| * add a new task entry on the task list | |||
| * | |||
| * @return Description of the Returned Value | |||
| */ | |||
| public Taskdef createTaskdef() | |||
| { | |||
| Taskdef task = new Taskdef(); | |||
| taskList.addElement( task ); | |||
| return task; | |||
| } | |||
| /** | |||
| * have execute do nothing | |||
| */ | |||
| public void execute() { } | |||
| /** | |||
| * do all the real work in init | |||
| */ | |||
| public void init() | |||
| { | |||
| log( "!! CompileTask is deprecated. !!" ); | |||
| log( "Use <taskdef> elements nested into <target>s instead" ); | |||
| // create all the include entries from the task defs | |||
| for( Enumeration e = taskList.elements(); e.hasMoreElements(); ) | |||
| { | |||
| Taskdef task = ( Taskdef )e.nextElement(); | |||
| String source = task.getClassname().replace( '.', '/' ) + ".java"; | |||
| PatternSet.NameEntry include = super.createInclude(); | |||
| include.setName( "**/" + source ); | |||
| } | |||
| // execute Javac | |||
| super.init(); | |||
| super.execute(); | |||
| // now define all the new tasks | |||
| for( Enumeration e = taskList.elements(); e.hasMoreElements(); ) | |||
| { | |||
| Taskdef task = ( Taskdef )e.nextElement(); | |||
| task.init(); | |||
| } | |||
| } | |||
| } | |||
| @@ -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 file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.util.Enumeration; | |||
| import java.util.Hashtable; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.DirectoryScanner; | |||
| /** | |||
| * Copies a directory. | |||
| * | |||
| * @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a> | |||
| * @deprecated The copydir task is deprecated. Use copy instead. | |||
| */ | |||
| public class Copydir extends MatchingTask | |||
| { | |||
| private boolean filtering = false; | |||
| private boolean flatten = false; | |||
| private boolean forceOverwrite = false; | |||
| private Hashtable filecopyList = new Hashtable(); | |||
| private File destDir; | |||
| private File srcDir; | |||
| public void setDest( File dest ) | |||
| { | |||
| destDir = dest; | |||
| } | |||
| public void setFiltering( boolean filter ) | |||
| { | |||
| filtering = filter; | |||
| } | |||
| public void setFlatten( boolean flatten ) | |||
| { | |||
| this.flatten = flatten; | |||
| } | |||
| public void setForceoverwrite( boolean force ) | |||
| { | |||
| forceOverwrite = force; | |||
| } | |||
| public void setSrc( File src ) | |||
| { | |||
| srcDir = src; | |||
| } | |||
| public void execute() | |||
| throws BuildException | |||
| { | |||
| log( "DEPRECATED - The copydir task is deprecated. Use copy instead." ); | |||
| if( srcDir == null ) | |||
| { | |||
| throw new BuildException( "src attribute must be set!", | |||
| location ); | |||
| } | |||
| if( !srcDir.exists() ) | |||
| { | |||
| throw new BuildException( "srcdir " + srcDir.toString() | |||
| + " does not exist!", location ); | |||
| } | |||
| if( destDir == null ) | |||
| { | |||
| throw new BuildException( "The dest attribute must be set.", location ); | |||
| } | |||
| if( srcDir.equals( destDir ) ) | |||
| { | |||
| log( "Warning: src == dest" ); | |||
| } | |||
| DirectoryScanner ds = super.getDirectoryScanner( srcDir ); | |||
| String[] files = ds.getIncludedFiles(); | |||
| scanDir( srcDir, destDir, files ); | |||
| if( filecopyList.size() > 0 ) | |||
| { | |||
| log( "Copying " + filecopyList.size() + " file" | |||
| + ( filecopyList.size() == 1 ? "" : "s" ) | |||
| + " to " + destDir.getAbsolutePath() ); | |||
| Enumeration enum = filecopyList.keys(); | |||
| while( enum.hasMoreElements() ) | |||
| { | |||
| String fromFile = ( String )enum.nextElement(); | |||
| String toFile = ( String )filecopyList.get( fromFile ); | |||
| try | |||
| { | |||
| project.copyFile( fromFile, toFile, filtering, | |||
| forceOverwrite ); | |||
| } | |||
| catch( IOException ioe ) | |||
| { | |||
| String msg = "Failed to copy " + fromFile + " to " + toFile | |||
| + " due to " + ioe.getMessage(); | |||
| throw new BuildException( msg, ioe, location ); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| private void scanDir( File from, File to, String[] files ) | |||
| { | |||
| for( int i = 0; i < files.length; i++ ) | |||
| { | |||
| String filename = files[i]; | |||
| File srcFile = new File( from, filename ); | |||
| File destFile; | |||
| if( flatten ) | |||
| { | |||
| destFile = new File( to, new File( filename ).getName() ); | |||
| } | |||
| else | |||
| { | |||
| destFile = new File( to, filename ); | |||
| } | |||
| if( forceOverwrite || | |||
| ( srcFile.lastModified() > destFile.lastModified() ) ) | |||
| { | |||
| filecopyList.put( srcFile.getAbsolutePath(), | |||
| destFile.getAbsolutePath() ); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -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 file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| * Copies a file. | |||
| * | |||
| * @author duncan@x180.com | |||
| * @deprecated The copyfile task is deprecated. Use copy instead. | |||
| */ | |||
| public class Copyfile extends Task | |||
| { | |||
| private boolean filtering = false; | |||
| private boolean forceOverwrite = false; | |||
| private File destFile; | |||
| private File srcFile; | |||
| public void setDest( File dest ) | |||
| { | |||
| destFile = dest; | |||
| } | |||
| public void setFiltering( String filter ) | |||
| { | |||
| filtering = Project.toBoolean( filter ); | |||
| } | |||
| public void setForceoverwrite( boolean force ) | |||
| { | |||
| forceOverwrite = force; | |||
| } | |||
| public void setSrc( File src ) | |||
| { | |||
| srcFile = src; | |||
| } | |||
| public void execute() | |||
| throws BuildException | |||
| { | |||
| log( "DEPRECATED - The copyfile task is deprecated. Use copy instead." ); | |||
| if( srcFile == null ) | |||
| { | |||
| throw new BuildException( "The src attribute must be present.", location ); | |||
| } | |||
| if( !srcFile.exists() ) | |||
| { | |||
| throw new BuildException( "src " + srcFile.toString() | |||
| + " does not exist.", location ); | |||
| } | |||
| if( destFile == null ) | |||
| { | |||
| throw new BuildException( "The dest attribute must be present.", location ); | |||
| } | |||
| if( srcFile.equals( destFile ) ) | |||
| { | |||
| log( "Warning: src == dest" ); | |||
| } | |||
| if( forceOverwrite || srcFile.lastModified() > destFile.lastModified() ) | |||
| { | |||
| try | |||
| { | |||
| project.copyFile( srcFile, destFile, filtering, forceOverwrite ); | |||
| } | |||
| catch( IOException ioe ) | |||
| { | |||
| String msg = "Error copying file: " + srcFile.getAbsolutePath() | |||
| + " due to " + ioe.getMessage(); | |||
| throw new BuildException( msg ); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -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 file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| * @author duncan@x180.com | |||
| * @deprecated The deltree task is deprecated. Use delete instead. | |||
| */ | |||
| public class Deltree extends Task | |||
| { | |||
| private File dir; | |||
| public void setDir( File dir ) | |||
| { | |||
| this.dir = dir; | |||
| } | |||
| public void execute() | |||
| throws BuildException | |||
| { | |||
| log( "DEPRECATED - The deltree task is deprecated. Use delete instead." ); | |||
| if( dir == null ) | |||
| { | |||
| throw new BuildException( "dir attribute must be set!", location ); | |||
| } | |||
| if( dir.exists() ) | |||
| { | |||
| if( !dir.isDirectory() ) | |||
| { | |||
| if( !dir.delete() ) | |||
| { | |||
| throw new BuildException( "Unable to delete directory " | |||
| + dir.getAbsolutePath(), | |||
| location ); | |||
| } | |||
| return; | |||
| // String msg = "Given dir: " + dir.getAbsolutePath() + | |||
| // " is not a dir"; | |||
| // throw new BuildException(msg); | |||
| } | |||
| log( "Deleting: " + dir.getAbsolutePath() ); | |||
| try | |||
| { | |||
| removeDir( dir ); | |||
| } | |||
| catch( IOException ioe ) | |||
| { | |||
| String msg = "Unable to delete " + dir.getAbsolutePath(); | |||
| throw new BuildException( msg, location ); | |||
| } | |||
| } | |||
| } | |||
| private void removeDir( File dir ) | |||
| throws IOException | |||
| { | |||
| // check to make sure that the given dir isn't a symlink | |||
| // the comparison of absolute path and canonical path | |||
| // catches this | |||
| // if (dir.getCanonicalPath().equals(dir.getAbsolutePath())) { | |||
| // (costin) It will not work if /home/costin is symlink to /da0/home/costin ( taz | |||
| // for example ) | |||
| String[] list = dir.list(); | |||
| for( int i = 0; i < list.length; i++ ) | |||
| { | |||
| String s = list[i]; | |||
| File f = new File( dir, s ); | |||
| if( f.isDirectory() ) | |||
| { | |||
| removeDir( f ); | |||
| } | |||
| else | |||
| { | |||
| if( !f.delete() ) | |||
| { | |||
| throw new BuildException( "Unable to delete file " + f.getAbsolutePath() ); | |||
| } | |||
| } | |||
| } | |||
| if( !dir.delete() ) | |||
| { | |||
| throw new BuildException( "Unable to delete directory " + dir.getAbsolutePath() ); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,252 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.BufferedReader; | |||
| import java.io.File; | |||
| import java.io.FileWriter; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.io.InputStreamReader; | |||
| import java.io.PrintWriter; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| * Executes a given command if the os platform is appropriate. | |||
| * | |||
| * @author duncan@x180.com | |||
| * @author rubys@us.ibm.com | |||
| * @deprecated Instead of using this class, please extend ExecTask or delegate | |||
| * to Execute. | |||
| */ | |||
| public class Exec extends Task | |||
| { | |||
| private final static int BUFFER_SIZE = 512; | |||
| protected PrintWriter fos = null; | |||
| private boolean failOnError = false; | |||
| private String command; | |||
| private File dir; | |||
| private String os; | |||
| private String out; | |||
| public void setCommand( String command ) | |||
| { | |||
| this.command = command; | |||
| } | |||
| public void setDir( String d ) | |||
| { | |||
| this.dir = project.resolveFile( d ); | |||
| } | |||
| public void setFailonerror( boolean fail ) | |||
| { | |||
| failOnError = fail; | |||
| } | |||
| public void setOs( String os ) | |||
| { | |||
| this.os = os; | |||
| } | |||
| public void setOutput( String out ) | |||
| { | |||
| this.out = out; | |||
| } | |||
| public void execute() | |||
| throws BuildException | |||
| { | |||
| run( command ); | |||
| } | |||
| protected void logFlush() | |||
| { | |||
| if( fos != null ) | |||
| fos.close(); | |||
| } | |||
| protected void outputLog( String line, int messageLevel ) | |||
| { | |||
| if( fos == null ) | |||
| { | |||
| log( line, messageLevel ); | |||
| } | |||
| else | |||
| { | |||
| fos.println( line ); | |||
| } | |||
| } | |||
| protected int run( String command ) | |||
| throws BuildException | |||
| { | |||
| int err = -1;// assume the worst | |||
| // test if os match | |||
| String myos = System.getProperty( "os.name" ); | |||
| log( "Myos = " + myos, Project.MSG_VERBOSE ); | |||
| if( ( os != null ) && ( os.indexOf( myos ) < 0 ) ) | |||
| { | |||
| // this command will be executed only on the specified OS | |||
| log( "Not found in " + os, Project.MSG_VERBOSE ); | |||
| return 0; | |||
| } | |||
| // default directory to the project's base directory | |||
| if( dir == null ) | |||
| dir = project.getBaseDir(); | |||
| if( myos.toLowerCase().indexOf( "windows" ) >= 0 ) | |||
| { | |||
| if( !dir.equals( project.resolveFile( "." ) ) ) | |||
| { | |||
| if( myos.toLowerCase().indexOf( "nt" ) >= 0 ) | |||
| { | |||
| command = "cmd /c cd " + dir + " && " + command; | |||
| } | |||
| else | |||
| { | |||
| String ant = project.getProperty( "ant.home" ); | |||
| if( ant == null ) | |||
| { | |||
| throw new BuildException( "Property 'ant.home' not found", location ); | |||
| } | |||
| String antRun = project.resolveFile( ant + "/bin/antRun.bat" ).toString(); | |||
| command = antRun + " " + dir + " " + command; | |||
| } | |||
| } | |||
| } | |||
| else | |||
| { | |||
| String ant = project.getProperty( "ant.home" ); | |||
| if( ant == null ) | |||
| throw new BuildException( "Property 'ant.home' not found", location ); | |||
| String antRun = project.resolveFile( ant + "/bin/antRun" ).toString(); | |||
| command = antRun + " " + dir + " " + command; | |||
| } | |||
| try | |||
| { | |||
| // show the command | |||
| log( command, Project.MSG_VERBOSE ); | |||
| // exec command on system runtime | |||
| Process proc = Runtime.getRuntime().exec( command ); | |||
| if( out != null ) | |||
| { | |||
| fos = new PrintWriter( new FileWriter( out ) ); | |||
| log( "Output redirected to " + out, Project.MSG_VERBOSE ); | |||
| } | |||
| // copy input and error to the output stream | |||
| StreamPumper inputPumper = | |||
| new StreamPumper( proc.getInputStream(), Project.MSG_INFO, this ); | |||
| StreamPumper errorPumper = | |||
| new StreamPumper( proc.getErrorStream(), Project.MSG_WARN, this ); | |||
| // starts pumping away the generated output/error | |||
| inputPumper.start(); | |||
| errorPumper.start(); | |||
| // Wait for everything to finish | |||
| proc.waitFor(); | |||
| inputPumper.join(); | |||
| errorPumper.join(); | |||
| proc.destroy(); | |||
| // close the output file if required | |||
| logFlush(); | |||
| // check its exit value | |||
| err = proc.exitValue(); | |||
| if( err != 0 ) | |||
| { | |||
| if( failOnError ) | |||
| { | |||
| throw new BuildException( "Exec returned: " + err, location ); | |||
| } | |||
| else | |||
| { | |||
| log( "Result: " + err, Project.MSG_ERR ); | |||
| } | |||
| } | |||
| } | |||
| catch( IOException ioe ) | |||
| { | |||
| throw new BuildException( "Error exec: " + command, ioe, location ); | |||
| } | |||
| catch( InterruptedException ex ) | |||
| {} | |||
| return err; | |||
| } | |||
| // Inner class for continually pumping the input stream during | |||
| // Process's runtime. | |||
| class StreamPumper extends Thread | |||
| { | |||
| private boolean endOfStream = false; | |||
| private int SLEEP_TIME = 5; | |||
| private BufferedReader din; | |||
| private int messageLevel; | |||
| private Exec parent; | |||
| public StreamPumper( InputStream is, int messageLevel, Exec parent ) | |||
| { | |||
| this.din = new BufferedReader( new InputStreamReader( is ) ); | |||
| this.messageLevel = messageLevel; | |||
| this.parent = parent; | |||
| } | |||
| public void pumpStream() | |||
| throws IOException | |||
| { | |||
| byte[] buf = new byte[BUFFER_SIZE]; | |||
| if( !endOfStream ) | |||
| { | |||
| String line = din.readLine(); | |||
| if( line != null ) | |||
| { | |||
| outputLog( line, messageLevel ); | |||
| } | |||
| else | |||
| { | |||
| endOfStream = true; | |||
| } | |||
| } | |||
| } | |||
| public void run() | |||
| { | |||
| try | |||
| { | |||
| try | |||
| { | |||
| while( !endOfStream ) | |||
| { | |||
| pumpStream(); | |||
| sleep( SLEEP_TIME ); | |||
| } | |||
| } | |||
| catch( InterruptedException ie ) | |||
| {} | |||
| din.close(); | |||
| } | |||
| catch( IOException ioe ) | |||
| {} | |||
| } | |||
| } | |||
| } | |||
| @@ -1,95 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.IOException; | |||
| import java.io.OutputStream; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| * Serves as an output stream to Javac. This let's us print messages out to the | |||
| * log and detect whether or not Javac had an error while compiling. | |||
| * | |||
| * @author James Duncan Davidson (duncan@x180.com) | |||
| * @deprecated use returnvalue of compile to detect compilation failure. | |||
| */ | |||
| class JavacOutputStream extends OutputStream | |||
| { | |||
| private boolean errorFlag = false; | |||
| private StringBuffer line; | |||
| private Task task; | |||
| /** | |||
| * Constructs a new JavacOutputStream with the given task as the output | |||
| * source for messages. | |||
| * | |||
| * @param task Description of Parameter | |||
| */ | |||
| JavacOutputStream( Task task ) | |||
| { | |||
| this.task = task; | |||
| line = new StringBuffer(); | |||
| } | |||
| /** | |||
| * Write a character to the output stream. This method looks to make sure | |||
| * that there isn't an error being reported and will flush each line of | |||
| * input out to the project's log stream. | |||
| * | |||
| * @param c Description of Parameter | |||
| * @exception IOException Description of Exception | |||
| */ | |||
| public void write( int c ) | |||
| throws IOException | |||
| { | |||
| char cc = ( char )c; | |||
| if( cc == '\r' || cc == '\n' ) | |||
| { | |||
| // line feed | |||
| if( line.length() > 0 ) | |||
| { | |||
| processLine(); | |||
| } | |||
| } | |||
| else | |||
| { | |||
| line.append( cc ); | |||
| } | |||
| } | |||
| /** | |||
| * Returns the error status of the compile. If no errors occured, this | |||
| * method will return false, else this method will return true. | |||
| * | |||
| * @return The ErrorFlag value | |||
| */ | |||
| boolean getErrorFlag() | |||
| { | |||
| return errorFlag; | |||
| } | |||
| /** | |||
| * Processes a line of input and determines if an error occured. | |||
| */ | |||
| private void processLine() | |||
| { | |||
| String s = line.toString(); | |||
| if( s.indexOf( "error" ) > -1 ) | |||
| { | |||
| errorFlag = true; | |||
| } | |||
| task.log( s ); | |||
| line = new StringBuffer(); | |||
| } | |||
| } | |||
| @@ -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 file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.File; | |||
| import java.io.FileWriter; | |||
| import java.io.IOException; | |||
| import java.io.PrintWriter; | |||
| import java.util.Random; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| /** | |||
| * Encapsulates a Jikes compiler, by directly executing an external process. | |||
| * | |||
| * @author skanthak@muehlheim.de | |||
| * @deprecated merged into the class Javac. | |||
| */ | |||
| public class Jikes | |||
| { | |||
| protected String command; | |||
| protected JikesOutputParser jop; | |||
| protected Project project; | |||
| /** | |||
| * Constructs a new Jikes obect. | |||
| * | |||
| * @param jop - Parser to send jike's output to | |||
| * @param command - name of jikes executeable | |||
| * @param project Description of Parameter | |||
| */ | |||
| protected Jikes( JikesOutputParser jop, String command, Project project ) | |||
| { | |||
| super(); | |||
| this.jop = jop; | |||
| this.command = command; | |||
| this.project = project; | |||
| } | |||
| /** | |||
| * Do the compile with the specified arguments. | |||
| * | |||
| * @param args - arguments to pass to process on command line | |||
| */ | |||
| protected void compile( String[] args ) | |||
| { | |||
| String[] commandArray = null; | |||
| File tmpFile = null; | |||
| try | |||
| { | |||
| String myos = System.getProperty( "os.name" ); | |||
| // Windows has a 32k limit on total arg size, so | |||
| // create a temporary file to store all the arguments | |||
| // There have been reports that 300 files could be compiled | |||
| // so 250 is a conservative approach | |||
| if( myos.toLowerCase().indexOf( "windows" ) >= 0 | |||
| && args.length > 250 ) | |||
| { | |||
| PrintWriter out = null; | |||
| try | |||
| { | |||
| tmpFile = new File( "jikes" + ( new Random( System.currentTimeMillis() ) ).nextLong() ); | |||
| out = new PrintWriter( new FileWriter( tmpFile ) ); | |||
| for( int i = 0; i < args.length; i++ ) | |||
| { | |||
| out.println( args[i] ); | |||
| } | |||
| out.flush(); | |||
| commandArray = new String[]{command, | |||
| "@" + tmpFile.getAbsolutePath()}; | |||
| } | |||
| catch( IOException e ) | |||
| { | |||
| throw new BuildException( "Error creating temporary file", e ); | |||
| } | |||
| finally | |||
| { | |||
| if( out != null ) | |||
| { | |||
| try | |||
| { | |||
| out.close(); | |||
| } | |||
| catch( Throwable t ) | |||
| {} | |||
| } | |||
| } | |||
| } | |||
| else | |||
| { | |||
| commandArray = new String[args.length + 1]; | |||
| commandArray[0] = command; | |||
| System.arraycopy( args, 0, commandArray, 1, args.length ); | |||
| } | |||
| // We assume, that everything jikes writes goes to | |||
| // standard output, not to standard error. The option | |||
| // -Xstdout that is given to Jikes in Javac.doJikesCompile() | |||
| // should guarantee this. At least I hope so. :) | |||
| try | |||
| { | |||
| Execute exe = new Execute( jop ); | |||
| exe.setAntRun( project ); | |||
| exe.setWorkingDirectory( project.getBaseDir() ); | |||
| exe.setCommandline( commandArray ); | |||
| exe.execute(); | |||
| } | |||
| catch( IOException e ) | |||
| { | |||
| throw new BuildException( "Error running Jikes compiler", e ); | |||
| } | |||
| } | |||
| finally | |||
| { | |||
| if( tmpFile != null ) | |||
| { | |||
| tmpFile.delete(); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,174 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.BufferedReader; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.io.InputStreamReader; | |||
| import java.io.OutputStream; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| * Parses output from jikes and passes errors and warnings into the right | |||
| * logging channels of Project. TODO: Parsing could be much better | |||
| * | |||
| * @author skanthak@muehlheim.de | |||
| * @deprecated use Jikes' exit value to detect compilation failure. | |||
| */ | |||
| public class JikesOutputParser implements ExecuteStreamHandler | |||
| { | |||
| protected boolean errorFlag = false; | |||
| protected boolean error = false; | |||
| protected BufferedReader br; | |||
| protected boolean emacsMode;// no errors so far | |||
| protected int errors, warnings; | |||
| protected Task task; | |||
| /** | |||
| * Construct a new Parser object | |||
| * | |||
| * @param task - task in whichs context we are called | |||
| * @param emacsMode Description of Parameter | |||
| */ | |||
| protected JikesOutputParser( Task task, boolean emacsMode ) | |||
| { | |||
| super(); | |||
| this.task = task; | |||
| this.emacsMode = emacsMode; | |||
| } | |||
| /** | |||
| * Ignore. | |||
| * | |||
| * @param is The new ProcessErrorStream value | |||
| */ | |||
| public void setProcessErrorStream( InputStream is ) { } | |||
| /** | |||
| * Ignore. | |||
| * | |||
| * @param os The new ProcessInputStream value | |||
| */ | |||
| public void setProcessInputStream( OutputStream os ) { } | |||
| /** | |||
| * Set the inputstream | |||
| * | |||
| * @param is The new ProcessOutputStream value | |||
| * @exception IOException Description of Exception | |||
| */ | |||
| public void setProcessOutputStream( InputStream is ) | |||
| throws IOException | |||
| { | |||
| br = new BufferedReader( new InputStreamReader( is ) ); | |||
| } | |||
| /** | |||
| * Invokes parseOutput. | |||
| * | |||
| * @exception IOException Description of Exception | |||
| */ | |||
| public void start() | |||
| throws IOException | |||
| { | |||
| parseOutput( br ); | |||
| } | |||
| /** | |||
| * Ignore. | |||
| */ | |||
| public void stop() { } | |||
| /** | |||
| * Indicate if there were errors during the compile | |||
| * | |||
| * @return if errors ocured | |||
| */ | |||
| protected boolean getErrorFlag() | |||
| { | |||
| return errorFlag; | |||
| } | |||
| /** | |||
| * Parse the output of a jikes compiler | |||
| * | |||
| * @param reader - Reader used to read jikes's output | |||
| * @exception IOException Description of Exception | |||
| */ | |||
| protected void parseOutput( BufferedReader reader ) | |||
| throws IOException | |||
| { | |||
| if( emacsMode ) | |||
| parseEmacsOutput( reader ); | |||
| else | |||
| parseStandardOutput( reader ); | |||
| } | |||
| private void setError( boolean err ) | |||
| { | |||
| error = err; | |||
| if( error ) | |||
| errorFlag = true; | |||
| } | |||
| private void log( String line ) | |||
| { | |||
| if( !emacsMode ) | |||
| { | |||
| task.log( "", ( error ? Project.MSG_ERR : Project.MSG_WARN ) ); | |||
| } | |||
| task.log( line, ( error ? Project.MSG_ERR : Project.MSG_WARN ) ); | |||
| } | |||
| private void parseEmacsOutput( BufferedReader reader ) | |||
| throws IOException | |||
| { | |||
| // This may change, if we add advanced parsing capabilities. | |||
| parseStandardOutput( reader ); | |||
| } | |||
| private void parseStandardOutput( BufferedReader reader ) | |||
| throws IOException | |||
| { | |||
| String line; | |||
| String lower; | |||
| // We assume, that every output, jike does, stands for an error/warning | |||
| // XXX | |||
| // Is this correct? | |||
| // TODO: | |||
| // A warning line, that shows code, which contains a variable | |||
| // error will cause some trouble. The parser should definitely | |||
| // be much better. | |||
| while( ( line = reader.readLine() ) != null ) | |||
| { | |||
| lower = line.toLowerCase(); | |||
| if( line.trim().equals( "" ) ) | |||
| continue; | |||
| if( lower.indexOf( "error" ) != -1 ) | |||
| setError( true ); | |||
| else if( lower.indexOf( "warning" ) != -1 ) | |||
| setError( false ); | |||
| else | |||
| { | |||
| // If we don't know the type of the line | |||
| // and we are in emacs mode, it will be | |||
| // an error, because in this mode, jikes won't | |||
| // always print "error", but sometimes other | |||
| // keywords like "Syntax". We should look for | |||
| // all those keywords. | |||
| if( emacsMode ) | |||
| setError( true ); | |||
| } | |||
| log( line ); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,202 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| 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.util.Hashtable; | |||
| import java.util.StringTokenizer; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| * Keyword substitution. Input file is written to output file. Do not make input | |||
| * file same as output file. Keywords in input files look like this: | |||
| * | |||
| * @author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a> | |||
| * @foo@. See the docs for the setKeys method to understand how to do the | |||
| * substitutions. | |||
| * @deprecated KeySubst is deprecated. Use Filter + CopyDir instead. | |||
| */ | |||
| public class KeySubst extends Task | |||
| { | |||
| private File source = null; | |||
| private File dest = null; | |||
| private String sep = "*"; | |||
| private Hashtable replacements = new Hashtable(); | |||
| public static void main( String[] args ) | |||
| { | |||
| try | |||
| { | |||
| Hashtable hash = new Hashtable(); | |||
| hash.put( "VERSION", "1.0.3" ); | |||
| hash.put( "b", "ffff" ); | |||
| System.out.println( KeySubst.replace( "$f ${VERSION} f ${b} jj $", hash ) ); | |||
| } | |||
| catch( Exception e ) | |||
| { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| /** | |||
| * Does replacement on text using the hashtable of keys. | |||
| * | |||
| * @param origString Description of Parameter | |||
| * @param keys Description of Parameter | |||
| * @return Description of the Returned Value | |||
| * @exception BuildException Description of Exception | |||
| * @returns the string with the replacements in it. | |||
| */ | |||
| public static String replace( String origString, Hashtable keys ) | |||
| throws BuildException | |||
| { | |||
| StringBuffer finalString = new StringBuffer(); | |||
| int index = 0; | |||
| int i = 0; | |||
| String key = null; | |||
| while( ( index = origString.indexOf( "${", i ) ) > -1 ) | |||
| { | |||
| key = origString.substring( index + 2, origString.indexOf( "}", index + 3 ) ); | |||
| finalString.append( origString.substring( i, index ) ); | |||
| if( keys.containsKey( key ) ) | |||
| { | |||
| finalString.append( keys.get( key ) ); | |||
| } | |||
| else | |||
| { | |||
| finalString.append( "${" ); | |||
| finalString.append( key ); | |||
| finalString.append( "}" ); | |||
| } | |||
| i = index + 3 + key.length(); | |||
| } | |||
| finalString.append( origString.substring( i ) ); | |||
| return finalString.toString(); | |||
| } | |||
| /** | |||
| * Set the destination file. | |||
| * | |||
| * @param dest The new Dest value | |||
| */ | |||
| public void setDest( File dest ) | |||
| { | |||
| this.dest = dest; | |||
| } | |||
| /** | |||
| * Format string is like this: <p> | |||
| * | |||
| * name=value*name2=value <p> | |||
| * | |||
| * Names are case sensitive. <p> | |||
| * | |||
| * Use the setSep() method to change the * to something else if you need to | |||
| * use * as a name or value. | |||
| * | |||
| * @param keys The new Keys value | |||
| */ | |||
| public void setKeys( String keys ) | |||
| { | |||
| if( keys != null && keys.length() > 0 ) | |||
| { | |||
| StringTokenizer tok = | |||
| new StringTokenizer( keys, this.sep, false ); | |||
| while( tok.hasMoreTokens() ) | |||
| { | |||
| String token = tok.nextToken().trim(); | |||
| StringTokenizer itok = | |||
| new StringTokenizer( token, "=", false ); | |||
| String name = itok.nextToken(); | |||
| String value = itok.nextToken(); | |||
| // log ( "Name: " + name ); | |||
| // log ( "Value: " + value ); | |||
| replacements.put( name, value ); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * Sets the seperator between name=value arguments in setKeys(). By default | |||
| * it is "*". | |||
| * | |||
| * @param sep The new Sep value | |||
| */ | |||
| public void setSep( String sep ) | |||
| { | |||
| this.sep = sep; | |||
| } | |||
| /** | |||
| * Set the source file. | |||
| * | |||
| * @param s The new Src value | |||
| */ | |||
| public void setSrc( File s ) | |||
| { | |||
| this.source = s; | |||
| } | |||
| /** | |||
| * Do the execution. | |||
| * | |||
| * @exception BuildException Description of Exception | |||
| */ | |||
| public void execute() | |||
| throws BuildException | |||
| { | |||
| log( "!! KeySubst is deprecated. Use Filter + CopyDir instead. !!" ); | |||
| log( "Performing Substitions" ); | |||
| if( source == null || dest == null ) | |||
| { | |||
| log( "Source and destinations must not be null" ); | |||
| return; | |||
| } | |||
| BufferedReader br = null; | |||
| BufferedWriter bw = null; | |||
| try | |||
| { | |||
| br = new BufferedReader( new FileReader( source ) ); | |||
| dest.delete(); | |||
| bw = new BufferedWriter( new FileWriter( dest ) ); | |||
| String line = null; | |||
| String newline = null; | |||
| int length; | |||
| line = br.readLine(); | |||
| while( line != null ) | |||
| { | |||
| if( line.length() == 0 ) | |||
| { | |||
| bw.newLine(); | |||
| } | |||
| else | |||
| { | |||
| newline = KeySubst.replace( line, replacements ); | |||
| bw.write( newline ); | |||
| bw.newLine(); | |||
| } | |||
| line = br.readLine(); | |||
| } | |||
| bw.flush(); | |||
| bw.close(); | |||
| br.close(); | |||
| } | |||
| catch( IOException ioe ) | |||
| { | |||
| ioe.printStackTrace(); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,92 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.File; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| * Renames a file. | |||
| * | |||
| * @author haas@softwired.ch | |||
| * @deprecated The rename task is deprecated. Use move instead. | |||
| */ | |||
| public class Rename extends Task | |||
| { | |||
| private boolean replace = true; | |||
| private File dest; | |||
| private File src; | |||
| /** | |||
| * Sets the new name of the file. | |||
| * | |||
| * @param dest the new name of the file. | |||
| */ | |||
| public void setDest( File dest ) | |||
| { | |||
| this.dest = dest; | |||
| } | |||
| /** | |||
| * Sets wheter an existing file should be replaced. | |||
| * | |||
| * @param replace <code>on</code>, if an existing file should be replaced. | |||
| */ | |||
| public void setReplace( String replace ) | |||
| { | |||
| this.replace = project.toBoolean( replace ); | |||
| } | |||
| /** | |||
| * Sets the file to be renamed. | |||
| * | |||
| * @param src the file to rename | |||
| */ | |||
| public void setSrc( File src ) | |||
| { | |||
| this.src = src; | |||
| } | |||
| /** | |||
| * Renames the file <code>src</code> to <code>dest</code> | |||
| * | |||
| * @exception BuildException Description of Exception | |||
| */ | |||
| public void execute() | |||
| throws BuildException | |||
| { | |||
| log( "DEPRECATED - The rename task is deprecated. Use move instead." ); | |||
| if( dest == null ) | |||
| { | |||
| throw new BuildException( "dest attribute is required", location ); | |||
| } | |||
| if( src == null ) | |||
| { | |||
| throw new BuildException( "src attribute is required", location ); | |||
| } | |||
| if( replace && dest.exists() ) | |||
| { | |||
| if( !dest.delete() ) | |||
| { | |||
| throw new BuildException( "Unable to remove existing file " + | |||
| dest ); | |||
| } | |||
| } | |||
| if( !src.renameTo( dest ) ) | |||
| { | |||
| throw new BuildException( "Unable to rename " + src + " to " + | |||
| dest ); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,84 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import java.io.IOException; | |||
| import java.io.OutputStream; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| * Redirects text written to a stream thru the standard ant logging mechanism. | |||
| * This class is useful for integrating with tools that write to System.out and | |||
| * System.err. For example, the following will cause all text written to | |||
| * System.out to be logged with "info" priority: <pre>System.setOut(new PrintStream(new TaskOutputStream(project, Project.MSG_INFO)));</pre> | |||
| * | |||
| * @author James Duncan Davidson (duncan@x180.com) | |||
| * @deprecated use LogOutputStream instead. | |||
| */ | |||
| public class TaskOutputStream extends OutputStream | |||
| { | |||
| private StringBuffer line; | |||
| private int msgOutputLevel; | |||
| private Task task; | |||
| /** | |||
| * Constructs a new JavacOutputStream with the given project as the output | |||
| * source for messages. | |||
| * | |||
| * @param task Description of Parameter | |||
| * @param msgOutputLevel Description of Parameter | |||
| */ | |||
| TaskOutputStream( Task task, int msgOutputLevel ) | |||
| { | |||
| this.task = task; | |||
| this.msgOutputLevel = msgOutputLevel; | |||
| line = new StringBuffer(); | |||
| } | |||
| /** | |||
| * Write a character to the output stream. This method looks to make sure | |||
| * that there isn't an error being reported and will flush each line of | |||
| * input out to the project's log stream. | |||
| * | |||
| * @param c Description of Parameter | |||
| * @exception IOException Description of Exception | |||
| */ | |||
| public void write( int c ) | |||
| throws IOException | |||
| { | |||
| char cc = ( char )c; | |||
| if( cc == '\r' || cc == '\n' ) | |||
| { | |||
| // line feed | |||
| if( line.length() > 0 ) | |||
| { | |||
| processLine(); | |||
| } | |||
| } | |||
| else | |||
| { | |||
| line.append( cc ); | |||
| } | |||
| } | |||
| /** | |||
| * Processes a line of input and determines if an error occured. | |||
| */ | |||
| private void processLine() | |||
| { | |||
| String s = line.toString(); | |||
| task.log( s, msgOutputLevel ); | |||
| line = new StringBuffer(); | |||
| } | |||
| } | |||
| @@ -1,131 +0,0 @@ | |||
| /* | |||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||
| * | |||
| * This software is published under the terms of the Apache Software License | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.optional; | |||
| import java.io.File; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.taskdefs.MatchingTask; | |||
| import org.apache.tools.ant.taskdefs.Move; | |||
| import org.apache.tools.ant.types.Mapper; | |||
| /** | |||
| * @author dIon Gillard <a href="mailto:dion@multitask.com.au"> | |||
| * dion@multitask.com.au</a> | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| * @version 1.2 | |||
| */ | |||
| public class RenameExtensions extends MatchingTask | |||
| { | |||
| private String fromExtension = ""; | |||
| private String toExtension = ""; | |||
| private boolean replace = false; | |||
| private Mapper.MapperType globType; | |||
| private File srcDir; | |||
| /** | |||
| * Creates new RenameExtensions | |||
| */ | |||
| public RenameExtensions() | |||
| { | |||
| super(); | |||
| globType = new Mapper.MapperType(); | |||
| globType.setValue( "glob" ); | |||
| } | |||
| /** | |||
| * store fromExtension * | |||
| * | |||
| * @param from The new FromExtension value | |||
| */ | |||
| public void setFromExtension( String from ) | |||
| { | |||
| fromExtension = from; | |||
| } | |||
| /** | |||
| * store replace attribute - this determines whether the target file should | |||
| * be overwritten if present | |||
| * | |||
| * @param replace The new Replace value | |||
| */ | |||
| public void setReplace( boolean replace ) | |||
| { | |||
| this.replace = replace; | |||
| } | |||
| /** | |||
| * Set the source dir to find the files to be renamed. | |||
| * | |||
| * @param srcDir The new SrcDir value | |||
| */ | |||
| public void setSrcDir( File srcDir ) | |||
| { | |||
| this.srcDir = srcDir; | |||
| } | |||
| /** | |||
| * store toExtension * | |||
| * | |||
| * @param to The new ToExtension value | |||
| */ | |||
| public void setToExtension( String to ) | |||
| { | |||
| toExtension = to; | |||
| } | |||
| /** | |||
| * Executes the task, i.e. does the actual compiler call | |||
| * | |||
| * @exception BuildException Description of Exception | |||
| */ | |||
| public void execute() | |||
| throws BuildException | |||
| { | |||
| // first off, make sure that we've got a from and to extension | |||
| if( fromExtension == null || toExtension == null || srcDir == null ) | |||
| { | |||
| throw new BuildException( "srcDir, fromExtension and toExtension " + | |||
| "attributes must be set!" ); | |||
| } | |||
| log( "DEPRECATED - The renameext task is deprecated. Use move instead.", | |||
| Project.MSG_WARN ); | |||
| log( "Replace this with:", Project.MSG_INFO ); | |||
| log( "<move todir=\"" + srcDir + "\" overwrite=\"" + replace + "\">", | |||
| Project.MSG_INFO ); | |||
| log( " <fileset dir=\"" + srcDir + "\" />", Project.MSG_INFO ); | |||
| log( " <mapper type=\"glob\"", Project.MSG_INFO ); | |||
| log( " from=\"*" + fromExtension + "\"", Project.MSG_INFO ); | |||
| log( " to=\"*" + toExtension + "\" />", Project.MSG_INFO ); | |||
| log( "</move>", Project.MSG_INFO ); | |||
| log( "using the same patterns on <fileset> as you\'ve used here", | |||
| Project.MSG_INFO ); | |||
| Move move = ( Move )project.createTask( "move" ); | |||
| move.setOwningTarget( target ); | |||
| move.setTaskName( getTaskName() ); | |||
| move.setLocation( getLocation() ); | |||
| move.setTodir( srcDir ); | |||
| move.setOverwrite( replace ); | |||
| fileset.setDir( srcDir ); | |||
| move.addFileset( fileset ); | |||
| Mapper me = move.createMapper(); | |||
| me.setType( globType ); | |||
| me.setFrom( "*" + fromExtension ); | |||
| me.setTo( "*" + toExtension ); | |||
| move.execute(); | |||
| } | |||
| } | |||