]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/Identifications/ModuleIdentification.java
1. Fix EDKT463: When wizard new or clone a msa/spd/fpd, should follow these rules
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / Identifications / ModuleIdentification.java
CommitLineData
a13899c5 1/** @file\r
2 \r
3 The file is used to save basic information of module\r
4 \r
5 Copyright (c) 2006, Intel Corporation\r
6 All rights reserved. This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10 \r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13 \r
14 **/\r
15\r
79cb6fdb 16package org.tianocore.frameworkwizard.module.Identifications;\r
a13899c5 17\r
92e29378 18import java.io.IOException;\r
19\r
20import org.apache.xmlbeans.XmlException;\r
21import org.tianocore.LibraryUsage;\r
22import org.tianocore.LibraryClassDefinitionsDocument.LibraryClassDefinitions;\r
23import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r
24import org.tianocore.frameworkwizard.common.DataType;\r
f9d0ab92 25import org.tianocore.frameworkwizard.common.OpenFile;\r
419558bb 26import org.tianocore.frameworkwizard.common.Tools;\r
79cb6fdb 27import org.tianocore.frameworkwizard.common.Identifications.Identification;\r
a13899c5 28import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r
29\r
30public class ModuleIdentification extends Identification {\r
fc87d0ba 31\r
a13899c5 32 private PackageIdentification packageId;\r
fc87d0ba 33\r
92e29378 34 private String moduleType;\r
fc87d0ba 35\r
92e29378 36 private boolean isLibrary;\r
fc87d0ba 37\r
a13899c5 38 public ModuleIdentification(String name, String guid, String version, String path) {\r
fc87d0ba 39 super(name, guid, version, path);\r
92e29378 40 setModuleType();\r
a13899c5 41 }\r
fc87d0ba 42\r
92e29378 43 public ModuleIdentification(String name, String guid, String version, String path, boolean library) {\r
44 super(name, guid, version, path);\r
45 this.isLibrary = library;\r
46 }\r
fc87d0ba 47\r
739c6b04 48 public ModuleIdentification(Identification id) {\r
49 super(id.getName(), id.getGuid(), id.getVersion(), id.getPath());\r
50 }\r
fc87d0ba 51\r
92e29378 52 public ModuleIdentification(Identification id, boolean library) {\r
a13899c5 53 super(id.getName(), id.getGuid(), id.getVersion(), id.getPath());\r
92e29378 54 this.isLibrary = library;\r
a13899c5 55 }\r
fc87d0ba 56\r
57 public ModuleIdentification(String name, String guid, String version, String path, PackageIdentification packageId) {\r
a13899c5 58 super(name, guid, version, path);\r
59 this.packageId = packageId;\r
92e29378 60 setModuleType();\r
61 }\r
fc87d0ba 62\r
63 public ModuleIdentification(String name, String guid, String version, String path, PackageIdentification packageId,\r
64 String type) {\r
92e29378 65 super(name, guid, version, path);\r
66 this.packageId = packageId;\r
67 this.moduleType = type;\r
a13899c5 68 }\r
fc87d0ba 69\r
a13899c5 70 public ModuleIdentification(Identification id, PackageIdentification packageId) {\r
71 super(id.getName(), id.getGuid(), id.getVersion(), id.getPath());\r
72 this.packageId = packageId;\r
92e29378 73 setModuleType();\r
a13899c5 74 }\r
fc87d0ba 75\r
92e29378 76 public ModuleIdentification(Identification id, PackageIdentification packageId, boolean library) {\r
77 super(id.getName(), id.getGuid(), id.getVersion(), id.getPath());\r
78 this.packageId = packageId;\r
79 this.isLibrary = library;\r
80 }\r
fc87d0ba 81\r
92e29378 82 public ModuleIdentification(Identification id, PackageIdentification packageId, String type) {\r
83 super(id.getName(), id.getGuid(), id.getVersion(), id.getPath());\r
84 this.packageId = packageId;\r
85 this.moduleType = type;\r
86 }\r
fc87d0ba 87\r
88 public String toString() {\r
a13899c5 89 return "Module " + this.getName() + "[" + this.getGuid() + "] in package " + packageId;\r
90 }\r
91\r
92 public PackageIdentification getPackageId() {\r
93 return packageId;\r
94 }\r
95\r
96 public void setPackageId(PackageIdentification packageId) {\r
97 this.packageId = packageId;\r
98 }\r
92e29378 99\r
100 public String getModuleType() {\r
101 return moduleType;\r
102 }\r
103\r
104 public void setModuleType(String moduleType) {\r
105 this.moduleType = moduleType;\r
106 }\r
fc87d0ba 107\r
92e29378 108 private void setModuleType() {\r
109 ModuleSurfaceArea msa = null;\r
110 try {\r
111 msa = OpenFile.openMsaFile(this.getPath());\r
112 } catch (IOException e) {\r
113 // TODO Auto-generated catch block\r
fc87d0ba 114\r
92e29378 115 } catch (XmlException e) {\r
116 // TODO Auto-generated catch block\r
fc87d0ba 117\r
92e29378 118 } catch (Exception e) {\r
119 // TODO Auto-generated catch block\r
fc87d0ba 120\r
92e29378 121 }\r
122 setModuleType(DataType.MODULE_TYPE_MODULE);\r
123 setLibrary(false);\r
124 if (msa != null) {\r
125 LibraryClassDefinitions lib = msa.getLibraryClassDefinitions();\r
126 if (lib != null) {\r
127 for (int index = 0; index < lib.getLibraryClassList().size(); index++) {\r
128 if (lib.getLibraryClassList().get(index).getUsage().equals(LibraryUsage.ALWAYS_PRODUCED)) {\r
129 setModuleType(DataType.MODULE_TYPE_LIBRARY);\r
130 setLibrary(true);\r
131 break;\r
132 }\r
133 }\r
134 }\r
135 }\r
136 }\r
fc87d0ba 137\r
419558bb 138 public boolean equals(String moduleGuid, String moduleVersion, String packageGuid, String packageVersion) {\r
139 boolean b = false;\r
140 if (this.getGuid().equals(moduleGuid) && this.getPackageId().getGuid().equals(packageGuid)) {\r
141 b = true;\r
142 //\r
143 // Check Version\r
144 //\r
145 if (moduleVersion != null) {\r
146 if (!Tools.isEmpty(moduleVersion)) {\r
147 if (!moduleVersion.equals(this.getVersion())) {\r
148 b = false;\r
149 }\r
150 }\r
151 }\r
152 if (packageVersion != null) {\r
153 if (!Tools.isEmpty(packageVersion)) {\r
154 if (!packageVersion.equals(this.getPackageId().getVersion())) {\r
155 b = false;\r
156 }\r
157 }\r
158 }\r
159 }\r
160 return b;\r
161 }\r
92e29378 162\r
163 public boolean isLibrary() {\r
164 return isLibrary;\r
165 }\r
166\r
167 public void setLibrary(boolean isLibrary) {\r
168 this.isLibrary = isLibrary;\r
169 }\r
a13899c5 170}\r