Java Code Examples for org.eclipse.core.resources.ProjectScope

The following examples show how to use org.eclipse.core.resources.ProjectScope. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: eclipse   Source File: BazelProjectSupport.java    License: Apache License 2.0 6 votes vote down vote up
private static void addSettings(IProject project, String workspaceRoot, List<String> targets,
    List<String> buildFlags) throws BackingStoreException {
  IScopeContext projectScope = new ProjectScope(project);
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  int i = 0;
  for (String target : targets) {
    projectNode.put("target" + i, target);
    i++;
  }
  projectNode.put("workspaceRoot", workspaceRoot);
  i = 0;
  for (String flag : buildFlags) {
    projectNode.put("buildFlag" + i, flag);
    i++;
  }
  projectNode.flush();
}
 
Example 2
@Test
public void testProjectSavedInPreferencesSelected()
    throws ProjectRepositoryException, InterruptedException, BackingStoreException {
  IEclipsePreferences node =
      new ProjectScope(project).getNode(DeployPreferences.PREFERENCE_STORE_QUALIFIER);
  try {
    node.put("project.id", "projectId1");
    node.put("account.email", EMAIL_1);
    model = new DeployPreferences(project);

    initializeProjectRepository();
    when(loginService.getAccounts()).thenReturn(twoAccountSet);
    deployPanel = createPanel(true /* requireValues */);
    deployPanel.latestGcpProjectQueryJob.join();

    ProjectSelector projectSelector = getProjectSelector();
    IStructuredSelection selection = projectSelector.getViewer().getStructuredSelection();
    assertThat(selection.size(), is(1));
    assertThat(((GcpProject) selection.getFirstElement()).getId(), is("projectId1"));
  } finally {
    node.clear();
  }
}
 
Example 3
/**
 * Switches the search scope of the preference store to use [Project, Instance, Configuration] if values are project
 * specific, and [Instance, Configuration] otherwise. This implementation requires that the given preference store
 * is based on the Project preference store when the page is used as a Properties page. (This is done in
 * {@link #doGetPreferenceStore()}).
 */
@SuppressWarnings("deprecation")
private void handleUseProjectSettings() {
	// Note: uses the pre Eclipse 3.6 way of specifying search scopes (deprecated since 3.6)
	boolean isUseProjectSettings = useProjectSettingsButton.getSelection();
	link.setEnabled(!isUseProjectSettings);
	if (!isUseProjectSettings) {
		((FixedScopedPreferenceStore) getPreferenceStore()).setSearchContexts(new IScopeContext[] {
				new InstanceScope(), new ConfigurationScope() });
	} else {
		((FixedScopedPreferenceStore) getPreferenceStore()).setSearchContexts(new IScopeContext[] {
				new ProjectScope(currentProject()), new InstanceScope(), new ConfigurationScope() });
		setProjectSpecificValues();
	}
	updateFieldEditors(isUseProjectSettings);
}
 
Example 4
/**
 * Updates project related fields, and saves to the preferences.
 */
private void updateProjectRelated() {
    IScopeContext context = new ProjectScope(project);
    IEclipsePreferences preferences = context.getNode(CodeCheckerNature.NATURE_ID);

    for (ConfigTypes ctp : ConfigTypes.PROJECT_TYPE){
        String value = null;
        switch (ctp) {
            case CHECKER_WORKSPACE:
                value = codeCheckerWorkspace.toString();
                break;
            case IS_GLOBAL:
                value = Boolean.toString(isGlobal);
                break;
            default:
                break;
        }
        preferences.put(ctp.toString(), value);
    }
    try {
        preferences.flush();
    } catch (BackingStoreException e) {
        Logger.log(IStatus.ERROR, "Preferences cannot be saved!");
        e.printStackTrace();
    }
}
 
Example 5
@SuppressWarnings("all")
@Override
public IPreferenceStore getContextPreferenceStore(Object context) {
	IProject project = getProject(context);
	if (project == null) return getPreferenceStore();
	IPreferenceStore store = super.getContextPreferenceStore(context);
	ProjectScope projectScope = new ProjectScope(project);
	FixedScopedPreferenceStore jdtStore = new FixedScopedPreferenceStore(projectScope, JavaCore.PLUGIN_ID);
	jdtStore.setSearchContexts(new IScopeContext[] {
			projectScope,
			new InstanceScope(),
			new ConfigurationScope()
	});
	return new ChainedPreferenceStore(new IPreferenceStore[] {
		store,
		jdtStore,
		PreferenceConstants.getPreferenceStore()
	});
}
 
