Author: xavier
Date: Thu Jan 3 05:51:43 2008
New Revision: 608488
URL: http://svn.apache.org/viewvc?rev=608488&view=rev
Log:
upgrade cleancache to latest cache management changes
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyCleanCache.java
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultResolutionCacheManager.java
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/RepositoryCacheManager.java
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/ResolutionCacheManager.java
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCleanCacheTest.java
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/ivysettings-cleancache.xml
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyCleanCache.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyCleanCache.java?rev=608488&r1=608487&r2=608488&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyCleanCache.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyCleanCache.java Thu Jan
3 05:51:43 2008
@@ -17,28 +17,70 @@
*/
package org.apache.ivy.ant;
+import org.apache.ivy.core.cache.RepositoryCacheManager;
+import org.apache.ivy.core.settings.IvySettings;
import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.taskdefs.Delete;
/**
- * Cleans the content of Ivy cache.
- *
- * The whole directory used as Ivy cache is deleted, this is roughly
equivalent to:
- * <pre>
- * <delete dir="${ivy.cache.dir}" >
- * </pre>
- *
- * Using the delete task gives more control over what is actually deleted
(you can use include
- * and exclude filters), but requires a settings to be loaded before, while
this task
- * ensures the settings is loaded.
+ * Cleans the content of Ivy cache(s).
*/
public class IvyCleanCache extends IvyTask {
+ public static final String ALL = "*";
+
+ public static final String NONE = "NONE";
+
+ private boolean resolution = true;
+
+ private String cache = ALL;
+
+ public String getCache() {
+ return cache;
+ }
+
+ /**
+ * Sets the name of the repository cache to clean, '*' for all caches,
'NONE' for no repository
+ * cache cleaning at all.
+ *
+ * @param cache
+ * the name of the cache to clean. Must not be
<code>null</code>.
+ */
+ public void setCache(String cache) {
+ this.cache = cache;
+ }
+
+ public boolean isResolution() {
+ return resolution;
+ }
+
+ /**
+ * Sets weither the resolution cache should be cleaned or not.
+ *
+ * @param resolution
+ * <code>true</code> if the resolution cache should be cleaned,
<code>false</code>
+ * otherwise.
+ */
+ public void setResolution(boolean resolution) {
+ this.resolution = resolution;
+ }
+
public void doExecute() throws BuildException {
- Delete delete = new Delete();
- delete.setTaskName(getTaskName());
- delete.setProject(getProject());
- delete.setDir(getIvyInstance().getSettings().getDefaultCache());
- delete.perform();
+ IvySettings settings = getIvyInstance().getSettings();
+ if (isResolution()) {
+ settings.getResolutionCacheManager().clean();
+ }
+ if (ALL.equals(getCache())) {
+ RepositoryCacheManager[] caches =
settings.getRepositoryCacheManagers();
+ for (int i = 0; i < caches.length; i++) {
+ caches[i].clean();
+ }
+ } else if (!NONE.equals(getCache())) {
+ RepositoryCacheManager cache =
settings.getRepositoryCacheManager(getCache());
+ if (cache == null) {
+ throw new BuildException("unknown cache '" + getCache() + "'");
+ } else {
+ cache.clean();
+ }
+ }
}
}
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java?rev=608488&r1=608487&r2=608488&view=diff
==============================================================================
---
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
(original)
+++
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
Thu Jan 3 05:51:43 2008
@@ -45,6 +45,7 @@
import org.apache.ivy.plugins.repository.ResourceHelper;
import org.apache.ivy.plugins.resolver.DependencyResolver;
import org.apache.ivy.plugins.resolver.util.ResolvedResource;
+import org.apache.ivy.util.FileUtil;
import org.apache.ivy.util.Message;
import org.apache.ivy.util.PropertiesFile;
@@ -763,5 +764,8 @@
moduleArtifact.getName() + ".original");
}
+ public void clean() {
+ FileUtil.forceDelete(getBasedir());
+ }
}
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultResolutionCacheManager.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultResolutionCacheManager.java?rev=608488&r1=608487&r2=608488&view=diff
==============================================================================
---
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultResolutionCacheManager.java
(original)
+++
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultResolutionCacheManager.java
Thu Jan 3 05:51:43 2008
@@ -22,6 +22,7 @@
import org.apache.ivy.core.IvyPatternHelper;
import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.util.FileUtil;
public class DefaultResolutionCacheManager implements ResolutionCacheManager {
private static final String DEFAULT_CACHE_RESOLVED_IVY_PATTERN =
@@ -113,5 +114,9 @@
public String toString() {
return name;
}
-
+
+ public void clean() {
+ FileUtil.forceDelete(getBasedir());
+ }
+
}
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/RepositoryCacheManager.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/RepositoryCacheManager.java?rev=608488&r1=608487&r2=608488&view=diff
==============================================================================
---
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/RepositoryCacheManager.java
(original)
+++
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/RepositoryCacheManager.java
Thu Jan 3 05:51:43 2008
@@ -143,4 +143,9 @@
ResolvedResource orginalMetadataRef, Artifact
requestedMetadataArtifact,
ResolvedModuleRevision rmr, ModuleDescriptorWriter writer);
+ /**
+ * Cleans the whole cache.
+ */
+ public void clean();
+
}
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/ResolutionCacheManager.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/ResolutionCacheManager.java?rev=608488&r1=608487&r2=608488&view=diff
==============================================================================
---
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/ResolutionCacheManager.java
(original)
+++
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/ResolutionCacheManager.java
Thu Jan 3 05:51:43 2008
@@ -31,4 +31,9 @@
public abstract File getConfigurationResolveReportInCache(String
resolveId, String conf);
public abstract File[] getConfigurationResolveReportsInCache(final String
resolveId);
+
+ /**
+ * Cleans the whole cache.
+ */
+ public void clean();
}
Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCleanCacheTest.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCleanCacheTest.java?rev=608488&r1=608487&r2=608488&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCleanCacheTest.java
(original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCleanCacheTest.java Thu
Jan 3 05:51:43 2008
@@ -21,26 +21,73 @@
import junit.framework.TestCase;
+import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
public class IvyCleanCacheTest extends TestCase {
- private IvyCleanCache cleanCache = new IvyCleanCache();
+ private IvyCleanCache cleanCache;
private File cacheDir;
+ private File repoCache2;
+ private File repoCache;
+ private File resolutionCache;
protected void setUp() throws Exception {
Project p = new Project();
cacheDir = new File("build/cache");
p.setProperty("cache", cacheDir.getAbsolutePath());
+ cleanCache = new IvyCleanCache();
cleanCache.setProject(p);
IvyAntSettings settings = IvyAntSettings.getDefaultInstance(p);
settings.setUrl(
IvyCleanCacheTest.class.getResource("ivysettings-cleancache.xml").toExternalForm());
+ resolutionCache = new File(cacheDir, "resolution");
+ repoCache = new File(cacheDir, "repository");
+ repoCache2 = new File(cacheDir, "repository2");
+ resolutionCache.mkdirs();
+ repoCache.mkdirs();
+ repoCache2.mkdirs();
}
- public void testClean() throws Exception {
- cacheDir.mkdirs();
- assertTrue(cacheDir.exists());
- cleanCache.execute();
- assertFalse(cacheDir.exists());
+ public void testCleanAll() throws Exception {
+ cleanCache.perform();
+ assertFalse(resolutionCache.exists());
+ assertFalse(repoCache.exists());
+ assertFalse(repoCache2.exists());
+ }
+
+ public void testResolutionOnly() throws Exception {
+ cleanCache.setCache(IvyCleanCache.NONE);
+ cleanCache.perform();
+ assertFalse(resolutionCache.exists());
+ assertTrue(repoCache.exists());
+ assertTrue(repoCache2.exists());
+ }
+
+ public void testRepositoryOnly() throws Exception {
+ cleanCache.setResolution(false);
+ cleanCache.perform();
+ assertTrue(resolutionCache.exists());
+ assertFalse(repoCache.exists());
+ assertFalse(repoCache2.exists());
+ }
+
+ public void testOneRepositoryOnly() throws Exception {
+ cleanCache.setResolution(false);
+ cleanCache.setCache("mycache");
+ cleanCache.perform();
+ assertTrue(resolutionCache.exists());
+ assertFalse(repoCache.exists());
+ assertTrue(repoCache2.exists());
+ }
+
+ public void testUnknownCache() throws Exception {
+ cleanCache.setResolution(false);
+ cleanCache.setCache("yourcache");
+ try {
+ cleanCache.perform();
+ fail("clean cache should have raised an exception with unkown
cache");
+ } catch (BuildException e) {
+ assertTrue(e.getMessage().indexOf("yourcache") != -1);
+ }
}
}
Modified:
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/ivysettings-cleancache.xml
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/ant/ivysettings-cleancache.xml?rev=608488&r1=608487&r2=608488&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/ant/ivysettings-cleancache.xml
(original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/ant/ivysettings-cleancache.xml
Thu Jan 3 05:51:43 2008
@@ -17,5 +17,14 @@
under the License.
-->
<ivysettings>
- <settings defaultCache="${cache}" />
+ <cacheDefaults
+ resolutionDir="${cache}/resolution"
+ repositoryDir="${cache}/repository"
+ />
+ <caches>
+ <cache name="mycache" />
+ <cache name="mycache2"
+ basedir="${cache}/repository2"
+ />
+ </caches>
</ivysettings>