use of com.intellij.openapi.roots.LibraryOrderEntry 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.LibraryOrderEntry in project intellij-community by JetBrains.
the class JUnitDependencyScopeSuggesterTest method getScope.
private DependencyScope getScope(String name) {
LibraryOrderEntry entry = OrderEntryUtil.findLibraryOrderEntry(ModuleRootManager.getInstance(myModule), name);
assertNotNull(entry);
Library library = entry.getLibrary();
assertNotNull(library);
return new JUnitDependencyScopeSuggester().getDefaultDependencyScope(library);
}
use of com.intellij.openapi.roots.LibraryOrderEntry 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.LibraryOrderEntry 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.LibraryOrderEntry in project ballerina by ballerina-lang.
the class BallerinaSdkConfigurable method updateModules.
private static void updateModules(@NotNull Project project, @NotNull Library lib, boolean remove) {
Module[] modules = ModuleManager.getInstance(project).getModules();
for (Module module : modules) {
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
if (!remove) {
if (model.findLibraryOrderEntry(lib) == null) {
LibraryOrderEntry entry = model.addLibraryEntry(lib);
entry.setScope(DependencyScope.PROVIDED);
}
} else {
LibraryOrderEntry entry = model.findLibraryOrderEntry(lib);
if (entry != null) {
model.removeOrderEntry(entry);
}
}
model.commit();
}
}
Aggregations