Search in sources :

Example 16 with CheckstylePluginException

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

the class TransformFormatterRulesJob method runInWorkspace.

/**
 * {@inheritDoc}
 */
@Override
public IStatus runInWorkspace(final IProgressMonitor arg0) throws CoreException {
    // TODO this way of loading formatter profiles is very dubious, to say
    // the least, refer to FormatterConfigWriter for a better API
    final String workspace = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();
    final String configLocation = workspace + "/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs";
    FormatterConfigParser parser = null;
    try {
        parser = new FormatterConfigParser(configLocation);
    } catch (final FileNotFoundException e) {
        return Status.CANCEL_STATUS;
    }
    final FormatterConfiguration rules = parser.parseRules();
    if (rules == null) {
        return Status.CANCEL_STATUS;
    }
    try {
        FormatterTransformer transformer = new FormatterTransformer(rules);
        transformer.transformRules(workspace + "/test-checkstyle.xml");
    } 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 : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) FormatterConfiguration(net.sf.eclipsecs.core.transformer.FormatterConfiguration) FormatterConfigParser(net.sf.eclipsecs.core.transformer.FormatterConfigParser) CoreException(org.eclipse.core.runtime.CoreException) FileNotFoundException(java.io.FileNotFoundException) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) FormatterTransformer(net.sf.eclipsecs.core.transformer.FormatterTransformer)

Example 17 with CheckstylePluginException

use of net.sf.eclipsecs.core.util.CheckstylePluginException 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 18 with CheckstylePluginException

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

the class MetadataFactory method parseMetadata.

@SuppressWarnings("unchecked")
private static void parseMetadata(InputStream metadataStream, ResourceBundle metadataBundle) throws DocumentException, CheckstylePluginException {
    SAXReader reader = new SAXReader();
    reader.setEntityResolver(new XMLUtil.InternalDtdEntityResolver(PUBLIC2INTERNAL_DTD_MAP));
    Document document = reader.read(metadataStream);
    List<Element> groupElements = document.getRootElement().elements(XMLTags.RULE_GROUP_METADATA_TAG);
    for (Element groupEl : groupElements) {
        String groupName = groupEl.attributeValue(XMLTags.NAME_TAG).trim();
        groupName = localize(groupName, metadataBundle);
        // process description
        String groupDesc = groupEl.elementTextTrim(XMLTags.DESCRIPTION_TAG);
        groupDesc = localize(groupDesc, metadataBundle);
        RuleGroupMetadata group = getRuleGroupMetadata(groupName);
        if (group == null) {
            boolean hidden = Boolean.valueOf(groupEl.attributeValue(XMLTags.HIDDEN_TAG)).booleanValue();
            int priority = 0;
            try {
                priority = Integer.parseInt(groupEl.attributeValue(XMLTags.PRIORITY_TAG));
            } catch (Exception e) {
                CheckstyleLog.log(e);
                priority = Integer.MAX_VALUE;
            }
            group = new RuleGroupMetadata(groupName, groupDesc, hidden, priority);
            sRuleGroupMetadata.put(groupName, group);
        }
        // process the modules
        processModules(groupEl, group, metadataBundle);
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) XMLUtil(net.sf.eclipsecs.core.util.XMLUtil) Document(org.dom4j.Document) DocumentException(org.dom4j.DocumentException) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException)

Example 19 with CheckstylePluginException

use of net.sf.eclipsecs.core.util.CheckstylePluginException 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 20 with CheckstylePluginException

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

the class ProjectClassLoader method addToClassPath.

/**
 * Adds the contents of a project to list of URLs.
 *
 * @param project
 *          the project
 * @param cpURLs
 *          the resulting list
 * @param isReferenced
 *          true if a referenced project is processed
 */
private static void addToClassPath(IProject project, List<URL> cpURLs, boolean isReferenced, Collection<IProject> processedProjects) {
    try {
        // this project has already been added
        if (processedProjects.contains(project)) {
            return;
        } else {
            processedProjects.add(project);
        }
        // get the java project
        IJavaProject javaProject = JavaCore.create(project);
        // get the resolved classpath of the project
        IClasspathEntry[] cpEntries = javaProject.getResolvedClasspath(true);
        // iterate over classpath to create classpath urls
        int size = cpEntries.length;
        for (int i = 0; i < size; i++) {
            int entryKind = cpEntries[i].getEntryKind();
            // handle a source path
            if (IClasspathEntry.CPE_SOURCE == entryKind) {
                handleSourcePath(project, cpURLs, cpEntries[i], javaProject);
            } else if (IClasspathEntry.CPE_PROJECT == entryKind) {
                // handle a project reference
                handleRefProject(cpURLs, cpEntries[i], processedProjects);
            } else if (IClasspathEntry.CPE_LIBRARY == entryKind) {
                // handle a library entry
                handleLibrary(project, cpURLs, cpEntries[i]);
            } else {
                // cannot happen since we use a resolved classpath
                // log as exception
                CheckstylePluginException ex = new CheckstylePluginException(NLS.bind(Messages.errorUnknownClasspathEntry, cpEntries[i].getPath()));
                CheckstyleLog.log(ex);
            }
        }
    } catch (JavaModelException jme) {
        CheckstyleLog.log(jme);
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException)

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