Search in sources :

Example 1 with LatestStrategy

use of org.apache.ivy.plugins.latest.LatestStrategy in project ant-ivy by apache.

the class ChainResolver method getDependency.

public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
    data = new ResolveData(data, doValidate(data));
    List<Exception> errors = new ArrayList<>();
    ResolvedModuleRevision resolved = data.getCurrentResolvedModuleRevision();
    ResolvedModuleRevision mr = resolved;
    if (mr == null) {
        Message.verbose(getName() + ": Checking cache for: " + dd);
        mr = findModuleInCache(dd, data, true);
        if (mr != null) {
            Message.verbose(getName() + ": module revision found in cache: " + mr.getId());
            mr = forcedRevision(mr);
        }
    }
    for (DependencyResolver resolver : chain) {
        LatestStrategy oldLatest = setLatestIfRequired(resolver, getLatestStrategy());
        try {
            ResolvedModuleRevision previouslyResolved = mr;
            data.setCurrentResolvedModuleRevision(previouslyResolved);
            mr = resolver.getDependency(dd, data);
            if (mr != previouslyResolved && isReturnFirst()) {
                mr = forcedRevision(mr);
            }
        } catch (Exception ex) {
            Message.verbose("problem occurred while resolving " + dd + " with " + resolver, ex);
            errors.add(ex);
        } finally {
            if (oldLatest != null) {
                setLatest(resolver, oldLatest);
            }
        }
        checkInterrupted();
    }
    if (mr == null && !errors.isEmpty()) {
        if (errors.size() == 1) {
            Exception ex = errors.get(0);
            if (ex instanceof RuntimeException) {
                throw (RuntimeException) ex;
            } else if (ex instanceof ParseException) {
                throw (ParseException) ex;
            } else {
                throw new RuntimeException(ex.toString(), ex);
            }
        } else {
            StringBuilder err = new StringBuilder();
            for (Exception ex : errors) {
                err.append("\t").append(StringUtils.getErrorMessage(ex)).append("\n");
            }
            err.setLength(err.length() - 1);
            throw new RuntimeException("several problems occurred while resolving " + dd + ":\n" + err);
        }
    }
    if (resolved == mr) {
        // nothing has actually been resolved here, we don't need to touch the returned rmr
        return resolved;
    }
    return resolvedRevision(mr);
}
Also used : ResolveData(org.apache.ivy.core.resolve.ResolveData) ArrayList(java.util.ArrayList) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) HasLatestStrategy(org.apache.ivy.plugins.resolver.util.HasLatestStrategy) LatestStrategy(org.apache.ivy.plugins.latest.LatestStrategy) ParseException(java.text.ParseException) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 2 with LatestStrategy

use of org.apache.ivy.plugins.latest.LatestStrategy in project ant-ivy by apache.

the class ChainResolver method setLatestIfRequired.

private LatestStrategy setLatestIfRequired(DependencyResolver resolver, LatestStrategy latestStrategy) {
    String latestName = getLatestStrategyName(resolver);
    if (latestName != null && !"default".equals(latestName)) {
        LatestStrategy oldLatest = getLatest(resolver);
        setLatest(resolver, latestStrategy);
        return oldLatest;
    } else {
        return null;
    }
}
Also used : HasLatestStrategy(org.apache.ivy.plugins.resolver.util.HasLatestStrategy) LatestStrategy(org.apache.ivy.plugins.latest.LatestStrategy)

Example 3 with LatestStrategy

use of org.apache.ivy.plugins.latest.LatestStrategy in project ant-ivy by apache.

the class IvySettings method getLatestStrategy.

public synchronized LatestStrategy getLatestStrategy(String name) {
    if ("default".equals(name)) {
        return getDefaultLatestStrategy();
    }
    LatestStrategy strategy = latestStrategies.get(name);
    if (workspaceResolver != null && !(strategy instanceof WorkspaceLatestStrategy)) {
        strategy = new WorkspaceLatestStrategy(strategy);
        latestStrategies.put(name, strategy);
    }
    return strategy;
}
Also used : WorkspaceLatestStrategy(org.apache.ivy.plugins.latest.WorkspaceLatestStrategy) LatestStrategy(org.apache.ivy.plugins.latest.LatestStrategy) WorkspaceLatestStrategy(org.apache.ivy.plugins.latest.WorkspaceLatestStrategy) OsgiLatestStrategy(org.apache.ivy.osgi.core.OsgiLatestStrategy)

Example 4 with LatestStrategy

use of org.apache.ivy.plugins.latest.LatestStrategy 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 LatestStrategy

use of org.apache.ivy.plugins.latest.LatestStrategy in project ant-ivy by apache.

the class XmlSettingsParserTest method test.

