From 7bb2ccf52f96d0781a32f7dd709f90c9f8243f47 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 2 Feb 2005 13:46:08 +0000 Subject: [PATCH] Make native2ascii a full-blown facade task, add docs git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277573 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 2 + docs/manual/OptionalTasks/native2ascii.html | 63 ++++++++++++++++++- .../ant/taskdefs/optional/Native2Ascii.java | 45 ++++++++++++- .../native2ascii/DefaultNative2Ascii.java | 4 +- 4 files changed, 110 insertions(+), 4 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 4b9bb1088..f4fc59b69 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -198,6 +198,8 @@ Other changes: * Added length task to get strings' and files' lengths. +* now also supports Kaffe's version. + Fixed bugs: ----------- diff --git a/docs/manual/OptionalTasks/native2ascii.html b/docs/manual/OptionalTasks/native2ascii.html index 459e10727..ca86e37d7 100644 --- a/docs/manual/OptionalTasks/native2ascii.html +++ b/docs/manual/OptionalTasks/native2ascii.html @@ -40,6 +40,15 @@ and <patternset> elements.

+

It is possible to use different converters. This can be selected + with the implementation attribute. + Here are the choices:

+ + @@ -49,7 +58,8 @@ + i.e. convert from ASCII to native only supported by the + sun converter @@ -105,8 +115,57 @@ taken to be an exclude pattern + + + + +
Attribute
reverse Reverse the sense of the conversion, - i.e. convert from ASCII to native No
No
implementationThe converter implementation to use. + If this attribute is not set, the default converter for the + current VM will be used. (See the above list of valid converters.)No
+

Parameters specified as nested elements

+ +

arg

+ +

You can specify additional command line arguments for the converter +with nested <arg> elements. These elements are +specified like Command-line Arguments +but have an additional attribute that can be used to enable arguments +only if a given converter implementation will be used.

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
AttributeDescriptionRequired
valueSee + Command-line Arguments.Exactly one of these.
line
file
path
implementationOnly pass the specified argument if the chosen converter + implementation matches the value of this attribute. Legal values + are the same as those in the above list of valid compilers.)No
+

Examples

@@ -133,6 +192,6 @@
     


-

Copyright © 2000-2002,2004 The Apache Software Foundation. All rights +

Copyright © 2000-2002,2004-2005 The Apache Software Foundation. All rights Reserved.

diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java b/src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java index 743441e4e..8ed26974e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java @@ -29,6 +29,8 @@ import org.apache.tools.ant.types.Mapper; import org.apache.tools.ant.util.FileNameMapper; import org.apache.tools.ant.util.IdentityMapper; import org.apache.tools.ant.util.SourceFileScanner; +import org.apache.tools.ant.util.facade.FacadeTaskHelper; +import org.apache.tools.ant.util.facade.ImplementationSpecificArgument; /** * Converts files from native encodings to ASCII. @@ -44,6 +46,11 @@ public class Native2Ascii extends MatchingTask { private String extension = null; // Extension of output files if different private Mapper mapper; + private FacadeTaskHelper facade = null; + + public Native2Ascii() { + facade = new FacadeTaskHelper(Native2AsciiAdapterFactory.getDefault()); + } /** * Flag the conversion to run in the reverse sense, @@ -114,6 +121,19 @@ public class Native2Ascii extends MatchingTask { this.extension = ext; } + /** + * Choose the implementation for this particular task. + * @param compiler the name of the compiler + * @since Ant 1.6.3 + */ + public void setImplementation(String impl) { + if ("default".equals(impl)) { + facade.setImplementation(Native2AsciiAdapterFactory.getDefault()); + } else { + facade.setImplementation(impl); + } + } + /** * Defines the FileNameMapper to use (nested mapper element). * @@ -139,6 +159,18 @@ public class Native2Ascii extends MatchingTask { createMapper().add(fileNameMapper); } + /** + * Adds an implementation specific command-line argument. + * @return a ImplementationSpecificArgument to be configured + * + * @since Ant 1.6.3 + */ + public ImplementationSpecificArgument createArg() { + ImplementationSpecificArgument arg = + new ImplementationSpecificArgument(); + facade.addImplementationArgument(arg); + return arg; + } /** * Execute the task @@ -230,12 +262,23 @@ public class Native2Ascii extends MatchingTask { log("converting " + srcName, Project.MSG_VERBOSE); Native2AsciiAdapter ad = - Native2AsciiAdapterFactory.getAdapter(null, this); + Native2AsciiAdapterFactory.getAdapter(facade.getImplementation(), + this); if (!ad.convert(this, srcFile, destFile)) { throw new BuildException("conversion failed"); } } + /** + * Returns the (implementation specific) settings given as nested + * arg elements. + * + * @since Ant 1.6.3 + */ + public String[] getCurrentArgs() { + return facade.getArgs(); + } + private class ExtMapper implements FileNameMapper { public void setFrom(String s) { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/native2ascii/DefaultNative2Ascii.java b/src/main/org/apache/tools/ant/taskdefs/optional/native2ascii/DefaultNative2Ascii.java index c9cd99958..87a6daf04 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/native2ascii/DefaultNative2Ascii.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/native2ascii/DefaultNative2Ascii.java @@ -50,7 +50,8 @@ public abstract class DefaultNative2Ascii implements Native2AsciiAdapter { /** * Sets up the initial command line. * - *

only the -encoding argument gets handled here.

+ *

only the -encoding argument and nested arg elements get + * handled here.

* * @param cmd Command line to add to * @param args provides the user-setting and access to Ant's @@ -62,6 +63,7 @@ public abstract class DefaultNative2Ascii implements Native2AsciiAdapter { cmd.createArgument().setValue("-encoding"); cmd.createArgument().setValue(args.getEncoding()); } + cmd.addArguments(args.getCurrentArgs()); } /**