author | jlaskey |
Wed, 11 May 2016 16:17:45 -0300 | |
changeset 37893 | f1cc7d17e66b |
parent 36511 | jdk/test/tools/jlink/plugins/SorterPluginTest.java@9d0388c6b336 |
child 38320 | e24c7029e8ba |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @summary Test sorter plugin |
|
27 |
* @author Jean-Francois Denise |
|
28 |
* @modules jdk.jlink/jdk.tools.jlink.internal |
|
29 |
* jdk.jlink/jdk.tools.jlink.internal.plugins |
|
37893
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
30 |
* @run main OrderResourcesPluginTest |
36511 | 31 |
*/ |
32 |
||
33 |
import java.io.File; |
|
34 |
import java.nio.file.Files; |
|
35 |
import java.util.Arrays; |
|
36 |
import java.util.Collection; |
|
37 |
import java.util.HashMap; |
|
38 |
import java.util.Map; |
|
39 |
import jdk.tools.jlink.internal.PoolImpl; |
|
40 |
||
37893
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
41 |
import jdk.tools.jlink.internal.plugins.OrderResourcesPlugin; |
36511 | 42 |
import jdk.tools.jlink.plugin.Pool; |
43 |
import jdk.tools.jlink.plugin.Pool.ModuleData; |
|
44 |
import jdk.tools.jlink.plugin.TransformerPlugin; |
|
45 |
||
37893
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
46 |
public class OrderResourcesPluginTest { |
36511 | 47 |
|
48 |
public static void main(String[] args) throws Exception { |
|
37893
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
49 |
new OrderResourcesPluginTest().test(); |
36511 | 50 |
} |
51 |
||
52 |
public void test() throws Exception { |
|
53 |
ModuleData[] array = { |
|
37893
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
54 |
Pool.newResource("/module1/toto1.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
55 |
Pool.newResource("/module2/toto2.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
56 |
Pool.newResource("/module3/toto3.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
57 |
Pool.newResource("/module3/toto3/module-info.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
58 |
Pool.newResource("/zazou/toto.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
59 |
Pool.newResource("/module4/zazou.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
60 |
Pool.newResource("/module5/toto5.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
61 |
Pool.newResource("/module6/toto6/module-info.class", new byte[0]) |
36511 | 62 |
}; |
63 |
||
64 |
ModuleData[] sorted = { |
|
37893
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
65 |
Pool.newResource("/zazou/toto.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
66 |
Pool.newResource("/module3/toto3/module-info.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
67 |
Pool.newResource("/module6/toto6/module-info.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
68 |
Pool.newResource("/module1/toto1.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
69 |
Pool.newResource("/module2/toto2.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
70 |
Pool.newResource("/module3/toto3.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
71 |
Pool.newResource("/module4/zazou.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
72 |
Pool.newResource("/module5/toto5.class", new byte[0]) |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
73 |
}; |
36511 | 74 |
|
75 |
ModuleData[] sorted2 = { |
|
37893
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
76 |
Pool.newResource("/module5/toto5.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
77 |
Pool.newResource("/module6/toto6/module-info.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
78 |
Pool.newResource("/module4/zazou.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
79 |
Pool.newResource("/module3/toto3.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
80 |
Pool.newResource("/module3/toto3/module-info.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
81 |
Pool.newResource("/module1/toto1.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
82 |
Pool.newResource("/module2/toto2.class", new byte[0]), |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
83 |
Pool.newResource("/zazou/toto.class", new byte[0]) |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
84 |
}; |
36511 | 85 |
|
86 |
Pool resources = new PoolImpl(); |
|
87 |
for (ModuleData r : array) { |
|
88 |
resources.add(r); |
|
89 |
} |
|
90 |
||
91 |
{ |
|
92 |
Pool out = new PoolImpl(); |
|
93 |
Map<String, String> config = new HashMap<>(); |
|
37893
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
94 |
config.put(OrderResourcesPlugin.NAME, "/zazou/*,*/module-info.class"); |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
95 |
TransformerPlugin p = new OrderResourcesPlugin(); |
36511 | 96 |
p.configure(config); |
97 |
p.visit(resources, out); |
|
98 |
check(out.getContent(), sorted); |
|
99 |
} |
|
100 |
||
101 |
{ |
|
102 |
// Order of resources in the file, then un-ordered resources. |
|
103 |
File order = new File("resources.order"); |
|
104 |
order.createNewFile(); |
|
105 |
StringBuilder builder = new StringBuilder(); |
|
106 |
// 5 first resources come from file |
|
107 |
for (int i = 0; i < 5; i++) { |
|
37893
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
108 |
String path = sorted2[i].getPath(); |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
109 |
int index = path.indexOf('/', 1); |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
110 |
path = path.substring(index + 1, path.length() - ".class".length()); |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
111 |
builder.append(path).append("\n"); |
36511 | 112 |
} |
113 |
Files.write(order.toPath(), builder.toString().getBytes()); |
|
114 |
||
115 |
Pool out = new PoolImpl(); |
|
116 |
Map<String, String> config = new HashMap<>(); |
|
37893
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
117 |
config.put(OrderResourcesPlugin.NAME, "@" + order.getAbsolutePath()); |
f1cc7d17e66b
8156781: change to jlink has result in test failure
jlaskey
parents:
36511
diff
changeset
|
118 |
TransformerPlugin p = new OrderResourcesPlugin(); |
36511 | 119 |
p.configure(config); |
120 |
p.visit(resources, out); |
|
121 |
check(out.getContent(), sorted2); |
|
122 |
||
123 |
} |
|
124 |
} |
|
125 |
||
126 |
private void check(Collection<ModuleData> outResources, |
|
127 |
ModuleData[] sorted) { |
|
128 |
if (outResources.size() != sorted.length) { |
|
129 |
throw new AssertionError("Wrong number of resources:\n" |
|
130 |
+ "expected: " + Arrays.toString(sorted) + ",\n" |
|
131 |
+ " got: " + outResources); |
|
132 |
} |
|
133 |
int i = 0; |
|
134 |
for (ModuleData r : outResources) { |
|
135 |
System.err.println("Resource: " + r); |
|
136 |
if (!sorted[i].getPath().equals(r.getPath())) { |
|
137 |
throw new AssertionError("Resource not properly sorted, difference at: " + i + "\n" |
|
138 |
+ "expected: " + Arrays.toString(sorted) + ",\n" |
|
139 |
+ " got: " + outResources); |
|
140 |
} |
|
141 |
i++; |
|
142 |
} |
|
143 |
} |
|
144 |
} |