3050N/A/*
3050N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3050N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3050N/A *
3050N/A * This code is free software; you can redistribute it and/or modify it
3050N/A * under the terms of the GNU General Public License version 2 only, as
3050N/A * published by the Free Software Foundation.
3050N/A *
3050N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3050N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3050N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3050N/A * version 2 for more details (a copy is included in the LICENSE file that
3050N/A * accompanied this code).
3050N/A *
3050N/A * You should have received a copy of the GNU General Public License version
3050N/A * 2 along with this work; if not, write to the Free Software Foundation,
3050N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3050N/A *
3050N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3050N/A * or visit www.oracle.com if you need additional information or have any
3050N/A * questions.
3050N/A */
3050N/A
3050N/A/*
3050N/A * @test
3050N/A * @bug 6987827
3050N/A * @summary security/util/Resources.java needs improvement
3050N/A */
3050N/A
3050N/A
3050N/Aimport java.lang.reflect.Method;
3050N/Aimport java.util.HashSet;
3050N/Aimport java.util.Set;
3050N/A
3050N/A/**
3050N/A * This test makes sure that the keys in resources files are using the new
3050N/A * format and there is no duplication.
3050N/A */
3050N/Apublic class NewNamesFormat {
3050N/A public static void main(String[] args) throws Exception {
3050N/A checkRes("sun.security.util.Resources");
3050N/A checkRes("sun.security.util.AuthResources");
3050N/A checkRes("sun.security.tools.JarSignerResources");
3050N/A }
3050N/A
3050N/A private static void checkRes(String resName) throws Exception {
3050N/A System.out.println("Checking " + resName + "...");
3050N/A Class clazz = Class.forName(resName);
3050N/A Method m = clazz.getMethod("getContents");
3050N/A Object[][] contents = (Object[][])m.invoke(clazz.newInstance());
3050N/A Set<String> keys = new HashSet<String>();
3050N/A for (Object[] pair: contents) {
3050N/A String key = (String)pair[0];
3050N/A if (keys.contains(key)) {
3050N/A System.out.println("Found dup: " + key);
3050N/A throw new Exception();
3050N/A }
3050N/A checkKey(key);
3050N/A keys.add(key);
3050N/A }
3050N/A }
3050N/A
3050N/A private static void checkKey(String key) throws Exception {
3050N/A for (char c: key.toCharArray()) {
3050N/A if (Character.isLetter(c) || Character.isDigit(c) ||
3050N/A c == '{' || c == '}' || c == '.') {
3050N/A // OK
3050N/A } else {
3050N/A System.out.println("Illegal char [" + c + "] in key: " + key);
3050N/A throw new Exception();
3050N/A }
3050N/A }
3050N/A }
3050N/A}