Merge remote branch 'origin/master'

This commit is contained in:
irengrig
2012-03-30 16:18:12 +04:00
42 changed files with 387 additions and 286 deletions
@@ -45,7 +45,7 @@ public class MarkLibraryRootAction extends AnAction {
final List<VirtualFile> jars = getRoots(e);
if (jars.isEmpty()) return;
final List<OrderRoot> roots = RootDetectionUtil.detectRoots(jars, null, project, new DefaultLibraryRootsComponentDescriptor().getRootDetectors(), true);
final List<OrderRoot> roots = RootDetectionUtil.detectRoots(jars, null, project, new DefaultLibraryRootsComponentDescriptor());
new CreateLibraryFromFilesDialog(project, roots).show();
}
@@ -43,9 +43,6 @@ import java.util.ArrayList;
import java.util.List;
public class ProjectCreateModeStep extends ModuleWizardStep {
private static final Icon NEW_PROJECT_ICON = IconLoader.getIcon("/newprojectwizard.png");
private final JPanel myWholePanel;
private WizardMode myMode;
@@ -138,7 +135,7 @@ public class ProjectCreateModeStep extends ModuleWizardStep {
}
public Icon getIcon() {
return myWizardContext.getProject() == null ? NEW_PROJECT_ICON : ICON;
return myWizardContext.getStepIcon();
}
public WizardMode getMode() {
@@ -25,7 +25,6 @@ import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.projectImport.ProjectFormatPanel;
@@ -38,8 +37,6 @@ import java.io.File;
* Date: Jul 17, 2007
*/
public class ProjectNameStep extends ModuleWizardStep {
private static final Icon NEW_PROJECT_ICON = IconLoader.getIcon("/newprojectwizard.png");
private final JPanel myPanel;
protected final JPanel myAdditionalContentPanel;
protected NamePathComponent myNamePathComponent;
@@ -97,7 +94,7 @@ public class ProjectNameStep extends ModuleWizardStep {
}
public Icon getIcon() {
return myWizardContext.getProject() == null ? NEW_PROJECT_ICON : ICON;
return myWizardContext.getStepIcon();
}
public JComponent getPreferredFocusedComponent() {
@@ -61,7 +61,7 @@ public abstract class CreateFromSourcesMode extends WizardMode {
myProjectBuilder = projectBuilder;
final StepSequence sequence = new StepSequence();
final Icon icon = getIcon();
final Icon icon = context.getStepIcon();
if (context.isCreatingNewProject()) {
sequence.addCommonStep(new ProjectNameStep(context, this));
}
@@ -89,8 +89,6 @@ public abstract class CreateFromSourcesMode extends WizardMode {
return sequence;
}
protected abstract Icon getIcon();
public ProjectBuilder getModuleBuilder() {
return myProjectBuilder;
}
@@ -31,14 +31,8 @@ import java.io.File;
* @author nik
*/
public class CreateModuleFromSourcesMode extends CreateFromSourcesMode {
private static final Icon STEP_ICON = IconLoader.getIcon("/addmodulewizard.png");
private TextFieldWithBrowseButton myPathPanel;
protected Icon getIcon() {
return STEP_ICON;
}
public boolean isAvailable(WizardContext context) {
return !context.isCreatingNewProject();
}
@@ -16,20 +16,11 @@
package com.intellij.ide.util.newProjectWizard.modes;
import com.intellij.ide.util.projectWizard.WizardContext;
import com.intellij.openapi.util.IconLoader;
import javax.swing.*;
/**
* @author nik
*/
public class CreateProjectFromSourcesMode extends CreateFromSourcesMode {
private static final Icon STEP_ICON = IconLoader.getIcon("/newprojectwizard.png");
protected Icon getIcon() {
return STEP_ICON;
}
public boolean isAvailable(WizardContext context) {
return context.isCreatingNewProject();
}
@@ -28,7 +28,6 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.JdkListConfigurab
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.MultiLineLabelUI;
import com.intellij.openapi.util.IconLoader;
import com.intellij.util.Consumer;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.Nullable;
@@ -43,7 +42,6 @@ import java.awt.event.ActionListener;
* Date: Jan 21, 2004
*/
public class ProjectJdkForModuleStep extends ModuleWizardStep {
private static final Icon NEW_PROJECT_ICON = IconLoader.getIcon("/newprojectwizard.png");
private final JdkChooserPanel myJdkChooser;
private final JPanel myPanel;
private final WizardContext myContext;
@@ -147,7 +145,7 @@ public class ProjectJdkForModuleStep extends ModuleWizardStep {
}
public Icon getIcon() {
return NEW_PROJECT_ICON;
return myContext.getStepIcon();
}
@Nullable
@@ -29,7 +29,6 @@ import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ui.configuration.ProjectJdksConfigurable;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.MultiLineLabelUI;
import com.intellij.openapi.util.IconLoader;
import javax.swing.*;
import java.awt.*;
@@ -39,7 +38,6 @@ import java.awt.*;
* Date: Jan 21, 2004
*/
public class ProjectJdkStep extends ModuleWizardStep {
private static final Icon NEW_PROJECT_ICON = IconLoader.getIcon("/newprojectwizard.png");
private final WizardContext myContext;
protected final ProjectJdksConfigurable myProjectJdksConfigurable;
@@ -85,7 +83,7 @@ public class ProjectJdkStep extends ModuleWizardStep {
}
public Icon getIcon() {
return NEW_PROJECT_ICON;
return myContext.getStepIcon();
}
public boolean validate() throws ConfigurationException {
@@ -16,14 +16,13 @@
package com.intellij.ide.util.projectWizard;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.highlighter.ProjectFileType;
import com.intellij.ide.highlighter.ModuleFileType;
import com.intellij.ide.highlighter.ProjectFileType;
import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NonNls;
@@ -40,7 +39,6 @@ import static com.intellij.openapi.components.StorageScheme.DIRECTORY_BASED;
* Date: Jan 21, 2004
*/
public class ProjectNameStep extends ModuleWizardStep {
private static final Icon NEW_PROJECT_ICON = IconLoader.getIcon("/newprojectwizard.png");
private final NamePathComponent myNamePathComponent;
private final JPanel myPanel;
private final WizardContext myWizardContext;
@@ -97,7 +95,7 @@ public class ProjectNameStep extends ModuleWizardStep {
}
public Icon getIcon() {
return NEW_PROJECT_ICON;
return myWizardContext.getStepIcon();
}
public boolean validate() throws ConfigurationException {
@@ -19,6 +19,7 @@ import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.ui.OrderRoot;
import com.intellij.openapi.roots.libraries.ui.RootDetector;
import com.intellij.openapi.roots.libraries.ui.impl.LibraryRootsDetectorImpl;
import com.intellij.openapi.roots.libraries.ui.impl.RootDetectionUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
@@ -56,7 +57,8 @@ public class PathUIUtils {
*/
public static VirtualFile[] scanAndSelectDetectedJavaSourceRoots(Component parentComponent, final VirtualFile[] rootCandidates) {
final List<OrderRoot> orderRoots = RootDetectionUtil.detectRoots(Arrays.asList(rootCandidates), parentComponent, null,
Collections.singletonList(JAVA_SOURCE_ROOT_DETECTOR), false);
new LibraryRootsDetectorImpl(Collections.singletonList(JAVA_SOURCE_ROOT_DETECTOR)),
new OrderRootType[0]);
final List<VirtualFile> result = new ArrayList<VirtualFile>();
for (OrderRoot root : orderRoots) {
result.add(root.getFile());
@@ -178,8 +178,13 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
WHEN_FOCUSED
);
myEditButton = new AnActionButton(ProjectBundle.message("module.classpath.button.edit"), null, IconUtil.getEditIcon()) {
@Override
public void actionPerformed(AnActionEvent e) {
doEdit();
}
};
add(createTableWithButtons(), BorderLayout.CENTER);
//add(createButtonsBlock(), BorderLayout.EAST);
if (myEntryTable.getRowCount() > 0) {
myEntryTable.getSelectionModel().setSelectionInterval(0,0);
@@ -212,6 +217,7 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
};
navigateAction.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE).getShortcutSet(),
myEntryTable);
actionGroup.add(myEditButton);
actionGroup.add(navigateAction);
actionGroup.add(new MyFindUsagesAction());
actionGroup.add(new AnalyzeDependencyAction());
@@ -280,30 +286,6 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
}
};
myEditButton = new AnActionButton(ProjectBundle.message("module.classpath.button.edit"), null, IconUtil.getEditIcon()) {
@Override
public void actionPerformed(AnActionEvent e) {
final OrderEntry entry = getSelectedEntry();
if (!(entry instanceof LibraryOrderEntry)) return;
final Library library = ((LibraryOrderEntry)entry).getLibrary();
if (library == null) {
return;
}
final LibraryTable table = library.getTable();
final String tableLevel = table != null ? table.getTableLevel() : LibraryTableImplUtil.MODULE_LEVEL;
final LibraryTablePresentation presentation = LibraryEditingUtil.getLibraryTablePresentation(getProject(), tableLevel);
final LibraryTableModifiableModelProvider provider = getModifiableModelProvider(tableLevel);
EditExistingLibraryDialog dialog = EditExistingLibraryDialog.createDialog(ClasspathPanelImpl.this, provider, library, myState.getProject(),
presentation, getStructureConfigurableContext());
dialog.setContextModule(getRootModel().getModule());
dialog.show();
myEntryTable.repaint();
ModuleStructureConfigurable.getInstance(myState.getProject()).getTree().repaint();
}
};
final AnActionButton analyzeButton = new AnActionButton(ProjectBundle.message("classpath.panel.analyze"), null, SystemInfo.isMac ? PlatformIcons.TABLE_ANALYZE : PlatformIcons.ANALYZE) {
@Override
public void actionPerformed(AnActionEvent e) {
@@ -395,6 +377,26 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
return panel;
}
private void doEdit() {
final OrderEntry entry = getSelectedEntry();
if (!(entry instanceof LibraryOrderEntry)) return;
final Library library = ((LibraryOrderEntry)entry).getLibrary();
if (library == null) {
return;
}
final LibraryTable table = library.getTable();
final String tableLevel = table != null ? table.getTableLevel() : LibraryTableImplUtil.MODULE_LEVEL;
final LibraryTablePresentation presentation = LibraryEditingUtil.getLibraryTablePresentation(getProject(), tableLevel);
final LibraryTableModifiableModelProvider provider = getModifiableModelProvider(tableLevel);
EditExistingLibraryDialog dialog = EditExistingLibraryDialog.createDialog(this, provider, library, myState.getProject(),
presentation, getStructureConfigurableContext());
dialog.setContextModule(getRootModel().getModule());
dialog.show();
myEntryTable.repaint();
ModuleStructureConfigurable.getInstance(myState.getProject()).getTree().repaint();
}
@Override
public void addNotify() {
super.addNotify();
@@ -168,7 +168,7 @@ public class CreateModuleLibraryChooser implements ClasspathElementChooser<Libra
rootsComponentDescriptor = myDefaultDescriptor;
}
List<OrderRoot> chosenRoots = RootDetectionUtil.detectRoots(Arrays.asList(files), myParentComponent, myModule.getProject(),
rootsComponentDescriptor.getRootDetectors(), true);
rootsComponentDescriptor);
final List<OrderRoot> roots = filterAlreadyAdded(chosenRoots);
if (roots.isEmpty()) {
@@ -173,7 +173,6 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent
}
});
final List<? extends RootDetector> detectors = myDescriptor.getRootDetectors();
toolbarDecorator.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
@@ -188,9 +187,7 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent
private AnAction[] getActions() {
List<AnAction> actions = new ArrayList<AnAction>();
if (!detectors.isEmpty()) {
actions.add(new AttachFilesAction(detectors, ProjectBundle.message("button.text.attach.files")));
}
actions.add(new AttachFilesAction(ProjectBundle.message("button.text.attach.files")));
for (AttachRootButtonDescriptor descriptor : myDescriptor.createAttachButtons()) {
actions.add(new AttachItemAction(descriptor, descriptor.getButtonText()));
}
@@ -348,11 +345,8 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent
}
private class AttachFilesAction extends AttachItemActionBase {
private final List<? extends RootDetector> myDetectors;
public AttachFilesAction(List<? extends RootDetector> detectors, String title) {
public AttachFilesAction(String title) {
super(title);
myDetectors = detectors;
}
@Override
@@ -368,7 +362,7 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent
final VirtualFile[] files = FileChooser.chooseFiles(myPanel, chooserDescriptor, initialSelection);
if (files.length == 0) return Collections.emptyList();
return RootDetectionUtil.detectRoots(Arrays.asList(files), myPanel, myProject, myDetectors, true);
return RootDetectionUtil.detectRoots(Arrays.asList(files), myPanel, myProject, myDescriptor);
}
}
@@ -17,7 +17,6 @@ package com.intellij.projectImport;
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
import com.intellij.ide.util.projectWizard.WizardContext;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.io.FileUtil;
import javax.swing.*;
@@ -26,7 +25,6 @@ import javax.swing.*;
* @author Vladislav.Kaznacheev
*/
public abstract class ProjectImportWizardStep extends ModuleWizardStep {
protected static final Icon NEW_PROJECT_ICON = IconLoader.getIcon("/newprojectwizard.png");
private final WizardContext myContext;
public ProjectImportWizardStep(WizardContext context) {
@@ -34,7 +32,7 @@ public abstract class ProjectImportWizardStep extends ModuleWizardStep {
}
public Icon getIcon() {
return myContext.isCreatingNewProject() ? NEW_PROJECT_ICON : ICON;
return myContext.getStepIcon();
}
protected ProjectImportBuilder getBuilder() {
@@ -20,6 +20,7 @@ import com.intellij.lang.ASTNode;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.lexer.JavaLexer;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
@@ -772,7 +773,8 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
// 1. Call 'introduce variable' refactoring for the code like 'System.out.println(1);';
// 2. When KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE is on, the output looks like 'int i = 1; System.out.println(i);';
// That's why we process the option only during the explicit reformat (directly invoked by an user).
if ((mySettings.KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE && FormatterUtil.isFormatterCalledExplicitly())
if ((mySettings.KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE
&& (FormatterUtil.isFormatterCalledExplicitly() || ApplicationManager.getApplication().isUnitTestMode()))
|| psi != null && PsiTreeUtil.hasErrorElements(psi))
{
minSpaces = 1;
@@ -22,15 +22,19 @@ import com.intellij.openapi.components.StorageScheme;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.IconLoader;
import com.intellij.util.SystemProperties;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class WizardContext {
private static final Icon NEW_PROJECT_ICON = IconLoader.getIcon("/newprojectwizard.png");
private static final Icon NEW_MODULE_ICON = IconLoader.getIcon("/addmodulewizard.png");
/**
* a project where the module should be added, can be null => the wizard creates a new project
*/
@@ -118,6 +122,10 @@ public class WizardContext {
return myProject == null;
}
public Icon getStepIcon() {
return isCreatingNewProject() ? NEW_PROJECT_ICON : NEW_MODULE_ICON;
}
public void requestWizardButtonsUpdate() {
final Listener[] listeners = myListeners.toArray(new Listener[myListeners.size()]);
for (Listener listener : listeners) {
@@ -125,7 +125,7 @@ public class BaseIndentEnterHandler extends EnterHandlerDelegateAdapter {
}
else {
if (myIndentTokens.contains(type)) {
final String singleIndent = getSingleIndent(file);
final String singleIndent = getSingleIndent(file, lineIndent);
EditorModificationUtil.insertStringAtCaret(editor, "\n" + lineIndent + singleIndent);
return Result.Stop;
}
@@ -136,9 +136,12 @@ public class BaseIndentEnterHandler extends EnterHandlerDelegateAdapter {
}
}
protected static String getSingleIndent(final PsiFile file) {
CodeStyleSettings currantSettings = CodeStyleSettingsManager.getSettings(file.getProject());
CommonCodeStyleSettings.IndentOptions indentOptions = currantSettings.getIndentOptions(file.getFileType());
protected static String getSingleIndent(final PsiFile file, CharSequence lineIndent) {
if (lineIndent.length() > 0 && lineIndent.charAt(lineIndent.length() - 1) == '\t') {
return "\t";
}
CodeStyleSettings currentSettings = CodeStyleSettingsManager.getSettings(file.getProject());
CommonCodeStyleSettings.IndentOptions indentOptions = currentSettings.getIndentOptions(file.getFileType());
return StringUtil.repeatSymbol(' ', indentOptions.INDENT_SIZE);
}
@@ -24,7 +24,6 @@ import com.intellij.openapi.roots.libraries.LibraryTypeService;
import com.intellij.openapi.roots.libraries.NewLibraryConfiguration;
import com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor;
import com.intellij.openapi.roots.libraries.ui.OrderRoot;
import com.intellij.openapi.roots.libraries.ui.RootDetector;
import com.intellij.openapi.roots.libraries.ui.impl.RootDetectionUtil;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
import com.intellij.openapi.util.io.FileUtil;
@@ -35,7 +34,6 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
@@ -60,22 +58,15 @@ public class LibraryTypeServiceImpl extends LibraryTypeService {
@Nullable VirtualFile contextDirectory,
LibraryType<?> type,
final Project project) {
final List<? extends RootDetector> rootDetectors = descriptor.getRootDetectors();
final List<OrderRoot> roots;
if (!rootDetectors.isEmpty()) {
final FileChooserDescriptor chooserDescriptor = descriptor.createAttachFilesChooserDescriptor();
chooserDescriptor.setTitle("Select Library Files");
final VirtualFile[] rootCandidates = FileChooser.chooseFiles(parentComponent, chooserDescriptor, contextDirectory);
if (rootCandidates.length == 0) {
return null;
}
final FileChooserDescriptor chooserDescriptor = descriptor.createAttachFilesChooserDescriptor();
chooserDescriptor.setTitle("Select Library Files");
final VirtualFile[] rootCandidates = FileChooser.chooseFiles(parentComponent, chooserDescriptor, contextDirectory);
if (rootCandidates.length == 0) {
return null;
}
roots = RootDetectionUtil.detectRoots(Arrays.asList(rootCandidates), parentComponent, project, rootDetectors, true);
if (roots.isEmpty()) return null;
}
else {
roots = Collections.emptyList();
}
final List<OrderRoot> roots = RootDetectionUtil.detectRoots(Arrays.asList(rootCandidates), parentComponent, project, descriptor);
if (roots.isEmpty()) return null;
String name = suggestLibraryName(roots);
return doCreate(type, name, roots);
}
@@ -15,6 +15,7 @@ package com.intellij.openapi.roots.libraries.ui;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.ui.impl.LibraryRootsDetectorImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -36,14 +37,29 @@ public abstract class LibraryRootsComponentDescriptor {
public abstract OrderRootTypePresentation getRootTypePresentation(@NotNull OrderRootType type);
/**
* Provides root detectors for 'Attach Files' button. They will be used to automatically assign {@link OrderRootType}s for selected files.
* Also these detectors are used when a new library is created so the list must not be empty.
* Provides separate detectors for root types supported by the library type.
*
* @return non-empty list of {@link RootDetector}'s implementations
*/
@NotNull
public abstract List<? extends RootDetector> getRootDetectors();
/**
* Provides root detector for 'Attach Files' button. It will be used to automatically assign {@link OrderRootType}s for selected files.
* Also this detector is used when a new library is created
*
* @return {@link LibraryRootsDetector}'s implementation
*/
@NotNull
public LibraryRootsDetector getRootsDetector() {
final List<? extends RootDetector> detectors = getRootDetectors();
if (detectors.isEmpty()) {
throw new IllegalStateException("Detectors list is empty for " + this);
}
return new LibraryRootsDetectorImpl(detectors);
}
/**
* @return descriptor for the file chooser which will be shown when 'Attach Files' button is pressed
*/
@@ -0,0 +1,43 @@
/*
* Copyright 2000-2012 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.openapi.roots.libraries.ui;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
/**
* @author nik
*/
public abstract class LibraryRootsDetector {
/**
* Find suitable roots in {@code rootCandidate} or its descendants.
* @param rootCandidate file selected in the file chooser by user
* @param progressIndicator can be used to show information about the progress and to abort searching if process is cancelled
* @return suitable roots
*/
public abstract Collection<OrderRoot> detectRoots(@NotNull VirtualFile rootCandidate, @NotNull ProgressIndicator progressIndicator);
/**
* @return presentable name for the root type or {@code null} if the root type isn't supported by this detector
*/
@Nullable
public abstract String getRootTypeName(@NotNull OrderRootType rootType, boolean isJarDirectory);
}
@@ -141,7 +141,7 @@ public class DetectedRootsChooserDialog extends DialogWrapper {
private static CheckedTreeNode createTree(List<SuggestedChildRootInfo> suggestedRoots) {
TObjectIntHashMap<VirtualFile> rootTypesCount = new TObjectIntHashMap<VirtualFile>();
for (SuggestedChildRootInfo suggestedRoot : suggestedRoots) {
final VirtualFile root = suggestedRoot.getSuggestedRoot();
final VirtualFile root = suggestedRoot.getSuggestedRoot().getFile();
if (!rootTypesCount.containsKey(root)) {
rootTypesCount.put(root, 0);
}
@@ -158,7 +158,7 @@ public class DetectedRootsChooserDialog extends DialogWrapper {
rootCandidateNodes.put(rootCandidate, parent);
root.add(parent);
}
final String rootType = rootTypesCount.get(rootInfo.getSuggestedRoot()) > 1 ? rootInfo.getDetector().getPresentableRootTypeName() : null;
final String rootType = rootTypesCount.get(rootInfo.getSuggestedRoot().getFile()) > 1 ? rootInfo.getRootTypeName() : null;
parent.add(new VirtualFileCheckedTreeNode(rootInfo, rootType));
}
return root;
@@ -197,7 +197,7 @@ public class DetectedRootsChooserDialog extends DialogWrapper {
public VirtualFileCheckedTreeNode(SuggestedChildRootInfo rootInfo, String rootType) {
super(rootInfo);
myFile = rootInfo.getSuggestedRoot();
myFile = rootInfo.getSuggestedRoot().getFile();
myRootType = rootType;
}
@@ -0,0 +1,61 @@
/*
* Copyright 2000-2012 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.openapi.roots.libraries.ui.impl;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.ui.LibraryRootsDetector;
import com.intellij.openapi.roots.libraries.ui.OrderRoot;
import com.intellij.openapi.roots.libraries.ui.RootDetector;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* @author nik
*/
public class LibraryRootsDetectorImpl extends LibraryRootsDetector {
private List<? extends RootDetector> myDetectors;
public LibraryRootsDetectorImpl(List<? extends RootDetector> detectors) {
myDetectors = detectors;
}
@Override
public Collection<OrderRoot> detectRoots(@NotNull VirtualFile rootCandidate, @NotNull ProgressIndicator progressIndicator) {
List<OrderRoot> result = new ArrayList<OrderRoot>();
for (RootDetector detector : myDetectors) {
final Collection<VirtualFile> files = detector.detectRoots(rootCandidate, progressIndicator);
for (VirtualFile file : files) {
result.add(new OrderRoot(file, detector.getRootType(), detector.isJarDirectory()));
}
}
return result;
}
@Override
public String getRootTypeName(@NotNull OrderRootType rootType, boolean isJarDirectory) {
for (RootDetector detector : myDetectors) {
if (detector.getRootType().equals(rootType) && detector.isJarDirectory() == isJarDirectory) {
return detector.getPresentableRootTypeName();
}
}
return null;
}
}
@@ -20,12 +20,14 @@ import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor;
import com.intellij.openapi.roots.libraries.ui.LibraryRootsDetector;
import com.intellij.openapi.roots.libraries.ui.OrderRoot;
import com.intellij.openapi.roots.libraries.ui.RootDetector;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ArrayUtil;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -46,26 +48,31 @@ public class RootDetectionUtil {
public static List<OrderRoot> detectRoots(@NotNull final Collection<VirtualFile> rootCandidates,
@Nullable Component parentComponent,
@Nullable Project project,
@NotNull final List<? extends RootDetector> detectors,
boolean allowUserToSelectRootTypeIfNothingIsDetected) {
LOG.assertTrue(!detectors.isEmpty());
@NotNull final LibraryRootsComponentDescriptor rootsComponentDescriptor) {
return detectRoots(rootCandidates, parentComponent, project, rootsComponentDescriptor.getRootsDetector(),
rootsComponentDescriptor.getRootTypes());
}
@NotNull
public static List<OrderRoot> detectRoots(@NotNull final Collection<VirtualFile> rootCandidates, @Nullable Component parentComponent,
@Nullable Project project, @NotNull final LibraryRootsDetector detector,
@NotNull OrderRootType[] rootTypesAllowedToBeSelectedByUserIfNothingIsDetected) {
final List<OrderRoot> result = new ArrayList<OrderRoot>();
final List<SuggestedChildRootInfo> suggestedRoots = new ArrayList<SuggestedChildRootInfo>();
new Task.Modal(project, "Scanning for Roots", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
for (RootDetector detector : detectors) {
for (VirtualFile rootCandidate : rootCandidates) {
final Collection<VirtualFile> roots = detector.detectRoots(rootCandidate, indicator);
final VirtualFile first = ContainerUtil.getFirstItem(roots);
if (first != null && roots.size() == 1 && first.equals(rootCandidate)) {
result.add(new OrderRoot(first, detector.getRootType(), detector.isJarDirectory()));
}
else {
for (VirtualFile root : roots) {
suggestedRoots.add(new SuggestedChildRootInfo(detector, rootCandidate, root));
}
for (VirtualFile rootCandidate : rootCandidates) {
final Collection<OrderRoot> roots = detector.detectRoots(rootCandidate, indicator);
if (!roots.isEmpty() && allRootsEqualTo(roots, rootCandidate)) {
result.addAll(roots);
}
else {
for (OrderRoot root : roots) {
final String typeName = detector.getRootTypeName(root.getType(), root.isJarDirectory());
LOG.assertTrue(typeName != null, "Unexpected root type " + root.getType().name() + (root.isJarDirectory() ? " (jar directory)" : "") + ", detectors: " + detector);
suggestedRoots.add(new SuggestedChildRootInfo(rootCandidate, root, typeName));
}
}
}
@@ -84,33 +91,42 @@ public class RootDetectionUtil {
return Collections.emptyList();
}
for (SuggestedChildRootInfo rootInfo : dialog.getChosenRoots()) {
result
.add(new OrderRoot(rootInfo.getSuggestedRoot(), rootInfo.getDetector().getRootType(), rootInfo.getDetector().isJarDirectory()));
result.add(rootInfo.getSuggestedRoot());
}
}
if (result.isEmpty() && allowUserToSelectRootTypeIfNothingIsDetected) {
List<RootDetector> sortedDetectors = new ArrayList<RootDetector>(detectors);
Collections.sort(sortedDetectors, new Comparator<RootDetector>() {
@Override
public int compare(final RootDetector o1, final RootDetector o2) {
return o1.getPresentableRootTypeName().compareToIgnoreCase(o2.getPresentableRootTypeName());
if (result.isEmpty() && rootTypesAllowedToBeSelectedByUserIfNothingIsDetected.length > 0) {
Map<String, Pair<OrderRootType, Boolean>> types = new HashMap<String, Pair<OrderRootType, Boolean>>();
for (OrderRootType type : rootTypesAllowedToBeSelectedByUserIfNothingIsDetected) {
for (boolean isDirectory : new boolean[]{false, true}) {
final String typeName = detector.getRootTypeName(type, isDirectory);
if (typeName != null) {
types.put(typeName, Pair.create(type, isDirectory));
}
}
});
List<String> names = new ArrayList<String>();
for (RootDetector detector : sortedDetectors) {
names.add(detector.getPresentableRootTypeName());
}
LOG.assertTrue(!types.isEmpty(), "No allowed root types found for " + detector);
List<String> sortedNames = new ArrayList<String>(types.keySet());
Collections.sort(sortedNames, String.CASE_INSENSITIVE_ORDER);
final int i = Messages.showChooseDialog("Choose category for selected files:", "Attach Files",
ArrayUtil.toStringArray(names), names.get(0), null);
ArrayUtil.toStringArray(sortedNames), sortedNames.get(0), null);
if (i != -1) {
final RootDetector detector = sortedDetectors.get(i);
final Pair<OrderRootType, Boolean> pair = types.get(sortedNames.get(i));
for (VirtualFile candidate : rootCandidates) {
result.add(new OrderRoot(candidate, detector.getRootType(), detector.isJarDirectory()));
result.add(new OrderRoot(candidate, pair.getFirst(), pair.getSecond()));
}
}
}
return result;
}
private static boolean allRootsEqualTo(Collection<OrderRoot> roots, VirtualFile candidate) {
for (OrderRoot root : roots) {
if (!root.getFile().equals(candidate)) {
return false;
}
}
return true;
}
}
@@ -15,32 +15,32 @@
*/
package com.intellij.openapi.roots.libraries.ui.impl;
import com.intellij.openapi.roots.libraries.ui.RootDetector;
import com.intellij.openapi.roots.libraries.ui.OrderRoot;
import com.intellij.openapi.vfs.VirtualFile;
/**
* @author nik
*/
class SuggestedChildRootInfo {
private RootDetector myDetector;
private VirtualFile myRootCandidate;
private VirtualFile mySuggestedRoot;
private final VirtualFile myRootCandidate;
private final OrderRoot mySuggestedRoot;
private final String myRootTypeName;
SuggestedChildRootInfo(RootDetector detector, VirtualFile rootCandidate, VirtualFile suggestedRoot) {
myDetector = detector;
SuggestedChildRootInfo(VirtualFile rootCandidate, OrderRoot suggestedRoot, String rootTypeName) {
myRootCandidate = rootCandidate;
mySuggestedRoot = suggestedRoot;
}
public RootDetector getDetector() {
return myDetector;
myRootTypeName = rootTypeName;
}
public VirtualFile getRootCandidate() {
return myRootCandidate;
}
public VirtualFile getSuggestedRoot() {
public OrderRoot getSuggestedRoot() {
return mySuggestedRoot;
}
public String getRootTypeName() {
return myRootTypeName;
}
}
@@ -191,10 +191,10 @@ public abstract class ContentEntryEditor implements ContentRootPanel.ActionCallb
}
@Nullable
public SourceFolder addSourceFolder(@NotNull final VirtualFile file, boolean isTestSource) {
public SourceFolder addSourceFolder(@NotNull final VirtualFile file, boolean isTestSource, String packagePrefix) {
final ContentEntry contentEntry = getContentEntry();
if (contentEntry != null) {
final SourceFolder sourceFolder = contentEntry.addSourceFolder(file, isTestSource);
final SourceFolder sourceFolder = contentEntry.addSourceFolder(file, isTestSource, packagePrefix);
try {
return sourceFolder;
}
@@ -71,12 +71,13 @@ public class ToggleSourcesStateAction extends ContentEntryEditingAction {
final SourceFolder sourceFolder = contentEntryEditor.getSourceFolder(selectedFile);
if (isSelected) {
if (sourceFolder == null) { // not marked yet
contentEntryEditor.addSourceFolder(selectedFile, myEditTestSources);
contentEntryEditor.addSourceFolder(selectedFile, myEditTestSources, "");
}
else {
if (myEditTestSources != sourceFolder.isTestSource()) {
final String packagePrefix = sourceFolder.getPackagePrefix();
contentEntryEditor.removeSourceFolder(sourceFolder);
contentEntryEditor.addSourceFolder(selectedFile, myEditTestSources);
contentEntryEditor.addSourceFolder(selectedFile, myEditTestSources, packagePrefix);
}
}
}
@@ -50,6 +50,7 @@ public class JarFileSystemImpl extends JarFileSystem implements ApplicationCompo
private File myNoCopyJarDir;
private final Map<String, JarHandler> myHandlers = new HashMap<String, JarHandler>();
private String[] jarPathsCache; // jarPathsCache = myHandlers.keySet()
private static final class JarFileSystemImplLock {
}
@@ -68,10 +69,15 @@ public class JarFileSystemImpl extends JarFileSystem implements ApplicationCompo
for (VFileEvent event : events) {
if (event.getFileSystem() instanceof LocalFileSystem) {
final String path = event.getPath();
List<String> jarPaths = new ArrayList<String>();
String path = event.getPath();
String[] jarPaths;
synchronized (LOCK) {
jarPaths.addAll(myHandlers.keySet());
if (jarPathsCache == null) {
Set<String> jarPathsSet = myHandlers.keySet();
jarPathsCache = jarPathsSet.toArray(new String[jarPathsSet.size()]);
}
jarPaths = jarPathsCache;
}
for (String jarPath : jarPaths) {
@@ -119,6 +125,7 @@ public class JarFileSystemImpl extends JarFileSystem implements ApplicationCompo
final JarHandler handler;
synchronized (LOCK) {
handler = myHandlers.remove(path);
jarPathsCache = null;
}
if (handler != null) {
@@ -193,6 +200,7 @@ public class JarFileSystemImpl extends JarFileSystem implements ApplicationCompo
if (handler == null) {
freshHandler = handler = new JarHandler(this, jarRootPath.substring(0, jarRootPath.length() - JAR_SEPARATOR.length()));
myHandlers.put(jarRootPath, handler);
jarPathsCache = null;
}
else {
freshHandler = null;
@@ -23,6 +23,7 @@ import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vcs.actions.VcsContextFactory;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager;
@@ -444,12 +445,12 @@ public abstract class VcsVFSListener implements Disposable {
}
for (Iterator<FilePath> iter = myDeletedFiles.iterator(); iter.hasNext(); ) {
if (copiedAddedMoved.contains(iter.next().getPath())) {
if (copiedAddedMoved.contains(FileUtil.toSystemIndependentName(iter.next().getPath()))) {
iter.remove();
}
}
for (Iterator<FilePath> iter = myDeletedWithoutConfirmFiles.iterator(); iter.hasNext(); ) {
if (copiedAddedMoved.contains(iter.next().getPath())) {
if (copiedAddedMoved.contains(FileUtil.toSystemIndependentName(iter.next().getPath()))) {
iter.remove();
}
}
@@ -0,0 +1 @@
String s = getString(R.string.hello);
@@ -0,0 +1 @@
String s = "Hello, world";
@@ -0,0 +1,5 @@
<html>
<body>
This intention extracts existing Java or XML string to a resource
</body>
</html>
+5 -3
View File
@@ -152,6 +152,7 @@
<renamePsiElementProcessor implementation="org.jetbrains.android.AndroidRenameResourceProcessor" order="first"/>
<intentionAction>
<className>org.jetbrains.android.intentions.AndroidAddStringResourceAction</className>
<category>Android</category>
</intentionAction>
<localInspection language="XML" shortName="AndroidDomInspection" bundle="messages.AndroidBundle" key="android.inspections.dom.name"
@@ -166,9 +167,10 @@
key="android.inspections.element.not.allowed.name" groupKey="android.inspections.group.name" enabledByDefault="true"
level="WARNING" implementationClass="org.jetbrains.android.inspections.AndroidElementNotAllowedInspection"/>
<localInspection language="JAVA" shortName="AndroidNonConstantResIdsInSwitch" bundle="messages.AndroidBundle" key="android.inspections.group.name"
groupKey="android.inspections.group.name" enabledByDefault="true" level="ERROR"
implementationClass="org.jetbrains.android.inspections.AndroidNonConstantResIdsInSwitchInspection"/>
<localInspection language="JAVA" shortName="AndroidNonConstantResIdsInSwitch" bundle="messages.AndroidBundle"
key="android.inspections.non.constant.res.ids.in.switch.name" groupKey="android.inspections.group.name"
enabledByDefault="true" level="ERROR"
implementationClass="org.jetbrains.android.inspections.AndroidNonConstantResIdsInSwitchInspection"/>
<inspectionToolProvider implementation="org.jetbrains.android.inspections.lint.AndroidLintInspectionToolProvider"/>
<codeInspection.InspectionExtension implementation="org.jetbrains.android.inspections.lint.AndroidInspectionExtensionsFactory"/>
@@ -75,7 +75,7 @@ public class AndroidLintExternalAnnotator extends ExternalAnnotator<State, State
return null;
}
}
else if (fileType != StdFileTypes.JAVA) {
else {
return null;
}
@@ -295,8 +295,7 @@ public abstract class AndroidLintInspectionBase extends GlobalInspectionTool {
return true;
}
final Scope scope = scopeSet.iterator().next();
return scope != Scope.JAVA_FILE &&
scope != Scope.MANIFEST &&
return scope != Scope.MANIFEST &&
scope != Scope.RESOURCE_FILE &&
scope != Scope.PROGUARD_FILE;
}
@@ -95,7 +95,7 @@ public class AndroidAddStringResourceAction extends AbstractIntentionAction impl
@NotNull
@Override
public String getFamilyName() {
return AndroidBundle.message("intention.family");
return getText();
}
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
@@ -19,130 +19,55 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
/**
* The descriptor of git command. It contains policy information about myLocking and GUI thread policy.
* <p>
* The descriptor of git command.
* </p>
* <p>
* It contains policy information about locking which is handled in {@link GitHandler#runInCurrentThread(java.lang.Runnable)} to prevent
* simultaneous Git commands conflict on the index.lock file.
* write-commands can't be executed simultaneously, but a write-command doesn't prevent read-commands to execute.
* </p>
* <p>
* A lock-policy can be different for a single command, for example, {@code git stash} may change the index (and thus should hold the
* write lock), which {@code git stash list} doesn't (and therefore no lock is needed).
* </p>
*/
public class GitCommand {
public static final GitCommand ADD = write("add");
public static final GitCommand ANNOTATE = read("annotate");
public static final GitCommand BRANCH = meta("branch");
public static final GitCommand BRANCH = read("branch");
public static final GitCommand CHECKOUT = write("checkout");
public static final GitCommand COMMIT = write("commit");
public static final GitCommand CONFIG = meta("config");
public static final GitCommand CHECK_ATTR = read("check-attr");
public static final GitCommand CONFIG = read("config");
public static final GitCommand CHERRY_PICK = write("cherry-pick");
public static final GitCommand CLONE = write("clone");
public static final GitCommand DESCRIBE = meta("describe");
public static final GitCommand DIFF = read("diff");
public static final GitCommand DIFF_INDEX = read("diff-index");
public static final GitCommand FETCH = write("fetch");
public static final GitCommand FETCH = read("fetch"); // fetch is a read-command, because it doesn't modify the index
public static final GitCommand INIT = write("init");
public static final GitCommand LOG = meta("log");
public static final GitCommand LOG = read("log");
public static final GitCommand LS_FILES = read("ls-files");
public static final GitCommand LS_REMOTE = meta("ls-remote");
public static final GitCommand LS_REMOTE = read("ls-remote");
public static final GitCommand MERGE = write("merge");
public static final GitCommand MERGE_BASE = meta("merge-base");
public static final GitCommand MERGE_BASE = read("merge-base");
public static final GitCommand PULL = write("pull");
public static final GitCommand PUSH = write("push");
public static final GitCommand REBASE = writeSuspendable("rebase");
public static final GitCommand REMOTE = meta("remote");
public static final GitCommand REMOTE = read("remote");
public static final GitCommand RESET = write("reset");
public static final GitCommand REV_LIST = meta("rev-list");
public static final GitCommand REV_LIST = read("rev-list");
public static final GitCommand RM = write("rm");
public static final GitCommand SHOW = write("show");
public static final GitCommand SHOW = read("show");
public static final GitCommand STASH = write("stash");
public static final GitCommand STATUS = read("status");
public static final GitCommand TAG = meta("tag");
public static final GitCommand TAG = read("tag");
public static final GitCommand UPDATE_INDEX = write("update-index");
public static final GitCommand VERSION = meta("version");
public static final GitCommand GC = write("gc");
/**
* Name of environment variable that specifies editor for the git
*/
public static final String GIT_EDITOR_ENV = "GIT_EDITOR";
@NotNull @NonNls private final String myName; // command name passed to git
@NotNull private final LockingPolicy myLocking; // Locking policy for the command
@NotNull private final ThreadPolicy myThreading; // Thread policy for the command
/**
* The constructor
*
* @param name the command myName
* @param locking the myLocking policy
* @param threading the thread policy
*/
private GitCommand(@NonNls @NotNull String name, @NotNull LockingPolicy locking, @NotNull ThreadPolicy threading) {
this.myLocking = locking;
this.myName = name;
this.myThreading = threading;
}
/**
* Create command descriptor that performs metadata operations only
*
* @param name the command myName
* @return the created command object
*/
private static GitCommand meta(String name) {
return new GitCommand(name, LockingPolicy.META, ThreadPolicy.ANY);
}
/**
* Create command descriptor that performs reads from index
*
* @param name the command myName
* @return the create command objects
*/
private static GitCommand read(String name) {
return new GitCommand(name, LockingPolicy.READ, ThreadPolicy.BACKGROUND_ONLY);
}
/**
* Create command descriptor that performs write operations
*
* @param name the command myName
* @return the created command object
*/
private static GitCommand write(String name) {
return new GitCommand(name, LockingPolicy.WRITE, ThreadPolicy.BACKGROUND_ONLY);
}
/**
* Create command descriptor that performs write operations
*
* @param name the command myName
* @return the created command object
*/
private static GitCommand writeSuspendable(String name) {
return new GitCommand(name, LockingPolicy.WRITE_SUSPENDABLE, ThreadPolicy.BACKGROUND_ONLY);
}
/**
* @return the command name
*/
@NotNull
public String name() {
return myName;
}
/**
* @return the locking policy for the command
*/
@NotNull
public LockingPolicy lockingPolicy() {
return myLocking;
}
/**
* @return the locking policy for the command
*/
@NotNull
public ThreadPolicy threadingPolicy() {
return myThreading;
}
/**
* The myLocking policy for the command
*/
@@ -159,23 +84,56 @@ public class GitCommand {
* Write lock should be acquired for the command, and it could be acquired in several intervals
*/
WRITE_SUSPENDABLE,
/**
* Metadata read/write command
*/
META,
}
@NotNull @NonNls private final String myName; // command name passed to git
@NotNull private final LockingPolicy myLocking; // Locking policy for the command
/**
* Thread policy for command
* Creates a git command with LockingPolicy different from the default one.
* Use this constructor with care: specifying read-policy on a write operation may result in a conflict during simultaneous
* modification of index.
* @param command Original command.
* @param lockingPolicy Locking policy overriding default locking policy of the original command.
*/
enum ThreadPolicy {
/**
* Any thread could be used
*/
ANY,
/**
* Only background thread could be used
*/
BACKGROUND_ONLY
private GitCommand(@NotNull GitCommand command, @NotNull LockingPolicy lockingPolicy) {
myName = command.name();
myLocking = lockingPolicy;
}
private GitCommand(@NonNls @NotNull String name, @NotNull LockingPolicy locking) {
myLocking = locking;
myName = name;
}
@NotNull
private static GitCommand read(@NotNull String name) {
return new GitCommand(name, LockingPolicy.READ);
}
@NotNull
private static GitCommand write(@NotNull String name) {
return new GitCommand(name, LockingPolicy.WRITE);
}
@NotNull
private static GitCommand writeSuspendable(@NotNull String name) {
return new GitCommand(name, LockingPolicy.WRITE_SUSPENDABLE);
}
@NotNull
public String name() {
return myName;
}
@NotNull
public LockingPolicy lockingPolicy() {
return myLocking;
}
@NotNull
public GitCommand readLockingCommand() {
return new GitCommand(this, LockingPolicy.READ);
}
}
@@ -620,7 +620,6 @@ public abstract class GitHandler {
boolean suspendable = false;
switch (myCommand.lockingPolicy()) {
case META:
case READ:
// need to lock only write operations: reads can be performed even when a write operation is going on
break;
@@ -713,7 +712,6 @@ public abstract class GitHandler {
}
finally {
switch (myCommand.lockingPolicy()) {
case META:
case READ:
break;
case WRITE_SUSPENDABLE:
@@ -182,7 +182,7 @@ public class GitImpl implements Git {
@Override
public GitCommandResult checkoutNewBranch(@NotNull GitRepository repository, @NotNull String branchName,
@Nullable GitLineHandlerListener listener) {
final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitCommand.CHECKOUT);
final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitCommand.CHECKOUT.readLockingCommand());
h.setSilent(false);
h.addParameters("-b");
h.addParameters(branchName);
@@ -728,7 +728,7 @@ public class GitHistoryUtils {
@Nullable
public static Pair<AbstractHash, AbstractHash> getStashTop(@NotNull Project project, @NotNull VirtualFile root) throws VcsException {
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.STASH);
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.STASH.readLockingCommand());
GitLogParser parser = new GitLogParser(project, SHORT_HASH, SHORT_PARENTS);
h.setSilent(true);
h.setNoSSH(true);
@@ -776,7 +776,7 @@ public class GitHistoryUtils {
@Nullable
public static List<Pair<String, GitCommit>> loadStashStackAsCommits(@NotNull Project project, @NotNull VirtualFile root,
SymbolicRefsI refs, final String... parameters) throws VcsException {
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.STASH);
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.STASH.readLockingCommand());
GitLogParser parser = new GitLogParser(project, GitLogParser.NameStatus.STATUS, SHORT_HASH, HASH, COMMIT_TIME, AUTHOR_NAME, AUTHOR_TIME, AUTHOR_EMAIL, COMMITTER_NAME,
COMMITTER_EMAIL, SHORT_PARENTS, REF_NAMES, SHORT_REF_LOG_SELECTOR, SUBJECT, BODY, RAW_BODY);
h.setSilent(true);
@@ -64,7 +64,7 @@ public class GitStashUtils {
public static void loadStashStack(@NotNull Project project, @NotNull VirtualFile root, final Charset charset,
final Consumer<StashInfo> consumer) {
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.STASH);
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.STASH.readLockingCommand());
h.setSilent(true);
h.setNoSSH(true);
h.addParameters("list");
@@ -421,7 +421,7 @@ public class MavenIndex {
}
@TestOnly
protected File getDir() {
public File getDir() {
return myDir;
}
@@ -491,6 +491,17 @@ public class MavenIndex {
}, Collections.<String>emptySet());
}
@TestOnly
public void printInfo() {
doIndexTask(new IndexTask<Set<String>>() {
public Set<String> doTask() throws Exception {
System.out.println("BaseFile: " + myData.groupToArtifactMap.getBaseFile());
System.out.println("All data objects: " + myData.groupToArtifactMap.getAllDataObjects(null));
return Collections.<String>emptySet();
}
}, Collections.<String>emptySet());
}
public synchronized Set<String> getVersions(final String groupId, final String artifactId) {
return doIndexTask(new IndexTask<Set<String>>() {
public Set<String> doTask() throws Exception {
@@ -18,6 +18,7 @@ package org.jetbrains.idea.maven.dom;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiReference;
import org.jetbrains.idea.maven.indices.MavenIndex;
import org.jetbrains.idea.maven.indices.MavenIndicesTestFixture;
import org.jetbrains.idea.maven.indices.MavenProjectIndicesManager;
@@ -72,14 +73,22 @@ public class MavenExtensionCompletionAndResolutionTest extends MavenDomWithIndic
List<String> actual = getCompletionVariants(myProjectPom);
if (!new HashSet<String>(actual).equals(new HashSet<String>(Arrays.asList("maven-compiler-plugin", "maven-war-plugin", "maven-eclipse-plugin", "maven-surefire-plugin")))) {
MavenProjectIndicesManager instance = MavenProjectIndicesManager.getInstance(myProject);
System.out.println("GetArtifacts: " + instance.getArtifactIds("org.apache.maven.plugins"));
System.out.println("Indexes: " + instance.getIndices());
throw new AssertionError("GetArtifacts: " + instance.getArtifactIds("org.apache.maven.plugins") + "Indexes: " + instance.getIndices());
try {
assertUnorderedElementsAreEqual(actual, "maven-compiler-plugin", "maven-war-plugin", "maven-eclipse-plugin", "maven-surefire-plugin");
}
catch (Throwable t) {
MavenProjectIndicesManager instance = MavenProjectIndicesManager.getInstance(myProject);
System.out.println("GetArtifacts: " + new HashSet<String>(instance.getArtifactIds("org.apache.maven.plugins")));
System.out.println("Indexes: " + instance.getIndices());
assertUnorderedElementsAreEqual(actual, "maven-compiler-plugin", "maven-war-plugin", "maven-eclipse-plugin", "maven-surefire-plugin");
for (MavenIndex index : instance.getIndices()) {
System.out.println("Index: repositoryId=" + index.getRepositoryId() + " repositoryUrl=" + index.getRepositoryUrl() + " repositoryPathOrUrl" + index.getRepositoryPathOrUrl());
System.out.println("Dir: " + index.getDir());
index.printInfo();
}
throw new AssertionError("GetArtifacts: " + instance.getArtifactIds("org.apache.maven.plugins") + " Indexes: " + instance.getIndices());
}
}
public void testArtifactWithoutGroupCompletion() throws Exception {