Search in sources :

Example 26 with Location

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

the class V07ToV08ConverterTest method convertWorkspaceLocationFallback.

@Test
public void convertWorkspaceLocationFallback() {
    final RuleSetConfiguration config = new WorkspaceRuleSetConfiguration(1, "Workspace Config", Paths.get("../somewhere/else/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("/home", "somewhere", "else", "pmd.xml").toString(), result.getPath());
    assertEquals("Location context", LocationContext.FILE_SYSTEM, result.getContext());
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) Location(ch.acanda.eclipse.pmd.domain.Location) Test(org.junit.Test)

Example 27 with Location

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

the class V07ToV08ConverterTest method convertWorkspaceLocationProjectInWorkspace.

@Test
public void convertWorkspaceLocationProjectInWorkspace() {
    final RuleSetConfiguration config = new WorkspaceRuleSetConfiguration(1, "Workspace Config", Paths.get("ch.acanda.eclipse.pmd/pmd.xml"));
    final IWorkspaceRoot workspaceRoot = mock(IWorkspaceRoot.class);
    when(workspaceRoot.getLocationURI()).thenReturn(URI.create("file:///home/src/"));
    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 28 with Location

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

the class AddRuleSetConfigurationModel method getAbsoluteLocation.

private Optional<Path> getAbsoluteLocation() {
    final LocationContext locationContext;
    if (isWorkspaceTypeSelected) {
        locationContext = LocationContext.WORKSPACE;
    } else if (isProjectTypeSelected) {
        locationContext = LocationContext.PROJECT;
    } else if (isFileSystemTypeSelected) {
        locationContext = LocationContext.FILE_SYSTEM;
    } else {
        throw new IllegalStateException("Unknown location type");
    }
    final Optional<String> resolvedLocation = LocationResolver.resolveIfExists(new Location(location, locationContext), project);
    if (resolvedLocation.isPresent()) {
        return Optional.of(Paths.get(resolvedLocation.get()));
    }
    return Optional.absent();
}
Also used : LocationContext(ch.acanda.eclipse.pmd.domain.LocationContext) Location(ch.acanda.eclipse.pmd.domain.Location)

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