Remove additional / or \ in relative path.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / id / PackageIdentification.java
1 /** @file
2 This file is to define PackageIdentification 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 import java.io.File;
16
17 import org.tianocore.build.global.GlobalData;
18
19 public class PackageIdentification extends Identification{
20
21 //
22 // It is optional
23 //
24 private File spdFile;
25
26 public PackageIdentification(String guid, String version){
27 super(guid, version);
28 }
29
30 public PackageIdentification(String name, String guid, String version){
31 super(name, guid, version);
32 }
33
34 public PackageIdentification(String name, String guid, String version, String spdFilename){
35 super(name, guid, version);
36 this.spdFile = new File(spdFilename);
37 }
38
39 public PackageIdentification(String name, String guid, String version, File spdFile){
40 super(name, guid, version);
41 this.spdFile = spdFile;
42 }
43
44 public void setSpdFile(File spdFile) {
45 this.spdFile = spdFile;
46 }
47
48 public File getSpdFile() {
49 return spdFile;
50 }
51
52 public String toString(){
53 if (name == null) {
54 GlobalData.refreshPackageIdentification(this);
55 }
56 if (version == null || version.trim().equalsIgnoreCase("")) {
57 return "package [" + name + "]";
58 }
59 else {
60 return "package [" + name + " " + version + "]";
61 }
62 }
63
64 public String getPackageDir(){
65 prepareSpdFile();
66 return spdFile.getParent();
67 }
68
69 public String getPackageRelativeDir(){
70 prepareSpdFile();
71 String relativeDir =spdFile.getParent().substring(GlobalData.getWorkspacePath().length());
72 if(relativeDir.startsWith("\\") || relativeDir.startsWith("/")) {
73 relativeDir = relativeDir.substring(1);
74 }
75 return relativeDir;
76 }
77
78 private void prepareSpdFile(){
79 if (spdFile == null) {
80 GlobalData.refreshPackageIdentification(this);
81 }
82 }
83
84 public String getName() {
85 if (name == null) {
86 GlobalData.refreshPackageIdentification(this);
87 }
88 return name;
89 }
90 }