Search in sources :

Example 1 with DefaultRepositoryCacheManager

use of org.apache.ivy.core.cache.DefaultRepositoryCacheManager 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 2 with DefaultRepositoryCacheManager

use of org.apache.ivy.core.cache.DefaultRepositoryCacheManager 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 3 with DefaultRepositoryCacheManager

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

the class IvySettings method addConfigured.

public void addConfigured(AbstractWorkspaceResolver workspaceResolver) {
    this.workspaceResolver = workspaceResolver;
    if (workspaceResolver != null) {
        workspaceResolver.setSettings(this);
        DefaultRepositoryCacheManager cacheManager = new DefaultRepositoryCacheManager();
        String cacheName = "workspace-resolver-cache-" + workspaceResolver.getName();
        cacheManager.setBasedir(new File(getDefaultCache(), cacheName));
        cacheManager.setCheckmodified(true);
        cacheManager.setUseOrigin(true);
        cacheManager.setName(cacheName);
        addRepositoryCacheManager(cacheManager);
        workspaceResolver.setCache(cacheName);
    }
}
Also used : DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) File(java.io.File)

Example 4 with DefaultRepositoryCacheManager

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

the class IvySettings method getDefaultRepositoryCacheManager.

public synchronized RepositoryCacheManager getDefaultRepositoryCacheManager() {
    if (defaultRepositoryCacheManager == null) {
        defaultRepositoryCacheManager = new DefaultRepositoryCacheManager("default-cache", this, getDefaultRepositoryCacheBasedir());
        addRepositoryCacheManager(defaultRepositoryCacheManager);
    }
    return defaultRepositoryCacheManager;
}
Also used : DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager)

Example 5 with DefaultRepositoryCacheManager

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

the class ResolveTest method testMultipleCache.

@Test
public void testMultipleCache() throws Exception {
    Ivy ivy = new Ivy();
    ivy.configure(new File("test/repositories/ivysettings-multicache.xml"));
    // mod2.1 depends on mod1.1 which depends on mod1.2
    ResolveReport report = ivy.resolve(new File("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.xml"), getResolveOptions(new String[] { "*" }));
    assertNotNull(report);
    assertFalse(report.hasError());
    // dependencies
    DefaultArtifact depArtifact = TestHelper.newArtifact("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar");
    ModuleRevisionId depMrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
    DefaultRepositoryCacheManager cacheMgr1 = (DefaultRepositoryCacheManager) ivy.getSettings().getDefaultRepositoryCacheManager();
    DefaultRepositoryCacheManager cacheMgr2 = (DefaultRepositoryCacheManager) ivy.getSettings().getRepositoryCacheManager("cache2");
    // ivy file should be cached in default cache, and artifact in cache2
    assertTrue(cacheMgr1.getIvyFileInCache(depMrid).exists());
    assertFalse(cacheMgr1.getArchiveFileInCache(depArtifact).exists());
    assertEquals(new File(cache, "repo1/mod1.1/ivy-1.0.xml").getCanonicalFile(), cacheMgr1.getIvyFileInCache(depMrid).getCanonicalFile());
    assertFalse(cacheMgr2.getIvyFileInCache(depMrid).exists());
    assertTrue(cacheMgr2.getArchiveFileInCache(depArtifact).exists());
    assertEquals(new File(cache, "repo2/mod1.1-1.0/mod1.1.jar").getCanonicalFile(), cacheMgr2.getArchiveFileInCache(depArtifact).getCanonicalFile());
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) Ivy(org.apache.ivy.Ivy) JarFile(java.util.jar.JarFile) File(java.io.File) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Aggregations

DefaultRepositoryCacheManager (org.apache.ivy.core.cache.DefaultRepositoryCacheManager)16 File (java.io.File)13 Test (org.junit.Test)11 JarFile (java.util.jar.JarFile)7 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)7 ResolveReport (org.apache.ivy.core.report.ResolveReport)7 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)6 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)6 Ivy (org.apache.ivy.Ivy)5 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)5 Artifact (org.apache.ivy.core.module.descriptor.Artifact)3 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)2 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)2 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)2 DownloadReport (org.apache.ivy.core.report.DownloadReport)2 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)2 ModuleDescriptorParserRegistryTest (org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)2 FileNotFoundException (java.io.FileNotFoundException)1