Return-Path: Delivered-To: apmail-ant-notifications-archive@locus.apache.org Received: (qmail 39725 invoked from network); 3 Jan 2008 13:52:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Jan 2008 13:52:13 -0000 Received: (qmail 83427 invoked by uid 500); 3 Jan 2008 13:52:02 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 83406 invoked by uid 500); 3 Jan 2008 13:52:02 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 83397 invoked by uid 99); 3 Jan 2008 13:52:02 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Jan 2008 05:52:02 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Jan 2008 13:51:57 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2FDFC1A9832; Thu, 3 Jan 2008 05:51:45 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r608488 - in /ant/ivy/core/trunk: src/java/org/apache/ivy/ant/ src/java/org/apache/ivy/core/cache/ test/java/org/apache/ivy/ant/ Date: Thu, 03 Jan 2008 13:51:44 -0000 To: notifications@ant.apache.org From: xavier@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080103135145.2FDFC1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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: - *
- *  <delete dir="${ivy.cache.dir}" >
- *  
- * - * 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 null. + */ + 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 + * true if the resolution cache should be cleaned, false + * 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. --> - + + + + +