mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed adding source/javadoc roots to library created in the new project wizard
This commit is contained in:
+1
-2
@@ -108,9 +108,8 @@ public class LibraryCompositionSettings implements Disposable {
|
||||
@Nullable
|
||||
private Library createLibrary(final ModifiableRootModel rootModel, @Nullable LibrariesContainer additionalContainer) {
|
||||
if (myNewLibraryEditor != null) {
|
||||
VirtualFile[] roots = myNewLibraryEditor.getFiles(OrderRootType.CLASSES);
|
||||
return LibrariesContainerFactory.createLibrary(additionalContainer, LibrariesContainerFactory.createContainer(rootModel),
|
||||
myNewLibraryEditor.getName(), getLibraryLevel(), roots, VirtualFile.EMPTY_ARRAY);
|
||||
myNewLibraryEditor, getLibraryLevel());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
+15
@@ -126,6 +126,10 @@ public class NewLibraryEditor implements LibraryEditor {
|
||||
|
||||
public void apply(@NotNull Library.ModifiableModel model) {
|
||||
model.setName(myLibraryName);
|
||||
applyRoots(model);
|
||||
}
|
||||
|
||||
public void applyRoots(Library.ModifiableModel model) {
|
||||
for (OrderRootType type : myRoots.keySet()) {
|
||||
for (LightFilePointer pointer : myRoots.get(type)) {
|
||||
model.addRoot(pointer.getUrl(), type);
|
||||
@@ -135,4 +139,15 @@ public class NewLibraryEditor implements LibraryEditor {
|
||||
model.addJarDirectory(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void copyRoots(ExistingLibraryEditor editor) {
|
||||
for (OrderRootType type : myRoots.keySet()) {
|
||||
for (LightFilePointer pointer : myRoots.get(type)) {
|
||||
editor.addRoot(pointer.getUrl(), type);
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, Boolean> entry : myJarDirectories.entrySet()) {
|
||||
editor.addJarDirectory(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -19,6 +19,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -54,6 +55,8 @@ public interface LibrariesContainer {
|
||||
Library createLibrary(@NotNull @NonNls String name, @NotNull LibraryLevel level,
|
||||
@NotNull VirtualFile[] classRoots, @NotNull VirtualFile[] sourceRoots);
|
||||
|
||||
Library createLibrary(@NotNull NewLibraryEditor libraryEditor, @NotNull LibraryLevel level);
|
||||
|
||||
@NotNull
|
||||
String suggestUniqueLibraryName(@NotNull String baseName);
|
||||
|
||||
|
||||
+34
-26
@@ -25,6 +25,7 @@ import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
@@ -72,27 +73,21 @@ public class LibrariesContainerFactory {
|
||||
}
|
||||
|
||||
public static Library createLibrary(@Nullable LibrariesContainer container1, @NotNull LibrariesContainer container2,
|
||||
@NotNull @NonNls final String name, @NotNull final LibrariesContainer.LibraryLevel level,
|
||||
@NotNull final VirtualFile[] classRoots, @NotNull final VirtualFile[] sourceRoots) {
|
||||
@NotNull @NonNls final NewLibraryEditor editor, @NotNull final LibrariesContainer.LibraryLevel level) {
|
||||
if (container1 != null && container1.canCreateLibrary(level)) {
|
||||
return container1.createLibrary(name, level, classRoots, sourceRoots);
|
||||
return container1.createLibrary(editor, level);
|
||||
}
|
||||
else {
|
||||
return container2.createLibrary(name, level, classRoots, sourceRoots);
|
||||
return container2.createLibrary(editor, level);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Library createLibraryInTable(final @NonNls String name, final VirtualFile[] roots, final VirtualFile[] sources, final LibraryTable table) {
|
||||
private static Library createLibraryInTable(final @NotNull NewLibraryEditor editor, final LibraryTable table) {
|
||||
LibraryTable.ModifiableModel modifiableModel = table.getModifiableModel();
|
||||
Library library = modifiableModel.createLibrary(getUniqueLibraryName(name, modifiableModel));
|
||||
Library library = modifiableModel.createLibrary(getUniqueLibraryName(editor.getName(), modifiableModel));
|
||||
final Library.ModifiableModel model = library.getModifiableModel();
|
||||
for (VirtualFile root : roots) {
|
||||
model.addRoot(root, OrderRootType.CLASSES);
|
||||
}
|
||||
for (VirtualFile root : sources) {
|
||||
model.addRoot(root, OrderRootType.SOURCES);
|
||||
}
|
||||
editor.applyRoots(model);
|
||||
model.commit();
|
||||
modifiableModel.commit();
|
||||
return library;
|
||||
@@ -111,6 +106,22 @@ public class LibrariesContainerFactory {
|
||||
private abstract static class LibrariesContainerBase implements LibrariesContainer {
|
||||
private UniqueNameGenerator myNameGenerator;
|
||||
|
||||
@Override
|
||||
public Library createLibrary(@NotNull @NonNls String name,
|
||||
@NotNull LibraryLevel level,
|
||||
@NotNull VirtualFile[] classRoots,
|
||||
@NotNull VirtualFile[] sourceRoots) {
|
||||
NewLibraryEditor editor = new NewLibraryEditor();
|
||||
editor.setName(name);
|
||||
for (VirtualFile classRoot : classRoots) {
|
||||
editor.addRoot(classRoot, OrderRootType.CLASSES);
|
||||
}
|
||||
for (VirtualFile sourceRoot : sourceRoots) {
|
||||
editor.addRoot(sourceRoot, OrderRootType.SOURCES);
|
||||
}
|
||||
return createLibrary(editor, level);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Library[] getAllLibraries() {
|
||||
Library[] libraries = getLibraries(LibraryLevel.GLOBAL);
|
||||
@@ -204,10 +215,11 @@ public class LibrariesContainerFactory {
|
||||
return level == LibraryLevel.GLOBAL || myProject != null;
|
||||
}
|
||||
|
||||
public Library createLibrary(@NotNull @NonNls final String name, @NotNull final LibraryLevel level,
|
||||
@NotNull final VirtualFile[] classRoots, @NotNull final VirtualFile[] sourceRoots) {
|
||||
@Override
|
||||
public Library createLibrary(@NotNull NewLibraryEditor libraryEditor,
|
||||
@NotNull LibraryLevel level) {
|
||||
if (level == LibraryLevel.MODULE && myRootModel != null) {
|
||||
return createLibraryInTable(name, classRoots, sourceRoots, myRootModel.getModuleLibraryTable());
|
||||
return createLibraryInTable(libraryEditor, myRootModel.getModuleLibraryTable());
|
||||
}
|
||||
|
||||
LibraryTablesRegistrar registrar = LibraryTablesRegistrar.getInstance();
|
||||
@@ -221,7 +233,7 @@ public class LibrariesContainerFactory {
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
return createLibraryInTable(name, classRoots, sourceRoots, table);
|
||||
return createLibraryInTable(libraryEditor, table);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -239,22 +251,18 @@ public class LibrariesContainerFactory {
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
public Library createLibrary(@NotNull @NonNls final String name, @NotNull final LibraryLevel level,
|
||||
@NotNull final VirtualFile[] classRoots, @NotNull final VirtualFile[] sourceRoots) {
|
||||
@Override
|
||||
public Library createLibrary(@NotNull NewLibraryEditor libraryEditor,
|
||||
@NotNull LibraryLevel level) {
|
||||
LibraryTableModifiableModelProvider provider = getProvider(level);
|
||||
if (provider == null) {
|
||||
LOG.error("cannot create module library in this context");
|
||||
}
|
||||
|
||||
LibraryTable.ModifiableModel model = provider.getModifiableModel();
|
||||
Library library = model.createLibrary(getUniqueLibraryName(name, model));
|
||||
LibraryEditor libraryEditor = ((LibrariesModifiableModel)model).getLibraryEditor(library);
|
||||
for (VirtualFile root : classRoots) {
|
||||
libraryEditor.addRoot(root, OrderRootType.CLASSES);
|
||||
}
|
||||
for (VirtualFile source : sourceRoots) {
|
||||
libraryEditor.addRoot(source, OrderRootType.SOURCES);
|
||||
}
|
||||
Library library = model.createLibrary(getUniqueLibraryName(libraryEditor.getName(), model));
|
||||
ExistingLibraryEditor createdLibraryEditor = ((LibrariesModifiableModel)model).getLibraryEditor(library);
|
||||
libraryEditor.copyRoots(createdLibraryEditor);
|
||||
return library;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user