use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.
the class RepositoryLibraryWithDescriptionEditor method edit.
@Override
protected void edit() {
@NotNull RepositoryLibraryProperties properties = myEditorComponent.getProperties();
//String oldVersion = properties.getVersion();
boolean wasGeneratedName = RepositoryLibraryType.getInstance().getDescription(properties).equals(myEditorComponent.getLibraryEditor().getName());
RepositoryLibraryPropertiesModel model = new RepositoryLibraryPropertiesModel(properties.getVersion(), RepositoryUtils.libraryHasSources(myEditorComponent.getLibraryEditor()), RepositoryUtils.libraryHasJavaDocs(myEditorComponent.getLibraryEditor()));
RepositoryLibraryPropertiesDialog dialog = new RepositoryLibraryPropertiesDialog(myEditorComponent.getProject(), model, RepositoryLibraryDescription.findDescription(properties), true);
if (!dialog.showAndGet()) {
return;
}
myEditorComponent.getProperties().changeVersion(model.getVersion());
if (wasGeneratedName) {
myEditorComponent.renameLibrary(RepositoryLibraryType.getInstance().getDescription(properties));
}
final LibraryEditor libraryEditor = myEditorComponent.getLibraryEditor();
MavenDependenciesRemoteManager.getInstance(myEditorComponent.getProject()).downloadDependenciesAsync(properties, model.isDownloadSources(), model.isDownloadJavaDocs(), RepositoryUtils.getStorageRoot(myEditorComponent.getLibraryEditor().getUrls(OrderRootType.CLASSES), myEditorComponent.getProject()), new MavenRemoteTask.ResultProcessor<List<OrderRoot>>() {
@Override
public void process(@Nullable List<OrderRoot> roots) {
libraryEditor.removeAllRoots();
if (roots != null) {
libraryEditor.addRoots(roots);
}
}
});
}
use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.
the class RepositoryUtils method loadDependencies.
public static void loadDependencies(@NotNull final Project project, @NotNull final LibraryEx library, boolean downloadSources, boolean downloadJavaDocs, @Nullable String copyTo) {
if (library.getKind() != RepositoryLibraryType.REPOSITORY_LIBRARY_KIND) {
return;
}
final RepositoryLibraryProperties properties = (RepositoryLibraryProperties) library.getProperties();
MavenDependenciesRemoteManager.getInstance(project).downloadDependenciesAsync(properties, downloadSources, downloadJavaDocs, copyTo, new MavenRemoteTask.ResultProcessor<List<OrderRoot>>() {
@Override
public void process(@Nullable final List<OrderRoot> roots) {
if (roots == null || roots.isEmpty()) {
ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(project, ProjectBundle.message("maven.downloading.failed", properties.getMavenId()), CommonBundle.getErrorTitle()));
return;
}
ApplicationManager.getApplication().invokeLater(() -> {
if (library.isDisposed()) {
return;
}
WriteAction.run(() -> {
final NewLibraryEditor editor = new NewLibraryEditor(null, properties);
editor.removeAllRoots();
editor.addRoots(roots);
final Library.ModifiableModel model = library.getModifiableModel();
editor.applyTo((LibraryEx.ModifiableModelEx) model);
model.commit();
});
});
}
});
}
use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.
the class RepositoryAttachHandler method createRoots.
public static List<OrderRoot> createRoots(@NotNull Collection<MavenArtifact> artifacts, @Nullable String copyTo) {
final List<OrderRoot> result = new ArrayList<>();
final VirtualFileManager manager = VirtualFileManager.getInstance();
for (MavenArtifact each : artifacts) {
try {
File repoFile = each.getFile();
File toFile = repoFile;
if (copyTo != null) {
toFile = new File(copyTo, repoFile.getName());
if (repoFile.exists()) {
FileUtil.copy(repoFile, toFile);
}
}
// search for jar file first otherwise lib root won't be found!
manager.refreshAndFindFileByUrl(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(toFile.getPath())));
final String url = VfsUtil.getUrlForLibraryRoot(toFile);
final VirtualFile file = manager.refreshAndFindFileByUrl(url);
if (file != null) {
OrderRootType rootType;
if (MavenExtraArtifactType.DOCS.getDefaultClassifier().equals(each.getClassifier())) {
rootType = JavadocOrderRootType.getInstance();
} else if (MavenExtraArtifactType.SOURCES.getDefaultClassifier().equals(each.getClassifier())) {
rootType = OrderRootType.SOURCES;
} else {
rootType = OrderRootType.CLASSES;
}
result.add(new OrderRoot(file, rootType));
}
} catch (IOException e) {
MavenLog.LOG.warn(e);
}
}
return result;
}
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