Search in sources :

Example 1 with RepositoryCacheManager

use of org.apache.ivy.core.cache.RepositoryCacheManager 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)

Example 2 with RepositoryCacheManager

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

the class CacheResolver method ensureConfigured.

private void ensureConfigured() {
    if (getIvyPatterns().isEmpty()) {
        setIvyPatterns(new ArrayList<String>());
        setArtifactPatterns(new ArrayList<String>());
        for (RepositoryCacheManager cache : getSettings().getRepositoryCacheManagers()) {
            if (cache instanceof DefaultRepositoryCacheManager) {
                DefaultRepositoryCacheManager c = (DefaultRepositoryCacheManager) cache;
                addIvyPattern(c.getBasedir().getAbsolutePath() + "/" + c.getIvyPattern());
                addArtifactPattern(c.getBasedir().getAbsolutePath() + "/" + c.getArtifactPattern());
            } else {
                Message.verbose(cache + ": cache implementation is not a DefaultRepositoryCacheManager:" + " unable to configure cache resolver with it");
            }
        }
    }
}
Also used : RepositoryCacheManager(org.apache.ivy.core.cache.RepositoryCacheManager) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager)

Example 3 with RepositoryCacheManager

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

the class BuildOBRTask method doExecute.

public void doExecute() throws BuildException {
    if (file == null) {
        throw new BuildException("No output file specified: use the attribute 'out'");
    }
    Iterable<ManifestAndLocation> it;
    if (resolverName != null) {
        if (baseDir != null) {
            throw new BuildException("specify only one of 'resolver' or 'baseDir'");
        }
        if (cacheName != null) {
            throw new BuildException("specify only one of 'resolver' or 'cache'");
        }
        Ivy ivy = getIvyInstance();
        IvySettings settings = ivy.getSettings();
        DependencyResolver resolver = settings.getResolver(resolverName);
        if (resolver == null) {
            throw new BuildException("the resolver '" + resolverName + "' was not found");
        }
        if (!(resolver instanceof BasicResolver)) {
            throw new BuildException("the type of resolver '" + resolver.getClass().getName() + "' is not supported.");
        }
        it = new ResolverManifestIterable((BasicResolver) resolver);
    } else if (baseDir != null) {
        if (cacheName != null) {
            throw new BuildException("specify only one of 'baseDir' or 'cache'");
        }
        if (!baseDir.isDirectory()) {
            throw new BuildException(baseDir + " is not a directory");
        }
        it = new FSManifestIterable(baseDir);
    } else if (cacheName != null) {
        Ivy ivy = getIvyInstance();
        RepositoryCacheManager cacheManager = ivy.getSettings().getRepositoryCacheManager(cacheName);
        if (!(cacheManager instanceof DefaultRepositoryCacheManager)) {
            throw new BuildException("the type of cache '" + cacheManager.getClass().getName() + "' is not supported.");
        }
        File basedir = ((DefaultRepositoryCacheManager) cacheManager).getBasedir();
        it = new FSManifestIterable(basedir);
    } else {
        prepareAndCheck();
        try {
            it = new ArtifactReportManifestIterable(getArtifactReports(), sourceTypes);
        } catch (ParseException e) {
            throw new BuildException("Impossible to parse the artifact reports: " + e.getMessage(), e);
        }
    }
    OutputStream out;
    try {
        out = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        throw new BuildException(file + " was not found", e);
    }
    ContentHandler hd;
    try {
        hd = OBRXMLWriter.newHandler(out, encoding, indent);
    } catch (TransformerConfigurationException e) {
        throw new BuildException("Sax configuration error: " + e.getMessage(), e);
    }
    class AntMessageLogger2 extends AntMessageLogger {

        AntMessageLogger2() {
            super(BuildOBRTask.this);
        }
    }
    IvyContext.getContext().getMessageLogger();
    Message.setDefaultLogger(new AntMessageLogger2());
    try {
        OBRXMLWriter.writeManifests(it, hd, quiet);
    } catch (SAXException e) {
        throw new BuildException("Sax serialisation error: " + e.getMessage(), e);
    }
    try {
        out.flush();
        out.close();
    } catch (IOException e) {
    // don't care
    }
    Message.sumupProblems();
}
Also used : DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) RepositoryCacheManager(org.apache.ivy.core.cache.RepositoryCacheManager) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IvySettings(org.apache.ivy.core.settings.IvySettings) ArtifactReportManifestIterable(org.apache.ivy.osgi.repo.ArtifactReportManifestIterable) IOException(java.io.IOException) Ivy(org.apache.ivy.Ivy) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) ContentHandler(org.xml.sax.ContentHandler) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) SAXException(org.xml.sax.SAXException) FSManifestIterable(org.apache.ivy.osgi.repo.FSManifestIterable) FileOutputStream(java.io.FileOutputStream) BasicResolver(org.apache.ivy.plugins.resolver.BasicResolver) ResolverManifestIterable(org.apache.ivy.osgi.repo.ResolverManifestIterable) ManifestAndLocation(org.apache.ivy.osgi.repo.ManifestAndLocation) BuildException(org.apache.tools.ant.BuildException) ParseException(java.text.ParseException) File(java.io.File)

Example 4 with RepositoryCacheManager

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

the class XmlSettingsParser method endDocument.

