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

The following examples show how to use org.apache.ivy.core.module.descriptor.DependencyDescriptor. 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: DefaultDependencyToConfigurationResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Set<ConfigurationMetaData> resolveTargetConfigurations(DependencyMetaData dependencyMetaData, ConfigurationMetaData fromConfiguration, ComponentResolveMetaData targetComponent) {
    // TODO - resolve directly to config meta data
    ModuleDescriptor targetDescriptor = targetComponent.getDescriptor();
    DependencyDescriptor dependencyDescriptor = dependencyMetaData.getDescriptor();
    Set<String> targetConfigurationNames = new LinkedHashSet<String>();
    for (String config : dependencyDescriptor.getModuleConfigurations()) {
        if (config.equals("*") || config.equals("%")) {
            collectTargetConfiguration(dependencyDescriptor, fromConfiguration, fromConfiguration.getName(), targetDescriptor, targetConfigurationNames);
        } else if (fromConfiguration.getHierarchy().contains(config)) {
            collectTargetConfiguration(dependencyDescriptor, fromConfiguration, config, targetDescriptor, targetConfigurationNames);
        }
    }

    Set<ConfigurationMetaData> targets = new LinkedHashSet<ConfigurationMetaData>();
    for (String targetConfigurationName : targetConfigurationNames) {
        // TODO - move this down below
        if (targetDescriptor.getConfiguration(targetConfigurationName) == null) {
            throw new RuntimeException(String.format("Module version %s, configuration '%s' declares a dependency on configuration '%s' which is not declared in the module descriptor for %s",
                    fromConfiguration.getComponent().getId(), fromConfiguration.getName(),
                    targetConfigurationName, targetComponent.getId()));
        }
        ConfigurationMetaData targetConfiguration = targetComponent.getConfiguration(targetConfigurationName);
        targets.add(targetConfiguration);
    }
    return targets;
}
 
Example #2
Source File: IvyTranslationsTest.java    From jeka with Apache License 2.0 6 votes vote down vote up
@Test
public void toPublicationLessModule() throws Exception {
    final JkVersionProvider versionProvider = JkVersionProvider.of();

    // handle multiple artifacts properly
    JkDependencySet deps = deps();
    final DefaultModuleDescriptor desc = IvyTranslations.toPublicationLessModule(OWNER, deps, DEFAULT_SCOPE_MAPPING,
            versionProvider);
    final DependencyDescriptor[] dependencyDescriptors = desc.getDependencies();
    assertEquals(1, dependencyDescriptors.length);
    final DependencyDescriptor depDesc = dependencyDescriptors[0];
    final DependencyArtifactDescriptor[] artifactDescs = depDesc.getAllDependencyArtifacts();
    assertEquals(2, artifactDescs.length);
    final DependencyArtifactDescriptor mainArt = findArtifactIn(artifactDescs, null);
    assertNotNull(mainArt);
    final DependencyArtifactDescriptor linuxArt = findArtifactIn(artifactDescs, "linux");
    assertNotNull(linuxArt);
    System.out.println(Arrays.asList(linuxArt.getConfigurations()));

}
 
Example #3
Source File: DualResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testResolve() throws Exception {
    DualResolver dual = new DualResolver();
    MockResolver ivyResolver = MockResolver.buildMockResolver(settings, "ivy", true,
        new GregorianCalendar(2005, 1, 20).getTime());
    MockResolver artifactResolver = MockResolver.buildMockResolver(settings, "artifact",
        false, new GregorianCalendar(2005, 1, 20).getTime());
    dual.setIvyResolver(ivyResolver);
    dual.setArtifactResolver(artifactResolver);
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
            ModuleRevisionId.newInstance("org", "mod", "rev"), false);
    ResolvedModuleRevision rmr = dual.getDependency(dd, data);

    assertNotNull(rmr);
    assertEquals(dual, rmr.getArtifactResolver());
    assertEquals(Collections.<DependencyDescriptor> singletonList(dd), ivyResolver.askedDeps);
    assertTrue(artifactResolver.askedDeps.isEmpty());
}
 
