Search in sources :

Example 1 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class AbstractWorkspaceResolver method checkCandidate.

protected ResolvedModuleRevision checkCandidate(DependencyDescriptor dd, ModuleDescriptor md, String workspaceModuleName) {
    if (workspaceModuleName == null) {
        workspaceModuleName = dd.getDependencyId().toString();
    }
    ModuleRevisionId dependencyMrid = dd.getDependencyRevisionId();
    String org = dependencyMrid.getModuleId().getOrganisation();
    String module = dependencyMrid.getModuleId().getName();
    VersionMatcher versionMatcher = getSettings().getVersionMatcher();
    ModuleRevisionId candidateMrid = md.getModuleRevisionId();
    switch(org) {
        case BundleInfo.BUNDLE_TYPE:
            // looking for an OSGi bundle via its symbolic name
            String sn = md.getExtraInfoContentByTagName("Bundle-SymbolicName");
            if (sn == null || !module.equals(sn)) {
                // not found, skip to next
                return null;
            }
            break;
        case BundleInfo.PACKAGE_TYPE:
            // looking for an OSGi bundle via its exported package
            String exportedPackages = md.getExtraInfoContentByTagName("Export-Package");
            if (exportedPackages == null) {
                // not found, skip to next
                return null;
            }
            boolean found = false;
            String version = null;
            ManifestHeaderValue exportElements;
            try {
                exportElements = new ManifestHeaderValue(exportedPackages);
            } catch (ParseException e) {
                // wrong OSGi header: skip it
                return null;
            }
            for (ManifestHeaderElement exportElement : exportElements.getElements()) {
                if (exportElement.getValues().contains(module)) {
                    found = true;
                    version = exportElement.getAttributes().get("version");
                    break;
                }
            }
            if (!found) {
                // not found, skip to next
                return null;
            }
            if (version == null) {
                // no version means anything can match. Let's trick the version matcher by
                // setting the exact expected version
                version = dependencyMrid.getRevision();
            }
            md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(org, module, version));
            break;
        default:
            if (!candidateMrid.getModuleId().equals(dependencyMrid.getModuleId())) {
                // it doesn't match org#module, skip to next
                return null;
            }
            break;
    }
    Message.verbose("Workspace resolver found potential matching workspace module " + workspaceModuleName + " with module " + candidateMrid + " for module " + dependencyMrid);
    if (!ignoreBranch) {
        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) {
                Message.verbose("\t\trejected since branches doesn't match (one is set, the other isn't)");
                return null;
            }
            if (!dependencyBranch.equals(candidateBranch)) {
                Message.verbose("\t\trejected since branches doesn't match");
                return null;
            }
        }
    }
    // Found one; check if it is for the module we need
    if (!ignoreVersion && !md.getModuleRevisionId().getRevision().equals(Ivy.getWorkingRevision()) && !versionMatcher.accept(dd.getDependencyRevisionId(), md)) {
        Message.verbose("\t\treject as version didn't match");
        return null;
    }
    if (ignoreVersion) {
        Message.verbose("\t\tmatched (version are ignored)");
    } else {
        Message.verbose("\t\tversion matched");
    }
    WorkspaceModuleDescriptor workspaceMd = createWorkspaceMd(md);
    Artifact mdaf = md.getMetadataArtifact();
    if (mdaf == null) {
        mdaf = new DefaultArtifact(md.getModuleRevisionId(), md.getPublicationDate(), workspaceModuleName, "ivy", "");
    }
    MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(mdaf);
    madr.setDownloadStatus(DownloadStatus.SUCCESSFUL);
    madr.setSearched(true);
    return new ResolvedModuleRevision(this, this, workspaceMd, madr);
}
Also used : MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ManifestHeaderValue(org.apache.ivy.osgi.core.ManifestHeaderValue) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) DefaultWorkspaceModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultWorkspaceModuleDescriptor) WorkspaceModuleDescriptor(org.apache.ivy.core.module.descriptor.WorkspaceModuleDescriptor) ModuleId(org.apache.ivy.core.module.id.ModuleId) ManifestHeaderElement(org.apache.ivy.osgi.core.ManifestHeaderElement) VersionMatcher(org.apache.ivy.plugins.version.VersionMatcher) ParseException(java.text.ParseException) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact)

Example 2 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class IvyInfo method doExecute.

