Search in sources :

Example 11 with DependencyResolver

use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.

the class IvySettings method dumpSettings.

private void dumpSettings() {
    Message.verbose("\tdefault cache: " + getDefaultCache());
    Message.verbose("\tdefault resolver: " + getDefaultResolver());
    Message.debug("\tdefault latest strategy: " + getDefaultLatestStrategy());
    Message.debug("\tdefault conflict manager: " + getDefaultConflictManager());
    Message.debug("\tcircular dependency strategy: " + getCircularDependencyStrategy());
    Message.debug("\tvalidate: " + doValidate());
    Message.debug("\tcheck up2date: " + isCheckUpToDate());
    if (!classpathURLs.isEmpty()) {
        Message.verbose("\t-- " + classpathURLs.size() + " custom classpath urls:");
        for (URL url : classpathURLs) {
            Message.debug("\t\t" + url);
        }
    }
    Message.verbose("\t-- " + resolversMap.size() + " resolvers:");
    for (DependencyResolver resolver : resolversMap.values()) {
        resolver.dumpSettings();
    }
    Message.debug("\tmodule settings:");
    moduleSettings.dump("\t\t");
}
Also used : URL(java.net.URL) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 12 with DependencyResolver

use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.

the class ResolveEngine method findModule.

public ResolvedModuleRevision findModule(ModuleRevisionId id, ResolveOptions options) {
    DependencyResolver r = settings.getResolver(id);
    if (r == null) {
        throw new IllegalStateException("no resolver found for " + id.getModuleId());
    }
    DefaultModuleDescriptor md = DefaultModuleDescriptor.newCallerInstance(id, new String[] { "*" }, false, false);
    if (options.getResolveId() == null) {
        options.setResolveId(ResolveOptions.getDefaultResolveId(md));
    }
    try {
        return r.getDependency(new DefaultDependencyDescriptor(id, true), new ResolveData(this, options, new ConfigurationResolveReport(this, md, "default", null, options)));
    } catch (ParseException e) {
        throw new RuntimeException("problem while parsing repository module descriptor for " + id + ": " + e, e);
    }
}
Also used : DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ParseException(java.text.ParseException) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 13 with DependencyResolver

use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.

the class PublishEngine method publish.

/**
 * Publishes a module to the repository. The publish can update the ivy file to publish if
 * update is set to true. In this case it will use the given pubrevision, pubdate and status. If
 * pubdate is null it will default to the current date. If status is null it will default to the
 * current ivy file status (which itself defaults to integration if none is found). If update is
 * false, then if the revision is not the same in the ivy file than the one expected (given as
 * parameter), this method will fail with an IllegalArgumentException. pubdate and status are
 * not used if update is false. extra artifacts can be used to publish more artifacts than
 * actually declared in the ivy file. This can be useful to publish additional metadata or
 * reports. The extra artifacts array can be null (= no extra artifacts), and if non null only
 * the name, type, ext url and extra attributes of the artifacts are really used. Other methods
 * can return null safely.
 *
 * @param mrid ModuleRevisionId
 * @param srcArtifactPattern a Collection of String
 * @param resolverName String
 * @param options PublishOptions
 * @return Collection<Artifact>
 * @throws IOException if something goes wrong
 */
public Collection<Artifact> publish(ModuleRevisionId mrid, Collection<String> srcArtifactPattern, String resolverName, PublishOptions options) throws IOException {
    Message.info(":: publishing :: " + mrid.getModuleId());
    Message.verbose("\tvalidate = " + options.isValidate());
    long start = System.currentTimeMillis();
    options.setSrcIvyPattern(settings.substitute(options.getSrcIvyPattern()));
    if (options.getPubBranch() == null) {
        options.setPubbranch(mrid.getBranch());
    }
    if (options.getPubrevision() == null) {
        options.setPubrevision(mrid.getRevision());
    }
    ModuleRevisionId pubmrid = ModuleRevisionId.newInstance(mrid, options.getPubBranch(), options.getPubrevision());
    // let's find the resolved module descriptor
    ModuleDescriptor md = null;
    if (options.getSrcIvyPattern() != null) {
        File ivyFile = settings.resolveFile(IvyPatternHelper.substitute(options.getSrcIvyPattern(), DefaultArtifact.newIvyArtifact(pubmrid, new Date())));
        if (!ivyFile.exists()) {
            throw new IllegalArgumentException("ivy file to publish not found for " + mrid + ": call deliver before (" + ivyFile + ")");
        }
        URL ivyFileURL = ivyFile.toURI().toURL();
        try {
            md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyFileURL, false);
            if (options.isUpdate()) {
                File tmp = File.createTempFile("ivy", ".xml");
                tmp.deleteOnExit();
                String[] confs = replaceWildcards(options.getConfs(), md);
                Set<String> confsToRemove = new HashSet<>(Arrays.asList(md.getConfigurationsNames()));
                confsToRemove.removeAll(Arrays.asList(confs));
                try {
                    XmlModuleDescriptorUpdater.update(ivyFileURL, tmp, new UpdateOptions().setSettings(settings).setStatus(options.getStatus() == null ? md.getStatus() : options.getStatus()).setRevision(options.getPubrevision()).setBranch(options.getPubBranch()).setPubdate(options.getPubdate() == null ? new Date() : options.getPubdate()).setMerge(options.isMerge()).setMergedDescriptor(md).setConfsToExclude(confsToRemove.toArray(new String[confsToRemove.size()])));
                    ivyFile = tmp;
                    // we parse the new file to get updated module descriptor
                    md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyFile.toURI().toURL(), false);
                    options.setSrcIvyPattern(ivyFile.getAbsolutePath());
                } catch (SAXException e) {
                    throw new IllegalStateException("bad ivy file for " + mrid + ": " + ivyFile + ": " + e);
                }
            } else if (!options.getPubrevision().equals(md.getModuleRevisionId().getRevision())) {
                throw new IllegalArgumentException("cannot publish " + ivyFile + " as " + options.getPubrevision() + ": bad revision found in ivy file (Revision: " + md.getModuleRevisionId().getRevision() + "). Use forcedeliver or update.");
            }
        } catch (ParseException e) {
            throw new IllegalStateException("bad ivy file for " + mrid + ": " + ivyFile + ": " + e);
        }
    } else {
        ResolutionCacheManager cacheManager = settings.getResolutionCacheManager();
        try {
            md = cacheManager.getResolvedModuleDescriptor(mrid);
        } catch (ParseException e) {
            throw new IllegalStateException("bad ivy file in cache for " + mrid + ": " + e);
        }
        md.setResolvedModuleRevisionId(pubmrid);
    }
    DependencyResolver resolver = settings.getResolver(resolverName);
    if (resolver == null) {
        throw new IllegalArgumentException("unknown resolver " + resolverName);
    }
    // collect all declared artifacts of this module
    Collection<Artifact> missing = publish(md, srcArtifactPattern, resolver, options);
    Message.verbose("\tpublish done (" + (System.currentTimeMillis() - start) + "ms)");
    return missing;
}
Also used : ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) Date(java.util.Date) URL(java.net.URL) UpdateOptions(org.apache.ivy.plugins.parser.xml.UpdateOptions) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) MDArtifact(org.apache.ivy.core.module.descriptor.MDArtifact) SAXException(org.xml.sax.SAXException) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ParseException(java.text.ParseException) File(java.io.File) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 14 with DependencyResolver

