changeset 13546:aba5be17a1e8

Move Version to ModuleDescriptor.Version
author alanb
date Thu, 30 Jul 2015 11:27:10 +0100
parents d766c19978ef
children 9d56b977df96
files src/java.base/share/classes/java/lang/StackTraceElement.java src/java.base/share/classes/java/lang/module/ModuleDescriptor.java src/java.base/share/classes/java/lang/module/ModulePath.java src/java.base/share/classes/java/lang/module/Version.java src/java.base/share/classes/java/lang/reflect/Module.java src/java.base/share/classes/jdk/internal/module/ClassFileAttributes.java src/java.base/share/classes/jdk/internal/module/ModuleInfoExtender.java src/java.base/share/classes/jdk/internal/module/ModuleInfoWriter.java src/jdk.jartool/share/classes/sun/tools/jar/GNUStyleOptions.java src/jdk.jartool/share/classes/sun/tools/jar/Main.java src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java test/jdk/jigsaw/module/ModuleDescriptorTest.java test/jdk/jigsaw/module/VersionTest.java
diffstat 13 files changed, 219 insertions(+), 247 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/StackTraceElement.java	Thu Jul 30 10:42:32 2015 +0100
+++ b/src/java.base/share/classes/java/lang/StackTraceElement.java	Thu Jul 30 11:27:10 2015 +0100
@@ -165,7 +165,7 @@
      *         point represented by this stack trace element; {@code null}
      *         if the module version is not available.
      * @since 1.9
-     * @see java.lang.module.Version
+     * @see java.lang.module.ModuleDescriptor.Version
      */
     public String getModuleVersion() {
         return moduleVersion;
--- a/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java	Thu Jul 30 10:42:32 2015 +0100
+++ b/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java	Thu Jul 30 11:27:10 2015 +0100
@@ -29,14 +29,16 @@
 import java.io.IOException;
 import java.io.UncheckedIOException;
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
-import java.util.Objects;
 import java.util.function.Supplier;
 import static java.util.Objects.*;
 
@@ -291,6 +293,209 @@
 
     }
 
