Search in sources :

Example 56 with IPath

use of org.eclipse.core.runtime.IPath in project che by eclipse.

the class RefactoringSession method prepareRenamePackageChange.

private void prepareRenamePackageChange(List<ChangeInfo> changesInfo, ChangeInfo changeInfo, Change ch) {
    changeInfo.setName(ChangeInfo.ChangeName.RENAME_PACKAGE);
    RenamePackageChange renameChange = (RenamePackageChange) ch;
    IPath oldPackageName = new Path(renameChange.getOldName().replace('.', IPath.SEPARATOR));
    IPath newPackageName = new Path(renameChange.getNewName().replace('.', IPath.SEPARATOR));
    changeInfo.setOldPath(renameChange.getResourcePath().removeLastSegments(oldPackageName.segmentCount()).append(newPackageName).toString());
    changeInfo.setPath(renameChange.getResourcePath().toString());
    Set<IResource> compilationUnits = renameChange.getFCompilationUnitStamps().keySet();
    for (IResource iResource : compilationUnits) {
        ChangeInfo change = DtoFactory.newDto(ChangeInfo.class);
        change.setName(ChangeInfo.ChangeName.UPDATE);
        IPath fullPathOldPath = iResource.getFullPath();
        IPath newPath = renameChange.getResourcePath().append(fullPathOldPath.toFile().getName());
        change.setOldPath(fullPathOldPath.toString());
        change.setPath(newPath.toString());
        changesInfo.add(change);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) RenamePackageChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange) IResource(org.eclipse.core.resources.IResource)

Example 57 with IPath

use of org.eclipse.core.runtime.IPath in project che by eclipse.

the class WorkspaceTest method testSingleProjectClasspath.

@Test
public void testSingleProjectClasspath() throws Exception {
    String pom = "<groupId>test</groupId>" + "<artifactId>testArtifact</artifactId>" + "<version>42</version>" + "<dependencies>" + "    <dependency>" + "        <groupId>junit</groupId>" + "        <artifactId>junit</artifactId>" + "        <version>4.12</version>" + "    </dependency>" + "</dependencies>";
    createTestProject("test", pom);
    IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
    mavenWorkspace.update(Collections.singletonList(test));
    mavenWorkspace.waitForUpdate();
    JavaProject javaProject = (JavaProject) JavaCore.create(test);
    IClasspathEntry[] classpath = javaProject.getResolvedClasspath();
    assertThat(classpath).onProperty("path").is(new Condition<Object[]>() {

        @Override
        public boolean matches(Object[] value) {
            return Stream.of(value).filter(o -> {
                if (o instanceof IPath) {
                    return ((IPath) o).lastSegment().endsWith("junit-4.12.jar");
                }
                return false;
            }).findFirst().isPresent();
        }
    });
}
Also used : JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) ListIterator(java.util.ListIterator) ProjectRegistry(org.eclipse.che.api.project.server.ProjectRegistry) MavenWorkspace(org.eclipse.che.plugin.maven.server.core.MavenWorkspace) Test(org.testng.annotations.Test) MavenCommunication(org.eclipse.che.plugin.maven.server.core.MavenCommunication) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Constants(org.eclipse.che.ide.ext.java.shared.Constants) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest) Assert.assertThat(org.junit.Assert.assertThat) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) IPath(org.eclipse.core.runtime.IPath) Model(org.eclipse.che.ide.maven.tools.Model) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IJavaProject(org.eclipse.jdt.core.IJavaProject) BeforeMethod(org.testng.annotations.BeforeMethod) MessageType(org.eclipse.che.plugin.maven.shared.MessageType) Set(java.util.Set) MavenExecutorService(org.eclipse.che.plugin.maven.server.core.MavenExecutorService) Collectors(java.util.stream.Collectors) RemoteException(java.rmi.RemoteException) MavenKey(org.eclipse.che.maven.data.MavenKey) List(java.util.List) Stream(java.util.stream.Stream) MavenProjectManager(org.eclipse.che.plugin.maven.server.core.MavenProjectManager) Path(org.eclipse.core.runtime.Path) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) MavenTerminal(org.eclipse.che.maven.server.MavenTerminal) Mockito.mock(org.mockito.Mockito.mock) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) JavaProject(org.eclipse.jdt.internal.core.JavaProject) Condition(org.fest.assertions.Condition) ArrayList(java.util.ArrayList) TEST_SOURCE_FOLDER(org.eclipse.che.plugin.maven.shared.MavenAttributes.TEST_SOURCE_FOLDER) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) IProject(org.eclipse.core.resources.IProject) ClasspathManager(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathManager) JavaCore(org.eclipse.jdt.core.JavaCore) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Mockito.when(org.mockito.Mockito.when) File(java.io.File) Provider(com.google.inject.Provider) NotificationMessage(org.eclipse.che.plugin.maven.shared.dto.NotificationMessage) IJavaElement(org.eclipse.jdt.core.IJavaElement) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaProject(org.eclipse.jdt.internal.core.JavaProject) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) JsonObject(com.google.gson.JsonObject) IProject(org.eclipse.core.resources.IProject) Test(org.testng.annotations.Test) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)