Example #4
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testDependencyManagement() throws ParseException, IOException {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-dependencyMgt.pom"), false);
    assertNotNull(md);
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-depMgt", "1.0"),
        md.getModuleRevisionId());

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(1, dds.length);
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"),
        dds[0].getDependencyRevisionId());
    assertEquals("There is no special artifact when there is no classifier", 0,
        dds[0].getAllDependencyArtifacts().length);
    assertEquals(4, md.getExtraInfos().size());
}
 
Example #5
Source File: DefaultDependencyToConfigurationResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void collectTargetConfiguration(DependencyDescriptor dependencyDescriptor, ConfigurationMetaData fromConfiguration, String mappingRhs, ModuleDescriptor targetModule, Collection<String> targetConfigs) {
    String[] dependencyConfigurations = dependencyDescriptor.getDependencyConfigurations(mappingRhs, fromConfiguration.getName());
    for (String target : dependencyConfigurations) {
        String candidate = target;
        int startFallback = candidate.indexOf('(');
        if (startFallback >= 0) {
            if (candidate.charAt(candidate.length() - 1) == ')') {
                String preferred = candidate.substring(0, startFallback);
                if (targetModule.getConfiguration(preferred) != null) {
                    targetConfigs.add(preferred);
                    continue;
                }
                candidate = candidate.substring(startFallback + 1, candidate.length() - 1);
            }
        }
        if (candidate.equals("*")) {
            Collections.addAll(targetConfigs, targetModule.getPublicConfigurationsNames());
            continue;
        }
        targetConfigs.add(candidate);
    }
}
 
Example #6
Source File: DefaultDependencyToConfigurationResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Set<ConfigurationMetaData> resolveTargetConfigurations(DependencyMetaData dependencyMetaData, ConfigurationMetaData fromConfiguration, ComponentResolveMetaData targetComponent) {
    // TODO - resolve directly to config meta data
    ModuleDescriptor targetDescriptor = targetComponent.getDescriptor();
    DependencyDescriptor dependencyDescriptor = dependencyMetaData.getDescriptor();
    Set<String> targetConfigurationNames = new LinkedHashSet<String>();
    for (String config : dependencyDescriptor.getModuleConfigurations()) {
        if (config.equals("*") || config.equals("%")) {
            collectTargetConfiguration(dependencyDescriptor, fromConfiguration, fromConfiguration.getName(), targetDescriptor, targetConfigurationNames);
        } else if (fromConfiguration.getHierarchy().contains(config)) {
            collectTargetConfiguration(dependencyDescriptor, fromConfiguration, config, targetDescriptor, targetConfigurationNames);
        }
    }

    Set<ConfigurationMetaData> targets = new LinkedHashSet<ConfigurationMetaData>();
    for (String targetConfigurationName : targetConfigurationNames) {
        // TODO - move this down below
        if (targetDescriptor.getConfiguration(targetConfigurationName) == null) {
            throw new RuntimeException(String.format("Module version %s, configuration '%s' declares a dependency on configuration '%s' which is not declared in the module descriptor for %s",
                    fromConfiguration.getComponent().getId(), fromConfiguration.getName(),
                    targetConfigurationName, targetComponent.getId()));
        }
        ConfigurationMetaData targetConfiguration = targetComponent.getConfiguration(targetConfigurationName);
        targets.add(targetConfiguration);
    }
    return targets;
}
 
Example #7
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
protected ResourceMDParser getRMDParser(final DependencyDescriptor dd, final ResolveData data) {
    return new ResourceMDParser() {
        public MDResolvedResource parse(Resource resource, String rev) {
            try {
                ResolvedModuleRevision rmr = BasicResolver.this.parse(new ResolvedResource(
                        resource, rev), dd, data);
                if (rmr != null) {
                    return new MDResolvedResource(resource, rev, rmr);
                }
            } catch (ParseException e) {
                Message.warn("Failed to parse the file '" + resource + "'", e);
            }
            return null;
        }

    };
}
 
