]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/GlobalData.java
2d4fbe4699f3b70f2ffb29349e94fb3d51cbbe38
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / common / GlobalData.java
1 /** @file
2 The file is used to provide initializing global data.
3
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
9
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.
12 **/
13 package org.tianocore.frameworkwizard.common;
14
15 import java.io.IOException;
16 import java.util.Vector;
17
18 import org.apache.xmlbeans.XmlException;
19 import org.tianocore.FrameworkDatabaseDocument.FrameworkDatabase;
20 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;
21 import org.tianocore.MsaFilesDocument.MsaFiles;
22 import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;
23 import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;
24 import org.tianocore.frameworkwizard.common.Identifications.Identification;
25 import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleList;
26 import org.tianocore.frameworkwizard.common.Identifications.OpeningPackageList;
27 import org.tianocore.frameworkwizard.common.Identifications.OpeningPlatformList;
28 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
29 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
30 import org.tianocore.frameworkwizard.platform.PlatformIdentification;
31 import org.tianocore.frameworkwizard.workspace.Workspace;
32
33 public class GlobalData {
34
35 public static FrameworkDatabase fdb = null;
36
37 public static OpeningModuleList openingModuleList = new OpeningModuleList();
38
39 public static OpeningPackageList openingPackageList = new OpeningPackageList();
40
41 public static OpeningPlatformList openingPlatformList = new OpeningPlatformList();
42
43 public static Vector<ModuleIdentification> vModuleList = new Vector<ModuleIdentification>();
44
45 public static Vector<PackageIdentification> vPackageList = new Vector<PackageIdentification>();
46
47 public static Vector<PlatformIdentification> vPlatformList = new Vector<PlatformIdentification>();
48
49 public static void init() {
50 initDatabase();
51 initPackage();
52 initPlatform();
53 initModule();
54 }
55
56 public static void initDatabase() {
57 String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();
58 strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);
59 try {
60 fdb = OpenFile.openFrameworkDb(strFrameworkDbFilePath);
61 } catch (XmlException e) {
62 Log.err("Open Framework Database " + strFrameworkDbFilePath, e.getMessage());
63 return;
64 } catch (Exception e) {
65 Log.err("Open Framework Database " + strFrameworkDbFilePath, "Invalid file type");
66 return;
67 }
68 }
69
70 public static void initModule() {
71 vModuleList = new Vector<ModuleIdentification>();
72 openingModuleList = new OpeningModuleList();
73
74 ModuleSurfaceArea msa = null;
75 Vector<String> modulePaths = new Vector<String>();
76 Identification id = null;
77 ModuleIdentification mid = null;
78 String packagePath = null;
79 String modulePath = null;
80
81 //
82 // For each package, get all modules list
83 //
84 if (vPackageList.size() > 0) {
85 for (int indexI = 0; indexI < vPackageList.size(); indexI++) {
86 packagePath = vPackageList.elementAt(indexI).getPath();
87 modulePaths = getAllModulesOfPackage(packagePath);
88
89 for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) {
90 try {
91 modulePath = modulePaths.get(indexJ);
92 msa = OpenFile.openMsaFile(modulePath);
93
94 } catch (IOException e) {
95 Log.err("Open Module Surface Area " + modulePath, e.getMessage());
96 } catch (XmlException e) {
97 Log.err("Open Module Surface Area " + modulePath, e.getMessage());
98 } catch (Exception e) {
99 Log.err("Open Module Surface Area " + modulePath, "Invalid file type");
100 }
101 id = Tools.getId(modulePath, msa);
102 mid = new ModuleIdentification(id, vPackageList.elementAt(indexI));
103 vModuleList.addElement(mid);
104 openingModuleList.insertToOpeningModuleList(mid, msa);
105 }
106 }
107 Sort.sortModules(vModuleList, DataType.SORT_TYPE_ASCENDING);
108 }
109 }
110
111 public static void initPackage() {
112 vPackageList = new Vector<PackageIdentification>();
113 openingPackageList = new OpeningPackageList();
114 if (fdb != null) {
115 for (int index = 0; index < fdb.getPackageList().getFilenameList().size(); index++) {
116 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR
117 + fdb.getPackageList().getFilenameArray(index).getStringValue();
118 path = Tools.convertPathToCurrentOsType(path);
119 PackageSurfaceArea spd = null;
120 PackageIdentification id = null;
121 try {
122 spd = OpenFile.openSpdFile(path);
123 } catch (IOException e) {
124 Log.err("Open Package Surface Area " + path, e.getMessage());
125 } catch (XmlException e) {
126 Log.err("Open Package Surface Area " + path, e.getMessage());
127 } catch (Exception e) {
128 Log.err("Open Package Surface Area " + path, "Invalid file type");
129 }
130 id = Tools.getId(path, spd);
131 vPackageList.addElement(id);
132 openingPackageList.insertToOpeningPackageList(id, spd);
133 }
134 Sort.sortPackages(vPackageList, DataType.SORT_TYPE_ASCENDING);
135 }
136 }
137
138 public static void initPlatform() {
139 vPlatformList = new Vector<PlatformIdentification>();
140 openingPlatformList = new OpeningPlatformList();
141
142 if (fdb != null) {
143 for (int index = 0; index < fdb.getPlatformList().getFilenameList().size(); index++) {
144 String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR
145 + fdb.getPlatformList().getFilenameArray(index).getStringValue();
146 path = Tools.convertPathToCurrentOsType(path);
147 PlatformSurfaceArea fpd = null;
148 PlatformIdentification id = null;
149 try {
150 fpd = OpenFile.openFpdFile(path);
151 } catch (IOException e) {
152 Log.err("Open Platform Surface Area " + path, e.getMessage());
153 } catch (XmlException e) {
154 Log.err("Open Platform Surface Area " + path, e.getMessage());
155 } catch (Exception e) {
156 Log.err("Open Platform Surface Area " + path, "Invalid file type");
157 }
158 id = Tools.getId(path, fpd);
159 vPlatformList.addElement(new PlatformIdentification(id));
160 openingPlatformList.insertToOpeningPlatformList(id, fpd);
161 }
162 Sort.sortPlatforms(vPlatformList, DataType.SORT_TYPE_ASCENDING);
163 }
164 }
165
166 /**
167 Get all modules' paths from one package
168
169 @return a Vector with all modules' path
170
171 **/
172 private static Vector<String> getAllModulesOfPackage(String path) {
173 Vector<String> modulePath = new Vector<String>();
174 try {
175 MsaFiles files = OpenFile.openSpdFile(path).getMsaFiles();
176 if (files != null) {
177 for (int index = 0; index < files.getFilenameList().size(); index++) {
178 String msaPath = files.getFilenameList().get(index);
179 msaPath = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + msaPath;
180 msaPath = Tools.convertPathToCurrentOsType(msaPath);
181 modulePath.addElement(msaPath);
182 }
183 }
184 } catch (IOException e) {
185 Log.err("Get all mdoules of a package " + path, e.getMessage());
186 } catch (XmlException e) {
187 Log.err("Get all mdoules of a package " + path, e.getMessage());
188 } catch (Exception e) {
189 Log.err("Get all mdoules of a package " + path, e.getMessage());
190 }
191 return modulePath;
192 }
193 }