Search in sources :

Example 56 with DependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyDescriptor in project ant-ivy by apache.

the class IvyDeliverTest method testWithDynEvicted.

@Test
public void testWithDynEvicted() throws Exception {
    project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-dyn-evicted.xml");
    IvyResolve res = new IvyResolve();
    res.setValidate(false);
    res.setProject(project);
    res.execute();
    deliver.setPubrevision("1.2");
    deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml");
    deliver.setValidate(false);
    deliver.execute();
    // should have done the ivy delivering
    File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml");
    assertTrue(deliveredIvyFile.exists());
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), deliveredIvyFile.toURI().toURL(), false);
    assertEquals(ModuleRevisionId.newInstance("apache", "resolve-latest", "1.2"), md.getModuleRevisionId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertEquals(2, dds.length);
    assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.2"), dds[0].getDependencyRevisionId());
    IvyRetrieve ret = new IvyRetrieve();
    ret.setProject(project);
    ret.setPattern("build/test/retrieve/[artifact]-[revision].[ext]");
    ret.execute();
    File list = new File("build/test/retrieve");
    String[] files = list.list();
    HashSet<String> actualFileSet = new HashSet<>(Arrays.asList(files));
    HashSet<String> expectedFileSet = new HashSet<>();
    for (DependencyDescriptor dd : dds) {
        String name = dd.getDependencyId().getName();
        String rev = dd.getDependencyRevisionId().getRevision();
        String ext = "jar";
        String artifact = name + "-" + rev + "." + ext;
        expectedFileSet.add(artifact);
    }
    assertEquals("Delivered Ivy descriptor inconsistent with retrieved artifacts", expectedFileSet, actualFileSet);
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) IvySettings(org.apache.ivy.core.settings.IvySettings) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 57 with DependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyDescriptor in project ant-ivy by apache.

the class IvyDeliverTest method testNoReplaceDynamicRev.

@Test
public void testNoReplaceDynamicRev() throws Exception {
    project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest.xml");
    IvyResolve res = new IvyResolve();
    res.setProject(project);
    res.execute();
    deliver.setPubrevision("1.2");
    deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml");
    deliver.setReplacedynamicrev(false);
    deliver.execute();
    // should have done the ivy delivering
    File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml");
    assertTrue(deliveredIvyFile.exists());
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), deliveredIvyFile.toURI().toURL(), true);
    assertEquals(ModuleRevisionId.newInstance("apache", "resolve-latest", "1.2"), md.getModuleRevisionId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertEquals(1, dds.length);
    assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "latest.integration"), dds[0].getDependencyRevisionId());
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) IvySettings(org.apache.ivy.core.settings.IvySettings) File(java.io.File) Test(org.junit.Test)

Example 58 with DependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyDescriptor in project ant-ivy by apache.

the class IvyBuildList method processFilterNodeFromRoot.

/**
 * Adds the current node to the toKeep collection and then processes the each of the direct
 * dependencies of this node that appear in the moduleIdMap (indicating that the dependency is
 * part of this BuildList)
 *
 * @param node
 *            the node to be processed
 * @param toKeep
 *            the set of ModuleDescriptors that should be kept
 * @param moduleIdMap
 *            reference mapping of moduleId to ModuleDescriptor that are part of the BuildList
 */
private void processFilterNodeFromRoot(ModuleDescriptor node, Set<ModuleDescriptor> toKeep, Map<ModuleId, ModuleDescriptor> moduleIdMap) {
    // toKeep.add(node);
    for (DependencyDescriptor dep : node.getDependencies()) {
        ModuleId id = dep.getDependencyId();
        ModuleDescriptor md = moduleIdMap.get(id);
        // toKeep Set, in which there's probably a circular dependency
        if (md != null && !toKeep.contains(md)) {
            toKeep.add(md);
            if (!getOnlydirectdep()) {
                processFilterNodeFromRoot(md, toKeep, moduleIdMap);
            }
        }
    }
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor)

Example 59 with DependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyDescriptor 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 60 with DependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyDescriptor in project ant-ivy by apache.

the class IvyResolve method doExecute.