use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.

the class PomModuleDescriptorParserTest method createIvySettingsForParentLicenseTesting.

private IvySettings createIvySettingsForParentLicenseTesting(final String parentPomFileName, final String parentOrgName, final String parentModuleName) throws Exception {
    final URL parentPomURL = this.getClass().getResource(parentPomFileName);
    assertNotNull("Could not find " + parentPomFileName, parentPomURL);
    final PomReader parentPomReader = new PomReader(parentPomURL, new URLResource(parentPomURL));
    final License[] parentLicenses = parentPomReader.getLicenses();
    assertNotNull("Missing licenses in parent pom " + parentPomFileName, parentLicenses);
    assertEquals("Unexpected number of licenses in parent pom " + parentPomFileName, 1, parentLicenses.length);
    final DependencyResolver dependencyResolver = new MockedDependencyResolver() {

        @Override
        protected ModuleDescriptor getModuleDescriptor(DependencyDescriptor dependencyDescriptor) {
            final String depOrg = dependencyDescriptor.getDependencyId().getOrganisation();
            final String depModuleName = dependencyDescriptor.getDependencyId().getName();
            if (depOrg.equals(parentOrgName) && depModuleName.equals(parentModuleName)) {
                final DefaultModuleDescriptor moduleDescriptor = DefaultModuleDescriptor.newDefaultInstance(dependencyDescriptor.getDependencyRevisionId());
                for (final License license : parentLicenses) {
                    moduleDescriptor.addLicense(license);
                }
                return moduleDescriptor;
            } else {
                return super.getModuleDescriptor(dependencyDescriptor);
            }
        }
    };
    final IvySettings ivySettings = new IvySettings();
    ivySettings.setDictatorResolver(dependencyResolver);
    return ivySettings;
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) License(org.apache.ivy.core.module.descriptor.License) IvySettings(org.apache.ivy.core.settings.IvySettings) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) URL(java.net.URL) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 15 with DependencyResolver

use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.

the class OnlineXmlSettingsParserTest method testIncludeHttpUrl.

// remote.test
@Test
public void testIncludeHttpUrl() throws Exception {
    configureURLHandler();
    IvySettings settings = new IvySettings();
    XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(new URL("http://ant.apache.org/ivy/test/ivysettings-include-http-url.xml"));
    DependencyResolver resolver = settings.getResolver("ivyrep");
    assertNotNull(resolver);
    assertTrue(resolver instanceof IvyRepResolver);
}
Also used : URL(java.net.URL) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) IvyRepResolver(org.apache.ivy.plugins.resolver.IvyRepResolver) Test(org.junit.Test)

Aggregations

DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)50 Test (org.junit.Test)23 ModuleDescriptorParserRegistryTest (org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)11 ChainResolver (org.apache.ivy.plugins.resolver.ChainResolver)11 File (java.io.File)10 Ivy (org.apache.ivy.Ivy)9 HashMap (java.util.HashMap)8 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)8 URL (java.net.URL)7 HashSet (java.util.HashSet)7 Map (java.util.Map)7 LinkedHashSet (java.util.LinkedHashSet)6 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)6 IvySettings (org.apache.ivy.core.settings.IvySettings)6 FileSystemResolver (org.apache.ivy.plugins.resolver.FileSystemResolver)6 ParseException (java.text.ParseException)5 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)5 IvyRepResolver (org.apache.ivy.plugins.resolver.IvyRepResolver)5 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)4 ModuleId (org.apache.ivy.core.module.id.ModuleId)4