Browse Source

Checkstyle

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@394274 13f79535-47bb-0310-9956-ffa450edef68
master
Jan Materne 19 years ago
parent
commit
86334b78a7
5 changed files with 390 additions and 314 deletions
  1. +220
    -149
      src/main/org/apache/tools/ant/filters/FixCrLfFilter.java
  2. +37
    -41
      src/main/org/apache/tools/ant/taskdefs/CopyPath.java
  3. +57
    -63
      src/main/org/apache/tools/ant/taskdefs/optional/SchemaValidate.java
  4. +59
    -46
      src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetResource.java
  5. +17
    -15
      src/main/org/apache/tools/ant/taskdefs/optional/vss/MSVSS.java

+ 220
- 149
src/main/org/apache/tools/ant/filters/FixCrLfFilter.java View File

@@ -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.
* <p>
* This filter can take the following arguments:
* <ul>
@@ -38,42 +37,52 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
* </ul>
* None of which are required.
* <p>
* 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.
* <p>
* <em>Caution:</em> run with care on carefully formatted files. This may
* <em>Caution:</em> 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.
*
* <P>Example:
* <pre>&lt;<fixcrlf tab=&quot;add&quot; eol=&quot;crlf&quot; eof=&quot;asis&quot;/&gt;</pre>
* <P>
* Example:
*
* <pre>
* &lt;&lt;fixcrlf tab=&quot;add&quot; eol=&quot;crlf&quot; eof=&quot;asis&quot;/&gt;
* </pre>
*
* Or:
*
* <pre>&lt;filterreader classname=&quot;org.apache.tools.ant.filters.FixCrLfFilter&quot;&gt;
* &lt;param eol=&quot;crlf&quot; tab=&quot;asis&quot;/&gt;
* &lt;/filterreader&gt;</pre>
* <pre>
* &lt;filterreader classname=&quot;org.apache.tools.ant.filters.FixCrLfFilter&quot;&gt;
* &lt;param eol=&quot;crlf&quot; tab=&quot;asis&quot;/&gt;
* &lt;/filterreader&gt;
* </pre>
*
*/
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 <code>null</code>.
* @param in
* A Reader object providing the underlying stream. Must not be
* <code>null</code>.
*/
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 <code>null</code>.
* @param rdr
* A Reader object providing the underlying stream. Must not be
* <code>null</code>.
*
* @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:
* <ul>
* <li>add: ensure that there is an eof at the end of the file
* <li>asis: leave eof characters alone
* <li>remove: remove any eof character found at the end
* </ul>
* <ul>
* <li>add: ensure that there is an eof at the end of the file
* <li>asis: leave eof characters alone
* <li>remove: remove any eof character found at the end
* </ul>
*/
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:
* <ul>
* <li>asis: convert line endings to your O/S convention
* <li>cr: convert line endings to CR
* <li>lf: convert line endings to LF
* <li>crlf: convert line endings to CRLF
* </ul>
* <ul>
* <li>asis: convert line endings to your O/S convention
* <li>cr: convert line endings to CR
* <li>lf: convert line endings to LF
* <li>crlf: convert line endings to CRLF
* </ul>
*/
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.
* <P>
* This attribute is only used in assocation with the
* &quot;<i><b>tab</b></i>&quot; attribute. Tabs found in Java literals
* are protected from changes by this filter.
* This attribute is only used in assocation with the &quot;<i><b>tab</b></i>&quot;
* 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:
* <ul>
* <li>add: convert sequences of spaces which span a tab stop to tabs
* <li>asis: leave tab and space characters alone
* <li>remove: convert tabs to spaces
* </ul>
* <ul>
* <li>add: convert sequences of spaces which span a tab stop to
* tabs
* <li>asis: leave tab and space characters alone
* <li>remove: convert tabs to spaces
* </ul>
*/
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:
* <ul>
* <li>add: ensure that there is an eof at the end of the file
* <li>asis: leave eof characters alone
* <li>remove: remove any eof character found at the end
* </ul>
* @param attr
* valid values:
* <ul>
* <li>add: ensure that there is an eof at the end of the file
* <li>asis: leave eof characters alone
* <li>remove: remove any eof character found at the end
* </ul>
*/
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:
* <ul>
* <li>asis: convert line endings to your O/S convention
* <li>cr: convert line endings to CR
* <li>lf: convert line endings to LF
* <li>crlf: convert line endings to CRLF
* </ul>
* @param attr
* valid values:
* <ul>
* <li>asis: convert line endings to your O/S convention
* <li>cr: convert line endings to CR
* <li>lf: convert line endings to LF
* <li>crlf: convert line endings to CRLF
* </ul>
*/
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
* &quot;<i><b>tab</b></i>&quot; 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 &quot;<i><b>tab</b></i>&quot;
* 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:
* <ul>
* <li>add: convert sequences of spaces which span a tab stop to tabs
* <li>asis: leave tab and space characters alone
* <li>remove: convert tabs to spaces
* </ul>
* @param attr
* valid values:
* <ul>
* <li>add: convert sequences of spaces which span a tab stop to
* tabs
* <li>asis: leave tab and space characters alone
* <li>remove: convert tabs to spaces
* </ul>
*/
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.
*
* <P>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.</P>
* <P>
* 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.
* </P>
*/
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() {


+ 37
- 41
src/main/org/apache/tools/ant/taskdefs/CopyPath.java View File

@@ -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());
}
}

}

}
}

