Package org.apache.ivy.core.cache
Class DefaultRepositoryCacheManager
java.lang.Object
org.apache.ivy.core.cache.DefaultRepositoryCacheManager
- All Implemented Interfaces:
RepositoryCacheManager,IvySettingsAware
public class DefaultRepositoryCacheManager
extends Object
implements RepositoryCacheManager, IvySettingsAware
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classResource downloader which makes a copy of the previously existing file before overriding it.private static final classprivate class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Patternprivate Stringprivate Fileprivate Stringprivate Stringprivate Booleanprivate final List<DefaultRepositoryCacheManager.ConfiguredTTL>private Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final intprivate Longprivate static final Patternprivate Stringprivate LockStrategyprivate Stringprivate ModuleDescriptorMemoryCacheprivate static final intprivate static final intprivate static final intprivate static final intprivate Stringprivate PackagingManagerprivate IvySettingsprivate static MessageDigestprivate ModuleRules<Long>private Boolean -
Constructor Summary
ConstructorsConstructorDescriptionDefaultRepositoryCacheManager(String name, IvySettings settings, File basedir) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConfiguredTtl(Map<String, String> attributes) voidaddTTL(Map<String, String> attributes, PatternMatcher matcher, long duration) final voidassertInsideCache(File fileInCache) cacheModuleDescriptor(DependencyResolver resolver, ResolvedResource mdRef, DependencyDescriptor dd, Artifact moduleArtifact, ResourceDownloader downloader, CacheMetadataOptions options) Caches an original module descriptor.private booleancheckCacheUptodate(File archiveFile, Resource resource, ArtifactOrigin savedOrigin, ArtifactOrigin origin, long ttl) Check that a cached file can be considered up to date and thus not downloadedvoidclean()Cleans the whole cache.private StringcomputeResourceNameHash(Resource resource) Compute a SHA1 of the resource name, encoded in base64, so we can use it as a file name.private ResolvedModuleRevisiondoFindModuleInCache(ModuleRevisionId mrid, CacheMetadataOptions options, String expectedResolver) download(Artifact artifact, ArtifactResourceResolver resourceResolver, ResourceDownloader resourceDownloader, CacheDownloadOptions options) Downloads an artifact to this cache.downloadRepositoryResource(Resource resource, String name, String type, String extension, CacheResourceOptions options, Repository repository) Download some repository resource and put it in the cache.voidfindModuleInCache(DependencyDescriptor dd, ModuleRevisionId requestedRevisionId, CacheMetadataOptions options, String expectedResolver) Search a module descriptor in cache for a mridgetArchiveFileInCache(Artifact artifact) Returns a File object pointing to where the artifact can be found on the local file system.getArchiveFileInCache(Artifact artifact, ArtifactOrigin origin) Returns a File object pointing to where the artifact can be found on the local file system.private FilegetArchiveFileInCache(Artifact artifact, ArtifactOrigin origin, boolean useOrigin) 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.getArchivePathInCache(Artifact artifact) getArchivePathInCache(Artifact artifact, ArtifactOrigin origin) private PropertiesFilegetCachedDataFile(String resolverName, ModuleRevisionId mRevId) A resolver-specific ivydata file, only used for caching dynamic revisions, e.g.private PropertiesFileprivate PropertiesFilegetCachedDataFile(ModuleRevisionId mRevId) private MatchergetChangingMatcher(CacheMetadataOptions options) private Artifactprivate ArtifactOriginlongprivate StringgetExistsKey(Artifact artifact) Returns the key used to identify the existence of the remote artifact.private intgetGroupIntValue(Matcher m, int groupNumber) private StringgetIsLocalKey(Artifact artifact) Returns the key used to identify if the artifact is local.private StringgetLastCheckedKey(Artifact artifact) Returns the key used to identify the last time the artifact was checked to be up to date.private StringgetLocationKey(Artifact artifact) Returns the key used to identify the location of the artifact.private ModuleDescriptorgetMdFromCache(ModuleDescriptorParser mdParser, CacheMetadataOptions options, File ivyFile) protected ModuleDescriptorParsergetModuleDescriptorParser(File moduleDescriptorFile) Choose write module descriptor parser for a given moduleDescriptorgetName()Returns the name of the repository cache manager.private StringgetOriginalKey(Artifact artifact) Returns the key used to identify the original artifact.getOriginalMetadataArtifact(Artifact moduleArtifact) private StringgetPrefixKey(Artifact artifact) Creates the unique prefix key that will reference the artifact within the properties.private StringgetResolvedRevision(String expectedResolver, ModuleRevisionId mrid, CacheMetadataOptions options) Called by doFindModuleInCache to lookup the dynamicmridin the ivycache's ivydata file.getSavedArtifactOrigin(Artifact artifact) Returns the artifact origin of the given artifact as saved in this cache.private Stringprivate Stringprivate ModuleDescriptorgetStaledMd(ModuleDescriptorParser mdParser, CacheMetadataOptions options, File ivyFile, ParserSettings parserSettings) longgetTTL(ModuleRevisionId mrid) private booleanisChanging(DependencyDescriptor dd, ModuleRevisionId requestedRevisionId, CacheMetadataOptions options) booleanTrue if this cache should check lastmodified date to know if ivy files are up to date.private booleanisCheckmodified(DependencyDescriptor dd, ModuleRevisionId requestedRevisionId, CacheMetadataOptions options) private booleanisOriginalMetadataArtifact(Artifact artifact) booleanTrue if this cache should use artifacts original location when possible, false if they should be copied to cache.private booleanvoidoriginalToCachedModuleDescriptor(DependencyResolver resolver, ResolvedResource originalMetadataRef, Artifact requestedMetadataArtifact, ResolvedModuleRevision rmr, ModuleDescriptorWriter writer) Stores a standardized version of an original module descriptor in the cache for later use.private static StringIf thelocation of the artifact originis afile:scheme URI, then this method parses that URI and returns back the path of the file it represents.private longparseDuration(String duration) private voidremoveSavedArtifactOrigin(Artifact artifact) (package private) voidsaveArtifactOrigin(Artifact artifact, ArtifactOrigin origin) voidsaveResolvedRevision(String resolverName, ModuleRevisionId mrid, String revision) Caches a dynamic revision constraint resolution for a specific resolver.voidsaveResolvedRevision(ModuleRevisionId mrid, String revision) Deprecated.private voidsaveResolver(ModuleDescriptor md, String name) Saves the information of which resolver was used to resolve a md, so that this info can be retrieve later (even after a jvm restart) by getSavedResolverName(ModuleDescriptor md)voidsaveResolvers(ModuleDescriptor md, String metadataResolverName, String artifactResolverName) Saves the information of which resolver was used to resolve a md, so that this info can be retrieve later (even after a jvm restart) by getSavedArtResolverName(ModuleDescriptor md)voidsetArtifactPattern(String artifactPattern) voidsetBasedir(File cache) voidsetChangingMatcher(String changingMatcherName) voidsetChangingPattern(String changingPattern) voidsetCheckmodified(boolean check) voidsetDataFilePattern(String dataFilePattern) voidsetDefaultTTL(long defaultTTL) voidsetDefaultTTL(String defaultTTL) voidsetIvyPattern(String ivyPattern) voidsetLockStrategy(String lockStrategyName) voidsetLockStrategy(LockStrategy lockStrategy) voidsetMemorySize(int size) voidvoidsetSettings(IvySettings settings) voidsetUseOrigin(boolean b) toString()private voidprivate voidunpackArtifact(Artifact artifact, ArtifactDownloadReport adr, CacheDownloadOptions options)
-
Field Details
-
DEFAULT_ARTIFACT_PATTERN
- See Also:
-
DEFAULT_DATA_FILE_PATTERN
- See Also:
-
DEFAULT_IVY_PATTERN
- See Also:
-
DEFAULT_MEMORY_CACHE_SIZE
private static final int DEFAULT_MEMORY_CACHE_SIZE- See Also:
-
SHA_DIGEST
-
settings
-
basedir
-
lockStrategy
-
name
-
ivyPattern
-
dataFilePattern
-
artifactPattern
-
lockStrategyName
-
changingPattern
-
changingMatcherName
-
checkmodified
-
useOrigin
-
ttlRules
-
defaultTTL
-
memoryModuleDescrCache
-
packagingManager
-
configuredTTLs
-
DURATION_PATTERN
-
MILLIS_IN_SECONDS
private static final int MILLIS_IN_SECONDS- See Also:
-
MILLIS_IN_MINUTES
private static final int MILLIS_IN_MINUTES- See Also:
-
MILLIS_IN_HOUR
private static final int MILLIS_IN_HOUR- See Also:
-
MILLIS_IN_DAY
private static final int MILLIS_IN_DAY- See Also:
-
ARTIFACT_KEY_PATTERN
-
-
Constructor Details
-
DefaultRepositoryCacheManager
public DefaultRepositoryCacheManager() -
DefaultRepositoryCacheManager
-
-
Method Details
-
getSettings
-
setSettings
- Specified by:
setSettingsin interfaceIvySettingsAware
-
getIvyFileInCache
-
getIvyPattern
-
getArtifactPattern
-
setArtifactPattern
-
getBasedir
-
setBasedir
-
getDefaultTTL
public long getDefaultTTL() -
setDefaultTTL
public void setDefaultTTL(long defaultTTL) -
setDefaultTTL
-
getDataFilePattern
-
setDataFilePattern
-
setIvyPattern
-
getName
Description copied from interface:RepositoryCacheManagerReturns the name of the repository cache manager.- Specified by:
getNamein interfaceRepositoryCacheManager- Returns:
- the name of the repository cache manager.
-
setName
-
getChangingMatcherName
-
setChangingMatcher
-
getChangingPattern
-
setChangingPattern
-
addTTL
-
addConfiguredTtl
-
setMemorySize
public void setMemorySize(int size) -
getMemoryCache
-
parseDuration
-
getGroupIntValue
-
isCheckmodified
public boolean isCheckmodified()True if this cache should check lastmodified date to know if ivy files are up to date.- Returns:
- boolean
-
setCheckmodified
public void setCheckmodified(boolean check) -
isUseOrigin
public boolean isUseOrigin()True if this cache should use artifacts original location when possible, false if they should be copied to cache.- Returns:
- boolean
-
setUseOrigin
public void setUseOrigin(boolean b) -
getArchiveFileInCache
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- Parameters:
artifact- Artifact- Returns:
- File
-
getArchiveFileInCache
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- Parameters:
artifact- Artifactorigin- ArtifactOrigin- Returns:
- File
-
getArchiveFileInCache
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.- Parameters:
artifact- Artifactorigin- ArtifactOriginuseOrigin- boolean- Returns:
- File
-
getArchivePathInCache
-
getArchivePathInCache
-
saveResolver
Saves the information of which resolver was used to resolve a md, so that this info can be retrieve later (even after a jvm restart) by getSavedResolverName(ModuleDescriptor md)- Parameters:
md- the module descriptor resolvedname- resolver name
-
saveResolvers
public void saveResolvers(ModuleDescriptor md, String metadataResolverName, String artifactResolverName) Saves the information of which resolver was used to resolve a md, so that this info can be retrieve later (even after a jvm restart) by getSavedArtResolverName(ModuleDescriptor md)- Specified by:
saveResolversin interfaceRepositoryCacheManager- Parameters:
md- the module descriptor resolvedmetadataResolverName- metadata resolver nameartifactResolverName- artifact resolver name
-
getSavedResolverName
-
getSavedArtResolverName
-
saveArtifactOrigin
-
removeSavedArtifactOrigin
-
getSavedArtifactOrigin
Description copied from interface:RepositoryCacheManagerReturns the artifact origin of the given artifact as saved in this cache.If the origin is unknown, the returned ArtifactOrigin instance will return true when
ArtifactOrigin.isUnknown(ArtifactOrigin)is called.- Specified by:
getSavedArtifactOriginin interfaceRepositoryCacheManager- Parameters:
artifact- the artifact for which the saved artifact origin should be returned.- Returns:
- the artifact origin of the given artifact as saved in this cache
-
getPrefixKey
Creates the unique prefix key that will reference the artifact within the properties.- Parameters:
artifact- the artifact to create the unique key from. Cannot be null.- Returns:
- the unique prefix key as a string.
-
getLocationKey
Returns the key used to identify the location of the artifact.- Parameters:
artifact- the artifact to generate the key from. Cannot be null.- Returns:
- the key to be used to reference the artifact location.
-
getIsLocalKey
Returns the key used to identify if the artifact is local.- Parameters:
artifact- the artifact to generate the key from. Cannot be null.- Returns:
- the key to be used to reference the artifact locality.
-
getLastCheckedKey
Returns the key used to identify the last time the artifact was checked to be up to date.- Parameters:
artifact- the artifact to generate the key from. Cannot be null.- Returns:
- the key to be used to reference the artifact's last check date.
-
getExistsKey
Returns the key used to identify the existence of the remote artifact.- Parameters:
artifact- the artifact to generate the key from. Cannot be null.- Returns:
- the key to be used to reference the existence of the artifact.
-
getOriginalKey
Returns the key used to identify the original artifact.- Parameters:
artifact- the artifact to generate the key from. Cannot be null.- Returns:
- the key to be used to reference the original artifact.
-
getCachedDataFile
-
getCachedDataFile
-
getCachedDataFile
A resolver-specific ivydata file, only used for caching dynamic revisions, e.g. integration-repo. -
findModuleInCache
public ResolvedModuleRevision findModuleInCache(DependencyDescriptor dd, ModuleRevisionId requestedRevisionId, CacheMetadataOptions options, String expectedResolver) Description copied from interface:RepositoryCacheManagerSearch a module descriptor in cache for a mrid- Specified by:
findModuleInCachein interfaceRepositoryCacheManager- Parameters:
dd- the dependency descriptor identifying the module to searchrequestedRevisionId- the requested dependency module revision id identifying the module to searchoptions- options on how caching should be handledexpectedResolver- the resolver with which the md in cache must have been resolved to be returned, null if this doesn't matter- Returns:
- the ResolvedModuleRevision corresponding to the module found, null if none correct has been found in cache
-
doFindModuleInCache
private ResolvedModuleRevision doFindModuleInCache(ModuleRevisionId mrid, CacheMetadataOptions options, String expectedResolver) -
getModuleDescriptorParser
Choose write module descriptor parser for a given moduleDescriptor- Parameters:
moduleDescriptorFile- a given module descriptor- Returns:
- ModuleDescriptorParser
-
getMdFromCache
private ModuleDescriptor getMdFromCache(ModuleDescriptorParser mdParser, CacheMetadataOptions options, File ivyFile) throws ParseException, IOException - Throws:
ParseExceptionIOException
-
getStaledMd
private ModuleDescriptor getStaledMd(ModuleDescriptorParser mdParser, CacheMetadataOptions options, File ivyFile, ParserSettings parserSettings) throws ParseException, IOException - Throws:
ParseExceptionIOException
-
getResolvedRevision
private String getResolvedRevision(String expectedResolver, ModuleRevisionId mrid, CacheMetadataOptions options) Called by doFindModuleInCache to lookup the dynamicmridin the ivycache's ivydata file. -
saveResolvedRevision
Deprecated.Description copied from interface:RepositoryCacheManagerCaches a dynamic revision constraint resolution.- Specified by:
saveResolvedRevisionin interfaceRepositoryCacheManager- Parameters:
mrid- the dynamic module revision idrevision- the resolved revision
-
saveResolvedRevision
Description copied from interface:RepositoryCacheManagerCaches a dynamic revision constraint resolution for a specific resolver.- Specified by:
saveResolvedRevisionin interfaceRepositoryCacheManager- Parameters:
resolverName- the resolver in which this dynamic revision was resolvedmrid- the dynamic module revision idrevision- the resolved revision
-
getTTL
-
toString
-
getRepositoryCacheRoot
-
getLockStrategy
-
setLockStrategy
-
setLockStrategy
-
download
public ArtifactDownloadReport download(Artifact artifact, ArtifactResourceResolver resourceResolver, ResourceDownloader resourceDownloader, CacheDownloadOptions options) Description copied from interface:RepositoryCacheManagerDownloads an artifact to this cache.- Specified by:
downloadin interfaceRepositoryCacheManager- Parameters:
artifact- the artifact to downloadresourceResolver- a resource resolver to use if the artifact needs to be resolved to a Resource for downloadingresourceDownloader- a resource downloader to use if actual download of the resource is neededoptions- a set of options to adjust the download- Returns:
- a report indicating how the download was performed
-
unpackArtifact
private void unpackArtifact(Artifact artifact, ArtifactDownloadReport adr, CacheDownloadOptions options) -
downloadRepositoryResource
public ArtifactDownloadReport downloadRepositoryResource(Resource resource, String name, String type, String extension, CacheResourceOptions options, Repository repository) Description copied from interface:RepositoryCacheManagerDownload some repository resource and put it in the cache.If the cached version is considered enough up to date, no downloading is done.
- Specified by:
downloadRepositoryResourcein interfaceRepositoryCacheManager- Parameters:
resource- the resource of the file to put in cachename- the descriptive name of the resource (helps while manually looking into the cache files)type- the type of the resource (helps while manually looking into the cache files)extension- the extension of the resource (helps while manually looking into the cache files)options- a set of options to adjust the downloadrepository- the repository which resolve the content of the resource- Returns:
- a report indicating how the download was performed
-
computeResourceNameHash
Compute a SHA1 of the resource name, encoded in base64, so we can use it as a file name.- Parameters:
resource- the resource which name will be hashed- Returns:
- the hash
-
checkCacheUptodate
private boolean checkCacheUptodate(File archiveFile, Resource resource, ArtifactOrigin savedOrigin, ArtifactOrigin origin, long ttl) Check that a cached file can be considered up to date and thus not downloaded- Parameters:
archiveFile- the file in the cacheresource- the remote resource to checksavedOrigin- the saved origin which contains that last checked dateorigin- the origin in which to store the new last checked datettl- the time to live to consider the cache up to date- Returns:
trueif the cache is considered up to date
-
originalToCachedModuleDescriptor
public void originalToCachedModuleDescriptor(DependencyResolver resolver, ResolvedResource originalMetadataRef, Artifact requestedMetadataArtifact, ResolvedModuleRevision rmr, ModuleDescriptorWriter writer) Description copied from interface:RepositoryCacheManagerStores a standardized version of an original module descriptor in the cache for later use.- Specified by:
originalToCachedModuleDescriptorin interfaceRepositoryCacheManager- Parameters:
resolver- the dependency resolver from which the cache request comes fromoriginalMetadataRef- a resolved resource pointing to the remote original module descriptorrequestedMetadataArtifact- the module descriptor artifact as requested originallyrmr- theResolvedModuleRevisionrepresenting the local cached module descriptorwriter- aModuleDescriptorWriterable to write the module descriptor to a stream.
-
cacheModuleDescriptor
public ResolvedModuleRevision cacheModuleDescriptor(DependencyResolver resolver, ResolvedResource mdRef, DependencyDescriptor dd, Artifact moduleArtifact, ResourceDownloader downloader, CacheMetadataOptions options) throws ParseException Description copied from interface:RepositoryCacheManagerCaches an original module descriptor.After this call, the original module descriptor file (with no modification nor conversion) should be available as a local file.
- Specified by:
cacheModuleDescriptorin interfaceRepositoryCacheManager- Parameters:
resolver- the dependency resolver from which the cache request comes frommdRef- a resolved resource pointing to the remote original module descriptordd- the dependency descriptor for which the module descriptor should be cachedmoduleArtifact- the module descriptor artifact as requested originallydownloader- a ResourceDownloader able to download the original module descriptor resource if required by this cache implementationoptions- options to apply to cache this module descriptor- Returns:
- a
ResolvedModuleRevisionrepresenting the local cached module descriptor, or null if it failed - Throws:
ParseException- if an exception occurred while parsing the module descriptor
-
lockMetadataArtifact
-
unlockMetadataArtifact
-
getDefaultMetadataArtifactOrigin
-
getDefaultMetadataArtifact
-
getOriginalMetadataArtifact
-
isOriginalMetadataArtifact
-
isChanging
private boolean isChanging(DependencyDescriptor dd, ModuleRevisionId requestedRevisionId, CacheMetadataOptions options) -
getChangingMatcher
-
isCheckmodified
private boolean isCheckmodified(DependencyDescriptor dd, ModuleRevisionId requestedRevisionId, CacheMetadataOptions options) -
clean
public void clean()Description copied from interface:RepositoryCacheManagerCleans the whole cache.- Specified by:
cleanin interfaceRepositoryCacheManager
-
dumpSettings
public void dumpSettings() -
assertInsideCache
- Throws:
IllegalArgumentException- if the given path points outside of the cache.
-
parseArtifactOriginFilePath
If thelocation of the artifact originis afile:scheme URI, then this method parses that URI and returns back the path of the file it represents. Else returns backArtifactOrigin.getLocation()- Parameters:
origin- The artifact origin- Returns:
-