use of ch.acanda.eclipse.pmd.domain.RuleSetModel in project eclipse-pmd by acanda.
the class PMDPropertyPageModelTransformer method toDomainModel.
/**
* Transforms a rule set view model to a rule set domain model.
*/
public static RuleSetModel toDomainModel(final RuleSetViewModel viewModel) {
final String name = viewModel.getName();
final String path = viewModel.getLocation();
final LocationContext context = CONTEXT_TYPE_MAP.inverse().get(viewModel.getType());
return new RuleSetModel(name, new Location(path, context));
}
use of ch.acanda.eclipse.pmd.domain.RuleSetModel 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);
}
}
}
}
}
}
use of ch.acanda.eclipse.pmd.domain.RuleSetModel in project eclipse-pmd by acanda.
the class RuleSetsCacheTest method secondGetLoadsWhenLaterAddedProjectRuleSetsWereChanged.
/**
* Verifies that the second cache access loads the rule sets if the project model's rule sets have been changed
* after the first access. In this case, the project model was added after the rule sets cache was created.
*/
@Test
public void secondGetLoadsWhenLaterAddedProjectRuleSetsWereChanged() throws Exception {
final WorkspaceModel workspaceModel = getWorkspaceModel();
final RuleSetsCache cache = new RuleSetsCache(getCacheLoaderMock(), workspaceModel);
workspaceModel.add(new ProjectModel(PROJECT_NAME_2));
cache.getRuleSets(PROJECT_NAME_2);
final RuleSetModel ruleSetModel = new RuleSetModel("abc", new Location("path", LocationContext.WORKSPACE));
workspaceModel.getOrCreateProject(PROJECT_NAME_2).setRuleSets(Arrays.asList(ruleSetModel));
final RuleSets actualRuleSets = cache.getRuleSets(PROJECT_NAME_2);
assertSame("Second cache access should reload rule sets", RULE_SETS_BAR_2, actualRuleSets);
}
use of ch.acanda.eclipse.pmd.domain.RuleSetModel in project eclipse-pmd by acanda.
the class RuleSetsCacheLoader method load.
@Override
public RuleSets load(final String projectName) {
PMDPlugin.getDefault().info("RuleSetsCache: loading rule sets for project " + projectName);
try {
final ProjectModel projectModel = repository.load(projectName).or(new ProjectModel(projectName));
final ImmutableSortedSet<RuleSetModel> ruleSetModels = projectModel.getRuleSets();
final Iterable<RuleSetReferenceId> ids = presentInstances(transform(ruleSetModels, new ToReferenceId(projectName)));
return new RuleSetFactory().createRuleSets(ImmutableList.copyOf(ids));
} catch (final RuleSetNotFoundException e) {
PMDPlugin.getDefault().error("Cannot load rule sets for project " + projectName, e);
return new RuleSets();
}
}
use of ch.acanda.eclipse.pmd.domain.RuleSetModel in project eclipse-pmd by acanda.
the class V07ToV08Converter method moveProjectSettings.
private static void moveProjectSettings(final IProject project, final ImmutableList<RuleSetConfiguration> configs, final ProjectModelRepository repository) {
final PMDProjectSettings pmdProjectSettings = new PMDProjectSettings(project);
final Set<RuleSetConfiguration> activeConfigs = pmdProjectSettings.getActiveRuleSetConfigurations(configs);
if (!activeConfigs.isEmpty()) {
final ProjectModel projectModel = new ProjectModel(project.getName());
projectModel.setPMDEnabled(pmdProjectSettings.isPMDEnabled());
final List<RuleSetModel> ruleSets = new ArrayList<>(activeConfigs.size());
for (final RuleSetConfiguration config : activeConfigs) {
final Location location = getLocation(config, project.getWorkspace().getRoot());
final RuleSetModel ruleSetModel = new RuleSetModel(config.getName(), location);
ruleSets.add(ruleSetModel);
}
projectModel.setRuleSets(ruleSets);
repository.save(projectModel);
}
if (repository.load(project.getName()).isPresent()) {
pmdProjectSettings.deleteSettings();
}
}
Aggregations