@Override
  protected void performDefaults() {
    IEclipsePreferences prefs = LiferayDebugCore.getPrefs();
    prefs.remove(LiferayDebugCore.PREF_FM_DEBUG_PASSWORD);
    prefs.remove(LiferayDebugCore.PREF_FM_DEBUG_PORT);

    try {
      prefs.flush();
    } catch (BackingStoreException e) {
      LiferayDebugUI.logError(e);
    }

    super.performDefaults();
  }
  protected void updateProfilesWithName(String oldName, Profile newProfile, boolean applySettings) {
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (int i = 0; i < projects.length; i++) {
      IScopeContext projectScope = fPreferencesAccess.getProjectScope(projects[i]);
      IEclipsePreferences node = projectScope.getNode(JavaUI.ID_PLUGIN);
      String profileId = node.get(fProfileKey, null);
      if (oldName.equals(profileId)) {
        if (newProfile == null) {
          node.remove(fProfileKey);
        } else {
          if (applySettings) {
            writeToPreferenceStore(newProfile, projectScope);
          } else {
            node.put(fProfileKey, newProfile.getID());
          }
        }
      }
    }

    IScopeContext instanceScope = fPreferencesAccess.getInstanceScope();
    final IEclipsePreferences uiPrefs = instanceScope.getNode(JavaUI.ID_PLUGIN);
    if (newProfile != null && oldName.equals(uiPrefs.get(fProfileKey, null))) {
      writeToPreferenceStore(newProfile, instanceScope);
    }
  }
 @Override
 public void put(T element, String key, String value) throws Exception {
   IEclipsePreferences prefs = createPrefs(element);
   if (value == null) {
     prefs.remove(key);
   } else {
     prefs.put(key, value);
   }
   prefs.flush();
 }
  public void clearAllSettings(IScopeContext context) {
    for (int i = 0; i < fKeySets.length; i++) {
      updatePreferences(
          context.getNode(fKeySets[i].getNodeName()),
          fKeySets[i].getKeys(),
          Collections.<String, String>emptyMap());
    }

    final IEclipsePreferences uiPrefs = context.getNode(JavaUI.ID_PLUGIN);
    uiPrefs.remove(fProfileKey);
  }
 /*
  * Ensures that classpath problems are removed when a missing classpath variable is added through the preferences
  * (regression test for bug 109691 Importing preferences does not update classpath variables)
  */
 public void test12() throws CoreException {
   IEclipsePreferences preferences =
       JavaModelManager.getJavaModelManager().getInstancePreferences();
   try {
     IJavaProject project = createJavaProject("P", new String[0], new String[] {"TEST"}, "");
     waitForAutoBuild();
     preferences.put(
         JavaModelManager.CP_VARIABLE_PREFERENCES_PREFIX + "TEST", getExternalJCLPathString());
     assertMarkers("Unexpected markers", "", project);
   } finally {
     deleteProject("P");
     preferences.remove(JavaModelManager.CP_VARIABLE_PREFERENCES_PREFIX + "TEST");
   }
 }
  @Override
  protected void updateProfilesWithName(String oldName, Profile newProfile, boolean applySettings) {
    super.updateProfilesWithName(oldName, newProfile, applySettings);

    IEclipsePreferences node = fPreferencesAccess.getInstanceScope().getNode(JavaUI.ID_PLUGIN);
    String name = node.get(CleanUpConstants.CLEANUP_ON_SAVE_PROFILE, null);
    if (name != null && name.equals(oldName)) {
      if (newProfile == null) {
        node.remove(CleanUpConstants.CLEANUP_ON_SAVE_PROFILE);
      } else {
        node.put(CleanUpConstants.CLEANUP_ON_SAVE_PROFILE, newProfile.getID());
      }
    }
  }
 public void setOrderingConfig(OrderingConfig config) {
   orderingConfig = config;
   if (config == null) {
     store.remove(ORDERING_CONFIG);
   } else {
     store.put(ORDERING_CONFIG, config.toSaveString());
   }
   try {
     store.flush();
   } catch (BackingStoreException e) {
     GrailsCoreActivator.log(e);
   }
   notifyListeners(config);
 }
 @Override
 public void removePreferences(IEclipsePreferences preferences) {
   preferences.remove(pluginKey + separator + "enabled"); // $NON-NLS-1$
   preferences.remove(pluginKey + separator + "color"); // $NON-NLS-1$
   preferences.remove(pluginKey + separator + "bold"); // $NON-NLS-1$
   preferences.remove(pluginKey + separator + "italic"); // $NON-NLS-1$
   preferences.remove(pluginKey + separator + "underline"); // $NON-NLS-1$
   preferences.remove(pluginKey + separator + "strikethrough"); // $NON-NLS-1$
 }
