ASF Bugzilla – Attachment 10309 Details for
Bug 26849
[PATCH] Pathconvert output in xml format and write to file
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
pathconvert.patch
pathconvert.patch (text/plain), 5.81 KB, created by
Nicola Ken Barozzi
on 2004-02-11 10:20:18 UTC
(
hide
)
Description:
pathconvert.patch
Filename:
MIME Type:
Creator:
Nicola Ken Barozzi
Created:
2004-02-11 10:20:18 UTC
Size:
5.81 KB
patch
obsolete
>Index: PathConvert.java >=================================================================== >RCS file: /home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/PathConvert.java,v >retrieving revision 1.30 >diff -u -r1.30 PathConvert.java >--- PathConvert.java 9 Feb 2004 21:05:20 -0000 1.30 >+++ PathConvert.java 11 Feb 2004 10:12:53 -0000 >@@ -16,7 +16,11 @@ > */ > package org.apache.tools.ant.taskdefs; > >+import java.io.BufferedOutputStream; > import java.io.File; >+import java.io.FileOutputStream; >+import java.io.IOException; >+import java.io.PrintStream; > import java.util.StringTokenizer; > import java.util.Vector; > import org.apache.tools.ant.BuildException; >@@ -36,6 +40,8 @@ > * > * @author Larry Streepy <a href="mailto:streepy@healthlanguage.com"> > * streepy@healthlanguage.com</a> >+ * @author Nicola Ken Barozzi <a href="mailto:nicolaken@apache.org"> >+ * nicolaken@apache.org</a> > * @since Ant 1.4 > * @ant.task category="utility" > */ >@@ -71,6 +77,14 @@ > */ > private String property = null;// > /** >+ * The file to write the conversion to >+ */ >+ private File file = null;// >+ /** >+ * The type of the output, xml or plain >+ */ >+ private String type = null;// >+ /** > * Path prefix map > */ > private Vector prefixMap = new Vector(); >@@ -88,6 +102,7 @@ > */ > public PathConvert() { > onWindows = Os.isFamily("dos"); >+ type="plain"; > } > > >@@ -254,7 +269,21 @@ > property = p; > } > >- >+ /** >+ * The file into which the converted path will be written. >+ */ >+ public void setFile(File f) { >+ file = f; >+ } >+ >+ /** >+ * The type of output into which the converted path will be placed. >+ * Can be <code>plain</core> or <code>xml</code> >+ */ >+ public void setType(String t) { >+ type = t; >+ } >+ > /** > * Adds a reference to a Path, FileSet, DirSet, or FileList defined > * elsewhere. >@@ -352,7 +381,10 @@ > // Get the list of path components in canonical form > String[] elems = path.list(); > >+ if (type.equals("xml")) rslt.append("<?xml version=\"1.0\" ?><path>"); >+ > for (int i = 0; i < elems.length; i++) { >+ if (type.equals("xml")) rslt.append("<pathelement>"); > String elem = elems[i]; > > elem = mapElement(elem); // Apply the path prefix map >@@ -360,7 +392,7 @@ > // Now convert the path and file separator characters from the > // current os to the target os. > >- if (i != 0) { >+ if (i != 0 && !type.equals("xml")) { > rslt.append(pathSep); > } > >@@ -368,29 +400,28 @@ > 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); >- } >+ if (fromDirSep.equals(token)) { >+ rslt.append(dirSep); >+ } else { >+ rslt.append(token); >+ } > } >+ if (type.equals("xml")) rslt.append("</pathelement>"); > } >+ if (type.equals("xml")) rslt.append("</path>"); > > // Place the result into the specified property, > // unless setonempty == false > String value = rslt.toString(); > if (setonempty) { >- log("Set property " + property + " = " + value, >- Project.MSG_VERBOSE); >- getProject().setNewProperty(property, value); >+ exportProperty(property, value); > } else { > if (rslt.length() > 0) { >- log("Set property " + property + " = " + value, >- Project.MSG_VERBOSE); >- getProject().setNewProperty(property, value); >+ exportProperty(property, value); > } > } > } finally { >@@ -400,6 +431,28 @@ > } > } > >+ private void exportProperty(String property, String value) throws BuildException{ >+ if(property!=null) { >+ log("Set property " + property + " = " + value, Project.MSG_VERBOSE); >+ getProject().setNewProperty(property, value); >+ } >+ >+ if(file!=null) { >+ log("Writing to file " + file.getPath() + " \n value: " + value, Project.MSG_VERBOSE); >+ PrintStream ps = null; >+ try { >+ ps = new PrintStream(new BufferedOutputStream(new FileOutputStream(file))); >+ ps.print(value); >+ ps.flush(); >+ } catch (IOException ioe) { >+ throw new BuildException(ioe, getLocation()); >+ } finally { >+ if (ps != null) { >+ ps.close(); >+ } >+ } >+ } >+ } > > /** > * Apply the configured map to a path element. The map is used to convert >@@ -447,8 +500,8 @@ > throw new BuildException("You must specify a path to convert"); > } > >- if (property == null) { >- throw new BuildException("You must specify a property"); >+ if (property == null && file == null ) { >+ throw new BuildException("You must specify at least a property or a file"); > } > > // Must either have a target OS or both a dirSep and pathSep
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 26849
: 10309