Search in sources :

Example 31 with DependencyResolver

use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.

the class IvyNode method loadData.

/**
 * After the call node may be discarded. To avoid using discarded node, make sure to get the
 * real node after the call
 * <code>IvyNode node = ... node.loadData(); node = node.getRealNode(); ...</code>
 *
 * @param rootModuleConf String
 * @param parent IvyNode
 * @param parentConf String
 * @param conf String
 * @param shouldBePublic boolean
 * @param usage IvyNodeUsage
 * @return boolean
 */
public boolean loadData(String rootModuleConf, IvyNode parent, String parentConf, String conf, boolean shouldBePublic, IvyNodeUsage usage) {
    Message.debug("loadData of " + this.toString() + " of rootConf=" + rootModuleConf);
    if (!isRoot() && (data.getReport() != null)) {
        data.getReport().addDependency(this);
    }
    boolean loaded = false;
    if (hasProblem()) {
        Message.debug("Node has problem.  Skip loading");
    } else if (isEvicted(rootModuleConf)) {
        Message.debug(rootModuleConf + " is evicted.  Skip loading");
    } else if (!hasConfigurationsToLoad() && isRootModuleConfLoaded(rootModuleConf)) {
        Message.debug(rootModuleConf + " is loaded and no conf to load.  Skip loading");
    } else {
        markRootModuleConfLoaded(rootModuleConf);
        if (md == null) {
            DependencyResolver resolver = data.getSettings().getResolver(getId());
            if (resolver == null) {
                Message.error("no resolver found for " + getModuleId() + ": check your configuration");
                problem = new RuntimeException("no resolver found for " + getModuleId() + ": check your configuration");
                return false;
            }
            try {
                Message.debug("\tusing " + resolver + " to resolve " + getId());
                DependencyDescriptor dependencyDescriptor = getDependencyDescriptor(parent);
                long start = System.currentTimeMillis();
                ModuleRevisionId requestedRevisionId = dependencyDescriptor.getDependencyRevisionId();
                data.getEventManager().fireIvyEvent(new StartResolveDependencyEvent(resolver, dependencyDescriptor, requestedRevisionId));
                module = resolver.getDependency(dependencyDescriptor, data);
                data.getEventManager().fireIvyEvent(new EndResolveDependencyEvent(resolver, dependencyDescriptor, requestedRevisionId, module, System.currentTimeMillis() - start));
                if (module != null) {
                    module.getResolver().getRepositoryCacheManager().saveResolvers(module.getDescriptor(), module.getResolver().getName(), module.getArtifactResolver().getName());
                    if (settings.logModuleWhenFound() && LogOptions.LOG_DEFAULT.equals(getData().getOptions().getLog())) {
                        Message.info("\tfound " + module.getId() + " in " + module.getResolver().getName());
                    } else {
                        Message.verbose("\tfound " + module.getId() + " in " + module.getResolver().getName());
                    }
                    // IVY-56: check if revision has actually been resolved
                    if (settings.getVersionMatcher().isDynamic(getId()) && settings.getVersionMatcher().isDynamic(module.getId())) {
                        Message.error("impossible to resolve dynamic revision for " + getId() + ": check your configuration and make sure revision is part of your pattern");
                        problem = new RuntimeException("impossible to resolve dynamic revision");
                        return false;
                    }
                    if (!getId().equals(module.getId())) {
                        IvyNode resolved = data.getNode(module.getId());
                        if (resolved != null) {
                            // found revision has already been resolved
                            // => update it and discard this node
                            // needed for handleConfiguration
                            md = module.getDescriptor();
                            if (!handleConfiguration(loaded, rootModuleConf, parent, parentConf, conf, shouldBePublic, usage)) {
                                return false;
                            }
                            moveToRealNode(rootModuleConf, parent, parentConf, conf, shouldBePublic, resolved);
                            return true;
                        }
                        String log = "\t[" + module.getId().getRevision() + "] " + getId();
                        if (!settings.getVersionMatcher().isDynamic(getId())) {
                            log += " (forced)";
                        }
                        if (settings.logResolvedRevision() && LogOptions.LOG_DEFAULT.equals(getData().getOptions().getLog())) {
                            Message.info(log);
                        } else {
                            Message.verbose(log);
                        }
                    }
                    downloaded = module.getReport().isDownloaded();
                    searched = module.getReport().isSearched();
                    loaded = true;
                    md = module.getDescriptor();
                    confsToFetch.remove("*");
                    updateConfsToFetch(Arrays.asList(resolveSpecialConfigurations(getRequiredConfigurations(parent, parentConf))));
                } else {
                    Message.warn("\tmodule not found: " + getId());
                    resolver.reportFailure();
                    problem = new RuntimeException("not found");
                    return false;
                }
            } catch (ResolveProcessException e) {
                throw e;
            } catch (Exception e) {
                problem = e;
                Message.debug("Unexpected error: " + problem.getMessage(), problem);
                return false;
            }
        } else {
            loaded = true;
        }
    }
    handleConfiguration(loaded, rootModuleConf, parent, parentConf, conf, shouldBePublic, usage);
    if (hasProblem()) {
        Message.debug("problem : " + problem.getMessage());
        return false;
    }
    DependencyDescriptor dd = getDependencyDescriptor(parent);
    if (dd != null) {
        usage.addUsage(rootModuleConf, dd, parentConf);
    }
    return loaded;
}
Also used : DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) StartResolveDependencyEvent(org.apache.ivy.core.event.resolve.StartResolveDependencyEvent) EndResolveDependencyEvent(org.apache.ivy.core.event.resolve.EndResolveDependencyEvent) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 32 with DependencyResolver

