Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Map;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.URIUtil;
Expand All @@ -44,7 +45,9 @@ public class JUnitLaunchConfigurationDelegate extends org.eclipse.pde.launching.
public JUnitLaunchArguments getJUnitLaunchArguments(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
loadInstalledBundlesToPDECache();
ILaunch launch = new Launch(configuration, mode, null);
showCommandLine(configuration, mode, launch, monitor);
String commandLine = showCommandLine(configuration, mode, launch, monitor);
ILog.get().error(commandLine);
String javaExec = commandLine.split("\\s+")[0];

String mainTypeName = verifyMainTypeName(configuration);

Expand Down Expand Up @@ -100,6 +103,7 @@ public JUnitLaunchArguments getJUnitLaunchArguments(ILaunchConfiguration configu
launchArguments.programArguments = programArguments.toArray(new String[programArguments.size()]);
launchArguments.environment = EclipseApplicationLaunchConfiguration.getEnvironmentVariable(configuration);
launchArguments.port = launch.getAttribute(JUnitLaunchConfigurationConstants.ATTR_PORT);
launchArguments.javaExec = javaExec;

return launchArguments;
}
Expand Down Expand Up @@ -174,5 +178,6 @@ public static class JUnitLaunchArguments {
String[] programArguments;
Map<String, String> environment;
String port;
String javaExec;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class TestInfo {
public String testProject = "";
public String jreContainer = "org.eclipse.jdt.launching.JRE_CONTAINER";
public String testBundle = "";
public String vmArgs = "";
public boolean useUIThread = false;

public Map<String, String> toValueMap() {
Expand All @@ -84,10 +85,11 @@ public Map<String, String> toValueMap() {
valueMap.put("testProject", testProject);
valueMap.put("testBundle", testBundle);
valueMap.put("useUIThread", String.valueOf(useUIThread));

if (Platform.OS_MACOSX.equals(Platform.getOS())) {
valueMap.put("vmArgs", "-XstartOnFirstThread");
valueMap.put("vmArgs", "-XstartOnFirstThread " + vmArgs);
} else {
valueMap.put("vmArgs", "");
valueMap.put("vmArgs", vmArgs);
}
return valueMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,37 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.Launch;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.IVMInstallType;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
import org.eclipse.jdt.ls.core.internal.IDelegateCommandHandler;
import org.eclipse.jdt.ls.core.internal.JDTUtils;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
Expand All @@ -57,6 +64,7 @@ public class PDEDelegateCommandHandler implements IDelegateCommandHandler {
public static final String RESOLVE_LAUNCH_ARGUMENTS = "java.pde.resolveLaunchArguments";
public static final String RELOAD_TARGET_PLATFORM = "java.pde.reloadTargetPlatform";
public static final String RESOLVE_JUNIT_ARGUMENTS = "java.pde.resolveJUnitArguments";
public static final String JUNIT_LAUNCH_CONFIG = "org.eclipse.pde.ui.JunitLaunchConfig";

@Override
public Object executeCommand(String commandId, List<Object> arguments, IProgressMonitor monitor) throws Exception {
Expand Down Expand Up @@ -92,19 +100,51 @@ private static Object resolveLaunchArguments(String launchFileUri) throws Except
String fileName = getSimpleName(file);
ILaunchConfiguration configuration = new PDELaunchConfiguration(fileName, file);
String configType = configuration.getType().getIdentifier();
if (!configType.equals(IPDELauncherConstants.ECLIPSE_APPLICATION_LAUNCH_CONFIGURATION_TYPE)) {

if (configType.equals(JUNIT_LAUNCH_CONFIG)) {
TestInfo testInfo = new TestInfo();
testInfo.testKind = "org.eclipse.jdt.junit.loader.junit4";

List<String> classesUnderTest = configuration.getAttribute("org.eclipse.debug.core.MAPPED_RESOURCE_PATHS", Collections.emptyList());
if (classesUnderTest.isEmpty()) {
throw new IllegalArgumentException("Expected a test class or suite to test");
}
testInfo.testMainType = configuration.getAttribute("org.eclipse.jdt.launching.MAIN_TYPE", "");
testInfo.testProject = configuration.getAttribute("org.eclipse.jdt.launching.PROJECT_ATTR", "");
testInfo.jreContainer = configuration.getAttribute("org.eclipse.jdt.launching.JRE_CONTAINER", "");
testInfo.vmArgs = configuration.getAttribute("org.eclipse.jdt.launching.VM_ARGUMENTS", "");
testInfo.testName = configuration.getAttribute("org.eclipse.jdt.junit.TESTNAME", "");
testInfo.testBundle = testInfo.testProject;
testInfo.useUIThread = configuration.getAttribute("run_in_ui_thread", true);
JunitLaunchConfiguration launchConfiguration = new JunitLaunchConfiguration(configType, testInfo);
JUnitLaunchConfigurationDelegate delegate = new JUnitLaunchConfigurationDelegate();
return delegate.getJUnitLaunchArguments(launchConfiguration, "run", new NullProgressMonitor());
} else if (configType.equals(IPDELauncherConstants.ECLIPSE_APPLICATION_LAUNCH_CONFIGURATION_TYPE)) {
EclipseApplicationLaunchConfiguration pdeLaunchConfiguration = new EclipseApplicationLaunchConfiguration();
pdeLaunchConfiguration.preLaunchCheck(configuration, (ILaunch) null, new NullProgressMonitor());
LaunchArguments launchArguments = new LaunchArguments();
launchArguments.setVmArguments(pdeLaunchConfiguration.getVMArguments(configuration));
launchArguments.setProgramArguments(pdeLaunchConfiguration.getProgramArguments(configuration));
launchArguments.setEnvironment(pdeLaunchConfiguration.getEnvironmentVariable(configuration));
launchArguments.setClasspath(pdeLaunchConfiguration.getClasspath(configuration));
launchArguments.setWorkspaceLocation(pdeLaunchConfiguration.getWorkspaceLocation());

String jreContainer = configuration.getAttribute("org.eclipse.jdt.launching.JRE_CONTAINER", "org.eclipse.jdt.launching.JRE_CONTAINER");
if (!jreContainer.isEmpty()) {
String[] segments = jreContainer.split("/");
if (segments.length > 2) {
IExecutionEnvironment ee = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(segments[2]);
if (ee != null && ee.getDefaultVM() != null) {
launchArguments.setJavaExec(ee.getDefaultVM().getInstallLocation().toPath().resolve("bin").resolve("java").toAbsolutePath().toString());
}
}
}

return launchArguments;
} else {
throw new UnsupportedOperationException(String.format("PDE plugin doesn't support the launch type '%s'.", configType));
}

EclipseApplicationLaunchConfiguration pdeLaunchConfiguration = new EclipseApplicationLaunchConfiguration();
pdeLaunchConfiguration.preLaunchCheck(configuration, (ILaunch) null, new NullProgressMonitor());
LaunchArguments launchArguments = new LaunchArguments();
launchArguments.setVmArguments(pdeLaunchConfiguration.getVMArguments(configuration));
launchArguments.setProgramArguments(pdeLaunchConfiguration.getProgramArguments(configuration));
launchArguments.setEnvironment(pdeLaunchConfiguration.getEnvironmentVariable(configuration));
launchArguments.setClasspath(pdeLaunchConfiguration.getClasspath(configuration));
launchArguments.setWorkspaceLocation(pdeLaunchConfiguration.getWorkspaceLocation());
return launchArguments;

} catch (URISyntaxException | CoreException e) {
throw new Exception("Failed to parse the launch configuration", e);
}
Expand Down Expand Up @@ -285,6 +325,7 @@ private static class LaunchArguments {
Map<String, String> environment;
String workspaceLocation;
String[] classpath;
String javaExec;

public LaunchArguments() {
}
Expand All @@ -308,5 +349,9 @@ public void setWorkspaceLocation(String workspaceLocation) {
public void setClasspath(String[] classpath) {
this.classpath = classpath;
}

public void setJavaExec(String javaExec) {
this.javaExec = javaExec;
}
}
}
4 changes: 3 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ async function launchPDEApplication(context: vscode.ExtensionContext, uri: vscod
classPaths: launchArguments.classpath,
args: launchArguments.programArguments,
vmArgs: launchArguments.vmArguments,
env: launchArguments.environment
env: launchArguments.environment,
javaExec: launchArguments.javaExec,
};

await persistLaunchConfig(launchConfiguration, workspaceFolder.uri);
Expand Down Expand Up @@ -290,6 +291,7 @@ interface LaunchArguments {
environment;
workspaceLocation: string;
classpath: string[];
javaExec: string;
}

interface JUnitLaunchArguments {
Expand Down