git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274773 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -97,9 +97,9 @@ public class AndSelector extends BaseSelectorContainer { | |||
| Enumeration e = selectorElements(); | |||
| boolean result; | |||
| while(e.hasMoreElements()) { | |||
| result = ((FileSelector)e.nextElement()).isSelected(basedir, | |||
| filename,file); | |||
| while (e.hasMoreElements()) { | |||
| result = ((FileSelector) e.nextElement()).isSelected(basedir, | |||
| filename, file); | |||
| if (!result) { | |||
| return false; | |||
| } | |||
| @@ -54,6 +54,7 @@ | |||
| package org.apache.tools.ant.types.selectors; | |||
| import java.io.File; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.types.Parameter; | |||
| @@ -67,8 +68,8 @@ import org.apache.tools.ant.types.Parameter; | |||
| * @since 1.5 | |||
| */ | |||
| public abstract class BaseExtendSelector | |||
| extends BaseSelector | |||
| implements ExtendFileSelector { | |||
| extends BaseSelector | |||
| implements ExtendFileSelector { | |||
| /** The passed in parameter array. */ | |||
| protected Parameter[] parameters = null; | |||
| @@ -55,6 +55,7 @@ | |||
| package org.apache.tools.ant.types.selectors; | |||
| import java.io.File; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.types.DataType; | |||
| @@ -111,7 +112,6 @@ public abstract class BaseSelector extends DataType implements FileSelector { | |||
| } | |||
| /** | |||
| * Subclasses can use this to throw the requisite exception | |||
| * in isSelected() in the case of an error condition. | |||
| @@ -137,7 +137,7 @@ public abstract class BaseSelector extends DataType implements FileSelector { | |||
| * @return whether the file should be selected or not | |||
| */ | |||
| public abstract boolean isSelected(File basedir, String filename, | |||
| File file); | |||
| File file); | |||
| } | |||
| @@ -57,6 +57,7 @@ package org.apache.tools.ant.types.selectors; | |||
| import java.io.File; | |||
| import java.util.Enumeration; | |||
| import java.util.Vector; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| @@ -118,7 +119,7 @@ public abstract class BaseSelectorContainer extends BaseSelector | |||
| StringBuffer buf = new StringBuffer(); | |||
| Enumeration e = selectorElements(); | |||
| if (e.hasMoreElements()) { | |||
| while(e.hasMoreElements()) { | |||
| while (e.hasMoreElements()) { | |||
| buf.append(e.nextElement().toString()); | |||
| if (e.hasMoreElements()) { | |||
| buf.append(", "); | |||
| @@ -161,10 +162,10 @@ public abstract class BaseSelectorContainer extends BaseSelector | |||
| throw new BuildException(errmsg); | |||
| } | |||
| Enumeration e = selectorElements(); | |||
| while(e.hasMoreElements()) { | |||
| while (e.hasMoreElements()) { | |||
| Object o = e.nextElement(); | |||
| if (o instanceof BaseSelector) { | |||
| ((BaseSelector)o).validate(); | |||
| ((BaseSelector) o).validate(); | |||
| } | |||
| } | |||
| } | |||
| @@ -290,14 +291,14 @@ public abstract class BaseSelectorContainer extends BaseSelector | |||
| public void addDifferent(DifferentSelector selector) { | |||
| appendSelector(selector); | |||
| } | |||
| /** | |||
| * adds a type selector to the selector list | |||
| */ | |||
| public void addType(TypeSelector selector) { | |||
| appendSelector(selector); | |||
| } | |||
| /** | |||
| * add a regular expression selector entry on the selector list | |||
| */ | |||
| @@ -305,7 +306,7 @@ public abstract class BaseSelectorContainer extends BaseSelector | |||
| appendSelector(selector); | |||
| } | |||
| /** | |||
| * add an arbitary selector | |||
| * @since Ant 1.6 | |||
| @@ -82,7 +82,8 @@ public class ContainsRegexpSelector extends BaseExtendSelector { | |||
| } | |||
| public String toString() { | |||
| StringBuffer buf = new StringBuffer("{containsregexpselector expression: "); | |||
| StringBuffer buf = new StringBuffer( | |||
| "{containsregexpselector expression: "); | |||
| buf.append(userProvidedExpression); | |||
| buf.append("}"); | |||
| return buf.toString(); | |||
| @@ -91,8 +92,7 @@ public class ContainsRegexpSelector extends BaseExtendSelector { | |||
| /** | |||
| * The regular expression used to search the file. | |||
| * | |||
| * @param regular expression that must match a line in the file to | |||
| * be selected. | |||
| * @param theexpression this must match a line in the file to be selected. | |||
| */ | |||
| public void setExpression(String theexpression) { | |||
| this.userProvidedExpression = theexpression; | |||
| @@ -139,15 +139,15 @@ public class ContainsRegexpSelector extends BaseExtendSelector { | |||
| public boolean isSelected(File basedir, String filename, File file) { | |||
| String teststr = null; | |||
| BufferedReader in = null; | |||
| // throw BuildException on error | |||
| validate(); | |||
| if (file.isDirectory()) { | |||
| return true; | |||
| } | |||
| if (myRegExp == null) { | |||
| myRegExp = new RegularExpression(); | |||
| myRegExp.setPattern(userProvidedExpression); | |||
| @@ -155,20 +155,20 @@ public class ContainsRegexpSelector extends BaseExtendSelector { | |||
| } | |||
| try { | |||
| in = new BufferedReader(new InputStreamReader( | |||
| in = new BufferedReader(new InputStreamReader( | |||
| new FileInputStream(file))); | |||
| teststr = in.readLine(); | |||
| while (teststr != null) { | |||
| if (myExpression.matches(teststr) == true) { | |||
| return true; | |||
| } | |||
| teststr = in.readLine(); | |||
| } | |||
| return false; | |||
| teststr = in.readLine(); | |||
| while (teststr != null) { | |||
| if (myExpression.matches(teststr) == true) { | |||
| return true; | |||
| } | |||
| teststr = in.readLine(); | |||
| } | |||
| return false; | |||
| } catch (IOException ioe) { | |||
| throw new BuildException("Could not read file " + filename); | |||
| } finally { | |||
| @@ -59,6 +59,7 @@ import java.io.File; | |||
| import java.io.FileInputStream; | |||
| import java.io.IOException; | |||
| import java.io.InputStreamReader; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.types.Parameter; | |||
| @@ -123,7 +124,7 @@ public class ContainsSelector extends BaseExtendSelector { | |||
| /** | |||
| * Whether to ignore whitespace in the string being searched. | |||
| * | |||
| * @param whitespace whether to ignore any whitespace (spaces, tabs, etc.) in the searchstring | |||
| * @param ignorewhitespace whether to ignore any whitespace (spaces, tabs, etc.) in the searchstring | |||
| */ | |||
| public void setIgnorewhitespace(boolean ignorewhitespace) { | |||
| this.ignorewhitespace = ignorewhitespace; | |||
| @@ -142,16 +143,13 @@ public class ContainsSelector extends BaseExtendSelector { | |||
| String paramname = parameters[i].getName(); | |||
| if (CONTAINS_KEY.equalsIgnoreCase(paramname)) { | |||
| setText(parameters[i].getValue()); | |||
| } | |||
| else if (CASE_KEY.equalsIgnoreCase(paramname)) { | |||
| } else if (CASE_KEY.equalsIgnoreCase(paramname)) { | |||
| setCasesensitive(Project.toBoolean( | |||
| parameters[i].getValue())); | |||
| } | |||
| else if (WHITESPACE_KEY.equalsIgnoreCase(paramname)) { | |||
| parameters[i].getValue())); | |||
| } else if (WHITESPACE_KEY.equalsIgnoreCase(paramname)) { | |||
| setIgnorewhitespace(Project.toBoolean( | |||
| parameters[i].getValue())); | |||
| } | |||
| else { | |||
| parameters[i].getValue())); | |||
| } else { | |||
| setError("Invalid parameter " + paramname); | |||
| } | |||
| } | |||
| @@ -212,15 +210,12 @@ public class ContainsSelector extends BaseExtendSelector { | |||
| teststr = in.readLine(); | |||
| } | |||
| return false; | |||
| } | |||
| catch (IOException ioe) { | |||
| } catch (IOException ioe) { | |||
| throw new BuildException("Could not read file " + filename); | |||
| } | |||
| finally { | |||
| } finally { | |||
| try { | |||
| in.close(); | |||
| } | |||
| catch (Exception e) { | |||
| } catch (Exception e) { | |||
| throw new BuildException("Could not close file " + filename); | |||
| } | |||
| } | |||
| @@ -58,6 +58,7 @@ import java.io.File; | |||
| import java.text.DateFormat; | |||
| import java.text.ParseException; | |||
| import java.util.Locale; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.taskdefs.condition.Os; | |||
| import org.apache.tools.ant.types.EnumeratedAttribute; | |||
| @@ -94,8 +95,7 @@ public class DateSelector extends BaseExtendSelector { | |||
| buf.append(" compare: "); | |||
| if (cmp == 0) { | |||
| buf.append("before"); | |||
| } | |||
| else if (cmp == 1) { | |||
| } else if (cmp == 1) { | |||
| buf.append("after"); | |||
| } else { | |||
| buf.append("equal"); | |||
| @@ -133,18 +133,18 @@ public class DateSelector extends BaseExtendSelector { | |||
| this.dateTime = dateTime; | |||
| if (dateTime != null) { | |||
| DateFormat df = DateFormat.getDateTimeInstance( | |||
| DateFormat.SHORT, | |||
| DateFormat.SHORT, | |||
| Locale.US); | |||
| DateFormat.SHORT, | |||
| DateFormat.SHORT, | |||
| Locale.US); | |||
| try { | |||
| setMillis(df.parse(dateTime).getTime()); | |||
| if (millis < 0) { | |||
| setError("Date of " + dateTime | |||
| + " results in negative milliseconds value relative" | |||
| + " to epoch (January 1, 1970, 00:00:00 GMT)."); | |||
| + " results in negative milliseconds value relative" | |||
| + " to epoch (January 1, 1970, 00:00:00 GMT)."); | |||
| } | |||
| } catch (ParseException pe) { | |||
| setError("Date of " + dateTime | |||
| setError("Date of " + dateTime | |||
| + " Cannot be parsed correctly. It should be in" | |||
| + " MM/DD/YYYY HH:MM AM_PM format."); | |||
| } | |||
| @@ -192,33 +192,28 @@ public class DateSelector extends BaseExtendSelector { | |||
| if (MILLIS_KEY.equalsIgnoreCase(paramname)) { | |||
| try { | |||
| setMillis(new Long(parameters[i].getValue() | |||
| ).longValue()); | |||
| ).longValue()); | |||
| } catch (NumberFormatException nfe) { | |||
| setError("Invalid millisecond setting " + | |||
| parameters[i].getValue()); | |||
| parameters[i].getValue()); | |||
| } | |||
| } | |||
| else if (DATETIME_KEY.equalsIgnoreCase(paramname)) { | |||
| } else if (DATETIME_KEY.equalsIgnoreCase(paramname)) { | |||
| setDatetime(parameters[i].getValue()); | |||
| } | |||
| else if (CHECKDIRS_KEY.equalsIgnoreCase(paramname)) { | |||
| } else if (CHECKDIRS_KEY.equalsIgnoreCase(paramname)) { | |||
| setCheckdirs(Project.toBoolean(parameters[i].getValue())); | |||
| } | |||
| else if (GRANULARITY_KEY.equalsIgnoreCase(paramname)) { | |||
| } else if (GRANULARITY_KEY.equalsIgnoreCase(paramname)) { | |||
| try { | |||
| setGranularity(new Integer(parameters[i].getValue() | |||
| ).intValue()); | |||
| ).intValue()); | |||
| } catch (NumberFormatException nfe) { | |||
| setError("Invalid granularity setting " + | |||
| parameters[i].getValue()); | |||
| parameters[i].getValue()); | |||
| } | |||
| } | |||
| else if (WHEN_KEY.equalsIgnoreCase(paramname)) { | |||
| } else if (WHEN_KEY.equalsIgnoreCase(paramname)) { | |||
| TimeComparisons cmp = new TimeComparisons(); | |||
| cmp.setValue(parameters[i].getValue()); | |||
| setWhen(cmp); | |||
| } | |||
| else { | |||
| } else { | |||
| setError("Invalid parameter " + paramname); | |||
| } | |||
| } | |||
| @@ -232,12 +227,11 @@ public class DateSelector extends BaseExtendSelector { | |||
| public void verifySettings() { | |||
| if (dateTime == null && millis < 0) { | |||
| setError("You must provide a datetime or the number of " | |||
| + "milliseconds."); | |||
| } | |||
| else if (millis < 0) { | |||
| + "milliseconds."); | |||
| } else if (millis < 0) { | |||
| setError("Date of " + dateTime | |||
| + " results in negative milliseconds" | |||
| + " value relative to epoch (January 1, 1970, 00:00:00 GMT)."); | |||
| + " results in negative milliseconds value" | |||
| + " relative to epoch (January 1, 1970, 00:00:00 GMT)."); | |||
| } | |||
| } | |||
| @@ -257,12 +251,10 @@ public class DateSelector extends BaseExtendSelector { | |||
| } | |||
| if (cmp == 0) { | |||
| return ((file.lastModified() - granularity) < millis); | |||
| } | |||
| else if (cmp == 1) { | |||
| } else if (cmp == 1) { | |||
| return ((file.lastModified() + granularity) > millis); | |||
| } | |||
| else { | |||
| return (Math.abs(file.lastModified() - millis) <= granularity); | |||
| } else { | |||
| return (Math.abs(file.lastModified() - millis) <= granularity); | |||
| } | |||
| } | |||
| @@ -272,7 +264,7 @@ public class DateSelector extends BaseExtendSelector { | |||
| */ | |||
| public static class TimeComparisons extends EnumeratedAttribute { | |||
| public String[] getValues() { | |||
| return new String[] {"before", "after", "equal"}; | |||
| return new String[]{"before", "after", "equal"}; | |||
| } | |||
| } | |||
| @@ -75,8 +75,7 @@ public class DependSelector extends MappingSelector { | |||
| StringBuffer buf = new StringBuffer("{dependselector targetdir: "); | |||
| if (targetdir == null) { | |||
| buf.append("NOT YET SET"); | |||
| } | |||
| else { | |||
| } else { | |||
| buf.append(targetdir.getName()); | |||
| } | |||
| buf.append(" granularity: "); | |||
| @@ -84,8 +83,7 @@ public class DependSelector extends MappingSelector { | |||
| if (map != null) { | |||
| buf.append(" mapper: "); | |||
| buf.append(map.toString()); | |||
| } | |||
| else if (mapperElement != null) { | |||
| } else if (mapperElement != null) { | |||
| buf.append(" mapper: "); | |||
| buf.append(mapperElement.toString()); | |||
| } | |||
| @@ -101,7 +99,8 @@ public class DependSelector extends MappingSelector { | |||
| * @return | |||
| */ | |||
| public boolean selectionTest(File srcfile, File destfile) { | |||
| boolean selected=SelectorUtils.isOutOfDate(srcfile, destfile, granularity); | |||
| boolean selected = SelectorUtils.isOutOfDate(srcfile, destfile, | |||
| granularity); | |||
| return selected; | |||
| } | |||
| @@ -56,6 +56,7 @@ package org.apache.tools.ant.types.selectors; | |||
| import java.io.File; | |||
| import java.util.StringTokenizer; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.types.Parameter; | |||
| @@ -97,7 +98,7 @@ public class DepthSelector extends BaseExtendSelector { | |||
| /** | |||
| * The minimum depth below the basedir before a file is selected. | |||
| * | |||
| * @param min maximum directory levels below basedir to go | |||
| * @param max maximum directory levels below basedir to go | |||
| */ | |||
| public void setMax(int max) { | |||
| this.max = max; | |||
| @@ -117,22 +118,18 @@ public class DepthSelector extends BaseExtendSelector { | |||
| if (MIN_KEY.equalsIgnoreCase(paramname)) { | |||
| try { | |||
| setMin(Integer.parseInt(parameters[i].getValue())); | |||
| } | |||
| catch (NumberFormatException nfe1) { | |||
| } catch (NumberFormatException nfe1) { | |||
| setError("Invalid minimum value " | |||
| + parameters[i].getValue()); | |||
| + parameters[i].getValue()); | |||
| } | |||
| } | |||
| else if (MAX_KEY.equalsIgnoreCase(paramname)) { | |||
| } else if (MAX_KEY.equalsIgnoreCase(paramname)) { | |||
| try { | |||
| setMax(Integer.parseInt(parameters[i].getValue())); | |||
| } | |||
| catch (NumberFormatException nfe1) { | |||
| } catch (NumberFormatException nfe1) { | |||
| setError("Invalid maximum value " | |||
| + parameters[i].getValue()); | |||
| + parameters[i].getValue()); | |||
| } | |||
| } | |||
| else { | |||
| } else { | |||
| setError("Invalid parameter " + paramname); | |||
| } | |||
| } | |||
| @@ -145,8 +142,8 @@ public class DepthSelector extends BaseExtendSelector { | |||
| */ | |||
| public void verifySettings() { | |||
| if (min < 0 && max < 0) { | |||
| setError("You must set at least one of the min or the " + | |||
| "max levels."); | |||
| setError("You must set at least one of the min or the " | |||
| + "max levels."); | |||
| } | |||
| if (max < min && max > -1) { | |||
| setError("The maximum depth is lower than the minimum."); | |||
| @@ -174,19 +171,21 @@ public class DepthSelector extends BaseExtendSelector { | |||
| // If you felt daring, you could cache the basedir absolute path | |||
| String abs_base = basedir.getAbsolutePath(); | |||
| String abs_file = file.getAbsolutePath(); | |||
| StringTokenizer tok_base = new StringTokenizer(abs_base, File.separator); | |||
| StringTokenizer tok_file = new StringTokenizer(abs_file, File.separator); | |||
| StringTokenizer tok_base = new StringTokenizer(abs_base, | |||
| File.separator); | |||
| StringTokenizer tok_file = new StringTokenizer(abs_file, | |||
| File.separator); | |||
| while (tok_file.hasMoreTokens()) { | |||
| String filetoken = tok_file.nextToken(); | |||
| if (tok_base.hasMoreTokens()) { | |||
| String basetoken = tok_base.nextToken(); | |||
| // Sanity check. Ditch it if you want faster performance | |||
| if (!basetoken.equals(filetoken)) { | |||
| throw new BuildException("File " + filename + | |||
| " does not appear within " + abs_base + "directory"); | |||
| throw new BuildException("File " + filename | |||
| + " does not appear within " + abs_base | |||
| + "directory"); | |||
| } | |||
| } | |||
| else { | |||
| } else { | |||
| depth += 1; | |||
| if (max > -1 && depth > max) { | |||
| return false; | |||
| @@ -195,7 +194,7 @@ public class DepthSelector extends BaseExtendSelector { | |||
| } | |||
| if (tok_base.hasMoreTokens()) { | |||
| throw new BuildException("File " + filename + | |||
| " is outside of " + abs_base + "directory tree"); | |||
| " is outside of " + abs_base + "directory tree"); | |||
| } | |||
| if (min > -1 && depth < min) { | |||
| return false; | |||
| @@ -61,27 +61,29 @@ import java.io.File; | |||
| import java.io.IOException; | |||
| /** | |||
| * This selector selects files against a mapped set of target files, selecting all those | |||
| * files which are different. A byte-by-byte comparision is performed on equal length files; | |||
| * files with different lengths are deemed different automatically; files with identical timestamps | |||
| * are viewed as matching by default, unless you specify otherwise. | |||
| * This selector selects files against a mapped set of target files, selecting | |||
| * all those files which are different. A byte-by-byte comparision is performed | |||
| * on equal length files; files with different lengths are deemed different | |||
| * automatically; files with identical timestamps are viewed as matching by | |||
| * default, unless you specify otherwise. | |||
| * <p> | |||
| * This is a useful selector to work with programs and tasks that don't handle | |||
| * dependency checking properly; Even if a predecessor task always creates its | |||
| * output files, followup tasks can be driven off copies made with a different selector, | |||
| * so their dependencies are driven on the absolute state of the files, not a timestamp. | |||
| * output files, followup tasks can be driven off copies made with a different | |||
| * selector, so their dependencies are driven on the absolute state of the | |||
| * files, not a timestamp. | |||
| * <p> | |||
| * Clearly, however, bulk file comparisons is inefficient; anything that can use | |||
| * timestamps is to be preferred. If this selector must be used, use it over as few files | |||
| * as possible, perhaps following it with an <uptodate;> to keep the descendent | |||
| * routines conditional. | |||
| * Clearly, however, bulk file comparisons is inefficient; anything that can | |||
| * use timestamps is to be preferred. If this selector must be used, use it | |||
| * over as few files as possible, perhaps following it with an <uptodate;> | |||
| * to keep the descendent routines conditional. | |||
| * | |||
| */ | |||
| public class DifferentSelector extends MappingSelector { | |||
| private FileUtils fileUtils= FileUtils.newFileUtils(); | |||
| private FileUtils fileUtils = FileUtils.newFileUtils(); | |||
| private boolean ignoreFileTimes=true; | |||
| private boolean ignoreFileTimes = true; | |||
| /** | |||
| @@ -114,19 +116,20 @@ public class DifferentSelector extends MappingSelector { | |||
| //same date if dest timestamp is within granularity of the srcfile | |||
| boolean sameDate; | |||
| sameDate = destfile.lastModified() >= srcfile.lastModified() - granularity | |||
| && destfile.lastModified() <= srcfile.lastModified() + granularity; | |||
| && destfile.lastModified() <= srcfile.lastModified() + granularity; | |||
| // different dates => different files | |||
| if(!sameDate) { | |||
| if (!sameDate) { | |||
| return true; | |||
| } | |||
| } | |||
| //here do a bulk comparison | |||
| try { | |||
| return !fileUtils.contentEquals(srcfile,destfile); | |||
| return !fileUtils.contentEquals(srcfile, destfile); | |||
| } catch (IOException e) { | |||
| throw new BuildException("while comparing "+srcfile+" and "+destfile,e); | |||
| throw new BuildException("while comparing " + srcfile + " and " | |||
| + destfile, e); | |||
| } | |||
| } | |||
| } | |||
| @@ -70,7 +70,7 @@ import org.apache.tools.ant.types.Parameterizable; | |||
| */ | |||
| public interface ExtendFileSelector extends FileSelector, Parameterizable { | |||
| // No further methods necessary. This is just an amalgamation of two other | |||
| // interfaces. | |||
| // No further methods necessary. This is just an amalgamation of two other | |||
| // interfaces. | |||
| } | |||
| @@ -56,6 +56,7 @@ package org.apache.tools.ant.types.selectors; | |||
| import java.io.File; | |||
| import java.util.Vector; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.AntClassLoader; | |||
| import org.apache.tools.ant.BuildException; | |||
| @@ -102,25 +103,22 @@ public class ExtendSelector extends BaseSelector { | |||
| c = Class.forName(classname); | |||
| } else { | |||
| AntClassLoader al | |||
| = getProject().createClassLoader(classpath); | |||
| = getProject().createClassLoader(classpath); | |||
| c = al.loadClass(classname); | |||
| AntClassLoader.initializeClass(c); | |||
| } | |||
| dynselector = (FileSelector) c.newInstance(); | |||
| final Project project = getProject(); | |||
| if ( project != null ) { | |||
| project.setProjectReference( dynselector ); | |||
| if (project != null) { | |||
| project.setProjectReference(dynselector); | |||
| } | |||
| } | |||
| catch (ClassNotFoundException cnfexcept) { | |||
| } catch (ClassNotFoundException cnfexcept) { | |||
| setError("Selector " + classname + | |||
| " not initialized, no such class"); | |||
| } | |||
| catch (InstantiationException iexcept) { | |||
| } catch (InstantiationException iexcept) { | |||
| setError("Selector " + classname + | |||
| " not initialized, could not create class"); | |||
| } | |||
| catch (IllegalAccessException iaexcept) { | |||
| } catch (IllegalAccessException iaexcept) { | |||
| setError("Selector " + classname + | |||
| " not initialized, class not accessible"); | |||
| } | |||
| @@ -198,11 +196,9 @@ public class ExtendSelector extends BaseSelector { | |||
| } | |||
| if (classname == null || classname.length() < 1) { | |||
| setError("The classname attribute is required"); | |||
| } | |||
| else if (dynselector == null) { | |||
| } else if (dynselector == null) { | |||
| setError("Internal Error: The custom selector was not created"); | |||
| } | |||
| else if (!(dynselector instanceof ExtendFileSelector) && | |||
| } else if (!(dynselector instanceof ExtendFileSelector) && | |||
| (paramVec.size() > 0)) { | |||
| setError("Cannot set parameters on custom selector that does not " | |||
| + "implement ExtendFileSelector"); | |||
| @@ -224,9 +220,9 @@ public class ExtendSelector extends BaseSelector { | |||
| Parameter[] paramArray = new Parameter[paramVec.size()]; | |||
| paramVec.copyInto(paramArray); | |||
| // We know that dynselector must be non-null if no error message | |||
| ((ExtendFileSelector)dynselector).setParameters(paramArray); | |||
| ((ExtendFileSelector) dynselector).setParameters(paramArray); | |||
| } | |||
| return dynselector.isSelected(basedir,filename,file); | |||
| return dynselector.isSelected(basedir, filename, file); | |||
| } | |||
| } | |||
| @@ -55,6 +55,7 @@ | |||
| package org.apache.tools.ant.types.selectors; | |||
| import java.io.File; | |||
| import org.apache.tools.ant.BuildException; | |||
| /** | |||
| @@ -55,6 +55,7 @@ | |||
| package org.apache.tools.ant.types.selectors; | |||
| import java.io.File; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.types.Parameter; | |||
| @@ -103,7 +104,7 @@ public class FilenameSelector extends BaseExtendSelector { | |||
| * against in order to be selected. | |||
| */ | |||
| public void setName(String pattern) { | |||
| pattern = pattern.replace('/',File.separatorChar).replace('\\', | |||
| pattern = pattern.replace('/', File.separatorChar).replace('\\', | |||
| File.separatorChar); | |||
| if (pattern.endsWith(File.separator)) { | |||
| pattern += "**"; | |||
| @@ -145,15 +146,12 @@ public class FilenameSelector extends BaseExtendSelector { | |||
| String paramname = parameters[i].getName(); | |||
| if (NAME_KEY.equalsIgnoreCase(paramname)) { | |||
| setName(parameters[i].getValue()); | |||
| } | |||
| else if (CASE_KEY.equalsIgnoreCase(paramname)) { | |||
| } else if (CASE_KEY.equalsIgnoreCase(paramname)) { | |||
| setCasesensitive(Project.toBoolean( | |||
| parameters[i].getValue())); | |||
| } | |||
| else if (NEGATE_KEY.equalsIgnoreCase(paramname)) { | |||
| parameters[i].getValue())); | |||
| } else if (NEGATE_KEY.equalsIgnoreCase(paramname)) { | |||
| setNegate(Project.toBoolean(parameters[i].getValue())); | |||
| } | |||
| else { | |||
| } else { | |||
| setError("Invalid parameter " + paramname); | |||
| } | |||
| } | |||
| @@ -186,7 +184,7 @@ public class FilenameSelector extends BaseExtendSelector { | |||
| public boolean isSelected(File basedir, String filename, File file) { | |||
| validate(); | |||
| return (SelectorUtils.matchPath(pattern,filename, | |||
| return (SelectorUtils.matchPath(pattern, filename, | |||
| casesensitive) == !(negated)); | |||
| } | |||
| @@ -111,21 +111,18 @@ public class MajoritySelector extends BaseSelectorContainer { | |||
| Enumeration e = selectorElements(); | |||
| boolean result; | |||
| while(e.hasMoreElements()) { | |||
| result = ((FileSelector)e.nextElement()).isSelected(basedir, | |||
| filename,file); | |||
| while (e.hasMoreElements()) { | |||
| result = ((FileSelector) e.nextElement()).isSelected(basedir, | |||
| filename, file); | |||
| if (result) { | |||
| yesvotes = yesvotes + 1; | |||
| } | |||
| else { | |||
| } else { | |||
| novotes = novotes + 1; | |||
| } | |||
| } | |||
| if (yesvotes > novotes) | |||
| { | |||
| if (yesvotes > novotes) { | |||
| return true; | |||
| } | |||
| else if (novotes > yesvotes) { | |||
| } else if (novotes > yesvotes) { | |||
| return false; | |||
| } | |||
| // At this point, we know we have a tie. | |||
| @@ -110,8 +110,7 @@ public abstract class MappingSelector extends BaseSelector { | |||
| } | |||
| if (mapperElement == null) { | |||
| map = new IdentityMapper(); | |||
| } | |||
| else { | |||
| } else { | |||
| map = mapperElement.getImplementation(); | |||
| } | |||
| if (map == null) { | |||
| @@ -143,10 +142,10 @@ public abstract class MappingSelector extends BaseSelector { | |||
| // Sanity check | |||
| if (destfiles.length != 1 || destfiles[0] == null) { | |||
| throw new BuildException("Invalid destination file results for " | |||
| + targetdir.getName() + " with filename " + filename); | |||
| + targetdir.getName() + " with filename " + filename); | |||
| } | |||
| String destname = destfiles[0]; | |||
| File destfile = new File(targetdir,destname); | |||
| File destfile = new File(targetdir, destname); | |||
| boolean selected = selectionTest(file, destfile); | |||
| return selected; | |||
| @@ -162,8 +161,8 @@ public abstract class MappingSelector extends BaseSelector { | |||
| /** | |||
| * Sets the number of milliseconds leeway we will give before we consider | |||
| * a file out of date. Defaults to 2000 on MS-DOS derivatives as the FAT file | |||
| * system. | |||
| * a file out of date. Defaults to 2000 on MS-DOS derivatives as the FAT | |||
| * file system. | |||
| */ | |||
| public void setGranularity(int granularity) { | |||
| this.granularity = granularity; | |||
| @@ -98,9 +98,9 @@ public class NoneSelector extends BaseSelectorContainer { | |||
| Enumeration e = selectorElements(); | |||
| boolean result; | |||
| while(e.hasMoreElements()) { | |||
| result = ((FileSelector)e.nextElement()).isSelected(basedir, | |||
| filename,file); | |||
| while (e.hasMoreElements()) { | |||
| result = ((FileSelector) e.nextElement()).isSelected(basedir, | |||
| filename, file); | |||
| if (result) { | |||
| return false; | |||
| } | |||
| @@ -55,7 +55,6 @@ | |||
| package org.apache.tools.ant.types.selectors; | |||
| /** | |||
| * This selector has one other selectors whose meaning it inverts. It | |||
| * actually relies on NoneSelector for its implementation of the | |||
| @@ -98,9 +98,9 @@ public class OrSelector extends BaseSelectorContainer { | |||
| boolean result; | |||
| // First, check that all elements are correctly configured | |||
| while(e.hasMoreElements()) { | |||
| result = ((FileSelector)e.nextElement()).isSelected(basedir, | |||
| filename,file); | |||
| while (e.hasMoreElements()) { | |||
| result = ((FileSelector) e.nextElement()).isSelected(basedir, | |||
| filename, file); | |||
| if (result) { | |||
| return true; | |||
| } | |||
| @@ -55,6 +55,7 @@ | |||
| package org.apache.tools.ant.types.selectors; | |||
| import java.io.File; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.types.EnumeratedAttribute; | |||
| import org.apache.tools.ant.types.Mapper; | |||
| @@ -84,8 +85,7 @@ public class PresentSelector extends BaseSelector { | |||
| StringBuffer buf = new StringBuffer("{presentselector targetdir: "); | |||
| if (targetdir == null) { | |||
| buf.append("NOT YET SET"); | |||
| } | |||
| else { | |||
| } else { | |||
| buf.append(targetdir.getName()); | |||
| } | |||
| buf.append(" present: "); | |||
| @@ -96,8 +96,7 @@ public class PresentSelector extends BaseSelector { | |||
| } | |||
| if (map != null) { | |||
| buf.append(map.toString()); | |||
| } | |||
| else if (mapperElement != null) { | |||
| } else if (mapperElement != null) { | |||
| buf.append(mapperElement.toString()); | |||
| } | |||
| buf.append("}"); | |||
| @@ -154,8 +153,7 @@ public class PresentSelector extends BaseSelector { | |||
| } | |||
| if (mapperElement == null) { | |||
| map = new IdentityMapper(); | |||
| } | |||
| else { | |||
| } else { | |||
| map = mapperElement.getImplementation(); | |||
| } | |||
| if (map == null) { | |||
| @@ -187,10 +185,10 @@ public class PresentSelector extends BaseSelector { | |||
| // Sanity check | |||
| if (destfiles.length != 1 || destfiles[0] == null) { | |||
| throw new BuildException("Invalid destination file results for " | |||
| + targetdir + " with filename " + filename); | |||
| + targetdir + " with filename " + filename); | |||
| } | |||
| String destname = destfiles[0]; | |||
| File destfile = new File(targetdir,destname); | |||
| File destfile = new File(targetdir, destname); | |||
| return destfile.exists() == destmustexist; | |||
| } | |||
| @@ -200,7 +198,7 @@ public class PresentSelector extends BaseSelector { | |||
| */ | |||
| public static class FilePresence extends EnumeratedAttribute { | |||
| public String[] getValues() { | |||
| return new String[] {"srconly", "both"}; | |||
| return new String[]{"srconly", "both"}; | |||
| } | |||
| } | |||
| @@ -153,7 +153,6 @@ public class SelectSelector extends BaseSelectorContainer { | |||
| * Add a new selector into this container. | |||
| * | |||
| * @param selector the new selector to add | |||
| * @return the selector that was added | |||
| */ | |||
| public void appendSelector(FileSelector selector) { | |||
| if (isReference()) { | |||
| @@ -163,7 +162,6 @@ public class SelectSelector extends BaseSelectorContainer { | |||
| } | |||
| /** | |||
| * Makes sure that there is only one entry, sets an error message if | |||
| * not. | |||
| @@ -172,7 +170,7 @@ public class SelectSelector extends BaseSelectorContainer { | |||
| int cnt = selectorCount(); | |||
| if (cnt < 0 || cnt > 1) { | |||
| setError("Only one selector is allowed within the " + | |||
| "<selector> tag"); | |||
| "<selector> tag"); | |||
| } | |||
| } | |||
| @@ -182,10 +180,10 @@ public class SelectSelector extends BaseSelectorContainer { | |||
| */ | |||
| public boolean passesConditions() { | |||
| if (ifProperty != null && | |||
| getProject().getProperty(ifProperty) == null) { | |||
| getProject().getProperty(ifProperty) == null) { | |||
| return false; | |||
| } else if (unlessProperty != null && | |||
| getProject().getProperty(unlessProperty) != null) { | |||
| getProject().getProperty(unlessProperty) != null) { | |||
| return false; | |||
| } | |||
| return true; | |||
| @@ -232,8 +230,8 @@ public class SelectSelector extends BaseSelectorContainer { | |||
| if (!(e.hasMoreElements())) { | |||
| return true; | |||
| } | |||
| FileSelector f = (FileSelector)e.nextElement(); | |||
| return f.isSelected(basedir,filename,file); | |||
| FileSelector f = (FileSelector) e.nextElement(); | |||
| return f.isSelected(basedir, filename, file); | |||
| } | |||
| } | |||
| @@ -55,6 +55,7 @@ | |||
| package org.apache.tools.ant.types.selectors; | |||
| import java.util.Enumeration; | |||
| import org.apache.tools.ant.Project; | |||
| /** | |||
| @@ -97,7 +98,6 @@ public interface SelectorContainer { | |||
| * Add a new selector into this container. | |||
| * | |||
| * @param selector the new selector to add | |||
| * @return the selector that was added | |||
| */ | |||
| public void appendSelector(FileSelector selector); | |||
| @@ -172,7 +172,7 @@ public interface SelectorContainer { | |||
| * add a depends selector entry on the selector list | |||
| */ | |||
| public void addDepend(DependSelector selector); | |||
| /** | |||
| * add a regular expression selector entry on the selector list | |||
| */ | |||
| @@ -71,14 +71,14 @@ public interface SelectorScanner { | |||
| /** | |||
| * Directories which were selected out of a scan. | |||
| * | |||
| * @param selectors list selector objects | |||
| * @return list of directories not selected | |||
| */ | |||
| public String[] getDeselectedDirectories(); | |||
| /** | |||
| * Files which were selected out of a scan. | |||
| * | |||
| * @param selectors list selector objects | |||
| * @return list of files not selected | |||
| */ | |||
| public String[] getDeselectedFiles(); | |||
| @@ -84,9 +84,10 @@ public final class SelectorUtils { | |||
| private SelectorUtils() { | |||
| } | |||
| /** | |||
| * Retrieves the instance of the Singleton. | |||
| */ | |||
| /** | |||
| * Retrieves the instance of the Singleton. | |||
| * @return singleton instance | |||
| */ | |||
| public static SelectorUtils getInstance() { | |||
| return instance; | |||
| } | |||
| @@ -110,6 +111,7 @@ public final class SelectorUtils { | |||
| public static boolean matchPatternStart(String pattern, String str) { | |||
| return matchPatternStart(pattern, str, true); | |||
| } | |||
| /** | |||
| * Tests whether or not a given path matches the start of a given | |||
| * pattern up to the first "**". | |||
| @@ -129,13 +131,13 @@ public final class SelectorUtils { | |||
| * pattern up to the first "**". | |||
| */ | |||
| public static boolean matchPatternStart(String pattern, String str, | |||
| boolean isCaseSensitive) { | |||
| boolean isCaseSensitive) { | |||
| // When str starts with a File.separator, pattern has to start with a | |||
| // File.separator. | |||
| // When pattern starts with a File.separator, str has to start with a | |||
| // File.separator. | |||
| if (str.startsWith(File.separator) != | |||
| pattern.startsWith(File.separator)) { | |||
| if (str.startsWith(File.separator) | |||
| != pattern.startsWith(File.separator)) { | |||
| return false; | |||
| } | |||
| @@ -143,9 +145,9 @@ public final class SelectorUtils { | |||
| String[] strDirs = tokenizePathAsArray(str); | |||
| int patIdxStart = 0; | |||
| int patIdxEnd = patDirs.length-1; | |||
| int patIdxEnd = patDirs.length - 1; | |||
| int strIdxStart = 0; | |||
| int strIdxEnd = strDirs.length-1; | |||
| int strIdxEnd = strDirs.length - 1; | |||
| // up to first '**' | |||
| while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { | |||
| @@ -153,8 +155,7 @@ public final class SelectorUtils { | |||
| if (patDir.equals("**")) { | |||
| break; | |||
| } | |||
| if (!match(patDir,strDirs[strIdxStart], | |||
| isCaseSensitive)) { | |||
| if (!match(patDir, strDirs[strIdxStart], isCaseSensitive)) { | |||
| return false; | |||
| } | |||
| patIdxStart++; | |||
| @@ -203,13 +204,13 @@ public final class SelectorUtils { | |||
| * or <code>false</code> otherwise. | |||
| */ | |||
| public static boolean matchPath(String pattern, String str, | |||
| boolean isCaseSensitive) { | |||
| boolean isCaseSensitive) { | |||
| // When str starts with a File.separator, pattern has to start with a | |||
| // File.separator. | |||
| // When pattern starts with a File.separator, str has to start with a | |||
| // File.separator. | |||
| if (str.startsWith(File.separator) != | |||
| pattern.startsWith(File.separator)) { | |||
| if (str.startsWith(File.separator) | |||
| != pattern.startsWith(File.separator)) { | |||
| return false; | |||
| } | |||
| @@ -217,9 +218,9 @@ public final class SelectorUtils { | |||
| String[] strDirs = tokenizePathAsArray(str); | |||
| int patIdxStart = 0; | |||
| int patIdxEnd = patDirs.length-1; | |||
| int patIdxEnd = patDirs.length - 1; | |||
| int strIdxStart = 0; | |||
| int strIdxEnd = strDirs.length-1; | |||
| int strIdxEnd = strDirs.length - 1; | |||
| // up to first '**' | |||
| while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { | |||
| @@ -227,9 +228,9 @@ public final class SelectorUtils { | |||
| if (patDir.equals("**")) { | |||
| break; | |||
| } | |||
| if (!match(patDir,strDirs[strIdxStart], | |||
| isCaseSensitive)) { | |||
| patDirs = null; strDirs = null; | |||
| if (!match(patDir, strDirs[strIdxStart], isCaseSensitive)) { | |||
| patDirs = null; | |||
| strDirs = null; | |||
| return false; | |||
| } | |||
| patIdxStart++; | |||
| @@ -239,7 +240,8 @@ public final class SelectorUtils { | |||
| // String is exhausted | |||
| for (int i = patIdxStart; i <= patIdxEnd; i++) { | |||
| if (!patDirs[i].equals("**")) { | |||
| patDirs = null; strDirs = null; | |||
| patDirs = null; | |||
| strDirs = null; | |||
| return false; | |||
| } | |||
| } | |||
| @@ -247,7 +249,8 @@ public final class SelectorUtils { | |||
| } else { | |||
| if (patIdxStart > patIdxEnd) { | |||
| // String not exhausted, but pattern is. Failure. | |||
| patDirs = null; strDirs = null; | |||
| patDirs = null; | |||
| strDirs = null; | |||
| return false; | |||
| } | |||
| } | |||
| @@ -258,9 +261,9 @@ public final class SelectorUtils { | |||
| if (patDir.equals("**")) { | |||
| break; | |||
| } | |||
| if (!match(patDir,strDirs[strIdxEnd], | |||
| isCaseSensitive)) { | |||
| patDirs = null; strDirs = null; | |||
| if (!match(patDir, strDirs[strIdxEnd], isCaseSensitive)) { | |||
| patDirs = null; | |||
| strDirs = null; | |||
| return false; | |||
| } | |||
| patIdxEnd--; | |||
| @@ -270,7 +273,8 @@ public final class SelectorUtils { | |||
| // String is exhausted | |||
| for (int i = patIdxStart; i <= patIdxEnd; i++) { | |||
| if (!patDirs[i].equals("**")) { | |||
| patDirs = null; strDirs = null; | |||
| patDirs = null; | |||
| strDirs = null; | |||
| return false; | |||
| } | |||
| } | |||
| @@ -279,48 +283,50 @@ public final class SelectorUtils { | |||
| while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) { | |||
| int patIdxTmp = -1; | |||
| for (int i = patIdxStart+1; i <= patIdxEnd; i++) { | |||
| for (int i = patIdxStart + 1; i <= patIdxEnd; i++) { | |||
| if (patDirs[i].equals("**")) { | |||
| patIdxTmp = i; | |||
| break; | |||
| } | |||
| } | |||
| if (patIdxTmp == patIdxStart+1) { | |||
| if (patIdxTmp == patIdxStart + 1) { | |||
| // '**/**' situation, so skip one | |||
| patIdxStart++; | |||
| continue; | |||
| } | |||
| // Find the pattern between padIdxStart & padIdxTmp in str between | |||
| // strIdxStart & strIdxEnd | |||
| int patLength = (patIdxTmp-patIdxStart-1); | |||
| int strLength = (strIdxEnd-strIdxStart+1); | |||
| int foundIdx = -1; | |||
| strLoop: | |||
| for (int i = 0; i <= strLength - patLength; i++) { | |||
| for (int j = 0; j < patLength; j++) { | |||
| String subPat = patDirs[patIdxStart+j+1]; | |||
| String subStr = strDirs[strIdxStart+i+j]; | |||
| if (!match(subPat,subStr, isCaseSensitive)) { | |||
| continue strLoop; | |||
| } | |||
| } | |||
| foundIdx = strIdxStart+i; | |||
| break; | |||
| } | |||
| int patLength = (patIdxTmp - patIdxStart - 1); | |||
| int strLength = (strIdxEnd - strIdxStart + 1); | |||
| int foundIdx = -1; | |||
| strLoop: | |||
| for (int i = 0; i <= strLength - patLength; i++) { | |||
| for (int j = 0; j < patLength; j++) { | |||
| String subPat = patDirs[patIdxStart + j + 1]; | |||
| String subStr = strDirs[strIdxStart + i + j]; | |||
| if (!match(subPat, subStr, isCaseSensitive)) { | |||
| continue strLoop; | |||
| } | |||
| } | |||
| foundIdx = strIdxStart + i; | |||
| break; | |||
| } | |||
| if (foundIdx == -1) { | |||
| patDirs = null; strDirs = null; | |||
| patDirs = null; | |||
| strDirs = null; | |||
| return false; | |||
| } | |||
| patIdxStart = patIdxTmp; | |||
| strIdxStart = foundIdx+patLength; | |||
| strIdxStart = foundIdx + patLength; | |||
| } | |||
| for (int i = patIdxStart; i <= patIdxEnd; i++) { | |||
| if (!patDirs[i].equals("**")) { | |||
| patDirs = null; strDirs = null; | |||
| patDirs = null; | |||
| strDirs = null; | |||
| return false; | |||
| } | |||
| } | |||
| @@ -364,13 +370,13 @@ strLoop: | |||
| * or <code>false</code> otherwise. | |||
| */ | |||
| public static boolean match(String pattern, String str, | |||
| boolean isCaseSensitive) { | |||
| boolean isCaseSensitive) { | |||
| char[] patArr = pattern.toCharArray(); | |||
| char[] strArr = str.toCharArray(); | |||
| int patIdxStart = 0; | |||
| int patIdxEnd = patArr.length-1; | |||
| int patIdxEnd = patArr.length - 1; | |||
| int strIdxStart = 0; | |||
| int strIdxEnd = strArr.length-1; | |||
| int strIdxEnd = strArr.length - 1; | |||
| char ch; | |||
| boolean containsStar = false; | |||
| @@ -390,12 +396,12 @@ strLoop: | |||
| ch = patArr[i]; | |||
| if (ch != '?') { | |||
| if (isCaseSensitive && ch != strArr[i]) { | |||
| return false;// Character mismatch | |||
| } | |||
| if (!isCaseSensitive && Character.toUpperCase(ch) != | |||
| Character.toUpperCase(strArr[i])) { | |||
| return false; // Character mismatch | |||
| } | |||
| if (!isCaseSensitive && Character.toUpperCase(ch) | |||
| != Character.toUpperCase(strArr[i])) { | |||
| return false; // Character mismatch | |||
| } | |||
| } | |||
| } | |||
| return true; // String matches against pattern | |||
| @@ -406,14 +412,14 @@ strLoop: | |||
| } | |||
| // Process characters before first star | |||
| while((ch = patArr[patIdxStart]) != '*' && strIdxStart <= strIdxEnd) { | |||
| while ((ch = patArr[patIdxStart]) != '*' && strIdxStart <= strIdxEnd) { | |||
| if (ch != '?') { | |||
| if (isCaseSensitive && ch != strArr[strIdxStart]) { | |||
| return false;// Character mismatch | |||
| return false; // Character mismatch | |||
| } | |||
| if (!isCaseSensitive && Character.toUpperCase(ch) != | |||
| Character.toUpperCase(strArr[strIdxStart])) { | |||
| return false;// Character mismatch | |||
| if (!isCaseSensitive && Character.toUpperCase(ch) | |||
| != Character.toUpperCase(strArr[strIdxStart])) { | |||
| return false; // Character mismatch | |||
| } | |||
| } | |||
| patIdxStart++; | |||
| @@ -431,14 +437,14 @@ strLoop: | |||
| } | |||
| // Process characters after last star | |||
| while((ch = patArr[patIdxEnd]) != '*' && strIdxStart <= strIdxEnd) { | |||
| while ((ch = patArr[patIdxEnd]) != '*' && strIdxStart <= strIdxEnd) { | |||
| if (ch != '?') { | |||
| if (isCaseSensitive && ch != strArr[strIdxEnd]) { | |||
| return false;// Character mismatch | |||
| return false; // Character mismatch | |||
| } | |||
| if (!isCaseSensitive && Character.toUpperCase(ch) != | |||
| Character.toUpperCase(strArr[strIdxEnd])) { | |||
| return false;// Character mismatch | |||
| if (!isCaseSensitive && Character.toUpperCase(ch) | |||
| != Character.toUpperCase(strArr[strIdxEnd])) { | |||
| return false; // Character mismatch | |||
| } | |||
| } | |||
| patIdxEnd--; | |||
| @@ -459,38 +465,40 @@ strLoop: | |||
| // always to a '*'. | |||
| while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) { | |||
| int patIdxTmp = -1; | |||
| for (int i = patIdxStart+1; i <= patIdxEnd; i++) { | |||
| for (int i = patIdxStart + 1; i <= patIdxEnd; i++) { | |||
| if (patArr[i] == '*') { | |||
| patIdxTmp = i; | |||
| break; | |||
| } | |||
| } | |||
| if (patIdxTmp == patIdxStart+1) { | |||
| if (patIdxTmp == patIdxStart + 1) { | |||
| // Two stars next to each other, skip the first one. | |||
| patIdxStart++; | |||
| continue; | |||
| } | |||
| // Find the pattern between padIdxStart & padIdxTmp in str between | |||
| // strIdxStart & strIdxEnd | |||
| int patLength = (patIdxTmp-patIdxStart-1); | |||
| int strLength = (strIdxEnd-strIdxStart+1); | |||
| int foundIdx = -1; | |||
| int patLength = (patIdxTmp - patIdxStart - 1); | |||
| int strLength = (strIdxEnd - strIdxStart + 1); | |||
| int foundIdx = -1; | |||
| strLoop: | |||
| for (int i = 0; i <= strLength - patLength; i++) { | |||
| for (int j = 0; j < patLength; j++) { | |||
| ch = patArr[patIdxStart+j+1]; | |||
| ch = patArr[patIdxStart + j + 1]; | |||
| if (ch != '?') { | |||
| if (isCaseSensitive && ch != strArr[strIdxStart+i+j]) { | |||
| if (isCaseSensitive && ch != strArr[strIdxStart + i | |||
| + j]) { | |||
| continue strLoop; | |||
| } | |||
| if (!isCaseSensitive && Character.toUpperCase(ch) != | |||
| Character.toUpperCase(strArr[strIdxStart+i+j])) { | |||
| Character.toUpperCase(strArr[strIdxStart + i | |||
| + j])) { | |||
| continue strLoop; | |||
| } | |||
| } | |||
| } | |||
| foundIdx = strIdxStart+i; | |||
| foundIdx = strIdxStart + i; | |||
| break; | |||
| } | |||
| @@ -499,7 +507,7 @@ strLoop: | |||
| } | |||
| patIdxStart = patIdxTmp; | |||
| strIdxStart = foundIdx+patLength; | |||
| strIdxStart = foundIdx + patLength; | |||
| } | |||
| // All characters in the string are used. Check if only '*'s are left | |||
| @@ -520,15 +528,15 @@ strLoop: | |||
| * | |||
| * @return a Vector of path elements from the tokenized path | |||
| */ | |||
| public static Vector tokenizePath (String path) { | |||
| public static Vector tokenizePath(String path) { | |||
| Vector ret = new Vector(); | |||
| StringTokenizer st = new StringTokenizer(path,File.separator); | |||
| StringTokenizer st = new StringTokenizer(path, File.separator); | |||
| while (st.hasMoreTokens()) { | |||
| ret.addElement(st.nextToken()); | |||
| } | |||
| return ret; | |||
| } | |||
| /** | |||
| * Same as {@link #tokenizePath tokenizePath} but hopefully faster. | |||
| */ | |||
| @@ -609,7 +617,7 @@ strLoop: | |||
| * determining out of dateness | |||
| * @return whether the target is out of date | |||
| */ | |||
| public static boolean isOutOfDate(Resource src, Resource target, | |||
| public static boolean isOutOfDate(Resource src, Resource target, | |||
| int granularity) { | |||
| if (!src.isExists()) { | |||
| return false; | |||
| @@ -623,7 +631,7 @@ strLoop: | |||
| return false; | |||
| } | |||
| /** | |||
| /** | |||
| * "Flattens" a string by removing all whitespace (space, tab, linefeed, | |||
| * carriage return, and formfeed). This uses StringTokenizer and the | |||
| * default set of tokens as documented in the single arguement constructor. | |||
| @@ -634,10 +642,10 @@ strLoop: | |||
| public static String removeWhitespace(String input) { | |||
| StringBuffer result = new StringBuffer(); | |||
| if (input != null) { | |||
| StringTokenizer st = new StringTokenizer(input); | |||
| while (st.hasMoreTokens()){ | |||
| result.append(st.nextToken()); | |||
| } | |||
| StringTokenizer st = new StringTokenizer(input); | |||
| while (st.hasMoreTokens()) { | |||
| result.append(st.nextToken()); | |||
| } | |||
| } | |||
| return result.toString(); | |||
| } | |||
| @@ -55,6 +55,7 @@ | |||
| package org.apache.tools.ant.types.selectors; | |||
| import java.io.File; | |||
| import org.apache.tools.ant.types.EnumeratedAttribute; | |||
| import org.apache.tools.ant.types.Parameter; | |||
| @@ -83,8 +84,7 @@ public class SizeSelector extends BaseExtendSelector { | |||
| buf.append("compare: "); | |||
| if (cmp == 0) { | |||
| buf.append("less"); | |||
| } | |||
| else if (cmp == 1) { | |||
| } else if (cmp == 1) { | |||
| buf.append("more"); | |||
| } else { | |||
| buf.append("equal"); | |||
| @@ -138,26 +138,19 @@ public class SizeSelector extends BaseExtendSelector { | |||
| multiplier = 0; | |||
| if ((i > -1) && (i < 4)) { | |||
| multiplier = 1000; | |||
| } | |||
| else if ((i > 3) && (i < 9)) { | |||
| } else if ((i > 3) && (i < 9)) { | |||
| multiplier = 1024; | |||
| } | |||
| else if ((i > 8) && (i < 13)) { | |||
| } else if ((i > 8) && (i < 13)) { | |||
| multiplier = 1000000; | |||
| } | |||
| else if ((i > 12) && (i < 18)) { | |||
| } else if ((i > 12) && (i < 18)) { | |||
| multiplier = 1048576; | |||
| } | |||
| else if ((i > 17) && (i < 22)) { | |||
| } else if ((i > 17) && (i < 22)) { | |||
| multiplier = 1000000000L; | |||
| } | |||
| else if ((i > 21) && (i < 27)) { | |||
| } else if ((i > 21) && (i < 27)) { | |||
| multiplier = 1073741824L; | |||
| } | |||
| else if ((i > 26) && (i < 31)) { | |||
| } else if ((i > 26) && (i < 31)) { | |||
| multiplier = 1000000000000L; | |||
| } | |||
| else if ((i > 30) && (i < 36)) { | |||
| } else if ((i > 30) && (i < 36)) { | |||
| multiplier = 1099511627776L; | |||
| } | |||
| if ((multiplier > 0) && (size > -1)) { | |||
| @@ -190,23 +183,20 @@ public class SizeSelector extends BaseExtendSelector { | |||
| if (SIZE_KEY.equalsIgnoreCase(paramname)) { | |||
| try { | |||
| setValue(new Long(parameters[i].getValue() | |||
| ).longValue()); | |||
| ).longValue()); | |||
| } catch (NumberFormatException nfe) { | |||
| setError("Invalid size setting " | |||
| + parameters[i].getValue()); | |||
| + parameters[i].getValue()); | |||
| } | |||
| } | |||
| else if (UNITS_KEY.equalsIgnoreCase(paramname)) { | |||
| } else if (UNITS_KEY.equalsIgnoreCase(paramname)) { | |||
| ByteUnits units = new ByteUnits(); | |||
| units.setValue(parameters[i].getValue()); | |||
| setUnits(units); | |||
| } | |||
| else if (WHEN_KEY.equalsIgnoreCase(paramname)) { | |||
| } else if (WHEN_KEY.equalsIgnoreCase(paramname)) { | |||
| SizeComparisons cmp = new SizeComparisons(); | |||
| cmp.setValue(parameters[i].getValue()); | |||
| setWhen(cmp); | |||
| } | |||
| else { | |||
| } else { | |||
| setError("Invalid parameter " + paramname); | |||
| } | |||
| } | |||
| @@ -226,11 +216,9 @@ public class SizeSelector extends BaseExtendSelector { | |||
| public void verifySettings() { | |||
| if (size < 0) { | |||
| setError("The value attribute is required, and must be positive"); | |||
| } | |||
| else if (multiplier < 1) { | |||
| } else if (multiplier < 1) { | |||
| setError("Invalid Units supplied, must be K,Ki,M,Mi,G,Gi,T,or Ti"); | |||
| } | |||
| else if (sizelimit < 0) { | |||
| } else if (sizelimit < 0) { | |||
| setError("Internal error: Code is not setting sizelimit correctly"); | |||
| } | |||
| } | |||
| @@ -255,17 +243,14 @@ public class SizeSelector extends BaseExtendSelector { | |||
| } | |||
| if (cmp == 0) { | |||
| return (file.length() < sizelimit); | |||
| } | |||
| else if (cmp == 1) { | |||
| } else if (cmp == 1) { | |||
| return (file.length() > sizelimit); | |||
| } | |||
| else { | |||
| } else { | |||
| return (file.length() == sizelimit); | |||
| } | |||
| } | |||
| /** | |||
| * Enumerated attribute with the values for units. | |||
| * <p> | |||
| @@ -286,15 +271,15 @@ public class SizeSelector extends BaseExtendSelector { | |||
| */ | |||
| public static class ByteUnits extends EnumeratedAttribute { | |||
| public String[] getValues() { | |||
| return new String[] {"K", "k", "kilo", "KILO", | |||
| "Ki", "KI", "ki", "kibi", "KIBI", | |||
| "M", "m", "mega", "MEGA", | |||
| "Mi", "MI", "mi", "mebi", "MEBI", | |||
| "G", "g", "giga", "GIGA", | |||
| "Gi", "GI", "gi", "gibi", "GIBI", | |||
| "T", "t", "tera", "TERA", | |||
| /* You wish! */ "Ti", "TI", "ti", "tebi", "TEBI" | |||
| }; | |||
| return new String[]{"K", "k", "kilo", "KILO", | |||
| "Ki", "KI", "ki", "kibi", "KIBI", | |||
| "M", "m", "mega", "MEGA", | |||
| "Mi", "MI", "mi", "mebi", "MEBI", | |||
| "G", "g", "giga", "GIGA", | |||
| "Gi", "GI", "gi", "gibi", "GIBI", | |||
| "T", "t", "tera", "TERA", | |||
| /* You wish! */ "Ti", "TI", "ti", "tebi", "TEBI" | |||
| }; | |||
| } | |||
| } | |||
| @@ -303,7 +288,7 @@ public class SizeSelector extends BaseExtendSelector { | |||
| */ | |||
| public static class SizeComparisons extends EnumeratedAttribute { | |||
| public String[] getValues() { | |||
| return new String[] {"less", "more", "equal"}; | |||
| return new String[]{"less", "more", "equal"}; | |||
| } | |||
| } | |||
| @@ -55,6 +55,7 @@ | |||
| package org.apache.tools.ant.types.selectors; | |||
| import java.io.File; | |||
| import org.apache.tools.ant.types.EnumeratedAttribute; | |||
| import org.apache.tools.ant.types.Parameter; | |||
| @@ -102,8 +103,7 @@ public class TypeSelector extends BaseExtendSelector { | |||
| FileType type = new FileType(); | |||
| type.setValue(parameters[i].getValue()); | |||
| setType(type); | |||
| } | |||
| else { | |||
| } else { | |||
| setError("Invalid parameter " + paramname); | |||
| } | |||
| } | |||
| @@ -137,17 +137,20 @@ public class TypeSelector extends BaseExtendSelector { | |||
| if (file.isDirectory()) { | |||
| return type.equals(FileType.DIR); | |||
| } else return type.equals(FileType.FILE); | |||
| } else { | |||
| return type.equals(FileType.FILE); | |||
| } | |||
| } | |||
| /** | |||
| * Enumerated attribute with the values for types of file | |||
| */ | |||
| public static class FileType extends EnumeratedAttribute { | |||
| public static final String FILE="file"; | |||
| public static final String DIR="dir"; | |||
| public static final String FILE = "file"; | |||
| public static final String DIR = "dir"; | |||
| public String[] getValues() { | |||
| return new String[] {FILE, DIR}; | |||
| return new String[]{FILE, DIR}; | |||
| } | |||
| } | |||