Examples of IvyContext


Examples of org.apache.ivy.core.IvyContext

    public ResolvedModuleRevision getDependency(DependencyDescriptor dde, ResolveData data) {
        if (dde.getExtraAttribute(ClientModule.CLIENT_MODULE_KEY) == null) {
            return null;
        }

        IvyContext context = IvyContext.pushNewCopyContext();
        try {
            context.setDependencyDescriptor(dde);
            context.setResolveData(data);
            DefaultModuleDescriptor moduleDescriptor =
                    (DefaultModuleDescriptor) moduleRegistry.get(dde.getExtraAttribute(ClientModule.CLIENT_MODULE_KEY));
            MetadataArtifactDownloadReport downloadReport = new MetadataArtifactDownloadReport(moduleDescriptor.getMetadataArtifact());
            downloadReport.setDownloadStatus(DownloadStatus.NO);
            downloadReport.setSearched(false);
View Full Code Here

Examples of org.apache.ivy.core.IvyContext

        ModuleDescriptor moduleDescriptor = findProject(dd);
        if (moduleDescriptor == null) {
            return data.getCurrentResolvedModuleRevision();
        }

        IvyContext context = IvyContext.pushNewCopyContext();
        try {
            context.setDependencyDescriptor(dd);
            context.setResolveData(data);
            MetadataArtifactDownloadReport downloadReport = new MetadataArtifactDownloadReport(moduleDescriptor.getMetadataArtifact());
            downloadReport.setDownloadStatus(DownloadStatus.NO);
            downloadReport.setSearched(false);
            return new ResolvedModuleRevision(this, this, moduleDescriptor, downloadReport);
        } finally {
View Full Code Here

Examples of org.apache.ivy.core.IvyContext

     * Resolve dependencies of a module described by a module descriptor.
     */
    public ResolveReport resolve(ModuleDescriptor md, ResolveOptions options)
            throws ParseException, IOException {
        DependencyResolver oldDictator = getDictatorResolver();
        IvyContext context = IvyContext.getContext();
        try {
            String[] confs = options.getConfs(md);
            options.setConfs(confs);

            if (options.getResolveId() == null) {
                options.setResolveId(ResolveOptions.getDefaultResolveId(md));
            }

            eventManager.fireIvyEvent(new StartResolveEvent(md, confs));

            long start = System.currentTimeMillis();
            if (ResolveOptions.LOG_DEFAULT.equals(options.getLog())) {
                Message.info(":: resolving dependencies :: " + md.getResolvedModuleRevisionId()
                        + (options.isTransitive() ? "" : " [not transitive]"));
                Message.info("\tconfs: " + Arrays.asList(confs));
            } else {
                Message.verbose(":: resolving dependencies :: " + md.getResolvedModuleRevisionId()
                        + (options.isTransitive() ? "" : " [not transitive]"));
                Message.verbose("\tconfs: " + Arrays.asList(confs));
            }
            Message.verbose("\tvalidate = " + options.isValidate());
            Message.verbose("\trefresh = " + options.isRefresh());

            ResolveReport report = new ResolveReport(md, options.getResolveId());

            ResolveData data = new ResolveData(this, options);
            context.setResolveData(data);

            // resolve dependencies
            IvyNode[] dependencies = getDependencies(md, options, report);
            report.setDependencies(Arrays.asList(dependencies), options.getArtifactFilter());

            if (options.getCheckIfChanged()) {
                report.checkIfChanged();
            }

            // produce resolved ivy file and ivy properties in cache
            ResolutionCacheManager cacheManager = settings.getResolutionCacheManager();
            cacheManager.saveResolvedModuleDescriptor(md);

            // we store the resolved dependencies revisions and statuses per asked dependency
            // revision id, for direct dependencies only.
            // this is used by the deliver task to resolve dynamic revisions to static ones
            File ivyPropertiesInCache = cacheManager.getResolvedIvyPropertiesInCache(md
                    .getResolvedModuleRevisionId());
            Properties props = new Properties();
            if (dependencies.length > 0) {
                Map forcedRevisions = new HashMap();
                for (int i = 0; i < dependencies.length; i++) {
                    if (dependencies[i].getModuleRevision() != null
                            && dependencies[i].getModuleRevision().isForce()) {
                        forcedRevisions.put(dependencies[i].getModuleId(),
                            dependencies[i].getResolvedId());
                    }
                }

                IvyNode root = dependencies[0].getRoot();

                // <ModuleId,IvyNode>();
                Map topLevelDeps = new HashMap(); //
                for (int i = 0; i < dependencies.length; i++) {
                    if (!dependencies[i].hasProblem()) {
                        DependencyDescriptor dd = dependencies[i].getDependencyDescriptor(root);
                        if (dd != null) {
                            ModuleId orgMod = dependencies[i].getModuleId();
                            topLevelDeps.put(orgMod, dependencies[i]);
                        }
                    }
                }

                for (int i = 0; i < dependencies.length; i++) {
                    if (!dependencies[i].hasProblem() && !dependencies[i].isCompletelyEvicted()) {
                        DependencyDescriptor dd = dependencies[i].getDependencyDescriptor(root);
                        if (dd == null) {
                            ModuleId mid = dependencies[i].getModuleId();
                            IvyNode tlDep = (IvyNode) topLevelDeps.get(mid);
                            if (tlDep != null) {
                                dd = tlDep.getDependencyDescriptor(root);
                            }
                        }
                        if (dd != null) {
                            ModuleRevisionId depResolvedId = dependencies[i].getResolvedId();
                            ModuleDescriptor depDescriptor = dependencies[i].getDescriptor();
                            ModuleRevisionId depRevisionId = dd.getDependencyRevisionId();
                            ModuleRevisionId forcedRevisionId = (ModuleRevisionId) forcedRevisions
                                    .get(dependencies[i].getModuleId());

                            if (dependencies[i].getModuleRevision() != null
                                    && dependencies[i].getModuleRevision().isForce()
                                    && !depResolvedId.equals(depRevisionId)
                                    && !settings.getVersionMatcher().isDynamic(depRevisionId)) {
                                // if we were forced to this revision and we
                                // are not a dynamic revision, reset to the
                                // asked revision
                                depResolvedId = depRevisionId;
                                depDescriptor = null;
                            }

                            if (depResolvedId == null) {
                                throw new NullPointerException("getResolvedId() is null for "
                                        + dependencies[i].toString());
                            }
                            if (depRevisionId == null) {
                                throw new NullPointerException("getDependencyRevisionId() "
                                        + "is null for " + dd.toString());
                            }
                            String rev = depResolvedId.getRevision();
                            String forcedRev = forcedRevisionId == null ? rev : forcedRevisionId
                                    .getRevision();

                            // The evicted modules have no description, so we can't put the status
                            String status = depDescriptor == null ? "?" : depDescriptor.getStatus();
                            Message.debug("storing dependency " + depResolvedId + " in props");
                            props.put(depRevisionId.encodeToString(), rev + " " + status + " "
                                    + forcedRev + " " + depResolvedId.getBranch());
                        }
                    }
                }
            }
            FileOutputStream out = new FileOutputStream(ivyPropertiesInCache);
            props.store(out, md.getResolvedModuleRevisionId() + " resolved revisions");
            out.close();
            Message.verbose("\tresolved ivy file produced in cache");

            report.setResolveTime(System.currentTimeMillis() - start);

            if (options.isDownload()) {
                Message.verbose(":: downloading artifacts ::");

                DownloadOptions downloadOptions = new DownloadOptions();
                downloadOptions.setLog(options.getLog());
                downloadArtifacts(report, options.getArtifactFilter(), downloadOptions);
            }

            if (options.isOutputReport()) {
                outputReport(report, cacheManager, options);
            }

            Message.verbose("\tresolve done (" + report.getResolveTime() + "ms resolve - "
                    + report.getDownloadTime() + "ms download)");
            Message.sumupProblems();

            eventManager.fireIvyEvent(new EndResolveEvent(md, confs, report));
            return report;
        } catch (RuntimeException ex) {
            Message.debug(ex);
            Message.error(ex.getMessage());
            Message.sumupProblems();
            throw ex;
        } finally {
            context.setResolveData(null);
            setDictatorResolver(oldDictator);
        }
    }
View Full Code Here

Examples of org.apache.ivy.core.IvyContext

            throw new IllegalArgumentException("requested configuration"
                    + (missingConfs.size() > 1 ? "s" : "") + " not found in "
                    + md.getModuleRevisionId() + ": " + missingConfs);
        }

        IvyContext context = IvyContext.pushNewCopyContext();
        try {
            options.setConfs(confs);

            Date reportDate = new Date();
            ResolveData data = context.getResolveData();
            if (data == null) {
                data = new ResolveData(this, options);
                context.setResolveData(data);
            }
            IvyNode rootNode = new IvyNode(data, md);

            for (int i = 0; i < confs.length; i++) {
                Message.verbose("resolving dependencies for configuration '" + confs[i] + "'");
View Full Code Here

Examples of org.apache.ivy.core.IvyContext

         * empty (not computed yet) and we aren't in the context of the direct parent of the node.
         */
        if (evictedInSelected
                || (selectedNodes.isEmpty() && !node.getParent().getNode()
                        .equals(ancestor.getNode()))) {
            IvyContext context = IvyContext.getContext();
            ResolveData data = context.getResolveData();
            VisitNode oldVisitNode = data.getCurrentVisitNode();
            data.setCurrentVisitNode(ancestor);
            try {
                // In this case we need to compute selected nodes again.
                Collection deps = ancestor.getNode().getDependencies(node.getRootModuleConf(),
View Full Code Here

Examples of org.apache.ivy.core.IvyContext

    private ModuleRevisionId(ModuleId moduleId, String branch, String revision,
            Map extraAttributes, boolean replaceNullBranchWithDefault) {
        super(null, extraAttributes);
        this.moduleId = moduleId;
        IvyContext context = IvyContext.getContext();
        this.branch = (replaceNullBranchWithDefault && branch == null)
        // we test if there's already an Ivy instance loaded, to avoid loading a default one
        // just to get the default branch
        ? (context.peekIvy() == null ? null : context.getSettings().getDefaultBranch(moduleId))
                : branch;
        this.revision = revision == null ? Ivy.getWorkingRevision() : normalizeRevision(revision);
        setStandardAttribute(IvyPatternHelper.ORGANISATION_KEY, this.moduleId.getOrganisation());
        setStandardAttribute(IvyPatternHelper.MODULE_KEY, this.moduleId.getName());
        setStandardAttribute(IvyPatternHelper.BRANCH_KEY, this.branch);
View Full Code Here

Examples of org.apache.ivy.core.IvyContext

        this.envDependent = envDependent;
    }

    public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
            throws ParseException {
        IvyContext context = IvyContext.pushNewCopyContext();
        try {
            ResolvedModuleRevision mr = data.getCurrentResolvedModuleRevision();
            if (mr != null) {
                if (shouldReturnResolvedModule(dd, mr)) {
                    return mr;
                }
            }

            if (isForce()) {
                dd = dd.clone(ModuleRevisionId.newInstance(dd.getDependencyRevisionId(),
                    "latest.integration"));
            }
            DependencyDescriptor systemDd = dd;
            DependencyDescriptor nsDd = fromSystem(dd);
            context.setDependencyDescriptor(systemDd);
            context.setResolveData(data);

            clearIvyAttempts();
            clearArtifactAttempts();
            ModuleRevisionId systemMrid = systemDd.getDependencyRevisionId();
            ModuleRevisionId nsMrid = nsDd.getDependencyRevisionId();
View Full Code Here

Examples of org.apache.ivy.core.IvyContext

        ResolvedResource found = null;
        List sorted = getLatestStrategy().sort(rress);
        List rejected = new ArrayList();
        List foundBlacklisted = new ArrayList();
        IvyContext context = IvyContext.getContext();

        for (ListIterator iter = sorted.listIterator(sorted.size()); iter.hasPrevious();) {
            ResolvedResource rres = (ResolvedResource) iter.previous();
            // we start by filtering based on information already available,
            // even though we don't even know if the resource actually exist.
            // But checking for existence is most of the time more costly than checking
            // name, blacklisting and first level version matching
            if (filterNames(new ArrayList(Collections.singleton(rres.getRevision()))).isEmpty()) {
                Message.debug("\t" + name + ": filtered by name: " + rres);
                continue;
            }
            ModuleRevisionId foundMrid = ModuleRevisionId.newInstance(mrid, rres.getRevision());

            ResolveData data = context.getResolveData();
            if (data != null && data.getReport() != null
                    && data.isBlacklisted(data.getReport().getConfiguration(), foundMrid)) {
                Message.debug("\t" + name + ": blacklisted: " + rres);
                rejected.add(rres.getRevision() + " (blacklisted)");
                foundBlacklisted.add(foundMrid);
                continue;
            }

            if (!versionMatcher.accept(mrid, foundMrid)) {
                Message.debug("\t" + name + ": rejected by version matcher: " + rres);
                rejected.add(rres.getRevision());
                continue;
            }
            if (rres.getResource() != null && !rres.getResource().exists()) {
                Message.debug("\t" + name + ": unreachable: " + rres + "; res="
                        + rres.getResource());
                rejected.add(rres.getRevision() + " (unreachable)");
                continue;
            }
            if ((date != null && rres.getLastModified() > date.getTime())) {
                Message.verbose("\t" + name + ": too young: " + rres);
                rejected.add(rres.getRevision() + " (" + rres.getLastModified() + ")");
                continue;
            }
            if (versionMatcher.needModuleDescriptor(mrid, foundMrid)) {
                ResolvedResource r = rmdparser.parse(rres.getResource(), rres.getRevision());
                if (r == null) {
                    Message.debug("\t" + name + ": impossible to get module descriptor resource: "
                            + rres);
                    rejected.add(rres.getRevision() + " (no or bad MD)");
                    continue;
                }
                ModuleDescriptor md = ((MDResolvedResource) r).getResolvedModuleRevision()
                        .getDescriptor();
                if (md.isDefault()) {
                    Message.debug("\t" + name + ": default md rejected by version matcher"
                            + "requiring module descriptor: " + rres);
                    rejected.add(rres.getRevision() + " (MD)");
                    continue;
                } else if (!versionMatcher.accept(mrid, md)) {
                    Message.debug("\t" + name + ": md rejected by version matcher: " + rres);
                    rejected.add(rres.getRevision() + " (MD)");
                    continue;
                } else {
                    found = r;
                }
            } else {
                found = rres;
            }

            if (found != null) {
                break;
            }
        }
        if (found == null && !rejected.isEmpty()) {
            logAttempt(rejected.toString());
        }
        if (found == null && !foundBlacklisted.isEmpty()) {
            // all acceptable versions have been blacklisted, this means that an unsolvable conflict
            // has been found
            DependencyDescriptor dd = context.getDependencyDescriptor();
            IvyNode parentNode = context.getResolveData().getNode(dd.getParentRevisionId());
            ConflictManager cm = parentNode.getConflictManager(mrid.getModuleId());
            cm.handleAllBlacklistedRevisions(dd, foundBlacklisted);
        }

        return found;
View Full Code Here

Examples of org.apache.ivy.core.IvyContext

        ignoreVersionOnWorkspaceProjects = IvyPlugin.getPreferenceStoreHelper()
                .getIgnoreVersionOnWorkspaceProjects();
    }

    public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
        IvyContext context = IvyContext.getContext();
        Map/* <Artifact, Artifact> */workspaceArtifacts = (Map) context
                .get(IVYDE_WORKSPACE_ARTIFACTS);
        Map/* <String, ArtifactDownloadReport> */workspaceReports = null;
        if (workspaceArtifacts != null) {
            workspaceReports = new HashMap();
            context.set(IVYDE_WORKSPACE_ARTIFACT_REPORTS, workspaceReports);
        }

        // Not much to do here - downloads are not required for workspace projects.
        DownloadReport dr = new DownloadReport();
        for (int i = 0; i < artifacts.length; i++) {
View Full Code Here

Examples of org.apache.ivy.core.IvyContext

        return dr;
    }

    public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
            throws ParseException {
        IvyContext context = IvyContext.getContext();

        String contextId = "ivyde.workspaceresolver." + getName() + "." + dd.getDependencyRevisionId().toString();
        DependencyDescriptor parentDD = (DependencyDescriptor) context.get(contextId);
        if (parentDD != null && parentDD.getDependencyRevisionId().equals(dd.getDependencyRevisionId())) {
            // this very workspace resolver has been already called for the same dependency
            // we are going into a circular dependency, let's return 'not found'
            return null;
        }
        context.set(contextId, dd);

        ModuleRevisionId dependencyMrid = dd.getDependencyRevisionId();

        VersionMatcher versionMatcher = getSettings().getVersionMatcher();

        // Iterate over workspace to find Java project which has an Ivy
        // container for this dependency
        for (int i = 0; i < projects.length; i++) {
            IProject p = projects[i];
            if (!p.exists()) {
                continue;
            }
            List/* <IvyClasspathContainer> */containers = IvyClasspathContainerHelper
                    .getContainers(p);
            Iterator/* <IvyClasspathContainer> */itContainer = containers.iterator();
            while (itContainer.hasNext()) {
                IvyClasspathContainerImpl ivycp = (IvyClasspathContainerImpl) itContainer.next();
                ModuleDescriptor md = ivycp.getState().getCachedModuleDescriptor();
                if (md == null) {
                    continue;
                }

                ModuleRevisionId candidateMrid = md.getModuleRevisionId();

                if (!candidateMrid.getModuleId().equals(dependencyMrid.getModuleId())) {
                    // it doesn't match org#module
                    continue;
                }

                IvyDEMessage.verbose("Workspace resolver found potential matching project "
                        + p.getName() + " with module " + candidateMrid + " for module "
                        + dependencyMrid);

                if (!ignoreBranchOnWorkspaceProjects) {
                    ModuleId mid = dependencyMrid.getModuleId();
                    String defaultBranch = getSettings().getDefaultBranch(mid);
                    String dependencyBranch = dependencyMrid.getBranch();
                    String candidateBranch = candidateMrid.getBranch();
                    if (dependencyBranch == null) {
                        dependencyBranch = defaultBranch;
                    }
                    if (candidateBranch == null) {
                        candidateBranch = defaultBranch;
                    }
                    if (dependencyBranch != candidateBranch) {
                        // Both cannot be null
                        if (dependencyBranch == null || candidateBranch == null) {
                            IvyDEMessage.verbose("\t\trejected since branches doesn't match (one is set, the other isn't)");
                            continue;
                        }
                        if (!dependencyBranch.equals(candidateBranch)) {
                            IvyDEMessage.verbose("\t\trejected since branches doesn't match");
                            continue;
                        }
                    }
                }

                // Found one; check if it is for the module we need
                if (ignoreVersionOnWorkspaceProjects
                        || md.getModuleRevisionId().getRevision().equals(Ivy.getWorkingRevision())
                        || versionMatcher.accept(dd.getDependencyRevisionId(), md)) {

                    if (ignoreVersionOnWorkspaceProjects) {
                        IvyDEMessage.verbose("\t\tmatched (version are ignored)");
                    } else {
                        IvyDEMessage.verbose("\t\tversion matched");
                    }

                    Artifact af = new DefaultArtifact(md.getModuleRevisionId(),
                            md.getPublicationDate(), p.getFullPath().toString(),
                            ECLIPSE_PROJECT_TYPE, ECLIPSE_PROJECT_EXTENSION);

                    DependencyArtifactDescriptor[] dArtifacts = dd.getAllDependencyArtifacts();
                    if (dArtifacts != null) {
                        // the dependency is declaring explicitely some artifacts to download
                        // we need to trick to and map these requested artifact by the Eclipse
                        // project

                        // we need the context which is used when downloading data, which is the
                        // parent
                        // of the current one
                        // so let's hack: popContext (the child), getContext (the parent), setVar,
                        // pushContext (child)
                        IvyContext currentContext = IvyContext.popContext();
                        IvyContext parentContext = IvyContext.getContext();
                        Map/* <Artifact, Artifact> */workspaceArtifacts = (Map) parentContext
                                .get(IVYDE_WORKSPACE_ARTIFACTS);
                        if (workspaceArtifacts == null) {
                            workspaceArtifacts = new HashMap();
                            parentContext.set(IVYDE_WORKSPACE_ARTIFACTS, workspaceArtifacts);
                        }
                        for (int j = 0; j < dArtifacts.length; j++) {
                            Artifact artifact = new MDArtifact(md, dArtifacts[j].getName(),
                                    dArtifacts[j].getType(), dArtifacts[j].getExt(),
                                    dArtifacts[j].getUrl(),
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.