-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utility to check java project settings (#264)
Signed-off-by: Jinbo Wang <[email protected]>
- Loading branch information
1 parent
c140561
commit 81bdeb2
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ProjectSettingsChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |