jdk/test/javax/crypto/sanity/CheckManifestForRelease.java
author wetmore
Tue, 23 Oct 2012 12:36:47 -0700
changeset 14316 f7665c887b97
permissions -rw-r--r--
7197071: Makefiles for various security providers aren't including the default manifest Reviewed-by: valeriep, mullan, katleman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14316
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
     1
/*
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
     4
 *
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
     8
 *
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    13
 * accompanied this code).
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    14
 *
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    18
 *
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    21
 * questions.
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    22
 */
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    23
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    24
/*
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    25
 * @test
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    26
 * @bug 7197071
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    27
 * @summary Makefiles for various security providers aren't including
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    28
 *          the default manifest.
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    29
 */
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    30
import java.net.*;
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    31
import java.io.*;
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    32
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    33
/**
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    34
 * When the Java specification version is incremented, all of the providers
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    35
 * must be recompiled with the proper implementation version to match.
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    36
 */
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    37
public class CheckManifestForRelease {
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    38
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    39
    /**
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    40
     * @param args the command line arguments
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    41
     */
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    42
    public static void main(String[] args) throws Exception {
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    43
        checkFileManifests();
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    44
    }
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    45
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    46
    /*
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    47
     * Iterate over the files of interest: JCE framework and providers
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    48
     */
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    49
    static private void checkFileManifests() throws Exception {
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    50
        System.out.println("=============");
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    51
        String libDirName = System.getProperty("java.home", ".") + "/lib";
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    52
        String extDirName = libDirName + "/ext";
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    53
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    54
        System.out.println("Checking Manifest in directory: \n    " +
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    55
            extDirName);
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    56
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    57
        /*
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    58
         * Current list of JCE providers, all of which currently live in
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    59
         * the extensions directory.  Add if more are created.
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    60
         */
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    61
        String[] providers = new String[]{
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    62
            "sunjce_provider.jar",
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    63
            "sunec.jar",
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    64
            "sunmscapi.jar",
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    65
            "sunpkcs11.jar",
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    66
            "ucrypto.jar"
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    67
        };
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    68
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    69
        checkManifest(libDirName, "jce.jar");
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    70
        for (String provider : providers) {
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    71
            checkManifest(extDirName, provider);
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    72
        }
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    73
        System.out.println("Passed.");
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    74
    }
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    75
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    76
    // Helper method to format the URL properly.
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    77
    static private String formatURL(String dir, String file) {
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    78
        return "jar:file:///" + dir + "/" + file + "!/";
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    79
    }
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    80
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    81
    static private String specVersion =
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    82
        System.getProperty("java.specification.version");
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    83
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    84
    /*
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    85
     * Test the root cause, which is that there were no manifest values
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    86
     * for many of the providers, and for those that had them, there was
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    87
     * no test to make sure that the impl version was appropriate for
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    88
     * the spec version.
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    89
     */
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    90
    static private void checkManifest(String dir, String file)
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    91
            throws Exception {
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    92
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    93
        System.out.println("Checking: " + file);
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    94
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    95
        String url = formatURL(dir, file);
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    96
        JarURLConnection urlc =
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    97
            (JarURLConnection) (new URL(url).openConnection());
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    98
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
    99
        String implVersion;
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   100
        try {
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   101
            implVersion = urlc.getManifest().getMainAttributes().getValue(
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   102
                "Implementation-Version");
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   103
        } catch (FileNotFoundException e) {
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   104
            /*
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   105
             * If the file doesn't exist (e.g. mscapi on solaris),
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   106
             * skip it. If there are other problems, fail out.
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   107
             */
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   108
            System.out.println("    " + file + " not found, skipping...");
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   109
            return;
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   110
        }
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   111
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   112
        if (implVersion == null) {
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   113
            throw new Exception(
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   114
                "Implementation-Version not found in Manifest");
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   115
        }
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   116
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   117
        if (!implVersion.startsWith(specVersion)) {
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   118
            throw new Exception(
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   119
                "Implementation-Version does not match " +
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   120
                "Specification-Version");
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   121
        }
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   122
    }
f7665c887b97 7197071: Makefiles for various security providers aren't including the default manifest
wetmore
parents:
diff changeset
   123
}