Example usage for org.eclipse.jdt.internal.core JavaProject INVALID_CLASSPATH

List of usage examples for org.eclipse.jdt.internal.core JavaProject INVALID_CLASSPATH

Introduction

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

Prototype

IClasspathEntry[] INVALID_CLASSPATH

To view the source code for org.eclipse.jdt.internal.core JavaProject INVALID_CLASSPATH.

Click Source Link

Document

Value of the project's raw classpath if the .classpath file contains invalid entries.

Usage

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

License:Open Source License

private static void recreatePersistedContainer(final IJavaProject project, final IPath containerPath,
        String containerString, boolean addToContainerValues) {
    if (!project.getProject().isAccessible())
        return; // avoid leaking deleted project's persisted container
    if (containerString == null) {
        getJavaModelManager().containerPut(project, containerPath, null);
    } else {/* w w  w.  ja v a2  s.c  o  m*/
        IClasspathEntry[] entries;
        try {
            entries = ((JavaProject) project).decodeClasspath(containerString,
                    null/*not interested in unknown elements*/)[0];
        } catch (IOException e) {
            Util.log(e, "Could not recreate persisted container: \n" + containerString); //$NON-NLS-1$
            entries = JavaProject.INVALID_CLASSPATH;
        }
        if (entries != JavaProject.INVALID_CLASSPATH) {
            final IClasspathEntry[] containerEntries = entries;
            IClasspathContainer container = new IClasspathContainer() {
                public IClasspathEntry[] getClasspathEntries() {
                    return containerEntries;
                }

                public String getDescription() {
                    return "Persisted container [" + containerPath + " for project [" + project.getElementName() //$NON-NLS-1$//$NON-NLS-2$
                            + "]"; //$NON-NLS-1$
                }

                public int getKind() {
                    return 0;
                }

                public IPath getPath() {
                    return containerPath;
                }

                public String toString() {
                    return getDescription();
                }

            };
            if (addToContainerValues) {
                getJavaModelManager().containerPut(project, containerPath, container);
            }
            Map projectContainers = (Map) getJavaModelManager().previousSessionContainers.get(project);
            if (projectContainers == null) {
                projectContainers = new HashMap(1);
                getJavaModelManager().previousSessionContainers.put(project, projectContainers);
            }
            projectContainers.put(containerPath, container);
        }
    }
}

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

License:Open Source License

/**
 * @see IJavaProject//from w w w. ja  v  a  2 s  .  com
 */
public IClasspathEntry[] getRawClasspath() throws JavaModelException {
    JavaModelManager.PerProjectInfo perProjectInfo = getPerProjectInfo();
    IClasspathEntry[] classpath = perProjectInfo.rawClasspath;
    if (classpath != null)
        return classpath;

    classpath = perProjectInfo.readAndCacheClasspath(this)[0];

    if (classpath == JavaProject.INVALID_CLASSPATH)
        return defaultClasspath();

    return classpath;
}

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

License:Open Source License

private IClasspathEntry[][] readFileEntries(Map unkwownElements) {
    try {//from ww w.java 2s. c o  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

/**
 * @see IJavaProject/*from w ww.  jav  a2 s  .c  o  m*/
 */
public IPath readOutputLocation() {
    // Read classpath file without creating markers nor logging problems
    IClasspathEntry[][] classpath = readFileEntries(null/*not interested in unknown elements*/);
    if (classpath[0] == JavaProject.INVALID_CLASSPATH)
        return defaultOutputLocation();

    // extract the output location
    IPath outputLocation = null;
    if (classpath[0].length > 0) {
        IClasspathEntry entry = classpath[0][classpath[0].length - 1];
        if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
            outputLocation = entry.getPath();
        }
    }
    return outputLocation;
}

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

License:Open Source License

/**
 * @see IJavaProject/*from   ww w .j  a  va 2s.  co m*/
 */
public IClasspathEntry[] readRawClasspath() {
    // Read classpath file without creating markers nor logging problems
    IClasspathEntry[][] classpath = readFileEntries(null/*not interested in unknown elements*/);
    if (classpath[0] == JavaProject.INVALID_CLASSPATH)
        return defaultClasspath();

    // discard the output location
    if (classpath[0].length > 0) {
        IClasspathEntry entry = classpath[0][classpath[0].length - 1];
        if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
            IClasspathEntry[] copy = new IClasspathEntry[classpath[0].length - 1];
            System.arraycopy(classpath[0], 0, copy, 0, copy.length);
            classpath[0] = copy;
        }
    }
    return classpath[0];
}

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

License:Open Source License

/**
 * Writes the classpath in a sharable format (VCM-wise) only when necessary, that is, if  it is semantically different
 * from the existing one in file. Will never write an identical one.
 *
 * @param newClasspath IClasspathEntry[]
 * @param newOutputLocation IPath/*  ww  w .j av a 2 s. c  om*/
 * @return boolean Return whether the .classpath file was modified.
 * @throws JavaModelException
 */
public boolean writeFileEntries(IClasspathEntry[] newClasspath, IClasspathEntry[] referencedEntries,
        IPath newOutputLocation) throws JavaModelException {

    if (!this.project.isAccessible())
        return false;

    Map unknownElements = new HashMap();
    IClasspathEntry[][] fileEntries = readFileEntries(unknownElements);
    if (fileEntries[0] != JavaProject.INVALID_CLASSPATH
            && areClasspathsEqual(newClasspath, newOutputLocation, fileEntries[0])
            && (referencedEntries == null || areClasspathsEqual(referencedEntries, fileEntries[1]))) {
        // no need to save it, it is the same
        return false;
    }

    // actual file saving
    try {
        setSharedProperty(JavaProject.CLASSPATH_FILENAME,
                encodeClasspath(newClasspath, referencedEntries, newOutputLocation, true, unknownElements));
        return true;
    } catch (CoreException e) {
        throw new JavaModelException(e);
    }
}