+
+
+    /**
+     * Vaguely Debian-like version strings, for now.
+     * This will, eventually, change.
+     *
+     * @see <a href="http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version">Debian
+     * Policy Manual, Chapter 5: Control files and their fields<a>
+     *
+     * @see ModuleDescriptor#version()
+     * @since 1.9
+     */
+
+    public final static class Version
+        implements Comparable<Version>
+    {
+
+        private final String version;
+
+        // If Java had disjunctive types then we'd write List<Integer|String> here
+        //
+        private final List<Object> sequence;
+        private final List<Object> branch;
+
+        // Take a numeric token starting at position i
+        // Append it to the given list
+        // Return the index of the first character not taken
+        // Requires: s.charAt(i) is (decimal) numeric
+        //
+        private static int takeNumber(String s, int i, List<Object> acc) {
+            char c = s.charAt(i);
+            int d = (c - '0');
+            int n = s.length();
+            while (++i < n) {
+                c = s.charAt(i);
+                if (c >= '0' && c <= '9') {
+                    d = d * 10 + (c - '0');
+                    continue;
+                }
+                break;
+            }
+            acc.add(d);
+            return i;
+        }
+
+        // Take a string token starting at position i
+        // Append it to the given list
+        // Return the index of the first character not taken
+        // Requires: s.charAt(i) is not '.'
+        //
+        private static int takeString(String s, int i, List<Object> acc) {
+            int b = i;
+            int n = s.length();
+            while (++i < n) {
+                char c = s.charAt(i);
+                if (c != '.' && c != '-' && !(c >= '0' && c <= '9'))
+                    continue;
+                break;
+            }
+            acc.add(s.substring(b, i));
+            return i;
+        }
+
+        // Version syntax, for now: tok+ ( '-' tok+)?
+        // First token string is sequence, second is branch
+        // Tokens are delimited by '.', or by changes between alpha & numeric
+        // chars
+        // Numeric tokens are compared as decimal numbers
+        // Non-numeric tokens are compared lexicographically
+        // Tokens in branch may contain '-'
+        //
+        private Version(String v) {
+
+            if (v == null)
+                throw new IllegalArgumentException("Null version string");
+            int n = v.length();
+            if (n == 0)
+                throw new IllegalArgumentException("Empty version string");
+
+            int i = 0;
+            char c = v.charAt(i);
+            if (!(c >= '0' && c <= '9'))
+                throw new
+                        IllegalArgumentException(v
+                        + ": Version does not start"
+                        + " with a number");
+
+            List<Object> sequence = new ArrayList<>(4);
+            List<Object> branch = new ArrayList<>(2);
+
+            i = takeNumber(v, i, sequence);
+
+            while (i < n) {
+                c = v.charAt(i);
+                if (c == '.') {
+                    i++;
+                    continue;
+                }
+                if (c == '-') {
+                    i++;
+                    break;
+                }
+                if (c >= '0' && c <= '9')
+                    i = takeNumber(v, i, sequence);
+                else
+                    i = takeString(v, i, sequence);
+            }
+
+            if (c == '-' && i >= n)
+                throw new IllegalArgumentException(v + ": Empty branch");
+
+            while (i < n) {
+                c = v.charAt(i);
+                if (c >= '0' && c <= '9')
+                    i = takeNumber(v, i, branch);
+                else
+                    i = takeString(v, i, branch);
+                if (i >= n)
+                    break;
+                c = v.charAt(i);
+                if (c == '.') {
+                    i++;
+                    continue;
+                }
+            }
+
+            this.version = v;
+            this.sequence = sequence;
+            this.branch = branch;
+        }
+
+        /**
+         * Parses the given string as a version string.
+         *
+         * @throws IllegalArgumentException
+         *         If {@code v} is {@code null}, an empty string, or cannot be
+         *         parsed as a version string
+         */
+        public static Version parse(String v) {
+            return new Version(v);
+        }
+
+        @SuppressWarnings("unchecked")
+        private int cmp(Object o1, Object o2) {
+            return ((Comparable)o1).compareTo(o2);
+        }
+
+        private int compareTokens(List<Object> ts1, List<Object> ts2) {
+            int n = Math.min(ts1.size(), ts2.size());
+            for (int i = 0; i < n; i++) {
+                Object o1 = ts1.get(i);
+                Object o2 = ts2.get(i);
+                if (   (o1 instanceof Integer && o2 instanceof Integer)
+                        || (o1 instanceof String && o2 instanceof String)) {
+                    int c = cmp(o1, o2);
+                    if (c == 0)
+                        continue;
+                    return c;
+                }
+                // Types differ, so convert number to string form
+                int c = o1.toString().compareTo(o2.toString());
+                if (c == 0)
+                    continue;
+                return c;
+            }
+            List<Object> rest = ts1.size() > ts2.size() ? ts1 : ts2;
+            int e = rest.size();
+            for (int i = n; i < e; i++) {
+                Object o = rest.get(i);
+                if (o instanceof Integer && ((Integer)o) == 0)
+                    continue;
+                return ts1.size() - ts2.size();
+            }
+            return 0;
+        }
+
+        @Override
+        public int compareTo(Version that) {
+            int c = compareTokens(this.sequence, that.sequence);
+            if (c != 0)
+                return c;
+            return compareTokens(this.branch, that.branch);
+        }
+
+        @Override
+        public boolean equals(Object ob) {
+            if (!(ob instanceof Version))
+                return false;
+            return compareTo((Version)ob) == 0;
+        }
+
+        @Override
+        public int hashCode() {
+            return version.hashCode();
+        }
+
+        @Override
+        public String toString() {
+            return version;
+        }
+
+    }
+
 
 
     // From module declarations
