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);
    }
  }
Ejemplo n.º 2
0
  public WorkspaceLanguageConfiguration decodeWorkspaceMappings() throws CoreException {
    IEclipsePreferences node = InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID);
    IEclipsePreferences defaultNode = DefaultScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID);
    String encodedMappings = node.get(CCorePreferenceConstants.WORKSPACE_LANGUAGE_MAPPINGS, null);
    if (encodedMappings == null) {
      encodedMappings = defaultNode.get(CCorePreferenceConstants.WORKSPACE_LANGUAGE_MAPPINGS, null);
    }
    WorkspaceLanguageConfiguration config = new WorkspaceLanguageConfiguration();

    if (encodedMappings == null || encodedMappings.length() == 0) {
      return config;
    }

    // The mappings are encoded as XML in a String so we need to parse it.
    InputSource input = new InputSource(new StringReader(encodedMappings));
    try {
      Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(input);
      config.setWorkspaceMappings(decodeContentTypeMappings(document.getDocumentElement()));
      return config;
    } catch (SAXException e) {
      throw new CoreException(Util.createStatus(e));
    } catch (IOException e) {
      throw new CoreException(Util.createStatus(e));
    } catch (ParserConfigurationException e) {
      throw new CoreException(Util.createStatus(e));
    }
  }
Ejemplo n.º 3
0
 public void load(final IEclipsePreferences root) throws BackingStoreException {
   output = new Path(root.get(ProjectPreferencesConstants.OUTPUT, "ebin"));
   requiredRuntimeVersion =
       new RuntimeVersion(root.get(ProjectPreferencesConstants.REQUIRED_BACKEND_VERSION, null));
   includes = PathSerializer.unpackList(root.get(ProjectPreferencesConstants.INCLUDES, ""));
   final Preferences srcNode = root.node(ProjectPreferencesConstants.SOURCES);
   sources.clear();
   for (final String src : srcNode.childrenNames()) {
     final IEclipsePreferences sn = (IEclipsePreferences) srcNode.node(src);
     final SourceLocation loc = new SourceLocation(sn);
     sources.add(loc);
   }
 }
Ejemplo n.º 4
0
  /**
   * Check if model version is changed and rebuild PHP projects if necessary.
   *
   * @see PHPCoreConstants.STRUCTURE_VERSION
   */
  private void rebuildProjects() {
    IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(ID);
    String modelVersion = preferences.get(PHPCoreConstants.STRUCTURE_VERSION_PREFERENCE, null);
    if (PHPCoreConstants.STRUCTURE_VERSION.equals(modelVersion)) {
      return;
    }

    preferences.put(
        PHPCoreConstants.STRUCTURE_VERSION_PREFERENCE, PHPCoreConstants.STRUCTURE_VERSION);
    try {
      preferences.flush();
    } catch (BackingStoreException e1) {
      Logger.logException(e1);
    }

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject[] projects = workspace.getRoot().getProjects();
    if (workspace.isAutoBuilding()) {
      try {
        for (IProject project : projects) {
          if (PHPToolkitUtil.isPhpProject(project)) {
            project.build(IncrementalProjectBuilder.CLEAN_BUILD, null);
          }
        }
      } catch (CoreException e) {
        Logger.logException(e);
      }
    }
  }
Ejemplo n.º 5
0
 /** Serializes a preference node as a JSON object. */
 private JSONObject toJSON(HttpServletRequest req, IEclipsePreferences node)
     throws JSONException, BackingStoreException {
   JSONObject result = new JSONObject();
   // TODO Do we need this extra information?
   //		String nodePath = node.absolutePath();
   //		result.put("path", nodePath);
   //		JSONObject children = new JSONObject();
   //		for (String child : node.childrenNames())
   //			children.put(child, createQuery(req, "/prefs" + nodePath + '/' + child));
   //		result.put("children", children);
   //		JSONObject values = new JSONObject();
   for (String key : node.keys()) {
     String valueString = node.get(key, null);
     Object value = null;
     if (valueString != null) {
       try {
         // value might be serialized JSON
         value = new JSONObject(valueString);
       } catch (JSONException e) {
         // value must be a string
         value = valueString;
       }
     }
     result.put(key, value);
   }
   return result;
 }
