use of org.apache.ivy.core.module.descriptor.Configuration in project ant-ivy by apache.
the class IvyInfo method setProperties.
private void setProperties(ModuleDescriptor md, ModuleRevisionId mrid) {
getProject().setProperty(property + ".organisation", mrid.getOrganisation());
getProject().setProperty(property + ".module", mrid.getName());
if (mrid.getBranch() != null) {
getProject().setProperty(property + ".branch", mrid.getBranch());
}
getProject().setProperty(property + ".revision", mrid.getRevision());
getProject().setProperty(property + ".status", md.getStatus());
if (md.getPublicationDate() != null) {
getProject().setProperty(property + ".publication", Long.toString(md.getPublicationDate().getTime()));
}
for (Map.Entry<String, String> entry : mrid.getExtraAttributes().entrySet()) {
getProject().setProperty(property + ".extra." + entry.getKey(), entry.getValue());
}
getProject().setProperty(property + ".configurations", mergeConfs(md.getConfigurationsNames()));
// store the public configurations in a separate property
List<String> publicConfigsList = new ArrayList<>();
for (Configuration config : md.getConfigurations()) {
String name = config.getName();
if (PUBLIC.equals(config.getVisibility())) {
publicConfigsList.add(name);
}
if (config.getDescription() != null) {
getProject().setProperty(property + ".configuration." + name + ".desc", config.getDescription());
}
}
String[] publicConfigs = publicConfigsList.toArray(new String[publicConfigsList.size()]);
getProject().setProperty(property + ".public.configurations", mergeConfs(publicConfigs));
List<Artifact> artifacts = Arrays.asList(md.getAllArtifacts());
for (Artifact artifact : artifacts) {
int id = artifacts.indexOf(artifact) + 1;
getProject().setProperty(property + ".artifact." + id + ".name", artifact.getName());
getProject().setProperty(property + ".artifact." + id + ".type", artifact.getType());
getProject().setProperty(property + ".artifact." + id + ".ext", artifact.getExt());
getProject().setProperty(property + ".artifact." + id + ".conf", mergeConfs(artifact.getConfigurations()));
for (Map.Entry<String, String> entry : artifact.getExtraAttributes().entrySet()) {
getProject().setProperty(property + ".artifact." + id + ".extra." + entry.getKey(), entry.getValue());
}
}
}
use of org.apache.ivy.core.module.descriptor.Configuration in project ant-ivy by apache.
the class IvyDependencyUpdateChecker method doExecute.
public void doExecute() throws BuildException {
prepareAndCheck();
ModuleDescriptor originalModuleDescriptor = getResolvedReport().getModuleDescriptor();
// clone module descriptor
DefaultModuleDescriptor latestModuleDescriptor = new DefaultModuleDescriptor(originalModuleDescriptor.getModuleRevisionId(), originalModuleDescriptor.getStatus(), originalModuleDescriptor.getPublicationDate());
// copy configurations
for (Configuration configuration : originalModuleDescriptor.getConfigurations()) {
latestModuleDescriptor.addConfiguration(configuration);
}
// clone dependency and add new one with the requested revisionToCheck
for (DependencyDescriptor dependencyDescriptor : originalModuleDescriptor.getDependencies()) {
ModuleRevisionId upToDateMrid = ModuleRevisionId.newInstance(dependencyDescriptor.getDependencyRevisionId(), revisionToCheck);
latestModuleDescriptor.addDependency(dependencyDescriptor.clone(upToDateMrid));
}
// resolve
ResolveOptions resolveOptions = new ResolveOptions();
resolveOptions.setDownload(isDownload());
resolveOptions.setLog(getLog());
resolveOptions.setConfs(splitToArray(getConf()));
resolveOptions.setCheckIfChanged(checkIfChanged);
ResolveReport latestReport;
try {
latestReport = getIvyInstance().getResolveEngine().resolve(latestModuleDescriptor, resolveOptions);
displayDependencyUpdates(getResolvedReport(), latestReport);
if (showTransitive) {
displayNewDependencyOnLatest(getResolvedReport(), latestReport);
displayMissingDependencyOnLatest(getResolvedReport(), latestReport);
}
} catch (ParseException | IOException e) {
throw new BuildException("impossible to resolve dependencies:\n\t" + e, e);
}
}
use of org.apache.ivy.core.module.descriptor.Configuration in project ant-ivy by apache.
the class InstallEngine method install.
public ResolveReport install(ModuleRevisionId mrid, String from, String to, InstallOptions options) throws IOException {
DependencyResolver fromResolver = settings.getResolver(from);
DependencyResolver toResolver = settings.getResolver(to);
if (fromResolver == null) {
throw new IllegalArgumentException("unknown resolver " + from + ". Available resolvers are: " + settings.getResolverNames());
}
if (toResolver == null) {
throw new IllegalArgumentException("unknown resolver " + to + ". Available resolvers are: " + settings.getResolverNames());
}
PatternMatcher matcher = settings.getMatcher(options.getMatcherName());
if (matcher == null) {
throw new IllegalArgumentException("unknown matcher " + options.getMatcherName() + ". Available matchers are: " + settings.getMatcherNames());
}
// build module file declaring the dependency
Message.info(":: installing " + mrid + " ::");
DependencyResolver oldDictator = resolveEngine.getDictatorResolver();
boolean log = settings.logNotConvertedExclusionRule();
try {
settings.setLogNotConvertedExclusionRule(true);
resolveEngine.setDictatorResolver(fromResolver);
DefaultModuleDescriptor md = new DefaultModuleDescriptor(ModuleRevisionId.newInstance("apache", "ivy-install", "1.0"), settings.getStatusManager().getDefaultStatus(), new Date());
String resolveId = ResolveOptions.getDefaultResolveId(md);
md.addConfiguration(new Configuration("default"));
md.addConflictManager(new ModuleId(ExactPatternMatcher.ANY_EXPRESSION, ExactPatternMatcher.ANY_EXPRESSION), ExactPatternMatcher.INSTANCE, new NoConflictManager());
for (String dc : options.getConfs()) {
final String depConf = dc.trim();
if (MatcherHelper.isExact(matcher, mrid)) {
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, mrid, false, false, options.isTransitive());
dd.addDependencyConfiguration("default", depConf);
md.addDependency(dd);
} else {
for (ModuleRevisionId imrid : searchEngine.listModules(fromResolver, mrid, matcher)) {
Message.info("\tfound " + imrid + " to install: adding to the list");
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, imrid, false, false, options.isTransitive());
dd.addDependencyConfiguration("default", depConf);
md.addDependency(dd);
}
}
}
// resolve using appropriate resolver
ResolveReport report = new ResolveReport(md, resolveId);
Message.info(":: resolving dependencies ::");
ResolveOptions resolveOptions = new ResolveOptions().setResolveId(resolveId).setConfs(new String[] { "default" }).setValidate(options.isValidate());
IvyNode[] dependencies = resolveEngine.getDependencies(md, resolveOptions, report);
report.setDependencies(Arrays.asList(dependencies), options.getArtifactFilter());
Message.info(":: downloading artifacts to cache ::");
resolveEngine.downloadArtifacts(report, options.getArtifactFilter(), new DownloadOptions());
// now that everything is in cache, we can publish all these modules
Message.info(":: installing in " + to + " ::");
for (IvyNode dependency : dependencies) {
ModuleDescriptor depmd = dependency.getDescriptor();
if (depmd != null) {
ModuleRevisionId depMrid = depmd.getModuleRevisionId();
Message.verbose("installing " + depMrid);
boolean successfullyPublished = false;
try {
toResolver.beginPublishTransaction(depMrid, options.isOverwrite());
// publish artifacts
for (ArtifactDownloadReport artifact : report.getArtifactsReports(depMrid)) {
if (artifact.getLocalFile() != null) {
toResolver.publish(artifact.getArtifact(), artifact.getLocalFile(), options.isOverwrite());
}
}
// publish metadata
MetadataArtifactDownloadReport artifactDownloadReport = dependency.getModuleRevision().getReport();
File localIvyFile = artifactDownloadReport.getLocalFile();
toResolver.publish(depmd.getMetadataArtifact(), localIvyFile, options.isOverwrite());
if (options.isInstallOriginalMetadata()) {
if (artifactDownloadReport.getArtifactOrigin() != null && artifactDownloadReport.getArtifactOrigin().isExists() && !ArtifactOrigin.isUnknown(artifactDownloadReport.getArtifactOrigin()) && artifactDownloadReport.getArtifactOrigin().getArtifact() != null && artifactDownloadReport.getArtifactOrigin().getArtifact().getType().endsWith(".original") && !artifactDownloadReport.getArtifactOrigin().getArtifact().getType().equals(depmd.getMetadataArtifact().getType() + ".original")) {
// publish original metadata artifact, too, as it has a different
// type
toResolver.publish(artifactDownloadReport.getArtifactOrigin().getArtifact(), artifactDownloadReport.getOriginalLocalFile(), options.isOverwrite());
}
}
// end module publish
toResolver.commitPublishTransaction();
successfullyPublished = true;
} finally {
if (!successfullyPublished) {
toResolver.abortPublishTransaction();
}
}
}
}
Message.info(":: install resolution report ::");
// output report
resolveEngine.outputReport(report, settings.getResolutionCacheManager(), resolveOptions);
return report;
} finally {
// IVY-834: log the problems if there were any...
Message.sumupProblems();
resolveEngine.setDictatorResolver(oldDictator);
settings.setLogNotConvertedExclusionRule(log);
}
}
use of org.apache.ivy.core.module.descriptor.Configuration in project ant-ivy by apache.
the class ConfigurationUtils method replaceWildcards.
/**
* Replace the wildcards in the given configuration array, by the name of the given
* ModuleDescriptor
*
* The supported wildcards are:
* <ul>
* <li><b><tt>*</tt> :</b> all configurations</li>
* <li><b><tt>*(public)</tt> :</b> all public configurations</li>
* <li><b><tt>*(private)</tt> :</b> all private configurations</li>
* </ul>
* If the given array of configurations is <code>null</code>, all configurations from the given
* module descriptor are returned, including if this array is empty.
*
* @param confs
* the configurations, can contain wildcards
* @param md
* the configurations where the wildcards are replaced
* @return configurations
*/
public static String[] replaceWildcards(String[] confs, ModuleDescriptor md) {
if (confs == null) {
return md.getConfigurationsNames();
}
Set<String> result = new LinkedHashSet<>();
Set<String> excluded = new LinkedHashSet<>();
for (String conf : confs) {
if ("*".equals(conf)) {
result.addAll(Arrays.asList(md.getConfigurationsNames()));
} else if ("*(public)".equals(conf)) {
for (Configuration cf : md.getConfigurations()) {
if (PUBLIC.equals(cf.getVisibility())) {
result.add(cf.getName());
}
}
} else if ("*(private)".equals(conf)) {
for (Configuration cf : md.getConfigurations()) {
if (PRIVATE.equals(cf.getVisibility())) {
result.add(cf.getName());
}
}
} else if (conf.startsWith("!")) {
excluded.add(conf.substring(1));
} else {
result.add(conf);
}
}
for (String ex : excluded) {
result.remove(ex);
}
return result.toArray(new String[result.size()]);
}
use of org.apache.ivy.core.module.descriptor.Configuration in project ant-ivy by apache.
the class PomModuleDescriptorParser method parseDescriptor.
public ModuleDescriptor parseDescriptor(ParserSettings ivySettings, URL descriptorURL, Resource res, boolean validate) throws ParseException, IOException {
PomModuleDescriptorBuilder mdBuilder = new PomModuleDescriptorBuilder(this, res, ivySettings);
try {
final IvyContext ivyContext = IvyContext.pushNewCopyContext();
HashSet<ModuleRevisionId> parents = ivyContext.get(PARENT_MAP_KEY);
if (parents == null) {
parents = new LinkedHashSet<>();
ivyContext.set(PARENT_MAP_KEY, parents);
}
PomReader domReader = new PomReader(descriptorURL, res);
domReader.setProperty("parent.version", domReader.getParentVersion());
domReader.setProperty("parent.groupId", domReader.getParentGroupId());
domReader.setProperty("project.parent.version", domReader.getParentVersion());
domReader.setProperty("project.parent.groupId", domReader.getParentGroupId());
Message.debug("parent.groupId: " + domReader.getParentGroupId());
Message.debug("parent.artifactId: " + domReader.getParentArtifactId());
Message.debug("parent.version: " + domReader.getParentVersion());
for (final Map.Entry<String, String> prop : domReader.getPomProperties().entrySet()) {
domReader.setProperty(prop.getKey(), prop.getValue());
mdBuilder.addProperty(prop.getKey(), prop.getValue());
}
final List<PomProfileElement> activeProfiles = new ArrayList<>();
// add profile specific properties
for (final PomProfileElement profile : domReader.getProfiles()) {
if (!profile.isActive()) {
continue;
}
// keep track of this active profile for later use
activeProfiles.add(profile);
final Map<String, String> profileProps = profile.getProfileProperties();
if (profileProps.isEmpty()) {
continue;
}
for (final Map.Entry<String, String> entry : profileProps.entrySet()) {
domReader.setProperty(entry.getKey(), entry.getValue());
mdBuilder.addProperty(entry.getKey(), entry.getValue());
}
}
ModuleDescriptor parentDescr = null;
if (domReader.hasParent()) {
// Is there any other parent properties?
ModuleRevisionId parentModRevID = ModuleRevisionId.newInstance(domReader.getParentGroupId(), domReader.getParentArtifactId(), domReader.getParentVersion());
// check for cycles
if (parents.contains(parentModRevID)) {
throw new CircularDependencyException(parents);
} else {
parents.add(parentModRevID);
}
ResolvedModuleRevision parentModule = parseOtherPom(ivySettings, parentModRevID);
if (parentModule == null) {
throw new IOException("Impossible to load parent for " + res.getName() + ". Parent=" + parentModRevID);
}
parentDescr = parentModule.getDescriptor();
if (parentDescr != null) {
for (Map.Entry<String, String> prop : extractPomProperties(parentDescr.getExtraInfos()).entrySet()) {
domReader.setProperty(prop.getKey(), prop.getValue());
}
}
}
String groupId = domReader.getGroupId();
String artifactId = domReader.getArtifactId();
String version = domReader.getVersion();
mdBuilder.setModuleRevId(groupId, artifactId, version);
mdBuilder.setHomePage(domReader.getHomePage());
mdBuilder.setDescription(domReader.getDescription());
// if this module doesn't have an explicit license, use the parent's license (if any)
final License[] licenses = domReader.getLicenses();
if (licenses != null && licenses.length > 0) {
mdBuilder.setLicenses(licenses);
} else if (parentDescr != null) {
mdBuilder.setLicenses(parentDescr.getLicenses());
}
ModuleRevisionId relocation = domReader.getRelocation();
if (relocation != null) {
if (groupId != null && artifactId != null && artifactId.equals(relocation.getName()) && groupId.equals(relocation.getOrganisation())) {
Message.error("Relocation to an other version number not supported in ivy : " + mdBuilder.getModuleDescriptor().getModuleRevisionId() + " relocated to " + relocation + ". Please update your dependency to directly use the right version.");
Message.warn("Resolution will only pick dependencies of the relocated element." + " Artifact and other metadata will be ignored.");
ResolvedModuleRevision relocatedModule = parseOtherPom(ivySettings, relocation);
if (relocatedModule == null) {
throw new ParseException("impossible to load module " + relocation + " to which " + mdBuilder.getModuleDescriptor().getModuleRevisionId() + " has been relocated", 0);
}
for (DependencyDescriptor dd : relocatedModule.getDescriptor().getDependencies()) {
mdBuilder.addDependency(dd);
}
} else {
Message.info(mdBuilder.getModuleDescriptor().getModuleRevisionId() + " is relocated to " + relocation + ". Please update your dependencies.");
Message.verbose("Relocated module will be considered as a dependency");
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(mdBuilder.getModuleDescriptor(), relocation, true, false, true);
/* Map all public dependencies */
for (Configuration m2Conf : MAVEN2_CONFIGURATIONS) {
if (PUBLIC.equals(m2Conf.getVisibility())) {
dd.addDependencyConfiguration(m2Conf.getName(), m2Conf.getName());
}
}
mdBuilder.addDependency(dd);
}
} else {
domReader.setProperty("project.groupId", groupId);
domReader.setProperty("pom.groupId", groupId);
domReader.setProperty("groupId", groupId);
domReader.setProperty("project.artifactId", artifactId);
domReader.setProperty("pom.artifactId", artifactId);
domReader.setProperty("artifactId", artifactId);
domReader.setProperty("project.version", version);
domReader.setProperty("pom.version", version);
domReader.setProperty("version", version);
if (parentDescr != null) {
mdBuilder.addExtraInfos(parentDescr.getExtraInfos());
// add dependency management info from parent
for (PomDependencyMgt dep : getDependencyManagements(parentDescr)) {
if (dep instanceof PomDependencyMgtElement) {
dep = domReader.new PomDependencyMgtElement((PomDependencyMgtElement) dep);
}
mdBuilder.addDependencyMgt(dep);
}
// add plugins from parent
for (PomDependencyMgt pomDependencyMgt : getPlugins(parentDescr)) {
mdBuilder.addPlugin(pomDependencyMgt);
}
}
for (PomDependencyMgt dep : domReader.getDependencyMgt()) {
addTo(mdBuilder, dep, ivySettings);
}
for (PomDependencyData dep : domReader.getDependencies()) {
mdBuilder.addDependency(res, dep);
}
for (PomPluginElement plugin : domReader.getPlugins()) {
mdBuilder.addPlugin(plugin);
}
// consult active profiles:
for (final PomProfileElement activeProfile : activeProfiles) {
for (PomDependencyMgt dep : activeProfile.getDependencyMgt()) {
addTo(mdBuilder, dep, ivySettings);
}
for (PomDependencyData dep : activeProfile.getDependencies()) {
mdBuilder.addDependency(res, dep);
}
for (PomPluginElement plugin : activeProfile.getPlugins()) {
mdBuilder.addPlugin(plugin);
}
}
if (parentDescr != null) {
for (DependencyDescriptor descriptor : parentDescr.getDependencies()) {
if (descriptor instanceof PomDependencyDescriptor) {
PomDependencyData parentDep = ((PomDependencyDescriptor) descriptor).getPomDependencyData();
PomDependencyData dep = domReader.new PomDependencyData(parentDep);
mdBuilder.addDependency(res, dep);
} else {
mdBuilder.addDependency(descriptor);
}
}
}
mdBuilder.addMainArtifact(artifactId, domReader.getPackaging());
addSourcesAndJavadocArtifactsIfPresent(mdBuilder, ivySettings);
}
} catch (SAXException e) {
throw newParserException(e);
} finally {
IvyContext.popContext();
}
return mdBuilder.getModuleDescriptor();
}
Aggregations