Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Another attempt the fix the issue #23.

  • Loading branch information...
commit f04a9922aa3c8571e6d659c8617d6c9e226ca984 1 parent 962cf38
@kelemen authored
View
2  src/org/netbeans/gradle/project/persistent/PropertiesPersister.java
@@ -9,5 +9,5 @@
= new RequestProcessor("Gradle-properties-persister", 1, true);
public void save(ProjectProperties properties, Runnable onDone);
- public void load(ProjectProperties properties, Runnable onDone);
+ public void load(ProjectProperties properties, boolean usedConcurrently, Runnable onDone);
}
View
55 src/org/netbeans/gradle/project/persistent/XmlPropertiesPersister.java
@@ -4,6 +4,7 @@
import java.nio.charset.Charset;
import java.util.LinkedList;
import java.util.List;
+import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -37,20 +38,25 @@ private void checkCallingThread() {
}
@Override
- public void save(ProjectProperties properties, final Runnable onDone) {
+ public void save(final ProjectProperties properties, final Runnable onDone) {
checkCallingThread();
- final PropertiesSnapshot snapshot = new PropertiesSnapshot(properties);
- NbGradleProject.PROJECT_PROCESSOR.execute(new Runnable() {
+ SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
- try {
- XmlPropertyFormat.saveToXml(propertiesFile, snapshot);
- } finally {
- if (onDone != null) {
- SwingUtilities.invokeLater(onDone);
+ final PropertiesSnapshot snapshot = new PropertiesSnapshot(properties);
+ NbGradleProject.PROJECT_PROCESSOR.execute(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ XmlPropertyFormat.saveToXml(propertiesFile, snapshot);
+ } finally {
+ if (onDone != null) {
+ onDone.run();
+ }
+ }
}
- }
+ });
}
});
}
@@ -62,7 +68,7 @@ public void run() {
}
@Override
- public void load(final ProjectProperties properties, final Runnable onDone) {
+ public void load(final ProjectProperties properties, final boolean usedConcurrently, final Runnable onDone) {
checkCallingThread();
// We must listen for changes, so that we do not overwrite properties
@@ -114,13 +120,17 @@ public void load(final ProjectProperties properties, final Runnable onDone) {
setter.start();
}
+ final Executor setterExecutor = usedConcurrently
+ ? SwingExecutor.INSTANCE
+ : RecursiveExecutor.INSTANCE;
+
NbGradleProject.PROJECT_PROCESSOR.execute(new Runnable() {
@Override
public void run() {
try {
final PropertiesSnapshot snapshot = XmlPropertyFormat.readFromXml(propertiesFile);
- SwingUtilities.invokeLater(new Runnable() {
+ setterExecutor.execute(new Runnable() {
@Override
public void run() {
for (PropertySetter<?> setter: setters) {
@@ -132,11 +142,10 @@ public void run() {
}
}
});
-
} finally {
- // invokeLater is required, so that the listeners will not
+ // required, so that the listeners will not
// be removed before setting the properties.
- SwingUtilities.invokeLater(new Runnable() {
+ setterExecutor.execute(new Runnable() {
@Override
public void run() {
for (PropertySetter<?> setter: setters) {
@@ -208,4 +217,22 @@ public void stateChanged(ChangeEvent e) {
changed = true;
}
}
+
+ private enum RecursiveExecutor implements Executor {
+ INSTANCE;
+
+ @Override
+ public void execute(Runnable command) {
+ command.run();
+ }
+ }
+
+ private enum SwingExecutor implements Executor {
+ INSTANCE;
+
+ @Override
+ public void execute(Runnable command) {
+ SwingUtilities.invokeLater(command);
+ }
+ }
}
View
4 src/org/netbeans/gradle/project/properties/MutableProperty.java
@@ -3,7 +3,9 @@
import javax.swing.event.ChangeListener;
public interface MutableProperty<ValueType> {
- // Setting and getting the value of a property is only allowed from the EDT.
+ // Setting and getting the value of a property is not allowed concurrently.
+ // If you don't know if it might be used concurrently, you must access
+ // them from the EDT.
public void setValueFromSource(PropertySource<? extends ValueType> source);
public void setValue(ValueType value);
public ValueType getValue();
View
3  src/org/netbeans/gradle/project/properties/ProjectPropertiesManager.java
@@ -13,7 +13,6 @@
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.netbeans.gradle.project.WaitableSignal;
@@ -213,7 +212,7 @@ private static ProjectProperties loadPropertiesAlways(
PropertiesPersister.PERSISTER_PROCESSOR.execute(new Runnable() {
@Override
public void run() {
- persister.load(properties, new Runnable() {
+ persister.load(properties, false, new Runnable() {
@Override
public void run() {
try {
Please sign in to comment.
Something went wrong with that request. Please try again.