Example usage for org.eclipse.jdt.internal.core ClasspathEntry NO_ENTRIES

List of usage examples for org.eclipse.jdt.internal.core ClasspathEntry NO_ENTRIES

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core ClasspathEntry NO_ENTRIES.

Prototype

ClasspathEntry[] NO_ENTRIES

To view the source code for org.eclipse.jdt.internal.core ClasspathEntry NO_ENTRIES.

Click Source Link

Usage

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

/**
 * Reads the classpath file entries of this project's .classpath file.
 * Returns a two-dimensional array, where the number of elements in the row is fixed to 2.
 * The first element is an array of raw classpath entries, which includes the output entry,
 * and the second element is an array of referenced entries that may have been stored 
 * by the client earlier. // ww  w .j a  v  a 2  s. co m
 * See {@link IJavaProject#getReferencedClasspathEntries()} for more details.
 * As a side effect, unknown elements are stored in the given map (if not null)
 * Throws exceptions if the file cannot be accessed or is malformed.
 */
public IClasspathEntry[][] readFileEntriesWithException(Map unknownElements)
        throws CoreException, IOException, ClasspathEntry.AssertionFailedException {
    IFile rscFile = this.project.getFile(JavaProject.CLASSPATH_FILENAME);
    byte[] bytes;
    if (rscFile.exists()) {
        bytes = Util.getResourceContentsAsByteArray(rscFile);
    } else {
        // when a project is imported, we get a first delta for the addition of the .project, but the .classpath is not accessible
        // so default to using java.io.File
        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=96258
        URI location = rscFile.getLocationURI();
        if (location == null)
            throw new IOException("Cannot obtain a location URI for " + rscFile); //$NON-NLS-1$
        File file = Util.toLocalFile(location, null/*no progress monitor available*/);
        if (file == null)
            throw new IOException("Unable to fetch file from " + location); //$NON-NLS-1$
        try {
            bytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file);
        } catch (IOException e) {
            if (!file.exists())
                return new IClasspathEntry[][] { defaultClasspath(), ClasspathEntry.NO_ENTRIES };
            throw e;
        }
    }
    if (hasUTF8BOM(bytes)) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=240034
        int length = bytes.length - IContentDescription.BOM_UTF_8.length;
        System.arraycopy(bytes, IContentDescription.BOM_UTF_8.length, bytes = new byte[length], 0, length);
    }
    String xmlClasspath;
    try {
        xmlClasspath = new String(bytes, org.eclipse.jdt.internal.compiler.util.Util.UTF_8); // .classpath always encoded with UTF-8
    } catch (UnsupportedEncodingException e) {
        Util.log(e, "Could not read .classpath with UTF-8 encoding"); //$NON-NLS-1$
        // fallback to default
        xmlClasspath = new String(bytes);
    }
    return decodeClasspath(xmlClasspath, unknownElements);
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

private IClasspathEntry[][] readFileEntries(Map unkwownElements) {
    try {/*www . j av a2  s.co m*/
        return readFileEntriesWithException(unkwownElements);
    } catch (CoreException e) {
        Util.log(e, "Exception while reading " + getPath().append(JavaProject.CLASSPATH_FILENAME)); //$NON-NLS-1$
        return new IClasspathEntry[][] { JavaProject.INVALID_CLASSPATH, ClasspathEntry.NO_ENTRIES };
    } catch (IOException e) {
        Util.log(e, "Exception while reading " + getPath().append(JavaProject.CLASSPATH_FILENAME)); //$NON-NLS-1$
        return new IClasspathEntry[][] { JavaProject.INVALID_CLASSPATH, ClasspathEntry.NO_ENTRIES };
    } catch (ClasspathEntry.AssertionFailedException e) {
        Util.log(e, "Exception while reading " + getPath().append(JavaProject.CLASSPATH_FILENAME)); //$NON-NLS-1$
        return new IClasspathEntry[][] { JavaProject.INVALID_CLASSPATH, ClasspathEntry.NO_ENTRIES };
    }
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

public boolean writeFileEntries(IClasspathEntry[] newClasspath, IPath newOutputLocation)
        throws JavaModelException {
    return writeFileEntries(newClasspath, ClasspathEntry.NO_ENTRIES, newOutputLocation);
}