public void doExecute() throws BuildException {
    Ivy ivy = getIvyInstance();
    IvySettings settings = ivy.getSettings();
    try {
        if (organisation != null || module != null || revision != null || branch != null) {
            if (organisation == null) {
                throw new BuildException("no organisation provided for ivy info task");
            }
            if (module == null) {
                throw new BuildException("no module name provided for ivy info task");
            }
            if (revision == null) {
                throw new BuildException("no revision provided for ivy info task");
            }
            if (branch == null) {
                settings.getDefaultBranch(new ModuleId(organisation, module));
            }
            ResolvedModuleRevision rmr = ivy.findModule(ModuleRevisionId.newInstance(organisation, module, branch, revision));
            if (rmr != null) {
                ModuleDescriptor md = rmr.getDescriptor();
                ModuleRevisionId mrid = rmr.getId();
                setProperties(md, mrid);
            }
        } else {
            if (file == null) {
                file = getProject().resolveFile(getProperty(settings, "ivy.dep.file"));
            }
            ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor(settings, file.toURI().toURL(), doValidate(settings));
            ModuleRevisionId mrid = md.getModuleRevisionId();
            setProperties(md, mrid);
        }
    } catch (MalformedURLException e) {
        throw new BuildException("unable to convert given ivy file to url: " + file + ": " + e, e);
    } catch (ParseException e) {
        log(e.getMessage(), Project.MSG_ERR);
        throw new BuildException("syntax errors in ivy file: " + e, e);
    } catch (Exception e) {
        throw new BuildException("impossible to resolve dependencies: " + e, e);
    }
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) MalformedURLException(java.net.MalformedURLException) IvySettings(org.apache.ivy.core.settings.IvySettings) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) BuildException(org.apache.tools.ant.BuildException) ParseException(java.text.ParseException) Ivy(org.apache.ivy.Ivy) MalformedURLException(java.net.MalformedURLException) BuildException(org.apache.tools.ant.BuildException) ParseException(java.text.ParseException)

Example 3 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class IvyReport method doExecute.

public void doExecute() throws BuildException {
    Ivy ivy = getIvyInstance();
    IvySettings settings = ivy.getSettings();
    conf = getProperty(conf, settings, "ivy.resolved.configurations", resolveId);
    if ("*".equals(conf)) {
        conf = getProperty(settings, "ivy.resolved.configurations", resolveId);
    }
    if (conf == null) {
        throw new BuildException("no conf provided for ivy report task: " + "It can either be set explicitly via the attribute 'conf' or " + "via 'ivy.resolved.configurations' property or a prior call to <resolve/>");
    }
    if (todir == null) {
        String t = getProperty(settings, "ivy.report.todir");
        if (t != null) {
            todir = getProject().resolveFile(t);
        }
    }
    if (todir != null && todir.exists()) {
        todir.mkdirs();
    }
    outputpattern = getProperty(outputpattern, settings, "ivy.report.output.pattern");
    if (outputpattern == null) {
        outputpattern = "[organisation]-[module]-[conf].[ext]";
    }
    if (todir != null && todir.exists() && !todir.isDirectory()) {
        throw new BuildException("destination directory should be a directory !");
    }
    if (resolveId == null) {
        organisation = getProperty(organisation, settings, "ivy.organisation", resolveId);
        module = getProperty(module, settings, "ivy.module", resolveId);
        if (organisation == null) {
            throw new BuildException("no organisation provided for ivy report task: " + "It can either be set explicitly via the attribute 'organisation' or " + "via 'ivy.organisation' property or a prior call to <resolve/>");
        }
        if (module == null) {
            throw new BuildException("no module name provided for ivy report task: " + "It can either be set explicitly via the attribute 'module' or " + "via 'ivy.module' property or a prior call to <resolve/>");
        }
        resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(organisation, module));
    }
    try {
        String[] confs = splitToArray(conf);
        if (xsl) {
            genreport(confs);
        }
        if (xml) {
            genxml(confs);
        }
        if (graph) {
            genStyled(confs, getStylePath("ivy-report-graph.xsl"), "graphml");
        }
        if (dot) {
            genStyled(confs, getStylePath("ivy-report-dot.xsl"), "dot");
        }
    } catch (IOException e) {
        throw new BuildException("impossible to generate report: " + e, e);
    }
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) IvySettings(org.apache.ivy.core.settings.IvySettings) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) Ivy(org.apache.ivy.Ivy)

Example 4 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class IvyRepositoryReport method doExecute.