Example 6
/**
 * Update all formatter settings with the settings of the specified profile.
 * 
 * @param profile
 *            The profile to write to the preference store
 */
private void writeToPreferenceStore(Profile profile, IScopeContext context) {
	final Map profileOptions = profile.getSettings();

	for (int i = 0; i < fKeySets.length; i++) {
		updatePreferences(context.getNode(fKeySets[i].getNodeName()), fKeySets[i].getKeys(), profileOptions);
	}

	final IEclipsePreferences uiPrefs = context.getNode(getNodeId());
	if (uiPrefs.getInt(fProfileVersionKey, 0) != fProfileVersioner.getCurrentVersion()) {
		uiPrefs.putInt(fProfileVersionKey, fProfileVersioner.getCurrentVersion());
	}

	if (context.getName() == InstanceScope.SCOPE) {
		uiPrefs.put(fProfileKey, profile.getID());
	} else if (context.getName() == ProjectScope.SCOPE && !profile.isSharedProfile()) {
		uiPrefs.put(fProfileKey, profile.getID());
	}
}
 
Example 7
Source Project: gwt-eclipse-plugin   Source File: GWTJavaEditor.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private boolean formatOnSaveEnabled(IJavaProject javaProject) {
  SaveParticipantRegistry spr = JavaPlugin.getDefault().getSaveParticipantRegistry();
  IPostSaveListener[] listeners = spr.getEnabledPostSaveListeners(javaProject.getProject());

  for (IPostSaveListener listener : listeners) {
    if (listener instanceof CleanUpPostSaveListener) {
      Map<String, String> settings =
          CleanUpPreferenceUtil.loadSaveParticipantOptions(new ProjectScope(
          javaProject.getProject()));

      if (settings == null) {
        return false;
      }

      return (CLEAN_UP_OPTION_TRUE.equals(settings.get(CleanUpConstants.FORMAT_SOURCE_CODE)));
    }
  }

  return false;
}
 
Example 8
public IProfile getSelected(IProject project)
{
	IProfile selected = fSelected.get(project);
	if (selected == null && project != null)
	{
		// try to resolve the selected profile
		PreferenceKey activeProfileKey = getActiveProfileKey();
		ProjectScope scope = new ProjectScope(project);
		IProfile profile = findProfile(activeProfileKey.getStoredValue(scope));
		if (profile != null)
		{
			fSelected.put(project, profile);
			selected = profile;
		}
		else
		{
			// Return the default workspace setting
			selected = fSelected.get(null);
		}
	}
	return selected;
}
 
Example 9
public boolean hasProjectSpecificOptions(IProject project)
{
	if (project != null)
	{
		IScopeContext projectContext = new ProjectScope(project);
		PreferenceKey[] allKeys = fAllKeys;
		for (int i = 0; i < allKeys.length; i++)
		{
			if (allKeys[i].getStoredValue(projectContext, fManager) != null)
			{
				return true;
			}
		}
	}
	return false;
}
 
Example 10
/**
 * Given a project, return the list of active user agent IDs. The current implementation processes only the first
 * (primary) nature ID of the given project. Secondary natures may be taken into consideration at a later point in
 * time
 * 
 * @param project
 *            An {@link IProject}.
 * @return Returns an array of user agent IDs for the main mature of the given project. In case the given project is
 *         null, an empty string array is returned.
 */
public String[] getActiveUserAgentIDs(IProject project)
{
	if (project == null)
	{
		return ArrayUtil.NO_STRINGS;
	}
	// Extract the natures from the given project
	String[] natureIDs = getProjectNatures(project);

	// Look at the project-scope preferences for the active agents.
	ProjectScope scope = new ProjectScope(project);
	IEclipsePreferences node = scope.getNode(CommonEditorPlugin.PLUGIN_ID);
	if (node != null)
	{
		String agents = node.get(IPreferenceConstants.USER_AGENT_PREFERENCE, null);
		if (agents != null)
		{
			Map<String, String[]> userAgents = extractUserAgents(agents);
			return getActiveUserAgentIDs(userAgents, natureIDs);
		}
	}
	// In case we did not find any project-specific settings, use the project's nature IDs to grab the agents that
	// were set in the workspace settings.
	return getActiveUserAgentIDs(natureIDs);
}
 