Example #8
Source File: IvyBuildList.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Adds the current node to the toKeep collection and then processes the each of the direct
 * dependencies of this node that appear in the moduleIdMap (indicating that the dependency is
 * part of this BuildList)
 *
 * @param node
 *            the node to be processed
 * @param toKeep
 *            the set of ModuleDescriptors that should be kept
 * @param moduleIdMap
 *            reference mapping of moduleId to ModuleDescriptor that are part of the BuildList
 */
private void processFilterNodeFromRoot(ModuleDescriptor node, Set<ModuleDescriptor> toKeep,
        Map<ModuleId, ModuleDescriptor> moduleIdMap) {
    // toKeep.add(node);
    for (DependencyDescriptor dep : node.getDependencies()) {
        ModuleId id = dep.getDependencyId();
        ModuleDescriptor md = moduleIdMap.get(id);
        // we test if this module id has a module descriptor, and if it isn't already in the
        // toKeep Set, in which there's probably a circular dependency
        if (md != null && !toKeep.contains(md)) {
            toKeep.add(md);
            if (!getOnlydirectdep()) {
                processFilterNodeFromRoot(md, toKeep, moduleIdMap);
            }
        }
    }
}
 
Example #9
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testDependencyManagementWithScope() throws ParseException, IOException {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-dependencyMgt-with-scope.pom"), false);
    assertNotNull(md);
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-depMgt", "1.1"),
        md.getModuleRevisionId());

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(1, dds.length);
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"),
        dds[0].getDependencyRevisionId());
    assertEquals("There is no special artifact when there is no classifier", 0,
        dds[0].getAllDependencyArtifacts().length);
    assertEquals("The number of configurations is incorrect", 1,
        dds[0].getModuleConfigurations().length);
    assertEquals("The configuration must be test", "test", dds[0].getModuleConfigurations()[0]);
}
 
Example #10
Source File: AbstractModuleDescriptorParserTester.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
protected void assertDependencyArtifactIncludeRules(DependencyDescriptor dd, String[] confs,
        String[] artifactsNames) {
    IncludeRule[] dads = dd.getIncludeRules(confs);
    assertNotNull(dads);
    assertEquals(artifactsNames.length, dads.length);
    for (String artifactsName : artifactsNames) {
        boolean found = false;
        for (IncludeRule dad : dads) {
            assertNotNull(dad);
            if (dad.getId().getName().equals(artifactsName)) {
                found = true;
                break;
            }
        }
        assertTrue("dependency include not found: " + artifactsName, found);
    }
}
 
Example #11
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Test case for IVY-392.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-392">IVY-392</a>
 */
@Test
public void testDependenciesWithInactiveProfile() throws Exception {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-dependencies-with-profile.pom"), false);
    assertNotNull(md);

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

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(1, dds.length);
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"),
        dds[0].getDependencyRevisionId());
}
 
Example #12
Source File: AbstractModuleDescriptorParserTester.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
protected void assertDependencyArtifacts(DependencyDescriptor dd, String[] confs,
        String[] artifactsNames) {
    DependencyArtifactDescriptor[] dads = dd.getDependencyArtifacts(confs);
    assertNotNull(dads);
    assertEquals(artifactsNames.length, dads.length);
    for (String artifactsName : artifactsNames) {
        boolean found = false;
        for (DependencyArtifactDescriptor dad : dads) {
            assertNotNull(dad);
            if (dad.getName().equals(artifactsName)) {
                found = true;
                break;
            }
        }
        assertTrue("dependency artifact not found: " + artifactsName, found);
    }
}
 
