Search in sources :

Example 11 with CheckstylePluginException

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

the class CheckstyleBuilder method handleBuildSelection.

/**
 * Builds the selected resources.
 *
 * @param resources
 *          the resourcesto build
 * @param configuration
 *          the project configuration
 * @param monitor
 *          the progress monitor
 * @param project
 *          the built project
 * @param kind
 *          the kind of build
 * @param <T>
 *          the resource type parameter
 * @throws CoreException
 *           if the build fails
 */
public final <T extends IResource> void handleBuildSelection(final Collection<T> resources, final IProjectConfiguration configuration, final IProgressMonitor monitor, final IProject project, final int kind) throws CoreException {
    // on full build remove all previous checkstyle markers
    if (kind == IncrementalProjectBuilder.FULL_BUILD) {
        project.deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_INFINITE);
    }
    boolean backgroundFullBuild = CheckstylePluginPrefs.getBoolean(CheckstylePluginPrefs.PREF_BACKGROUND_FULL_BUILD);
    try {
        // 
        // Build a set of auditors from the file sets of this project
        // configuration.
        // File sets that share the same check configuration merge into
        // one Auditor.
        // 
        List<FileSet> fileSets = configuration.getFileSets();
        Map<ICheckConfiguration, Auditor> audits = new HashMap<>();
        for (FileSet fileSet : fileSets) {
            // skip not enabled filesets
            if (!fileSet.isEnabled()) {
                continue;
            }
            ICheckConfiguration checkConfig = fileSet.getCheckConfig();
            if (checkConfig == null) {
                throw new CheckstylePluginException(NLS.bind(Messages.errorNoCheckConfig, project.getName()));
            }
            // get an already created audit from the map
            Auditor audit = audits.get(checkConfig);
            // create the audit with the file sets check configuration
            if (audit == null) {
                audit = new Auditor(checkConfig);
                audits.put(checkConfig, audit);
            }
            // check which files belong to the file set
            for (IResource resource : resources) {
                if (resource instanceof IFile) {
                    IFile file = (IFile) resource;
                    // if file set includes file add to the audit
                    if (fileSet.includesFile(file)) {
                        audit.addFile(file);
                        // remove markers on this file
                        file.deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_ZERO);
                        // remove markers from package to prevent
                        // packagehtml messages from accumulatin
                        file.getParent().deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_ZERO);
                    }
                }
            }
        }
        // run all auditors
        for (Auditor audit : audits.values()) {
            if (monitor.isCanceled()) {
                throw new OperationCanceledException();
            }
            if (backgroundFullBuild && kind == FULL_BUILD) {
                AuditorJob j = new AuditorJob(project, audit);
                j.schedule();
            } else {
                audit.runAudit(project, monitor);
            }
        }
    } catch (CheckstylePluginException e) {
        Status status = new Status(IStatus.ERROR, CheckstylePlugin.PLUGIN_ID, IStatus.ERROR, e.getLocalizedMessage(), e);
        throw new CoreException(status);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IFile(org.eclipse.core.resources.IFile) FileSet(net.sf.eclipsecs.core.projectconfig.FileSet) ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) HashMap(java.util.HashMap) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) AuditorJob(net.sf.eclipsecs.core.jobs.AuditorJob) CoreException(org.eclipse.core.runtime.CoreException) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) IResource(org.eclipse.core.resources.IResource)

Example 12 with CheckstylePluginException

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

the class CheckstylePreferencePage method performOk.

/**
 * {@inheritDoc}
 */
