use of net.sourceforge.pmd.eclipse.runtime.writer.IRuleSetWriter in project pmd-eclipse-plugin by pmd.
the class RuleTableManager method exportTo.
private void exportTo(String fileName, Shell shell) throws FileNotFoundException, WriterException, IOException {
File file = new File(fileName);
boolean flContinue = true;
if (file.exists()) {
flContinue = MessageDialog.openConfirm(shell, getMessage(StringKeys.CONFIRM_TITLE), getMessage(StringKeys.CONFIRM_RULESET_EXISTS));
}
InputDialog input = null;
RuleSet ruleSet = null;
if (flContinue) {
ruleSet = ruleSelectionAsRuleSet();
input = new InputDialog(shell, getMessage(StringKeys.PREF_RULESET_DIALOG_TITLE), getMessage(StringKeys.PREF_RULESET_DIALOG_RULESET_DESCRIPTION), ruleSet.getDescription() == null ? "" : ruleSet.getDescription().trim(), null);
flContinue = input.open() == Window.OK;
}
if (flContinue) {
OutputStream out = null;
try {
ruleSet = RuleSetUtil.setNameDescription(ruleSet, FileUtil.getFileNameWithoutExtension(file.getName()), input.getValue());
out = new FileOutputStream(fileName);
IRuleSetWriter writer = plugin.getRuleSetWriter();
writer.write(out, ruleSet);
} finally {
IOUtil.closeQuietly(out);
}
MessageDialog.openInformation(shell, getMessage(StringKeys.INFORMATION_TITLE), getMessage(StringKeys.INFORMATION_RULESET_EXPORTED));
}
}
use of net.sourceforge.pmd.eclipse.runtime.writer.IRuleSetWriter in project pmd-eclipse-plugin by pmd.
the class PMDPreferencePage method buildExportRuleSetButton.
/**
* Build the export rule set button
*/
private Button buildExportRuleSetButton(Composite parent) {
Button button = new Button(parent, SWT.PUSH | SWT.LEFT);
button.setText(getMessage(StringKeys.PREF_RULESET_BUTTON_EXPORTRULESET));
button.setEnabled(true);
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
String fileName = dialog.open();
if (fileName != null) {
try {
File file = new File(fileName);
boolean flContinue = true;
if (file.exists()) {
flContinue = MessageDialog.openConfirm(getShell(), getMessage(StringKeys.CONFIRM_TITLE), getMessage(StringKeys.CONFIRM_RULESET_EXISTS));
}
InputDialog input = null;
if (flContinue) {
input = new InputDialog(getShell(), getMessage(StringKeys.PREF_RULESET_DIALOG_TITLE), getMessage(StringKeys.PREF_RULESET_DIALOG_RULESET_DESCRIPTION), ruleSet.getDescription() == null ? "" : ruleSet.getDescription().trim(), null);
flContinue = input.open() == InputDialog.OK;
}
if (flContinue) {
ruleSet = RuleSetUtil.setNameDescription(ruleSet, getFileNameWithoutExtension(file.getName()), input.getValue());
OutputStream out = new FileOutputStream(fileName);
IRuleSetWriter writer = PMDPlugin.getDefault().getRuleSetWriter();
writer.write(out, ruleSet);
out.close();
MessageDialog.openInformation(getShell(), getMessage(StringKeys.INFORMATION_TITLE), getMessage(StringKeys.INFORMATION_RULESET_EXPORTED));
}
} catch (IOException e) {
PMDPlugin.getDefault().showError(getMessage(StringKeys.ERROR_EXPORTING_RULESET), e);
} catch (WriterException e) {
PMDPlugin.getDefault().showError(getMessage(StringKeys.ERROR_EXPORTING_RULESET), e);
}
}
}
});
return button;
}
use of net.sourceforge.pmd.eclipse.runtime.writer.IRuleSetWriter in project pmd-eclipse-plugin by pmd.
the class ProjectPropertiesImpl method createDefaultRuleSetFile.
/**
* Create a project ruleset file from the current configured rules
*/
public void createDefaultRuleSetFile() throws PropertiesException {
LOG.info("Create a default rule set file for project " + this.project.getName());
ByteArrayOutputStream baos = null;
ByteArrayInputStream bais = null;
try {
IRuleSetWriter writer = PMDPlugin.getDefault().getRuleSetWriter();
baos = new ByteArrayOutputStream();
writer.write(baos, projectRuleSet);
final IFile file = project.getFile(PROJECT_RULESET_FILE);
if (file.exists() && file.isAccessible()) {
throw new PropertiesException("Project ruleset file already exists");
} else {
bais = new ByteArrayInputStream(baos.toByteArray());
file.create(bais, true, null);
}
} catch (WriterException e) {
throw new PropertiesException(e);
} catch (CoreException e) {
throw new PropertiesException(e);
} finally {
IOUtil.closeQuietly(baos);
IOUtil.closeQuietly(bais);
}
}
use of net.sourceforge.pmd.eclipse.runtime.writer.IRuleSetWriter in project pmd-eclipse-plugin by pmd.
the class PreferencesManagerImpl method storeRuleSetInStateLocation.
/**
* Store the rule set in preference store
*/
private void storeRuleSetInStateLocation(RuleSet ruleSet) {
OutputStream out = null;
PMDPlugin plugin = PMDPlugin.getDefault();
try {
IPath ruleSetLocation = plugin.getStateLocation().append(PREFERENCE_RULESET_FILE);
out = new FileOutputStream(ruleSetLocation.toOSString());
IRuleSetWriter writer = plugin.getRuleSetWriter();
writer.write(out, ruleSet);
out.flush();
} catch (IOException e) {
plugin.logError("IO Exception when storing ruleset in state location", e);
} catch (WriterException e) {
plugin.logError("General PMD Eclipse Exception when storing ruleset in state location", e);
} finally {
IOUtil.closeQuietly(out);
}
}
Aggregations