Search in sources :

Example 21 with ResolveData

use of org.apache.ivy.core.resolve.ResolveData in project ant-ivy by apache.

the class WarnCircularDependencyStrategyTest method setResolveContext.

private void setResolveContext(String resolveId) {
    IvySettings settings = new IvySettings();
    IvyContext.getContext().setResolveData(new ResolveData(new ResolveEngine(settings, new EventManager(), new SortEngine(settings)), new ResolveOptions().setResolveId(resolveId)));
}
Also used : ResolveEngine(org.apache.ivy.core.resolve.ResolveEngine) ResolveData(org.apache.ivy.core.resolve.ResolveData) SortEngine(org.apache.ivy.core.sort.SortEngine) EventManager(org.apache.ivy.core.event.EventManager) IvySettings(org.apache.ivy.core.settings.IvySettings) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions)

Example 22 with ResolveData

use of org.apache.ivy.core.resolve.ResolveData in project ant-ivy by apache.

the class CheckEngine method check.

/**
 * Checks the given ivy file using current settings to see if all dependencies are available,
 * with good confs. If a resolver name is given, it also checks that the declared publications
 * are available in the corresponding resolver. Note that the check is not performed
 * recursively, i.e. if a dependency has itself dependencies badly described or not available,
 * this check will not discover it.
 *
 * @param ivyFile URL
 * @param resolvername String
 * @return boolean
 */
public boolean check(URL ivyFile, String resolvername) {
    try {
        boolean result = true;
        // parse ivy file
        ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor(settings, ivyFile, settings.doValidate());
        // check publications if possible
        if (resolvername != null) {
            DependencyResolver resolver = settings.getResolver(resolvername);
            Set<Artifact> artifacts = new HashSet<>();
            for (String conf : md.getConfigurationsNames()) {
                artifacts.addAll(Arrays.asList(md.getArtifacts(conf)));
            }
            for (Artifact artifact : artifacts) {
                if (!resolver.exists(artifact)) {
                    Message.info("declared publication not found: " + artifact);
                    result = false;
                }
            }
        }
        // check dependencies
        ResolveData data = new ResolveData(resolveEngine, new ResolveOptions());
        for (DependencyDescriptor dd : md.getDependencies()) {
            // check master confs
            for (String masterConf : dd.getModuleConfigurations()) {
                if (!"*".equals(masterConf.trim()) && md.getConfiguration(masterConf) == null) {
                    Message.info("dependency required in non existing conf for " + ivyFile + " \n\tin " + dd + ": " + masterConf);
                    result = false;
                }
            }
            // resolve
            DependencyResolver resolver = settings.getResolver(dd.getDependencyRevisionId());
            ResolvedModuleRevision rmr = resolver.getDependency(dd, data);
            if (rmr == null) {
                Message.info("dependency not found in " + ivyFile + ":\n\t" + dd);
                result = false;
            } else {
                for (String depConf : dd.getDependencyConfigurations(md.getConfigurationsNames())) {
                    if (!Arrays.asList(rmr.getDescriptor().getConfigurationsNames()).contains(depConf)) {
                        Message.info("dependency configuration is missing for " + ivyFile + "\n\tin " + dd + ": " + depConf);
                        result = false;
                    }
                    for (Artifact art : rmr.getDescriptor().getArtifacts(depConf)) {
                        if (!resolver.exists(art)) {
                            Message.info("dependency artifact is missing for " + ivyFile + "\n\t in " + dd + ": " + art);
                            result = false;
                        }
                    }
                }
            }
        }
        return result;
    } catch (ParseException e) {
        Message.info("parse problem on " + ivyFile, e);
        return false;
    } catch (IOException e) {
        Message.info("io problem on " + ivyFile, e);
        return false;
    } catch (Exception e) {
        Message.info("problem on " + ivyFile, e);
        return false;
    }
}
Also used : DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) IOException(java.io.IOException) Artifact(org.apache.ivy.core.module.descriptor.Artifact) IOException(java.io.IOException) ParseException(java.text.ParseException) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ResolveData(org.apache.ivy.core.resolve.ResolveData) ParseException(java.text.ParseException) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) HashSet(java.util.HashSet)

Example 23 with ResolveData

use of org.apache.ivy.core.resolve.ResolveData in project ant-ivy by apache.

the class Ivy method bind.

/**
 * This method is used to bind this Ivy instance to required dependencies, i.e. instance of
 * settings, engines, and so on.
 * <p>
 * After this call Ivy is still not configured, which means that the settings object is still
 * empty.
 * </p>
 */
