Search in sources :

Example 1 with ModuleDescriptorWriter

use of org.apache.ivy.core.cache.ModuleDescriptorWriter in project ant-ivy by apache.

the class BasicResolver method cacheModuleDescriptor.

private void cacheModuleDescriptor(ModuleDescriptor systemMd, ModuleRevisionId systemMrid, ResolvedResource ivyRef, ResolvedModuleRevision rmr) {
    RepositoryCacheManager cacheManager = getRepositoryCacheManager();
    final ModuleDescriptorParser parser = systemMd.getParser();
    // the metadata artifact which was used to cache the original metadata file
    Artifact requestedMetadataArtifact = (ivyRef == null) ? systemMd.getMetadataArtifact() : parser.getMetadataArtifact(ModuleRevisionId.newInstance(systemMrid, systemMd.getRevision()), ivyRef.getResource());
    cacheManager.originalToCachedModuleDescriptor(this, ivyRef, requestedMetadataArtifact, rmr, new ModuleDescriptorWriter() {

        public void write(ResolvedResource originalMdResource, ModuleDescriptor md, File src, File dest) throws IOException, ParseException {
            if (originalMdResource == null) {
                // a basic ivy file is written containing default data
                XmlModuleDescriptorWriter.write(md, dest);
            } else {
                // copy and update ivy file from source to cache
                parser.toIvyFile(new FileInputStream(src), originalMdResource.getResource(), dest, md);
                long repLastModified = originalMdResource.getLastModified();
                if (repLastModified > 0) {
                    dest.setLastModified(repLastModified);
                }
            }
        }
    });
}
Also used : DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) RepositoryCacheManager(org.apache.ivy.core.cache.RepositoryCacheManager) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource) IOException(java.io.IOException) ParseException(java.text.ParseException) ModuleDescriptorWriter(org.apache.ivy.core.cache.ModuleDescriptorWriter) XmlModuleDescriptorWriter(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter) File(java.io.File) ModuleDescriptorParser(org.apache.ivy.plugins.parser.ModuleDescriptorParser) Artifact(org.apache.ivy.core.module.descriptor.Artifact) FileInputStream(java.io.FileInputStream)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 ModuleDescriptorWriter (org.apache.ivy.core.cache.ModuleDescriptorWriter)1 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)1 Artifact (org.apache.ivy.core.module.descriptor.Artifact)1 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)1 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)1 ModuleDescriptorParser (org.apache.ivy.plugins.parser.ModuleDescriptorParser)1 XmlModuleDescriptorWriter (org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter)1 MDResolvedResource (org.apache.ivy.plugins.resolver.util.MDResolvedResource)1 ResolvedResource (org.apache.ivy.plugins.resolver.util.ResolvedResource)1