--- a/src/java.base/share/classes/java/lang/module/ModulePath.java	Thu Jul 30 10:42:32 2015 +0100
+++ b/src/java.base/share/classes/java/lang/module/ModulePath.java	Thu Jul 30 11:27:10 2015 +0100
@@ -311,7 +311,7 @@
             // attempt to parse the tail as a version string
             try {
                 String tail = mn.substring(start+1);
-                Version.parse(tail);
+                ModuleDescriptor.Version.parse(tail);
                 vs = tail;
             } catch (IllegalArgumentException ignore) { }
 
--- a/src/java.base/share/classes/java/lang/module/Version.java	Thu Jul 30 10:42:32 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,233 +0,0 @@
-/*
- * Copyright (c) 2009, 2013 Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package java.lang.module;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Vaguely Debian-like version strings, for now.
- * This will, eventually, change.
- *
- * @see <a href="http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version">Debian
- * Policy Manual, Chapter 5: Control files and their fields<a>
- *
- * @since 1.9
- */
-
-public final class Version
-    implements Comparable<Version>
-{
-
-    private final String version;
-
-    // If Java had disjunctive types then we'd write List<Integer|String> here
-    //
-    private final List<Object> sequence;
-    private final List<Object> branch;
-
-    // Take a numeric token starting at position i
-    // Append it to the given list
-    // Return the index of the first character not taken
-    // Requires: s.charAt(i) is (decimal) numeric
-    //
-    private static int takeNumber(String s, int i, List<Object> acc) {
-        char c = s.charAt(i);
-        int d = (c - '0');
-        int n = s.length();
-        while (++i < n) {
-            c = s.charAt(i);
-            if (c >= '0' && c <= '9') {
-                d = d * 10 + (c - '0');
-                continue;
-            }
-            break;
-        }
-        acc.add(d);
-        return i;
-    }
-
-    // Take a string token starting at position i
-    // Append it to the given list
-    // Return the index of the first character not taken
-    // Requires: s.charAt(i) is not '.'
-    //
-    private static int takeString(String s, int i, List<Object> acc) {
-        int b = i;
-        int n = s.length();
-        while (++i < n) {
-            char c = s.charAt(i);
-            if (c != '.' && c != '-' && !(c >= '0' && c <= '9'))
-                continue;
-            break;
-        }
-        acc.add(s.substring(b, i));
-        return i;
-    }
-
-    // Version syntax, for now: tok+ ( '-' tok+)?
-    // First token string is sequence, second is branch
-    // Tokens are delimited by '.', or by changes between alpha & numeric chars
-    // Numeric tokens are compared as decimal numbers
-    // Non-numeric tokens are compared lexicographically
-    // Tokens in branch may contain '-'
-    //
-    private Version(String v) {
-
-        if (v == null)
-            throw new IllegalArgumentException("Null version string");
-        int n = v.length();
-        if (n == 0)
-            throw new IllegalArgumentException("Empty version string");
-
-        int i = 0;
-        char c = v.charAt(i);
-        if (!(c >= '0' && c <= '9'))
-            throw new
-                IllegalArgumentException(v
-                                         + ": Version does not start"
-                                         + " with a number");
-
-        List<Object> sequence = new ArrayList<>(4);
-        List<Object> branch = new ArrayList<>(2);
-
-        i = takeNumber(v, i, sequence);
-
-        while (i < n) {
-            c = v.charAt(i);
-            if (c == '.') {
-                i++;
-                continue;
-            }
-            if (c == '-') {
-                i++;
-                break;
-            }
-            if (c >= '0' && c <= '9')
-                i = takeNumber(v, i, sequence);
-            else
-                i = takeString(v, i, sequence);
-        }
-
-        if (c == '-' && i >= n)
-            throw new IllegalArgumentException(v + ": Empty branch");
-
-        while (i < n) {
-            c = v.charAt(i);
-            if (c >= '0' && c <= '9')
-                i = takeNumber(v, i, branch);
-            else
-                i = takeString(v, i, branch);
-            if (i >= n)
-                break;
-            c = v.charAt(i);
-            if (c == '.') {
-                i++;
-                continue;
-            }
-        }
-
-        this.version = v;
-        this.sequence = sequence;
-        this.branch = branch;
-    }
-
-    /**
-     * Parses the given string as a version string.
-     *
-     * @throws IllegalArgumentException
-     *         If {@code v} is {@code null}, an empty string, or cannot be
-     *         parsed as a version string
-     */
-    public static Version parse(String v) {
-        return new Version(v);
-    }
-
-    @SuppressWarnings("unchecked")
-    private int cmp(Object o1, Object o2) {
-        return ((Comparable)o1).compareTo(o2);
-    }
-
-    private int compareTokens(List<Object> ts1, List<Object> ts2) {
-        int n = Math.min(ts1.size(), ts2.size());
-        for (int i = 0; i < n; i++) {
-            Object o1 = ts1.get(i);
-            Object o2 = ts2.get(i);
-            if (   (o1 instanceof Integer && o2 instanceof Integer)
-                || (o1 instanceof String && o2 instanceof String)) {
-                int c = cmp(o1, o2);
-                if (c == 0)
-                    continue;
-                return c;
-            }
-            // Types differ, so convert number to string form
-            int c = o1.toString().compareTo(o2.toString());
-            if (c == 0)
-                continue;
-            return c;
-        }
-        List<Object> rest = ts1.size() > ts2.size() ? ts1 : ts2;
-        int e = rest.size();
-        for (int i = n; i < e; i++) {
-            Object o = rest.get(i);
-            if (o instanceof Integer && ((Integer)o) == 0)
-                continue;
-            return ts1.size() - ts2.size();
-        }
-        return 0;
-    }
-
-    @Override
-    public int compareTo(Version that) {
-        int c = compareTokens(this.sequence, that.sequence);
-        if (c != 0)
-            return c;
-        return compareTokens(this.branch, that.branch);
-    }
-
-    // needed?
-    String toDebugString() {
-        return "v" + sequence + "-" + branch;
-    }
-
-    @Override
-    public boolean equals(Object ob) {
-        if (!(ob instanceof Version))
-            return false;
-        return compareTo((Version)ob) == 0;
-    }
-
-    @Override
-    public int hashCode() {
-        return version.hashCode();
-    }
-
-    @Override
-    public String toString() {
-        return version;
-    }
-
-}
--- a/src/java.base/share/classes/java/lang/reflect/Module.java	Thu Jul 30 10:42:32 2015 +0100
+++ b/src/java.base/share/classes/java/lang/reflect/Module.java	Thu Jul 30 11:27:10 2015 +0100
@@ -34,7 +34,7 @@
 import java.lang.module.ModuleDescriptor;
 import java.lang.module.ModuleDescriptor.Exports;
 import java.lang.module.ModuleDescriptor.Provides;
