public void testMultipleInstances() throws Exception {
// this test checks that IvyContext is properly set and unset when using multiple instances
// of Ivy. We also check logging, because it heavily relies on IvyContext.
// we start by loading one ivy instance and using it to resolve some dependencies
MockMessageLogger mockLogger = new MockMessageLogger();
Ivy ivy = Ivy.newInstance();
ivy.getLoggerEngine().setDefaultLogger(mockLogger);
ivy.configure(new File("test/repositories/ivysettings.xml"));
assertFalse("IvyContext should be cleared and return a default Ivy instance",
IvyContext.getContext().getIvy() == ivy);
File cache = new File("build/cache");
ResolveReport report = ivy.resolve(new File(
"test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
getResolveOptions(ivy, new String[] {"*"}));
assertNotNull(report);
assertFalse(report.hasError());
mockLogger.assertLogContains("mod1.1");
assertFalse("IvyContext should be cleared and return a default Ivy instance",
IvyContext.getContext().getIvy() == ivy);
// then we load another instance, and use it for another resolution
MockMessageLogger mockLogger2 = new MockMessageLogger();
Ivy ivy2 = new Ivy();
ivy2.getLoggerEngine().setDefaultLogger(mockLogger2);
ivy2.configure(new File("test/repositories/norev/ivysettings.xml").toURL());
report = ivy2.resolve(new File("test/repositories/norev/ivy.xml").toURL(),
getResolveOptions(ivy2, new String[] {"*"}));
assertNotNull(report);
assertFalse(report.hasError());
mockLogger2.assertLogContains("norev/ivysettings.xml");
assertFalse("IvyContext should be cleared and return a default Ivy instance",
IvyContext.getContext().getIvy() == ivy2);
// finally we reuse the first instance to make another resolution
report = ivy.resolve(new File(