Search in sources :

Example 6 with FileSet

use of net.sf.eclipsecs.core.projectconfig.FileSet in project eclipse-cs by checkstyle.

the class GlobalCheckConfigurationWorkingSet method updateProjectConfigurations.

/**
 * Updates the project configurations that use the changed check configurations.
 *
 * @param configurations
 *          the check configurations
 * @throws CheckstylePluginException
 *           an unexpected exception occurred
 */
private void updateProjectConfigurations() throws CheckstylePluginException {
    for (CheckConfigurationWorkingCopy checkConfig : mWorkingCopies) {
        ICheckConfiguration original = checkConfig.getSourceCheckConfiguration();
        // only if the name of the check config differs from the original
        if (original != null && original.getName() != null && !checkConfig.getName().equals(original.getName())) {
            List<IProject> projects = ProjectConfigurationFactory.getProjectsUsingConfig(checkConfig);
            for (IProject project : projects) {
                IProjectConfiguration projectConfig = ProjectConfigurationFactory.getConfiguration(project);
                ProjectConfigurationWorkingCopy workingCopy = new ProjectConfigurationWorkingCopy(projectConfig);
                List<FileSet> fileSets = workingCopy.getFileSets();
                for (FileSet fileSet : fileSets) {
                    // Check if the fileset uses the check config
                    if (original.equals(fileSet.getCheckConfig())) {
                        // set the new check configuration
                        fileSet.setCheckConfig(checkConfig);
                    }
                }
                // store the project configuration
                if (workingCopy.isDirty()) {
                    workingCopy.store();
                }
            }
        }
    }
}
Also used : FileSet(net.sf.eclipsecs.core.projectconfig.FileSet) IProjectConfiguration(net.sf.eclipsecs.core.projectconfig.IProjectConfiguration) ProjectConfigurationWorkingCopy(net.sf.eclipsecs.core.projectconfig.ProjectConfigurationWorkingCopy) IProject(org.eclipse.core.resources.IProject)

Example 7 with FileSet

use of net.sf.eclipsecs.core.projectconfig.FileSet in project eclipse-cs by checkstyle.

the class ComplexFileSetsEditor method addFileSet.

private void addFileSet() {
    try {
        FileSetEditDialog dialog = new FileSetEditDialog(mComposite.getShell(), null, mProject, mPropertyPage);
        if (Window.OK == dialog.open()) {
            FileSet fileSet = dialog.getFileSet();
            mFileSets.add(fileSet);
            mViewer.refresh();
            mViewer.setChecked(fileSet, fileSet.isEnabled());
            mPropertyPage.getContainer().updateButtons();
        }
    } catch (CheckstylePluginException e) {
        CheckstyleUIPlugin.errorDialog(mComposite.getShell(), NLS.bind(Messages.errorFailedAddFileset, e.getMessage()), e, true);
    }
}
Also used : FileSet(net.sf.eclipsecs.core.projectconfig.FileSet) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException)

Example 8 with FileSet

use of net.sf.eclipsecs.core.projectconfig.FileSet in project eclipse-cs by checkstyle.

the class SimpleFileSetsEditor method setFileSets.

/**
 * {@inheritDoc}
 */
@Override
public void setFileSets(List<FileSet> fileSets) throws CheckstylePluginException {
    mFileSets = fileSets;
    ICheckConfiguration config = null;
    if (mFileSets.size() > 0) {
        config = (mFileSets.get(0)).getCheckConfig();
    }
    if (config == null) {
        CheckConfigurationWorkingCopy[] allConfigs = mPropertyPage.getProjectConfigurationWorkingCopy().getGlobalCheckConfigWorkingSet().getWorkingCopies();
        if (allConfigs.length > 0) {
            config = allConfigs[0];
        }
    }
    mDefaultFileSet = new FileSet(Messages.SimpleFileSetsEditor_nameAllFileset, config);
    // $NON-NLS-1$
    mDefaultFileSet.getFileMatchPatterns().add(new FileMatchPattern("."));
    mFileSets.clear();
    mFileSets.add(mDefaultFileSet);
}
Also used : FileMatchPattern(net.sf.eclipsecs.core.projectconfig.FileMatchPattern) FileSet(net.sf.eclipsecs.core.projectconfig.FileSet) ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) CheckConfigurationWorkingCopy(net.sf.eclipsecs.core.config.CheckConfigurationWorkingCopy)