@Override
public boolean performOk() {
    try {
        // 
        // Save the check configurations.
        // 
        mWorkingSet.store();
        // 
        // Save the general preferences.
        // 
        CheckstyleUIPluginPrefs.setString(CheckstyleUIPluginPrefs.PREF_ASK_BEFORE_REBUILD, mRebuildIfNeeded.getItem(mRebuildIfNeeded.getSelectionIndex()));
        // 
        // fileset warning preference
        // 
        boolean warnFileSetsNow = mWarnBeforeLosingFilesets.getSelection();
        CheckstyleUIPluginPrefs.setBoolean(CheckstyleUIPluginPrefs.PREF_FILESET_WARNING, warnFileSetsNow);
        // 
        // Include rule names preference.
        // 
        boolean includeRuleNamesNow = mIncludeRuleNamesButton.getSelection();
        boolean includeRuleNamesOriginal = CheckstylePluginPrefs.getBoolean(CheckstylePluginPrefs.PREF_INCLUDE_RULE_NAMES);
        CheckstylePluginPrefs.setBoolean(CheckstylePluginPrefs.PREF_INCLUDE_RULE_NAMES, includeRuleNamesNow);
        // 
        // Include module id preference.
        // 
        boolean includeModuleIdNow = mIncludeModuleIdButton.getSelection();
        boolean includeModuleIdOriginal = CheckstylePluginPrefs.getBoolean(CheckstylePluginPrefs.PREF_INCLUDE_MODULE_IDS);
        CheckstylePluginPrefs.setBoolean(CheckstylePluginPrefs.PREF_INCLUDE_MODULE_IDS, includeModuleIdNow);
        // 
        // Limit markers preference
        // 
        boolean limitMarkersNow = mLimitCheckstyleMarkers.getSelection();
        boolean limitMarkersOriginal = CheckstylePluginPrefs.getBoolean(CheckstylePluginPrefs.PREF_LIMIT_MARKERS_PER_RESOURCE);
        CheckstylePluginPrefs.setBoolean(CheckstylePluginPrefs.PREF_LIMIT_MARKERS_PER_RESOURCE, limitMarkersNow);
        int markerLimitNow = Integer.parseInt(mTxtMarkerLimit.getText());
        int markerLimitOriginal = CheckstylePluginPrefs.getInt(CheckstylePluginPrefs.PREF_MARKER_AMOUNT_LIMIT);
        CheckstylePluginPrefs.setInt(CheckstylePluginPrefs.PREF_MARKER_AMOUNT_LIMIT, markerLimitNow);
        // 
        // Include background build preference.
        // 
        boolean runInBackgroundNow = mBackgroundFullBuild.getSelection();
        CheckstylePluginPrefs.setBoolean(CheckstylePluginPrefs.PREF_BACKGROUND_FULL_BUILD, runInBackgroundNow);
        // See if all projects need rebuild
        boolean needRebuildAllProjects = (includeRuleNamesNow != includeRuleNamesOriginal) || (includeModuleIdNow != includeModuleIdOriginal) || (limitMarkersNow != limitMarkersOriginal) || (markerLimitNow != markerLimitOriginal) || mRebuildAll;
        // Get projects that need rebuild considering the changes
        Collection<IProject> projectsToBuild = mWorkingSet.getAffectedProjects();
        String promptRebuildPref = CheckstyleUIPluginPrefs.getString(CheckstyleUIPluginPrefs.PREF_ASK_BEFORE_REBUILD);
        boolean rebuild = MessageDialogWithToggle.ALWAYS.equals(promptRebuildPref) && (needRebuildAllProjects || projectsToBuild.size() > 0);
        // 
        if (MessageDialogWithToggle.PROMPT.equals(promptRebuildPref) && (needRebuildAllProjects || projectsToBuild.size() > 0)) {
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(getShell(), Messages.CheckstylePreferencePage_titleRebuild, Messages.CheckstylePreferencePage_msgRebuild, Messages.CheckstylePreferencePage_nagRebuild, false, CheckstyleUIPlugin.getDefault().getPreferenceStore(), CheckstyleUIPluginPrefs.PREF_ASK_BEFORE_REBUILD);
            rebuild = dialog.getReturnCode() == IDialogConstants.YES_ID;
        }
        if (rebuild) {
            try {
                if (needRebuildAllProjects) {
                    CheckstyleBuilder.buildAllProjects();
                } else {
                    CheckstyleBuilder.buildProjects(projectsToBuild);
                }
            } catch (CheckstylePluginException e) {
                CheckstyleUIPlugin.errorDialog(getShell(), NLS.bind(Messages.errorFailedRebuild, e.getMessage()), e, true);
            }
        }
    } catch (CheckstylePluginException e) {
        CheckstyleUIPlugin.errorDialog(getShell(), NLS.bind(Messages.errorFailedSavePreferences, e.getLocalizedMessage()), e, true);
    } catch (BackingStoreException e) {
        CheckstyleUIPlugin.errorDialog(getShell(), NLS.bind(Messages.errorFailedSavePreferences, e.getLocalizedMessage()), e, true);
    }
    return true;
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) IProject(org.eclipse.core.resources.IProject)

