Search in sources :

Example 16 with DependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyDescriptor in project ant-ivy by apache.

the class URLResolverTest method testTimeoutConstraint.

/**
 * Tests that the timeout constraint set on the URL resolver is used correctly by the resolver
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testTimeoutConstraint() throws Exception {
    final NamedTimeoutConstraint highTimeout = new NamedTimeoutConstraint("test-high-timeout");
    highTimeout.setConnectionTimeout(60000);
    settings.addConfigured(highTimeout);
    final NamedTimeoutConstraint extremelyLowTimeout = new NamedTimeoutConstraint("test-extremely-low-timeout");
    extremelyLowTimeout.setConnectionTimeout(10);
    extremelyLowTimeout.setReadTimeout(20);
    settings.addConfigured(extremelyLowTimeout);
    // setup a HTTP backed repo
    // TODO: Right now the port is hard coded, but we need to find a "available" port to which can be bind to.
    // Else this can lead to occasional bind failures
    final InetSocketAddress fastServerBindAddr = new InetSocketAddress("localhost", 12345);
    final String contextRoot = "/testTimeouts";
    final Path repoRoot = new File("test/repositories/1").toPath();
    assertTrue(repoRoot + " is not a directory", Files.isDirectory(repoRoot));
    final DependencyDescriptor dependency = new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org1", "mod1.1", "2.0"), false);
    try (final AutoCloseable httpServer = TestHelper.createHttpServerBackedRepository(fastServerBindAddr, contextRoot, repoRoot)) {
        final String ivyPattern = "http://" + fastServerBindAddr.getHostName() + ":" + fastServerBindAddr.getPort() + "/testTimeouts/[organisation]/[module]/ivys/ivy-[revision].xml";
        final String artifactPattern = "http://" + fastServerBindAddr.getHostName() + ":" + fastServerBindAddr.getPort() + "/testTimeouts/[organisation]/[module]/[type]s/[artifact]-[revision].[type]";
        // first use a resolver with a high timeout to make sure
        // it can actually fetch the resources
        final URLResolver highTimeoutResolver = new URLResolver();
        highTimeoutResolver.setName("high-timeout-resolver");
        highTimeoutResolver.setAllownomd(false);
        highTimeoutResolver.setTimeoutConstraint("test-high-timeout");
        highTimeoutResolver.setSettings(settings);
        highTimeoutResolver.setIvyPatterns(Collections.singletonList(ivyPattern));
        highTimeoutResolver.setArtifactPatterns(Collections.singletonList(artifactPattern));
        highTimeoutResolver.validate();
        final TimeoutConstraint resolverTimeoutConstraint = highTimeoutResolver.getTimeoutConstraint();
        assertNotNull("Timeout constraint is missing on resolver " + highTimeoutResolver.getName(), resolverTimeoutConstraint);
        assertEquals("Unexpected connection timeout on resolver", 60000, resolverTimeoutConstraint.getConnectionTimeout());
        assertEquals("Unexpected read timeout on resolver", -1, resolverTimeoutConstraint.getReadTimeout());
        // do the fetch (expected to work fine)
        final ResolvedModuleRevision resolvedModule = highTimeoutResolver.getDependency(dependency, data);
        assertNotNull("Dependency wasn't resolved by resolver " + highTimeoutResolver.getName(), resolvedModule);
        assertEquals("Unexpected dependency resolved by resolver " + highTimeoutResolver.getName(), dependency.getDependencyRevisionId(), resolvedModule.getId());
    }
    // now test this whole fetch using a resolver with a very low connection timeout and
    // by starting the repo server with a delay so that the connection request can timeout
    // clean the cache before testing to ensure the resource isn't fetched from cache
    settings.getDefaultRepositoryCacheManager().clean();
    settings.getResolutionCacheManager().clean();
    final InetSocketAddress slowServerAddr = new InetSocketAddress("localhost", 23456);
    final String ivyPattern = "http://" + slowServerAddr.getHostName() + ":" + slowServerAddr.getPort() + "/testTimeouts/[organisation]/[module]/ivys/ivy-[revision].xml";
    final String artifactPattern = "http://" + slowServerAddr.getHostName() + ":" + slowServerAddr.getPort() + "/testTimeouts/[organisation]/[module]/[type]s/[artifact]-[revision].[type]";
    final URLResolver lowTimeoutResolver = new URLResolver();
    lowTimeoutResolver.setAllownomd(false);
    lowTimeoutResolver.setName("low-timeout-resolver");
    lowTimeoutResolver.setTimeoutConstraint("test-extremely-low-timeout");
    lowTimeoutResolver.setSettings(settings);
    lowTimeoutResolver.setIvyPatterns(Collections.singletonList(ivyPattern));
    lowTimeoutResolver.setArtifactPatterns(Collections.singletonList(artifactPattern));
    lowTimeoutResolver.validate();
    final TimeoutConstraint lowTimeoutConstraint = lowTimeoutResolver.getTimeoutConstraint();
    assertNotNull("Timeout constraint is missing on resolver " + lowTimeoutResolver.getName(), lowTimeoutConstraint);
    assertEquals("Unexpected connection timeout on resolver", 10, lowTimeoutConstraint.getConnectionTimeout());
    assertEquals("Unexpected read timeout on resolver", 20, lowTimeoutConstraint.getReadTimeout());
    final ExecutorService executor = Executors.newSingleThreadExecutor();
    final long serverStartupDelayInMillis = 500;
    final Future<AutoCloseable> httpServer = executor.submit(new ServerManager(slowServerAddr, contextRoot, repoRoot, serverStartupDelayInMillis));
    try {
        // do the fetch (resolution *isn't* expected to return resolved module)
        final ResolvedModuleRevision resolvedModuleFromLowTimeouts = lowTimeoutResolver.getDependency(dependency, data);
        assertNull("Dependency wasn't expected to be resolved by resolver " + lowTimeoutResolver.getName(), resolvedModuleFromLowTimeouts);
    } finally {
        try {
            // stop the server
            httpServer.get().close();
        } catch (Exception e) {
        // ignore
        // TODO: Better log it too. But I don't see usage of loggers in test cases currently. So need to get to this later
        }
        try {
            executor.shutdownNow();
        } catch (Exception e) {
        // ignore
        // TODO: Better log it too. But I don't see usage of loggers in test cases currently. So need to get to this later
        }
    }
}
Also used : Path(java.nio.file.Path) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) InetSocketAddress(java.net.InetSocketAddress) NamedTimeoutConstraint(org.apache.ivy.core.settings.NamedTimeoutConstraint) TimeoutConstraint(org.apache.ivy.core.settings.TimeoutConstraint) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) NamedTimeoutConstraint(org.apache.ivy.core.settings.NamedTimeoutConstraint) ExecutorService(java.util.concurrent.ExecutorService) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) File(java.io.File) Test(org.junit.Test)

Example 17 with DependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyDescriptor in project ant-ivy by apache.

the class RepositoryManagementEngine method analyze.

/**
 * Analyze data in the repository.
 * <p>
 * This method may take a long time to proceed. It should never be called from event dispatch
 * thread in a GUI.
 * </p>
 *
 * @throws IllegalStateException
 *             if the repository has not been loaded yet
 * @see #load()
 */
