use of com.intellij.openapi.roots.OrderEntry in project android by JetBrains.
the class ModuleDependenciesSetup method addLibraryAsDependency.
protected void addLibraryAsDependency(@NotNull Library library, @NotNull String libraryName, @NotNull DependencyScope scope, @NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider) {
for (OrderEntry orderEntry : modelsProvider.getModifiableRootModel(module).getOrderEntries()) {
if (orderEntry instanceof LibraryOrderEntry) {
Library entryLibrary = ((LibraryOrderEntry) orderEntry).getLibrary();
if (entryLibrary != null && libraryName.equals(entryLibrary.getName())) {
// Dependency already set up.
return;
}
}
}
LibraryOrderEntry orderEntry = modelsProvider.getModifiableRootModel(module).addLibraryEntry(library);
orderEntry.setScope(scope);
orderEntry.setExported(true);
}
use of com.intellij.openapi.roots.OrderEntry in project android by JetBrains.
the class NonGradleApkProvider method fillRuntimeAndTestDependencies.
private static void fillRuntimeAndTestDependencies(@NotNull Module module, @NotNull Map<AndroidFacet, String> module2PackageName) throws ApkProvisionException {
for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) {
if (entry instanceof ModuleOrderEntry) {
ModuleOrderEntry moduleOrderEntry = (ModuleOrderEntry) entry;
Module depModule = moduleOrderEntry.getModule();
if (depModule != null) {
AndroidFacet depFacet = AndroidFacet.getInstance(depModule);
if (depFacet != null && !module2PackageName.containsKey(depFacet) && depFacet.isAppProject()) {
String packageName = ApkProviderUtil.computePackageName(depFacet);
module2PackageName.put(depFacet, packageName);
fillRuntimeAndTestDependencies(depModule, module2PackageName);
}
}
}
}
}
use of com.intellij.openapi.roots.OrderEntry 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.OrderEntry in project intellij-community by JetBrains.
the class GeneratePluginClassAction method getModule.
@Nullable
protected static Module getModule(PsiDirectory dir) {
Project project = dir.getProject();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final VirtualFile vFile = dir.getVirtualFile();
if (fileIndex.isInLibrarySource(vFile) || fileIndex.isInLibraryClasses(vFile)) {
final List<OrderEntry> orderEntries = fileIndex.getOrderEntriesForFile(vFile);
if (orderEntries.isEmpty()) {
return null;
}
Set<Module> modules = new HashSet<>();
for (OrderEntry orderEntry : orderEntries) {
modules.add(orderEntry.getOwnerModule());
}
final Module[] candidates = modules.toArray(new Module[modules.size()]);
Arrays.sort(candidates, ModuleManager.getInstance(project).moduleDependencyComparator());
return candidates[0];
}
return fileIndex.getModuleForFile(vFile);
}
use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class ProjectUtilCore method displayUrlRelativeToProject.
public static String displayUrlRelativeToProject(@NotNull VirtualFile file, @NotNull String url, @NotNull Project project, boolean includeFilePath, boolean keepModuleAlwaysOnTheLeft) {
final VirtualFile baseDir = project.getBaseDir();
if (baseDir != null && includeFilePath) {
//noinspection ConstantConditions
final String projectHomeUrl = baseDir.getPresentableUrl();
if (url.startsWith(projectHomeUrl)) {
url = "..." + url.substring(projectHomeUrl.length());
}
}
if (SystemInfo.isMac && file.getFileSystem() instanceof LocalFileProvider) {
final VirtualFile fileForJar = ((LocalFileProvider) file.getFileSystem()).getLocalVirtualFileFor(file);
if (fileForJar != null) {
final OrderEntry libraryEntry = LibraryUtil.findLibraryEntry(file, project);
if (libraryEntry != null) {
if (libraryEntry instanceof JdkOrderEntry) {
url = url + " - [" + ((JdkOrderEntry) libraryEntry).getJdkName() + "]";
} else {
url = url + " - [" + libraryEntry.getPresentableName() + "]";
}
} else {
url = url + " - [" + fileForJar.getName() + "]";
}
}
}
final Module module = ModuleUtilCore.findModuleForFile(file, project);
if (module == null)
return url;
return !keepModuleAlwaysOnTheLeft && SystemInfo.isMac ? url + " - [" + module.getName() + "]" : "[" + module.getName() + "] - " + url;
}
Aggregations