Search in sources :

Example 76 with IPath

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

the class Launching method readInstallInfo.

/**
     * Reads the file of saved time stamps and populates the {@link #fgInstallTimeMap}.
     * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=266651 for more information
     *
     * @since 3.7
     */
private static void readInstallInfo() {
    fgInstallTimeMap = new HashMap<String, Long>();
    IPath libPath = getDefault().getStateLocation();
    //$NON-NLS-1$
    libPath = libPath.append(".install.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().equalsIgnoreCase("dirs")) {
                //$NON-NLS-1$
                NodeList nodes = root.getChildNodes();
                Node node = null;
                Element element = null;
                for (int i = 0; i < nodes.getLength(); i++) {
                    node = nodes.item(i);
                    if (node.getNodeType() == Node.ELEMENT_NODE) {
                        element = (Element) node;
                        if (element.getNodeName().equalsIgnoreCase("entry")) {
                            //$NON-NLS-1$
                            //$NON-NLS-1$
                            String loc = element.getAttribute("loc");
                            //$NON-NLS-1$
                            String stamp = element.getAttribute("stamp");
                            try {
                                Long l = new Long(stamp);
                                fgInstallTimeMap.put(loc, l);
                            } catch (NumberFormatException nfe) {
                            //do nothing
                            }
                        }
                    }
                }
            }
        } catch (IOException e) {
            log(e);
        } catch (ParserConfigurationException e) {
            log(e);
        } catch (SAXException 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 77 with IPath

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

the class StandardVMType method getDefaultSystemLibrarySource.

/**
	 * Returns a path to the source attachment for the given library, or
	 * an empty path if none.
	 *
	 * @param libLocation
	 *         the {@link java.io.File} location of the library to find the source for
	 * @return a path to the source attachment for the given library, or
	 * an empty path if none
	 */
protected IPath getDefaultSystemLibrarySource(File libLocation) {
    File parent = libLocation.getParentFile();
    while (parent != null) {
        File parentsrc = new File(parent, SRC_JAR);
        if (parentsrc.isFile()) {
            setDefaultRootPath(SRC);
            return new Path(parentsrc.getPath());
        }
        parentsrc = new File(parent, SRC_ZIP);
        if (parentsrc.isFile()) {
            //$NON-NLS-1$
            setDefaultRootPath("");
            return new Path(parentsrc.getPath());
        }
        parent = parent.getParentFile();
    }
    // if we didn't find any of the normal source files, look for J9 source
    IPath result = checkForJ9LibrarySource(libLocation);
    if (result != null) {
        return result;
    }
    // check for <lib>-src.jar pattern
    IPath libName = new Path(libLocation.getName());
    String extension = libName.getFileExtension();
    String prefix = libName.removeFileExtension().lastSegment();
    if (extension != null) {
        IPath srcPath = new Path(libLocation.getPath());
        srcPath = srcPath.removeLastSegments(1);
        StringBuffer buf = new StringBuffer();
        buf.append(prefix);
        //$NON-NLS-1$
        buf.append("-src.");
        buf.append(extension);
        srcPath = srcPath.append(buf.toString());
        if (srcPath.toFile().exists()) {
            return srcPath;
        }
    }
    //$NON-NLS-1$
    setDefaultRootPath("");
    return Path.EMPTY;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) File(java.io.File)

Example 78 with IPath

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

the class StandardVMType method gatherAllLibraries.

/**
	 * Returns a list of all zip's and jars contained in the given directories.
	 *
	 * @param dirPaths
	 *         a list of absolute paths of directories to search
	 * @return List of all zip's and jars
	 */
public static List<LibraryLocation> gatherAllLibraries(String[] dirPaths) {
    List<LibraryLocation> libraries = new ArrayList<LibraryLocation>();
    for (int i = 0; i < dirPaths.length; i++) {
        File extDir = new File(dirPaths[i]);
        if (extDir.isDirectory()) {
            String[] names = extDir.list(fgArchiveFilter);
            if (names != null) {
                for (int j = 0; j < names.length; j++) {
                    File jar = new File(extDir, names[j]);
                    if (jar.isFile()) {
                        try {
                            IPath libPath = new Path(jar.getCanonicalPath());
                            IPath sourcePath = Path.EMPTY;
                            IPath packageRoot = Path.EMPTY;
                            URL javadocLocation = null;
                            URL indexLocation = null;
                            //								for( ILibraryLocationResolver resolver : getLibraryLocationResolvers() ) {
                            //									try {
                            //										sourcePath = resolver.getSourcePath(libPath);
                            //										packageRoot = resolver.getPackageRoot(libPath);
                            //										javadocLocation = resolver.getJavadocLocation(libPath);
                            //										indexLocation = resolver.getIndexLocation(libPath);
                            //										break;
                            //									} catch(Exception e) {
                            //										Launching.log(e);
                            //									}
                            //								}
                            LibraryLocation library = new LibraryLocation(libPath, sourcePath, packageRoot, javadocLocation, indexLocation);
                            libraries.add(library);
                        } catch (IOException e) {
                            Launching.log(e);
                        }
                    }
                }
            }
        }
    }
    return libraries;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL)

Example 79 with IPath

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

the class StandardVMType method getDefaultLibraryLocations.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.launching.IVMInstallType#getDefaultLibraryLocations(java.io.File)
	 */
public LibraryLocation[] getDefaultLibraryLocations(File installLocation) {
    //NOTE: We do not add libraries from the "endorsed" directory explicitly, as
    //the bootpath contains these entries already (if they exist).
    // Determine the java executable that corresponds to the specified install location
    // and use this to generate library information.  If no java executable was found, 
    // the 'standard' libraries will be returned.
    List<LibraryLocation> allLibs = fgDefaultLibLocs.get(installLocation.getAbsolutePath());
    if (allLibs == null) {
        File javaExecutable = findJavaExecutable(installLocation);
        LibraryInfo libInfo;
        if (javaExecutable == null) {
            libInfo = getDefaultLibraryInfo(installLocation);
        } else {
            libInfo = getLibraryInfo(installLocation, javaExecutable);
        }
        // Add all endorsed libraries - they are first, as they replace
        allLibs = new ArrayList<LibraryLocation>(gatherAllLibraries(libInfo.getEndorsedDirs()));
        // next is the boot path libraries
        String[] bootpath = libInfo.getBootpath();
        List<LibraryLocation> boot = new ArrayList<LibraryLocation>(bootpath.length);
        URL url = getDefaultJavadocLocation(installLocation);
        for (int i = 0; i < bootpath.length; i++) {
            IPath path = new Path(bootpath[i]);
            File lib = path.toFile();
            if (lib.exists() && lib.isFile()) {
                LibraryLocation libraryLocation = new LibraryLocation(path, getDefaultSystemLibrarySource(lib), getDefaultPackageRootPath(), url);
                boot.add(libraryLocation);
            }
        }
        allLibs.addAll(boot);
        // Add all extension libraries
        allLibs.addAll(gatherAllLibraries(libInfo.getExtensionDirs()));
        //remove duplicates
        HashSet<String> set = new HashSet<String>();
        LibraryLocation lib = null;
        for (ListIterator<LibraryLocation> liter = allLibs.listIterator(); liter.hasNext(); ) {
            lib = liter.next();
            IPath systemLibraryPath = lib.getSystemLibraryPath();
            String device = systemLibraryPath.getDevice();
            if (device != null) {
                // @see Bug 197866 - Installed JRE Wizard creates duplicate system libraries when drive letter is lower case
                systemLibraryPath = systemLibraryPath.setDevice(device.toUpperCase());
            }
            if (!set.add(systemLibraryPath.toOSString())) {
                //did not add it, duplicate
                liter.remove();
            }
        }
        fgDefaultLibLocs.put(installLocation.getAbsolutePath(), allLibs);
    }
    return allLibs.toArray(new LibraryLocation[allLibs.size()]);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) URL(java.net.URL) File(java.io.File) HashSet(java.util.HashSet)

Example 80 with IPath

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

the class ChangeDescription method createSourceResource.

private IResource createSourceResource(IResourceDelta delta) {
    IPath sourcePath = delta.getMovedFromPath();
    IResource resource = delta.getResource();
    IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
    switch(resource.getType()) {
        case IResource.PROJECT:
            return wsRoot.getProject(sourcePath.segment(0));
        case IResource.FOLDER:
            return wsRoot.getFolder(sourcePath);
        case IResource.FILE:
            return wsRoot.getFile(sourcePath);
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IResource(org.eclipse.core.resources.IResource)

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