예제 #9
0
  @Test
  public void testLinkToFolderWithDefaultSCM() throws Exception {
    // enable git autoinit for new projects
    IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(ServerConstants.PREFERENCE_SCOPE);
    String oldValue = prefs.get(ServerConstants.CONFIG_FILE_DEFAULT_SCM, null);
    prefs.put(ServerConstants.CONFIG_FILE_DEFAULT_SCM, "git");
    prefs.flush();

    try {
      // the same check as in
      // org.eclipse.orion.server.git.GitFileDecorator.initGitRepository(HttpServletRequest, IPath,
      // JSONObject)
      String scm = PreferenceHelper.getString(ServerConstants.CONFIG_FILE_DEFAULT_SCM, "");
      Assume.assumeTrue("git".equals(scm)); // $NON-NLS-1$

      URI workspaceLocation = createWorkspace(getMethodName());

      String contentLocation = new File(gitDir, "folder").getAbsolutePath();

      JSONObject newProject =
          createProjectOrLink(workspaceLocation, getMethodName() + "-link", contentLocation);
      String projectContentLocation = newProject.getString(ProtocolConstants.KEY_CONTENT_LOCATION);

      // http://<host>/file/<projectId>/
      WebRequest request = getGetFilesRequest(projectContentLocation);
      WebResponse response = webConversation.getResponse(request);
      assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
      JSONObject project = new JSONObject(response.getText());
      String childrenLocation = project.getString(ProtocolConstants.KEY_CHILDREN_LOCATION);
      assertNotNull(childrenLocation);

      // http://<host>/file/<projectId>/?depth=1
      request = getGetFilesRequest(childrenLocation);
      response = webConversation.getResponse(request);
      assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
      List<JSONObject> children = getDirectoryChildren(new JSONObject(response.getText()));
      String[] expectedChildren = new String[] {"folder.txt"}; // no .git even though auto-git is on
      assertEquals("Wrong number of directory children", expectedChildren.length, children.size());
      assertEquals(expectedChildren[0], children.get(0).getString(ProtocolConstants.KEY_NAME));
    } finally {
      // reset the preference we messed with for the test
      if (oldValue == null) prefs.remove(ServerConstants.CONFIG_FILE_DEFAULT_SCM);
      else prefs.put(ServerConstants.CONFIG_FILE_DEFAULT_SCM, oldValue);
      prefs.flush();
    }
  }
예제 #10
0
  /** Tests that we are not allowed to get metadata files */
  @Test
  public void testGetForbiddenFiles() throws IOException, SAXException, BackingStoreException {
    // enable global anonymous read
    IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(ServerConstants.PREFERENCE_SCOPE);
    String oldValue = prefs.get(ServerConstants.CONFIG_FILE_ANONYMOUS_READ, null);
    prefs.put(ServerConstants.CONFIG_FILE_ANONYMOUS_READ, "true");
    prefs.flush();
    try {
      // should not be allowed to get at file root
      WebRequest request = new GetMethodWebRequest(SERVER_LOCATION + FILE_SERVLET_LOCATION);
      setAuthentication(request);
      WebResponse response = webConversation.getResponse(request);
      assertEquals(
          "Should not be able to get the root",
          HttpURLConnection.HTTP_FORBIDDEN,
          response.getResponseCode());

      // should not be allowed to access the metadata directory
      request = new GetMethodWebRequest(SERVER_LOCATION + FILE_SERVLET_LOCATION + ".metadata");
      setAuthentication(request);
      response = webConversation.getResponse(request);
      assertEquals(
          "Should not be able to get metadata",
          HttpURLConnection.HTTP_FORBIDDEN,
          response.getResponseCode());

      // should not be allowed to read specific metadata files
      request =
          new GetMethodWebRequest(
              SERVER_LOCATION
                  + FILE_SERVLET_LOCATION
                  + ".metadata/.plugins/org.eclipse.orion.server.user.securestorage/user_store");
      setAuthentication(request);
      response = webConversation.getResponse(request);
      assertEquals(
          "Should not be able to get metadata",
          HttpURLConnection.HTTP_FORBIDDEN,
          response.getResponseCode());
    } finally {
      // reset the preference we messed with for the test
      if (oldValue == null) prefs.remove(ServerConstants.CONFIG_FILE_ANONYMOUS_READ);
      else prefs.put(ServerConstants.CONFIG_FILE_ANONYMOUS_READ, oldValue);
      prefs.flush();
    }
  }
