-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathIntegrationTest1.java
More file actions
273 lines (229 loc) · 9.4 KB
/
IntegrationTest1.java
File metadata and controls
273 lines (229 loc) · 9.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
* Copyright (c) 2016, 2018, Player, asie
* Copyright (c) 2021, FabricMC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.fabricmc.tinyremapper;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Set;
import java.util.jar.JarFile;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Opcodes;
public class IntegrationTest1 {
private static final String MAPPING1_PATH = "/mapping/mapping1.tiny";
private static final String BASIC_INPUT_PATH = "/integration/basic/input.jar";
private static final String MRJ1_INPUT_PATH = "/integration/mrj1/input.jar";
private static final String MRJ2_INPUT_PATH = "/integration/mrj2/input.jar";
@TempDir
static Path folder;
@BeforeAll
public static void setup() throws IOException {
TestUtil.folder = folder;
TestUtil.copyFile(IntegrationTest1.class, MAPPING1_PATH);
TestUtil.copyFile(IntegrationTest1.class, BASIC_INPUT_PATH);
TestUtil.copyFile(IntegrationTest1.class, MRJ1_INPUT_PATH);
TestUtil.copyFile(IntegrationTest1.class, MRJ2_INPUT_PATH);
}
private TinyRemapper setupRemapper() {
// copy from Main.java
final boolean ignoreFieldDesc = false;
final boolean propagatePrivate = false;
final boolean removeFrames = false;
final Set<String> forcePropagation = Collections.emptySet();
final File forcePropagationFile = null;
final boolean ignoreConflicts = false;
final boolean checkPackageAccess = false;
final boolean fixPackageAccess = false;
final boolean resolveMissing = false;
final boolean rebuildSourceFilenames = false;
final boolean skipLocalVariableMapping = false;
final boolean renameInvalidLocals = false;
final int threads = -1;
final String from = "a";
final String to = "b";
Path mappings = TestUtil.getFile(IntegrationTest1.MAPPING1_PATH).toPath();
return TinyRemapper.newRemapper()
.withMappings(TinyUtils.createTinyMappingProvider(mappings, from, to))
.ignoreFieldDesc(ignoreFieldDesc)
.withForcedPropagation(forcePropagation)
.propagatePrivate(propagatePrivate)
.removeFrames(removeFrames)
.ignoreConflicts(ignoreConflicts)
.checkPackageAccess(checkPackageAccess)
.fixPackageAccess(fixPackageAccess)
.resolveMissing(resolveMissing)
.rebuildSourceFilenames(rebuildSourceFilenames)
.skipLocalVariableMapping(skipLocalVariableMapping)
.renameInvalidLocals(renameInvalidLocals)
.threads(threads)
.build();
}
/**
* This is a simple remap test that only remap a name of class.
*
* @throws IOException io failure.
*/
@Test
public void basic() throws IOException {
try (TinyRemapper remapper = setupRemapper()) {
final NonClassCopyMode ncCopyMode = NonClassCopyMode.FIX_META_INF;
final Path[] classpath = new Path[]{};
Path output = TestUtil.output(BASIC_INPUT_PATH);
Path input = TestUtil.input(BASIC_INPUT_PATH);
try (OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(output).build()) {
outputConsumer.addNonClassFiles(input, ncCopyMode, remapper);
remapper.readInputs(input);
remapper.readClassPath(classpath);
remapper.apply(outputConsumer);
} catch (IOException e) {
throw new RuntimeException(e);
}
final String MAIN_CLASS = "com/github/logicf/Main.class";
final String GREETING_CLASS = "com/github/logicf/Greeting.class";
try (JarFile result = new JarFile(output.toFile())) {
assertNotNull(result.getEntry(MAIN_CLASS));
assertNotNull(result.getEntry(GREETING_CLASS));
}
}
}
/**
* This is a simple remap test for a Multi-Release Jar.
*
* @throws IOException io failure.
*/
@Test
public void mrj1() throws IOException {
Path output = TestUtil.output(MRJ1_INPUT_PATH);
Path input = TestUtil.input(MRJ1_INPUT_PATH);
try (TinyRemapper remapper = setupRemapper()) {
final NonClassCopyMode ncCopyMode = NonClassCopyMode.FIX_META_INF;
final Path[] classpath = new Path[]{};
try (OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(output).build()) {
outputConsumer.addNonClassFiles(input, ncCopyMode, remapper);
remapper.readInputs(input);
remapper.readClassPath(classpath);
remapper.apply(outputConsumer);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
final String MAIN_CLASS = "com/github/logicf/Main.class";
final String GREETING_CLASS = "com/github/logicf/Greeting.class";
final String MRJ_GREETING_CLASS = "META-INF/versions/9/com/github/logicf/Greeting.class";
try (JarFile result = new JarFile(output.toFile())) {
assertNotNull(result.getEntry(MAIN_CLASS));
assertNotNull(result.getEntry(GREETING_CLASS));
assertNotNull(result.getEntry(MRJ_GREETING_CLASS));
}
}
/**
* This tests the cross-version isolation of {@code children} and {@code parents}
* in the {@code ClassInstance} for Multi-Release Jar.
*
* @throws IOException io failure.
*/
@Test
public void mrj2() throws IOException {
Path output = TestUtil.output(MRJ2_INPUT_PATH);
Path input = TestUtil.input(MRJ2_INPUT_PATH);
try (TinyRemapper remapper = setupRemapper()) {
final NonClassCopyMode ncCopyMode = NonClassCopyMode.FIX_META_INF;
final Path[] classpath = new Path[]{};
try (OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(output).build()) {
outputConsumer.addNonClassFiles(input, ncCopyMode, remapper);
remapper.readInputs(input);
remapper.readClassPath(classpath);
remapper.apply(outputConsumer);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
final String J8_MAIN_CLASS = "com/github/logicf/Main.class";
final String J8_D1_CLASS = "com/github/logicf/D1.class";
final String J8_D3_CLASS = "com/github/logicf/D3.class";
final String J8_D5_CLASS = "com/github/logicf/D5.class";
final String J9_D1_CLASS = "META-INF/versions/9/com/github/logicf/D1.class";
final String J9_D2_CLASS = "META-INF/versions/9/com/github/logicf/D2.class";
final String J9_D4_CLASS = "META-INF/versions/9/com/github/logicf/D4.class";
try (JarFile result = new JarFile(output.toFile())) {
assertNotNull(result.getEntry(J8_MAIN_CLASS));
assertNotNull(result.getEntry(J8_D1_CLASS));
assertNotNull(result.getEntry(J8_D3_CLASS));
assertNotNull(result.getEntry(J8_D5_CLASS));
assertNotNull(result.getEntry(J9_D1_CLASS));
assertNotNull(result.getEntry(J9_D2_CLASS));
assertNotNull(result.getEntry(J9_D4_CLASS));
ClassReader readerJ8D1 = new ClassReader(result.getInputStream(result.getEntry(J8_D1_CLASS)));
readerJ8D1.accept(new ClassVisitor(Opcodes.ASM9, null) {
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
assertEquals("com/github/logicf/D3", superName);
}
}, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE);
ClassReader readerJ9D1 = new ClassReader(result.getInputStream(result.getEntry(J9_D1_CLASS)));
readerJ9D1.accept(new ClassVisitor(Opcodes.ASM9, null) {
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
assertEquals("com/github/logicf/D2", superName);
}
}, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE);
}
}
/**
* This tests the Multi-Release Jar with input tag.
*
* @throws IOException io failure.
*/
@Test
public void mrj4() throws IOException {
Path output = TestUtil.output(MRJ1_INPUT_PATH);
Path input = TestUtil.input(MRJ1_INPUT_PATH);
try (TinyRemapper remapper = setupRemapper()) {
final NonClassCopyMode ncCopyMode = NonClassCopyMode.FIX_META_INF;
final Path[] classpath = new Path[]{};
InputTag tag = remapper.createInputTag();
try (OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(output).build()) {
outputConsumer.addNonClassFiles(input, ncCopyMode, remapper);
remapper.readInputs(tag, input);
remapper.readClassPath(classpath);
remapper.apply(outputConsumer, tag);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
final String MAIN_CLASS = "com/github/logicf/Main.class";
final String GREETING_CLASS = "com/github/logicf/Greeting.class";
final String MRJ_GREETING_CLASS = "META-INF/versions/9/com/github/logicf/Greeting.class";
try (JarFile result = new JarFile(output.toFile())) {
assertNotNull(result.getEntry(MAIN_CLASS));
assertNotNull(result.getEntry(GREETING_CLASS));
assertNotNull(result.getEntry(MRJ_GREETING_CLASS));
}
}
@AfterAll
public static void cleanup() throws IOException {
TestUtil.folder = null;
}
}