Blob Blame History Raw
From 5adbd31eb97262e3d9bf0b3df71a4f248ade1d3d Mon Sep 17 00:00:00 2001
From: Fabio Zadrozny <fabiofz@gmail.com>
Date: Thu, 23 Jan 2020 10:05:30 -0300
Subject: [PATCH] Update yaml to snakeyaml-engine.

---
 .../revisited/modules/AbstractModule.java     |   3 +-
 .../pydev/debug/model/PyBreakpoint.java       |   5 ++--
 .../pydev/debug/model/PyRunToLineTarget.java  |   3 +-
 .../pydev/debug/model/PySetNextTarget.java    |   6 ++--
 .../org.python.pydev.shared_core/.classpath   |   2 +-
 .../META-INF/MANIFEST.MF                      |   4 +--
 .../build.properties                          |   9 +++---
 .../libs/README.txt                           |  10 ++++++-
 .../libs/snakeyaml-1.11.jar                   | Bin 270552 -> 0 bytes
 ...snakeyaml-engine-2.1-20200105.160423-4.jar | Bin 0 -> 259565 bytes
 .../preferences/ScopedPreferences.java        |  11 +++-----
 .../pydev/shared_core/yaml/YamlWrapper.java   |  26 ++++++++++++++++--
 12 files changed, 53 insertions(+), 26 deletions(-)
 delete mode 100644 plugins/org.python.pydev.shared_core/libs/snakeyaml-1.11.jar
 create mode 100644 plugins/org.python.pydev.shared_core/libs/snakeyaml-engine-2.1-20200105.160423-4.jar

