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;
}
}
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);
}
}
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);
}
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");
}
}
}
}
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);
}
Aggregations