-import java.lang.module.Version;
+import java.lang.module.ModuleDescriptor.Version;
 import java.net.URI;
 import java.net.URL;
 import java.util.Collections;
--- a/src/java.base/share/classes/jdk/internal/module/ClassFileAttributes.java	Thu Jul 30 10:42:32 2015 +0100
+++ b/src/java.base/share/classes/jdk/internal/module/ClassFileAttributes.java	Thu Jul 30 11:27:10 2015 +0100
@@ -30,7 +30,7 @@
 import java.lang.module.ModuleDescriptor.Requires.Modifier;
 import java.lang.module.ModuleDescriptor.Exports;
 import java.lang.module.ModuleDescriptor.Provides;
-import java.lang.module.Version;
+import java.lang.module.ModuleDescriptor.Version;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
--- a/src/java.base/share/classes/jdk/internal/module/ModuleInfoExtender.java	Thu Jul 30 10:42:32 2015 +0100
+++ b/src/java.base/share/classes/jdk/internal/module/ModuleInfoExtender.java	Thu Jul 30 11:27:10 2015 +0100
@@ -28,7 +28,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.lang.module.Version;
+import java.lang.module.ModuleDescriptor.Version;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
--- a/src/java.base/share/classes/jdk/internal/module/ModuleInfoWriter.java	Thu Jul 30 10:42:32 2015 +0100
+++ b/src/java.base/share/classes/jdk/internal/module/ModuleInfoWriter.java	Thu Jul 30 11:27:10 2015 +0100
@@ -27,7 +27,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.lang.module.ModuleDescriptor;
-import java.lang.module.Version;
+import java.lang.module.ModuleDescriptor.Version;
 import java.nio.ByteBuffer;
 import java.util.Optional;
 