diff --git a/plugins/org.python.pydev.debug/src/org/python/pydev/debug/model/PyBreakpoint.java b/plugins/org.python.pydev.debug/src/org/python/pydev/debug/model/PyBreakpoint.java
index ef32f96d4..1e1eee973 100644
--- a/plugins/org.python.pydev.debug/src/org/python/pydev/debug/model/PyBreakpoint.java
+++ b/plugins/org.python.pydev.debug/src/org/python/pydev/debug/model/PyBreakpoint.java
@@ -137,7 +137,8 @@ private IPythonNature getPythonNature() {
             try {
                 String externalPath = (String) marker.getAttribute(PyBreakpoint.PY_BREAK_EXTERNAL_PATH_ID);
                 if (externalPath != null) {
-                    Tuple<IPythonNature, String> infoForFile = InterpreterManagersAPI.getInfoForFile(new File(externalPath));
+                    Tuple<IPythonNature, String> infoForFile = InterpreterManagersAPI
+                            .getInfoForFile(new File(externalPath));
                     if (infoForFile != null) {
                         nature = infoForFile.o1;
                     }
@@ -272,7 +273,7 @@ public String getFunctionName() {
                     //the ast manager is actually restored (so, modName is None, and we have little alternative
                     //but making a parse to get the function name)
                     IDocument doc = getDocument();
-                    sourceModule = AbstractModule.createModuleFromDoc("", null, doc, nature, true);
+                    sourceModule = AbstractModule.createModuleFromDoc("", file, doc, nature, true);
                 }
 
                 int lineToUse = getLineNumber() - 1;
diff --git a/plugins/org.python.pydev.debug/src/org/python/pydev/debug/model/PyRunToLineTarget.java b/plugins/org.python.pydev.debug/src/org/python/pydev/debug/model/PyRunToLineTarget.java
index 326f29acb..8b0ac59af 100644
--- a/plugins/org.python.pydev.debug/src/org/python/pydev/debug/model/PyRunToLineTarget.java
+++ b/plugins/org.python.pydev.debug/src/org/python/pydev/debug/model/PyRunToLineTarget.java
@@ -26,7 +26,6 @@
 import org.python.pydev.parser.visitors.NodeUtils;
 import org.python.pydev.shared_core.string.FullRepIterable;
 
-
 public class PyRunToLineTarget implements IRunToLineTarget {
 
     @Override
@@ -71,7 +70,7 @@ public void runToLine(IWorkbenchPart part, ISelection selection, ISuspendResume
             }
 
             try {
-                sourceModule = (SourceModule) AbstractModule.createModuleFromDoc("", null, doc, nature, true);
+                sourceModule = AbstractModule.createModuleFromDoc("", pyEdit.getEditorFile(), doc, nature, true);
             } catch (MisconfigurationException e) {
                 Log.log(e);
                 return;
diff --git a/plugins/org.python.pydev.debug/src/org/python/pydev/debug/model/PySetNextTarget.java b/plugins/org.python.pydev.debug/src/org/python/pydev/debug/model/PySetNextTarget.java
index 8ea27494f..36e2a6923 100644
--- a/plugins/org.python.pydev.debug/src/org/python/pydev/debug/model/PySetNextTarget.java
+++ b/plugins/org.python.pydev.debug/src/org/python/pydev/debug/model/PySetNextTarget.java
@@ -26,7 +26,6 @@
 import org.python.pydev.parser.visitors.NodeUtils;
 import org.python.pydev.shared_core.string.FullRepIterable;
 
-
 /**
  * @author Hussain Bohra
  */
@@ -38,7 +37,8 @@ public boolean canSetNextToLine(IWorkbenchPart part, ISelection selection, ISusp
     }
 
     @Override
-    public boolean setNextToLine(IWorkbenchPart part, ISelection selection, ISuspendResume target) throws CoreException {
+    public boolean setNextToLine(IWorkbenchPart part, ISelection selection, ISuspendResume target)
+            throws CoreException {
         // System.out.println("Run to line:"+target);
         PyStackFrame stack = null;
         if (target instanceof PyStackFrame) {
@@ -74,7 +74,7 @@ public boolean setNextToLine(IWorkbenchPart part, ISelection selection, ISuspend
             }
 
             try {
-                sourceModule = (SourceModule) AbstractModule.createModuleFromDoc("", null, doc, nature, true);
+                sourceModule = AbstractModule.createModuleFromDoc("", pyEdit.getEditorFile(), doc, nature, true);
             } catch (MisconfigurationException e) {
                 Log.log(e);
                 return false;
diff --git a/plugins/org.python.pydev.shared_core/.classpath b/plugins/org.python.pydev.shared_core/.classpath
index f8225c656..1cdb88323 100644
--- a/plugins/org.python.pydev.shared_core/.classpath
+++ b/plugins/org.python.pydev.shared_core/.classpath
@@ -2,7 +2,7 @@
 <classpath>
 	<classpathentry kind="src" path="src"/>
 	<classpathentry kind="src" path="tests"/>
-	<classpathentry exported="true" kind="lib" path="libs/snakeyaml-1.11.jar"/>
+	<classpathentry exported="true" kind="lib" path="libs/snakeyaml-engine-2.1-20200105.160423-4.jar"/>
 	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
 	<classpathentry kind="lib" path="libs/lucene-analyzers-common-6.1.0.jar"/>
diff --git a/plugins/org.python.pydev.shared_core/META-INF/MANIFEST.MF b/plugins/org.python.pydev.shared_core/META-INF/MANIFEST.MF
index 3c1f8b4df..6baa9c2b2 100644
--- a/plugins/org.python.pydev.shared_core/META-INF/MANIFEST.MF
+++ b/plugins/org.python.pydev.shared_core/META-INF/MANIFEST.MF
@@ -4,9 +4,9 @@ Bundle-Name: Shared Core Plug-in
 Bundle-SymbolicName: org.python.pydev.shared_core;singleton:=true
 Bundle-Version: 7.7.0.qualifier
 Bundle-ClassPath: shared_core.jar,
- libs/snakeyaml-1.11.jar,
  libs/lucene-analyzers-common-6.1.0.jar,
- libs/lucene-core-6.1.0.jar
+ libs/lucene-core-6.1.0.jar,
+ libs/snakeyaml-engine-2.1-20200105.160423-4.jar
 Bundle-Activator: org.python.pydev.shared_core.SharedCorePlugin
 Eclipse-BundleShape: dir
 Require-Bundle: org.eclipse.core.runtime,
diff --git a/plugins/org.python.pydev.shared_core/build.properties b/plugins/org.python.pydev.shared_core/build.properties
index 8af3a0600..3a551ee8c 100644
--- a/plugins/org.python.pydev.shared_core/build.properties
+++ b/plugins/org.python.pydev.shared_core/build.properties
@@ -2,11 +2,10 @@ bin.includes = shared_core.jar,\
                META-INF/,\
                LICENSE.txt,\
                libs/,\
-               libs/lucene-analyzers-common-6.1.0.jar,\
-               libs/lucene-core-6.1.0.jar
+               libs/snakeyaml-engine-2.1-20200105.160423-4.jar
 jars.compile.order = shared_core.jar
 source.shared_core.jar = src/
 output.shared_core.jar = bin/
-jars.extra.classpath = libs/snakeyaml-1.11.jar,\
-                       libs/lucene-core-6.1.0.jar,\
-                       libs/lucene-analyzers-common-6.1.0.jar
+jars.extra.classpath = libs/lucene-core-6.1.0.jar,\
+                       libs/lucene-analyzers-common-6.1.0.jar,\
+                       libs/snakeyaml-engine-2.1-20200105.160423-4.jar
diff --git a/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/preferences/ScopedPreferences.java b/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/preferences/ScopedPreferences.java
index 125a6f2eb..c6aa9c86a 100644
--- a/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/preferences/ScopedPreferences.java
+++ b/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/preferences/ScopedPreferences.java
@@ -41,7 +41,7 @@
 import org.python.pydev.shared_core.string.StringUtils;
 import org.python.pydev.shared_core.structure.OrderedSet;
 import org.python.pydev.shared_core.structure.Tuple;
-import org.yaml.snakeyaml.Yaml;
+import org.python.pydev.shared_core.yaml.YamlWrapper;
 
 public final class ScopedPreferences implements IScopedPreferences {
 
@@ -272,8 +272,7 @@ public String saveToProjectSettings(Map<String, Object> saveData, IProject... pr
 
     private void dumpSaveDataToFile(Map<String, Object> saveData, IFile yamlFile, boolean exists) throws IOException,
             CoreException {
-        Yaml yaml = new Yaml();
-        String dumpAsMap = yaml.dumpAsMap(saveData);
+        String dumpAsMap = YamlWrapper.dumpAsMap(saveData);
         if (!exists) {
             // Create empty (so that we can set the charset properly later on).
             yamlFile.create(new ByteArrayInputStream("".getBytes()), true, new NullProgressMonitor());
@@ -284,8 +283,7 @@ private void dumpSaveDataToFile(Map<String, Object> saveData, IFile yamlFile, bo
     }
 
     private void dumpSaveDataToFile(Map<String, Object> saveData, File yamlFile) throws IOException {
-        Yaml yaml = new Yaml();
-        String dumpAsMap = yaml.dumpAsMap(saveData);
+        String dumpAsMap = YamlWrapper.dumpAsMap(saveData);
         FileUtils.writeStrToFile(dumpAsMap, yamlFile);
         // Don't use the code below because we want to dump as a map to have a better layout for the file.
         //
@@ -541,8 +539,7 @@ public Object call() {
         if (yamlContents.trim().length() == 0) {
             return new HashMap<String, Object>();
         }
-        Yaml yaml = new Yaml();
-        Object load = yaml.load(yamlContents);
+        Object load = YamlWrapper.load(yamlContents);
         if (!(load instanceof Map)) {
             if (load == null) {
                 throw new Exception("Expected top-level element to be a map. Found: null");
diff --git a/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/yaml/YamlWrapper.java b/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/yaml/YamlWrapper.java
index 452675f10..844de9550 100644
--- a/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/yaml/YamlWrapper.java
+++ b/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/yaml/YamlWrapper.java
@@ -2,12 +2,34 @@
 
 import java.util.Map;
 
-import org.yaml.snakeyaml.Yaml;
+import org.snakeyaml.engine.v2.api.Dump;
+import org.snakeyaml.engine.v2.api.DumpSettings;
+import org.snakeyaml.engine.v2.api.Load;
+import org.snakeyaml.engine.v2.api.LoadSettings;
+import org.snakeyaml.engine.v2.api.LoadSettingsBuilder;
+import org.snakeyaml.engine.v2.common.FlowStyle;
 
 public class YamlWrapper {
 
     public static String dumpAsMap(@SuppressWarnings("rawtypes") Map map) {
-        return new Yaml().dumpAsMap(map);
+        Dump dump = new Dump(
+                DumpSettings.builder()
+                        .setBestLineBreak("\n")
+                        .setMultiLineFlow(true)
+                        .setIndent(2)
+                        .setDefaultFlowStyle(FlowStyle.BLOCK)
+                        .build());
+        String output = dump.dumpToString(map);
+        return output;
+    }
+
+    public static Object load(String yamlContents) {
+        LoadSettingsBuilder builder = LoadSettings.builder();
+        LoadSettings settings = builder
+                .setMaxAliasesForCollections(10)
+                .build();
+        Load load = new Load(settings);
+        return load.loadFromString(yamlContents);
     }
 
 }