in jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/ProjectCommand.java [162:206]
private static boolean exportJarExecution(String mainClass, Classpath[] classpaths, String destination,
String terminalId, IProgressMonitor monitor) throws OperationCanceledException {
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
if (mainClass.length() > 0) {
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, mainClass);
}
try (JarOutputStream target = new JarOutputStream(new FileOutputStream(destination), manifest)) {
Set<String> directories = new HashSet<>();
for (Classpath classpath : classpaths) {
if (monitor.isCanceled()) {
return false;
}
if (classpath.isArtifact) {
MultiStatus resultStatus = writeArchive(new ZipFile(classpath.source),
/* areDirectoryEntriesIncluded = */true, /* isCompressed = */true, target, directories, monitor);
int severity = resultStatus.getSeverity();
if (severity == IStatus.OK) {
java.nio.file.Path path = java.nio.file.Paths.get(classpath.source);
reportExportJarMessage(terminalId, IStatus.OK, "Successfully extracted the file to the exported jar: " + path.getFileName().toString());
continue;
}
if (resultStatus.isMultiStatus()) {
for (IStatus childStatus : resultStatus.getChildren()) {
reportExportJarMessage(terminalId, severity, childStatus.getMessage());
}
} else {
reportExportJarMessage(terminalId, severity, resultStatus.getMessage());
}
} else {
try {
writeFile(new File(classpath.source), new Path(classpath.destination), /* areDirectoryEntriesIncluded = */true,
/* isCompressed = */true, target, directories);
reportExportJarMessage(terminalId, IStatus.OK, "Successfully added the file to the exported jar: " + classpath.destination);
} catch (CoreException e) {
reportExportJarMessage(terminalId, IStatus.ERROR, e.getMessage());
}
}
}
} catch (IOException e) {
reportExportJarMessage(terminalId, IStatus.ERROR, e.getMessage());
return false;
}
return true;
}