Search in sources :

Example 11 with IProjectProperties

use of net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties in project pmd-eclipse-plugin by pmd.

the class ReviewCodeCmd method rulesetFrom.

private RuleSet rulesetFrom(IResource resource) throws PropertiesException, CommandException {
    IProject project = resource.getProject();
    IProjectProperties properties = getProjectProperties(project);
    // properties.getProjectRuleSet();
    return filteredRuleSet(properties);
}
Also used : IProjectProperties(net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties) IProject(org.eclipse.core.resources.IProject)

Example 12 with IProjectProperties

use of net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties in project pmd-eclipse-plugin by pmd.

the class ProjectPropertiesManagerImpl method loadProjectProperties.

/**
 * Load a project properties
 *
 * @param project
 *            a project
 */
public IProjectProperties loadProjectProperties(final IProject project) throws PropertiesException {
    LOG.debug("Loading project properties for project " + project.getName());
    try {
        IProjectProperties projectProperties = this.projectsProperties.get(project);
        if (projectProperties == null) {
            LOG.debug("Creating new poject properties for " + project.getName());
            projectProperties = new PropertiesFactoryImpl().newProjectProperties(project, this);
            final ProjectPropertiesTO to = readProjectProperties(project);
            fillProjectProperties(projectProperties, to);
            this.projectsProperties.put(project, projectProperties);
        }
        // if the ruleset is stored in the project always reload it
        if (projectProperties.isRuleSetStoredInProject()) {
            loadRuleSetFromProject(projectProperties);
        } else {
            // else resynchronize the ruleset
            final boolean needRebuild = synchronizeRuleSet(projectProperties);
            projectProperties.setNeedRebuild(projectProperties.isNeedRebuild() || needRebuild);
        }
        return projectProperties;
    } catch (CoreException e) {
        throw new PropertiesException("Core Exception when loading project properties for project " + project.getName(), e);
    }
}
Also used : IProjectProperties(net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties) CoreException(org.eclipse.core.runtime.CoreException) PropertiesException(net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException)

Example 13 with IProjectProperties

use of net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties in project pmd-eclipse-plugin by pmd.

the class PreferencesManagerImpl method updateConfiguredProjects.

/**
 * Add new rules to already configured projects, and update the
 * exclude/include patterns
 */
private void updateConfiguredProjects(RuleSet updatedRuleSet) {
    LOG.debug("Updating configured projects");
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (IProject project : projects) {
        if (project.isAccessible()) {
            try {
                IProjectProperties properties = PMDPlugin.getDefault().loadProjectProperties(project);
                RuleSet projectRuleSet = properties.getProjectRuleSet();
                if (projectRuleSet != null) {
                    projectRuleSet = RuleSetUtil.addRules(projectRuleSet, getNewRules(updatedRuleSet));
                    projectRuleSet = RuleSetUtil.setExcludePatterns(projectRuleSet, updatedRuleSet.getExcludePatterns());
                    projectRuleSet = RuleSetUtil.setIncludePatterns(projectRuleSet, updatedRuleSet.getIncludePatterns());
                    properties.setProjectRuleSet(projectRuleSet);
                    properties.sync();
                }
            } catch (PropertiesException e) {
                PMDPlugin.getDefault().logError("Unable to add new rules for project: " + project, e);
            }
        }
    }
}
Also used : RuleSet(net.sourceforge.pmd.RuleSet) IProjectProperties(net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties) PropertiesException(net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException) IProject(org.eclipse.core.resources.IProject)

Example 14 with IProjectProperties

use of net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties in project pmd-eclipse-plugin by pmd.

the class PMDPropertyPageController method createDefaultRuleSetFile.

/**
 * Create a default ruleset file from the current project ruleset
 */
private void createDefaultRuleSetFile() throws PropertiesException {
    final boolean create = MessageDialog.openQuestion(shell, getMessage(StringKeys.QUESTION_TITLE), getMessage(StringKeys.QUESTION_CREATE_RULESET_FILE));
    if (create) {
        final IProjectProperties properties = PMDPlugin.getDefault().loadProjectProperties(project);
        properties.createDefaultRuleSetFile();
    } else {
        propertyPageBean.setRuleSetStoredInProject(false);
    }
}
Also used : IProjectProperties(net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties)

Aggregations

IProjectProperties (net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties)14 PropertiesException (net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException)6 IProject (org.eclipse.core.resources.IProject)6 RuleSet (net.sourceforge.pmd.RuleSet)5 IFile (org.eclipse.core.resources.IFile)4 CommandException (name.herlin.command.CommandException)3 CoreException (org.eclipse.core.runtime.CoreException)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 Rule (net.sourceforge.pmd.Rule)2 IResource (org.eclipse.core.resources.IResource)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 Set (java.util.Set)1 RuleSetFactory (net.sourceforge.pmd.RuleSetFactory)1 IProjectPropertiesManager (net.sourceforge.pmd.eclipse.runtime.properties.IProjectPropertiesManager)1 IFolder (org.eclipse.core.resources.IFolder)1 IResourceDeltaVisitor (org.eclipse.core.resources.IResourceDeltaVisitor)1 IResourceVisitor (org.eclipse.core.resources.IResourceVisitor)1 Before (org.junit.Before)1