Search in sources :

Example 26 with CheckstylePluginException

use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.

the class CheckConfigurationWorkingSetEditor method exportCheckstyleCheckConfig.

/**
 * Export a configuration.
 */
private void exportCheckstyleCheckConfig() {
    IStructuredSelection selection = (IStructuredSelection) mViewer.getSelection();
    ICheckConfiguration config = (ICheckConfiguration) selection.getFirstElement();
    if (config == null) {
        // 
        return;
    }
    FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
    dialog.setText(Messages.CheckstylePreferencePage_titleExportConfig);
    String path = dialog.open();
    if (path == null) {
        return;
    }
    File file = new File(path);
    try {
        CheckConfigurationFactory.exportConfiguration(file, config);
    } catch (CheckstylePluginException e) {
        CheckstyleUIPlugin.errorDialog(getShell(), Messages.msgErrorFailedExportConfig, e, true);
    }
}
Also used : ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 27 with CheckstylePluginException

use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.

the class RuleConfigurationEditDialog method okPressed.

/**
 * OK button was selected.
 */
@Override
protected void okPressed() {
    // 
    // Get the selected severity level.
    // 
    Severity severity = mRule.getSeverity();
    try {
        severity = (Severity) ((IStructuredSelection) mSeverityCombo.getSelection()).getFirstElement();
    } catch (IllegalArgumentException e) {
        CheckstyleLog.log(e);
    }
    // Get the comment.
    final String comment = Strings.emptyToNull(mCommentText.getText());
    // Get the id
    final String id = Strings.emptyToNull(mIdText.getText());
    // Get the custom message
    for (Map.Entry<String, Text> entry : mCustomMessages.entrySet()) {
        String msgKey = entry.getKey();
        String standardMessage = MetadataFactory.getStandardMessage(msgKey, mRule.getMetaData().getInternalName());
        if (standardMessage == null) {
            // $NON-NLS-1$
            standardMessage = "";
        }
        String message = Strings.emptyToNull(entry.getValue().getText());
        if (message != null && !message.equals(standardMessage)) {
            mRule.getCustomMessages().put(msgKey, message);
        } else {
            mRule.getCustomMessages().remove(msgKey);
        }
    }
    // 
    if (mConfigPropertyWidgets != null) {
        for (int i = 0; i < mConfigPropertyWidgets.length; i++) {
            IConfigPropertyWidget widget = mConfigPropertyWidgets[i];
            ConfigProperty property = widget.getConfigProperty();
            try {
                widget.validate();
            } catch (CheckstylePluginException e) {
                String message = NLS.bind(Messages.RuleConfigurationEditDialog_msgInvalidPropertyValue, property.getMetaData().getName());
                this.setErrorMessage(message);
                return;
            }
            property.setValue(widget.getValue());
        }
    }
    // 
    // If we made it this far then all of the user input validated and we
    // can
    // update the final rule with the values the user entered.
    // 
    mRule.setSeverity(severity);
    mRule.setComment(comment);
    mRule.setId(id);
    super.okPressed();
}
Also used : ConfigProperty(net.sf.eclipsecs.core.config.ConfigProperty) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) Severity(net.sf.eclipsecs.core.config.Severity) Text(org.eclipse.swt.widgets.Text) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) HashMap(java.util.HashMap) Map(java.util.Map) IConfigPropertyWidget(net.sf.eclipsecs.ui.config.widgets.IConfigPropertyWidget)

Example 28 with CheckstylePluginException

use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.

the class CheckstylePropertyPage method setElement.

/**
 * {@inheritDoc}
 */
