Search in sources :

Example 26 with DefaultModuleDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor 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)

Example 27 with DefaultModuleDescriptor

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

the class XmlModuleDescriptorWriterTest method testTransitiveAttributeNotWrittenForTransitiveConfs.

/**
 * Test that the transitive attribute is not written when the configuration IS transitive.
 *
 * This is the default and writing it will only add noise and cause a deviation from the known
 * behavior (before fixing IVY-1207).
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1207">IVY-1207</a>
 */
@Test
public void testTransitiveAttributeNotWrittenForTransitiveConfs() throws Exception {
    // Given a ModuleDescriptor with a transitive configuration
    DefaultModuleDescriptor md = new DefaultModuleDescriptor(new ModuleRevisionId(new ModuleId("myorg", "myname"), "1.0"), "integration", new Date());
    Configuration conf = new Configuration("conf", PUBLIC, "desc", null, true, null);
    md.addConfiguration(conf);
    // When the ModuleDescriptor is written
    XmlModuleDescriptorWriter.write(md, LICENSE, dest);
    // Then the transitive attribute must NOT be written
    String output = FileUtil.readEntirely(dest);
    String writtenConf = output.substring(output.indexOf("<configurations>") + 16, output.indexOf("</configurations>")).trim();
    assertFalse("Transitive attribute set: " + writtenConf, writtenConf.contains("transitive="));
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) Date(java.util.Date) Test(org.junit.Test) PomModuleDescriptorParserTest(org.apache.ivy.plugins.parser.m2.PomModuleDescriptorParserTest)

Example 28 with DefaultModuleDescriptor

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

the class MockResolver method buildMockResolver.

static MockResolver buildMockResolver(ResolverSettings settings, String name, boolean findRevision, final ModuleRevisionId mrid, final Date publicationDate, final boolean isdefault) {
    final MockResolver r = new MockResolver();
    r.setName(name);
    r.setSettings(settings);
    if (findRevision) {
        DefaultModuleDescriptor md = new DefaultModuleDescriptor(mrid, "integration", publicationDate, isdefault);
        r.rmr = new ResolvedModuleRevision(r, r, md, new MetadataArtifactDownloadReport(md.getMetadataArtifact()));
    }
    return r;
}
Also used : MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)

Example 29 with DefaultModuleDescriptor

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

the class LatestVersionMatcherTest method assertAccept.

private void assertAccept(String askedVersion, String askedBranch, String foundStatus, String foundBranch, boolean b) {
    ModuleRevisionId askedMrid = ModuleRevisionId.newInstance("org", "name", askedBranch, askedVersion);
    DefaultModuleDescriptor foundMD = DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.newInstance("org", "name", foundBranch, (String) null));
    foundMD.setStatus(foundStatus);
    assertEquals(b, vm.accept(askedMrid, foundMD));
}
Also used : ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)

Example 30 with DefaultModuleDescriptor

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

the class XmlModuleDescriptorParser method toIvyFile.

public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md) throws IOException, ParseException {
    try {
        Namespace ns = null;
        if (md instanceof DefaultModuleDescriptor) {
            DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md;
            ns = dmd.getNamespace();
        }
        XmlModuleDescriptorUpdater.update(is, res, destFile, new UpdateOptions().setSettings(IvyContext.getContext().getSettings()).setStatus(md.getStatus()).setRevision(md.getResolvedModuleRevisionId().getRevision()).setPubdate(md.getResolvedPublicationDate()).setUpdateBranch(false).setNamespace(ns));
    } catch (SAXException e) {
        ParseException pe = new ParseException("exception occurred while parsing " + res, 0);
        pe.initCause(e);
        throw pe;
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
Also used : ParseException(java.text.ParseException) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) Namespace(org.apache.ivy.plugins.namespace.Namespace) SAXException(org.xml.sax.SAXException)

Aggregations

DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)30 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)17 Date (java.util.Date)10 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)9 File (java.io.File)7 Configuration (org.apache.ivy.core.module.descriptor.Configuration)7 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)6 ResolveReport (org.apache.ivy.core.report.ResolveReport)6 IvySettings (org.apache.ivy.core.settings.IvySettings)6 Test (org.junit.Test)6 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)5 ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)5 ParseException (java.text.ParseException)4 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)4 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)4 BufferedReader (java.io.BufferedReader)3 IOException (java.io.IOException)3 Map (java.util.Map)3 Artifact (org.apache.ivy.core.module.descriptor.Artifact)3 ModuleId (org.apache.ivy.core.module.id.ModuleId)3