use of org.apache.ivy.core.resolve.ResolveData in project ant-ivy by apache.
the class WarnCircularDependencyStrategyTest method setResolveContext.
private void setResolveContext(String resolveId) {
IvySettings settings = new IvySettings();
IvyContext.getContext().setResolveData(new ResolveData(new ResolveEngine(settings, new EventManager(), new SortEngine(settings)), new ResolveOptions().setResolveId(resolveId)));
}
use of org.apache.ivy.core.resolve.ResolveData 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.core.resolve.ResolveData in project ant-ivy by apache.
the class Ivy method bind.
/**
* This method is used to bind this Ivy instance to required dependencies, i.e. instance of
* settings, engines, and so on.
* <p>
* After this call Ivy is still not configured, which means that the settings object is still
* empty.
* </p>
*/
public void bind() {
pushContext();
try {
if (settings == null) {
settings = new IvySettings();
}
if (eventManager == null) {
eventManager = new EventManager();
}
if (sortEngine == null) {
sortEngine = new SortEngine(settings);
}
if (searchEngine == null) {
searchEngine = new SearchEngine(settings);
}
if (resolveEngine == null) {
resolveEngine = new ResolveEngine(settings, eventManager, sortEngine);
}
if (retrieveEngine == null) {
retrieveEngine = new RetrieveEngine(settings, eventManager);
}
if (deliverEngine == null) {
deliverEngine = new DeliverEngine(settings);
}
if (publishEngine == null) {
publishEngine = new PublishEngine(settings, eventManager);
}
if (installEngine == null) {
installEngine = new InstallEngine(settings, searchEngine, resolveEngine);
}
if (repositoryEngine == null) {
repositoryEngine = new RepositoryManagementEngine(settings, searchEngine, resolveEngine);
}
eventManager.addTransferListener(new TransferListener() {
public void transferProgress(TransferEvent evt) {
ResolveData resolve;
switch(evt.getEventType()) {
case TransferEvent.TRANSFER_PROGRESS:
resolve = IvyContext.getContext().getResolveData();
if (resolve == null || !LogOptions.LOG_QUIET.equals(resolve.getOptions().getLog())) {
Message.progress();
}
break;
case TransferEvent.TRANSFER_COMPLETED:
resolve = IvyContext.getContext().getResolveData();
if (resolve == null || !LogOptions.LOG_QUIET.equals(resolve.getOptions().getLog())) {
Message.endProgress(" (" + (evt.getTotalLength() / KILO) + "kB)");
}
break;
default:
break;
}
}
});
bound = true;
} finally {
popContext();
}
}
use of org.apache.ivy.core.resolve.ResolveData in project ant-ivy by apache.
the class PomModuleDescriptorParserTest method testParentProperties.
@Test
public void testParentProperties() throws ParseException, IOException {
settings.setDictatorResolver(new MockResolver() {
public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
try {
ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-version.pom"), false);
return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
} catch (IOException e) {
throw new AssertionError(e);
}
}
});
ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-parent-properties.pom"), false);
assertNotNull(md);
assertEquals("1.0", md.getRevision());
DependencyDescriptor[] dds = md.getDependencies();
assertNotNull(dds);
assertEquals(3, dds.length);
// 2 are inherited from parent. Only the first one is important for this test
assertEquals(ModuleRevisionId.newInstance("org.apache", "test-version-other", "5.76"), dds[0].getDependencyRevisionId());
// present in the pom using a property defined in the parent
}
use of org.apache.ivy.core.resolve.ResolveData in project ant-ivy by apache.
the class PomModuleDescriptorParserTest method testParentDependencyMgt.
@Test
public void testParentDependencyMgt() throws ParseException, IOException {
settings.setDictatorResolver(new MockResolver() {
public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
try {
ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-dependencyMgt.pom"), false);
return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
} catch (IOException e) {
throw new AssertionError(e);
}
}
});
ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-parentDependencyMgt.pom"), false);
assertNotNull(md);
assertEquals(ModuleRevisionId.newInstance("org.apache", "test-parentdep", "1.0"), md.getModuleRevisionId());
DependencyDescriptor[] dds = md.getDependencies();
assertNotNull(dds);
assertEquals(2, dds.length);
assertEquals(ModuleRevisionId.newInstance("commons-collection", "commons-collection", "1.0.5"), dds[0].getDependencyRevisionId());
assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), dds[1].getDependencyRevisionId());
ExcludeRule[] excludes = dds[0].getAllExcludeRules();
assertNotNull(excludes);
assertEquals(2, excludes.length);
assertEquals("javax.mail", excludes[0].getId().getModuleId().getOrganisation());
assertEquals("mail", excludes[0].getId().getModuleId().getName());
assertEquals("javax.jms", excludes[1].getId().getModuleId().getOrganisation());
assertEquals("jms", excludes[1].getId().getModuleId().getName());
}
Aggregations