Search in sources :

Example 11 with IFolder

use of org.eclipse.core.resources.IFolder 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)

Example 12 with IFolder

use of org.eclipse.core.resources.IFolder in project che by eclipse.

the class JavaProjectHelper method removeSourceContainer.

/**
     * Removes a source folder from a IJavaProject.
     * @param jproject The parent project
     * @param containerName Name of the source folder to remove
     * @throws CoreException Remove failed
     */
public static void removeSourceContainer(IJavaProject jproject, String containerName) throws CoreException {
    IFolder folder = jproject.getProject().getFolder(containerName);
    removeFromClasspath(jproject, folder.getFullPath());
    folder.delete(true, null);
}
Also used : IFolder(org.eclipse.core.resources.IFolder)

Example 13 with IFolder

use of org.eclipse.core.resources.IFolder in project che by eclipse.

the class JavaProjectHelper method addClassFolder.

/**
     * Creates and adds a class folder to the class path.
     * @param jproject The parent project
     * @param containerName
     * @param sourceAttachPath The source attachment path
     * @param sourceAttachRoot The source attachment root path
     * @return The handle of the created root
     * @throws CoreException
     */
public static IPackageFragmentRoot addClassFolder(IJavaProject jproject, String containerName, IPath sourceAttachPath, IPath sourceAttachRoot) throws CoreException {
    IProject project = jproject.getProject();
    IContainer container = null;
    if (containerName == null || containerName.length() == 0) {
        container = project;
    } else {
        IFolder folder = project.getFolder(containerName);
        if (!folder.exists()) {
            CoreUtility.createFolder(folder, false, true, null);
        }
        container = folder;
    }
    IClasspathEntry cpe = JavaCore.newLibraryEntry(container.getFullPath(), sourceAttachPath, sourceAttachRoot);
    addToClasspath(jproject, cpe);
    return jproject.getPackageFragmentRoot(container);
}
Also used : IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IContainer(org.eclipse.core.resources.IContainer) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 14 with IFolder

use of org.eclipse.core.resources.IFolder in project che by eclipse.

the class IndexSelector method initializeIndexLocations.

/*
 *  Compute the list of paths which are keying index files.
 */
private void initializeIndexLocations() {
    IPath[] projectsAndJars = this.searchScope.enclosingProjectsAndJars();
    IndexManager manager = JavaModelManager.getIndexManager();
    // use a linked set to preserve the order during search: see bug 348507
    LinkedHashSet locations = new LinkedHashSet();
    IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern);
    if (focus == null) {
        for (int i = 0; i < projectsAndJars.length; i++) {
            IPath path = projectsAndJars[i];
            Object target = JavaModel.getTarget(path, false);
            if (// case of an external folder
            target instanceof IFolder)
                path = ((IFolder) target).getFullPath();
            locations.add(manager.computeIndexLocation(path));
        }
    } else {
        try {
            // See whether the state builder might be used to reduce the number of index locations
            // find the projects from projectsAndJars that see the focus then walk those projects looking for the jars from projectsAndJars
            int length = projectsAndJars.length;
            JavaProject[] projectsCanSeeFocus = new JavaProject[length];
            SimpleSet visitedProjects = new SimpleSet(length);
            int projectIndex = 0;
            SimpleSet externalLibsToCheck = new SimpleSet(length);
            ObjectVector superTypes = new ObjectVector();
            IJavaElement[] focuses = getFocusedElementsAndTypes(this.pattern, focus, superTypes);
            char[][][] focusQualifiedNames = null;
            boolean isAutoBuilding = ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
            if (isAutoBuilding && focus instanceof IJavaProject) {
                focusQualifiedNames = getQualifiedNames(superTypes);
            }
            IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
            for (int i = 0; i < length; i++) {
                IPath path = projectsAndJars[i];
                JavaProject project = (JavaProject) getJavaProject(path, model);
                if (project != null) {
                    visitedProjects.add(project);
                    /*We are adding all modules to the locations for searching in each one.
					Now the location contains not only current module and Jars on which depends, but also all modules from the workspace.*/
                    locations.add(manager.computeIndexLocation(path));
                /*int canSeeFocus = canSeeFocus(focuses, project, focusQualifiedNames);
					if (canSeeFocus == PROJECT_CAN_SEE_FOCUS) {
						locations.add(manager.computeIndexLocation(path));
					}
					if (canSeeFocus != PROJECT_CAN_NOT_SEE_FOCUS) {
						projectsCanSeeFocus[projectIndex++] = project;
					}*/
                } else {
                    externalLibsToCheck.add(path);
                }
            }
            for (int i = 0; i < projectIndex && externalLibsToCheck.elementSize > 0; i++) {
                IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath();
                for (int j = entries.length; --j >= 0; ) {
                    IClasspathEntry entry = entries[j];
                    if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                        IPath path = entry.getPath();
                        if (externalLibsToCheck.remove(path) != null) {
                            Object target = JavaModel.getTarget(path, false);
                            if (// case of an external folder
                            target instanceof IFolder)
                                path = ((IFolder) target).getFullPath();
                            locations.add(manager.computeIndexLocation(path));
                        }
                    }
                }
            }
            // jar files can be included in the search scope without including one of the projects that references them, so scan all projects that have not been visited
            if (externalLibsToCheck.elementSize > 0) {
                IJavaProject[] allProjects = model.getJavaProjects();
                for (int i = 0, l = allProjects.length; i < l && externalLibsToCheck.elementSize > 0; i++) {
                    JavaProject project = (JavaProject) allProjects[i];
                    if (!visitedProjects.includes(project)) {
                        IClasspathEntry[] entries = project.getResolvedClasspath();
                        for (int j = entries.length; --j >= 0; ) {
                            IClasspathEntry entry = entries[j];
                            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                                IPath path = entry.getPath();
                                if (externalLibsToCheck.remove(path) != null) {
                                    Object target = JavaModel.getTarget(path, false);
                                    if (// case of an external folder
                                    target instanceof IFolder)
                                        path = ((IFolder) target).getFullPath();
                                    locations.add(manager.computeIndexLocation(path));
                                }
                            }
                        }
                    }
                }
            }
        } catch (JavaModelException e) {
        // ignored
        }
    }
    // Ensure no nulls
    locations.remove(null);
    this.indexLocations = (IndexLocation[]) locations.toArray(new IndexLocation[locations.size()]);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaProject(org.eclipse.jdt.internal.core.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) SimpleSet(org.eclipse.jdt.internal.compiler.util.SimpleSet) JavaModelException(org.eclipse.jdt.core.JavaModelException) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ObjectVector(org.eclipse.jdt.internal.compiler.util.ObjectVector) IndexManager(org.eclipse.jdt.internal.core.search.indexing.IndexManager) IJavaProject(org.eclipse.jdt.core.IJavaProject) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) IFolder(org.eclipse.core.resources.IFolder) IJavaModel(org.eclipse.jdt.core.IJavaModel)