@Override
public void doExecute() throws BuildException {
    Ivy ivy = getIvyInstance();
    IvySettings settings = ivy.getSettings();
    try {
        conf = getProperty(conf, settings, "ivy.configurations");
        type = getProperty(type, settings, "ivy.resolve.default.type.filter");
        String[] confs = splitToArray(conf);
        boolean childs = !dependencies.isEmpty() || !excludes.isEmpty() || !conflicts.isEmpty();
        ResolveReport report;
        if (childs) {
            if (isInline()) {
                throw new BuildException("the inline mode is incompatible with child elements");
            }
            if (organisation != null) {
                throw new BuildException("'organisation' is not allowed with child elements");
            }
            if (module != null) {
                throw new BuildException("'module' is not allowed with child elements");
            }
            if (file != null) {
                throw new BuildException("'file' not allowed with child elements");
            }
            if (!getAllowedLogOptions().contains(log)) {
                throw new BuildException("invalid option for 'log': " + log + ". Available options are " + getAllowedLogOptions());
            }
            ModuleRevisionId mrid = ModuleRevisionId.newInstance("", "", Ivy.getWorkingRevision());
            DefaultModuleDescriptor md = DefaultModuleDescriptor.newBasicInstance(mrid, null);
            for (IvyDependency dep : dependencies) {
                DependencyDescriptor dd = dep.asDependencyDescriptor(md, "default", settings);
                md.addDependency(dd);
            }
            for (IvyExclude exclude : excludes) {
                DefaultExcludeRule rule = exclude.asRule(settings);
                rule.addConfiguration("default");
                md.addExcludeRule(rule);
            }
            for (IvyConflict conflict : conflicts) {
                conflict.addConflict(md, settings);
            }
            report = ivy.resolve(md, getResolveOptions(ivy, new String[] { "default" }, settings));
        } else if (isInline()) {
            if (organisation == null) {
                throw new BuildException("'organisation' is required when using inline mode");
            }
            if (module == null) {
                throw new BuildException("'module' is required when using inline mode");
            }
            if (file != null) {
                throw new BuildException("'file' not allowed when using inline mode");
            }
            if (!getAllowedLogOptions().contains(log)) {
                throw new BuildException("invalid option for 'log': " + log + ". Available options are " + getAllowedLogOptions());
            }
            for (int i = 0; i < confs.length; i++) {
                if ("*".equals(confs[i])) {
                    confs[i] = "*(public)";
                }
            }
            if (revision == null) {
                revision = "latest.integration";
            }
            report = ivy.resolve(ModuleRevisionId.newInstance(organisation, module, branch, revision), getResolveOptions(ivy, confs, settings), changing);
        } else {
            if (organisation != null) {
                throw new BuildException("'organisation' not allowed when not using 'org' attribute");
            }
            if (module != null) {
                throw new BuildException("'module' not allowed when not using 'org' attribute");
            }
            if (file == null) {
                file = getProject().resolveFile(getProperty(settings, "ivy.dep.file"));
            }
            report = ivy.resolve(file.toURI().toURL(), getResolveOptions(ivy, confs, settings));
        }
        if (report.hasError()) {
            if (failureProperty != null) {
                getProject().setProperty(failureProperty, "true");
            }
            if (isHaltonfailure()) {
                throw new BuildException("resolve failed - see output for details");
            }
        }
        setResolved(report, resolveId, isKeep());
        confs = report.getConfigurations();
        if (isKeep()) {
            ModuleDescriptor md = report.getModuleDescriptor();
            // put resolved infos in ant properties and ivy variables
            // putting them in ivy variables is important to be able to change from one resolve
            // call to the other
            String mdOrg = md.getModuleRevisionId().getOrganisation();
            String mdName = md.getModuleRevisionId().getName();
            String mdRev = md.getResolvedModuleRevisionId().getRevision();
            getProject().setProperty("ivy.organisation", mdOrg);
            settings.setVariable("ivy.organisation", mdOrg);
            getProject().setProperty("ivy.module", mdName);
            settings.setVariable("ivy.module", mdName);
            getProject().setProperty("ivy.revision", mdRev);
            settings.setVariable("ivy.revision", mdRev);
            List<ExtendsDescriptor> parents = Arrays.asList(md.getInheritedDescriptors());
            for (ExtendsDescriptor parent : parents) {
                int i = parents.indexOf(parent);
                String parentOrg = parent.getResolvedParentRevisionId().getOrganisation();
                String parentModule = parent.getResolvedParentRevisionId().getName();
                String parentRevision = parent.getResolvedParentRevisionId().getRevision();
                String parentBranch = parent.getResolvedParentRevisionId().getBranch();
                getProject().setProperty("ivy.parent[" + i + "].organisation", parentOrg);
                settings.setVariable("ivy.parent[" + i + "].organisation", parentOrg);
                getProject().setProperty("ivy.parent[" + i + "].module", parentModule);
                settings.setVariable("ivy.parent[" + i + "].module", parentModule);
                getProject().setProperty("ivy.parent[" + i + "].revision", parentRevision);
                settings.setVariable("ivy.parent[" + i + "].revision", parentRevision);
                if (parentBranch != null) {
                    getProject().setProperty("ivy.parent[" + i + "].branch", parentBranch);
                    settings.setVariable("ivy.parent[" + i + "].branch", parentBranch);
                }
            }
            getProject().setProperty("ivy.parents.count", String.valueOf(md.getInheritedDescriptors().length));
            settings.setVariable("ivy.parents.count", String.valueOf(md.getInheritedDescriptors().length));
            Boolean hasChanged = null;
            if (getCheckIfChanged()) {
                hasChanged = report.hasChanged();
                getProject().setProperty("ivy.deps.changed", hasChanged.toString());
                settings.setVariable("ivy.deps.changed", hasChanged.toString());
            }
            getProject().setProperty("ivy.resolved.configurations", mergeConfs(confs));
            settings.setVariable("ivy.resolved.configurations", mergeConfs(confs));
            if (file != null) {
                getProject().setProperty("ivy.resolved.file", file.getAbsolutePath());
                settings.setVariable("ivy.resolved.file", file.getAbsolutePath());
            }
            if (resolveId != null) {
                getProject().setProperty("ivy.organisation." + resolveId, mdOrg);
                settings.setVariable("ivy.organisation." + resolveId, mdOrg);
                getProject().setProperty("ivy.module." + resolveId, mdName);
                settings.setVariable("ivy.module." + resolveId, mdName);
                getProject().setProperty("ivy.revision." + resolveId, mdRev);
                settings.setVariable("ivy.revision." + resolveId, mdRev);
                if (getCheckIfChanged()) {
                    // hasChanged has already been set earlier
                    getProject().setProperty("ivy.deps.changed." + resolveId, hasChanged.toString());
                    settings.setVariable("ivy.deps.changed." + resolveId, hasChanged.toString());
                }
                getProject().setProperty("ivy.resolved.configurations." + resolveId, mergeConfs(confs));
                settings.setVariable("ivy.resolved.configurations." + resolveId, mergeConfs(confs));
                if (file != null) {
                    getProject().setProperty("ivy.resolved.file." + resolveId, file.getAbsolutePath());
                    settings.setVariable("ivy.resolved.file." + resolveId, file.getAbsolutePath());
                }
            }
        }
    } 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 (ResolveProcessException e) {
        throw new BuildException("impossible to resolve dependencies:\n\t" + e.getMessage(), e);
    } catch (Exception e) {
        throw new BuildException("impossible to resolve dependencies:\n\t" + e, e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) IvySettings(org.apache.ivy.core.settings.IvySettings) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) Ivy(org.apache.ivy.Ivy) MalformedURLException(java.net.MalformedURLException) BuildException(org.apache.tools.ant.BuildException) ResolveProcessException(org.apache.ivy.core.resolve.ResolveProcessException) ParseException(java.text.ParseException) DefaultExcludeRule(org.apache.ivy.core.module.descriptor.DefaultExcludeRule) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ExtendsDescriptor(org.apache.ivy.core.module.descriptor.ExtendsDescriptor) ResolveReport(org.apache.ivy.core.report.ResolveReport) ResolveProcessException(org.apache.ivy.core.resolve.ResolveProcessException) BuildException(org.apache.tools.ant.BuildException) ParseException(java.text.ParseException) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)

Aggregations

DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)101 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)80 Test (org.junit.Test)75 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)35 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)33 File (java.io.File)26 XmlModuleDescriptorParserTest (org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest)26 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)25 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)18 IvySettings (org.apache.ivy.core.settings.IvySettings)17 Configuration (org.apache.ivy.core.module.descriptor.Configuration)15 Artifact (org.apache.ivy.core.module.descriptor.Artifact)13 ParseException (java.text.ParseException)12 IOException (java.io.IOException)11 ResolveData (org.apache.ivy.core.resolve.ResolveData)11 MockResolver (org.apache.ivy.plugins.resolver.MockResolver)9 JarFile (java.util.jar.JarFile)7 GregorianCalendar (java.util.GregorianCalendar)6 ModuleId (org.apache.ivy.core.module.id.ModuleId)6 ResolveReport (org.apache.ivy.core.report.ResolveReport)6