use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class PythonFacetUtil method removeLibrary.
public static void removeLibrary(Module module) {
ApplicationManager.getApplication().runWriteAction(() -> {
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
final ModifiableRootModel model = rootManager.getModifiableModel();
// Just remove all old facet libraries
for (OrderEntry entry : model.getOrderEntries()) {
if (entry instanceof LibraryOrderEntry) {
final Library library = ((LibraryOrderEntry) entry).getLibrary();
if (library != null) {
final String libraryName = library.getName();
if (libraryName != null && libraryName.endsWith(PYTHON_FACET_LIBRARY_NAME_SUFFIX)) {
model.removeOrderEntry(entry);
//PyBuiltinCache.clearInstanceCache();
}
}
}
}
model.commit();
});
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class MvcFramework method getImplicitClasspathRoots.
protected List<File> getImplicitClasspathRoots(@NotNull Module module) {
final List<File> toExclude = new ArrayList<>();
VirtualFile sdkRoot = getSdkRoot(module);
if (sdkRoot != null)
toExclude.add(VfsUtil.virtualToIoFile(sdkRoot));
ContainerUtil.addIfNotNull(toExclude, getCommonPluginsDir(module));
final VirtualFile appRoot = findAppRoot(module);
if (appRoot != null) {
VirtualFile pluginDir = appRoot.findChild(MvcModuleStructureUtil.PLUGINS_DIRECTORY);
if (pluginDir != null)
toExclude.add(VfsUtil.virtualToIoFile(pluginDir));
VirtualFile libDir = appRoot.findChild("lib");
if (libDir != null)
toExclude.add(VfsUtil.virtualToIoFile(libDir));
}
final Library library = MvcModuleStructureUtil.findUserLibrary(module, getUserLibraryName());
if (library != null) {
for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
toExclude.add(VfsUtil.virtualToIoFile(PathUtil.getLocalFile(file)));
}
}
return toExclude;
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class MvcModuleStructureUtil method syncAuxModuleSdk.
public static void syncAuxModuleSdk(@NotNull Module appModule, @NotNull Module pluginsModule, @NotNull final MvcFramework framework) {
final ModuleRootManager auxRootManager = ModuleRootManager.getInstance(pluginsModule);
final ModuleRootManager appRootManager = ModuleRootManager.getInstance(appModule);
final boolean isSdkEquals = Comparing.equal(auxRootManager.getSdk(), appRootManager.getSdk());
List<Library> appLibraries = new ArrayList<>();
Library appUserLibrary = extractNonModuleLibraries(appLibraries, appRootManager, false, framework.getUserLibraryName());
List<Library> auxLibraries = new ArrayList<>();
Library auxUserLibrary = extractNonModuleLibraries(auxLibraries, auxRootManager, false, framework.getUserLibraryName());
final boolean isLibrariesEquals = appLibraries.equals(auxLibraries) && getJarUrls(auxUserLibrary).equals(getJarUrls(appUserLibrary));
if (!isSdkEquals || !isLibrariesEquals) {
ModuleRootModificationUtil.updateModel(pluginsModule, model -> {
if (!isSdkEquals) {
copySdk(appRootManager, model);
}
if (!isLibrariesEquals) {
copyUserLibraries(appRootManager, model, framework);
}
});
}
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class MvcModuleStructureUtil method addJarDirectory.
@Nullable
public static Consumer<ModifiableRootModel> addJarDirectory(VirtualFile root, Module module, final String libName) {
final VirtualFile libDir = root.findFileByRelativePath("lib");
if (libDir == null || !libDir.isDirectory() || ProjectRootManager.getInstance(module.getProject()).getFileIndex().isExcluded(libDir)) {
return null;
}
final Library library = findUserLibrary(module, libName);
if (library != null && library.isJarDirectory(libDir.getUrl())) {
return null;
}
return model -> {
Library.ModifiableModel libModel = modifyDefaultLibrary(model, libName);
libModel.addJarDirectory(libDir, false);
libModel.commit();
};
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class MvcModuleStructureUtil method copyUserLibraries.
public static void copyUserLibraries(ModuleRootModel from, ModifiableRootModel to, @NotNull MvcFramework framework) {
Library userLibraryTo = null;
for (OrderEntry entry : to.getOrderEntries()) {
if (entry instanceof LibraryOrderEntry) {
LibraryOrderEntry libraryEntry = (LibraryOrderEntry) entry;
Library library = libraryEntry.getLibrary();
if (library != null) {
String libraryName = libraryEntry.getLibraryName();
if (libraryName != null && libraryName.startsWith(framework.getUserLibraryName())) {
userLibraryTo = library;
} else {
if (library.getTable() != null && (!libraryEntry.getScope().isForProductionRuntime() || framework.isSDKLibrary(library))) {
to.removeOrderEntry(entry);
}
}
}
}
}
Library userLibraryFrom = null;
for (OrderEntry entry : from.getOrderEntries()) {
if (entry instanceof LibraryOrderEntry) {
LibraryOrderEntry libraryEntry = (LibraryOrderEntry) entry;
Library library = libraryEntry.getLibrary();
if (library != null) {
String libraryName = library.getName();
if (libraryName != null && libraryName.startsWith(framework.getUserLibraryName())) {
userLibraryFrom = library;
} else {
if (library.getTable() != null) {
LibraryOrderEntry libraryOrderEntry = to.addLibraryEntry(library);
libraryOrderEntry.setScope(DependencyScope.PROVIDED);
}
}
}
}
}
if (userLibraryTo == null) {
if (userLibraryFrom == null)
return;
userLibraryTo = to.getModuleLibraryTable().createLibrary(framework.getUserLibraryName() + " (" + to.getModule().getName() + ')');
} else {
OrderEntry[] orderEntries = to.getOrderEntries().clone();
for (int i = 0; i < orderEntries.length; i++) {
OrderEntry orderEntry = orderEntries[i];
if (orderEntry instanceof LibraryOrderEntry) {
if (userLibraryTo == ((LibraryOrderEntry) orderEntry).getLibrary()) {
System.arraycopy(orderEntries, i + 1, orderEntries, i, orderEntries.length - i - 1);
orderEntries[orderEntries.length - 1] = orderEntry;
to.rearrangeOrderEntries(orderEntries);
break;
}
}
}
}
Library.ModifiableModel model = userLibraryTo.getModifiableModel();
for (String url : model.getUrls(OrderRootType.CLASSES)) {
if (!model.isJarDirectory(url)) {
model.removeRoot(url, OrderRootType.CLASSES);
}
}
if (userLibraryFrom != null) {
for (String url : userLibraryFrom.getUrls(OrderRootType.CLASSES)) {
if (!userLibraryFrom.isJarDirectory(url)) {
model.addRoot(url, OrderRootType.CLASSES);
}
}
}
model.commit();
}
Aggregations