Java Code Examples for org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor#addDependency()

The following examples show how to use org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor#addDependency() . 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: 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 2
Source File: BundleInfoAdapter.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private static void requirementAsDependency(DefaultModuleDescriptor md, BundleInfo bundleInfo,
        Set<String> exportedPkgNames) {
    for (BundleRequirement requirement : bundleInfo.getRequirements()) {
        String type = requirement.getType();
        String name = requirement.getName();

        if (BundleInfo.PACKAGE_TYPE.equals(type) && exportedPkgNames.contains(name)) {
            // don't declare package exported by the current bundle
            continue;
        }

        if (BundleInfo.EXECUTION_ENVIRONMENT_TYPE.equals(type)) {
            // execution environment are handled elsewhere
            continue;
        }

        ModuleRevisionId ddmrid = asMrid(type, name, requirement.getVersion());
        DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ddmrid, false);

        String conf = CONF_NAME_DEFAULT;
        if (BundleInfo.PACKAGE_TYPE.equals(type)) {
            // declare the configuration for the package
            conf = CONF_USE_PREFIX + name;
            md.addConfiguration(new Configuration(CONF_USE_PREFIX + name, PUBLIC,
                    "Exported package " + name, new String[] {CONF_NAME_DEFAULT}, true, null));
            dd.addDependencyConfiguration(conf, conf);
        }

        if ("optional".equals(requirement.getResolution())) {
            dd.addDependencyConfiguration(CONF_NAME_OPTIONAL, conf);
            dd.addDependencyConfiguration(CONF_NAME_TRANSITIVE_OPTIONAL,
                CONF_NAME_TRANSITIVE_OPTIONAL);
        } else {
            dd.addDependencyConfiguration(CONF_NAME_DEFAULT, conf);
        }

        md.addDependency(dd);
    }

}
 
Example 3
Source File: XmlModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Describes how dependencies should be inherited
 *
 * @param dependencies
 *            array of dependencies to inherit
 */
protected void mergeDependencies(DependencyDescriptor[] dependencies) {
    DefaultModuleDescriptor md = getMd();
    for (DependencyDescriptor dependencyDescriptor : dependencies) {
        Message.debug("Merging dependency with: "
                + dependencyDescriptor.getDependencyRevisionId().toString());
        md.addDependency(dependencyDescriptor);
    }
}
 
Example 4
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 5
Source File: TestClassWithDependencyRunner.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
private static List<URL> resolveArtifacts(List<String> dependencies) throws Exception {
    //creates clear ivy settings
    IvySettings ivySettings = new IvySettings();
    //url resolver for configuration of maven repo
    URLResolver resolver = new URLResolver();
    resolver.setM2compatible(true);
    resolver.setName("central");
    //you can specify the url resolution pattern strategy
    resolver.addArtifactPattern(
        "https://repo1.maven.org/maven2/"
            + "[organisation]/[module]/[revision]/[artifact](-[revision]).[ext]");
    //adding maven repo resolver
    ivySettings.addResolver(resolver);
    //set to the default resolver
    ivySettings.setDefaultResolver(resolver.getName());
    //creates an Ivy instance with settings
    Ivy ivy = Ivy.newInstance(ivySettings);

    File ivyfile = File.createTempFile("ivy", ".xml");
    ivyfile.deleteOnExit();

    DefaultModuleDescriptor md =
        DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.newInstance("foo", "foo" + "-caller", "working"));
    for (String dependency : dependencies) {
        String[] split = dependency.split(":");

        DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md,
            ModuleRevisionId.newInstance(split[0], split[1], split[2]), false, false, true);
        md.addDependency(dd);
    }

    //creates an ivy configuration file
    XmlModuleDescriptorWriter.write(md, ivyfile);

    String[] confs = new String[]{"default"};
    ResolveOptions resolveOptions = new ResolveOptions().setConfs(confs);

    //init resolve report
    ResolveReport report = ivy.resolve(ivyfile.toURL(), resolveOptions);

    List<URL> resolvedDependencies = new ArrayList<>();
    ArtifactDownloadReport[] allArtifactsReports = report.getAllArtifactsReports();
    for (ArtifactDownloadReport allArtifactsReport : allArtifactsReports) {
        resolvedDependencies.add(allArtifactsReport.getLocalFile().toURI().toURL());
    }
    assertThat(resolvedDependencies).hasSizeGreaterThanOrEqualTo(dependencies.size());
    return resolvedDependencies;
}
 
Example 6
Source File: DefaultDependencyDescriptorFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void addDependencyDescriptor(String configuration, DefaultModuleDescriptor moduleDescriptor,
                                    ModuleDependency dependency) {
    IvyDependencyDescriptorFactory factoryInternal = findFactoryForDependency(dependency);
    EnhancedDependencyDescriptor dependencyDescriptor = factoryInternal.createDependencyDescriptor(configuration, dependency, moduleDescriptor);
    moduleDescriptor.addDependency(dependencyDescriptor);
}
 
Example 7
Source File: DefaultDependencyDescriptorFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void addDependencyDescriptor(String configuration, DefaultModuleDescriptor moduleDescriptor,
                                    ModuleDependency dependency) {
    IvyDependencyDescriptorFactory factoryInternal = findFactoryForDependency(dependency);
    EnhancedDependencyDescriptor dependencyDescriptor = factoryInternal.createDependencyDescriptor(configuration, dependency, moduleDescriptor);
    moduleDescriptor.addDependency(dependencyDescriptor);
}
 
