From 1037f64ac2290334560b08c70d7e41ca255eff7c Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Thu, 11 Aug 2011 13:30:49 +0400 Subject: [PATCH 01/13] Quick fix for "too many threads" issue --- .../status/GitUntrackedFilesHolder.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/plugins/git4idea/src/git4idea/status/GitUntrackedFilesHolder.java b/plugins/git4idea/src/git4idea/status/GitUntrackedFilesHolder.java index 5ec11214fa58..1d259e7f7fbb 100644 --- a/plugins/git4idea/src/git4idea/status/GitUntrackedFilesHolder.java +++ b/plugins/git4idea/src/git4idea/status/GitUntrackedFilesHolder.java @@ -312,18 +312,21 @@ public class GitUntrackedFilesHolder implements Disposable, BulkFileListener { } private void asyncRefreshFiles(final Set filesCreated) { - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { - public void run() { - Set filesToRefresh = new HashSet(); - for (VirtualFile file : filesCreated) { - if (belongsToThisRepository(file) && !myChangeListManager.isIgnoredFile(file)) { - filesToRefresh.add(file); - } - } - rescanFiles(filesToRefresh); - myDirtyScopeManager.filesDirty(filesToRefresh, null); // make ChangeListManager capture new info + final Set filesToRefresh = new HashSet(); + for (VirtualFile file : filesCreated) { + if (belongsToThisRepository(file) && !myChangeListManager.isIgnoredFile(file)) { + filesToRefresh.add(file); } - }); + } + + if (!filesToRefresh.isEmpty()) { + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + public void run() { + rescanFiles(filesToRefresh); + myDirtyScopeManager.filesDirty(filesToRefresh, null); // make ChangeListManager capture new info + } + }); + } } private boolean belongsToThisRepository(VirtualFile file) { From 1c3c28fb00c98c103c9dbfbaadb7b647b4e2062c Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 11 Aug 2011 13:42:13 +0400 Subject: [PATCH 02/13] IDEA-59460: Add menu entry for opening library settings on libraries in project view --- .../IdeaProjectSettingsService.java | 8 +-- .../ProjectStructureConfigurable.java | 25 ++++++- .../artifacts/ArtifactEditorContextImpl.java | 3 +- .../AnalyzeDependenciesComponent.java | 7 +- .../AddExistingCustomLibraryAction.java | 10 +-- .../libraries/CreateCustomLibraryAction.java | 20 +++--- .../libraries/CustomLibraryActionBase.java | 10 +-- .../projectRoot/ModuleConfigurable.java | 2 +- .../ModuleStructureConfigurable.java | 27 ++------ .../daemon/UsageInModuleClasspath.java | 4 +- .../documentation/DocumentationManager.java | 3 +- .../impl/nodes/NamedLibraryElementNode.java | 22 +++---- .../impl/nodes/PsiDirectoryNode.java | 7 +- .../projectView/impl/nodes/PsiFileNode.java | 65 ++++++++++++++++--- .../roots/libraries/LibraryNavigatable.java | 7 +- .../configuration/ProjectSettingsService.java | 18 ++--- 16 files changed, 142 insertions(+), 96 deletions(-) diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/IdeaProjectSettingsService.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/IdeaProjectSettingsService.java index ed1cbe542a1b..cb44dfd80ecb 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/IdeaProjectSettingsService.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/IdeaProjectSettingsService.java @@ -16,7 +16,6 @@ package com.intellij.openapi.roots.ui.configuration; import com.intellij.ide.projectView.impl.ModuleGroup; -import com.intellij.ide.projectView.impl.nodes.NamedLibraryElement; import com.intellij.ide.util.projectWizard.JdkChooserPanel; import com.intellij.openapi.module.Module; import com.intellij.openapi.options.ShowSettingsUtil; @@ -85,21 +84,20 @@ public class IdeaProjectSettingsService extends ProjectSettingsService { ShowSettingsUtil.getInstance().editConfigurable(myProject, ProjectStructureConfigurable.getInstance(myProject), new Runnable() { @Override public void run() { - ModuleStructureConfigurable.getInstance(myProject).selectOrderEntry(module, orderEntry); + ProjectStructureConfigurable.getInstance(myProject).selectOrderEntry(module, orderEntry); } }); } @Override - public boolean canOpenProjectLibrarySettings(NamedLibraryElement value) { + public boolean canOpenLibraryOrSdkSettings(OrderEntry orderEntry) { return true; } - public void openProjectLibrarySettings(final NamedLibraryElement element) { + public void openLibraryOrSdkSettings(@NotNull final OrderEntry orderEntry) { final ProjectStructureConfigurable config = ProjectStructureConfigurable.getInstance(myProject); ShowSettingsUtil.getInstance().editConfigurable(myProject, config, new Runnable() { public void run() { - final OrderEntry orderEntry = element.getOrderEntry(); if (orderEntry instanceof JdkOrderEntry) { config.select(((JdkOrderEntry)orderEntry).getJdk(), true); } else { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java index c149f5e66a08..1db3b05fecf3 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ProjectStructureConfigurable.java @@ -20,6 +20,7 @@ import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleConfigurationEditor; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.options.BaseConfigurable; import com.intellij.openapi.options.Configurable; @@ -30,6 +31,7 @@ import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.LibraryOrderEntry; +import com.intellij.openapi.roots.OrderEntry; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar; import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactsStructureConfigurable; @@ -420,15 +422,32 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se public ActionCallback select(@NotNull LibraryOrderEntry libraryOrderEntry, final boolean requestFocus) { final Library lib = libraryOrderEntry.getLibrary(); if (lib == null || lib.getTable() == null) { - Place place = createPlaceFor(myModulesConfig); - place.putPath(BaseStructureConfigurable.TREE_OBJECT, libraryOrderEntry.getOwnerModule()); - return navigateTo(place, requestFocus); + return selectOrderEntry(libraryOrderEntry.getOwnerModule(), libraryOrderEntry); } Place place = createPlaceFor(getConfigurableFor(lib)); place.putPath(BaseStructureConfigurable.TREE_NAME, libraryOrderEntry.getLibraryName()); return navigateTo(place, requestFocus); } + public ActionCallback selectOrderEntry(@NotNull final Module module, @Nullable final OrderEntry orderEntry) { + return select(module.getName(), null, true).doWhenDone(new Runnable() { + public void run() { + final MasterDetailsComponent.MyNode node = ModuleStructureConfigurable.getInstance(myProject).findModuleNode(module); + if (node != null) { + ModuleConfigurable moduleConfigurable = (ModuleConfigurable)node.getConfigurable(); + ModuleEditor moduleEditor = moduleConfigurable.getModuleEditor(); + moduleEditor.setSelectedTabName(ClasspathEditor.NAME); + if (orderEntry != null) { + ModuleConfigurationEditor editor = moduleEditor.getEditor(ClasspathEditor.NAME); + if (editor instanceof ClasspathEditor) { + ((ClasspathEditor)editor).selectOrderEntry(orderEntry); + } + } + } + } + }); + } + public ActionCallback navigateTo(@Nullable final Place place, final boolean requestFocus) { final Configurable toSelect = (Configurable)place.getPath(CATEGORY); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java index 25ed97cb012f..e55af48bc8bb 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java @@ -30,7 +30,6 @@ import com.intellij.openapi.roots.ui.configuration.ChooseModulesDialog; import com.intellij.openapi.roots.ui.configuration.FacetsProvider; import com.intellij.openapi.roots.ui.configuration.ModulesProvider; import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable; -import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable; import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.artifacts.ArtifactModel; import com.intellij.packaging.artifacts.ArtifactType; @@ -124,7 +123,7 @@ public class ArtifactEditorContextImpl implements ArtifactEditorContext { final ModuleLibraryOrderEntryImpl libraryEntry = (ModuleLibraryOrderEntryImpl)entry; if (libraryName != null && libraryName.equals(libraryEntry.getLibraryName()) || libraryName == null && library.equals(libraryEntry.getLibrary())) { - ModuleStructureConfigurable.getInstance(getProject()).selectOrderEntry(module, libraryEntry); + ProjectStructureConfigurable.getInstance(getProject()).selectOrderEntry(module, libraryEntry); return; } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/dependencyAnalysis/AnalyzeDependenciesComponent.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/dependencyAnalysis/AnalyzeDependenciesComponent.java index fd4f1779f582..bde56cba8bc7 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/dependencyAnalysis/AnalyzeDependenciesComponent.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/dependencyAnalysis/AnalyzeDependenciesComponent.java @@ -26,7 +26,7 @@ import com.intellij.openapi.roots.ModuleRootEvent; import com.intellij.openapi.roots.ModuleRootListener; import com.intellij.openapi.roots.ModuleSourceOrderEntry; import com.intellij.openapi.roots.OrderEntry; -import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable; +import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable; import com.intellij.openapi.roots.ui.util.CellAppearance; import com.intellij.openapi.roots.ui.util.OrderEntryCellAppearanceUtils; import com.intellij.openapi.ui.MasterDetailsComponent; @@ -39,8 +39,8 @@ import com.intellij.ui.PopupHandler; import com.intellij.ui.SimpleColoredComponent; import com.intellij.ui.SimpleTextAttributes; import com.intellij.ui.components.JBScrollPane; -import com.intellij.util.PathUtil; import com.intellij.ui.treeStructure.Tree; +import com.intellij.util.PathUtil; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.tree.TreeUtil; @@ -269,13 +269,12 @@ public class AnalyzeDependenciesComponent extends MasterDetailsComponent { if (module == null) { return; } - ModuleStructureConfigurable c = ModuleStructureConfigurable.getInstance(module.getProject()); final ModuleDependenciesAnalyzer.OrderPathElement element = e.getData(ORDER_PATH_ELEMENT_KEY); if (element != null && element instanceof ModuleDependenciesAnalyzer.OrderEntryPathElement) { final ModuleDependenciesAnalyzer.OrderEntryPathElement o = (ModuleDependenciesAnalyzer.OrderEntryPathElement)element; final OrderEntry entry = o.entry(); final Module m = entry.getOwnerModule(); - c.selectOrderEntry(m, entry); + ProjectStructureConfigurable.getInstance(module.getProject()).selectOrderEntry(m, entry); } } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/AddExistingCustomLibraryAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/AddExistingCustomLibraryAction.java index 763d6df14404..c174ee0587f1 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/AddExistingCustomLibraryAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/AddExistingCustomLibraryAction.java @@ -20,7 +20,7 @@ import com.intellij.openapi.module.Module; 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.projectRoot.ModuleStructureConfigurable; +import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable; import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; import javax.swing.*; @@ -29,15 +29,15 @@ import javax.swing.*; * @author nik */ public class AddExistingCustomLibraryAction extends CustomLibraryActionBase { - private Library myLibrary; + private final Library myLibrary; public AddExistingCustomLibraryAction(Library library, Icon icon, CustomLibraryCreator creator, StructureConfigurableContext context, - ModuleStructureConfigurable moduleStructureConfigurable, + ProjectStructureConfigurable projectStructureConfigurable, Module module) { - super(library.getName(), null, icon, context, moduleStructureConfigurable, creator, module); + super(library.getName(), null, icon, context, projectStructureConfigurable, creator, module); myLibrary = library; } @@ -48,6 +48,6 @@ public class AddExistingCustomLibraryAction extends CustomLibraryActionBase { return; } final LibraryOrderEntry orderEntry = rootModel.addLibraryEntry(myLibrary); - myModuleStructureConfigurable.selectOrderEntry(myModule, orderEntry); + myProjectStructureConfigurable.selectOrderEntry(myModule, orderEntry); } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CreateCustomLibraryAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CreateCustomLibraryAction.java index bb492146eab0..f1e61d3ed7d2 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CreateCustomLibraryAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CreateCustomLibraryAction.java @@ -29,12 +29,14 @@ import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryKind; import com.intellij.openapi.roots.libraries.LibraryTable; import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar; +import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable; import com.intellij.openapi.roots.ui.configuration.libraryEditor.CreateNewLibraryDialog; import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor; import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer; import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory; import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable; import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; +import com.intellij.ui.treeStructure.Tree; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -46,13 +48,14 @@ import java.util.*; public class CreateCustomLibraryAction extends CustomLibraryActionBase { private CreateCustomLibraryAction(final String name, CustomLibraryCreator creator, StructureConfigurableContext context, - ModuleStructureConfigurable moduleStructureConfigurable, Module module) { - super(name, null, creator.getIcon(), context, moduleStructureConfigurable, creator, module); + ProjectStructureConfigurable projectStructureConfigurable, Module module) { + super(name, null, creator.getIcon(), context, projectStructureConfigurable, creator, module); } @Override public void actionPerformed(AnActionEvent e) { - final NewLibraryConfiguration libraryConfiguration = myCreator.getDescription().createNewLibrary(myModuleStructureConfigurable.getTree(), + final Tree parentComponent = ModuleStructureConfigurable.getInstance(myContext.getProject()).getTree(); + final NewLibraryConfiguration libraryConfiguration = myCreator.getDescription().createNewLibrary(parentComponent, null); if (libraryConfiguration == null) { return; @@ -64,7 +67,7 @@ public class CreateCustomLibraryAction extends CustomLibraryActionBase { LibraryTablesRegistrar registrar = LibraryTablesRegistrar.getInstance(); final Project project = myContext.getProject(); final List tables = Arrays.asList(registrar.getLibraryTable(project), registrar.getLibraryTable()); - final CreateNewLibraryDialog dialog = new CreateNewLibraryDialog(myModuleStructureConfigurable.getTree(), myContext, libraryEditor, tables, 0); + final CreateNewLibraryDialog dialog = new CreateNewLibraryDialog(parentComponent, myContext, libraryEditor, tables, 0); dialog.show(); if (dialog.isOK()) { final Library library = dialog.createLibrary(); @@ -73,7 +76,7 @@ public class CreateCustomLibraryAction extends CustomLibraryActionBase { return; } final LibraryOrderEntry orderEntry = rootModel.addLibraryEntry(library); - myModuleStructureConfigurable.selectOrderEntry(myModule, orderEntry); + myProjectStructureConfigurable.selectOrderEntry(myModule, orderEntry); } } @@ -81,6 +84,7 @@ public class CreateCustomLibraryAction extends CustomLibraryActionBase { final Module module = moduleStructureConfigurable.getSelectedModule(); if (module == null) return Collections.emptyList(); + final ProjectStructureConfigurable projectStructureConfigurable = ProjectStructureConfigurable.getInstance(module.getProject()); final List actions = new ArrayList(); final LibrariesContainer container = LibrariesContainerFactory.createContainer(context); for (CustomLibraryCreator creator : CustomLibraryCreator.EP_NAME.getExtensions()) { @@ -98,15 +102,15 @@ public class CreateCustomLibraryAction extends CustomLibraryActionBase { final Predicate notAddedLibrariesCondition = LibraryEditingUtil.getNotAddedLibrariesCondition(context.getModulesConfigurator().getRootModel(module)); final Collection librariesToAdd = Collections2.filter(libraries, Predicates.and(suitablePredicate, notAddedLibrariesCondition)); if (librariesToAdd.isEmpty()) { - actions.add(new CreateCustomLibraryAction(creator.getDisplayName(), creator, context, moduleStructureConfigurable, module)); + actions.add(new CreateCustomLibraryAction(creator.getDisplayName(), creator, context, projectStructureConfigurable, module)); } else { final DefaultActionGroup group = new DefaultActionGroup(creator.getDisplayName(), true); group.getTemplatePresentation().setIcon(creator.getIcon()); - group.add(new CreateCustomLibraryAction("New...", creator, context, moduleStructureConfigurable, module)); + group.add(new CreateCustomLibraryAction("New...", creator, context, projectStructureConfigurable, module)); for (Library library : librariesToAdd) { Icon icon = LibraryPresentationManager.getInstance().getNamedLibraryIcon(library, context); - group.add(new AddExistingCustomLibraryAction(library, icon, creator, context, moduleStructureConfigurable, module)); + group.add(new AddExistingCustomLibraryAction(library, icon, creator, context, projectStructureConfigurable, module)); } actions.add(group); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CustomLibraryActionBase.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CustomLibraryActionBase.java index 32f4b3f17b73..16058bb70f68 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CustomLibraryActionBase.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CustomLibraryActionBase.java @@ -21,9 +21,9 @@ import com.intellij.openapi.roots.LibraryOrderEntry; import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.roots.OrderEntry; import com.intellij.openapi.roots.libraries.Library; +import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable; import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer; import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory; -import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable; import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; import com.intellij.openapi.ui.Messages; import org.jetbrains.annotations.NotNull; @@ -38,14 +38,14 @@ import java.util.List; public abstract class CustomLibraryActionBase extends DumbAwareAction { protected final CustomLibraryCreator myCreator; protected final StructureConfigurableContext myContext; - protected final ModuleStructureConfigurable myModuleStructureConfigurable; - protected Module myModule; + protected final ProjectStructureConfigurable myProjectStructureConfigurable; + protected final Module myModule; protected CustomLibraryActionBase(String text, String description, Icon icon, StructureConfigurableContext context, - ModuleStructureConfigurable moduleStructureConfigurable, CustomLibraryCreator creator, Module module) { + ProjectStructureConfigurable projectStructureConfigurable, CustomLibraryCreator creator, Module module) { super(text, description, icon); myContext = context; - myModuleStructureConfigurable = moduleStructureConfigurable; + myProjectStructureConfigurable = projectStructureConfigurable; myCreator = creator; myModule = module; } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleConfigurable.java index aa645ed865fb..3584e55b996a 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleConfigurable.java @@ -130,7 +130,7 @@ public class ModuleConfigurable extends ProjectStructureElementConfigurable getChildren() { final List children = new ArrayList(); @@ -107,22 +103,24 @@ public class NamedLibraryElementNode extends ProjectViewNode implements Navig service.openModuleSettings(module); } else if (ProjectRootsUtil.isLibraryRoot(file, project)) { - service.openModuleLibrarySettings(module); + final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(file, module.getProject()); + if (orderEntry != null) { + service.openLibraryOrSdkSettings(orderEntry); + } } else { service.openContentEntriesSettings(module); diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiFileNode.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiFileNode.java index 45cbf3bc1037..c89bcab3a4a5 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiFileNode.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiFileNode.java @@ -19,13 +19,18 @@ package com.intellij.ide.projectView.impl.nodes; import com.intellij.ide.highlighter.ArchiveFileType; import com.intellij.ide.projectView.PresentationData; import com.intellij.ide.projectView.ViewSettings; +import com.intellij.ide.projectView.impl.ProjectRootsUtil; import com.intellij.ide.util.treeView.AbstractTreeNode; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectUtil; +import com.intellij.openapi.roots.OrderEntry; +import com.intellij.openapi.roots.libraries.LibraryUtil; +import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService; import com.intellij.openapi.util.Iconable; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.pom.NavigatableWithText; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; @@ -36,20 +41,18 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; -public class PsiFileNode extends BasePsiNode{ +public class PsiFileNode extends BasePsiNode implements NavigatableWithText { public PsiFileNode(Project project, PsiFile value, ViewSettings viewSettings) { super(project, value, viewSettings); } public Collection getChildrenImpl() { - if (isArchive()) { - VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(getVirtualFile()); - if (jarRoot != null) { - PsiDirectory psiDirectory = PsiManager.getInstance(getProject()).findDirectory(jarRoot); - if (psiDirectory != null) { - return ProjectViewDirectoryHelper.getInstance(getProject()).getDirectoryChildren(psiDirectory, getSettings(), true); - } + VirtualFile jarRoot = getJarRoot(); + if (jarRoot != null) { + PsiDirectory psiDirectory = PsiManager.getInstance(getProject()).findDirectory(jarRoot); + if (psiDirectory != null) { + return ProjectViewDirectoryHelper.getInstance(getProject()).getDirectoryChildren(psiDirectory, getSettings(), true); } } @@ -72,6 +75,52 @@ public class PsiFileNode extends BasePsiNode{ return value != null ? value.getVirtualFile() : null; } + @Override + public boolean canNavigate() { + return isNavigatableLibraryRoot() || super.canNavigate(); + } + + private boolean isNavigatableLibraryRoot() { + VirtualFile jarRoot = getJarRoot(); + final Project project = getProject(); + if (jarRoot != null && ProjectRootsUtil.isLibraryRoot(jarRoot, project)) { + final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(jarRoot, project); + return orderEntry != null && ProjectSettingsService.getInstance(project).canOpenLibraryOrSdkSettings(orderEntry); + } + return false; + } + + @Nullable + private VirtualFile getJarRoot() { + final VirtualFile file = getVirtualFile(); + if (file == null || !file.isValid() || !(file.getFileType() instanceof ArchiveFileType)) { + return null; + } + return JarFileSystem.getInstance().getJarRootForLocalFile(file); + } + + @Override + public void navigate(boolean requestFocus) { + VirtualFile jarRoot = getJarRoot(); + final Project project = getProject(); + if (jarRoot != null && ProjectRootsUtil.isLibraryRoot(jarRoot, project)) { + final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(jarRoot, project); + if (orderEntry != null) { + ProjectSettingsService.getInstance(project).openLibraryOrSdkSettings(orderEntry); + return; + } + } + super.navigate(requestFocus); + } + + @Override + public String getNavigateActionText(boolean focusEditor) { + if (isNavigatableLibraryRoot()) { + return "Open Library Settings"; + } + return null; + } + public int getWeight() { return 20; } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryNavigatable.java b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryNavigatable.java index 80d00c99ba9b..37f0f751214b 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryNavigatable.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/LibraryNavigatable.java @@ -15,7 +15,6 @@ */ package com.intellij.openapi.roots.libraries; -import com.intellij.ide.projectView.impl.nodes.NamedLibraryElement; import com.intellij.openapi.module.Module; import com.intellij.openapi.roots.LibraryOrderEntry; import com.intellij.openapi.roots.ModuleRootManager; @@ -29,14 +28,14 @@ import org.jetbrains.annotations.NotNull; */ public class LibraryNavigatable implements Navigatable { private final Module module; - private NamedLibraryElement element; + private OrderEntry element; public LibraryNavigatable(@NotNull Library library, @NotNull Module module) { this.module = module; for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) { if (entry instanceof LibraryOrderEntry) { if (((LibraryOrderEntry)entry).getLibrary() == library) { - element = new NamedLibraryElement(module, entry); + element = entry; } } } @@ -44,7 +43,7 @@ public class LibraryNavigatable implements Navigatable { @Override public void navigate(boolean requestFocus) { - ProjectSettingsService.getInstance(module.getProject()).openProjectLibrarySettings(element); + ProjectSettingsService.getInstance(module.getProject()).openLibraryOrSdkSettings(element); } @Override diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ProjectSettingsService.java b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ProjectSettingsService.java index 08621d9bb3e0..03297f5e58a0 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ProjectSettingsService.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ProjectSettingsService.java @@ -17,7 +17,6 @@ package com.intellij.openapi.roots.ui.configuration; import com.intellij.ide.projectView.impl.ModuleGroup; -import com.intellij.ide.projectView.impl.nodes.NamedLibraryElement; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.options.Configurable; @@ -29,7 +28,6 @@ import com.intellij.openapi.roots.OrderEntry; import com.intellij.openapi.roots.impl.libraries.LibraryEx; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryType; -import com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -72,22 +70,20 @@ public class ProjectSettingsService { return false; } - public void openProjectLibrarySettings(final NamedLibraryElement value) { - Configurable additionalSettingsConfigurable = getLibrarySettingsConfigurable(value); + public void openLibraryOrSdkSettings(final @NotNull OrderEntry orderEntry) { + Configurable additionalSettingsConfigurable = getLibrarySettingsConfigurable(orderEntry); if (additionalSettingsConfigurable != null) { - LibraryOrderEntry entry = (LibraryOrderEntry) value.getOrderEntry(); - ShowSettingsUtil.getInstance() - .showSettingsDialog(entry.getOwnerModule().getProject(), additionalSettingsConfigurable.getDisplayName()); + ShowSettingsUtil.getInstance().showSettingsDialog(orderEntry.getOwnerModule().getProject(), + additionalSettingsConfigurable.getDisplayName()); } } - public boolean canOpenProjectLibrarySettings(final NamedLibraryElement value) { - return getLibrarySettingsConfigurable(value) != null; + public boolean canOpenLibraryOrSdkSettings(final OrderEntry orderEntry) { + return getLibrarySettingsConfigurable(orderEntry) != null; } @Nullable - private static Configurable getLibrarySettingsConfigurable(NamedLibraryElement value) { - OrderEntry orderEntry = value.getOrderEntry(); + private static Configurable getLibrarySettingsConfigurable(OrderEntry orderEntry) { if (!(orderEntry instanceof LibraryOrderEntry)) return null; LibraryOrderEntry libOrderEntry = (LibraryOrderEntry)orderEntry; Library lib = libOrderEntry.getLibrary(); From 229afcb3057eec06eda4a34351fac38690862735 Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 11 Aug 2011 13:51:05 +0400 Subject: [PATCH 03/13] renamed and simplified --- ...va => ProjectStructureSelectInTarget.java} | 68 +++++-------------- .../ui/configuration/ModulesConfigurator.java | 19 ------ resources/src/idea/RichPlatformPlugin.xml | 2 +- 3 files changed, 19 insertions(+), 70 deletions(-) rename java/idea-ui/src/com/intellij/ide/impl/{ProjectSettingsSelectInTarget.java => ProjectStructureSelectInTarget.java} (66%) diff --git a/java/idea-ui/src/com/intellij/ide/impl/ProjectSettingsSelectInTarget.java b/java/idea-ui/src/com/intellij/ide/impl/ProjectStructureSelectInTarget.java similarity index 66% rename from java/idea-ui/src/com/intellij/ide/impl/ProjectSettingsSelectInTarget.java rename to java/idea-ui/src/com/intellij/ide/impl/ProjectStructureSelectInTarget.java index a707b0fea081..f4dba9026f52 100644 --- a/java/idea-ui/src/com/intellij/ide/impl/ProjectSettingsSelectInTarget.java +++ b/java/idea-ui/src/com/intellij/ide/impl/ProjectStructureSelectInTarget.java @@ -25,9 +25,12 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; -import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.roots.*; +import com.intellij.openapi.roots.OrderEntry; +import com.intellij.openapi.roots.ProjectFileIndex; +import com.intellij.openapi.roots.ProjectRootManager; +import com.intellij.openapi.roots.libraries.LibraryUtil; import com.intellij.openapi.roots.ui.configuration.ModulesConfigurator; +import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.WrappingVirtualFile; import org.jetbrains.annotations.NotNull; @@ -35,12 +38,11 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Iterator; -import java.util.List; /** * @author nik */ -public class ProjectSettingsSelectInTarget implements SelectInTarget, DumbAware { +public class ProjectStructureSelectInTarget implements SelectInTarget, DumbAware { public boolean canSelect(final SelectInContext context) { final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(context.getProject()).getFileIndex(); final VirtualFile file = context.getVirtualFile(); @@ -54,7 +56,6 @@ public class ProjectSettingsSelectInTarget implements SelectInTarget, DumbAware public void selectIn(final SelectInContext context, final boolean requestFocus) { final Project project = context.getProject(); final VirtualFile file = context.getVirtualFile(); - final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); final Module module; final Facet facet; @@ -64,8 +65,9 @@ public class ProjectSettingsSelectInTarget implements SelectInTarget, DumbAware module = facet == null? null : facet.getModule(); } else { + final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); module = fileIndex.getModuleForFile(file); - facet = findFacet(project, file, fileIndex); + facet = fileIndex.isInSourceContent(file) ? null : findFacet(project, file); } if (module != null || facet != null) { ApplicationManager.getApplication().invokeLater(new Runnable() { @@ -74,64 +76,30 @@ public class ProjectSettingsSelectInTarget implements SelectInTarget, DumbAware ModulesConfigurator.showFacetSettingsDialog(facet, null); } else { - ModulesConfigurator.showDialog(project, module.getName(), null, false); + ProjectSettingsService.getInstance(project).openModuleSettings(module); } } }); return; } - final LibraryOrderEntry libraryOrderEntry = findLibrary(file, fileIndex); - if (libraryOrderEntry != null) { + final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(file, project); + if (orderEntry != null) { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { - ModulesConfigurator.showLibrarySettings(project, libraryOrderEntry); - } - }); - return; - } - - final Sdk jdk = findJdk(file, fileIndex); - if (jdk != null) { - ApplicationManager.getApplication().invokeLater(new Runnable() { - public void run() { - ModulesConfigurator.showSdkSettings(project, jdk); + ProjectSettingsService.getInstance(project).openLibraryOrSdkSettings(orderEntry); } }); } } @Nullable - private static LibraryOrderEntry findLibrary(final VirtualFile file, final ProjectFileIndex fileIndex) { - List entries = fileIndex.getOrderEntriesForFile(file); - for (OrderEntry entry : entries) { - if (entry instanceof LibraryOrderEntry) { - return (LibraryOrderEntry)entry; - } - } - return null; - } - - @Nullable - private static Sdk findJdk(final VirtualFile file, final ProjectFileIndex fileIndex) { - List entries = fileIndex.getOrderEntriesForFile(file); - for (OrderEntry entry : entries) { - if (entry instanceof JdkOrderEntry) { - return ((JdkOrderEntry)entry).getJdk(); - } - } - return null; - } - - @Nullable - private static Facet findFacet(final @NotNull Project project, final @NotNull VirtualFile file, final @NotNull ProjectFileIndex fileIndex) { - if (!fileIndex.isInSourceContent(file)) { - for (FacetTypeId id : FacetTypeRegistry.getInstance().getFacetTypeIds()) { - if (hasFacetWithRoots(project, id)) { - Facet facet = FacetFinder.getInstance(project).findFacet(file, id); - if (facet != null) { - return facet; - } + private static Facet findFacet(final @NotNull Project project, final @NotNull VirtualFile file) { + for (FacetTypeId id : FacetTypeRegistry.getInstance().getFacetTypeIds()) { + if (hasFacetWithRoots(project, id)) { + Facet facet = FacetFinder.getInstance(project).findFacet(file, id); + if (facet != null) { + return facet; } } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModulesConfigurator.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModulesConfigurator.java index 1a52495c5c2a..c5a5be9693f3 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModulesConfigurator.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModulesConfigurator.java @@ -35,7 +35,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.ContentEntry; -import com.intellij.openapi.roots.LibraryOrderEntry; import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.roots.ModuleRootModel; import com.intellij.openapi.roots.impl.ProjectRootManagerImpl; @@ -519,24 +518,6 @@ public class ModulesConfigurator implements ModulesProvider, ModuleEditor.Change return myModified || myFacetsConfigurator.isModified(); } - public static boolean showSdkSettings(@NotNull Project project, final Sdk sdk) { - final ProjectStructureConfigurable configurable = ProjectStructureConfigurable.getInstance(project); - return ShowSettingsUtil.getInstance().editConfigurable(project, configurable, new Runnable() { - public void run() { - configurable.select(sdk, true); - } - }); - } - - public static boolean showLibrarySettings(@NotNull Project project, @NotNull final LibraryOrderEntry library) { - final ProjectStructureConfigurable configurable = ProjectStructureConfigurable.getInstance(project); - return ShowSettingsUtil.getInstance().editConfigurable(project, configurable, new Runnable() { - public void run() { - configurable.select(library, true); - } - }); - } - public static boolean showArtifactSettings(@NotNull Project project, @Nullable final Artifact artifact) { final ProjectStructureConfigurable configurable = ProjectStructureConfigurable.getInstance(project); return ShowSettingsUtil.getInstance().editConfigurable(project, configurable, new Runnable() { diff --git a/resources/src/idea/RichPlatformPlugin.xml b/resources/src/idea/RichPlatformPlugin.xml index 38d166ac198c..fbf98ba62fe0 100644 --- a/resources/src/idea/RichPlatformPlugin.xml +++ b/resources/src/idea/RichPlatformPlugin.xml @@ -288,7 +288,7 @@ - + From 44756eb7c1360b7320823c4a88cff9a54cca22f3 Mon Sep 17 00:00:00 2001 From: "Kirill.Safonov" Date: Thu, 11 Aug 2011 14:00:49 +0400 Subject: [PATCH 04/13] IDE errors dialog: don't update controls twice on creation --- .../src/com/intellij/diagnostic/IdeErrorsDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java b/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java index 385b1ed3a826..52932985d18e 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java @@ -121,6 +121,7 @@ public class IdeErrorsDialog extends DialogWrapper implements MessagePoolListene SwingUtilities.invokeLater(new Runnable() { public void run() { rebuildHeaders(); + updateControls(); } }); } @@ -574,7 +575,6 @@ public class IdeErrorsDialog extends DialogWrapper implements MessagePoolListene for (final ArrayList abstractMessages : hash2Messages.values()) { myMergedMessages.add(abstractMessages); } - updateControls(); } private void markAllAsRead() { From 2d9e3b338a7a8fc2e66993f328b1f907493835e4 Mon Sep 17 00:00:00 2001 From: "Kirill.Safonov" Date: Thu, 11 Aug 2011 14:10:36 +0400 Subject: [PATCH 05/13] IDE errors dialog: NPE when no submitter and no plugin are found for pluginId (IDEA-73143) --- .../src/com/intellij/diagnostic/IdeErrorsDialog.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java b/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java index 52932985d18e..c5c81c91935c 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java @@ -460,8 +460,14 @@ public class IdeErrorsDialog extends DialogWrapper implements MessagePoolListene final Throwable throwable = message.getThrowable(); ErrorReportSubmitter submitter = getSubmitter(throwable); if (submitter == null) { + PluginId pluginId = findPluginId(throwable); + IdeaPluginDescriptor plugin = PluginManager.getPlugin(pluginId); + if (plugin == null) { + LOG.warn("Neither submitter nor plugin found for plugin id " + plugin); + myForeignPluginWarningLabel.setVisible(false); + return; + } myForeignPluginWarningLabel.setVisible(true); - final IdeaPluginDescriptor plugin = PluginManager.getPlugin(findPluginId(throwable)); String vendor = plugin.getVendor(); String contactInfo = plugin.getVendorUrl(); if (StringUtil.isEmpty(contactInfo)) { From 717801a289f100993e3cd7efcb1f2df67b1d600a Mon Sep 17 00:00:00 2001 From: "Kirill.Safonov" Date: Thu, 11 Aug 2011 14:22:01 +0400 Subject: [PATCH 06/13] remove warning --- .../src/com/intellij/diagnostic/IdeErrorsDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java b/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java index c5c81c91935c..eebde2feafe2 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java @@ -463,7 +463,7 @@ public class IdeErrorsDialog extends DialogWrapper implements MessagePoolListene PluginId pluginId = findPluginId(throwable); IdeaPluginDescriptor plugin = PluginManager.getPlugin(pluginId); if (plugin == null) { - LOG.warn("Neither submitter nor plugin found for plugin id " + plugin); + // unknown plugin myForeignPluginWarningLabel.setVisible(false); return; } From 6427cb1a84c38fea66323380a4cdb1dfed644d85 Mon Sep 17 00:00:00 2001 From: "Kirill.Safonov" Date: Thu, 11 Aug 2011 14:28:39 +0400 Subject: [PATCH 07/13] IDE errors dialog: NPE when action 'Analyze Stacktrace' is not registered in product --- .../src/com/intellij/diagnostic/IdeErrorsDialog.java | 6 +++++- .../com/intellij/diagnostic/errordialog/DetailsTabForm.java | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java b/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java index eebde2feafe2..b481e4423d6b 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java @@ -82,6 +82,7 @@ public class IdeErrorsDialog extends DialogWrapper implements MessagePoolListene private ClearFatalsAction myClearAction = new ClearFatalsAction(); private BlameAction myBlameAction = new BlameAction(); + @Nullable private AnalyzeAction myAnalyzeAction; private boolean myMute; @@ -219,7 +220,10 @@ public class IdeErrorsDialog extends DialogWrapper implements MessagePoolListene myDetailsTabForm.setCommentsAreaVisible(false); } else { - myAnalyzeAction = new AnalyzeAction(ActionManager.getInstance().getAction("AnalyzeStacktraceOnError")); + final AnAction analyzePlatformAction = ActionManager.getInstance().getAction("AnalyzeStacktraceOnError"); + if (analyzePlatformAction != null) { + myAnalyzeAction = new AnalyzeAction(analyzePlatformAction); + } myDetailsTabForm = new DetailsTabForm(myAnalyzeAction); myDetailsTabForm.setCommentsAreaVisible(true); myDetailsTabForm.addCommentsListener(commentsListener); diff --git a/platform/platform-impl/src/com/intellij/diagnostic/errordialog/DetailsTabForm.java b/platform/platform-impl/src/com/intellij/diagnostic/errordialog/DetailsTabForm.java index de794b6dcb7e..fcaedf7c4c08 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/errordialog/DetailsTabForm.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/errordialog/DetailsTabForm.java @@ -3,6 +3,7 @@ package com.intellij.diagnostic.errordialog; import com.intellij.diagnostic.DiagnosticBundle; import com.intellij.ui.IdeBorderFactory; import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -16,7 +17,7 @@ public class DetailsTabForm { private JPanel myDetailsHolder; private JButton myAnalyzeStacktraceButton; - public DetailsTabForm(Action analyzeAction) { + public DetailsTabForm(@Nullable Action analyzeAction) { myCommentsArea.setTitle(DiagnosticBundle.message("error.dialog.comment.prompt")); myDetailsPane.setBackground(UIUtil.getTextFieldBackground()); myDetailsHolder.setBorder(IdeBorderFactory.createBorder()); From 449c0a7944383a7a9f7a4922a2b0209649efb86e Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Thu, 11 Aug 2011 14:31:17 +0400 Subject: [PATCH 08/13] IDEA-53476 Gradle integration (Maven's level - dependencies, modules, repositories) 1. Provided model for project description derived from the gradle api; 2. Implemented populating of the model mentioned above; --- plugins/gradle/src/META-INF/plugin.xml | 4 +- .../importing/model/GradleContentRoot.java | 24 ++ .../importing/model/GradleDependency.java | 20 ++ .../model/GradleDependencyVisitor.java | 12 + .../model/GradleLibraryDependency.java | 25 ++ .../gradle/importing/model/GradleModule.java | 27 ++ .../model/GradleModuleDependency.java | 13 + .../importing/model/GradleModuleImpl.java | 12 - .../gradle/importing/model/GradleProject.java | 6 + .../importing/model/LibraryPathType.java | 8 + .../gradle/importing/model/SourceType.java | 11 + .../model/impl/AbstractGradleDependency.java | 43 ++++ .../model/impl/GradleContentRootImpl.java | 63 +++++ .../impl/GradleLibraryDependencyImpl.java | 55 +++++ .../impl/GradleModuleDependencyImpl.java | 39 +++ .../model/impl/GradleModuleImpl.java | 92 +++++++ .../model/{ => impl}/GradleProjectImpl.java | 43 +++- .../wizard/GradleProjectImportBuilder.java | 9 +- .../remote/{api => }/GradleApiFacade.java | 2 +- .../gradle/remote/GradleApiFacadeManager.java | 5 +- .../{api => }/GradleProjectResolver.java | 2 +- .../RemoteGradleProcessSettings.java | 2 +- .../remote/{api => }/RemoteGradleService.java | 2 +- .../remote/impl/GradleApiFacadeImpl.java | 8 +- .../impl/GradleProjectResolverImpl.java | 233 +++++++++++++++++- 25 files changed, 719 insertions(+), 41 deletions(-) create mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleContentRoot.java create mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleDependency.java create mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleDependencyVisitor.java create mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleLibraryDependency.java create mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleModuleDependency.java delete mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleModuleImpl.java create mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/LibraryPathType.java create mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/SourceType.java create mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/AbstractGradleDependency.java create mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleContentRootImpl.java create mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleLibraryDependencyImpl.java create mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleModuleDependencyImpl.java create mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleModuleImpl.java rename plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/{ => impl}/GradleProjectImpl.java (57%) rename plugins/gradle/src/org/jetbrains/plugins/gradle/remote/{api => }/GradleApiFacade.java (96%) rename plugins/gradle/src/org/jetbrains/plugins/gradle/remote/{api => }/GradleProjectResolver.java (96%) rename plugins/gradle/src/org/jetbrains/plugins/gradle/remote/{api => }/RemoteGradleProcessSettings.java (94%) rename plugins/gradle/src/org/jetbrains/plugins/gradle/remote/{api => }/RemoteGradleService.java (89%) diff --git a/plugins/gradle/src/META-INF/plugin.xml b/plugins/gradle/src/META-INF/plugin.xml index 92ac91aee149..358251936b38 100644 --- a/plugins/gradle/src/META-INF/plugin.xml +++ b/plugins/gradle/src/META-INF/plugin.xml @@ -13,9 +13,11 @@ + - + diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleContentRoot.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleContentRoot.java new file mode 100644 index 000000000000..9a99ec423fe3 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleContentRoot.java @@ -0,0 +1,24 @@ +package org.jetbrains.plugins.gradle.importing.model; + +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; + +/** + * Implementations of this interface are expected to be thread-safe. + * + * @author Denis Zhdanov + * @since 8/9/11 6:39 PM + */ +public interface GradleContentRoot { + + @NotNull + String getRootPath(); + + /** + * @param type target dir type + * @return directories of the target type configured for the current content root + */ + @NotNull + Collection getPaths(@NotNull SourceType type); +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleDependency.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleDependency.java new file mode 100644 index 000000000000..86a142e3ad85 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleDependency.java @@ -0,0 +1,20 @@ +package org.jetbrains.plugins.gradle.importing.model; + +import com.intellij.openapi.roots.DependencyScope; +import org.jetbrains.annotations.NotNull; + +/** + * Implementations of this interface are not obliged to be thread-safe. + * + * @author Denis Zhdanov + * @since 8/10/11 6:31 PM + */ +public interface GradleDependency { + + boolean isExported(); + + @NotNull + DependencyScope getScope(); + + void invite(@NotNull GradleDependencyVisitor visitor); +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleDependencyVisitor.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleDependencyVisitor.java new file mode 100644 index 000000000000..662d80f62700 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleDependencyVisitor.java @@ -0,0 +1,12 @@ +package org.jetbrains.plugins.gradle.importing.model; + +import org.jetbrains.annotations.NotNull; + +/** + * @author Denis Zhdanov + * @since 8/10/11 6:31 PM + */ +public interface GradleDependencyVisitor { + void visit(@NotNull GradleModuleDependency dependency); + void visit(@NotNull GradleLibraryDependency dependency); +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleLibraryDependency.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleLibraryDependency.java new file mode 100644 index 000000000000..6152842be5a6 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleLibraryDependency.java @@ -0,0 +1,25 @@ +package org.jetbrains.plugins.gradle.importing.model; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Implementations of this interface are not obliged to be thread-safe. + * + * @author Denis Zhdanov + * @since 8/10/11 6:32 PM + */ +public interface GradleLibraryDependency extends GradleDependency { + + @NotNull + String getName(); + + /** + * Allows to ask for the target path configured for the current library dependency. + * + * @param type target path type + * @return path to the target path configured for the current library dependency + */ + @Nullable + String getPath(@NotNull LibraryPathType type); +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleModule.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleModule.java index a3a67bd2906d..ece63f073df0 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleModule.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleModule.java @@ -1,5 +1,10 @@ package org.jetbrains.plugins.gradle.importing.model; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; + /** * Defines IntelliJ module view to the application configured via gradle. *

@@ -9,4 +14,26 @@ package org.jetbrains.plugins.gradle.importing.model; * @since 8/8/11 12:10 PM */ public interface GradleModule { + + @NotNull + String getName(); + + @NotNull + Collection getContentRoots(); + + boolean isInheritProjectCompileOutputPath(); + + /** + * Allows to get file system path of the compile output of the source of the target type. + * + * @param type target source type + * @return file system path to use for compile output for the target source type; + * {@link GradleProject#getCompileOutputPath() project compile output path} should be used if current module + * doesn't provide specific compile output path + */ + @Nullable + String getCompileOutputPath(@NotNull SourceType type); + + @NotNull + Collection getDependencies(); } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleModuleDependency.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleModuleDependency.java new file mode 100644 index 000000000000..ca15ad5114ec --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleModuleDependency.java @@ -0,0 +1,13 @@ +package org.jetbrains.plugins.gradle.importing.model; + +import org.jetbrains.annotations.NotNull; + +/** + * @author Denis Zhdanov + * @since 8/10/11 6:32 PM + */ +public interface GradleModuleDependency extends GradleDependency { + + @NotNull + GradleModule getModule(); +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleModuleImpl.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleModuleImpl.java deleted file mode 100644 index 2535ad24a669..000000000000 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleModuleImpl.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.jetbrains.plugins.gradle.importing.model; - -import java.io.Serializable; - -/** - * @author Denis Zhdanov - * @since 8/8/11 12:11 PM - */ -public class GradleModuleImpl implements GradleModule, Serializable { - - // TODO den implement -} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleProject.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleProject.java index 3bef2cdb1a3a..17414c353ba6 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleProject.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleProject.java @@ -15,6 +15,12 @@ import java.util.Set; */ public interface GradleProject { + @NotNull + String getName(); + + @NotNull + String getCompileOutputPath(); + @NotNull String getJdkName(); diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/LibraryPathType.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/LibraryPathType.java new file mode 100644 index 000000000000..b90a3d910691 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/LibraryPathType.java @@ -0,0 +1,8 @@ +package org.jetbrains.plugins.gradle.importing.model; + +/** + * @author Denis Zhdanov + * @since 8/10/11 6:37 PM + */ +public enum LibraryPathType { + BINARY, SOURCE, JAVADOC} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/SourceType.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/SourceType.java new file mode 100644 index 000000000000..ceef1168a970 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/SourceType.java @@ -0,0 +1,11 @@ +package org.jetbrains.plugins.gradle.importing.model; + +/** + * Enumerates module source types. + * + * @author Denis Zhdanov + * @since 8/10/11 5:21 PM + */ +public enum SourceType { + SOURCE, TEST, EXCLUDED +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/AbstractGradleDependency.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/AbstractGradleDependency.java new file mode 100644 index 000000000000..58f6a0d3e56e --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/AbstractGradleDependency.java @@ -0,0 +1,43 @@ +package org.jetbrains.plugins.gradle.importing.model.impl; + +import com.intellij.openapi.roots.DependencyScope; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.importing.model.GradleDependency; + +import java.io.Serializable; + +/** + * @author Denis Zhdanov + * @since 8/10/11 6:41 PM + */ +public abstract class AbstractGradleDependency implements GradleDependency, Serializable { + + private static final long serialVersionUID = 1L; + + private DependencyScope myScope = DependencyScope.COMPILE; + private boolean myExported; + + @NotNull + @Override + public DependencyScope getScope() { + return myScope; + } + + public void setScope(DependencyScope scope) { + myScope = scope; + } + + @Override + public boolean isExported() { + return myExported; + } + + public void setExported(boolean exported) { + myExported = exported; + } + + @Override + public String toString() { + return "scope: " + getScope() + ", exported: " + isExported(); + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleContentRootImpl.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleContentRootImpl.java new file mode 100644 index 000000000000..4d8c5ea7111c --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleContentRootImpl.java @@ -0,0 +1,63 @@ +package org.jetbrains.plugins.gradle.importing.model.impl; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.importing.model.GradleContentRoot; +import org.jetbrains.plugins.gradle.importing.model.SourceType; + +import java.io.File; +import java.io.Serializable; +import java.util.*; + +/** + * @author Denis Zhdanov + * @since 8/9/11 6:25 PM + */ +public class GradleContentRootImpl implements Serializable, GradleContentRoot { + + private static final long serialVersionUID = 1L; + + private final Map> myData = new EnumMap>(SourceType.class); + private final Map> myViews = new EnumMap>(SourceType.class); + + private final String myRootPath; + + /** + * Creates new GradleContentRootImpl object. + * + * @param rootPath path to the root directory + */ + public GradleContentRootImpl(@NotNull String rootPath) { + myRootPath = new File(rootPath).getAbsolutePath(); + for (SourceType type : SourceType.values()) { + Set data = new HashSet(); + myData.put(type, data); + myViews.put(type, Collections.unmodifiableCollection(data)); + } + } + + @NotNull + @Override + public Collection getPaths(@NotNull SourceType type) { + return myViews.get(type); + } + + public void storePath(@NotNull SourceType type, @NotNull String path) { + myData.get(type).add(new File(path).getAbsolutePath()); + } + + @NotNull + @Override + public String getRootPath() { + return myRootPath; + } + + @Override + public String toString() { + StringBuilder buffer = new StringBuilder(); + for (Map.Entry> entry : myData.entrySet()) { + buffer.append(entry.getKey().toString().toLowerCase()).append(": ").append(entry.getValue()).append("; "); + } + buffer.setLength(buffer.length() - 2); + return buffer.toString(); + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleLibraryDependencyImpl.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleLibraryDependencyImpl.java new file mode 100644 index 000000000000..210acbb0dfb3 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleLibraryDependencyImpl.java @@ -0,0 +1,55 @@ +package org.jetbrains.plugins.gradle.importing.model.impl; + +import com.intellij.util.containers.HashMap; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.gradle.importing.model.GradleDependencyVisitor; +import org.jetbrains.plugins.gradle.importing.model.GradleLibraryDependency; +import org.jetbrains.plugins.gradle.importing.model.LibraryPathType; + +import java.io.File; +import java.io.Serializable; +import java.util.Map; + +/** + * @author Denis Zhdanov + * @since 8/10/11 6:46 PM + */ +public class GradleLibraryDependencyImpl extends AbstractGradleDependency implements GradleLibraryDependency, Serializable { + + private static final long serialVersionUID = 1L; + + private final Map myPaths = new HashMap(); + + private final String myName; + + public GradleLibraryDependencyImpl(@NotNull String name) { + myName = name; + } + + @NotNull + @Override + public String getName() { + return myName; + } + + @Nullable + @Override + public String getPath(@NotNull LibraryPathType type) { + return myPaths.get(type); + } + + public void addPath(@NotNull LibraryPathType type, @NotNull String path) { + myPaths.put(type, new File(path).getAbsolutePath()); + } + + @Override + public void invite(@NotNull GradleDependencyVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return super.toString() + ", library: " + getName(); + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleModuleDependencyImpl.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleModuleDependencyImpl.java new file mode 100644 index 000000000000..f802d0e18551 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleModuleDependencyImpl.java @@ -0,0 +1,39 @@ +package org.jetbrains.plugins.gradle.importing.model.impl; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.importing.model.GradleDependencyVisitor; +import org.jetbrains.plugins.gradle.importing.model.GradleModule; +import org.jetbrains.plugins.gradle.importing.model.GradleModuleDependency; + +import java.io.Serializable; + +/** + * @author Denis Zhdanov + * @since 8/10/11 6:40 PM + */ +public class GradleModuleDependencyImpl extends AbstractGradleDependency implements GradleModuleDependency, Serializable { + + private static final long serialVersionUID = 1L; + + private final GradleModule myModule; + + public GradleModuleDependencyImpl(@NotNull GradleModule module) { + myModule = module; + } + + @NotNull + @Override + public GradleModule getModule() { + return myModule; + } + + @Override + public void invite(@NotNull GradleDependencyVisitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return super.toString() + ", dependency module: " + getModule(); + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleModuleImpl.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleModuleImpl.java new file mode 100644 index 000000000000..232699dad213 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleModuleImpl.java @@ -0,0 +1,92 @@ +package org.jetbrains.plugins.gradle.importing.model.impl; + +import com.intellij.util.containers.HashMap; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.gradle.importing.model.GradleContentRoot; +import org.jetbrains.plugins.gradle.importing.model.GradleDependency; +import org.jetbrains.plugins.gradle.importing.model.GradleModule; +import org.jetbrains.plugins.gradle.importing.model.SourceType; + +import java.io.File; +import java.io.Serializable; +import java.util.*; + +/** + * @author Denis Zhdanov + * @since 8/8/11 12:11 PM + */ +public class GradleModuleImpl implements GradleModule, Serializable { + + private static final long serialVersionUID = 1L; + + private final List myContentRoots = new ArrayList(); + private final Map myCompileOutputPaths = new HashMap(); + private final Set myDependencies = new HashSet(); + private final Collection myDependenciesView = Collections.unmodifiableCollection(myDependencies); + + private boolean myInheritProjectCompileOutputPath = true; + + private final String myName; + + public GradleModuleImpl(@NotNull String name) { + myName = name; + } + + @NotNull + @Override + public String getName() { + return myName; + } + + @NotNull + @Override + public Collection getContentRoots() { + return myContentRoots; + } + + public void addContentRoot(@NotNull GradleContentRoot contentRoot) { + myContentRoots.add(contentRoot); + } + + @Override + public boolean isInheritProjectCompileOutputPath() { + return myInheritProjectCompileOutputPath; + } + + public void setInheritProjectCompileOutputPath(boolean inheritProjectCompileOutputPath) { + myInheritProjectCompileOutputPath = inheritProjectCompileOutputPath; + } + + @Nullable + @Override + public String getCompileOutputPath(@NotNull SourceType type) { + return myCompileOutputPaths.get(type); + } + + public void setCompileOutputPath(@NotNull SourceType type, @Nullable String path) { + if (path == null) { + myCompileOutputPaths.remove(type); + return; + } + myCompileOutputPaths.put(type, new File(path).getAbsolutePath()); + } + + @NotNull + @Override + public Collection getDependencies() { + return myDependenciesView; + } + + public void addDependency(@NotNull GradleDependency dependency) { + myDependencies.add(dependency); + } + + @Override + public String toString() { + return String.format( + "module '%s'. Content roots: %s; inherit compile output path: %b", + getName(), getContentRoots(), isInheritProjectCompileOutputPath() + ); + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleProjectImpl.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleProjectImpl.java similarity index 57% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleProjectImpl.java rename to plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleProjectImpl.java index cac370ab1144..2538fc48bb0e 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/GradleProjectImpl.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/model/impl/GradleProjectImpl.java @@ -1,9 +1,12 @@ -package org.jetbrains.plugins.gradle.importing.model; +package org.jetbrains.plugins.gradle.importing.model.impl; import com.intellij.pom.java.LanguageLevel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.gradle.importing.model.GradleModule; +import org.jetbrains.plugins.gradle.importing.model.GradleProject; +import java.io.File; import java.io.Serializable; import java.util.HashSet; import java.util.Set; @@ -17,22 +20,48 @@ import java.util.Set; public class GradleProjectImpl implements Serializable, GradleProject { private static final long serialVersionUID = 1L; + private static final LanguageLevel DEFAULT_LANGUAGE_LEVEL = LanguageLevel.JDK_1_6; private static final String DEFAULT_JDK = "1.6"; private final Set myModules = new HashSet(); + private final String myCompileOutputPath; + + private String myName = "unnamed"; private String myJdk = DEFAULT_JDK; private LanguageLevel myLanguageLevel = DEFAULT_LANGUAGE_LEVEL; - + + public GradleProjectImpl(@NotNull String compileOutputPath) { + myCompileOutputPath = new File(compileOutputPath).getAbsolutePath(); + } + + @NotNull + @Override + public String getName() { + return myName; + } + + public void setName(@NotNull String name) { + myName = name; + } + + @NotNull + @Override + public String getCompileOutputPath() { + return myCompileOutputPath; + } + @NotNull @Override public String getJdkName() { return myJdk; } - public void setJdk(@NotNull String jdk) { - myJdk = jdk; + public void setJdk(@Nullable String jdk) { + if (jdk != null) { + myJdk = jdk; + } } @NotNull @@ -57,4 +86,10 @@ public class GradleProjectImpl implements Serializable, GradleProject { public Set getModules() { return myModules; } + + @Override + public String toString() { + return String.format("project '%s'. Jdk: '%s', language level: '%s', modules: %s", + getName(), getJdkName(), getLanguageLevel(), getModules()); + } } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/wizard/GradleProjectImportBuilder.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/wizard/GradleProjectImportBuilder.java index 67c31cbb67e0..bc10da87ac3e 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/wizard/GradleProjectImportBuilder.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/wizard/GradleProjectImportBuilder.java @@ -10,6 +10,7 @@ import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.roots.ui.configuration.ModulesProvider; import com.intellij.packaging.artifacts.ModifiableArtifactModel; import com.intellij.projectImport.ProjectImportBuilder; @@ -17,7 +18,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.gradle.importing.model.GradleProject; import org.jetbrains.plugins.gradle.remote.GradleApiFacadeManager; -import org.jetbrains.plugins.gradle.remote.api.GradleProjectResolver; +import org.jetbrains.plugins.gradle.remote.GradleProjectResolver; import org.jetbrains.plugins.gradle.util.GradleBundle; import org.jetbrains.plugins.gradle.util.GradleIcons; import org.jetbrains.plugins.gradle.util.GradleLog; @@ -134,10 +135,12 @@ public class GradleProjectImportBuilder extends ProjectImportBuilder gradleModules = gradleProject.getModules(); + if (gradleModules == null || gradleModules.isEmpty()) { + throw new IllegalStateException("No modules found for the target project: " + gradleProject); + } + Map modules = new HashMap(); + for (IdeaModule gradleModule : gradleModules) { + if (gradleModule == null) { + continue; + } + GradleModuleImpl module = populateModule(gradleModule, intellijProject); + String moduleName = module.getName(); + GradleModule previouslyParsedModule = modules.get(moduleName); + if (modules.containsKey(moduleName)) { + throw new IllegalStateException( + String.format("Modules with duplicate name (%s) detected: '%s' and '%s'", moduleName, module, previouslyParsedModule) + ); + } + modules.put(moduleName, module); + intellijProject.addModule(module); + } + } + + @NotNull + private static GradleModuleImpl populateModule(@NotNull IdeaModule gradleModule, @NotNull GradleProject intellijProject) + throws IllegalStateException + { + String name = gradleModule.getName(); + if (name == null) { + throw new IllegalStateException("Module with undefined name detected: " + gradleModule); + } + GradleModuleImpl result = new GradleModuleImpl(name); + populateContentRoots(gradleModule, result); + populateCompileOutputSettings(gradleModule.getCompilerOutput(), result); + populateDependencies(gradleModule, result, intellijProject); + return result; + } + + private static void populateContentRoots(@NotNull IdeaModule gradleModule, @NotNull GradleModuleImpl intellijModule) { + DomainObjectSet contentRoots = gradleModule.getContentRoots(); + if (contentRoots == null) { + return; + } + for (IdeaContentRoot gradleContentRoot : contentRoots) { + if (gradleContentRoot == null) { + continue; + } + File rootDirectory = gradleContentRoot.getRootDirectory(); + if (rootDirectory == null) { + continue; + } + GradleContentRootImpl intellijContentRoot = new GradleContentRootImpl(rootDirectory.getAbsolutePath()); + populateContentRoot(intellijContentRoot, SourceType.SOURCE, gradleContentRoot.getSourceDirectories()); + populateContentRoot(intellijContentRoot, SourceType.TEST, gradleContentRoot.getTestDirectories()); + Set excluded = gradleContentRoot.getExcludeDirectories(); + if (excluded != null) { + for (File file : excluded) { + intellijContentRoot.storePath(SourceType.EXCLUDED, file.getAbsolutePath()); + } + } + intellijModule.addContentRoot(intellijContentRoot); + } + } + + private static void populateContentRoot(@NotNull GradleContentRootImpl contentRoot, SourceType type, + @Nullable Iterable dirs) { + if (dirs == null) { + return; + } + for (IdeaSourceDirectory dir : dirs) { + contentRoot.storePath(type, dir.getDirectory().getAbsolutePath()); + } + } + + private static void populateCompileOutputSettings(@Nullable IdeaCompilerOutput gradleSettings, + @NotNull GradleModuleImpl intellijModule) { + if (gradleSettings == null) { + return; + } + intellijModule.setInheritProjectCompileOutputPath(gradleSettings.getInheritOutputDirs()); + + File sourceCompileOutputPath = gradleSettings.getOutputDir(); + if (sourceCompileOutputPath != null) { + intellijModule.setCompileOutputPath(SourceType.SOURCE, sourceCompileOutputPath.getAbsolutePath()); + } + + File testCompileOutputPath = gradleSettings.getTestOutputDir(); + if (testCompileOutputPath != null) { + intellijModule.setCompileOutputPath(SourceType.TEST, testCompileOutputPath.getAbsolutePath()); + } + } + + private static void populateDependencies(@NotNull IdeaModule gradleModule, @NotNull GradleModuleImpl intellijModule, + @NotNull GradleProject intellijProject) + { + DomainObjectSet dependencies = gradleModule.getDependencies(); + if (dependencies == null) { + return; + } + for (IdeaDependency dependency : dependencies) { + if (dependency == null) { + continue; + } + AbstractGradleDependency intellijDependency = null; + if (dependency instanceof IdeaModuleDependency) { + intellijDependency = buildDependency((IdeaModuleDependency)dependency, intellijProject); + } + else if (dependency instanceof IdeaSingleEntryLibraryDependency) { + intellijDependency = buildDependency((IdeaSingleEntryLibraryDependency)dependency); + } + + if (intellijDependency == null) { + continue; + } + + intellijDependency.setExported(dependency.getExported()); + DependencyScope scope = parseScope(dependency.getScope()); + if (scope != null) { + intellijDependency.setScope(scope); + } + intellijModule.addDependency(intellijDependency); + } + } + + private static AbstractGradleDependency buildDependency(@NotNull IdeaModuleDependency dependency, @NotNull GradleProject intellijProject) + throws IllegalStateException + { + IdeaModule module = dependency.getDependencyModule(); + if (module == null) { + throw new IllegalStateException( + String.format("Can't parse gradle module dependency '%s'. Reason: referenced module is null", dependency) + ); + } + + String moduleName = module.getName(); + if (moduleName == null) { + throw new IllegalStateException(String.format( + "Can't parse gradle module dependency '%s'. Reason: referenced module name is undefined (module: '%s') ", dependency, module + )); + } + + Set registeredModuleNames = new HashSet(); + for (GradleModule gradleModule : intellijProject.getModules()) { + registeredModuleNames.add(gradleModule.getName()); + if (gradleModule.getName().equals(moduleName)) { + return new GradleModuleDependencyImpl(gradleModule); + } + } + throw new IllegalStateException(String.format( + "Can't parse gradle module dependency '%s'. Reason: no module with such name (%s) is found. Registered modules: %s", + dependency, moduleName, registeredModuleNames + )); + } + + private static AbstractGradleDependency buildDependency(@NotNull IdeaSingleEntryLibraryDependency dependency) + throws IllegalStateException + { + File binaryPath = dependency.getFile(); + if (binaryPath == null) { + throw new IllegalStateException(String.format( + "Can't parse external library dependency '%s'. Reason: it doesn't specify path to the binaries", dependency + )); + } + + // TODO den use library name from gradle api when it's ready + GradleLibraryDependencyImpl result = new GradleLibraryDependencyImpl(binaryPath.getName()); + result.addPath(LibraryPathType.BINARY, binaryPath.getAbsolutePath()); + + File sourcePath = dependency.getSource(); + if (sourcePath != null) { + result.addPath(LibraryPathType.SOURCE, sourcePath.getAbsolutePath()); + } + + File javadocPath = dependency.getJavadoc(); + if (javadocPath != null) { + result.addPath(LibraryPathType.JAVADOC, javadocPath.getAbsolutePath()); + } + return result; + } + + @Nullable + private static DependencyScope parseScope(@Nullable IdeaDependencyScope scope) { + if (scope == null) { + return null; + } + String scopeAsString = scope.getScope(); + if (scopeAsString == null) { + return null; + } + for (DependencyScope dependencyScope : DependencyScope.values()) { + if (scopeAsString.equalsIgnoreCase(dependencyScope.toString())) { + return dependencyScope; + } + } + return null; + } + /** * Allows to retrieve gradle api connection to use for the given project. * From 3726b111794ebc295169788558e1eafe5b6bdf2c Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Thu, 11 Aug 2011 14:36:04 +0400 Subject: [PATCH 09/13] IDEA-73117 Gradle plugin pretends to be non-JetBrains Defined standard jb error handler for the gradle plugin --- plugins/gradle/src/META-INF/plugin.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/gradle/src/META-INF/plugin.xml b/plugins/gradle/src/META-INF/plugin.xml index 358251936b38..4653b04f499b 100644 --- a/plugins/gradle/src/META-INF/plugin.xml +++ b/plugins/gradle/src/META-INF/plugin.xml @@ -9,6 +9,7 @@ org.intellij.groovy + From ab375feb65662392947d5af414b011aec6379635 Mon Sep 17 00:00:00 2001 From: Eugene Toporov Date: Thu, 11 Aug 2011 14:43:41 +0400 Subject: [PATCH 10/13] menu item relayout --- .../src/messages/ActionsBundle.properties | 20 ++++---- .../src/tips/CtrlShiftI.html | 4 +- .../src/tips/FileStructurePopup.html | 2 +- .../src/tips/ImagesLookup.html | 2 +- .../src/tips/QuickJavaDoc.html | 2 +- .../src/tips/QuickJavaDocInLookups.html | 2 +- .../src/idea/LangActions.xml | 46 +++++++++---------- .../src/idea/PlatformActions.xml | 7 +-- 8 files changed, 44 insertions(+), 41 deletions(-) diff --git a/platform/platform-resources-en/src/messages/ActionsBundle.properties b/platform/platform-resources-en/src/messages/ActionsBundle.properties index 4e0b7de76486..2eb67dc9c348 100644 --- a/platform/platform-resources-en/src/messages/ActionsBundle.properties +++ b/platform/platform-resources-en/src/messages/ActionsBundle.properties @@ -224,11 +224,11 @@ action.CloseProject.text=Close Pro_ject action.CloseProject.description=Close current project action.ShowSettings.text=Se_ttings action.ShowSettings.description=Configure application settings -action.ShowProjectStructureSettings.text=Pro_ject Structure +action.ShowProjectStructureSettings.text=Pro_ject Structure... action.ShowProjectStructureSettings.description=Configure project structure -action.TemplateProjectProperties.text=Templ_ate Settings +action.TemplateProjectProperties.text=Templ_ate Settings... action.TemplateProjectProperties.description=Configure template settings for all new projects -action.TemplateProjectStructure.text=Te_mplate Project Structure +action.TemplateProjectStructure.text=Te_mplate Project Structure... action.TemplateProjectStructure.description=Configure template structure for all new projects action.SaveAll.text=_Save All action.SaveAll.description=Save all files and settings @@ -324,15 +324,15 @@ action.ViewToolButtons.text=_Tool Buttons action.ViewToolButtons.description=Show/hide tool window buttons action.ViewNavigationBar.text=Na_vigation Bar action.ViewNavigationBar.description=Show/hide the navigation bar -action.FileStructurePopup.text=_File Structure Popup +action.FileStructurePopup.text=_File Structure action.FileStructurePopup.description=Popup structure of the current file for quick navigation action.ShowFilePath.text=File _Path action.ShowFilePath.description=Popup path of the current file for opening in external file manager action.SelectIn.text=Se_lect In... action.SelectIn.description=Select the current class or method in any view -action.QuickJavaDoc.text=Quick _Documentation Lookup +action.QuickJavaDoc.text=Quick _Documentation action.QuickJavaDoc.description=Show a popup window with documentation for the symbol at caret -action.QuickImplementations.text=Quick Definition Loo_kup +action.QuickImplementations.text=Quic_k Definition action.QuickImplementations.description=Show a popup window with the symbol (and its implementations) content action.ParameterInfo.text=_Parameter Info action.ParameterInfo.description=Show parameters of the method call at caret @@ -340,7 +340,7 @@ action.EditorContextInfo.text=_Context Info action.EditorContextInfo.description=Show the current method or class declaration when it is not visible action.ShowErrorDescription.text=E_rror Description action.ShowErrorDescription.description=Show description of error or warning at caret -action.ProjectViewChangeView.text=Change View +action.ProjectViewChangeView.text=Change View... action.ProjectViewChangeView.description=Choose Project, Sourcepath or Classpath tree in the Project View window action.EditSource.text=_Jump to Source action.EditSource.description=Open editor for the selected item and give focus to it @@ -407,6 +407,8 @@ action.GotoNextError.text=_Next Highlighted Error action.GotoNextError.description=Navigate to the next highlighted error in the active editor action.GotoPreviousError.text=_Previous Highlighted Error action.GotoPreviousError.description=Navigate to the previous highlighted error in the active editor +action.GotoRelated.text=_Related File... +action.GotoRelated.description=Navigate to one of the related or linked files action.MethodDown.text=N_ext Method action.MethodDown.description=Navigate to the next method in the active editor action.MethodUp.text=Prev_ious Method @@ -1189,9 +1191,9 @@ action.Diff.IgnoreWhitespace.text=Toggle Diff Ignore Whitespace action.ShelvedChanges.Restore.text=Restore Applied Shelved Change action.Graph.Current.Node.Dependencies.Filter.text=Show selected nodes with dependencies group.VcsToobarActions.text=VCS Actions -action.StartupWizard.text=Configure Plugins +action.StartupWizard.text=Configure Plugins... action.StartupWizard.description=Run a wizard for selecting the set of enabled plugins -action.PopupHector.text=Popup Per File Highlighting Settings +action.PopupHector.text=Per File Highlighting Settings... action.PopupHector.description=Show panel to configure highlighting mode for the current file group.EditorTabPopupMenu.text=Editor Tab Popup Menu group.MainMenu.text=Main menu diff --git a/platform/platform-resources-en/src/tips/CtrlShiftI.html b/platform/platform-resources-en/src/tips/CtrlShiftI.html index 6cf4e89c900b..29b0ba311aeb 100644 --- a/platform/platform-resources-en/src/tips/CtrlShiftI.html +++ b/platform/platform-resources-en/src/tips/CtrlShiftI.html @@ -6,7 +6,7 @@

Use &shortcut:QuickImplementations; - (View | Quick Definition Lookup), + (View | Quick Definition), to quickly review definition or content of the symbol at caret, without the need to open it in a new editor tab.

@@ -14,4 +14,4 @@ - \ No newline at end of file + diff --git a/platform/platform-resources-en/src/tips/FileStructurePopup.html b/platform/platform-resources-en/src/tips/FileStructurePopup.html index 739e6003a542..9d40131bad12 100644 --- a/platform/platform-resources-en/src/tips/FileStructurePopup.html +++ b/platform/platform-resources-en/src/tips/FileStructurePopup.html @@ -6,7 +6,7 @@

You can quickly navigate in the currently edited file with &shortcut:FileStructurePopup; - (View | File Structure Popup).

+ (View | File Structure).

It shows the list of members of the current class. Select an element you want to navigate to and press the Enter key or the &shortcut:EditSource; key.

To easily locate an item in the list, just start typing its name.

diff --git a/platform/platform-resources-en/src/tips/ImagesLookup.html b/platform/platform-resources-en/src/tips/ImagesLookup.html index a1437f522b8e..ee3e2c7b6479 100644 --- a/platform/platform-resources-en/src/tips/ImagesLookup.html +++ b/platform/platform-resources-en/src/tips/ImagesLookup.html @@ -6,7 +6,7 @@

You can quickly view the image referenced at caret by using the - Quick Definition Lookup + Quick Definition (&shortcut:QuickImplementations;). The underlying image will be opened in a popup instead of a separate editor tab.

diff --git a/platform/platform-resources-en/src/tips/QuickJavaDoc.html b/platform/platform-resources-en/src/tips/QuickJavaDoc.html index c7fd10a47280..5a54891f2bf0 100644 --- a/platform/platform-resources-en/src/tips/QuickJavaDoc.html +++ b/platform/platform-resources-en/src/tips/QuickJavaDoc.html @@ -5,7 +5,7 @@

To quickly see the documentation for the class or method used at the editor's caret, press &shortcut:QuickJavaDoc; - (View | Quick Documentation Lookup).

+ (View | Quick Documentation).

diff --git a/platform/platform-resources-en/src/tips/QuickJavaDocInLookups.html b/platform/platform-resources-en/src/tips/QuickJavaDocInLookups.html index 60ee82f9ca34..5ba036c05010 100644 --- a/platform/platform-resources-en/src/tips/QuickJavaDocInLookups.html +++ b/platform/platform-resources-en/src/tips/QuickJavaDocInLookups.html @@ -6,7 +6,7 @@

The shortcuts such as &shortcut:QuickJavaDoc; - (View | Quick Documentation Lookup), + (View | Quick Documentation), &shortcut:ParameterInfo; (View | Parameter Info), &shortcut:GotoDeclaration; (Go To | Declaration) and others can be used not only in the editor but in the code completion popup list as well.

diff --git a/platform/platform-resources/src/idea/LangActions.xml b/platform/platform-resources/src/idea/LangActions.xml index 87474960e2ce..e6bee2d60653 100644 --- a/platform/platform-resources/src/idea/LangActions.xml +++ b/platform/platform-resources/src/idea/LangActions.xml @@ -124,15 +124,12 @@ - - - + + + - - - - - + + @@ -144,18 +141,28 @@ - - - - - - + + + + + + + + + + + + + + + + @@ -170,13 +177,6 @@ - - - - - - - @@ -188,7 +188,7 @@ - + @@ -226,7 +226,7 @@ - + diff --git a/platform/platform-resources/src/idea/PlatformActions.xml b/platform/platform-resources/src/idea/PlatformActions.xml index 7fb3f56e48b9..56f663d82b44 100644 --- a/platform/platform-resources/src/idea/PlatformActions.xml +++ b/platform/platform-resources/src/idea/PlatformActions.xml @@ -209,13 +209,14 @@ - - - + + + + From 90dee33e2a83e12d75f16a31f7b05de5bc0a4b36 Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 11 Aug 2011 15:27:59 +0400 Subject: [PATCH 11/13] extracted interface from FileContent --- .../impl/FrameworkDetectionProcessor.java | 3 +- .../src/com/intellij/psi/stubs/StubTree.java | 3 +- .../intellij/psi/stubs/StubUpdatingIndex.java | 2 +- .../util/indexing/FileBasedIndex.java | 10 +- .../intellij/util/indexing/FileContent.java | 152 ++------------- .../util/indexing/FileContentImpl.java | 181 ++++++++++++++++++ .../util/indexing/SubstitutedFileType.java | 2 +- .../xml/XmlPropertiesIndexTest.java | 6 +- 8 files changed, 206 insertions(+), 153 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/util/indexing/FileContentImpl.java diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionProcessor.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionProcessor.java index 4c43979af990..715b25c6aa0b 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionProcessor.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionProcessor.java @@ -26,6 +26,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.patterns.ElementPattern; import com.intellij.util.containers.MultiMap; import com.intellij.util.indexing.FileContent; +import com.intellij.util.indexing.FileContentImpl; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -90,7 +91,7 @@ public class FrameworkDetectionProcessor { myProgressIndicator.setText2(file.getPresentableUrl()); try { - FileContent fileContent = new FileContent(file, file.contentsToByteArray(false)); + FileContent fileContent = new FileContentImpl(file, file.contentsToByteArray(false)); for (FrameworkDetectorData detector : myDetectorsByFileType.get(fileType)) { if (detector.myFilePattern.accepts(fileContent)) { detector.mySuitableFiles.add(file); diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubTree.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubTree.java index e4239fc0e3fc..14a04b93b02d 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubTree.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubTree.java @@ -30,6 +30,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.indexing.FileContent; +import com.intellij.util.indexing.FileContentImpl; import gnu.trove.TIntArrayList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -110,7 +111,7 @@ public class StubTree { } try { - final FileContent fc = new FileContent(vFile, vFile.contentsToByteArray()); + final FileContent fc = new FileContentImpl(vFile, vFile.contentsToByteArray()); fc.putUserData(FileBasedIndex.PROJECT, project); final StubElement element = StubUpdatingIndex.buildStubTree(fc); if (element instanceof PsiFileStub) { diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java index 66820d9ebe49..f5824b2ac867 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java @@ -149,7 +149,7 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType); assert builder != null; - data = builder.buildStubTree(inputData.getFile(), inputData.getContent(), inputData.getProject()); + data = builder.buildStubTree(inputData.getFile(), inputData.getContent(), ((FileContentImpl)inputData).getProject()); } else { final LanguageFileType filetype = (LanguageFileType)fileType; diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index ced6e0cc5290..904b310d9d26 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -1196,7 +1196,7 @@ public class FileBasedIndex implements ApplicationComponent { return; } - final FileContent newFc = new FileContent(vFile, contentText, vFile.getCharset()); + final FileContentImpl newFc = new FileContentImpl(vFile, contentText, vFile.getCharset()); if (dominantContentFile != null) { dominantContentFile.putUserData(PsiFileImpl.BUILDING_STUB, true); @@ -1341,7 +1341,7 @@ public class FileBasedIndex implements ApplicationComponent { public void indexFileContent(@Nullable Project project, com.intellij.ide.caches.FileContent content) { myChangedFilesCollector.ensureAllInvalidateTasksCompleted(); final VirtualFile file = content.getVirtualFile(); - FileContent fc = null; + FileContentImpl fc = null; PsiFile psiFile = null; @@ -1355,7 +1355,7 @@ public class FileBasedIndex implements ApplicationComponent { catch (IOException e) { currentBytes = ArrayUtil.EMPTY_BYTE_ARRAY; } - fc = new FileContent(file, currentBytes); + fc = new FileContentImpl(file, currentBytes); psiFile = content.getUserData(PSI_FILE); if (psiFile != null) { @@ -1524,7 +1524,7 @@ public class FileBasedIndex implements ApplicationComponent { if (getInputFilter(indexId).acceptInput(file)) { try { if (fileContent == null) { - fileContent = new FileContent(file); + fileContent = new FileContentImpl(file); } updateSingleIndex(indexId, file, fileContent); } @@ -1814,7 +1814,7 @@ public class FileBasedIndex implements ApplicationComponent { oldStuff = false; try { if (fileContent == null) { - fileContent = new FileContent(file); + fileContent = new FileContentImpl(file); } updateSingleIndex(indexId, file, fileContent); } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileContent.java b/platform/lang-impl/src/com/intellij/util/indexing/FileContent.java index 7748e785a698..71214a6b60e2 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileContent.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileContent.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,158 +16,28 @@ package com.intellij.util.indexing; -import com.intellij.lang.Language; -import com.intellij.openapi.fileEditor.impl.LoadTextUtil; import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.FileTypeManager; -import com.intellij.openapi.fileTypes.LanguageFileType; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectManager; -import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.UserDataHolderBase; +import com.intellij.openapi.util.UserDataHolder; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.LanguageSubstitutors; import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiFileFactory; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.TestOnly; - -import java.io.UnsupportedEncodingException; -import java.nio.charset.Charset; /** * @author Eugene Zhuravlev * Date: Mar 28, 2008 */ -public final class FileContent extends UserDataHolderBase { - private final VirtualFile myFile; - private final String fileName; - private final FileType myFileType; - private final Charset myCharset; - private byte[] myContent; - private CharSequence myContentAsText; +public interface FileContent extends UserDataHolder { + @NotNull + FileType getFileType(); - public Project getProject() { - return getUserData(FileBasedIndex.PROJECT); - } + VirtualFile getFile(); - private final Key CACHED_PSI = Key.create("cached psi from content"); + String getFileName(); - /** - * @return psiFile associated with the content. If the file was not set on FileContentCreation, it will be created on the spot - */ - public PsiFile getPsiFile() { - PsiFile psi = getUserData(FileBasedIndex.PSI_FILE); + byte[] getContent(); - if (psi == null) { - psi = getUserData(CACHED_PSI); - } + CharSequence getContentAsText(); - if (psi == null) { - Project project = getProject(); - if (project == null) { - project = ProjectManager.getInstance().getDefaultProject(); - } - final Language language = ((LanguageFileType)getFileTypeWithoutSubstitution()).getLanguage(); - final Language substitutedLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, getFile(), project); - psi = PsiFileFactory.getInstance(project).createFileFromText(getFileName(), substitutedLanguage, getContentAsText(), false, false, true); - - psi.putUserData(FileBasedIndex.VIRTUAL_FILE, getFile()); - putUserData(CACHED_PSI, psi); - } - return psi; - } - - public static class IllegalDataException extends RuntimeException { - public IllegalDataException(final String message) { - super(message); - } - } - - public FileContent(@NotNull final VirtualFile file, @NotNull final CharSequence contentAsText, final Charset charset) { - this(file, contentAsText, null, charset); - } - - public FileContent(@NotNull final VirtualFile file, @NotNull final byte[] content) { - this(file, null, content, LoadTextUtil.detectCharsetAndSetBOM(file, content)); - } - - public FileContent(@NotNull final VirtualFile file) { - this(file, null, null, null); - } - - @TestOnly - public FileContent(byte[] content) { - this(null, null, content, null); - } - - private FileContent(VirtualFile file, CharSequence contentAsText, byte[] content, Charset charset) { - myFile = file; - myContentAsText = contentAsText; - myContent = content; - myCharset = charset; - myFileType = file == null ? null : FileTypeManager.getInstance().getFileTypeByFile(file); - // remember name explicitly because the file could be renamed afterwards - fileName = file == null ? null : file.getName(); - } - - private FileType substituteFileType(VirtualFile file, FileType fileType) { - Project project = getProject(); - return SubstitutedFileType.substituteFileType(file, fileType, project); - } - - public FileType getSubstitutedFileType() { - return substituteFileType(myFile, myFileType); - } - - public FileType getFileTypeWithoutSubstitution() { - return myFileType; - } - - public FileType getFileType() { - return getSubstitutedFileType(); - } - - public VirtualFile getFile() { - return myFile; - } - - public String getFileName() { - return fileName; - } - - public Charset getCharset() { - return myCharset; - } - - public byte[] getContent() { - if (myContent == null) { - if (myContentAsText != null) { - try { - myContent = myCharset != null ? myContentAsText.toString().getBytes(myCharset.name()) : myContentAsText.toString().getBytes(); - } - catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } - } - return myContent; - } - - public CharSequence getContentAsText() { - if (myFileType.isBinary()) { - throw new IllegalDataException("Cannot obtain text for binary file type : " + myFileType.getDescription()); - } - if (myContentAsText == null) { - if (myContent != null) { - myContentAsText = LoadTextUtil.getTextByBinaryPresentation(myContent, myCharset); - } - } - return myContentAsText; - } - - @Override - public String toString() { - return fileName; - } + @NotNull + PsiFile getPsiFile(); } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileContentImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileContentImpl.java new file mode 100644 index 000000000000..0e15c43f5099 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileContentImpl.java @@ -0,0 +1,181 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util.indexing; + +import com.intellij.lang.Language; +import com.intellij.openapi.fileEditor.impl.LoadTextUtil; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.fileTypes.FileTypeManager; +import com.intellij.openapi.fileTypes.LanguageFileType; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; +import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.UserDataHolderBase; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.LanguageSubstitutors; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiFileFactory; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.TestOnly; + +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; + +/** + * @author nik + */ +public class FileContentImpl extends UserDataHolderBase implements FileContent { + private final VirtualFile myFile; + private final String fileName; + private final FileType myFileType; + private final Charset myCharset; + private byte[] myContent; + private CharSequence myContentAsText; + + public Project getProject() { + return getUserData(FileBasedIndex.PROJECT); + } + + private final Key CACHED_PSI = Key.create("cached psi from content"); + + /** + * @return psiFile associated with the content. If the file was not set on FileContentCreation, it will be created on the spot + */ + @NotNull + @Override + public PsiFile getPsiFile() { + PsiFile psi = getUserData(FileBasedIndex.PSI_FILE); + + if (psi == null) { + psi = getUserData(CACHED_PSI); + } + + if (psi == null) { + Project project = getProject(); + if (project == null) { + project = ProjectManager.getInstance().getDefaultProject(); + } + final Language language = ((LanguageFileType)getFileTypeWithoutSubstitution()).getLanguage(); + final Language substitutedLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, getFile(), project); + psi = PsiFileFactory.getInstance(project).createFileFromText(getFileName(), substitutedLanguage, getContentAsText(), false, false, true); + + psi.putUserData(FileBasedIndex.VIRTUAL_FILE, getFile()); + putUserData(CACHED_PSI, psi); + } + return psi; + } + + public static class IllegalDataException extends RuntimeException { + public IllegalDataException(final String message) { + super(message); + } + } + + public FileContentImpl(@NotNull final VirtualFile file, @NotNull final CharSequence contentAsText, final Charset charset) { + this(file, contentAsText, null, charset); + } + + public FileContentImpl(@NotNull final VirtualFile file, @NotNull final byte[] content) { + this(file, null, content, LoadTextUtil.detectCharsetAndSetBOM(file, content)); + } + + public FileContentImpl(@NotNull final VirtualFile file) { + this(file, null, null, null); + } + + @TestOnly + public FileContentImpl(byte[] content) { + this(null, null, content, null); + } + + private FileContentImpl(VirtualFile file, CharSequence contentAsText, byte[] content, Charset charset) { + myFile = file; + myContentAsText = contentAsText; + myContent = content; + myCharset = charset; + myFileType = file == null ? null : FileTypeManager.getInstance().getFileTypeByFile(file); + // remember name explicitly because the file could be renamed afterwards + fileName = file == null ? null : file.getName(); + } + + @NotNull + private FileType substituteFileType(VirtualFile file, FileType fileType) { + Project project = getProject(); + return SubstitutedFileType.substituteFileType(file, fileType, project); + } + + @NotNull + public FileType getSubstitutedFileType() { + return substituteFileType(myFile, myFileType); + } + + public FileType getFileTypeWithoutSubstitution() { + return myFileType; + } + + @NotNull + @Override + public FileType getFileType() { + return getSubstitutedFileType(); + } + + @Override + public VirtualFile getFile() { + return myFile; + } + + @Override + public String getFileName() { + return fileName; + } + + public Charset getCharset() { + return myCharset; + } + + @Override + public byte[] getContent() { + if (myContent == null) { + if (myContentAsText != null) { + try { + myContent = myCharset != null ? myContentAsText.toString().getBytes(myCharset.name()) : myContentAsText.toString().getBytes(); + } + catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } + } + return myContent; + } + + @Override + public CharSequence getContentAsText() { + if (myFileType.isBinary()) { + throw new IllegalDataException("Cannot obtain text for binary file type : " + myFileType.getDescription()); + } + if (myContentAsText == null) { + if (myContent != null) { + myContentAsText = LoadTextUtil.getTextByBinaryPresentation(myContent, myCharset); + } + } + return myContentAsText; + } + + @Override + public String toString() { + return fileName; + } +} diff --git a/platform/lang-impl/src/com/intellij/util/indexing/SubstitutedFileType.java b/platform/lang-impl/src/com/intellij/util/indexing/SubstitutedFileType.java index 8e9cc82dc8f9..aec35fb9cfd6 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/SubstitutedFileType.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/SubstitutedFileType.java @@ -38,7 +38,7 @@ public class SubstitutedFileType extends LanguageFileType{ this.fileType = substitutionFileType; } - + @NotNull public static FileType substituteFileType(VirtualFile file, @NotNull FileType fileType, Project project) { if (project == null) { return fileType; diff --git a/plugins/properties/testSrc/com/intellij/lang/properties/xml/XmlPropertiesIndexTest.java b/plugins/properties/testSrc/com/intellij/lang/properties/xml/XmlPropertiesIndexTest.java index 653df2813948..9959c5a70328 100644 --- a/plugins/properties/testSrc/com/intellij/lang/properties/xml/XmlPropertiesIndexTest.java +++ b/plugins/properties/testSrc/com/intellij/lang/properties/xml/XmlPropertiesIndexTest.java @@ -1,6 +1,6 @@ package com.intellij.lang.properties.xml; -import com.intellij.util.indexing.FileContent; +import com.intellij.util.indexing.FileContentImpl; import junit.framework.TestCase; import java.util.Map; @@ -12,7 +12,7 @@ import java.util.Map; public class XmlPropertiesIndexTest extends TestCase { public void testIndex() throws Exception { - Map map = new XmlPropertiesIndex().map(new FileContent(("\n" + + Map map = new XmlPropertiesIndex().map(new FileContentImpl(("\n" + "\n" + "\n" + "Hi\n" + @@ -27,7 +27,7 @@ public class XmlPropertiesIndexTest extends TestCase { } public void testSystemId() throws Exception { - Map map = new XmlPropertiesIndex().map(new FileContent(("\n" + + Map map = new XmlPropertiesIndex().map(new FileContentImpl(("\n" + "\n" + "\n" + "Hi\n" + From 0ed9f997eec6edb429d2bc4769ec574670304eca Mon Sep 17 00:00:00 2001 From: Evgeny Zakrevsky Date: Thu, 11 Aug 2011 15:32:07 +0400 Subject: [PATCH 12/13] git update dialog fixed --- .../openapi/vcs/update/UpdateOrStatusOptionsDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateOrStatusOptionsDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateOrStatusOptionsDialog.java index c3aec8259417..1385088c2761 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateOrStatusOptionsDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateOrStatusOptionsDialog.java @@ -43,7 +43,7 @@ public abstract class UpdateOrStatusOptionsDialog extends OptionsDialog { myMainPanel = new JPanel(new BorderLayout()); final Configurable configurable = confs.keySet().iterator().next(); addComponent(confs.get(configurable), configurable, BorderLayout.CENTER); - myMainPanel.add(Box.createHorizontalGlue()); + myMainPanel.add(Box.createVerticalStrut(10), BorderLayout.SOUTH); } else { myMainPanel = new JTabbedPane(); From a97aed8b3517f9e334673b5e01e16cea6bcbaac6 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Thu, 11 Aug 2011 13:59:24 +0200 Subject: [PATCH 13/13] dialog style corrected --- .../src/com/intellij/debugger/ui/RunHotswapDialog.java | 7 +------ resources-en/src/messages/DebuggerBundle.properties | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/RunHotswapDialog.java b/java/debugger/impl/src/com/intellij/debugger/ui/RunHotswapDialog.java index 5e0cbeba3862..36a5351162e6 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/RunHotswapDialog.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/RunHotswapDialog.java @@ -114,13 +114,8 @@ public class RunHotswapDialog extends OptionsDialog { label.setIconTextGap(7); } if (myDisplayHangWarning) { - final JLabel warningLabel = new JLabel(DebuggerBundle.message("hotswap.dialog.hang.warning")); + final JLabel warningLabel = new JLabel("WARNING! " + DebuggerBundle.message("hotswap.dialog.hang.warning")); warningLabel.setUI(new MultiLineLabelUI()); - final Icon warningIcon = UIUtil.getWarningIcon(); - if (warningIcon != null) { - warningLabel.setIcon(warningIcon); - warningLabel.setIconTextGap(7); - } panel.add(warningLabel, BorderLayout.SOUTH); } return panel; diff --git a/resources-en/src/messages/DebuggerBundle.properties b/resources-en/src/messages/DebuggerBundle.properties index 669a8d191854..87add5bb72fa 100644 --- a/resources-en/src/messages/DebuggerBundle.properties +++ b/resources-en/src/messages/DebuggerBundle.properties @@ -288,7 +288,7 @@ position.highlighter.stripe.tooltip=Execution line hotswap.dialog.title.with.session=Reload Changed Classes for {0} hotswap.dialog.title=Reload Changed Classes hotswap.dialog.run.prompt=Some classes have been changed. Reload changed classes now? -hotswap.dialog.hang.warning=JVM is currently suspended.\nClasses reloading with active third-party JVM agents may cause the JVM to hang. +hotswap.dialog.hang.warning=JVM is currently suspended.\nReloading classes with active third-party JVM agents may cause the JVM to hang. hotswap.dialog.hang.question=Would you like to reload changed classes anyway? evaluate.statement.dialog.title=Code Fragment Evaluation label.evaluation.dialog.statements=Statements to &evaluate: