use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.
the class XmlSettingsParserTest method testRef.
@Test
public void testRef() throws Exception {
IvySettings settings = new IvySettings();
XmlSettingsParser parser = new XmlSettingsParser(settings);
parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-ref.xml"));
DependencyResolver internal = settings.getResolver("internal");
assertNotNull(internal);
assertTrue(internal instanceof ChainResolver);
ChainResolver chain = (ChainResolver) internal;
List<DependencyResolver> subresolvers = chain.getResolvers();
assertNotNull(subresolvers);
assertEquals(2, subresolvers.size());
FileSystemResolver fsInt1 = (FileSystemResolver) subresolvers.get(0);
assertEquals("fs", fsInt1.getName());
List<String> ivyPatterns = fsInt1.getIvyPatterns();
assertNotNull(ivyPatterns);
assertEquals(1, ivyPatterns.size());
assertLocationEquals("sharedrep/[organisation]/[module]/ivys/ivy-[revision].xml", ivyPatterns.get(0));
DependencyResolver external = settings.getResolver("external");
assertNotNull(external);
assertTrue(external instanceof ChainResolver);
chain = (ChainResolver) external;
subresolvers = chain.getResolvers();
assertNotNull(subresolvers);
assertEquals(1, subresolvers.size());
FileSystemResolver fsInt2 = (FileSystemResolver) subresolvers.get(0);
assertEquals("fs", fsInt2.getName());
ivyPatterns = fsInt2.getIvyPatterns();
assertNotNull(ivyPatterns);
assertEquals(1, ivyPatterns.size());
assertLocationEquals("sharedrep/[organisation]/[module]/ivys/ivy-[revision].xml", ivyPatterns.get(0));
}
use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.
the class XmlSettingsParserTest method testIncludeSpecialCharInName.
@Test
public void testIncludeSpecialCharInName() throws Exception {
IvySettings settings = new IvySettings();
XmlSettingsParser parser = new XmlSettingsParser(settings);
parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-include-special.xml"));
DependencyResolver def = settings.getResolver("default");
assertNotNull(def);
assertTrue(def instanceof ChainResolver);
ChainResolver chain = (ChainResolver) def;
List<DependencyResolver> subresolvers = chain.getResolvers();
assertNotNull(subresolvers);
assertEquals(2, subresolvers.size());
FileSystemResolver fsInt1 = (FileSystemResolver) subresolvers.get(0);
assertEquals("default-fs1", fsInt1.getName());
List<String> ivyPatterns = fsInt1.getIvyPatterns();
assertNotNull(ivyPatterns);
assertEquals(1, ivyPatterns.size());
assertLocationEquals("path/to/myrep/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]", ivyPatterns.get(0));
DependencyResolver inc = settings.getResolver("includeworks");
assertNotNull(inc);
assertTrue(inc instanceof ChainResolver);
chain = (ChainResolver) inc;
subresolvers = chain.getResolvers();
assertNotNull(subresolvers);
assertEquals(2, subresolvers.size());
fsInt1 = (FileSystemResolver) subresolvers.get(0);
assertEquals("includeworks-fs1", fsInt1.getName());
ivyPatterns = fsInt1.getIvyPatterns();
assertNotNull(ivyPatterns);
assertEquals(1, ivyPatterns.size());
assertLocationEquals("included/myrep/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]", ivyPatterns.get(0));
// properties defined in included file should be available to including file (IVY-780)
assertEquals("myvalue", settings.getVariable("ivy.test.prop"));
}
use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.
the class ResolveEngine method resolve.
/**
* Resolve dependencies of a module described by a module descriptor.
* @param md ModuleDescriptor
* @param options ResolveOptions
* @return ResolveReport
* @throws ParseException if something goes wrong
* @throws IOException if something goes wrong
*/
public ResolveReport resolve(ModuleDescriptor md, ResolveOptions options) throws ParseException, IOException {
DependencyResolver oldDictator = getDictatorResolver();
IvyContext context = IvyContext.getContext();
try {
String[] confs = options.getConfs(md);
options.setConfs(confs);
if (options.getResolveId() == null) {
options.setResolveId(ResolveOptions.getDefaultResolveId(md));
}
eventManager.fireIvyEvent(new StartResolveEvent(md, confs));
long start = System.currentTimeMillis();
if (ResolveOptions.LOG_DEFAULT.equals(options.getLog())) {
Message.info(":: resolving dependencies :: " + md.getResolvedModuleRevisionId() + (options.isTransitive() ? "" : " [not transitive]"));
Message.info("\tconfs: " + Arrays.asList(confs));
} else {
Message.verbose(":: resolving dependencies :: " + md.getResolvedModuleRevisionId() + (options.isTransitive() ? "" : " [not transitive]"));
Message.verbose("\tconfs: " + Arrays.asList(confs));
}
Message.verbose("\tvalidate = " + options.isValidate());
Message.verbose("\trefresh = " + options.isRefresh());
ResolveReport report = new ResolveReport(md, options.getResolveId());
ResolveData data = new ResolveData(this, options);
context.setResolveData(data);
// resolve dependencies
IvyNode[] dependencies = getDependencies(md, options, report);
report.setDependencies(Arrays.asList(dependencies), options.getArtifactFilter());
if (options.getCheckIfChanged()) {
report.checkIfChanged();
}
// produce resolved ivy file and ivy properties in cache
ResolutionCacheManager cacheManager = settings.getResolutionCacheManager();
cacheManager.saveResolvedModuleDescriptor(md);
// we store the resolved dependencies revisions and statuses per asked dependency
// revision id, for direct dependencies only.
// this is used by the deliver task to resolve dynamic revisions to static ones
File ivyPropertiesInCache = cacheManager.getResolvedIvyPropertiesInCache(md.getResolvedModuleRevisionId());
Properties props = new Properties();
if (dependencies.length > 0) {
Map<ModuleId, ModuleRevisionId> forcedRevisions = new HashMap<>();
for (IvyNode dependency : dependencies) {
if (dependency.getModuleRevision() != null && dependency.getModuleRevision().isForce()) {
forcedRevisions.put(dependency.getModuleId(), dependency.getResolvedId());
}
}
IvyNode root = dependencies[0].getRoot();
Map<ModuleId, IvyNode> topLevelDeps = new HashMap<>();
for (IvyNode dependency : dependencies) {
if (!dependency.hasProblem()) {
DependencyDescriptor dd = dependency.getDependencyDescriptor(root);
if (dd != null) {
ModuleId orgMod = dependency.getModuleId();
topLevelDeps.put(orgMod, dependency);
}
}
}
for (IvyNode dependency : dependencies) {
if (!dependency.hasProblem() && !dependency.isCompletelyEvicted()) {
DependencyDescriptor dd = dependency.getDependencyDescriptor(root);
if (dd == null) {
ModuleId mid = dependency.getModuleId();
IvyNode tlDep = topLevelDeps.get(mid);
if (tlDep != null) {
dd = tlDep.getDependencyDescriptor(root);
}
}
if (dd != null) {
ModuleRevisionId depResolvedId = dependency.getResolvedId();
ModuleDescriptor depDescriptor = dependency.getDescriptor();
ModuleRevisionId depRevisionId = dd.getDependencyRevisionId();
ModuleRevisionId forcedRevisionId = forcedRevisions.get(dependency.getModuleId());
if (dependency.getModuleRevision() != null && dependency.getModuleRevision().isForce() && !depResolvedId.equals(depRevisionId) && !settings.getVersionMatcher().isDynamic(depRevisionId)) {
// if we were forced to this revision and we
// are not a dynamic revision, reset to the
// asked revision
depResolvedId = depRevisionId;
depDescriptor = null;
}
if (depResolvedId == null) {
throw new NullPointerException("getResolvedId() is null for " + dependency.toString());
}
if (depRevisionId == null) {
throw new NullPointerException("getDependencyRevisionId() " + "is null for " + dd.toString());
}
String rev = depResolvedId.getRevision();
String forcedRev = forcedRevisionId == null ? rev : forcedRevisionId.getRevision();
// The evicted modules have no description, so we can't put the status
String status = depDescriptor == null ? "?" : depDescriptor.getStatus();
Message.debug("storing dependency " + depResolvedId + " in props");
props.put(depRevisionId.encodeToString(), rev + " " + status + " " + forcedRev + " " + depResolvedId.getBranch());
}
}
}
}
FileOutputStream out = new FileOutputStream(ivyPropertiesInCache);
props.store(out, md.getResolvedModuleRevisionId() + " resolved revisions");
out.close();
Message.verbose("\tresolved ivy file produced in cache");
report.setResolveTime(System.currentTimeMillis() - start);
if (options.isDownload()) {
Message.verbose(":: downloading artifacts ::");
DownloadOptions downloadOptions = new DownloadOptions();
downloadOptions.setLog(options.getLog());
downloadArtifacts(report, options.getArtifactFilter(), downloadOptions);
}
if (options.isOutputReport()) {
outputReport(report, cacheManager, options);
}
Message.verbose("\tresolve done (" + report.getResolveTime() + "ms resolve - " + report.getDownloadTime() + "ms download)");
Message.sumupProblems();
eventManager.fireIvyEvent(new EndResolveEvent(md, confs, report));
return report;
} catch (RuntimeException ex) {
Message.debug(ex);
Message.error(ex.getMessage());
Message.sumupProblems();
throw ex;
} finally {
context.setResolveData(null);
setDictatorResolver(oldDictator);
}
}
use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.
the class ResolveEngine method download.
/**
* Download an artifact to the cache. Not used internally, useful especially for IDE plugins
* needing to download artifact one by one (for source or javadoc artifact, for instance).
* <p>
* Downloaded artifact file can be accessed using {@link ArtifactDownloadReport#getLocalFile()}.
* </p>
* <p>
* It is possible to track the progression of the download using classical ivy progress
* monitoring feature (see addTransferListener).
* </p>
*
* @param artifact
* the artifact to download
* @param options DownloadOptions
* @return a report concerning the download
* @see #download(ArtifactOrigin, DownloadOptions)
*/
public ArtifactDownloadReport download(Artifact artifact, DownloadOptions options) {
DependencyResolver resolver = settings.getResolver(artifact.getModuleRevisionId());
DownloadReport r = resolver.download(new Artifact[] { artifact }, options);
return r.getArtifactReport(artifact);
}
use of org.apache.ivy.plugins.resolver.DependencyResolver in project ant-ivy by apache.
the class ResolveEngine method downloadArtifacts.
public void downloadArtifacts(ResolveReport report, Filter<Artifact> artifactFilter, DownloadOptions options) {
long start = System.currentTimeMillis();
eventManager.fireIvyEvent(new PrepareDownloadEvent(report.getArtifacts().toArray(new Artifact[report.getArtifacts().size()])));
long totalSize = 0;
for (IvyNode dependency : report.getDependencies()) {
checkInterrupted();
// download artifacts required in all asked configurations
if (!dependency.isCompletelyEvicted() && !dependency.hasProblem() && dependency.getModuleRevision() != null) {
DependencyResolver resolver = dependency.getModuleRevision().getArtifactResolver();
Artifact[] selectedArtifacts = dependency.getSelectedArtifacts(artifactFilter);
DownloadReport dReport = resolver.download(selectedArtifacts, options);
for (ArtifactDownloadReport adr : dReport.getArtifactsReports()) {
if (adr.getDownloadStatus() == DownloadStatus.FAILED) {
if (adr.getArtifact().getExtraAttribute("ivy:merged") != null) {
Message.warn("\tmerged artifact not found: " + adr.getArtifact() + ". It was required in " + adr.getArtifact().getExtraAttribute("ivy:merged"));
} else {
Message.warn("\t" + adr);
resolver.reportFailure(adr.getArtifact());
}
} else if (adr.getDownloadStatus() == DownloadStatus.SUCCESSFUL) {
totalSize += adr.getSize();
}
}
// update concerned reports
for (String dconf : dependency.getRootModuleConfigurations()) {
// (as described by the Dependency object)
if (dependency.isEvicted(dconf) || dependency.isBlacklisted(dconf)) {
report.getConfigurationReport(dconf).addDependency(dependency);
} else {
report.getConfigurationReport(dconf).addDependency(dependency, dReport);
}
}
}
}
report.setDownloadTime(System.currentTimeMillis() - start);
report.setDownloadSize(totalSize);
}
Aggregations