Example 11
public void clearPreferences(IProject project)
{
	if (project != null)
	{
		// Save to the project scope
		IEclipsePreferences preferences = new ProjectScope(project).getNode(CommonEditorPlugin.PLUGIN_ID);
		preferences.remove(IPreferenceConstants.USER_AGENT_PREFERENCE);
		try
		{
			preferences.flush();
		}
		catch (BackingStoreException e)
		{
			// ignore
		}
	}
}
 
Example 12
/**
 * Creates and returns the preference store for this Java editor with the given input.
 *
 * @param input The editor input for which to create the preference store
 * @return the preference store for this editor
 *
 * @since 3.0
 */
private IPreferenceStore createCombinedPreferenceStore(IEditorInput input) {
	List<IPreferenceStore> stores= new ArrayList<IPreferenceStore>(3);

	IJavaProject project= EditorUtility.getJavaProject(input);
	if (project != null) {
		stores.add(new EclipsePreferencesAdapter(new ProjectScope(project.getProject()), JavaCore.PLUGIN_ID));
	}

	stores.add(JavaPlugin.getDefault().getPreferenceStore());
	stores.add(new PreferencesAdapter(JavaPlugin.getJavaCorePluginPreferences()));
	stores.add(EditorsUI.getPreferenceStore());
	stores.add(PlatformUI.getPreferenceStore());

	return new ChainedPreferenceStore(stores.toArray(new IPreferenceStore[stores.size()]));
}
 
Example 13
/**
 * Update all formatter settings with the settings of the specified profile.
 * @param profile The profile to write to the preference store
 */
private void writeToPreferenceStore(Profile profile, IScopeContext context) {
	final Map<String, String> profileOptions= profile.getSettings();

	for (int i= 0; i < fKeySets.length; i++) {
        updatePreferences(context.getNode(fKeySets[i].getNodeName()), fKeySets[i].getKeys(), profileOptions);
       }

	final IEclipsePreferences uiPrefs= context.getNode(JavaUI.ID_PLUGIN);
	if (uiPrefs.getInt(fProfileVersionKey, 0) != fProfileVersioner.getCurrentVersion()) {
		uiPrefs.putInt(fProfileVersionKey, fProfileVersioner.getCurrentVersion());
	}

	if (context.getName() == InstanceScope.SCOPE) {
		uiPrefs.put(fProfileKey, profile.getID());
	} else if (context.getName() == ProjectScope.SCOPE && !profile.isSharedProfile()) {
		uiPrefs.put(fProfileKey, profile.getID());
	}
}
 
Example 14
/**
 * {@inheritDoc}
 */
@Override
public void performDefaults() {
	if (ProjectScope.SCOPE.equals(fContext.getName()) && !hasSettingsInScope(fContext))
		return;

	enabled(true);

	if (ProjectScope.SCOPE.equals(fContext.getName())) {
		fSettings= CleanUpPreferenceUtil.loadSaveParticipantOptions(InstanceScope.INSTANCE);
	} else {
		fSettings= JavaPlugin.getDefault().getCleanUpRegistry().getDefaultOptions(CleanUpConstants.DEFAULT_SAVE_ACTION_OPTIONS).getMap();
	}
	settingsChanged();

	super.performDefaults();
}
 
Example 15
Source Project: goclipse   Source File: AbstractLangEditor.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected IPreferenceStore createCombinedPreferenceStore(IEditorInput input) {
	List<IPreferenceStore> stores = new ArrayList<IPreferenceStore>(4);
	
	IProject project = EditorUtils.getAssociatedProject(input);
	if (project != null) {
		stores.add(new EclipsePreferencesAdapter(new ProjectScope(project), LangUIPlugin.PLUGIN_ID));
	}
	
	stores.add(LangUIPlugin.getInstance().getPreferenceStore());
	stores.add(LangUIPlugin.getInstance().getCorePreferenceStore());
	
	alterCombinedPreferenceStores_beforeEditorsUI(stores);
	stores.add(EditorsUI.getPreferenceStore());
	
	return new ChainedPreferenceStore(ArrayUtil.createFrom(stores, IPreferenceStore.class));
}
 
Example 16
Source Project: eclipse   Source File: BazelProjectSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * List targets configure for <code>project</code>. Each project configured for Bazel is
 * configured to track certain targets and this function fetch this list from the project
 * preferences.
 */
public static List<String> getTargets(IProject project) throws BackingStoreException {
  // Get the list of targets from the preferences
  IScopeContext projectScope = new ProjectScope(project);
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  ImmutableList.Builder<String> builder = ImmutableList.builder();
  for (String s : projectNode.keys()) {
    if (s.startsWith("target")) {
      builder.add(projectNode.get(s, ""));
    }
  }
  return builder.build();
}
 
Example 17
Source Project: eclipse   Source File: BazelProjectSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * List of build flags for <code>project</code>, taken from the project configuration
 */
public static List<String> getBuildFlags(IProject project) throws BackingStoreException {
  // Get the list of targets from the preferences
  IScopeContext projectScope = new ProjectScope(project);
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  ImmutableList.Builder<String> builder = ImmutableList.builder();
  for (String s : projectNode.keys()) {
    if (s.startsWith("buildArgs")) {
      builder.add(projectNode.get(s, ""));
    }
  }
  return builder.build();
}
 
Example 18
Source Project: eclipse   Source File: BazelProjectSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Return the {@link BazelInstance} corresponding to the given <code>project</code>. It looks for
 * the instance that runs for the workspace root configured for that project.
 *
 * @throws BazelNotFoundException
 */
public static BazelCommand.BazelInstance getBazelCommandInstance(IProject project)
    throws BackingStoreException, IOException, InterruptedException, BazelNotFoundException {
  IScopeContext projectScope = new ProjectScope(project.getProject());
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  File workspaceRoot =
      new File(projectNode.get("workspaceRoot", project.getLocation().toFile().toString()));
  return Activator.getDefault().getCommand().getInstance(workspaceRoot);
}
 
Example 19
Source Project: eclipse   Source File: BazelProjectSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Convert an Eclipse JDT project into an IntelliJ project view
 */
public static ProjectView getProjectView(IProject project)
    throws BackingStoreException, JavaModelException {
  com.google.devtools.bazel.e4b.projectviews.Builder builder = ProjectView.builder();
  IScopeContext projectScope = new ProjectScope(project);
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  for (String s : projectNode.keys()) {
    if (s.startsWith("buildArgs")) {
      builder.addBuildFlag(projectNode.get(s, ""));
    } else if (s.startsWith("target")) {
      builder.addTarget(projectNode.get(s, ""));
    }
  }

  IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
  for (IClasspathEntry entry : ((IJavaProject) project).getRawClasspath()) {
    switch (entry.getEntryKind()) {
      case IClasspathEntry.CPE_SOURCE:
        IResource res = root.findMember(entry.getPath());
        if (res != null) {
          builder.addDirectory(res.getProjectRelativePath().removeFirstSegments(1).toOSString());
        }
        break;
      case IClasspathEntry.CPE_CONTAINER:
        String path = entry.getPath().toOSString();
        if (path.startsWith(STANDARD_VM_CONTAINER_PREFIX)) {
          builder.setJavaLanguageLevel(
              Integer.parseInt(path.substring(STANDARD_VM_CONTAINER_PREFIX.length())));
        }
        break;
    }
  }
  return builder.build();
}
 
Example 20
@Before
public void setUp() {
  IProject project = mock(IProject.class);
  when(project.getName()).thenReturn("");
  preferences = new DeployPreferences(project);
  preferenceStore =
      new ProjectScope(project).getNode("com.google.cloud.tools.eclipse.appengine.deploy");
}
 
Example 21
@Before
public void setUp() {
  IProject project = mock(IProject.class);
  when(project.getName()).thenReturn("");
  preferences = new FlexDeployPreferences(project);
  preferenceStore =
      new ProjectScope(project).getNode("com.google.cloud.tools.eclipse.appengine.deploy");
}
 
Example 22
public static void setUnixLineEndings(IProject project) {
	IEclipsePreferences prefs = new ProjectScope(project).getNode(Platform.PI_RUNTIME);
	prefs.put(Platform.PREF_LINE_SEPARATOR, "\n");
	try {
		prefs.flush();
	} catch (BackingStoreException e) {
		throw new RuntimeException(e);
	}
}
 
Example 23
/**
 * Read a setting from the project scope (higher prio) or the instance scope (lower prio) to decide if Eclipse should use its own output
 * dir or compile to the maven standard output directories.
 * 
 * Defaults to {@code false}.
 */
private boolean compileToBin(IProject project) {
	String pluginId = "org.eclipse.xtext.m2e";
	String key = "compileToBin";
	ProjectScope projectScope = new ProjectScope(project);
	IEclipsePreferences projectPreferences = projectScope.getNode(pluginId);
	String value = projectPreferences.get(key, null);
	if (value != null) {
		return "true".equals(value);
	}
	IEclipsePreferences instancePreferences = InstanceScope.INSTANCE.getNode(pluginId);
	return "true".equals(instancePreferences.get(key, "false"));
}
 
