Adding Java Tool: ckt.bat for CheckTools.
[mirror_edk2.git] / Tools / Java / Source / CheckTools / src / org / tianocore / CheckTools / ToolChecks.java
1 /** @file
2 Verify the tool configuration file for location of the correct tools.
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 /**
16 * This tool checks to see if specified tool chain paths exist.
17 * It will check all specified paths, as indicated by the last field of the
18 * tool property line equal to _PATH
19 *
20 * no option = check 1) the file specified in target.txt or 2) tools_def.txt
21 * if neither is found, we check the tools_def.template file.
22 * -i = INIT checks the tools_def.template file
23 *
24 * -s = SCAN will check all standard locations for tool chains
25 * C:\Program Files\Microsoft Visual Studio *
26 * C:\WINDDK
27 * C:\Bin
28 * C:\ASL
29 * C:\MASM*
30 * /opt/tiano
31 *
32 * -f = FILE check the tools in this file instead of tools_def.txt, or
33 * a file that was specified in target.txt
34 */
35 package org.tianocore.CheckTools;
36
37 import java.io.*;
38 import java.util.*;
39
40 public class ToolChecks {
41 private static int DEBUG = 0;
42
43 private final int DEFAULT = 1;
44
45 private final int TEST = 2;
46
47 private final int SCAN = 4;
48
49 private final int INTERACTIVE = 8;
50
51 private final int PASS = 0;
52
53 private final int FAIL = 1;
54
55 private ArrayList<String> errLog = new ArrayList<String>();
56
57 private ArrayList<String> goodLog = new ArrayList<String>();
58
59 public int checkTools(String toolConfFile, int cmdCode, int VERBOSE) {
60
61 int returnCode = FAIL;
62 boolean interActive = false;
63
64 if ((DEBUG > 0) || (VERBOSE > 0)) {
65 System.out.println("Using Tool Configuration File: " + toolConfFile);
66 }
67
68 if (DEBUG > 2)
69 System.out.println("The cmdCode: " + cmdCode);
70
71 if ((cmdCode & INTERACTIVE) == INTERACTIVE) {
72 interActive = true;
73 System.out.println("***** WARNING ***** The Interactive function has not been implemented yet!");
74 }
75
76 if ((cmdCode & SCAN) == SCAN) {
77 returnCode = scanFile(toolConfFile, interActive, VERBOSE);
78 }
79
80 if (((cmdCode & TEST) == TEST) || ((cmdCode & DEFAULT) == DEFAULT))
81 returnCode = testFile(toolConfFile, interActive, VERBOSE);
82
83 if (!errLog.isEmpty()) {
84 System.out.println("Tool Configuration File: " + toolConfFile);
85 for (int i = 0; i < goodLog.size(); i++)
86 System.out.println("Tool Chain Tag Name: " + goodLog.get(i) + " is valid!");
87 for (int i = 0; i < errLog.size(); i++)
88 System.out.println(errLog.get(i));
89 }
90
91 return returnCode;
92 }
93
94 private int scanFile(String testFile, boolean interActive, int VERBOSE) {
95 if ((DEBUG > 0) || (VERBOSE > 0))
96 System.out.println("Scanning the Normal Installation Locations ...");
97 System.out.println("The Scan function has not been implemented yet!");
98 return FAIL;
99 }
100 private int testFile(String testFile, boolean interActive, int VERBOSE) {
101
102 int retCode = PASS;
103 String readLine = "";
104 String fileLine[] = new String[2];
105 try {
106 FileReader toolConfFile = new FileReader(testFile);
107 BufferedReader reader = new BufferedReader(toolConfFile);
108 String path = "";
109 String props[] = new String[5];
110 String lastErrTag = "barf";
111 String lastTag = "barf";
112 while ((readLine = reader.readLine()) != null) {
113 if ((!readLine.startsWith("#")) && (readLine.contains("_PATH"))) {
114 if (DEBUG > 2) {
115 System.out.println(" PATH LINE: " + readLine);
116 }
117 readLine = readLine.trim();
118 fileLine = readLine.split("=");
119 path = fileLine[1].trim();
120 props = fileLine[0].split("_");
121 File testPath = new File(path);
122 if (!testPath.exists()) {
123 if (!props[1].trim().contentEquals(lastErrTag))
124 errLog.add(" -- ERROR: Tool Chain Tag Name: " + props[1].trim() + " is invalid!");
125 // System.out.println(" +++++ ERROR: Tool Chain: " + props[1].trim() + " is invalid!");
126 errLog.add(" Tool Code: [" + props[3].trim() + "] Path: " + path + " does not exist!");
127 // System.out.println(" Tool: " + props[3].trim() + " Path: " + path + " does not exist!");
128 retCode = 1;
129 lastErrTag = props[1].trim();
130 } else {
131 if ((DEBUG > 0) || (VERBOSE > 0)) {
132 if ((!props[1].trim().contentEquals(lastTag))
133 && (!props[1].trim().contentEquals(lastErrTag)))
134 System.out.println("Tool Chain: " + props[1].trim() + " is valid");
135 }
136 if (!props[1].trim().contentEquals(lastTag))
137 goodLog.add(props[1].trim());
138 lastTag = props[1].trim();
139 }
140 }
141 }
142 } catch (IOException e) {
143 System.out.println(" [" + testFile + "] " + e);
144 System.exit(1);
145 }
146 if (errLog.size() > 0)
147 for (int i = 0; i < goodLog.size(); i++) {
148 for (int j = 0; j < errLog.size(); j++) {
149 if (errLog.get(j).contains(goodLog.get(i).trim())) {
150 goodLog.remove(i);
151 break;
152 }
153 }
154 }
155 return retCode;
156
157 }
158
159 }