Example 58 with IPath

use of org.eclipse.core.runtime.IPath in project che by eclipse.

the class WorkspaceTest method testShouldContainsCustomTestSourceDirectory.

@Test
public void testShouldContainsCustomTestSourceDirectory() throws Exception {
    String pom = "<groupId>test</groupId>" + "<artifactId>testArtifact</artifactId>" + "<version>42</version>" + "<dependencies>" + "    <dependency>" + "        <groupId>junit</groupId>" + "        <artifactId>junit</artifactId>" + "        <version>4.12</version>" + "    </dependency>" + "</dependencies>" + "<build>" + "<testSourceDirectory>/mytest</testSourceDirectory>" + "</build>";
    createTestProject("test", pom);
    IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
    mavenWorkspace.update(Collections.singletonList(test));
    mavenWorkspace.waitForUpdate();
    JavaProject javaProject = (JavaProject) JavaCore.create(test);
    IClasspathEntry[] classpath = javaProject.getResolvedClasspath();
    assertThat(classpath).onProperty("path").is(new Condition<Object[]>() {

        @Override
        public boolean matches(Object[] value) {
            return Stream.of(value).filter(o -> {
                if (o instanceof IPath) {
                    return ((IPath) o).toOSString().endsWith("test");
                }
                return false;
            }).findFirst().isPresent();
        }
    });
}
Also used : JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) ListIterator(java.util.ListIterator) ProjectRegistry(org.eclipse.che.api.project.server.ProjectRegistry) MavenWorkspace(org.eclipse.che.plugin.maven.server.core.MavenWorkspace) Test(org.testng.annotations.Test) MavenCommunication(org.eclipse.che.plugin.maven.server.core.MavenCommunication) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Constants(org.eclipse.che.ide.ext.java.shared.Constants) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest) Assert.assertThat(org.junit.Assert.assertThat) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) IPath(org.eclipse.core.runtime.IPath) Model(org.eclipse.che.ide.maven.tools.Model) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IJavaProject(org.eclipse.jdt.core.IJavaProject) BeforeMethod(org.testng.annotations.BeforeMethod) MessageType(org.eclipse.che.plugin.maven.shared.MessageType) Set(java.util.Set) MavenExecutorService(org.eclipse.che.plugin.maven.server.core.MavenExecutorService) Collectors(java.util.stream.Collectors) RemoteException(java.rmi.RemoteException) MavenKey(org.eclipse.che.maven.data.MavenKey) List(java.util.List) Stream(java.util.stream.Stream) MavenProjectManager(org.eclipse.che.plugin.maven.server.core.MavenProjectManager) Path(org.eclipse.core.runtime.Path) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) MavenTerminal(org.eclipse.che.maven.server.MavenTerminal) Mockito.mock(org.mockito.Mockito.mock) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) JavaProject(org.eclipse.jdt.internal.core.JavaProject) Condition(org.fest.assertions.Condition) ArrayList(java.util.ArrayList) TEST_SOURCE_FOLDER(org.eclipse.che.plugin.maven.shared.MavenAttributes.TEST_SOURCE_FOLDER) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) IProject(org.eclipse.core.resources.IProject) ClasspathManager(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathManager) JavaCore(org.eclipse.jdt.core.JavaCore) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Mockito.when(org.mockito.Mockito.when) File(java.io.File) Provider(com.google.inject.Provider) NotificationMessage(org.eclipse.che.plugin.maven.shared.dto.NotificationMessage) IJavaElement(org.eclipse.jdt.core.IJavaElement) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaProject(org.eclipse.jdt.internal.core.JavaProject) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) JsonObject(com.google.gson.JsonObject) IProject(org.eclipse.core.resources.IProject) Test(org.testng.annotations.Test) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)

