Search in sources :

Example 56 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project sling by apache.

the class ProjectUtil method setPathPersistentProperty.

private static void setPathPersistentProperty(IProject project, IPath path, String propertyName) {
    IScopeContext projectScope = new ProjectScope(project);
    IEclipsePreferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
    if (projectNode != null) {
        projectNode.put(propertyName, path.toPortableString());
        try {
            projectNode.flush();
        } catch (BackingStoreException e) {
            Activator.getDefault().getPluginLogger().error(e.getMessage(), e);
        }
    }
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException)

Example 57 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project eclipse.platform.text by eclipse.

the class FileDocumentProvider method getLineDelimiterPreference.

/**
 * Returns the default line delimiter preference for the given file.
 *
 * @param file the file
 * @return the default line delimiter
 * @since 3.1
 */
private String getLineDelimiterPreference(IFile file) {
    IScopeContext[] scopeContext;
    if (file != null && file.getProject() != null) {
        // project preference
        scopeContext = new IScopeContext[] { new ProjectScope(file.getProject()) };
        String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext);
        if (lineDelimiter != null)
            return lineDelimiter;
    }
    // workspace preference
    scopeContext = new IScopeContext[] { InstanceScope.INSTANCE };
    return Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext);
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext)

Example 58 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project linuxtools by eclipse.

the class GprofLaunchTest method setUp.

@Before
public void setUp() throws Exception {
    // $NON-NLS-1$
    proj = createProjectAndBuild(FrameworkUtil.getBundle(this.getClass()), "fibTest");
    ProjectScope ps = new ProjectScope(proj.getProject());
    ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps, ProviderProfileConstants.PLUGIN_ID);
    scoped.setSearchContexts(new IScopeContext[] { ps, InstanceScope.INSTANCE });
    scoped.setValue(ProviderProfileConstants.PREFS_KEY + GPROF_CATEGORY, GPROF_PROVIDER_ID);
    scoped.setValue(ProviderProfileConstants.USE_PROJECT_SETTINGS + GPROF_CATEGORY, true);
    scoped.save();
    IExtensionPoint extPoint = Platform.getExtensionRegistry().getExtensionPoint(LAUNCH_SHORT_EXTPT);
    IConfigurationElement[] configs = extPoint.getConfigurationElements();
    for (IConfigurationElement cfg : configs) {
        if (cfg.getAttribute("id").equals(ID)) {
            // $NON-NLS-1$
            try {
                // $NON-NLS-1$
                shortcut = (ProviderLaunchShortcut) cfg.createExecutableExtension("class");
                // $NON-NLS-1$
                launchConfigTypeId = cfg.getChildren("class")[0].getChildren("parameter")[1].getAttribute("value");
            } catch (Exception e) {
                fail(e.getMessage());
            }
        }
    }
    config = createConfiguration(proj.getProject());
    // (otherwise test hangs on 'enable GGprof support' dialogue. )
    enableGprofSupport();
    // ---- Continue with launch.
    launch = new Launch(config, ILaunchManager.PROFILE_MODE, null);
    wc = config.getWorkingCopy();
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Launch(org.eclipse.debug.core.Launch) ILaunch(org.eclipse.debug.core.ILaunch) ScopedPreferenceStore(org.eclipse.ui.preferences.ScopedPreferenceStore) CoreException(org.eclipse.core.runtime.CoreException) Before(org.junit.Before)

Example 59 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project linuxtools by eclipse.

the class GprofShortcutTest method setUp.

