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);
}
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;
}
}
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;
}
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);
}
}
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());
}
Aggregations