org.apache.ivy.core.module.descriptor.ModuleDescriptor Java Examples

The following examples show how to use org.apache.ivy.core.module.descriptor.ModuleDescriptor. 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: AntWorkspaceResolver.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private synchronized Map<ModuleDescriptor, File> getModuleDescriptors() {
    if (md2IvyFile == null) {
        md2IvyFile = new HashMap<>();
        for (ResourceCollection resources : allResources) {
            for (Resource resource : resources) {
                File ivyFile = ((FileResource) resource).getFile();
                try {
                    ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance()
                            .parseDescriptor(getParserSettings(), ivyFile.toURI().toURL(),
                                isValidate());
                    md2IvyFile.put(md, ivyFile);
                    Message.debug("Add " + md.getModuleRevisionId().getModuleId());
                } catch (Exception ex) {
                    if (haltOnError) {
                        throw new BuildException("impossible to parse ivy file " + ivyFile
                                + " exception=" + ex, ex);
                    } else {
                        Message.warn("impossible to parse ivy file " + ivyFile
                                + " exception=" + ex.getMessage());
                    }
                }
            }
        }
    }
    return md2IvyFile;
}
 
Example #2
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testEjbType() throws Exception {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-ejb-type.pom"), false);
    assertNotNull(md);

    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test-ejb-type", "1.0");
    assertEquals(mrid, md.getModuleRevisionId());

    DependencyDescriptor[] deps = md.getDependencies();
    assertNotNull(deps);
    assertEquals(1, deps.length);

    DependencyArtifactDescriptor[] artifacts = deps[0].getAllDependencyArtifacts();
    assertNotNull(artifacts);
    assertEquals(1, artifacts.length);
    assertEquals("test", artifacts[0].getName());
    assertEquals("jar", artifacts[0].getExt());
    assertEquals("ejb", artifacts[0].getType());
}
 
Example #3
Source File: OsgiLatestStrategy.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private ModuleRevisionId getImplMrid(ArtifactInfo o) {
    if (!(o instanceof MDResolvedResource)) {
        return null;
    }
    MDResolvedResource mdrr = (MDResolvedResource) o;
    ResolvedModuleRevision rmr = mdrr.getResolvedModuleRevision();
    if (rmr == null) {
        return null;
    }
    ModuleDescriptor md = rmr.getDescriptor();
    if (md == null) {
        return null;
    }
    if (!md.getModuleRevisionId().getOrganisation().equals(BundleInfo.PACKAGE_TYPE)) {
        return null;
    }
    DependencyDescriptor[] dds = md.getDependencies();
    if (dds == null || dds.length != 1) {
        return null;
    }
    return dds[0].getDependencyRevisionId();
}
 
