org.apache.ivy.plugins.resolver.IBiblioResolver Java Examples

The following examples show how to use org.apache.ivy.plugins.resolver.IBiblioResolver. 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: IvyConfigureTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefault() {
    // by default settings look in the current directory for an ivysettings.xml file...
    // but Ivy itself has one, and we don't want to use it
    configure.getProject().setProperty("ivy.settings.file", "no/settings/will/use/default.xml");
    configure.execute();

    IvySettings settings = getIvyInstance().getSettings();
    assertNotNull(settings.getDefaultResolver());

    DependencyResolver publicResolver = settings.getResolver("public");
    assertNotNull(publicResolver);
    assertTrue(publicResolver instanceof IBiblioResolver);
    IBiblioResolver ibiblio = (IBiblioResolver) publicResolver;
    assertTrue(ibiblio.isM2compatible());
}
 
Example #2
Source File: XmlSettingsParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Test case for IVY-860.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-860">IVY-860</a>
 */
@Test
public void testMacroAndRef2() throws Exception {
    IvySettings settings = new IvySettings();
    XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-macro+ref2.xml"));

    DependencyResolver macrores = settings.getResolver("macroresolver");
    assertNotNull(macrores);
    assertTrue(macrores instanceof ChainResolver);

    DependencyResolver testResolver = settings.getResolver("test");
    assertNotNull(testResolver);
    assertTrue(testResolver instanceof IBiblioResolver);

    ChainResolver chain = (ChainResolver) macrores;
    List<DependencyResolver> subresolvers = chain.getResolvers();
    assertNotNull(subresolvers);
    assertEquals(1, subresolvers.size());
    assertEquals(testResolver, subresolvers.get(0));
}
 
Example #3
Source File: CommonRepositories.java    From IJava with MIT License 5 votes vote down vote up
public static DependencyResolver maven(String name, String urlRaw) {
    IBiblioResolver resolver = new IBiblioResolver();
    resolver.setM2compatible(true);
    resolver.setUseMavenMetadata(true);
    resolver.setUsepoms(true);

    resolver.setRoot(urlRaw);
    resolver.setName(name);

    return resolver;
}
 
Example #4
Source File: IvyPublisherForMaven.java    From jeka with Apache License 2.0 5 votes vote down vote up
private String completePath(String path) {
    if (this.resolver instanceof IBiblioResolver) {
        final IBiblioResolver iBiblioResolver = (IBiblioResolver) this.resolver;
        return iBiblioResolver.getRoot() + path;
    }
    return path;
}
 
Example #5
Source File: SearchTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testListInMavenRepo2() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/m2/ivysettings.xml").toURI().toURL());
    ((IBiblioResolver) ivy.getSettings().getResolver("m2")).setUseMavenMetadata(false);

    Map<String, Object> otherTokenValues = new HashMap<>();
    otherTokenValues.put(IvyPatternHelper.ORGANISATION_KEY, "org.apache");
    otherTokenValues.put(IvyPatternHelper.MODULE_KEY, "test-metadata");
    String[] revs = ivy.listTokenValues(IvyPatternHelper.REVISION_KEY, otherTokenValues);

    assertEquals(new HashSet<>(Arrays.asList("1.0", "1.1", "1.2")),
            new HashSet<>(Arrays.asList(revs)));
}
 
Example #6
Source File: ConfigureTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefault() throws ParseException, IOException {
    Ivy ivy = new Ivy();
    ivy.configureDefault();

    IvySettings settings = ivy.getSettings();
    assertNotNull(settings.getDefaultResolver());

    DependencyResolver publicResolver = settings.getResolver("public");
    assertNotNull(publicResolver);
    assertTrue(publicResolver instanceof IBiblioResolver);
    IBiblioResolver ibiblio = (IBiblioResolver) publicResolver;
    assertTrue(ibiblio.isM2compatible());
}
 
Example #7
Source File: XmlSettingsParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that timeout constraints referenced by resolvers, in an ivy settings file, are
 * processed correctly and the corresponding resolvers use the right timeout constraints
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testResolverTimeoutConstraintRefs() throws Exception {
    final IvySettings settings = new IvySettings();
    settings.setBaseDir(new File("test/base/dir"));
    final XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-timeout-constraints.xml"));

    final URLResolver resolver1 = (URLResolver) settings.getResolver("urlresolver-1");
    assertNotNull("Missing resolver urlresolver-1", resolver1);
    final TimeoutConstraint resolver1Timeouts = resolver1.getTimeoutConstraint();
    assertNotNull("Timeout constraint missing on resolver " + resolver1.getName(), resolver1Timeouts);
    assertEquals("Unexpected connection timeout " + resolver1Timeouts.getConnectionTimeout() + " on resolver " + resolver1.getName(), 400, resolver1Timeouts.getConnectionTimeout());
    assertEquals("Unexpected read timeout " + resolver1Timeouts.getReadTimeout() + " on resolver " + resolver1.getName(), -1, resolver1Timeouts.getReadTimeout());

    final IBiblioResolver resolver2 = (IBiblioResolver) settings.getResolver("ibiblio-resolver");
    assertNotNull("Missing resolver ibiblio-resolver", resolver2);
    final TimeoutConstraint resolver2Timeouts = resolver2.getTimeoutConstraint();
    assertNotNull("Timeout constraint missing on resolver " + resolver2.getName(), resolver2Timeouts);
    assertEquals("Unexpected connection timeout " + resolver2Timeouts.getConnectionTimeout() + " on resolver " + resolver2.getName(), 100, resolver2Timeouts.getConnectionTimeout());
    assertEquals("Unexpected read timeout " + resolver2Timeouts.getReadTimeout() + " on resolver " + resolver2.getName(), 500, resolver2Timeouts.getReadTimeout());

    final FileSystemResolver resolver3 = (FileSystemResolver) settings.getResolver("fs");
    assertNotNull("Missing resolver fs", resolver3);
    final TimeoutConstraint resolver3Timeouts = resolver3.getTimeoutConstraint();
    assertNull("No timeout was expected on resolver " + resolver3.getName(), resolver3Timeouts);

}
 
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);
    }

}