use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project android by JetBrains.
the class AndroidSdks method setUpSdk.
public void setUpSdk(@NotNull Sdk androidSdk, @NotNull SdkModificator androidSdkModificator, @NotNull IAndroidTarget target, @NotNull String sdkName, @NotNull Collection<Sdk> allSdks, @Nullable Sdk jdk, boolean addRoots) {
AndroidSdkAdditionalData data = new AndroidSdkAdditionalData(androidSdk, jdk);
data.setBuildTarget(target);
String name = createUniqueSdkName(sdkName, allSdks);
androidSdkModificator.setName(name);
if (jdk != null) {
androidSdkModificator.setVersionString(jdk.getVersionString());
}
androidSdkModificator.setSdkAdditionalData(data);
if (addRoots) {
List<OrderRoot> newRoots = getLibraryRootsForTarget(target, androidSdk, true);
androidSdkModificator.removeAllRoots();
for (OrderRoot orderRoot : newRoots) {
androidSdkModificator.addRoot(orderRoot.getFile(), orderRoot.getType());
}
// TODO move this method to Jdks.
attachJdkAnnotations(androidSdkModificator);
}
// Add sources at the end, otherwise if 'addRoots' is true, removing all existing roots will delete sources as well.
// https://code.google.com/p/android/issues/detail?id=233221
findAndSetPlatformSources(target, androidSdkModificator);
}
use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project azure-tools-for-java by Microsoft.
the class LibrariesConfigurationDialog method addLibrary.
private void addLibrary() {
AddLibraryWizardModel model = new AddLibraryWizardModel(module);
AddLibraryWizardDialog wizard = new AddLibraryWizardDialog(model);
wizard.setTitle(message("addLibraryTitle"));
wizard.show();
if (wizard.isOK()) {
AzureLibrary azureLibrary = model.getSelectedLibrary();
final LibrariesContainer.LibraryLevel level = LibrariesContainer.LibraryLevel.MODULE;
AccessToken token = WriteAction.start();
try {
final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
if (orderEntry instanceof ModuleLibraryOrderEntryImpl && azureLibrary.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
PluginUtil.displayErrorDialog(message("error"), message("libraryExistsError"));
return;
}
}
Library newLibrary = LibrariesContainerFactory.createContainer(modifiableModel).createLibrary(azureLibrary.getName(), level, new ArrayList<OrderRoot>());
if (model.isExported()) {
for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
if (orderEntry instanceof ModuleLibraryOrderEntryImpl && azureLibrary.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
((ModuleLibraryOrderEntryImpl) orderEntry).setExported(true);
break;
}
}
}
Library.ModifiableModel newLibraryModel = newLibrary.getModifiableModel();
// if there is separate resources folder
if (azureLibrary.getLocation() != null) {
File file = new File(String.format("%s%s%s", AzurePlugin.pluginFolder, File.separator, azureLibrary.getLocation()));
AddLibraryUtility.addLibraryRoot(file, newLibraryModel);
}
// if some files already contained in plugin dependencies, take them from there - true for azure sdk library
if (azureLibrary.getFiles().length > 0) {
AddLibraryUtility.addLibraryFiles(new File(PluginHelper.getAzureLibLocation()), newLibraryModel, azureLibrary.getFiles());
}
newLibraryModel.commit();
modifiableModel.commit();
((DefaultListModel) librariesList.getModel()).addElement(azureLibrary);
tempList.add(azureLibrary);
} catch (Exception ex) {
PluginUtil.displayErrorDialogAndLog(message("error"), message("addLibraryError"), ex);
} finally {
token.finish();
}
LocalFileSystem.getInstance().findFileByPath(PluginUtil.getModulePath(module)).refresh(true, true);
}
}
use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project azure-tools-for-java by Microsoft.
the class SparkLibraryOptionsPanel method getNewLibraryEditor.
private NewLibraryEditor getNewLibraryEditor(@NotNull String path) {
if (StringHelper.isNullOrWhiteSpace(path)) {
return null;
}
VirtualFile root = LocalFileSystem.getInstance().findFileByPath(path);
if (root == null) {
return null;
}
final FileChooserDescriptor chooserDescriptor = new FileChooserDescriptor(false, false, true, false, true, false);
VirtualFile[] libraryFiles = VfsUtilCore.toVirtualFileArray(FileChooserUtil.getChosenFiles(chooserDescriptor, Arrays.asList(root)));
try {
chooserDescriptor.validateSelectedFiles(libraryFiles);
} catch (Exception exception) {
//do noting if check failed
return null;
}
final List<OrderRoot> roots = RootDetectionUtil.detectRoots(Arrays.asList(libraryFiles), null, null, new DefaultLibraryRootsComponentDescriptor());
if (roots.isEmpty()) {
return null;
}
NewLibraryConfiguration configuration = new NewLibraryConfiguration(LibraryTypeServiceImpl.suggestLibraryName(roots), SparkLibraryType.getInstance(), new SparkLibraryProperties()) {
@Override
public void addRoots(@NotNull LibraryEditor libraryEditor) {
libraryEditor.addRoots(roots);
}
};
if (configuration != null) {
NewLibraryEditor libraryEditor = new NewLibraryEditor(configuration.getLibraryType(), configuration.getProperties());
libraryEditor.setName(suggestUniqueLibraryName(configuration.getDefaultLibraryName()));
configuration.addRoots(libraryEditor);
return libraryEditor;
}
return null;
}
use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.
the class CreateLibraryFromFilesDialog method findModule.
@Nullable
private Module findModule(List<OrderRoot> roots) {
for (OrderRoot root : roots) {
Module module = null;
final VirtualFile local = JarFileSystem.getInstance().getVirtualFileForJar(root.getFile());
if (local != null) {
module = ModuleUtil.findModuleForFile(local, myProject);
}
if (module == null) {
module = ModuleUtil.findModuleForFile(root.getFile(), myProject);
}
if (module != null) {
return module;
}
}
return null;
}
use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.
the class CreateModuleLibraryChooser method filterAlreadyAdded.
private static List<OrderRoot> filterAlreadyAdded(final List<OrderRoot> roots, LibraryTable.ModifiableModel moduleLibrariesModel) {
if (roots == null || roots.isEmpty()) {
return Collections.emptyList();
}
final List<OrderRoot> result = new ArrayList<>();
final Library[] libraries = moduleLibrariesModel.getLibraries();
for (OrderRoot root : roots) {
if (!Arrays.stream(libraries).anyMatch(library -> contains(root.getFile(), library.getFiles(root.getType())))) {
result.add(root);
}
}
return result;
}
Aggregations