mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-81373 Flex project structure: shared library becomes invalid after moving it to global libraries
This commit is contained in:
+12
@@ -1,10 +1,13 @@
|
||||
package com.intellij.openapi.roots.ui.configuration.artifacts;
|
||||
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.LibraryProjectStructureElement;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.PlaceInProjectStructure;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElementUsage;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.packaging.elements.PackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElementFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@@ -81,4 +84,13 @@ public class UsageInArtifact extends ProjectStructureElementUsage {
|
||||
public void removeSourceElement() {
|
||||
removeElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceElement(final ProjectStructureElement newElement) {
|
||||
Library library = ((LibraryProjectStructureElement)newElement).getLibrary();
|
||||
PackagingElement<?> newLibraryElement = PackagingElementFactory.getInstance().createLibraryFiles(library.getName(),
|
||||
library.getTable().getTableLevel(),
|
||||
null);
|
||||
replaceElement(newLibraryElement);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-23
@@ -17,21 +17,13 @@ package com.intellij.openapi.roots.ui.configuration.projectRoot;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.impl.OrderEntryUtil;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.ModuleEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.ModulesConfigurator;
|
||||
import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.UsageInArtifact;
|
||||
import com.intellij.openapi.roots.ui.configuration.classpath.ChangeLibraryLevelActionBase;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.*;
|
||||
import com.intellij.packaging.elements.PackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElementFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -67,23 +59,9 @@ public class ChangeLibraryLevelAction extends ChangeLibraryLevelActionBase {
|
||||
final Library newLibrary = doCopy(oldLibrary);
|
||||
if (newLibrary == null) return;
|
||||
|
||||
final ModulesConfigurator configurator = context.getModulesConfigurator();
|
||||
final Collection<ProjectStructureElementUsage> usages = context.getDaemonAnalyzer().getUsages(libraryElement);
|
||||
for (ProjectStructureElementUsage usage : usages) {
|
||||
if (usage instanceof UsageInModuleClasspath) {
|
||||
final Module module = ((UsageInModuleClasspath)usage).getModule();
|
||||
final ModuleEditor editor = configurator.getModuleEditor(module);
|
||||
if (editor != null) {
|
||||
final ModifiableRootModel rootModel = editor.getModifiableRootModelProxy();
|
||||
OrderEntryUtil.replaceLibrary(rootModel, oldLibrary, newLibrary);
|
||||
context.getDaemonAnalyzer().queueUpdate(new ModuleProjectStructureElement(context, module));
|
||||
}
|
||||
}
|
||||
else if (usage instanceof UsageInArtifact) {
|
||||
final PackagingElement<?> newLibraryElement = PackagingElementFactory.getInstance().createLibraryFiles(newLibrary.getName(),
|
||||
newLibrary.getTable().getTableLevel(), null);
|
||||
((UsageInArtifact)usage).replaceElement(newLibraryElement);
|
||||
}
|
||||
usage.replaceElement(new LibraryProjectStructureElement(context, newLibrary));
|
||||
}
|
||||
|
||||
if (!myCopy) {
|
||||
|
||||
+4
@@ -1,5 +1,7 @@
|
||||
package com.intellij.openapi.roots.ui.configuration.projectRoot.daemon;
|
||||
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
@@ -23,4 +25,6 @@ public abstract class ProjectStructureElementUsage {
|
||||
public abstract Icon getIcon();
|
||||
|
||||
public abstract void removeSourceElement();
|
||||
|
||||
public abstract void replaceElement(ProjectStructureElement newElement);
|
||||
}
|
||||
|
||||
+14
@@ -2,6 +2,9 @@ package com.intellij.openapi.roots.ui.configuration.projectRoot.daemon;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.impl.OrderEntryUtil;
|
||||
import com.intellij.openapi.roots.ui.configuration.ModuleEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -72,4 +75,15 @@ public class UsageInModuleClasspath extends ProjectStructureElementUsage {
|
||||
.removeLibraryOrderEntry(myModule, ((LibraryProjectStructureElement)mySourceElement).getLibrary());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceElement(final ProjectStructureElement newElement) {
|
||||
final ModuleEditor editor = myContext.getModulesConfigurator().getModuleEditor(myModule);
|
||||
if (editor != null) {
|
||||
final ModifiableRootModel rootModel = editor.getModifiableRootModelProxy();
|
||||
OrderEntryUtil.replaceLibrary(rootModel, ((LibraryProjectStructureElement)mySourceElement).getLibrary(),
|
||||
((LibraryProjectStructureElement)newElement).getLibrary());
|
||||
myContext.getDaemonAnalyzer().queueUpdate(new ModuleProjectStructureElement(myContext, myModule));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user