]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/ContextTool/org/tianocore/context/TargetFile.java
2 File is TargetFile class which is used to generate the new target.txt.
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
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.
13 package org
.tianocore
.context
;
15 import java
.io
.BufferedReader
;
16 import java
.io
.BufferedWriter
;
18 import java
.io
.FileNotFoundException
;
19 import java
.io
.FileReader
;
20 import java
.io
.FileWriter
;
21 import java
.io
.IOException
;
23 public class TargetFile
{
28 * validate the filename
29 * @param String filename : the name of target file
31 * @return true or false
33 public static boolean validateFilename(String filename
) {
35 String workspacePath
= System
.getenv("WORKSPACE");
37 Fd
= new File(workspacePath
+ File
.separator
+ "Tools" + File
.separator
+ "Conf" + File
.separator
+ filename
);
39 if (Fd
.exists() == true && Fd
.canRead() == true)
47 * create a empty temp file, which is located at the same directory with target file
48 * @param String filename : the name of target temp file
49 * @return true or false
51 public static boolean createTempFile(String filename
) {
53 String workspacePath
= System
.getenv("WORKSPACE");
55 TempFd
= new File(workspacePath
+ File
.separator
+ "Tools" + File
.separator
+ "Conf" + File
.separator
+ filename
+ "tmp");
57 if (TempFd
.exists() == true) {
58 if (TempFd
.delete() == false) {
59 System
.out
.printf("%n%s%n", "target.txttmp has been existed, and failed in deletion!");
64 TempFd
.createNewFile();
65 } catch (IOException e
) {
66 System
.out
.printf("%n%s%n", "Failed in creation of the temp file:target.txttmp!");
74 * read from target.txt and write to target.txttmp, del target.txt, rename
76 * @return true or false
78 public static boolean readwriteFile() {
80 if (Fd
.canRead() != true)
83 BufferedReader br
= null;
84 BufferedWriter bw
= null;
85 String textLine
= null;
88 br
= new BufferedReader(new FileReader(Fd
));
89 } catch (FileNotFoundException e
) {
91 .println("\n# Creating BufferedReader fail!");
95 bw
= new BufferedWriter(new FileWriter(TempFd
));
96 } catch (IOException e
) {
97 System
.out
.println("\n# Creating the BufferedWriter fail!");
102 //TARGET_ARCH must be in front of TARGET!!! according to the target.txt
105 while ((textLine
= br
.readLine()) != null) {
107 // the line is composed of Space
109 if (textLine
.trim().compareToIgnoreCase("") == 0) {
114 // the line starts with "#", and no "="
116 else if ((textLine
.trim().charAt(0) == '#') && (textLine
.indexOf("=") == -1)){
121 //modify at the first time, and there should be "*ACTIVE_PLATFORM*=*" in the line
123 if (textLine
.indexOf("ACTIVE_PLATFORM") != -1) {
125 if(textLine
.trim().charAt(0) == '#'){
126 if(ParseParameter
.npflag
== true) {
127 bw
.write(ParseParameter
.curpstr
);
135 if(ParseParameter
.npflag
== true) {
136 bw
.write(ParseParameter
.curpstr
);
143 } else if (textLine
.indexOf("TARGET_ARCH") != -1) {
145 if(textLine
.trim().charAt(0) == '#'){
146 if(ParseParameter
.naflag
== true) {
147 bw
.write(ParseParameter
.curastr
);
155 if(ParseParameter
.naflag
== true) {
156 bw
.write(ParseParameter
.curastr
);
163 } else if (textLine
.indexOf("TARGET") != -1) {
165 if(textLine
.trim().charAt(0) == '#'){
166 if(ParseParameter
.ntflag
== true) {
167 bw
.write(ParseParameter
.curtstr
);
175 if(ParseParameter
.ntflag
== true) {
176 bw
.write(ParseParameter
.curtstr
);
183 } else if (textLine
.indexOf("TOOL_CHAIN_CONF") != -1) {
185 if(textLine
.trim().charAt(0) == '#'){
186 if(ParseParameter
.ncflag
== true) {
187 bw
.write(ParseParameter
.curcstr
);
195 if(ParseParameter
.ncflag
== true) {
196 bw
.write(ParseParameter
.curcstr
);
203 } else if (textLine
.indexOf("TOOL_CHAIN_TAG") != -1) {
205 if(textLine
.trim().charAt(0) == '#'){
206 if(ParseParameter
.nnflag
== true) {
207 bw
.write(ParseParameter
.curnstr
);
215 if(ParseParameter
.nnflag
== true) {
216 bw
.write(ParseParameter
.curnstr
);
223 } else if (textLine
.indexOf("MAX_CONCURRENT_THREAD_NUMBER") != -1) {
225 if(textLine
.trim().charAt(0) == '#'){
226 if(ParseParameter
.nmflag
== true) {
227 bw
.write(ParseParameter
.curmstr
);
235 if(ParseParameter
.nmflag
== true) {
236 bw
.write(ParseParameter
.curmstr
);
243 }else if (textLine
.indexOf("MULTIPLE_THREAD") != -1) {
245 if(textLine
.trim().charAt(0) == '#'){
246 if(ParseParameter
.nmeflag
== true) {
247 bw
.write(ParseParameter
.curmestr
);
255 if(ParseParameter
.nmeflag
== true) {
256 bw
.write(ParseParameter
.curmestr
);
267 //user maybe delete the line *ACTIVE_PLATFORM*=*
269 if( (pflag
== true) && (ParseParameter
.npflag
== true) ){
270 bw
.write(ParseParameter
.curpstr
);
272 } else if ( (tflag
== true) && (ParseParameter
.ntflag
== true) ){
273 bw
.write(ParseParameter
.curtstr
);
275 } else if ( (aflag
== true) && (ParseParameter
.naflag
== true) ){
276 bw
.write(ParseParameter
.curastr
);
278 } else if ( (cflag
== true) && (ParseParameter
.ncflag
== true) ){
279 bw
.write(ParseParameter
.curcstr
);
281 } else if ( (nflag
== true) && (ParseParameter
.nnflag
== true) ){
282 bw
.write(ParseParameter
.curnstr
);
284 } else if ( (meflag
== true) && (ParseParameter
.nmeflag
== true) ){
285 bw
.write(ParseParameter
.curmestr
);
287 } else if ( (mflag
== true) && (ParseParameter
.nmflag
== true) ){
288 bw
.write(ParseParameter
.curmstr
);
291 } catch (IOException e
) {
292 System
.out
.println("\n# Reading or Writing file fail!");
299 } catch (IOException e
) {
301 .println("\n# Closing BufferedReader&BufferedWriter fail!");
305 if (Fd
.delete() == false) {
306 System
.out
.println("\n# Deleting file fail!");
309 if (TempFd
.renameTo(Fd
) == false) {
310 System
.out
.println("\n# Renaming file failed!");
318 * read the file and output the lines which include setting
319 * @param File fd : the File of the target file
320 * @return String: the current setting
322 public static boolean readFile() {
324 BufferedReader br
= null;
325 String textLine
= null;
328 br
= new BufferedReader(new FileReader(Fd
));
329 } catch (FileNotFoundException e
) {
331 .println("\n# Creating BufferedReader fail!");
335 while ((textLine
= br
.readLine()) != null) {
337 // the line is composed of Space
339 if (textLine
.trim().compareToIgnoreCase("") == 0) {
343 // the line starts with "#"
345 else if ((textLine
.trim().charAt(0) == '#')){
348 if (textLine
.indexOf("ACTIVE_PLATFORM") != -1) {
349 ParseParameter
.curpstr
= textLine
;
350 } else if (textLine
.indexOf("TARGET_ARCH") != -1) {
351 ParseParameter
.curastr
= textLine
;
352 } else if (textLine
.indexOf("TARGET") != -1) {
353 ParseParameter
.curtstr
= textLine
;
354 } else if (textLine
.indexOf("TOOL_CHAIN_CONF") != -1) {
355 ParseParameter
.curcstr
= textLine
;
356 } else if (textLine
.indexOf("TOOL_CHAIN_TAG") != -1) {
357 ParseParameter
.curnstr
= textLine
;
358 } else if (textLine
.indexOf("MAX_CONCURRENT_THREAD_NUMBER") != -1) {
359 ParseParameter
.curmstr
= textLine
;
360 } else if (textLine
.indexOf("MULTIPLE_THREAD") != -1) {
361 ParseParameter
.curmestr
= textLine
;
365 } catch (IOException e
) {
366 System
.out
.println("\n# Reading file fail!");
372 } catch (IOException e
) {
374 .println("\n# Closing BufferedReader fail!");
382 /// point to target.txttmp, a temp file, which is created and deleted during the tool's runtime.
384 private static File TempFd
;
387 /// point to target.txt.
389 private static File Fd
;
392 /// when the flag is true, the corresponding str should be add at the end of file.
394 private static boolean pflag
= true;
395 private static boolean tflag
= true;
396 private static boolean aflag
= true;
397 private static boolean cflag
= true;
398 private static boolean nflag
= true;
399 private static boolean mflag
= true;
400 private static boolean meflag
= true;