1 package org.codehaus.mojo.webstart;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.Artifact;
23
24
25
26
27
28
29
30
31
32 public class ResolvedJarResource
33 {
34
35
36
37 private final JarResource jarResource;
38
39
40
41
42 private final Artifact artifact;
43
44
45
46
47 private String hrefValue;
48
49 public ResolvedJarResource( Artifact artifact )
50 {
51 this( new JarResource(), artifact );
52 }
53
54 public ResolvedJarResource( JarResource jarResource, Artifact artifact )
55 {
56 if ( artifact == null )
57 {
58 throw new IllegalArgumentException( "artifact must not be null" );
59 }
60 if ( jarResource == null )
61 {
62 throw new IllegalArgumentException( "jarResource must not be null" );
63 }
64 this.jarResource = jarResource;
65 this.artifact = artifact;
66 setHrefValue( jarResource.getHrefValue() );
67 }
68
69 public String getArtifactId()
70 {
71 return artifact.getArtifactId();
72 }
73
74 public String getType()
75 {
76 return artifact.getType();
77 }
78
79 public String getClassifier()
80 {
81 return artifact.getClassifier();
82 }
83
84 public String getGroupId()
85 {
86 return artifact.getGroupId();
87 }
88
89 public String getVersion()
90 {
91 return artifact.getVersion();
92 }
93
94 public String getMainClass()
95 {
96 return jarResource.getMainClass();
97 }
98
99 public boolean isOutputJarVersion()
100 {
101 return jarResource.isOutputJarVersion();
102 }
103
104 public boolean isIncludeInJnlp()
105 {
106 return jarResource.isIncludeInJnlp();
107 }
108
109
110
111
112
113
114 public Artifact getArtifact()
115 {
116 return artifact;
117 }
118
119
120
121
122
123
124
125
126 public String getHrefValue()
127 {
128 String result;
129 if ( hrefValue == null && getArtifact() != null )
130 {
131
132 result = getArtifact().getFile().getName();
133 }
134 else
135 {
136
137 result = hrefValue;
138 }
139 return result;
140 }
141
142
143
144
145
146
147
148
149 public void setHrefValue( String hrefValue )
150 {
151 this.hrefValue = hrefValue;
152 }
153
154
155
156
157
158
159
160
161 @Override
162 public boolean equals( Object obj )
163 {
164
165 if ( obj == this )
166 {
167 return true;
168 }
169
170 if ( !( obj instanceof ResolvedJarResource ) )
171 {
172 return false;
173 }
174
175 ResolvedJarResource other = (ResolvedJarResource) obj;
176
177 if ( fieldsAreNotEqual( getGroupId(), other.getGroupId() ) )
178 {
179 return false;
180 }
181
182 if ( fieldsAreNotEqual( getArtifactId(), other.getArtifactId() ) )
183 {
184 return false;
185 }
186
187 if ( fieldsAreNotEqual( getVersion(), other.getVersion() ) )
188 {
189 return false;
190 }
191
192 if ( fieldsAreNotEqual( getType(), other.getType() ) )
193 {
194 return false;
195 }
196
197 if ( fieldsAreNotEqual( getClassifier(), other.getClassifier() ) )
198 {
199 return false;
200 }
201
202 return true;
203
204 }
205
206 private boolean fieldsAreNotEqual( Object field1, Object field2 )
207 {
208
209 if ( field1 == null )
210 {
211 return field2 != null;
212 }
213 else
214 {
215 return !field1.equals( field2 );
216 }
217
218 }
219
220
221
222
223 public int hashCode()
224 {
225 final int offset = 17;
226 final int multiplier = 37;
227 int result = offset;
228 result += multiplier * fieldHashCode( getGroupId() );
229 result += multiplier * fieldHashCode( getArtifactId() );
230 result += multiplier * fieldHashCode( getVersion() );
231 result += multiplier * fieldHashCode( getType() );
232 result += multiplier * fieldHashCode( getClassifier() );
233 return result;
234
235 }
236
237 private int fieldHashCode( Object field )
238 {
239 return field == null ? 0 : field.hashCode();
240 }
241 }
242