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

Method call

src/main/java/me/coley/recaf/command/impl/Export.java:55–99  ·  view source on GitHub ↗

@return n/a @throws Exception IOException, cannot write to output

()

Source from the content-addressed store, hash-verified

53 * <ul><li>IOException, cannot write to output</li></ul>
54 */
55 @Override
56 public Void call() throws Exception {
57 // Ensure parent directory exists
58 File parentDir = output.getParentFile();
59 if (parentDir != null && !parentDir.isDirectory() && !parentDir.mkdirs())
60 throw new IOException("Failed to create parent directory for: " + output);
61 JavaResource primary = getWorkspace().getPrimary();
62 // Handle class exports
63 boolean noShadeContent = !shadeLibs || getWorkspace().getLibraries().isEmpty();
64 if (primary instanceof ClassResource && noShadeContent) {
65 byte[] clazz = primary.getClasses().values().iterator().next();
66 for (ExportInterceptorPlugin interceptor : PluginsManager.getInstance()
67 .ofType(ExportInterceptorPlugin.class)) {
68 clazz = interceptor.intercept(new ClassReader(clazz).getClassName(), clazz);
69 }
70 FileUtils.writeByteArrayToFile(output, clazz);
71 info("Saved to {}", output.getName());
72 return null;
73 }
74 // Collect content to put into export archive
75 Map<String, byte[]> outContent = new TreeMap<>();
76 if (shadeLibs)
77 getWorkspace().getLibraries().forEach(lib -> put(outContent, lib));
78 put(outContent, primary);
79 // Calculate modified classes
80 Set<String> modifiedClasses = new HashSet<>();
81 Set<String> modifiedResources = new HashSet<>();
82 modifiedClasses.addAll(primary.getDirtyClasses());
83 modifiedClasses.addAll(primary.getClassHistory().entrySet().stream()
84 .filter(e -> e.getValue().size() > 1)
85 .map(Map.Entry::getKey)
86 .collect(Collectors.toSet()));
87 modifiedResources.addAll(primary.getFileHistory().entrySet().stream()
88 .filter(e -> e.getValue().size() > 1)
89 .map(Map.Entry::getKey)
90 .collect(Collectors.toSet()));
91 // Write to archive
92 if (output.isDirectory() && primary instanceof DirectoryResource)
93 writeDirectory(output, outContent);
94 else
95 writeArchive(compress, output, outContent);
96 info("Saved to {}.\n - Modified classes: {}\n - Modified resources: {}",
97 output.getName(), modifiedClasses.size(), modifiedResources.size());
98 return null;
99 }
100
101 /**
102 * Writes a map to a directory.

Callers 1

saveApplicationMethod · 0.95

Calls 15

getClassesMethod · 0.95
getInstanceMethod · 0.95
putMethod · 0.95
getDirtyClassesMethod · 0.95
getClassHistoryMethod · 0.95
getFileHistoryMethod · 0.95
writeDirectoryMethod · 0.95
writeArchiveMethod · 0.95
isDirectoryMethod · 0.80
getPrimaryMethod · 0.80
getLibrariesMethod · 0.80
nextMethod · 0.80

Tested by

no test coverage detected