use of ch.acanda.eclipse.pmd.domain.Location 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.Location in project eclipse-pmd by acanda.
the class V07ToV08ConverterTest method convertWorkspaceLocation.
@Test
public void convertWorkspaceLocation() {
final RuleSetConfiguration config = new WorkspaceRuleSetConfiguration(1, "Workspace Config", Paths.get("../src/ch.acanda.eclipse.pmd/pmd.xml"));
final IWorkspaceRoot workspaceRoot = mock(IWorkspaceRoot.class);
when(workspaceRoot.getLocationURI()).thenReturn(URI.create("file:///home/workspace/"));
doReturn(createProjects()).when(workspaceRoot).getProjects();
final Location result = V07ToV08Converter.getLocation(config, workspaceRoot);
assertEquals("Location path", Paths.get("ch.acanda.eclipse.pmd", "pmd.xml").toString(), result.getPath());
assertEquals("Location context", LocationContext.WORKSPACE, result.getContext());
}
use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.
the class LocationResolverTest method resolveIfExistsWorkspaceLocationWithInvalidPath.
/**
* Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} does not throw an exception in a
* workspace context if the path contains invalid characters.
*/
@Test
public void resolveIfExistsWorkspaceLocationWithInvalidPath() throws URISyntaxException {
final Location location = new Location("project/\u0000:", 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 resolveIfExistsFileSystemLocationWithInvalidPath.
/**
* Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} does not throw an exception in a file
* system context if the path is invalid.
*/
@Test
public void resolveIfExistsFileSystemLocationWithInvalidPath() {
final Location location = new Location("\u0000:", LocationContext.FILE_SYSTEM);
final IProject project = mock(IProject.class);
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 resolveWorkspaceLocation.
/**
* Verifies that {@link LocationResolver#resolve(Location, IProject)} resolves the location in a project context
* correctly.
*/
@Test
public void resolveWorkspaceLocation() throws URISyntaxException {
final Location location = new Location("project/path/pmd.xml", 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 String result = LocationResolver.resolve(location, project);
assertEquals("The resolved location should be the project's path with the location's path appended", Paths.get("/workspace", "project", "path", "pmd.xml"), Paths.get(result));
}
Aggregations