Search in sources :

Example 76 with IEclipsePreferences

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);
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences)

Example 77 with IEclipsePreferences

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"));
}
Also used : Path(java.nio.file.Path) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 78 with IEclipsePreferences

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"));
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Test(org.junit.Test)

Example 79 with IEclipsePreferences

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HashSet(java.util.HashSet)

Aggregations

IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)79 BackingStoreException (org.osgi.service.prefs.BackingStoreException)15 Test (org.junit.Test)11 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)9 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)9 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)6 ProjectScope (org.eclipse.core.resources.ProjectScope)6 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)6 After (org.junit.After)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Iterator (java.util.Iterator)4 Map (java.util.Map)4 XMLMemento (com.cubrid.cubridmanager.core.common.xml.XMLMemento)3 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2