bodewig 00/09/20 08:53:32
Modified: . WHATSNEW
docs index.html
src/main/org/apache/tools/ant/taskdefs defaults.properties
Added: docs native2ascii.html
src/main/org/apache/tools/ant/taskdefs/optional
Native2Ascii.java
Log:
New task <native2ascii>.
Revision Changes Path
1.31 +1 -1 jakarta-ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- WHATSNEW 2000/09/20 14:49:34 1.30
+++ WHATSNEW 2000/09/20 15:53:20 1.31
@@ -46,7 +46,7 @@
--------------
* New tasks: antstructure, cab, execon, fail, ftp, genkey, jlink,
-junit, sql, javacc, jjtree, starteam, war, unwar, uptodate.
+junit, sql, javacc, jjtree, starteam, war, unwar, uptodate, native2ascii.
* New tasks mparse pending documentation.
1.112 +1 -0 jakarta-ant/docs/index.html
Index: index.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/index.html,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -r1.111 -r1.112
--- index.html 2000/09/20 14:49:35 1.111
+++ index.html 2000/09/20 15:53:25 1.112
@@ -4104,6 +4104,7 @@
<li><a href="#ftp">FTP</a></li>
<li><a href="jlink.html">Jlink</a></li>
<li><a href="junit.html">JUnit</a></li>
+ <li><a href="native2ascii.html">Native2Ascii</a></li>
<li><a href="#netrexxc">NetRexxC</a></li>
<li><a href="#renameexts">RenameExtensions</a></li>
<li><a href="#script">Script</a></li>
1.1 jakarta-ant/docs/native2ascii.html
Index: native2ascii.html
===================================================================
<html>
<head><title>Native2Ascii</title></head>
<body>
<h2>Native2Ascii</h2>
<h3>Description:</h3>
<p>Converts files from native encodings to ascii with escaped Unicode.
A common usage is to convert source files maintained in a native
operating system encoding, to ascii prior to compilation.</p>
<p>All matching files in the source directory are converted from a
native encoding to ascii. If no encoding is specified, the default
encoding for the JVM is used. If ext is specified, then output
files are renamed to use it as a new extension. If dest and
src point to the same directory, ext is required.</p>
<p>This is a directory based task, and supports includes, includesfile,
excludes, excludesfile, and defaultexcludes along with its specific
attributes.</p>
<pre>
Attribute Description Required
-----------------------------------------------------------
reverse Reverse the sense of the conversion, No
i.e. convert from ascii to native
encoding The native encoding the files are in No
src The directory to find files in No
dest The directory to output file to Yes
ext File extension to use in renaming No
output files
</pre>
<h3>Examples</h3>
<pre>
<native2ascii encoding="EUCJIS" src="srcdir"
dest="srcdir"
includes="**/*.eucjis" ext=".java" />
</pre>
<p>Converts all files in the directory srcdir ending in eucjis
from the EUCJIS encoding to ascii and renames the to end in
.java.</p>
<pre>
<native2ascii encoding='EUCJIS" src="native/japanese"
dest="src"
includes="**/*.java />
</pre>
<p>Converts all the files ending in .java in the directory native/japanese
to ascii, placing the results in the directory src. The names of
the files remain the same.</p>
</body>
</html>
1.41 +2 -1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties
Index: defaults.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- defaults.properties 2000/09/20 14:49:37 1.40
+++ defaults.properties 2000/09/20 15:53:29 1.41
@@ -32,7 +32,6 @@
fixcrlf=org.apache.tools.ant.taskdefs.FixCRLF
rename=org.apache.tools.ant.taskdefs.Rename
patch=org.apache.tools.ant.taskdefs.Patch
-compileTask=org.apache.tools.ant.taskdefs.CompileTask
style=org.apache.tools.ant.taskdefs.XSLTProcess
touch=org.apache.tools.ant.taskdefs.Touch
signjar=org.apache.tools.ant.taskdefs.SignJar
@@ -64,6 +63,8 @@
jjtree=org.apache.tools.ant.taskdefs.optional.javacc.JJTree
starteam=org.apache.tools.ant.taskdefs.optional.scm.AntStarTeamCheckOut
jlink=org.apache.tools.ant.taskdefs.optional.jlink.JlinkTask
+native2ascii=org.apache.tools.ant.taskdefs.optional.Native2Ascii
# deprecated ant tasks (kept for back compatibility)
javadoc2=org.apache.tools.ant.taskdefs.Javadoc
+compileTask=org.apache.tools.ant.taskdefs.CompileTask
1.1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java
Index: Native2Ascii.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.taskdefs.optional;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Commandline.Argument;
import java.io.File;
/**
* Convert files from native encodings to ascii.
*
* @author Drew Sudell <[EMAIL PROTECTED]>
*/
public class Native2Ascii extends MatchingTask {
private boolean reverse = false; // convert from ascii back to native
private String encoding = null; // encoding to convert to/from
private File srcDir = null; // Where to find input files
private File destDir = null; // Where to put output files
private String extension = null; // Extension of output files if
different
/**
* Flag the conversion to run in the reverse sense,
* that is Ascii to Native encoding.
*
* @param reverse True if the conversion is to be reversed,
* otherwise false;
*/
public void setReverse(boolean reverse){
this.reverse = reverse;
}
/**
* Set the encoding to translate to/from.
* If unset, the default encoding for the JVM is used.
*
* @param encoding String containing the name of the Native
* encoding to convert from or to.
*/
public void setEncoding(String encoding){
this.encoding = encoding;
}
/**
* Set the source directory in which to find files to convert.
*
* @param srcDir Direcrory to find input file in.
*/
public void setSrc(File srcDir){
this.srcDir = srcDir;
}
/**
* Set the destination dirctory to place converted files into.
*
* @param destDir directory to place output file into.
*/
public void setDest(File destDir){
this.destDir = destDir;
}
/**
* Set the extension which converted files should have.
* If unset, files will not be renamed.
*
* @param ext File extension to use for converted files.
*/
public void setExt(String ext){
this.extension = ext;
}
public void execute() throws BuildException {
Commandline baseCmd = null; // the common portion of our cmd line
DirectoryScanner scanner = null; // Scanner to find our inputs
String[] files; // list of files to process
// default srcDir to basedir
if (srcDir == null){
srcDir = project.resolveFile(".");
}
// Require destDir
if (destDir == null){
throw new BuildException("The dest attribute must be set.");
}
// if src and dest dirs are the same, require the extension
// to be set, so we don't stomp every file. One could still
// include a file with the same extension, but ....
if (srcDir.equals(destDir) && (extension == null)){
throw new BuildException("The ext attribut must be set if"
+ " src and dest dirs are the same.");
}
scanner = getDirectoryScanner(srcDir);
log("Converting files from " + srcDir + " to " + destDir);
files = scanner.getIncludedFiles();
for (int i = 0; i < files.length; i++){
convert(files[i]);
}
}
/**
* Convert a single file.
*
* @param fileName Name of the file to convert (relative to srcDir).
*/
private void convert(String fileName) throws BuildException {
Commandline cmd = new Commandline(); // Command line to run
File srcFile; // File to convert
File destFile; // where to put the results
// Set up the basic args (this could be done once, but
// it's cleaner here)
if (reverse){
cmd.createArgument().setValue("-reverse");
}
if (encoding != null){
cmd.createArgument().setValue("-encoding");
cmd.createArgument().setValue(encoding);
}
// Build the full file names, substuting the extension on the
// destination file if needed.
srcFile = new File(srcDir, fileName);
if (extension != null){
destFile
= new File(destDir,
fileName.substring(0, fileName.lastIndexOf('.'))
+ extension);
}else{
destFile = new File(destDir, fileName);
}
cmd.createArgument().setFile(srcFile);
cmd.createArgument().setFile(destFile);
// Only process if dest not newer than src
if (! destFile.exists()
|| (destFile.lastModified() < srcFile.lastModified())){
// Make sure we're not about to clobber something
if (srcFile.equals(destFile)){
throw new BuildException("file " + srcFile
+ " would overwrite its self");
}
// Make intermediate directories if needed
// XXX JDK 1.1 dosen't have File.getParentFile,
String parentName = destFile.getParent();
if (parentName != null){
File parentFile = new File(parentName);
if ((! parentFile.exists()) && ( ! parentFile.mkdirs())){
throw new BuildException("cannot create parent directory "
+ parentName);
}
}
log("converting " + fileName, Project.MSG_VERBOSE);
sun.tools.native2ascii.Main n2a
= new sun.tools.native2ascii.Main();
if(! n2a.convert(cmd.getArguments())){
throw new BuildException("conversion failed");
}
}
}
}