Java Code Examples for org.apache.ivy.Ivy#resolve()
The following examples show how to use
org.apache.ivy.Ivy#resolve() .
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 List<File> resolveFromIvyFile(Ivy ivy, File ivyFile, List<String> scopes) throws IOException, ParseException { ResolveOptions resolveOptions = new ResolveOptions(); resolveOptions.setTransitive(true); resolveOptions.setDownload(true); resolveOptions.setConfs(!scopes.isEmpty() ? scopes.toArray(new String[0]) : DEFAULT_RESOLVE_CONFS ); ResolveReport resolved = ivy.resolve(ivyFile, resolveOptions); if (resolved.hasError()) // TODO better error... throw new RuntimeException("Error resolving '" + ivyFile + "'. " + resolved.getAllProblemMessages()); return Arrays.stream(resolved.getAllArtifactsReports()) .map(ArtifactDownloadReport::getLocalFile) .collect(Collectors.toList()); }
Example 2
Source File: LatestConflictManagerTest.java From ant-ivy with Apache License 2.0 | 6 votes |
/** * Test case for IVY-407. * * @throws Exception if something goes wrong * @see <a href="https://issues.apache.org/jira/browse/IVY-407">IVY-407</a> */ @Test public void testLatestTime1() throws Exception { ivy = new Ivy(); ivy.configure(LatestConflictManagerTest.class.getResource("ivysettings-latest-time.xml")); ivy.getSettings().setVariable("ivy.log.conflict.resolution", "true", true); // set timestamps, because svn is not preserving this information, // and the latest time strategy is relying on it long time = System.currentTimeMillis() - 10000; new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").setLastModified(time); new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.2.jar") .setLastModified(time + 2000); ResolveReport report = ivy.resolve( LatestConflictManagerTest.class.getResource("ivy-latest-time-1.xml"), getResolveOptions()); ConfigurationResolveReport defaultReport = report.getConfigurationReport("default"); for (ModuleRevisionId mrid : defaultReport.getModuleRevisionIds()) { if (mrid.getName().equals("mod1.1")) { assertEquals("1.0", mrid.getRevision()); } else if (mrid.getName().equals("mod1.2")) { assertEquals("2.2", mrid.getRevision()); } } }
Example 3
Source File: LatestConflictManagerTest.java From ant-ivy with Apache License 2.0 | 6 votes |
@Test public void testLatestTime2() throws Exception { ivy = new Ivy(); ivy.configure(LatestConflictManagerTest.class.getResource("ivysettings-latest-time.xml")); ivy.getSettings().setVariable("ivy.log.conflict.resolution", "true", true); // set timestamps, because svn is not preserving this information, // and the latest time strategy is relying on it long time = System.currentTimeMillis() - 10000; new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").setLastModified(time); new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.2.jar") .setLastModified(time + 2000); ResolveReport report = ivy.resolve( LatestConflictManagerTest.class.getResource("ivy-latest-time-2.xml"), getResolveOptions()); ConfigurationResolveReport defaultReport = report.getConfigurationReport("default"); for (ModuleRevisionId mrid : defaultReport.getModuleRevisionIds()) { if (mrid.getName().equals("mod1.1")) { assertEquals("1.0", mrid.getRevision()); } else if (mrid.getName().equals("mod1.2")) { assertEquals("2.2", mrid.getRevision()); } } }
Example 4
Source File: AntBuildTriggerTest.java From ant-ivy with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { assertFalse(new File("test/triggers/ant-build/A/A.jar").exists()); Ivy ivy = new Ivy(); ivy.configure(new File("test/triggers/ant-build/ivysettings.xml")); ResolveReport r = ivy.resolve(new File("test/triggers/ant-build/B/ivy.xml")); assertFalse(r.hasError()); // should have triggered an A publish assertTrue(new File("test/triggers/ant-build/local/A/A.jar").exists()); }
Example 5
Source File: LatestConflictManagerTest.java From ant-ivy with Apache License 2.0 | 5 votes |
/** * Test case for IVY-407 (with transitivity). There are 5 modules A, B, C, D and E. * <ol> * <li>publish C-1.0.0, C-1.0.1 and C-1.0.2</li> * <li>B needs C-1.0.0 : retrieve ok and publish B-1.0.0</li> * <li>A needs B-1.0.0 and C-1.0.2 : retrieve ok and publish A-1.0.0</li> * <li>D needs C-1.0.1 : retrieve ok and publish D-1.0.0</li> * <li>E needs D-1.0.0 and A-1.0.0 (D before A in ivy file) : * retrieve failed to get C-1.0.2 from A (get apparently C-1.0.1 from D)</li> * </ol> * * @throws Exception if something goes wrong * @see <a href="https://issues.apache.org/jira/browse/IVY-407">IVY-407</a> */ @Test public void testLatestTimeTransitivity() throws Exception { ivy = new Ivy(); ivy.configure(LatestConflictManagerTest.class .getResource("ivysettings-latest-time-transitivity.xml")); ivy.getSettings().setVariable("ivy.log.conflict.resolution", "true", true); // set timestamps, because svn is not preserving this information, // and the latest time strategy is relying on it long time = System.currentTimeMillis() - 10000; new File("test/repositories/IVY-407/MyCompany/C/ivy-1.0.0.xml").setLastModified(time); new File("test/repositories/IVY-407/MyCompany/C/ivy-1.0.1.xml") .setLastModified(time + 2000); new File("test/repositories/IVY-407/MyCompany/C/ivy-1.0.2.xml") .setLastModified(time + 4000); ResolveReport report = ivy.resolve( LatestConflictManagerTest.class.getResource("ivy-latest-time-transitivity.xml"), getResolveOptions()); ConfigurationResolveReport defaultReport = report.getConfigurationReport("default"); for (ModuleRevisionId mrid : defaultReport.getModuleRevisionIds()) { switch (mrid.getName()) { case "A": assertEquals("A revision should be 1.0.0", "1.0.0", mrid.getRevision()); break; case "B": // by transitivity assertEquals("B revision should be 1.0.0", "1.0.0", mrid.getRevision()); break; case "C": assertEquals("C revision should be 1.0.2", "1.0.2", mrid.getRevision()); break; case "D": assertEquals("D revision should be 1.0.0", "1.0.0", mrid.getRevision()); break; } } }
Example 6
Source File: TestClassWithDependencyRunner.java From apm-agent-java with Apache License 2.0 | 4 votes |
private static List<URL> resolveArtifacts(List<String> dependencies) throws Exception { //creates clear ivy settings IvySettings ivySettings = new IvySettings(); //url resolver for configuration of maven repo URLResolver resolver = new URLResolver(); resolver.setM2compatible(true); resolver.setName("central"); //you can specify the url resolution pattern strategy resolver.addArtifactPattern( "https://repo1.maven.org/maven2/" + "[organisation]/[module]/[revision]/[artifact](-[revision]).[ext]"); //adding maven repo resolver ivySettings.addResolver(resolver); //set to the default resolver ivySettings.setDefaultResolver(resolver.getName()); //creates an Ivy instance with settings Ivy ivy = Ivy.newInstance(ivySettings); File ivyfile = File.createTempFile("ivy", ".xml"); ivyfile.deleteOnExit(); DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.newInstance("foo", "foo" + "-caller", "working")); for (String dependency : dependencies) { String[] split = dependency.split(":"); DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(split[0], split[1], split[2]), false, false, true); md.addDependency(dd); } //creates an ivy configuration file XmlModuleDescriptorWriter.write(md, ivyfile); String[] confs = new String[]{"default"}; ResolveOptions resolveOptions = new ResolveOptions().setConfs(confs); //init resolve report ResolveReport report = ivy.resolve(ivyfile.toURL(), resolveOptions); List<URL> resolvedDependencies = new ArrayList<>(); ArtifactDownloadReport[] allArtifactsReports = report.getAllArtifactsReports(); for (ArtifactDownloadReport allArtifactsReport : allArtifactsReports) { resolvedDependencies.add(allArtifactsReport.getLocalFile().toURI().toURL()); } assertThat(resolvedDependencies).hasSizeGreaterThanOrEqualTo(dependencies.size()); return resolvedDependencies; }
Example 7
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 8
Source File: SampleIvyRunner.java From jeka with Apache License 2.0 | 4 votes |
public void retrieve() { final IBiblioResolver dependencyResolver = new IBiblioResolver(); dependencyResolver .setRoot("http://i-net1102e-prod:8081/nexus/content/groups/bnppf-secured"); dependencyResolver.setM2compatible(true); dependencyResolver.setUseMavenMetadata(true); dependencyResolver.setName("nexus"); // Name is necessary to avoid NPE final IvySettings ivySettings = new IvySettings(); ivySettings.addResolver(dependencyResolver); ivySettings.setDefaultResolver("nexus"); // Setting a default resolver // is necessary final Ivy ivy = Ivy.newInstance(ivySettings); ivy.getLoggerEngine().setDefaultLogger(new DefaultMessageLogger(Message.MSG_DEBUG)); final ModuleRevisionId thisModuleRevisionId = ModuleRevisionId.newInstance("mygroupId", "myartifactId-envelope", "myversion"); final ModuleRevisionId dependee = ModuleRevisionId.newInstance("org.springframework", "spring-jdbc", "3.0.0.RELEASE"); // final ModuleRevisionId dependee = // ModuleRevisionId.newInstance("org.hibernate", // "hibernate-core", "3.6.10.Final"); // 1st create an ivy module (this always(!) has a "default" // configuration already) final DefaultModuleDescriptor moduleDescriptor = DefaultModuleDescriptor .newDefaultInstance(thisModuleRevisionId); // don't go transitive here, if you want the single artifact final boolean transitive = true; final DefaultDependencyDescriptor dependencyDescriptor = new DefaultDependencyDescriptor( moduleDescriptor, dependee, false, false, transitive); // map to master to just get the code jar. See generated ivy module xmls // from maven repo // on how configurations are mapped into ivy. Or check // e.g. // http://lightguard-jp.blogspot.de/2009/04/ivy-configurations-when-pulling-from.html // dependencyDescriptor.addDependencyConfiguration("default", "master"); // To get more than 1 artifact i need to declare "compile" and not // "master" dependencyDescriptor.addDependencyConfiguration("default", "compile"); moduleDescriptor.addDependency(dependencyDescriptor); // now resolve final ResolveOptions resolveOptions = new ResolveOptions() .setConfs(new String[] { "default" }); resolveOptions.setTransitive(transitive); ResolveReport reportResolver; try { reportResolver = ivy.resolve(moduleDescriptor, resolveOptions); } catch (final Exception e1) { throw new RuntimeException(e1); } if (reportResolver.hasError()) { System.out .println("*************************************************************************"); System.out.println(reportResolver); throw new RuntimeException(reportResolver.getAllProblemMessages().toString()); } for (final ArtifactDownloadReport artifactDownloadReport : reportResolver .getAllArtifactsReports()) { System.out.println("*********************************" + artifactDownloadReport.getLocalFile()); } final String filePattern = new File("jeka/output/downloaded-libs").getAbsolutePath() + "/[artifact](-[classifier]).[ext]"; final RetrieveOptions retrieveOptions = new RetrieveOptions() .setConfs(new String[] { "default" }); try { ivy.retrieve(moduleDescriptor.getModuleRevisionId(), filePattern, retrieveOptions); } catch (final IOException e) { throw new RuntimeException(e); } }
Example 9
Source File: IvyRepositoryReport.java From ant-ivy with Apache License 2.0 | 4 votes |
public void doExecute() throws BuildException { Ivy ivy = getIvyInstance(); IvySettings settings = ivy.getSettings(); if (xsl && xslFile == null) { throw new BuildException("xsl file is mandatory when using xsl generation"); } if (module == null && PatternMatcher.EXACT.equals(matcher)) { throw new BuildException("no module name provided for ivy repository graph task: " + "It can either be set explicitly via the attribute 'module' or " + "via 'ivy.module' property or a prior call to <resolve/>"); } else if (module == null && !PatternMatcher.EXACT.equals(matcher)) { module = PatternMatcher.ANY_EXPRESSION; } ModuleRevisionId moduleRevisionId = ModuleRevisionId.newInstance(organisation, module, revision); try { ModuleRevisionId criteria = (revision == null) || settings.getVersionMatcher().isDynamic(moduleRevisionId) ? new ModuleRevisionId(new ModuleId(organisation, module), branch, "*") : new ModuleRevisionId(new ModuleId(organisation, module), branch, revision); ModuleRevisionId[] mrids = ivy.listModules(criteria, settings.getMatcher(matcher)); // replace all found revisions with the original requested revision Set<ModuleRevisionId> modules = new HashSet<>(); for (ModuleRevisionId mrid : mrids) { modules.add(ModuleRevisionId.newInstance(mrid, revision)); } mrids = modules.toArray(new ModuleRevisionId[modules.size()]); ModuleDescriptor md = DefaultModuleDescriptor.newCallerInstance(mrids, true, false); String resolveId = ResolveOptions.getDefaultResolveId(md); ResolveReport report = ivy.resolve(md, new ResolveOptions().setResolveId(resolveId) .setValidate(doValidate(settings))); ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager(); new XmlReportOutputter().output(report, cacheMgr, new ResolveOptions()); if (graph) { gengraph(cacheMgr, md.getModuleRevisionId().getOrganisation(), md.getModuleRevisionId().getName()); } if (dot) { gendot(cacheMgr, md.getModuleRevisionId().getOrganisation(), md.getModuleRevisionId().getName()); } if (xml) { FileUtil.copy(cacheMgr.getConfigurationResolveReportInCache(resolveId, "default"), new File(getTodir(), outputname + ".xml"), null); } if (xsl) { genreport(cacheMgr, md.getModuleRevisionId().getOrganisation(), md.getModuleRevisionId().getName()); } } catch (Exception e) { throw new BuildException("impossible to generate graph for " + moduleRevisionId + ": " + e, e); } }