use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project knime-core by knime.
the class WorkflowCoachPreferenceInitializer method initializeDefaultPreferences.
/**
* {@inheritDoc}
*/
@Override
public void initializeDefaultPreferences() {
IEclipsePreferences prefs = DefaultScope.INSTANCE.getNode(FrameworkUtil.getBundle(getClass()).getSymbolicName());
// disable the community recommendations by default (because the 'send_statistics'-property is disabled by default, too)
prefs.putBoolean(P_COMMUNITY_NODE_TRIPLE_PROVIDER, false);
prefs.putInt(P_AUTO_UPDATE_SCHEDULE, MONTHLY_UPDATE);
}
use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project knime-core by knime.
the class ProfileManagerTest method testVariablesReplacement.
/**
* Checks if variables in preference values are replaced correctly.
*
* @throws Exception if an error occurs
*/
@Test
public void testVariablesReplacement() throws Exception {
IEclipsePreferences prefs = DefaultScope.INSTANCE.getNode("org.knime.product");
String expectedEnv = System.getenv("USER");
assertThat("Unexpected value for environment variable", prefs.get("environment-variable", "XXX"), is(expectedEnv));
String expectedSysprop = System.getProperty("user.name");
assertThat("Unexpected value for system property", prefs.get("system-property", "XXX"), is(expectedSysprop));
assertThat("Unexpected value for profile name", prefs.get("profile-name", "XXX"), is("base"));
Path profileLocation = Paths.get(prefs.get("profile-location", "XXX"));
assertThat("Returned profile location " + profileLocation + " does not exist", Files.isDirectory(profileLocation), is(true));
assertThat("Unexpected value for custom variable", prefs.get("custom-variable", "XXX"), is("replaced-value"));
// unknown variables => no replacement
assertThat("Unexpected value for unknown environment variable", prefs.get("unknown-environment-variable", "XXX"), is("${env:unknown}"));
assertThat("Unexpected value for unknown system property", prefs.get("unknown-system-property", "XXX"), is("${sysprop:unknown}"));
assertThat("Unexpected value for unknown custom variable", prefs.get("unknown-custom-variable", "XXX"), is("${custom:unknown}"));
assertThat("Unexpected value for unknown profile variable", prefs.get("unknown-profile-variable", "XXX"), is("${profile:unknown}"));
// escaped "variable" (with $$) => no replacement
assertThat("Unexpected value for escaped variable", prefs.get("non-variable", "XXX"), is("bla/${custom:var}/foo"));
}
use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project knime-core by knime.
the class ProfileManagerTest method testAppliedPreferences.
/**
* Checks if preferences from two profiles have been applied correctly. The profiles are part of this fragment
* (test-profiles/base and test-profiles/custom).
*
* @throws Exception if an error occurs
*/
@Test
public void testAppliedPreferences() throws Exception {
IEclipsePreferences productPrefs = DefaultScope.INSTANCE.getNode("org.knime.product");
assertThat("Unexpected preferences value for 'test-pref'", productPrefs.get("test-pref", ""), is("custom"));
IEclipsePreferences workbenchPrefs = DefaultScope.INSTANCE.getNode("org.knime.workbench.ui");
assertThat("Unexpected preferences value", workbenchPrefs.get("knime.gridsize.x", ""), is("3333"));
assertThat("Unexpected preferences value", workbenchPrefs.get("knime.gridsize.y", ""), is("5555"));
}
use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project knime-core by knime.
the class RepositoryUpdater method processDefaultRepositories.
private void processDefaultRepositories(final IMetadataRepositoryManager repoManager, final URL usFileUrl) {
Set<URI> knownRepositories = new HashSet<>(Arrays.asList(repoManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_NON_LOCAL | IRepositoryManager.REPOSITORIES_DISABLED)));
IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(FrameworkUtil.getBundle(getClass()).getSymbolicName());
try (BufferedReader in = new BufferedReader(new InputStreamReader(usFileUrl.openStream()))) {
String line;
while ((line = in.readLine()) != null) {
if (line.startsWith("#") || line.trim().isEmpty()) {
continue;
}
String[] parts = line.split(",");
URI uri = new URI(parts[0]);
// preference key until 2.11
String oldPrefName = uri.toString();
// preference key since 2.12
String newPrefName = "us_info-" + uri;
// has re-added or removed an entry himself, we don't try it a second time
if ("remove".equals(parts[1]) && !preferences.getBoolean(oldPrefName + "-removed", false) && !preferences.getBoolean(newPrefName + "-removed", false)) {
repoManager.removeRepository(uri);
preferences.putBoolean(newPrefName + "-removed", true);
} else if ("add".equals(parts[1]) && (knownRepositories.isEmpty() || (!knownRepositories.contains(uri) && !preferences.getBoolean(oldPrefName + "-added", false) && !preferences.getBoolean(newPrefName + "-added", false)))) {
repoManager.addRepository(uri);
repoManager.setEnabled(uri, (parts.length > 2) && "enabled".equals(parts[2]));
if (parts.length > 3) {
repoManager.setRepositoryProperty(uri, IRepository.PROP_NAME, parts[3]);
}
preferences.putBoolean(newPrefName + "-added", true);
}
}
} catch (IOException | URISyntaxException ex) {
NodeLogger.getLogger(getClass()).error("Error while adding KNIME Update Sites: " + ex.getMessage(), ex);
}
}
Aggregations