@Override
public void endDocument() throws SAXException {
    if (defaultResolver != null) {
        ivy.setDefaultResolver(ivy.substitute(defaultResolver));
    }
    if (defaultCM != null) {
        ConflictManager conflictManager = ivy.getConflictManager(ivy.substitute(defaultCM));
        if (conflictManager == null) {
            throw new IllegalArgumentException("unknown conflict manager " + ivy.substitute(defaultCM));
        }
        ivy.setDefaultConflictManager(conflictManager);
    }
    if (defaultLatest != null) {
        LatestStrategy latestStrategy = ivy.getLatestStrategy(ivy.substitute(defaultLatest));
        if (latestStrategy == null) {
            throw new IllegalArgumentException("unknown latest strategy " + ivy.substitute(defaultLatest));
        }
        ivy.setDefaultLatestStrategy(latestStrategy);
    }
    if (defaultCacheManager != null) {
        RepositoryCacheManager cache = ivy.getRepositoryCacheManager(ivy.substitute(defaultCacheManager));
        if (cache == null) {
            throw new IllegalArgumentException("unknown cache manager " + ivy.substitute(defaultCacheManager));
        }
        ivy.setDefaultRepositoryCacheManager(cache);
    }
    if (defaultCircular != null) {
        CircularDependencyStrategy strategy = ivy.getCircularDependencyStrategy(ivy.substitute(defaultCircular));
        if (strategy == null) {
            throw new IllegalArgumentException("unknown circular dependency strategy " + ivy.substitute(defaultCircular));
        }
        ivy.setCircularDependencyStrategy(strategy);
    }
    if (defaultLock != null) {
        LockStrategy strategy = ivy.getLockStrategy(ivy.substitute(defaultLock));
        if (strategy == null) {
            throw new IllegalArgumentException("unknown lock strategy " + ivy.substitute(defaultLock));
        }
        ivy.setDefaultLockStrategy(strategy);
    }
}
Also used : CircularDependencyStrategy(org.apache.ivy.plugins.circular.CircularDependencyStrategy) RepositoryCacheManager(org.apache.ivy.core.cache.RepositoryCacheManager) LatestStrategy(org.apache.ivy.plugins.latest.LatestStrategy) ConflictManager(org.apache.ivy.plugins.conflict.ConflictManager) LockStrategy(org.apache.ivy.plugins.lock.LockStrategy)

Example 5 with RepositoryCacheManager

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

the class UpdateSiteAndIbiblioResolverTest method setUp.

@Before
public void setUp() throws Exception {
    settings = new IvySettings();
    chain = new ChainResolver();
    chain.setName("chain");
    chain.setSettings(settings);
    resolver = new UpdateSiteResolver();
    resolver.setName("ivyde-repo");
    resolver.setUrl(new File("test/test-p2/ivyde-repo").toURI().toURL().toExternalForm());
    resolver.setSettings(settings);
    resolver2 = new IBiblioResolver();
    resolver2.setName("maven2");
    settings.setVariable("ivy.ibiblio.default.artifact.root", DEFAULT_M2_ROOT);
    settings.setVariable("ivy.ibiblio.default.artifact.pattern", "[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
    resolver2.setSettings(settings);
    chain.add(resolver);
    chain.add(resolver2);
    settings.addResolver(chain);
    settings.setDefaultResolver("chain");
    cache = new File("build/cache");
    cache.mkdirs();
    settings.setDefaultCache(cache);
    ivy = new Ivy();
    ivy.setSettings(settings);
    ivy.bind();
    ivy.getResolutionCacheManager().clean();
    RepositoryCacheManager[] caches = settings.getRepositoryCacheManagers();
    for (RepositoryCacheManager cache : caches) {
        cache.clean();
    }
    data = new ResolveData(ivy.getResolveEngine(), new ResolveOptions());
}
Also used : ChainResolver(org.apache.ivy.plugins.resolver.ChainResolver) IBiblioResolver(org.apache.ivy.plugins.resolver.IBiblioResolver) ResolveData(org.apache.ivy.core.resolve.ResolveData) RepositoryCacheManager(org.apache.ivy.core.cache.RepositoryCacheManager) IvySettings(org.apache.ivy.core.settings.IvySettings) File(java.io.File) Ivy(org.apache.ivy.Ivy) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) Before(org.junit.Before)

Aggregations

RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)12 File (java.io.File)8 Ivy (org.apache.ivy.Ivy)6 IvySettings (org.apache.ivy.core.settings.IvySettings)6 ResolveData (org.apache.ivy.core.resolve.ResolveData)5 ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)5 Before (org.junit.Before)5 IOException (java.io.IOException)4 ParseException (java.text.ParseException)3 Artifact (org.apache.ivy.core.module.descriptor.Artifact)3 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)3 SAXException (org.xml.sax.SAXException)3 FileOutputStream (java.io.FileOutputStream)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 DefaultRepositoryCacheManager (org.apache.ivy.core.cache.DefaultRepositoryCacheManager)2 UpdateSiteResolver (org.apache.ivy.osgi.updatesite.UpdateSiteResolver)2 ResolvedResource (org.apache.ivy.plugins.resolver.util.ResolvedResource)2 BuildException (org.apache.tools.ant.BuildException)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1