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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
}
}
Aggregations