@return n/a @throws Exception IOException, cannot write to output
()
| 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. |
no test coverage detected