예제 #11
0
 /**
  * Remove an option from the list of processor options.
  *
  * @param jproj a project, or null to remove the option workspace-wide.
  * @param key must be a nonempty string. It should only include the key; that is, it should not
  *     start with "-A".
  */
 public static void removeProcessorOption(IJavaProject jproj, String key) {
   if (key == null || key.length() < 1) {
     throw new IllegalArgumentException();
   }
   IScopeContext context =
       (null != jproj) ? new ProjectScope(jproj.getProject()) : InstanceScope.INSTANCE;
   IEclipsePreferences node =
       context.getNode(
           AptPlugin.PLUGIN_ID
               + "/"
               + //$NON-NLS-1$
               AptPreferenceConstants.APT_PROCESSOROPTIONS);
   node.remove(key);
   try {
     node.flush();
   } catch (BackingStoreException e) {
     AptPlugin.log(e, "Unable to save annotation processor option" + key); // $NON-NLS-1$
   }
 }
 private boolean updatePreferences(
     IEclipsePreferences prefs, List<String> keys, Map<String, String> profileOptions) {
   boolean hasChanges = false;
   for (final Iterator<String> keyIter = keys.iterator(); keyIter.hasNext(); ) {
     final String key = keyIter.next();
     final String oldVal = prefs.get(key, null);
     final String val = profileOptions.get(key);
     if (val == null) {
       if (oldVal != null) {
         prefs.remove(key);
         hasChanges = true;
       }
     } else if (!val.equals(oldVal)) {
       prefs.put(key, val);
       hasChanges = true;
     }
   }
   return hasChanges;
 }
 /**
  * @bug 131707: Cannot add classpath variables when starting with -pluginCustomization option
  * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=131707"
  */
 public void testBug131707() throws CoreException {
   IEclipsePreferences defaultPreferences = DefaultScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
   try {
     defaultPreferences.put(
         "org.eclipse.jdt.core.classpathVariable.MY_DEFAULT_LIB", "c:\\temp\\lib.jar");
     simulateExitRestart();
     String[] variableNames = JavaCore.getClasspathVariableNames();
     for (int i = 0, length = variableNames.length; i < length; i++) {
       if ("MY_DEFAULT_LIB".equals(variableNames[i])) {
         assertEquals(
             "Unexpected value for MY_DEFAULT_LIB",
             new Path("c:\\temp\\lib.jar"),
             JavaCore.getClasspathVariable("MY_DEFAULT_LIB"));
         return;
       }
     }
     assertFalse("Variable MY_DEFAULT_LIB not found", true);
   } finally {
     defaultPreferences.remove("org.eclipse.jdt.core.classpathVariable.MY_DEFAULT_LIB");
   }
 }
예제 #14
0
 @Override
 protected void doDelete(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   IEclipsePreferences node = getNode(req, resp, false);
   if (node == null) {
     // should not fail on delete when resource doesn't exist
     resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
     return;
   }
   String key = req.getParameter("key");
   try {
     // if a key is specified write that single value, otherwise write the entire node
     if (key != null) node.remove(key);
     else node.removeNode();
     prefRoot.flush();
     resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
   } catch (Exception e) {
     handleException(
         resp, NLS.bind("Failed to retrieve preferences for path {0}", req.getPathInfo()), e);
     return;
   }
 }
예제 #15
0
 public void setCharsetFor(IPath resourcePath, String newCharset) throws CoreException {
   // for the workspace root we just set a preference in the instance scope
   if (resourcePath.segmentCount() == 0) {
     IEclipsePreferences resourcesPreferences =
         InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES);
     if (newCharset != null) resourcesPreferences.put(ResourcesPlugin.PREF_ENCODING, newCharset);
     else resourcesPreferences.remove(ResourcesPlugin.PREF_ENCODING);
     try {
       resourcesPreferences.flush();
     } catch (BackingStoreException e) {
       IProject project = workspace.getRoot().getProject(resourcePath.segment(0));
       String message = Messages.resources_savingEncoding;
       throw new ResourceException(
           IResourceStatus.FAILED_SETTING_CHARSET, project.getFullPath(), message, e);
     }
     return;
   }
   // for all other cases, we set a property in the corresponding project
   IResource resource = workspace.getRoot().findMember(resourcePath);
   if (resource != null) {
     try {
       // disable the listener so we don't react to changes made by ourselves
       Preferences encodingSettings =
           getPreferences(
               resource.getProject(), true, resource.isDerived(IResource.CHECK_ANCESTORS));
       if (newCharset == null || newCharset.trim().length() == 0)
         encodingSettings.remove(getKeyFor(resourcePath));
       else encodingSettings.put(getKeyFor(resourcePath), newCharset);
       flushPreferences(encodingSettings, true);
     } catch (BackingStoreException e) {
       IProject project = workspace.getRoot().getProject(resourcePath.segment(0));
       String message = Messages.resources_savingEncoding;
       throw new ResourceException(
           IResourceStatus.FAILED_SETTING_CHARSET, project.getFullPath(), message, e);
     }
   }
 }
 private void setToDefault(String preference) {
   IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(HelpBasePlugin.PLUGIN_ID);
   prefs.remove(preference);
 }
 protected void removeProperty(String key) {
   eclipsePreferences.remove(DESIGNER_SETTINGS_PREFIX + key);
 }
예제 #18
0
 /**
  * TODO: this code is needed only for backwards compatibility with settings files previous to
  * 2005.11.13. At some point it should be removed. Delete the key that saves annotation processor
  * options as a single command-line-type string ("-Afoo=bar -Abaz=quux").
  */
 private static void removeOldStyleSettings(IScopeContext context) {
   IEclipsePreferences node = context.getNode(AptPlugin.PLUGIN_ID);
   node.remove(AptPreferenceConstants.APT_PROCESSOROPTIONS);
 }