Browse Source

Small redesign of ModifiedSelector. Integrating BugIDs 29742+29743. Adding support of custom classes. Checkstyle.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276688 13f79535-47bb-0310-9956-ffa450edef68
master
Jan Materne 21 years ago
parent
commit
590844e775
9 changed files with 1209 additions and 371 deletions
  1. +70
    -3
      docs/manual/CoreTypes/selectors.html
  2. +15
    -0
      src/etc/testcases/types/selectors.xml
  3. +4
    -5
      src/main/org/apache/tools/ant/types/selectors/modifiedselector/DigestAlgorithm.java
  4. +331
    -69
      src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java
  5. +20
    -2
      src/main/org/apache/tools/ant/types/selectors/modifiedselector/PropertiesfileCache.java
  6. +36
    -0
      src/testcases/org/apache/tools/ant/types/selectors/MockAlgorithm.java
  7. +67
    -0
      src/testcases/org/apache/tools/ant/types/selectors/MockCache.java
  8. +31
    -0
      src/testcases/org/apache/tools/ant/types/selectors/MockComparator.java
  9. +635
    -292
      src/testcases/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java

+ 70
- 3
docs/manual/CoreTypes/selectors.html View File

@@ -2,7 +2,7 @@
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>Selectors in Ant</title>
<link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
<link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
</head>

<body>
@@ -652,6 +652,7 @@
<ul>
<li> hashvalue - HashvalueAlgorithm </li>
<li> digest - DigestAlgorithm </li>
<li> checksum - ChecksumAlgorithm </li>
</ul>
</td>
<td valign="top" align="center"> No, defaults to <i>digest</i> </td>
@@ -672,11 +673,35 @@
Acceptable values are (further information see later):
<ul>
<li> equal - EqualComparator </li>
<li> rule - java.text.RuleBasedCollator </li>
<li> rule - java.text.RuleBasedCollator
<!-- NOTE -->
<i>(see <a href="#ModSelNote">note</a> for restrictions)</i>
</li>
</ul>
</td>
<td valign="top" align="center"> No, defaults to <i>equal</i> </td>
</tr>
<tr>
<td valign="top"> algorithmclass </td>
<td valign="top"> Classname of custom algorithm implementation. Lower
priority than <i>algorithm</i>.
<!-- NOTE --> (see <a href="#ModSelNote">note</a> for restrictions) </td>
<td valign="top" align="center"> No </td>
</tr>
<tr>
<td valign="top"> cacheclass </td>
<td valign="top"> Classname of custom cache implementation. Lower
priority than <i>cache</i>.
<!-- NOTE --> (see <a href="#ModSelNote">note</a> for restrictions) </td>
<td valign="top" align="center"> No </td>
</tr>
<tr>
<td valign="top"> comparatorclass </td>
<td valign="top"> Classname of custom comparator implementation. Lower
priority than <i>comparator</i>.
<!-- NOTE --> (see <a href="#ModSelNote">note</a> for restrictions) </td>
<td valign="top" align="center"> No </td>
</tr>
<tr>
<td valign="top"> update </td>
<td valign="top"> Should the cache be updated when values differ? (boolean) </td>
@@ -687,6 +712,15 @@
<td valign="top"> Should directories be selected? (boolean) </td>
<td valign="top" align="center"> No, defaults to <i>true</i> </td>
</tr>
<tr>
<td valign="top"> delayupdate </td>
<td valign="top"> If set to <i>true</i>, the storage of the cache will be delayed until the
next finished BuildEvent; task finished, target finished or build finished,
whichever comes first. This is provided for increased performance. If set
to <i>false</i>, the storage of the cache will happen with each change. This
attribute depends upon the <i>update</i> attribute. (boolean)</td>
<td valign="top" align="center"> No, defaults to <i>true</i> </td>
</tr>
</table>

