Permalink
Browse files

BearMenu: Use coala-json to get list of bears

Fixes #16
  • Loading branch information...
arafsheikh committed Jul 11, 2016
1 parent 9cf253d commit f4283ecaedff66a0979deacde569227c27b3723c
@@ -2,6 +2,7 @@
import com.coala.core.utils.ExternalUtils;
import org.apache.commons.exec.ExecuteException;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.action.ContributionItem;
import org.eclipse.swt.SWT;
@@ -10,8 +11,10 @@
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.ui.PlatformUI;
import org.json.JSONArray;
import java.io.IOException;
import java.util.ArrayList;
public class BearMenu extends ContributionItem {
@@ -24,7 +27,13 @@ public BearMenu(String id) {
@Override
public void fill(Menu menu, int index) {
String[] bears = getBears();
ArrayList<String> bears = new ArrayList<>();
try {
bears = getBears();
} catch (IOException ex) {
System.out.println("Bear list could not be fetched");
ex.printStackTrace();
}
for (final String bear : bears) {
MenuItem menuItem = new MenuItem(menu, SWT.CHECK, index);
@@ -44,81 +53,12 @@ public void widgetSelected(SelectionEvent event) {
}
}
private String[] getBears() {
// TODO: Use coala-json to fetch list of bears
String[] bears = {"AlexBear",
"AnnotationBear",
"BootLintBear",
"CMakeLintBear",
"CPDBear",
"CPPCheckBear",
"CPPCleanBear",
"CPPLintBear",
"CSSAutoPrefixBear",
"CSSLintBear",
"CSharpLintBear",
"CheckstyleBear",
"ClangASTPrintBear",
"ClangBear",
"ClangCloneDetectionBear",
"ClangComplexityBear",
"ClangFunctionDifferenceBear",
"CoffeeLintBear",
"DartLintBear",
"DockerfileLintBear",
"ESLintBear",
"FormatRBear",
"GNUIndentBear",
"GitCommitBear",
"GoImportsBear",
"GoLintBear",
"GoReturnsBear",
"GoTypeBear",
"GoVetBear",
"GofmtBear",
"HTMLLintBear",
"HaskellLintBear",
"InferBear",
"InvalidLinkBear",
"JSComplexityBear",
"JSHintBear",
"JSONFormatBear",
"JavaPMDBear",
"JuliaLintBear",
"KeywordBear",
"LanguageToolBear",
"LatexLintBear",
"LineCountBear",
"LineLengthBear",
"LuaLintBear",
"MarkdownBear",
"MatlabIndentationBear",
"PEP8Bear",
"PHPLintBear",
"PerlCriticBear",
"ProseLintBear",
"PyCommentedCodeBear",
"PyDocStyleBear",
"PyImportSortBear",
"PyLintBear",
"PyUnusedCodeBear",
"RLintBear",
"RadonBear",
"RuboCopBear",
"RubySyntaxBear",
"SCSSLintBear",
"SQLintBear",
"ScalaLintBear",
"ShellCheckBear",
"SpaceConsistencyBear",
"TSLintBear",
"VHDLLintBear",
"VerilogLintBear",
"VintBear",
"XMLBear",
"YAMLLintBear",
"reSTLintBear"};
return bears;
private ArrayList<String> getBears() throws ExecuteException, IOException {
JSONArray bearList = ExternalUtils.getAvailableBears();
ArrayList<String> bearNames = new ArrayList<>();
for (int i = 0; i < bearList.length(); i++) {
bearNames.add(bearList.getJSONObject(i).getString("name"));
}
return bearNames;
}
}
@@ -133,6 +133,23 @@ public void onProcessFailed(ExecuteException executeException) {
executor.execute(cmdLine, resultHandler);
}
/**
* Get details of all bears that are available on the user's system.
*
* @return JSONArray containing details of bears.
*/
public static JSONArray getAvailableBears() throws ExecuteException, IOException {
CommandLine cmdLine = new CommandLine("coala-json");
cmdLine.addArgument("-B");
final ByteArrayOutputStream stdout = new ByteArrayOutputStream();
PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(stdout);
Executor executor = new DefaultExecutor();
executor.setStreamHandler(pumpStreamHandler);
executor.execute(cmdLine);
JSONArray bearList = new JSONObject(stdout.toString()).getJSONArray("bears");
return bearList;
}
/**
* Process the JSON output of coala and add marker for each problem.
*

0 comments on commit f4283ec

Please sign in to comment.