public void analyze() {
    ensureLoaded();
    Message.info("\nanalyzing dependencies...");
    for (ModuleDescriptor md : revisions.values()) {
        for (DependencyDescriptor dd : md.getDependencies()) {
            ModuleRevisionId dep = getDependency(dd);
            if (dep == null) {
                Message.warn("inconsistent repository: declared dependency not found: " + dd);
            } else {
                getDependers(dep).add(md.getModuleRevisionId());
            }
        }
        Message.progress();
    }
    analyzed = true;
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId)

Example 18 with DependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyDescriptor in project ant-ivy by apache.

the class ResolveTest method testIVY1300.

/**
 * Test case for IVY-1300.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1300">IVY-1300</a>
 */
@Test
public void testIVY1300() throws Exception {
    ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/IVY-1300/ivysettings.xml"));
    ResolveOptions opts = new ResolveOptions();
    opts.setConfs(new String[] { "*" });
    opts.setResolveId("resolveid");
    opts.setTransitive(true);
    ResolveReport report = ivy.resolve(new File("test/repositories/IVY-1300/assembly-ivy.xml"), opts);
    assertFalse(report.hasError());
    ModuleRevisionId modAExpectedRevId = ModuleRevisionId.newInstance("myorg", "modA", "trunk", "5");
    ModuleRevisionId modBExpectedRevId = ModuleRevisionId.newInstance("myorg", "modB", "releasebranch", "1");
    // check that the resolve report has the expected results, namely that
    // trunk/5 is considered later than branch/1 purely because 5>1. Of
    // course it is more likely that we would want to consider this a
    // 'bad comparison', but this Unit Test is not about that. It is about
    // inconsistency of results between the resolve report and the
    // delivered descriptor. In fact the delivered descriptor is out of
    // step, because retrieve and the report both agree that trunk/5 is
    // selected. Deliver begs to differ.
    Set<ModuleRevisionId> reportMrids = report.getConfigurationReport("default").getModuleRevisionIds();
    assertEquals(new HashSet<>(Arrays.asList(modAExpectedRevId, modBExpectedRevId)), reportMrids);
    DeliverOptions dopts = new DeliverOptions();
    dopts.setGenerateRevConstraint(true);
    dopts.setConfs(new String[] { "*" });
    dopts.setStatus("release");
    dopts.setPubdate(new Date());
    dopts.setResolveId("resolveid");
    String pubrev = "1";
    String deliveryPattern = "build/test/deliver/assembly-[revision].xml";
    ivy.deliver(pubrev, deliveryPattern, dopts);
    // now check that the resolve report has the same info as the delivered descriptor
    File deliveredIvyFile = new File("build/test/deliver/assembly-1.xml");
    assertTrue(deliveredIvyFile.exists());
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(ivy.getSettings(), deliveredIvyFile.toURI().toURL(), false);
    DependencyDescriptor[] dds = md.getDependencies();
    assertEquals(2, dds.length);
    assertEquals(ModuleRevisionId.newInstance("myorg", "modB", "releasebranch", "1"), dds[1].getDependencyRevisionId());
    assertEquals(ModuleRevisionId.newInstance("myorg", "modA", "trunk", "5"), dds[0].getDependencyRevisionId());
}
Also used : DeliverOptions(org.apache.ivy.core.deliver.DeliverOptions) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) JarFile(java.util.jar.JarFile) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 19 with DependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyDescriptor in project ant-ivy by apache.