public void bind() {
    pushContext();
    try {
        if (settings == null) {
            settings = new IvySettings();
        }
        if (eventManager == null) {
            eventManager = new EventManager();
        }
        if (sortEngine == null) {
            sortEngine = new SortEngine(settings);
        }
        if (searchEngine == null) {
            searchEngine = new SearchEngine(settings);
        }
        if (resolveEngine == null) {
            resolveEngine = new ResolveEngine(settings, eventManager, sortEngine);
        }
        if (retrieveEngine == null) {
            retrieveEngine = new RetrieveEngine(settings, eventManager);
        }
        if (deliverEngine == null) {
            deliverEngine = new DeliverEngine(settings);
        }
        if (publishEngine == null) {
            publishEngine = new PublishEngine(settings, eventManager);
        }
        if (installEngine == null) {
            installEngine = new InstallEngine(settings, searchEngine, resolveEngine);
        }
        if (repositoryEngine == null) {
            repositoryEngine = new RepositoryManagementEngine(settings, searchEngine, resolveEngine);
        }
        eventManager.addTransferListener(new TransferListener() {

            public void transferProgress(TransferEvent evt) {
                ResolveData resolve;
                switch(evt.getEventType()) {
                    case TransferEvent.TRANSFER_PROGRESS:
                        resolve = IvyContext.getContext().getResolveData();
                        if (resolve == null || !LogOptions.LOG_QUIET.equals(resolve.getOptions().getLog())) {
                            Message.progress();
                        }
                        break;
                    case TransferEvent.TRANSFER_COMPLETED:
                        resolve = IvyContext.getContext().getResolveData();
                        if (resolve == null || !LogOptions.LOG_QUIET.equals(resolve.getOptions().getLog())) {
                            Message.endProgress(" (" + (evt.getTotalLength() / KILO) + "kB)");
                        }
                        break;
                    default:
                        break;
                }
            }
        });
        bound = true;
    } finally {
        popContext();
    }
}
Also used : TransferListener(org.apache.ivy.plugins.repository.TransferListener) EventManager(org.apache.ivy.core.event.EventManager) DeliverEngine(org.apache.ivy.core.deliver.DeliverEngine) TransferEvent(org.apache.ivy.plugins.repository.TransferEvent) IvySettings(org.apache.ivy.core.settings.IvySettings) ResolveEngine(org.apache.ivy.core.resolve.ResolveEngine) RetrieveEngine(org.apache.ivy.core.retrieve.RetrieveEngine) RepositoryManagementEngine(org.apache.ivy.core.repository.RepositoryManagementEngine) SortEngine(org.apache.ivy.core.sort.SortEngine) ResolveData(org.apache.ivy.core.resolve.ResolveData) SearchEngine(org.apache.ivy.core.search.SearchEngine) PublishEngine(org.apache.ivy.core.publish.PublishEngine) InstallEngine(org.apache.ivy.core.install.InstallEngine)

Example 24 with ResolveData

use of org.apache.ivy.core.resolve.ResolveData in project ant-ivy by apache.

the class PomModuleDescriptorParserTest method testParentProperties.

@Test
public void testParentProperties() throws ParseException, IOException {
    settings.setDictatorResolver(new MockResolver() {

        public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
            try {
                ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-version.pom"), false);
                return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
            } catch (IOException e) {
                throw new AssertionError(e);
            }
        }
    });
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-parent-properties.pom"), false);
    assertNotNull(md);
    assertEquals("1.0", md.getRevision());
    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(3, dds.length);
    // 2 are inherited from parent. Only the first one is important for this test
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-version-other", "5.76"), dds[0].getDependencyRevisionId());
// present in the pom using a property defined in the parent
}
Also used : ResolveData(org.apache.ivy.core.resolve.ResolveData) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) MockResolver(org.apache.ivy.plugins.resolver.MockResolver) ParseException(java.text.ParseException) IOException(java.io.IOException) XmlModuleDescriptorParserTest(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest) Test(org.junit.Test)

Example 25 with ResolveData

use of org.apache.ivy.core.resolve.ResolveData in project ant-ivy by apache.

the class PomModuleDescriptorParserTest method testParentDependencyMgt.

@Test
public void testParentDependencyMgt() throws ParseException, IOException {
    settings.setDictatorResolver(new MockResolver() {

        public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
            try {
                ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-dependencyMgt.pom"), false);
                return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
            } catch (IOException e) {
                throw new AssertionError(e);
            }
        }
    });
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-parentDependencyMgt.pom"), false);
    assertNotNull(md);
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-parentdep", "1.0"), md.getModuleRevisionId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(2, dds.length);
    assertEquals(ModuleRevisionId.newInstance("commons-collection", "commons-collection", "1.0.5"), dds[0].getDependencyRevisionId());
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), dds[1].getDependencyRevisionId());
    ExcludeRule[] excludes = dds[0].getAllExcludeRules();
    assertNotNull(excludes);
    assertEquals(2, excludes.length);
    assertEquals("javax.mail", excludes[0].getId().getModuleId().getOrganisation());
    assertEquals("mail", excludes[0].getId().getModuleId().getName());
    assertEquals("javax.jms", excludes[1].getId().getModuleId().getOrganisation());
    assertEquals("jms", excludes[1].getId().getModuleId().getName());
}
Also used : ResolveData(org.apache.ivy.core.resolve.ResolveData) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) MockResolver(org.apache.ivy.plugins.resolver.MockResolver) ParseException(java.text.ParseException) IOException(java.io.IOException) ExcludeRule(org.apache.ivy.core.module.descriptor.ExcludeRule) XmlModuleDescriptorParserTest(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest) Test(org.junit.Test)

Aggregations

ResolveData (org.apache.ivy.core.resolve.ResolveData)33 ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)19 IvySettings (org.apache.ivy.core.settings.IvySettings)18 Before (org.junit.Before)16 ResolveEngine (org.apache.ivy.core.resolve.ResolveEngine)14 EventManager (org.apache.ivy.core.event.EventManager)13 SortEngine (org.apache.ivy.core.sort.SortEngine)13 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)11 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)11 File (java.io.File)10 IOException (java.io.IOException)10 ParseException (java.text.ParseException)10 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)10 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)9 XmlModuleDescriptorParserTest (org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest)8 MockResolver (org.apache.ivy.plugins.resolver.MockResolver)8 Test (org.junit.Test)8 Ivy (org.apache.ivy.Ivy)5 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)5 ArrayList (java.util.ArrayList)2