Browse Source

Fix API backwards incompatibilty in PathConvert I had introduced.

Make sure <pathconvert> resets its state (7552).

Cosmetics.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272394 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
25253f3faa
6 changed files with 154 additions and 113 deletions
  1. +9
    -6
      src/main/org/apache/tools/ant/taskdefs/Manifest.java
  2. +1
    -3
      src/main/org/apache/tools/ant/taskdefs/ManifestException.java
  3. +6
    -3
      src/main/org/apache/tools/ant/taskdefs/Mkdir.java
  4. +7
    -4
      src/main/org/apache/tools/ant/taskdefs/Parallel.java
  5. +2
    -0
      src/main/org/apache/tools/ant/taskdefs/Patch.java
  6. +129
    -97
      src/main/org/apache/tools/ant/taskdefs/PathConvert.java

+ 9
- 6
src/main/org/apache/tools/ant/taskdefs/Manifest.java View File

@@ -70,6 +70,7 @@ import java.io.StringWriter;
import java.io.UnsupportedEncodingException;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.util.CollectionUtils;
@@ -81,6 +82,8 @@ import org.apache.tools.ant.util.CollectionUtils;
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:j_a_fernandez@yahoo.com">Jose Alberto Fernandez</a>
*
* @since Ant 1.4
*
* @ant.task category="java"
*/
public class Manifest extends Task {
@@ -553,7 +556,7 @@ public class Manifest extends Task {
String check = addAttributeAndCheck(attribute);
if (check != null) {
throw new BuildException("Specify the section name using "
+ "the \"name\" attribute of the <section> element rather "
+ "the \"name\" attribute of the <section> element rather "
+ "than using a \"Name\" manifest attribute");
}
}
@@ -691,7 +694,6 @@ public class Manifest extends Task {
/**
* Construct a manifest from Ant's default manifest file.
*
*
* @return the default manifest.
* @exception BuildException if there is a problem loading the
* default manifest
@@ -1031,7 +1033,7 @@ public class Manifest extends Task {
/**
* Create or update the Manifest when used as a task.
*
* @throws BuildException if the manifst cannot be written.
* @throws BuildException if the manifest cannot be written.
*/
public void execute() throws BuildException {
if (manifestFile == null) {
@@ -1049,10 +1051,10 @@ public class Manifest extends Task {
current = new Manifest(f);
} catch (ManifestException m) {
error = new BuildException("Existing manifest " + manifestFile
+ " is invalid", m, location);
+ " is invalid", m, location);
} catch (IOException e) {
error = new BuildException("Failed to read " + manifestFile,
e, location);
e, location);
} finally {
if (f != null) {
try {
@@ -1078,7 +1080,8 @@ public class Manifest extends Task {
}

if (toWrite.equals(current)) {
log("Manifest has not changed, do not recreate", project.MSG_VERBOSE);
log("Manifest has not changed, do not recreate",
Project.MSG_VERBOSE);
return;
}



+ 1
- 3
src/main/org/apache/tools/ant/taskdefs/ManifestException.java View File

@@ -53,13 +53,11 @@
*/
package org.apache.tools.ant.taskdefs;




/**
* Exception thrown indicating problems in a JAR Manifest
*
* @author Conor MacNeill
* @since Ant 1.4
*/
public class ManifestException extends Exception {



+ 6
- 3
src/main/org/apache/tools/ant/taskdefs/Mkdir.java View File

@@ -62,6 +62,7 @@ import java.io.File;
* Creates a given directory.
*
* @author duncan@x180.com
* @since Ant 1.1
*
* @ant.task category="filesystem"
*/
@@ -76,14 +77,16 @@ public class Mkdir extends Task {
}

if (dir.isFile()) {
throw new BuildException("Unable to create directory as a file already exists with that name: " + dir.getAbsolutePath());
throw new BuildException("Unable to create directory as a file "
+ "already exists with that name: "
+ dir.getAbsolutePath());
}

if (!dir.exists()) {
boolean result = dir.mkdirs();
if (!result) {
String msg = "Directory " + dir.getAbsolutePath() + " creation was not " +
"successful for an unknown reason";
String msg = "Directory " + dir.getAbsolutePath()
+ " creation was not successful for an unknown reason";
throw new BuildException(msg, location);
}
log("Created dir: " + dir.getAbsolutePath());


+ 7
- 4
src/main/org/apache/tools/ant/taskdefs/Parallel.java View File

@@ -57,6 +57,7 @@ import org.apache.tools.ant.Task;
import org.apache.tools.ant.TaskContainer;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Location;
import org.apache.tools.ant.util.StringUtils;

import java.util.Vector;
import java.util.Enumeration;
@@ -68,6 +69,7 @@ import java.util.Enumeration;
* <p>
* @author Thomas Christen <a href="mailto:chr@active.ch">chr@active.ch</a>
* @author Conor MacNeill
* @since Ant 1.4
*
* @ant.task category="control"
*/
@@ -95,7 +97,8 @@ public class Parallel extends Task
public void execute() throws BuildException {
TaskThread[] threads = new TaskThread[nestedTasks.size()];
int threadNumber = 0;
for (Enumeration e = nestedTasks.elements(); e.hasMoreElements(); threadNumber++) {
for (Enumeration e = nestedTasks.elements(); e.hasMoreElements();
threadNumber++) {
Task nestedTask = (Task)e.nextElement();
threads[threadNumber] = new TaskThread(threadNumber, nestedTask);
}
@@ -117,7 +120,6 @@ public class Parallel extends Task
// now did any of the threads throw an exception
StringBuffer exceptionMessage = new StringBuffer();
String lSep = System.getProperty("line.separator");
int numExceptions = 0;
Throwable firstException = null;
Location firstLocation = Location.UNKNOWN_LOCATION;;
@@ -132,7 +134,7 @@ public class Parallel extends Task
firstLocation == Location.UNKNOWN_LOCATION) {
firstLocation = ((BuildException)t).getLocation();
}
exceptionMessage.append(lSep);
exceptionMessage.append(StringUtils.LINE_SEP);
exceptionMessage.append(t.getMessage());
}
}
@@ -146,7 +148,8 @@ public class Parallel extends Task
}
}
else if (numExceptions > 1) {
throw new BuildException(exceptionMessage.toString(), firstLocation);
throw new BuildException(exceptionMessage.toString(),
firstLocation);
}
}



+ 2
- 0
src/main/org/apache/tools/ant/taskdefs/Patch.java View File

@@ -66,6 +66,8 @@ import java.io.IOException;
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*
* @since Ant 1.1
*
* @ant.task category="utility"
*/
public class Patch extends Task {


+ 129
- 97
src/main/org/apache/tools/ant/taskdefs/PathConvert.java View File

@@ -70,35 +70,39 @@ import java.util.Vector;
import java.io.File;

/**
* This task converts path and classpath information to a specific target OS format.
* The resulting formatted path is placed into a specified property.
* <p>
* LIMITATION: Currently this implementation groups all machines into one of two
* types: Unix or Windows. Unix is defined as NOT windows.
* This task converts path and classpath information to a specific
* target OS format. The resulting formatted path is placed into a
* specified property.
*
* @author Larry Streepy <a href="mailto:streepy@healthlanguage.com">streepy@healthlanguage.com</a>
*
* @since Ant 1.4
*
* @ant.task category="utility"
*/
public class PathConvert extends Task {

public PathConvert() {
onWindows = Os.isFamily("dos");
}

/**
* Helper class, holds the nested <map> values. Elements will look like this:
* &lt;map from="d:" to="/foo"/&gt;
* Helper class, holds the nested <map> values. Elements will
* look like this: &lt;map from=&quot;d:&quot; to=&quot;/foo&quot;/&gt;
* <p>
* When running on windows, the prefix comparison will be case insensitive.
*/
public class MapEntry {

/**
* Set the "from" attribute of the map entry
* Set the &quot;from&quot; attribute of the map entry
*/
public void setFrom( String from ) {
this.from = from;
}

/**
* Set the "to" attribute of the map entry
* Set the &quot;to&quot; attribute of the map entry
*/
public void setTo( String to ) {
this.to = to;
@@ -111,15 +115,16 @@ public class PathConvert extends Task {
*/
public String apply( String elem ) {
if( from == null || to == null ) {
throw new BuildException( "Both 'from' and 'to' must be set in a map entry" );
throw new BuildException( "Both 'from' and 'to' must be set "
+ "in a map entry" );
}

// If we're on windows, then do the comparison ignoring case
String cmpElem = onWindows ? elem.toLowerCase() : elem;
String cmpFrom = onWindows ? from.toLowerCase() : from;

// If the element starts with the configured prefix, then convert the prefix
// to the configured 'to' value.
// If the element starts with the configured prefix, then
// convert the prefix to the configured 'to' value.

if( cmpElem.startsWith( cmpFrom ) ) {
int len = from.length();
@@ -170,8 +175,21 @@ public class PathConvert extends Task {
return entry;
}


/**
* Set the value of the targetos attribute
* @deprecated use the method taking a TargetOs argument instead
* @see #setTargetos(TargetOs)
*/
public void setTargetos( String target ) {
TargetOs to = new TargetOs();
to.setValue(target);
setTargetos(to);
}

/**
* Set the value of the targetos attribute
* @since Ant 1.5
*/
public void setTargetos( TargetOs target ) {

@@ -180,7 +198,7 @@ public class PathConvert extends Task {
// Currently, we deal with only two path formats: Unix and Windows
// And Unix is everything that is not Windows

// for NetWare and os/2, piggy-back on Windows, since in the
// for NetWare and OS/2, piggy-back on Windows, since in the
// validateSetup code, the same assumptions can be made as
// with windows - that ; is the path separator

@@ -232,84 +250,94 @@ public class PathConvert extends Task {
* Do the execution.
*/
public void execute() throws BuildException {

// If we are a reference, create a Path from the reference
if( isReference() ) {
path = new Path(getProject()).createPath();

Object obj = refid.getReferencedObject(getProject());

if( obj instanceof Path ) {
path.setRefid(refid);
} else if( obj instanceof FileSet ) {
FileSet fs = (FileSet)obj;
path.addFileset( fs );
} else if( obj instanceof DirSet ) {
DirSet ds = (DirSet)obj;
path.addDirset( ds );
} else if( obj instanceof FileList ) {
FileList fl = (FileList)obj;
path.addFilelist( fl );
Path savedPath = path;
String savedPathSep = pathSep; // may be altered in validateSetup
String savedDirSep = dirSep; // may be altered in validateSetup

try {
// If we are a reference, create a Path from the reference
if( isReference() ) {
path = new Path(getProject()).createPath();
} else {
throw new BuildException( "'refid' does not refer to a path, fileset, dirset, or filelist." );
}
}

validateSetup(); // validate our setup

// Currently, we deal with only two path formats: Unix and Windows
// And Unix is everything that is not Windows
// (with the exception for NetWare below)

// for NetWare and OS/2, piggy-back on Windows, since here and
// in the apply code, the same assumptions can be made as with
// windows - that \\ is an OK separator, and do comparisons
// case-insensitive.
onWindows = Os.isFamily("dos");

String fromDirSep = onWindows ? "\\" : "/";

StringBuffer rslt = new StringBuffer( 100 );

// Get the list of path components in canonical form
String[] elems = path.list();

for( int i=0; i < elems.length; i++ ) {
String elem = elems[i];

elem = mapElement( elem ); // Apply the path prefix map


// Now convert the path and file separator characters from the
// current os to the target os.

if( i != 0 ) {
rslt.append( pathSep );
Object obj = refid.getReferencedObject(getProject());
if( obj instanceof Path ) {
path.setRefid(refid);
} else if( obj instanceof FileSet ) {
FileSet fs = (FileSet)obj;
path.addFileset( fs );
} else if( obj instanceof DirSet ) {
DirSet ds = (DirSet)obj;
path.addDirset( ds );
} else if( obj instanceof FileList ) {
FileList fl = (FileList)obj;
path.addFilelist( fl );
} else {
throw new BuildException( "'refid' does not refer to a "
+ "path, fileset, dirset, or "
+ "filelist." );
}
}

StringTokenizer stDirectory =
new StringTokenizer(elem, fromDirSep, true);
String token = null;

while ( stDirectory.hasMoreTokens() ) {
token = stDirectory.nextToken();

if (fromDirSep.equals(token)) {
rslt.append( dirSep );
validateSetup(); // validate our setup
// Currently, we deal with only two path formats: Unix and Windows
// And Unix is everything that is not Windows
// (with the exception for NetWare and OS/2 below)
// for NetWare and OS/2, piggy-back on Windows, since here and
// in the apply code, the same assumptions can be made as with
// windows - that \\ is an OK separator, and do comparisons
// case-insensitive.
String fromDirSep = onWindows ? "\\" : "/";
StringBuffer rslt = new StringBuffer( 100 );
// Get the list of path components in canonical form
String[] elems = path.list();
for( int i=0; i < elems.length; i++ ) {
String elem = elems[i];
elem = mapElement( elem ); // Apply the path prefix map
// Now convert the path and file separator characters from the
// current os to the target os.
if( i != 0 ) {
rslt.append( pathSep );
}
else {
rslt.append( token );
StringTokenizer stDirectory =
new StringTokenizer(elem, fromDirSep, true);
String token = null;
while ( stDirectory.hasMoreTokens() ) {
token = stDirectory.nextToken();
if (fromDirSep.equals(token)) {
rslt.append( dirSep );
}
else {
rslt.append( token );
}
}
}
}

// Place the result into the specified property
String value = rslt.toString();

log( "Set property " + property + " = " + value, Project.MSG_VERBOSE );

getProject().setNewProperty( property, value );
// Place the result into the specified property
String value = rslt.toString();
log( "Set property " + property + " = " + value,
Project.MSG_VERBOSE );
getProject().setNewProperty( property, value );
} finally {
path = savedPath;
dirSep = savedDirSep;
pathSep = savedPathSep;
}
}

/**
@@ -363,7 +391,8 @@ public class PathConvert extends Task {
// Must either have a target OS or both a dirSep and pathSep

if( targetOS == null && pathSep == null && dirSep == null ) {
throw new BuildException( "You must specify at least one of targetOS, dirSep, or pathSep" );
throw new BuildException( "You must specify at least one of "
+ "targetOS, dirSep, or pathSep" );
}

// Determine the separator strings. The dirsep and pathsep attributes
@@ -393,19 +422,22 @@ public class PathConvert extends Task {
* not have child elements if the refid attribute is set.
*/
private BuildException noChildrenAllowed() {
return new BuildException("You must not specify nested <path> elements when using the refid attribute.");
return new BuildException("You must not specify nested <path> "
+ "elements when using the refid attribute.");
}


// Members
private Path path = null; // Path to be converted
private Reference refid = null; // Reference to path/fileset to convert
private String targetOS = null; // The target OS type
private boolean targetWindows = false; // Set when targetOS is set
private boolean onWindows = false; // Set if we're running on windows
private String property = null; // The property to receive the results
private Vector prefixMap = new Vector(); // Path prefix map
private String pathSep = null; // User override on path sep char
private String dirSep = null; // User override on directory sep char
private Path path = null; // Path to be converted
private Reference refid = null; // Reference to path/fileset to
// convert
private String targetOS = null; // The target OS type
private boolean targetWindows = false; // Set when targetOS is set
private boolean onWindows = false; // Set if we're running on windows
private String property = null; // The property to receive the
//results
private Vector prefixMap = new Vector(); // Path prefix map
private String pathSep = null; // User override on path sep char
private String dirSep = null; // User override on directory sep
// char

}

Loading…
Cancel
Save