public void doExecute() throws BuildException {
    Ivy ivy = getIvyInstance();
    IvySettings settings = ivy.getSettings();
    if (xsl && xslFile == null) {
        throw new BuildException("xsl file is mandatory when using xsl generation");
    }
    if (module == null && PatternMatcher.EXACT.equals(matcher)) {
        throw new BuildException("no module name provided for ivy repository graph task: " + "It can either be set explicitly via the attribute 'module' or " + "via 'ivy.module' property or a prior call to <resolve/>");
    } else if (module == null && !PatternMatcher.EXACT.equals(matcher)) {
        module = PatternMatcher.ANY_EXPRESSION;
    }
    ModuleRevisionId moduleRevisionId = ModuleRevisionId.newInstance(organisation, module, revision);
    try {
        ModuleRevisionId criteria = (revision == null) || settings.getVersionMatcher().isDynamic(moduleRevisionId) ? new ModuleRevisionId(new ModuleId(organisation, module), branch, "*") : new ModuleRevisionId(new ModuleId(organisation, module), branch, revision);
        ModuleRevisionId[] mrids = ivy.listModules(criteria, settings.getMatcher(matcher));
        // replace all found revisions with the original requested revision
        Set<ModuleRevisionId> modules = new HashSet<>();
        for (ModuleRevisionId mrid : mrids) {
            modules.add(ModuleRevisionId.newInstance(mrid, revision));
        }
        mrids = modules.toArray(new ModuleRevisionId[modules.size()]);
        ModuleDescriptor md = DefaultModuleDescriptor.newCallerInstance(mrids, true, false);
        String resolveId = ResolveOptions.getDefaultResolveId(md);
        ResolveReport report = ivy.resolve(md, new ResolveOptions().setResolveId(resolveId).setValidate(doValidate(settings)));
        ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
        new XmlReportOutputter().output(report, cacheMgr, new ResolveOptions());
        if (graph) {
            gengraph(cacheMgr, md.getModuleRevisionId().getOrganisation(), md.getModuleRevisionId().getName());
        }
        if (dot) {
            gendot(cacheMgr, md.getModuleRevisionId().getOrganisation(), md.getModuleRevisionId().getName());
        }
        if (xml) {
            FileUtil.copy(cacheMgr.getConfigurationResolveReportInCache(resolveId, "default"), new File(getTodir(), outputname + ".xml"), null);
        }
        if (xsl) {
            genreport(cacheMgr, md.getModuleRevisionId().getOrganisation(), md.getModuleRevisionId().getName());
        }
    } catch (Exception e) {
        throw new BuildException("impossible to generate graph for " + moduleRevisionId + ": " + e, e);
    }
}
Also used : ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) IvySettings(org.apache.ivy.core.settings.IvySettings) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) Ivy(org.apache.ivy.Ivy) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) ModuleId(org.apache.ivy.core.module.id.ModuleId) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) XmlReportOutputter(org.apache.ivy.plugins.report.XmlReportOutputter) ResolveReport(org.apache.ivy.core.report.ResolveReport) BuildException(org.apache.tools.ant.BuildException) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) File(java.io.File) HashSet(java.util.HashSet)

Example 5 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class IvyRepositoryReport method gen.

private void gen(ResolutionCacheManager cache, String organisation, String module, String style, String ext) {
    XSLTProcess xslt = new XSLTProcess();
    xslt.setTaskName(getTaskName());
    xslt.setProject(getProject());
    xslt.init();
    String resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(organisation, module));
    xslt.setIn(cache.getConfigurationResolveReportInCache(resolveId, "default"));
    xslt.setOut(new File(getTodir(), outputname + "." + ext));
    xslt.setBasedir(cache.getResolutionCacheRoot());
    xslt.setStyle(style);
    xslt.execute();
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) XSLTProcess(org.apache.tools.ant.taskdefs.XSLTProcess) File(java.io.File)

Aggregations

ModuleId (org.apache.ivy.core.module.id.ModuleId)49 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)19 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)13 File (java.io.File)9 HashMap (java.util.HashMap)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 Date (java.util.Date)6 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)6 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)6 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)6 BuildException (org.apache.tools.ant.BuildException)6 Ivy (org.apache.ivy.Ivy)5 ArtifactId (org.apache.ivy.core.module.id.ArtifactId)5 ResolveReport (org.apache.ivy.core.report.ResolveReport)5 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)5 IvySettings (org.apache.ivy.core.settings.IvySettings)5 IOException (java.io.IOException)4 Map (java.util.Map)4 Configuration (org.apache.ivy.core.module.descriptor.Configuration)4