Search in sources :

Example 21 with IPath

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

the class ImportOperation method getDestinationContainerFor.

/**
     * Returns the container resource that the passed file system object should be
     * imported into.
     *
     * @param fileSystemObject the file system object being imported
     * @return the container resource that the passed file system object should be
     *     imported into
     * @exception CoreException if this method failed
     */
IContainer getDestinationContainerFor(Object fileSystemObject) throws CoreException {
    IPath pathname = new Path(provider.getFullPath(fileSystemObject));
    if (createContainerStructure) {
        return createContainersFor(pathname.removeLastSegments(1));
    }
    if (source == fileSystemObject) {
        return null;
    }
    IPath sourcePath = new Path(provider.getFullPath(source));
    IPath destContainerPath = pathname.removeLastSegments(1);
    IPath relativePath = destContainerPath.removeFirstSegments(sourcePath.segmentCount()).setDevice(null);
    return createContainersFor(relativePath);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath)

Example 22 with IPath

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

the class ImportOperation method importFileSystemObjects.

/**
     * Imports the specified file system objects into the workspace.
     * If the import fails, adds a status object to the list to be returned by
     * <code>getStatus</code>.
     *
     * @param filesToImport the list of file system objects to import
     *   (element type: <code>Object</code>)
     * @throws CoreException
     * @exception OperationCanceledException if canceled
     */
void importFileSystemObjects(List filesToImport) throws CoreException {
    Iterator filesEnum = filesToImport.iterator();
    while (filesEnum.hasNext()) {
        Object fileSystemObject = filesEnum.next();
        if (source == null) {
            // We just import what we are given into the destination
            IPath sourcePath = new Path(provider.getFullPath(fileSystemObject)).removeLastSegments(1);
            if (provider.isFolder(fileSystemObject) && sourcePath.isEmpty()) {
                // If we don't have a parent then we have selected the
                // file systems root. Roots can't copied (at least not
                // under windows).
                errorTable.add(new Status(IStatus.INFO, PlatformUI.PLUGIN_ID, 0, "DataTransferMessages.ImportOperation_cannotCopy", null));
                continue;
            }
            source = sourcePath.toFile();
        }
        importRecursivelyFrom(fileSystemObject, POLICY_DEFAULT);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) Iterator(java.util.Iterator)

Example 23 with IPath

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

the class JavaProjectHelper method addRTJar13.

public static IPackageFragmentRoot addRTJar13(IJavaProject jproject) throws CoreException {
    IPath[] rtJarPath = findRtJar(RT_STUBS_13);
    Map options = jproject.getOptions(false);
    JavaProjectHelper.set13CompilerOptions(options);
    jproject.setOptions(options);
    return addLibrary(jproject, rtJarPath[0], rtJarPath[1], rtJarPath[2]);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Map(java.util.Map)

Example 24 with IPath

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

the class ClasspathUpdaterService method createModifiedEntry.

private IClasspathEntry[] createModifiedEntry(List<ClasspathEntryDto> entries) {
    List<IClasspathEntry> coreClasspathEntries = new ArrayList<>(entries.size());
    for (ClasspathEntryDto entry : entries) {
        IPath path = fromOSString(entry.getPath());
        int entryKind = entry.getEntryKind();
        if (IClasspathEntry.CPE_LIBRARY == entryKind) {
            coreClasspathEntries.add(newLibraryEntry(path, null, null));
        } else if (IClasspathEntry.CPE_SOURCE == entryKind) {
            coreClasspathEntries.add(newSourceEntry(path));
        } else if (IClasspathEntry.CPE_VARIABLE == entryKind) {
            coreClasspathEntries.add(newVariableEntry(path, null, null));
        } else if (IClasspathEntry.CPE_CONTAINER == entryKind) {
            coreClasspathEntries.add(newContainerEntry(path));
        } else if (IClasspathEntry.CPE_PROJECT == entryKind) {
            coreClasspathEntries.add(newProjectEntry(path));
        }
    }
    return coreClasspathEntries.toArray(new IClasspathEntry[coreClasspathEntries.size()]);
}
Also used : IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) ClasspathEntryDto(org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto)

Example 25 with IPath

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

the class ClasspathBuilder method addJars.

private void addJars(IJavaProject project, List<String> library, final List<IClasspathEntry> classpathEntries) {
    if (library == null || library.isEmpty()) {
        return;
    }
    for (String libFolder : library) {
        if (libFolder.isEmpty()) {
            continue;
        }
        IFolder libraryFolder = project.getProject().getFolder(libFolder);
        if (!libraryFolder.exists()) {
            return;
        }
        try {
            libraryFolder.accept(proxy -> {
                if (IResource.FILE != proxy.getType()) {
                    return true;
                }
                IPath path = proxy.requestFullPath();
                if (!path.toString().endsWith(".jar")) {
                    return false;
                }
                IClasspathEntry libEntry = JavaCore.newLibraryEntry(proxy.requestResource().getLocation(), null, null);
                classpathEntries.add(libEntry);
                return false;
            }, IContainer.INCLUDE_PHANTOMS);
        } catch (CoreException e) {
            LOG.warn("Can't read folder structure: " + libraryFolder.getFullPath().toString());
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IPath (org.eclipse.core.runtime.IPath)500 Path (org.eclipse.core.runtime.Path)128 File (java.io.File)106 IFile (org.eclipse.core.resources.IFile)89 IResource (org.eclipse.core.resources.IResource)80 CoreException (org.eclipse.core.runtime.CoreException)74 ArrayList (java.util.ArrayList)72 IFolder (org.eclipse.core.resources.IFolder)63 IProject (org.eclipse.core.resources.IProject)60 IOException (java.io.IOException)57 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)51 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)40 IStatus (org.eclipse.core.runtime.IStatus)33 IJavaProject (org.eclipse.jdt.core.IJavaProject)33 URL (java.net.URL)26 InputStream (java.io.InputStream)23 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)23 Status (org.eclipse.core.runtime.Status)23 HashSet (java.util.HashSet)22 Test (org.junit.Test)22