587
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
628
|
17 |
|
587
|
18 |
package com.nokia.helium.checktools;
|
|
19 |
|
|
20 |
import java.io.FileInputStream;
|
|
21 |
import java.io.IOException;
|
|
22 |
import java.util.Properties;
|
|
23 |
|
|
24 |
/**
|
628
|
25 |
* HeliumToolsCheckerMain is the main class which is used to trigger the checking of basic tools
|
|
26 |
* required by the Helium.
|
587
|
27 |
*
|
628
|
28 |
* Note: HeliumToolsCheckerMain requires a '-config' parameter to be passed as the argument. The
|
|
29 |
* config parameter should be followed by a valid location of the configuration file.
|
587
|
30 |
*
|
|
31 |
*/
|
|
32 |
public final class HeliumToolsCheckerMain {
|
|
33 |
|
|
34 |
private Properties configuration;
|
|
35 |
private CheckEngine checkEngine;
|
|
36 |
|
|
37 |
/**
|
|
38 |
* Create an instance of HeliumToolsCheckerMain.
|
|
39 |
*
|
628
|
40 |
* @param configFile is the config file to read.
|
587
|
41 |
*/
|
|
42 |
private HeliumToolsCheckerMain(String configFile) {
|
|
43 |
loadConfiguration(configFile);
|
|
44 |
checkEngine = new CheckEngine(configuration);
|
|
45 |
}
|
|
46 |
|
|
47 |
/**
|
|
48 |
* Check ant version.
|
|
49 |
*
|
|
50 |
*/
|
|
51 |
private void checkAnt() {
|
|
52 |
try {
|
|
53 |
checkEngine.verifyAntVersion();
|
|
54 |
} catch (CheckToolException e) {
|
628
|
55 |
println("*** Error: " + e.getMessage());
|
587
|
56 |
}
|
|
57 |
}
|
|
58 |
|
|
59 |
/**
|
|
60 |
* Check python version.
|
|
61 |
*/
|
|
62 |
private void checkPython() {
|
|
63 |
try {
|
|
64 |
checkEngine.verifyPythonVersion();
|
|
65 |
} catch (CheckToolException e) {
|
628
|
66 |
println("*** Error: " + e.getMessage());
|
587
|
67 |
}
|
|
68 |
}
|
|
69 |
|
|
70 |
/**
|
|
71 |
* Method to check whether the tool check failed or not.
|
|
72 |
*
|
|
73 |
* @return true, if the tool check failed with errors; otherwise false.
|
|
74 |
*/
|
|
75 |
private boolean checkFailed() {
|
|
76 |
return checkEngine.getErrorCount() > 0;
|
|
77 |
}
|
|
78 |
|
|
79 |
/**
|
|
80 |
* Method loads the configuration details from the given file.
|
|
81 |
*
|
628
|
82 |
* @param configFile is the configuration file to be loaded.
|
587
|
83 |
*/
|
|
84 |
private void loadConfiguration(String configFile) {
|
|
85 |
try {
|
|
86 |
configuration = new Properties();
|
|
87 |
configuration.load(new FileInputStream(configFile));
|
|
88 |
} catch (IOException th) {
|
628
|
89 |
println("Error occured while loading config file: " + configFile);
|
587
|
90 |
System.exit(-1);
|
|
91 |
}
|
|
92 |
}
|
|
93 |
|
|
94 |
/**
|
|
95 |
* Main method to trigger tool check.
|
|
96 |
*
|
628
|
97 |
* @param args contains command line arguments passed.
|
587
|
98 |
* @throws Exception
|
|
99 |
*/
|
|
100 |
public static void main(String[] args) throws Exception {
|
|
101 |
|
|
102 |
String configFile = null;
|
|
103 |
|
|
104 |
// check for configuration file
|
|
105 |
if (args.length == 2 && args[0].equalsIgnoreCase("-config")) {
|
628
|
106 |
if (args[1] == null || (args[1] != null && args[1].trim().isEmpty())) {
|
|
107 |
println("*** Error: Parameter '-config' not set for HeliumToolsCheckerMain");
|
587
|
108 |
System.exit(-1);
|
|
109 |
}
|
|
110 |
configFile = args[1];
|
|
111 |
}
|
|
112 |
|
|
113 |
if (configFile != null) {
|
628
|
114 |
HeliumToolsCheckerMain checkerMain = new HeliumToolsCheckerMain(configFile);
|
587
|
115 |
checkerMain.checkAnt();
|
|
116 |
checkerMain.checkPython();
|
|
117 |
if (checkerMain.checkFailed()) {
|
|
118 |
System.exit(-1);
|
|
119 |
}
|
628
|
120 |
}
|
|
121 |
else {
|
|
122 |
println("*** Error: Missing '-config' argument for HeliumToolsCheckerMain");
|
|
123 |
println("Usage: java [main-class-name] -config [location of configuration file]");
|
|
124 |
println("Example: java com.nokia.helium.checktools.HeliumToolsCheckerMain -config \"config/helium.basic.tools.config\"");
|
587
|
125 |
System.exit(-1);
|
|
126 |
}
|
|
127 |
}
|
628
|
128 |
|
|
129 |
@SuppressWarnings("PMD.SystemPrintln")
|
|
130 |
public static void println(String text) {
|
|
131 |
System.out.println(text);
|
|
132 |
}
|
587
|
133 |
}
|