Example 9 with FileSet

use of net.sf.eclipsecs.core.projectconfig.FileSet in project eclipse-cs by checkstyle.

the class TransformCheckstyleRulesJob method runInWorkspace.

/**
 * {@inheritDoc}
 */
@Override
public IStatus runInWorkspace(final IProgressMonitor arg0) throws CoreException {
    try {
        final IProjectConfiguration conf = ProjectConfigurationFactory.getConfiguration(mProject);
        final List<Configuration> rules = new ArrayList<Configuration>();
        // collect rules from all configured filesets
        for (FileSet fs : conf.getFileSets()) {
            ICheckConfiguration checkConfig = fs.getCheckConfig();
            CheckstyleConfigurationFile configFile = checkConfig.getCheckstyleConfiguration();
            PropertyResolver resolver = configFile.getPropertyResolver();
            // context
            if (resolver instanceof IContextAware) {
                ((IContextAware) resolver).setProjectContext(mProject);
            }
            InputSource in = null;
            try {
                in = configFile.getCheckConfigFileInputSource();
                Configuration configuration = ConfigurationLoader.loadConfiguration(in, resolver, true);
                // flatten the nested configuration tree into a list
                recurseConfiguration(configuration, rules);
            } finally {
                Closeables.closeQuietly(in.getByteStream());
            }
        }
        if (rules.isEmpty()) {
            return Status.CANCEL_STATUS;
        }
        final CheckstyleTransformer transformer = new CheckstyleTransformer(mProject, rules);
        transformer.transformRules();
    } catch (CheckstyleException e) {
        Status status = new Status(IStatus.ERROR, CheckstylePlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
        throw new CoreException(status);
    } catch (CheckstylePluginException e) {
        Status status = new Status(IStatus.ERROR, CheckstylePlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
        throw new CoreException(status);
    }
    return Status.OK_STATUS;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) InputSource(org.xml.sax.InputSource) Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) IProjectConfiguration(net.sf.eclipsecs.core.projectconfig.IProjectConfiguration) ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) FileSet(net.sf.eclipsecs.core.projectconfig.FileSet) ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) IProjectConfiguration(net.sf.eclipsecs.core.projectconfig.IProjectConfiguration) ArrayList(java.util.ArrayList) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) PropertyResolver(com.puppycrawl.tools.checkstyle.PropertyResolver) IContextAware(net.sf.eclipsecs.core.config.configtypes.IContextAware) CoreException(org.eclipse.core.runtime.CoreException) CheckstyleConfigurationFile(net.sf.eclipsecs.core.config.CheckstyleConfigurationFile) CheckstyleTransformer(net.sf.eclipsecs.core.transformer.CheckstyleTransformer) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException)

Aggregations

FileSet (net.sf.eclipsecs.core.projectconfig.FileSet)9 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)4 ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)3 IProjectConfiguration (net.sf.eclipsecs.core.projectconfig.IProjectConfiguration)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 PropertyResolver (com.puppycrawl.tools.checkstyle.PropertyResolver)1 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CheckConfigurationWorkingCopy (net.sf.eclipsecs.core.config.CheckConfigurationWorkingCopy)1 CheckstyleConfigurationFile (net.sf.eclipsecs.core.config.CheckstyleConfigurationFile)1 IContextAware (net.sf.eclipsecs.core.config.configtypes.IContextAware)1 AuditorJob (net.sf.eclipsecs.core.jobs.AuditorJob)1 FileMatchPattern (net.sf.eclipsecs.core.projectconfig.FileMatchPattern)1 ProjectConfigurationWorkingCopy (net.sf.eclipsecs.core.projectconfig.ProjectConfigurationWorkingCopy)1 CheckstyleTransformer (net.sf.eclipsecs.core.transformer.CheckstyleTransformer)1