Search in sources :

Example 1 with AbstractRepository

use of org.apache.ivy.plugins.repository.AbstractRepository in project ant-ivy by apache.

the class ResolveTest method testUseCacheOnly.

@Test
public void testUseCacheOnly() throws Exception {
    ResolveOptions option = getResolveOptions(new String[] { "*" }).setValidate(false);
    URL url = new File("test/repositories/1/usecacheonly/mod1/ivys/ivy-1.0.xml").toURI().toURL();
    // normal resolve, the file goes in the cache
    ResolveReport report = ivy.resolve(url, option);
    assertFalse(report.hasError());
    option.setUseCacheOnly(true);
    // use cache only, hit the cache
    report = ivy.resolve(url, option);
    assertFalse(report.hasError());
    CacheCleaner.deleteDir(cache);
    createCache();
    // no more in the cache, missed
    report = ivy.resolve(url, option);
    assertTrue(report.hasError());
    option.setUseCacheOnly(false);
    // try with use origin: should fail as the cache is empty
    ivy.getSettings().setDefaultUseOrigin(true);
    option.setUseCacheOnly(true);
    report = ivy.resolve(url, option);
    assertTrue(report.hasError());
    // populate the cache
    option.setUseCacheOnly(false);
    report = ivy.resolve(url, option);
    assertFalse(report.hasError());
    // use origin should now work
    option.setUseCacheOnly(true);
    report = ivy.resolve(url, option);
    assertFalse(report.hasError());
    // ensure that we hit only the cache and never try to hit in the repository
    FileSystemResolver resolver = (FileSystemResolver) ivy.getSettings().getResolver("1");
    resolver.setRepository(new AbstractRepository() {

        public List<String> list(String parent) {
            throw new UnsupportedOperationException();
        }

        public Resource getResource(String source) {
            throw new UnsupportedOperationException();
        }

        public void get(String source, File destination) {
            throw new UnsupportedOperationException();
        }
    });
    report = ivy.resolve(url, option);
    assertFalse(report.hasError());
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) AbstractRepository(org.apache.ivy.plugins.repository.AbstractRepository) Resource(org.apache.ivy.plugins.repository.Resource) List(java.util.List) ArrayList(java.util.ArrayList) JarFile(java.util.jar.JarFile) File(java.io.File) URL(java.net.URL) FileSystemResolver(org.apache.ivy.plugins.resolver.FileSystemResolver) Test(org.junit.Test)

Aggregations

File (java.io.File)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JarFile (java.util.jar.JarFile)1 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)1 ResolveReport (org.apache.ivy.core.report.ResolveReport)1 AbstractRepository (org.apache.ivy.plugins.repository.AbstractRepository)1 Resource (org.apache.ivy.plugins.repository.Resource)1 FileSystemResolver (org.apache.ivy.plugins.resolver.FileSystemResolver)1 Test (org.junit.Test)1