Search in sources :

Example 1 with FileChangedListener

use of ch.acanda.eclipse.pmd.file.FileChangedListener in project eclipse-pmd by acanda.

the class RuleSetsCache method startWatchingRuleSetFiles.

private void startWatchingRuleSetFiles(final ProjectModel projectModel) {
    if (fileWatcher.isPresent() && projectModel.isPMDEnabled()) {
        final FileChangedListener listener = new RuleSetFileListener(projectModel);
        final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectModel.getProjectName());
        for (final RuleSetModel ruleSetModel : projectModel.getRuleSets()) {
            if (ruleSetModel.getLocation().getContext() != LocationContext.REMOTE) {
                final Optional<String> resolvedLocation = LocationResolver.resolveIfExists(ruleSetModel.getLocation(), project);
                if (resolvedLocation.isPresent()) {
                    final Path file = Paths.get(resolvedLocation.get());
                    try {
                        final Subscription subscription = fileWatcher.get().subscribe(file, listener);
                        subscriptions.put(projectModel.getProjectName(), subscription);
                    } catch (final IOException e) {
                        final String msg = "Cannot watch rule set file %s. " + "Changes to this file will not be picked up for up to an hour.";
                        PMDPlugin.getDefault().warn(String.format(msg, file.toAbsolutePath()), e);
                    }
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) RuleSetModel(ch.acanda.eclipse.pmd.domain.RuleSetModel) IOException(java.io.IOException) Subscription(ch.acanda.eclipse.pmd.file.Subscription) IProject(org.eclipse.core.resources.IProject) FileChangedListener(ch.acanda.eclipse.pmd.file.FileChangedListener)

Aggregations

RuleSetModel (ch.acanda.eclipse.pmd.domain.RuleSetModel)1 FileChangedListener (ch.acanda.eclipse.pmd.file.FileChangedListener)1 Subscription (ch.acanda.eclipse.pmd.file.Subscription)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 IProject (org.eclipse.core.resources.IProject)1