Search in sources :

Example 11 with PropertiesException

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

the class DetectCutAndPasteCmd method execute.

/**
 * @see name.herlin.command.AbstractProcessableCommand#execute()
 */
@Override
public void execute() throws CommandException {
    try {
        List<File> files = findCandidateFiles();
        if (files.isEmpty()) {
            logInfo("No files found for specified language.");
        } else {
            logInfo("Found " + files.size() + " files for the specified language. Performing CPD.");
        }
        setStepCount(files.size());
        beginTask("Finding suspect Cut And Paste", getStepCount() * 2);
        if (!isCanceled()) {
            final CPD cpd = detectCutAndPaste(files);
            if (!isCanceled()) {
                if (createReport) {
                    renderReport(cpd.getMatches());
                }
                notifyListeners(cpd);
            }
        }
    } catch (CoreException e) {
        LOG.debug("Core Exception: " + e.getMessage(), e);
        throw new CommandException(e);
    } catch (PropertiesException e) {
        LOG.debug("Properties Exception: " + e.getMessage(), e);
        throw new CommandException(e);
    } finally {
        setTerminated(true);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) PropertiesException(net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException) CPD(net.sourceforge.pmd.cpd.CPD) CommandException(name.herlin.command.CommandException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 12 with PropertiesException

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

the class ProjectPropertiesManagerImpl method storeProjectProperties.

/**
 * @see net.sourceforge.pmd.eclipse.runtime.properties.IProjectPropertiesManager#storeProjectProperties(net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties)
 */
public void storeProjectProperties(IProjectProperties projectProperties) throws PropertiesException {
    LOG.debug("Storing project properties for project " + projectProperties.getProject().getName());
    try {
        if (projectProperties.isPmdEnabled()) {
            PMDNature.addPMDNature(projectProperties.getProject(), null);
        } else {
            PMDNature.removePMDNature(projectProperties.getProject(), null);
        }
        writeProjectProperties(projectProperties.getProject(), fillTransferObject(projectProperties));
        projectsProperties.put(projectProperties.getProject(), projectProperties);
    } catch (CoreException e) {
        throw new PropertiesException("Core Exception when storing project properties for project " + projectProperties.getProject().getName(), e);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) PropertiesException(net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException)

Example 13 with PropertiesException

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

the class ProjectPropertiesManagerImpl method readProjectProperties.

/**
 * Read a project properties from properties file
 *
 * @param project
 *            a project
 */
private ProjectPropertiesTO readProjectProperties(final IProject project) throws PropertiesException {
    ProjectPropertiesTO projectProperties = null;
    try {
        final IFile propertiesFile = project.getFile(PROPERTIES_FILE);
        if (propertiesFile.exists() && propertiesFile.isAccessible()) {
            String properties = IOUtils.toString(propertiesFile.getContents());
            projectProperties = convertProjectPropertiesFromString(properties);
        }
        return projectProperties;
    } catch (IOException e) {
        throw new PropertiesException(e);
    } catch (CoreException e) {
        throw new PropertiesException(e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) PropertiesException(net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException)

Example 14 with PropertiesException

use of net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException 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 15 with PropertiesException

use of net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException 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)

Aggregations

PropertiesException (net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException)17 CoreException (org.eclipse.core.runtime.CoreException)10 IFile (org.eclipse.core.resources.IFile)9 File (java.io.File)6 IProjectProperties (net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties)6 CommandException (name.herlin.command.CommandException)5 RuleSet (net.sourceforge.pmd.RuleSet)3 IProject (org.eclipse.core.resources.IProject)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 BufferedReader (java.io.BufferedReader)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 Timer (name.herlin.command.Timer)1 PMDException (net.sourceforge.pmd.PMDException)1 Report (net.sourceforge.pmd.Report)1 ConfigurationError (net.sourceforge.pmd.Report.ConfigurationError)1 ProcessingError (net.sourceforge.pmd.Report.ProcessingError)1 RuleContext (net.sourceforge.pmd.RuleContext)1