buildframework/helium/sf/java/checktools/src/com/nokia/helium/checktools/HeliumToolsCheckerMain.java
changeset 628 7c4a911dc066
parent 587 85df38eb4012
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
    12  * Contributors:
    12  * Contributors:
    13  *
    13  *
    14  * Description: 
    14  * Description: 
    15  *
    15  *
    16  */
    16  */
       
    17 
    17 package com.nokia.helium.checktools;
    18 package com.nokia.helium.checktools;
    18 
    19 
    19 import java.io.FileInputStream;
    20 import java.io.FileInputStream;
    20 import java.io.IOException;
    21 import java.io.IOException;
    21 import java.util.Properties;
    22 import java.util.Properties;
    22 
    23 
    23 /**
    24 /**
    24  * HeliumToolsCheckerMain is the main class which is used to trigger the
    25  * HeliumToolsCheckerMain is the main class which is used to trigger the checking of basic tools
    25  * checking of basic tools required by the Helium.
    26  * required by the Helium.
    26  * 
    27  * 
    27  * Note: HeliumToolsCheckerMain requires a '-config' parameter to be passed as
    28  * Note: HeliumToolsCheckerMain requires a '-config' parameter to be passed as the argument. The
    28  * the argument. The config parameter should be followed by a valid location of
    29  * config parameter should be followed by a valid location of the configuration file.
    29  * the configuration file.
       
    30  * 
    30  * 
    31  */
    31  */
    32 public final class HeliumToolsCheckerMain {
    32 public final class HeliumToolsCheckerMain {
    33 
    33 
    34     private Properties configuration;
    34     private Properties configuration;
    35     private CheckEngine checkEngine;
    35     private CheckEngine checkEngine;
    36 
    36 
    37     
       
    38     /**
    37     /**
    39      * Create an instance of HeliumToolsCheckerMain.
    38      * Create an instance of HeliumToolsCheckerMain.
    40      * 
    39      * 
    41      * @param configFile
    40      * @param configFile is the config file to read.
    42      *            is the config file to read.
       
    43      */
    41      */
    44     private HeliumToolsCheckerMain(String configFile) {
    42     private HeliumToolsCheckerMain(String configFile) {
    45         loadConfiguration(configFile);
    43         loadConfiguration(configFile);
    46         checkEngine = new CheckEngine(configuration);
    44         checkEngine = new CheckEngine(configuration);
    47     }
    45     }
    52      */
    50      */
    53     private void checkAnt() {
    51     private void checkAnt() {
    54         try {
    52         try {
    55             checkEngine.verifyAntVersion();
    53             checkEngine.verifyAntVersion();
    56         } catch (CheckToolException e) {
    54         } catch (CheckToolException e) {
    57             System.out.println("*** Error: " + e.getMessage());
    55             println("*** Error: " + e.getMessage());
    58         }
    56         }
    59     }
    57     }
    60 
    58 
    61     /**
    59     /**
    62      * Check python version.
    60      * Check python version.
    63      */
    61      */
    64     private void checkPython() {
    62     private void checkPython() {
    65         try {
    63         try {
    66             checkEngine.verifyPythonVersion();
    64             checkEngine.verifyPythonVersion();
    67         } catch (CheckToolException e) {
    65         } catch (CheckToolException e) {
    68             System.out.println("*** Error: " + e.getMessage());
    66             println("*** Error: " + e.getMessage());
    69         }
    67         }
    70     }
    68     }
    71 
    69 
    72     /**
    70     /**
    73      * Method to check whether the tool check failed or not.
    71      * Method to check whether the tool check failed or not.
    79     }
    77     }
    80 
    78 
    81     /**
    79     /**
    82      * Method loads the configuration details from the given file.
    80      * Method loads the configuration details from the given file.
    83      * 
    81      * 
    84      * @param configFile
    82      * @param configFile is the configuration file to be loaded.
    85      *            is the configuration file to be loaded.
       
    86      */
    83      */
    87     private void loadConfiguration(String configFile) {
    84     private void loadConfiguration(String configFile) {
    88         try {
    85         try {
    89             configuration = new Properties();
    86             configuration = new Properties();
    90             configuration.load(new FileInputStream(configFile));
    87             configuration.load(new FileInputStream(configFile));
    91         } catch (IOException th) {
    88         } catch (IOException th) {
    92             System.out.println("Error occured while loading config file: "
    89             println("Error occured while loading config file: " + configFile);
    93                     + configFile);
       
    94             System.exit(-1);
    90             System.exit(-1);
    95         }
    91         }
    96     }
    92     }
    97 
    93 
    98     /**
    94     /**
    99      * Main method to trigger tool check.
    95      * Main method to trigger tool check.
   100      * 
    96      * 
   101      * @param args
    97      * @param args contains command line arguments passed.
   102      *            contains command line arguments passed.
       
   103      * @throws Exception
    98      * @throws Exception
   104      */
    99      */
   105     public static void main(String[] args) throws Exception {
   100     public static void main(String[] args) throws Exception {
   106 
   101 
   107         String configFile = null;
   102         String configFile = null;
   108 
   103 
   109         // check for configuration file
   104         // check for configuration file
   110         if (args.length == 2 && args[0].equalsIgnoreCase("-config")) {
   105         if (args.length == 2 && args[0].equalsIgnoreCase("-config")) {
   111             if (args[1] == null
   106             if (args[1] == null || (args[1] != null && args[1].trim().isEmpty())) {
   112                     || (args[1] != null && args[1].trim().isEmpty())) {
   107                 println("*** Error: Parameter '-config' not set for HeliumToolsCheckerMain");
   113                 System.out.println("*** Error: Parameter '-config' not set for HeliumToolsCheckerMain");
       
   114                 System.exit(-1);
   108                 System.exit(-1);
   115             }
   109             }
   116             configFile = args[1];
   110             configFile = args[1];
   117         }
   111         }
   118 
   112 
   119         if (configFile != null) {
   113         if (configFile != null) {
   120             HeliumToolsCheckerMain checkerMain = new HeliumToolsCheckerMain(
   114             HeliumToolsCheckerMain checkerMain = new HeliumToolsCheckerMain(configFile);
   121                     configFile);
       
   122             checkerMain.checkAnt();
   115             checkerMain.checkAnt();
   123             checkerMain.checkPython();
   116             checkerMain.checkPython();
   124             if (checkerMain.checkFailed()) {
   117             if (checkerMain.checkFailed()) {
   125                 System.exit(-1);
   118                 System.exit(-1);
   126             }
   119             }
   127         } else {
   120         }
   128             System.out.println("*** Error: Missing '-config' argument for HeliumToolsCheckerMain");
   121         else {
   129             System.out
   122             println("*** Error: Missing '-config' argument for HeliumToolsCheckerMain");
   130                     .println("Usage: java [main-class-name] -config [location of configuration file]");
   123             println("Usage: java [main-class-name] -config [location of configuration file]");
   131             System.out
   124             println("Example: java com.nokia.helium.checktools.HeliumToolsCheckerMain -config \"config/helium.basic.tools.config\"");
   132                     .println("Example: java com.nokia.helium.checktools.HeliumToolsCheckerMain -config \"config/helium.basic.tools.config\"");
       
   133             System.exit(-1);
   125             System.exit(-1);
   134         }
   126         }
   135     }
   127     }
       
   128 
       
   129     @SuppressWarnings("PMD.SystemPrintln")
       
   130     public static void println(String text) {
       
   131         System.out.println(text);
       
   132     }
   136 }
   133 }