Example #4
Source File: SortTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Sorter does not throw circular dependency, circular dependencies are handled at resolve time
 * only. However the sort respect the transitive order when it is unambiguous. (If A depends
 * transitively of B, but B doesn't depends transitively on A, then B always comes before A.)
 */
@Test
public void testCircularDependency() {
    addDependency(md1, "md4", "rev4");
    addDependency(md2, "md1", "rev1");
    addDependency(md3, "md2", "rev2");
    addDependency(md4, "md3", "rev3");

    DefaultModuleDescriptor[][] possibleOrder = new DefaultModuleDescriptor[][] {
            {md2, md3, md4, md1}, {md3, md4, md1, md2}, {md4, md1, md2, md3},
            {md1, md2, md3, md4}};

    for (List<ModuleDescriptor> toSort : getAllLists(md1, md3, md2, md4)) {
        assertSorted(possibleOrder, sortModuleDescriptors(toSort, nonMatchReporter));
    }
}
 
Example #5
Source File: XmlModuleDescriptorWriter.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private static void printAllExcludes(ModuleDescriptor md, PrintWriter out) {
    ExcludeRule[] excludes = md.getAllExcludeRules();
    if (excludes.length > 0) {
        for (ExcludeRule exclude : excludes) {
            out.print(String.format("\t\t<exclude org=\"%s\" module=\"%s\" artifact=\"%s\" type=\"%s\" ext=\"%s\"",
                    XMLHelper.escape(exclude.getId().getModuleId().getOrganisation()),
                    XMLHelper.escape(exclude.getId().getModuleId().getName()),
                    XMLHelper.escape(exclude.getId().getName()),
                    XMLHelper.escape(exclude.getId().getType()),
                    XMLHelper.escape(exclude.getId().getExt())));
            String[] ruleConfs = exclude.getConfigurations();
            if (!Arrays.asList(ruleConfs).equals(Arrays.asList(md.getConfigurationsNames()))) {
                out.print(listToPrefixedString(ruleConfs, " conf=\""));
            }
            out.print(" matcher=\"" + XMLHelper.escape(exclude.getMatcher().getName()) + "\"");
            out.println("/>");
        }
    }
}
 
Example #6
Source File: ModuleDescriptorMemoryCache.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
ModuleDescriptor getFromCache(File ivyFile, ParserSettings ivySettings, boolean validated) {
    if (maxSize <= 0) {
        // cache is disabled
        return null;
    }
    synchronized (valueMap) {
        CacheEntry entry = valueMap.get(ivyFile);
        if (entry != null) {
            if (entry.isStale(ivyFile, validated, ivySettings)) {
                Message.debug("Entry is found in the ModuleDescriptorCache but entry should be "
                        + "reevaluated : " + ivyFile);
                valueMap.remove(ivyFile);
                return null;
            } else {
                // Move the entry at the end of the list
                valueMap.remove(ivyFile);
                valueMap.put(ivyFile, entry);
                Message.debug("Entry is found in the ModuleDescriptorCache : " + ivyFile);
                return entry.md;
            }
        } else {
            Message.debug("No entry is found in the ModuleDescriptorCache : " + ivyFile);
            return null;
        }
    }
}
 
Example #7
Source File: XmlModuleUpdaterTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #8
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * This test is here to just test the deprecated {@code symlinkmass} option for retrieve task.
 * A version or two down the line, after 2.5 release, we can remove this test and the option
 * altogether.
 *
 * @throws Exception if something goes wrong
 */
@SuppressWarnings("deprecation")
@Test
public void testRetrieveWithSymlinksMass() throws Exception {
    // mod1.1 depends on mod1.2
    ResolveReport report = ivy.resolve(new File(
            "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURI().toURL(),
        getResolveOptions(new String[] {"*"}));
    assertNotNull(report);
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);

    String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]";
    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setMakeSymlinksInMass(true).setDestArtifactPattern(pattern));
    assertLinkOrExists(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", "jar",
        "jar", "default"));

    pattern = "build/test/retrieve/[module]/[conf]/[type]s/[artifact]-[revision].[ext]";
    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setMakeSymlinksInMass(true).setDestArtifactPattern(pattern));
    assertLinkOrExists(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", "jar",
        "jar", "default"));
}
 
Example #9
Source File: ResolveReportTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testFixedMdRange() throws Exception {
    ResolveReport report = ivy.resolve(new File(
            "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml"),
        getResolveOptions(new String[] {"*"}));
    assertNotNull(report);
    assertFalse(report.hasError());
    ModuleDescriptor fixedMd = report.toFixedModuleDescriptor(ivy.getSettings(), null);

    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.4", "1.0.2");
    assertEquals(mrid, fixedMd.getModuleRevisionId());

    assertEquals(Arrays.asList("default", "compile"),
        Arrays.asList(fixedMd.getConfigurationsNames()));

    assertEquals(1, fixedMd.getDependencies().length);

    checkFixedMdDependency(fixedMd.getDependencies()[0], "org1", "mod1.2", "1.1", "default",
        new String[] {"*"});
    checkFixedMdDependency(fixedMd.getDependencies()[0], "org1", "mod1.2", "1.1", "compile",
        new String[] {"default"});
}
 
Example #10
Source File: ResolveReportTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testFixedMdSimple() throws Exception {
    ResolveReport report = ivy.resolve(new File(
            "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"),
        getResolveOptions(new String[] {"*"}));
    assertNotNull(report);
    assertFalse(report.hasError());
    ModuleDescriptor fixedMd = report.toFixedModuleDescriptor(ivy.getSettings(), null);

    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
    assertEquals(mrid, fixedMd.getModuleRevisionId());

    assertEquals(Collections.singletonList("default"),
        Arrays.asList(fixedMd.getConfigurationsNames()));

    assertEquals(1, fixedMd.getDependencies().length);
    checkFixedMdDependency(fixedMd.getDependencies()[0], "org1", "mod1.2", "2.0", "default",
        new String[] {"*"});
}
 
