Search in sources :

Example 1 with EndResolveDependencyEvent

use of org.apache.ivy.core.event.resolve.EndResolveDependencyEvent 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)

Aggregations

EndResolveDependencyEvent (org.apache.ivy.core.event.resolve.EndResolveDependencyEvent)1 StartResolveDependencyEvent (org.apache.ivy.core.event.resolve.StartResolveDependencyEvent)1 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)1 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)1 DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)1