Class DefaultRepositoryCacheManager

java.lang.Object
org.apache.ivy.core.cache.DefaultRepositoryCacheManager
All Implemented Interfaces:
RepositoryCacheManager, IvySettingsAware

public class DefaultRepositoryCacheManager extends Object implements RepositoryCacheManager, IvySettingsAware
  • Field Details

  • Constructor Details

    • DefaultRepositoryCacheManager

      public DefaultRepositoryCacheManager()
    • DefaultRepositoryCacheManager

      public DefaultRepositoryCacheManager(String name, IvySettings settings, File basedir)
  • Method Details

    • getSettings

      public IvySettings getSettings()
    • setSettings

      public void setSettings(IvySettings settings)
      Specified by:
      setSettings in interface IvySettingsAware
    • getIvyFileInCache

      public File getIvyFileInCache(ModuleRevisionId mrid)
    • getIvyPattern

      public String getIvyPattern()
    • getArtifactPattern

      public String getArtifactPattern()
    • setArtifactPattern

      public void setArtifactPattern(String artifactPattern)
    • getBasedir

      public File getBasedir()
    • setBasedir

      public void setBasedir(File cache)
    • getDefaultTTL

      public long getDefaultTTL()
    • setDefaultTTL

      public void setDefaultTTL(long defaultTTL)
    • setDefaultTTL

      public void setDefaultTTL(String defaultTTL)
    • getDataFilePattern

      public String getDataFilePattern()
    • setDataFilePattern

      public void setDataFilePattern(String dataFilePattern)
    • setIvyPattern

      public void setIvyPattern(String ivyPattern)
    • getName

      public String getName()
      Description copied from interface: RepositoryCacheManager
      Returns the name of the repository cache manager.
      Specified by:
      getName in interface RepositoryCacheManager
      Returns:
      the name of the repository cache manager.
    • setName

      public void setName(String name)
    • getChangingMatcherName

      public String getChangingMatcherName()
    • setChangingMatcher

      public void setChangingMatcher(String changingMatcherName)
    • getChangingPattern

      public String getChangingPattern()
    • setChangingPattern

      public void setChangingPattern(String changingPattern)
    • addTTL

      public void addTTL(Map<String,String> attributes, PatternMatcher matcher, long duration)
    • addConfiguredTtl

      public void addConfiguredTtl(Map<String,String> attributes)
    • setMemorySize

      public void setMemorySize(int size)
    • getMemoryCache

      public ModuleDescriptorMemoryCache getMemoryCache()
    • parseDuration

      private long parseDuration(String duration)
    • getGroupIntValue

      private int getGroupIntValue(Matcher m, int groupNumber)
    • 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

      public 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
      Parameters:
      artifact - Artifact
      Returns:
      File
    • getArchiveFileInCache

      public File getArchiveFileInCache(Artifact artifact, ArtifactOrigin origin)
      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
      origin - ArtifactOrigin
      Returns:
      File
    • getArchiveFileInCache

      private File getArchiveFileInCache(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. If useOrigin is false, this method will always return the file in the cache.
      Parameters:
      artifact - Artifact
      origin - ArtifactOrigin
      useOrigin - boolean
      Returns:
      File
    • getArchivePathInCache

      public String getArchivePathInCache(Artifact artifact)
    • getArchivePathInCache

      public String getArchivePathInCache(Artifact artifact, ArtifactOrigin origin)
    • saveResolver

      private void saveResolver(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)
      Parameters:
      md - the module descriptor resolved
      name - 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:
      saveResolvers in interface RepositoryCacheManager
      Parameters:
      md - the module descriptor resolved
      metadataResolverName - metadata resolver name
      artifactResolverName - artifact resolver name
    • getSavedResolverName

      private String getSavedResolverName(ModuleDescriptor md)
    • getSavedArtResolverName

      private String getSavedArtResolverName(ModuleDescriptor md)
    • saveArtifactOrigin

      void saveArtifactOrigin(Artifact artifact, ArtifactOrigin origin)
    • removeSavedArtifactOrigin

      private void removeSavedArtifactOrigin(Artifact artifact)
    • getSavedArtifactOrigin

      public ArtifactOrigin getSavedArtifactOrigin(Artifact artifact)
      Description copied from interface: RepositoryCacheManager
      Returns 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:
      getSavedArtifactOrigin in interface RepositoryCacheManager
      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

      private String getPrefixKey(Artifact artifact)
      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

      private String getLocationKey(Artifact artifact)
      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

      private String getIsLocalKey(Artifact artifact)
      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

      private String getLastCheckedKey(Artifact artifact)
      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

      private String getExistsKey(Artifact artifact)
      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

      private String getOriginalKey(Artifact artifact)
      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

      private PropertiesFile getCachedDataFile(ModuleDescriptor md)
    • getCachedDataFile

      private PropertiesFile getCachedDataFile(ModuleRevisionId mRevId)
    • getCachedDataFile

      private PropertiesFile getCachedDataFile(String resolverName, ModuleRevisionId mRevId)
      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: RepositoryCacheManager
      Search a module descriptor in cache for a mrid
      Specified by:
      findModuleInCache in interface RepositoryCacheManager
      Parameters:
      dd - the dependency descriptor identifying the module to search
      requestedRevisionId - the requested dependency module revision id identifying the module to search
      options - options on how caching should be handled
      expectedResolver - 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

      protected ModuleDescriptorParser getModuleDescriptorParser(File moduleDescriptorFile)
      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:
      ParseException
      IOException
    • getStaledMd

      private ModuleDescriptor getStaledMd(ModuleDescriptorParser mdParser, CacheMetadataOptions options, File ivyFile, ParserSettings parserSettings) throws ParseException, IOException
      Throws:
      ParseException
      IOException
    • getResolvedRevision

      private String getResolvedRevision(String expectedResolver, ModuleRevisionId mrid, CacheMetadataOptions options)
      Called by doFindModuleInCache to lookup the dynamic mrid in the ivycache's ivydata file.
    • saveResolvedRevision

      @Deprecated public void saveResolvedRevision(ModuleRevisionId mrid, String revision)
      Deprecated.
      Description copied from interface: RepositoryCacheManager
      Caches a dynamic revision constraint resolution.
      Specified by:
      saveResolvedRevision in interface RepositoryCacheManager
      Parameters:
      mrid - the dynamic module revision id
      revision - the resolved revision
    • saveResolvedRevision

      public void saveResolvedRevision(String resolverName, ModuleRevisionId mrid, String revision)
      Description copied from interface: RepositoryCacheManager
      Caches a dynamic revision constraint resolution for a specific resolver.
      Specified by:
      saveResolvedRevision in interface RepositoryCacheManager
      Parameters:
      resolverName - the resolver in which this dynamic revision was resolved
      mrid - the dynamic module revision id
      revision - the resolved revision
    • getTTL

      public long getTTL(ModuleRevisionId mrid)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getRepositoryCacheRoot

      public File getRepositoryCacheRoot()
    • getLockStrategy

      public LockStrategy getLockStrategy()
    • setLockStrategy

      public void setLockStrategy(LockStrategy lockStrategy)
    • setLockStrategy

      public void setLockStrategy(String lockStrategyName)
    • download

      public ArtifactDownloadReport download(Artifact artifact, ArtifactResourceResolver resourceResolver, ResourceDownloader resourceDownloader, CacheDownloadOptions options)
      Description copied from interface: RepositoryCacheManager
      Downloads an artifact to this cache.
      Specified by:
      download in interface RepositoryCacheManager
      Parameters:
      artifact - the artifact to download
      resourceResolver - a resource resolver to use if the artifact needs to be resolved to a Resource for downloading
      resourceDownloader - a resource downloader to use if actual download of the resource is needed
      options - 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: RepositoryCacheManager
      Download 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:
      downloadRepositoryResource in interface RepositoryCacheManager
      Parameters:
      resource - the resource of the file to put in cache
      name - 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 download
      repository - the repository which resolve the content of the resource
      Returns:
      a report indicating how the download was performed
    • computeResourceNameHash

      private String computeResourceNameHash(Resource resource)
      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 cache
      resource - the remote resource to check
      savedOrigin - the saved origin which contains that last checked date
      origin - the origin in which to store the new last checked date
      ttl - the time to live to consider the cache up to date
      Returns:
      true if 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: RepositoryCacheManager
      Stores a standardized version of an original module descriptor in the cache for later use.
      Specified by:
      originalToCachedModuleDescriptor in interface RepositoryCacheManager
      Parameters:
      resolver - the dependency resolver from which the cache request comes from
      originalMetadataRef - a resolved resource pointing to the remote original module descriptor
      requestedMetadataArtifact - the module descriptor artifact as requested originally
      rmr - the ResolvedModuleRevision representing the local cached module descriptor
      writer - a ModuleDescriptorWriter able 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: RepositoryCacheManager
      Caches 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:
      cacheModuleDescriptor in interface RepositoryCacheManager
      Parameters:
      resolver - the dependency resolver from which the cache request comes from
      mdRef - a resolved resource pointing to the remote original module descriptor
      dd - the dependency descriptor for which the module descriptor should be cached
      moduleArtifact - the module descriptor artifact as requested originally
      downloader - a ResourceDownloader able to download the original module descriptor resource if required by this cache implementation
      options - options to apply to cache this module descriptor
      Returns:
      a ResolvedModuleRevision representing the local cached module descriptor, or null if it failed
      Throws:
      ParseException - if an exception occurred while parsing the module descriptor
    • lockMetadataArtifact

      private boolean lockMetadataArtifact(ModuleRevisionId mrid)
    • unlockMetadataArtifact

      private void unlockMetadataArtifact(ModuleRevisionId mrid)
    • getDefaultMetadataArtifactOrigin

      private ArtifactOrigin getDefaultMetadataArtifactOrigin(ModuleRevisionId mrid)
    • getDefaultMetadataArtifact

      private Artifact getDefaultMetadataArtifact(ModuleRevisionId mrid)
    • getOriginalMetadataArtifact

      public Artifact getOriginalMetadataArtifact(Artifact moduleArtifact)
    • isOriginalMetadataArtifact

      private boolean isOriginalMetadataArtifact(Artifact artifact)
    • isChanging

      private boolean isChanging(DependencyDescriptor dd, ModuleRevisionId requestedRevisionId, CacheMetadataOptions options)
    • getChangingMatcher

      private Matcher getChangingMatcher(CacheMetadataOptions options)
    • isCheckmodified

      private boolean isCheckmodified(DependencyDescriptor dd, ModuleRevisionId requestedRevisionId, CacheMetadataOptions options)
    • clean

      public void clean()
      Description copied from interface: RepositoryCacheManager
      Cleans the whole cache.
      Specified by:
      clean in interface RepositoryCacheManager
    • dumpSettings

      public void dumpSettings()
    • assertInsideCache

      public final void assertInsideCache(File fileInCache)
      Throws:
      IllegalArgumentException - if the given path points outside of the cache.
    • parseArtifactOriginFilePath

      private static String parseArtifactOriginFilePath(ArtifactOrigin origin)
      If the location of the artifact origin is a file: scheme URI, then this method parses that URI and returns back the path of the file it represents. Else returns back ArtifactOrigin.getLocation()
      Parameters:
      origin - The artifact origin
      Returns: