MCPcopy
hub / github.com/Col-E/Recaf / call

Method call

src/main/java/me/coley/recaf/command/impl/Remap.java:49–91  ·  view source on GitHub ↗

@return n/a @throws Exception IllegalStateException, Invalid map file given

()

Source from the content-addressed store, hash-verified

47 * <ul><li>IllegalStateException, Invalid map file given</li></ul>
48 */
49 @Override
50 public Void call() throws Exception {
51 if(mapFile == null || !Files.exists(mapFile))
52 throw new IllegalStateException("No mapping file provided!");
53 // Apply
54 Mappings mappings = mapper.create(mapFile, getWorkspace());
55 mappings.setClearDebugInfo(noDebug);
56 mappings.setCheckFieldHierarchy(lookup);
57 mappings.setCheckMethodHierarchy(lookup);
58
59 JavaResource primary = getWorkspace().getPrimary();
60 Map<String, byte[]> mapped = mappings.accept(primary);
61
62 byte[] manifestBytes = primary.getFiles().get("META-INF/MANIFEST.MF");
63 if (manifestBytes != null) {
64 Manifest manifest = new Manifest(new ByteArrayInputStream(manifestBytes));
65 Attributes attr = manifest.getMainAttributes();
66 if (!attr.isEmpty()) {
67 String mainClass = attr.getValue("Main-Class").replaceAll("\\.", "/");
68 if (mapped.containsKey(mainClass)) {
69 String mappedName = new ClassReader(mapped.get(mainClass))
70 .getClassName().replaceAll("/", "\\.");
71 debug("Remapping Main-Class attribute in MANIFEST.MF from '{}' to '{}'", mainClass, mappedName);
72 attr.putValue("Main-Class", mappedName);
73 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
74 manifest.write(outputStream);
75 primary.getFiles().put("META-INF/MANIFEST.MF", outputStream.toByteArray());
76 outputStream.close();
77 }
78 }
79 }
80
81 // Log
82 StringBuilder sb = new StringBuilder("Classes updated: " + mapped.size());
83 mapped.forEach((old, value) -> {
84 ClassReader reader = new ClassReader(value);
85 String rename = reader.getClassName();
86 if (!old.equals(rename))
87 sb.append("\n - ").append(old).append(" => ").append(rename);
88 });
89 info(sb.toString());
90 return null;
91 }
92}

Callers

nothing calls this directly

Calls 15

setClearDebugInfoMethod · 0.95
acceptMethod · 0.95
getFilesMethod · 0.95
getPrimaryMethod · 0.80
debugMethod · 0.80
toByteArrayMethod · 0.80
appendMethod · 0.80
infoMethod · 0.80
createMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected