Skip to content

Commit

Permalink
Use equinox preferences APIs in AutoBuildJob class #497
Browse files Browse the repository at this point in the history
Replace deprecated preferences APIs.
In the implementation of
IPreferenceChangeListener.preferenceChange(PreferenceChangeEvent) do not
use the newValue field of the PreferenceChangeEvent object because it is
null when autobuild is being turned on (this is caused by the method
Preferences.setValue(String, boolean) removing the explicit setting when
the value is equal to the default value).

Partially fixes
#497
  • Loading branch information
alex2145 authored and jukzi committed Jun 22, 2023
1 parent 65070b3 commit 8b87e40
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,34 @@
*******************************************************************************/
package org.eclipse.core.internal.events;

import org.eclipse.core.internal.resources.*;
import org.eclipse.core.internal.resources.ICoreConstants;
import org.eclipse.core.internal.resources.ResourceException;
import org.eclipse.core.internal.resources.Workspace;
import org.eclipse.core.internal.utils.Messages;
import org.eclipse.core.internal.utils.Policy;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.osgi.framework.Bundle;

/**
* The job for performing workspace auto-builds, and pre- and post- autobuild
* notification. This job is run whenever the workspace changes regardless
* of whether autobuild is on or off.
*/
class AutoBuildJob extends Job implements Preferences.IPropertyChangeListener {
class AutoBuildJob extends Job implements IEclipsePreferences.IPreferenceChangeListener {
private volatile boolean avoidBuild;
private volatile boolean buildNeeded;
private volatile boolean forceBuild;
Expand All @@ -41,7 +53,6 @@ class AutoBuildJob extends Job implements Preferences.IPropertyChangeListener {
private volatile boolean interrupted;
private volatile boolean isAutoBuilding;
private volatile long lastBuild = 0L;
private Preferences preferences = ResourcesPlugin.getPlugin().getPluginPreferences();
private final Bundle systemBundle = Platform.getBundle("org.eclipse.osgi"); //$NON-NLS-1$
private Workspace workspace;
final Job noBuildJob;
Expand All @@ -52,7 +63,7 @@ class AutoBuildJob extends Job implements Preferences.IPropertyChangeListener {
setPriority(BUILD);
isAutoBuilding = workspace.isAutoBuilding();
this.workspace = workspace;
this.preferences.addPropertyChangeListener(this);
InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES).addPreferenceChangeListener(this);
noBuildJob = new AutoBuildOffJob();
}

Expand Down Expand Up @@ -255,14 +266,14 @@ synchronized boolean isInterrupted() {
return interrupted;
}

@Deprecated
@Override
public void propertyChange(PropertyChangeEvent event) {
if (!event.getProperty().equals(ResourcesPlugin.PREF_AUTO_BUILDING))
public void preferenceChange(PreferenceChangeEvent event) {
if (!ResourcesPlugin.PREF_AUTO_BUILDING.equals(event.getKey()))
return;
// get the new value of auto-build directly from the preferences
boolean wasAutoBuilding = isAutoBuilding;
isAutoBuilding = preferences.getBoolean(ResourcesPlugin.PREF_AUTO_BUILDING);
isAutoBuilding = Platform.getPreferencesService().getBoolean(ResourcesPlugin.PI_RESOURCES,
ResourcesPlugin.PREF_AUTO_BUILDING, false, null);
if (wasAutoBuilding && !isAutoBuilding) {
// stop the current autobuild when autobuild has been turned off
interrupt();
Expand Down

0 comments on commit 8b87e40

Please sign in to comment.