Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jdtls.ext/com.microsoft.jdtls.ext.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<command id="java.project.list"/>
<command id="java.getPackageData"/>
<command id="java.resolvePath" />
<command id="java.project.getMainMethod" />
<command id="java.project.getMainClasses" />
<command id="java.project.generateJar" />
</delegateCommandHandler>
</extension>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public Object executeCommand(String commandId, List<Object> arguments, IProgress
return PackageCommand.getChildren(arguments, monitor);
case "java.resolvePath":
return PackageCommand.resolvePath(arguments, monitor);
case "java.project.getMainMethod":
return ProjectCommand.getMainMethod(arguments, monitor);
case "java.project.getMainClasses":
return ProjectCommand.getMainClasses(arguments, monitor);
case "java.project.generateJar":
return ProjectCommand.exportJar(arguments, monitor);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@
public final class ProjectCommand {

private static class MainClassInfo {

public String name;

public String path;

public MainClassInfo(String name, String path) {
Expand All @@ -78,6 +76,12 @@ public MainClassInfo(String name, String path) {
}
}

private static class Classpath {
public String source;
public String destination;
public boolean isArtifact;
}

private static class ExportResult {
public boolean result;
public String message;
Expand Down Expand Up @@ -150,25 +154,21 @@ public static ExportResult exportJar(List<Object> arguments, IProgressMonitor mo
if (arguments.size() < 3) {
return new ExportResult(false, "Invalid export Arguments");
}
String mainMethod = gson.fromJson(gson.toJson(arguments.get(0)), String.class);
String[] classpaths = gson.fromJson(gson.toJson(arguments.get(1)), String[].class);
String mainClass = gson.fromJson(gson.toJson(arguments.get(0)), String.class);
Classpath[] classpaths = gson.fromJson(gson.toJson(arguments.get(1)), Classpath[].class);
String destination = gson.fromJson(gson.toJson(arguments.get(2)), String.class);
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
if (mainMethod.length() > 0) {
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, mainMethod);
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 (String classpath : classpaths) {
if (classpath != null) {
if (classpath.endsWith(".jar")) {
ZipFile zip = new ZipFile(classpath);
writeArchive(zip, true, true, target, directories, monitor);
} else {
File folder = new File(classpath);
writeFileRecursively(folder, target, directories, folder.getAbsolutePath().length() + 1);
}
for (Classpath classpath : classpaths) {
if (classpath.isArtifact) {
writeArchive(new ZipFile(classpath.source), true, true, target, directories, monitor);
} else {
writeFile(new File(classpath.source), new Path(classpath.destination), true, true, target, directories);
}
}
} catch (Exception e) {
Expand All @@ -177,23 +177,7 @@ public static ExportResult exportJar(List<Object> arguments, IProgressMonitor mo
return new ExportResult(true);
}

private static void writeFileRecursively(File folder, JarOutputStream jarOutputStream, Set<String> directories,
int len) {
File[] files = folder.listFiles();
for (File file : files) {
if (file.isDirectory()) {
writeFileRecursively(file, jarOutputStream, directories, len);
} else if (file.isFile()) {
try {
writeFile(file, new Path(file.getAbsolutePath().substring(len)), true, true, jarOutputStream, directories);
} catch (Exception e) {
// do nothing
}
}
}
}

public static List<MainClassInfo> getMainMethod(List<Object> arguments, IProgressMonitor monitor) throws Exception {
public static List<MainClassInfo> getMainClasses(List<Object> arguments, IProgressMonitor monitor) throws Exception {
List<PackageNode> projectList = listProjects(arguments, monitor);
final List<MainClassInfo> res = new ArrayList<>();
List<IJavaElement> searchRoots = new ArrayList<>();
Expand Down
133 changes: 119 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading