use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class IvyArtifactReport method doExecute.
public void doExecute() throws BuildException {
prepareAndCheck();
if (tofile == null) {
throw new BuildException("no destination file name: please provide it through parameter 'tofile'");
}
pattern = getProperty(pattern, getSettings(), "ivy.retrieve.pattern");
try {
String[] confs = splitToArray(getConf());
ModuleDescriptor md = null;
if (getResolveId() == null) {
md = getResolvedDescriptor(getOrganisation(), getModule(), false);
} else {
md = getResolvedDescriptor(getResolveId());
}
IvyNode[] dependencies = getIvyInstance().getResolveEngine().getDependencies(md, ((ResolveOptions) new ResolveOptions().setLog(getLog())).setConfs(confs).setResolveId(getResolveId()).setValidate(doValidate(getSettings())), null);
Map<ArtifactDownloadReport, Set<String>> artifactsToCopy = getIvyInstance().getRetrieveEngine().determineArtifactsToCopy(ModuleRevisionId.newInstance(getOrganisation(), getModule(), getRevision()), pattern, ((RetrieveOptions) new RetrieveOptions().setLog(getLog())).setConfs(confs).setResolveId(getResolveId()));
Map<ModuleRevisionId, Set<ArtifactDownloadReport>> moduleRevToArtifactsMap = new HashMap<>();
for (ArtifactDownloadReport artifact : artifactsToCopy.keySet()) {
Set<ArtifactDownloadReport> moduleRevArtifacts = moduleRevToArtifactsMap.get(artifact.getArtifact().getModuleRevisionId());
if (moduleRevArtifacts == null) {
moduleRevArtifacts = new HashSet<>();
moduleRevToArtifactsMap.put(artifact.getArtifact().getModuleRevisionId(), moduleRevArtifacts);
}
moduleRevArtifacts.add(artifact);
}
generateXml(dependencies, moduleRevToArtifactsMap, artifactsToCopy);
} catch (ParseException e) {
log(e.getMessage(), Project.MSG_ERR);
throw new BuildException("syntax errors in ivy file: " + e, e);
} catch (IOException e) {
throw new BuildException("impossible to generate report: " + e, e);
}
}
use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class IvyBuildList method doExecute.
@Override
public void doExecute() throws BuildException {
if (reference == null) {
throw new BuildException("reference should be provided in ivy build list");
}
if (buildFileSets.isEmpty()) {
throw new BuildException("at least one nested fileset should be provided in ivy build list");
}
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
ivyFilePath = getProperty(ivyFilePath, settings, "ivy.buildlist.ivyfilepath");
Path path = new Path(getProject());
Map<ModuleDescriptor, File> buildFiles = new HashMap<>();
List<File> independent = new ArrayList<>();
List<File> noDescriptor = new ArrayList<>();
Collection<ModuleDescriptor> mds = new ArrayList<>();
Set<String> rootModuleNames = new LinkedHashSet<>();
if (!"*".equals(root)) {
StringTokenizer st = new StringTokenizer(root, delimiter);
while (st.hasMoreTokens()) {
rootModuleNames.add(st.nextToken());
}
}
Set<String> leafModuleNames = new LinkedHashSet<>();
if (!"*".equals(leaf)) {
StringTokenizer st = new StringTokenizer(leaf, delimiter);
while (st.hasMoreTokens()) {
leafModuleNames.add(st.nextToken());
}
}
Set<String> restartFromModuleNames = new LinkedHashSet<>();
if (!"*".equals(restartFrom)) {
StringTokenizer st = new StringTokenizer(restartFrom, delimiter);
// Only accept one (first) module
restartFromModuleNames.add(st.nextToken());
}
for (FileSet fs : buildFileSets) {
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
for (String build : ds.getIncludedFiles()) {
File buildFile = new File(ds.getBasedir(), build);
File ivyFile = getIvyFileFor(buildFile);
if (!ivyFile.exists()) {
onMissingDescriptor(buildFile, ivyFile, noDescriptor);
} else {
try {
ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor(settings, ivyFile.toURI().toURL(), doValidate(settings));
buildFiles.put(md, buildFile);
mds.add(md);
Message.debug("Add " + md.getModuleRevisionId().getModuleId());
} catch (Exception ex) {
if (haltOnError) {
throw new BuildException("impossible to parse ivy file for " + buildFile + ": ivyfile=" + ivyFile + " exception=" + ex, ex);
} else {
Message.warn("impossible to parse ivy file for " + buildFile + ": ivyfile=" + ivyFile + " exception=" + ex.getMessage());
Message.info("\t=> adding it at the beginning of the path");
independent.add(buildFile);
}
}
}
}
}
List<ModuleDescriptor> leafModuleDescriptors = convertModuleNamesToModuleDescriptors(mds, leafModuleNames, "leaf");
List<ModuleDescriptor> rootModuleDescriptors = convertModuleNamesToModuleDescriptors(mds, rootModuleNames, "root");
List<ModuleDescriptor> restartFromModuleDescriptors = convertModuleNamesToModuleDescriptors(mds, restartFromModuleNames, "restartFrom");
if (!rootModuleDescriptors.isEmpty()) {
Message.info("Filtering modules based on roots " + rootModuleNames);
mds = filterModulesFromRoot(mds, rootModuleDescriptors);
}
if (!leafModuleDescriptors.isEmpty()) {
Message.info("Filtering modules based on leafs " + leafModuleNames);
mds = filterModulesFromLeaf(mds, leafModuleDescriptors);
}
List<ModuleDescriptor> sortedModules = ivy.sortModuleDescriptors(mds, SortOptions.DEFAULT);
if (!OnMissingDescriptor.TAIL.equals(onMissingDescriptor)) {
for (File buildFile : noDescriptor) {
addBuildFile(path, buildFile);
}
}
for (File buildFile : independent) {
addBuildFile(path, buildFile);
}
if (isReverse()) {
Collections.reverse(sortedModules);
}
// so they are not removed from build path.
if (!restartFromModuleDescriptors.isEmpty()) {
boolean foundRestartFrom = false;
List<ModuleDescriptor> keptModules = new ArrayList<>();
ModuleDescriptor restartFromModuleDescriptor = restartFromModuleDescriptors.get(0);
for (ModuleDescriptor md : sortedModules) {
if (md.equals(restartFromModuleDescriptor)) {
foundRestartFrom = true;
}
if (foundRestartFrom) {
keptModules.add(md);
}
}
sortedModules = keptModules;
}
StringBuilder order = new StringBuilder();
for (ModuleDescriptor md : sortedModules) {
if (order.length() > 0) {
order.append(", ");
}
order.append(md.getModuleRevisionId().getModuleId());
addBuildFile(path, buildFiles.get(md));
}
if (OnMissingDescriptor.TAIL.equals(onMissingDescriptor)) {
for (File buildFile : noDescriptor) {
addBuildFile(path, buildFile);
}
}
getProject().addReference(getReference(), path);
getProject().setProperty("ivy.sorted.modules", order.toString());
}
use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class IvyBuildList method filterModulesFromRoot.
/**
* Returns a collection of ModuleDescriptors that are contained in the input collection of
* ModuleDescriptors and upon which the root module depends
*
* @param mds
* input collection of ModuleDescriptors
* @param rootmds
* root module
* @return filtered list of modules
*/
private Collection<ModuleDescriptor> filterModulesFromRoot(Collection<ModuleDescriptor> mds, List<ModuleDescriptor> rootmds) {
Map<ModuleId, ModuleDescriptor> moduleIdMap = new HashMap<>();
for (ModuleDescriptor md : mds) {
moduleIdMap.put(md.getModuleRevisionId().getModuleId(), md);
}
// recursively process the nodes
Set<ModuleDescriptor> toKeep = new LinkedHashSet<>();
for (ModuleDescriptor rootmd : rootmds) {
processFilterNodeFromRoot(rootmd, toKeep, moduleIdMap);
// With the excluderoot attribute set to true, take the rootmd out of the toKeep set.
if (excludeRoot) {
// Only for logging purposes
Message.verbose("Excluded module " + rootmd.getModuleRevisionId().getModuleId().getName());
} else {
toKeep.add(rootmd);
}
}
// just for logging
for (ModuleDescriptor md : toKeep) {
Message.verbose("Kept module " + md.getModuleRevisionId().getModuleId().getName());
}
return toKeep;
}
use of org.apache.ivy.core.module.descriptor.ModuleDescriptor 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();
}
use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class AbstractOSGiResolver method findIvyFileRef.
public ResolvedResource findIvyFileRef(DependencyDescriptor dd, ResolveData data) {
ModuleRevisionId mrid = dd.getDependencyRevisionId();
String osgiType = mrid.getOrganisation();
if (osgiType == null) {
throw new RuntimeException("Unsupported OSGi module Id: " + mrid.getModuleId());
}
String id = mrid.getName();
Collection<ModuleDescriptor> mds = ModuleDescriptorWrapper.unwrap(getRepoDescriptor().findModules(osgiType, id));
if (mds == null || mds.isEmpty()) {
Message.verbose("\t " + id + " not found.");
return null;
}
ResolvedResource[] ret;
if (BundleInfo.BUNDLE_TYPE.equals(osgiType)) {
ret = findBundle(dd, data, mds);
} else {
ret = findCapability(dd, data, mds);
}
ResolvedResource found = findResource(ret, getDefaultRMDParser(dd.getDependencyId()), mrid, data.getDate());
if (found == null) {
Message.debug("\t" + getName() + ": no resource found for " + mrid);
}
return found;
}
Aggregations