use of com.intellij.openapi.roots.LibraryOrderEntry in project android by JetBrains.
the class AndroidModuleDependenciesSetupTest method testSetUpLibraryWithExistingLibrary.
public void testSetUpLibraryWithExistingLibrary() throws IOException {
File binaryPath = createTempFile("fakeLibrary", "jar");
File sourcePath = createTempFile("fakeLibrary-src", "jar");
Library newLibrary = createLibrary(binaryPath, sourcePath);
String libraryName = binaryPath.getName();
Module module = getModule();
IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
File[] binaryPaths = { binaryPath };
myDependenciesSetup.setUpLibraryDependency(module, modelsProvider, libraryName, COMPILE, binaryPath, binaryPaths, EMPTY_FILE_ARRAY);
// Apply changes before checking state.
ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
List<LibraryOrderEntry> libraryOrderEntries = getLibraryOrderEntries(module);
// Only one library should be in the library table.
assertThat(libraryOrderEntries).hasSize(1);
LibraryOrderEntry libraryOrderEntry = libraryOrderEntries.get(0);
// The existing library should not have been changed.
assertSame(newLibrary, libraryOrderEntry.getLibrary());
verify(myLibraryRegistry).markAsUsed(newLibrary, binaryPaths);
// Should not attemp to look up sources for existing libraries.
verify(myLibraryFilePaths, never()).findSourceJarPath(binaryPath);
}
use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-plugins by JetBrains.
the class DartUrlResolverImpl method initPackagesMapFromLib.
private void initPackagesMapFromLib(@NotNull final VirtualFile contextFile) {
final Module module = ModuleUtilCore.findModuleForFile(contextFile, myProject);
final List<OrderEntry> orderEntries = module != null ? Arrays.asList(ModuleRootManager.getInstance(module).getOrderEntries()) : ProjectRootManager.getInstance(myProject).getFileIndex().getOrderEntriesForFile(contextFile);
for (OrderEntry orderEntry : orderEntries) {
if (orderEntry instanceof LibraryOrderEntry && LibraryTablesRegistrar.PROJECT_LEVEL.equals(((LibraryOrderEntry) orderEntry).getLibraryLevel()) && DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME.equals(((LibraryOrderEntry) orderEntry).getLibraryName())) {
final LibraryEx library = (LibraryEx) ((LibraryOrderEntry) orderEntry).getLibrary();
final LibraryProperties properties = library == null ? null : library.getProperties();
if (properties instanceof DartPackagesLibraryProperties) {
for (Map.Entry<String, List<String>> entry : ((DartPackagesLibraryProperties) properties).getPackageNameToDirsMap().entrySet()) {
if (entry != null && entry.getKey() != null && entry.getValue() != null) {
myPackagesMapFromLib.put(entry.getKey(), entry.getValue());
}
}
return;
}
}
}
}
use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-plugins by JetBrains.
the class CodeContext method createCodeContextFromLibraries.
private static CodeContext createCodeContextFromLibraries(final String namespace, final Module module, final FlexBuildConfiguration bc) {
final Map<String, CodeContext> contextsOfModule = new THashMap<>();
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
// If fixed - then method usage at getStdCodeContext() must be changed to make sure that all namespaces handled at that point.
for (DependencyEntry entry : bc.getDependencies().getEntries()) {
if (entry.getDependencyType().getLinkageType() == LinkageType.LoadInRuntime)
continue;
if (entry instanceof BuildConfigurationEntry) {
final FlexBuildConfiguration bcDependency = ((BuildConfigurationEntry) entry).findBuildConfiguration();
if (bcDependency != null && bcDependency.getOutputType() == OutputType.Library) {
addComponentsFromManifests(module, contextsOfModule, bcDependency, true);
}
} else if (entry instanceof ModuleLibraryEntry) {
final LibraryOrderEntry orderEntry = FlexProjectRootsUtil.findOrderEntry((ModuleLibraryEntry) entry, rootManager);
if (orderEntry != null) {
for (VirtualFile file : orderEntry.getRootFiles(OrderRootType.CLASSES)) {
handleFileDependency(module, contextsOfModule, file);
}
}
} else if (entry instanceof SharedLibraryEntry) {
final Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), (SharedLibraryEntry) entry);
if (library != null) {
for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
handleFileDependency(module, contextsOfModule, file);
}
}
}
}
addComponentsFromManifests(module, contextsOfModule, bc, false);
final CodeContextHolder contextHolder = CodeContextHolder.getInstance(module.getProject());
for (Map.Entry<String, CodeContext> entry : contextsOfModule.entrySet()) {
contextHolder.putCodeContext(entry.getKey(), module, entry.getValue());
}
CodeContext codeContext = contextsOfModule.get(namespace);
if (codeContext == null) {
codeContext = CodeContextHolder.EMPTY;
}
return codeContext;
}
use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-plugins by JetBrains.
the class AddAsSwcLibDialog method filterAlreadyExistingRoots.
private static Collection<VirtualFile> filterAlreadyExistingRoots(final Collection<VirtualFile> roots, final FlexProjectConfigurationEditor flexConfigEditor, final Module module, final ModifiableFlexBuildConfiguration bc) {
final Set<VirtualFile> result = new THashSet<>(roots);
final DependencyEntry[] entries = bc.getDependencies().getEntries();
for (DependencyEntry entry : entries) {
if (entry instanceof ModifiableModuleLibraryEntry) {
final LibraryOrderEntry orderEntry = FlexProjectRootsUtil.findOrderEntry((ModuleLibraryEntry) entry, flexConfigEditor.getModifiableRootModel(module));
if (orderEntry != null) {
for (VirtualFile file : orderEntry.getRootFiles(OrderRootType.CLASSES)) {
if (result.contains(file)) {
result.remove(file);
}
}
}
} else if (entry instanceof ModifiableSharedLibraryEntry) {
final Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), (SharedLibraryEntry) entry);
if (library != null) {
for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
if (result.contains(file)) {
result.remove(file);
}
}
}
}
}
return result;
}
use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-plugins by JetBrains.
the class FlexmojosImporterTestBase method checkLibrariesOfFlexType.
private static void checkLibrariesOfFlexType(final Module module, final FlexBuildConfiguration bc) {
final List<LibraryOrderEntry> moduleLibEntries = ContainerUtil.filter(ModuleRootManager.getInstance(module).getOrderEntries(), new FilteringIterator.InstanceOf(LibraryOrderEntry.class));
final List<SharedLibraryEntry> bcLibEntries = ContainerUtil.filter(bc.getDependencies().getEntries(), new FilteringIterator.InstanceOf(SharedLibraryEntry.class));
assertTrue(bcLibEntries.size() > 0);
assertEquals(moduleLibEntries.size(), bcLibEntries.size());
for (SharedLibraryEntry entry : bcLibEntries) {
assertTrue(entry.getLibraryName().contains(":swc:") || entry.getLibraryName().contains(":rb.swc:") || entry.getLibraryName().contains(":resource-bundle:"));
assertEquals(LibraryTablesRegistrar.PROJECT_LEVEL, entry.getLibraryLevel());
final Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), entry);
assertNotNull(library);
assertTrue(((LibraryEx) library).getKind() == FlexLibraryType.FLEX_LIBRARY);
checkContainsLibrary(moduleLibEntries, library);
}
}
Aggregations