Skip to content

Commit 92c6a16

Browse files
committed
Enable m2e-apt by default
Also a small bugfix related to enabling spring-boot validation builder on new projects. Both of these contribute to make a smoother experience working with JDT APT. See: #822
1 parent ed9c0cd commit 92c6a16

File tree

5 files changed

+63
-7
lines changed

5 files changed

+63
-7
lines changed

eclipse-extensions/org.springframework.ide.eclipse.boot.validation/src/org/springframework/ide/eclipse/boot/validation/BootValidationEnabler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private boolean hasBuilder(IProject p, String builderId) throws CoreException {
109109
@Override
110110
public void earlyStartup() {
111111
//Don't do this stuff actually during startup. Its not critical and it can wait.
112-
new ValidationEnablerStartupJob().schedule(Duration.ofMinutes(1).toMillis());
112+
new ValidationEnablerStartupJob().schedule(Duration.ofSeconds(10).toMillis());
113113
}
114114

115115
}

eclipse-extensions/org.springframework.ide.eclipse.boot/plugin.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,5 +272,7 @@
272272
point="org.springframework.ide.eclipse.boot.project">
273273
<project nature="org.eclipse.m2e.core.maven2Nature" projectClass="org.springframework.ide.eclipse.boot.core.internal.MavenSpringBootProject"></project>
274274
</extension>
275-
275+
<extension point="org.eclipse.ui.startup">
276+
<startup class="org.springframework.ide.eclipse.boot.ui.preferences.MavenAptPreferenceInitializer"/>
277+
</extension>
276278
</plugin>

eclipse-extensions/org.springframework.ide.eclipse.boot/src/org/springframework/ide/eclipse/boot/core/internal/MavenSpringBootProject.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.io.File;
3737
import java.lang.reflect.Constructor;
3838
import java.util.ArrayList;
39-
import java.util.Arrays;
4039
import java.util.Collection;
4140
import java.util.Collections;
4241
import java.util.List;
@@ -337,7 +336,11 @@ public void updateProjectConfiguration() {
337336
protected IStatus run(IProgressMonitor arg0) {
338337
Job job = createUpdateMavenProjectJob(getProject());
339338
if (job != null) {
340-
job.schedule();
339+
job.schedule(2000); //Without 2000ms delay, we tend to get deadlocks.
340+
// TODO: ^^^^ debug this and find a better solution (suspect this actually bug in m2e,
341+
// but it rarely happens when a user invokes the operation from the UI.
342+
// It happens here presumably because some updates happen in quick succession
343+
// and this causes some sort of a race condition causing a deadlock situation.
341344
return Status.OK_STATUS;
342345
}
343346
else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.springframework.ide.eclipse.boot.ui.preferences;
2+
3+
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
4+
import org.eclipse.core.runtime.preferences.DefaultScope;
5+
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
6+
import org.eclipse.core.runtime.preferences.InstanceScope;
7+
import org.eclipse.ui.IStartup;
8+
import org.osgi.service.prefs.BackingStoreException;
9+
import org.springframework.ide.eclipse.boot.core.BootActivator;
10+
import org.springsource.ide.eclipse.commons.livexp.util.Log;
11+
12+
public class MavenAptPreferenceInitializer implements IStartup {
13+
14+
private static final String M2E_APT_PLUGIN_ID = "org.eclipse.m2e.apt";
15+
private static final String PREF_MODE= M2E_APT_PLUGIN_ID+".mode";
16+
17+
private static final String PREF_STS_CUSTONISATIONS_APPLIED= BootActivator.PLUGIN_ID+".customised";
18+
// ^^^ used to ensure we do not apply our customisations more than once (allows users to change the preference
19+
// by themselves and not have us repeatedly return it back to our own default setting.
20+
21+
@Override
22+
public void earlyStartup() {
23+
try {
24+
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(M2E_APT_PLUGIN_ID);
25+
if (!prefs.getBoolean(PREF_STS_CUSTONISATIONS_APPLIED, false)) {
26+
prefs.put(PREF_MODE, "jdt_apt");
27+
prefs.putBoolean(PREF_STS_CUSTONISATIONS_APPLIED, true);
28+
}
29+
prefs.flush();
30+
} catch (BackingStoreException e) {
31+
Log.log(e);
32+
}
33+
}
34+
}

eclipse-language-servers/org.springsource.ide.eclipse.commons.frameworks.core/src/org/springsource/ide/eclipse/commons/frameworks/core/workspace/ClasspathListenerManager.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
*******************************************************************************/
1111
package org.springsource.ide.eclipse.commons.frameworks.core.workspace;
1212

13+
import java.util.Collections;
14+
import java.util.HashSet;
15+
import java.util.Set;
16+
1317
import org.eclipse.core.resources.IProject;
1418
import org.eclipse.core.resources.ResourcesPlugin;
1519
import org.eclipse.core.runtime.CoreException;
@@ -37,6 +41,8 @@ public interface ClasspathListener {
3741

3842
private class MyListener implements IElementChangedListener {
3943

44+
private Set<String> knownProjectNames = Collections.synchronizedSet(new HashSet<>());
45+
4046
//@Override
4147
public void elementChanged(ElementChangedEvent event) {
4248
visit(event.getDelta());
@@ -49,15 +55,20 @@ private void visit(IJavaElementDelta delta) {
4955
visitChildren(delta);
5056
break;
5157
case IJavaElement.JAVA_PROJECT:
52-
if (isClasspathChanged(delta.getFlags())) {
53-
listener.classpathChanged((IJavaProject)el);
58+
IJavaProject jp = (IJavaProject) el;
59+
if (isNewProject(jp) || isClasspathChanged(delta.getFlags())) {
60+
listener.classpathChanged(jp);
5461
}
5562
break;
5663
default:
5764
break;
5865
}
5966
}
6067

68+
private boolean isNewProject(IJavaProject jp) {
69+
return knownProjectNames.add(jp.getElementName());
70+
}
71+
6172
private boolean isClasspathChanged(int flags) {
6273
return 0!= (flags & (
6374
IJavaElementDelta.F_CLASSPATH_CHANGED |
@@ -70,6 +81,10 @@ public void visitChildren(IJavaElementDelta delta) {
7081
visit(c);
7182
}
7283
}
84+
85+
public void addKnownProject(IJavaProject jp) {
86+
this.knownProjectNames.add(jp.getElementName());
87+
}
7388
}
7489

7590
private ClasspathListener listener;
@@ -83,19 +98,21 @@ public void visitChildren(IJavaElementDelta delta) {
8398
*/
8499
public ClasspathListenerManager(ClasspathListener listener, boolean initialEvent) {
85100
this.listener = listener;
101+
myListener=new MyListener();
86102
if (initialEvent) {
87103
for (IProject p : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
88104
try {
89105
if (p.isAccessible() && p.hasNature(JavaCore.NATURE_ID)) {
90106
IJavaProject jp = JavaCore.create(p);
91107
listener.classpathChanged(jp);
108+
myListener.addKnownProject(jp);
92109
}
93110
} catch (CoreException e) {
94111
FrameworkCoreActivator.log(e);
95112
}
96113
}
97114
}
98-
JavaCore.addElementChangedListener(myListener=new MyListener(), ElementChangedEvent.POST_CHANGE);
115+
JavaCore.addElementChangedListener(myListener, ElementChangedEvent.POST_CHANGE);
99116
}
100117

101118
public ClasspathListenerManager(ClasspathListener listener) {

0 commit comments

Comments
 (0)