]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/far/PackageQuery.java
1. Show source files' attributes when editing SourceFiles in msa
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / far / PackageQuery.java
1 /** @file
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 **/
13
14 package org.tianocore.frameworkwizard.far;
15
16 import java.io.File;
17 import java.io.InputStream;
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.Vector;
22
23 import org.apache.xmlbeans.XmlObject;
24 import org.tianocore.ModuleSurfaceAreaDocument;
25 import org.tianocore.PackageDependenciesDocument;
26 import org.tianocore.PackageSurfaceAreaDocument;
27 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;
28 import org.tianocore.frameworkwizard.common.OpenFile;
29 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
30 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
31
32 public class PackageQuery implements PackageQueryInterface {
33
34 public PackageIdentification getPackageIdentification(File spdFile) {
35 PackageIdentification packageId = null;
36 try {
37 String path = spdFile.getPath();
38 WorkspaceTools wt = new WorkspaceTools();
39 packageId = new PackageIdentification(wt.getId(path, OpenFile.openSpdFile(path)));
40 } catch (Exception e) {
41 e.printStackTrace();
42 }
43 return packageId;
44 }
45
46 public List<String> getPackageMsaList(InputStream spdInput) {
47 List<String> result = new ArrayList<String>();
48 try {
49 PackageSurfaceAreaDocument spd = (PackageSurfaceAreaDocument) XmlObject.Factory.parse(spdInput);
50 result = spd.getPackageSurfaceArea().getMsaFiles().getFilenameList();
51 } catch (Exception e) {
52 e.printStackTrace();
53 }
54 return result;
55 }
56
57 public List<PackageIdentification> getModuleDependencies(InputStream msaInput) {
58 List<PackageIdentification> result = new ArrayList<PackageIdentification>();
59 try {
60 ModuleSurfaceAreaDocument msa = (ModuleSurfaceAreaDocument) XmlObject.Factory.parse(msaInput);
61 ModuleSurfaceAreaDocument.ModuleSurfaceArea sa = msa.getModuleSurfaceArea();
62 if (sa == null) {
63 return result;
64 }
65 PackageDependenciesDocument.PackageDependencies pkgDep = sa.getPackageDependencies();
66 if (pkgDep == null) {
67 return result;
68 }
69 List<PackageDependenciesDocument.PackageDependencies.Package> list = pkgDep.getPackageList();
70 Iterator<PackageDependenciesDocument.PackageDependencies.Package> iter = list.iterator();
71 while (iter.hasNext()) {
72 PackageDependenciesDocument.PackageDependencies.Package item = iter.next();
73 PackageIdentification packageId = new PackageIdentification(null, item.getPackageGuid(),
74 item.getPackageVersion());
75 result.add(packageId);
76 }
77 } catch (Exception e) {
78 e.printStackTrace();
79 }
80 return result;
81 }
82
83 public List<File> getPackageMsaList(File spdFile) {
84 List<File> result = new Vector<File>();
85 WorkspaceTools wt = new WorkspaceTools();
86 List<String> v = wt.getAllModulesOfPackage(spdFile.getPath());
87 Iterator<String> iter = v.iterator();
88 while (iter.hasNext()) {
89 result.add(new File(iter.next()));
90 }
91 return result;
92 }
93
94 public List<PackageIdentification> getPackageDependencies(File spdFile) {
95 List<File> msaFiles = getPackageMsaList(spdFile);
96 return getPackageDependencies(msaFiles);
97 }
98
99 public List<PackageIdentification> getPackageDependencies(List<File> msaFiles) {
100 List<PackageIdentification> result = new ArrayList<PackageIdentification>();
101 Iterator<File> iter = msaFiles.iterator();
102 while (iter.hasNext()) {
103 result = AggregationOperation.union(result, getModuleDependencies(iter.next()));
104 }
105 return result;
106 }
107
108 public List<PackageIdentification> getModuleDependencies(File msaFile) {
109 List<PackageIdentification> result = new ArrayList<PackageIdentification>();
110 try {
111 ModuleSurfaceArea msa = OpenFile.openMsaFile(msaFile.getPath());
112 List<PackageDependenciesDocument.PackageDependencies.Package> p = msa.getPackageDependencies()
113 .getPackageList();
114 Iterator<PackageDependenciesDocument.PackageDependencies.Package> iter = p.iterator();
115 while (iter.hasNext()) {
116 PackageDependenciesDocument.PackageDependencies.Package item = iter.next();
117 PackageIdentification packageId = new PackageIdentification(null, item.getPackageGuid(),
118 item.getPackageVersion());
119 if (!AggregationOperation.belongs(packageId, result)) {
120 result.add(packageId);
121 }
122 }
123 } catch (Exception e) {
124 }
125 return result;
126 }
127 }