Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/crypto/sanity/CheckManifestForRelease.java
38839 views
/*1* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 719707126* @summary Makefiles for various security providers aren't including27* the default manifest.28*/29import java.net.*;30import java.io.*;3132/**33* When the Java specification version is incremented, all of the providers34* must be recompiled with the proper implementation version to match.35*/36public class CheckManifestForRelease {3738/**39* @param args the command line arguments40*/41public static void main(String[] args) throws Exception {42checkFileManifests();43}4445/*46* Iterate over the files of interest: JCE framework and providers47*/48static private void checkFileManifests() throws Exception {49System.out.println("=============");50String libDirName = System.getProperty("java.home", ".") + "/lib";51String extDirName = libDirName + "/ext";5253System.out.println("Checking Manifest in directory: \n " +54extDirName);5556/*57* Current list of JCE providers, all of which currently live in58* the extensions directory. Add if more are created.59*/60String[] providers = new String[]{61"sunjce_provider.jar",62"sunec.jar",63"sunmscapi.jar",64"sunpkcs11.jar",65"ucrypto.jar"66};6768checkManifest(libDirName, "jce.jar");69for (String provider : providers) {70checkManifest(extDirName, provider);71}72System.out.println("Passed.");73}7475// Helper method to format the URL properly.76static private String formatURL(String dir, String file) {77return "jar:file:///" + dir + "/" + file + "!/";78}7980static private String specVersion =81System.getProperty("java.specification.version");8283/*84* Test the root cause, which is that there were no manifest values85* for many of the providers, and for those that had them, there was86* no test to make sure that the impl version was appropriate for87* the spec version.88*/89static private void checkManifest(String dir, String file)90throws Exception {9192System.out.println("Checking: " + file);9394String url = formatURL(dir, file);95JarURLConnection urlc =96(JarURLConnection) (new URL(url).openConnection());9798String implVersion;99try {100implVersion = urlc.getManifest().getMainAttributes().getValue(101"Implementation-Version");102} catch (FileNotFoundException e) {103/*104* If the file doesn't exist (e.g. mscapi on solaris),105* skip it. If there are other problems, fail out.106*/107System.out.println(" " + file + " not found, skipping...");108return;109}110111if (implVersion == null) {112throw new Exception(113"Implementation-Version not found in Manifest");114}115116if (!implVersion.startsWith(specVersion)) {117throw new Exception(118"Implementation-Version does not match " +119"Specification-Version");120}121}122}123124125