Ejemplo n.º 6
0
 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   traceRequest(req);
   IEclipsePreferences node = getNode(req, resp, false);
   if (node == null) return;
   String key = req.getParameter("key");
   try {
     // if a key is specified write that single value, otherwise write the entire node
     JSONObject result = null;
     if (key != null) {
       String value = node.get(key, null);
       if (value == null) {
         handleNotFound(req, resp, HttpServletResponse.SC_NOT_FOUND);
         return;
       }
       result = new JSONObject().put(key, value);
     } else result = toJSON(req, node);
     writeJSONResponse(req, resp, result);
   } catch (Exception e) {
     handleException(
         resp, NLS.bind("Failed to retrieve preferences for path {0}", req.getPathInfo()), e);
     return;
   }
 }
Ejemplo n.º 7
0
  public static String getBuildTime(IProject project) {

    // If exists in prefs, add them
    IEclipsePreferences node =
        new InstanceScope().getNode(net.bioclipse.qsar.ui.Activator.PLUGIN_ID);
    return node.get(project.getName() + "_time", "N/A");
  }
Ejemplo n.º 8
0
  private void PreProcessing(String projectName) {
    IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(Constants.BUNDLE_NAME);
    String fileName = prefs.get("LTiEFileName", null);
    java.io.File f = new java.io.File(fileName + projectName + ".MTD");
    if (!f.exists()) {
      String id = "default";
      String UNCTime;
      Calendar calendar = Calendar.getInstance();
      if (fileName != null) {
        int index = fileName.indexOf('_');
        int index2 = fileName.indexOf('_', index + 1);
        UNCTime = fileName.substring(index2 + 1, fileName.length() - 1);
        id = fileName.substring(index + 1, index2);
        calendar.setTimeInMillis(Long.parseLong(UNCTime));
      }

      try {
        PrintStream p = new PrintStream(f);
        p.print(CreateStartOfSessionString(calendar, id, projectName));
        p.close();
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      }
    }
  }
Ejemplo n.º 9
0
 public String getGroovyCompilerLevel(IProject project) {
   IEclipsePreferences projectPreferences = getProjectScope(project);
   if (projectPreferences != null) {
     return projectPreferences.get(GROOVY_COMPILER_LEVEL, null);
   } else {
     return null;
   }
 }
