Search in sources :

Example 1 with WorkspaceModel

use of ch.acanda.eclipse.pmd.domain.WorkspaceModel in project eclipse-pmd by acanda.

the class PMDPlugin method initWorkspaceModel.

private void initWorkspaceModel() {
    workspaceModel = new WorkspaceModel();
    final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    final ProjectModelRepository projectModelRepository = new ProjectModelRepository();
    for (final IProject project : projects) {
        final Optional<ProjectModel> model = projectModelRepository.load(project.getName());
        if (model.isPresent()) {
            workspaceModel.add(model.get());
        } else {
            workspaceModel.add(new ProjectModel(project.getName()));
        }
    }
    final IResourceChangeListener workspaceChangeListener = new WorkspaceChangeListener(workspaceModel, projectModelRepository);
    ResourcesPlugin.getWorkspace().addResourceChangeListener(workspaceChangeListener, IResourceChangeEvent.POST_CHANGE);
}
Also used : WorkspaceModel(ch.acanda.eclipse.pmd.domain.WorkspaceModel) ProjectModelRepository(ch.acanda.eclipse.pmd.repository.ProjectModelRepository) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) ProjectModel(ch.acanda.eclipse.pmd.domain.ProjectModel) IProject(org.eclipse.core.resources.IProject)

Example 2 with WorkspaceModel

use of ch.acanda.eclipse.pmd.domain.WorkspaceModel 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);
}
Also used : WorkspaceModel(ch.acanda.eclipse.pmd.domain.WorkspaceModel) RuleSetModel(ch.acanda.eclipse.pmd.domain.RuleSetModel) RuleSets(net.sourceforge.pmd.RuleSets) ProjectModel(ch.acanda.eclipse.pmd.domain.ProjectModel) Location(ch.acanda.eclipse.pmd.domain.Location) Test(org.junit.Test)

Example 3 with WorkspaceModel

use of ch.acanda.eclipse.pmd.domain.WorkspaceModel in project eclipse-pmd by acanda.

the class PMDPropertyPageController method init.

public void init(final IProject project) {
    this.project = project;
    final WorkspaceModel workspaceModel = PMDPlugin.getDefault().getWorkspaceModel();
    projectModel = workspaceModel.getOrCreateProject(project.getName());
    model.setInitialState(projectModel.isPMDEnabled(), projectModel.getRuleSets(), project);
    final ImmutableSortedSet.Builder<RuleSetModel> ruleSetBuilder = ImmutableSortedSet.orderedBy(ProjectModel.RULE_SET_COMPARATOR);
    for (final ProjectModel projectModel : workspaceModel.getProjects()) {
        ruleSetBuilder.addAll(projectModel.getRuleSets());
    }
    model.setRuleSets(ImmutableList.copyOf(toViewModels(ruleSetBuilder.build(), project)));
    reset();
}
Also used : WorkspaceModel(ch.acanda.eclipse.pmd.domain.WorkspaceModel) RuleSetModel(ch.acanda.eclipse.pmd.domain.RuleSetModel) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ProjectModel(ch.acanda.eclipse.pmd.domain.ProjectModel)

Example 4 with WorkspaceModel

use of ch.acanda.eclipse.pmd.domain.WorkspaceModel in project eclipse-pmd by acanda.

the class RuleSetsCacheTest method secondGetLoadsWhenProjectRuleSetsWereChanged.

/**
 * Verifies that the second cache access loads the rule sets if the project model's rule sets have been changed
 * after the first access.
 */
@Test
public void secondGetLoadsWhenProjectRuleSetsWereChanged() throws Exception {
    final WorkspaceModel workspaceModel = getWorkspaceModel();
    final RuleSetsCache cache = new RuleSetsCache(getCacheLoaderMock(), workspaceModel);
    cache.getRuleSets(PROJECT_NAME_1);
    final RuleSetModel ruleSetModel = new RuleSetModel("abc", new Location("path", LocationContext.WORKSPACE));
    workspaceModel.getOrCreateProject(PROJECT_NAME_1).setRuleSets(Arrays.asList(ruleSetModel));
    final RuleSets actualRuleSets = cache.getRuleSets(PROJECT_NAME_1);
    assertSame("Second cache access should reload rule sets", RULE_SETS_FOO_2, actualRuleSets);
}
Also used : WorkspaceModel(ch.acanda.eclipse.pmd.domain.WorkspaceModel) RuleSetModel(ch.acanda.eclipse.pmd.domain.RuleSetModel) RuleSets(net.sourceforge.pmd.RuleSets) Location(ch.acanda.eclipse.pmd.domain.Location) Test(org.junit.Test)

Example 5 with WorkspaceModel

use of ch.acanda.eclipse.pmd.domain.WorkspaceModel in project eclipse-pmd by acanda.

the class RuleSetsCacheTest method secondGetLoadsWhenProjectWasREmovedAndAddedAfterFirstGet.

/**
 * Verifies that the second cache access loads the rule sets if the project model has been removed and added after
 * the first access.
 */
@Test
public void secondGetLoadsWhenProjectWasREmovedAndAddedAfterFirstGet() throws Exception {
    final WorkspaceModel workspaceModel = getWorkspaceModel();
    final RuleSetsCache cache = new RuleSetsCache(getCacheLoaderMock(), workspaceModel);
    cache.getRuleSets(PROJECT_NAME_1);
    workspaceModel.remove(PROJECT_NAME_1);
    workspaceModel.add(new ProjectModel(PROJECT_NAME_1));
    final RuleSets actualRuleSets = cache.getRuleSets(PROJECT_NAME_1);
    assertSame("Second cache access should reload rule sets", RULE_SETS_FOO_2, actualRuleSets);
}
Also used : WorkspaceModel(ch.acanda.eclipse.pmd.domain.WorkspaceModel) RuleSets(net.sourceforge.pmd.RuleSets) ProjectModel(ch.acanda.eclipse.pmd.domain.ProjectModel) Test(org.junit.Test)

Aggregations

WorkspaceModel (ch.acanda.eclipse.pmd.domain.WorkspaceModel)6 ProjectModel (ch.acanda.eclipse.pmd.domain.ProjectModel)5 RuleSetModel (ch.acanda.eclipse.pmd.domain.RuleSetModel)3 RuleSets (net.sourceforge.pmd.RuleSets)3 Test (org.junit.Test)3 Location (ch.acanda.eclipse.pmd.domain.Location)2 ProjectModelRepository (ch.acanda.eclipse.pmd.repository.ProjectModelRepository)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 IProject (org.eclipse.core.resources.IProject)1 IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)1