Search in sources :

Example 1 with PropertiesException

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

the class BuildProjectCommand method execute.

/**
 * @see name.herlin.command.AbstractProcessableCommand#execute()
 */
public void execute() throws CommandException {
    try {
        project().build(IncrementalProjectBuilder.FULL_BUILD, this.getMonitor());
        projectProperties().setNeedRebuild(false);
    } catch (CoreException e) {
        throw new CommandException(e);
    } catch (PropertiesException e) {
        throw new CommandException(e);
    } finally {
        this.setTerminated(true);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) PropertiesException(net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException) CommandException(name.herlin.command.CommandException)

Example 2 with PropertiesException

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

the class ProjectPropertiesImpl method setRuleSetStoredInProject.

/**
 * @see net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties#setRuleSetStoredInProject(boolean)
 */
public void setRuleSetStoredInProject(final boolean ruleSetStoredInProject) throws PropertiesException {
    LOG.debug("Set rule set stored in project for project " + this.project.getName() + ": " + ruleSetStoredInProject);
    this.needRebuild |= this.ruleSetStoredInProject != ruleSetStoredInProject;
    this.ruleSetStoredInProject = ruleSetStoredInProject;
    if (this.ruleSetStoredInProject) {
        if (!isRuleSetFileExist()) {
            // TODO: NLS
            throw new PropertiesException("The project ruleset file cannot be found for project " + this.project.getName());
        }
        File f = getResolvedRuleSetFile();
        if (f != null) {
            projectRuleFileLastModified = f.lastModified();
        }
    }
}
Also used : PropertiesException(net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 3 with PropertiesException

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

the class ProjectPropertiesImpl method createDefaultRuleSetFile.

/**
 * Create a project ruleset file from the current configured rules
 */
public void createDefaultRuleSetFile() throws PropertiesException {
    LOG.info("Create a default rule set file for project " + this.project.getName());
    ByteArrayOutputStream baos = null;
    ByteArrayInputStream bais = null;
    try {
        IRuleSetWriter writer = PMDPlugin.getDefault().getRuleSetWriter();
        baos = new ByteArrayOutputStream();
        writer.write(baos, projectRuleSet);
        final IFile file = project.getFile(PROJECT_RULESET_FILE);
        if (file.exists() && file.isAccessible()) {
            throw new PropertiesException("Project ruleset file already exists");
        } else {
            bais = new ByteArrayInputStream(baos.toByteArray());
            file.create(bais, true, null);
        }
    } catch (WriterException e) {
        throw new PropertiesException(e);
    } catch (CoreException e) {
        throw new PropertiesException(e);
    } finally {
        IOUtil.closeQuietly(baos);
        IOUtil.closeQuietly(bais);
    }
}
Also used : IRuleSetWriter(net.sourceforge.pmd.eclipse.runtime.writer.IRuleSetWriter) IFile(org.eclipse.core.resources.IFile) PropertiesException(net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WriterException(net.sourceforge.pmd.eclipse.runtime.writer.WriterException)

Example 4 with PropertiesException

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

the class ProjectPropertiesManagerImpl method writeProjectProperties.

/**
 * Save project properties
 *
 * @param project
 *            a project
 * @param projectProperties
 *            the project properties to save
 * @param monitor
 *            a progress monitor
 * @throws DAOException
 */
private void writeProjectProperties(final IProject project, final ProjectPropertiesTO projectProperties) throws PropertiesException {
    try {
        String writer = convertProjectPropertiesToString(projectProperties);
        final IFile propertiesFile = project.getFile(PROPERTIES_FILE);
        if (propertiesFile.exists() && propertiesFile.isAccessible()) {
            propertiesFile.setContents(new ByteArrayInputStream(writer.getBytes()), false, false, null);
        } else {
            propertiesFile.create(new ByteArrayInputStream(writer.getBytes()), false, null);
        }
    } catch (CoreException e) {
        throw new PropertiesException(e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) PropertiesException(net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 5 with PropertiesException

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

the class PMDPropertyPageController method getPropertyPageBean.

/**
 * populates teh property page bean from the loaded properties
 *
 * @return Returns the propertyPageBean.
 */
public PMDPropertyPageBean getPropertyPageBean() {
    if (this.propertyPageBean == null) {
        LOG.debug("Building a property page bean");
        try {
            final IProjectProperties properties = PMDPlugin.getDefault().loadProjectProperties(this.project);
            propertyPageBean = new PMDPropertyPageBean();
            propertyPageBean.setPmdEnabled(properties.isPmdEnabled());
            propertyPageBean.setProjectWorkingSet(properties.getProjectWorkingSet());
            propertyPageBean.setProjectRuleSet(properties.getProjectRuleSet());
            propertyPageBean.setRuleSetStoredInProject(properties.isRuleSetStoredInProject());
            propertyPageBean.setRuleSetFile(properties.getRuleSetFile());
            propertyPageBean.setIncludeDerivedFiles(properties.isIncludeDerivedFiles());
            propertyPageBean.setFullBuildEnabled(properties.isFullBuildEnabled());
            propertyPageBean.setViolationsAsErrors(properties.violationsAsErrors());
            pmdAlreadyActivated = properties.isPmdEnabled();
        } catch (PropertiesException e) {
            PMDPlugin.getDefault().showError(e.getMessage(), e);
        }
    }
    return this.propertyPageBean;
}
Also used : IProjectProperties(net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties) PropertiesException(net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException)

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