Search in sources :

Example 6 with ProjectModel

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

the class ProjectModelSerializerTest method deserializeProjectModelWithoutRuleSets.

/**
 * Verifies that {@link ProjectModelSerializer#deserialize(java.io.InputStream, String)} deserializes the attributes
 * of {@link ProjectModel} correctly.
 */
@Test
public void deserializeProjectModelWithoutRuleSets() throws IOException {
    final ByteArrayInputStream stream = new ByteArrayInputStream(createXmlConfigurationWithoutRuleSets().getBytes(Charsets.UTF_8));
    final ProjectModel projectModel = new ProjectModelSerializer().deserialize(stream, "TestProjectName");
    assertEquals("Project name", "TestProjectName", projectModel.getProjectName());
    assertFalse("PMD should be disabled", projectModel.isPMDEnabled());
    assertEquals("Number of rule sets", 0, projectModel.getRuleSets().size());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ProjectModel(ch.acanda.eclipse.pmd.domain.ProjectModel) Test(org.junit.Test)

Example 7 with ProjectModel

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

the class ProjectModelSerializerTest method deserializeFilesystemRuleSetModel.

/**
 * Verifies that {@link ProjectModelSerializer#deserialize(java.io.InputStream, String)} deserializes the attributes
 * of a filesystem {@link RuleSetModel} correctly.
 */
@Test
public void deserializeFilesystemRuleSetModel() throws IOException {
    final ByteArrayInputStream stream = new ByteArrayInputStream(createXmlConfiguration().getBytes(Charsets.UTF_8));
    final ProjectModel projectModel = new ProjectModelSerializer().deserialize(stream, "TestProjectName");
    assertRuleSetModel(projectModel, LocationContext.FILE_SYSTEM, "Filesystem Rule Set", "x:\\pmx.xml");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ProjectModel(ch.acanda.eclipse.pmd.domain.ProjectModel) Test(org.junit.Test)

Example 8 with ProjectModel

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

the class ProjectModelSerializerTest method deserializeRemoteRuleSetModel.

/**
 * Verifies that {@link ProjectModelSerializer#deserialize(java.io.InputStream, String)} deserializes the attributes
 * of a remote {@link RuleSetModel} correctly.
 */
@Test
public void deserializeRemoteRuleSetModel() throws IOException {
    final ByteArrayInputStream stream = new ByteArrayInputStream(createXmlConfiguration().getBytes(Charsets.UTF_8));
    final ProjectModel projectModel = new ProjectModelSerializer().deserialize(stream, "TestProjectName");
    assertRuleSetModel(projectModel, LocationContext.REMOTE, "Remote Rule Set", "http://example.org/pmd.xml");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ProjectModel(ch.acanda.eclipse.pmd.domain.ProjectModel) Test(org.junit.Test)

Example 9 with ProjectModel

use of ch.acanda.eclipse.pmd.domain.ProjectModel 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();
    }
}
Also used : RuleSetFactory(net.sourceforge.pmd.RuleSetFactory) RuleSetModel(ch.acanda.eclipse.pmd.domain.RuleSetModel) RuleSetReferenceId(net.sourceforge.pmd.RuleSetReferenceId) RuleSets(net.sourceforge.pmd.RuleSets) RuleSetNotFoundException(net.sourceforge.pmd.RuleSetNotFoundException) ProjectModel(ch.acanda.eclipse.pmd.domain.ProjectModel)

Example 10 with ProjectModel

use of ch.acanda.eclipse.pmd.domain.ProjectModel 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();
    }
}
Also used : RuleSetModel(ch.acanda.eclipse.pmd.domain.RuleSetModel) ArrayList(java.util.ArrayList) ProjectModel(ch.acanda.eclipse.pmd.domain.ProjectModel) Location(ch.acanda.eclipse.pmd.domain.Location)

Aggregations

ProjectModel (ch.acanda.eclipse.pmd.domain.ProjectModel)17 Test (org.junit.Test)10 ByteArrayInputStream (java.io.ByteArrayInputStream)6 WorkspaceModel (ch.acanda.eclipse.pmd.domain.WorkspaceModel)5 RuleSetModel (ch.acanda.eclipse.pmd.domain.RuleSetModel)4 RuleSets (net.sourceforge.pmd.RuleSets)3 Location (ch.acanda.eclipse.pmd.domain.Location)2 IProject (org.eclipse.core.resources.IProject)2 ProjectModelRepository (ch.acanda.eclipse.pmd.repository.ProjectModelRepository)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 RuleSetFactory (net.sourceforge.pmd.RuleSetFactory)1 RuleSetNotFoundException (net.sourceforge.pmd.RuleSetNotFoundException)1 RuleSetReferenceId (net.sourceforge.pmd.RuleSetReferenceId)1 IFile (org.eclipse.core.resources.IFile)1 IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 CoreException (org.eclipse.core.runtime.CoreException)1