use of com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl in project azure-tools-for-java by Microsoft.
the class ApplicationInsightsPanel method configureAzureSDK.
private void configureAzureSDK() {
final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
if (orderEntry instanceof ModuleLibraryOrderEntryImpl && AzureLibrary.APP_INSIGHTS.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
return;
}
}
final LibrariesContainer.LibraryLevel level = LibrariesContainer.LibraryLevel.MODULE;
AccessToken token = WriteAction.start();
try {
Library newLibrary = LibrariesContainerFactory.createContainer(modifiableModel).createLibrary(AzureLibrary.APP_INSIGHTS.getName(), level, new ArrayList<OrderRoot>());
for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
if (orderEntry instanceof ModuleLibraryOrderEntryImpl && AzureLibrary.APP_INSIGHTS.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
((ModuleLibraryOrderEntryImpl) orderEntry).setExported(true);
break;
}
}
Library.ModifiableModel newLibraryModel = newLibrary.getModifiableModel();
AddLibraryUtility.addLibraryFiles(new File(PluginHelper.getAzureLibLocation()), newLibraryModel, AzureLibrary.APP_INSIGHTS.getFiles());
newLibraryModel.commit();
modifiableModel.commit();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
token.finish();
}
}
use of com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl in project azure-tools-for-java by Microsoft.
the class LibrariesConfigurationDialog method editLibrary.
private void editLibrary() {
AzureLibrary azureLibrary = (AzureLibrary) librariesList.getSelectedValue();
final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
OrderEntry libraryOrderEntry = null;
for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
if (orderEntry instanceof ModuleLibraryOrderEntryImpl && azureLibrary.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
libraryOrderEntry = orderEntry;
break;
}
}
if (libraryOrderEntry != null) {
LibraryPropertiesPanel libraryPropertiesPanel = new LibraryPropertiesPanel(module, azureLibrary, true, ((ModuleLibraryOrderEntryImpl) libraryOrderEntry).isExported());
DefaultDialogWrapper libraryProperties = new DefaultDialogWrapper(module.getProject(), libraryPropertiesPanel);
libraryProperties.show();
if (libraryProperties.isOK()) {
AccessToken token = WriteAction.start();
try {
((ModuleLibraryOrderEntryImpl) libraryOrderEntry).setExported(libraryPropertiesPanel.isExported());
modifiableModel.commit();
} finally {
token.finish();
}
LocalFileSystem.getInstance().findFileByPath(PluginUtil.getModulePath(module)).refresh(true, true);
}
} else {
PluginUtil.displayInfoDialog("Library not found", "Library was not found");
}
}
use of com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl in project intellij-community by JetBrains.
the class LibraryDependencyDataService method syncExistingAndRemoveObsolete.
private void syncExistingAndRemoveObsolete(@NotNull IdeModifiableModelsProvider modelsProvider, @NotNull Map<Set<String>, LibraryDependencyData> moduleLibrariesToImport, @NotNull Map<String, LibraryDependencyData> projectLibrariesToImport, @NotNull Set<LibraryDependencyData> toImport, @NotNull Map<OrderEntry, OrderAware> orderEntryDataMap, @NotNull ModifiableRootModel moduleRootModel, boolean hasUnresolvedLibraries) {
for (OrderEntry entry : moduleRootModel.getOrderEntries()) {
if (entry instanceof ModuleLibraryOrderEntryImpl) {
ModuleLibraryOrderEntryImpl moduleLibraryOrderEntry = (ModuleLibraryOrderEntryImpl) entry;
Library library = moduleLibraryOrderEntry.getLibrary();
if (library == null) {
LOG.warn("Skipping module-level library entry because it doesn't have backing Library object. Entry: " + entry);
continue;
}
final VirtualFile[] libraryFiles = library.getFiles(OrderRootType.CLASSES);
final Set<String> moduleLibraryKey = ContainerUtilRt.newHashSet(libraryFiles.length);
for (VirtualFile file : libraryFiles) {
moduleLibraryKey.add(ExternalSystemApiUtil.getLocalFileSystemPath(file) + moduleLibraryOrderEntry.getScope().name());
}
LibraryDependencyData existing = moduleLibrariesToImport.remove(moduleLibraryKey);
if (existing == null || !StringUtil.equals(StringUtil.nullize(existing.getInternalName()), library.getName())) {
moduleRootModel.removeOrderEntry(entry);
} else {
orderEntryDataMap.put(entry, existing);
syncExistingLibraryDependency(modelsProvider, existing, library, moduleRootModel, moduleLibraryOrderEntry.getOwnerModule());
toImport.remove(existing);
}
} else if (entry instanceof LibraryOrderEntry) {
LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;
String libraryName = libraryOrderEntry.getLibraryName();
LibraryDependencyData existing = projectLibrariesToImport.remove(libraryName + libraryOrderEntry.getScope().name());
if (existing != null) {
toImport.remove(existing);
orderEntryDataMap.put(entry, existing);
libraryOrderEntry.setExported(existing.isExported());
libraryOrderEntry.setScope(existing.getScope());
} else if (!hasUnresolvedLibraries) {
// There is a possible case that a project has been successfully imported from external model and after
// that network/repo goes down. We don't want to drop existing binary mappings then.
moduleRootModel.removeOrderEntry(entry);
}
}
}
}
use of com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl in project intellij-community by JetBrains.
the class ArtifactEditorContextImpl method selectLibrary.
@Override
public void selectLibrary(@NotNull Library library) {
final LibraryTable table = library.getTable();
if (table != null) {
ProjectStructureConfigurable.getInstance(getProject()).selectProjectOrGlobalLibrary(library, true);
} else {
final Module module = ((LibraryImpl) library).getModule();
if (module != null) {
final ModuleRootModel rootModel = myParent.getModulesProvider().getRootModel(module);
final String libraryName = library.getName();
for (OrderEntry entry : rootModel.getOrderEntries()) {
if (entry instanceof ModuleLibraryOrderEntryImpl) {
final ModuleLibraryOrderEntryImpl libraryEntry = (ModuleLibraryOrderEntryImpl) entry;
if (libraryName != null && libraryName.equals(libraryEntry.getLibraryName()) || libraryName == null && library.equals(libraryEntry.getLibrary())) {
ProjectStructureConfigurable.getInstance(getProject()).selectOrderEntry(module, libraryEntry);
return;
}
}
}
}
}
}
use of com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl in project azure-tools-for-java by Microsoft.
the class LibrariesConfigurationDialog method addLibrary.
private void addLibrary() {
AddLibraryWizardModel model = new AddLibraryWizardModel(module);
AddLibraryWizardDialog wizard = new AddLibraryWizardDialog(model);
wizard.setTitle(message("addLibraryTitle"));
wizard.show();
if (wizard.isOK()) {
AzureLibrary azureLibrary = model.getSelectedLibrary();
final LibrariesContainer.LibraryLevel level = LibrariesContainer.LibraryLevel.MODULE;
AccessToken token = WriteAction.start();
try {
final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
if (orderEntry instanceof ModuleLibraryOrderEntryImpl && azureLibrary.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
PluginUtil.displayErrorDialog(message("error"), message("libraryExistsError"));
return;
}
}
Library newLibrary = LibrariesContainerFactory.createContainer(modifiableModel).createLibrary(azureLibrary.getName(), level, new ArrayList<OrderRoot>());
if (model.isExported()) {
for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
if (orderEntry instanceof ModuleLibraryOrderEntryImpl && azureLibrary.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
((ModuleLibraryOrderEntryImpl) orderEntry).setExported(true);
break;
}
}
}
Library.ModifiableModel newLibraryModel = newLibrary.getModifiableModel();
// if there is separate resources folder
if (azureLibrary.getLocation() != null) {
File file = new File(String.format("%s%s%s", AzurePlugin.pluginFolder, File.separator, azureLibrary.getLocation()));
AddLibraryUtility.addLibraryRoot(file, newLibraryModel);
}
// if some files already contained in plugin dependencies, take them from there - true for azure sdk library
if (azureLibrary.getFiles().length > 0) {
AddLibraryUtility.addLibraryFiles(new File(PluginHelper.getAzureLibLocation()), newLibraryModel, azureLibrary.getFiles());
}
newLibraryModel.commit();
modifiableModel.commit();
((DefaultListModel) librariesList.getModel()).addElement(azureLibrary);
tempList.add(azureLibrary);
} catch (Exception ex) {
PluginUtil.displayErrorDialogAndLog(message("error"), message("addLibraryError"), ex);
} finally {
token.finish();
}
LocalFileSystem.getInstance().findFileByPath(PluginUtil.getModulePath(module)).refresh(true, true);
}
}
Aggregations