2424import java .util .Map ;
2525import java .util .Properties ;
2626
27+ import org .codehaus .groovy .eclipse .GroovyLogManager ;
28+ import org .codehaus .groovy .eclipse .IGroovyLogger ;
29+ import org .codehaus .groovy .eclipse .TraceCategory ;
2730import org .codehaus .groovy .eclipse .core .GroovyCoreActivator ;
2831import org .codehaus .groovy .eclipse .refactoring .formatter .DefaultGroovyFormatter ;
2932import org .codehaus .groovy .eclipse .refactoring .formatter .FormatterPreferencesOnStore ;
3740import org .eclipse .jface .text .TextSelection ;
3841import org .eclipse .text .edits .TextEdit ;
3942
43+ import dev .equo .solstice .NestedJars ;
44+ import dev .equo .solstice .ShimIdeBootstrapServices ;
4045import dev .equo .solstice .Solstice ;
46+ import dev .equo .solstice .p2 .CacheLocations ;
4147
4248/** Spotless-Formatter step which calls out to the Groovy-Eclipse formatter. */
4349public class GrEclipseFormatterStepImpl {
@@ -54,10 +60,15 @@ public class GrEclipseFormatterStepImpl {
5460
5561 public GrEclipseFormatterStepImpl (final Properties properties ) throws Exception {
5662 var solstice = Solstice .findBundlesOnClasspath ();
63+ NestedJars .setToWarnOnly ();
64+ NestedJars .onClassPath ().confirmAllNestedJarsArePresentOnClasspath (CacheLocations .nestedJars ());
5765 solstice .warnAndModifyManifestsToFix ();
58- solstice .openShim (Map .of ());
66+ var props = Map .<String , String > of ();
67+ solstice .openShim (props );
68+ ShimIdeBootstrapServices .apply (props , solstice .getContext ());
5969 solstice .startAllWithLazy (false );
6070 solstice .startWithoutTransitives ("org.codehaus.groovy.eclipse.core" );
71+
6172 PreferenceStore preferences = createPreferences (properties );
6273 preferencesStore = new FormatterPreferencesOnStore (preferences );
6374 ignoreFormatterProblems = Boolean .parseBoolean (properties .getProperty (IGNORE_FORMATTER_PROBLEMS , "false" ));
@@ -80,8 +91,7 @@ public String format(String raw) throws Exception {
8091 /**
8192 * Eclipse Groovy formatter does not signal problems by its return value, but by logging errors.
8293 */
83- private static class GroovyErrorListener implements ILogListener {
84-
94+ private static class GroovyErrorListener implements ILogListener , IGroovyLogger {
8595 private final List <String > errors ;
8696
8797 public GroovyErrorListener () {
@@ -92,6 +102,9 @@ public GroovyErrorListener() {
92102 errors = Collections .synchronizedList (new ArrayList <String >());
93103 ILog groovyLogger = GroovyCoreActivator .getDefault ().getLog ();
94104 groovyLogger .addLogListener (this );
105+ synchronized (GroovyLogManager .manager ) {
106+ GroovyLogManager .manager .addLogger (this );
107+ }
95108 }
96109
97110 @ Override
@@ -102,6 +115,9 @@ public void logging(final IStatus status, final String plugin) {
102115 public boolean errorsDetected () {
103116 ILog groovyLogger = GroovyCoreActivator .getDefault ().getLog ();
104117 groovyLogger .removeLogListener (this );
118+ synchronized (GroovyLogManager .manager ) {
119+ GroovyLogManager .manager .removeLogger (this );
120+ }
105121 return 0 != errors .size ();
106122 }
107123
@@ -120,6 +136,22 @@ public String toString() {
120136
121137 return string .toString ();
122138 }
139+
140+ @ Override
141+ public boolean isCategoryEnabled (TraceCategory cat ) {
142+ /*
143+ * Note that the compiler errors are just additionally caught here.
144+ * They are also printed directly to System.err.
145+ * See org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.recordProblems
146+ * for details.
147+ */
148+ return TraceCategory .COMPILER .equals (cat );
149+ }
150+
151+ @ Override
152+ public void log (TraceCategory arg0 , String arg1 ) {
153+ errors .add (arg1 );
154+ }
123155 }
124156
125157 private static PreferenceStore createPreferences (final Properties properties ) throws IOException {
@@ -130,5 +162,4 @@ private static PreferenceStore createPreferences(final Properties properties) th
130162 preferences .load (input );
131163 return preferences ;
132164 }
133-
134165}
0 commit comments