@Test
public void test() throws Exception {
    IvySettings settings = new IvySettings();
    XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-test.xml"));
    File defaultCache = settings.getDefaultCache();
    assertNotNull(defaultCache);
    assertEquals("mycache", defaultCache.getName());
    assertFalse(settings.isCheckUpToDate());
    assertFalse(settings.doValidate());
    assertEquals("[module]/ivys/ivy-[revision].xml", settings.getDefaultCacheIvyPattern());
    assertEquals("[module]/[type]s/[artifact]-[revision].[ext]", settings.getDefaultCacheArtifactPattern());
    LatestStrategy latest = settings.getLatestStrategy("mylatest-revision");
    assertNotNull(latest);
    assertTrue(latest instanceof LatestRevisionStrategy);
    LatestRevisionStrategy l = (LatestRevisionStrategy) latest;
    assertEquals(new Integer(-2), l.getSpecialMeanings().get("pre"));
    assertEquals(new Integer(4), l.getSpecialMeanings().get("qa"));
    DependencyResolver defaultResolver = settings.getDefaultResolver();
    assertNotNull(defaultResolver);
    assertEquals("libraries", defaultResolver.getName());
    assertTrue(defaultResolver instanceof FileSystemResolver);
    FileSystemResolver fsres = (FileSystemResolver) defaultResolver;
    List<String> ivyPatterns = fsres.getIvyPatterns();
    assertNotNull(ivyPatterns);
    assertEquals(1, ivyPatterns.size());
    assertLocationEquals("lib/[organisation]/[module]/ivys/ivy-[revision].xml", ivyPatterns.get(0));
    LatestStrategy strategy = fsres.getLatestStrategy();
    assertNotNull(strategy);
    assertTrue(strategy instanceof LatestRevisionStrategy);
    DependencyResolver internal = settings.getResolver("internal");
    assertNotNull(internal);
    assertTrue(internal instanceof ChainResolver);
    ChainResolver chain = (ChainResolver) internal;
    List<DependencyResolver> subresolvers = chain.getResolvers();
    assertNotNull(subresolvers);
    assertEquals(2, subresolvers.size());
    FileSystemResolver fsInt1 = (FileSystemResolver) subresolvers.get(0);
    assertEquals("int1", fsInt1.getName());
    assertEquals(1, fsInt1.getIvyPatterns().size());
    assertLocationEquals("sharedrep/[organisation]/[module]/ivys/ivy-[revision].xml", fsInt1.getIvyPatterns().get(0));
    assertEquals("int2", subresolvers.get(1).getName());
    strategy = fsInt1.getLatestStrategy();
    assertNotNull(strategy);
    assertTrue(strategy instanceof LatestTimeStrategy);
    assertEquals("libraries", settings.getResolver(ModuleRevisionId.newInstance("unknown", "lib", "1.0")).getName());
    assertEquals("internal", settings.getResolver(ModuleRevisionId.newInstance("apache", "ant", "1.0")).getName());
    assertEquals("int2", settings.getResolver(ModuleRevisionId.newInstance("apache", "ivy", "2.0")).getName());
    assertEquals("int1", settings.getResolver(ModuleRevisionId.newInstance("apache", "ivy", "1.0")).getName());
    assertEquals("int1", settings.getResolver(ModuleRevisionId.newInstance("apache", "ivyde", "1.0")).getName());
}
Also used : ChainResolver(org.apache.ivy.plugins.resolver.ChainResolver) LatestRevisionStrategy(org.apache.ivy.plugins.latest.LatestRevisionStrategy) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) LatestStrategy(org.apache.ivy.plugins.latest.LatestStrategy) LatestTimeStrategy(org.apache.ivy.plugins.latest.LatestTimeStrategy) File(java.io.File) FileSystemResolver(org.apache.ivy.plugins.resolver.FileSystemResolver) Test(org.junit.Test) ModuleDescriptorParserRegistryTest(org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)

Aggregations

LatestStrategy (org.apache.ivy.plugins.latest.LatestStrategy)6 ArrayList (java.util.ArrayList)2 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)2 DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)2 HasLatestStrategy (org.apache.ivy.plugins.resolver.util.HasLatestStrategy)2 File (java.io.File)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 Ivy (org.apache.ivy.Ivy)1 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)1 ModuleId (org.apache.ivy.core.module.id.ModuleId)1 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)1 ResolveData (org.apache.ivy.core.resolve.ResolveData)1 SearchEngine (org.apache.ivy.core.search.SearchEngine)1 IvySettings (org.apache.ivy.core.settings.IvySettings)1 OsgiLatestStrategy (org.apache.ivy.osgi.core.OsgiLatestStrategy)1 CircularDependencyStrategy (org.apache.ivy.plugins.circular.CircularDependencyStrategy)1 ConflictManager (org.apache.ivy.plugins.conflict.ConflictManager)1 ArtifactInfo (org.apache.ivy.plugins.latest.ArtifactInfo)1 LatestRevisionStrategy (org.apache.ivy.plugins.latest.LatestRevisionStrategy)1