--- a/src/jdk.jartool/share/classes/sun/tools/jar/GNUStyleOptions.java	Thu Jul 30 10:42:32 2015 +0100
+++ b/src/jdk.jartool/share/classes/sun/tools/jar/GNUStyleOptions.java	Thu Jul 30 11:27:10 2015 +0100
@@ -28,7 +28,7 @@
 import java.io.File;
 import java.io.PrintStream;
 import java.lang.module.ModuleFinder;
-import java.lang.module.Version;
+import java.lang.module.ModuleDescriptor.Version;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.regex.Pattern;
--- a/src/jdk.jartool/share/classes/sun/tools/jar/Main.java	Thu Jul 30 10:42:32 2015 +0100
+++ b/src/jdk.jartool/share/classes/sun/tools/jar/Main.java	Thu Jul 30 11:27:10 2015 +0100
@@ -27,9 +27,9 @@
 
 import java.io.*;
 import java.lang.module.ModuleDescriptor;
+import java.lang.module.ModuleDescriptor.Version;
 import java.lang.module.ModuleFinder;
 import java.lang.module.ModuleReference;
-import java.lang.module.Version;
 import java.net.URI;
 import java.nio.file.Path;
 import java.nio.file.Files;
--- a/src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java	Thu Jul 30 10:42:32 2015 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java	Thu Jul 30 11:27:10 2015 +0100
@@ -37,7 +37,7 @@
 import java.lang.module.ModuleFinder;
 import java.lang.module.ModuleDescriptor.Requires;
 import java.lang.module.ModuleDescriptor;
-import java.lang.module.Version;
+import java.lang.module.ModuleDescriptor.Version;
 import java.lang.reflect.InvocationTargetException;
 import java.net.URI;
 import java.nio.file.FileVisitResult;
--- a/test/jdk/jigsaw/module/ModuleDescriptorTest.java	Thu Jul 30 10:42:32 2015 +0100
+++ b/test/jdk/jigsaw/module/ModuleDescriptorTest.java	Thu Jul 30 11:27:10 2015 +0100
@@ -36,7 +36,7 @@
 import java.lang.module.ModuleDescriptor.Requires;
 import java.lang.module.ModuleDescriptor.Provides;
 import java.lang.module.ModuleDescriptor.Requires.Modifier;
-import java.lang.module.Version;
+import java.lang.module.ModuleDescriptor.Version;
 import java.lang.reflect.Module;
 import java.nio.ByteBuffer;
 import java.util.Collections;
--- a/test/jdk/jigsaw/module/VersionTest.java	Thu Jul 30 10:42:32 2015 +0100
+++ b/test/jdk/jigsaw/module/VersionTest.java	Thu Jul 30 11:27:10 2015 +0100
@@ -24,11 +24,11 @@
 /**
  * @test
  * @run testng VersionTest
- * @summary Basic tests for java.lang.module.Version. The tests will be
- *   extended once Version is specifed.
+ * @summary Basic tests for java.lang.module.ModuleDescriptor.Version.
+ *   The test will be extended once Version is specified.
  */
 
-import java.lang.module.Version;
+import java.lang.module.ModuleDescriptor.Version;
 
 import org.testng.annotations.Test;
 import org.testng.annotations.DataProvider;