Ejemplo n.º 10
0
  protected void init() {
    prefs = ConfigurationScope.INSTANCE.getNode("org.bbaw.bts.ui.corpus");
    IEclipsePreferences defaultpref = DefaultScope.INSTANCE.getNode("org.bbaw.bts.ui.corpus");

    default_visibility = prefs.get(BTSCorpusConstants.PREF_LEMMA_DEFAULT_VISIBILITY, null);
    default_reviewState = prefs.get(BTSCorpusConstants.PREF_LEMMA_DEFAULT_REVIEWSTATE, null);

    object = BtsCorpusModelFactory.eINSTANCE.createBTSTCObject();
    object.setVisibility(default_visibility);
    object.setRevisionState(default_reviewState);

    DataBindingContext bindingContext = new DataBindingContext();

    // visibility
    EMFUpdateValueStrategy targetToModel_vis = new EMFUpdateValueStrategy();
    targetToModel_vis.setConverter(new BTSConfigItemToStringConverter());
    EMFUpdateValueStrategy modelToTarget_vis = new EMFUpdateValueStrategy();
    modelToTarget_vis.setConverter(new BTSStringToConfigItemConverter(visibility_viewer));
    IObservableValue target_vis_viewer =
        ViewersObservables.observeSingleSelection(visibility_viewer);
    Binding binding_vis =
        bindingContext.bindValue(
            target_vis_viewer,
            EMFProperties.value(BtsmodelPackage.Literals.ADMINISTRATIV_DATA_OBJECT__VISIBILITY)
                .observe(object),
            targetToModel_vis,
            modelToTarget_vis);

    // review status
    EMFUpdateValueStrategy targetToModel_rev = new EMFUpdateValueStrategy();
    targetToModel_rev.setConverter(new BTSConfigItemToStringConverter());
    EMFUpdateValueStrategy modelToTarget_rev = new EMFUpdateValueStrategy();
    modelToTarget_rev.setConverter(new BTSStringToConfigItemConverter(reviewState_viewer));
    IObservableValue target_rev_viewer =
        ViewersObservables.observeSingleSelection(reviewState_viewer);
    Binding binding_rev =
        bindingContext.bindValue(
            target_rev_viewer,
            EMFProperties.value(BtsmodelPackage.Literals.ADMINISTRATIV_DATA_OBJECT__REVISION_STATE)
                .observe(object),
            targetToModel_rev,
            modelToTarget_rev);
    super.initialize();
  }
  /** Loads combo choices fromt he platform and from PDE core preferences */
  private void initializeChoices() {
    IEclipsePreferences node = new InstanceScope().getNode(PDECore.PLUGIN_ID);

    fOSChoices = new TreeSet<String>();
    String[] os = Platform.knownOSValues();
    for (int i = 0; i < os.length; i++) {
      fOSChoices.add(os[i]);
    }
    String pref = node.get(ICoreConstants.OS_EXTRA, EMPTY_STRING);
    if (!EMPTY_STRING.equals(pref)) {
      addExtraChoices(fOSChoices, pref);
    }

    fWSChoices = new TreeSet<String>();
    String[] ws = Platform.knownWSValues();
    for (int i = 0; i < ws.length; i++) {
      fWSChoices.add(ws[i]);
    }
    pref = node.get(ICoreConstants.WS_EXTRA, EMPTY_STRING);
    if (!EMPTY_STRING.equals(pref)) {
      addExtraChoices(fWSChoices, pref);
    }

    fArchChoices = new TreeSet<String>();
    String[] arch = Platform.knownOSArchValues();
    for (int i = 0; i < arch.length; i++) {
      fArchChoices.add(arch[i]);
    }
    pref = node.get(ICoreConstants.ARCH_EXTRA, EMPTY_STRING);
    if (!EMPTY_STRING.equals(pref)) {
      addExtraChoices(fArchChoices, pref);
    }

    fNLChoices = new TreeSet<String>();
    String[] nl = LocaleUtil.getLocales();
    for (int i = 0; i < nl.length; i++) {
      fNLChoices.add(nl[i]);
    }
    pref = node.get(ICoreConstants.NL_EXTRA, EMPTY_STRING);
    if (!EMPTY_STRING.equals(pref)) {
      addExtraChoices(fNLChoices, pref);
    }
  }
 /*
  * Ensures that a classpath variable is removed from the preferences if set to null
  * (regression test for bug 98720 [preferences] classpath variables are not exported if the session is closed and restored)
  */
 public void test11() throws CoreException {
   JavaCore.setClasspathVariable("TEST", new Path("testing"), null);
   JavaCore.removeClasspathVariable("TEST", null);
   JavaModelManager manager = JavaModelManager.getJavaModelManager();
   IEclipsePreferences preferences = manager.getInstancePreferences();
   assertEquals(
       "Should not find variable TEST in preferences",
       "null",
       preferences.get(JavaModelManager.CP_VARIABLE_PREFERENCES_PREFIX + "TEST", "null"));
 }
Ejemplo n.º 13
0
  private static String getRepoURL() {
    IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(ProjectCore.PLUGIN_ID);

    String repoURL = prefs.get(BLADE_CLI_REPO_URL, defaultRepoUrl);

    if (!repoURL.endsWith("/")) {
      repoURL = repoURL + "/";
    }

    return repoURL;
  }
Ejemplo n.º 14
0
 public List<String> getListStringPreference(
     IEclipsePreferences preferences, String key, String def) {
   if (preferences == null) {
     preferences = getProjectOrWorkspacePreferences(null);
   }
   String result = preferences.get(key, def);
   if (result == null) {
     result = "";
   }
   String[] splits = result.split(",");
   return Arrays.asList(splits);
 }
Ejemplo n.º 15
0
 public OrderingConfig getOrderingConfig() {
   if (orderingConfig == null) {
     // Try to read a stored config
     String encoded = store.get(ORDERING_CONFIG, (String) null);
     if (encoded != null) {
       orderingConfig = OrderingConfig.fromSaveString(encoded);
     } else {
       orderingConfig = OrderingConfig.DEFAULT;
     }
   }
   return orderingConfig;
 }
