Search in sources :

Example 1 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class JavaUtil method resolveFQN.

/**
     * Resolves fully qualified name based on base on start point container and end point resource.
     * <p/>
     * Usually as start point there is a source directory and as end point there is a package fragment or java file.
     *
     * @param startPoint
     *         the start point container from which fqn should be resolved
     * @param endPoint
     *         the end point resource to which fqn should be resolved
     * @return the resolved fully qualified name
     * @throws IllegalArgumentException
     *         in case if given arguments are invalid. Reason includes:
     *         <ul>
     *         <li>Null source folder occurred</li>
     *         <li>Null resource occurred</li>
     *         <li>Given base folder is not prefix of checked resource</li>
     *         </ul>
     * @since 4.4.0
     */
public static String resolveFQN(Container startPoint, Resource endPoint) {
    checkArgument(startPoint != null, "Null source folder occurred");
    checkArgument(endPoint != null, "Null resource occurred");
    checkArgument(startPoint.getLocation().isPrefixOf(endPoint.getLocation()), "Given base folder is not prefix of checked resource");
    Path path = endPoint.getLocation().removeFirstSegments(startPoint.getLocation().segmentCount());
    if (isJavaFile(endPoint)) {
        final String ext = ((File) endPoint).getExtension();
        if (!isNullOrEmpty(ext)) {
            final String name = endPoint.getName();
            path = path.removeLastSegments(1).append(name.substring(0, name.length() - ext.length() - 1));
        }
    }
    return path.toString().replace('/', '.');
}
Also used : Path(org.eclipse.che.ide.resource.Path) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile)

Example 2 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class MavenMessagesHandler method computeUniqueHiLevelProjects.

private Set<String> computeUniqueHiLevelProjects(List<String> updatedProjects) {
    Set<String> result = new HashSet<>();
    for (String project : updatedProjects) {
        Path path = new Path(project);
        if (path.segmentCount() > 1) {
            //TODO maven modules may exists in sub sub directory
            path = path.removeLastSegments(1);
        }
        result.add(path.toString());
    }
    return result;
}
Also used : Path(org.eclipse.che.ide.resource.Path) HashSet(java.util.HashSet)

Example 3 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class SourcepathMacroTest method setUp.

@Before
public void setUp() throws Exception {
    resources[0] = resource;
    when(appContext.getResources()).thenReturn(resources);
    when(resource.getRelatedProject()).thenReturn(projectOptional);
    when(projectOptional.get()).thenReturn(project);
    Map<String, List<String>> attributes = new HashMap<>();
    attributes.put(Constants.LANGUAGE, singletonList("java"));
    when(project.getAttributes()).thenReturn(attributes);
    Path projectPath = Path.valueOf("/name");
    when(project.getLocation()).thenReturn(projectPath);
}
Also used : Path(org.eclipse.che.ide.resource.Path) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) Before(org.junit.Before)

Example 4 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class SourcepathMacroTest method defaultValueOfSourcepathShouldBeBuilt.

@Test
public void defaultValueOfSourcepathShouldBeBuilt() throws Exception {
    List<ClasspathEntryDto> entries = new ArrayList<>();
    Set<String> libs = new HashSet<>();
    Path projectsRoot = Path.valueOf("/projects");
    when(appContext.getProjectsRoot()).thenReturn(projectsRoot);
    when(classpathContainer.getClasspathEntries(anyString())).thenReturn(classpathEntriesPromise);
    when(classpathResolver.getLibs()).thenReturn(libs);
    sourcepathMacro.expand();
    verify(classpathEntriesPromise).then(classpathEntriesCapture.capture());
    String classpath = classpathEntriesCapture.getValue().apply(entries);
    verify(classpathResolver).resolveClasspathEntries(entries);
    assertEquals("/projects/name", classpath);
}
Also used : Path(org.eclipse.che.ide.resource.Path) ArrayList(java.util.ArrayList) ClasspathEntryDto(org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto) Matchers.anyString(org.mockito.Matchers.anyString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class ClasspathMacroTest method setUp.

@Before
public void setUp() throws Exception {
    resources[0] = resource;
    when(appContext.getResources()).thenReturn(resources);
    when(resource.getRelatedProject()).thenReturn(projectOptional);
    when(projectOptional.get()).thenReturn(project);
    Map<String, List<String>> attributes = new HashMap<>();
    attributes.put(Constants.LANGUAGE, singletonList("java"));
    when(project.getAttributes()).thenReturn(attributes);
    Path projectPath = Path.valueOf("/name");
    when(project.getLocation()).thenReturn(projectPath);
}
Also used : Path(org.eclipse.che.ide.resource.Path) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) Before(org.junit.Before)

Aggregations

Path (org.eclipse.che.ide.resource.Path)72 Resource (org.eclipse.che.ide.api.resources.Resource)27 Operation (org.eclipse.che.api.promises.client.Operation)15 OperationException (org.eclipse.che.api.promises.client.OperationException)15 PromiseError (org.eclipse.che.api.promises.client.PromiseError)13 ArrayList (java.util.ArrayList)11 Project (org.eclipse.che.ide.api.resources.Project)11 Promise (org.eclipse.che.api.promises.client.Promise)10 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)10 List (java.util.List)8 Test (org.junit.Test)7 ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)6 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)6 Optional (com.google.common.base.Optional)5 Function (org.eclipse.che.api.promises.client.Function)5 FunctionException (org.eclipse.che.api.promises.client.FunctionException)5 Container (org.eclipse.che.ide.api.resources.Container)5 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)5 HashMap (java.util.HashMap)4 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)4