mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
set default dependency scope for framework libraries added to a module
This commit is contained in:
+11
-2
@@ -18,6 +18,9 @@ package com.intellij.facet.impl.ui.libraries;
|
||||
import com.intellij.framework.library.FrameworkLibraryVersion;
|
||||
import com.intellij.framework.library.FrameworkLibraryVersionFilter;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.roots.DependencyScope;
|
||||
import com.intellij.openapi.roots.LibraryDependencyScopeSuggester;
|
||||
import com.intellij.openapi.roots.LibraryOrderEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
|
||||
@@ -183,13 +186,19 @@ public class LibraryCompositionSettings implements Disposable {
|
||||
|
||||
if (library != null) {
|
||||
addedLibraries.add(library);
|
||||
DependencyScope scope = LibraryDependencyScopeSuggester.getDefaultScope(library);
|
||||
if (getLibraryLevel() != LibrariesContainer.LibraryLevel.MODULE) {
|
||||
rootModel.addLibraryEntry(library);
|
||||
rootModel.addLibraryEntry(library).setScope(scope);
|
||||
}
|
||||
else {
|
||||
LibraryOrderEntry orderEntry = rootModel.findLibraryOrderEntry(library);
|
||||
assert orderEntry != null;
|
||||
orderEntry.setScope(scope);
|
||||
}
|
||||
}
|
||||
if (mySelectedLibrary != null) {
|
||||
addedLibraries.add(mySelectedLibrary);
|
||||
rootModel.addLibraryEntry(mySelectedLibrary);
|
||||
rootModel.addLibraryEntry(mySelectedLibrary).setScope(LibraryDependencyScopeSuggester.getDefaultScope(mySelectedLibrary));
|
||||
}
|
||||
return library;
|
||||
}
|
||||
|
||||
+1
-15
@@ -112,24 +112,10 @@ class AddLibraryDependencyAction extends AddItemPopupAction<Library> {
|
||||
}
|
||||
}
|
||||
final LibraryOrderEntry orderEntry = rootModel.addLibraryEntry(item);
|
||||
DependencyScope defaultScope = getDefaultScope(item);
|
||||
if (defaultScope != null) {
|
||||
orderEntry.setScope(defaultScope);
|
||||
}
|
||||
orderEntry.setScope(LibraryDependencyScopeSuggester.getDefaultScope(item));
|
||||
return ClasspathTableItem.createLibItem(orderEntry, myContext);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static DependencyScope getDefaultScope(Library item) {
|
||||
for (LibraryDependencyScopeSuggester suggester : LibraryDependencyScopeSuggester.EP_NAME.getExtensions()) {
|
||||
DependencyScope scope = suggester.getDefaultDependencyScope(item);
|
||||
if (scope != null) {
|
||||
return scope;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClasspathElementChooser<Library> createChooser() {
|
||||
return new ExistingLibraryChooser();
|
||||
|
||||
@@ -28,4 +28,15 @@ public abstract class LibraryDependencyScopeSuggester {
|
||||
|
||||
@Nullable
|
||||
public abstract DependencyScope getDefaultDependencyScope(@NotNull Library library);
|
||||
|
||||
@NotNull
|
||||
public static DependencyScope getDefaultScope(@NotNull Library library) {
|
||||
for (LibraryDependencyScopeSuggester suggester : EP_NAME.getExtensions()) {
|
||||
DependencyScope scope = suggester.getDefaultDependencyScope(library);
|
||||
if (scope != null) {
|
||||
return scope;
|
||||
}
|
||||
}
|
||||
return DependencyScope.COMPILE;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user