jdk/src/share/classes/com/sun/tools/extcheck/Main.java
changeset 1159 ef22d0ad63bf
parent 2 90ce3da70b43
child 5506 202f599c92aa
equal deleted inserted replaced
1158:34d64e750f8e 1159:ef22d0ad63bf
     1 /*
     1 /*
     2  * Copyright 1998 Sun Microsystems, Inc.  All Rights Reserved.
     2  * Copyright 1998-2008 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Sun designates this
     7  * published by the Free Software Foundation.  Sun designates this
    30 /**
    30 /**
    31  * Main program of extcheck
    31  * Main program of extcheck
    32  */
    32  */
    33 
    33 
    34 public final class Main {
    34 public final class Main {
    35 
    35     public static final String INSUFFICIENT = "Insufficient number of arguments";
       
    36     public static final String MISSING = "Missing <jar file> argument";
       
    37     public static final String DOES_NOT_EXIST = "Jarfile does not exist: ";
       
    38     public static final String EXTRA = "Extra command line argument: ";
    36 
    39 
    37     /**
    40     /**
    38      * Terminates with one of the following codes
    41      * Terminates with one of the following codes
    39      *  1 A newer (or same version) jar file is already installed
    42      *  1 A newer (or same version) jar file is already installed
    40      *  0 No newer jar file was found
    43      *  0 No newer jar file was found
    41      *  -1 An internal error occurred
    44      *  -1 An internal error occurred
    42      */
    45      */
    43     public static void main(String args[]){
    46     public static void main(String args[]) {
       
    47         try {
       
    48             realMain(args);
       
    49         } catch (Exception ex) {
       
    50             System.err.println(ex.getMessage());
       
    51             System.exit(-1);
       
    52         }
       
    53     }
    44 
    54 
    45         if (args.length < 1){
    55     public static void realMain(String[] args) throws Exception {
    46             System.err.println("Usage: extcheck [-verbose] <jar file>");
    56         if (args.length < 1) {
    47             System.exit(-1);
    57             usage(INSUFFICIENT);
    48         }
    58         }
    49         int argIndex = 0;
    59         int argIndex = 0;
    50         boolean verboseFlag = false;
    60         boolean verboseFlag = false;
    51         if (args[argIndex].equals("-verbose")){
    61         if (args[argIndex].equals("-verbose")) {
    52             verboseFlag = true;
    62             verboseFlag = true;
    53             argIndex++;
    63             argIndex++;
       
    64             if (argIndex >= args.length) {
       
    65                 usage(MISSING);
       
    66             }
    54         }
    67         }
    55         String jarName = args[argIndex];
    68         String jarName = args[argIndex];
    56         argIndex++;
    69         argIndex++;
    57         File jarFile = new File(jarName);
    70         File jarFile = new File(jarName);
    58         if (!jarFile.exists()){
    71         if (!jarFile.exists()){
    59             ExtCheck.error("Jarfile " + jarName + " does not exist");
    72             usage(DOES_NOT_EXIST + jarName);
    60         }
    73         }
    61         if (argIndex < args.length) {
    74         if (argIndex < args.length) {
    62             ExtCheck.error("Extra command line argument :"+args[argIndex]);
    75             usage(EXTRA + args[argIndex]);
    63         }
    76         }
    64         ExtCheck jt = ExtCheck.create(jarFile,verboseFlag);
    77         ExtCheck jt = ExtCheck.create(jarFile,verboseFlag);
    65         boolean result = jt.checkInstalledAgainstTarget();
    78         boolean result = jt.checkInstalledAgainstTarget();
    66         if (result) {
    79         if (result) {
    67             System.exit(0);
    80             System.exit(0);
    68         } else {
    81         } else {
    69             System.exit(1);
    82             System.exit(1);
    70         }
    83         }
    71 
       
    72     }
    84     }
    73 
    85 
       
    86     private static void usage(String msg) throws Exception {
       
    87         throw new Exception(msg + "\nUsage: extcheck [-verbose] <jar file>");
       
    88     }
    74 }
    89 }
       
    90