final VirtualFile customPack1 =
myFixture.addFileToProject("custom_pack1/RootProject/rootlib.dart", "").getVirtualFile().getParent().getParent();
final VirtualFile customPack2 =
myFixture.addFileToProject("custom_pack2/SomePackage/somepack.dart", "").getVirtualFile().getParent().getParent();
DartUrlResolver resolver = DartUrlResolver.getInstance(getProject(), nestedPubspec);
VirtualFile file;
file = resolver.findFileByDartUrl("dart:collection");
assertNotNull(file);
assertEquals(DartTestUtils.SDK_HOME_PATH + "/lib/collection/collection.dart", file.getPath());
assertEquals("dart:collection", resolver.getDartUrlForFile(file));
file = resolver.findFileByDartUrl("dart:collection/hash_map.dart");
assertNotNull(file);
assertEquals(DartTestUtils.SDK_HOME_PATH + "/lib/collection/hash_map.dart", file.getPath());
assertEquals("dart:collection/hash_map.dart", resolver.getDartUrlForFile(file));
file = resolver.findFileByDartUrl("package:NestedProject/src/nestedlib.dart");
assertNotNull(file);
assertEquals(rootPath + "/example/lib/src/nestedlib.dart", file.getPath());
assertEquals("package:NestedProject/src/nestedlib.dart", resolver.getDartUrlForFile(file));
file = resolver.findFileByDartUrl("package:RootProject/rootlib.dart");
assertNotNull(file);
assertEquals(rootPath + "/lib/rootlib.dart", file.getPath());
assertEquals("package:RootProject/rootlib.dart", resolver.getDartUrlForFile(file));
file = resolver.findFileByDartUrl("package:SomePackage/somepack.dart");
assertNotNull(file);
assertEquals(rootPath + "/example/packages/SomePackage/somepack.dart", file.getPath());
assertEquals("package:SomePackage/somepack.dart", resolver.getDartUrlForFile(file));
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
try {
final Library library = modifiableModel.getModuleLibraryTable().createLibrary("Dart custom package roots");
final Library.ModifiableModel libModel = library.getModifiableModel();
libModel.addRoot(customPack1.getUrl(), OrderRootType.CLASSES);
libModel.addRoot(customPack2.getUrl(), OrderRootType.CLASSES);
libModel.commit();
modifiableModel.commit();
}
catch (Exception e) {
if (!modifiableModel.isDisposed()) modifiableModel.dispose();
}
}
});
resolver = DartUrlResolver.getInstance(getProject(), nestedPubspec);
file = resolver.findFileByDartUrl("package:NestedProject/src/nestedlib.dart");
assertNull(file);
file = resolver.findFileByDartUrl("package:RootProject/rootlib.dart");
assertNotNull(file);
assertEquals(rootPath + "/custom_pack1/RootProject/rootlib.dart", file.getPath());
assertEquals("package:RootProject/rootlib.dart", resolver.getDartUrlForFile(file));
file = resolver.findFileByDartUrl("package:SomePackage/somepack.dart");
assertNotNull(file);
assertEquals(rootPath + "/custom_pack2/SomePackage/somepack.dart", file.getPath());
assertEquals("package:SomePackage/somepack.dart", resolver.getDartUrlForFile(file));
}