Search in sources :

Example 1 with Location

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));
}
Also used : RuleSetModel(ch.acanda.eclipse.pmd.domain.RuleSetModel) LocationContext(ch.acanda.eclipse.pmd.domain.LocationContext) Location(ch.acanda.eclipse.pmd.domain.Location)

Example 2 with Location

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());
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) Location(ch.acanda.eclipse.pmd.domain.Location) Test(org.junit.Test)

Example 3 with Location

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());
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) Location(ch.acanda.eclipse.pmd.domain.Location) Test(org.junit.Test)

Example 4 with Location

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());
}
Also used : IProject(org.eclipse.core.resources.IProject) Location(ch.acanda.eclipse.pmd.domain.Location) Test(org.junit.Test)

Example 5 with Location

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));
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) Location(ch.acanda.eclipse.pmd.domain.Location) Test(org.junit.Test)

Aggregations

Location (ch.acanda.eclipse.pmd.domain.Location)28 Test (org.junit.Test)24 IProject (org.eclipse.core.resources.IProject)19 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)10 URI (java.net.URI)8 IWorkspace (org.eclipse.core.resources.IWorkspace)7 RuleSetModel (ch.acanda.eclipse.pmd.domain.RuleSetModel)5 Path (java.nio.file.Path)4 LocationContext (ch.acanda.eclipse.pmd.domain.LocationContext)3 ProjectModel (ch.acanda.eclipse.pmd.domain.ProjectModel)2 WorkspaceModel (ch.acanda.eclipse.pmd.domain.WorkspaceModel)2 RuleSets (net.sourceforge.pmd.RuleSets)2 ArrayList (java.util.ArrayList)1