Example #13
Source File: LoopbackDependencyResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ResolvedModuleRevision getDependency(final DependencyDescriptor dd, final ResolveData data) throws ParseException {
    final DependencyResolver loopback = this;
    return cacheLockingManager.useCache(String.format("Resolve %s", dd), new Factory<ResolvedModuleRevision>() {
        public ResolvedModuleRevision create() {
            DefaultBuildableComponentResolveResult result = new DefaultBuildableComponentResolveResult();
            DefaultDependencyMetaData dependency = new DefaultDependencyMetaData(dd);
            IvyContext ivyContext = IvyContext.pushNewCopyContext();
            try {
                ivyContext.setResolveData(data);
                dependencyResolver.resolve(dependency, result);
            } finally {
                IvyContext.popContext();
            }
            return new ResolvedModuleRevision(loopback, loopback, result.getMetaData().getDescriptor(), null);
        }
    });
}
 
Example #14
Source File: AbstractModuleDescriptorParserTester.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
protected void assertDependencyModulesExcludes(DependencyDescriptor dd, String[] confs,
        String[] moduleNames) {
    ExcludeRule[] rules = dd.getExcludeRules(confs);
    assertNotNull(rules);
    assertEquals(moduleNames.length, rules.length);
    for (String moduleName : moduleNames) {
        boolean found = false;
        for (ExcludeRule rule : rules) {
            assertNotNull(rule);
            if (rule.getId().getModuleId().getName().equals(moduleName)) {
                found = true;
                break;
            }
        }
        assertTrue("dependency module exclude not found: " + moduleName, found);
    }
}
 
Example #15
Source File: ModuleDescriptorSorter.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * If current module has already been added to list, returns, Otherwise invokes
 * sortModuleDescriptorsHelp for all dependencies contained within set of moduleDescriptors.
 * Then finally adds self to list of sorted.<br/>
 * When a loop is detected by a recursive call, the moduleDescriptors are not added immediately
 * added to the sorted list. They are added as loop dependencies of the root, and will be added
 * to the sorted list only when the root itself will be added.
 *
 * @param current
 *            Current module to add to sorted list.
 * @throws CircularDependencyException somehow
 */
private void sortModuleDescriptorsHelp(ModuleInSort current, ModuleInSort caller)
        throws CircularDependencyException {
    // if already sorted return
    if (current.isProcessed()) {
        return;
    }
    if (current.checkLoop(caller, circularDepStrategy)) {
        return;
    }
    DependencyDescriptor[] descriptors = current.getDependencies();
    Message.debug("Sort dependencies of : " + current.toString()
            + " / Number of dependencies = " + descriptors.length);
    current.setCaller(caller);
    for (DependencyDescriptor descriptor : descriptors) {
        ModuleInSort child = moduleDescriptors.getModuleDescriptorDependency(descriptor);
        if (child != null) {
            sortModuleDescriptorsHelp(child, current);
        }
    }
    current.endOfCall();
    Message.debug("Sort done for : " + current.toString());
    current.addToSortedListIfRequired(sorted);
}
 
Example #16
Source File: IBiblioResolver.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Override
public ResolvedResource findIvyFileRef(DependencyDescriptor dd, ResolveData data) {
    if (!isM2compatible() || !isUsepoms()) {
        return null;
    }
    ModuleRevisionId mrid = dd.getDependencyRevisionId();
    mrid = convertM2IdForResourceSearch(mrid);
    final String revision = dd.getDependencyRevisionId().getRevision();
    final MavenTimedSnapshotVersionMatcher.MavenSnapshotRevision snapshotRevision = MavenTimedSnapshotVersionMatcher.computeIfSnapshot(revision);
    if (snapshotRevision != null) {
        final ResolvedResource rres = findSnapshotDescriptor(dd, data, mrid, snapshotRevision);
        if (rres != null) {
            return rres;
        }
    }
    return findResourceUsingPatterns(mrid, getIvyPatterns(),
            DefaultArtifact.newPomArtifact(mrid, data.getDate()), getRMDParser(dd, data),
            data.getDate());
}
 
