]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/CreateMdkPkg/src/org/tianocore/common/Tools.java
Obliterate these files.
[mirror_edk2.git] / Tools / Source / CreateMdkPkg / src / org / tianocore / common / Tools.java
1 /** @file
2
3 The file is used to provides some useful interfaces
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 package org.tianocore.common;
17
18 import java.io.File;
19 import java.text.SimpleDateFormat;
20 import java.util.Date;
21 import java.util.UUID;
22
23 /**
24 The class is used to provides some useful interfaces
25
26 @since CreateMdkPkg 1.0
27
28 **/
29 public class Tools {
30
31 /**
32 Used for test
33
34 @param args
35
36 **/
37 public static void main(String[] args) {
38 System.out.println(getCurrentDateTime());
39 }
40
41 /**
42 Get current date and time and format it as "yyyy-MM-dd HH:mm"
43
44 @return formatted current date and time
45
46 **/
47 public static String getCurrentDateTime() {
48 Date now = new Date(System.currentTimeMillis());
49 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
50 return sdf.format(now);
51 }
52
53 /**
54 Delete a folder and all its files
55
56 @param fleFolderName The name of the folder which need be deleted
57
58 @retval true - Delete successfully
59 @retval false - Delete successfully
60
61 **/
62 public static boolean deleteFolder(File fleFolderName) {
63 boolean blnIsDeleted = true;
64 File[] aryAllFiles = fleFolderName.listFiles();
65
66 for (int indexI = 0; indexI < aryAllFiles.length; indexI++) {
67 if (blnIsDeleted) {
68 if (aryAllFiles[indexI].isDirectory()) {
69 //
70 //If is a directory, recursively call this function to delete sub folders
71 //
72 blnIsDeleted = deleteFolder(aryAllFiles[indexI]);
73 } else if (aryAllFiles[indexI].isFile()) {
74 //
75 //If is a file, delete it
76 //
77 if (!aryAllFiles[indexI].delete()) {
78 blnIsDeleted = false;
79 }
80 }
81 }
82 }
83 if (blnIsDeleted) {
84 fleFolderName.delete();
85 }
86 return blnIsDeleted;
87 }
88
89 /**
90 Generate a UUID
91
92 @return the created UUID
93
94 **/
95 public static String generateUuidString() {
96 return UUID.randomUUID().toString();
97 }
98
99 /**
100 Get all system properties and output to the console
101
102 **/
103 public static void getSystemProperties() {
104 System.out.println(System.getProperty("java.class.version"));
105 System.out.println(System.getProperty("java.class.path"));
106 System.out.println(System.getProperty("java.ext.dirs"));
107 System.out.println(System.getProperty("os.name"));
108 System.out.println(System.getProperty("os.arch"));
109 System.out.println(System.getProperty("os.version"));
110 System.out.println(System.getProperty("file.separator"));
111 System.out.println(System.getProperty("path.separator"));
112 System.out.println(System.getProperty("line.separator"));
113 System.out.println(System.getProperty("user.name"));
114 System.out.println(System.getProperty("user.home"));
115 System.out.println(System.getProperty("user.dir"));
116 System.out.println(System.getProperty("PATH"));
117
118 System.out.println(System.getenv("PROCESSOR_REVISION"));
119 }
120 }