author | chegar |
Thu, 03 Feb 2011 11:56:56 +0000 | |
changeset 8169 | 0dc88a086893 |
child 10612 | 841791b02746 |
permissions | -rw-r--r-- |
8169
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
1 |
/* |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
2 |
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
4 |
* |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
8 |
* |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
13 |
* accompanied this code). |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
14 |
* |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
18 |
* |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
21 |
* questions. |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
22 |
*/ |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
23 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
24 |
/* |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
25 |
* @test |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
26 |
* @bug 6887710 |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
27 |
* @summary Verify the impact of sun.misc.JarIndex.metaInfFilenames on Service loaders |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
28 |
* @run main/othervm Basic |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
29 |
*/ |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
30 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
31 |
import java.io.IOException; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
32 |
import java.io.BufferedReader; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
33 |
import java.io.File; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
34 |
import java.io.FileInputStream; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
35 |
import java.io.InputStream; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
36 |
import java.io.InputStreamReader; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
37 |
import java.io.OutputStream; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
38 |
import java.net.InetSocketAddress; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
39 |
import java.net.URI; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
40 |
import java.net.URL; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
41 |
import java.net.URLClassLoader; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
42 |
import java.util.Arrays; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
43 |
import java.util.Iterator; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
44 |
import java.util.ServiceLoader; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
45 |
import com.sun.net.httpserver.Headers; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
46 |
import com.sun.net.httpserver.HttpExchange; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
47 |
import com.sun.net.httpserver.HttpHandler; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
48 |
import com.sun.net.httpserver.HttpServer; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
49 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
50 |
/** |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
51 |
* Verifies the impact of sun.misc.JarIndex.metaInfFilenames on service loaders |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
52 |
* (sun.misc.Service & java.util.ServiceLoader), as well as finding resources |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
53 |
* through Class.getResouce. |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
54 |
* |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
55 |
* 1) Compile the test sources: |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
56 |
* jarA: |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
57 |
* META-INF/services/my.happy.land |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
58 |
* com/message/spi/MessageService.java |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
59 |
* a/A.java |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
60 |
* jarB: |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
61 |
* META-INF/JAVA2.DS |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
62 |
* META-INF/services/no.name.service |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
63 |
* b/B.java |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
64 |
* jarC: |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
65 |
* META-INF/fonts.mf |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
66 |
* META-INF/fonts/Company-corporate.ttf |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
67 |
* META-INF/fonts/kidpr.ttf |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
68 |
* META-INF/services/com.message.spi.MessageService |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
69 |
* my/impl/StandardMessageService.java |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
70 |
* |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
71 |
* 2) Build three jar files a.jar, b.jar, c.jar |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
72 |
* |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
73 |
* 3) Create an index in a.jar (jar -i a.jar b.jar c.jar) |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
74 |
* with sun.misc.JarIndex.metaInfFilenames=true |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
75 |
* |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
76 |
* 4) Start a HTTP server serving out the three jars. |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
77 |
* |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
78 |
* The test then tries to locate services/resources within the jars using |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
79 |
* URLClassLoader. Each request to the HTTP server is recorded to ensure |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
80 |
* only the correct amount of requests are being made. |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
81 |
* |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
82 |
* Note: Needs jdk/lib/tools.jar in the classpath to compile and run. |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
83 |
*/ |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
84 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
85 |
public class Basic { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
86 |
static final String slash = File.separator; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
87 |
static final String[] testSources = { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
88 |
"jarA" + slash + "a" + slash + "A.java", |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
89 |
"jarA" + slash + "com" + slash + "message" + slash + "spi" + slash + "MessageService.java", |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
90 |
"jarB" + slash + "b" + slash + "B.java", |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
91 |
"jarC" + slash + "my" + slash + "impl" + slash + "StandardMessageService.java"}; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
92 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
93 |
static final String testSrc = System.getProperty("test.src"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
94 |
static final String testSrcDir = testSrc != null ? testSrc : "."; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
95 |
static final String testClasses = System.getProperty("test.classes"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
96 |
static final String testClassesDir = testClasses != null ? testClasses : "."; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
97 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
98 |
static JarHttpServer httpServer; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
99 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
100 |
public static void main(String[] args) throws Exception { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
101 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
102 |
// Set global url cache to false so that we can track every jar request. |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
103 |
(new URL("http://localhost/")).openConnection().setDefaultUseCaches(false); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
104 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
105 |
buildTest(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
106 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
107 |
try { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
108 |
httpServer = new JarHttpServer(testClassesDir); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
109 |
httpServer.start(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
110 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
111 |
doTest(httpServer.getAddress()); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
112 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
113 |
} catch (IOException ioe) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
114 |
ioe.printStackTrace(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
115 |
} finally { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
116 |
if (httpServer != null) { httpServer.stop(2); } |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
117 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
118 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
119 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
120 |
static void buildTest() { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
121 |
/* compile the source that will be used to generate the jars */ |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
122 |
for (int i=0; i<testSources.length; i++) |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
123 |
testSources[i] = testSrcDir + slash + testSources[i]; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
124 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
125 |
compile("-d" , testClassesDir, |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
126 |
"-sourcepath", testSrcDir, |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
127 |
testSources[0], testSources[1], testSources[2], testSources[3]); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
128 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
129 |
/* build the 3 jar files */ |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
130 |
jar("-cf", testClassesDir + slash + "a.jar", |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
131 |
"-C", testClassesDir, "a", |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
132 |
"-C", testClassesDir, "com", |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
133 |
"-C", testSrcDir + slash + "jarA", "META-INF"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
134 |
jar("-cf", testClassesDir + slash + "b.jar", |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
135 |
"-C", testClassesDir, "b", |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
136 |
"-C", testSrcDir + slash + "jarB", "META-INF"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
137 |
jar("-cf", testClassesDir + slash + "c.jar", |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
138 |
"-C", testClassesDir, "my", |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
139 |
"-C", testSrcDir + slash + "jarC", "META-INF"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
140 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
141 |
/* Create an index in a.jar for b.jar and c.jar */ |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
142 |
createIndex(testClassesDir); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
143 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
144 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
145 |
/* run jar <args> */ |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
146 |
static void jar(String... args) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
147 |
debug("Running: jar " + Arrays.toString(args)); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
148 |
sun.tools.jar.Main jar = new sun.tools.jar.Main(System.out, System.err, "jar"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
149 |
if (!jar.run(args)) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
150 |
throw new RuntimeException("jar failed: args=" + Arrays.toString(args)); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
151 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
152 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
153 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
154 |
/* run javac <args> */ |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
155 |
static void compile(String... args) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
156 |
debug("Running: javac " + Arrays.toString(args)); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
157 |
com.sun.tools.javac.main.Main compiler = new com.sun.tools.javac.main.Main("javac"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
158 |
if (compiler.compile(args) != 0) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
159 |
throw new RuntimeException("javac failed: args=" + Arrays.toString(args)); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
160 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
161 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
162 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
163 |
static String jar; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
164 |
static { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
165 |
String javaHome = System.getProperty("java.home"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
166 |
if (javaHome.endsWith("jre")) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
167 |
int index = javaHome.lastIndexOf(slash); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
168 |
if (index != -1) |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
169 |
javaHome = javaHome.substring(0, index); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
170 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
171 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
172 |
jar = javaHome + slash+ "bin" + slash + "jar"; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
173 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
174 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
175 |
/* create the index */ |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
176 |
static void createIndex(String workingDir) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
177 |
// ProcessBuilder is used so that the current directory can be set |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
178 |
// to the directory that directly contains the jars. |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
179 |
debug("Running jar to create the index"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
180 |
ProcessBuilder pb = new ProcessBuilder( |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
181 |
jar, "-J-Dsun.misc.JarIndex.metaInfFilenames=true", "-i", "a.jar", "b.jar", "c.jar"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
182 |
pb.directory(new File(workingDir)); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
183 |
//pd.inheritIO(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
184 |
try { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
185 |
Process p = pb.start(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
186 |
if(p.waitFor() != 0) |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
187 |
throw new RuntimeException("jar indexing failed"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
188 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
189 |
if(debug && p != null) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
190 |
String line = null; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
191 |
BufferedReader reader = |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
192 |
new BufferedReader(new InputStreamReader(p.getInputStream())); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
193 |
while((line = reader.readLine()) != null) |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
194 |
debug(line); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
195 |
reader = new BufferedReader(new InputStreamReader(p.getErrorStream())); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
196 |
while((line = reader.readLine()) != null) |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
197 |
debug(line); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
198 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
199 |
} catch(InterruptedException ie) { throw new RuntimeException(ie); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
200 |
} catch(IOException e) { throw new RuntimeException(e); } |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
201 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
202 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
203 |
static final boolean debug = true; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
204 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
205 |
static void debug(Object message) { if (debug) System.out.println(message); } |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
206 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
207 |
/* service define in c.jar */ |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
208 |
static final String messageService = "com.message.spi.MessageService"; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
209 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
210 |
/* a service that is not defined in any of the jars */ |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
211 |
static final String unknownService = "java.lang.Object"; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
212 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
213 |
static void doTest(InetSocketAddress serverAddress) throws IOException { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
214 |
URL baseURL = new URL("http://localhost:" + serverAddress.getPort() + "/"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
215 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
216 |
int failed = 0; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
217 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
218 |
// Tests using sun.misc.Service |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
219 |
if (!sunMiscServiceTest(baseURL, messageService, true, false, true)) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
220 |
System.out.println("Test: sun.misc.Service looking for " + messageService + ", failed"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
221 |
failed++; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
222 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
223 |
if (!sunMiscServiceTest(baseURL, unknownService, false, false, false)) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
224 |
System.out.println("Test: sun.misc.Service looking for " + unknownService + " failed"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
225 |
failed++; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
226 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
227 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
228 |
// Tests using java.util.SerivceLoader |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
229 |
if (!javaUtilServiceLoaderTest(baseURL, messageService, true, false, true)) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
230 |
System.out.println("Test: sun.misc.Service looking for " + messageService + ", failed"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
231 |
failed++; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
232 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
233 |
if (!javaUtilServiceLoaderTest(baseURL, unknownService, false, false, false)) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
234 |
System.out.println("Test: sun.misc.Service looking for " + unknownService + " failed"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
235 |
failed++; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
236 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
237 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
238 |
// Tests using java.lang.Class (similar to the FontManager in javafx) |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
239 |
if (!klassLoader(baseURL, "/META-INF/fonts.mf", true, false, true)) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
240 |
System.out.println("Test: klassLoader looking for /META-INF/fonts.mf failed"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
241 |
failed++; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
242 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
243 |
if (!klassLoader(baseURL, "/META-INF/unknown.mf", false, false, false)) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
244 |
System.out.println("Test: klassLoader looking for /META-INF/unknown.mf failed"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
245 |
failed++; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
246 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
247 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
248 |
if (failed > 0) |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
249 |
throw new RuntimeException("Failed: " + failed + " tests"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
250 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
251 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
252 |
static boolean sunMiscServiceTest(URL baseURL, |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
253 |
String serviceClass, |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
254 |
boolean expectToFind, |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
255 |
boolean expectbDotJar, |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
256 |
boolean expectcDotJar) throws IOException { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
257 |
debug("----------------------------------"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
258 |
debug("Running test with sun.misc.Service looking for " + serviceClass); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
259 |
URLClassLoader loader = getLoader(baseURL); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
260 |
httpServer.reset(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
261 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
262 |
Class messageServiceClass = null; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
263 |
try { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
264 |
messageServiceClass = loader.loadClass(serviceClass); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
265 |
} catch (ClassNotFoundException cnfe) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
266 |
System.err.println(cnfe); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
267 |
throw new RuntimeException("Error in test: " + cnfe); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
268 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
269 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
270 |
Iterator<Class<?>> iterator = sun.misc.Service.providers(messageServiceClass, loader); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
271 |
if (expectToFind && !iterator.hasNext()) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
272 |
debug(messageServiceClass + " NOT found."); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
273 |
return false; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
274 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
275 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
276 |
while (iterator.hasNext()) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
277 |
debug("found " + iterator.next() + " " + messageService); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
278 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
279 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
280 |
debug("HttpServer: " + httpServer); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
281 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
282 |
if (!expectbDotJar && httpServer.bDotJar > 0) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
283 |
debug("Unexpeced request sent to the httpserver for b.jar"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
284 |
return false; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
285 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
286 |
if (!expectcDotJar && httpServer.cDotJar > 0) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
287 |
debug("Unexpeced request sent to the httpserver for c.jar"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
288 |
return false; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
289 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
290 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
291 |
return true; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
292 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
293 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
294 |
static boolean javaUtilServiceLoaderTest(URL baseURL, |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
295 |
String serviceClass, |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
296 |
boolean expectToFind, |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
297 |
boolean expectbDotJar, |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
298 |
boolean expectcDotJar) throws IOException { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
299 |
debug("----------------------------------"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
300 |
debug("Running test with java.util.ServiceLoader looking for " + serviceClass); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
301 |
URLClassLoader loader = getLoader(baseURL); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
302 |
httpServer.reset(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
303 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
304 |
Class messageServiceClass = null; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
305 |
try { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
306 |
messageServiceClass = loader.loadClass(serviceClass); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
307 |
} catch (ClassNotFoundException cnfe) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
308 |
System.err.println(cnfe); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
309 |
throw new RuntimeException("Error in test: " + cnfe); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
310 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
311 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
312 |
Iterator<Class<?>> iterator = (ServiceLoader.load(messageServiceClass, loader)).iterator(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
313 |
if (expectToFind && !iterator.hasNext()) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
314 |
debug(messageServiceClass + " NOT found."); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
315 |
return false; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
316 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
317 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
318 |
while (iterator.hasNext()) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
319 |
debug("found " + iterator.next() + " " + messageService); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
320 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
321 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
322 |
debug("HttpServer: " + httpServer); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
323 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
324 |
if (!expectbDotJar && httpServer.bDotJar > 0) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
325 |
debug("Unexpeced request sent to the httpserver for b.jar"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
326 |
return false; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
327 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
328 |
if (!expectcDotJar && httpServer.cDotJar > 0) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
329 |
debug("Unexpeced request sent to the httpserver for c.jar"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
330 |
return false; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
331 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
332 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
333 |
return true; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
334 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
335 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
336 |
/* Tries to find a resource in a similar way to the font manager in javafx |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
337 |
* com.sun.javafx.scene.text.FontManager */ |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
338 |
static boolean klassLoader(URL baseURL, |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
339 |
String resource, |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
340 |
boolean expectToFind, |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
341 |
boolean expectbDotJar, |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
342 |
boolean expectcDotJar) throws IOException { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
343 |
debug("----------------------------------"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
344 |
debug("Running test looking for " + resource); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
345 |
URLClassLoader loader = getLoader(baseURL); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
346 |
httpServer.reset(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
347 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
348 |
Class ADotAKlass = null; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
349 |
try { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
350 |
ADotAKlass = loader.loadClass("a.A"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
351 |
} catch (ClassNotFoundException cnfe) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
352 |
System.err.println(cnfe); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
353 |
throw new RuntimeException("Error in test: " + cnfe); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
354 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
355 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
356 |
URL u = ADotAKlass.getResource(resource); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
357 |
if (expectToFind && u == null) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
358 |
System.out.println("Expected to find " + resource + " but didn't"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
359 |
return false; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
360 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
361 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
362 |
debug("HttpServer: " + httpServer); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
363 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
364 |
if (!expectbDotJar && httpServer.bDotJar > 0) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
365 |
debug("Unexpeced request sent to the httpserver for b.jar"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
366 |
return false; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
367 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
368 |
if (!expectcDotJar && httpServer.cDotJar > 0) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
369 |
debug("Unexpeced request sent to the httpserver for c.jar"); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
370 |
return false; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
371 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
372 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
373 |
return true; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
374 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
375 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
376 |
static URLClassLoader getLoader(URL baseURL) throws IOException { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
377 |
ClassLoader loader = Basic.class.getClassLoader(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
378 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
379 |
while (loader.getParent() != null) |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
380 |
loader = loader.getParent(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
381 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
382 |
return new URLClassLoader( new URL[]{ |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
383 |
new URL(baseURL, "a.jar"), |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
384 |
new URL(baseURL, "b.jar"), |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
385 |
new URL(baseURL, "c.jar")}, loader ); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
386 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
387 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
388 |
/** |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
389 |
* HTTP Server to server the jar files. |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
390 |
*/ |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
391 |
static class JarHttpServer implements HttpHandler { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
392 |
final String docsDir; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
393 |
final HttpServer httpServer; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
394 |
int aDotJar, bDotJar, cDotJar; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
395 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
396 |
JarHttpServer(String docsDir) throws IOException { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
397 |
this.docsDir = docsDir; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
398 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
399 |
httpServer = HttpServer.create(new InetSocketAddress(0), 0); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
400 |
httpServer.createContext("/", this); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
401 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
402 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
403 |
void start() throws IOException { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
404 |
httpServer.start(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
405 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
406 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
407 |
void stop(int delay) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
408 |
httpServer.stop(delay); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
409 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
410 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
411 |
InetSocketAddress getAddress() { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
412 |
return httpServer.getAddress(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
413 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
414 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
415 |
void reset() { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
416 |
aDotJar = bDotJar = cDotJar = 0; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
417 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
418 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
419 |
@Override |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
420 |
public String toString() { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
421 |
return "aDotJar=" + aDotJar + ", bDotJar=" + bDotJar + ", cDotJar=" + cDotJar; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
422 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
423 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
424 |
public void handle(HttpExchange t) throws IOException { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
425 |
InputStream is = t.getRequestBody(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
426 |
Headers map = t.getRequestHeaders(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
427 |
Headers rmap = t.getResponseHeaders(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
428 |
URI uri = t.getRequestURI(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
429 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
430 |
debug("Server: received request for " + uri); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
431 |
String path = uri.getPath(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
432 |
if (path.endsWith("a.jar")) |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
433 |
aDotJar++; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
434 |
else if (path.endsWith("b.jar")) |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
435 |
bDotJar++; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
436 |
else if (path.endsWith("c.jar")) |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
437 |
cDotJar++; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
438 |
else |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
439 |
System.out.println("Unexpected resource request" + path); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
440 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
441 |
while (is.read() != -1); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
442 |
is.close(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
443 |
|
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
444 |
File file = new File(docsDir, path); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
445 |
if (!file.exists()) |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
446 |
throw new RuntimeException("Error: request for " + file); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
447 |
long clen = file.length(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
448 |
t.sendResponseHeaders (200, clen); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
449 |
OutputStream os = t.getResponseBody(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
450 |
FileInputStream fis = new FileInputStream(file); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
451 |
try { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
452 |
byte[] buf = new byte [16 * 1024]; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
453 |
int len; |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
454 |
while ((len=fis.read(buf)) != -1) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
455 |
os.write (buf, 0, len); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
456 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
457 |
} catch (IOException e) { |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
458 |
e.printStackTrace(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
459 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
460 |
fis.close(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
461 |
os.close(); |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
462 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
463 |
} |
0dc88a086893
6887710: Jar index should avoid putting META-INF in the INDEX.LIST
chegar
parents:
diff
changeset
|
464 |
} |