Java Code Examples for java.lang.module.ModuleDescriptor.Version#parse()
The following examples show how to use
java.lang.module.ModuleDescriptor.Version#parse() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Builder.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Returns a {@link Requires} for a dependence on a module with the given * (and possibly empty) set of modifiers, and optionally the version * recorded at compile time. */ public static Requires newRequires(Set<Requires.Modifier> mods, String mn, String compiledVersion) { Version version = null; if (compiledVersion != null) { // use the cached version if the same version string Version ver = cachedVersion; if (ver != null && compiledVersion.equals(ver.toString())) { version = ver; } else { version = Version.parse(compiledVersion); } } return JLMA.newRequires(mods, mn, version); }
Example 2
Source File: Builder.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Returns a {@link Requires} for a dependence on a module with the given * (and possibly empty) set of modifiers, and optionally the version * recorded at compile time. */ public static Requires newRequires(Set<Requires.Modifier> mods, String mn, String compiledVersion) { Version version = null; if (compiledVersion != null) { // use the cached version if the same version string Version ver = cachedVersion; if (ver != null && compiledVersion.equals(ver.toString())) { version = ver; } else { version = Version.parse(compiledVersion); } } return JLMA.newRequires(mods, mn, version); }
Example 3
Source File: VersionTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider = "validVersions") public void testEqualsAndHashCode(String vs, String ignore) { Version v1 = Version.parse(vs); Version v2 = Version.parse(vs); assertEquals(v1, v2); assertEquals(v2, v1); assertEquals(v1.hashCode(), v2.hashCode()); Version v3 = Version.parse("1.0-rhubarb"); assertNotEquals(v1, v3); assertNotEquals(v2, v3); assertNotEquals(v3, v1); assertNotEquals(v3, v2); }
Example 4
Source File: VersionTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Test compareTo with equal versions. */ @Test(dataProvider = "equalVersions") public void testCompareEqualsVersions(String vs1, String vs2) { Version v1 = Version.parse(vs1); assertTrue(v1.compareTo(v1) == 0); Version v2 = Version.parse(vs2); assertTrue(v2.compareTo(v2) == 0); assertTrue(v1.compareTo(v2) == 0); assertTrue(v2.compareTo(v1) == 0); assertEquals(v1, v2); assertEquals(v2, v1); }
Example 5
Source File: Builder.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Sets the module version. * * @throws IllegalArgumentException if {@code v} is null or cannot be * parsed as a version string * * @see Version#parse(String) */ public Builder version(String v) { Version ver = cachedVersion; if (ver != null && v.equals(ver.toString())) { version = ver; } else { cachedVersion = version = Version.parse(v); } return this; }
Example 6
Source File: Builder.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Sets the module version. * * @throws IllegalArgumentException if {@code v} is null or cannot be * parsed as a version string * * @see Version#parse(String) */ public Builder version(String v) { Version ver = cachedVersion; if (ver != null && v.equals(ver.toString())) { version = ver; } else { cachedVersion = version = Version.parse(v); } return this; }
Example 7
Source File: JmodTask.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public Version convert(String value) { try { return Version.parse(value); } catch (IllegalArgumentException x) { throw new CommandException("err.invalid.version", x.getMessage()); } }
Example 8
Source File: VersionTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Test compareTo with ordered versions. */ @Test(dataProvider = "orderedVersions") public void testCompareOrderedVersions(String vs1, String vs2) { Version v1 = Version.parse(vs1); assertTrue(v1.compareTo(v1) == 0); Version v2 = Version.parse(vs2); assertTrue(v2.compareTo(v2) == 0); // v1 < v2 assertTrue(v1.compareTo(v2) < 0); assertTrue(v2.compareTo(v1) > 0); }
Example 9
Source File: ModuleDescriptorTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void testRequiresWithCompiledVersion() { Version v = Version.parse("1.0"); Requires r = requires(Set.of(), "foo", v); assertEquals(r, r); assertTrue(r.compareTo(r) == 0); assertEquals(r.modifiers(), Set.of()); assertEquals(r.name(), "foo"); assertTrue(r.compiledVersion().isPresent()); assertEquals(r.compiledVersion().get().toString(), "1.0"); }
Example 10
Source File: ModuleDescriptorTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void testRequiresEqualsAndHashCode() { Requires r1 = requires("foo"); Requires r2 = requires("foo"); assertEquals(r1, r2); assertTrue(r1.hashCode() == r2.hashCode()); r1 = requires(EnumSet.allOf(Requires.Modifier.class), "foo"); r2 = requires(EnumSet.allOf(Requires.Modifier.class), "foo"); assertEquals(r1, r2); assertTrue(r1.hashCode() == r2.hashCode()); r1 = requires("foo"); r2 = requires("bar"); assertNotEquals(r1, r2); r1 = requires(EnumSet.allOf(Requires.Modifier.class), "foo"); r2 = requires(Set.of(), "foo"); assertNotEquals(r1, r2); Version v1 = Version.parse("1.0"); r1 = requires(EnumSet.allOf(Requires.Modifier.class), "foo", v1); r2 = requires(EnumSet.allOf(Requires.Modifier.class), "foo", v1); assertEquals(r1, r2); assertTrue(r1.hashCode() == r2.hashCode()); Version v2 = Version.parse("2.0"); r1 = requires(EnumSet.allOf(Requires.Modifier.class), "foo", v1); r2 = requires(EnumSet.allOf(Requires.Modifier.class), "foo", v2); assertNotEquals(r1, r2); }
Example 11
Source File: ModuleDescriptorTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void testVersion1() { Version v1 = Version.parse("1.0"); Version v2 = ModuleDescriptor.newModule("foo") .version(v1) .build() .version() .get(); assertEquals(v1, v2); }
Example 12
Source File: ModuleDescriptorTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void testVersion2() { String vs = "1.0"; Version v1 = ModuleDescriptor.newModule("foo") .version(vs) .build() .version() .get(); Version v2 = Version.parse(vs); assertEquals(v1, v2); }
Example 13
Source File: ModuleDescriptorTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private boolean isParsableVersion(String vs) { try { Version.parse(vs); return true; } catch (IllegalArgumentException e) { return false; } }
Example 14
Source File: VersionTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider = "validVersions") public void testParseValidVersions(String vs, String ignore) { Version v = Version.parse(vs); assertEquals(v.toString(), vs); }
Example 15
Source File: VersionTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider = "invalidVersions", expectedExceptions = IllegalArgumentException.class ) public void testParseInvalidVersions(String vs, String ignore) { Version.parse(vs); }