the class ResolveTest method testIVY1159_orderIsModBModAReplaceForced.

/**
 * Test case for IVY-1159.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1159">IVY-1159</a>
 */
@Test
public void testIVY1159_orderIsModBModAReplaceForced() throws Exception {
    testIVY1159("ivy-depsorder_modB_then_modA.xml", true);
    File deliveredIvyFile = new File("build/test/deliver/ivy-1.xml");
    assertTrue(deliveredIvyFile.exists());
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(ivy.getSettings(), deliveredIvyFile.toURI().toURL(), false);
    DependencyDescriptor[] dds = md.getDependencies();
    assertEquals(2, dds.length);
    assertEquals(ModuleRevisionId.newInstance("myorg", "modB", "1"), dds[0].getDependencyRevisionId());
    assertEquals(ModuleRevisionId.newInstance("myorg", "modA", "1"), dds[1].getDependencyRevisionId());
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Example 20 with DependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyDescriptor in project ant-ivy by apache.

the class PomModuleDescriptorParserTest method testDependenciesWithScope.

@Test
public void testDependenciesWithScope() throws Exception {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-dependencies-with-scope.pom"), false);
    assertNotNull(md);
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"), md.getModuleRevisionId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(3, dds.length);
    assertEquals(ModuleRevisionId.newInstance("odmg", "odmg", "3.0"), dds[0].getDependencyRevisionId());
    assertEquals(new HashSet<>(Collections.singletonList("runtime")), new HashSet<>(Arrays.asList(dds[0].getModuleConfigurations())));
    assertEquals(new HashSet<>(Arrays.asList("compile(*)", "runtime(*)", "master(*)")), new HashSet<>(Arrays.asList(dds[0].getDependencyConfigurations("runtime"))));
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), dds[1].getDependencyRevisionId());
    assertEquals(new HashSet<>(Arrays.asList("compile", "runtime")), new HashSet<>(Arrays.asList(dds[1].getModuleConfigurations())));
    assertEquals(new HashSet<>(Arrays.asList("master(*)", "compile(*)")), new HashSet<>(Arrays.asList(dds[1].getDependencyConfigurations("compile"))));
    assertEquals(new HashSet<>(Collections.singletonList("runtime(*)")), new HashSet<>(Arrays.asList(dds[1].getDependencyConfigurations("runtime"))));
    assertEquals(ModuleRevisionId.newInstance("cglib", "cglib", "2.0.2"), dds[2].getDependencyRevisionId());
    assertEquals(new HashSet<>(Arrays.asList("compile", "runtime")), new HashSet<>(Arrays.asList(dds[2].getModuleConfigurations())));
    assertEquals(new HashSet<>(Arrays.asList("master(*)", "compile(*)")), new HashSet<>(Arrays.asList(dds[2].getDependencyConfigurations("compile"))));
    assertEquals(new HashSet<>(Collections.singletonList("runtime(*)")), new HashSet<>(Arrays.asList(dds[2].getDependencyConfigurations("runtime"))));
}
Also used : DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) XmlModuleDescriptorParserTest(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest) Test(org.junit.Test)

Aggregations

DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)101 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)80 Test (org.junit.Test)75 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)35 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)33 File (java.io.File)26 XmlModuleDescriptorParserTest (org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest)26 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)25 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)18 IvySettings (org.apache.ivy.core.settings.IvySettings)17 Configuration (org.apache.ivy.core.module.descriptor.Configuration)15 Artifact (org.apache.ivy.core.module.descriptor.Artifact)13 ParseException (java.text.ParseException)12 IOException (java.io.IOException)11 ResolveData (org.apache.ivy.core.resolve.ResolveData)11 MockResolver (org.apache.ivy.plugins.resolver.MockResolver)9 JarFile (java.util.jar.JarFile)7 GregorianCalendar (java.util.GregorianCalendar)6 ModuleId (org.apache.ivy.core.module.id.ModuleId)6 ResolveReport (org.apache.ivy.core.report.ResolveReport)6