Example #11
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimple() throws Exception {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-simple.pom"), false);
    assertNotNull(md);

    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0");
    assertEquals(mrid, md.getModuleRevisionId());

    assertNotNull(md.getConfigurations());
    assertEquals(Arrays.asList(PomModuleDescriptorBuilder.MAVEN2_CONFIGURATIONS),
        Arrays.asList(md.getConfigurations()));

    Artifact[] artifact = md.getArtifacts("master");
    assertEquals(1, artifact.length);
    assertEquals(mrid, artifact[0].getModuleRevisionId());
    assertEquals("test", artifact[0].getName());
    assertEquals("jar", artifact[0].getExt());
    assertEquals("jar", artifact[0].getType());
}
 
Example #12
Source File: IvyDeliverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimple() throws Exception {
    project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest.xml");
    IvyResolve res = new IvyResolve();
    res.setProject(project);
    res.execute();

    deliver.setPubrevision("1.2");
    deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml");
    deliver.execute();

    // should have done the ivy delivering
    File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml");
    assertTrue(deliveredIvyFile.exists());
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(
        new IvySettings(), deliveredIvyFile.toURI().toURL(), true);
    assertEquals(ModuleRevisionId.newInstance("apache", "resolve-latest", "1.2"),
        md.getModuleRevisionId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertEquals(1, dds.length);
    assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.2"),
        dds[0].getDependencyRevisionId());
    assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "latest.integration"),
        dds[0].getDynamicConstraintDependencyRevisionId());
}
 
Example #13
Source File: ModuleDescriptorMemoryCache.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
void putInCache(File url, ParserSettingsMonitor ivySettingsMonitor, boolean validated,
        ModuleDescriptor descriptor) {
    if (maxSize <= 0) {
        // cache is disabled
        return;
    }
    synchronized (valueMap) {
        if (valueMap.size() >= maxSize) {
            Message.debug("ModuleDescriptorCache is full, remove one entry");
            Iterator<CacheEntry> it = valueMap.values().iterator();
            it.next();
            it.remove();
        }
        valueMap.put(url, new CacheEntry(descriptor, validated, ivySettingsMonitor));
    }
}
 
Example #14
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testHomeAndDescription() throws Exception {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("mule-1.3.3.pom"), false);
    assertNotNull(md);

    assertEquals(ModuleRevisionId.newInstance("org.mule", "mule", "1.3.3"),
        md.getModuleRevisionId());

    assertEquals("http://mule.mulesource.org", md.getHomePage());
    assertEquals(
        "Mule is a simple yet robust and highly scalable Integration and ESB services "
                + "framework. It is designed\n        as a light-weight, event-driven component "
                + "technology that handles communication with disparate systems\n        "
                + "transparently providing a simple component interface.", md.getDescription()
                .replaceAll("\r\n", "\n").replace('\r', '\n'));
}
 
Example #15
Source File: PomModuleDescriptorWriter.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private static DependencyDescriptor[] getDependencies(ModuleDescriptor md,
        PomWriterOptions options) {
    String[] confs = ConfigurationUtils.replaceWildcards(options.getConfs(), md);

    List<DependencyDescriptor> result = new ArrayList<>();
    for (DependencyDescriptor dd : md.getDependencies()) {
        String[] depConfs = dd.getDependencyConfigurations(confs);
        if (depConfs != null && depConfs.length > 0) {
            result.add(dd);
        }
    }

    return result.toArray(new DependencyDescriptor[result.size()]);
}
 
Example #16
Source File: EndResolveEvent.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public EndResolveEvent(ModuleDescriptor md, String[] confs, ResolveReport report) {
    super(NAME, md, confs);
    this.report = report;
    addAttribute("resolve-id", String.valueOf(report.getResolveId()));
    addAttribute("nb-dependencies", String.valueOf(report.getDependencies().size()));
    addAttribute("nb-artifacts", String.valueOf(report.getArtifacts().size()));
    addAttribute("resolve-duration", String.valueOf(report.getResolveTime()));
    addAttribute("download-duration", String.valueOf(report.getDownloadTime()));
    addAttribute("download-size", String.valueOf(report.getDownloadSize()));
}
 