Ejemplo n.º 16
0
 private static void setBoolean(IJavaProject jproject, String optionName, boolean value) {
   IScopeContext context =
       (null != jproject) ? new ProjectScope(jproject.getProject()) : InstanceScope.INSTANCE;
   IEclipsePreferences node = context.getNode(AptPlugin.PLUGIN_ID);
   // get old val as a String, so it can be null if setting doesn't exist yet
   String oldValue = node.get(optionName, null);
   node.putBoolean(optionName, value);
   if (jproject != null && oldValue == null || (value != Boolean.parseBoolean(oldValue))) {
     AptProject aproj = AptPlugin.getAptProject(jproject);
     aproj.preferenceChanged(optionName);
   }
   flushPreference(optionName, node);
 }
  @SuppressWarnings({"unchecked", "rawtypes"})
  private void setupOptions() {

    options = new HashMap(PHPCorePlugin.getOptions());

    IScopeContext[] contents =
        new IScopeContext[] {
          new ProjectScope(type.getScriptProject().getProject()),
          InstanceScope.INSTANCE,
          DefaultScope.INSTANCE
        };

    for (int i = 0; i < contents.length; i++) {

      IScopeContext scopeContext = contents[i];
      IEclipsePreferences inode = scopeContext.getNode(PHPCorePlugin.ID);

      if (inode != null) {

        if (!options.containsKey(PHPCoreConstants.FORMATTER_USE_TABS)) {

          String useTabs = inode.get(PHPCoreConstants.FORMATTER_USE_TABS, null);
          if (useTabs != null) {
            options.put(PHPCoreConstants.FORMATTER_USE_TABS, useTabs);
          }
        }

        if (!options.containsKey(PHPCoreConstants.FORMATTER_INDENTATION_SIZE)) {

          String size = inode.get(PHPCoreConstants.FORMATTER_INDENTATION_SIZE, null);

          if (size != null) {
            options.put(PHPCoreConstants.FORMATTER_INDENTATION_SIZE, size);
          }
        }
      }
    }
  }
  public void testBug100393b() throws CoreException, BackingStoreException {
    // Get JavaCore default preferences
    JavaModelManager manager = JavaModelManager.getJavaModelManager();
    IEclipsePreferences preferences = manager.getDefaultPreferences();

    // verify that JavaCore default preferences for modified options
    assertEquals(
        "Invalid default for " + JavaCore.COMPILER_PB_UNUSED_LOCAL,
        "warning",
        preferences.get(JavaCore.COMPILER_PB_UNUSED_LOCAL, "null"));
    assertEquals(
        "Invalid default for " + JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER,
        "warning",
        preferences.get(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, "null"));
    assertEquals(
        "Invalid default for " + JavaCore.COMPILER_PB_FIELD_HIDING,
        "ignore",
        preferences.get(JavaCore.COMPILER_PB_FIELD_HIDING, "null"));
    assertEquals(
        "Invalid default for " + JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING,
        "ignore",
        preferences.get(JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING, "null"));
  }
 public static boolean hasProjectSpecificSettings(IScopeContext context, KeySet[] keySets) {
   for (int i = 0; i < keySets.length; i++) {
     KeySet keySet = keySets[i];
     IEclipsePreferences preferences = context.getNode(keySet.getNodeName());
     for (final Iterator<String> keyIter = keySet.getKeys().iterator(); keyIter.hasNext(); ) {
       final String key = keyIter.next();
       Object val = preferences.get(key, null);
       if (val != null) {
         return true;
       }
     }
   }
   return false;
 }
  @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());
      }
    }
  }
 /**
  * @param uiPrefs
  * @param allOptions
  */
 private void addAll(IEclipsePreferences uiPrefs, Map<String, String> allOptions) {
   try {
     String[] keys = uiPrefs.keys();
     for (int i = 0; i < keys.length; i++) {
       String key = keys[i];
       String val = uiPrefs.get(key, null);
       if (val != null) {
         allOptions.put(key, val);
       }
     }
   } catch (BackingStoreException e) {
     // ignore
   }
 }