@Override
public void setElement(IAdaptable element) {
    super.setElement(element);
    IProject project = null;
    try {
        // 
        // Get the project.
        // 
        IResource resource = (IResource) element;
        if (resource.getType() == IResource.PROJECT) {
            project = (IProject) resource;
        }
        IProjectConfiguration projectConfig = ProjectConfigurationFactory.getConfiguration(project);
        mProjectConfig = new ProjectConfigurationWorkingCopy(projectConfig);
        mCheckstyleInitiallyActivated = project.hasNature(CheckstyleNature.NATURE_ID);
    } catch (CoreException e) {
        handleConfigFileError(e, project);
    } catch (CheckstylePluginException e) {
        handleConfigFileError(e, project);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IProjectConfiguration(net.sf.eclipsecs.core.projectconfig.IProjectConfiguration) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) ProjectConfigurationWorkingCopy(net.sf.eclipsecs.core.projectconfig.ProjectConfigurationWorkingCopy) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Example 29 with CheckstylePluginException

use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.

the class CheckstylePropertyPage method performOk.

@Override
public boolean performOk() {
    try {
        IProject project = mProjectConfig.getProject();
        // save the edited project configuration
        if (mProjectConfig.isDirty()) {
            mProjectConfig.store();
        }
        boolean checkstyleEnabled = mChkEnable.getSelection();
        boolean needRebuild = mProjectConfig.isRebuildNeeded();
        // check if checkstyle nature has to be configured/deconfigured
        if (checkstyleEnabled != mCheckstyleInitiallyActivated) {
            ConfigureDeconfigureNatureJob configOperation = new ConfigureDeconfigureNatureJob(project, CheckstyleNature.NATURE_ID);
            configOperation.setRule(ResourcesPlugin.getWorkspace().getRoot());
            configOperation.schedule();
            needRebuild = needRebuild || !mCheckstyleInitiallyActivated;
        }
        if (checkstyleEnabled && mProjectConfig.isSyncFormatter()) {
            TransformCheckstyleRulesJob transFormJob = new TransformCheckstyleRulesJob(project);
            transFormJob.schedule();
        }
        // really be done.
        if (checkstyleEnabled && needRebuild) {
            String promptRebuildPref = CheckstyleUIPluginPrefs.getString(CheckstyleUIPluginPrefs.PREF_ASK_BEFORE_REBUILD);
            boolean doRebuild = MessageDialogWithToggle.ALWAYS.equals(promptRebuildPref) && needRebuild;
            // 
            if (MessageDialogWithToggle.PROMPT.equals(promptRebuildPref) && needRebuild) {
                MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(getShell(), Messages.CheckstylePropertyPage_titleRebuild, Messages.CheckstylePropertyPage_msgRebuild, Messages.CheckstylePropertyPage_nagRebuild, false, CheckstyleUIPlugin.getDefault().getPreferenceStore(), CheckstyleUIPluginPrefs.PREF_ASK_BEFORE_REBUILD);
                doRebuild = dialog.getReturnCode() == IDialogConstants.YES_ID;
            }
            // check if a rebuild is necessary
            if (checkstyleEnabled && doRebuild) {
                BuildProjectJob rebuildOperation = new BuildProjectJob(project, IncrementalProjectBuilder.FULL_BUILD);
                rebuildOperation.setRule(ResourcesPlugin.getWorkspace().getRoot());
                rebuildOperation.schedule();
            }
        }
    } catch (CheckstylePluginException e) {
        CheckstyleUIPlugin.errorDialog(getShell(), e, true);
    }
    return true;
}
Also used : TransformCheckstyleRulesJob(net.sf.eclipsecs.core.jobs.TransformCheckstyleRulesJob) ConfigureDeconfigureNatureJob(net.sf.eclipsecs.core.jobs.ConfigureDeconfigureNatureJob) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) BuildProjectJob(net.sf.eclipsecs.core.jobs.BuildProjectJob) IProject(org.eclipse.core.resources.IProject)

Example 30 with CheckstylePluginException

use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.

the class CheckFileOnOpenPartListener method isFileAffected.

/**
 * Checks if the given file is affected by the UnOpenedFilesFilter and needs to be handled on
 * editor open/close.
 *
 * @param file
 *          the file to check
 * @return <code>true</code> if the file is affected, <code>false</code> otherwise
 */
private boolean isFileAffected(IFile file) {
    boolean affected = false;
    IProject project = file.getProject();
    try {
        // check if checkstyle is enabled on the project
        if (project.isAccessible() && project.hasNature(CheckstyleNature.NATURE_ID)) {
            IProjectConfiguration config = ProjectConfigurationFactory.getConfiguration(project);
            // now check if the UnOpenedFilesFilter is active
            boolean unOpenedFilesFilterActive = false;
            boolean filtered = false;
            List<IFilter> filters = config.getFilters();
            for (IFilter filter : filters) {
                if (filter instanceof UnOpenedFilesFilter && ((UnOpenedFilesFilter) filter).isEnabled()) {
                    unOpenedFilesFilterActive = true;
                }
                // check if the file would be filtered out
                if (filter.isEnabled() && !(filter instanceof UnOpenedFilesFilter)) {
                    filtered = filtered || !filter.accept(file);
                }
            }
            affected = unOpenedFilesFilterActive && !filtered;
        }
    } catch (CoreException e) {
        // should never happen, since editor cannot be open
        // when project isn't
        CheckstyleLog.log(e);
    } catch (CheckstylePluginException e) {
        CheckstyleLog.log(e);
    }
    return affected;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) IProjectConfiguration(net.sf.eclipsecs.core.projectconfig.IProjectConfiguration) UnOpenedFilesFilter(net.sf.eclipsecs.core.projectconfig.filters.UnOpenedFilesFilter) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) IProject(org.eclipse.core.resources.IProject)

Aggregations

CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)34 ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)7 IProject (org.eclipse.core.resources.IProject)7 CoreException (org.eclipse.core.runtime.CoreException)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 IProjectConfiguration (net.sf.eclipsecs.core.projectconfig.IProjectConfiguration)5 GridData (org.eclipse.swt.layout.GridData)5 Composite (org.eclipse.swt.widgets.Composite)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 FileSet (net.sf.eclipsecs.core.projectconfig.FileSet)4 IFilter (net.sf.eclipsecs.core.projectconfig.filters.IFilter)4 Document (org.dom4j.Document)4 IStatus (org.eclipse.core.runtime.IStatus)4 Status (org.eclipse.core.runtime.Status)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Button (org.eclipse.swt.widgets.Button)4 File (java.io.File)3 IOException (java.io.IOException)3 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)2