Example 24
private void configureLanguages(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
	List<MojoExecution> executions = getMojoExecutions(request, monitor);
	SubMonitor progress = SubMonitor.convert(monitor, executions.size());
	for (MojoExecution execution : executions) {
		Languages languages = maven.getMojoParameterValue(request.getMavenProject(), execution, "languages", Languages.class, progress.split(1));
		if(languages!=null) {
			ProjectScope projectPreferences = new ProjectScope(request.getProject());
			for (Language language : languages) {
				configureLanguage(projectPreferences, language, request);
			}
		}
	}
}
 
Example 25
private void configureLanguage(ProjectScope projectPreferences, Language language, ProjectConfigurationRequest request) throws CoreException {
	if (language.getOutputConfigurations().isEmpty()) return;
	
	IEclipsePreferences languagePreferences = projectPreferences.getNode(language.name());
	languagePreferences.putBoolean(OptionsConfigurationBlock.isProjectSpecificPropertyKey(BuilderConfigurationBlock.PROPERTY_PREFIX), true);
	languagePreferences.putBoolean(PREF_AUTO_BUILDING, true);
	for (OutputConfiguration outputConfiguration : language.getOutputConfigurations()) {
		configureOutlet(languagePreferences, outputConfiguration, request);
	}
	try {
		languagePreferences.flush();
	} catch (BackingStoreException e) {
		throw new RuntimeException(e);
	}
}
 
Example 26
public static void setUnixLineEndings(IProject project) {
	IEclipsePreferences prefs = new ProjectScope(project).getNode(Platform.PI_RUNTIME);
	prefs.put(Platform.PREF_LINE_SEPARATOR, "\n");
	try {
		prefs.flush();
	} catch (BackingStoreException e) {
		throw new RuntimeException(e);
	}
}
 
Example 27
Source Project: uml2solidity   Source File: PreferenceConstants.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public static IPreferenceStore getPreferenceStore(IProject project) {
	if (project != null) {
		IPreferenceStore store = new ScopedPreferenceStore(new ProjectScope(project), Activator.PLUGIN_ID);
		if(store.getBoolean(PreferenceConstants.GENERATOR_PROJECT_SETTINGS))
		return store;
	}
	return new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.PLUGIN_ID);//Activator.PLUGIN_ID);
}
 
Example 28
Source Project: uml2solidity   Source File: PreferenceConstants.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public static IPreferenceStore getPreferenceStore(IProject project) {
	if (project != null) {
		IPreferenceStore store = new ScopedPreferenceStore(new ProjectScope(project), Activator.PLUGIN_ID);
		if(store.getBoolean(PreferenceConstants.COMPILER_PROJECT_SETTINGS)|| store.getBoolean(PreferenceConstants.BUILDER_PROJECT_SETTINGS))
		return store;
	}
	return new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.PLUGIN_ID);//Activator.PLUGIN_ID);
}
 
Example 29
Source Project: SparkBuilderGenerator   Source File: PreferenceStoreProvider.java    License: MIT License 5 votes vote down vote up
public PreferenceStoreWrapper providePreferenceStore() {
    IPreferenceStore[] preferenceStores = new IPreferenceStore[2];
    preferenceStores[0] = Activator.getDefault().getPreferenceStore();

    ScopedPreferenceStore jdtCorePreferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.jdt.core");
    if (currentJavaProject.isPresent()) { // if we are in a project add to search scope
        jdtCorePreferenceStore.setSearchContexts(new IScopeContext[] { new ProjectScope(currentJavaProject.get().getProject()), InstanceScope.INSTANCE });
    }
    preferenceStores[1] = jdtCorePreferenceStore;

    return new PreferenceStoreWrapper(new ChainedPreferenceStore(preferenceStores));
}
 
Example 30
private void initPreferencesStore(IProject currProject) {
    workspaceStore = new ScopedPreferenceStore(new InstanceScope(), FindbugsPlugin.PLUGIN_ID);
    if (currProject != null) {
        projectStore = new ScopedPreferenceStore(new ProjectScope(currProject), FindbugsPlugin.PLUGIN_ID);
        projectPropsInitiallyEnabled = FindbugsPlugin.isProjectSettingsEnabled(currProject);
        if (!projectPropsInitiallyEnabled) {
            // use workspace properties instead
            currProject = null;
        }
        setPreferenceStore(projectStore);
    } else {
        setPreferenceStore(workspaceStore);
    }
    loadPreferences(currProject);
}