Skip to content

Commit

Permalink
Update to SnakeYAML 1.21 to fix jruby/jruby#5098.
Browse files Browse the repository at this point in the history
This will be released in Psych 3.0.3. See #352.
  • Loading branch information
headius committed Apr 16, 2018
1 parent fe4e455 commit 51f395c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -18,7 +18,7 @@ if RUBY_PLATFORM =~ /java/
# and tell maven via system properties the snakeyaml version
# this is basically the same as running from the commandline:
# rmvn dependency:build-classpath -Dsnakeyaml.version='use version from Psych::DEFAULT_SNAKEYAML_VERSION here'
Maven::Ruby::Maven.new.exec('dependency:build-classpath', "-Dsnakeyaml.version=1.18", '-Dverbose=true')
Maven::Ruby::Maven.new.exec('dependency:build-classpath', "-Dsnakeyaml.version=1.21", '-Dverbose=true')
ext.source_version = '1.7'
ext.target_version = '1.7'
ext.classpath = File.read('pkg/classpath')
Expand Down
22 changes: 11 additions & 11 deletions ext/java/PsychEmitter.java
Expand Up @@ -202,7 +202,7 @@ public IRubyObject scalar(ThreadContext context, IRubyObject[] args) {
value.asJavaString(),
NULL_MARK,
NULL_MARK,
SCALAR_STYLES[(int)style.convertToInteger().getLongValue()]);
SCALAR_STYLES[style.convertToInteger().getIntValue()]);
emit(context, event);
return this;
}
Expand All @@ -222,7 +222,7 @@ public IRubyObject start_sequence(ThreadContext context, IRubyObject[] args) {
implicit.isTrue(),
NULL_MARK,
NULL_MARK,
SEQUENCE_BLOCK != style.convertToInteger().getLongValue());
SEQUENCE_BLOCK != style.convertToInteger().getLongValue() ? DumperOptions.FlowStyle.BLOCK : DumperOptions.FlowStyle.FLOW);
emit(context, event);
return this;
}
Expand All @@ -249,7 +249,7 @@ public IRubyObject start_mapping(ThreadContext context, IRubyObject[] args) {
implicit.isTrue(),
NULL_MARK,
NULL_MARK,
MAPPING_BLOCK != style.convertToInteger().getLongValue());
MAPPING_BLOCK != style.convertToInteger().getLongValue() ? DumperOptions.FlowStyle.BLOCK : DumperOptions.FlowStyle.FLOW);
emit(context, event);
return this;
}
Expand Down Expand Up @@ -332,16 +332,16 @@ private void initEmitter(ThreadContext context, IRubyObject _encoding) {
DumperOptions options = new DumperOptions();
IRubyObject io;

private static final Mark NULL_MARK = new Mark(null, 0, 0, 0, null, 0);
private static final Mark NULL_MARK = new Mark(null, 0, 0, 0, new int[0], 0);

// Map style constants from Psych values (ANY = 0 ... FOLDED = 5)
// to SnakeYaml values; see psych/nodes/scalar.rb.
private static final Character[] SCALAR_STYLES = new Character[] {
null, // ANY; we'll choose plain
null, // PLAIN
'\'', // SINGLE_QUOTED
'"', // DOUBLE_QUOTED
'|', // LITERAL
'>', // FOLDED
private static final DumperOptions.ScalarStyle[] SCALAR_STYLES = new DumperOptions.ScalarStyle[] {
DumperOptions.ScalarStyle.PLAIN, // ANY
DumperOptions.ScalarStyle.PLAIN,
DumperOptions.ScalarStyle.SINGLE_QUOTED,
DumperOptions.ScalarStyle.DOUBLE_QUOTED,
DumperOptions.ScalarStyle.LITERAL,
DumperOptions.ScalarStyle.FOLDED
};
}
33 changes: 18 additions & 15 deletions ext/java/PsychParser.java
Expand Up @@ -41,6 +41,7 @@
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyEncoding;
import org.jruby.RubyFixnum;
import org.jruby.RubyIO;
import org.jruby.RubyKernel;
import org.jruby.RubyModule;
Expand Down Expand Up @@ -359,24 +360,26 @@ private static void raiseParserException(ThreadContext context, IRubyObject yaml
RubyKernel.raise(context, runtime.getKernel(), new IRubyObject[] { exception }, Block.NULL_BLOCK);
}

private static int translateStyle(Character style) {
private static int translateStyle(DumperOptions.ScalarStyle style) {
if (style == null) return 0; // any

switch (style) {
case 0: return 1; // plain
case '\'': return 2; // single-quoted
case '"': return 3; // double-quoted
case '|': return 4; // literal
case '>': return 5; // folded
case PLAIN: return 1; // plain
case SINGLE_QUOTED: return 2; // single-quoted
case DOUBLE_QUOTED: return 3; // double-quoted
case LITERAL: return 4; // literal
case FOLDED: return 5; // folded
default: return 0; // any
}
}

private static int translateFlowStyle(Boolean flowStyle) {
if (flowStyle == null) return 0; // any

if (flowStyle) return 2;
return 1;
private static int translateFlowStyle(DumperOptions.FlowStyle flowStyle) {
switch (flowStyle) {
case AUTO: return 0;
case BLOCK: return 1;
case FLOW:
default: return 2;
}
}

@JRubyMethod
Expand All @@ -394,9 +397,9 @@ public IRubyObject mark(ThreadContext context) {
if (event == null) {
return ((RubyClass)context.runtime.getClassFromPath("Psych::Parser::Mark")).newInstance(
context,
runtime.newFixnum(0),
runtime.newFixnum(0),
runtime.newFixnum(0),
RubyFixnum.zero(runtime),
RubyFixnum.zero(runtime),
RubyFixnum.zero(runtime),
Block.NULL_BLOCK
);
}
Expand All @@ -405,7 +408,7 @@ public IRubyObject mark(ThreadContext context) {

return ((RubyClass)context.runtime.getClassFromPath("Psych::Parser::Mark")).newInstance(
context,
runtime.newFixnum(mark.getIndex()),
RubyFixnum.zero(runtime),
runtime.newFixnum(mark.getLine()),
runtime.newFixnum(mark.getColumn()),
Block.NULL_BLOCK
Expand Down
2 changes: 1 addition & 1 deletion lib/psych/versions.rb
Expand Up @@ -4,6 +4,6 @@ module Psych
VERSION = '3.0.2'

if RUBY_ENGINE == 'jruby'
DEFAULT_SNAKEYAML_VERSION = '1.18'.freeze
DEFAULT_SNAKEYAML_VERSION = '1.21'.freeze
end
end
2 changes: 1 addition & 1 deletion psych.gemspec
Expand Up @@ -53,7 +53,7 @@ DESCRIPTION
"ext/java/PsychEmitter.java", "ext/java/PsychLibrary.java", "ext/java/PsychParser.java", "ext/java/PsychToRuby.java",
"ext/java/PsychYamlTree.java", "lib/psych_jars.rb", "lib/psych.jar"
]
s.requirements = "jar org.yaml:snakeyaml, 1.18"
s.requirements = "jar org.yaml:snakeyaml, 1.21"
s.add_dependency 'jar-dependencies', '>= 0.1.7'
s.add_development_dependency 'ruby-maven'
else
Expand Down

0 comments on commit 51f395c

Please sign in to comment.