org.apache.ivy.plugins.resolver.ChainResolver Java Examples
The following examples show how to use
org.apache.ivy.plugins.resolver.ChainResolver.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MavenResolver.java From IJava with MIT License | 6 votes |
private ChainResolver searchAllReposResolver(Set<String> repos) { ChainResolver resolver = new ChainResolver(); resolver.setName(DEFAULT_RESOLVER_NAME); this.repos.stream() .filter(r -> repos == null || repos.contains(r.getName().toLowerCase())) .forEach(resolver::add); if (repos != null) { Set<String> resolverNames = resolver.getResolvers().stream() .map(d -> d.getName().toLowerCase()) .collect(Collectors.toSet()); repos.removeAll(resolverNames); repos.forEach(r -> { try { URL url = new URL(r); resolver.add(CommonRepositories.maven("from-" + url.getHost(), r)); } catch (MalformedURLException e) { // Ignore as we will assume that a bad url was a name } }); } return resolver; }
Example #2
Source File: IvySettings.java From ant-ivy with Apache License 2.0 | 6 votes |
public synchronized void addResolver(DependencyResolver resolver) { if (resolver == null) { throw new NullPointerException("null resolver"); } init(resolver); resolversMap.put(resolver.getName(), resolver); if (resolver instanceof ChainResolver) { List<DependencyResolver> subresolvers = ((ChainResolver) resolver).getResolvers(); for (DependencyResolver dr : subresolvers) { addResolver(dr); } } else if (resolver instanceof DualResolver) { DependencyResolver ivyResolver = ((DualResolver) resolver).getIvyResolver(); if (ivyResolver != null) { addResolver(ivyResolver); } DependencyResolver artifactResolver = ((DualResolver) resolver).getArtifactResolver(); if (artifactResolver != null) { addResolver(artifactResolver); } } }
Example #3
Source File: XmlSettingsParserTest.java From ant-ivy with Apache License 2.0 | 6 votes |
@Test public void testTypedef() throws Exception { IvySettings settings = new IvySettings(); XmlSettingsParser parser = new XmlSettingsParser(settings); parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-typedef.xml")); DependencyResolver mock = settings.getResolver("mock3"); assertNotNull(mock); assertTrue(mock instanceof MockResolver); 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()); assertEquals("mock1", subresolvers.get(0).getName()); assertEquals("mock2", subresolvers.get(1).getName()); assertTrue(subresolvers.get(0) instanceof MockResolver); assertTrue(subresolvers.get(1) instanceof MockResolver); }
Example #4
Source File: XmlSettingsParserTest.java From ant-ivy with Apache License 2.0 | 6 votes |
/** * Test case for IVY-319. * * @throws Exception if something goes wrong * @see <a href="https://issues.apache.org/jira/browse/IVY-319">IVY-319</a> */ @Test public void testMacroAndRef() throws Exception { IvySettings settings = new IvySettings(); XmlSettingsParser parser = new XmlSettingsParser(settings); parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-macro+ref.xml")); DependencyResolver shared = settings.getResolver("shared"); assertNotNull(shared); assertTrue(shared instanceof FileSystemResolver); DependencyResolver mychain = settings.getResolver("mychain"); assertNotNull(mychain); assertTrue(mychain instanceof ChainResolver); ChainResolver chain = (ChainResolver) mychain; List<DependencyResolver> subresolvers = chain.getResolvers(); assertNotNull(subresolvers); assertEquals(1, subresolvers.size()); shared = subresolvers.get(0); assertEquals("shared", shared.getName()); assertTrue(shared instanceof FileSystemResolver); }
Example #5
Source File: XmlSettingsParserTest.java From ant-ivy with Apache License 2.0 | 6 votes |
/** * Test case for IVY-860. * * @throws Exception if something goes wrong * @see <a href="https://issues.apache.org/jira/browse/IVY-860">IVY-860</a> */ @Test public void testMacroAndRef2() throws Exception { IvySettings settings = new IvySettings(); XmlSettingsParser parser = new XmlSettingsParser(settings); parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-macro+ref2.xml")); DependencyResolver macrores = settings.getResolver("macroresolver"); assertNotNull(macrores); assertTrue(macrores instanceof ChainResolver); DependencyResolver testResolver = settings.getResolver("test"); assertNotNull(testResolver); assertTrue(testResolver instanceof IBiblioResolver); ChainResolver chain = (ChainResolver) macrores; List<DependencyResolver> subresolvers = chain.getResolvers(); assertNotNull(subresolvers); assertEquals(1, subresolvers.size()); assertEquals(testResolver, subresolvers.get(0)); }
Example #6
Source File: MavenResolver.java From IJava with MIT License | 5 votes |
private void addPomReposToIvySettings(IvySettings settings, File pomFile) throws ModelBuildingException { Model mavenModel = Maven.getInstance().readEffectiveModel(pomFile).getEffectiveModel(); ChainResolver pomRepos = MavenToIvy.createChainForModelRepositories(mavenModel); pomRepos.setName(DEFAULT_RESOLVER_NAME); settings.addResolver(pomRepos); settings.setDefaultResolver(DEFAULT_RESOLVER_NAME); }
Example #7
Source File: XmlSettingsParserTest.java From ant-ivy with Apache License 2.0 | 5 votes |
@Test public void testIncludeAbsoluteFile() throws Exception { // WARNING : this test will only work if the test are launched from the project root // directory IvySettings settings = new IvySettings(); XmlSettingsParser parser = new XmlSettingsParser(settings); parser.parse(XmlSettingsParserTest.class .getResource("ivysettings-include-absolute-file.xml")); DependencyResolver inc = settings.getResolver("includeworks"); assertNotNull(inc); assertTrue(inc instanceof ChainResolver); }
Example #8
Source File: OnlineXmlSettingsParserTest.java From ant-ivy with Apache License 2.0 | 5 votes |
@Test public void testIncludeHttpAbsoluteFile() throws Exception { // Use a settings file via http that use an include with absolute file // WARNING : this test will only work if the test are launched from the project root // directory configureURLHandler(); IvySettings settings = new IvySettings(); XmlSettingsParser parser = new XmlSettingsParser(settings); parser.parse(new URL( "http://ant.apache.org/ivy/test/ivysettings-include-http-absolute-file.xml")); DependencyResolver inc = settings.getResolver("includeworks"); assertNotNull(inc); assertTrue(inc instanceof ChainResolver); }
Example #9
Source File: MavenResolver.java From IJava with MIT License | 4 votes |
public List<File> resolveMavenDependency(String canonical, Set<String> repos, int verbosity) throws IOException, ParseException { ChainResolver rootResolver = this.searchAllReposResolver(repos); Ivy ivy = this.createDefaultIvyInstance(verbosity); IvySettings settings = ivy.getSettings(); settings.addResolver(rootResolver); rootResolver.setCheckmodified(true); settings.setDefaultResolver(rootResolver.getName()); ivy.getLoggerEngine().info("Searching for dependencies in: " + rootResolver.getResolvers()); ResolveOptions resolveOptions = new ResolveOptions(); resolveOptions.setTransitive(true); resolveOptions.setDownload(true); ModuleRevisionId artifactIdentifier = MavenResolver.parseCanonicalArtifactName(canonical); DefaultModuleDescriptor containerModule = DefaultModuleDescriptor.newCallerInstance( artifactIdentifier, DEFAULT_RESOLVE_CONFS, true, // Transitive repos != null // Changing - the resolver will set this based on SNAPSHOT since they are all m2 compatible // but if `repos` is specified, we want to force a lookup. ); ResolveReport resolved = ivy.resolve(containerModule, resolveOptions); if (resolved.hasError()) { MessageLogger logger = ivy.getLoggerEngine(); Arrays.stream(resolved.getAllArtifactsReports()) .forEach(r -> { logger.error("download " + r.getDownloadStatus() + ": " + r.getArtifact() + " of " + r.getType()); if (r.getArtifactOrigin() == null) logger.error("\tCouldn't find artifact."); else logger.error("\tfrom: " + r.getArtifactOrigin()); }); // TODO better error... throw new RuntimeException("Error resolving '" + canonical + "'. " + resolved.getAllProblemMessages()); } return Arrays.stream(resolved.getAllArtifactsReports()) .filter(a -> JAR_TYPE.equalsIgnoreCase(a.getType())) .map(ArtifactDownloadReport::getLocalFile) .collect(Collectors.toList()); }
Example #10
Source File: XmlSettingsParserTest.java From ant-ivy with Apache License 2.0 | 4 votes |
@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()); }
Example #11
Source File: MavenToIvy.java From IJava with MIT License | 3 votes |
public static ChainResolver createChainForModelRepositories(Model model) { ChainResolver resolver = new ChainResolver(); // Maven central is always an implicit repository. resolver.add(CommonRepositories.mavenCentral()); MavenToIvy.getRepositoriesFromModel(model).forEach(resolver::add); return resolver; }