Skip to content
Merged
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
/*******************************************************************************
* Copyright (c) 2017 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Microsoft Corporation - initial API and implementation
*******************************************************************************/

package com.microsoft.java.debug.plugin.internal;

import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.ls.core.internal.IDelegateCommandHandler;

public class JavaDebugDelegateCommandHandler implements IDelegateCommandHandler {

public static String DEBUG_STARTSESSION = "vscode.java.startDebugSession";

public static String RESOLVE_CLASSPATH = "vscode.java.resolveClasspath";

public static String BUILD_WORKSPACE = "vscode.java.buildWorkspace";

@Override
public Object executeCommand(String commandId, List<Object> arguments, IProgressMonitor progress) throws Exception {
if (DEBUG_STARTSESSION.equals(commandId)) {
IDebugServer debugServer = JavaDebugServer.getInstance();
debugServer.start();
return debugServer.getPort();
} else if (RESOLVE_CLASSPATH.equals(commandId)) {
ResolveClasspathsHandler handler = new ResolveClasspathsHandler();
return handler.resolveClasspaths(arguments);
} else if (BUILD_WORKSPACE.equals(commandId)) {
// TODO
}
throw new UnsupportedOperationException(String.format("Java debug plugin doesn't support the command '%s'.", commandId));
}

public class JavaDebugDelegateCommandHandler implements IDelegateCommandHandler {

public static String DEBUG_STARTSESSION = "vscode.java.startDebugSession";

public static String RESOLVE_CLASSPATH = "vscode.java.resolveClasspath";

public static String BUILD_WORKSPACE = "vscode.java.buildWorkspace";

@Override
public Object executeCommand(String commandId, List<Object> arguments) {
if (DEBUG_STARTSESSION.equals(commandId)) {
IDebugServer debugServer = JavaDebugServer.getInstance();
debugServer.start();
return debugServer.getPort();
} else if (RESOLVE_CLASSPATH.equals(commandId)) {
ResolveClasspathsHandler handler = new ResolveClasspathsHandler();
return handler.resolveClasspaths(arguments);
} else if (BUILD_WORKSPACE.equals(commandId)) {

}
return null;
}

public static JavaDebugDelegateCommandHandler getInstance() {
return new JavaDebugDelegateCommandHandler();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,27 @@

package com.microsoft.java.debug.plugin.internal;

import java.util.logging.Logger;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

import com.microsoft.java.debug.core.Configuration;

public class JavaDebuggerServerPlugin implements BundleActivator {
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);

public static final String PLUGIN_ID = "com.microsoft.java.debug";


@Override
public void start(BundleContext context) throws Exception {
System.out.println("Starting " + PLUGIN_ID);
logger.info("Starting " + PLUGIN_ID);
}

@Override
public void stop(BundleContext context) throws Exception {

logger.info("Stopping " + PLUGIN_ID);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*******************************************************************************
* Copyright (c) 2017 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Microsoft Corporation - initial API and implementation
*******************************************************************************/

package com.microsoft.java.debug.plugin.internal;

import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*******************************************************************************
* Copyright (c) 2017 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Microsoft Corporation - initial API and implementation
*******************************************************************************/

package com.microsoft.java.debug.plugin.internal;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
*******************************************************************************/
package com.microsoft.java.debug.plugin.internal;

import static org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin.logException;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
Expand All @@ -32,120 +31,122 @@
import org.eclipse.jdt.core.search.SearchPattern;
import org.eclipse.jdt.core.search.SearchRequestor;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;

import com.microsoft.java.debug.core.Configuration;

public class ResolveClasspathsHandler {
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);

public String[] resolveClasspaths(List<Object> arguments) {
try {
return computeClassPath((String)arguments.get(0), (String)arguments.get(1));
} catch (CoreException e) {
logException("Failed to resolve classpath.", e);
}
return null;
}
public String[] resolveClasspaths(List<Object> arguments) throws Exception {
try {
return computeClassPath((String) arguments.get(0), (String) arguments.get(1));
} catch (CoreException e) {
logger.severe("Failed to resolve classpath: " + e.getMessage());
throw new Exception("Failed to resolve classpath: " + e.getMessage(), e);
}
}

/**
* Get java project from name.
*
* @param projectName
* project name
* @return java project
* @throws CoreException
* CoreException
*/
private static IJavaProject getJavaProjectFromName(String projectName) throws CoreException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(projectName);
if (!project.exists()) {
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID,
String.format("Cannot find the project with name '%s'.", projectName)));
}
if (!project.isNatureEnabled("org.eclipse.jdt.core.javanature")) {
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID,
String.format("The project '%s' does not have java nature enabled.", projectName)));
}
IJavaProject javaProject = JavaCore.create(project);
return javaProject;
}
/**
* Get java project from name.
*
* @param projectName
* project name
* @return java project
* @throws CoreException
* CoreException
*/
private static IJavaProject getJavaProjectFromName(String projectName) throws CoreException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(projectName);
if (!project.exists()) {
throw new CoreException(new Status(IStatus.ERROR, JavaDebuggerServerPlugin.PLUGIN_ID,
String.format("Cannot find the project with name '%s'.", projectName)));
}
if (!project.isNatureEnabled("org.eclipse.jdt.core.javanature")) {
throw new CoreException(new Status(IStatus.ERROR, JavaDebuggerServerPlugin.PLUGIN_ID,
String.format("The project '%s' does not have java nature enabled.", projectName)));
}
IJavaProject javaProject = JavaCore.create(project);
return javaProject;
}