Example 59 with IPath

use of org.eclipse.core.runtime.IPath in project che by eclipse.

the class Checks method checkCompilationUnitNewName.

/**
	 * Returns OK status if the new name is OK, i.e. when no file with that name exists.
	 * The name of the given CU is not OK.
	 * 
	 * @param cu CU to rename
	 * @param newBareName the new name of the CU (without extension)
	 * @return the status: FATAL if the CU already exists, OK if OK
	 */
public static RefactoringStatus checkCompilationUnitNewName(ICompilationUnit cu, String newBareName) {
    String newCUName = JavaModelUtil.getRenamedCUName(cu, newBareName);
    IPath renamedResourcePath = cu.getParent().getPath().append(newCUName);
    if (resourceExists(renamedResourcePath))
        return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.Checks_cu_name_used, BasicElementLabels.getResourceName(newCUName)));
    else
        return new RefactoringStatus();
}
Also used : IPath(org.eclipse.core.runtime.IPath) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus)

Example 60 with IPath

use of org.eclipse.core.runtime.IPath in project che by eclipse.

the class MultiStateTextFileChange method acquireDocument.

/**
	 * Acquires a document from the file buffer manager.
	 *
	 * @param monitor
	 *            the progress monitor to use
	 * @return the document
	 * @throws CoreException if the document could not successfully be acquired
	 */
private IDocument acquireDocument(final IProgressMonitor monitor) throws CoreException {
    if (fCount > 0)
        return fBuffer.getDocument();
    final ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    final IPath path = fFile.getFullPath();
    manager.connect(path, LocationKind.IFILE, monitor);
    fCount++;
    fBuffer = manager.getTextFileBuffer(path, LocationKind.IFILE);
    final IDocument document = fBuffer.getDocument();
    fContentStamp = ContentStamps.get(fFile, document);
    return document;
}
Also used : IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

IPath (org.eclipse.core.runtime.IPath)800 Path (org.eclipse.core.runtime.Path)219 File (java.io.File)161 IFile (org.eclipse.core.resources.IFile)150 CoreException (org.eclipse.core.runtime.CoreException)135 IResource (org.eclipse.core.resources.IResource)112 IOException (java.io.IOException)100 ArrayList (java.util.ArrayList)92 IProject (org.eclipse.core.resources.IProject)85 IFolder (org.eclipse.core.resources.IFolder)80 Test (org.junit.Test)72 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)58 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)55 IStatus (org.eclipse.core.runtime.IStatus)48 InputStream (java.io.InputStream)44 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)42 Status (org.eclipse.core.runtime.Status)36 IJavaProject (org.eclipse.jdt.core.IJavaProject)36 URL (java.net.URL)33 IContainer (org.eclipse.core.resources.IContainer)33