Search in sources :

Example 71 with IPath

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

the class JREContainer method computeClasspathEntries.

/**
	 * Computes the classpath entries associated with a VM - one entry per library
	 * in the context of the given path and project.
	 * 
	 * @param vm the VM
	 * @param project the project the resolution is for
	 * @param environmentId execution environment the resolution is for, or <code>null</code>
	 * @return classpath entries
	 */
private static IClasspathEntry[] computeClasspathEntries(IVMInstallType vm, IJavaProject project, String environmentId) {
    //vm.getLibraryLocations();
    LibraryLocation[] libs = null;
    boolean overrideJavaDoc = false;
    if (libs == null) {
        libs = getLibraryLocations(vm);
        overrideJavaDoc = true;
    }
    IAccessRule[][] rules = null;
    //		if (environmentId != null) {
    // compute access rules for execution environment
    IExecutionEnvironment environment = JavaRuntime.getEnvironment(environmentId);
    if (environment != null) {
        rules = environment.getAccessRules(vm, libs, project);
    }
    //		}
    RuleKey key = null;
    if (vm != null && rules != null && environmentId != null) {
        key = new RuleKey(vm, environmentId);
        RuleEntry entry = fgClasspathEntriesWithRules.get(key);
        if (entry != null && entry.equals(rules)) {
            return entry.getClasspathEntries();
        }
    }
    List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(libs.length);
    for (int i = 0; i < libs.length; i++) {
        if (!libs[i].getSystemLibraryPath().isEmpty()) {
            IPath sourcePath = libs[i].getSystemLibrarySourcePath();
            if (sourcePath.isEmpty()) {
                sourcePath = null;
            }
            IPath rootPath = libs[i].getPackageRootPath();
            if (rootPath.isEmpty()) {
                rootPath = null;
            }
            // construct the classpath attributes for this library location
            IClasspathAttribute[] attributes = JREContainer.buildClasspathAttributes(vm, libs[i], overrideJavaDoc);
            IAccessRule[] libRules = null;
            if (rules != null) {
                libRules = rules[i];
            } else {
                libRules = EMPTY_RULES;
            }
            entries.add(JavaCore.newLibraryEntry(libs[i].getSystemLibraryPath(), sourcePath, rootPath, libRules, attributes, false));
        }
    }
    IClasspathEntry[] cpEntries = entries.toArray(new IClasspathEntry[entries.size()]);
    if (key != null && rules != null) {
        fgClasspathEntriesWithRules.put(key, new RuleEntry(rules, cpEntries));
    }
    return cpEntries;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IExecutionEnvironment(org.eclipse.che.jdt.core.launching.environments.IExecutionEnvironment) IAccessRule(org.eclipse.jdt.core.IAccessRule)

Example 72 with IPath

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

the class Launching method writeInstallInfo.

/**
     * Writes out the mappings of SDK install time stamps to disk. See
     * https://bugs.eclipse.org/bugs/show_bug.cgi?id=266651 for more information.
     */
private static void writeInstallInfo() {
    if (fgInstallTimeMap != null) {
        OutputStream stream = null;
        try {
            Document doc = newDocument();
            //$NON-NLS-1$
            Element root = doc.createElement("dirs");
            doc.appendChild(root);
            Map.Entry<String, Long> entry = null;
            Element e = null;
            String key = null;
            for (Iterator<Map.Entry<String, Long>> i = fgInstallTimeMap.entrySet().iterator(); i.hasNext(); ) {
                entry = i.next();
                key = entry.getKey();
                if (fgLibraryInfoMap == null || fgLibraryInfoMap.containsKey(key)) {
                    //only persist the info if the library map also has info OR is null - prevent persisting deleted JRE information
                    //$NON-NLS-1$
                    e = doc.createElement("entry");
                    root.appendChild(e);
                    //$NON-NLS-1$
                    e.setAttribute("loc", key);
                    //$NON-NLS-1$
                    e.setAttribute("stamp", entry.getValue().toString());
                }
            }
            String xml = serializeDocument(doc);
            IPath libPath = getDefault().getStateLocation();
            //$NON-NLS-1$
            libPath = libPath.append(".install.xml");
            File file = libPath.toFile();
            if (!file.exists()) {
                file.createNewFile();
            }
            stream = new BufferedOutputStream(new FileOutputStream(file));
            //$NON-NLS-1$
            stream.write(xml.getBytes("UTF8"));
        } catch (IOException e) {
            log(e);
        } catch (CoreException e) {
            log(e);
        } finally {
            if (stream != null) {
                try {
                    stream.close();
                } catch (IOException e1) {
                }
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Element(org.w3c.dom.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) CoreException(org.eclipse.core.runtime.CoreException) FileOutputStream(java.io.FileOutputStream) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 73 with IPath

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

the class Launching method restoreLibraryInfo.

/**
     * Restores library information for VMs
     */
private static void restoreLibraryInfo() {
    fgLibraryInfoMap = new HashMap<String, LibraryInfo>(10);
    IPath libPath = getDefault().getStateLocation();
    //$NON-NLS-1$
    libPath = libPath.append("libraryInfos.xml");
    File file = libPath.toFile();
    if (file.exists()) {
        try {
            InputStream stream = new BufferedInputStream(new FileInputStream(file));
            DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            parser.setErrorHandler(new DefaultHandler());
            Element root = parser.parse(new InputSource(stream)).getDocumentElement();
            if (!root.getNodeName().equals("libraryInfos")) {
                //$NON-NLS-1$
                return;
            }
            NodeList list = root.getChildNodes();
            int length = list.getLength();
            for (int i = 0; i < length; ++i) {
                Node node = list.item(i);
                short type = node.getNodeType();
                if (type == Node.ELEMENT_NODE) {
                    Element element = (Element) node;
                    String nodeName = element.getNodeName();
                    if (nodeName.equalsIgnoreCase("libraryInfo")) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        String version = element.getAttribute("version");
                        //$NON-NLS-1$
                        String location = element.getAttribute("home");
                        //$NON-NLS-1$
                        String[] bootpath = getPathsFromXML(element, "bootpath");
                        //$NON-NLS-1$
                        String[] extDirs = getPathsFromXML(element, "extensionDirs");
                        //$NON-NLS-1$
                        String[] endDirs = getPathsFromXML(element, "endorsedDirs");
                        if (location != null) {
                            LibraryInfo info = new LibraryInfo(version, bootpath, extDirs, endDirs);
                            fgLibraryInfoMap.put(location, info);
                        }
                    }
                }
            }
        } catch (IOException | SAXException | ParserConfigurationException e) {
            log(e);
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) IPath(org.eclipse.core.runtime.IPath) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXException(org.xml.sax.SAXException) BufferedInputStream(java.io.BufferedInputStream) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 74 with IPath

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

the class Workspace method createResource.

public void createResource(IResource resource, int updateFlags) throws CoreException {
    try {
        IPath path = resource.getFullPath();
        switch(resource.getType()) {
            case IResource.FILE:
                String newName = path.lastSegment();
                VirtualFileEntry child = getProjectsRoot().getChild(path.removeLastSegments(1).toOSString());
                if (child == null) {
                    throw new NotFoundException("Can't find parent folder: " + path.removeLastSegments(1).toOSString());
                }
                FolderEntry entry = (FolderEntry) child;
                entry.createFile(newName, new byte[0]);
                break;
            case IResource.FOLDER:
                getProjectsRoot().createFolder(path.toOSString());
                break;
            case IResource.PROJECT:
                ProjectConfigImpl projectConfig = new ProjectConfigImpl();
                projectConfig.setPath(resource.getName());
                projectConfig.setName(resource.getName());
                projectConfig.setType(BaseProjectType.ID);
                projectManager.get().createProject(projectConfig, new HashMap<>());
                break;
            default:
                throw new UnsupportedOperationException();
        }
    } catch (ForbiddenException | ConflictException | ServerException | NotFoundException e) {
        throw new CoreException(new Status(0, ResourcesPlugin.getPluginId(), e.getMessage(), e));
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) IPath(org.eclipse.core.runtime.IPath) ConflictException(org.eclipse.che.api.core.ConflictException) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) NotFoundException(org.eclipse.che.api.core.NotFoundException) CoreException(org.eclipse.core.runtime.CoreException) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)

Example 75 with IPath

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

the class WorkspaceRoot method getProject.

@Override
public IProject getProject(String name) {
    //first check our project cache
    Project result = projectTable.get(name);
    if (result == null) {
        IPath projectPath = new Path(null, name).makeAbsolute();
        //try to get the project using a canonical name
        //.lastSegment();
        String canonicalName = projectPath.toOSString();
        result = projectTable.get(canonicalName);
        if (result != null)
            return result;
        result = new Project(projectPath, workspace);
        projectTable.putIfAbsent(canonicalName, result);
    }
    return result;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IProject(org.eclipse.core.resources.IProject) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) IPath(org.eclipse.core.runtime.IPath)

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