jdk/src/java.base/share/classes/sun/misc/ExtensionInfo.java
author chegar
Wed, 03 Dec 2014 14:22:58 +0000
changeset 27565 729f9700483a
parent 25859 3317bb8137f4
child 30655 d83f50188ca9
permissions -rw-r--r--
8049367: Modular Run-Time Images Reviewed-by: chegar, dfuchs, ihse, joehw, mullan, psandoz, wetmore Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, bradford.wetmore@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, james.laskey@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com, sundararajan.athijegannathan@oracle.com
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
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * public static values returned by the isCompatible method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static final int COMPATIBLE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static final int REQUIRE_SPECIFICATION_UPGRADE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static final int REQUIRE_IMPLEMENTATION_UPGRADE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static final int REQUIRE_VENDOR_SWITCH = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public static final int INCOMPATIBLE = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * attributes fully describer an extension. The underlying described
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * extension may be installed and requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public String title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public String specVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public String specVendor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public String implementationVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public String vendor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public String vendorId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public String url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // For I18N support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static final ResourceBundle rb =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        ResourceBundle.getBundle("sun.misc.resources.Messages");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Create a new uninitialized extension information object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public ExtensionInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Create and initialize an extension information object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * The initialization uses the attributes passed as being
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * the content of a manifest file to load the extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * information from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Since manifest file may contain information on several
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * extension they may depend on, the extension key parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * is prepanded to the attribute name to make the key used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * to retrieve the attribute from the manifest file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param extensionKey unique extension key in the manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param attr Attributes of a manifest file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public ExtensionInfo(String extensionKey, Attributes attr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        throws NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        String s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (extensionKey!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            s = extensionKey + "-";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            s ="";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        String attrKey = s + Name.EXTENSION_NAME.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        name = attr.getValue(attrKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if (name != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            name = name.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        attrKey = s + Name.SPECIFICATION_TITLE.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        title = attr.getValue(attrKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (title != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            title = title.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        attrKey = s + Name.SPECIFICATION_VERSION.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        specVersion = attr.getValue(attrKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if (specVersion != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            specVersion = specVersion.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        attrKey = s + Name.SPECIFICATION_VENDOR.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        specVendor = attr.getValue(attrKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (specVendor != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            specVendor = specVendor.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        attrKey = s + Name.IMPLEMENTATION_VERSION.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        implementationVersion = attr.getValue(attrKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (implementationVersion != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            implementationVersion = implementationVersion.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        attrKey = s + Name.IMPLEMENTATION_VENDOR.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        vendor = attr.getValue(attrKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (vendor != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            vendor = vendor.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        attrKey = s + Name.IMPLEMENTATION_VENDOR_ID.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        vendorId = attr.getValue(attrKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (vendorId != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            vendorId = vendorId.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        attrKey =s + Name.IMPLEMENTATION_URL.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        url = attr.getValue(attrKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (url != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            url = url.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @return true if the extension described by this extension information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * is compatible with the extension described by the extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * information passed as a parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param the requested extension information to compare to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public int isCompatibleWith(ExtensionInfo ei) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if (name == null || ei.name == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            return INCOMPATIBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (name.compareTo(ei.name)==0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            // is this true, if not spec version is specified, we consider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            // the value as being "any".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            if (specVersion == null || ei.specVersion == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                return COMPATIBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            int version = compareExtensionVersion(specVersion, ei.specVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if (version<0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                // this extension specification is "older"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                if (vendorId != null && ei.vendorId !=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    if (vendorId.compareTo(ei.vendorId)!=0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                        return REQUIRE_VENDOR_SWITCH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                return REQUIRE_SPECIFICATION_UPGRADE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                // the extension spec is compatible, let's look at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                // implementation attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                if (vendorId != null && ei.vendorId != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    // They care who provides the extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    if (vendorId.compareTo(ei.vendorId)!=0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                        // They want to use another vendor implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                        return REQUIRE_VENDOR_SWITCH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                        // Vendor matches, let's see the implementation version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                        if (implementationVersion != null && ei.implementationVersion != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                            // they care about the implementation version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                            version = compareExtensionVersion(implementationVersion, ei.implementationVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                            if (version<0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                // This extension is an older implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                                return REQUIRE_IMPLEMENTATION_UPGRADE;
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
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                // All othe cases, we consider the extensions to be compatible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                return COMPATIBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return INCOMPATIBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * helper method to print sensible information on the undelying described
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return "Extension : title(" + title + "), name(" + name + "), spec vendor(" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            specVendor + "), spec version(" + specVersion + "), impl vendor(" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            vendor + "), impl vendor id(" + vendorId + "), impl version(" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            implementationVersion + "), impl url(" + url + ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * helper method to compare two versions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * version are in the x.y.z.t pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param source version to compare to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param target version used to compare against
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @return < 0 if source < version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *         > 0 if source > version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *         = 0 if source = version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    private int compareExtensionVersion(String source, String target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        throws NumberFormatException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        source = source.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        target = target.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        return strictCompareExtensionVersion(source, target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * helper method to compare two versions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * version are in the x.y.z.t pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @param source version to compare to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @param target version used to compare against
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @return < 0 if source < version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *         > 0 if source > version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *         = 0 if source = version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    private int strictCompareExtensionVersion(String source, String target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        throws NumberFormatException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (source.equals(target))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        StringTokenizer stk = new StringTokenizer(source, ".,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        StringTokenizer ttk = new StringTokenizer(target, ".,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        // Compare number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        int n = 0, m = 0, result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        // Convert token into meaning number for comparision
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (stk.hasMoreTokens())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            n = convertToken(stk.nextToken().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        // Convert token into meaning number for comparision
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if (ttk.hasMoreTokens())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            m = convertToken(ttk.nextToken().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if (n > m)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        else if (m > n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            // Look for index of "." in the string
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 5506
diff changeset
   278
            int sIdx = source.indexOf('.');
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 5506
diff changeset
   279
            int tIdx = target.indexOf('.');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            if (sIdx == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                sIdx = source.length() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            if (tIdx == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                tIdx = target.length() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            return strictCompareExtensionVersion(source.substring(sIdx + 1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                                                 target.substring(tIdx + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    private int convertToken(String token)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (token == null || token.equals(""))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        int charValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        int charVersion = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        int patchVersion = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        int strLength = token.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        int endIndex = strLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        char lastChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        Object[] args = {name};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        MessageFormat mf = new MessageFormat(rb.getString("optpkg.versionerror"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        String versionError = mf.format(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        // Look for "-" for pre-release
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 5506
diff changeset
   309
        int prIndex = token.indexOf('-');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        // Look for "_" for patch release
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 5506
diff changeset
   312
        int patchIndex = token.indexOf('_');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (prIndex == -1 && patchIndex == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            // This is a FCS release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                return Integer.parseInt(token) * 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                System.out.println(versionError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        else if (patchIndex != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            // This is a patch (update) release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            int prversion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                // Obtain the version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                prversion = Integer.parseInt(token.substring(0, patchIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                // Check to see if the patch version is in the n.n.n_nnl format (special release)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                lastChar = token.charAt(strLength-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                if (Character.isLetter(lastChar)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    // letters a-z have values from 10-35
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    charValue = Character.getNumericValue(lastChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    endIndex = strLength-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    // Obtain the patch version id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    patchVersion = Integer.parseInt(token.substring(patchIndex+1, endIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    if (charValue >= Character.getNumericValue('a') && charValue <= Character.getNumericValue('z')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                        // This is a special release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                        charVersion = (patchVersion * 100) + charValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                        // character is not a a-z letter, ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                        charVersion = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                        System.out.println(versionError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    // This is a regular update release. Obtain the patch version id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                    patchVersion = Integer.parseInt(token.substring(patchIndex+1, endIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                System.out.println(versionError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            return prversion * 100 + (patchVersion + charVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            //This is a milestone release, either a early access, alpha, beta, or RC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            // Obtain the version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            int mrversion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                mrversion = Integer.parseInt(token.substring(0, prIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                System.out.println(versionError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            // Obtain the patch version string, including the milestone + version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            String prString = token.substring(prIndex + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            // Milestone version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            String msVersion = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            int delta = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            if (prString.indexOf("ea") != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                msVersion = prString.substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                delta = 50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            else if (prString.indexOf("alpha") != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                msVersion = prString.substring(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                delta = 40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            else if (prString.indexOf("beta") != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                msVersion = prString.substring(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                delta = 30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            else if (prString.indexOf("rc") != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                msVersion = prString.substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                delta = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            if (msVersion == null || msVersion.equals(""))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                // No version after the milestone, assume 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                return mrversion * 100 - delta ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                // Convert the milestone version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    return mrversion * 100 - delta + Integer.parseInt(msVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    System.out.println(versionError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
}