Search in sources :

Example 1 with Ivy

use of org.apache.ivy.Ivy 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 2 with Ivy

use of org.apache.ivy.Ivy in project ant-ivy by apache.

the class IvyInstall method doExecute.

public void doExecute() throws BuildException {
    Ivy ivy = getIvyInstance();
    IvySettings settings = ivy.getSettings();
    if (organisation == null) {
        throw new BuildException("no organisation provided for ivy publish 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) {
        if (PatternMatcher.EXACT.equals(matcher)) {
            throw new BuildException("no module name provided for ivy publish task: " + "It can either be set explicitly via the attribute 'module' " + "or via 'ivy.module' property or a prior call to <resolve/>");
        }
        module = PatternMatcher.ANY_EXPRESSION;
    }
    if (revision == null) {
        if (PatternMatcher.EXACT.equals(matcher)) {
            throw new BuildException("no module revision provided for ivy publish task: " + "It can either be set explicitly via the attribute 'revision' " + "or via 'ivy.revision' property or a prior call to <resolve/>");
        }
        revision = PatternMatcher.ANY_EXPRESSION;
    }
    if (branch == null) {
        if (PatternMatcher.EXACT.equals(matcher)) {
            branch = settings.getDefaultBranch(ModuleId.newInstance(organisation, module));
        } else {
            branch = PatternMatcher.ANY_EXPRESSION;
        }
    }
    if (from == null) {
        throw new BuildException("no from resolver name: please provide it through parameter 'from'");
    }
    if (to == null) {
        throw new BuildException("no to resolver name: please provide it through parameter 'to'");
    }
    ModuleRevisionId mrid = ModuleRevisionId.newInstance(organisation, module, branch, revision);
    ResolveReport report;
    try {
        report = ivy.install(mrid, from, to, new InstallOptions().setTransitive(transitive).setValidate(doValidate(settings)).setOverwrite(overwrite).setConfs(conf.split(",")).setArtifactFilter(FilterHelper.getArtifactTypeFilter(type)).setMatcherName(matcher).setInstallOriginalMetadata(installOriginalMetadata));
    } catch (Exception e) {
        throw new BuildException("impossible to install " + mrid + ": " + e, e);
    }
    if (report.hasError() && isHaltonfailure()) {
        throw new BuildException("Problem happened while installing modules - see output for details");
    }
}
Also used : ResolveReport(org.apache.ivy.core.report.ResolveReport) IvySettings(org.apache.ivy.core.settings.IvySettings) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) InstallOptions(org.apache.ivy.core.install.InstallOptions) BuildException(org.apache.tools.ant.BuildException) Ivy(org.apache.ivy.Ivy) BuildException(org.apache.tools.ant.BuildException)

Example 3 with Ivy

use of org.apache.ivy.Ivy in project ant-ivy by apache.

the class IvyPostResolveTask method prepareAndCheck.

protected void prepareAndCheck() {
    Ivy ivy = getIvyInstance();
    IvySettings settings = ivy.getSettings();
    boolean orgAndModSetManually = organisation != null && module != null;
    organisation = getProperty(organisation, settings, "ivy.organisation");
    module = getProperty(module, settings, "ivy.module");
    if (file == null) {
        String fileName = getProperty(settings, "ivy.resolved.file", resolveId);
        if (fileName != null) {
            file = getProject().resolveFile(fileName);
        }
    }
    if (isInline()) {
        if (conf == null) {
            conf = "*";
        }
        if (organisation == null) {
            throw new BuildException("no organisation provided for ivy cache task in inline mode: " + "It can either be set explicitly via the attribute 'organisation' " + "or via 'ivy.organisation' property");
        }
        if (module == null) {
            throw new BuildException("no module name provided for ivy cache task in inline mode: " + "It can either be set explicitly via the attribute 'module' " + "or via 'ivy.module' property");
        }
        String[] toResolve = getConfsToResolve(getOrganisation(), getModule() + "-caller", conf, true);
        // When we make an inline resolution, we can not resolve private confs.
        for (int i = 0; i < toResolve.length; i++) {
            if ("*".equals(toResolve[i])) {
                toResolve[i] = "*(public)";
            }
        }
        if (toResolve.length > 0) {
            Message.verbose(String.format("using inline mode to resolve %s %s %s (%s)", getOrganisation(), getModule(), getRevision(), joinArray(toResolve, ", ")));
            IvyResolve resolve = setupResolve(isHaltonfailure(), isUseOrigin());
            resolve.setOrganisation(getOrganisation());
            resolve.setModule(getModule());
            resolve.setBranch(getBranch());
            resolve.setRevision(getRevision());
            resolve.setInline(true);
            resolve.setChanging(isChanging());
            resolve.setConf(conf);
            resolve.setResolveId(resolveId);
            resolve.setTransitive(isTransitive());
            resolve.execute();
        } else {
            Message.verbose(String.format("inline resolve already done for %s %s %s (%s)", getOrganisation(), getModule(), getRevision(), conf));
        }
        if ("*".equals(conf)) {
            conf = joinArray(getResolvedConfigurations(getOrganisation(), getModule() + "-caller", true), ", ");
        }
    } else {
        Message.debug("using standard ensure resolved");
        // from these report names?)
        if (!orgAndModSetManually) {
            ensureResolved(settings);
        }
        conf = getProperty(conf, settings, "ivy.resolved.configurations");
        if ("*".equals(conf)) {
            conf = getProperty(settings, "ivy.resolved.configurations");
            if (conf == null) {
                throw new BuildException("bad conf provided for ivy cache task: " + "'*' can only be used with a prior call to <resolve/>");
            }
        }
    }
    organisation = getProperty(organisation, settings, "ivy.organisation");
    module = getProperty(module, settings, "ivy.module");
    if (organisation == null) {
        throw new BuildException("no organisation provided for ivy cache 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 cache task: " + "It can either be set explicitly via the attribute 'module' " + "or via 'ivy.module' property or a prior call to <resolve/>");
    }
    if (conf == null) {
        throw new BuildException("no conf provided for ivy cache task: " + "It can either be set explicitly via the attribute 'conf' or " + "via 'ivy.resolved.configurations' property or a prior call to <resolve/>");
    }
    artifactFilter = FilterHelper.getArtifactTypeFilter(type);
}
Also used : IvySettings(org.apache.ivy.core.settings.IvySettings) BuildException(org.apache.tools.ant.BuildException) Ivy(org.apache.ivy.Ivy)

Example 4 with Ivy

use of org.apache.ivy.Ivy 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 5 with Ivy

use of org.apache.ivy.Ivy 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)

Aggregations

Ivy (org.apache.ivy.Ivy)169 File (java.io.File)147 Test (org.junit.Test)137 ResolveReport (org.apache.ivy.core.report.ResolveReport)102 JarFile (java.util.jar.JarFile)100 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)97 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)40 IvySettings (org.apache.ivy.core.settings.IvySettings)26 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)23 BuildException (org.apache.tools.ant.BuildException)17 Before (org.junit.Before)12 HashMap (java.util.HashMap)9 DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)8 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)6 ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)6 DefaultRepositoryCacheManager (org.apache.ivy.core.cache.DefaultRepositoryCacheManager)5 ModuleId (org.apache.ivy.core.module.id.ModuleId)5 IOException (java.io.IOException)4 ParseException (java.text.ParseException)4 Date (java.util.Date)4