Example #17
Source File: LoopbackDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ResolvedModuleRevision getDependency(final DependencyDescriptor dd, final ResolveData data) throws ParseException {
    final DependencyResolver loopback = this;
    return cacheLockingManager.useCache(String.format("Resolve %s", dd), new Factory<ResolvedModuleRevision>() {
        public ResolvedModuleRevision create() {
            DefaultBuildableComponentResolveResult result = new DefaultBuildableComponentResolveResult();
            DefaultDependencyMetaData dependency = new DefaultDependencyMetaData(dd);
            IvyContext ivyContext = IvyContext.pushNewCopyContext();
            try {
                ivyContext.setResolveData(data);
                dependencyResolver.resolve(dependency, result);
            } finally {
                IvyContext.popContext();
            }
            return new ResolvedModuleRevision(loopback, loopback, result.getMetaData().getDescriptor(), null);
        }
    });
}
 
Example #18
Source File: DualResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testResolveFail() throws Exception {
    DualResolver dual = new DualResolver();
    MockResolver ivyResolver = MockResolver.buildMockResolver(settings, "ivy", false,
        new GregorianCalendar(2005, 1, 20).getTime());
    MockResolver artifactResolver = MockResolver.buildMockResolver(settings, "artifact",
        false, new GregorianCalendar(2005, 1, 20).getTime());
    dual.setIvyResolver(ivyResolver);
    dual.setArtifactResolver(artifactResolver);
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
            ModuleRevisionId.newInstance("org", "mod", "rev"), false);
    ResolvedModuleRevision rmr = dual.getDependency(dd, data);

    assertNull(rmr);
    assertEquals(Collections.<DependencyDescriptor> singletonList(dd), ivyResolver.askedDeps);
    assertEquals(Collections.<DependencyDescriptor> singletonList(dd), artifactResolver.askedDeps);
}
 
Example #19
Source File: MessageBasedNonMatchingVersionReporter.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public void reportNonMatchingVersion(DependencyDescriptor descriptor, ModuleDescriptor md) {
    ModuleRevisionId dependencyRevisionId = descriptor.getDependencyRevisionId();
    ModuleRevisionId parentRevisionId = descriptor.getParentRevisionId();
    if (parentRevisionId == null) {
        // There are some rare case where DependencyDescriptor have no parent.
        // This is should not be used in the SortEngine, but if it is, we
        // show a decent trace.
        reportMessage("Non matching revision detected when sorting.  Dependency "
                + dependencyRevisionId + " doesn't match " + md.getModuleRevisionId());
    } else {
        ModuleId parentModuleId = parentRevisionId.getModuleId();
        reportMessage("Non matching revision detected when sorting.  " + parentModuleId
                + " depends on " + dependencyRevisionId + ", doesn't match "
                + md.getModuleRevisionId());
    }
}
 
Example #20
Source File: MockResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
        throws ParseException {
    ResolvedModuleRevision mr = data.getCurrentResolvedModuleRevision();
    if (mr != null) {
        if (shouldReturnResolvedModule(dd, mr)) {
            return mr;
        }
    }
    askedDeps.add(dd);
    return checkLatest(dd, rmr, data);
}
 