Example #17
Source File: ModuleDescriptorWrapper.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public static Collection<ModuleDescriptor> unwrap(Collection<ModuleDescriptorWrapper> collection) {
    if (collection == null) {
        return null;
    }
    if (collection.isEmpty()) {
        return Collections.emptyList();
    }
    List<ModuleDescriptor> unwrapped = new ArrayList<>();
    for (ModuleDescriptorWrapper wrapped : collection) {
        unwrapped.add(wrapped.getModuleDescriptor());
    }
    return unwrapped;
}
 
Example #18
Source File: FixDepsTask.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Override
public void doExecute() throws BuildException {
    prepareAndCheck();

    if (dest == null) {
        throw new BuildException("Missing required parameter 'tofile'");
    }
    if (dest.exists() && dest.isDirectory()) {
        throw new BuildException("The destination file '" + dest.getAbsolutePath()
                + "' already exist and is a folder");
    }

    ResolveReport report = getResolvedReport();

    List<ModuleId> midToKeep = new ArrayList<>();
    for (Keep keep : keeps) {
        midToKeep.add(ModuleId.newInstance(keep.org, keep.module));
    }

    ModuleDescriptor md = report.toFixedModuleDescriptor(getSettings(), midToKeep);
    try {
        XmlModuleDescriptorWriter.write(md, dest);
    } catch (IOException e) {
        throw new BuildException("Failed to write into the file " + dest.getAbsolutePath()
                + " (" + e.getMessage() + ")", e);
    }
}
 
