|
41 | 41 | import org.jruby.runtime.builtin.IRubyObject; |
42 | 42 | import org.jruby.runtime.load.Library; |
43 | 43 |
|
| 44 | +import org.snakeyaml.engine.v2.common.SpecVersion; |
| 45 | + |
44 | 46 | import java.io.IOException; |
45 | 47 | import java.io.InputStream; |
46 | 48 | import java.util.Properties; |
47 | 49 |
|
48 | 50 | public class PsychLibrary implements Library { |
| 51 | + |
| 52 | + private static final String POM_PROPERTIES = "META-INF/maven/org.snakeyaml/snakeyaml-engine/pom.properties"; |
49 | 53 | private static final String DUMMY_VERSION = "0.0"; |
50 | 54 |
|
51 | 55 | public void load(final Ruby runtime, boolean wrap) { |
52 | 56 | RubyModule psych = runtime.defineModule("Psych"); |
53 | 57 |
|
54 | 58 | // load version from properties packed with the jar |
55 | 59 | Properties props = new Properties(); |
56 | | - try( InputStream is = runtime.getJRubyClassLoader().getResourceAsStream("META-INF/maven/org.snakeyaml/snakeyaml-engine/pom.properties") ) { |
57 | | - props.load(is); |
| 60 | + try( InputStream is = SpecVersion.class.getResourceAsStream(POM_PROPERTIES) ) { |
| 61 | + if (is != null) props.load(is); |
58 | 62 | } |
59 | 63 | catch( IOException e ) { |
60 | 64 | // ignored |
61 | 65 | } |
62 | 66 | String snakeyamlVersion = props.getProperty("version", DUMMY_VERSION); |
63 | 67 |
|
| 68 | + RubyString version = runtime.newString(snakeyamlVersion); |
| 69 | + version.setFrozen(true); |
| 70 | + psych.setConstant("SNAKEYAML_VERSION", version); // e.g. 2.10-SNAPSHOT |
| 71 | + |
64 | 72 | if (snakeyamlVersion.endsWith("-SNAPSHOT")) { |
65 | 73 | snakeyamlVersion = snakeyamlVersion.substring(0, snakeyamlVersion.length() - "-SNAPSHOT".length()); |
66 | 74 | } |
67 | 75 |
|
68 | | - RubyString version = runtime.newString(snakeyamlVersion + ".0"); |
69 | | - version.setFrozen(true); |
70 | | - psych.setConstant("SNAKEYAML_VERSION", version); |
71 | | - |
72 | | - String[] versionParts = version.toString().split("\\."); |
| 76 | + String[] versionParts = (snakeyamlVersion + ".0").split("\\."); // 2.10-SNAPSHOT -> 2.10.0 |
73 | 77 | final RubyArray versionElements = runtime.newArray(runtime.newFixnum(Integer.parseInt(versionParts[0])), runtime.newFixnum(Integer.parseInt(versionParts[1])), runtime.newFixnum(Integer.parseInt(versionParts[2]))); |
74 | 78 | versionElements.setFrozen(true); |
75 | 79 |
|
|
0 commit comments