Example #21
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultConf() throws Exception {
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-defaultconf.xml"), true);
    assertNotNull(md);

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

    // no conf def => defaults to defaultConf: default
    DependencyDescriptor dd = getDependency(dependencies, "mymodule1");
    assertNotNull(dd);
    assertEquals("myorg", dd.getDependencyId().getOrganisation());
    assertEquals("1.0", dd.getDependencyRevisionId().getRevision());
    assertEquals(Collections.singletonList("default"),
        Arrays.asList(dd.getModuleConfigurations()));
    assertEquals(Collections.singletonList("default"),
        Arrays.asList(dd.getDependencyConfigurations("default")));

    // confs def: *->*
    dd = getDependency(dependencies, "mymodule2");
    assertNotNull(dd);
    assertEquals("myorg", dd.getDependencyId().getOrganisation());
    assertEquals("2.0", dd.getDependencyRevisionId().getRevision());
    assertEquals(Collections.singletonList("*"), Arrays.asList(dd.getModuleConfigurations()));
    assertEquals(Collections.singletonList("*"),
        Arrays.asList(dd.getDependencyConfigurations("default")));
}
 
Example #22
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithVersionPropertyAndPropertiesTag() throws Exception {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("test-version.pom"), false);
    assertNotNull(md);

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(2, dds.length);
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-other", "1.0"),
        dds[0].getDependencyRevisionId());
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-yet-other", "5.76"),
        dds[1].getDependencyRevisionId());
}
 
Example #23
Source File: SortTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private DependencyDescriptor addDependency(DefaultModuleDescriptor parent, String moduleName,
        String revision) {
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org", moduleName, revision);
    DependencyDescriptor depDescr = new DefaultDependencyDescriptor(parent, mrid, false, false,
            true);
    parent.addDependency(depDescr);
    return depDescr;
}
 
Example #24
Source File: IvyDeliverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithResolveIdInAnotherBuild() throws Exception {
    // create a new build
    Project other = TestHelper.newProject();
    other.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml");
    other.setProperty("build", "build/test/deliver");

    // do a resolve in the new build
    IvyResolve resolve = new IvyResolve();
    resolve.setProject(other);
    resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml"));
    resolve.setResolveId("withResolveId");
    resolve.execute();

    // resolve another ivy file
    resolve = new IvyResolve();
    resolve.setProject(project);
    resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml"));
    resolve.execute();

    deliver.setResolveId("withResolveId");
    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-simple", "1.2"),
        md.getModuleRevisionId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertEquals(1, dds.length);
    assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"),
        dds[0].getDependencyRevisionId());
}
 
Example #25
Source File: AbstractResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
protected void saveModuleRevisionIfNeeded(DependencyDescriptor dd,
        ResolvedModuleRevision newModuleFound) {
    if (newModuleFound != null
            && getSettings().getVersionMatcher().isDynamic(dd.getDependencyRevisionId())) {
        getRepositoryCacheManager().saveResolvedRevision(getName(),
            dd.getDependencyRevisionId(), newModuleFound.getId().getRevision());
    }
}
 
Example #26
Source File: XmlModuleUpdaterTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateWithExcludeConfigurations5() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/"
            + "test-update-excludedconfs5.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);

    DependencyDescriptor[] deps = updatedMd.getDependencies();
    assertNotNull("Dependencies shouldn't be null", deps);
    assertEquals("Number of dependencies is incorrect", 8, deps.length);

    // check that none of the dependencies contains myconf2
    for (DependencyDescriptor dep : deps) {
        String name = dep.getDependencyId().getName();
        assertFalse("Dependency " + name + " shouldn't have myconf2 as module configuration",
            Arrays.asList(dep.getModuleConfigurations()).contains("myconf2"));
        assertEquals(
            "Dependency " + name
                    + " shouldn't have a dependency artifact for configuration myconf2",
            0, dep.getDependencyArtifacts("myconf2").length);
    }
}
 
