1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.classloader.internal.protocol.jar; |
21 |
|
|
22 |
|
import java.io.FileNotFoundException; |
23 |
|
import java.io.IOException; |
24 |
|
import java.io.InputStream; |
25 |
|
import java.io.UnsupportedEncodingException; |
26 |
|
import java.net.MalformedURLException; |
27 |
|
import java.net.URL; |
28 |
|
import java.net.URLDecoder; |
29 |
|
import java.net.URLStreamHandlerFactory; |
30 |
|
import java.security.Permission; |
31 |
|
import java.util.jar.Attributes; |
32 |
|
import java.util.jar.JarEntry; |
33 |
|
import java.util.jar.JarFile; |
34 |
|
import java.util.jar.Manifest; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@version |
49 |
|
@since |
50 |
|
|
|
|
| 44.9% |
Uncovered Elements: 38 (69) |
Complexity: 23 |
Complexity Density: 0.57 |
|
51 |
|
public class JarURLConnection extends java.net.URLConnection implements org.xwiki.classloader.internal.JarURLConnection |
52 |
|
{ |
53 |
|
private URLStreamHandlerFactory handlerFactory; |
54 |
|
|
55 |
|
final JarOpener opener; |
56 |
|
|
57 |
|
boolean connected; |
58 |
|
|
59 |
|
JarFile jfile; |
60 |
|
|
61 |
|
JarEntry jentry; |
62 |
|
|
63 |
|
private URL jarFileURL; |
64 |
|
|
65 |
|
private String entryName; |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
67 |
6 |
public JarURLConnection(URL url, JarOpener opener, URLStreamHandlerFactory handlerFactory) throws IOException... |
68 |
|
{ |
69 |
6 |
super(url); |
70 |
6 |
this.opener = opener; |
71 |
6 |
this.handlerFactory = handlerFactory; |
72 |
6 |
parseSpecs(url); |
73 |
|
} |
74 |
|
|
|
|
| 42.9% |
Uncovered Elements: 8 (14) |
Complexity: 5 |
Complexity Density: 0.62 |
|
75 |
6 |
@Override... |
76 |
|
public synchronized void connect() throws IOException |
77 |
|
{ |
78 |
6 |
if (this.connected) { |
79 |
0 |
return; |
80 |
|
} |
81 |
6 |
this.jfile = this.opener.openJarFile(this); |
82 |
5 |
if (this.jfile != null && getEntryName() != null) { |
83 |
0 |
this.jentry = this.jfile.getJarEntry(getEntryName()); |
84 |
0 |
if (this.jentry == null) { |
85 |
0 |
throw new FileNotFoundException("Entry " + getEntryName() + " not found in " + getJarFileURL()); |
86 |
|
} |
87 |
|
} |
88 |
5 |
this.connected = true; |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
91 |
6 |
@Override... |
92 |
|
public synchronized JarFile getJarFile() throws IOException |
93 |
|
{ |
94 |
6 |
connect(); |
95 |
5 |
return this.jfile; |
96 |
|
} |
97 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
98 |
0 |
public synchronized JarEntry getJarEntry() throws IOException... |
99 |
|
{ |
100 |
0 |
connect(); |
101 |
0 |
return this.jentry; |
102 |
|
} |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
104 |
0 |
@Override... |
105 |
|
public synchronized InputStream getInputStream() throws IOException |
106 |
|
{ |
107 |
0 |
connect(); |
108 |
0 |
return this.jfile.getInputStream(this.jentry); |
109 |
|
} |
110 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
111 |
6 |
@Override... |
112 |
|
public Permission getPermission() throws IOException |
113 |
|
{ |
114 |
6 |
return getJarFileURL().openConnection().getPermission(); |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
|
|
| 56.2% |
Uncovered Elements: 7 (16) |
Complexity: 4 |
Complexity Density: 0.33 |
|
120 |
6 |
private void parseSpecs(URL url) throws MalformedURLException... |
121 |
|
{ |
122 |
6 |
String spec = url.getFile(); |
123 |
|
|
124 |
6 |
int separator = spec.indexOf('!'); |
125 |
|
|
126 |
|
|
127 |
|
|
128 |
6 |
if (separator == -1) { |
129 |
0 |
throw new MalformedURLException("no ! found in url spec:" + spec); |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
6 |
String protocol = spec.substring(0, spec.indexOf(":")); |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
6 |
this.jarFileURL = |
138 |
|
new URL(null, spec.substring(0, separator++), this.handlerFactory.createURLStreamHandler(protocol)); |
139 |
6 |
this.entryName = null; |
140 |
|
|
141 |
|
|
142 |
6 |
if (++separator != spec.length()) { |
143 |
0 |
this.entryName = spec.substring(separator, spec.length()); |
144 |
0 |
try { |
145 |
|
|
146 |
|
|
147 |
0 |
this.entryName = URLDecoder.decode(this.entryName, "UTF-8"); |
148 |
|
} catch (UnsupportedEncodingException e) { |
149 |
|
|
150 |
|
|
151 |
0 |
throw new RuntimeException("Failed to URL decode [" + this.entryName + "] using UTF-8.", e); |
152 |
|
} |
153 |
|
} |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
@return |
160 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
161 |
12 |
public URL getJarFileURL()... |
162 |
|
{ |
163 |
12 |
return this.jarFileURL; |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
@return |
171 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
172 |
5 |
public String getEntryName()... |
173 |
|
{ |
174 |
5 |
return this.entryName; |
175 |
|
} |
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
@return |
181 |
|
@exception |
182 |
|
@see |
183 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
184 |
0 |
public Manifest getManifest() throws IOException... |
185 |
|
{ |
186 |
0 |
return getJarFile().getManifest(); |
187 |
|
} |
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
@return |
193 |
|
@exception |
194 |
|
@see |
195 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
196 |
0 |
public Attributes getAttributes() throws IOException... |
197 |
|
{ |
198 |
0 |
JarEntry e = getJarEntry(); |
199 |
0 |
return e != null ? e.getAttributes() : null; |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
@return |
206 |
|
@exception |
207 |
|
@see |
208 |
|
@see |
209 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
210 |
0 |
public Attributes getMainAttributes() throws IOException... |
211 |
|
{ |
212 |
0 |
Manifest man = getManifest(); |
213 |
0 |
return man != null ? man.getMainAttributes() : null; |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
@return |
222 |
|
@exception |
223 |
|
@see |
224 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
225 |
0 |
public java.security.cert.Certificate[] getCertificates() throws IOException... |
226 |
|
{ |
227 |
0 |
JarEntry e = getJarEntry(); |
228 |
0 |
return e != null ? e.getCertificates() : null; |
229 |
|
} |
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
@author |
237 |
|
@version |
238 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
239 |
|
public static interface JarOpener |
240 |
|
{ |
241 |
|
|
242 |
|
|
243 |
|
@link |
244 |
|
|
245 |
|
@param |
246 |
|
@return |
247 |
|
@throws |
248 |
|
|
249 |
|
public JarFile openJarFile(JarURLConnection conn) throws IOException; |
250 |
|
} |
251 |
|
} |