Example #19
Source File: AbstractRepositoryCacheManager.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected ModuleDescriptor parseModuleDescriptor(DependencyResolver resolver, Artifact moduleArtifact, CacheMetadataOptions options, File artifactFile, Resource resource) throws ParseException {
    ModuleRevisionId moduleRevisionId = moduleArtifact.getId().getModuleRevisionId();
    try {
        IvySettings ivySettings = IvyContextualiser.getIvyContext().getSettings();
        ParserSettings parserSettings = new LegacyResolverParserSettings(ivySettings, resolver, moduleRevisionId);
        ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(resource);
        return parser.parseDescriptor(parserSettings, new URL(artifactFile.toURI().toASCIIString()), resource, options.isValidate());
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
Example #20
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNamespaces() throws Exception {
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-namespaces.xml"), true);
    assertNotNull(md);
    ModuleRevisionId mrid = md.getModuleRevisionId();
    assertEquals("myorg", mrid.getOrganisation());
    assertEquals("mymodule", mrid.getName());
    assertEquals("myval", mrid.getExtraAttribute("e:myextra"));
    assertEquals(Collections.singletonMap("e:myextra", "myval"),
        mrid.getQualifiedExtraAttributes());
    assertEquals("myval", mrid.getExtraAttribute("myextra"));
    assertEquals(Collections.singletonMap("myextra", "myval"), mrid.getExtraAttributes());
    assertEquals("http://ant.apache.org/ivy/extra", md.getExtraAttributesNamespaces().get("e"));
}
 
Example #21
Source File: AntWorkspaceResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
        throws ParseException {
    for (Map.Entry<ModuleDescriptor, File> md : getModuleDescriptors().entrySet()) {
        ResolvedModuleRevision rmr = checkCandidate(dd, md.getKey(),
            getProjectName(md.getValue()));
        if (rmr != null) {
            return rmr;
        }
    }
    return null;
}
 
Example #22
Source File: AbstractOSGiResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Override
protected void checkModuleDescriptorRevision(ModuleDescriptor systemMd,
        ModuleRevisionId systemMrid) {
    String osgiType = systemMrid.getOrganisation();
    // only check revision if we're searching for a bundle (package and bundle have different
    // version
    if (osgiType == null || osgiType.equals(BundleInfo.BUNDLE_TYPE)) {
        super.checkModuleDescriptorRevision(systemMd, systemMrid);
    }
}
 
Example #23
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
protected void checkModuleDescriptorRevision(ModuleDescriptor systemMd,
        ModuleRevisionId systemMrid) {
    if (!getSettings().getVersionMatcher().accept(systemMrid, systemMd)) {
        throw new UnresolvedDependencyException("\t" + getName()
                + ": unacceptable revision => was="
                + systemMd.getResolvedModuleRevisionId().getRevision() + " required="
                + systemMrid.getRevision());
    }
}
 
Example #24
Source File: ExternalModuleIvyDependencyDescriptorFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public EnhancedDependencyDescriptor createDependencyDescriptor(String configuration, ModuleDependency dependency, ModuleDescriptor parent) {
    ModuleRevisionId moduleRevisionId = createModuleRevisionId(dependency);
    EnhancedDependencyDescriptor dependencyDescriptor = new EnhancedDependencyDescriptor(
            dependency,
            parent,
            moduleRevisionId,
            getExternalModuleDependency(dependency).isForce(),
            getExternalModuleDependency(dependency).isChanging(),
            getExternalModuleDependency(dependency).isTransitive());
    addExcludesArtifactsAndDependencies(configuration, getExternalModuleDependency(dependency), dependencyDescriptor);
    return dependencyDescriptor;
}
 
Example #25
Source File: ProjectIvyDependencyDescriptorFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public EnhancedDependencyDescriptor createDependencyDescriptor(String configuration, ModuleDependency dependency, ModuleDescriptor parent) {
    ProjectDependencyInternal projectDependency = (ProjectDependencyInternal) dependency;
    projectDependency.beforeResolved();
    ModuleRevisionId moduleRevisionId = createModuleRevisionId(dependency);
    ProjectDependencyDescriptor dependencyDescriptor = new ProjectDependencyDescriptor(projectDependency, parent, moduleRevisionId, false, false, dependency.isTransitive());
    addExcludesArtifactsAndDependencies(configuration, dependency, dependencyDescriptor);
    return dependencyDescriptor;
}
 
Example #26
Source File: ResolvedModuleRevision.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public ResolvedModuleRevision(DependencyResolver resolver, DependencyResolver artifactResolver,
        ModuleDescriptor descriptor, MetadataArtifactDownloadReport report) {
    this.resolver = resolver;
    this.artifactResolver = artifactResolver;
    this.descriptor = descriptor;
    this.report = report;
}
 
Example #27
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #28
Source File: ModuleDescriptorStore.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public LocallyAvailableResource putModuleDescriptor(ModuleComponentRepository repository, final ModuleDescriptor moduleDescriptor) {
    String filePath = getFilePath(repository, moduleDescriptor.getModuleRevisionId());
    return metaDataStore.add(filePath, new Action<File>() {
        public void execute(File moduleDescriptorFile) {
            try {
                descriptorWriter.write(moduleDescriptor, moduleDescriptorFile);
            } catch (Exception e) {
                throw UncheckedException.throwAsUncheckedException(e);
            }
        }
    });
}
 
Example #29
Source File: XmlModuleDescriptorUpdater.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void writeInheritedConfigurations(ModuleDescriptor merged) {
    if (!mergedConfigurations) {
        mergedConfigurations = true;
        writeInheritedItems(merged, merged.getConfigurations(),
            ConfigurationPrinter.INSTANCE, "configurations", false);
    }
}
 
Example #30
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testImportConfigurationsWithWildcardAndMappingOverride() throws Exception {
    // import configurations and default mapping
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-configextendsothers3.xml"), true);
    assertNotNull(md);

    // has 2 dependencies
    DependencyDescriptor[] dependencies = md.getDependencies();
    assertNotNull(dependencies);
    assertEquals(2, dependencies.length);

    // confs dep1: all-public->all-public (mappingoverride = true)
    DependencyDescriptor dd = getDependency(dependencies, "mymodule1");
    assertEquals(Collections.singletonList("all-public"),
        Arrays.asList(dd.getModuleConfigurations()));
    assertEquals(Collections.singletonList("all-public"),
        Arrays.asList(dd.getDependencyConfigurations("all-public")));

    // confs dep2: extra->extra;all-public->all-public (mappingoverride = true)
    dd = getDependency(dependencies, "mymodule2");
    assertEquals(Arrays.asList("extra", "all-public"),
        Arrays.asList(dd.getModuleConfigurations()));
    assertEquals(Collections.singletonList("extra"),
        Arrays.asList(dd.getDependencyConfigurations("extra")));
    assertEquals(Collections.singletonList("all-public"),
        Arrays.asList(dd.getDependencyConfigurations("all-public")));
}