Example 15 with IFolder

use of org.eclipse.core.resources.IFolder in project che by eclipse.

the class JavaSearchScope method toString.

public String toString() {
    //$NON-NLS-1$
    StringBuffer result = new StringBuffer("JavaSearchScope on ");
    if (this.elements != null) {
        //$NON-NLS-1$
        result.append("[");
        for (int i = 0, length = this.elements.size(); i < length; i++) {
            JavaElement element = (JavaElement) this.elements.get(i);
            //$NON-NLS-1$
            result.append("\n\t");
            result.append(element.toStringWithAncestors());
        }
        //$NON-NLS-1$
        result.append("\n]");
    } else {
        if (this.pathsCount == 0) {
            //$NON-NLS-1$
            result.append("[empty scope]");
        } else {
            //$NON-NLS-1$
            result.append("[");
            String[] paths = new String[this.relativePaths.length];
            int index = 0;
            for (int i = 0; i < this.relativePaths.length; i++) {
                String path = this.relativePaths[i];
                if (path == null)
                    continue;
                String containerPath;
                if (ExternalFoldersManager.isInternalPathForExternalFolder(new Path(this.containerPaths[i]))) {
                    Object target = JavaModel.getWorkspaceTarget(new Path(this.containerPaths[i]));
                    containerPath = ((IFolder) target).getLocation().toOSString();
                } else {
                    containerPath = this.containerPaths[i];
                }
                if (path.length() > 0) {
                    paths[index++] = containerPath + '/' + path;
                } else {
                    paths[index++] = containerPath;
                }
            }
            System.arraycopy(paths, 0, paths = new String[index], 0, index);
            Util.sort(paths);
            for (int i = 0; i < index; i++) {
                //$NON-NLS-1$
                result.append("\n\t");
                result.append(paths[i]);
            }
            //$NON-NLS-1$
            result.append("\n]");
        }
    }
    return result.toString();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) JavaElement(org.eclipse.jdt.internal.core.JavaElement) IJavaElement(org.eclipse.jdt.core.IJavaElement) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IFolder (org.eclipse.core.resources.IFolder)237 IFile (org.eclipse.core.resources.IFile)95 IPath (org.eclipse.core.runtime.IPath)70 CoreException (org.eclipse.core.runtime.CoreException)65 IProject (org.eclipse.core.resources.IProject)64 IResource (org.eclipse.core.resources.IResource)56 File (java.io.File)35 IContainer (org.eclipse.core.resources.IContainer)33 ArrayList (java.util.ArrayList)31 Path (org.eclipse.core.runtime.Path)31 IOException (java.io.IOException)26 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)26 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)18 Test (org.junit.Test)18 IRunProcessService (org.talend.designer.runprocess.IRunProcessService)17 PersistenceException (org.talend.commons.exception.PersistenceException)16 InputStream (java.io.InputStream)15 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)13 IJavaProject (org.eclipse.jdt.core.IJavaProject)13 URL (java.net.URL)12