Example 13 with CheckstylePluginException

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

the class ComplexFileSetsEditor method editFileSet.

private void editFileSet() {
    IStructuredSelection selection = (IStructuredSelection) mViewer.getSelection();
    FileSet fileSet = (FileSet) selection.getFirstElement();
    if (fileSet == null) {
        // 
        return;
    }
    try {
        FileSetEditDialog dialog = new FileSetEditDialog(mComposite.getShell(), fileSet.clone(), mProject, mPropertyPage);
        if (Window.OK == dialog.open()) {
            FileSet newFileSet = dialog.getFileSet();
            mFileSets.remove(fileSet);
            mFileSets.add(newFileSet);
            mViewer.refresh();
            mViewer.setChecked(newFileSet, newFileSet.isEnabled());
            mPropertyPage.getContainer().updateButtons();
        }
    } catch (CheckstylePluginException e) {
        CheckstyleUIPlugin.errorDialog(mComposite.getShell(), NLS.bind(Messages.errorFailedEditFileset, e.getMessage()), e, true);
    }
}
Also used : FileSet(net.sf.eclipsecs.core.projectconfig.FileSet) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 14 with CheckstylePluginException

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

the class RemoteConfigurationEditor method createEditorControl.

/**
 * {@inheritDoc}
 */
@Override
public Control createEditorControl(Composite parent, final Shell shell) {
    Composite contents = new Composite(parent, SWT.NULL);
    contents.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    contents.setLayout(layout);
    Label lblConfigName = new Label(contents, SWT.NULL);
    lblConfigName.setText(Messages.CheckConfigurationPropertiesDialog_lblName);
    GridData gd = new GridData();
    lblConfigName.setLayoutData(gd);
    mConfigName = new Text(contents, SWT.LEFT | SWT.SINGLE | SWT.BORDER);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    mConfigName.setLayoutData(gd);
    Label lblConfigLocation = new Label(contents, SWT.NULL);
    lblConfigLocation.setText(Messages.CheckConfigurationPropertiesDialog_lblLocation);
    gd = new GridData();
    gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
    lblConfigLocation.setLayoutData(gd);
    mLocation = new Text(contents, SWT.LEFT | SWT.SINGLE | SWT.BORDER);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    mLocation.setLayoutData(gd);
    Label lblDescription = new Label(contents, SWT.NULL);
    lblDescription.setText(Messages.CheckConfigurationPropertiesDialog_lblDescription);
    gd = new GridData();
    gd.horizontalSpan = 2;
    lblDescription.setLayoutData(gd);
    mDescription = new Text(contents, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.VERTICAL);
    gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 2;
    gd.widthHint = 300;
    gd.heightHint = 100;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    mDescription.setLayoutData(gd);
    Group credentialsGroup = new Group(contents, SWT.NULL);
    credentialsGroup.setText(Messages.RemoteConfigurationEditor_titleCredentialsGroup);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    credentialsGroup.setLayoutData(gd);
    credentialsGroup.setLayout(new GridLayout(2, false));
    Label lblUserName = new Label(credentialsGroup, SWT.NULL);
    lblUserName.setText(Messages.RemoteConfigurationEditor_lblUserName);
    gd = new GridData();
    lblUserName.setLayoutData(gd);
    mUserName = new Text(credentialsGroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.widthHint = 100;
    mUserName.setLayoutData(gd);
    Label lblPassword = new Label(credentialsGroup, SWT.NULL);
    lblPassword.setText(Messages.RemoteConfigurationEditor_lblPassword);
    gd = new GridData();
    lblPassword.setLayoutData(gd);
    mPassword = new Text(credentialsGroup, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
    gd = new GridData();
    gd.widthHint = 100;
    mPassword.setLayoutData(gd);
    Group advancedGroup = new Group(contents, SWT.NULL);
    advancedGroup.setText(Messages.RemoteConfigurationEditor_titleAdvancedOptions);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    advancedGroup.setLayoutData(gd);
    advancedGroup.setLayout(new GridLayout(2, false));
    mChkCacheConfig = new Button(advancedGroup, SWT.CHECK);
    mChkCacheConfig.setText(Messages.RemoteConfigurationEditor_btnCacheRemoteConfig);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    mChkCacheConfig.setLayoutData(gd);
    if (mWorkingCopy.getName() != null) {
        mConfigName.setText(mWorkingCopy.getName());
    }
    if (mWorkingCopy.getLocation() != null) {
        mLocation.setText(mWorkingCopy.getLocation());
    }
    if (mWorkingCopy.getDescription() != null) {
        mDescription.setText(mWorkingCopy.getDescription());
    }
    mChkCacheConfig.setSelection(Boolean.valueOf(mWorkingCopy.getAdditionalData().get(RemoteConfigurationType.KEY_CACHE_CONFIG)).booleanValue());
    if (mWorkingCopy.getLocation() != null) {
        try {
            PasswordAuthentication auth = RemoteConfigurationType.RemoteConfigAuthenticator.getPasswordAuthentication(mWorkingCopy.getResolvedConfigurationFileURL());
            if (auth != null) {
                mUserName.setText(auth.getUserName());
                mPassword.setText(new String(auth.getPassword()));
            }
        } catch (CheckstylePluginException e) {
            CheckstyleUIPlugin.errorDialog(shell, e, true);
        }
    }
    return contents;
}
Also used : Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) Text(org.eclipse.swt.widgets.Text) PasswordAuthentication(java.net.PasswordAuthentication)

Example 15 with CheckstylePluginException

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

the class RunCheckstyleOnFilesJob method runInWorkspace.

/**
 * {@inheritDoc}
 */
@Override
public final IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
    try {
        Map<IProject, List<IFile>> projectFilesMap = getFilesSortedToProject(mFilesToCheck);
        for (Map.Entry<IProject, List<IFile>> entry : projectFilesMap.entrySet()) {
            IProject project = entry.getKey();
            List<IFile> files = entry.getValue();
            IProjectConfiguration checkConfig = ProjectConfigurationFactory.getConfiguration(project);
            filter(files, checkConfig);
            CheckstyleBuilder builder = new CheckstyleBuilder();
            builder.handleBuildSelection(files, checkConfig, monitor, project, IncrementalProjectBuilder.INCREMENTAL_BUILD);
        }
    } catch (CheckstylePluginException e) {
        Status status = new Status(IStatus.ERROR, CheckstylePlugin.PLUGIN_ID, IStatus.ERROR, e.getLocalizedMessage(), e);
        throw new CoreException(status);
    }
    return Status.OK_STATUS;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) CheckstyleBuilder(net.sf.eclipsecs.core.builder.CheckstyleBuilder) IProjectConfiguration(net.sf.eclipsecs.core.projectconfig.IProjectConfiguration) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) 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