Search in sources :

Example 16 with BackingStoreException

use of org.osgi.service.prefs.BackingStoreException in project che by eclipse.

the class JavaProject method setOption.

@Override
public void setOption(String optionName, String optionValue) {
    // Store option value
    IEclipsePreferences projectPreferences = getEclipsePreferences();
    boolean modified = getJavaModelManager().storePreference(optionName, optionValue, projectPreferences, null);
    // Write changes
    if (modified) {
        try {
            projectPreferences.flush();
        } catch (BackingStoreException e) {
        // problem with pref store - quietly ignore
        }
    }
    getJavaModelManager().resetProjectOptions(JavaProject.this);
    // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=233568
    JavaProject.this.resetCaches();
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException)

Example 17 with BackingStoreException

use of org.osgi.service.prefs.BackingStoreException 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)

Example 18 with BackingStoreException

use of org.osgi.service.prefs.BackingStoreException in project cubrid-manager by CUBRID.

the class PersistUtils method saveXMLMemento.

/**
	 * 
	 * Save the xml content to instance scope preference
	 * 
	 * @param pluginId String
	 * @param key String
	 * @param memento XMLMemento
	 */
public static void saveXMLMemento(String pluginId, String key, XMLMemento memento) {
    String xmlString = null;
    try {
        xmlString = memento.saveToString();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    IEclipsePreferences preference = PersistUtils.getPreference(pluginId);
    try {
        preference.put(key, xmlString);
        preference.flush();
    } catch (BackingStoreException e) {
        preference = null;
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException) IOException(java.io.IOException)

Example 19 with BackingStoreException

use of org.osgi.service.prefs.BackingStoreException in project dbeaver by serge-rider.

the class BundlePreferenceStore method save.

@Override
public void save() throws IOException {
    try {
        props.flush();
        defaultProps.flush();
    } catch (BackingStoreException e) {
        throw new IOException(e);
    }
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) IOException(java.io.IOException)

Example 20 with BackingStoreException

use of org.osgi.service.prefs.BackingStoreException in project cubrid-manager by CUBRID.

the class CubridStatusMonitorInstance method removeSetting.

/**
	 * Remove the info of StatusMonInstanceData relevant to key from preference
	 * 
	 * @param key the key relevant to saving instance of StatusMonInstanceData
	 */
public void removeSetting(String key) {
    synchronized (this) {
        IEclipsePreferences preference = new InstanceScope().getNode(CubridManagerUIPlugin.PLUGIN_ID);
        preference.remove(key);
        try {
            preference.flush();
        } catch (BackingStoreException ex) {
            LOGGER.error(ex.getMessage());
        }
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) BackingStoreException(org.osgi.service.prefs.BackingStoreException)

Aggregations

BackingStoreException (org.osgi.service.prefs.BackingStoreException)27 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)13 Preferences (org.osgi.service.prefs.Preferences)8 IOException (java.io.IOException)6 ProjectScope (org.eclipse.core.resources.ProjectScope)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)2 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 JavaModelManager.getJavaModelManager (org.eclipse.jdt.internal.core.JavaModelManager.getJavaModelManager)2 Inject (com.google.inject.Inject)1 ApplicationInsightsResource (com.microsoft.applicationinsights.preference.ApplicationInsightsResource)1 FileNotFoundException (java.io.FileNotFoundException)1