Search in sources :

Example 1 with PerProjectInfo

use of org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo in project che by eclipse.

the class JavaProject method getRawClasspath.

/**
     * Returns the raw classpath for the project, as a list of classpath
     * entries. This corresponds to the exact set of entries which were assigned
     * using <code>setRawClasspath</code>, in particular such a classpath may
     * contain classpath variable and classpath container entries. Classpath
     * variable and classpath container entries can be resolved using the
     * helper method <code>getResolvedClasspath</code>; classpath variable
     * entries also can be resolved individually using
     * <code>JavaCore#getClasspathVariable</code>).
     * <p>
     * Both classpath containers and classpath variables provides a level of
     * indirection that can make the <code>.classpath</code> file stable across
     * workspaces.
     * As an example, classpath variables allow a classpath to no longer refer
     * directly to external JARs located in some user specific location.
     * The classpath can simply refer to some variables defining the proper
     * locations of these external JARs. Similarly, classpath containers
     * allows classpath entries to be computed dynamically by the plug-in that
     * defines that kind of classpath container.
     * </p>
     * <p>
     * Note that in case the project isn't yet opened, the classpath will
     * be read directly from the associated <tt>.classpath</tt> file.
     * </p>
     *
     * @return the raw classpath for the project, as a list of classpath entries
     * @throws org.eclipse.jdt.core.JavaModelException
     *         if this element does not exist or if an
     *         exception occurs while accessing its corresponding resource
     * @see org.eclipse.jdt.core.IClasspathEntry
     */
