Java Code Examples for org.apache.ivy.core.resolve.ResolveOptions#setTransitive()

The following examples show how to use org.apache.ivy.core.resolve.ResolveOptions#setTransitive() . 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: MavenResolver.java    From IJava with MIT License 6 votes vote down vote up
private List<File> resolveFromIvyFile(Ivy ivy, File ivyFile, List<String> scopes) throws IOException, ParseException {
    ResolveOptions resolveOptions = new ResolveOptions();
    resolveOptions.setTransitive(true);
    resolveOptions.setDownload(true);
    resolveOptions.setConfs(!scopes.isEmpty()
            ? scopes.toArray(new String[0])
            : DEFAULT_RESOLVE_CONFS
    );

    ResolveReport resolved = ivy.resolve(ivyFile, resolveOptions);
    if (resolved.hasError())
        // TODO better error...
        throw new RuntimeException("Error resolving '" + ivyFile + "'. " + resolved.getAllProblemMessages());

    return Arrays.stream(resolved.getAllArtifactsReports())
            .map(ArtifactDownloadReport::getLocalFile)
            .collect(Collectors.toList());
}
 
Example 2
Source File: MavenResolver.java    From IJava with MIT License 4 votes vote down vote up
public List<File> resolveMavenDependency(String canonical, Set<String> repos, int verbosity) throws IOException, ParseException {
    ChainResolver rootResolver = this.searchAllReposResolver(repos);

    Ivy ivy = this.createDefaultIvyInstance(verbosity);
    IvySettings settings = ivy.getSettings();

    settings.addResolver(rootResolver);
    rootResolver.setCheckmodified(true);
    settings.setDefaultResolver(rootResolver.getName());

    ivy.getLoggerEngine().info("Searching for dependencies in: " + rootResolver.getResolvers());

    ResolveOptions resolveOptions = new ResolveOptions();
    resolveOptions.setTransitive(true);
    resolveOptions.setDownload(true);

    ModuleRevisionId artifactIdentifier = MavenResolver.parseCanonicalArtifactName(canonical);
    DefaultModuleDescriptor containerModule = DefaultModuleDescriptor.newCallerInstance(
            artifactIdentifier,
            DEFAULT_RESOLVE_CONFS,
            true, // Transitive
            repos != null // Changing - the resolver will set this based on SNAPSHOT since they are all m2 compatible
            // but if `repos` is specified, we want to force a lookup.
    );

    ResolveReport resolved = ivy.resolve(containerModule, resolveOptions);
    if (resolved.hasError()) {
        MessageLogger logger = ivy.getLoggerEngine();
        Arrays.stream(resolved.getAllArtifactsReports())
                .forEach(r -> {
                    logger.error("download " + r.getDownloadStatus() + ": " + r.getArtifact() + " of " + r.getType());
                    if (r.getArtifactOrigin() == null)
                        logger.error("\tCouldn't find artifact.");
                    else
                        logger.error("\tfrom: " + r.getArtifactOrigin());
                });

        // TODO better error...
        throw new RuntimeException("Error resolving '" + canonical + "'. " + resolved.getAllProblemMessages());
    }

    return Arrays.stream(resolved.getAllArtifactsReports())
            .filter(a -> JAR_TYPE.equalsIgnoreCase(a.getType()))
            .map(ArtifactDownloadReport::getLocalFile)
            .collect(Collectors.toList());
}
 
Example 3
Source File: IvyInternalDepResolver.java    From jeka with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public JkResolveResult resolve(JkVersionedModule moduleArg, JkDependencySet deps,
                               JkResolutionParameters parameters, JkScope ... resolvedScopes) {
    final JkVersionedModule module;
    if (moduleArg == null) {
        module = anonymousVersionedModule();
    } else {
        module = moduleArg;
    }
    final DefaultModuleDescriptor moduleDescriptor = IvyTranslations.toPublicationLessModule(
            module,
            deps,
            parameters.getScopeMapping(),
            deps.getVersionProvider()
    );
    setConflictManager(moduleDescriptor, parameters.getConflictResolver());

    final String[] confs = toConfs(moduleDescriptor.getConfigurations(), resolvedScopes);
    final ResolveOptions resolveOptions = new ResolveOptions();
    resolveOptions.setConfs(confs);
    resolveOptions.setTransitive(true);
    resolveOptions.setOutputReport(JkLog.verbosity().isVerbose());
    resolveOptions.setLog(logLevel());
    resolveOptions.setRefresh(parameters.isRefreshed());
    resolveOptions.setCheckIfChanged(true);
    resolveOptions.setOutputReport(true);
    if (resolvedScopes.length == 0) {   // if no scope, verbose ivy report turns in exception
        resolveOptions.setOutputReport(false);
    }
    final ResolveReport ivyReport;
    try {
        ivyReport = ivy.resolve(moduleDescriptor, resolveOptions);
    } catch (final Exception e) {
        throw JkUtilsThrowable.unchecked(e);
    }
    final JkResolveResult.JkErrorReport errorReport;
    if (ivyReport.hasError()) {
        errorReport = JkResolveResult.JkErrorReport.failure(moduleProblems(
                ivyReport.getDependencies()));
    } else {
        errorReport = JkResolveResult.JkErrorReport.allFine();
    }
    final ArtifactDownloadReport[] artifactDownloadReports = ivyReport.getAllArtifactsReports();
    final IvyArtifactContainer artifactContainer = IvyArtifactContainer.of(artifactDownloadReports);
    final JkResolveResult resolveResult = getResolveConf(ivyReport.getDependencies(), module,
            errorReport, artifactContainer);
    if (moduleArg == null) {
        deleteResolveCache(module);
    }
    return resolveResult;
}
 
Example 4
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);
    }

}