Author: xavier
Date: Wed Jan 2 09:58:40 2008
New Revision: 608162
URL: http://svn.apache.org/viewvc?rev=608162&view=rev
Log:
reduce RepositoryCacheManager contract
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyArtifactReport.java
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/RepositoryCacheManager.java
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java
ant/ivy/core/trunk/test/java/org/apache/ivy/TestHelper.java
ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyArtifactReport.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyArtifactReport.java?rev=608162&r1=608161&r2=608162&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyArtifactReport.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyArtifactReport.java Wed
Jan 2 09:58:40 2008
@@ -152,9 +152,9 @@
startArtifact(saxHandler, artifact.getArtifact());
- writeOriginLocationIfPresent(cache, saxHandler,
artifact.getArtifact());
+ writeOriginLocationIfPresent(cache, saxHandler,
artifact);
- writeCacheLocation(cache, saxHandler,
artifact.getArtifact());
+ writeCacheLocation(cache, saxHandler, artifact);
Set artifactDestPaths = (Set)
artifactsToCopy.get(artifact);
for (Iterator iterator =
artifactDestPaths.iterator(); iterator
@@ -216,10 +216,11 @@
}
private void writeOriginLocationIfPresent(
- RepositoryCacheManager cache, TransformerHandler saxHandler,
Artifact artifact)
+ RepositoryCacheManager cache, TransformerHandler saxHandler,
+ ArtifactDownloadReport artifact)
throws IOException, SAXException {
- ArtifactOrigin origin = cache.getSavedArtifactOrigin(artifact);
- if (origin != ArtifactOrigin.UNKNOWN) {
+ ArtifactOrigin origin = artifact.getArtifactOrigin();
+ if (origin != ArtifactOrigin.UNKNOWN && origin != null) {
String originName = origin.getLocation();
boolean isOriginLocal = origin.isLocal();
@@ -241,9 +242,8 @@
}
private void writeCacheLocation(RepositoryCacheManager cache,
TransformerHandler saxHandler,
- Artifact artifact) throws SAXException {
- ArtifactOrigin origin = cache.getSavedArtifactOrigin(artifact);
- File archiveInCache = cache.getArchiveFileInCache(artifact, origin,
false);
+ ArtifactDownloadReport artifact) throws SAXException {
+ File archiveInCache = artifact.getLocalFile();
saxHandler.startElement(null, "cache-location", "cache-location", new
AttributesImpl());
char[] archiveInCacheAsChars = archiveInCache.getPath().replace('\\',
'/').toCharArray();
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=608162&r1=608161&r2=608162&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
Wed Jan 2 09:58:40 2008
@@ -17,7 +17,6 @@
*/
package org.apache.ivy.core.cache;
-import java.io.File;
import java.text.ParseException;
import org.apache.ivy.core.module.descriptor.Artifact;
@@ -99,48 +98,49 @@
ResourceDownloader resourceDownloader,
CacheDownloadOptions options);
- public ResolvedModuleRevision cacheModuleDescriptor(
- DependencyResolver resolver, ResolvedResource orginalMetadataRef,
- Artifact requestedMetadataArtifact,
- ResourceDownloader downloader, CacheMetadataOptions options)
throws ParseException;
-
- public void originalToCachedModuleDescriptor(
- DependencyResolver resolver, ResolvedResource orginalMetadataRef,
- Artifact requestedMetadataArtifact,
- ResolvedModuleRevision rmr, ModuleDescriptorWriter writer);
-
-
-
- /*
- * TODO: remove these methods from here
- * (require some clients change + tests rely on
DefaultRepositoryCacheManager)
- */
- public abstract File getIvyFileInCache(ModuleRevisionId mrid);
-
- /**
- * Returns a File object pointing to where the artifact can be found on
the local file system.
- * This is usually in the cache, but it can be directly in the repository
if it is local and if
- * the resolve has been done with useOrigin = true
- */
- public abstract File getArchiveFileInCache(Artifact artifact);
-
/**
- * Returns a File object pointing to where the artifact can be found on
the local file system.
- * This is usually in the cache, but it can be directly in the repository
if it is local and if
- * the resolve has been done with useOrigin = true
+ * Caches an original module descriptor.
+ * <p>
+ * After this call, the original module descriptor file (with no
modification nor conversion)
+ * should be available as a local file.
+ * </p>
+ *
+ * @param resolver
+ * the dependency resolver from which the cache request comes
from
+ * @param orginalMetadataRef
+ * a resolved resource pointing to the remote original module
descriptor
+ * @param requestedMetadataArtifact
+ * the module descriptor artifact as requested originally
+ * @param downloader
+ * a ResourceDownloader able to download the original module
descriptor resource if
+ * required by this cache implementation
+ * @param options
+ * options to apply to cache this module descriptor
+ * @return a [EMAIL PROTECTED] ResolvedModuleRevision} representing the
local cached module descriptor, or
+ * null if it failed
+ * @throws ParseException
+ * if an exception occured while parsing the module descriptor
*/
- public abstract File getArchiveFileInCache(Artifact artifact,
ArtifactOrigin origin);
+ public ResolvedModuleRevision cacheModuleDescriptor(DependencyResolver
resolver,
+ ResolvedResource orginalMetadataRef, Artifact
requestedMetadataArtifact,
+ ResourceDownloader downloader, CacheMetadataOptions options)
throws ParseException;
/**
- * Returns a File object pointing to where the artifact can be found on
the local file system,
- * using or not the original location depending on the availability of
origin information
- * provided as parameter and the setting of useOrigin. If useOrigin is
false, this method will
- * always return the file in the cache.
+ * Stores a standardized version of an original module descriptor in the
cache for later use.
+ *
+ * @param resolver
+ * the dependency resolver from which the cache request comes
from
+ * @param orginalMetadataRef
+ * a resolved resource pointing to the remote original module
descriptor
+ * @param requestedMetadataArtifact
+ * the module descriptor artifact as requested originally
+ * @param rmr
+ * the [EMAIL PROTECTED] ResolvedModuleRevision} representing
the local cached module descriptor
+ * @param writer
+ * a [EMAIL PROTECTED] ModuleDescriptorWriter} able to write
the module descriptor to a stream.
*/
- public abstract File getArchiveFileInCache(Artifact artifact,
ArtifactOrigin origin,
- boolean useOrigin);
-
- public abstract String getArchivePathInCache(Artifact artifact);
-
- public abstract String getArchivePathInCache(Artifact artifact,
ArtifactOrigin origin);
+ public void originalToCachedModuleDescriptor(DependencyResolver resolver,
+ ResolvedResource orginalMetadataRef, Artifact
requestedMetadataArtifact,
+ ResolvedModuleRevision rmr, ModuleDescriptorWriter writer);
+
}
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java?rev=608162&r1=608161&r2=608162&view=diff
==============================================================================
---
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java
(original)
+++
ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java
Wed Jan 2 09:58:40 2008
@@ -21,12 +21,11 @@
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
-import java.util.Date;
+import org.apache.ivy.core.cache.ArtifactOrigin;
import org.apache.ivy.core.cache.DefaultRepositoryCacheManager;
import org.apache.ivy.core.cache.RepositoryCacheManager;
import org.apache.ivy.core.module.descriptor.Artifact;
-import org.apache.ivy.core.module.descriptor.DefaultArtifact;
import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
import org.apache.ivy.core.module.id.ModuleRevisionId;
import org.apache.ivy.core.report.ArtifactDownloadReport;
@@ -39,6 +38,7 @@
import org.apache.ivy.core.search.ModuleEntry;
import org.apache.ivy.core.search.OrganisationEntry;
import org.apache.ivy.core.search.RevisionEntry;
+import org.apache.ivy.plugins.repository.file.FileResource;
import org.apache.ivy.plugins.resolver.util.ResolvedResource;
import org.apache.ivy.util.Message;
@@ -67,8 +67,6 @@
Message.verbose("\t" + getName() + ": revision in cache: " +
mrid);
return rmr;
} else {
-
logIvyAttempt(getRepositoryCacheManager().getArchiveFileInCache(
- DefaultArtifact.newIvyArtifact(mrid, new
Date())).getAbsolutePath());
Message.verbose("\t" + getName() + ": no ivy file in cache
found for " + mrid);
return null;
}
@@ -111,14 +109,17 @@
for (int i = 0; i < artifacts.length; i++) {
final ArtifactDownloadReport adr = new
ArtifactDownloadReport(artifacts[i]);
dr.addArtifactReport(adr);
- File archiveFile =
getRepositoryCacheManager().getArchiveFileInCache(artifacts[i]);
- if (archiveFile.exists()) {
+ ResolvedResource artifactRef = getArtifactRef(artifacts[i], null);
+ if (artifactRef != null) {
Message.verbose("\t[NOT REQUIRED] " + artifacts[i]);
+ ArtifactOrigin origin = new ArtifactOrigin(
+ true, artifactRef.getResource().getName());
+ File archiveFile = ((FileResource)
artifactRef.getResource()).getFile();
adr.setDownloadStatus(DownloadStatus.NO);
adr.setSize(archiveFile.length());
+ adr.setArtifactOrigin(origin);
adr.setLocalFile(archiveFile);
} else {
- logArtifactAttempt(artifacts[i],
archiveFile.getAbsolutePath());
adr.setDownloadStatus(DownloadStatus.FAILED);
}
}
Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/TestHelper.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/TestHelper.java?rev=608162&r1=608161&r2=608162&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/TestHelper.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/TestHelper.java Wed Jan 2
09:58:40 2008
@@ -29,7 +29,7 @@
import junit.framework.Assert;
-import org.apache.ivy.core.cache.RepositoryCacheManager;
+import org.apache.ivy.core.cache.DefaultRepositoryCacheManager;
import org.apache.ivy.core.event.EventManager;
import org.apache.ivy.core.module.descriptor.Artifact;
import org.apache.ivy.core.module.descriptor.DefaultArtifact;
@@ -66,10 +66,11 @@
}
- public static RepositoryCacheManager getRepositoryCacheManager(Ivy ivy,
ModuleRevisionId id) {
+ public static DefaultRepositoryCacheManager getRepositoryCacheManager(Ivy
ivy, ModuleRevisionId id) {
// WARN: this doesn't work if the resolver registered is a compound
resolver (chain or dual)
// and a sub resolver doesn't use the same cache manager as the parent
- return
ivy.getSettings().getResolver(id.getModuleId()).getRepositoryCacheManager();
+ return (DefaultRepositoryCacheManager)
+
ivy.getSettings().getResolver(id.getModuleId()).getRepositoryCacheManager();
}
/**
Modified:
ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java?rev=608162&r1=608161&r2=608162&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java
(original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java
Wed Jan 2 09:58:40 2008
@@ -34,7 +34,6 @@
import org.apache.ivy.TestHelper;
import org.apache.ivy.core.cache.ArtifactOrigin;
import org.apache.ivy.core.cache.DefaultRepositoryCacheManager;
-import org.apache.ivy.core.cache.RepositoryCacheManager;
import org.apache.ivy.core.module.descriptor.Artifact;
import org.apache.ivy.core.module.descriptor.DefaultArtifact;
import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
@@ -3617,7 +3616,7 @@
return TestHelper.getRepositoryCacheManager(ivy,
id).getIvyFileInCache(id);
}
- private RepositoryCacheManager getRepositoryCacheManager(ModuleRevisionId
id) {
+ private DefaultRepositoryCacheManager
getRepositoryCacheManager(ModuleRevisionId id) {
return TestHelper.getRepositoryCacheManager(ivy, id);
}
Modified:
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java
URL:
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java?rev=608162&r1=608161&r2=608162&view=diff
==============================================================================
---
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java
(original)
+++
ant/ivy/core/trunk/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java
Wed Jan 2 09:58:40 2008
@@ -23,8 +23,7 @@
import java.util.Date;
import java.util.GregorianCalendar;
-import org.apache.ivy.core.cache.DefaultResolutionCacheManager;
-import org.apache.ivy.core.cache.RepositoryCacheManager;
+import org.apache.ivy.core.cache.DefaultRepositoryCacheManager;
import org.apache.ivy.core.event.EventManager;
import org.apache.ivy.core.module.descriptor.Artifact;
import org.apache.ivy.core.module.descriptor.DefaultArtifact;
@@ -68,7 +67,7 @@
private File cache;
- private RepositoryCacheManager cacheManager;
+ private DefaultRepositoryCacheManager cacheManager;
public FileSystemResolverTest() {
setupLastModified();
@@ -81,7 +80,7 @@
data = new ResolveData(engine, new ResolveOptions());
cache.mkdirs();
settings.setDefaultCache(cache);
- cacheManager = settings.getDefaultRepositoryCacheManager();
+ cacheManager = (DefaultRepositoryCacheManager)
settings.getDefaultRepositoryCacheManager();
}
private void setupLastModified() {