Java Code Examples for org.apache.ivy.core.module.descriptor.ModuleDescriptor#getConfigurations()
The following examples show how to use
org.apache.ivy.core.module.descriptor.ModuleDescriptor#getConfigurations() .
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: XmlModuleUpdaterTest.java From ant-ivy with Apache License 2.0 | 6 votes |
@Test public void testUpdateWithExcludeConfigurations1() throws Exception { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs1.xml").toURI().toURL(); XmlModuleDescriptorUpdater.update(settingsUrl, buffer, getUpdateOptions("release", "mynewrev").setConfsToExclude(new String[] {"myconf2"})); XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance(); ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true); // test the number of configurations Configuration[] configs = updatedMd.getConfigurations(); assertNotNull("Configurations shouldn't be null", configs); assertEquals("Number of configurations incorrect", 3, configs.length); // test that the correct configuration has been removed assertNull("myconf2 hasn't been removed", updatedMd.getConfiguration("myconf2")); // test that the other configurations aren't removed assertNotNull("myconf1 has been removed", updatedMd.getConfiguration("myconf1")); assertNotNull("myconf3 has been removed", updatedMd.getConfiguration("myconf3")); assertNotNull("myconf4 has been removed", updatedMd.getConfiguration("myconf4")); }
Example 2
Source File: XmlModuleUpdaterTest.java From ant-ivy with Apache License 2.0 | 6 votes |
/** * Test case for IVY-1315. * * @throws Exception if something goes wrong * @see <a href="https://issues.apache.org/jira/browse/IVY-1315">IVY-1315</a> */ @Test public void testMergedUpdateWithInclude() throws Exception { URL url = XmlModuleUpdaterTest.class.getResource("test-update-excludedconfs6.xml"); XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance(); ModuleDescriptor md = parser.parseDescriptor(new IvySettings(), url, true); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); XmlModuleDescriptorUpdater.update(url, buffer, getUpdateOptions("release", "mynewrev") .setMerge(true) .setMergedDescriptor(md)); ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true); Configuration[] configurations = updatedMd.getConfigurations(); assertNotNull("Configurations shouldn't be null", configurations); assertEquals("Number of configurations is incorrect", 6, configurations.length); String updatedXml = buffer.toString(); System.out.println(updatedXml); assertTrue(updatedXml.contains("dependencies defaultconf=\"conf1->default\"")); }
Example 3
Source File: LazyDependencyToModuleResolver.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
protected void checkDescriptor(ComponentMetaData metaData) { ModuleDescriptor moduleDescriptor = metaData.getDescriptor(); for (Configuration configuration : moduleDescriptor.getConfigurations()) { for (String parent : configuration.getExtends()) { if (moduleDescriptor.getConfiguration(parent) == null) { throw new ModuleVersionResolveException(metaData.getId(), String.format("Configuration '%s' extends unknown configuration '%s' in module descriptor for %%s.", configuration.getName(), parent)); } } } }
Example 4
Source File: LazyDependencyToModuleResolver.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
protected void checkDescriptor(ComponentMetaData metaData) { ModuleDescriptor moduleDescriptor = metaData.getDescriptor(); for (Configuration configuration : moduleDescriptor.getConfigurations()) { for (String parent : configuration.getExtends()) { if (moduleDescriptor.getConfiguration(parent) == null) { throw new ModuleVersionResolveException(metaData.getId(), String.format("Configuration '%s' extends unknown configuration '%s' in module descriptor for %%s.", configuration.getName(), parent)); } } } }
Example 5
Source File: XmlModuleDescriptorWriter.java From ant-ivy with Apache License 2.0 | 5 votes |
private static void printConfigurations(ModuleDescriptor md, PrintWriter out) { Configuration[] confs = md.getConfigurations(); if (confs.length > 0) { out.println("\t<configurations>"); for (Configuration conf : confs) { out.print("\t\t"); printConfiguration(conf, out); } out.println("\t</configurations>"); } }
Example 6
Source File: XmlModuleDescriptorParser.java From ant-ivy with Apache License 2.0 | 5 votes |
/** * Describes how to merge configurations elements * * @param parent * the module descriptor */ protected void mergeConfigurations(ModuleDescriptor parent) { ModuleRevisionId sourceMrid = parent.getModuleRevisionId(); for (Configuration configuration : parent.getConfigurations()) { Message.debug("Merging configuration with: " + configuration.getName()); // copy configuration from parent descriptor getMd().addConfiguration(new Configuration(configuration, sourceMrid)); } if (parent instanceof DefaultModuleDescriptor) { setDefaultConfMapping(((DefaultModuleDescriptor) parent).getDefaultConfMapping()); setDefaultConf(((DefaultModuleDescriptor) parent).getDefaultConf()); getMd().setMappingOverride(((DefaultModuleDescriptor) parent).isMappingOverride()); } }
Example 7
Source File: XmlModuleDescriptorUpdater.java From ant-ivy with Apache License 2.0 | 5 votes |
/** * <p> * If publishing in merge mode, guarantee that any merged elements appearing before * <code>moduleElement</code> have been written. This method should be called <i>before</i> * we write the start tag of <code>moduleElement</code>. This covers cases where merged * elements like "configurations" and "dependencies" appear in the parent descriptor, but * are completely missing in the child descriptor. * </p> * * <p> * For example, if "moduleElement" is "dependencies", guarantees that "configurations" has * been written. If <code>moduleElement</code> is <code>null</code>, then all missing merged * elements will be flushed. * </p> * * @param moduleElement * a descriptor element name, for example "configurations" or "info" */ private void flushMergedElementsBefore(String moduleElement) { if (options.isMerge() && context.size() == 1 && "ivy-module".equals(context.peek()) && !(mergedConfigurations && mergedDependencies)) { // calculate the position of the element in ivy-module int position = (moduleElement == null) ? MODULE_ELEMENTS.size() : MODULE_ELEMENTS.indexOf(moduleElement); ModuleDescriptor merged = options.getMergedDescriptor(); // see if we should write <configurations> if (!mergedConfigurations && position > CONFIGURATIONS_POSITION && merged.getConfigurations().length > 0) { mergedConfigurations = true; writeInheritedItems(merged, merged.getConfigurations(), ConfigurationPrinter.INSTANCE, "configurations", true); } // see if we should write <dependencies> if (!mergedDependencies && position > DEPENDENCIES_POSITION && merged.getDependencies().length > 0) { mergedDependencies = true; writeInheritedItems(merged, merged.getDependencies(), DependencyPrinter.INSTANCE, "dependencies", true); } } }
Example 8
Source File: XmlModuleDescriptorParserTest.java From ant-ivy with Apache License 2.0 | 5 votes |
/** * Tests that when the <code>location</code> attribute of the <code>extends</code> element of * a module descriptor file, includes an {@link File#isAbsolute() absolute path} with * characters that {@link java.net.URI} considers as encoded characters (for example, * <code>%2F</code>) then the module descriptor and the location of the parent descriptor * are resolved and parsed correctly. * * @throws Exception if something goes wrong * @see <a href="https://issues.apache.org/jira/browse/IVY-1562">IVY-1562</a> */ @Test public void testExtendsAbsoluteLocation() throws Exception { final URL ivyXML = this.getClass().getResource("foo%2Fbar/hello/test-ivy-extends-absolute.xml"); assertNotNull("Ivy xml file is missing", ivyXML); final URL parentIvyXML = this.getClass().getResource("foo%2Fbar/parent-ivy.xml"); assertNotNull("Parent Ivy xml file is missing", parentIvyXML); // the ivy xml references a parent ivy xml via extends "location" and expects the parent // ivy to be present at a location under java.io.tmpdir, so we copy over the parent ivy // file over there final Path targetDir = Paths.get(System.getProperty("java.io.tmpdir"), "foo%2Fbar"); Files.createDirectories(targetDir); final Path parentIvyXMLPath = Paths.get(targetDir.toString(), "parent-ivy.xml"); try (final InputStream is = parentIvyXML.openStream()) { Files.copy(is, parentIvyXMLPath, StandardCopyOption.REPLACE_EXISTING); } assertTrue("Parent ivy xml file wasn't copied", Files.isRegularFile(parentIvyXMLPath)); try { // now start parsing the Ivy xml final ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyXML, true); assertNotNull("Parsed module descriptor is null", md); assertEquals("Unexpected org for the parsed module descriptor", "myorg", md.getModuleRevisionId().getOrganisation()); assertEquals("Unexpected module name for the parsed module descriptor", "mymodule", md.getModuleRevisionId().getName()); assertEquals("Unexpected revision for the parsed module descriptor", "1.0.0", md.getModuleRevisionId().getRevision()); final Configuration[] confs = md.getConfigurations(); assertNotNull("No configurations found in module descriptor", confs); assertEquals("Unexpected number of configurations found in module descriptor", 3, confs.length); final Set<String> expectedConfs = new HashSet<>(Arrays.asList("parent-conf1", "parent-conf2", "conf2")); for (final Configuration conf : confs) { assertNotNull("One of the configurations was null in module descriptor", conf); assertTrue("Unexpected configuration " + conf.getName() + " found in parsed module descriptor", expectedConfs.remove(conf.getName())); } assertTrue("Missing configurations " + expectedConfs + " from the parsed module descriptor", expectedConfs.isEmpty()); } finally { // clean up the copied over file Files.delete(parentIvyXMLPath); } }
Example 9
Source File: XmlModuleUpdaterTest.java From ant-ivy with Apache License 2.0 | 5 votes |
@Test public void testUpdateWithExcludeConfigurations3() throws Exception { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs3.xml").toURI().toURL(); XmlModuleDescriptorUpdater.update( settingsUrl, buffer, getUpdateOptions("release", "mynewrev").setConfsToExclude( new String[] {"myconf2", "conf2"})); XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance(); ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true); // test the number of configurations Configuration[] configs = updatedMd.getConfigurations(); assertNotNull("Configurations shouldn't be null", configs); assertEquals("Number of configurations incorrect", 4, configs.length); // test that the correct configuration has been removed assertNull("myconf2 hasn't been removed", updatedMd.getConfiguration("myconf2")); assertNull("conf2 hasn't been removed", updatedMd.getConfiguration("conf2")); // test that the other configurations aren't removed assertNotNull("conf1 has been removed", updatedMd.getConfiguration("conf1")); assertNotNull("myconf1 has been removed", updatedMd.getConfiguration("myconf1")); assertNotNull("myconf3 has been removed", updatedMd.getConfiguration("myconf3")); assertNotNull("myconf4 has been removed", updatedMd.getConfiguration("myconf4")); }
Example 10
Source File: XmlModuleUpdaterTest.java From ant-ivy with Apache License 2.0 | 5 votes |
/** * Test case for IVY-1420. * * @throws Exception if something goes wrong * @see <a href="https://issues.apache.org/jira/browse/IVY-1420">IVY-1420</a> */ @Test public void testMergedUpdateWithExtendsAndDefaultConfMappings() throws Exception { URL url = XmlModuleUpdaterTest.class.getResource("test-extends-configurations-defaultconfmapping.xml"); XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance(); ModuleDescriptor md = parser.parseDescriptor(new IvySettings(), url, true); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); XmlModuleDescriptorUpdater.update(url, buffer, getUpdateOptions("release", "mynewrev") .setMerge(true) .setMergedDescriptor(md)); ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true); Configuration[] configurations = updatedMd.getConfigurations(); assertNotNull("Configurations shouldn't be null", configurations); assertEquals("Number of configurations is incorrect", 3, configurations.length); String updatedXml = buffer.toString(); System.out.println(updatedXml); assertTrue(updatedXml.contains("configurations defaultconfmapping=\"conf1,default->@()\"")); assertTrue(updatedXml.contains("dependencies defaultconfmapping=\"conf1,default->@()\"")); }
Example 11
Source File: XmlModuleUpdaterTest.java From ant-ivy with Apache License 2.0 | 5 votes |
/** * Test case for IVY-1437. * * @throws Exception if something goes wrong * @see <a href="https://issues.apache.org/jira/browse/IVY-1437">IVY-1437</a> */ @Test public void testMergedUpdateWithExtendsAndConfigurationsInheritance() throws Exception { URL url = XmlModuleUpdaterTest.class.getResource("test-extends-configurations-inherit.xml"); XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance(); ModuleDescriptor md = parser.parseDescriptor(new IvySettings(), url, true); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); XmlModuleDescriptorUpdater.update(url, buffer, getUpdateOptions("release", "mynewrev") .setMerge(true) .setMergedDescriptor(md)); ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true); Configuration[] configurations = updatedMd.getConfigurations(); assertNotNull("Configurations shouldn't be null", configurations); assertEquals("Number of configurations is incorrect", 2, configurations.length); String updatedXml = buffer.toString(); System.out.println(updatedXml); assertTrue(updatedXml.contains("configurations defaultconf=\"compile\" defaultconfmapping=\"*->default\"")); assertTrue(updatedXml.contains("dependencies defaultconf=\"compile\" defaultconfmapping=\"*->default\"")); }
Example 12
Source File: XmlModuleUpdaterTest.java From ant-ivy with Apache License 2.0 | 5 votes |
/** * Test case for IVY-1419. * * @throws Exception if something goes wrong * @see <a href="https://issues.apache.org/jira/browse/IVY-1419">IVY-1419</a> */ @Test public void testMergedUpdateWithIncludeAndExcludedConf() throws Exception { URL url = XmlModuleUpdaterTest.class.getResource("test-update-excludedconfs6.xml"); XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance(); ModuleDescriptor md = parser.parseDescriptor(new IvySettings(), url, true); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); XmlModuleDescriptorUpdater.update(url, buffer, getUpdateOptions("release", "mynewrev") .setMerge(true) .setMergedDescriptor(md) .setConfsToExclude(new String[]{"conf1"})); ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true); Configuration[] configurations = updatedMd.getConfigurations(); assertNotNull("Configurations shouldn't be null", configurations); assertEquals("Number of configurations is incorrect", 5, configurations.length); String updatedXml = buffer.toString(); System.out.println(updatedXml); assertTrue(updatedXml.contains("dependencies/")); }
Example 13
Source File: IvyDependencyUpdateChecker.java From ant-ivy with Apache License 2.0 | 4 votes |
public void doExecute() throws BuildException { prepareAndCheck(); ModuleDescriptor originalModuleDescriptor = getResolvedReport().getModuleDescriptor(); // clone module descriptor DefaultModuleDescriptor latestModuleDescriptor = new DefaultModuleDescriptor( originalModuleDescriptor.getModuleRevisionId(), originalModuleDescriptor.getStatus(), originalModuleDescriptor.getPublicationDate()); // copy configurations for (Configuration configuration : originalModuleDescriptor.getConfigurations()) { latestModuleDescriptor.addConfiguration(configuration); } // clone dependency and add new one with the requested revisionToCheck for (DependencyDescriptor dependencyDescriptor : originalModuleDescriptor.getDependencies()) { ModuleRevisionId upToDateMrid = ModuleRevisionId.newInstance( dependencyDescriptor.getDependencyRevisionId(), revisionToCheck); latestModuleDescriptor.addDependency(dependencyDescriptor.clone(upToDateMrid)); } // resolve ResolveOptions resolveOptions = new ResolveOptions(); resolveOptions.setDownload(isDownload()); resolveOptions.setLog(getLog()); resolveOptions.setConfs(splitToArray(getConf())); resolveOptions.setCheckIfChanged(checkIfChanged); ResolveReport latestReport; try { latestReport = getIvyInstance().getResolveEngine().resolve(latestModuleDescriptor, resolveOptions); displayDependencyUpdates(getResolvedReport(), latestReport); if (showTransitive) { displayNewDependencyOnLatest(getResolvedReport(), latestReport); displayMissingDependencyOnLatest(getResolvedReport(), latestReport); } } catch (ParseException | IOException e) { throw new BuildException("impossible to resolve dependencies:\n\t" + e, e); } }
Example 14
Source File: AbstractModuleDescriptorParser.java From ant-ivy with Apache License 2.0 | 4 votes |
private void replaceConfigurationWildcards(ModuleDescriptor md) { for (Configuration config : md.getConfigurations()) { config.replaceWildcards(md); } }
Example 15
Source File: AbstractWorkspaceResolver.java From ant-ivy with Apache License 2.0 | 4 votes |
protected WorkspaceModuleDescriptor createWorkspaceMd(ModuleDescriptor md) { DefaultWorkspaceModuleDescriptor newMd = new DefaultWorkspaceModuleDescriptor( md.getModuleRevisionId(), "release", null, true); newMd.addConfiguration(new Configuration(ModuleDescriptor.DEFAULT_CONFIGURATION)); newMd.setLastModified(System.currentTimeMillis()); newMd.setDescription(md.getDescription()); newMd.setHomePage(md.getHomePage()); newMd.setLastModified(md.getLastModified()); newMd.setPublicationDate(md.getPublicationDate()); newMd.setResolvedPublicationDate(md.getResolvedPublicationDate()); newMd.setStatus(md.getStatus()); Configuration[] allConfs = md.getConfigurations(); for (Artifact af : createWorkspaceArtifacts(md)) { if (allConfs.length == 0) { newMd.addArtifact(ModuleDescriptor.DEFAULT_CONFIGURATION, af); } else { for (Configuration conf : allConfs) { newMd.addConfiguration(conf); newMd.addArtifact(conf.getName(), af); } } } for (DependencyDescriptor dependency : md.getDependencies()) { newMd.addDependency(dependency); } for (ExcludeRule excludeRule : md.getAllExcludeRules()) { newMd.addExcludeRule(excludeRule); } newMd.getExtraInfos().addAll(md.getExtraInfos()); for (License license : md.getLicenses()) { newMd.addLicense(license); } return newMd; }