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
1 change: 1 addition & 0 deletions com.microsoft.java.debug.plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<command id="vscode.java.validateLaunchConfig"/>
<command id="vscode.java.resolveMainMethod"/>
<command id="vscode.java.inferLaunchCommandLength"/>
<command id="vscode.java.checkProjectSettings"/>
</delegateCommandHandler>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Microsoft Corporation and others.
* Copyright (c) 2017-2019 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
Expand Down Expand Up @@ -30,6 +30,7 @@ public class JavaDebugDelegateCommandHandler implements IDelegateCommandHandler
public static final String VALIDATE_LAUNCHCONFIG = "vscode.java.validateLaunchConfig";
public static final String RESOLVE_MAINMETHOD = "vscode.java.resolveMainMethod";
public static final String INFER_LAUNCH_COMMAND_LENGTH = "vscode.java.inferLaunchCommandLength";
public static final String CHECK_PROJECT_SETTINGS = "vscode.java.checkProjectSettings";

@Override
public Object executeCommand(String commandId, List<Object> arguments, IProgressMonitor progress) throws Exception {
Expand Down Expand Up @@ -57,6 +58,8 @@ public Object executeCommand(String commandId, List<Object> arguments, IProgress
return ResolveMainMethodHandler.resolveMainMethods(arguments);
case INFER_LAUNCH_COMMAND_LENGTH:
return LaunchCommandHandler.getLaunchCommandLength(JsonUtils.fromJson((String) arguments.get(0), LaunchArguments.class));
case CHECK_PROJECT_SETTINGS:
return ProjectSettingsChecker.check(JsonUtils.fromJson((String) arguments.get(0), ProjectSettingsChecker.ProjectSettingsCheckerParams.class));
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2019 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.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaProject;

public class ProjectSettingsChecker {
/**
* Check whether the project settings are all matched as the expected.
* @param params - The checker parameters
* @return true if all settings is matched
*/
public static boolean check(ProjectSettingsCheckerParams params) {
Map<String, String> options = new HashMap<>();
IJavaProject javaProject = null;
if (StringUtils.isNotBlank(params.projectName)) {
javaProject = JdtUtils.getJavaProject(params.projectName);
} else if (StringUtils.isNotBlank(params.className)) {
try {
List<IJavaProject> projects = ResolveClasspathsHandler.getJavaProjectFromType(params.className);
if (!projects.isEmpty()) {
javaProject = projects.get(0);
}
} catch (CoreException e) {
// do nothing
}
}

if (javaProject != null) {
options = javaProject.getOptions(params.inheritedOptions);
}

for (Entry<String, String> expected : params.expectedOptions.entrySet()) {
if (!Objects.equals(options.get(expected.getKey()), expected.getValue())) {
return false;
}
}

return true;
}

public static class ProjectSettingsCheckerParams {
String className;
String projectName;
boolean inheritedOptions;
Map<String, String> expectedOptions;
}
}