+ 57
- 63
src/main/org/apache/tools/ant/taskdefs/optional/SchemaValidate.java View File

@@ -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
}
}

+ 59
- 46
src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetResource.java View File

@@ -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 <filesets>
@@ -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 <resource name=\"...\"> attribute with filesets");
if (getFile()!=null) throw new BuildException(
"Cannot use <resource file=\"...\"> attribute with filesets");
}
else {
if (getNamespace()!=null) throw new BuildException(
"Cannot use <resource namespace=\"...\"> attribute without filesets");
if (getName() != null)
throw new BuildException(
"Cannot use <resource name=\"...\"> attribute with filesets");
if (getFile() != null)
throw new BuildException(
"Cannot use <resource file=\"...\"> attribute with filesets");
} else {
if (getNamespace() != null)
throw new BuildException(
"Cannot use <resource namespace=\"...\"> 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<files.length; i++) {
String file=files[i];
command.addArgument(getParameter(baseDirectory+File.separatorChar+file, (namespace==null ? null : namespace+file.replace(File.separatorChar, '.')), csharpStyle));
for (int i = 0; i < files.length; i++) {
String file = files[i];
command.addArgument(getParameter(baseDirectory + File.separatorChar + file,
(namespace == null ? null : namespace
+ file.replace(File.separatorChar, '.')), csharpStyle));
}
}
}
else {
command.addArgument(getParameter(getFile().toString(), getName(),
csharpStyle));
} else {
command.addArgument(getParameter(getFile().toString(), getName(), csharpStyle));
}
}

private String getParameter(String fileName, String name, boolean csharpStyle) {
StringBuffer buffer=new StringBuffer();
buffer.append(isEmbed()?"/resource":"/linkresource");
StringBuffer buffer = new StringBuffer();
buffer.append(isEmbed() ? "/resource" : "/linkresource");
buffer.append(':');
buffer.append(fileName);
if (name!=null) {
if (name != null) {
buffer.append(',');
buffer.append(name);
if (csharpStyle) {
if (getPublic()!=null) {
throw new BuildException(
"This compiler does not support the "
+"public/private option.");
}
else {
if (getPublic()!=null) {
if (getPublic() != null) {
throw new BuildException("This compiler does not support the "
+ "public/private option.");
} else {
if (getPublic() != null) {
buffer.append(',');
buffer.append(getPublic().booleanValue()
?"public":"private");
buffer.append(getPublic().booleanValue() ? "public" : "private");

}
}
}
else if (getPublic()!=null) {
} else if (getPublic() != null) {
throw new BuildException("You cannot have a public or private "
+"option without naming the resource");
+ "option without naming the resource");
}
}
return buffer.toString();
@@ -197,7 +207,9 @@ public class DotnetResource {

/**
* Adds a resource file set.
* @param fileset FileSet
*
* @param fileset
* FileSet
*/
public void addFileset(FileSet fileset) {
fileSets.add(fileset);
@@ -205,9 +217,10 @@ public class DotnetResource {

/**
* Checks that <resource> node has embedded <filesets>
*
* @return boolean
*/
public boolean hasFilesets() {
return fileSets.size()>0;
return fileSets.size() > 0;
}
}
}

+ 17
- 15
src/main/org/apache/tools/ant/taskdefs/optional/vss/MSVSS.java View File

@@ -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;
}



Loading…
Cancel
Save