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: https://github.com/spring-projects/sts4/issues/822
This commit is contained in:
@@ -109,7 +109,7 @@ public class BootValidationEnabler implements org.eclipse.ui.IStartup {
|
||||
@Override
|
||||
public void earlyStartup() {
|
||||
//Don't do this stuff actually during startup. Its not critical and it can wait.
|
||||
new ValidationEnablerStartupJob().schedule(Duration.ofMinutes(1).toMillis());
|
||||
new ValidationEnablerStartupJob().schedule(Duration.ofSeconds(10).toMillis());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -272,5 +272,7 @@
|
||||
point="org.springframework.ide.eclipse.boot.project">
|
||||
<project nature="org.eclipse.m2e.core.maven2Nature" projectClass="org.springframework.ide.eclipse.boot.core.internal.MavenSpringBootProject"></project>
|
||||
</extension>
|
||||
|
||||
<extension point="org.eclipse.ui.startup">
|
||||
<startup class="org.springframework.ide.eclipse.boot.ui.preferences.MavenAptPreferenceInitializer"/>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
||||
@@ -36,7 +36,6 @@ import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.performOnDOMDocu
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -337,7 +336,11 @@ public class MavenSpringBootProject extends SpringBootProject {
|
||||
protected IStatus run(IProgressMonitor arg0) {
|
||||
Job job = createUpdateMavenProjectJob(getProject());
|
||||
if (job != null) {
|
||||
job.schedule();
|
||||
job.schedule(2000); //Without 2000ms delay, we tend to get deadlocks.
|
||||
// TODO: ^^^^ debug this and find a better solution (suspect this actually bug in m2e,
|
||||
// but it rarely happens when a user invokes the operation from the UI.
|
||||
// It happens here presumably because some updates happen in quick succession
|
||||
// and this causes some sort of a race condition causing a deadlock situation.
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.springframework.ide.eclipse.boot.ui.preferences;
|
||||
|
||||
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
|
||||
import org.eclipse.core.runtime.preferences.DefaultScope;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.eclipse.ui.IStartup;
|
||||
import org.osgi.service.prefs.BackingStoreException;
|
||||
import org.springframework.ide.eclipse.boot.core.BootActivator;
|
||||
import org.springsource.ide.eclipse.commons.livexp.util.Log;
|
||||
|
||||
public class MavenAptPreferenceInitializer implements IStartup {
|
||||
|
||||
private static final String M2E_APT_PLUGIN_ID = "org.eclipse.m2e.apt";
|
||||
private static final String PREF_MODE= M2E_APT_PLUGIN_ID+".mode";
|
||||
|
||||
private static final String PREF_STS_CUSTONISATIONS_APPLIED= BootActivator.PLUGIN_ID+".customised";
|
||||
// ^^^ used to ensure we do not apply our customisations more than once (allows users to change the preference
|
||||
// by themselves and not have us repeatedly return it back to our own default setting.
|
||||
|
||||
@Override
|
||||
public void earlyStartup() {
|
||||
try {
|
||||
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(M2E_APT_PLUGIN_ID);
|
||||
if (!prefs.getBoolean(PREF_STS_CUSTONISATIONS_APPLIED, false)) {
|
||||
prefs.put(PREF_MODE, "jdt_apt");
|
||||
prefs.putBoolean(PREF_STS_CUSTONISATIONS_APPLIED, true);
|
||||
}
|
||||
prefs.flush();
|
||||
} catch (BackingStoreException e) {
|
||||
Log.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,10 @@
|
||||
*******************************************************************************/
|
||||
package org.springsource.ide.eclipse.commons.frameworks.core.workspace;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
@@ -37,6 +41,8 @@ public class ClasspathListenerManager implements Disposable {
|
||||
|
||||
private class MyListener implements IElementChangedListener {
|
||||
|
||||
private Set<String> knownProjectNames = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
//@Override
|
||||
public void elementChanged(ElementChangedEvent event) {
|
||||
visit(event.getDelta());
|
||||
@@ -49,8 +55,9 @@ public class ClasspathListenerManager implements Disposable {
|
||||
visitChildren(delta);
|
||||
break;
|
||||
case IJavaElement.JAVA_PROJECT:
|
||||
if (isClasspathChanged(delta.getFlags())) {
|
||||
listener.classpathChanged((IJavaProject)el);
|
||||
IJavaProject jp = (IJavaProject) el;
|
||||
if (isNewProject(jp) || isClasspathChanged(delta.getFlags())) {
|
||||
listener.classpathChanged(jp);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -58,6 +65,10 @@ public class ClasspathListenerManager implements Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNewProject(IJavaProject jp) {
|
||||
return knownProjectNames.add(jp.getElementName());
|
||||
}
|
||||
|
||||
private boolean isClasspathChanged(int flags) {
|
||||
return 0!= (flags & (
|
||||
IJavaElementDelta.F_CLASSPATH_CHANGED |
|
||||
@@ -70,6 +81,10 @@ public class ClasspathListenerManager implements Disposable {
|
||||
visit(c);
|
||||
}
|
||||
}
|
||||
|
||||
public void addKnownProject(IJavaProject jp) {
|
||||
this.knownProjectNames.add(jp.getElementName());
|
||||
}
|
||||
}
|
||||
|
||||
private ClasspathListener listener;
|
||||
@@ -83,19 +98,21 @@ public class ClasspathListenerManager implements Disposable {
|
||||
*/
|
||||
public ClasspathListenerManager(ClasspathListener listener, boolean initialEvent) {
|
||||
this.listener = listener;
|
||||
myListener=new MyListener();
|
||||
if (initialEvent) {
|
||||
for (IProject p : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
|
||||
try {
|
||||
if (p.isAccessible() && p.hasNature(JavaCore.NATURE_ID)) {
|
||||
IJavaProject jp = JavaCore.create(p);
|
||||
listener.classpathChanged(jp);
|
||||
myListener.addKnownProject(jp);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
FrameworkCoreActivator.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
JavaCore.addElementChangedListener(myListener=new MyListener(), ElementChangedEvent.POST_CHANGE);
|
||||
JavaCore.addElementChangedListener(myListener, ElementChangedEvent.POST_CHANGE);
|
||||
}
|
||||
|
||||
public ClasspathListenerManager(ClasspathListener listener) {
|
||||
|
||||
Reference in New Issue
Block a user