Ejemplo n.º 22
0
 public void buildFinished(IJavaProject project) {
   try {
     StringBuilder sb = new StringBuilder();
     PreProcessing(project.getElementName());
     IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(Constants.BUNDLE_NAME);
     String fileName =
         prefs.get("LTiEFileName", "Empty String") + project.getElementName() + ".MTD";
     sb.append("<COMPILE_INSTANCE>");
     Calendar c = Calendar.getInstance();
     SimpleDateFormat format = new SimpleDateFormat("EEE, MMM d, yyyy 'at' HH:mm:ss z");
     sb.append(
         "<TIME UTC=\"" + c.getTimeInMillis() + "\">" + format.format(c.getTime()) + "</TIME>");
     IPackageFragment[] packages = project.getPackageFragments();
     sb.append("<PACKAGES>");
     for (IPackageFragment aPackage : packages) {
       if (aPackage.getKind() == IPackageFragmentRoot.K_SOURCE) {
         String packageName =
             aPackage.getElementName().isEmpty() ? "default" : aPackage.getElementName();
         Constants.writer.println("Package Fragment Name: " + packageName);
         sb.append("<PACKAGE>");
         sb.append("<NAME>" + packageName + "</NAME>");
         sb.append("<FILES>");
         for (ICompilationUnit unit : aPackage.getCompilationUnits()) {
           sb.append("<FILE>");
           sb.append("<NAME>" + unit.getElementName() + "</NAME>");
           printFileInternals(unit, sb);
           printFilesProblems(unit, sb);
           sb.append("<SOURCE>" + StringEscapeUtils.escapeHtml4(unit.getSource()) + "</SOURCE>");
           sb.append("</FILE>");
         }
         ProcessUMLFiles(aPackage.getNonJavaResources(), sb);
         sb.append("</FILES>");
         sb.append("</PACKAGE>");
       }
     }
     sb.append("</PACKAGES>");
     Object[] nonJavaResources = project.getNonJavaResources();
     if (nonJavaResources != null && nonJavaResources.length > 0) {
       sb.append("<FILES>");
       ProcessUMLFiles(nonJavaResources, sb);
       sb.append("</FILES>");
     }
     sb.append("</COMPILE_INSTANCE>");
     PrintWriter out = new PrintWriter(new FileWriter(fileName, true));
     out.write(XMLFormatter.format(sb.toString()));
     out.close();
   } catch (Exception e) {
     e.printStackTrace(Constants.writer);
   }
 }
  public void select() {
    final String directory =
        _preferencesStore.get(_preferencesString, Utilities.getWorkingDirectory());

    final Shell shell = new Shell(Display.getDefault());
    DirectoryDialog dialog = new DirectoryDialog(shell, SWT.MULTI);
    dialog.setFilterPath(directory);
    dialog.setText("Save JavaSeis Volume(s)");
    String rtn = dialog.open();
    if (rtn != null) {
      _preferencesStore.put(_preferencesString, rtn);
      PreferencesUtil.saveInstanceScopePreferences(ServiceComponent.PLUGIN_ID);
    }
  }
  protected void createProjectSettings(IProject project, String containerPath, String consolePath)
      throws BackingStoreException {

    IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(SymfonyCorePlugin.ID);
    String executable = preferences.get(Keys.PHP_EXECUTABLE, null);
    IEclipsePreferences node = new ProjectScope(project).getNode(SymfonyCorePlugin.ID);
    if (executable != null) {
      node.put(Keys.PHP_EXECUTABLE, executable);
      Logger.log(Logger.WARNING, "Executable not found!");
    }
    node.put(Keys.CONSOLE, consolePath);
    node.put(Keys.USE_PROJECT_PHAR, Boolean.FALSE.toString());
    node.put(Keys.DUMPED_CONTAINER, containerPath);
    node.flush();
  }
  @Test
  public void testGetPrefferedImplByDescriptorID() {

    IEclipsePreferences prefs = new DefaultScope().getNode(Activator.PLUGIN_ID);
    assertNotNull(prefs);
    String prefsString = prefs.get(QSARConstants.QSAR_PROVIDERS_ORDER_PREFERENCE, null);
    assertNotNull(prefsString);

    System.out.println("Got prefs string: " + prefsString);

    DescriptorImpl impl = qsar.getPreferredImpl(chiChainID);
    assertNotNull(impl);
    System.out.println("pref impl: " + impl.getId());
    //		assertEquals("net.bioclipse.qsar.test.descriptor2", impl.getId());
    System.out.println("wee");
  }
