summaryrefslogtreecommitdiff
path: root/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/GlobalData.java
blob: ed175e53430a01af51227f21f748707651dbe338 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/** @file 
 The file is used to provide initializing global data.
 
 Copyright (c) 2006, Intel Corporation
 All rights reserved. This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php

 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/
package org.tianocore.frameworkwizard.common;

import java.io.IOException;
import java.util.Vector;

import org.apache.xmlbeans.XmlException;
import org.tianocore.FrameworkDatabaseDocument.FrameworkDatabase;
import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;
import org.tianocore.MsaFilesDocument.MsaFiles;
import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;
import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;
import org.tianocore.frameworkwizard.common.Identifications.Identification;
import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleList;
import org.tianocore.frameworkwizard.common.Identifications.OpeningPackageList;
import org.tianocore.frameworkwizard.common.Identifications.OpeningPlatformList;
import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
import org.tianocore.frameworkwizard.packaging.PackageIdentification;
import org.tianocore.frameworkwizard.platform.PlatformIdentification;
import org.tianocore.frameworkwizard.workspace.Workspace;

public class GlobalData {

    public static FrameworkDatabase fdb = null;

    public static OpeningModuleList openingModuleList = new OpeningModuleList();

    public static OpeningPackageList openingPackageList = new OpeningPackageList();

    public static OpeningPlatformList openingPlatformList = new OpeningPlatformList();

    public static Vector<ModuleIdentification> vModuleList = new Vector<ModuleIdentification>();

    public static Vector<PackageIdentification> vPackageList = new Vector<PackageIdentification>();

    public static Vector<PlatformIdentification> vPlatformList = new Vector<PlatformIdentification>();

    public static void init() {
        initDatabase();
        initPackage();
        initPlatform();
        initModule();
    }

    public static void initDatabase() {
        String strFrameworkDbFilePath = Workspace.getCurrentWorkspace() + Workspace.getStrWorkspaceDatabaseFile();
        strFrameworkDbFilePath = Tools.convertPathToCurrentOsType(strFrameworkDbFilePath);
        try {
            fdb = OpenFile.openFrameworkDb(strFrameworkDbFilePath);
        } catch (XmlException e) {
            Log.err("Open Framework Database " + strFrameworkDbFilePath, e.getMessage());
            return;
        } catch (Exception e) {
            Log.err("Open Framework Database " + strFrameworkDbFilePath, "Invalid file type");
            return;
        }
    }

    public static void initModule() {
        vModuleList = new Vector<ModuleIdentification>();
        openingModuleList = new OpeningModuleList();

        ModuleSurfaceArea msa = null;
        Vector<String> modulePaths = new Vector<String>();
        Identification id = null;
        ModuleIdentification mid = null;
        String packagePath = null;
        String modulePath = null;

        //
        // For each package, get all modules list
        //
        if (vPackageList.size() > 0) {
            for (int indexI = 0; indexI < vPackageList.size(); indexI++) {
                packagePath = vPackageList.elementAt(indexI).getPath();
                modulePaths = getAllModulesOfPackage(packagePath);

                for (int indexJ = 0; indexJ < modulePaths.size(); indexJ++) {
                    try {
                        modulePath = modulePaths.get(indexJ);
                        msa = OpenFile.openMsaFile(modulePath);

                    } catch (IOException e) {
                        Log.err("Open Module Surface Area " + modulePath, e.getMessage());
                        continue;
                    } catch (XmlException e) {
                        Log.err("Open Module Surface Area " + modulePath, e.getMessage());
                        continue;
                    } catch (Exception e) {
                        Log.err("Open Module Surface Area " + modulePath, "Invalid file type");
                        continue;
                    }
                    id = Tools.getId(modulePath, msa);
                    mid = new ModuleIdentification(id, vPackageList.elementAt(indexI));
                    vModuleList.addElement(mid);
                    openingModuleList.insertToOpeningModuleList(mid, msa);
                }
            }
            Sort.sortModules(vModuleList, DataType.SORT_TYPE_ASCENDING);
        }
    }

    public static void initPackage() {
        vPackageList = new Vector<PackageIdentification>();
        openingPackageList = new OpeningPackageList();
        if (fdb != null) {
            for (int index = 0; index < fdb.getPackageList().getFilenameList().size(); index++) {
                String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR
                              + fdb.getPackageList().getFilenameArray(index).getStringValue();
                path = Tools.convertPathToCurrentOsType(path);
                PackageSurfaceArea spd = null;
                PackageIdentification id = null;
                try {
                    spd = OpenFile.openSpdFile(path);
                } catch (IOException e) {
                    Log.err("Open Package Surface Area " + path, e.getMessage());
                    continue;
                } catch (XmlException e) {
                    Log.err("Open Package Surface Area " + path, e.getMessage());
                    continue;
                } catch (Exception e) {
                    Log.err("Open Package Surface Area " + path, "Invalid file type");
                    continue;
                }
                id = Tools.getId(path, spd);
                vPackageList.addElement(id);
                openingPackageList.insertToOpeningPackageList(id, spd);
            }
            Sort.sortPackages(vPackageList, DataType.SORT_TYPE_ASCENDING);
        }
    }

    public static void initPlatform() {
        vPlatformList = new Vector<PlatformIdentification>();
        openingPlatformList = new OpeningPlatformList();

        if (fdb != null) {
            for (int index = 0; index < fdb.getPlatformList().getFilenameList().size(); index++) {
                String path = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR
                              + fdb.getPlatformList().getFilenameArray(index).getStringValue();
                path = Tools.convertPathToCurrentOsType(path);
                PlatformSurfaceArea fpd = null;
                PlatformIdentification id = null;
                try {
                    fpd = OpenFile.openFpdFile(path);
                } catch (IOException e) {
                    Log.err("Open Platform Surface Area " + path, e.getMessage());
                    continue;
                } catch (XmlException e) {
                    Log.err("Open Platform Surface Area " + path, e.getMessage());
                    continue;
                } catch (Exception e) {
                    Log.err("Open Platform Surface Area " + path, "Invalid file type");
                    continue;
                }
                id = Tools.getId(path, fpd);
                vPlatformList.addElement(new PlatformIdentification(id));
                openingPlatformList.insertToOpeningPlatformList(id, fpd);
            }
            Sort.sortPlatforms(vPlatformList, DataType.SORT_TYPE_ASCENDING);
        }
    }

    /**
     Get all modules' paths from one package
     
     @return a Vector with all modules' path
     
     **/
    public static Vector<String> getAllModulesOfPackage(String path) {
        Vector<String> modulePath = new Vector<String>();
        try {
            MsaFiles files = OpenFile.openSpdFile(path).getMsaFiles();
            if (files != null) {
                for (int index = 0; index < files.getFilenameList().size(); index++) {
                    String msaPath = files.getFilenameList().get(index);
                    msaPath = Tools.addFileSeparator(Tools.getFilePathOnly(path)) + msaPath;
                    msaPath = Tools.convertPathToCurrentOsType(msaPath);
                    modulePath.addElement(msaPath);
                }
            }
        } catch (IOException e) {
            Log.err("Get all modules from a package " + path, e.getMessage());
        } catch (XmlException e) {
            Log.err("Get all modules from a package " + path, e.getMessage());
        } catch (Exception e) {
            Log.err("Get all modules from a package " + path, e.getMessage());
        }
        return modulePath;
    }

    /**
     Get a module id
     
     @param moduleGuid
     @param moduleVersion
     @param packageGuid
     @param packageVersion
     @return
     
     **/
    public static ModuleIdentification findModuleId(String moduleGuid, String moduleVersion, String packageGuid,
                                                    String packageVersion) {
        ModuleIdentification mid = null;
        for (int index = 0; index < vModuleList.size(); index++) {
            if (vModuleList.elementAt(index).equals(moduleGuid, moduleVersion, packageGuid, packageVersion)) {
                mid = vModuleList.elementAt(index);
                break;
            }
        }
        return mid;
    }

    /**
     Get a package id
     
     @param packageGuid
     @param packageVersion
     @return
     
     **/
    public static PackageIdentification findPackageId(String packageGuid, String packageVersion) {
        PackageIdentification pid = null;
        for (int index = 0; index < vPackageList.size(); index++) {
            if (vPackageList.elementAt(index).equals(packageGuid, packageVersion)) {
                pid = vPackageList.elementAt(index);
                break;
            }
        }
        return pid;
    }

    /**
     Get a platform id 
     
     @param platformGuid
     @param platformVersion
     @return
     
     **/
    public static PlatformIdentification findPlatformId(String platformGuid, String platformVersion) {
        PlatformIdentification pid = null;
        for (int index = 0; index < vPlatformList.size(); index++) {
            if (vPlatformList.elementAt(index).equals(platformGuid, platformVersion)) {
                pid = vPlatformList.elementAt(index);
                break;
            }
        }
        return pid;
    }

    /**
    
     @param relativePath
     @param mode
     @return
    
    **/
    public static boolean isDuplicateRelativePath(String relativePath, int mode) {
        if (mode == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {
            for (int index = 0; index < vModuleList.size(); index++) {
                String path = vModuleList.elementAt(index).getPath();
                if (Tools.getFilePathOnly(path).equals(relativePath)) {
                    return true;
                }
            }
        }

        if (mode == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {
            for (int index = 0; index < vPackageList.size(); index++) {
                String path = vPackageList.elementAt(index).getPath();
                if (Tools.getFilePathOnly(path).equals(relativePath)) {
                    return true;
                }
            }
        }

        if (mode == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {
            for (int index = 0; index < vPlatformList.size(); index++) {
                String path = vPlatformList.elementAt(index).getPath();
                if (Tools.getFilePathOnly(path).equals(relativePath)) {
                    return true;
                }
            }
        }

        return false;
    }
}