Search in sources :

Example 6 with ICheckConfiguration

use of net.sf.eclipsecs.core.config.ICheckConfiguration in project eclipse-cs by checkstyle.

the class ProjectConfigurationFactory method getProjectConfiguration.

private static IProjectConfiguration getProjectConfiguration(InputStream in, IProject project) throws DocumentException, CheckstylePluginException {
    SAXReader reader = new SAXReader();
    Document document = reader.read(in);
    Element root = document.getRootElement();
    String version = root.attributeValue(XMLTags.FORMAT_VERSION_TAG);
    if (!SUPPORTED_VERSIONS.contains(version)) {
        throw new CheckstylePluginException(NLS.bind(Messages.errorUnknownFileFormat, version));
    }
    boolean useSimpleConfig = Boolean.valueOf(root.attributeValue(XMLTags.SIMPLE_CONFIG_TAG)).booleanValue();
    boolean syncFormatter = Boolean.valueOf(root.attributeValue(XMLTags.SYNC_FORMATTER_TAG)).booleanValue();
    List<ICheckConfiguration> checkConfigs = getLocalCheckConfigs(root, project);
    List<FileSet> fileSets = getFileSets(root, checkConfigs);
    List<IFilter> filters = getFilters(root);
    return new ProjectConfiguration(project, checkConfigs, fileSets, filters, useSimpleConfig, syncFormatter);
}
Also used : ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) Document(org.dom4j.Document) IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException)

Example 7 with ICheckConfiguration

use of net.sf.eclipsecs.core.config.ICheckConfiguration 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 8 with ICheckConfiguration

use of net.sf.eclipsecs.core.config.ICheckConfiguration in project eclipse-cs by checkstyle.

the class InternalConfigurationEditor 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);
    mLocation.setEditable(false);
    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);
    mBtnImport = new Button(contents, SWT.PUSH);
    mBtnImport.setText(Messages.InternalConfigurationEditor_btnImport);
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.horizontalAlignment = GridData.END;
    mBtnImport.setLayoutData(gd);
    mBtnImport.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                ICheckConfiguration targetConfig = getEditedWorkingCopy();
                FileDialog fileDialog = new FileDialog(mConfigName.getShell());
                fileDialog.setText(Messages.InternalConfigurationEditor_titleImportDialog);
                // $NON-NLS-1$ //$NON-NLS-2$
                fileDialog.setFilterExtensions(new String[] { "*.xml", "*.*" });
                String configFileString = fileDialog.open();
                if (configFileString != null && new File(configFileString).exists()) {
                    ICheckConfiguration tmpSourceConfig = new // $NON-NLS-1$
                    CheckConfiguration(// $NON-NLS-1$
                    "dummy", configFileString, null, new ExternalFileConfigurationType(), true, null, null);
                    CheckConfigurationFactory.copyConfiguration(tmpSourceConfig, targetConfig);
                }
            } catch (CheckstylePluginException ex) {
                mDialog.setErrorMessage(ex.getLocalizedMessage());
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // NOOP
        }
    });
    if (mWorkingCopy.getName() != null) {
        mConfigName.setText(mWorkingCopy.getName());
    }
    if (mWorkingCopy.getLocation() != null) {
        mLocation.setText(mWorkingCopy.getLocation());
    }
    if (mWorkingCopy.getDescription() != null) {
        mDescription.setText(mWorkingCopy.getDescription());
    }
    return contents;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) ExternalFileConfigurationType(net.sf.eclipsecs.core.config.configtypes.ExternalFileConfigurationType) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 9 with ICheckConfiguration

use of net.sf.eclipsecs.core.config.ICheckConfiguration in project eclipse-cs by checkstyle.

the class ProjectConfigurationFactory method getFileSets.

@SuppressWarnings("unchecked")
private static List<FileSet> getFileSets(Element root, List<ICheckConfiguration> localCheckConfigs) throws CheckstylePluginException {
    List<FileSet> fileSets = new ArrayList<>();
    List<Element> fileSetElements = root.elements(XMLTags.FILESET_TAG);
    for (Element fileSetEl : fileSetElements) {
        boolean local = Boolean.valueOf(fileSetEl.attributeValue(XMLTags.LOCAL_TAG)).booleanValue();
        FileSet fileSet = new FileSet();
        fileSet.setName(fileSetEl.attributeValue(XMLTags.NAME_TAG));
        fileSet.setEnabled(Boolean.valueOf(fileSetEl.attributeValue(XMLTags.ENABLED_TAG)).booleanValue());
        // find the referenced check configuration
        ICheckConfiguration checkConfig = null;
        String checkConfigName = fileSetEl.attributeValue(XMLTags.CHECK_CONFIG_NAME_TAG);
        if (local) {
            for (ICheckConfiguration tmp : localCheckConfigs) {
                if (tmp.getName().equals(checkConfigName)) {
                    checkConfig = tmp;
                    break;
                }
            }
        } else {
            checkConfig = CheckConfigurationFactory.getByName(checkConfigName);
        }
        fileSet.setCheckConfig(checkConfig);
        // get patterns
        List<FileMatchPattern> patterns = new ArrayList<>();
        List<Element> patternElements = fileSetEl.elements(XMLTags.FILE_MATCH_PATTERN_TAG);
        for (Element patternEl : patternElements) {
            FileMatchPattern pattern = new FileMatchPattern(patternEl.attributeValue(XMLTags.MATCH_PATTERN_TAG));
            pattern.setIsIncludePattern(Boolean.valueOf(patternEl.attributeValue(XMLTags.INCLUDE_PATTERN_TAG)).booleanValue());
            patterns.add(pattern);
        }
        fileSet.setFileMatchPatterns(patterns);
        fileSets.add(fileSet);
    }
    return fileSets;
}
Also used : ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) Element(org.dom4j.Element) ArrayList(java.util.ArrayList)

Example 10 with ICheckConfiguration

use of net.sf.eclipsecs.core.config.ICheckConfiguration 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)

Aggregations

ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)15 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)7 Element (org.dom4j.Element)5 ArrayList (java.util.ArrayList)3 FileSet (net.sf.eclipsecs.core.projectconfig.FileSet)3 File (java.io.File)2 HashMap (java.util.HashMap)2 CheckConfigurationWorkingCopy (net.sf.eclipsecs.core.config.CheckConfigurationWorkingCopy)2 IFilter (net.sf.eclipsecs.core.projectconfig.filters.IFilter)2 Document (org.dom4j.Document)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 FileDialog (org.eclipse.swt.widgets.FileDialog)2 PropertyResolver (com.puppycrawl.tools.checkstyle.PropertyResolver)1 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 CheckConfiguration (net.sf.eclipsecs.core.config.CheckConfiguration)1 CheckstyleConfigurationFile (net.sf.eclipsecs.core.config.CheckstyleConfigurationFile)1