- Move global declarations from AutoGen.c to AutoGen.h
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / id / ModuleIdentification.java
1 /** @file
2 This file is to define ModuleIdentification class.
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
14 package org.tianocore.build.id;
15
16 import java.io.File;
17
18 /**
19 This class is used to identify a module with Module Guid, Module Version,
20 Package Guid, Package Version.
21
22 @since GenBuild 1.0
23 **/
24 public class ModuleIdentification extends Identification {
25
26 private PackageIdentification packageId;
27
28 private File msaFile;
29
30 private String moduleType;
31
32 private boolean isLibrary = false;
33
34 private boolean isBinary = false;
35
36 private String constructor = "";
37
38 private String destructor = "";
39
40 /**
41 @param guid Guid
42 @param version Version
43 **/
44 public ModuleIdentification(String guid, String version){
45 super(guid, version);
46 }
47
48 /**
49 @param guid Guid
50 @param version Version
51 @param packageId Package Identification
52 **/
53 public ModuleIdentification(String guid, String version, PackageIdentification packageId){
54 super(guid, version);
55 this.packageId = packageId;
56 }
57
58 /**
59 @param name Name
60 @param guid Guid
61 @param version Version
62 **/
63 public ModuleIdentification(String name, String guid, String version){
64 super(name, guid, version);
65 }
66
67 /**
68 @param name Name
69 @param guid Guid
70 @param version Version
71 @param packageId PackageIdentification
72 **/
73 public ModuleIdentification(String name, String guid, String version, PackageIdentification packageId){
74 super(name, guid, version);
75 this.packageId = packageId;
76 }
77
78 /**
79 @return boolean is this module is library
80 **/
81 public boolean isLibrary() {
82 return isLibrary;
83 }
84
85 /**
86 @param isLibrary
87 **/
88 public void setLibrary(boolean isLibrary) {
89 this.isLibrary = isLibrary;
90 }
91
92 /**
93 @return boolean is this module is binary
94 **/
95 public boolean isBinary() {
96 return isBinary;
97 }
98
99 /**
100 @param isBinary
101 **/
102 public void setBinary(boolean isBinary) {
103 this.isBinary = isBinary;
104 }
105
106 /**
107 @return MSA File
108 **/
109 public File getMsaFile() {
110 return msaFile;
111 }
112
113 /**
114 @return Module relative path to package
115 **/
116 public String getModuleRelativePath() {
117 if (msaFile.getParent().length() == packageId.getPackageDir().length()) {
118 return ".";
119 }
120 return msaFile.getParent().substring(packageId.getPackageDir().length() + 1);
121 }
122
123 /**
124 @param msaFile Set Msa File
125 **/
126 public void setMsaFile(File msaFile) {
127 this.msaFile = msaFile;
128 }
129
130 public boolean equals(Object obj) {
131 if (obj instanceof ModuleIdentification) {
132 ModuleIdentification id = (ModuleIdentification)obj;
133 if (guid.equalsIgnoreCase(id.getGuid()) && packageId.equals(id.getPackage())) {
134 if (version == null || id.version == null) {
135 return true;
136 }
137 else if (version.trim().equalsIgnoreCase("") || id.version.trim().equalsIgnoreCase("")){
138 return true;
139 }
140 else if (version.equalsIgnoreCase(id.version)) {
141 return true;
142 }
143 }
144 return false;
145 }
146 else {
147 return super.equals(obj);
148 }
149 }
150
151 public String toString() {
152 String nameString;
153 String versionString;
154 String packageString;
155
156 if (name != null && name != "") {
157 nameString = name;
158 } else {
159 if (guid != null && guid != "") {
160 nameString = guid;
161 } else {
162 nameString = "UNKNOWN";
163 }
164 }
165
166 if (version != null) {
167 versionString = version;
168 } else {
169 versionString = "";
170 }
171
172 if (packageId != null) {
173 packageString = packageId.toString();
174 } else {
175 packageString = "Package [UNKNOWN]";
176 }
177
178 return "Module [" + nameString + versionString + "] in " + packageString;
179 }
180
181 /**
182 @param packageId set package identification
183 **/
184 public void setPackage(PackageIdentification packageId) {
185 this.packageId = packageId;
186 }
187
188 /**
189 @return get package identification
190 **/
191 public PackageIdentification getPackage() {
192 return packageId;
193 }
194
195 /**
196 @return get module type
197 **/
198 public String getModuleType() {
199 return moduleType;
200 }
201
202 /**
203 @param moduleType set module type
204 **/
205 public void setModuleType(String moduleType) {
206 this.moduleType = moduleType;
207 }
208
209 /**
210 @return String The module name
211 **/
212 public String getName() {
213 return name;
214 }
215
216 /**
217 @return boolean
218 **/
219 public boolean hasConstructor() {
220 return constructor != "";
221 }
222
223 /**
224 @return boolean
225 */
226 public boolean hasDestructor() {
227 return destructor != "";
228 }
229
230 /**
231 Set the constructor function name if this module is a library
232
233 @param name
234 */
235 public void setConstructor(String name) {
236 if (name != null) {
237 constructor = name;
238 }
239 }
240
241 /**
242 Set the destructor function name if this module is a library
243
244 @param name
245 */
246 public void setDestructor(String name) {
247 if (name != null) {
248 destructor = name;
249 }
250 }
251 }