use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.
the class LocationResolverTest method resolveIfExistsWorkspaceLocationWithProjectNameOnly.
/**
* Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} does not throw an exception in a
* workspace context if the path consists only of the project name.
*/
@Test
public void resolveIfExistsWorkspaceLocationWithProjectNameOnly() throws URISyntaxException {
final Location location = new Location("project", LocationContext.WORKSPACE);
final IProject project = mock(IProject.class);
final IWorkspace workspace = mock(IWorkspace.class);
final IWorkspaceRoot workspaceRoot = mock(IWorkspaceRoot.class);
when(project.getWorkspace()).thenReturn(workspace);
when(workspace.getRoot()).thenReturn(workspaceRoot);
when(workspaceRoot.getProject("project")).thenReturn(project);
when(project.getLocationURI()).thenReturn(new URI("file:///workspace/project/"));
final Optional<String> result = LocationResolver.resolveIfExists(location, project);
assertFalse("The location should not resolve", result.isPresent());
}
use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.
the class LocationResolverTest method resolveRemoteLocation.
/**
* Verifies that {@link LocationResolver#resolve(Location, IProject)} resolves the location in a remote context
* correctly.
*/
@Test
public void resolveRemoteLocation() {
final Location location = new Location("http://example.org/pmd.xml", LocationContext.FILE_SYSTEM);
final IProject project = mock(IProject.class);
final String result = LocationResolver.resolve(location, project);
assertEquals("The resolved location should be the URL", "http://example.org/pmd.xml", result);
}
use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.
the class LocationResolverTest method resolveIfExistsWorkspaceLocation.
/**
* Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} resolves the location in a workspace
* context correctly.
*/
@Test
public void resolveIfExistsWorkspaceLocation() throws URISyntaxException, IOException {
final Path ruleSetFile = Files.createTempFile(LocationResolverTest.class.getSimpleName(), ".xml");
try {
final Location location = new Location("project/" + ruleSetFile.getFileName().toString(), LocationContext.WORKSPACE);
final IProject project = mock(IProject.class);
final IWorkspace workspace = mock(IWorkspace.class);
final IWorkspaceRoot workspaceRoot = mock(IWorkspaceRoot.class);
when(project.getWorkspace()).thenReturn(workspace);
when(workspace.getRoot()).thenReturn(workspaceRoot);
when(workspaceRoot.getProject("project")).thenReturn(project);
when(project.getLocationURI()).thenReturn(ruleSetFile.getParent().toUri());
final Optional<String> result = LocationResolver.resolveIfExists(location, project);
assertTrue("A valid workspace location should resolve", result.isPresent());
assertEquals("The resolved location in a workspace context should be the provided location appended to the workspace location", ruleSetFile.toString(), result.get());
} finally {
Files.deleteIfExists(ruleSetFile);
}
}
use of ch.acanda.eclipse.pmd.domain.Location 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();
}
}
use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.
the class ProjectConfigurationContentHandler method createRuleSet.
private RuleSetModel createRuleSet(final Attributes attributes) {
final LocationContext context = getContext(attributes.getValue(ATTRIBUTE_NAME_REFCONTEXT));
final Location location = new Location(attributes.getValue(ATTRIBUTE_NAME_REF), context);
return new RuleSetModel(attributes.getValue(ATTRIBUTE_NAME_NAME), location);
}
Aggregations