< prev index next >

test/sun/security/util/Resources/NewNamesFormat.java

Print this page
rev 17687 : 8148371: Remove policytool


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6987827
  27  * @modules java.base/sun.security.util
  28  *          java.base/sun.security.tools.keytool
  29  *          jdk.jartool/sun.security.tools.jarsigner
  30  *          jdk.policytool/sun.security.tools.policytool
  31  * @summary security/util/Resources.java needs improvement
  32  */
  33 
  34 
  35 import java.lang.reflect.Method;
  36 import java.util.HashSet;
  37 import java.util.Set;
  38 
  39 /**
  40  * This test makes sure that the keys in resources files are using the new
  41  * format and there is no duplication.
  42  */
  43 public class NewNamesFormat {
  44     public static void main(String[] args) throws Exception {
  45         checkRes("sun.security.util.Resources");
  46         checkRes("sun.security.util.AuthResources");
  47         checkRes("sun.security.tools.jarsigner.Resources");
  48         checkRes("sun.security.tools.keytool.Resources");
  49         checkRes("sun.security.tools.policytool.Resources");
  50     }
  51 
  52     private static void checkRes(String resName) throws Exception {
  53         System.out.println("Checking " + resName + "...");
  54         Class clazz = Class.forName(resName);
  55         Method m = clazz.getMethod("getContents");
  56         Object[][] contents = (Object[][])m.invoke(clazz.newInstance());
  57         Set<String> keys = new HashSet<String>();
  58         for (Object[] pair: contents) {
  59             String key = (String)pair[0];
  60             if (keys.contains(key)) {
  61                 System.out.println("Found dup: " + key);
  62                 throw new Exception();
  63             }
  64             checkKey(key);
  65             keys.add(key);
  66         }
  67     }
  68 
  69     private static void checkKey(String key) throws Exception {


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6987827
  27  * @modules java.base/sun.security.util
  28  *          java.base/sun.security.tools.keytool
  29  *          jdk.jartool/sun.security.tools.jarsigner

  30  * @summary security/util/Resources.java needs improvement
  31  */
  32 
  33 
  34 import java.lang.reflect.Method;
  35 import java.util.HashSet;
  36 import java.util.Set;
  37 
  38 /**
  39  * This test makes sure that the keys in resources files are using the new
  40  * format and there is no duplication.
  41  */
  42 public class NewNamesFormat {
  43     public static void main(String[] args) throws Exception {
  44         checkRes("sun.security.util.Resources");
  45         checkRes("sun.security.util.AuthResources");
  46         checkRes("sun.security.tools.jarsigner.Resources");
  47         checkRes("sun.security.tools.keytool.Resources");

  48     }
  49 
  50     private static void checkRes(String resName) throws Exception {
  51         System.out.println("Checking " + resName + "...");
  52         Class clazz = Class.forName(resName);
  53         Method m = clazz.getMethod("getContents");
  54         Object[][] contents = (Object[][])m.invoke(clazz.newInstance());
  55         Set<String> keys = new HashSet<String>();
  56         for (Object[] pair: contents) {
  57             String key = (String)pair[0];
  58             if (keys.contains(key)) {
  59                 System.out.println("Found dup: " + key);
  60                 throw new Exception();
  61             }
  62             checkKey(key);
  63             keys.add(key);
  64         }
  65     }
  66 
  67     private static void checkKey(String key) throws Exception {
< prev index next >