use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.

the class ResolveTest method testResolveDualChain.

@Test
public void testResolveDualChain() throws Exception {
    Ivy ivy = new Ivy();
    ivy.configure(ResolveTest.class.getResource("dualchainresolverconf.xml"));
    DependencyResolver resolver = ivy.getSettings().getResolver("default");
    assertNotNull(resolver);
    assertTrue(resolver instanceof DualResolver);
    // first without cache
    ivy.resolve(ResolveTest.class.getResource("ivy-dualchainresolver.xml"), getResolveOptions(new String[] { "default" }));
    assertTrue(new File("build/cache/xerces/xerces/ivy-2.6.2.xml").exists());
    assertTrue(new File("build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar").exists());
    assertTrue(new File("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar").exists());
    // second with cache for ivy file only
    new File("build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar").delete();
    new File("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar").delete();
    assertFalse(new File("build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar").exists());
    assertFalse(new File("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar").exists());
    ivy.resolve(ResolveTest.class.getResource("ivy-dualchainresolver.xml"), getResolveOptions(new String[] { "default" }));
    assertTrue(new File("build/cache/xerces/xerces/ivy-2.6.2.xml").exists());
    assertTrue(new File("build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar").exists());
    assertTrue(new File("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar").exists());
}
Also used : DualResolver(org.apache.ivy.plugins.resolver.DualResolver) Ivy(org.apache.ivy.Ivy) JarFile(java.util.jar.JarFile) File(java.io.File) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) Test(org.junit.Test)

Example 33 with DependencyResolver

use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.

the class ConfigureTest method testTypedefWithCustomClasspath.

@Test
public void testTypedefWithCustomClasspath() throws Exception {
    Ivy ivy = new Ivy();
    ivy.setVariable("ivy.custom.test.dir", new File("test/java/org/apache/ivy/core/settings").toURI().toURL().toString());
    ivy.configure(ConfigureTest.class.getResource("ivysettings-custom-typedef.xml"));
    DependencyResolver custom = ivy.getSettings().getResolver("custom");
    assertNotNull(custom);
    assertEquals("org.apache.ivy.plugins.resolver.CustomResolver", custom.getClass().getName());
}
Also used : Ivy(org.apache.ivy.Ivy) File(java.io.File) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) Test(org.junit.Test)

Example 34 with DependencyResolver

use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.

the class ConfigureTest method testDefault14.

@Test
public void testDefault14() throws ParseException, IOException {
    Ivy ivy = new Ivy();
    ivy.configureDefault14();
    IvySettings settings = ivy.getSettings();
    assertNotNull(settings.getDefaultResolver());
    DependencyResolver publicResolver = settings.getResolver("public");
    assertTrue(publicResolver instanceof IvyRepResolver);
}
Also used : Ivy(org.apache.ivy.Ivy) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) IvyRepResolver(org.apache.ivy.plugins.resolver.IvyRepResolver) Test(org.junit.Test)

Example 35 with DependencyResolver

use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.

the class ConfigureTest method testDefault.

@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());
}
Also used : IBiblioResolver(org.apache.ivy.plugins.resolver.IBiblioResolver) Ivy(org.apache.ivy.Ivy) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) Test(org.junit.Test)

Aggregations

DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)50 Test (org.junit.Test)23 ModuleDescriptorParserRegistryTest (org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)11 ChainResolver (org.apache.ivy.plugins.resolver.ChainResolver)11 File (java.io.File)10 Ivy (org.apache.ivy.Ivy)9 HashMap (java.util.HashMap)8 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)8 URL (java.net.URL)7 HashSet (java.util.HashSet)7 Map (java.util.Map)7 LinkedHashSet (java.util.LinkedHashSet)6 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)6 IvySettings (org.apache.ivy.core.settings.IvySettings)6 FileSystemResolver (org.apache.ivy.plugins.resolver.FileSystemResolver)6 ParseException (java.text.ParseException)5 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)5 IvyRepResolver (org.apache.ivy.plugins.resolver.IvyRepResolver)5 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)4 ModuleId (org.apache.ivy.core.module.id.ModuleId)4