git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@394274 13f79535-47bb-0310-9956-ffa450edef68master
@@ -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"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with 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; | 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> | * <p> | ||||
* This filter can take the following arguments: | * This filter can take the following arguments: | ||||
* <ul> | * <ul> | ||||
@@ -38,42 +37,52 @@ import org.apache.tools.ant.types.EnumeratedAttribute; | |||||
* </ul> | * </ul> | ||||
* None of which are required. | * None of which are required. | ||||
* <p> | * <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> | * <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 | * 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><<fixcrlf tab="add" eol="crlf" eof="asis"/></pre> | |||||
* <P> | |||||
* Example: | |||||
* | |||||
* <pre> | |||||
* <<fixcrlf tab="add" eol="crlf" eof="asis"/> | |||||
* </pre> | |||||
* | * | ||||
* Or: | * Or: | ||||
* | * | ||||
* <pre><filterreader classname="org.apache.tools.ant.filters.FixCrLfFilter"> | |||||
* <param eol="crlf" tab="asis"/> | |||||
* </filterreader></pre> | |||||
* <pre> | |||||
* <filterreader classname="org.apache.tools.ant.filters.FixCrLfFilter"> | |||||
* <param eol="crlf" tab="asis"/> | |||||
* </filterreader> | |||||
* </pre> | |||||
* | * | ||||
*/ | */ | ||||
public final class FixCrLfFilter | |||||
extends BaseParamFilterReader | |||||
implements ChainableReader { | |||||
public final class FixCrLfFilter extends BaseParamFilterReader implements ChainableReader { | |||||
private static final char CTRLZ = '\u001A'; | private static final char CTRLZ = '\u001A'; | ||||
private int tabLength = 8; | private int tabLength = 8; | ||||
private CrLf eol; | private CrLf eol; | ||||
private AddAsisRemove ctrlz; | private AddAsisRemove ctrlz; | ||||
private AddAsisRemove tabs; | private AddAsisRemove tabs; | ||||
private boolean javafiles = false; | private boolean javafiles = false; | ||||
private boolean fixlast = true; | private boolean fixlast = true; | ||||
private boolean initialized = false; | private boolean initialized = false; | ||||
/** | /** | ||||
@@ -88,14 +97,16 @@ public final class FixCrLfFilter | |||||
/** | /** | ||||
* Create a new filtered reader. | * 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 { | public FixCrLfFilter(final Reader in) throws IOException { | ||||
super(in); | 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; | tabs = AddAsisRemove.ASIS; | ||||
if (Os.isFamily("mac")) { | 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) { | public final Reader chain(final Reader rdr) { | ||||
try { | try { | ||||
@@ -126,7 +137,7 @@ public final class FixCrLfFilter | |||||
newFilter.setJavafiles(getJavafiles()); | newFilter.setJavafiles(getJavafiles()); | ||||
newFilter.setEol(getEol()); | newFilter.setEol(getEol()); | ||||
newFilter.setTab(getTab()); | |||||
newFilter.setTab(getTab()); | |||||
newFilter.setTablength(getTablength()); | newFilter.setTablength(getTablength()); | ||||
newFilter.setEof(getEof()); | newFilter.setEof(getEof()); | ||||
newFilter.setFixlast(getFixlast()); | newFilter.setFixlast(getFixlast()); | ||||
@@ -142,14 +153,15 @@ public final class FixCrLfFilter | |||||
* Get how DOS EOF (control-z) characters are being handled. | * Get how DOS EOF (control-z) characters are being handled. | ||||
* | * | ||||
* @return values: | * @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() { | 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(); | return ctrlz.newInstance(); | ||||
} | } | ||||
@@ -157,15 +169,16 @@ public final class FixCrLfFilter | |||||
* Get how EndOfLine characters are being handled. | * Get how EndOfLine characters are being handled. | ||||
* | * | ||||
* @return values: | * @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() { | 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(); | 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> | * <P> | ||||
* This attribute is only used in assocation with the | |||||
* "<i><b>tab</b></i>" attribute. Tabs found in Java literals | |||||
* are protected from changes by this filter. | |||||
* This attribute is only used in assocation with the "<i><b>tab</b></i>" | |||||
* attribute. Tabs found in Java literals are protected from changes by this | |||||
* filter. | |||||
* | * | ||||
* @return true if whitespace in Java character and string literals is | * @return true if whitespace in Java character and string literals is | ||||
* ignored. | |||||
* ignored. | |||||
*/ | */ | ||||
public boolean getJavafiles() { | public boolean getJavafiles() { | ||||
return javafiles; | return javafiles; | ||||
@@ -196,14 +210,16 @@ public final class FixCrLfFilter | |||||
* Return how tab characters are being handled. | * Return how tab characters are being handled. | ||||
* | * | ||||
* @return values: | * @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() { | 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(); | return tabs.newInstance(); | ||||
} | } | ||||
@@ -212,7 +228,7 @@ public final class FixCrLfFilter | |||||
* | * | ||||
* @return the length of tab in spaces | * @return the length of tab in spaces | ||||
*/ | */ | ||||
public int getTablength(){ | |||||
public int getTablength() { | |||||
return tabLength; | return tabLength; | ||||
} | } | ||||
@@ -227,13 +243,13 @@ public final class FixCrLfFilter | |||||
if (eol == CrLf.CRLF || eol == CrLf.DOS) { | if (eol == CrLf.CRLF || eol == CrLf.DOS) { | ||||
return "\r\n"; | return "\r\n"; | ||||
} | } | ||||
//assume (eol == CrLf.LF || eol == CrLf.UNIX) | |||||
// assume (eol == CrLf.LF || eol == CrLf.UNIX) | |||||
return "\n"; | 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() { | private void initInternalFilters() { | ||||
@@ -241,7 +257,7 @@ public final class FixCrLfFilter | |||||
// filters don't see that character. | // filters don't see that character. | ||||
in = (ctrlz == AddAsisRemove.REMOVE) ? new RemoveEofFilter(in) : in; | 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 | // configured to do so, append a trailing EOL so that the file ends on | ||||
// a EOL. | // a EOL. | ||||
in = new NormalizeEolFilter(in, calculateEolString(eol), getFixlast()); | in = new NormalizeEolFilter(in, calculateEolString(eol), getFixlast()); | ||||
@@ -253,23 +269,23 @@ public final class FixCrLfFilter | |||||
in = new MaskJavaTabLiteralsFilter(in); | in = new MaskJavaTabLiteralsFilter(in); | ||||
} | } | ||||
// Add/Remove tabs | // 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 | // Add missing EOF character | ||||
in = (ctrlz == AddAsisRemove.ADD) ? new AddEofFilter(in) : in; | in = (ctrlz == AddAsisRemove.ADD) ? new AddEofFilter(in) : in; | ||||
initialized = true; | initialized = true; | ||||
} | |||||
} | |||||
/** | /** | ||||
* Return the next character in the filtered stream. | * 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 { | public synchronized final int read() throws IOException { | ||||
if (!initialized) { | if (!initialized) { | ||||
@@ -281,12 +297,13 @@ public final class FixCrLfFilter | |||||
/** | /** | ||||
* Specify how DOS EOF (control-z) characters are to be handled. | * 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) { | public void setEof(AddAsisRemove attr) { | ||||
ctrlz = attr.resolve(); | ctrlz = attr.resolve(); | ||||
@@ -295,23 +312,24 @@ public final class FixCrLfFilter | |||||
/** | /** | ||||
* Specify how end of line (EOL) characters are to be handled. | * 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) { | public void setEol(CrLf attr) { | ||||
eol = attr.resolve(); | 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) { | public void setFixlast(boolean fixlast) { | ||||
this.fixlast = fixlast; | this.fixlast = fixlast; | ||||
@@ -319,12 +337,13 @@ public final class FixCrLfFilter | |||||
/** | /** | ||||
* Indicate whether this stream contains Java source. | * Indicate whether this stream contains Java source. | ||||
* | |||||
* This attribute is only used in assocation with the | |||||
* "<i><b>tab</b></i>" 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 "<i><b>tab</b></i>" | |||||
* attribute. | |||||
* | |||||
* @param javafiles | |||||
* set to true to prevent this filter from changing tabs found in | |||||
* Java literals. | |||||
*/ | */ | ||||
public void setJavafiles(boolean javafiles) { | public void setJavafiles(boolean javafiles) { | ||||
this.javafiles = javafiles; | this.javafiles = javafiles; | ||||
@@ -333,12 +352,14 @@ public final class FixCrLfFilter | |||||
/** | /** | ||||
* Specify how tab characters are to be handled. | * 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) { | public void setTab(AddAsisRemove attr) { | ||||
tabs = attr.resolve(); | tabs = attr.resolve(); | ||||
@@ -347,9 +368,9 @@ public final class FixCrLfFilter | |||||
/** | /** | ||||
* Specify tab length in characters. | * 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 { | public void setTablength(int tabLength) throws IOException { | ||||
if (tabLength < 2 || tabLength > 80) { | 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 static class SimpleFilterReader extends Reader { | ||||
private Reader in; | private Reader in; | ||||
int[] preempt = new int[16]; | int[] preempt = new int[16]; | ||||
int preemptIndex = 0; | int preemptIndex = 0; | ||||
public SimpleFilterReader(Reader in) { | public SimpleFilterReader(Reader in) { | ||||
@@ -390,7 +417,7 @@ public final class FixCrLfFilter | |||||
public void push(char[] cs, int start, int length) { | public void push(char[] cs, int start, int length) { | ||||
for (int i = start + length - 1; i >= start;) { | 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() { | public boolean editsBlocked() { | ||||
return in instanceof SimpleFilterReader | |||||
&& ((SimpleFilterReader) in).editsBlocked(); | |||||
return in instanceof SimpleFilterReader && ((SimpleFilterReader) in).editsBlocked(); | |||||
} | } | ||||
public int read() throws java.io.IOException { | public int read() throws java.io.IOException { | ||||
@@ -458,13 +485,19 @@ public final class FixCrLfFilter | |||||
private static class MaskJavaTabLiteralsFilter extends SimpleFilterReader { | private static class MaskJavaTabLiteralsFilter extends SimpleFilterReader { | ||||
boolean editsBlocked = false; | 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_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; | private int state; | ||||
@@ -473,7 +506,7 @@ public final class FixCrLfFilter | |||||
state = JAVA; | state = JAVA; | ||||
} | } | ||||
public boolean editsBlocked () { | |||||
public boolean editsBlocked() { | |||||
return editsBlocked || super.editsBlocked(); | return editsBlocked || super.editsBlocked(); | ||||
} | } | ||||
@@ -485,20 +518,30 @@ public final class FixCrLfFilter | |||||
switch (state) { | switch (state) { | ||||
case JAVA: | case JAVA: | ||||
// The current character is always emitted. | // 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; | break; | ||||
case IN_CHAR_CONST: | case IN_CHAR_CONST: | ||||
switch (thisChar) { | switch (thisChar) { | ||||
case '\'': state = JAVA; break; | |||||
case '\'': | |||||
state = JAVA; | |||||
break; | |||||
} | } | ||||
break; | break; | ||||
case IN_STR_CONST: | case IN_STR_CONST: | ||||
switch (thisChar) { | switch (thisChar) { | ||||
case '"' : state = JAVA; break; | |||||
case '"': | |||||
state = JAVA; | |||||
break; | |||||
} | } | ||||
break; | break; | ||||
case IN_SINGLE_COMMENT: | case IN_SINGLE_COMMENT: | ||||
@@ -513,23 +556,36 @@ public final class FixCrLfFilter | |||||
case IN_MULTI_COMMENT: | case IN_MULTI_COMMENT: | ||||
// The current character is always emitted. | // The current character is always emitted. | ||||
switch (thisChar) { | switch (thisChar) { | ||||
case '*': state = TRANS_FROM_MULTI; break; | |||||
case '*': | |||||
state = TRANS_FROM_MULTI; | |||||
break; | |||||
} | } | ||||
break; | break; | ||||
case TRANS_TO_COMMENT: | case TRANS_TO_COMMENT: | ||||
// The current character is always emitted. | // The current character is always emitted. | ||||
switch (thisChar) { | 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; | break; | ||||
case TRANS_FROM_MULTI: | case TRANS_FROM_MULTI: | ||||
// The current character is always emitted. | // The current character is always emitted. | ||||
switch (thisChar) { | switch (thisChar) { | ||||
case '/': state = JAVA; break; | |||||
case '/': | |||||
state = JAVA; | |||||
break; | |||||
} | } | ||||
break; | break; | ||||
} | } | ||||
@@ -539,8 +595,11 @@ public final class FixCrLfFilter | |||||
private static class NormalizeEolFilter extends SimpleFilterReader { | private static class NormalizeEolFilter extends SimpleFilterReader { | ||||
boolean previousWasEOL; | boolean previousWasEOL; | ||||
boolean fixLast; | boolean fixLast; | ||||
int normalizedEOL = 0; | int normalizedEOL = 0; | ||||
char[] eol = null; | char[] eol = null; | ||||
public NormalizeEolFilter(Reader in, String eolString, boolean fixLast) { | public NormalizeEolFilter(Reader in, String eolString, boolean fixLast) { | ||||
@@ -586,7 +645,8 @@ public final class FixCrLfFilter | |||||
if (c1 == '\r' && c2 == '\n') { | if (c1 == '\r' && c2 == '\n') { | ||||
// EOL was "\r\r\n" | // EOL was "\r\r\n" | ||||
} else if (c1 == '\r') { | } 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; | numEOL = 2; | ||||
push(c2); | push(c2); | ||||
} else if (c1 == '\n') { | } else if (c1 == '\n') { | ||||
@@ -643,7 +703,7 @@ public final class FixCrLfFilter | |||||
public RemoveEofFilter(Reader in) { | public RemoveEofFilter(Reader in) { | ||||
super(in); | super(in); | ||||
try { | try { | ||||
lookAhead = in.read(); | lookAhead = in.read(); | ||||
} catch (IOException e) { | } catch (IOException e) { | ||||
@@ -667,7 +727,8 @@ public final class FixCrLfFilter | |||||
private static class AddTabFilter extends SimpleFilterReader { | private static class AddTabFilter extends SimpleFilterReader { | ||||
int columnNumber = 0; | int columnNumber = 0; | ||||
int tabLength = 0; | |||||
int tabLength = 0; | |||||
public AddTabFilter(Reader in, int tabLength) { | public AddTabFilter(Reader in, int tabLength) { | ||||
super(in); | super(in); | ||||
@@ -689,8 +750,7 @@ public final class FixCrLfFilter | |||||
int countSpaces = 1; | int countSpaces = 1; | ||||
int numTabs = 0; | int numTabs = 0; | ||||
scanWhitespace: | |||||
while ((c = super.read()) != -1) { | |||||
scanWhitespace: while ((c = super.read()) != -1) { | |||||
switch (c) { | switch (c) { | ||||
case ' ': | case ' ': | ||||
if (++columnNumber == colNextTab) { | if (++columnNumber == colNextTab) { | ||||
@@ -722,8 +782,12 @@ public final class FixCrLfFilter | |||||
} | } | ||||
c = super.read(); | c = super.read(); | ||||
switch (c) { | switch (c) { | ||||
case ' ': columnNumber ++; break; | |||||
case '\t': columnNumber += tabLength; break; | |||||
case ' ': | |||||
columnNumber++; | |||||
break; | |||||
case '\t': | |||||
columnNumber += tabLength; | |||||
break; | |||||
} | } | ||||
} | } | ||||
break; | break; | ||||
@@ -739,11 +803,12 @@ public final class FixCrLfFilter | |||||
private static class RemoveTabFilter extends SimpleFilterReader { | private static class RemoveTabFilter extends SimpleFilterReader { | ||||
int columnNumber = 0; | int columnNumber = 0; | ||||
int tabLength = 0; | int tabLength = 0; | ||||
public RemoveTabFilter(Reader in, int tabLength) { | public RemoveTabFilter(Reader in, int tabLength) { | ||||
super(in); | super(in); | ||||
this.tabLength = tabLength; | this.tabLength = tabLength; | ||||
} | } | ||||
@@ -759,7 +824,7 @@ public final class FixCrLfFilter | |||||
int width = tabLength - columnNumber % tabLength; | int width = tabLength - columnNumber % tabLength; | ||||
if (!editsBlocked()) { | if (!editsBlocked()) { | ||||
for (;width > 1; width--) { | |||||
for (; width > 1; width--) { | |||||
push(' '); | push(' '); | ||||
} | } | ||||
c = ' '; | c = ' '; | ||||
@@ -777,17 +842,19 @@ public final class FixCrLfFilter | |||||
* Enumerated attribute with the values "asis", "add" and "remove". | * Enumerated attribute with the values "asis", "add" and "remove". | ||||
*/ | */ | ||||
public static class AddAsisRemove extends EnumeratedAttribute { | 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"); | private static final AddAsisRemove REMOVE = newInstance("remove"); | ||||
public String[] getValues() { | public String[] getValues() { | ||||
return new String[] {"add", "asis", "remove"}; | |||||
return new String[] { "add", "asis", "remove" }; | |||||
} | } | ||||
public boolean equals(Object other) { | public boolean equals(Object other) { | ||||
return other instanceof AddAsisRemove | return other instanceof AddAsisRemove | ||||
&& getIndex() == ((AddAsisRemove) other).getIndex(); | |||||
&& getIndex() == ((AddAsisRemove) other).getIndex(); | |||||
} | } | ||||
AddAsisRemove resolve() throws IllegalStateException { | AddAsisRemove resolve() throws IllegalStateException { | ||||
@@ -820,24 +887,28 @@ public final class FixCrLfFilter | |||||
*/ | */ | ||||
public static class CrLf extends EnumeratedAttribute { | public static class CrLf extends EnumeratedAttribute { | ||||
private static final CrLf ASIS = newInstance("asis"); | 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 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"); | private static final CrLf UNIX = newInstance("unix"); | ||||
/** | /** | ||||
* @see EnumeratedAttribute#getValues | * @see EnumeratedAttribute#getValues | ||||
*/ | */ | ||||
public String[] 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) { | public boolean equals(Object other) { | ||||
return other instanceof CrLf | |||||
&& getIndex() == ((CrLf) other).getIndex(); | |||||
return other instanceof CrLf && getIndex() == ((CrLf) other).getIndex(); | |||||
} | } | ||||
CrLf resolve() { | CrLf resolve() { | ||||
@@ -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"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -15,7 +15,6 @@ | |||||
* | * | ||||
*/ | */ | ||||
package org.apache.tools.ant.taskdefs; | package org.apache.tools.ant.taskdefs; | ||||
import org.apache.tools.ant.BuildException; | 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.Path; | ||||
import org.apache.tools.ant.types.Reference; | import org.apache.tools.ant.types.Reference; | ||||
import java.io.File; | import java.io.File; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
/** | /** | ||||
* Copy the contents of a path to a destination, using the mapper of choice | * Copy the contents of a path to a destination, using the mapper of choice | ||||
* | |||||
* @since Ant 1.7 | * @since Ant 1.7 | ||||
* | |||||
* | |||||
* @ant.task category="filesystem" | * @ant.task category="filesystem" | ||||
*/ | */ | ||||
@@ -44,10 +43,12 @@ public class CopyPath extends Task { | |||||
private Path path; | private Path path; | ||||
private File destDir; | private File destDir; | ||||
protected FileUtils fileUtils; | protected FileUtils fileUtils; | ||||
//TODO not read, yet in a public setter | |||||
// TODO not read, yet in a public setter | |||||
private long granularity = 0; | private long granularity = 0; | ||||
protected boolean preserveLastModified = false; | protected boolean preserveLastModified = false; | ||||
public CopyPath() { | 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_DESTDIR = "No destDir specified"; | ||||
public static final String ERROR_NO_PATH = "No path specified"; | public static final String ERROR_NO_PATH = "No path specified"; | ||||
public static final String ERROR_NO_MAPPER = "No mapper specified"; | public static final String ERROR_NO_MAPPER = "No mapper specified"; | ||||
public void setDestDir(File destDir) { | public void setDestDir(File destDir) { | ||||
@@ -65,20 +68,21 @@ public class CopyPath extends Task { | |||||
/** | /** | ||||
* add a mapper | * add a mapper | ||||
* | |||||
* @param newmapper | * @param newmapper | ||||
*/ | */ | ||||
public void add(FileNameMapper newmapper) { | public void add(FileNameMapper newmapper) { | ||||
if(mapper!=null) { | |||||
if (mapper != null) { | |||||
throw new BuildException("Only one mapper allowed"); | throw new BuildException("Only one mapper allowed"); | ||||
} | } | ||||
mapper=newmapper; | |||||
mapper = newmapper; | |||||
} | } | ||||
/** | /** | ||||
* Set the path to be used when running the Java class. | * 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) { | public void setPath(Path s) { | ||||
createPath().append(s); | createPath().append(s); | ||||
@@ -86,8 +90,9 @@ public class CopyPath extends Task { | |||||
/** | /** | ||||
* Set the path to use by reference. | * 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) { | public void setPathRef(Reference r) { | ||||
createPath().setRefid(r); | createPath().setRefid(r); | ||||
@@ -95,7 +100,7 @@ public class CopyPath extends Task { | |||||
/** | /** | ||||
* Create a path. | * Create a path. | ||||
* | |||||
* | |||||
* @return a path to be configured. | * @return a path to be configured. | ||||
*/ | */ | ||||
public Path createPath() { | 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 | * Ensure we have a consistent and legal set of attributes, and set any | ||||
* internal flags necessary based on different combinations of attributes. | * 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 { | protected void validateAttributes() throws BuildException { | ||||
if(destDir==null) { | |||||
if (destDir == null) { | |||||
throw new BuildException(ERROR_NO_DESTDIR); | throw new BuildException(ERROR_NO_DESTDIR); | ||||
} | } | ||||
if(mapper==null) { | |||||
if (mapper == null) { | |||||
throw new BuildException(ERROR_NO_MAPPER); | throw new BuildException(ERROR_NO_MAPPER); | ||||
} | } | ||||
if(path==null) { | |||||
if (path == null) { | |||||
throw new BuildException(ERROR_NO_PATH); | throw new BuildException(ERROR_NO_PATH); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* This is a very minimal derivative of the nomal copy logic. | * 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 { | public void execute() throws BuildException { | ||||
validateAttributes(); | validateAttributes(); | ||||
@@ -147,46 +154,35 @@ public class CopyPath extends Task { | |||||
for (int sources = 0; sources < sourceFiles.length; sources++) { | for (int sources = 0; sources < sourceFiles.length; sources++) { | ||||
String sourceFileName = sourceFiles[sources]; | String sourceFileName = sourceFiles[sources]; | ||||
File sourceFile=new File(sourceFileName); | |||||
File sourceFile = new File(sourceFileName); | |||||
String[] toFiles = (String[]) mapper.mapFileName(sourceFileName); | String[] toFiles = (String[]) mapper.mapFileName(sourceFileName); | ||||
for (int i = 0; i < toFiles.length; i++) { | for (int i = 0; i < toFiles.length; i++) { | ||||
String destFileName = toFiles[i]; | String destFileName = toFiles[i]; | ||||
File destFile=new File(destDir,destFileName); | |||||
File destFile = new File(destDir, destFileName); | |||||
if (sourceFile.equals(destFile)) { | if (sourceFile.equals(destFile)) { | ||||
log("Skipping self-copy of " + sourceFileName, | |||||
Project.MSG_VERBOSE); | |||||
log("Skipping self-copy of " + sourceFileName, Project.MSG_VERBOSE); | |||||
continue; | continue; | ||||
} | } | ||||
if(sourceFile.isDirectory()) { | |||||
if (sourceFile.isDirectory()) { | |||||
log("Skipping directory " + sourceFileName); | log("Skipping directory " + sourceFileName); | ||||
continue; | continue; | ||||
} | } | ||||
try { | 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) { | } 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()) { | if (destFile.exists() && !destFile.delete()) { | ||||
msg += " and I couldn't delete the corrupt " + destFile; | msg += " and I couldn't delete the corrupt " + destFile; | ||||
} | } | ||||
throw new BuildException(msg, ioe, getLocation()); | throw new BuildException(msg, ioe, getLocation()); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } |
@@ -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"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with 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.io.File; | ||||
import java.net.MalformedURLException; | import java.net.MalformedURLException; | ||||
/** | /** | ||||
* Validate XML Schema documents. | * Validate XML Schema documents. | ||||
* This task validates XML schema documents. It requires an XML parser | * This task validates XML schema documents. It requires an XML parser | ||||
@@ -50,15 +49,15 @@ import java.net.MalformedURLException; | |||||
public class SchemaValidate extends XMLValidateTask { | public class SchemaValidate extends XMLValidateTask { | ||||
/** map of all declared schemas; we catch and complain about redefinitions */ | /** 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 */ | /** full checking of a schema */ | ||||
private boolean fullChecking=true; | |||||
private boolean fullChecking = true; | |||||
/** | /** | ||||
* flag to disable DTD support. Best left enabled. | * flag to disable DTD support. Best left enabled. | ||||
*/ | */ | ||||
private boolean disableDTD=false; | |||||
private boolean disableDTD = false; | |||||
/** | /** | ||||
* default URL for nonamespace schemas | * default URL for nonamespace schemas | ||||
@@ -66,12 +65,15 @@ public class SchemaValidate extends XMLValidateTask { | |||||
private SchemaLocation anonymousSchema; | private SchemaLocation anonymousSchema; | ||||
public static final String ERROR_SAX_1 = "SAX1 parsers are not supported"; | 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 ERROR_PARSER_CREATION_FAILURE = "Could not create parser"; | ||||
public static final String MESSAGE_ADDING_SCHEMA = "Adding schema "; | public static final String MESSAGE_ADDING_SCHEMA = "Adding schema "; | ||||
public static final String ERROR_DUPLICATE_SCHEMA = "Duplicate declaration of schema "; | public static final String ERROR_DUPLICATE_SCHEMA = "Duplicate declaration of schema "; | ||||
/** | /** | ||||
@@ -92,12 +94,11 @@ public class SchemaValidate extends XMLValidateTask { | |||||
*/ | */ | ||||
public boolean enableXercesSchemaValidation() { | public boolean enableXercesSchemaValidation() { | ||||
try { | try { | ||||
setFeature(XmlConstants.FEATURE_XSD,true); | |||||
setFeature(XmlConstants.FEATURE_XSD, true); | |||||
//set the schema source for the doc | //set the schema source for the doc | ||||
setNoNamespaceSchemaProperty( | |||||
XmlConstants.PROPERTY_NO_NAMESPACE_SCHEMA_LOCATION); | |||||
setNoNamespaceSchemaProperty(XmlConstants.PROPERTY_NO_NAMESPACE_SCHEMA_LOCATION); | |||||
} catch (BuildException e) { | } catch (BuildException e) { | ||||
log(e.toString(),Project.MSG_VERBOSE); | |||||
log(e.toString(), Project.MSG_VERBOSE); | |||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
@@ -110,8 +111,7 @@ public class SchemaValidate extends XMLValidateTask { | |||||
private void setNoNamespaceSchemaProperty(String property) { | private void setNoNamespaceSchemaProperty(String property) { | ||||
String anonSchema = getNoNamespaceSchemaURL(); | String anonSchema = getNoNamespaceSchemaURL(); | ||||
if (anonSchema != null) { | if (anonSchema != null) { | ||||
setProperty(property, | |||||
anonSchema); | |||||
setProperty(property, anonSchema); | |||||
} | } | ||||
} | } | ||||
@@ -124,11 +124,9 @@ public class SchemaValidate extends XMLValidateTask { | |||||
public boolean enableJAXP12SchemaValidation() { | public boolean enableJAXP12SchemaValidation() { | ||||
try { | try { | ||||
//enable XSD | //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 | //set the schema source for the doc | ||||
setNoNamespaceSchemaProperty( | |||||
XmlConstants.FEATURE_JAXP12_SCHEMA_SOURCE); | |||||
setNoNamespaceSchemaProperty(XmlConstants.FEATURE_JAXP12_SCHEMA_SOURCE); | |||||
} catch (BuildException e) { | } catch (BuildException e) { | ||||
log(e.toString(), Project.MSG_VERBOSE); | log(e.toString(), Project.MSG_VERBOSE); | ||||
return false; | return false; | ||||
@@ -143,12 +141,11 @@ public class SchemaValidate extends XMLValidateTask { | |||||
* is a declaration of this schema with a different value | * is a declaration of this schema with a different value | ||||
*/ | */ | ||||
public void addConfiguredSchema(SchemaLocation location) { | public void addConfiguredSchema(SchemaLocation location) { | ||||
log("adding schema "+location,Project.MSG_DEBUG); | |||||
log("adding schema " + location, Project.MSG_DEBUG); | |||||
location.validateNamespace(); | 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); | schemaLocations.put(location.getNamespace(), location); | ||||
} | } | ||||
@@ -161,17 +158,17 @@ public class SchemaValidate extends XMLValidateTask { | |||||
this.fullChecking = fullChecking; | this.fullChecking = fullChecking; | ||||
} | } | ||||
/** | /** | ||||
* create a schema location to hold the anonymous | * create a schema location to hold the anonymous | ||||
* schema | * schema | ||||
*/ | */ | ||||
protected void createAnonymousSchema() { | protected void createAnonymousSchema() { | ||||
if(anonymousSchema==null) { | |||||
anonymousSchema=new SchemaLocation(); | |||||
if (anonymousSchema == null) { | |||||
anonymousSchema = new SchemaLocation(); | |||||
} | } | ||||
anonymousSchema.setNamespace("(no namespace)"); | anonymousSchema.setNamespace("(no namespace)"); | ||||
} | } | ||||
/** | /** | ||||
* identify the URL of the default schema | * identify the URL of the default schema | ||||
* @param defaultSchemaURL | * @param defaultSchemaURL | ||||
@@ -207,24 +204,24 @@ public class SchemaValidate extends XMLValidateTask { | |||||
protected void initValidator() { | protected void initValidator() { | ||||
super.initValidator(); | super.initValidator(); | ||||
//validate the parser type | //validate the parser type | ||||
if(isSax1Parser()) { | |||||
if (isSax1Parser()) { | |||||
throw new BuildException(ERROR_SAX_1); | throw new BuildException(ERROR_SAX_1); | ||||
} | } | ||||
//enable schema | //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 | //couldnt use the xerces or jaxp calls | ||||
throw new BuildException(ERROR_NO_XSD_SUPPORT); | throw new BuildException(ERROR_NO_XSD_SUPPORT); | ||||
} | } | ||||
//enable schema checking | //enable schema checking | ||||
setFeature(XmlConstants.FEATURE_XSD_FULL_VALIDATION,fullChecking); | |||||
setFeature(XmlConstants.FEATURE_XSD_FULL_VALIDATION, fullChecking); | |||||
//turn off DTDs if desired | //turn off DTDs if desired | ||||
setFeatureIfSupported(XmlConstants.FEATURE_DISALLOW_DTD,disableDTD); | |||||
setFeatureIfSupported(XmlConstants.FEATURE_DISALLOW_DTD, disableDTD); | |||||
//schema declarations go in next | //schema declarations go in next | ||||
addSchemaLocations(); | addSchemaLocations(); | ||||
} | } | ||||
@@ -244,7 +241,7 @@ public class SchemaValidate extends XMLValidateTask { | |||||
SAXParser saxParser = factory.newSAXParser(); | SAXParser saxParser = factory.newSAXParser(); | ||||
reader = saxParser.getXMLReader(); | reader = saxParser.getXMLReader(); | ||||
} catch (ParserConfigurationException e) { | } catch (ParserConfigurationException e) { | ||||
throw new BuildException(ERROR_PARSER_CREATION_FAILURE,e); | |||||
throw new BuildException(ERROR_PARSER_CREATION_FAILURE, e); | |||||
} catch (SAXException e) { | } catch (SAXException e) { | ||||
throw new BuildException(ERROR_PARSER_CREATION_FAILURE, e); | throw new BuildException(ERROR_PARSER_CREATION_FAILURE, e); | ||||
} | } | ||||
@@ -266,7 +263,7 @@ public class SchemaValidate extends XMLValidateTask { | |||||
SchemaLocation schemaLocation = (SchemaLocation) it.next(); | SchemaLocation schemaLocation = (SchemaLocation) it.next(); | ||||
String tuple = schemaLocation.getURIandLocation(); | String tuple = schemaLocation.getURIandLocation(); | ||||
buffer.append(tuple); | buffer.append(tuple); | ||||
log("Adding schema "+tuple,Project.MSG_VERBOSE); | |||||
log("Adding schema " + tuple, Project.MSG_VERBOSE); | |||||
count++; | count++; | ||||
} | } | ||||
if (count > 0) { | if (count > 0) { | ||||
@@ -280,7 +277,7 @@ public class SchemaValidate extends XMLValidateTask { | |||||
* @return | * @return | ||||
*/ | */ | ||||
protected String getNoNamespaceSchemaURL() { | protected String getNoNamespaceSchemaURL() { | ||||
if(anonymousSchema==null) { | |||||
if (anonymousSchema == null) { | |||||
return null; | return null; | ||||
} else { | } else { | ||||
return anonymousSchema.getSchemaLocationURL(); | return anonymousSchema.getSchemaLocationURL(); | ||||
@@ -293,11 +290,11 @@ public class SchemaValidate extends XMLValidateTask { | |||||
* @param feature | * @param feature | ||||
* @param value | * @param value | ||||
*/ | */ | ||||
protected void setFeatureIfSupported(String feature,boolean value) { | |||||
protected void setFeatureIfSupported(String feature, boolean value) { | |||||
try { | try { | ||||
getXmlReader().setFeature(feature, value); | getXmlReader().setFeature(feature, value); | ||||
} catch (SAXNotRecognizedException e) { | } catch (SAXNotRecognizedException e) { | ||||
log("Not recognizied: "+feature,Project.MSG_VERBOSE); | |||||
log("Not recognizied: " + feature, Project.MSG_VERBOSE); | |||||
} catch (SAXNotSupportedException e) { | } catch (SAXNotSupportedException e) { | ||||
log("Not supported: " + feature, Project.MSG_VERBOSE); | log("Not supported: " + feature, Project.MSG_VERBOSE); | ||||
} | } | ||||
@@ -309,7 +306,7 @@ public class SchemaValidate extends XMLValidateTask { | |||||
* @param fileProcessed number of files processed. | * @param fileProcessed number of files processed. | ||||
*/ | */ | ||||
protected void onSuccessfulValidation(int fileProcessed) { | 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 { | public static class SchemaLocation { | ||||
private String namespace; | private String namespace; | ||||
private File file; | private File file; | ||||
private String url; | private String url; | ||||
public static final String ERROR_NO_URI = "No namespace URI"; | 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_FILE = "File not found: "; | ||||
public static final String ERROR_NO_URL_REPRESENTATION = "Cannot make a URL of "; | 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 static final String ERROR_NO_LOCATION = "No file or URL supplied for the schema "; | ||||
public SchemaLocation() { | public SchemaLocation() { | ||||
} | } | ||||
public String getNamespace() { | public String getNamespace() { | ||||
return namespace; | return namespace; | ||||
} | } | ||||
@@ -378,9 +379,8 @@ public class SchemaValidate extends XMLValidateTask { | |||||
boolean hasFile = file != null; | boolean hasFile = file != null; | ||||
boolean hasURL = isSet(url); | boolean hasURL = isSet(url); | ||||
//error if both are empty, or both are set | //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) { | if (hasFile && hasURL) { | ||||
throw new BuildException(ERROR_TWO_LOCATIONS + namespace); | throw new BuildException(ERROR_TWO_LOCATIONS + namespace); | ||||
@@ -392,11 +392,10 @@ public class SchemaValidate extends XMLValidateTask { | |||||
} | } | ||||
try { | try { | ||||
schema = | |||||
FileUtils.getFileUtils().getFileURL(file).toString(); | |||||
schema = FileUtils.getFileUtils().getFileURL(file).toString(); | |||||
} catch (MalformedURLException e) { | } catch (MalformedURLException e) { | ||||
//this is almost implausible, but required handling | //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; | return schema; | ||||
@@ -452,19 +451,14 @@ public class SchemaValidate extends XMLValidateTask { | |||||
final SchemaLocation schemaLocation = (SchemaLocation) o; | 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; | return false; | ||||
} | } | ||||
if (namespace != null ? | |||||
!namespace.equals(schemaLocation.namespace) : | |||||
schemaLocation.namespace != null) { | |||||
if (namespace != null ? !namespace.equals(schemaLocation.namespace) | |||||
: schemaLocation.namespace != null) { | |||||
return false; | return false; | ||||
} | } | ||||
if (url != null ? | |||||
!url.equals(schemaLocation.url) : | |||||
schemaLocation.url != null) { | |||||
if (url != null ? !url.equals(schemaLocation.url) : schemaLocation.url != null) { | |||||
return false; | return false; | ||||
} | } | ||||
@@ -489,12 +483,12 @@ public class SchemaValidate extends XMLValidateTask { | |||||
* @return a string representation of the object. | * @return a string representation of the object. | ||||
*/ | */ | ||||
public String toString() { | 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(' '); | ||||
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(); | return buffer.toString(); | ||||
} | } | ||||
} //SchemaLocation | } //SchemaLocation | ||||
} | |||||
} |
@@ -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"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with 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.*; | 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 { | public class DotnetResource { | ||||
/** | /** | ||||
* name of resource | * name of resource | ||||
*/ | */ | ||||
@@ -55,7 +53,7 @@ public class DotnetResource { | |||||
/** | /** | ||||
* A list of filesets with resources. | * A list of filesets with resources. | ||||
*/ | */ | ||||
private ArrayList fileSets=new ArrayList(); | |||||
private ArrayList fileSets = new ArrayList(); | |||||
/** | /** | ||||
* a namespace to be used with <filesets> | * 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. | * embed the resource in the assembly (default, true) or just link to it. | ||||
* | |||||
* @param embed | * @param embed | ||||
*/ | */ | ||||
public void setEmbed(boolean embed) { | public void setEmbed(boolean embed) { | ||||
@@ -80,6 +79,7 @@ public class DotnetResource { | |||||
/** | /** | ||||
* name the resource | * name the resource | ||||
* | |||||
* @param file | * @param file | ||||
*/ | */ | ||||
public void setFile(File file) { | public void setFile(File file) { | ||||
@@ -92,6 +92,7 @@ public class DotnetResource { | |||||
/** | /** | ||||
* VB and J# only: is a resource public or not? | * VB and J# only: is a resource public or not? | ||||
* | |||||
* @param aPublic | * @param aPublic | ||||
*/ | */ | ||||
public void setPublic(Boolean aPublic) { | public void setPublic(Boolean aPublic) { | ||||
@@ -104,6 +105,7 @@ public class DotnetResource { | |||||
/** | /** | ||||
* should the resource have a name? | * should the resource have a name? | ||||
* | |||||
* @param name | * @param name | ||||
*/ | */ | ||||
public void setName(String name) { | public void setName(String name) { | ||||
@@ -112,6 +114,7 @@ public class DotnetResource { | |||||
/** | /** | ||||
* Filesets root namespace. The value always ends with '.' . | * Filesets root namespace. The value always ends with '.' . | ||||
* | |||||
* @return String namespace name | * @return String namespace name | ||||
*/ | */ | ||||
public String getNamespace() { | public String getNamespace() { | ||||
@@ -120,76 +123,83 @@ public class DotnetResource { | |||||
/** | /** | ||||
* Sets filesets root namespace. | * Sets filesets root namespace. | ||||
* @param namespace String root namespace | |||||
* | |||||
* @param namespace | |||||
* String root namespace | |||||
*/ | */ | ||||
public void setNamespace(String 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() { | private void checkParameters() { | ||||
if (hasFilesets()) { | 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) | * build the C# style parameter (which has no public/private option) | ||||
* | |||||
* @return the built C# style parameter | * @return the built C# style parameter | ||||
*/ | */ | ||||
public void getParameters(Project p, NetCommand command, boolean csharpStyle) { | public void getParameters(Project p, NetCommand command, boolean csharpStyle) { | ||||
checkParameters(); | checkParameters(); | ||||
if (hasFilesets()) { | 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); | DirectoryScanner ds = fs.getDirectoryScanner(p); | ||||
String[] files = ds.getIncludedFiles(); | 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) { | 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(':'); | ||||
buffer.append(fileName); | buffer.append(fileName); | ||||
if (name!=null) { | |||||
if (name != null) { | |||||
buffer.append(','); | buffer.append(','); | ||||
buffer.append(name); | buffer.append(name); | ||||
if (csharpStyle) { | 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(','); | ||||
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 " | throw new BuildException("You cannot have a public or private " | ||||
+"option without naming the resource"); | |||||
+ "option without naming the resource"); | |||||
} | } | ||||
} | } | ||||
return buffer.toString(); | return buffer.toString(); | ||||
@@ -197,7 +207,9 @@ public class DotnetResource { | |||||
/** | /** | ||||
* Adds a resource file set. | * Adds a resource file set. | ||||
* @param fileset FileSet | |||||
* | |||||
* @param fileset | |||||
* FileSet | |||||
*/ | */ | ||||
public void addFileset(FileSet fileset) { | public void addFileset(FileSet fileset) { | ||||
fileSets.add(fileset); | fileSets.add(fileset); | ||||
@@ -205,9 +217,10 @@ public class DotnetResource { | |||||
/** | /** | ||||
* Checks that <resource> node has embedded <filesets> | * Checks that <resource> node has embedded <filesets> | ||||
* | |||||
* @return boolean | * @return boolean | ||||
*/ | */ | ||||
public boolean hasFilesets() { | public boolean hasFilesets() { | ||||
return fileSets.size()>0; | |||||
return fileSets.size() > 0; | |||||
} | } | ||||
} | |||||
} |
@@ -323,23 +323,25 @@ public abstract class MSVSS extends Task implements MSVSSConstants { | |||||
* @return An empty string if label is not set. | * @return An empty string if label is not set. | ||||
*/ | */ | ||||
protected String getLabel() { | protected String getLabel() { | ||||
String shortLabel=""; | |||||
String shortLabel = ""; | |||||
if (label != null && label.length() > 0) { | if (label != null && label.length() > 0) { | ||||
shortLabel = FLAG_LABEL + getShortLabel(); | shortLabel = FLAG_LABEL + getShortLabel(); | ||||
} | |||||
} | |||||
return shortLabel; | 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 | * @return at most the 30 first chars of the label | ||||
*/ | */ | ||||
private String getShortLabel() { | private String getShortLabel() { | ||||
String shortLabel; | |||||
String shortLabel; | |||||
if (label != null && label.length() > 31) { | 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 { | } else { | ||||
shortLabel = label; | |||||
shortLabel = label; | |||||
} | } | ||||
return shortLabel; | 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. | * @return An empty string if a version, date and label are not set. | ||||
*/ | */ | ||||
protected String getVersionDateLabel() { | protected String getVersionDateLabel() { | ||||
String versionDateLabel = ""; | |||||
String versionDateLabel = ""; | |||||
if (version != null) { | if (version != null) { | ||||
versionDateLabel = FLAG_VERSION + version; | |||||
versionDateLabel = FLAG_VERSION + version; | |||||
} else if (date != null) { | } else if (date != null) { | ||||
versionDateLabel = FLAG_VERSION_DATE + date; | |||||
versionDateLabel = FLAG_VERSION_DATE + date; | |||||
} else { | } else { | ||||
// Use getShortLabel() so labels longer then 30 char are truncated | // Use getShortLabel() so labels longer then 30 char are truncated | ||||
// and the user is warned | // and the user is warned | ||||
String shortLabel = getShortLabel(); | String shortLabel = getShortLabel(); | ||||
if (shortLabel != null && !shortLabel.equals("")) { | if (shortLabel != null && !shortLabel.equals("")) { | ||||
versionDateLabel = FLAG_VERSION_LABEL + shortLabel; | |||||
versionDateLabel = FLAG_VERSION_LABEL + shortLabel; | |||||
} | } | ||||
} | } | ||||
return versionDateLabel; | return versionDateLabel; | ||||
@@ -387,9 +389,9 @@ public abstract class MSVSS extends Task implements MSVSSConstants { | |||||
* @return An empty string if localpath is not set. | * @return An empty string if localpath is not set. | ||||
*/ | */ | ||||
protected String getLocalpath() { | 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); | File dir = getProject().resolveFile(localPath); | ||||
if (!dir.exists()) { | if (!dir.exists()) { | ||||
boolean done = dir.mkdirs(); | boolean done = dir.mkdirs(); | ||||
@@ -401,7 +403,7 @@ public abstract class MSVSS extends Task implements MSVSSConstants { | |||||
getProject().log("Created dir: " + dir.getAbsolutePath()); | getProject().log("Created dir: " + dir.getAbsolutePath()); | ||||
} | } | ||||
lclPath = FLAG_OVERRIDE_WORKING_DIR + localPath; | lclPath = FLAG_OVERRIDE_WORKING_DIR + localPath; | ||||
} | |||||
} | |||||
return lclPath; | return lclPath; | ||||
} | } | ||||