Revision 37599 branches/v2_0_0_prep/extensions/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/src/main/java/org/gvsig/installer/lib/impl/DefaultDependency.java
DefaultDependency.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
public class DefaultDependency implements Dependency { |
11 | 11 |
|
12 |
private String type;
|
|
13 |
private String code;
|
|
14 |
private String op;
|
|
15 |
private Version version;
|
|
12 |
private String type;
|
|
13 |
private String code;
|
|
14 |
private String op;
|
|
15 |
private Version version;
|
|
16 | 16 |
|
17 |
public DefaultDependency() {
|
|
18 |
super();
|
|
19 |
clear();
|
|
20 |
}
|
|
17 |
public DefaultDependency() {
|
|
18 |
super();
|
|
19 |
clear();
|
|
20 |
}
|
|
21 | 21 |
|
22 |
public DefaultDependency(PackageInfo packageInfo) {
|
|
23 |
this();
|
|
24 |
this.code = packageInfo.getCode();
|
|
25 |
this.type = "required";
|
|
26 |
this.op = ">=";
|
|
27 |
this.version = packageInfo.getVersion();
|
|
28 |
}
|
|
22 |
public DefaultDependency(PackageInfo packageInfo) {
|
|
23 |
this();
|
|
24 |
this.code = packageInfo.getCode();
|
|
25 |
this.type = "required";
|
|
26 |
this.op = ">=";
|
|
27 |
this.version = packageInfo.getVersion();
|
|
28 |
}
|
|
29 | 29 |
|
30 |
public void clear() {
|
|
31 |
this.type = "required";
|
|
32 |
this.code = "unknow";
|
|
33 |
this.op = "=";
|
|
34 |
this.version = new DefaultVersion();
|
|
35 |
}
|
|
30 |
public void clear() {
|
|
31 |
this.type = "required";
|
|
32 |
this.code = "unknow";
|
|
33 |
this.op = "=";
|
|
34 |
this.version = new DefaultVersion();
|
|
35 |
}
|
|
36 | 36 |
|
37 |
public Dependency parse(String dependency) {
|
|
38 |
// Parse a string with the dependency specification
|
|
39 |
// (required|suggested|recommended|conflict)[:] code (=|>|<|>=|<=)
|
|
40 |
// version
|
|
41 |
if (dependency == null) {
|
|
42 |
this.clear();
|
|
43 |
return this;
|
|
44 |
}
|
|
45 |
dependency = dependency.trim();
|
|
46 |
if (dependency.equals("")) {
|
|
47 |
this.clear();
|
|
48 |
return this;
|
|
49 |
}
|
|
50 |
String s = dependency.replace(':', ' ');
|
|
51 |
s = s.replaceAll(" ", " ");
|
|
52 |
String[] x = s.split(" ");
|
|
53 |
if (x.length != 4) {
|
|
54 |
throw new InvalidDependencyFormatException(dependency);
|
|
55 |
}
|
|
56 |
this.type = x[0];
|
|
57 |
this.code = x[1];
|
|
58 |
this.op = x[2];
|
|
59 |
this.version.parse(x[3]);
|
|
60 |
return this;
|
|
61 |
}
|
|
37 |
public Dependency parse(String dependency) {
|
|
38 |
// Parse a string with the dependency specification
|
|
39 |
// (required|suggested|recommended|conflict)[:] code (=|>|<|>=|<=)
|
|
40 |
// version
|
|
41 |
if (dependency == null) {
|
|
42 |
this.clear();
|
|
43 |
return this;
|
|
44 |
}
|
|
45 |
dependency = dependency.trim();
|
|
46 |
if (dependency.equals("")) {
|
|
47 |
this.clear();
|
|
48 |
return this;
|
|
49 |
}
|
|
50 |
String s = dependency.replace(':', ' ');
|
|
51 |
s = s.replaceAll(" ", " ");
|
|
52 |
String[] x = s.split(" ");
|
|
53 |
if (x.length != 4) {
|
|
54 |
throw new InvalidDependencyFormatException(dependency);
|
|
55 |
}
|
|
56 |
this.type = x[0];
|
|
57 |
this.code = x[1];
|
|
58 |
this.op = x[2];
|
|
59 |
this.version.parse(x[3]);
|
|
60 |
return this;
|
|
61 |
}
|
|
62 | 62 |
|
63 |
private class InvalidDependencyFormatException extends BaseRuntimeException {
|
|
63 |
private class InvalidDependencyFormatException extends BaseRuntimeException {
|
|
64 | 64 |
|
65 |
private static final long serialVersionUID = 2856837862117653856L;
|
|
65 |
private static final long serialVersionUID = 2856837862117653856L;
|
|
66 | 66 |
|
67 |
private static final String message = |
|
68 |
"Error parsing dependecy '%(dependency)s'"; |
|
67 |
private static final String message = "Error parsing dependecy '%(dependency)s'"; |
|
69 | 68 |
|
70 |
private static final String KEY = |
|
71 |
"_Error_parsing_dependecy_XdependecyX"; |
|
69 |
private static final String KEY = "_Error_parsing_dependecy_XdependecyX"; |
|
72 | 70 |
|
73 |
public InvalidDependencyFormatException(String dependency) {
|
|
74 |
super(message, null, KEY, serialVersionUID);
|
|
75 |
setValue("dependency", dependency);
|
|
76 |
}
|
|
77 |
}
|
|
71 |
public InvalidDependencyFormatException(String dependency) {
|
|
72 |
super(message, null, KEY, serialVersionUID);
|
|
73 |
setValue("dependency", dependency);
|
|
74 |
}
|
|
75 |
}
|
|
78 | 76 |
|
79 |
public String getType() {
|
|
80 |
return this.type;
|
|
81 |
}
|
|
77 |
public String getType() {
|
|
78 |
return this.type;
|
|
79 |
}
|
|
82 | 80 |
|
83 |
public String getCode() {
|
|
84 |
return this.code;
|
|
85 |
}
|
|
81 |
public String getCode() {
|
|
82 |
return this.code;
|
|
83 |
}
|
|
86 | 84 |
|
87 |
public String getOp() {
|
|
88 |
return this.op;
|
|
89 |
}
|
|
85 |
public String getOp() {
|
|
86 |
return this.op;
|
|
87 |
}
|
|
90 | 88 |
|
91 |
public Version getVersion() {
|
|
92 |
return this.version;
|
|
93 |
}
|
|
89 |
public Version getVersion() {
|
|
90 |
return this.version;
|
|
91 |
}
|
|
94 | 92 |
|
95 |
public boolean match(String type, String code, Version version) {
|
|
96 |
if (!this.type.equalsIgnoreCase(type)) {
|
|
97 |
return false;
|
|
98 |
}
|
|
99 |
if (!this.code.equalsIgnoreCase(code)) {
|
|
100 |
return false;
|
|
101 |
}
|
|
102 |
return version.check(this.op, this.version);
|
|
103 |
}
|
|
93 |
public boolean match(String type, String code, Version version) {
|
|
94 |
if (!this.type.equalsIgnoreCase(type)) {
|
|
95 |
return false;
|
|
96 |
}
|
|
97 |
if (!this.code.equalsIgnoreCase(code)) {
|
|
98 |
return false;
|
|
99 |
}
|
|
100 |
return version.check(this.op, this.version);
|
|
101 |
}
|
|
104 | 102 |
|
105 |
public String toString() { |
|
106 |
return MessageFormat.format("{0}: {1} {2} {3}", this.type, this.code, |
|
107 |
this.op, this.version.toString()); |
|
108 |
} |
|
103 |
@Override |
|
104 |
public String toString() { |
|
105 |
return MessageFormat.format("{0}: {1} {2} {3}", this.type, this.code, |
|
106 |
this.op, this.version.toString()); |
|
107 |
} |
|
109 | 108 |
|
110 |
public Object clone() throws CloneNotSupportedException { |
|
111 |
DefaultDependency x = (DefaultDependency) super.clone(); |
|
112 |
x.version = (Version) this.version.clone(); |
|
113 |
return x; |
|
114 |
} |
|
109 |
@Override |
|
110 |
public Object clone() throws CloneNotSupportedException { |
|
111 |
DefaultDependency x = (DefaultDependency) super.clone(); |
|
112 |
x.version = (Version) this.version.clone(); |
|
113 |
return x; |
|
114 |
} |
|
115 | 115 |
|
116 |
public boolean equals(Object obj) { |
|
117 |
Dependency other; |
|
118 |
try { |
|
119 |
other = (Dependency) obj; |
|
120 |
} catch (Exception ex) { |
|
121 |
return false; |
|
122 |
} |
|
123 |
if (!this.code.equalsIgnoreCase(other.getCode())) { |
|
124 |
return false; |
|
125 |
} |
|
126 |
if (!this.type.equalsIgnoreCase(other.getType())) { |
|
127 |
return false; |
|
128 |
} |
|
129 |
if (!this.op.equalsIgnoreCase(other.getOp())) { |
|
130 |
return false; |
|
131 |
} |
|
132 |
if (!this.version.equals(other.getVersion())) { |
|
133 |
return false; |
|
134 |
} |
|
135 |
return true; |
|
136 |
} |
|
116 |
@Override |
|
117 |
public boolean equals(Object obj) { |
|
118 |
Dependency other; |
|
119 |
try { |
|
120 |
other = (Dependency) obj; |
|
121 |
} catch (Exception ex) { |
|
122 |
return false; |
|
123 |
} |
|
124 |
if (!this.code.equalsIgnoreCase(other.getCode())) { |
|
125 |
return false; |
|
126 |
} |
|
127 |
if (!this.type.equalsIgnoreCase(other.getType())) { |
|
128 |
return false; |
|
129 |
} |
|
130 |
if (!this.op.equalsIgnoreCase(other.getOp())) { |
|
131 |
return false; |
|
132 |
} |
|
133 |
if (!this.version.equals(other.getVersion())) { |
|
134 |
return false; |
|
135 |
} |
|
136 |
return true; |
|
137 |
} |
|
137 | 138 |
} |
Also available in: Unified diff