use of org.osgi.service.prefs.BackingStoreException in project che by eclipse.
the class JavaProject method setOptions.
@Override
public void setOptions(Map newOptions) {
IEclipsePreferences projectPreferences = getEclipsePreferences();
if (projectPreferences == null)
return;
try {
if (newOptions == null) {
projectPreferences.clear();
} else {
Iterator entries = newOptions.entrySet().iterator();
JavaModelManager javaModelManager = getJavaModelManager();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
String key = (String) entry.getKey();
String value = (String) entry.getValue();
javaModelManager.storePreference(key, value, projectPreferences, newOptions);
}
// reset to default all options not in new map
// @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=26255
// @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49691
String[] pNames = projectPreferences.keys();
int ln = pNames.length;
for (int i = 0; i < ln; i++) {
String key = pNames[i];
if (!newOptions.containsKey(key)) {
// old preferences => remove from preferences table
projectPreferences.remove(key);
}
}
}
// persist options
projectPreferences.flush();
// flush cache immediately
try {
getPerProjectInfo().options = null;
} catch (JavaModelException e) {
// do nothing
}
} catch (BackingStoreException e) {
// problem with pref store - quietly ignore
}
}
use of org.osgi.service.prefs.BackingStoreException in project che by eclipse.
the class ChePreferences method loadProperties.
protected static Properties loadProperties(String location) throws BackingStoreException {
// if (DEBUG_PREFERENCE_GENERAL)
// PrefsMessages.message("Loading preferences from file: " + location); //$NON-NLS-1$
InputStream input = null;
Properties result = new Properties();
try {
input = new SafeFileInputStream(new File(location));
result.load(input);
} catch (FileNotFoundException e) {
// PrefsMessages.message("Preference file does not exist: " + location); //$NON-NLS-1$
return result;
} catch (IOException e) {
// log(new Status(IStatus.INFO, PrefsMessages.OWNER_NAME, IStatus.INFO, message, e));
throw new BackingStoreException(e.getMessage(), e);
} finally {
if (input != null)
try {
input.close();
} catch (IOException e) {
// ignore
}
}
return result;
}
use of org.osgi.service.prefs.BackingStoreException in project che by eclipse.
the class ChePreferences method write.
/*
* Helper method to persist a Properties object to the filesystem. We use this
* helper so we can remove the date/timestamp that Properties#store always
* puts in the file.
*/
protected static void write(Properties properties, String location) throws BackingStoreException {
// create the parent directories if they don't exist
// File parentFile = new File(location);
// if (parentFile == null)
// return;
// parentFile.mkdirs();
OutputStream output = null;
try {
File file = new File(location);
if (!file.exists()) {
File parentFile = file.getParentFile();
if (!parentFile.exists()) {
parentFile.mkdirs();
}
file.createNewFile();
}
output = new SafeFileOutputStream(file);
//$NON-NLS-1$
output.write(removeTimestampFromTable(properties).getBytes("UTF-8"));
output.flush();
} catch (IOException e) {
// String message = NLS.bind(PrefsMessages.preferences_saveException, location);
ResourcesPlugin.log(new Status(IStatus.ERROR, PrefsMessages.OWNER_NAME, IStatus.ERROR, "preferences_saveException", e));
throw new BackingStoreException("preferences_saveException");
} finally {
if (output != null)
try {
output.close();
} catch (IOException e) {
// ignore
}
}
}
use of org.osgi.service.prefs.BackingStoreException in project flux by eclipse.
the class Activator method removeConnectedProjectPreference.
private void removeConnectedProjectPreference(String projectName) {
IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(PLUGIN_ID);
String currentPreferences = preferences.get(CONNECTED_PROJECTS_ID, "");
String[] projects = StringUtils.split(currentPreferences, ";");
Collection<String> retainedProjects = new HashSet<String>();
for (String existingProjectName : projects) {
if (!existingProjectName.equals(projectName)) {
retainedProjects.add(existingProjectName);
}
}
String newPreferences = StringUtils.join(retainedProjects, ";");
preferences.put(CONNECTED_PROJECTS_ID, newPreferences);
try {
preferences.flush();
} catch (BackingStoreException e) {
// We really don't care that much..
}
}
use of org.osgi.service.prefs.BackingStoreException in project azure-tools-for-java by Microsoft.
the class ApplicationInsightsPreferences method savePreferences.
/**
* Stores application insights resources list
* in preference file in the form of byte array.
*/
private void savePreferences() {
try {
Preferences prefs = PluginUtil.getPrefs(PREF_FILE);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutput output = new ObjectOutputStream(buffer);
List<ApplicationInsightsResource> data = ApplicationInsightsResourceRegistry.getAppInsightsResrcList();
ApplicationInsightsResource[] dataArray = data.stream().filter(a -> !a.isImported()).sorted().toArray(ApplicationInsightsResource[]::new);
/*
* Sort list according to application insights resource name.
* Save only manually added resources
*/
try {
output.writeObject(dataArray);
} finally {
output.close();
}
prefs.putByteArray(PREF_KEY, buffer.toByteArray());
prefs.flush();
} catch (BackingStoreException e) {
Activator.getDefault().log(e.getMessage(), e);
} catch (IOException e) {
Activator.getDefault().log(e.getMessage(), e);
}
}
Aggregations