Example #27
Source File: AbstractOSGiResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private MDResolvedResource buildResolvedCapabilityMd(DependencyDescriptor dd,
        ModuleDescriptor md) {
    String org = dd.getDependencyRevisionId().getOrganisation();
    String name = dd.getDependencyRevisionId().getName();
    String rev = md.getExtraInfoContentByTagName(BundleInfoAdapter.EXTRA_INFO_EXPORT_PREFIX
            + name);
    ModuleRevisionId capabilityRev = ModuleRevisionId.newInstance(org, name, rev,
        Collections.singletonMap(CAPABILITY_EXTRA_ATTR, md.getModuleRevisionId().toString()));

    DefaultModuleDescriptor capabilityMd = new DefaultModuleDescriptor(capabilityRev,
            getSettings().getStatusManager().getDefaultStatus(), new Date());

    String useConf = BundleInfoAdapter.CONF_USE_PREFIX + dd.getDependencyRevisionId().getName();

    capabilityMd.addConfiguration(BundleInfoAdapter.CONF_DEFAULT);
    capabilityMd.addConfiguration(BundleInfoAdapter.CONF_OPTIONAL);
    capabilityMd.addConfiguration(BundleInfoAdapter.CONF_TRANSITIVE_OPTIONAL);
    capabilityMd.addConfiguration(new Configuration(useConf));

    DefaultDependencyDescriptor capabilityDD = new DefaultDependencyDescriptor(
            md.getModuleRevisionId(), false);
    capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_DEFAULT,
        BundleInfoAdapter.CONF_NAME_DEFAULT);
    capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_OPTIONAL,
        BundleInfoAdapter.CONF_NAME_OPTIONAL);
    capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_TRANSITIVE_OPTIONAL,
        BundleInfoAdapter.CONF_NAME_TRANSITIVE_OPTIONAL);
    capabilityDD.addDependencyConfiguration(useConf, useConf);
    capabilityMd.addDependency(capabilityDD);

    MetadataArtifactDownloadReport report = new MetadataArtifactDownloadReport(null);
    report.setDownloadStatus(DownloadStatus.NO);
    report.setSearched(true);
    ResolvedModuleRevision rmr = new ResolvedModuleRevision(this, this, capabilityMd, report);
    return new MDResolvedResource(null, capabilityMd.getRevision(), rmr);
}
 
Example #28
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testGrandparentBomImport() throws ParseException, IOException {
    settings.setDictatorResolver(new MockResolver() {
        public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
                throws ParseException {
            try {
                ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance()
                        .parseDescriptor(settings,
                            getClass().getResource(
                                String.format("depmgt/%s.pom", dd.getDependencyId().getName())),
                            false);
                return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
            } catch (IOException e) {
                throw new AssertionError(e);
            }
        }
    });
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
        getClass().getResource("depmgt/grandchild.pom"), false);
    assertNotNull(md);
    assertEquals("1.0", md.getRevision());

    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(2, dds.length);

    assertEquals(
        ModuleRevisionId.newInstance("commons-collection", "commons-collection", "1.0.5"),
        dds[0].getDependencyRevisionId());
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"),
        dds[1].getDependencyRevisionId());
}
 
Example #29
Source File: IvyNode.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public void addCaller(String rootModuleConf, IvyNode callerNode, String callerConf,
        String requestedConf, String[] dependencyConfs, DependencyDescriptor dd) {
    callers.addCaller(rootModuleConf, callerNode, callerConf, requestedConf, dependencyConfs,
        dd);
    boolean isCircular = callers.getAllCallersModuleIds().contains(getId().getModuleId());
    if (isCircular) {
        IvyContext.getContext().getCircularDependencyStrategy()
                .handleCircularDependency(toMrids(findPath(getId().getModuleId()), this));
    }
}
 
Example #30
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
protected boolean shouldReturnResolvedModule(DependencyDescriptor dd, ResolvedModuleRevision mr) {
    // a resolved module revision has already been found by a prior dependency resolver
    // let's see if it should be returned and bypass this resolver

    ModuleRevisionId mrid = dd.getDependencyRevisionId();
    boolean isDynamic = getSettings().getVersionMatcher().isDynamic(mrid);
    boolean shouldReturn = mr.isForce();
    shouldReturn |= !isDynamic && !mr.getDescriptor().isDefault();
    shouldReturn &= !isForce();

    return shouldReturn;
}