Search in sources :

Example 46 with DependencyResolver

use of org.apache.ivy.plugins.resolver.DependencyResolver 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 47 with DependencyResolver

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

the class IvyListModules method doExecute.

public void doExecute() throws BuildException {
    if (organisation == null) {
        throw new BuildException("no organisation provided for ivy listmodules task");
    }
    if (module == null) {
        throw new BuildException("no module name provided for ivy listmodules task");
    }
    if (revision == null) {
        throw new BuildException("no revision provided for ivy listmodules task");
    }
    if (property == null) {
        throw new BuildException("no property provided for ivy listmodules task");
    }
    if (value == null) {
        throw new BuildException("no value provided for ivy listmodules task");
    }
    Ivy ivy = getIvyInstance();
    IvySettings settings = ivy.getSettings();
    SearchEngine searcher = new SearchEngine(settings);
    PatternMatcher patternMatcher = settings.getMatcher(matcher);
    ModuleRevisionId[] mrids;
    if (resolver == null) {
        mrids = searcher.listModules(ModuleRevisionId.newInstance(organisation, module, branch, revision), patternMatcher);
    } else {
        DependencyResolver depResolver = settings.getResolver(resolver);
        if (depResolver == null) {
            throw new BuildException("Unknown resolver: " + resolver);
        }
        mrids = searcher.listModules(depResolver, ModuleRevisionId.newInstance(organisation, module, branch, revision), patternMatcher);
    }
    for (ModuleRevisionId mrid : mrids) {
        String name = IvyPatternHelper.substitute(settings.substitute(property), mrid);
        String value = IvyPatternHelper.substitute(settings.substitute(this.value), mrid);
        getProject().setProperty(name, value);
    }
}
Also used : SearchEngine(org.apache.ivy.core.search.SearchEngine) IvySettings(org.apache.ivy.core.settings.IvySettings) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) BuildException(org.apache.tools.ant.BuildException) Ivy(org.apache.ivy.Ivy) PatternMatcher(org.apache.ivy.plugins.matcher.PatternMatcher) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 48 with DependencyResolver

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

the class PomModuleDescriptorParser method parseOtherPom.

private ResolvedModuleRevision parseOtherPom(ParserSettings ivySettings, ModuleRevisionId parentModRevID) throws ParseException {
    DependencyDescriptor dd = new DefaultDependencyDescriptor(parentModRevID, true);
    ResolveData data = IvyContext.getContext().getResolveData();
    if (data == null) {
        ResolveEngine engine = IvyContext.getContext().getIvy().getResolveEngine();
        ResolveOptions options = new ResolveOptions();
        options.setDownload(false);
        data = new ResolveData(engine, options);
    }
    DependencyResolver resolver = ivySettings.getResolver(parentModRevID);
    if (resolver == null) {
        // TODO: Throw exception here?
        return null;
    }
    dd = toSystem(dd, ivySettings.getContextNamespace());
    return resolver.getDependency(dd, data);
}
Also used : ResolveEngine(org.apache.ivy.core.resolve.ResolveEngine) ResolveData(org.apache.ivy.core.resolve.ResolveData) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) PomDependencyDescriptor(org.apache.ivy.plugins.parser.m2.PomModuleDescriptorBuilder.PomDependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 49 with DependencyResolver

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

the class PomModuleDescriptorParser method addSourcesAndJavadocArtifactsIfPresent.

private void addSourcesAndJavadocArtifactsIfPresent(PomModuleDescriptorBuilder mdBuilder, ParserSettings ivySettings) {
    if (mdBuilder.getMainArtifact() == null) {
        // no main artifact in pom, we don't need to search for meta artifacts
        return;
    }
    boolean sourcesLookup = !"false".equals(ivySettings.getVariable("ivy.maven.lookup.sources"));
    boolean javadocLookup = !"false".equals(ivySettings.getVariable("ivy.maven.lookup.javadoc"));
    if (!sourcesLookup && !javadocLookup) {
        Message.debug("Sources and javadocs lookup disabled");
        return;
    }
    ModuleDescriptor md = mdBuilder.getModuleDescriptor();
    ModuleRevisionId mrid = md.getModuleRevisionId();
    DependencyResolver resolver = ivySettings.getResolver(mrid);
    if (resolver == null) {
        Message.debug("no resolver found for " + mrid + ": no source or javadoc artifact lookup");
    } else {
        ArtifactOrigin mainArtifact = resolver.locate(mdBuilder.getMainArtifact());
        if (!ArtifactOrigin.isUnknown(mainArtifact)) {
            String mainArtifactLocation = mainArtifact.getLocation();
            if (sourcesLookup) {
                ArtifactOrigin sourceArtifact = resolver.locate(mdBuilder.getSourceArtifact());
                if (!ArtifactOrigin.isUnknown(sourceArtifact) && !sourceArtifact.getLocation().equals(mainArtifactLocation)) {
                    Message.debug("source artifact found for " + mrid);
                    mdBuilder.addSourceArtifact();
                } else {
                    // it seems that sometimes the 'src' classifier is used instead of 'sources'
                    // Cfr. IVY-1138
                    ArtifactOrigin srcArtifact = resolver.locate(mdBuilder.getSrcArtifact());
                    if (!ArtifactOrigin.isUnknown(srcArtifact) && !srcArtifact.getLocation().equals(mainArtifactLocation)) {
                        Message.debug("source artifact found for " + mrid);
                        mdBuilder.addSrcArtifact();
                    } else {
                        Message.debug("no source artifact found for " + mrid);
                    }
                }
            } else {
                Message.debug("sources lookup disabled");
            }
            if (javadocLookup) {
                ArtifactOrigin javadocArtifact = resolver.locate(mdBuilder.getJavadocArtifact());
                if (!ArtifactOrigin.isUnknown(javadocArtifact) && !javadocArtifact.getLocation().equals(mainArtifactLocation)) {
                    Message.debug("javadoc artifact found for " + mrid);
                    mdBuilder.addJavadocArtifact();
                } else {
                    Message.debug("no javadoc artifact found for " + mrid);
                }
            } else {
                Message.debug("javadocs lookup disabled");
            }
        }
    }
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 50 with DependencyResolver

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

the class PomModuleDescriptorBuilder method addMainArtifact.

public void addMainArtifact(String artifactId, String packaging) {
    String ext;
    /*
         * TODO: we should make packaging to ext mapping configurable, since it's not possible to
         * cover all cases.
         */
    if ("pom".equals(packaging)) {
        // no artifact defined! Add the default artifact if it exist.
        DependencyResolver resolver = parserSettings.getResolver(mrid);
        if (resolver != null) {
            DefaultArtifact artifact = new DefaultArtifact(mrid, new Date(), artifactId, "jar", "jar");
            ArtifactOrigin artifactOrigin = resolver.locate(artifact);
            if (!ArtifactOrigin.isUnknown(artifactOrigin)) {
                mainArtifact = artifact;
                ivyModuleDescriptor.addArtifact("master", mainArtifact);
            }
        }
        return;
    } else if (JAR_PACKAGINGS.contains(packaging)) {
        ext = "jar";
    } else if ("pear".equals(packaging)) {
        ext = "phar";
    } else {
        ext = packaging;
    }
    mainArtifact = new DefaultArtifact(mrid, new Date(), artifactId, packaging, ext);
    ivyModuleDescriptor.addArtifact("master", mainArtifact);
}
Also used : ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Date(java.util.Date) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

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