use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.
the class IvyDependencyExclude method asRule.
DefaultExcludeRule asRule(IvySettings settings) {
String matcherName = (matcher == null) ? PatternMatcher.EXACT : matcher;
String orgPattern = (org == null) ? PatternMatcher.ANY_EXPRESSION : org;
String modulePattern = (module == null) ? PatternMatcher.ANY_EXPRESSION : module;
String namePattern = (name == null) ? PatternMatcher.ANY_EXPRESSION : name;
String typePattern = (type == null) ? PatternMatcher.ANY_EXPRESSION : type;
String extPattern = (ext == null) ? typePattern : ext;
ArtifactId aid = new ArtifactId(new ModuleId(orgPattern, modulePattern), namePattern, typePattern, extPattern);
return new DefaultExcludeRule(aid, settings.getMatcher(matcherName), null);
}
use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.
the class IvyDependencyInclude method asRule.
DefaultIncludeRule asRule(IvySettings settings) {
String matcherName = matcher == null ? PatternMatcher.EXACT : matcher;
String namePattern = name == null ? PatternMatcher.ANY_EXPRESSION : name;
String typePattern = type == null ? PatternMatcher.ANY_EXPRESSION : type;
String extPattern = ext == null ? typePattern : ext;
ArtifactId aid = new ArtifactId(new ModuleId(PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION), namePattern, typePattern, extPattern);
return new DefaultIncludeRule(aid, settings.getMatcher(matcherName), null);
}
use of org.apache.ivy.core.module.id.ModuleId 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.id.ModuleId in project ant-ivy by apache.
the class FixDepsTask method doExecute.
@Override
public void doExecute() throws BuildException {
prepareAndCheck();
if (dest == null) {
throw new BuildException("Missing required parameter 'tofile'");
}
if (dest.exists() && dest.isDirectory()) {
throw new BuildException("The destination file '" + dest.getAbsolutePath() + "' already exist and is a folder");
}
ResolveReport report = getResolvedReport();
List<ModuleId> midToKeep = new ArrayList<>();
for (Keep keep : keeps) {
midToKeep.add(ModuleId.newInstance(keep.org, keep.module));
}
ModuleDescriptor md = report.toFixedModuleDescriptor(getSettings(), midToKeep);
try {
XmlModuleDescriptorWriter.write(md, dest);
} catch (IOException e) {
throw new BuildException("Failed to write into the file " + dest.getAbsolutePath() + " (" + e.getMessage() + ")", e);
}
}
use of org.apache.ivy.core.module.id.ModuleId 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;
}
Aggregations