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:
Kris De Volder
2022-09-14 15:46:12 -07:00
parent ed9c0cde56
commit 92c6a1698f
5 changed files with 63 additions and 7 deletions

View File

@@ -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>

View File

@@ -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 {

View File

@@ -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);
}
}
}