<p>These attributes can be set with nested &lt;param/&gt; tags. With &lt;param/&gt;
@@ -695,6 +729,9 @@
<li> <b> algorithm </b>: same as attribute algorithm </li>
<li> <b> cache </b>: same as attribute cache </li>
<li> <b> comparator </b>: same as attribute comparator </li>
<li> <b> algorithmclass </b>: same as attribute algorithmclass </li>
<li> <b> cacheclass </b>: same as attribute cacheclass </li>
<li> <b> comparatorclass </b>: same as attribute comparatorclass </li>
<li> <b> update </b>: same as attribute update </li>
<li> <b> seldirs </b>: same as attribute seldirs </li>
<li> <b> algorithm.* </b>: Value is transfered to the algorithm via its
@@ -729,6 +766,16 @@
</ul>
</td>
</tr>
<tr>
<td valign="top"> checksum </td>
<td valign="top"> Uses java.util.zip.Checksum. This Algorithm supports
the following attributes:
<ul>
<li><i>algorithm.algorithm</i> (optional): Name of the algorithm
(e.g. 'CRC' or 'ADLER', default = <i>CRC</i>) </li>
</ul>
</td>
</tr>
<tr><td colspan="2"><font size="+1"><b> Cache's </b></font></td></tr>
<tr>
<td valign="top"> propertyfile </td>
@@ -750,6 +797,8 @@
<td valign="top"> rule </td>
<td valign="top"> Uses <i>java.text.RuleBasedCollator</i> for Object
comparison.
<!-- NOTE -->
<i>(see <a href="#ModSelNote">note</a> for restrictions)</i>
</td>
</tr>
</table>
@@ -820,6 +869,24 @@
CacheSelector saves therefore much upload time.</p>


<!-- NOTE -->
<i>(see <a href="#ModSelNote">note</a> for restrictions)</i>
<a name="ModSelNote"></a>
<h4>Note on RuleBasedCollator</h4>
<p>The RuleBasedCollator needs a format for its work, but its needed while
instantiation. There is a problem in the initialization algorithm for this
case. Therefore you should not use this (or tell me the workaround :-).</p>

<p>The selector can not find the specified algorithm-, cache- or comparator-
class if the selector is loaded from a different classloader.
To be able to use your own classes you have to ensure that the selector
can find the classes by adding the your package to the core: <ul>
<li> by placing your JAR in %ANT_HOME/lib </li>
<li> by adding '-lib myclasses/' while invocation </li>
<li> by placing your JAR in ${ant.home}/.ant/lib </li>
</ul></p>


<a name="selectcontainers"></a>
<h3>Selector Containers</h3>

@@ -1216,4 +1283,4 @@

</body>

</html>
</html>

+ 15
- 0
src/etc/testcases/types/selectors.xml View File

@@ -242,4 +242,19 @@
</copy>
</target>

<target name="modifiedselectortest-customClasses" depends="modifiedselectortest-scenario-prepare">
<property name="pkg.live" value="org.apache.tools.ant.types.selectors.modifiedselector"/>
<property name="pkg.test" value="org.apache.tools.ant.types.selectors"/>
<fileset id="fs.mod" dir="${test.dir}/src">
<modified
algorithmclass="${pkg.test}.MockAlgorithm"
cacheclass="${pkg.test}.MockCache"
comparatorclass="${pkg.test}.MockComparator"
/>
</fileset>
<fileset id="fs.full" dir="${test.dir}/src"/>
<property name="fs.mod.value" refid="fs.mod"/>
<property name="fs.full.value" refid="fs.full"/>
</target>

</project>

+ 4
- 5
src/main/org/apache/tools/ant/types/selectors/modifiedselector/DigestAlgorithm.java View File