Ejemplo n.º 26
0
 private static void setString(IJavaProject jproject, String optionName, String value) {
   IScopeContext context =
       (null != jproject) ? new ProjectScope(jproject.getProject()) : InstanceScope.INSTANCE;
   IEclipsePreferences node;
   if (AptPreferenceConstants.APT_PROCESSANNOTATIONS.equals(optionName)) {
     node = context.getNode(JavaCore.PLUGIN_ID);
   } else {
     node = context.getNode(AptPlugin.PLUGIN_ID);
   }
   String oldValue = node.get(optionName, null);
   node.put(optionName, value);
   if (jproject != null && !value.equals(oldValue)) {
     AptProject aproj = AptPlugin.getAptProject(jproject);
     aproj.preferenceChanged(optionName);
   }
   flushPreference(optionName, node);
 }
Ejemplo n.º 27
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();
    }
  }
Ejemplo n.º 28
0
  /**
   * Get the options that are presented to annotation processors by the
   * AnnotationProcessorEnvironment. The -A and = are stripped out, so (key, value) is the
   * equivalent of -Akey=value.
   *
   * <p>This method differs from getProcessorOptions in that the options returned by this method do
   * NOT include any programmatically set options. This method returns only the options that are
   * persisted to the preference store and that are displayed in the configuration GUI.
   *
   * @param jproj a project, or null to query the workspace-wide setting. If jproj is not null, but
   *     the project has no per-project settings, this method will fall back to the workspace-wide
   *     settings.
   * @return a mutable, possibly empty, map of (key, value) pairs. The value part of a pair may be
   *     null (equivalent to "-Akey"). The value part can contain spaces, if it is quoted:
   *     -Afoo="bar baz".
   */
  public static Map<String, String> getRawProcessorOptions(IJavaProject jproj) {
    Map<String, String> options = new HashMap<String, String>();

    // TODO: this code is needed only for backwards compatibility with
    // settings files previous to 2005.11.13.  At some point it should be
    // removed.
    // If an old-style setting exists, add it into the mix for backward
    // compatibility.
    options.putAll(getOldStyleRawProcessorOptions(jproj));

    // Fall back from project to workspace scope on an all-or-nothing basis,
    // not value by value.  (Never fall back to default scope; there are no
    // default processor options.)  We can't use IPreferencesService for this
    // as we would normally do, because we don't know the names of the keys.
    IScopeContext[] contexts;
    if (jproj != null) {
      contexts = new IScopeContext[] {new ProjectScope(jproj.getProject()), InstanceScope.INSTANCE};
    } else {
      contexts = new IScopeContext[] {InstanceScope.INSTANCE};
    }
    for (IScopeContext context : contexts) {
      IEclipsePreferences prefs = context.getNode(AptPlugin.PLUGIN_ID);
      try {
        if (prefs.childrenNames().length > 0) {
          IEclipsePreferences procOptionsNode =
              context.getNode(
                  AptPlugin.PLUGIN_ID
                      + "/"
                      + AptPreferenceConstants.APT_PROCESSOROPTIONS); // $NON-NLS-1$
          if (procOptionsNode != null) {
            for (String key : procOptionsNode.keys()) {
              String nonNullVal = procOptionsNode.get(key, null);
              String val =
                  AptPreferenceConstants.APT_NULLVALUE.equals(nonNullVal) ? null : nonNullVal;
              options.put(key, val);
            }
            break;
          }
        }
      } catch (BackingStoreException e) {
        AptPlugin.log(e, "Unable to load annotation processor options"); // $NON-NLS-1$
      }
    }
    return options;
  }
Ejemplo n.º 29
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();
    }
  }
 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;
 }