Browse Source

Started to cleanup ExecuteOn

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270800 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
892dd8df07
6 changed files with 228 additions and 252 deletions
  1. +0
    -4
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/ExecTask.java
  2. +91
    -122
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/ExecuteOn.java
  3. +23
    -0
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/FileDirBoth.java
  4. +0
    -4
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/ExecTask.java
  5. +91
    -122
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/ExecuteOn.java
  6. +23
    -0
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/FileDirBoth.java

+ 0
- 4
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/ExecTask.java View File

@@ -67,8 +67,6 @@ public class ExecTask


/** /**
* The command to execute. * The command to execute.
*
* @param value The new Executable value
*/ */
public void setExecutable( final String value ) public void setExecutable( final String value )
throws TaskException throws TaskException
@@ -78,8 +76,6 @@ public class ExecTask


/** /**
* Use a completely new environment * Use a completely new environment
*
* @param newenv The new Newenvironment value
*/ */
public void setNewenvironment( final boolean newEnvironment ) public void setNewenvironment( final boolean newEnvironment )
{ {


+ 91
- 122
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/ExecuteOn.java View File

@@ -11,16 +11,14 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
import org.apache.avalon.excalibur.util.StringUtil;
import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.types.DirectoryScanner; import org.apache.tools.ant.types.DirectoryScanner;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.util.mappers.Mapper;
import org.apache.tools.ant.types.Marker; import org.apache.tools.ant.types.Marker;
import org.apache.tools.ant.util.mappers.FileNameMapper;
import org.apache.tools.ant.types.SourceFileScanner; import org.apache.tools.ant.types.SourceFileScanner;
import org.apache.avalon.excalibur.util.StringUtil;
import org.apache.tools.ant.util.mappers.FileNameMapper;
import org.apache.tools.ant.util.mappers.Mapper;


/** /**
* Executes a given command, supplying a set of files as arguments. * Executes a given command, supplying a set of files as arguments.
@@ -28,162 +26,143 @@ import org.apache.avalon.excalibur.util.StringUtil;
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:mariusz@rakiura.org">Mariusz Nowostawski</a> * @author <a href="mailto:mariusz@rakiura.org">Mariusz Nowostawski</a>
*/ */
public class ExecuteOn extends ExecTask
public class ExecuteOn
extends ExecTask
{ {
protected ArrayList filesets = new ArrayList();
private boolean relative = false;
private boolean parallel = false;
protected String type = "file";
protected Marker srcFilePos = null;
private boolean skipEmpty = false;
protected Marker targetFilePos = null;
protected Mapper mapperElement = null;
protected FileNameMapper mapper = null;
protected File destDir = null;
private ArrayList m_filesets = new ArrayList();
private boolean m_relative;
private boolean m_parallel;
private String m_type = "file";
private Marker m_srcFilePos;
private boolean m_skipEmpty;
private Marker m_targetFilePos;
private Mapper m_mapperElement;
private FileNameMapper m_mapper;
private File m_destDir


/** /**
* Has &lt;srcfile&gt; been specified before &lt;targetfile&gt; * Has &lt;srcfile&gt; been specified before &lt;targetfile&gt;
*/ */
protected boolean srcIsFirst = true;
private boolean m_srcIsFirst = true;


/** /**
* Set the destination directory. * Set the destination directory.
*
* @param destDir The new Dest value
*/ */
public void setDest( File destDir )
public void setDest( final File destDir )
{ {
this.destDir = destDir;
m_destDir = destDir;
} }


/** /**
* Shall the command work on all specified files in parallel? * Shall the command work on all specified files in parallel?
*
* @param parallel The new Parallel value
*/ */
public void setParallel( boolean parallel )
public void setParallel( final boolean parallel )
{ {
this.parallel = parallel;
m_parallel = parallel;
} }


/** /**
* Should filenames be returned as relative path names? * Should filenames be returned as relative path names?
*
* @param relative The new Relative value
*/ */
public void setRelative( boolean relative )
public void setRelative( final boolean relative )
{ {
this.relative = relative;
m_relative = relative;
} }


/** /**
* Should empty filesets be ignored? * Should empty filesets be ignored?
*
* @param skip The new SkipEmptyFilesets value
*/ */
public void setSkipEmptyFilesets( boolean skip )
public void setSkipEmptyFilesets( final boolean skip )
{ {
skipEmpty = skip;
m_skipEmpty = skip;
} }


/** /**
* Shall the command work only on files, directories or both? * Shall the command work only on files, directories or both?
*
* @param type The new Type value
*/ */
public void setType( FileDirBoth type )
public void setType( final FileDirBoth type )
{ {
this.type = type.getValue();
m_type = type.getValue();
} }


/** /**
* Adds a set of files (nested fileset attribute). * Adds a set of files (nested fileset attribute).
*
* @param set The feature to be added to the Fileset attribute
*/ */
public void addFileset( FileSet set )
public void addFileset( final FileSet set )
{ {
filesets.add( set );
m_filesets.add( set );
} }


/** /**
* Defines the FileNameMapper to use (nested mapper element). * Defines the FileNameMapper to use (nested mapper element).
*
* @return Description of the Returned Value
* @exception TaskException Description of Exception
*/ */
public Mapper createMapper() public Mapper createMapper()
throws TaskException throws TaskException
{ {
if( mapperElement != null )
if( m_mapperElement != null )
{ {
throw new TaskException( "Cannot define more than one mapper" ); throw new TaskException( "Cannot define more than one mapper" );
} }
mapperElement = new Mapper();
return mapperElement;
m_mapperElement = new Mapper();
return m_mapperElement;
} }


/** /**
* Marker that indicates where the name of the source file should be put on * Marker that indicates where the name of the source file should be put on
* the command line. * the command line.
*
* @return Description of the Returned Value
*/ */
public Marker createSrcfile() public Marker createSrcfile()
throws TaskException throws TaskException
{ {
if( srcFilePos != null )
if( m_srcFilePos != null )
{ {
throw new TaskException( getName() + " doesn\'t support multiple srcfile elements." ); throw new TaskException( getName() + " doesn\'t support multiple srcfile elements." );
} }
srcFilePos = getCommand().createMarker();
return srcFilePos;
m_srcFilePos = getCommand().createMarker();
return m_srcFilePos;
} }


/** /**
* Marker that indicates where the name of the target file should be put on * Marker that indicates where the name of the target file should be put on
* the command line. * the command line.
*
* @return Description of the Returned Value
*/ */
public Marker createTargetfile() public Marker createTargetfile()
throws TaskException throws TaskException
{ {
if( targetFilePos != null )
if( m_targetFilePos != null )
{ {
throw new TaskException( getName() + " doesn\'t support multiple targetfile elements." ); throw new TaskException( getName() + " doesn\'t support multiple targetfile elements." );
} }
targetFilePos = getCommand().createMarker();
srcIsFirst = ( srcFilePos != null );
return targetFilePos;
m_targetFilePos = getCommand().createMarker();
m_srcIsFirst = ( m_srcFilePos != null );
return m_targetFilePos;
} }


/** /**
* Construct the command line for parallel execution. * Construct the command line for parallel execution.
* *
* @param srcFiles The filenames to add to the commandline * @param srcFiles The filenames to add to the commandline
* @param baseDirs Description of Parameter
* @return The Commandline value
*/ */
protected String[] getCommandline( String[] srcFiles, File[] baseDirs )
protected String[] getCommandline( final String[] srcFiles,
final File[] baseDirs )
throws TaskException throws TaskException
{ {
ArrayList targets = new ArrayList();
if( targetFilePos != null )
final ArrayList targets = new ArrayList();
if( m_targetFilePos != null )
{ {
Hashtable addedFiles = new Hashtable(); Hashtable addedFiles = new Hashtable();
for( int i = 0; i < srcFiles.length; i++ ) for( int i = 0; i < srcFiles.length; i++ )
{ {
String[] subTargets = mapper.mapFileName( srcFiles[ i ] );
String[] subTargets = m_mapper.mapFileName( srcFiles[ i ] );
if( subTargets != null ) if( subTargets != null )
{ {
for( int j = 0; j < subTargets.length; j++ ) for( int j = 0; j < subTargets.length; j++ )
{ {
String name = null; String name = null;
if( !relative )
if( !m_relative )
{ {
name = name =
( new File( destDir, subTargets[ j ] ) ).getAbsolutePath();
( new File( m_destDir, subTargets[ j ] ) ).getAbsolutePath();
} }
else else
{ {
@@ -205,17 +184,17 @@ public class ExecuteOn extends ExecTask
String[] result = new String[ orig.length + srcFiles.length + targetFiles.length ]; String[] result = new String[ orig.length + srcFiles.length + targetFiles.length ];


int srcIndex = orig.length; int srcIndex = orig.length;
if( srcFilePos != null )
if( m_srcFilePos != null )
{ {
srcIndex = srcFilePos.getPosition();
srcIndex = m_srcFilePos.getPosition();
} }


if( targetFilePos != null )
if( m_targetFilePos != null )
{ {
int targetIndex = targetFilePos.getPosition();
int targetIndex = m_targetFilePos.getPosition();


if( srcIndex < targetIndex if( srcIndex < targetIndex
|| ( srcIndex == targetIndex && srcIsFirst ) )
|| ( srcIndex == targetIndex && m_srcIsFirst ) )
{ {


// 0 --> srcIndex // 0 --> srcIndex
@@ -274,7 +253,7 @@ public class ExecuteOn extends ExecTask
// fill in source file names // fill in source file names
for( int i = 0; i < srcFiles.length; i++ ) for( int i = 0; i < srcFiles.length; i++ )
{ {
if( !relative )
if( !m_relative )
{ {
result[ srcIndex + i ] = result[ srcIndex + i ] =
( new File( baseDirs[ i ], srcFiles[ i ] ) ).getAbsolutePath(); ( new File( baseDirs[ i ], srcFiles[ i ] ) ).getAbsolutePath();
@@ -294,7 +273,8 @@ public class ExecuteOn extends ExecTask
* @param baseDir filename is relative to this dir * @param baseDir filename is relative to this dir
* @return The Commandline value * @return The Commandline value
*/ */
protected String[] getCommandline( String srcFile, File baseDir )
protected String[] getCommandline( final String srcFile,
final File baseDir )
throws TaskException throws TaskException
{ {
return getCommandline( new String[]{srcFile}, new File[]{baseDir} ); return getCommandline( new String[]{srcFile}, new File[]{baseDir} );
@@ -308,15 +288,16 @@ public class ExecuteOn extends ExecTask
* @param ds Description of Parameter * @param ds Description of Parameter
* @return The Dirs value * @return The Dirs value
*/ */
protected String[] getDirs( File baseDir, DirectoryScanner ds )
protected String[] getDirs( final File baseDir,
final DirectoryScanner ds )
throws TaskException throws TaskException
{ {
if( mapper != null )
if( m_mapper != null )
{ {
final SourceFileScanner scanner = new SourceFileScanner(); final SourceFileScanner scanner = new SourceFileScanner();
setupLogger( scanner ); setupLogger( scanner );
return scanner.restrict( ds.getIncludedDirectories(), baseDir, destDir,
mapper );
return scanner.restrict( ds.getIncludedDirectories(), baseDir, m_destDir,
m_mapper );
} }
else else
{ {
@@ -332,15 +313,16 @@ public class ExecuteOn extends ExecTask
* @param ds Description of Parameter * @param ds Description of Parameter
* @return The Files value * @return The Files value
*/ */
protected String[] getFiles( File baseDir, DirectoryScanner ds )
protected String[] getFiles( final File baseDir,
final DirectoryScanner ds )
throws TaskException throws TaskException
{ {
if( mapper != null )
if( m_mapper != null )
{ {
final SourceFileScanner scanner = new SourceFileScanner(); final SourceFileScanner scanner = new SourceFileScanner();
setupLogger( scanner ); setupLogger( scanner );
return scanner.restrict( ds.getIncludedFiles(), baseDir, destDir,
mapper );
return scanner.restrict( ds.getIncludedFiles(), baseDir, m_destDir,
m_mapper );
} }
else else
{ {
@@ -352,44 +334,46 @@ public class ExecuteOn extends ExecTask
throws TaskException throws TaskException
{ {
super.validate(); super.validate();
if( filesets.size() == 0 )
if( m_filesets.size() == 0 )
{ {
throw new TaskException( "no filesets specified" );
final String message = "no filesets specified";
throw new TaskException( message );
} }


if( targetFilePos != null || mapperElement != null
|| destDir != null )
if( m_targetFilePos != null ||
m_mapperElement != null ||
m_destDir != null )
{ {

if( mapperElement == null )
if( m_mapperElement == null )
{ {
throw new TaskException( "no mapper specified" );
final String message = "no mapper specified";
throw new TaskException( message );
} }
if( mapperElement == null )
if( m_mapperElement == null )
{ {
throw new TaskException( "no dest attribute specified" );
final String message = "no dest attribute specified";
throw new TaskException( message );
} }
mapper = mapperElement.getImplementation();
m_mapper = m_mapperElement.getImplementation();
} }
} }


protected void runExec( Execute exe )
protected void runExec( final Execute exe )
throws TaskException throws TaskException
{ {
try try
{ {

ArrayList fileNames = new ArrayList();
ArrayList baseDirs = new ArrayList();
for( int i = 0; i < filesets.size(); i++ )
final ArrayList fileNames = new ArrayList();
final ArrayList baseDirs = new ArrayList();
for( int i = 0; i < m_filesets.size(); i++ )
{ {
FileSet fs = (FileSet)filesets.get( i );
File base = fs.getDir();
DirectoryScanner ds = fs.getDirectoryScanner();
final FileSet fs = (FileSet)m_filesets.get( i );
final File base = fs.getDir();
final DirectoryScanner ds = fs.getDirectoryScanner();


if( !"dir".equals( type ) )
if( !"dir".equals( m_type ) )
{ {
String[] s = getFiles( base, ds );
final String[] s = getFiles( base, ds );
for( int j = 0; j < s.length; j++ ) for( int j = 0; j < s.length; j++ )
{ {
fileNames.add( s[ j ] ); fileNames.add( s[ j ] );
@@ -397,10 +381,9 @@ public class ExecuteOn extends ExecTask
} }
} }


if( !"file".equals( type ) )
if( !"file".equals( m_type ) )
{ {
String[] s = getDirs( base, ds );
;
final String[] s = getDirs( base, ds );
for( int j = 0; j < s.length; j++ ) for( int j = 0; j < s.length; j++ )
{ {
fileNames.add( s[ j ] ); fileNames.add( s[ j ] );
@@ -408,15 +391,15 @@ public class ExecuteOn extends ExecTask
} }
} }


if( fileNames.size() == 0 && skipEmpty )
if( fileNames.size() == 0 && m_skipEmpty )
{ {
getLogger().info( "Skipping fileset for directory " + base + ". It is empty." ); getLogger().info( "Skipping fileset for directory " + base + ". It is empty." );
continue; continue;
} }


if( !parallel )
if( !m_parallel )
{ {
String[] s = new String[ fileNames.size() ];
final String[] s = new String[ fileNames.size() ];
s = (String[])fileNames.toArray( s ); s = (String[])fileNames.toArray( s );
for( int j = 0; j < s.length; j++ ) for( int j = 0; j < s.length; j++ )
{ {
@@ -430,7 +413,7 @@ public class ExecuteOn extends ExecTask
} }
} }


if( parallel && ( fileNames.size() > 0 || !skipEmpty ) )
if( m_parallel && ( fileNames.size() > 0 || !m_skipEmpty ) )
{ {
String[] s = new String[ fileNames.size() ]; String[] s = new String[ fileNames.size() ];
s = (String[])fileNames.toArray( s ); s = (String[])fileNames.toArray( s );
@@ -453,18 +436,4 @@ public class ExecuteOn extends ExecTask
logFlush(); logFlush();
} }
} }

/**
* Enumerated attribute with the values "file", "dir" and "both" for the
* type attribute.
*
* @author RT
*/
public static class FileDirBoth extends EnumeratedAttribute
{
public String[] getValues()
{
return new String[]{"file", "dir", "both"};
}
}
} }

+ 23
- 0
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/FileDirBoth.java View File

@@ -0,0 +1,23 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.exec;

import org.apache.tools.ant.types.EnumeratedAttribute;

/**
* Enumerated attribute with the values "file", "dir" and "both" for the
* type attribute.
*/
public class FileDirBoth
extends EnumeratedAttribute
{
public String[] getValues()
{
return new String[]{"file", "dir", "both"};
}
}

+ 0
- 4
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/ExecTask.java View File

@@ -67,8 +67,6 @@ public class ExecTask


/** /**
* The command to execute. * The command to execute.
*
* @param value The new Executable value
*/ */
public void setExecutable( final String value ) public void setExecutable( final String value )
throws TaskException throws TaskException
@@ -78,8 +76,6 @@ public class ExecTask


/** /**
* Use a completely new environment * Use a completely new environment
*
* @param newenv The new Newenvironment value
*/ */
public void setNewenvironment( final boolean newEnvironment ) public void setNewenvironment( final boolean newEnvironment )
{ {


+ 91
- 122
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/ExecuteOn.java View File

@@ -11,16 +11,14 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
import org.apache.avalon.excalibur.util.StringUtil;
import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.types.DirectoryScanner; import org.apache.tools.ant.types.DirectoryScanner;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.util.mappers.Mapper;
import org.apache.tools.ant.types.Marker; import org.apache.tools.ant.types.Marker;
import org.apache.tools.ant.util.mappers.FileNameMapper;
import org.apache.tools.ant.types.SourceFileScanner; import org.apache.tools.ant.types.SourceFileScanner;
import org.apache.avalon.excalibur.util.StringUtil;
import org.apache.tools.ant.util.mappers.FileNameMapper;
import org.apache.tools.ant.util.mappers.Mapper;


/** /**
* Executes a given command, supplying a set of files as arguments. * Executes a given command, supplying a set of files as arguments.
@@ -28,162 +26,143 @@ import org.apache.avalon.excalibur.util.StringUtil;
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:mariusz@rakiura.org">Mariusz Nowostawski</a> * @author <a href="mailto:mariusz@rakiura.org">Mariusz Nowostawski</a>
*/ */
public class ExecuteOn extends ExecTask
public class ExecuteOn
extends ExecTask
{ {
protected ArrayList filesets = new ArrayList();
private boolean relative = false;
private boolean parallel = false;
protected String type = "file";
protected Marker srcFilePos = null;
private boolean skipEmpty = false;
protected Marker targetFilePos = null;
protected Mapper mapperElement = null;
protected FileNameMapper mapper = null;
protected File destDir = null;
private ArrayList m_filesets = new ArrayList();
private boolean m_relative;
private boolean m_parallel;
private String m_type = "file";
private Marker m_srcFilePos;
private boolean m_skipEmpty;
private Marker m_targetFilePos;
private Mapper m_mapperElement;
private FileNameMapper m_mapper;
private File m_destDir


/** /**
* Has &lt;srcfile&gt; been specified before &lt;targetfile&gt; * Has &lt;srcfile&gt; been specified before &lt;targetfile&gt;
*/ */
protected boolean srcIsFirst = true;
private boolean m_srcIsFirst = true;


/** /**
* Set the destination directory. * Set the destination directory.
*
* @param destDir The new Dest value
*/ */
public void setDest( File destDir )
public void setDest( final File destDir )
{ {
this.destDir = destDir;
m_destDir = destDir;
} }


/** /**
* Shall the command work on all specified files in parallel? * Shall the command work on all specified files in parallel?
*
* @param parallel The new Parallel value
*/ */
public void setParallel( boolean parallel )
public void setParallel( final boolean parallel )
{ {
this.parallel = parallel;
m_parallel = parallel;
} }


/** /**
* Should filenames be returned as relative path names? * Should filenames be returned as relative path names?
*
* @param relative The new Relative value
*/ */
public void setRelative( boolean relative )
public void setRelative( final boolean relative )
{ {
this.relative = relative;
m_relative = relative;
} }


/** /**
* Should empty filesets be ignored? * Should empty filesets be ignored?
*
* @param skip The new SkipEmptyFilesets value
*/ */
public void setSkipEmptyFilesets( boolean skip )
public void setSkipEmptyFilesets( final boolean skip )
{ {
skipEmpty = skip;
m_skipEmpty = skip;
} }


/** /**
* Shall the command work only on files, directories or both? * Shall the command work only on files, directories or both?
*
* @param type The new Type value
*/ */
public void setType( FileDirBoth type )
public void setType( final FileDirBoth type )
{ {
this.type = type.getValue();
m_type = type.getValue();
} }


/** /**
* Adds a set of files (nested fileset attribute). * Adds a set of files (nested fileset attribute).
*
* @param set The feature to be added to the Fileset attribute
*/ */
public void addFileset( FileSet set )
public void addFileset( final FileSet set )
{ {
filesets.add( set );
m_filesets.add( set );
} }


/** /**
* Defines the FileNameMapper to use (nested mapper element). * Defines the FileNameMapper to use (nested mapper element).
*
* @return Description of the Returned Value
* @exception TaskException Description of Exception
*/ */
public Mapper createMapper() public Mapper createMapper()
throws TaskException throws TaskException
{ {
if( mapperElement != null )
if( m_mapperElement != null )
{ {
throw new TaskException( "Cannot define more than one mapper" ); throw new TaskException( "Cannot define more than one mapper" );
} }
mapperElement = new Mapper();
return mapperElement;
m_mapperElement = new Mapper();
return m_mapperElement;
} }


/** /**
* Marker that indicates where the name of the source file should be put on * Marker that indicates where the name of the source file should be put on
* the command line. * the command line.
*
* @return Description of the Returned Value
*/ */
public Marker createSrcfile() public Marker createSrcfile()
throws TaskException throws TaskException
{ {
if( srcFilePos != null )
if( m_srcFilePos != null )
{ {
throw new TaskException( getName() + " doesn\'t support multiple srcfile elements." ); throw new TaskException( getName() + " doesn\'t support multiple srcfile elements." );
} }
srcFilePos = getCommand().createMarker();
return srcFilePos;
m_srcFilePos = getCommand().createMarker();
return m_srcFilePos;
} }


/** /**
* Marker that indicates where the name of the target file should be put on * Marker that indicates where the name of the target file should be put on
* the command line. * the command line.
*
* @return Description of the Returned Value
*/ */
public Marker createTargetfile() public Marker createTargetfile()
throws TaskException throws TaskException
{ {
if( targetFilePos != null )
if( m_targetFilePos != null )
{ {
throw new TaskException( getName() + " doesn\'t support multiple targetfile elements." ); throw new TaskException( getName() + " doesn\'t support multiple targetfile elements." );
} }
targetFilePos = getCommand().createMarker();
srcIsFirst = ( srcFilePos != null );
return targetFilePos;
m_targetFilePos = getCommand().createMarker();
m_srcIsFirst = ( m_srcFilePos != null );
return m_targetFilePos;
} }


/** /**
* Construct the command line for parallel execution. * Construct the command line for parallel execution.
* *
* @param srcFiles The filenames to add to the commandline * @param srcFiles The filenames to add to the commandline
* @param baseDirs Description of Parameter
* @return The Commandline value
*/ */
protected String[] getCommandline( String[] srcFiles, File[] baseDirs )
protected String[] getCommandline( final String[] srcFiles,
final File[] baseDirs )
throws TaskException throws TaskException
{ {
ArrayList targets = new ArrayList();
if( targetFilePos != null )
final ArrayList targets = new ArrayList();
if( m_targetFilePos != null )
{ {
Hashtable addedFiles = new Hashtable(); Hashtable addedFiles = new Hashtable();
for( int i = 0; i < srcFiles.length; i++ ) for( int i = 0; i < srcFiles.length; i++ )
{ {
String[] subTargets = mapper.mapFileName( srcFiles[ i ] );
String[] subTargets = m_mapper.mapFileName( srcFiles[ i ] );
if( subTargets != null ) if( subTargets != null )
{ {
for( int j = 0; j < subTargets.length; j++ ) for( int j = 0; j < subTargets.length; j++ )
{ {
String name = null; String name = null;
if( !relative )
if( !m_relative )
{ {
name = name =
( new File( destDir, subTargets[ j ] ) ).getAbsolutePath();
( new File( m_destDir, subTargets[ j ] ) ).getAbsolutePath();
} }
else else
{ {
@@ -205,17 +184,17 @@ public class ExecuteOn extends ExecTask
String[] result = new String[ orig.length + srcFiles.length + targetFiles.length ]; String[] result = new String[ orig.length + srcFiles.length + targetFiles.length ];


int srcIndex = orig.length; int srcIndex = orig.length;
if( srcFilePos != null )
if( m_srcFilePos != null )
{ {
srcIndex = srcFilePos.getPosition();
srcIndex = m_srcFilePos.getPosition();
} }


if( targetFilePos != null )
if( m_targetFilePos != null )
{ {
int targetIndex = targetFilePos.getPosition();
int targetIndex = m_targetFilePos.getPosition();


if( srcIndex < targetIndex if( srcIndex < targetIndex
|| ( srcIndex == targetIndex && srcIsFirst ) )
|| ( srcIndex == targetIndex && m_srcIsFirst ) )
{ {


// 0 --> srcIndex // 0 --> srcIndex
@@ -274,7 +253,7 @@ public class ExecuteOn extends ExecTask
// fill in source file names // fill in source file names
for( int i = 0; i < srcFiles.length; i++ ) for( int i = 0; i < srcFiles.length; i++ )
{ {
if( !relative )
if( !m_relative )
{ {
result[ srcIndex + i ] = result[ srcIndex + i ] =
( new File( baseDirs[ i ], srcFiles[ i ] ) ).getAbsolutePath(); ( new File( baseDirs[ i ], srcFiles[ i ] ) ).getAbsolutePath();
@@ -294,7 +273,8 @@ public class ExecuteOn extends ExecTask
* @param baseDir filename is relative to this dir * @param baseDir filename is relative to this dir
* @return The Commandline value * @return The Commandline value
*/ */
protected String[] getCommandline( String srcFile, File baseDir )
protected String[] getCommandline( final String srcFile,
final File baseDir )
throws TaskException throws TaskException
{ {
return getCommandline( new String[]{srcFile}, new File[]{baseDir} ); return getCommandline( new String[]{srcFile}, new File[]{baseDir} );
@@ -308,15 +288,16 @@ public class ExecuteOn extends ExecTask
* @param ds Description of Parameter * @param ds Description of Parameter
* @return The Dirs value * @return The Dirs value
*/ */
protected String[] getDirs( File baseDir, DirectoryScanner ds )
protected String[] getDirs( final File baseDir,
final DirectoryScanner ds )
throws TaskException throws TaskException
{ {
if( mapper != null )
if( m_mapper != null )
{ {
final SourceFileScanner scanner = new SourceFileScanner(); final SourceFileScanner scanner = new SourceFileScanner();
setupLogger( scanner ); setupLogger( scanner );
return scanner.restrict( ds.getIncludedDirectories(), baseDir, destDir,
mapper );
return scanner.restrict( ds.getIncludedDirectories(), baseDir, m_destDir,
m_mapper );
} }
else else
{ {
@@ -332,15 +313,16 @@ public class ExecuteOn extends ExecTask
* @param ds Description of Parameter * @param ds Description of Parameter
* @return The Files value * @return The Files value
*/ */
protected String[] getFiles( File baseDir, DirectoryScanner ds )
protected String[] getFiles( final File baseDir,
final DirectoryScanner ds )
throws TaskException throws TaskException
{ {
if( mapper != null )
if( m_mapper != null )
{ {
final SourceFileScanner scanner = new SourceFileScanner(); final SourceFileScanner scanner = new SourceFileScanner();
setupLogger( scanner ); setupLogger( scanner );
return scanner.restrict( ds.getIncludedFiles(), baseDir, destDir,
mapper );
return scanner.restrict( ds.getIncludedFiles(), baseDir, m_destDir,
m_mapper );
} }
else else
{ {
@@ -352,44 +334,46 @@ public class ExecuteOn extends ExecTask
throws TaskException throws TaskException
{ {
super.validate(); super.validate();
if( filesets.size() == 0 )
if( m_filesets.size() == 0 )
{ {
throw new TaskException( "no filesets specified" );
final String message = "no filesets specified";
throw new TaskException( message );
} }


if( targetFilePos != null || mapperElement != null
|| destDir != null )
if( m_targetFilePos != null ||
m_mapperElement != null ||
m_destDir != null )
{ {

if( mapperElement == null )
if( m_mapperElement == null )
{ {
throw new TaskException( "no mapper specified" );
final String message = "no mapper specified";
throw new TaskException( message );
} }
if( mapperElement == null )
if( m_mapperElement == null )
{ {
throw new TaskException( "no dest attribute specified" );
final String message = "no dest attribute specified";
throw new TaskException( message );
} }
mapper = mapperElement.getImplementation();
m_mapper = m_mapperElement.getImplementation();
} }
} }


protected void runExec( Execute exe )
protected void runExec( final Execute exe )
throws TaskException throws TaskException
{ {
try try
{ {

ArrayList fileNames = new ArrayList();
ArrayList baseDirs = new ArrayList();
for( int i = 0; i < filesets.size(); i++ )
final ArrayList fileNames = new ArrayList();
final ArrayList baseDirs = new ArrayList();
for( int i = 0; i < m_filesets.size(); i++ )
{ {
FileSet fs = (FileSet)filesets.get( i );
File base = fs.getDir();
DirectoryScanner ds = fs.getDirectoryScanner();
final FileSet fs = (FileSet)m_filesets.get( i );
final File base = fs.getDir();
final DirectoryScanner ds = fs.getDirectoryScanner();


if( !"dir".equals( type ) )
if( !"dir".equals( m_type ) )
{ {
String[] s = getFiles( base, ds );
final String[] s = getFiles( base, ds );
for( int j = 0; j < s.length; j++ ) for( int j = 0; j < s.length; j++ )
{ {
fileNames.add( s[ j ] ); fileNames.add( s[ j ] );
@@ -397,10 +381,9 @@ public class ExecuteOn extends ExecTask
} }
} }


if( !"file".equals( type ) )
if( !"file".equals( m_type ) )
{ {
String[] s = getDirs( base, ds );
;
final String[] s = getDirs( base, ds );
for( int j = 0; j < s.length; j++ ) for( int j = 0; j < s.length; j++ )
{ {
fileNames.add( s[ j ] ); fileNames.add( s[ j ] );
@@ -408,15 +391,15 @@ public class ExecuteOn extends ExecTask
} }
} }


if( fileNames.size() == 0 && skipEmpty )
if( fileNames.size() == 0 && m_skipEmpty )
{ {
getLogger().info( "Skipping fileset for directory " + base + ". It is empty." ); getLogger().info( "Skipping fileset for directory " + base + ". It is empty." );
continue; continue;
} }


if( !parallel )
if( !m_parallel )
{ {
String[] s = new String[ fileNames.size() ];
final String[] s = new String[ fileNames.size() ];
s = (String[])fileNames.toArray( s ); s = (String[])fileNames.toArray( s );
for( int j = 0; j < s.length; j++ ) for( int j = 0; j < s.length; j++ )
{ {
@@ -430,7 +413,7 @@ public class ExecuteOn extends ExecTask
} }
} }


if( parallel && ( fileNames.size() > 0 || !skipEmpty ) )
if( m_parallel && ( fileNames.size() > 0 || !m_skipEmpty ) )
{ {
String[] s = new String[ fileNames.size() ]; String[] s = new String[ fileNames.size() ];
s = (String[])fileNames.toArray( s ); s = (String[])fileNames.toArray( s );
@@ -453,18 +436,4 @@ public class ExecuteOn extends ExecTask
logFlush(); logFlush();
} }
} }

/**
* Enumerated attribute with the values "file", "dir" and "both" for the
* type attribute.
*
* @author RT
*/
public static class FileDirBoth extends EnumeratedAttribute
{
public String[] getValues()
{
return new String[]{"file", "dir", "both"};
}
}
} }

+ 23
- 0
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/FileDirBoth.java View File

@@ -0,0 +1,23 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.exec;

import org.apache.tools.ant.types.EnumeratedAttribute;

/**
* Enumerated attribute with the values "file", "dir" and "both" for the
* type attribute.
*/
public class FileDirBoth
extends EnumeratedAttribute
{
public String[] getValues()
{
return new String[]{"file", "dir", "both"};
}
}

Loading…
Cancel
Save