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