public IClasspathEntry[] getRawClasspath() throws JavaModelException {
    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;
}
Also used : PerProjectInfo(org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Example 2 with PerProjectInfo

use of org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo in project che by eclipse.

the class JavaProject method getClasspathEntryFor.

/**
     * Returns the classpath entry that refers to the given path
     * or <code>null</code> if there is no reference to the path.
     *
     * @param path
     *         IPath
     * @return IClasspathEntry
     * @throws JavaModelException
     */
public IClasspathEntry getClasspathEntryFor(IPath path) throws JavaModelException {
    // force resolution
    getResolvedClasspath();
    PerProjectInfo perProjectInfo = getPerProjectInfo();
    if (perProjectInfo == null)
        return null;
    Map rootPathToResolvedEntries = perProjectInfo.rootPathToResolvedEntries;
    if (rootPathToResolvedEntries == null)
        return null;
    IClasspathEntry classpathEntry = (IClasspathEntry) rootPathToResolvedEntries.get(path);
    if (classpathEntry == null) {
        path = getProject().getWorkspace().getRoot().getLocation().append(path);
        classpathEntry = (IClasspathEntry) rootPathToResolvedEntries.get(path);
    }
    return classpathEntry;
}
Also used : PerProjectInfo(org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with PerProjectInfo

use of org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo in project che by eclipse.

the class JavaProject method getEclipsePreferences.

/**
     * Returns the project custom preference pool.
     * Project preferences may include custom encoding.
     * @return IEclipsePreferences or <code>null</code> if the project
     * 	does not have a java nature.
     */
public IEclipsePreferences getEclipsePreferences() {
    if (!org.eclipse.jdt.internal.core.JavaProject.hasJavaNature(this.project))
        return null;
    // Get cached preferences if exist
    PerProjectInfo perProjectInfo = getJavaModelManager().getPerProjectInfo(this.project, true);
    if (perProjectInfo.preferences != null)
        return perProjectInfo.preferences;
    // Init project preferences
    IScopeContext context = new ProjectScope(getProject());
    final IEclipsePreferences eclipsePreferences = context.getNode(JavaCore.PLUGIN_ID);
    //        updatePreferences(eclipsePreferences);
    perProjectInfo.preferences = eclipsePreferences;
    //        eclipsePreferences.addPreferenceChangeListener(this.preferencesChangeListener);
    return eclipsePreferences;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) PerProjectInfo(org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences)

Example 4 with PerProjectInfo

use of org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo in project che by eclipse.

the class JavaProject method getResolvedClasspath.

/**
     * This is a helper method returning the resolved classpath for the project
     * as a list of simple (non-variable, non-container) classpath entries.
     * All classpath variable and classpath container entries in the project's
     * raw classpath will be replaced by the simple classpath entries they
     * resolve to.
     * <p>
     * The resulting resolved classpath is accurate for the given point in time.
     * If the project's raw classpath is later modified, or if classpath
     * variables are changed, the resolved classpath can become out of date.
     * Because of this, hanging on resolved classpath is not recommended.
     * </p>
     * <p>
     * Note that if the resolution creates duplicate entries
     * (i.e. {@link IClasspathEntry entries} which are {@link Object#equals(Object)}),
     * only the first one is added to the resolved classpath.
     * </p>
     *
     * @see IClasspathEntry
     */
public IClasspathEntry[] getResolvedClasspath() throws JavaModelException {
    PerProjectInfo perProjectInfo = getPerProjectInfo();
    IClasspathEntry[] resolvedClasspath = perProjectInfo.getResolvedClasspath();
    if (resolvedClasspath == null) {
        resolveClasspath(perProjectInfo, false, /*don't use previous session values*/
        true);
        resolvedClasspath = perProjectInfo.getResolvedClasspath();
        if (resolvedClasspath == null) {
            // another thread reset the resolved classpath, use a temporary PerProjectInfo
            PerProjectInfo temporaryInfo = newTemporaryInfo();
            resolveClasspath(temporaryInfo, false, /*don't use previous session values*/
            true);
            resolvedClasspath = temporaryInfo.getResolvedClasspath();
        }
    }
    return resolvedClasspath;
}
Also used : PerProjectInfo(org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Example 5 with PerProjectInfo

use of org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo in project che by eclipse.

the class JavaProject method getOptions.

public Map getOptions(boolean inheritJavaCoreOptions) {
    // initialize to the defaults from JavaCore options pool
    Map options = inheritJavaCoreOptions ? JavaCore.getOptions() : new Hashtable(5);
    // Get project specific options
    PerProjectInfo perProjectInfo = null;
    Hashtable projectOptions = null;
    JavaModelManager javaModelManager = getJavaModelManager();
    HashSet optionNames = javaModelManager.optionNames;
    try {
        perProjectInfo = getPerProjectInfo();
        projectOptions = perProjectInfo.options;
        if (projectOptions == null) {
            // get eclipse preferences
            IEclipsePreferences projectPreferences = getEclipsePreferences();
            // cannot do better (non-Java project)
            if (projectPreferences == null)
                return options;
            // create project options
            String[] propertyNames = projectPreferences.keys();
            projectOptions = new Hashtable(propertyNames.length);
            for (int i = 0; i < propertyNames.length; i++) {
                String propertyName = propertyNames[i];
                String value = projectPreferences.get(propertyName, null);
                if (value != null) {
                    value = value.trim();
                    // Keep the option value, even if it's deprecated
                    // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=324987
                    projectOptions.put(propertyName, value);
                    if (!optionNames.contains(propertyName)) {
                        // try to migrate deprecated options
                        String[] compatibleOptions = (String[]) javaModelManager.deprecatedOptions.get(propertyName);
                        if (compatibleOptions != null) {
                            for (int co = 0, length = compatibleOptions.length; co < length; co++) {
                                String compatibleOption = compatibleOptions[co];
                                if (!projectOptions.containsKey(compatibleOption))
                                    projectOptions.put(compatibleOption, value);
                            }
                        }
                    }
                }
            }
            // cache project options
            perProjectInfo.options = projectOptions;
        }
    } catch (JavaModelException jme) {
        projectOptions = new Hashtable();
    } catch (BackingStoreException e) {
        projectOptions = new Hashtable();
    }
    // Inherit from JavaCore options if specified
    if (inheritJavaCoreOptions) {
        Iterator propertyNames = projectOptions.entrySet().iterator();
        while (propertyNames.hasNext()) {
            Map.Entry entry = (Map.Entry) propertyNames.next();
            String propertyName = (String) entry.getKey();
            String propertyValue = (String) entry.getValue();
            if (propertyValue != null && javaModelManager.knowsOption(propertyName)) {
                options.put(propertyName, propertyValue.trim());
            }
        }
        Util.fixTaskTags(options);
        return options;
    }
    Util.fixTaskTags(projectOptions);
    return projectOptions;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Hashtable(java.util.Hashtable) BackingStoreException(org.osgi.service.prefs.BackingStoreException) JavaModelManager.getJavaModelManager(org.eclipse.jdt.internal.core.JavaModelManager.getJavaModelManager) PerProjectInfo(org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

PerProjectInfo (org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo)5 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)2 HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1 ProjectScope (org.eclipse.core.resources.ProjectScope)1 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 JavaModelManager.getJavaModelManager (org.eclipse.jdt.internal.core.JavaModelManager.getJavaModelManager)1 BackingStoreException (org.osgi.service.prefs.BackingStoreException)1