Java Code Examples for org.apache.ivy.Ivy#getSettings()
The following examples show how to use
org.apache.ivy.Ivy#getSettings() .
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: IvySettingsTest.java From ant-ivy with Apache License 2.0 | 6 votes |
@Test public void testChangeDefaultResolver() throws ParseException, IOException { Ivy ivy = new Ivy(); ivy.configureDefault(); IvySettings settings = ivy.getSettings(); DependencyResolver defaultResolver = settings.getDefaultResolver(); assertNotNull(defaultResolver); assertEquals("default", defaultResolver.getName()); assertSame("default resolver cached", defaultResolver, settings.getDefaultResolver()); settings.setDefaultResolver("public"); DependencyResolver newDefault = settings.getDefaultResolver(); assertNotNull(newDefault); assertNotSame("default resolver has changed", defaultResolver, newDefault); assertEquals("resolver changed successfully", "public", newDefault.getName()); }
Example 2
Source File: DefaultRepositoryCacheManagerTest.java From ant-ivy with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { File f = File.createTempFile("ivycache", ".dir"); ivy = new Ivy(); ivy.configureDefault(); ivy.getLoggerEngine().setDefaultLogger(new DefaultMessageLogger(Message.MSG_DEBUG)); IvyContext.pushNewContext().setIvy(ivy); IvySettings settings = ivy.getSettings(); f.delete(); // we want to use the file as a directory, so we delete the file itself cacheManager = new DefaultRepositoryCacheManager(); cacheManager.setSettings(settings); cacheManager.setBasedir(f); artifact = createArtifact("org", "module", "rev", "name", "type", "ext"); Artifact originArtifact = createArtifact("org", "module", "rev", "name", "pom.original", "pom"); origin = new ArtifactOrigin(originArtifact, true, "file:/some/where.pom"); cacheManager.saveArtifactOrigin(originArtifact, origin); cacheManager.saveArtifactOrigin(artifact, origin); }
Example 3
Source File: IvyFindRevision.java From ant-ivy with Apache License 2.0 | 6 votes |
public void doExecute() throws BuildException { if (organisation == null) { throw new BuildException("no organisation provided for ivy findrevision task"); } if (module == null) { throw new BuildException("no module name provided for ivy findrevision task"); } if (revision == null) { throw new BuildException("no revision provided for ivy findrevision task"); } Ivy ivy = getIvyInstance(); IvySettings settings = ivy.getSettings(); if (branch == null) { branch = settings.getDefaultBranch(new ModuleId(organisation, module)); } ResolvedModuleRevision rmr = ivy.findModule(ModuleRevisionId.newInstance(organisation, module, branch, revision)); if (rmr != null) { getProject().setProperty(property, rmr.getId().getRevision()); } }
Example 4
Source File: IvyConfigureTest.java From ant-ivy with Apache License 2.0 | 6 votes |
@Test public void testFile() throws Exception { configure.setFile(new File("test/repositories/ivysettings.xml")); configure.execute(); Ivy ivy = getIvyInstance(); assertNotNull(ivy); IvySettings settings = ivy.getSettings(); assertNotNull(settings); assertEquals(new File("build/cache").getAbsoluteFile(), settings.getDefaultCache()); assertEquals(new File("test/repositories/ivysettings.xml").getAbsolutePath(), settings .getVariables().getVariable("ivy.settings.file")); assertEquals( new File("test/repositories/ivysettings.xml").toURI().toURL().toExternalForm(), settings.getVariables().getVariable("ivy.settings.url")); assertEquals(new File("test/repositories").getAbsolutePath(), settings.getVariables() .getVariable("ivy.settings.dir")); assertEquals("myvalue", settings.getVariables().getVariable("myproperty")); }
Example 5
Source File: IvyTaskTest.java From ant-ivy with Apache License 2.0 | 5 votes |
@Test public void testReferencedSettings() throws MalformedURLException { Project p = TestHelper.newProject(); p.setProperty("myproperty", "myvalue"); IvyAntSettings antSettings = new IvyAntSettings(); antSettings.setProject(p); // antSettings.setId("mySettings"); antSettings.setFile(new File("test/repositories/ivysettings.xml")); p.addReference("mySettings", antSettings); IvyTask task = new IvyTask() { public void doExecute() throws BuildException { } }; task.setProject(p); task.setSettingsRef(new Reference(task.getProject(), "mySettings")); Ivy ivy = task.getIvyInstance(); assertNotNull(ivy); IvySettings settings = ivy.getSettings(); assertNotNull(settings); assertEquals(new File("build/cache").getAbsoluteFile(), settings.getDefaultCache()); assertEquals(new File("test/repositories/ivysettings.xml").getAbsolutePath(), settings .getVariables().getVariable("ivy.settings.file")); assertEquals( new File("test/repositories/ivysettings.xml").toURI().toURL().toExternalForm(), settings.getVariables().getVariable("ivy.settings.url")); assertEquals(new File("test/repositories").getAbsolutePath(), settings.getVariables() .getVariable("ivy.settings.dir")); assertEquals("myvalue", settings.getVariables().getVariable("myproperty")); }
Example 6
Source File: ConfigureTest.java From ant-ivy with Apache License 2.0 | 5 votes |
@Test public void testDefault14() throws ParseException, IOException { Ivy ivy = new Ivy(); ivy.configureDefault14(); IvySettings settings = ivy.getSettings(); assertNotNull(settings.getDefaultResolver()); DependencyResolver publicResolver = settings.getResolver("public"); assertTrue(publicResolver instanceof IvyRepResolver); }
Example 7
Source File: ConfigureTest.java From ant-ivy with Apache License 2.0 | 5 votes |
@Test public void testDefault() throws ParseException, IOException { Ivy ivy = new Ivy(); ivy.configureDefault(); IvySettings settings = ivy.getSettings(); assertNotNull(settings.getDefaultResolver()); DependencyResolver publicResolver = settings.getResolver("public"); assertNotNull(publicResolver); assertTrue(publicResolver instanceof IBiblioResolver); IBiblioResolver ibiblio = (IBiblioResolver) publicResolver; assertTrue(ibiblio.isM2compatible()); }
Example 8
Source File: SearchTest.java From ant-ivy with Apache License 2.0 | 5 votes |
@Test public void testListModulesWithExtraAttributes() throws ParseException, IOException { Ivy ivy = Ivy.newInstance(); ivy.configure(new File("test/repositories/IVY-1128/ivysettings.xml")); IvySettings settings = ivy.getSettings(); Map<String, String> extendedAttributes = new HashMap<>(); extendedAttributes.put("e:att1", "extraatt"); extendedAttributes.put("e:att2", "extraatt2"); ModuleRevisionId criteria = ModuleRevisionId.newInstance("test", "a", "*", extendedAttributes); ModuleRevisionId[] mrids = ivy.listModules(criteria, settings.getMatcher(PatternMatcher.REGEXP)); assertEquals(2, mrids.length); ModuleRevisionId mrid = mrids[0]; assertEquals("extraatt", mrid.getExtraAttribute("att1")); Map<String, String> extraAttributes = mrid.getExtraAttributes(); assertEquals(2, extraAttributes.size()); assertTrue(extraAttributes.toString(), extraAttributes.keySet().contains("att1")); assertTrue(extraAttributes.toString(), extraAttributes.keySet().contains("att2")); Map<String, String> qualifiedExtraAttributes = mrid.getQualifiedExtraAttributes(); assertEquals(2, qualifiedExtraAttributes.size()); assertTrue(qualifiedExtraAttributes.toString(), qualifiedExtraAttributes.keySet().contains("e:att1")); assertTrue(qualifiedExtraAttributes.toString(), qualifiedExtraAttributes.keySet().contains("e:att2")); }
Example 9
Source File: IvyConfigureTest.java From ant-ivy with Apache License 2.0 | 5 votes |
/** * Tests that if the Ivy settings file <code>include</code>s another file as * <code>optional</code>, then the absence of that file doesn't lead to failures * * @throws Exception if something goes wrong */ @Test public void testOptionalFileInclude() throws Exception { final File ivySettingsXml = new File("test/repositories/ivysettings-optional-file-include.xml"); final Ivy ivy = new Ivy(); ivy.configure(ivySettingsXml); final IvySettings ivySettings = ivy.getSettings(); // just test that it indeed parsed fine assertTrue("Unexpected number of resolvers in Ivy settings", ivySettings.getResolvers().isEmpty()); final List<Status> statuses = ivySettings.getStatusManager().getStatuses(); assertEquals("Unexpected number of custom status in parsed Ivy settings", 1, statuses.size()); assertEquals("Custom status not found in the parsed Ivy settings", "ivy-1555", statuses.get(0).getName()); }
Example 10
Source File: ResolveIvyFactory.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private void ivyContextualize(IvyAwareModuleVersionRepository ivyAwareRepository, RepositoryChain userResolverChain, String configurationName) { Ivy ivy = IvyContext.getContext().getIvy(); IvySettings ivySettings = ivy.getSettings(); LoopbackDependencyResolver loopbackDependencyResolver = new LoopbackDependencyResolver("main", userResolverChain, cacheLockingManager); ivySettings.addResolver(loopbackDependencyResolver); ivySettings.setDefaultResolver(loopbackDependencyResolver.getName()); ResolveData resolveData = createResolveData(ivy, configurationName); ivyAwareRepository.setSettings(ivySettings); ivyAwareRepository.setResolveData(resolveData); }
Example 11
Source File: IvyTaskTest.java From ant-ivy with Apache License 2.0 | 5 votes |
@Test public void testDefaultSettings() throws MalformedURLException { Project p = TestHelper.newProject(); p.setBasedir("test/repositories"); p.setProperty("myproperty", "myvalue"); IvyTask task = new IvyTask() { public void doExecute() throws BuildException { } }; task.setProject(p); Ivy ivy = task.getIvyInstance(); assertNotNull(ivy); IvySettings settings = ivy.getSettings(); assertNotNull(settings); assertEquals(new File("test/repositories/build/cache").getAbsoluteFile(), settings.getDefaultCache()); // The next test doesn't always works on windows (mix C: and c: drive) assertEquals(new File("test/repositories/ivysettings.xml").getAbsolutePath().toUpperCase(), new File(settings.getVariables().getVariable("ivy.settings.file")).getAbsolutePath() .toUpperCase()); assertEquals(new File("test/repositories/ivysettings.xml").toURI().toURL().toExternalForm() .toUpperCase(), settings.getVariables().getVariable("ivy.settings.url") .toUpperCase()); assertEquals(new File("test/repositories").getAbsolutePath().toUpperCase(), settings .getVariables().getVariable("ivy.settings.dir").toUpperCase()); assertEquals("myvalue", settings.getVariables().getVariable("myproperty")); }
Example 12
Source File: ResolveIvyFactory.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
private void ivyContextualize(IvyAwareModuleVersionRepository ivyAwareRepository, RepositoryChain userResolverChain, String configurationName) { Ivy ivy = IvyContext.getContext().getIvy(); IvySettings ivySettings = ivy.getSettings(); LoopbackDependencyResolver loopbackDependencyResolver = new LoopbackDependencyResolver("main", userResolverChain, cacheLockingManager); ivySettings.addResolver(loopbackDependencyResolver); ivySettings.setDefaultResolver(loopbackDependencyResolver.getName()); ResolveData resolveData = createResolveData(ivy, configurationName); ivyAwareRepository.setSettings(ivySettings); ivyAwareRepository.setResolveData(resolveData); }
Example 13
Source File: MavenResolver.java From IJava with MIT License | 5 votes |
@LineMagic public void loadFromPOM(List<String> args) { if (args.isEmpty()) throw new IllegalArgumentException("Loading from POM requires at least the path to the POM file"); MagicsArgs schema = MagicsArgs.builder() .required("pomPath") .varargs("scopes") .flag("verbose", 'v') .onlyKnownKeywords().onlyKnownFlags().build(); Map<String, List<String>> vals = schema.parse(args); String pomPath = vals.get("pomPath").get(0); List<String> scopes = vals.get("scopes"); int verbosity = vals.get("verbose").size(); File pomFile = new File(pomPath); try { Ivy ivy = this.createDefaultIvyInstance(verbosity); IvySettings settings = ivy.getSettings(); File ivyFile = this.convertPomToIvy(ivy, pomFile); this.addPomReposToIvySettings(settings, pomFile); this.addJarsToClasspath( this.resolveFromIvyFile(ivy, ivyFile, scopes).stream() .map(File::getAbsolutePath) ::iterator ); } catch (IOException | ParseException | ModelBuildingException e) { throw new RuntimeException(e); } }
Example 14
Source File: IvyInstall.java From ant-ivy with Apache License 2.0 | 4 votes |
public void doExecute() throws BuildException { Ivy ivy = getIvyInstance(); IvySettings settings = ivy.getSettings(); if (organisation == null) { throw new BuildException("no organisation provided for ivy publish task: " + "It can either be set explicitly via the attribute 'organisation' " + "or via 'ivy.organisation' property or a prior call to <resolve/>"); } if (module == null) { if (PatternMatcher.EXACT.equals(matcher)) { throw new BuildException("no module name provided for ivy publish task: " + "It can either be set explicitly via the attribute 'module' " + "or via 'ivy.module' property or a prior call to <resolve/>"); } module = PatternMatcher.ANY_EXPRESSION; } if (revision == null) { if (PatternMatcher.EXACT.equals(matcher)) { throw new BuildException("no module revision provided for ivy publish task: " + "It can either be set explicitly via the attribute 'revision' " + "or via 'ivy.revision' property or a prior call to <resolve/>"); } revision = PatternMatcher.ANY_EXPRESSION; } if (branch == null) { if (PatternMatcher.EXACT.equals(matcher)) { branch = settings.getDefaultBranch(ModuleId.newInstance(organisation, module)); } else { branch = PatternMatcher.ANY_EXPRESSION; } } if (from == null) { throw new BuildException( "no from resolver name: please provide it through parameter 'from'"); } if (to == null) { throw new BuildException( "no to resolver name: please provide it through parameter 'to'"); } ModuleRevisionId mrid = ModuleRevisionId .newInstance(organisation, module, branch, revision); ResolveReport report; try { report = ivy.install( mrid, from, to, new InstallOptions().setTransitive(transitive).setValidate(doValidate(settings)) .setOverwrite(overwrite).setConfs(conf.split(",")) .setArtifactFilter(FilterHelper.getArtifactTypeFilter(type)) .setMatcherName(matcher) .setInstallOriginalMetadata(installOriginalMetadata)); } catch (Exception e) { throw new BuildException("impossible to install " + mrid + ": " + e, e); } if (report.hasError() && isHaltonfailure()) { throw new BuildException( "Problem happened while installing modules - see output for details"); } }
Example 15
Source File: IvyReport.java From ant-ivy with Apache License 2.0 | 4 votes |
public void doExecute() throws BuildException { Ivy ivy = getIvyInstance(); IvySettings settings = ivy.getSettings(); conf = getProperty(conf, settings, "ivy.resolved.configurations", resolveId); if ("*".equals(conf)) { conf = getProperty(settings, "ivy.resolved.configurations", resolveId); } if (conf == null) { throw new BuildException("no conf provided for ivy report task: " + "It can either be set explicitly via the attribute 'conf' or " + "via 'ivy.resolved.configurations' property or a prior call to <resolve/>"); } if (todir == null) { String t = getProperty(settings, "ivy.report.todir"); if (t != null) { todir = getProject().resolveFile(t); } } if (todir != null && todir.exists()) { todir.mkdirs(); } outputpattern = getProperty(outputpattern, settings, "ivy.report.output.pattern"); if (outputpattern == null) { outputpattern = "[organisation]-[module]-[conf].[ext]"; } if (todir != null && todir.exists() && !todir.isDirectory()) { throw new BuildException("destination directory should be a directory !"); } if (resolveId == null) { organisation = getProperty(organisation, settings, "ivy.organisation", resolveId); module = getProperty(module, settings, "ivy.module", resolveId); if (organisation == null) { throw new BuildException("no organisation provided for ivy report task: " + "It can either be set explicitly via the attribute 'organisation' or " + "via 'ivy.organisation' property or a prior call to <resolve/>"); } if (module == null) { throw new BuildException("no module name provided for ivy report task: " + "It can either be set explicitly via the attribute 'module' or " + "via 'ivy.module' property or a prior call to <resolve/>"); } resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(organisation, module)); } try { String[] confs = splitToArray(conf); if (xsl) { genreport(confs); } if (xml) { genxml(confs); } if (graph) { genStyled(confs, getStylePath("ivy-report-graph.xsl"), "graphml"); } if (dot) { genStyled(confs, getStylePath("ivy-report-dot.xsl"), "dot"); } } catch (IOException e) { throw new BuildException("impossible to generate report: " + e, e); } }
Example 16
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); } }
Example 17
Source File: IvySettingsTest.java From ant-ivy with Apache License 2.0 | 4 votes |
@Test public void testVariables() throws Exception { Ivy ivy = new Ivy(); ivy.configureDefault(); IvySettings settings = ivy.getSettings(); // test set assertNull(settings.getVariable("foo")); settings.setVariable("foo", "bar", false, null, null); assertEquals("bar", settings.getVariable("foo")); // test no override settings.setVariable("foo", "wrong", false, null, null); assertEquals("bar", settings.getVariable("foo")); // test override settings.setVariable("foo", "right", true, null, null); assertEquals("right", settings.getVariable("foo")); // test ifset no exist assertNull(settings.getVariable("bar")); settings.setVariable("bar", "foo", true, "noexist", null); assertNull(settings.getVariable("bar")); // test ifset exist settings.setVariable("bar", "foo", true, "foo", null); assertEquals("foo", settings.getVariable("bar")); // test unlessset exist assertNull(settings.getVariable("thing")); settings.setVariable("thing", "foo", true, null, "foo"); assertNull(settings.getVariable("thing")); // test unlessset noexist settings.setVariable("thing", "foo", true, null, "noexist"); assertEquals("foo", settings.getVariable("thing")); // test ifset no exist and unlessset exist assertNull(settings.getVariable("ivy")); settings.setVariable("ivy", "rocks", true, "noexist", "foo"); assertNull(settings.getVariable("ivy")); // test ifset no exist and unlessset no exist settings.setVariable("ivy", "rocks", true, "noexist", "noexist"); assertNull(settings.getVariable("ivy")); // test ifset exist and unlessset exist settings.setVariable("ivy", "rocks", true, "foo", "foo"); assertNull(settings.getVariable("ivy")); // test ifset exist and unlessset no exist settings.setVariable("ivy", "rocks", true, "foo", "noexist"); assertEquals("rocks", settings.getVariable("ivy")); }
Example 18
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()); }