From fcc06c29fa43773d1ae7e0c77bef72a17e67e0c6 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Thu, 6 Nov 2014 12:09:21 +0100 Subject: [PATCH 1/8] Array to xml refactored. --- python/helpers/pydev/pydev_console_utils.py | 15 +++++++ python/helpers/pydev/pydevd_comm.py | 45 +-------------------- python/helpers/pydev/pydevd_vars.py | 44 ++++++++++++++++++++ 3 files changed, 60 insertions(+), 44 deletions(-) diff --git a/python/helpers/pydev/pydev_console_utils.py b/python/helpers/pydev/pydev_console_utils.py index 6e532183b0d1..f519db6d191f 100644 --- a/python/helpers/pydev/pydev_console_utils.py +++ b/python/helpers/pydev/pydev_console_utils.py @@ -385,6 +385,21 @@ class BaseInterpreterInterface: return xml + def getArray(self, attr): + xml = "" + valDict = pydevd_vars.resolveVar(self.getNamespace(), attributes) + if valDict is None: + valDict = {} + + keys = valDict.keys() + + for k in keys: + xml += pydevd_vars.varToXML(valDict[k], to_string(k)) + + xml += "" + + return xml + def changeVariable(self, attr, value): def do_change_variable(): Exec('%s=%s' % (attr, value), self.getNamespace(), self.getNamespace()) diff --git a/python/helpers/pydev/pydevd_comm.py b/python/helpers/pydev/pydevd_comm.py index d26c965c88bd..5727b2d8f790 100644 --- a/python/helpers/pydev/pydevd_comm.py +++ b/python/helpers/pydev/pydevd_comm.py @@ -968,8 +968,6 @@ class InternalGetVariable(InternalThreadCommand): #======================================================================================================================= from pydevd_vars import getVariable -MAXIMUM_ARRAY_SIZE = 300 - class InternalGetArray(InternalThreadCommand): def __init__(self, seq, roffset, coffset, rows, cols, format, thread_id, frame_id, scope, attrs): self.sequence = seq @@ -988,50 +986,9 @@ class InternalGetArray(InternalThreadCommand): try: var = getVariable(self.thread_id, self.frame_id, 'EXPRESSION', self.attrs) - rows = min(self.rows, MAXIMUM_ARRAY_SIZE) - cols = min(self.cols, MAXIMUM_ARRAY_SIZE) - - if self.rows == 1 and self.cols == 1: - rows = 1 - cols = 1 - elif self.rows == 1 or self.cols == 1: - is_row = True if (self.rows == 1) else False - pure_1d = False if (len(var) == 1) else True - - if not pure_1d: - var = var[0] - - if is_row: - var = var[self.coffset:] - cols = min(cols, len(var)) - else: - var = var[self.roffset:] - rows = min(rows, len(var)) - else: - var = var[self.roffset:, self.coffset:] - rows = min(rows, len(var)) - cols = min(cols, len(var[0])) - xml = "" - xml += "" % (self.name, rows, cols) - for row in range(rows): - xml += "" % to_string(row) - for col in range(cols): - value = var - name = '%s[%s][%s]' % (self.name, row, col) - if self.rows == 1 or self.cols == 1: - if self.rows == 1 and self.cols == 1: - value = var - name = '%s' % self.name - else: - dim = col if (self.rows == 1) else row - value = var[dim] - name = '%s[%s]' % (self.name, dim) - else: - value = var[row][col] - value = self.format % value - xml += pydevd_vars.varToXML(value, name) + xml += pydevd_vars.array_to_xml(var, self.roffset, self.coffset, self.rows, self.cols, self.format) xml += "" cmd = dbg.cmdFactory.makeGetArrayMessage(self.sequence, xml) diff --git a/python/helpers/pydev/pydevd_vars.py b/python/helpers/pydev/pydevd_vars.py index b2df11eb410e..56c350034969 100644 --- a/python/helpers/pydev/pydevd_vars.py +++ b/python/helpers/pydev/pydevd_vars.py @@ -19,6 +19,7 @@ import _pydev_threading as threading import traceback import pydevd_save_locals from pydev_imports import Exec, quote, execfile +from pydevd_utils import to_string try: import types @@ -387,6 +388,49 @@ def changeAttrExpression(thread_id, frame_id, attr, expression, dbg): except Exception: traceback.print_exc() +MAXIMUM_ARRAY_SIZE = 300 + +def array_to_xml(array, roffset, coffset, rows, cols, format): + xml = "" + rows = min(rows, MAXIMUM_ARRAY_SIZE) + cols = min(cols, MAXIMUM_ARRAY_SIZE) + if rows == 1 and cols == 1: + rows = 1 + cols = 1 + elif rows == 1 or cols == 1: + is_row = True if (rows == 1) else False + pure_1d = False if (len(array) == 1) else True + + if not pure_1d: + array = array[0] + + if is_row: + array = array[coffset:] + cols = min(cols, len(array)) + else: + array = array[roffset:] + rows = min(rows, len(array)) + else: + array = array[roffset:, coffset:] + rows = min(rows, len(array)) + cols = min(cols, len(array[0])) + xml += "" % (rows, cols) + for row in range(rows): + xml += "" % to_string(row) + for col in range(cols): + value = array + if rows == 1 or cols == 1: + if rows == 1 and cols == 1: + value = array + else: + dim = col if (rows == 1) else row + value = array[dim] + else: + value = array[row][col] + value = format % value + xml += varToXML(value, '') + return xml + From 620be4e708f45272099f099ae03bbd55fafd67fb Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Tue, 4 Nov 2014 15:41:45 +0100 Subject: [PATCH 2/8] use JBColor functions to avoid colors caching (cherry picked from commit 0bd6ff0f93b5ba0f5525f04674b944495e140bfb) --- .../util/src/com/intellij/util/ui/UIUtil.java | 101 ++++++++++-------- 1 file changed, 56 insertions(+), 45 deletions(-) diff --git a/platform/util/src/com/intellij/util/ui/UIUtil.java b/platform/util/src/com/intellij/util/ui/UIUtil.java index 47f5990554a3..893eb1d636b3 100644 --- a/platform/util/src/com/intellij/util/ui/UIUtil.java +++ b/platform/util/src/com/intellij/util/ui/UIUtil.java @@ -680,11 +680,11 @@ public class UIUtil { } public static Color getLabelBackground() { - return UIManager.getColor("Label.background"); + return getColor("Label.background"); } public static Color getLabelForeground() { - return UIManager.getColor("Label.foreground"); + return getColor("Label.foreground"); } public static Color getLabelDisabledForeground() { @@ -734,11 +734,11 @@ public class UIUtil { } public static Color getTableHeaderBackground() { - return UIManager.getColor("TableHeader.background"); + return getColor("TableHeader.background"); } public static Color getTreeTextForeground() { - return UIManager.getColor("Tree.textForeground"); + return getColor("Tree.textForeground"); } public static Color getTreeSelectionBackground() { @@ -748,23 +748,22 @@ public class UIUtil { color = UIManager.getColor("nimbusSelectionBackground"); if (color != null) return color; } - return UIManager.getColor("Tree.selectionBackground"); + return getColor("Tree.selectionBackground"); } public static Color getTreeTextBackground() { - return UIManager.getColor("Tree.textBackground"); + return getColor("Tree.textBackground"); } public static Color getListSelectionForeground() { - final Color color = UIManager.getColor("List.selectionForeground"); - if (color == null) { + if (isUnderNimbusLookAndFeel()) { return UIManager.getColor("List[Selected].textForeground"); // Nimbus } - return color; + return getColor("List.selectionForeground"); } public static Color getFieldForegroundColor() { - return UIManager.getColor("field.foreground"); + return getColor("field.foreground"); } public static Color getTableSelectionBackground() { @@ -774,11 +773,23 @@ public class UIUtil { color = UIManager.getColor("nimbusSelectionBackground"); if (color != null) return color; } - return UIManager.getColor("Table.selectionBackground"); + return getColor("Table.selectionBackground"); } public static Color getActiveTextColor() { - return UIManager.getColor("textActiveText"); + return getColor("textActiveText"); + } + + @NotNull + private static Color getColor(final String property) { + return new JBColor(new NotNullProducer() { + @NotNull + @Override + public Color produce() { + final Color color = UIManager.getColor(property); + return color == null ? Gray.TRANSPARENT : color; + } + }); } public static Color getInactiveTextColor() { @@ -798,7 +809,7 @@ public class UIUtil { } public static Color getInactiveTextFieldBackgroundColor() { - return UIManager.getColor("TextField.inactiveBackground"); + return getColor("TextField.inactiveBackground"); } public static Font getTreeFont() { @@ -810,7 +821,7 @@ public class UIUtil { } public static Color getTreeSelectionForeground() { - return UIManager.getColor("Tree.selectionForeground"); + return getColor("Tree.selectionForeground"); } /** @@ -829,7 +840,7 @@ public class UIUtil { } public static Color getTreeSelectionBorderColor() { - return UIManager.getColor("Tree.selectionBorderColor"); + return getColor("Tree.selectionBorderColor"); } public static int getTreeRightChildIndent() { @@ -841,23 +852,23 @@ public class UIUtil { } public static Color getToolTipBackground() { - return UIManager.getColor("ToolTip.background"); + return getColor("ToolTip.background"); } public static Color getToolTipForeground() { - return UIManager.getColor("ToolTip.foreground"); + return getColor("ToolTip.foreground"); } public static Color getComboBoxDisabledForeground() { - return UIManager.getColor("ComboBox.disabledForeground"); + return getColor("ComboBox.disabledForeground"); } public static Color getComboBoxDisabledBackground() { - return UIManager.getColor("ComboBox.disabledBackground"); + return getColor("ComboBox.disabledBackground"); } public static Color getButtonSelectColor() { - return UIManager.getColor("Button.select"); + return getColor("Button.select"); } public static Integer getPropertyMaxGutterIconWidth(final String propertyPrefix) { @@ -865,7 +876,7 @@ public class UIUtil { } public static Color getMenuItemDisabledForeground() { - return UIManager.getColor("MenuItem.disabledForeground"); + return getColor("MenuItem.disabledForeground"); } public static Object getMenuItemDisabledForegroundObject() { @@ -882,7 +893,7 @@ public class UIUtil { public static Color getTableBackground() { // Under GTK+ L&F "Table.background" often has main panel color, which looks ugly - return isUnderGTKLookAndFeel() ? getTreeTextBackground() : UIManager.getColor("Table.background"); + return isUnderGTKLookAndFeel() ? getTreeTextBackground() : getColor("Table.background"); } public static Color getTableBackground(final boolean isSelected) { @@ -893,11 +904,11 @@ public class UIUtil { if (isUnderNimbusLookAndFeel()) { return UIManager.getColor("Table[Enabled+Selected].textForeground"); } - return UIManager.getColor("Table.selectionForeground"); + return getColor("Table.selectionForeground"); } public static Color getTableForeground() { - return UIManager.getColor("Table.foreground"); + return getColor("Table.foreground"); } public static Color getTableForeground(final boolean isSelected) { @@ -905,7 +916,7 @@ public class UIUtil { } public static Color getTableGridColor() { - return UIManager.getColor("Table.gridColor"); + return getColor("Table.gridColor"); } public static Color getListBackground() { @@ -915,7 +926,7 @@ public class UIUtil { return new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); } // Under GTK+ L&F "Table.background" often has main panel color, which looks ugly - return isUnderGTKLookAndFeel() ? getTreeTextBackground() : UIManager.getColor("List.background"); + return isUnderGTKLookAndFeel() ? getTreeTextBackground() : getColor("List.background"); } public static Color getListBackground(boolean isSelected) { @@ -923,7 +934,7 @@ public class UIUtil { } public static Color getListForeground() { - return UIManager.getColor("List.foreground"); + return getColor("List.foreground"); } public static Color getListForeground(boolean isSelected) { @@ -931,26 +942,26 @@ public class UIUtil { } public static Color getPanelBackground() { - return UIManager.getColor("Panel.background"); + return getColor("Panel.background"); } public static Color getTreeBackground() { - return UIManager.getColor("Tree.background"); + return getColor("Tree.background"); } public static Color getTreeForeground() { - return UIManager.getColor("Tree.foreground"); + return getColor("Tree.foreground"); } public static Color getTableFocusCellBackground() { - return UIManager.getColor(TABLE_FOCUS_CELL_BACKGROUND_PROPERTY); + return getColor(TABLE_FOCUS_CELL_BACKGROUND_PROPERTY); } public static Color getListSelectionBackground() { if (isUnderNimbusLookAndFeel()) { return UIManager.getColor("List[Selected].textBackground"); // Nimbus } - return UIManager.getColor("List.selectionBackground"); + return getColor("List.selectionBackground"); } public static Color getListUnfocusedSelectionBackground() { @@ -967,11 +978,11 @@ public class UIUtil { } public static Color getTextFieldForeground() { - return UIManager.getColor("TextField.foreground"); + return getColor("TextField.foreground"); } public static Color getTextFieldBackground() { - return isUnderGTKLookAndFeel() ? UIManager.getColor("EditorPane.background") : UIManager.getColor("TextField.background"); + return isUnderGTKLookAndFeel() ? UIManager.getColor("EditorPane.background") : getColor("TextField.background"); } public static Font getButtonFont() { @@ -983,7 +994,7 @@ public class UIUtil { } public static Color getTabbedPaneBackground() { - return UIManager.getColor("TabbedPane.background"); + return getColor("TabbedPane.background"); } public static void setSliderIsFilled(final JSlider slider, final boolean value) { @@ -991,11 +1002,11 @@ public class UIUtil { } public static Color getLabelTextForeground() { - return UIManager.getColor("Label.textForeground"); + return getColor("Label.textForeground"); } public static Color getControlColor() { - return UIManager.getColor("control"); + return getColor("control"); } public static Font getOptionPaneMessageFont() { @@ -1007,19 +1018,19 @@ public class UIUtil { } public static Color getSeparatorForeground() { - return UIManager.getColor("Separator.foreground"); + return getColor("Separator.foreground"); } public static Color getSeparatorBackground() { - return UIManager.getColor("Separator.background"); + return getColor("Separator.background"); } public static Color getSeparatorShadow() { - return UIManager.getColor("Separator.shadow"); + return getColor("Separator.shadow"); } public static Color getSeparatorHighlight() { - return UIManager.getColor("Separator.highlight"); + return getColor("Separator.highlight"); } public static Color getSeparatorColorUnderNimbus() { @@ -1054,7 +1065,7 @@ public class UIUtil { } public static Color getTableFocusCellForeground() { - return UIManager.getColor("Table.focusCellForeground"); + return getColor("Table.focusCellForeground"); } /** @@ -1149,15 +1160,15 @@ public class UIUtil { } public static Color getWindowColor() { - return UIManager.getColor("window"); + return getColor("window"); } public static Color getTextAreaForeground() { - return UIManager.getColor("TextArea.foreground"); + return getColor("TextArea.foreground"); } public static Color getOptionPaneBackground() { - return UIManager.getColor("OptionPane.background"); + return getColor("OptionPane.background"); } @SuppressWarnings({"HardCodedStringLiteral"}) From 2910486ed9250d2bd375a129aee74201be890dcc Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Tue, 4 Nov 2014 15:42:15 +0100 Subject: [PATCH 3/8] avoid double wrapping to JBColor (cherry picked from commit ec1e6584688a71954b52788ec584618a4ea3146d) --- platform/util/src/com/intellij/ui/JBColor.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/platform/util/src/com/intellij/ui/JBColor.java b/platform/util/src/com/intellij/ui/JBColor.java index 3669e725610d..cd204b3c00d8 100644 --- a/platform/util/src/com/intellij/ui/JBColor.java +++ b/platform/util/src/com/intellij/ui/JBColor.java @@ -250,23 +250,11 @@ public class JBColor extends Color { public static final Color CYAN = cyan; public static Color foreground() { - return new JBColor(new NotNullProducer() { - @NotNull - @Override - public Color produce() { - return UIUtil.getLabelForeground(); - } - }); + return UIUtil.getLabelForeground(); } public static Color background() { - return new JBColor(new NotNullProducer() { - @NotNull - @Override - public Color produce() { - return UIUtil.getListBackground(); - } - }); + return UIUtil.getListBackground(); } public static Color border() { From 051b7fbb9541277d142f1c58c534f397d206bafd Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Thu, 6 Nov 2014 15:51:47 +0400 Subject: [PATCH 4/8] gradle: honor gradle dependency classifier IDEA-127178 IDEA sets up incorrect classpath, when Gradle artifact is included multiple times with different classifiers --- .../test/ExternalSystemTestCase.java | 47 +++++++++++++++++-- .../BaseGradleProjectResolverExtension.java | 14 ++++++ .../GradleDependenciesImportingTest.java | 33 +++++++++++++ 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/test/ExternalSystemTestCase.java b/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/test/ExternalSystemTestCase.java index 312a95844cf3..b4d45ef03ec8 100644 --- a/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/test/ExternalSystemTestCase.java +++ b/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/test/ExternalSystemTestCase.java @@ -23,7 +23,8 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.command.WriteCommandAction; -import com.intellij.openapi.compiler.*; +import com.intellij.openapi.compiler.CompileScope; +import com.intellij.openapi.compiler.CompilerMessage; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.module.ModuleType; @@ -32,8 +33,12 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl; import com.intellij.openapi.roots.ModuleRootModificationUtil; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.io.ByteSequence; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.io.FileUtilRt; +import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; @@ -50,12 +55,15 @@ import org.junit.After; import org.junit.Before; import java.awt.*; -import java.io.File; -import java.io.IOException; +import java.io.*; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.*; import java.util.List; +import java.util.jar.Attributes; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; +import java.util.jar.Manifest; /** * @author Vladislav.Soroka @@ -337,6 +345,39 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase { return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f); } + @NotNull + protected VirtualFile createProjectJarSubFile(String relativePath, Pair... contentEntries) throws IOException { + assertTrue("Use 'jar' extension for JAR files: '" + relativePath + "'", FileUtilRt.extensionEquals(relativePath, "jar")); + File f = new File(getProjectPath(), relativePath); + FileUtil.ensureExists(f.getParentFile()); + FileUtil.ensureCanCreateFile(f); + final boolean created = f.createNewFile(); + if (!created) { + throw new AssertionError("Unable to create the project sub file: " + f.getAbsolutePath()); + } + + Manifest manifest = new Manifest(); + manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); + JarOutputStream target = new JarOutputStream(new FileOutputStream(f), manifest); + for (Pair contentEntry : contentEntries) { + addJarEntry(contentEntry.first.getBytes(), contentEntry.second, target); + } + target.close(); + + final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f); + assertNotNull(virtualFile); + final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(virtualFile); + assertNotNull(jarFile); + return jarFile; + } + + private static void addJarEntry(byte[] bytes, String path, JarOutputStream target) throws IOException { + JarEntry entry = new JarEntry(path.replace("\\", "/")); + target.putNextEntry(entry); + target.write(bytes); + target.close(); + } + protected VirtualFile createProjectSubFile(String relativePath, String content) throws IOException { VirtualFile file = createProjectSubFile(relativePath); setFileContent(file, content, false); diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseGradleProjectResolverExtension.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseGradleProjectResolverExtension.java index f72df5528590..715fcd7d133d 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseGradleProjectResolverExtension.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseGradleProjectResolverExtension.java @@ -68,6 +68,8 @@ import java.io.FilenameFilter; import java.io.IOException; import java.net.URL; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * {@link BaseGradleProjectResolverExtension} provides base implementation of Gradle project resolver. @@ -651,6 +653,18 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver else { level = LibraryLevel.PROJECT; libraryName = String.format("%s:%s:%s", moduleVersion.getGroup(), moduleVersion.getName(), moduleVersion.getVersion()); + if (binaryPath.isFile()) { + String libraryFileName = FileUtil.getNameWithoutExtension(binaryPath); + final String mavenLibraryFileName = String.format("%s-%s", moduleVersion.getName(), moduleVersion.getVersion()); + if (!mavenLibraryFileName.equals(libraryFileName)) { + Pattern pattern = Pattern.compile(moduleVersion.getName() + "-" + moduleVersion.getVersion() + "-(.*)"); + Matcher matcher = pattern.matcher(libraryFileName); + if (matcher.matches()) { + final String classifier = matcher.group(1); + libraryName += (":" + classifier); + } + } + } } final LibraryData library = new LibraryData(GradleConstants.SYSTEM_ID, libraryName, unresolved); diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/importing/GradleDependenciesImportingTest.java b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/importing/GradleDependenciesImportingTest.java index 41bcbeffc8b5..393f93e97f08 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/importing/GradleDependenciesImportingTest.java +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/importing/GradleDependenciesImportingTest.java @@ -16,6 +16,7 @@ package org.jetbrains.plugins.gradle.importing; import com.intellij.openapi.roots.DependencyScope; +import com.intellij.openapi.vfs.VirtualFile; import org.gradle.util.GradleVersion; import org.junit.Test; @@ -60,4 +61,36 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { assertModuleLibDepScope("project", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.TEST); assertModuleLibDepScope("project", "Gradle: junit:junit:4.11", DependencyScope.TEST); } + + @Test + public void testDependencyWithDifferentClassifiers() throws Exception { + final VirtualFile depJar = createProjectJarSubFile("lib/dep/dep/1.0/dep-1.0.jar"); + final VirtualFile depTestsJar = createProjectJarSubFile("lib/dep/dep/1.0/dep-1.0-tests.jar"); + + importProject( + "allprojects {\n" + + " apply plugin: 'java'\n" + + " sourceCompatibility = 1.5\n" + + " version = '1.0'\n" + + "\n" + + " repositories {\n" + + " mavenCentral()\n" + + " maven{ url file('lib') }\n" + + " }\n" + + "}\n" + + "\n" + + "dependencies {\n" + + " compile 'dep:dep:1.0'\n" + + " testCompile 'dep:dep:1.0:tests'\n" + + "}" + ); + + assertModules("project"); + + assertModuleLibDep("project", "Gradle: dep:dep:1.0", depJar.getUrl()); + assertModuleLibDepScope("project", "Gradle: dep:dep:1.0", DependencyScope.COMPILE); + + assertModuleLibDep("project", "Gradle: dep:dep:1.0:tests", depTestsJar.getUrl()); + assertModuleLibDepScope("project", "Gradle: dep:dep:1.0:tests", DependencyScope.TEST); + } } From 51b6a7117c11f197d8b2fd4d277b4a7e91d1584f Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Thu, 6 Nov 2014 13:34:52 +0100 Subject: [PATCH 5/8] Array viewer for console variables (PY-14182). --- python/helpers/pydev/pydev_console_utils.py | 19 ++- python/helpers/pydev/pydevconsole.py | 2 + python/helpers/pydev/pydevd_vars.py | 78 +++++------ .../python/debugger/PyFrameAccessor.java | 2 +- .../console/PydevConsoleCommunication.java | 37 +++++- .../debugger/array/AsyncArrayTableModel.java | 9 +- .../debugger/array/NumpyArrayTable.java | 123 ++++++++---------- 7 files changed, 147 insertions(+), 123 deletions(-) diff --git a/python/helpers/pydev/pydev_console_utils.py b/python/helpers/pydev/pydev_console_utils.py index f519db6d191f..2980873cd323 100644 --- a/python/helpers/pydev/pydev_console_utils.py +++ b/python/helpers/pydev/pydev_console_utils.py @@ -385,16 +385,21 @@ class BaseInterpreterInterface: return xml - def getArray(self, attr): + def getArray(self, attr, roffset, coffset, rows, cols, format): xml = "" - valDict = pydevd_vars.resolveVar(self.getNamespace(), attributes) - if valDict is None: - valDict = {} + array = pydevd_vars.evalInContext(attr, self.getNamespace(), self.getNamespace()) - keys = valDict.keys() + xml += pydevd_vars.array_to_xml(array, roffset, coffset, rows, cols, format) - for k in keys: - xml += pydevd_vars.varToXML(valDict[k], to_string(k)) + xml += "" + + return xml + + def evaluate(self, expression): + xml = "" + result = pydevd_vars.evalInContext(expression, self.getNamespace(), self.getNamespace()) + + xml += pydevd_vars.varToXML(result, expression) xml += "" diff --git a/python/helpers/pydev/pydevconsole.py b/python/helpers/pydev/pydevconsole.py index f48f975f703f..19c6c944bea2 100644 --- a/python/helpers/pydev/pydevconsole.py +++ b/python/helpers/pydev/pydevconsole.py @@ -293,6 +293,8 @@ def start_server(host, port, interpreter): server.register_function(handshake) server.register_function(interpreter.connectToDebugger) server.register_function(interpreter.hello) + server.register_function(interpreter.getArray) + server.register_function(interpreter.evaluate) # Functions for GUI main loop integration server.register_function(interpreter.enableGui) diff --git a/python/helpers/pydev/pydevd_vars.py b/python/helpers/pydev/pydevd_vars.py index 56c350034969..d9e1d28c37c5 100644 --- a/python/helpers/pydev/pydevd_vars.py +++ b/python/helpers/pydev/pydevd_vars.py @@ -277,6 +277,43 @@ def customOperation(thread_id, frame_id, scope, attrs, style, code_or_file, oper traceback.print_exc() +def evalInContext(expression, globals, locals): + result = None + try: + result = eval(expression, globals, locals) + except Exception: + s = StringIO() + traceback.print_exc(file=s) + result = s.getvalue() + + try: + try: + etype, value, tb = sys.exc_info() + result = value + finally: + etype = value = tb = None + except: + pass + + result = ExceptionOnEvaluate(result) + + # Ok, we have the initial error message, but let's see if we're dealing with a name mangling error... + try: + if '__' in expression: + # Try to handle '__' name mangling... + split = expression.split('.') + curr = locals.get(split[0]) + for entry in split[1:]: + if entry.startswith('__') and not hasattr(curr, entry): + entry = '_%s%s' % (curr.__class__.__name__, entry) + curr = getattr(curr, entry) + + result = curr + except: + pass + return result + + def evaluateExpression(thread_id, frame_id, expression, doExec): '''returns the result of the evaluated expression @param doExec: determines if we should do an exec or an eval @@ -285,9 +322,6 @@ def evaluateExpression(thread_id, frame_id, expression, doExec): if frame is None: return - expression = str(expression.replace('@LINE@', '\n')) - - #Not using frame.f_globals because of https://sourceforge.net/tracker2/?func=detail&aid=2541355&group_id=85796&atid=577329 #(Names not resolved in generator expression in method) #See message: http://mail.python.org/pipermail/python-list/2009-January/526522.html @@ -296,6 +330,7 @@ def evaluateExpression(thread_id, frame_id, expression, doExec): updated_globals.update(frame.f_locals) #locals later because it has precedence over the actual globals try: + expression = str(expression.replace('@LINE@', '\n')) if doExec: try: @@ -312,42 +347,7 @@ def evaluateExpression(thread_id, frame_id, expression, doExec): return else: - result = None - try: - result = eval(expression, updated_globals, frame.f_locals) - except Exception: - s = StringIO() - traceback.print_exc(file=s) - result = s.getvalue() - - try: - try: - etype, value, tb = sys.exc_info() - result = value - finally: - etype = value = tb = None - except: - pass - - result = ExceptionOnEvaluate(result) - - # Ok, we have the initial error message, but let's see if we're dealing with a name mangling error... - try: - if '__' in expression: - # Try to handle '__' name mangling... - split = expression.split('.') - curr = frame.f_locals.get(split[0]) - for entry in split[1:]: - if entry.startswith('__') and not hasattr(curr, entry): - entry = '_%s%s' % (curr.__class__.__name__, entry) - curr = getattr(curr, entry) - - result = curr - except: - pass - - - return result + return evalInContext(expression, updated_globals, frame.f_locals) finally: #Should not be kept alive if an exception happens and this frame is kept in the stack. del updated_globals diff --git a/python/pydevSrc/com/jetbrains/python/debugger/PyFrameAccessor.java b/python/pydevSrc/com/jetbrains/python/debugger/PyFrameAccessor.java index 7ce55d3f2031..e4f68b797571 100644 --- a/python/pydevSrc/com/jetbrains/python/debugger/PyFrameAccessor.java +++ b/python/pydevSrc/com/jetbrains/python/debugger/PyFrameAccessor.java @@ -21,5 +21,5 @@ public interface PyFrameAccessor { @Nullable PyReferrersLoader getReferrersLoader(); - Object[][] getArrayItems(PyDebugValue var, int colOffset, int rowOffset, int rows, int cols, String format) throws PyDebuggerException; + Object[][] getArrayItems(PyDebugValue var, int rowOffset, int colOffset, int rows, int cols, String format) throws PyDebuggerException; } diff --git a/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java b/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java index d756e198765e..c27cfbe0ca0a 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java +++ b/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java @@ -63,6 +63,8 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl private static final String CONNECT_TO_DEBUGGER = "connectToDebugger"; private static final String HANDSHAKE = "handshake"; private static final String CLOSE = "close"; + private static final String EVALUATE = "evaluate"; + private static final String GET_ARRAY = "getArray"; /** * XML-RPC client for sending messages to the server. @@ -461,7 +463,21 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl @Override public PyDebugValue evaluate(String expression, boolean execute, boolean doTrunc) throws PyDebuggerException { - return null; //To change body of implemented methods use File | Settings | File Templates. + if (myClient != null) { + try { + Object ret = myClient.execute(EVALUATE, new Object[]{expression}); + if (ret instanceof String) { + return ProtocolParser.parseValue((String)ret, this); + } + else { + checkError(ret); + } + } + catch (Exception e) { + throw new PyDebuggerException("Evaluate in console failed", e); + } + } + return null; } @Nullable @@ -532,8 +548,23 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl } @Override - public Object[][] getArrayItems(PyDebugValue var, int colOffset, int rowOffset, int rows, int cols, String format) { - return new Object[][]{new Object[]{1, 2}, new Object[]{3, 4}}; + public Object[][] getArrayItems(PyDebugValue var, int rowOffset, int colOffset, int rows, int cols, String format) + throws PyDebuggerException { + if (myClient != null) { + try { + Object ret = myClient.execute(GET_ARRAY, new Object[]{var.getName(), rowOffset, colOffset, rows, cols, format}); + if (ret instanceof String) { + return ProtocolParser.parseArrayValues((String)ret, this); + } + else { + checkError(ret); + } + } + catch (Exception e) { + throw new PyDebuggerException("Evaluate in console failed", e); + } + } + return null; } /** diff --git a/python/src/com/jetbrains/python/debugger/array/AsyncArrayTableModel.java b/python/src/com/jetbrains/python/debugger/array/AsyncArrayTableModel.java index 97316d821925..278bde5f3eb7 100644 --- a/python/src/com/jetbrains/python/debugger/array/AsyncArrayTableModel.java +++ b/python/src/com/jetbrains/python/debugger/array/AsyncArrayTableModel.java @@ -56,8 +56,8 @@ public class AsyncArrayTableModel extends AbstractTableModel { @Override public Object[][] call() throws Exception { return value.getFrameAccessor() - .getArrayItems(slicedValue, key.first, key.second, Math.min(CHUNK_COL_SIZE, getRowCount() - key.first), - Math.min(CHUNK_ROW_SIZE, getColumnCount() - key.second), + .getArrayItems(slicedValue, key.first, key.second, Math.min(CHUNK_ROW_SIZE, getRowCount() - key.first), + Math.min(CHUNK_COL_SIZE, getColumnCount() - key.second), myProvider.getFormat()); } }); @@ -99,10 +99,11 @@ public class AsyncArrayTableModel extends AbstractTableModel { if (r < chunk.get().length) { if (c < chunk.get()[r].length) { - return myProvider.correctStringValue((String)chunk.get()[r][c]); + return myProvider.correctStringValue(chunk.get()[r][c]); } } - } else { + } + else { chunk.addListener(new Runnable() { @Override public void run() { diff --git a/python/src/com/jetbrains/python/debugger/array/NumpyArrayTable.java b/python/src/com/jetbrains/python/debugger/array/NumpyArrayTable.java index a169fc3d6521..d8e5a9ad0821 100644 --- a/python/src/com/jetbrains/python/debugger/array/NumpyArrayTable.java +++ b/python/src/com/jetbrains/python/debugger/array/NumpyArrayTable.java @@ -22,11 +22,14 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; +import com.intellij.util.Consumer; import com.intellij.util.ui.UIUtil; import com.intellij.xdebugger.evaluation.XDebuggerEvaluator; import com.intellij.xdebugger.frame.XValue; import com.jetbrains.python.debugger.PyDebugValue; import com.jetbrains.python.debugger.PyDebuggerEvaluator; +import com.jetbrains.python.debugger.PyDebuggerException; +import com.jetbrains.python.debugger.PyFrameAccessor; import org.jetbrains.annotations.NotNull; import javax.management.InvalidAttributeValueException; @@ -197,8 +200,8 @@ public class NumpyArrayTable { return myValue; } - public PyDebuggerEvaluator getEvaluator() { - return myEvaluator; + public PyFrameAccessor getEvaluator() { + return myValue.getFrameAccessor(); } public void init() { @@ -244,10 +247,10 @@ public class NumpyArrayTable { } private void fillColorRange(@NotNull final Runnable returnToMain) { - XDebuggerEvaluator.XEvaluationCallback callback = new XDebuggerEvaluator.XEvaluationCallback() { + Consumer callback = new Consumer() { @Override - public void evaluated(@NotNull XValue result) { - String rawValue = ((PyDebugValue)result).getValue(); + public void consume(@NotNull PyDebugValue result) { + String rawValue = result.getValue(); double min; double max; String minValue = rawValue.substring(1, rawValue.indexOf(",")); @@ -271,11 +274,6 @@ public class NumpyArrayTable { myTableCellRenderer.setMax(max); returnToMain.run(); } - - @Override - public void errorOccurred(@NotNull String errorMessage) { - showError(errorMessage); - } }; if (getMaxRow(myShape) * getMaxColumn(myShape) > HUGE_ARRAY_SIZE) { @@ -284,7 +282,13 @@ public class NumpyArrayTable { } String evalTypeCommand = "[" + getNodeName() + ".min(), " + getNodeName() + ".max()]"; - getEvaluator().evaluate(evalTypeCommand, callback, null); + try { + PyDebugValue value = getEvaluator().evaluate(evalTypeCommand, true, false); + callback.consume(value); + } + catch (PyDebuggerException e) { + showError(e.getMessage()); + } } public String getDefaultPresentation() { @@ -341,42 +345,27 @@ public class NumpyArrayTable { } private void fillType(@NotNull final Runnable returnToMain) { - XDebuggerEvaluator.XEvaluationCallback callback = new XDebuggerEvaluator.XEvaluationCallback() { - @Override - public void evaluated(@NotNull XValue result) { - setDtypeKind(((PyDebugValue)result).getValue()); - returnToMain.run(); - } - - @Override - public void errorOccurred(@NotNull String errorMessage) { - showError(errorMessage); - } - }; String evalTypeCommand = getNodeName() + ".dtype.kind"; - getEvaluator().evaluate(evalTypeCommand, callback, null); + try { + PyDebugValue value = getEvaluator().evaluate(evalTypeCommand, true, false); + setDtypeKind(value.getValue()); + returnToMain.run(); + } + catch (PyDebuggerException e) { + showError(e.getMessage()); + } } private void fillShape(@NotNull final Runnable returnToMain) { - XDebuggerEvaluator.XEvaluationCallback callback = new XDebuggerEvaluator.XEvaluationCallback() { - @Override - public void evaluated(@NotNull XValue result) { - try { - setShape(parseShape(((PyDebugValue)result).getValue())); - returnToMain.run(); - } - catch (InvalidAttributeValueException e) { - errorOccurred(e.getMessage()); - } - } - - @Override - public void errorOccurred(@NotNull String errorMessage) { - showError(errorMessage); - } - }; String evalShapeCommand = getEvalShapeCommand(getNodeName()); - getEvaluator().evaluate(evalShapeCommand, callback, null); + try { + PyDebugValue value = getEvaluator().evaluate(evalShapeCommand, true, false); + setShape(parseShape(value.getValue())); + returnToMain.run(); + } + catch (Exception e) { + showError(e.getMessage()); + } } private int[] parseShape(String value) throws InvalidAttributeValueException { @@ -542,14 +531,20 @@ public class NumpyArrayTable { }; } - public String correctStringValue(@NotNull String value) { - String corrected = value; - if (isNumeric()) { - if (value.startsWith("\'") || value.startsWith("\"")) { - corrected = value.substring(1, value.length() - 1); + public String correctStringValue(@NotNull Object value) { + if (value instanceof String) { + String corrected = (String)value; + if (isNumeric()) { + if (corrected.startsWith("\'") || corrected.startsWith("\"")) { + corrected = corrected.substring(1, corrected.length() - 1); + } } + return corrected; } - return corrected; + else if (value instanceof Integer) { + return Integer.toString((Integer)value); + } + return value.toString(); } public void setDtypeKind(String dtype) { @@ -611,28 +606,18 @@ public class NumpyArrayTable { private void doReslice(final String newSlice, int[] shape) { if (shape == null) { - XDebuggerEvaluator.XEvaluationCallback callback = new XDebuggerEvaluator.XEvaluationCallback() { - @Override - public void evaluated(@NotNull XValue result) { - try { - int[] shape = parseShape(((PyDebugValue)result).getValue()); - if (!is2DShape(shape)) { - errorOccurred("Incorrect slice shape " + ((PyDebugValue)result).getValue() + "."); - } - doReslice(newSlice, shape); - } - catch (InvalidAttributeValueException e) { - errorOccurred(e.getMessage()); - } - } - - @Override - public void errorOccurred(@NotNull String errorMessage) { - showError(errorMessage); - } - }; String evalShapeCommand = getEvalShapeCommand(newSlice); - getEvaluator().evaluate(evalShapeCommand, callback, null); + try { + PyDebugValue result = getEvaluator().evaluate(evalShapeCommand, true, false); + shape = parseShape(((PyDebugValue)result).getValue()); + if (!is2DShape(shape)) { + showError("Incorrect slice shape " + ((PyDebugValue)result).getValue() + "."); + } + doReslice(newSlice, shape); + } + catch (Exception e) { + showError(e.getMessage()); + } return; } From 2e8e4a3a1d482d60918bab9fee63c8c5591cac03 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Thu, 6 Nov 2014 13:25:05 +0100 Subject: [PATCH 6/8] safely close output-to-target registry --- .../incremental/storage/BuildDataManager.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildDataManager.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildDataManager.java index 5c2bd7887605..f7e6dda1307e 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildDataManager.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/storage/BuildDataManager.java @@ -246,20 +246,24 @@ public class BuildDataManager implements StorageOwner { finally { try { closeSourceToOutputStorages(); - myOutputToTargetRegistry.close(); } finally { try { - closeStorage(mySrcToFormMap); + myOutputToTargetRegistry.close(); } finally { - final Mappings mappings = myMappings; - if (mappings != null) { - try { - mappings.close(); - } - catch (BuildDataCorruptedException e) { - throw e.getCause(); + try { + closeStorage(mySrcToFormMap); + } + finally { + final Mappings mappings = myMappings; + if (mappings != null) { + try { + mappings.close(); + } + catch (BuildDataCorruptedException e) { + throw e.getCause(); + } } } } From 197a04127938fd6ad028f6037a39affe5003707e Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Thu, 6 Nov 2014 13:45:20 +0100 Subject: [PATCH 7/8] Fix eval. --- .../python/debugger/array/NumpyArrayTable.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/python/src/com/jetbrains/python/debugger/array/NumpyArrayTable.java b/python/src/com/jetbrains/python/debugger/array/NumpyArrayTable.java index d8e5a9ad0821..97f7190e99ea 100644 --- a/python/src/com/jetbrains/python/debugger/array/NumpyArrayTable.java +++ b/python/src/com/jetbrains/python/debugger/array/NumpyArrayTable.java @@ -283,7 +283,7 @@ public class NumpyArrayTable { String evalTypeCommand = "[" + getNodeName() + ".min(), " + getNodeName() + ".max()]"; try { - PyDebugValue value = getEvaluator().evaluate(evalTypeCommand, true, false); + PyDebugValue value = getEvaluator().evaluate(evalTypeCommand, false, false); callback.consume(value); } catch (PyDebuggerException e) { @@ -347,7 +347,7 @@ public class NumpyArrayTable { private void fillType(@NotNull final Runnable returnToMain) { String evalTypeCommand = getNodeName() + ".dtype.kind"; try { - PyDebugValue value = getEvaluator().evaluate(evalTypeCommand, true, false); + PyDebugValue value = getEvaluator().evaluate(evalTypeCommand, false, false); setDtypeKind(value.getValue()); returnToMain.run(); } @@ -359,7 +359,7 @@ public class NumpyArrayTable { private void fillShape(@NotNull final Runnable returnToMain) { String evalShapeCommand = getEvalShapeCommand(getNodeName()); try { - PyDebugValue value = getEvaluator().evaluate(evalShapeCommand, true, false); + PyDebugValue value = getEvaluator().evaluate(evalShapeCommand, false, false); setShape(parseShape(value.getValue())); returnToMain.run(); } @@ -369,7 +369,12 @@ public class NumpyArrayTable { } private int[] parseShape(String value) throws InvalidAttributeValueException { - String shape = value.substring(0, value.indexOf('#')); + int index = value.indexOf('#'); + if (index == -1) { + LOG.error("Wrong shape format: " + value); + return new int[]{0, 0}; + } + String shape = value.substring(0, index); if (shape.equals("()")) { return new int[]{1, 1}; } @@ -608,7 +613,7 @@ public class NumpyArrayTable { if (shape == null) { String evalShapeCommand = getEvalShapeCommand(newSlice); try { - PyDebugValue result = getEvaluator().evaluate(evalShapeCommand, true, false); + PyDebugValue result = getEvaluator().evaluate(evalShapeCommand, false, false); shape = parseShape(((PyDebugValue)result).getValue()); if (!is2DShape(shape)) { showError("Incorrect slice shape " + ((PyDebugValue)result).getValue() + "."); From 6ff880772fc85d6112fb6bcae2e971d49762200c Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Thu, 6 Nov 2014 13:54:11 +0100 Subject: [PATCH 8/8] Fix NPE. --- .../python/debugger/array/NumpyArrayTable.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/python/src/com/jetbrains/python/debugger/array/NumpyArrayTable.java b/python/src/com/jetbrains/python/debugger/array/NumpyArrayTable.java index 97f7190e99ea..230e8c058974 100644 --- a/python/src/com/jetbrains/python/debugger/array/NumpyArrayTable.java +++ b/python/src/com/jetbrains/python/debugger/array/NumpyArrayTable.java @@ -167,11 +167,7 @@ public class NumpyArrayTable { } private void initSliceFieldActions() { - if (myComponent.getSliceTextField().getEditor() == null) { - LOG.error("Null editor in slice field."); - return; - } - myComponent.getSliceTextField().getEditor().getContentComponent().addKeyListener(new KeyAdapter() { + myComponent.getSliceTextField().addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { @@ -182,11 +178,7 @@ public class NumpyArrayTable { } private void initFormatFieldActions() { - if (myComponent.getFormatTextField().getEditor() == null) { - LOG.error("Null editor in format field."); - return; - } - myComponent.getFormatTextField().getEditor().getContentComponent().addKeyListener(new KeyAdapter() { + myComponent.getFormatTextField().addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) {