]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | \r | |
3 | The file is used to init workspace and get basic information of workspace\r | |
4 | \r | |
5 | Copyright (c) 2006, Intel Corporation\r | |
6 | All rights reserved. This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | package org.tianocore.packaging.workspace.common;\r | |
17 | \r | |
18 | import java.io.File;\r | |
2a8b1c0a | 19 | import java.util.Vector;\r |
878ddf1f | 20 | \r |
21 | import org.apache.xmlbeans.XmlException;\r | |
22 | import org.apache.xmlbeans.XmlObject;\r | |
23 | import org.tianocore.FrameworkDatabaseDocument;\r | |
24 | import org.tianocore.common.Log;\r | |
25 | \r | |
26 | /**\r | |
27 | The file is used to init workspace and get basic information of workspace\r | |
28 | \r | |
29 | @since ModuleEditor 1.0\r | |
30 | \r | |
31 | **/\r | |
32 | public class Workspace {\r | |
33 | \r | |
34 | //\r | |
35 | // Define class members\r | |
36 | //\r | |
37 | private String currentWorkspace = null;\r | |
38 | \r | |
39 | private FrameworkDatabaseDocument xmlFrameworkDbDoc = null;\r | |
2a8b1c0a | 40 | \r |
41 | //private PackageDocument xmlPackage = null;\r | |
878ddf1f | 42 | \r |
43 | private String strWorkspaceDatabaseFile = System.getProperty("file.separator") + "Tools"\r | |
44 | + System.getProperty("file.separator") + "Conf"\r | |
45 | + System.getProperty("file.separator") + "FrameworkDatabase.db";\r | |
46 | \r | |
47 | public static void main(String[] args) {\r | |
48 | \r | |
49 | }\r | |
50 | \r | |
51 | /**\r | |
52 | This is the default constructor\r | |
53 | Get current WORKSPACE from system environment variable\r | |
54 | \r | |
55 | **/\r | |
56 | public Workspace() {\r | |
57 | this.currentWorkspace = System.getenv("WORKSPACE");\r | |
58 | }\r | |
59 | \r | |
60 | /**\r | |
61 | Check if current workspace exists of not\r | |
62 | \r | |
63 | @retval true - The current WORKSPACE exists\r | |
64 | @retval false - The current WORKSPACE doesn't exist\r | |
65 | \r | |
66 | **/\r | |
67 | public boolean checkCurrentWorkspace() {\r | |
68 | return checkCurrentWorkspace(getCurrentWorkspace());\r | |
69 | }\r | |
70 | \r | |
71 | /**\r | |
72 | Check if current workspace exists or not via input workspace path\r | |
73 | \r | |
74 | @param strWorkspace The input data of WORKSPACE path\r | |
75 | @retval true - The current WORKSPACE exists\r | |
76 | @retval false - The current WORKSPACE doesn't exist\r | |
77 | \r | |
78 | **/\r | |
79 | public boolean checkCurrentWorkspace(String strWorkspace) {\r | |
80 | if (strWorkspace == null || strWorkspace == "") {\r | |
81 | return false;\r | |
82 | }\r | |
83 | File f = new File(strWorkspace);\r | |
84 | if (!f.isDirectory()) {\r | |
85 | return false;\r | |
86 | }\r | |
87 | if (!f.exists()) {\r | |
88 | return false;\r | |
89 | }\r | |
90 | return true;\r | |
91 | }\r | |
92 | \r | |
93 | /**\r | |
94 | Get Current Workspace\r | |
95 | \r | |
96 | @return currentWorkspace\r | |
97 | \r | |
98 | **/\r | |
99 | public String getCurrentWorkspace() {\r | |
100 | return currentWorkspace;\r | |
101 | }\r | |
102 | \r | |
103 | /**\r | |
104 | Set Current Workspace\r | |
105 | \r | |
106 | @param currentWorkspace The input data of currentWorkspace\r | |
107 | \r | |
108 | **/\r | |
109 | public void setCurrentWorkspace(String currentWorkspace) {\r | |
110 | this.currentWorkspace = currentWorkspace;\r | |
111 | }\r | |
112 | \r | |
113 | /**\r | |
114 | Open Framework Database file\r | |
115 | \r | |
116 | **/\r | |
117 | private void openFrameworkDb() {\r | |
118 | String strFrameworkDbFilePath = this.getCurrentWorkspace() + strWorkspaceDatabaseFile;\r | |
2a8b1c0a | 119 | File db = new File(strFrameworkDbFilePath);\r |
878ddf1f | 120 | try {\r |
2a8b1c0a | 121 | xmlFrameworkDbDoc = (FrameworkDatabaseDocument) XmlObject.Factory.parse(db);\r |
878ddf1f | 122 | } catch (XmlException e) {\r |
123 | Log.err("Open Framework Database " + strFrameworkDbFilePath, e.getMessage());\r | |
124 | return;\r | |
125 | } catch (Exception e) {\r | |
126 | Log.err("Open Framework Database " + strFrameworkDbFilePath, "Invalid file type");\r | |
127 | return;\r | |
128 | }\r | |
129 | }\r | |
130 | \r | |
131 | /**\r | |
132 | Get FrameworkDatabaseDocument\r | |
133 | \r | |
134 | @return FrameworkDatabaseDocument\r | |
135 | \r | |
136 | **/\r | |
137 | public FrameworkDatabaseDocument getXmlFrameworkDbDoc() {\r | |
138 | openFrameworkDb();\r | |
139 | return xmlFrameworkDbDoc;\r | |
140 | }\r | |
141 | \r | |
142 | /**\r | |
143 | Set FrameworkDatabaseDocument\r | |
144 | \r | |
145 | @param xmlFrameworkDbDoc The input data of FrameworkDatabaseDocument\r | |
146 | \r | |
147 | **/\r | |
148 | public void setXmlFrameworkDbDoc(FrameworkDatabaseDocument xmlFrameworkDbDoc) {\r | |
149 | this.xmlFrameworkDbDoc = xmlFrameworkDbDoc;\r | |
150 | }\r | |
2a8b1c0a | 151 | \r |
152 | /**\r | |
153 | Get all package name form the FrameworkDatabase.db file\r | |
154 | \r | |
155 | @return vPackageName A vector includes all package names\r | |
156 | \r | |
157 | **/\r | |
158 | public Vector getAllPackageName() {\r | |
159 | Vector<String> vPackageName = new Vector<String>();\r | |
160 | openFrameworkDb();\r | |
161 | \r | |
162 | for (int index = 0; index < xmlFrameworkDbDoc.getFrameworkDatabase().getPackageList().sizeOfPackageArray(); index++) {\r | |
163 | vPackageName.addElement(xmlFrameworkDbDoc.getFrameworkDatabase().getPackageList().getPackageArray(index)\r | |
164 | .getPackageNameArray(0).getStringValue());\r | |
165 | }\r | |
166 | \r | |
167 | return vPackageName;\r | |
168 | }\r | |
878ddf1f | 169 | }\r |