]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/ModuleEditor/src/org/tianocore/packaging/workspace/common/Workspace.java
1d989098329b5b4e098c578e6a56edc2d6267312
[mirror_edk2.git] / Tools / Source / ModuleEditor / src / org / tianocore / packaging / workspace / common / Workspace.java
1 /** @file
2
3 The file is used to init workspace and get basic information of workspace
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.packaging.workspace.common;
17
18 import java.io.File;
19
20 import org.apache.xmlbeans.XmlException;
21 import org.apache.xmlbeans.XmlObject;
22 import org.tianocore.FrameworkDatabaseDocument;
23 import org.tianocore.common.Log;
24
25 /**
26 The file is used to init workspace and get basic information of workspace
27
28 @since ModuleEditor 1.0
29
30 **/
31 public class Workspace {
32
33 //
34 // Define class members
35 //
36 private String currentWorkspace = null;
37
38 private FrameworkDatabaseDocument xmlFrameworkDbDoc = null;
39
40 private String strWorkspaceDatabaseFile = System.getProperty("file.separator") + "Tools"
41 + System.getProperty("file.separator") + "Conf"
42 + System.getProperty("file.separator") + "FrameworkDatabase.db";
43
44 public static void main(String[] args) {
45
46 }
47
48 /**
49 This is the default constructor
50 Get current WORKSPACE from system environment variable
51
52 **/
53 public Workspace() {
54 this.currentWorkspace = System.getenv("WORKSPACE");
55 }
56
57 /**
58 Check if current workspace exists of not
59
60 @retval true - The current WORKSPACE exists
61 @retval false - The current WORKSPACE doesn't exist
62
63 **/
64 public boolean checkCurrentWorkspace() {
65 return checkCurrentWorkspace(getCurrentWorkspace());
66 }
67
68 /**
69 Check if current workspace exists or not via input workspace path
70
71 @param strWorkspace The input data of WORKSPACE path
72 @retval true - The current WORKSPACE exists
73 @retval false - The current WORKSPACE doesn't exist
74
75 **/
76 public boolean checkCurrentWorkspace(String strWorkspace) {
77 if (strWorkspace == null || strWorkspace == "") {
78 return false;
79 }
80 File f = new File(strWorkspace);
81 if (!f.isDirectory()) {
82 return false;
83 }
84 if (!f.exists()) {
85 return false;
86 }
87 return true;
88 }
89
90 /**
91 Get Current Workspace
92
93 @return currentWorkspace
94
95 **/
96 public String getCurrentWorkspace() {
97 return currentWorkspace;
98 }
99
100 /**
101 Set Current Workspace
102
103 @param currentWorkspace The input data of currentWorkspace
104
105 **/
106 public void setCurrentWorkspace(String currentWorkspace) {
107 this.currentWorkspace = currentWorkspace;
108 }
109
110 /**
111 Open Framework Database file
112
113 **/
114 private void openFrameworkDb() {
115 String strFrameworkDbFilePath = this.getCurrentWorkspace() + strWorkspaceDatabaseFile;
116 try {
117 xmlFrameworkDbDoc = (FrameworkDatabaseDocument) XmlObject.Factory.parse(strFrameworkDbFilePath);
118 } catch (XmlException e) {
119 Log.err("Open Framework Database " + strFrameworkDbFilePath, e.getMessage());
120 return;
121 } catch (Exception e) {
122 Log.err("Open Framework Database " + strFrameworkDbFilePath, "Invalid file type");
123 return;
124 }
125 }
126
127 /**
128 Get FrameworkDatabaseDocument
129
130 @return FrameworkDatabaseDocument
131
132 **/
133 public FrameworkDatabaseDocument getXmlFrameworkDbDoc() {
134 openFrameworkDb();
135 return xmlFrameworkDbDoc;
136 }
137
138 /**
139 Set FrameworkDatabaseDocument
140
141 @param xmlFrameworkDbDoc The input data of FrameworkDatabaseDocument
142
143 **/
144 public void setXmlFrameworkDbDoc(FrameworkDatabaseDocument xmlFrameworkDbDoc) {
145 this.xmlFrameworkDbDoc = xmlFrameworkDbDoc;
146 }
147 }