@@ -51,7 +51,7 @@ import org.apache.tools.ant.BuildException;
* </tr>
* </table>
*
* @version 2003-09-13
* @version 2004-07-08
* @since Ant 1.6
*/
public class DigestAlgorithm implements Algorithm {
@@ -132,12 +132,11 @@ public class DigestAlgorithm implements Algorithm {


/**
* This algorithm doesn't need any configuration.
* Therefore it's always valid.
* This algorithm supports only MD5 and SHA.
* @return <i>true</i> if all is ok, otherwise <i>false</i>.
*/
public boolean isValid() {
return true;
return "SHA".equalsIgnoreCase(algorithm) || "MD5".equalsIgnoreCase(algorithm);
}


@@ -200,4 +199,4 @@ public class DigestAlgorithm implements Algorithm {
buf.append(">");
return buf.toString();
}
}
}

+ 331
- 69
src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java View File

@@ -27,6 +27,9 @@ import java.io.File;
// Ant
import org.apache.tools.ant.Project;
import org.apache.tools.ant.IntrospectionHelper;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.Parameter;
import org.apache.tools.ant.types.selectors.BaseExtendSelector;
@@ -93,7 +96,7 @@ import org.apache.tools.ant.types.selectors.BaseExtendSelector;
* comparison.</p>
*
* <p>A useful scenario for this selector is inside a build environment
* for homepage generation (e.g. with <a href="http://xml.apache.org/forrest/">
* for homepage generation (e.g. with <a href="http://forrest.apache.org/">
* Apache Forrest</a>). <pre>
* <target name="generate-and-upload-site">
* <echo> generate the site using forrest </echo>
@@ -109,7 +112,7 @@ import org.apache.tools.ant.types.selectors.BaseExtendSelector;
* </pre> Here all <b>changed</b> files are uploaded to the server. The
* ModifiedSelector saves therefore much upload time.</p>
*
* <p>This selector supports the following nested param's:
* <p>This selector supports the following attributes:
* <table>
* <tr><th>name</th><th>values</th><th>description</th><th>required</th></tr>
* <tr>
@@ -122,20 +125,21 @@ import org.apache.tools.ant.types.selectors.BaseExtendSelector;
* </tr>
* <tr>
* <td> algorithm </td>
* <td> hashvalue | digest </td>
* <td> hashvalue | digest | checksum </td>
* <td> which algorithm implementation should be used
* <li><b>hashvalue</b> - loads the file content into a String and
* uses its hashValue() method </li>
* <li><b>digest</b> - uses java.security.MessageDigest class </i>
* <li><b>checksum</b> - uses java.util.zip.Checksum interface </i>
* </td>
* <td> no, defaults to digest </td>
* </tr>
* <tr>
* <td> comparator </td>
* <td> equal | role </td>
* <td> equal | rule </td>
* <td> which comparator implementation should be used
* <li><b>equal</b> - simple comparison using String.equals() </li>
* <li><b>role</b> - uses java.text.RuleBasedCollator class </i>
* <li><b>rule</b> - uses java.text.RuleBasedCollator class </i>
* </td>
* <td> no, defaults to equal </td>
* </tr>
@@ -153,6 +157,34 @@ import org.apache.tools.ant.types.selectors.BaseExtendSelector;
* <td> no, defaults to true </td>
* </tr>
* <tr>
* <td> delayupdate </td>
* <td> true | false </td>
* <td> If set to <i>true</i>, the storage of the cache will be delayed until the
* next finished BuildEvent; task finished, target finished or build finished,
* whichever comes first. This is provided for increased performance. If set
* to <i>false</i>, the storage of the cache will happen with each change. This
* attribute depends upon the <i>update</i> attribute.</td>
* <td> no, defaults to true </td>
* </tr>
* <tr>
* <td> cacheclass </td>
* <td> <i>classname</i> </td>
* <td> which custom cache implementation should be used </td>
* <td> no </td>
* </tr>
* <tr>
* <td> algorithmclass </td>
* <td> <i>classname</i> </td>
* <td> which custom algorithm implementation should be used </td>
* <td> no </td>
* </tr>
* <tr>
* <td> comparatorclass </td>
* <td> <i>classname</i> </td>
* <td> which custom comparator implementation should be used </td>
* <td> no </td>
* </tr>
* <tr>
* <td> cache.* </td>
* <td> depends on used cache </td>
* <td> value is stored and given to the Cache-Object for initialisation </td>
@@ -182,23 +214,32 @@ import org.apache.tools.ant.types.selectors.BaseExtendSelector;
* a nested <i><param name="algorithm.provider" value="MyProvider"/></i>.
*
*
* @version 2003-09-13
* @version 2004-07-09
* @since Ant 1.6
*/
public class ModifiedSelector extends BaseExtendSelector {
*/
public class ModifiedSelector extends BaseExtendSelector implements BuildListener {


// ----- member variables - configuration
// ----- attributes -----


/** The Cache containing the old values. */
private Cache cache = null;
/** Cache name for later instantiation. */
private CacheName cacheName = null;

/** Algorithm for computing new values and updating the cache. */
private Algorithm algorithm = null;
/** User specified classname for Cache. */
private String cacheClass;

/** How should the cached value and the new one compared? */
private Comparator comparator = null;
/** Algorithm name for later instantiation. */
private AlgorithmName algoName = null;

/** User specified classname for Algorithm. */
private String algorithmClass;

/** Comparator name for later instantiation. */
private ComparatorName compName = null;

/** User specified classname for Comparator. */
private String comparatorClass;

/** Should the cache be updated? */
private boolean update = true;
@@ -206,22 +247,27 @@ public class ModifiedSelector extends BaseExtendSelector {
/** Are directories selected? */
private boolean selectDirectories = true;

/** Delay the writing of the cache file */
private boolean delayUpdate = true;

// ----- member variables - internal use

// ----- internal member variables -----

/** Flag whether this object is configured. Configuration is only done once. */
private boolean isConfigured = false;

/** Algorithm name for later instantiation. */
private AlgorithmName algoName = null;
/** How should the cached value and the new one compared? */
private Comparator comparator = null;

/** Cache name for later instantiation. */
private CacheName cacheName = null;
/** Algorithm for computing new values and updating the cache. */
private Algorithm algorithm = null;

/** Comparator name for later instantiation. */
private ComparatorName compName = null;
/** The Cache containing the old values. */
private Cache cache = null;

/** Count of modified properties */
private int modified = 0;

/** Flag whether this object is configured. Configuration is only done once. */
private boolean isConfigured = false;

/**
* Parameter vector with parameters for later initialization.
@@ -293,23 +339,26 @@ public class ModifiedSelector extends BaseExtendSelector {
//
// ----- Set default values -----
//
org.apache.tools.ant.Project project = getProject();
Project project = getProject();
String filename = "cache.properties";
File cachefile = null;
if (project != null) {
// normal use inside Ant
cachefile = new File(project.getBaseDir(), filename);

// set self as a BuildListener to delay cachefile saves
getProject().addBuildListener(this);
} else {
// no reference to project - e.g. during JUnit tests
// no reference to project - e.g. during normal JUnit tests
cachefile = new File(filename);
setDelayUpdate(false);
}
cache = new PropertiesfileCache(cachefile);
algorithm = new DigestAlgorithm();
comparator = new EqualComparator();
Cache defaultCache = new PropertiesfileCache(cachefile);
Algorithm defaultAlgorithm = new DigestAlgorithm();
Comparator defaultComparator = new EqualComparator();
update = true;
selectDirectories = true;


//
// ----- Set the main attributes, pattern '*' -----
//
@@ -328,54 +377,70 @@ public class ModifiedSelector extends BaseExtendSelector {
// ----- Instantiate the interfaces -----
//
String className = null;
String pkg = "org.apache.tools.ant.types.selectors.cacheselector";
String pkg = "org.apache.tools.ant.types.selectors.modifiedselector";

// the algorithm
if (algorithm == null) {
// specify the algorithm classname
if (algoName != null) {
// use Algorithm defined via name
if ("hashvalue".equals(algoName.getValue())) {
className = pkg + ".HashvalueAlgorithm";
algorithm = new HashvalueAlgorithm();
} else if ("digest".equals(algoName.getValue())) {
className = pkg + ".DigestAlgorithm";
algorithm = new DigestAlgorithm();
} else if ("checksum".equals(algoName.getValue())) {
algorithm = new ChecksumAlgorithm();
}
if (className != null) {
try {
// load the specified Algorithm, save the reference and configure it
algorithm = (Algorithm) Class.forName(className).newInstance();
} catch (Exception e) {
e.printStackTrace();
}
} else {
if (algorithmClass != null) {
// use Algorithm specified by classname
algorithm = (Algorithm) loadClass(
algorithmClass,
"is not an Algorithm.",
Algorithm.class);
} else {
// nothing specified - use default
algorithm = defaultAlgorithm;
}
}

// the cache
if (cache == null) {
// specify the cache classname
if (cacheName != null) {
// use Cache defined via name
if ("propertyfile".equals(cacheName.getValue())) {
className = pkg + ".PropertiesfileCache";
cache = new PropertiesfileCache();
}
if (className != null) {
try {
// load the specified Cache, save the reference and configure it
cache = (Cache) Class.forName(className).newInstance();
} catch (Exception e) {
e.printStackTrace();
}
} else {
if (cacheClass != null) {
// use Cache specified by classname
cache = (Cache) loadClass(cacheClass, "is not a Cache.", Cache.class);
} else {
// nothing specified - use default
cache = defaultCache;
}
}

// the comparator
if (comparator == null) {
// specify the comparator classname
if (compName != null) {
// use Algorithm defined via name
if ("equal".equals(compName.getValue())) {
className = pkg + ".EqualComparator";
} else if ("role".equals(compName.getValue())) {
className = "java.text.RuleBasedCollator";
comparator = new EqualComparator();
} else if ("rule".equals(compName.getValue())) {
// TODO there is a problem with the constructor for the RBC.
// you have to provide the rules in the constructors - no setters
// available.
throw new BuildException("RuleBasedCollator not yet supported.");
// Have to think about lazy initialization here... JHM
// comparator = new java.text.RuleBasedCollator();
}
if (className != null) {
try {
// load the specified Cache, save the reference and configure it
comparator = (Comparator) Class.forName(className).newInstance();
} catch (Exception e) {
e.printStackTrace();
}
} else {
if (comparatorClass != null) {
// use Algorithm specified by classname
comparator = (Comparator) loadClass(
comparatorClass,
"is not a Comparator.",
Comparator.class);
} else {
// nothing specified - use default
comparator = defaultComparator;
}
}

@@ -390,6 +455,47 @@ public class ModifiedSelector extends BaseExtendSelector {
}


/**
* Loads the specified class and initializes an object of that class.
* Throws a BuildException using the given message if an error occurs during
* loading/instantiation or if the object is not from the given type.
* @param classname the classname
* @param msg the message-part for the BuildException
* @param type the type to check against
* @return a castable object
*/
protected Object loadClass(String classname, String msg, Class type) {
try {
// load the specified class

/* TODO: the selector cant find the specified class if the
* selector is loaded from a different classloader.
* See ModifiedSelectorTest.testCustom<Algorithm|Cache|Comparator|Classes>().
* To be able to run these tests you have to ensure that <junit> can find
* the classes by adding the test package to the core:
* - by placing the ant-testutils.jar in %ANT_HOME/lib
* - by adding '-lib build/testcases' while invocation
*
* IMO this is not only a problem for the Mock-Classes inside the
* tests. The *classname attributes are designed for the user to
* provide his own implementations. Therefore they should be
* found ... Workaround again: -lib, ~/.ant/lib, ant.home/lib
* JHM
*/
Object rv = Class.forName(classname).newInstance();
if (!type.isInstance(rv)) {
throw new BuildException("Specified class (" + classname + ") " + msg);
}
return rv;
} catch (ClassNotFoundException e) {
throw new BuildException("Specified class (" + classname + ") not found.");
} catch (Exception e) {
throw new BuildException(e);
}
}



// ----- the selection work -----


@@ -412,21 +518,63 @@ public class ModifiedSelector extends BaseExtendSelector {
// Get the values and do the comparison
String cachedValue = String.valueOf(cache.get(f.getAbsolutePath()));
String newValue = algorithm.getValue(f);

boolean rv = (comparator.compare(cachedValue, newValue) != 0);

// Maybe update the cache
if (update && !cachedValue.equals(newValue)) {
if (update && rv) {
cache.put(f.getAbsolutePath(), newValue);
cache.save();
setModified(getModified() + 1);
if (!getDelayUpdate()) {
saveCache();
}
}

return rv;
}


/**
* save the cache file
*/
protected void saveCache() {
if (getModified() > 1) {
cache.save();
setModified(0);
}
}


// ----- attribute and nested element support -----


/**
* Setter for algorithmClass.
* @param classname new value
*/
public void setAlgorithmClass(String classname) {
algorithmClass = classname;
}


/**
* Setter for comparatorClass.
* @param classname new value
*/
public void setComparatorClass(String classname) {
comparatorClass = classname;
}


/**
* Setter for cacheClass.
* @param classname new value
*/
public void setCacheClass(String classname) {
cacheClass = classname;
}


/**
* Support for <i>update</i> attribute.
* @param update new value
@@ -445,6 +593,42 @@ public class ModifiedSelector extends BaseExtendSelector {
}


/**
* Getter for the modified count
* @return modified count
*/
public int getModified() {
return modified;
}


/**
* Setter for the modified count
* @param modified count
*/
public void setModified(int modified) {
this.modified = modified;
}


/**
* Getter for the delay update
* @return true if we should delay for performance
*/
public boolean getDelayUpdate() {
return delayUpdate;
}


/**
* Setter for the delay update
* @param delayUpdate true if we should delay for performance
*/
public void setDelayUpdate(boolean delayUpdate) {
this.delayUpdate = delayUpdate;
}


/**
* Support for nested &lt;param&gt; tags.
* @param key the key of the parameter
@@ -516,6 +700,12 @@ public class ModifiedSelector extends BaseExtendSelector {
? true
: false;
setUpdate(updateValue);
} else if ("delayupdate".equals(key)) {
boolean updateValue =
("true".equalsIgnoreCase(value))
? true
: false;
setDelayUpdate(updateValue);
} else if ("seldirs".equals(key)) {
boolean sdValue =
("true".equalsIgnoreCase(value))
@@ -548,7 +738,6 @@ public class ModifiedSelector extends BaseExtendSelector {
Project prj = (getProject() != null) ? getProject() : new Project();
IntrospectionHelper iHelper
= IntrospectionHelper.getHelper(prj, obj.getClass());

try {
iHelper.setAttribute(prj, obj, name, value);
} catch (org.apache.tools.ant.BuildException e) {
@@ -576,6 +765,79 @@ public class ModifiedSelector extends BaseExtendSelector {
}


// ----- BuildListener interface methods -----


/**
* Signals that the last target has finished.
* @param event recieved BuildEvent
*/
public void buildFinished(BuildEvent event) {
if (getDelayUpdate()) {
saveCache();
}
}


/**
* Signals that a target has finished.
* @param event recieved BuildEvent
*/
public void targetFinished(BuildEvent event) {
if (getDelayUpdate()) {
saveCache();
}
}


/**
* Signals that a task has finished.
* @param event recieved BuildEvent
*/
public void taskFinished(BuildEvent event) {
if (getDelayUpdate()) {
saveCache();
}
}


/**
* Signals that a build has started.
* @param event recieved BuildEvent
*/
public void buildStarted(BuildEvent event) {
// no-op
}


/**
* Signals that a target is starting.
* @param event recieved BuildEvent
*/
public void targetStarted(BuildEvent event) {
// no-op
}



/**
* Signals that a task is starting.
* @param event recieved BuildEvent
*/
public void taskStarted(BuildEvent event) {
// no-op
}


/**
* Signals a message logging event.
* @param event recieved BuildEvent
*/
public void messageLogged(BuildEvent event) {
// no-op
}


// The EnumeratedAttributes for the three interface implementations.
// Name-Classname mapping is done in the configure() method.

@@ -597,7 +859,7 @@ public class ModifiedSelector extends BaseExtendSelector {
}
public static class AlgorithmName extends EnumeratedAttribute {
public String[] getValues() {
return new String[] {"hashvalue", "digest" };
return new String[] {"hashvalue", "digest", "checksum" };
}
}

@@ -612,4 +874,4 @@ public class ModifiedSelector extends BaseExtendSelector {
}
}

}
} //class-ModifiedSelector

+ 20
- 2
src/main/org/apache/tools/ant/types/selectors/modifiedselector/PropertiesfileCache.java View File

@@ -96,12 +96,27 @@ public class PropertiesfileCache implements Cache {
// ----- Cache-Configuration -----


/**
* Setter.
* @param file new value
*/
public void setCachefile(File file) {
cachefile = file;
}

public File getCachefile() { return cachefile; }

/**
* Getter.
* @return the cachefile
*/
public File getCachefile() {
return cachefile;
}

/**
* This cache is valid if the cachefile is set.
* @return true if all is ok false otherwise
*/
public boolean isValid() {
return (cachefile != null);
}
@@ -110,6 +125,9 @@ public class PropertiesfileCache implements Cache {
// ----- Data Access


/**
* Load the cache from underlying properties file.
*/
public void load() {
if ((cachefile != null) && cachefile.isFile() && cachefile.canRead()) {
try {
@@ -214,4 +232,4 @@ public class PropertiesfileCache implements Cache {
buf.append(">");
return buf.toString();
}
}
}

+ 36
- 0
src/testcases/org/apache/tools/ant/types/selectors/MockAlgorithm.java View File

@@ -0,0 +1,36 @@
/*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.tools.ant.types.selectors;


import java.io.File;
import org.apache.tools.ant.types.selectors.modifiedselector.Algorithm;

public class MockAlgorithm implements Algorithm {
public boolean isValid() {
return true;
}

public String getValue(File file) {
return "TEST";
}

public String toString() {
return "MockAlgorithm@" + hashCode();
}
}

+ 67
- 0
src/testcases/org/apache/tools/ant/types/selectors/MockCache.java View File

@@ -0,0 +1,67 @@
/*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.tools.ant.types.selectors;


import java.util.Iterator;
import org.apache.tools.ant.types.selectors.modifiedselector.Cache;

public class MockCache implements Cache {

public boolean debug = false;
public boolean saved = false;


public MockCache() {
log("()");
}

public boolean isValid() {
log(".isValid()");
return true;
}
public void delete() {
log(".delete()");
}
public void load() {
log(".load()");
}
public void save() {
log(".save()");
saved = true;
}
public Object get(Object key) {
log(".get("+key+")");
return key;
}
public void put(Object key, Object value) {
log(".put("+key+", "+value+")");
saved = false;
}
public Iterator iterator() {
log("iterator()");
return null;
}
public String toString() {
return "MockCache@" + hashCode();
}

private void log(String msg) {
if (debug) System.out.println(this+msg);
}
}//class-MockCache

+ 31
- 0
src/testcases/org/apache/tools/ant/types/selectors/MockComparator.java View File

@@ -0,0 +1,31 @@
/*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.tools.ant.types.selectors;

import java.util.Comparator;

public class MockComparator implements Comparator {

public int compare(Object o1, Object o2) {
return 0;
}

public String toString() {
return "MockComparator";
}
}//class-MockCache

+ 635
- 292
src/testcases/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
File diff suppressed because it is too large
View File


Loading…
Cancel
Save