Example 8
Source File: SampleIvyRunner.java    From jeka with Apache License 2.0 4 votes vote down vote up
public void retrieve() {
    final IBiblioResolver dependencyResolver = new IBiblioResolver();
    dependencyResolver
    .setRoot("http://i-net1102e-prod:8081/nexus/content/groups/bnppf-secured");
    dependencyResolver.setM2compatible(true);
    dependencyResolver.setUseMavenMetadata(true);
    dependencyResolver.setName("nexus"); // Name is necessary to avoid NPE

    final IvySettings ivySettings = new IvySettings();
    ivySettings.addResolver(dependencyResolver);
    ivySettings.setDefaultResolver("nexus"); // Setting a default resolver
    // is necessary

    final Ivy ivy = Ivy.newInstance(ivySettings);
    ivy.getLoggerEngine().setDefaultLogger(new DefaultMessageLogger(Message.MSG_DEBUG));

    final ModuleRevisionId thisModuleRevisionId = ModuleRevisionId.newInstance("mygroupId",
            "myartifactId-envelope", "myversion");

    final ModuleRevisionId dependee = ModuleRevisionId.newInstance("org.springframework",
            "spring-jdbc", "3.0.0.RELEASE");
    // final ModuleRevisionId dependee =
    // ModuleRevisionId.newInstance("org.hibernate",
    // "hibernate-core", "3.6.10.Final");

    // 1st create an ivy module (this always(!) has a "default"
    // configuration already)
    final DefaultModuleDescriptor moduleDescriptor = DefaultModuleDescriptor
            .newDefaultInstance(thisModuleRevisionId);

    // don't go transitive here, if you want the single artifact
    final boolean transitive = true;
    final DefaultDependencyDescriptor dependencyDescriptor = new DefaultDependencyDescriptor(
            moduleDescriptor, dependee, false, false, transitive);

    // map to master to just get the code jar. See generated ivy module xmls
    // from maven repo
    // on how configurations are mapped into ivy. Or check
    // e.g.
    // http://lightguard-jp.blogspot.de/2009/04/ivy-configurations-when-pulling-from.html
    // dependencyDescriptor.addDependencyConfiguration("default", "master");

    // To get more than 1 artifact i need to declare "compile" and not
    // "master"
    dependencyDescriptor.addDependencyConfiguration("default", "compile");

    moduleDescriptor.addDependency(dependencyDescriptor);

    // now resolve
    final ResolveOptions resolveOptions = new ResolveOptions()
    .setConfs(new String[] { "default" });
    resolveOptions.setTransitive(transitive);
    ResolveReport reportResolver;
    try {
        reportResolver = ivy.resolve(moduleDescriptor, resolveOptions);
    } catch (final Exception e1) {
        throw new RuntimeException(e1);
    }
    if (reportResolver.hasError()) {
        System.out
        .println("*************************************************************************");
        System.out.println(reportResolver);

        throw new RuntimeException(reportResolver.getAllProblemMessages().toString());
    }
    for (final ArtifactDownloadReport artifactDownloadReport : reportResolver
            .getAllArtifactsReports()) {
        System.out.println("*********************************"
                + artifactDownloadReport.getLocalFile());

    }

    final String filePattern = new File("jeka/output/downloaded-libs").getAbsolutePath()
            + "/[artifact](-[classifier]).[ext]";
    final RetrieveOptions retrieveOptions = new RetrieveOptions()
    .setConfs(new String[] { "default" });
    try {
        ivy.retrieve(moduleDescriptor.getModuleRevisionId(), filePattern, retrieveOptions);
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }

}
 
Example 9
Source File: IvyDependencyUpdateChecker.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
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 10
Source File: TestPerformance.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private void generateModules(int nbModules, int minDependencies, int maxDependencies,
        int minVersions, int maxVersions) throws IOException {
    int nb = 0;
    int curDep = 1;
    int varDeps = maxDependencies - minDependencies;
    int varVersions = maxVersions - minVersions;
    Random r = new Random(System.currentTimeMillis());

    while (nb < nbModules) {
        int deps = minDependencies + r.nextInt(varDeps + 1);
        int versions = minVersions + r.nextInt(varVersions + 1);

        int prevCurDep = curDep;
        for (int ver = 0; ver < versions; ver++) {
            DefaultModuleDescriptor md = new DefaultModuleDescriptor(
                    ModuleRevisionId.newInstance("apache", "mod" + nb, "1." + ver),
                    "integration", new Date());

            curDep = prevCurDep;
            for (int i = 0; i < deps && curDep < nbModules; i++) {
                int d;
                if (i % 2 == 1) {
                    d = nb + i;
                    if (d >= prevCurDep) {
                        d = curDep;
                        curDep++;
                    }
                } else {
                    d = curDep;
                    curDep++;
                }
                DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
                        md,
                        ModuleRevisionId.newInstance("apache", "mod" + d, "latest.integration"),
                        false, false, true);
                dd.addDependencyConfiguration("default", "default");
                md.addDependency(dd);
            }
            XmlModuleDescriptorWriter.write(md, new File("build/test/perf/mod" + nb + "/ivy-1."
                    + ver + ".xml"));
            FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"),
                new File("build/test/perf/mod" + nb + "/mod" + nb + "-1." + ver + ".jar"), null);
        }
        nb++;
    }
}