/**
* Get java project from type.
*
* @param typeFullyQualifiedName
* fully qualified name of type
* @return java project
* @throws CoreException
* CoreException
*/
private static List<IJavaProject> getJavaProjectFromType(String typeFullyQualifiedName) throws CoreException {
SearchPattern pattern = SearchPattern.createPattern(typeFullyQualifiedName, IJavaSearchConstants.TYPE,
IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
ArrayList<IJavaProject> projects = new ArrayList<>();
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) {
Object element = match.getElement();
if (element instanceof IJavaElement) {
projects.add(((IJavaElement) element).getJavaProject());
}
}
};
SearchEngine searchEngine = new SearchEngine();
searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
requestor, null /* progress monitor */);
/**
* Get java project from type.
*
* @param typeFullyQualifiedName
* fully qualified name of type
* @return java project
* @throws CoreException
* CoreException
*/
private static List<IJavaProject> getJavaProjectFromType(String typeFullyQualifiedName) throws CoreException {
SearchPattern pattern = SearchPattern.createPattern(typeFullyQualifiedName, IJavaSearchConstants.TYPE,
IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
ArrayList<IJavaProject> projects = new ArrayList<>();
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) {
Object element = match.getElement();
if (element instanceof IJavaElement) {
projects.add(((IJavaElement) element).getJavaProject());
}
}
};
SearchEngine searchEngine = new SearchEngine();
searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
requestor, null /* progress monitor */);

return projects;
}
return projects;
}

/**
* Accord to the project name and the main class, compute runtime classpath.
*
* @param mainClass
/**
* Accord to the project name and the main class, compute runtime classpath.
*
* @param mainClass
* fully qualified class name
* @param projectName
* project name
* @return class path
* @throws CoreException
* CoreException
*/
private static String[] computeClassPath(String mainClass, String projectName) throws CoreException {
IJavaProject project = null;
// if type exists in multiple projects, debug configuration need provide
// project name.
if (projectName != null) {
project = getJavaProjectFromName(projectName);
} else {
List<IJavaProject> projects = getJavaProjectFromType(mainClass);
if (projects.size() == 0) {
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID,
String.format("Main class '%s' doesn't exist in the workspace.", mainClass)));
}
if (projects.size() > 1) {
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID,
String.format(
"Main class '%s' isn't unique in the workspace, please pass in specified projectname.",
mainClass)));
}
project = projects.get(0);
}
return computeClassPath(project);
}
* @param projectName
* project name
* @return class path
* @throws CoreException
* CoreException
*/
private static String[] computeClassPath(String mainClass, String projectName) throws CoreException {
IJavaProject project = null;
// if type exists in multiple projects, debug configuration need provide
// project name.
if (projectName != null) {
project = getJavaProjectFromName(projectName);
} else {
List<IJavaProject> projects = getJavaProjectFromType(mainClass);
if (projects.size() == 0) {
throw new CoreException(new Status(IStatus.ERROR, JavaDebuggerServerPlugin.PLUGIN_ID,
String.format("Main class '%s' doesn't exist in the workspace.", mainClass)));
}
if (projects.size() > 1) {
throw new CoreException(new Status(IStatus.ERROR, JavaDebuggerServerPlugin.PLUGIN_ID,
String.format(
"Main class '%s' isn't unique in the workspace, please pass in specified projectname.",
mainClass)));
}
project = projects.get(0);
}
return computeClassPath(project);
}

/**
* Compute runtime classpath of a java project.
*
* @param javaProject
* java project
* @return class path
* @throws CoreException
* CoreException
*/
private static String[] computeClassPath(IJavaProject javaProject) throws CoreException {
if (javaProject == null) {
throw new IllegalArgumentException("javaProject is null");
}
return JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
}
/**
* Compute runtime classpath of a java project.
*
* @param javaProject
* java project
* @return class path
* @throws CoreException
* CoreException
*/
private static String[] computeClassPath(IJavaProject javaProject) throws CoreException {
if (javaProject == null) {
throw new IllegalArgumentException("javaProject is null");
}
return JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
}
}