artifacts editor: handle renaming of library

This commit is contained in:
nik
2009-11-26 12:44:55 +03:00
parent cab7cd6d7c
commit 7fe7a7adf1
15 changed files with 220 additions and 73 deletions
@@ -15,20 +15,24 @@
*/
package com.intellij.packaging.impl.artifacts;
import com.intellij.packaging.elements.PackagingElementResolvingContext;
import com.intellij.packaging.artifacts.ArtifactModel;
import com.intellij.packaging.artifacts.ArtifactManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider;
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
import com.intellij.openapi.roots.ui.configuration.FacetsProvider;
import com.intellij.facet.impl.DefaultFacetsProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
import com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider;
import com.intellij.openapi.roots.ui.configuration.FacetsProvider;
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
import com.intellij.packaging.artifacts.ArtifactManager;
import com.intellij.packaging.artifacts.ArtifactModel;
import com.intellij.packaging.elements.PackagingElementResolvingContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author nik
*/
class DefaultPackagingElementResolvingContext implements PackagingElementResolvingContext {
public class DefaultPackagingElementResolvingContext implements PackagingElementResolvingContext {
private final Project myProject;
private final DefaultModulesProvider myModulesProvider;
@@ -56,4 +60,14 @@ class DefaultPackagingElementResolvingContext implements PackagingElementResolvi
public FacetsProvider getFacetsProvider() {
return DefaultFacetsProvider.INSTANCE;
}
public Library findLibrary(@NotNull String level, @NotNull String libraryName) {
return findLibrary(myProject, level, libraryName);
}
@Nullable
public static Library findLibrary(Project project, String level, String libraryName) {
LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(level, project);
return table != null ? table.getLibraryByName(libraryName) : null;
}
}
@@ -148,7 +148,7 @@ public class LibraryPackagingElement extends ComplexPackagingElement<LibraryPack
@Nullable
public Library findLibrary(@NotNull PackagingElementResolvingContext context) {
if (myModuleName == null) {
return findLibrary(myLibraryName, myLevel, context.getProject());
return context.findLibrary(myLevel, myLibraryName);
}
final ModulesProvider modulesProvider = context.getModulesProvider();
final Module module = modulesProvider.getModule(myModuleName);
@@ -181,28 +181,4 @@ public class LibraryPackagingElement extends ComplexPackagingElement<LibraryPack
}
return new PackagingElementOutputKind(containsDirectories, containsJars);
}
@Nullable
private static Library findLibrary(String libraryName, String libraryLevel, Project project) {
if (libraryName == null) {
return null;
}
LibraryTable table = findTable(libraryLevel, project);
if (table == null) {
return null;
}
else {
return table.getLibraryByName(libraryName);
}
}
@Nullable
private static LibraryTable findTable(String libraryLevel, Project project) {
if (libraryLevel == null) return null;
if (LibraryTablesRegistrar.APPLICATION_LEVEL.equals(libraryLevel)) {
return LibraryTablesRegistrar.getInstance().getLibraryTable();
}
return project == null? null : LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(libraryLevel, project);
}
}
@@ -15,11 +15,13 @@
*/
package com.intellij.packaging.elements;
import org.jetbrains.annotations.NotNull;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.FacetsProvider;
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
import com.intellij.packaging.artifacts.ArtifactModel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author nik
@@ -36,4 +38,7 @@ public interface PackagingElementResolvingContext {
@NotNull
FacetsProvider getFacetsProvider();
@Nullable
Library findLibrary(@NotNull String level, @NotNull String libraryName);
}
@@ -154,6 +154,10 @@ public class ArtifactEditorContextImpl implements ArtifactEditorContext {
return myParent.getFacetsProvider();
}
public Library findLibrary(@NotNull String level, @NotNull String libraryName) {
return myParent.findLibrary(level, libraryName);
}
public void queueValidation() {
myParent.queueValidation(getArtifact());
}
@@ -78,7 +78,7 @@ public class ArtifactErrorPanel {
myCurrentQuickFixes = quickFixes;
myFixButton.setVisible(!quickFixes.isEmpty());
if (!quickFixes.isEmpty()) {
myFixButton.setText(quickFixes.size() == 1 ? ContainerUtil.getFirstItem(quickFixes, null).getActionName() : "Fix");
myFixButton.setText(quickFixes.size() == 1 ? ContainerUtil.getFirstItem(quickFixes, null).getActionName() : "Fix...");
}
}
@@ -29,13 +29,21 @@ import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.impl.libraries.LibraryTableImplUtil;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.ui.configuration.ModuleEditor;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorListener;
import com.intellij.openapi.roots.ui.configuration.projectRoot.*;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
import com.intellij.openapi.ui.MasterDetailsStateService;
import com.intellij.packaging.artifacts.*;
import com.intellij.packaging.elements.CompositePackagingElement;
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
import com.intellij.packaging.impl.artifacts.PackagingElementPath;
import com.intellij.packaging.impl.artifacts.PackagingElementProcessor;
import com.intellij.packaging.impl.elements.LibraryElementType;
import com.intellij.packaging.impl.elements.LibraryPackagingElement;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -80,6 +88,7 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable {
}
}
});
final ItemsChangeListener listener = new ItemsChangeListener() {
public void itemChanged(@Nullable Object deletedItem) {
if (deletedItem instanceof Library || deletedItem instanceof Module) {
@@ -93,6 +102,59 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable {
moduleStructureConfigurable.addItemsChangeListener(listener);
projectLibrariesConfig.addItemsChangeListener(listener);
globalLibrariesConfig.addItemsChangeListener(listener);
context.addLibraryEditorListener(new LibraryEditorListener() {
public void libraryRenamed(@NotNull Library library, String oldName, String newName) {
final Artifact[] artifacts = myPackagingEditorContext.getArtifactModel().getArtifacts();
for (Artifact artifact : artifacts) {
updateLibraryElements(artifact, library, oldName, newName);
}
}
});
}
private void updateLibraryElements(final Artifact artifact, final Library library, final String oldName, final String newName) {
if (ArtifactUtil.processPackagingElements(myPackagingEditorContext.getRootElement(artifact), LibraryElementType.LIBRARY_ELEMENT_TYPE,
new PackagingElementProcessor<LibraryPackagingElement>() {
@Override
public boolean process(@NotNull LibraryPackagingElement element,
@NotNull PackagingElementPath path) {
return !isResolvedToLibrary(element, library, oldName);
}
}, myPackagingEditorContext, false, artifact.getArtifactType())) {
return;
}
myPackagingEditorContext.editLayout(artifact, new Runnable() {
public void run() {
final ModifiableArtifact modifiableArtifact = myPackagingEditorContext.getOrCreateModifiableArtifactModel().getOrCreateModifiableArtifact(artifact);
ArtifactUtil.processPackagingElements(modifiableArtifact, LibraryElementType.LIBRARY_ELEMENT_TYPE, new PackagingElementProcessor<LibraryPackagingElement>() {
@Override
public boolean process(@NotNull LibraryPackagingElement element, @NotNull PackagingElementPath path) {
if (isResolvedToLibrary(element, library, oldName)) {
element.setLibraryName(newName);
}
return true;
}
}, myPackagingEditorContext, false);
}
});
final ArtifactEditorImpl artifactEditor = myPackagingEditorContext.getArtifactEditor(artifact);
if (artifactEditor != null) {
artifactEditor.rebuildTries();
}
}
private static boolean isResolvedToLibrary(LibraryPackagingElement element, Library library, String name) {
if (!element.getLibraryName().equals(name)) {
return false;
}
final LibraryTable table = library.getTable();
if (table != null) {
return table.getTableLevel().equals(element.getLevel());
}
return element.getLevel().equals(LibraryTableImplUtil.MODULE_LEVEL);
}
private void onElementDeleted() {
@@ -21,6 +21,7 @@ import com.intellij.openapi.module.ModifiableModuleModel;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.FacetsProvider;
import com.intellij.openapi.roots.ui.configuration.ModuleEditor;
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
@@ -32,6 +33,7 @@ import com.intellij.openapi.util.Disposer;
import com.intellij.packaging.artifacts.*;
import com.intellij.packaging.elements.CompositePackagingElement;
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
import com.intellij.packaging.impl.artifacts.DefaultPackagingElementResolvingContext;
import com.intellij.packaging.ui.ManifestFileConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -152,6 +154,11 @@ public class ArtifactsStructureConfigurableContextImpl implements ArtifactsStruc
myContext.getDaemonAnalyzer().queueUpdate(getOrCreateArtifactElement(originalArtifact));
}
@Nullable
public ArtifactEditorImpl getArtifactEditor(Artifact artifact) {
return myArtifactEditors.get(getOriginalArtifact(artifact));
}
public ArtifactEditorImpl getOrCreateEditor(Artifact artifact) {
artifact = getOriginalArtifact(artifact);
ArtifactEditorImpl artifactEditor = myArtifactEditors.get(artifact);
@@ -191,6 +198,11 @@ public class ArtifactsStructureConfigurableContextImpl implements ArtifactsStruc
return myContext.getModulesConfigurator().getFacetsConfigurator();
}
public Library findLibrary(@NotNull String level, @NotNull String libraryName) {
final Library library = DefaultPackagingElementResolvingContext.findLibrary(myProject, level, libraryName);
return library != null ? myContext.getLibraryModel(library) : myContext.getLibrary(libraryName, level);
}
public ManifestFileConfiguration getManifestFile(CompositePackagingElement<?> element, ArtifactType artifactType) {
return myManifestFilesInfo.getManifestFile(element, artifactType, this);
}
@@ -21,14 +21,17 @@ import com.intellij.openapi.roots.impl.libraries.LibraryEx;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
public class LibraryEditor implements Disposable {
private final Library myLibrary;
private final LibraryEditorListener myListener;
private String myLibraryName = null;
private Library.ModifiableModel myModel = null;
public LibraryEditor(Library library) {
public LibraryEditor(Library library, @NotNull LibraryEditorListener listener) {
myLibrary = library;
myListener = listener;
}
public String getName() {
@@ -56,8 +59,10 @@ public class LibraryEditor implements Disposable {
}
public void setName(String name) {
String oldName = getModel().getName();
myLibraryName = name;
getModel().setName(name);
myListener.libraryRenamed(myLibrary, oldName, name);
}
public void addRoot(String url, OrderRootType rootType) {
@@ -0,0 +1,26 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.roots.ui.configuration.libraryEditor;
import com.intellij.openapi.roots.libraries.Library;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public interface LibraryEditorListener {
void libraryRenamed(@NotNull Library library, String oldName, String newName);
}
@@ -34,7 +34,6 @@ import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.impl.libraries.LibraryTableImplUtil;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.LibraryTablePresentation;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
import com.intellij.openapi.roots.ui.configuration.PathUIUtils;
@@ -57,6 +56,7 @@ import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Icons;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -77,7 +77,7 @@ import java.util.List;
* @author Eugene Zhuravlev
* Date: Jan 11, 2004
*/
public class LibraryTableEditor implements Disposable {
public class LibraryTableEditor implements Disposable, LibraryEditorListener {
static final UrlComparator ourUrlComparator = new UrlComparator();
private JPanel myPanel;
@@ -102,31 +102,11 @@ public class LibraryTableEditor implements Disposable {
private static final Icon JAR_DIRECTORY_ICON = IconLoader.getIcon("/nodes/jarDirectory.png");
private final Collection<Runnable> myListeners = new ArrayList<Runnable>();
private final List<LibraryEditorListener> myLibraryEditorListeners = new ArrayList<LibraryEditorListener>();
@Nullable private final Project myProject;
private final Map<DataKey, Object> myFileChooserUserData = new HashMap<DataKey, Object>();
private LibraryTableEditor(final LibraryTable libraryTableProvider, Project project) {
this(new LibraryTableModifiableModelProvider() {
public LibraryTable.ModifiableModel getModifiableModel() {
return libraryTableProvider.getModifiableModel();
}
public String getTableLevel() {
return libraryTableProvider.getTableLevel();
}
public LibraryTablePresentation getLibraryTablePresentation() {
return libraryTableProvider.getPresentation();
}
public boolean isLibraryTableEditable() {
return libraryTableProvider.isEditable();
}
}, project);
}
private LibraryTableEditor(LibraryTableModifiableModelProvider provider, Project project){
myProject = project;
myLibraryTableProvider = provider;
@@ -139,7 +119,7 @@ public class LibraryTableEditor implements Disposable {
}
}
public static LibraryTableEditor editLibraryTable(LibraryTableModifiableModelProvider provider, Project project){
public static LibraryTableEditor editLibraryTable(LibraryTableModifiableModelProvider provider, Project project) {
LibraryTableEditor result = new LibraryTableEditor(provider,project);
result.init(new LibraryTableTreeStructure(result));
return result;
@@ -229,7 +209,7 @@ public class LibraryTableEditor implements Disposable {
}
LibraryEditor libraryEditor = myLibraryToEditorMap.get(library);
if (libraryEditor == null) {
libraryEditor = new LibraryEditor(library);
libraryEditor = new LibraryEditor(library, this);
myLibraryToEditorMap.put(library, libraryEditor);
}
return libraryEditor;
@@ -282,6 +262,16 @@ public class LibraryTableEditor implements Disposable {
return false;
}
public void addLibraryEditorListener(@NotNull LibraryEditorListener listener) {
myLibraryEditorListeners.add(listener);
}
public void libraryRenamed(@NotNull Library library, String oldName, String newName) {
for (LibraryEditorListener listener : myLibraryEditorListeners) {
listener.libraryRenamed(library, oldName, newName);
}
}
public Library[] getLibraries() {
return myTableModifiableModel.getLibraries();
}
@@ -179,6 +179,7 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
return new AnAction[]{new AnAction(getAddText()) {
public void actionPerformed(AnActionEvent e) {
final LibraryTableEditor editor = LibraryTableEditor.editLibraryTable(getModelProvider(false), myProject);
editor.addLibraryEditorListener(myContext);
editor.createAddLibraryAction(true).actionPerformed(null);
Disposer.dispose(editor);
}
@@ -22,6 +22,7 @@ import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorListener;
import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.NotNull;
@@ -39,10 +40,12 @@ public class LibrariesModifiableModel implements LibraryTable.ModifiableModel {
private LibraryTable.ModifiableModel myLibrariesModifiableModel;
private final Project myProject;
private LibraryTable myTable;
private final LibraryEditorListener myLibraryEditorListener;
public LibrariesModifiableModel(final LibraryTable table, final Project project) {
public LibrariesModifiableModel(final LibraryTable table, final Project project, LibraryEditorListener libraryEditorListener) {
myProject = project;
myTable = table;
myLibraryEditorListener = libraryEditorListener;
}
public Library createLibrary(String name) {
@@ -126,7 +129,7 @@ public class LibrariesModifiableModel implements LibraryTable.ModifiableModel {
}
private LibraryEditor createLibraryEditor(final Library library) {
final LibraryEditor libraryEditor = new LibraryEditor(library);
final LibraryEditor libraryEditor = new LibraryEditor(library, myLibraryEditorListener);
myLibrary2EditorMap.put(library, libraryEditor);
return libraryEditor;
}
@@ -45,6 +45,7 @@ public class LibraryConfigurable extends ProjectStructureElementConfigurable<Lib
private final LibraryTableModifiableModelProvider myModel;
private final Project myProject;
private final LibraryProjectStructureElement myProjectStructureElement;
private boolean myUpdatingName;
protected LibraryConfigurable(final LibraryTableModifiableModelProvider libraryTable,
final Library library,
@@ -60,9 +61,11 @@ public class LibraryConfigurable extends ProjectStructureElementConfigurable<Lib
public JComponent createOptionsPanel() {
myLibraryEditor = LibraryTableEditor.editLibrary(myModel, myLibrary, myProject);
final StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(myProject).getContext();
myLibraryEditor.addLibraryEditorListener(context);
myLibraryEditor.addListener(new Runnable() {
public void run() {
ModuleStructureConfigurable.getInstance(myProject).getContext().getDaemonAnalyzer().queueUpdate(myProjectStructureElement);
context.getDaemonAnalyzer().queueUpdate(myProjectStructureElement);
}
});
return myLibraryEditor.getComponent();
@@ -94,13 +97,27 @@ public class LibraryConfigurable extends ProjectStructureElementConfigurable<Lib
}
public void setDisplayName(final String name) {
getLibraryEditor().setName(name);
if (!myUpdatingName) {
getLibraryEditor().setName(name);
}
}
private LibraryEditor getLibraryEditor() {
return ((LibrariesModifiableModel)myModel.getModifiableModel()).getLibraryEditor(myLibrary);
}
@Override
public void updateName() {
//todo[nik] pull up to NamedConfigurable
myUpdatingName = true;
try {
super.updateName();
}
finally {
myUpdatingName = false;
}
}
public Library getEditableObject() {
return myLibrary;
}
@@ -25,6 +25,7 @@ import com.intellij.openapi.roots.libraries.LibraryTablePresentation;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
import com.intellij.openapi.roots.ui.configuration.ModulesConfigurator;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorListener;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureDaemonAnalyzer;
import com.intellij.openapi.util.Disposer;
import com.intellij.util.NotNullFunction;
@@ -33,13 +34,15 @@ import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class StructureConfigurableContext implements Disposable {
public class StructureConfigurableContext implements Disposable, LibraryEditorListener {
private final ProjectStructureDaemonAnalyzer myDaemonAnalyzer;
public final ModulesConfigurator myModulesConfigurator;
public final Map<String, LibrariesModifiableModel> myLevel2Providers = new THashMap<String, LibrariesModifiableModel>();
private List<LibraryEditorListener> myLibraryEditorListeners = new ArrayList<LibraryEditorListener>();
private final Project myProject;
@@ -79,10 +82,24 @@ public class StructureConfigurableContext implements Disposable {
final LibraryTablesRegistrar tablesRegistrar = LibraryTablesRegistrar.getInstance();
myLevel2Providers.clear();
myLevel2Providers.put(LibraryTablesRegistrar.APPLICATION_LEVEL, new LibrariesModifiableModel(tablesRegistrar.getLibraryTable(), myProject));
myLevel2Providers.put(LibraryTablesRegistrar.PROJECT_LEVEL, new LibrariesModifiableModel(tablesRegistrar.getLibraryTable(myProject), myProject));
myLevel2Providers.put(LibraryTablesRegistrar.APPLICATION_LEVEL, new LibrariesModifiableModel(tablesRegistrar.getLibraryTable(), myProject, this));
myLevel2Providers.put(LibraryTablesRegistrar.PROJECT_LEVEL, new LibrariesModifiableModel(tablesRegistrar.getLibraryTable(myProject), myProject, this));
for (final LibraryTable table : tablesRegistrar.getCustomLibraryTables()) {
myLevel2Providers.put(table.getTableLevel(), new LibrariesModifiableModel(table, myProject));
myLevel2Providers.put(table.getTableLevel(), new LibrariesModifiableModel(table, myProject, this));
}
}
public void addLibraryEditorListener(LibraryEditorListener listener) {
myLibraryEditorListeners.add(listener);
}
public void removeLibraryEditorListener(LibraryEditorListener listener) {
myLibraryEditorListeners.remove(listener);
}
public void libraryRenamed(@NotNull Library library, String oldName, String newName) {
for (LibraryEditorListener listener : myLibraryEditorListeners) {
listener.libraryRenamed(library, oldName, newName);
}
}
@@ -134,9 +151,14 @@ public class StructureConfigurableContext implements Disposable {
}
@Nullable
private static Library findLibraryModel(final String libraryName, @NotNull LibrariesModifiableModel model) {
final Library library = model.getLibraryByName(libraryName);
return findLibraryModel(library, model);
private static Library findLibraryModel(final @NotNull String libraryName, @NotNull LibrariesModifiableModel model) {
for (Library library : model.getLibraries()) {
final Library libraryModel = findLibraryModel(library, model);
if (libraryModel != null && libraryName.equals(libraryModel.getName())) {
return libraryModel;
}
}
return null;
}
@Nullable
@@ -25,6 +25,8 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ModuleRootModel;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
import com.intellij.openapi.roots.ui.configuration.FacetsProvider;
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
import com.intellij.openapi.vfs.VirtualFile;
@@ -150,6 +152,14 @@ public abstract class MavenBaseModifiableModelsProvider implements MavenModifiab
return myFacetsProvider;
}
public Library findLibrary(@NotNull String level, @NotNull String libraryName) {
if (level.equals(LibraryTablesRegistrar.PROJECT_LEVEL)) {
return getLibraryByName(libraryName);
}
final LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(level, myProject);
return table != null ? table.getLibraryByName(libraryName) : null;
}
}
private class MavenModulesProvider implements ModulesProvider {