jdk/src/java.base/share/classes/sun/misc/ExtensionInfo.java
author avstepan
Tue, 19 May 2015 16:04:14 +0400
changeset 30655 d83f50188ca9
parent 27565 729f9700483a
permissions -rw-r--r--
8080422: some docs cleanup for core libs Summary: some docs cleanup Reviewed-by: rriggs, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.misc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.jar.Attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.jar.Attributes.Name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.MissingResourceException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.text.MessageFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.lang.Character.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * This class holds all necessary information to install or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * upgrade a extension on the user's disk
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    41
 * @deprecated this class will be removed in a future release.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author  Jerome Dochez
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    44
@Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class ExtensionInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * public static values returned by the isCompatible method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static final int COMPATIBLE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static final int REQUIRE_SPECIFICATION_UPGRADE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static final int REQUIRE_IMPLEMENTATION_UPGRADE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static final int REQUIRE_VENDOR_SWITCH = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static final int INCOMPATIBLE = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * attributes fully describer an extension. The underlying described
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * extension may be installed and requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public String title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public String specVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public String specVendor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public String implementationVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public String vendor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public String vendorId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public String url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    // For I18N support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static final ResourceBundle rb =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        ResourceBundle.getBundle("sun.misc.resources.Messages");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Create a new uninitialized extension information object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public ExtensionInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Create and initialize an extension information object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * The initialization uses the attributes passed as being
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * the content of a manifest file to load the extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * information from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Since manifest file may contain information on several
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * extension they may depend on, the extension key parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * is prepanded to the attribute name to make the key used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * to retrieve the attribute from the manifest file
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
    89
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param extensionKey unique extension key in the manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param attr Attributes of a manifest file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public ExtensionInfo(String extensionKey, Attributes attr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        throws NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        String s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        if (extensionKey!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            s = extensionKey + "-";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            s ="";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        String attrKey = s + Name.EXTENSION_NAME.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        name = attr.getValue(attrKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (name != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            name = name.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        attrKey = s + Name.SPECIFICATION_TITLE.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        title = attr.getValue(attrKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (title != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            title = title.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        attrKey = s + Name.SPECIFICATION_VERSION.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        specVersion = attr.getValue(attrKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (specVersion != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            specVersion = specVersion.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        attrKey = s + Name.SPECIFICATION_VENDOR.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        specVendor = attr.getValue(attrKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (specVendor != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            specVendor = specVendor.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        attrKey = s + Name.IMPLEMENTATION_VERSION.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        implementationVersion = attr.getValue(attrKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (implementationVersion != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            implementationVersion = implementationVersion.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        attrKey = s + Name.IMPLEMENTATION_VENDOR.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        vendor = attr.getValue(attrKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (vendor != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            vendor = vendor.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        attrKey = s + Name.IMPLEMENTATION_VENDOR_ID.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        vendorId = attr.getValue(attrKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (vendorId != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            vendorId = vendorId.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        attrKey =s + Name.IMPLEMENTATION_URL.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        url = attr.getValue(attrKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (url != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            url = url.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @return true if the extension described by this extension information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * is compatible with the extension described by the extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * information passed as a parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
   149
     * @param ei the requested extension information to compare to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public int isCompatibleWith(ExtensionInfo ei) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (name == null || ei.name == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            return INCOMPATIBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if (name.compareTo(ei.name)==0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            // is this true, if not spec version is specified, we consider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            // the value as being "any".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            if (specVersion == null || ei.specVersion == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                return COMPATIBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            int version = compareExtensionVersion(specVersion, ei.specVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            if (version<0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                // this extension specification is "older"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                if (vendorId != null && ei.vendorId !=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    if (vendorId.compareTo(ei.vendorId)!=0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                        return REQUIRE_VENDOR_SWITCH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                return REQUIRE_SPECIFICATION_UPGRADE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                // the extension spec is compatible, let's look at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                // implementation attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                if (vendorId != null && ei.vendorId != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    // They care who provides the extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    if (vendorId.compareTo(ei.vendorId)!=0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                        // They want to use another vendor implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                        return REQUIRE_VENDOR_SWITCH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                        // Vendor matches, let's see the implementation version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                        if (implementationVersion != null && ei.implementationVersion != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                            // they care about the implementation version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                            version = compareExtensionVersion(implementationVersion, ei.implementationVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                            if (version<0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                // This extension is an older implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                return REQUIRE_IMPLEMENTATION_UPGRADE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                // All othe cases, we consider the extensions to be compatible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                return COMPATIBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return INCOMPATIBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * helper method to print sensible information on the undelying described
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return "Extension : title(" + title + "), name(" + name + "), spec vendor(" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            specVendor + "), spec version(" + specVersion + "), impl vendor(" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            vendor + "), impl vendor id(" + vendorId + "), impl version(" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            implementationVersion + "), impl url(" + url + ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * helper method to compare two versions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * version are in the x.y.z.t pattern.
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
   211
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param source version to compare to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @param target version used to compare against
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
   214
     * @return <pre>{@code
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
   215
     *   < 0 if source < version
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
   216
     *   > 0 if source > version
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
   217
     *   = 0 if source = version}</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    private int compareExtensionVersion(String source, String target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        throws NumberFormatException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        source = source.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        target = target.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        return strictCompareExtensionVersion(source, target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * helper method to compare two versions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * version are in the x.y.z.t pattern.
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
   232
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param source version to compare to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @param target version used to compare against
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
   235
     * @return <pre>{@code
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
   236
     *   < 0 if source < version
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
   237
     *   > 0 if source > version
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
   238
     *   = 0 if source = version}</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    private int strictCompareExtensionVersion(String source, String target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        throws NumberFormatException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (source.equals(target))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        StringTokenizer stk = new StringTokenizer(source, ".,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        StringTokenizer ttk = new StringTokenizer(target, ".,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        // Compare number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        int n = 0, m = 0, result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        // Convert token into meaning number for comparision
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if (stk.hasMoreTokens())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            n = convertToken(stk.nextToken().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        // Convert token into meaning number for comparision
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (ttk.hasMoreTokens())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            m = convertToken(ttk.nextToken().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if (n > m)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        else if (m > n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            // Look for index of "." in the string
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 5506
diff changeset
   267
            int sIdx = source.indexOf('.');
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 5506
diff changeset
   268
            int tIdx = target.indexOf('.');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            if (sIdx == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                sIdx = source.length() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            if (tIdx == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                tIdx = target.length() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            return strictCompareExtensionVersion(source.substring(sIdx + 1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                                                 target.substring(tIdx + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    private int convertToken(String token)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (token == null || token.equals(""))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        int charValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        int charVersion = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        int patchVersion = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        int strLength = token.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        int endIndex = strLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        char lastChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        Object[] args = {name};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        MessageFormat mf = new MessageFormat(rb.getString("optpkg.versionerror"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        String versionError = mf.format(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        // Look for "-" for pre-release
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 5506
diff changeset
   298
        int prIndex = token.indexOf('-');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        // Look for "_" for patch release
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 5506
diff changeset
   301
        int patchIndex = token.indexOf('_');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if (prIndex == -1 && patchIndex == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            // This is a FCS release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                return Integer.parseInt(token) * 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                System.out.println(versionError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        else if (patchIndex != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            // This is a patch (update) release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            int prversion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                // Obtain the version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                prversion = Integer.parseInt(token.substring(0, patchIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                // Check to see if the patch version is in the n.n.n_nnl format (special release)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                lastChar = token.charAt(strLength-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                if (Character.isLetter(lastChar)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    // letters a-z have values from 10-35
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    charValue = Character.getNumericValue(lastChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    endIndex = strLength-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                    // Obtain the patch version id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    patchVersion = Integer.parseInt(token.substring(patchIndex+1, endIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    if (charValue >= Character.getNumericValue('a') && charValue <= Character.getNumericValue('z')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                        // This is a special release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                        charVersion = (patchVersion * 100) + charValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                        // character is not a a-z letter, ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                        charVersion = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                        System.out.println(versionError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    // This is a regular update release. Obtain the patch version id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                    patchVersion = Integer.parseInt(token.substring(patchIndex+1, endIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                System.out.println(versionError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            return prversion * 100 + (patchVersion + charVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            //This is a milestone release, either a early access, alpha, beta, or RC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            // Obtain the version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            int mrversion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                mrversion = Integer.parseInt(token.substring(0, prIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                System.out.println(versionError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            // Obtain the patch version string, including the milestone + version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            String prString = token.substring(prIndex + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            // Milestone version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            String msVersion = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            int delta = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            if (prString.indexOf("ea") != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                msVersion = prString.substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                delta = 50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            else if (prString.indexOf("alpha") != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                msVersion = prString.substring(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                delta = 40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            else if (prString.indexOf("beta") != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                msVersion = prString.substring(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                delta = 30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            else if (prString.indexOf("rc") != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                msVersion = prString.substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                delta = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            if (msVersion == null || msVersion.equals(""))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                // No version after the milestone, assume 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                return mrversion * 100 - delta ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                // Convert the milestone version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                    return mrversion * 100 - delta + Integer.parseInt(msVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    System.out.println(versionError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
}