This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #64: Add UI for configuring CFLint rules
- Loading branch information
Showing
14 changed files
with
1,918 additions
and
161 deletions.
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
119 changes: 119 additions & 0 deletions
119
org.cfeclipse.cfml/src/org/cfeclipse/cfml/cflint/CFLintConfigUI.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,119 @@ | ||
package org.cfeclipse.cfml.cflint; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileWriter; | ||
import java.io.PrintWriter; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
import org.cfeclipse.cfml.CFMLPlugin; | ||
import org.cfeclipse.cfml.properties.CFMLPropertyManager; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.resources.IncrementalProjectBuilder; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.events.SelectionAdapter; | ||
import org.eclipse.swt.events.SelectionEvent; | ||
import org.eclipse.swt.layout.GridData; | ||
import org.eclipse.swt.layout.GridLayout; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Button; | ||
import com.cflint.config.CFLintConfig; | ||
import com.cflint.config.CFLintPluginInfo; | ||
import com.cflint.config.CFLintPluginInfo.PluginInfoRule; | ||
import com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage; | ||
import com.cflint.config.ConfigUtils; | ||
|
||
public class CFLintConfigUI { | ||
|
||
private ArrayList<RuleEditor> ruleEditors; | ||
private static CFMLPropertyManager propertyManager = new CFMLPropertyManager(); | ||
|
||
public void buildGUI(Composite composite, IProject iProject) { | ||
CFLintPluginInfo info = ConfigUtils.loadDefaultPluginInfo(); | ||
List<PluginInfoRule> enabledRules = getProjectCFLintConfig(iProject).getRules(); | ||
List<PluginMessage> excludeMessages = getProjectCFLintConfig(iProject).getExcludes(); | ||
Button enabledCheckbox = new Button(composite, SWT.CHECK); | ||
enabledCheckbox.setText("Enable/Disable All Rules"); | ||
enabledCheckbox.setSelection(false); | ||
enabledCheckbox.addSelectionListener(new SelectionAdapter() { | ||
@Override | ||
public void widgetSelected(SelectionEvent event) { | ||
Button btn = (Button) event.getSource(); | ||
boolean enableAll = btn.getSelection(); | ||
for (RuleEditor ruleEditor : ruleEditors) { | ||
ruleEditor.setRuleEnabled(enableAll); | ||
} | ||
} | ||
}); | ||
ruleEditors = new ArrayList<RuleEditor>(); | ||
HashMap<String, String> descriptions = ConfigUtils.loadDescriptions(); | ||
for (PluginInfoRule rule : info.getRules()) { | ||
RuleEditor ruleEdit; | ||
if(enabledRules.contains(rule)){ | ||
rule = enabledRules.get(enabledRules.indexOf(rule)); | ||
ruleEdit = new RuleEditor(composite, SWT.NONE, rule, true, descriptions, excludeMessages); | ||
} else { | ||
ruleEdit = new RuleEditor(composite, SWT.NONE, rule, true, descriptions, excludeMessages); | ||
} | ||
ruleEdit.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); | ||
ruleEdit.setLayout(new GridLayout(1, false)); | ||
ruleEditors.add(ruleEdit); | ||
} | ||
} | ||
|
||
public static CFLintConfig getProjectCFLintConfig(IProject iProject) { | ||
CFLintConfig currentConfig = null; | ||
File configFile = getConfigFile(iProject); | ||
if (configFile.exists()) { | ||
try { | ||
currentConfig = ConfigUtils.unmarshalJson(new FileInputStream(configFile), | ||
CFLintConfig.class); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return currentConfig; | ||
} | ||
|
||
public static File getConfigFile(IProject iProject) { | ||
File configFile; | ||
if(!propertyManager.getCFLintStoreConfigInProject(iProject)) { | ||
configFile = iProject.getWorkingLocation(CFMLPlugin.PLUGIN_ID).append("cflint.definition.json").toFile(); | ||
} else { | ||
configFile = iProject.getProject().getLocation().append("cflint.definition.json").toFile(); | ||
} | ||
return configFile; | ||
} | ||
|
||
public void setProjectRules(IProject iProject) { | ||
File configFile = getConfigFile(iProject); | ||
ArrayList<PluginInfoRule> rules = new ArrayList<PluginInfoRule>(); | ||
ArrayList<PluginMessage> excludes = new ArrayList<PluginMessage>(); | ||
for (RuleEditor ruleEditor : ruleEditors) { | ||
rules.add(ruleEditor.getRule()); | ||
excludes.addAll(ruleEditor.getExcludes()); | ||
} | ||
try { | ||
String config = ConfigUtils.marshalJson(rules); | ||
String excludesStr = ConfigUtils.marshalJson(excludes); | ||
PrintWriter writer; | ||
writer = new PrintWriter(new BufferedWriter(new FileWriter(configFile))); | ||
writer.write("{\"rule\":" + config + ", \"excludes\":"+excludesStr+"}"); | ||
writer.close(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
try { | ||
iProject.build(IncrementalProjectBuilder.CLEAN_BUILD,null); | ||
iProject.build(IncrementalProjectBuilder.FULL_BUILD,null); | ||
} catch (CoreException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
86 changes: 86 additions & 0 deletions
86
org.cfeclipse.cfml/src/org/cfeclipse/cfml/cflint/MessageEditor.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,86 @@ | ||
package org.cfeclipse.cfml.cflint; | ||
|
||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Group; | ||
|
||
import java.util.HashMap; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.events.SelectionAdapter; | ||
import org.eclipse.swt.events.SelectionEvent; | ||
import org.eclipse.swt.layout.GridLayout; | ||
import org.eclipse.swt.layout.GridData; | ||
import org.eclipse.swt.widgets.Button; | ||
import org.eclipse.swt.widgets.Combo; | ||
import org.eclipse.swt.widgets.Text; | ||
import com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage; | ||
|
||
public class MessageEditor extends Group { | ||
private Text messageText; | ||
private PluginMessage message; | ||
private Combo severityCombo; | ||
private Button enabledCheckbox; | ||
private boolean messageEnabled; | ||
/** | ||
* Create the composite. | ||
* @param parent | ||
* @param style | ||
* @param message | ||
* @param descriptions | ||
* @param b | ||
*/ | ||
public MessageEditor(Composite parent, int style, PluginMessage message, HashMap<String, String> descriptions, boolean enabled) { | ||
super(parent, style); | ||
this.message = message; | ||
messageEnabled = enabled; | ||
this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); | ||
this.setLayout(new GridLayout(2, false)); | ||
|
||
enabledCheckbox = new Button(this, SWT.CHECK); | ||
GridData gdata = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); | ||
gdata.horizontalSpan = 2; | ||
enabledCheckbox.setLayoutData(gdata); | ||
enabledCheckbox.setText("Code: " + message.getCode() + " -- Description: " + descriptions.get(message.getCode())); | ||
enabledCheckbox.setSelection(enabled); | ||
enabledCheckbox.addSelectionListener(new SelectionAdapter() { | ||
@Override | ||
public void widgetSelected(SelectionEvent event) { | ||
Button btn = (Button) event.getSource(); | ||
setMessageEnabled(btn.getSelection()); | ||
} | ||
}); | ||
|
||
severityCombo = new Combo(this, SWT.NONE); | ||
severityCombo.setItems(new String[] {"INFO", "WARN", "ERROR"}); | ||
severityCombo.setText(message.getSeverity()); | ||
|
||
messageText = new Text(this, SWT.BORDER); | ||
messageText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); | ||
messageText.setText(message.getMessageText() == null ? "" : message.getMessageText()); | ||
|
||
setMessageEnabled(enabled); | ||
|
||
} | ||
|
||
@Override | ||
protected void checkSubclass() { | ||
// Disable the check that prevents subclassing of SWT components | ||
} | ||
|
||
public boolean getMessageEnabled() { | ||
return messageEnabled; | ||
} | ||
public void setMessageEnabled(boolean enabled) { | ||
messageEnabled = enabled; | ||
enabledCheckbox.setSelection(enabled); | ||
severityCombo.setEnabled(enabled); | ||
messageText.setEnabled(enabled); | ||
} | ||
|
||
public PluginMessage getMessage() { | ||
message.setMessageText(messageText.getText()); | ||
message.setSeverity(severityCombo.getText()); | ||
return message; | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
org.cfeclipse.cfml/src/org/cfeclipse/cfml/cflint/ParameterEditor.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,53 @@ | ||
package org.cfeclipse.cfml.cflint; | ||
|
||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Group; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.widgets.Label; | ||
import org.eclipse.swt.layout.GridLayout; | ||
import org.eclipse.swt.layout.GridData; | ||
import org.eclipse.swt.widgets.Text; | ||
|
||
import com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginParameter; | ||
|
||
public class ParameterEditor extends Group { | ||
private Text parameterText; | ||
private PluginParameter parameter; | ||
|
||
/** | ||
* Create the composite. | ||
* @param parent | ||
* @param style | ||
* @param parameter | ||
*/ | ||
public ParameterEditor(Composite parent, int style, PluginParameter parameter) { | ||
super(parent, style); | ||
this.parameter = parameter; | ||
this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); | ||
this.setLayout(new GridLayout(3, false)); | ||
|
||
Label parameterLabel = new Label(this, SWT.NONE); | ||
parameterLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); | ||
parameterLabel.setText("Parameter"); | ||
|
||
Label parameterNameLabel = new Label(this, SWT.NONE); | ||
parameterNameLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); | ||
parameterNameLabel.setText(parameter.getName()); | ||
|
||
parameterText = new Text(this, SWT.BORDER); | ||
parameterText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); | ||
parameterText.setText(parameter.getValue()); | ||
|
||
} | ||
|
||
@Override | ||
protected void checkSubclass() { | ||
// Disable the check that prevents subclassing of SWT components | ||
} | ||
|
||
public PluginParameter getParameter() { | ||
parameter.setValue(parameterText.getText()); | ||
return parameter; | ||
} | ||
|
||
} |
Oops, something went wrong.