Java Code Examples for org.apache.ivy.core.settings.IvySettings#addResolver()

The following examples show how to use org.apache.ivy.core.settings.IvySettings#addResolver() . 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: ResolveIvyFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void ivyContextualize(IvyAwareModuleVersionRepository ivyAwareRepository, RepositoryChain userResolverChain, String configurationName) {
    Ivy ivy = IvyContext.getContext().getIvy();
    IvySettings ivySettings = ivy.getSettings();
    LoopbackDependencyResolver loopbackDependencyResolver = new LoopbackDependencyResolver("main", userResolverChain, cacheLockingManager);
    ivySettings.addResolver(loopbackDependencyResolver);
    ivySettings.setDefaultResolver(loopbackDependencyResolver.getName());

    ResolveData resolveData = createResolveData(ivy, configurationName);
    ivyAwareRepository.setSettings(ivySettings);
    ivyAwareRepository.setResolveData(resolveData);
}
 
Example 2
Source File: MavenResolver.java    From IJava with MIT License 5 votes vote down vote up
private void addPomReposToIvySettings(IvySettings settings, File pomFile) throws ModelBuildingException {
    Model mavenModel = Maven.getInstance().readEffectiveModel(pomFile).getEffectiveModel();
    ChainResolver pomRepos = MavenToIvy.createChainForModelRepositories(mavenModel);
    pomRepos.setName(DEFAULT_RESOLVER_NAME);

    settings.addResolver(pomRepos);
    settings.setDefaultResolver(DEFAULT_RESOLVER_NAME);
}
 
Example 3
Source File: ResolveIvyFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void ivyContextualize(IvyAwareModuleVersionRepository ivyAwareRepository, RepositoryChain userResolverChain, String configurationName) {
    Ivy ivy = IvyContext.getContext().getIvy();
    IvySettings ivySettings = ivy.getSettings();
    LoopbackDependencyResolver loopbackDependencyResolver = new LoopbackDependencyResolver("main", userResolverChain, cacheLockingManager);
    ivySettings.addResolver(loopbackDependencyResolver);
    ivySettings.setDefaultResolver(loopbackDependencyResolver.getName());

    ResolveData resolveData = createResolveData(ivy, configurationName);
    ivyAwareRepository.setSettings(ivySettings);
    ivyAwareRepository.setResolveData(resolveData);
}
 
Example 4
Source File: IvyTranslations.java    From jeka with Apache License 2.0 5 votes vote down vote up
static void populateIvySettingsWithPublishRepo(IvySettings ivySettings,
                                               JkRepoSet repos) {
    for (final JkRepo publishRepo : repos.getRepoList()) {
        final DependencyResolver resolver = toResolver(publishRepo,false);
        resolver.setName(PUBLISH_RESOLVER_NAME + publishRepo.getUrl());
        ivySettings.addResolver(resolver);
    }
}
 
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: IvyResolverBackedModuleVersionPublisher.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setSettings(IvySettings settings) {
    settings.addResolver(resolver);
}
 
Example 7
Source File: IvyDependencyResolverAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setSettings(IvySettings settings) {
    settings.addResolver(resolver);
}
 
Example 8
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 9
Source File: IvyResolverBackedModuleVersionPublisher.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setSettings(IvySettings settings) {
    settings.addResolver(resolver);
}
 
Example 10
Source File: IvyDependencyResolverAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setSettings(IvySettings settings) {
    settings.addResolver(resolver);
}
 
Example 11
Source File: IvyTranslations.java    From jeka with Apache License 2.0 4 votes vote down vote up
static void populateIvySettingsWithRepo(IvySettings ivySettings, JkRepoSet repos) {
    final DependencyResolver resolver = toChainResolver(repos);
    resolver.setName(MAIN_RESOLVER_NAME);
    ivySettings.addResolver(resolver);
    ivySettings.setDefaultResolver(MAIN_RESOLVER_NAME);
}
 
Example 12
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 13
Source File: TestHelper.java    From ant-ivy with Apache License 2.0 3 votes vote down vote up
/**
 * Init a test resolver as default, useful combined with
 * {@link #fillRepository(DependencyResolver, Collection)}.
 *
 * @param settings
 *            the settings to initialize
 * @return test settings
 */
public static IvySettings loadTestSettings(IvySettings settings) {
    settings.setDefaultCache(new File("build/test/cache"));
    settings.addResolver(newTestRepository());
    settings.setDefaultResolver("test");
    return settings;
}