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

The following examples show how to use org.apache.ivy.core.resolve.ResolveOptions#setConfs() . 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: ResolveIvyFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private ResolveData createResolveData(Ivy ivy, String configurationName) {
    ResolveOptions options = new ResolveOptions();
    options.setDownload(false);
    options.setConfs(WrapUtil.toArray(configurationName));
    return new ResolveData(ivy.getResolveEngine(), options);
}
 
Example 3
Source File: ResolveIvyFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private ResolveData createResolveData(Ivy ivy, String configurationName) {
    ResolveOptions options = new ResolveOptions();
    options.setDownload(false);
    options.setConfs(WrapUtil.toArray(configurationName));
    return new ResolveData(ivy.getResolveEngine(), options);
}
 
Example 4
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 5
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 6
Source File: IBiblioMavenSnapshotsResolutionTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that an Ivy module that depends on regular and timestamped snapshots of Maven
 * artifacts, when resolved using a {@link IBiblioResolver} and with
 * {@link MavenTimedSnapshotVersionMatcher} configured in {@link IvySettings}, is resolved
 * correctly for such snapshot dependencies.
 *
 * @throws Exception
 *             if something goes wrong
 */
@Test
public void testSnapshotResolution() throws Exception {
    final IvySettings settings = this.ivy.getSettings();
    assertNotNull("Maven timestamped snapshot revision version matcher is absent",
        settings.getVersionMatcher(new MavenTimedSnapshotVersionMatcher().getName()));
    final ResolveOptions resolveOptions = new ResolveOptions();
    resolveOptions.setConfs(new String[]{"default"});
    final ResolveReport report = ivy.resolve(new File("test/repositories/2/maven-snapshot-deps-test/ivy-with-maven-snapshot-deps.xml"), resolveOptions);
    assertNotNull("Resolution report was null", report);
    assertFalse("Resolution report has error(s)", report.hasError());

    final ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull("Module descriptor in resolution report was null", md);
    final ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache.ivy",
        "maven-snapshot-deps-test", "1.2.3");
    assertEquals("Unexpected module resolved", mrid, md.getModuleRevisionId());

    final ConfigurationResolveReport crr = report.getConfigurationReport("default");

    final ModuleRevisionId exactRevision = ModuleRevisionId.newInstance("org.apache.ivy.maven-snapshot-test", "exact-revision", "2.3.4");
    final ArtifactDownloadReport[] dr1 = crr.getDownloadReports(exactRevision);
    assertNotNull("Artifact download report missing for dependency " + exactRevision, dr1);
    assertEquals("Unexpected number of artifact download report for dependency " + exactRevision, dr1.length, 1);
    final ArtifactDownloadReport exactRevDownloadReport = dr1[0];
    assertEquals("Unexpected download status for dependency " + exactRevision,
        exactRevDownloadReport.getDownloadStatus(), DownloadStatus.SUCCESSFUL);

    final ModuleRevisionId regularSnapshot = ModuleRevisionId.newInstance("org.apache.ivy.maven-snapshot-test", "regular-snapshot", "1.2.3-SNAPSHOT");
    final ArtifactDownloadReport[] dr2 = crr.getDownloadReports(regularSnapshot);
    assertNotNull("Artifact download report missing for dependency " + regularSnapshot, dr2);
    assertEquals("Unexpected number of artifact download report for dependency " + regularSnapshot, dr2.length, 1);
    final ArtifactDownloadReport regularSnapshotDownloadReport = dr2[0];
    assertEquals("Unexpected download status for dependency " + regularSnapshot,
        regularSnapshotDownloadReport.getDownloadStatus(), DownloadStatus.SUCCESSFUL);

    final ModuleRevisionId timestampedSnapshot = ModuleRevisionId.newInstance("org.apache.ivy.maven-snapshot-test", "timestamped-snapshot", "5.6.7-20170911.130943-1");
    final ArtifactDownloadReport[] dr3 = crr.getDownloadReports(timestampedSnapshot);
    assertNotNull("Artifact download report missing for dependency " + timestampedSnapshot, dr3);
    assertEquals("Unexpected number of artifact download report for dependency " + timestampedSnapshot, dr3.length, 1);
    final ArtifactDownloadReport timestampedSnapshotDownloadReport = dr3[0];
    assertEquals("Unexpected download status for dependency " + timestampedSnapshot,
        timestampedSnapshotDownloadReport.getDownloadStatus(), DownloadStatus.SUCCESSFUL);

}
 
Example 7
Source File: DependenciesManager.java    From restcommander with Apache License 2.0 4 votes vote down vote up
public ResolveReport resolve() throws Exception {

        // Module
        ModuleDescriptorParserRegistry.getInstance().addParser(new YamlParser());
        File ivyModule = new File(application, "conf/dependencies.yml");
        if(!ivyModule.exists()) {
            System.out.println("~ !! " + ivyModule.getAbsolutePath() + " does not exist");
            return null;
        }


        // Variables
        System.setProperty("play.path", framework.getAbsolutePath());
        
        // Ivy
        Ivy ivy = configure();

        // Clear the cache
        boolean clearcache = System.getProperty("clearcache") != null;
        if(clearcache){
           System.out.println("~ Clearing cache : " + ivy.getResolutionCacheManager().getResolutionCacheRoot() + ",");
           System.out.println("~");
           try{
      		   FileUtils.deleteDirectory(ivy.getResolutionCacheManager().getResolutionCacheRoot());
      		   System.out.println("~       Clear");
           }catch(IOException e){
        	   System.out.println("~       Could not clear");
        	   System.out.println("~ ");
        	   e.printStackTrace();
             }

           System.out.println("~");
         }
        

        System.out.println("~ Resolving dependencies using " + ivyModule.getAbsolutePath() + ",");
        System.out.println("~");
        
        // Resolve
        ResolveEngine resolveEngine = ivy.getResolveEngine();
        ResolveOptions resolveOptions = new ResolveOptions();
        resolveOptions.setConfs(new String[]{"default"});
        resolveOptions.setArtifactFilter(FilterHelper.getArtifactTypeFilter(new String[]{"jar", "bundle"}));

        return resolveEngine.resolve(ivyModule.toURI().toURL(), resolveOptions);
    }