@Before
public void setUp() throws Exception {
    // $NON-NLS-1$
    proj = createProjectAndBuild(FrameworkUtil.getBundle(this.getClass()), "fibTest2");
    ProjectScope ps = new ProjectScope(proj.getProject());
    ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps, ProviderProfileConstants.PLUGIN_ID);
    scoped.setSearchContexts(new IScopeContext[] { ps, InstanceScope.INSTANCE });
    scoped.setValue(ProviderProfileConstants.PREFS_KEY + GPROF_CATEGORY, GPROF_PROVIDER_ID);
    scoped.setValue(ProviderProfileConstants.USE_PROJECT_SETTINGS + GPROF_CATEGORY, true);
    scoped.save();
    IExtensionPoint extPoint = Platform.getExtensionRegistry().getExtensionPoint(LAUNCH_SHORT_EXTPT);
    IConfigurationElement[] configs = extPoint.getConfigurationElements();
    for (IConfigurationElement cfg : configs) {
        if (cfg.getAttribute("id").equals(ID)) {
            // $NON-NLS-1$
            try {
                // $NON-NLS-1$
                shortcut = (ProviderLaunchShortcut) cfg.createExecutableExtension("class");
                // $NON-NLS-1$
                launchConfigTypeId = cfg.getChildren("class")[0].getChildren("parameter")[1].getAttribute("value");
            } catch (Exception e) {
                fail(e.getMessage());
            }
        }
    }
    config = createConfiguration(proj.getProject());
    launch = new Launch(config, ILaunchManager.PROFILE_MODE, null);
    wc = config.getWorkingCopy();
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Launch(org.eclipse.debug.core.Launch) ILaunch(org.eclipse.debug.core.ILaunch) ScopedPreferenceStore(org.eclipse.ui.preferences.ScopedPreferenceStore) CModelException(org.eclipse.cdt.core.model.CModelException) Before(org.junit.Before)

Example 60 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project linuxtools by eclipse.

the class ProviderFramework method getProviderIdToRun.

/**
 * Get a provider id to run for the given profiling type.
 *
 * This first checks for a provider in the project properties if the project
 * can be found and has indicated that project preferences are to override
 * the workspace preferences.  If no project is obtainable or the project
 * has not indicated override, then it looks at provider preferences.  If these
 * are not set or the specified preference points to a non-installed provider,
 * it will look for the provider with the highest priority for the specified type.
 * If this fails, it will look for the default provider.
 *
 * @param wc The launch configuration.
 * @param type A profiling type
 * @return A provider id that contributes to the specified type
 * @since 2.0
 */
public static String getProviderIdToRun(ILaunchConfigurationWorkingCopy wc, String type) {
    String providerId = null;
    // Look for a project first
    if (wc != null) {
        try {
            IResource[] resources = wc.getMappedResources();
            if (resources != null) {
                for (int i = 0; i < resources.length; ++i) {
                    IResource resource = resources[i];
                    if (resource instanceof IProject) {
                        IProject project = (IProject) resource;
                        ScopedPreferenceStore store = new ScopedPreferenceStore(new ProjectScope(project), ProviderProfileConstants.PLUGIN_ID);
                        boolean use_project_settings = store.getBoolean(ProviderProfileConstants.USE_PROJECT_SETTINGS + type);
                        if (use_project_settings) {
                            String provider = store.getString(ProviderProfileConstants.PREFS_KEY + type);
                            if (!provider.isEmpty())
                                providerId = provider;
                        }
                    }
                }
            }
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
    // if no providerId specified for project, get one from the preferences
    if (providerId == null) {
        // Look in the preferences for a provider
        providerId = ConfigurationScope.INSTANCE.getNode(ProviderProfileConstants.PLUGIN_ID).get(ProviderProfileConstants.PREFS_KEY + type, // $NON-NLS-1$
        "");
        if (providerId.isEmpty() || getConfigurationDelegateFromId(providerId) == null) {
            // Get highest priority provider
            providerId = getHighestProviderId(type);
        }
    }
    return providerId;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) CoreException(org.eclipse.core.runtime.CoreException) IResource(org.eclipse.core.resources.IResource) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IProject(org.eclipse.core.resources.IProject) ScopedPreferenceStore(org.eclipse.ui.preferences.ScopedPreferenceStore)

Aggregations

ProjectScope (org.eclipse.core.resources.ProjectScope)92 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)42 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)31 IProject (org.eclipse.core.resources.IProject)28 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)24 Preferences (org.osgi.service.prefs.Preferences)18 DefaultScope (org.eclipse.core.runtime.preferences.DefaultScope)17 BackingStoreException (org.osgi.service.prefs.BackingStoreException)17 ScopedPreferenceStore (org.eclipse.ui.preferences.ScopedPreferenceStore)11 IFile (org.eclipse.core.resources.IFile)9 IResource (org.eclipse.core.resources.IResource)9 CoreException (org.eclipse.core.runtime.CoreException)8 IAdaptable (org.eclipse.core.runtime.IAdaptable)5 IPath (org.eclipse.core.runtime.IPath)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 Path (org.eclipse.core.runtime.Path)4 Test (org.junit.Test)4 File (java.io.File)3