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

The following examples show how to use org.apache.ivy.plugins.resolver.URLResolver. 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: 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 #2
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;
}