use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class MavenProjectsManagerTest method testForceReimport.
public void testForceReimport() throws Exception {
createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + " <dependency>" + " <groupId>junit</groupId>" + " <artifactId>junit</artifactId>" + " <version>4.0</version>" + " </dependency>" + "</dependencies>");
importProject();
assertModules("project");
createProjectSubDir("src/main/java");
ApplicationManager.getApplication().runWriteAction(() -> {
ModifiableRootModel model = ModuleRootManager.getInstance(getModule("project")).getModifiableModel();
for (OrderEntry each : model.getOrderEntries()) {
if (each instanceof LibraryOrderEntry && MavenRootModelAdapter.isMavenLibrary(((LibraryOrderEntry) each).getLibrary())) {
model.removeOrderEntry(each);
}
}
model.commit();
});
assertSources("project");
assertModuleLibDeps("project");
myProjectsManager.forceUpdateAllProjectsOrFindAllAvailablePomFiles();
waitForReadingCompletion();
myProjectsManager.waitForResolvingCompletion();
myProjectsManager.performScheduledImportInTests();
assertSources("project", "src/main/java");
assertModuleLibDeps("project", "Maven: junit:junit:4.0");
}
use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class ProjectStructureSelectInTarget method selectIn.
@Override
public void selectIn(final SelectInContext context, final boolean requestFocus) {
final Project project = context.getProject();
final VirtualFile file = context.getVirtualFile();
final Module module;
final Facet facet;
if (file instanceof WrappingVirtualFile) {
final Object o = ((WrappingVirtualFile) file).getWrappedObject(project);
facet = o instanceof Facet ? (Facet) o : null;
module = facet == null ? null : facet.getModule();
} else {
Module moduleByIml = file.getFileType().equals(StdFileTypes.IDEA_MODULE) ? findModuleByModuleFile(project, file) : null;
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
module = moduleByIml != null ? moduleByIml : fileIndex.getModuleForFile(file);
facet = fileIndex.isInSourceContent(file) ? null : findFacet(project, file);
}
if (module != null || facet != null) {
ApplicationManager.getApplication().invokeLater(() -> {
if (facet != null) {
ModulesConfigurator.showFacetSettingsDialog(facet, null);
} else {
ProjectSettingsService.getInstance(project).openModuleSettings(module);
}
});
return;
}
final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(file, project);
if (orderEntry != null) {
ApplicationManager.getApplication().invokeLater(() -> ProjectSettingsService.getInstance(project).openLibraryOrSdkSettings(orderEntry));
}
}
use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class ChangeLibraryLevelInClasspathAction method isEnabled.
@Override
protected boolean isEnabled() {
final OrderEntry entry = myPanel.getSelectedEntry();
boolean enabled = false;
if (entry instanceof LibraryOrderEntry) {
final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;
if (libraryOrderEntry.getLibrary() != null) {
boolean isFromModuleLibrary = libraryOrderEntry.isModuleLevel();
boolean isToModuleLibrary = isConvertingToModuleLibrary();
enabled = isFromModuleLibrary != isToModuleLibrary;
}
}
return enabled;
}
use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class FindInProjectUtil method addSourceDirectoriesFromLibraries.
private static void addSourceDirectoriesFromLibraries(@NotNull Project project, @NotNull VirtualFile directory, @NotNull Collection<VirtualFile> outSourceRoots) {
ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(project);
// if we already are in the sources, search just in this directory only
if (!index.isInLibraryClasses(directory))
return;
VirtualFile classRoot = index.getClassRootForFile(directory);
if (classRoot == null)
return;
String relativePath = VfsUtilCore.getRelativePath(directory, classRoot);
if (relativePath == null)
return;
Collection<VirtualFile> otherSourceRoots = new THashSet<>();
// otherwise, if we outside sources or in a jar directory, add directories from other source roots
searchForOtherSourceDirs: for (OrderEntry entry : index.getOrderEntriesForFile(directory)) {
if (entry instanceof LibraryOrderEntry) {
Library library = ((LibraryOrderEntry) entry).getLibrary();
if (library == null)
continue;
// note: getUrls() returns jar directories too
String[] sourceUrls = library.getUrls(OrderRootType.SOURCES);
for (String sourceUrl : sourceUrls) {
if (VfsUtilCore.isEqualOrAncestor(sourceUrl, directory.getUrl())) {
// already in this library sources, no need to look for another source root
otherSourceRoots.clear();
break searchForOtherSourceDirs;
}
// otherwise we may be inside the jar file in a library which is configured as a jar directory
// in which case we have no way to know whether this is a source jar or classes jar - so try to locate the source jar
}
}
for (VirtualFile sourceRoot : entry.getFiles(OrderRootType.SOURCES)) {
VirtualFile sourceFile = sourceRoot.findFileByRelativePath(relativePath);
if (sourceFile != null) {
otherSourceRoots.add(sourceFile);
}
}
}
outSourceRoots.addAll(otherSourceRoots);
}
use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class PyBuiltinCache method findSdkForNonModuleFile.
@Nullable
public static Sdk findSdkForNonModuleFile(PsiFileSystemItem psiFile) {
Project project = psiFile.getProject();
Sdk sdk = null;
final VirtualFile vfile = psiFile instanceof PsiFile ? ((PsiFile) psiFile).getOriginalFile().getVirtualFile() : psiFile.getVirtualFile();
if (vfile != null) {
// reality
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
sdk = projectRootManager.getProjectSdk();
if (sdk == null) {
final List<OrderEntry> orderEntries = projectRootManager.getFileIndex().getOrderEntriesForFile(vfile);
for (OrderEntry orderEntry : orderEntries) {
if (orderEntry instanceof JdkOrderEntry) {
sdk = ((JdkOrderEntry) orderEntry).getJdk();
} else if (orderEntry instanceof ModuleLibraryOrderEntryImpl) {
sdk = PythonSdkType.findPythonSdk(orderEntry.getOwnerModule());
}
}
}
}
return sdk;
}
Aggregations