diff --git a/src/main/org/apache/tools/ant/filters/FixCrLfFilter.java b/src/main/org/apache/tools/ant/filters/FixCrLfFilter.java index 4ef910131..9715873c2 100755 --- a/src/main/org/apache/tools/ant/filters/FixCrLfFilter.java +++ b/src/main/org/apache/tools/ant/filters/FixCrLfFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2005 The Apache Software Foundation + * Copyright 2005-2006 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,8 @@ import org.apache.tools.ant.taskdefs.condition.Os; import org.apache.tools.ant.types.EnumeratedAttribute; /** - * Converts text to local OS formatting conventions, as - * well as repair text damaged by misconfigured or misguided editors or - * file transfer programs. + * Converts text to local OS formatting conventions, as well as repair text + * damaged by misconfigured or misguided editors or file transfer programs. *

* This filter can take the following arguments: *

* None of which are required. *

- * This version generalises the handling of EOL characters, and allows - * for CR-only line endings (which I suspect is the standard on Macs.) - * Tab handling has also been generalised to accommodate any tabwidth - * from 2 to 80, inclusive. Importantly, it can leave untouched any - * literal TAB characters embedded within Java string or character constants. + * This version generalises the handling of EOL characters, and allows for + * CR-only line endings (which I suspect is the standard on Macs.) Tab handling + * has also been generalised to accommodate any tabwidth from 2 to 80, + * inclusive. Importantly, it can leave untouched any literal TAB characters + * embedded within Java string or character constants. *

- * Caution: run with care on carefully formatted files. This may + * Caution: run with care on carefully formatted files. This may * sound obvious, but if you don't specify asis, presume that your files are - * going to be modified. If "tabs" is "add" or "remove", whitespace - * characters may be added or removed as necessary. Similarly, for EOL's - - * eol="asis" actually means convert to your native O/S EOL convention while - * eol="crlf" or cr="add" can result in CR characters being removed in one - * special case accommodated, i.e., CRCRLF is regarded as a single EOL to - * handle cases where other programs have converted CRLF into CRCRLF. + * going to be modified. If "tabs" is "add" or "remove", whitespace characters + * may be added or removed as necessary. Similarly, for EOL's - eol="asis" + * actually means convert to your native O/S EOL convention while eol="crlf" or + * cr="add" can result in CR characters being removed in one special case + * accommodated, i.e., CRCRLF is regarded as a single EOL to handle cases where + * other programs have converted CRLF into CRCRLF. * - *

Example: - *

<
+ * 

+ * Example: + * + *

+ * <<fixcrlf tab="add" eol="crlf" eof="asis"/>
+ * 
* * Or: * - *
<filterreader classname="org.apache.tools.ant.filters.FixCrLfFilter">
- *  <param eol="crlf" tab="asis"/>
- * </filterreader>
+ *
+ * <filterreader classname="org.apache.tools.ant.filters.FixCrLfFilter">
+ *   <param eol="crlf" tab="asis"/>
+ *  </filterreader>
+ * 
* */ -public final class FixCrLfFilter - extends BaseParamFilterReader - implements ChainableReader { +public final class FixCrLfFilter extends BaseParamFilterReader implements ChainableReader { private static final char CTRLZ = '\u001A'; private int tabLength = 8; + private CrLf eol; + private AddAsisRemove ctrlz; + private AddAsisRemove tabs; + private boolean javafiles = false; + private boolean fixlast = true; + private boolean initialized = false; /** @@ -88,14 +97,16 @@ public final class FixCrLfFilter /** * Create a new filtered reader. * - * @param in A Reader object providing the underlying stream. - * Must not be null. + * @param in + * A Reader object providing the underlying stream. Must not be + * null. */ public FixCrLfFilter(final Reader in) throws IOException { super(in); } - // Instance initializer: Executes just after the super() call in this class's constructor. + // Instance initializer: Executes just after the super() call in this + // class's constructor. { tabs = AddAsisRemove.ASIS; if (Os.isFamily("mac")) { @@ -111,14 +122,14 @@ public final class FixCrLfFilter } /** - * Create a new FixCrLfFilter using the passed in - * Reader for instantiation. + * Create a new FixCrLfFilter using the passed in Reader for instantiation. * - * @param rdr A Reader object providing the underlying stream. - * Must not be null. + * @param rdr + * A Reader object providing the underlying stream. Must not be + * null. * - * @return a new filter based on this configuration, but filtering - * the specified reader. + * @return a new filter based on this configuration, but filtering the + * specified reader. */ public final Reader chain(final Reader rdr) { try { @@ -126,7 +137,7 @@ public final class FixCrLfFilter newFilter.setJavafiles(getJavafiles()); newFilter.setEol(getEol()); - newFilter.setTab(getTab()); + newFilter.setTab(getTab()); newFilter.setTablength(getTablength()); newFilter.setEof(getEof()); newFilter.setFixlast(getFixlast()); @@ -142,14 +153,15 @@ public final class FixCrLfFilter * Get how DOS EOF (control-z) characters are being handled. * * @return values: - * + * */ public AddAsisRemove getEof() { - // Return copy so that the call must call setEof() to change the state of fixCRLF + // Return copy so that the call must call setEof() to change the state + // of fixCRLF return ctrlz.newInstance(); } @@ -157,15 +169,16 @@ public final class FixCrLfFilter * Get how EndOfLine characters are being handled. * * @return values: - * + * */ public CrLf getEol() { - // Return copy so that the call must call setEol() to change the state of fixCRLF + // Return copy so that the call must call setEol() to change the state + // of fixCRLF return eol.newInstance(); } @@ -179,14 +192,15 @@ public final class FixCrLfFilter } /** - * Get whether the stream is to be treated as though it contains Java source. + * Get whether the stream is to be treated as though it contains Java + * source. *

- * This attribute is only used in assocation with the - * "tab" attribute. Tabs found in Java literals - * are protected from changes by this filter. + * This attribute is only used in assocation with the "tab" + * attribute. Tabs found in Java literals are protected from changes by this + * filter. * * @return true if whitespace in Java character and string literals is - * ignored. + * ignored. */ public boolean getJavafiles() { return javafiles; @@ -196,14 +210,16 @@ public final class FixCrLfFilter * Return how tab characters are being handled. * * @return values: - *

+ * */ public AddAsisRemove getTab() { - // Return copy so that the caller must call setTab() to change the state of fixCRLF. + // Return copy so that the caller must call setTab() to change the state + // of fixCRLF. return tabs.newInstance(); } @@ -212,7 +228,7 @@ public final class FixCrLfFilter * * @return the length of tab in spaces */ - public int getTablength(){ + public int getTablength() { return tabLength; } @@ -227,13 +243,13 @@ public final class FixCrLfFilter if (eol == CrLf.CRLF || eol == CrLf.DOS) { return "\r\n"; } - //assume (eol == CrLf.LF || eol == CrLf.UNIX) + // assume (eol == CrLf.LF || eol == CrLf.UNIX) return "\n"; } /** - * Wrap the input stream with the internal filters necessary to perform - * the configuration settings. + * Wrap the input stream with the internal filters necessary to perform the + * configuration settings. */ private void initInternalFilters() { @@ -241,7 +257,7 @@ public final class FixCrLfFilter // filters don't see that character. in = (ctrlz == AddAsisRemove.REMOVE) ? new RemoveEofFilter(in) : in; - // Change all EOL characters to match the calculated EOL string. If + // Change all EOL characters to match the calculated EOL string. If // configured to do so, append a trailing EOL so that the file ends on // a EOL. in = new NormalizeEolFilter(in, calculateEolString(eol), getFixlast()); @@ -253,23 +269,23 @@ public final class FixCrLfFilter in = new MaskJavaTabLiteralsFilter(in); } // Add/Remove tabs - in = (tabs == AddAsisRemove.ADD) - ? (Reader) new AddTabFilter(in, getTablength()) - : (Reader) new RemoveTabFilter(in, getTablength()); + in = (tabs == AddAsisRemove.ADD) ? (Reader) new AddTabFilter(in, getTablength()) + : (Reader) new RemoveTabFilter(in, getTablength()); } // Add missing EOF character in = (ctrlz == AddAsisRemove.ADD) ? new AddEofFilter(in) : in; initialized = true; - } + } /** * Return the next character in the filtered stream. * - * @return the next character in the resulting stream, or -1 - * if the end of the resulting stream has been reached. + * @return the next character in the resulting stream, or -1 if the end of + * the resulting stream has been reached. * - * @exception IOException if the underlying stream throws an IOException - * during reading. + * @exception IOException + * if the underlying stream throws an IOException during + * reading. */ public synchronized final int read() throws IOException { if (!initialized) { @@ -281,12 +297,13 @@ public final class FixCrLfFilter /** * Specify how DOS EOF (control-z) characters are to be handled. * - * @param attr valid values: - * + * @param attr + * valid values: + * */ public void setEof(AddAsisRemove attr) { ctrlz = attr.resolve(); @@ -295,23 +312,24 @@ public final class FixCrLfFilter /** * Specify how end of line (EOL) characters are to be handled. * - * @param attr valid values: - * + * @param attr + * valid values: + * */ public void setEol(CrLf attr) { eol = attr.resolve(); } /** - * Specify whether a missing EOL will be added - * to the final line of input. + * Specify whether a missing EOL will be added to the final line of input. * - * @param fixlast if true a missing EOL will be appended. + * @param fixlast + * if true a missing EOL will be appended. */ public void setFixlast(boolean fixlast) { this.fixlast = fixlast; @@ -319,12 +337,13 @@ public final class FixCrLfFilter /** * Indicate whether this stream contains Java source. - * - * This attribute is only used in assocation with the - * "tab" attribute. * - * @param javafiles set to true to prevent this filter from changing tabs - * found in Java literals. + * This attribute is only used in assocation with the "tab" + * attribute. + * + * @param javafiles + * set to true to prevent this filter from changing tabs found in + * Java literals. */ public void setJavafiles(boolean javafiles) { this.javafiles = javafiles; @@ -333,12 +352,14 @@ public final class FixCrLfFilter /** * Specify how tab characters are to be handled. * - * @param attr valid values: - * + * @param attr + * valid values: + * */ public void setTab(AddAsisRemove attr) { tabs = attr.resolve(); @@ -347,9 +368,9 @@ public final class FixCrLfFilter /** * Specify tab length in characters. * - * @param tabLength specify the length of tab in spaces. - * Valid values are between 2 and 80 - * inclusive. The default for this parameter is 8. + * @param tabLength + * specify the length of tab in spaces. Valid values are between + * 2 and 80 inclusive. The default for this parameter is 8. */ public void setTablength(int tabLength) throws IOException { if (tabLength < 2 || tabLength > 80) { @@ -359,14 +380,20 @@ public final class FixCrLfFilter } /** - * This filter reader redirects all read I/O methods through its own read() method. + * This filter reader redirects all read I/O methods through its own read() + * method. * - *

The input stream is already buffered by the copy task so this doesn't significantly - * impact performance while it makes writing the individual fix filters much easier.

+ *

+ * The input stream is already buffered by the copy task so this doesn't + * significantly impact performance while it makes writing the individual + * fix filters much easier. + *

*/ private static class SimpleFilterReader extends Reader { private Reader in; + int[] preempt = new int[16]; + int preemptIndex = 0; public SimpleFilterReader(Reader in) { @@ -390,7 +417,7 @@ public final class FixCrLfFilter public void push(char[] cs, int start, int length) { for (int i = start + length - 1; i >= start;) { - push(cs [i--]); + push(cs[i--]); } } @@ -403,11 +430,11 @@ public final class FixCrLfFilter } /** - * Does this filter want to block edits on the last character returned by read()? + * Does this filter want to block edits on the last character returned + * by read()? */ public boolean editsBlocked() { - return in instanceof SimpleFilterReader - && ((SimpleFilterReader) in).editsBlocked(); + return in instanceof SimpleFilterReader && ((SimpleFilterReader) in).editsBlocked(); } public int read() throws java.io.IOException { @@ -458,13 +485,19 @@ public final class FixCrLfFilter private static class MaskJavaTabLiteralsFilter extends SimpleFilterReader { boolean editsBlocked = false; - private static final int JAVA = 1; - private static final int IN_CHAR_CONST = 2; - private static final int IN_STR_CONST = 3; + private static final int JAVA = 1; + + private static final int IN_CHAR_CONST = 2; + + private static final int IN_STR_CONST = 3; + private static final int IN_SINGLE_COMMENT = 4; - private static final int IN_MULTI_COMMENT = 5; - private static final int TRANS_TO_COMMENT = 6; - private static final int TRANS_FROM_MULTI = 8; + + private static final int IN_MULTI_COMMENT = 5; + + private static final int TRANS_TO_COMMENT = 6; + + private static final int TRANS_FROM_MULTI = 8; private int state; @@ -473,7 +506,7 @@ public final class FixCrLfFilter state = JAVA; } - public boolean editsBlocked () { + public boolean editsBlocked() { return editsBlocked || super.editsBlocked(); } @@ -485,20 +518,30 @@ public final class FixCrLfFilter switch (state) { case JAVA: // The current character is always emitted. - switch(thisChar) { - case '\'': state = IN_CHAR_CONST; break; - case '"' : state = IN_STR_CONST; break; - case '/' : state = TRANS_TO_COMMENT; break; + switch (thisChar) { + case '\'': + state = IN_CHAR_CONST; + break; + case '"': + state = IN_STR_CONST; + break; + case '/': + state = TRANS_TO_COMMENT; + break; } break; case IN_CHAR_CONST: switch (thisChar) { - case '\'': state = JAVA; break; + case '\'': + state = JAVA; + break; } break; case IN_STR_CONST: switch (thisChar) { - case '"' : state = JAVA; break; + case '"': + state = JAVA; + break; } break; case IN_SINGLE_COMMENT: @@ -513,23 +556,36 @@ public final class FixCrLfFilter case IN_MULTI_COMMENT: // The current character is always emitted. switch (thisChar) { - case '*': state = TRANS_FROM_MULTI; break; + case '*': + state = TRANS_FROM_MULTI; + break; } break; case TRANS_TO_COMMENT: // The current character is always emitted. switch (thisChar) { - case '*' : state = IN_MULTI_COMMENT; break; - case '/' : state = IN_SINGLE_COMMENT; break; - case '\'': state = IN_CHAR_CONST; break; - case '"' : state = IN_STR_CONST; break; - default : state = JAVA; + case '*': + state = IN_MULTI_COMMENT; + break; + case '/': + state = IN_SINGLE_COMMENT; + break; + case '\'': + state = IN_CHAR_CONST; + break; + case '"': + state = IN_STR_CONST; + break; + default: + state = JAVA; } break; case TRANS_FROM_MULTI: // The current character is always emitted. switch (thisChar) { - case '/': state = JAVA; break; + case '/': + state = JAVA; + break; } break; } @@ -539,8 +595,11 @@ public final class FixCrLfFilter private static class NormalizeEolFilter extends SimpleFilterReader { boolean previousWasEOL; + boolean fixLast; + int normalizedEOL = 0; + char[] eol = null; public NormalizeEolFilter(Reader in, String eolString, boolean fixLast) { @@ -586,7 +645,8 @@ public final class FixCrLfFilter if (c1 == '\r' && c2 == '\n') { // EOL was "\r\r\n" } else if (c1 == '\r') { - // EOL was "\r\r" - handle as two consecutive "\r" and "\r" + // EOL was "\r\r" - handle as two consecutive "\r" and + // "\r" numEOL = 2; push(c2); } else if (c1 == '\n') { @@ -643,7 +703,7 @@ public final class FixCrLfFilter public RemoveEofFilter(Reader in) { super(in); - + try { lookAhead = in.read(); } catch (IOException e) { @@ -667,7 +727,8 @@ public final class FixCrLfFilter private static class AddTabFilter extends SimpleFilterReader { int columnNumber = 0; - int tabLength = 0; + + int tabLength = 0; public AddTabFilter(Reader in, int tabLength) { super(in); @@ -689,8 +750,7 @@ public final class FixCrLfFilter int countSpaces = 1; int numTabs = 0; - scanWhitespace: - while ((c = super.read()) != -1) { + scanWhitespace: while ((c = super.read()) != -1) { switch (c) { case ' ': if (++columnNumber == colNextTab) { @@ -722,8 +782,12 @@ public final class FixCrLfFilter } c = super.read(); switch (c) { - case ' ': columnNumber ++; break; - case '\t': columnNumber += tabLength; break; + case ' ': + columnNumber++; + break; + case '\t': + columnNumber += tabLength; + break; } } break; @@ -739,11 +803,12 @@ public final class FixCrLfFilter private static class RemoveTabFilter extends SimpleFilterReader { int columnNumber = 0; + int tabLength = 0; public RemoveTabFilter(Reader in, int tabLength) { super(in); - + this.tabLength = tabLength; } @@ -759,7 +824,7 @@ public final class FixCrLfFilter int width = tabLength - columnNumber % tabLength; if (!editsBlocked()) { - for (;width > 1; width--) { + for (; width > 1; width--) { push(' '); } c = ' '; @@ -777,17 +842,19 @@ public final class FixCrLfFilter * Enumerated attribute with the values "asis", "add" and "remove". */ public static class AddAsisRemove extends EnumeratedAttribute { - private static final AddAsisRemove ASIS = newInstance("asis"); - private static final AddAsisRemove ADD = newInstance("add"); + private static final AddAsisRemove ASIS = newInstance("asis"); + + private static final AddAsisRemove ADD = newInstance("add"); + private static final AddAsisRemove REMOVE = newInstance("remove"); public String[] getValues() { - return new String[] {"add", "asis", "remove"}; + return new String[] { "add", "asis", "remove" }; } public boolean equals(Object other) { return other instanceof AddAsisRemove - && getIndex() == ((AddAsisRemove) other).getIndex(); + && getIndex() == ((AddAsisRemove) other).getIndex(); } AddAsisRemove resolve() throws IllegalStateException { @@ -820,24 +887,28 @@ public final class FixCrLfFilter */ public static class CrLf extends EnumeratedAttribute { private static final CrLf ASIS = newInstance("asis"); - private static final CrLf CR = newInstance("cr"); + + private static final CrLf CR = newInstance("cr"); + private static final CrLf CRLF = newInstance("crlf"); - private static final CrLf DOS = newInstance("dos"); - private static final CrLf LF = newInstance("lf"); - private static final CrLf MAC = newInstance("mac"); + + private static final CrLf DOS = newInstance("dos"); + + private static final CrLf LF = newInstance("lf"); + + private static final CrLf MAC = newInstance("mac"); + private static final CrLf UNIX = newInstance("unix"); /** * @see EnumeratedAttribute#getValues */ public String[] getValues() { - return new String[] {"asis", "cr", "lf", "crlf", - "mac", "unix", "dos"}; + return new String[] {"asis", "cr", "lf", "crlf", "mac", "unix", "dos"}; } public boolean equals(Object other) { - return other instanceof CrLf - && getIndex() == ((CrLf) other).getIndex(); + return other instanceof CrLf && getIndex() == ((CrLf) other).getIndex(); } CrLf resolve() { diff --git a/src/main/org/apache/tools/ant/taskdefs/CopyPath.java b/src/main/org/apache/tools/ant/taskdefs/CopyPath.java index 85b0beee5..f5b90c14b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/CopyPath.java +++ b/src/main/org/apache/tools/ant/taskdefs/CopyPath.java @@ -1,5 +1,5 @@ /* - * Copyright 2005 The Apache Software Foundation + * Copyright 2005-2006 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ * */ - package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.BuildException; @@ -26,14 +25,14 @@ import org.apache.tools.ant.util.FileNameMapper; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; - import java.io.File; import java.io.IOException; /** * Copy the contents of a path to a destination, using the mapper of choice + * * @since Ant 1.7 - * + * * @ant.task category="filesystem" */ @@ -44,10 +43,12 @@ public class CopyPath extends Task { private Path path; private File destDir; + protected FileUtils fileUtils; - - //TODO not read, yet in a public setter + + // TODO not read, yet in a public setter private long granularity = 0; + protected boolean preserveLastModified = false; public CopyPath() { @@ -56,7 +57,9 @@ public class CopyPath extends Task { } public static final String ERROR_NO_DESTDIR = "No destDir specified"; + public static final String ERROR_NO_PATH = "No path specified"; + public static final String ERROR_NO_MAPPER = "No mapper specified"; public void setDestDir(File destDir) { @@ -65,20 +68,21 @@ public class CopyPath extends Task { /** * add a mapper + * * @param newmapper */ public void add(FileNameMapper newmapper) { - if(mapper!=null) { + if (mapper != null) { throw new BuildException("Only one mapper allowed"); } - mapper=newmapper; + mapper = newmapper; } - /** * Set the path to be used when running the Java class. - * - * @param s an Ant Path object containing the path. + * + * @param s + * an Ant Path object containing the path. */ public void setPath(Path s) { createPath().append(s); @@ -86,8 +90,9 @@ public class CopyPath extends Task { /** * Set the path to use by reference. - * - * @param r a reference to an existing path. + * + * @param r + * a reference to an existing path. */ public void setPathRef(Reference r) { createPath().setRefid(r); @@ -95,7 +100,7 @@ public class CopyPath extends Task { /** * Create a path. - * + * * @return a path to be configured. */ public Path createPath() { @@ -116,25 +121,27 @@ public class CopyPath extends Task { /** * Ensure we have a consistent and legal set of attributes, and set any * internal flags necessary based on different combinations of attributes. - * - * @throws BuildException if an error occurs. + * + * @throws BuildException + * if an error occurs. */ protected void validateAttributes() throws BuildException { - if(destDir==null) { + if (destDir == null) { throw new BuildException(ERROR_NO_DESTDIR); } - if(mapper==null) { + if (mapper == null) { throw new BuildException(ERROR_NO_MAPPER); } - if(path==null) { + if (path == null) { throw new BuildException(ERROR_NO_PATH); } } /** * This is a very minimal derivative of the nomal copy logic. - * - * @throws BuildException if something goes wrong with the build. + * + * @throws BuildException + * if something goes wrong with the build. */ public void execute() throws BuildException { validateAttributes(); @@ -147,46 +154,35 @@ public class CopyPath extends Task { for (int sources = 0; sources < sourceFiles.length; sources++) { String sourceFileName = sourceFiles[sources]; - File sourceFile=new File(sourceFileName); + File sourceFile = new File(sourceFileName); String[] toFiles = (String[]) mapper.mapFileName(sourceFileName); for (int i = 0; i < toFiles.length; i++) { String destFileName = toFiles[i]; - File destFile=new File(destDir,destFileName); + File destFile = new File(destDir, destFileName); - - if (sourceFile.equals(destFile)) { - log("Skipping self-copy of " + sourceFileName, - Project.MSG_VERBOSE); + log("Skipping self-copy of " + sourceFileName, Project.MSG_VERBOSE); continue; } - if(sourceFile.isDirectory()) { + if (sourceFile.isDirectory()) { log("Skipping directory " + sourceFileName); continue; } try { - log("Copying " + sourceFile + " to " + destFile, - Project.MSG_VERBOSE); + log("Copying " + sourceFile + " to " + destFile, Project.MSG_VERBOSE); - fileUtils.copyFile(sourceFile, destFile, null, - null, false, - preserveLastModified, null, - null, getProject()); + fileUtils.copyFile(sourceFile, destFile, null, null, false, + preserveLastModified, null, null, getProject()); } catch (IOException ioe) { - String msg = "Failed to copy " - + sourceFile - + " to " - + destFile - + " due to " + ioe.getMessage(); + String msg = "Failed to copy " + sourceFile + " to " + destFile + " due to " + + ioe.getMessage(); if (destFile.exists() && !destFile.delete()) { msg += " and I couldn't delete the corrupt " + destFile; } throw new BuildException(msg, ioe, getLocation()); } } - } - } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/SchemaValidate.java b/src/main/org/apache/tools/ant/taskdefs/optional/SchemaValidate.java index ad848d826..5c17ba9dc 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/SchemaValidate.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/SchemaValidate.java @@ -1,5 +1,5 @@ /* - * Copyright 2005 The Apache Software Foundation + * Copyright 2006 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,6 @@ import java.util.HashMap; import java.io.File; import java.net.MalformedURLException; - /** * Validate XML Schema documents. * This task validates XML schema documents. It requires an XML parser @@ -50,15 +49,15 @@ import java.net.MalformedURLException; public class SchemaValidate extends XMLValidateTask { /** map of all declared schemas; we catch and complain about redefinitions */ - private HashMap schemaLocations= new HashMap(); + private HashMap schemaLocations = new HashMap(); /** full checking of a schema */ - private boolean fullChecking=true; + private boolean fullChecking = true; /** * flag to disable DTD support. Best left enabled. */ - private boolean disableDTD=false; + private boolean disableDTD = false; /** * default URL for nonamespace schemas @@ -66,12 +65,15 @@ public class SchemaValidate extends XMLValidateTask { private SchemaLocation anonymousSchema; public static final String ERROR_SAX_1 = "SAX1 parsers are not supported"; - public static final String ERROR_NO_XSD_SUPPORT = - "Parser does not support Xerces or JAXP schema features"; - public static final String ERROR_TOO_MANY_DEFAULT_SCHEMAS = - "Only one of defaultSchemaFile and defaultSchemaURL allowed"; + + public static final String ERROR_NO_XSD_SUPPORT = "Parser does not support Xerces or JAXP schema features"; + + public static final String ERROR_TOO_MANY_DEFAULT_SCHEMAS = "Only one of defaultSchemaFile and defaultSchemaURL allowed"; + public static final String ERROR_PARSER_CREATION_FAILURE = "Could not create parser"; + public static final String MESSAGE_ADDING_SCHEMA = "Adding schema "; + public static final String ERROR_DUPLICATE_SCHEMA = "Duplicate declaration of schema "; /** @@ -92,12 +94,11 @@ public class SchemaValidate extends XMLValidateTask { */ public boolean enableXercesSchemaValidation() { try { - setFeature(XmlConstants.FEATURE_XSD,true); + setFeature(XmlConstants.FEATURE_XSD, true); //set the schema source for the doc - setNoNamespaceSchemaProperty( - XmlConstants.PROPERTY_NO_NAMESPACE_SCHEMA_LOCATION); + setNoNamespaceSchemaProperty(XmlConstants.PROPERTY_NO_NAMESPACE_SCHEMA_LOCATION); } catch (BuildException e) { - log(e.toString(),Project.MSG_VERBOSE); + log(e.toString(), Project.MSG_VERBOSE); return false; } return true; @@ -110,8 +111,7 @@ public class SchemaValidate extends XMLValidateTask { private void setNoNamespaceSchemaProperty(String property) { String anonSchema = getNoNamespaceSchemaURL(); if (anonSchema != null) { - setProperty(property, - anonSchema); + setProperty(property, anonSchema); } } @@ -124,11 +124,9 @@ public class SchemaValidate extends XMLValidateTask { public boolean enableJAXP12SchemaValidation() { try { //enable XSD - setProperty(XmlConstants.FEATURE_JAXP12_SCHEMA_LANGUAGE, - XmlConstants.URI_XSD); + setProperty(XmlConstants.FEATURE_JAXP12_SCHEMA_LANGUAGE, XmlConstants.URI_XSD); //set the schema source for the doc - setNoNamespaceSchemaProperty( - XmlConstants.FEATURE_JAXP12_SCHEMA_SOURCE); + setNoNamespaceSchemaProperty(XmlConstants.FEATURE_JAXP12_SCHEMA_SOURCE); } catch (BuildException e) { log(e.toString(), Project.MSG_VERBOSE); return false; @@ -143,12 +141,11 @@ public class SchemaValidate extends XMLValidateTask { * is a declaration of this schema with a different value */ public void addConfiguredSchema(SchemaLocation location) { - log("adding schema "+location,Project.MSG_DEBUG); + log("adding schema " + location, Project.MSG_DEBUG); location.validateNamespace(); - SchemaLocation old=(SchemaLocation) schemaLocations.get( - location.getNamespace()); - if(old!=null && !old.equals(location)) { - throw new BuildException(ERROR_DUPLICATE_SCHEMA+location); + SchemaLocation old = (SchemaLocation) schemaLocations.get(location.getNamespace()); + if (old != null && !old.equals(location)) { + throw new BuildException(ERROR_DUPLICATE_SCHEMA + location); } schemaLocations.put(location.getNamespace(), location); } @@ -161,17 +158,17 @@ public class SchemaValidate extends XMLValidateTask { this.fullChecking = fullChecking; } - /** * create a schema location to hold the anonymous * schema */ protected void createAnonymousSchema() { - if(anonymousSchema==null) { - anonymousSchema=new SchemaLocation(); + if (anonymousSchema == null) { + anonymousSchema = new SchemaLocation(); } anonymousSchema.setNamespace("(no namespace)"); } + /** * identify the URL of the default schema * @param defaultSchemaURL @@ -207,24 +204,24 @@ public class SchemaValidate extends XMLValidateTask { protected void initValidator() { super.initValidator(); //validate the parser type - if(isSax1Parser()) { + if (isSax1Parser()) { throw new BuildException(ERROR_SAX_1); } //enable schema - //setFeature(XmlConstants.FEATURE_VALIDATION,false); - setFeature(XmlConstants.FEATURE_NAMESPACES,true); - if(!enableXercesSchemaValidation() && - !enableJAXP12SchemaValidation()) { + //setFeature(XmlConstants.FEATURE_VALIDATION, false); + setFeature(XmlConstants.FEATURE_NAMESPACES, true); + if (!enableXercesSchemaValidation() && !enableJAXP12SchemaValidation()) { //couldnt use the xerces or jaxp calls throw new BuildException(ERROR_NO_XSD_SUPPORT); } //enable schema checking - setFeature(XmlConstants.FEATURE_XSD_FULL_VALIDATION,fullChecking); + setFeature(XmlConstants.FEATURE_XSD_FULL_VALIDATION, fullChecking); //turn off DTDs if desired - setFeatureIfSupported(XmlConstants.FEATURE_DISALLOW_DTD,disableDTD); + setFeatureIfSupported(XmlConstants.FEATURE_DISALLOW_DTD, disableDTD); + //schema declarations go in next addSchemaLocations(); } @@ -244,7 +241,7 @@ public class SchemaValidate extends XMLValidateTask { SAXParser saxParser = factory.newSAXParser(); reader = saxParser.getXMLReader(); } catch (ParserConfigurationException e) { - throw new BuildException(ERROR_PARSER_CREATION_FAILURE,e); + throw new BuildException(ERROR_PARSER_CREATION_FAILURE, e); } catch (SAXException e) { throw new BuildException(ERROR_PARSER_CREATION_FAILURE, e); } @@ -266,7 +263,7 @@ public class SchemaValidate extends XMLValidateTask { SchemaLocation schemaLocation = (SchemaLocation) it.next(); String tuple = schemaLocation.getURIandLocation(); buffer.append(tuple); - log("Adding schema "+tuple,Project.MSG_VERBOSE); + log("Adding schema " + tuple, Project.MSG_VERBOSE); count++; } if (count > 0) { @@ -280,7 +277,7 @@ public class SchemaValidate extends XMLValidateTask { * @return */ protected String getNoNamespaceSchemaURL() { - if(anonymousSchema==null) { + if (anonymousSchema == null) { return null; } else { return anonymousSchema.getSchemaLocationURL(); @@ -293,11 +290,11 @@ public class SchemaValidate extends XMLValidateTask { * @param feature * @param value */ - protected void setFeatureIfSupported(String feature,boolean value) { + protected void setFeatureIfSupported(String feature, boolean value) { try { getXmlReader().setFeature(feature, value); } catch (SAXNotRecognizedException e) { - log("Not recognizied: "+feature,Project.MSG_VERBOSE); + log("Not recognizied: " + feature, Project.MSG_VERBOSE); } catch (SAXNotSupportedException e) { log("Not supported: " + feature, Project.MSG_VERBOSE); } @@ -309,7 +306,7 @@ public class SchemaValidate extends XMLValidateTask { * @param fileProcessed number of files processed. */ protected void onSuccessfulValidation(int fileProcessed) { - log(fileProcessed + MESSAGE_FILES_VALIDATED,Project.MSG_VERBOSE); + log(fileProcessed + MESSAGE_FILES_VALIDATED, Project.MSG_VERBOSE); } /** @@ -318,20 +315,24 @@ public class SchemaValidate extends XMLValidateTask { */ public static class SchemaLocation { private String namespace; + private File file; + private String url; public static final String ERROR_NO_URI = "No namespace URI"; - public static final String ERROR_TWO_LOCATIONS = - "Both URL and File were given for schema "; + + public static final String ERROR_TWO_LOCATIONS = "Both URL and File were given for schema "; + public static final String ERROR_NO_FILE = "File not found: "; + public static final String ERROR_NO_URL_REPRESENTATION = "Cannot make a URL of "; + public static final String ERROR_NO_LOCATION = "No file or URL supplied for the schema "; public SchemaLocation() { } - public String getNamespace() { return namespace; } @@ -378,9 +379,8 @@ public class SchemaValidate extends XMLValidateTask { boolean hasFile = file != null; boolean hasURL = isSet(url); //error if both are empty, or both are set - if(!hasFile && !hasURL) { - throw new BuildException( - ERROR_NO_LOCATION+namespace); + if (!hasFile && !hasURL) { + throw new BuildException(ERROR_NO_LOCATION + namespace); } if (hasFile && hasURL) { throw new BuildException(ERROR_TWO_LOCATIONS + namespace); @@ -392,11 +392,10 @@ public class SchemaValidate extends XMLValidateTask { } try { - schema = - FileUtils.getFileUtils().getFileURL(file).toString(); + schema = FileUtils.getFileUtils().getFileURL(file).toString(); } catch (MalformedURLException e) { //this is almost implausible, but required handling - throw new BuildException(ERROR_NO_URL_REPRESENTATION + file,e); + throw new BuildException(ERROR_NO_URL_REPRESENTATION + file, e); } } return schema; @@ -452,19 +451,14 @@ public class SchemaValidate extends XMLValidateTask { final SchemaLocation schemaLocation = (SchemaLocation) o; - if (file != null ? - !file.equals(schemaLocation.file) : - schemaLocation.file != null) { + if (file != null ? !file.equals(schemaLocation.file) : schemaLocation.file != null) { return false; } - if (namespace != null ? - !namespace.equals(schemaLocation.namespace) : - schemaLocation.namespace != null) { + if (namespace != null ? !namespace.equals(schemaLocation.namespace) + : schemaLocation.namespace != null) { return false; } - if (url != null ? - !url.equals(schemaLocation.url) : - schemaLocation.url != null) { + if (url != null ? !url.equals(schemaLocation.url) : schemaLocation.url != null) { return false; } @@ -489,12 +483,12 @@ public class SchemaValidate extends XMLValidateTask { * @return a string representation of the object. */ public String toString() { - StringBuffer buffer=new StringBuffer(); - buffer.append(namespace!=null?namespace:"(anonymous)"); + StringBuffer buffer = new StringBuffer(); + buffer.append(namespace != null ? namespace : "(anonymous)"); buffer.append(' '); - buffer.append(url!=null?(url+" "):""); - buffer.append(file!=null?file.getAbsolutePath():""); + buffer.append(url != null ? (url + " ") : ""); + buffer.append(file != null ? file.getAbsolutePath() : ""); return buffer.toString(); } } //SchemaLocation -} +} \ No newline at end of file diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetResource.java b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetResource.java index e103beb4b..7a7d4b5ed 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetResource.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2005 The Apache Software Foundation + * Copyright 2000-2006 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,13 +25,11 @@ import java.util.Iterator; import org.apache.tools.ant.*; /** - * class used by DotnetCompile to name resources, could be upgraded to a datatype - * in the distant future. - * a resource maps to /res:file,name + * class used by DotnetCompile to name resources, could be upgraded to a + * datatype in the distant future. a resource maps to /res:file,name */ public class DotnetResource { - /** * name of resource */ @@ -55,7 +53,7 @@ public class DotnetResource { /** * A list of filesets with resources. */ - private ArrayList fileSets=new ArrayList(); + private ArrayList fileSets = new ArrayList(); /** * a namespace to be used with @@ -68,6 +66,7 @@ public class DotnetResource { /** * embed the resource in the assembly (default, true) or just link to it. + * * @param embed */ public void setEmbed(boolean embed) { @@ -80,6 +79,7 @@ public class DotnetResource { /** * name the resource + * * @param file */ public void setFile(File file) { @@ -92,6 +92,7 @@ public class DotnetResource { /** * VB and J# only: is a resource public or not? + * * @param aPublic */ public void setPublic(Boolean aPublic) { @@ -104,6 +105,7 @@ public class DotnetResource { /** * should the resource have a name? + * * @param name */ public void setName(String name) { @@ -112,6 +114,7 @@ public class DotnetResource { /** * Filesets root namespace. The value always ends with '.' . + * * @return String namespace name */ public String getNamespace() { @@ -120,76 +123,83 @@ public class DotnetResource { /** * Sets filesets root namespace. - * @param namespace String root namespace + * + * @param namespace + * String root namespace */ public void setNamespace(String namespace) { - if (namespace==null) this.namespace=null; - else this.namespace=(namespace.length()==0 || namespace.endsWith(".") ? namespace : namespace+'.'); + if (namespace == null) { + this.namespace = null; + } else { + this.namespace = (namespace.length() == 0 || namespace.endsWith(".") ? namespace + : namespace + '.'); + } } private void checkParameters() { if (hasFilesets()) { - if (getName()!=null) throw new BuildException( - "Cannot use attribute with filesets"); - if (getFile()!=null) throw new BuildException( - "Cannot use attribute with filesets"); - } - else { - if (getNamespace()!=null) throw new BuildException( - "Cannot use attribute without filesets"); + if (getName() != null) + throw new BuildException( + "Cannot use attribute with filesets"); + if (getFile() != null) + throw new BuildException( + "Cannot use attribute with filesets"); + } else { + if (getNamespace() != null) + throw new BuildException( + "Cannot use attribute without filesets"); } } + /** * build the C# style parameter (which has no public/private option) + * * @return the built C# style parameter */ public void getParameters(Project p, NetCommand command, boolean csharpStyle) { checkParameters(); if (hasFilesets()) { - for (Iterator listIter=fileSets.iterator(); listIter.hasNext();) { - FileSet fs=(FileSet)listIter.next();; - String baseDirectory=fs.getDir(p).toString(); - String namespace=getNamespace(); // ends with '.' or null + for (Iterator listIter = fileSets.iterator(); listIter.hasNext();) { + FileSet fs = (FileSet) listIter.next(); + ; + String baseDirectory = fs.getDir(p).toString(); + String namespace = getNamespace(); // ends with '.' or null DirectoryScanner ds = fs.getDirectoryScanner(p); String[] files = ds.getIncludedFiles(); - for (int i=0; i node has embedded + * * @return boolean */ public boolean hasFilesets() { - return fileSets.size()>0; + return fileSets.size() > 0; } -} +} \ No newline at end of file diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/vss/MSVSS.java b/src/main/org/apache/tools/ant/taskdefs/optional/vss/MSVSS.java index 898f1b336..613d81c22 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/vss/MSVSS.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/vss/MSVSS.java @@ -323,23 +323,25 @@ public abstract class MSVSS extends Task implements MSVSSConstants { * @return An empty string if label is not set. */ protected String getLabel() { - String shortLabel=""; + String shortLabel = ""; if (label != null && label.length() > 0) { shortLabel = FLAG_LABEL + getShortLabel(); - } + } return shortLabel; } /** - * Return at most the 30 first chars of the label, logging a warning message about the truncation + * Return at most the 30 first chars of the label, + * logging a warning message about the truncation * @return at most the 30 first chars of the label */ private String getShortLabel() { - String shortLabel; + String shortLabel; if (label != null && label.length() > 31) { - shortLabel = this.label.substring(0, 30); - log("Label is longer than 31 characters, truncated to: " + shortLabel, Project.MSG_WARN); + shortLabel = this.label.substring(0, 30); + log("Label is longer than 31 characters, truncated to: " + shortLabel, + Project.MSG_WARN); } else { - shortLabel = label; + shortLabel = label; } return shortLabel; } @@ -357,17 +359,17 @@ public abstract class MSVSS extends Task implements MSVSSConstants { * @return An empty string if a version, date and label are not set. */ protected String getVersionDateLabel() { - String versionDateLabel = ""; + String versionDateLabel = ""; if (version != null) { - versionDateLabel = FLAG_VERSION + version; + versionDateLabel = FLAG_VERSION + version; } else if (date != null) { - versionDateLabel = FLAG_VERSION_DATE + date; + versionDateLabel = FLAG_VERSION_DATE + date; } else { // Use getShortLabel() so labels longer then 30 char are truncated // and the user is warned String shortLabel = getShortLabel(); if (shortLabel != null && !shortLabel.equals("")) { - versionDateLabel = FLAG_VERSION_LABEL + shortLabel; + versionDateLabel = FLAG_VERSION_LABEL + shortLabel; } } return versionDateLabel; @@ -387,9 +389,9 @@ public abstract class MSVSS extends Task implements MSVSSConstants { * @return An empty string if localpath is not set. */ protected String getLocalpath() { - String lclPath = ""; //set to empty str if no local path return - if (localPath != null) { - //make sure m_LocalDir exists, create it if it doesn't + String lclPath = ""; //set to empty str if no local path return + if (localPath != null) { + //make sure m_LocalDir exists, create it if it doesn't File dir = getProject().resolveFile(localPath); if (!dir.exists()) { boolean done = dir.mkdirs(); @@ -401,7 +403,7 @@ public abstract class MSVSS extends Task implements MSVSSConstants { getProject().log("Created dir: " + dir.getAbsolutePath()); } lclPath = FLAG_OVERRIDE_WORKING_DIR + localPath; - } + } return lclPath; }