use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.
the class CreateModuleLibraryFromFilesTest method testTwoJarAndSources.
public void testTwoJarAndSources() {
List<Library> libraries = createLibraries(new OrderRoot(getJDomJar(), OrderRootType.CLASSES), new OrderRoot(getAsmJar(), OrderRootType.CLASSES), new OrderRoot(getJDomSources(), OrderRootType.SOURCES));
Library library = assertOneElement(libraries);
assertNull(library.getName());
assertSameElements(library.getFiles(OrderRootType.CLASSES), getJDomJar(), getAsmJar());
assertSameElements(library.getFiles(OrderRootType.SOURCES), getJDomSources());
}
use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.
the class CreateModuleLibraryChooser method chooseElements.
@Override
@NotNull
public List<Library> chooseElements() {
final FileChooserDescriptor chooserDescriptor;
final List<Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor>> descriptors = new ArrayList<>();
for (LibraryRootsComponentDescriptor componentDescriptor : myLibraryTypes.keySet()) {
descriptors.add(Pair.create(componentDescriptor, componentDescriptor.createAttachFilesChooserDescriptor(null)));
}
if (descriptors.size() == 1) {
chooserDescriptor = descriptors.get(0).getSecond();
} else {
chooserDescriptor = new FileChooserDescriptor(true, true, true, false, true, false) {
@Override
public boolean isFileSelectable(VirtualFile file) {
for (Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor> pair : descriptors) {
if (pair.getSecond().isFileSelectable(file)) {
return true;
}
}
return false;
}
@Override
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
for (Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor> pair : descriptors) {
if (pair.getSecond().isFileVisible(file, showHiddenFiles)) {
return true;
}
}
return false;
}
};
}
chooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, myModule);
final Project project = myModule.getProject();
final VirtualFile[] files = FileChooser.chooseFiles(chooserDescriptor, myParentComponent, project, project.getBaseDir());
if (files.length == 0)
return Collections.emptyList();
List<LibraryRootsComponentDescriptor> suitableDescriptors = new ArrayList<>();
for (Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor> pair : descriptors) {
if (acceptAll(pair.getSecond(), files)) {
suitableDescriptors.add(pair.getFirst());
}
}
final LibraryRootsComponentDescriptor rootsComponentDescriptor;
LibraryType libraryType = null;
if (suitableDescriptors.size() == 1) {
rootsComponentDescriptor = suitableDescriptors.get(0);
libraryType = myLibraryTypes.get(rootsComponentDescriptor);
} else {
rootsComponentDescriptor = myDefaultDescriptor;
}
List<OrderRoot> chosenRoots = RootDetectionUtil.detectRoots(Arrays.asList(files), myParentComponent, project, rootsComponentDescriptor);
return createLibrariesFromRoots(chosenRoots, libraryType, myModuleLibrariesModel, myDefaultPropertiesFactory);
}
use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.
the class CreateModuleLibraryChooser method createLibraryFromRoots.
private static Library createLibraryFromRoots(@NotNull List<OrderRoot> roots, @Nullable final LibraryType libraryType, @NotNull LibraryTable.ModifiableModel moduleLibrariesModel, @Nullable Function<LibraryType, LibraryProperties> defaultPropertiesFactory) {
final PersistentLibraryKind kind = libraryType == null ? null : libraryType.getKind();
final Library library = moduleLibrariesModel.createLibrary(null, kind);
final LibraryEx.ModifiableModelEx libModel = (LibraryEx.ModifiableModelEx) library.getModifiableModel();
if (defaultPropertiesFactory != null) {
libModel.setProperties(defaultPropertiesFactory.fun(libraryType));
}
for (OrderRoot root : roots) {
if (root.isJarDirectory()) {
libModel.addJarDirectory(root.getFile(), false, root.getType());
} else {
libModel.addRoot(root.getFile(), root.getType());
}
}
libModel.commit();
return library;
}
use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.
the class LibrarySourceRootDetectorUtil method scanAndSelectDetectedJavaSourceRoots.
/**
* This method takes a candidates for the project root, then scans the candidates and
* if multiple candidates or non root source directories are found within some
* directories, it shows a dialog that allows selecting or deselecting them.
* @param parent a parent parent or project
* @param rootCandidates a candidates for roots
* @return a array of source folders or empty array if non was selected or dialog was canceled.
*/
public static VirtualFile[] scanAndSelectDetectedJavaSourceRoots(Component parentComponent, final VirtualFile[] rootCandidates) {
final List<OrderRoot> orderRoots = RootDetectionUtil.detectRoots(Arrays.asList(rootCandidates), parentComponent, null, new LibraryRootsDetectorImpl(Arrays.asList(Extensions.getExtensions(JAVA_SOURCE_ROOT_DETECTOR))), new OrderRootType[] { OrderRootType.SOURCES });
final List<VirtualFile> result = new ArrayList<>();
for (OrderRoot root : orderRoots) {
result.add(root.getFile());
}
return VfsUtil.toVirtualFileArray(result);
}
use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project android by JetBrains.
the class CreateLibraryFromFilesAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final Project project = getEventProject(e);
if (project == null)
return;
if (!AndroidProjectInfo.getInstance(project).requiresAndroidModel()) {
myDelegate.actionPerformed(e);
return;
}
final List<VirtualFile> jars = getRoots(e);
if (jars.isEmpty()) {
return;
}
final List<OrderRoot> roots = RootDetectionUtil.detectRoots(jars, null, project, new DefaultLibraryRootsComponentDescriptor());
new CreateGradleLibraryFromFilesDialog(project, roots).show();
}
Aggregations