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