Skip to content

Commit f1ce2a0

Browse files
committed
Restore the more complex GrEclipse log manager.
1 parent 2673e91 commit f1ce2a0

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
// https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md
3-
id 'dev.equo.ide' version '0.16.0'
3+
id 'dev.equo.ide' version '0.17.1'
44
}
55
equoIde {
66
branding().title('Spotless').icon(file('_images/spotless_logo.png'))

lib-extra/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ version = rootProject.spotlessChangelog.versionNext
77
apply from: rootProject.file('gradle/java-setup.gradle')
88
apply from: rootProject.file('gradle/java-publish.gradle')
99

10-
String VER_SOLSTICE = '0.18.0'
10+
String VER_SOLSTICE = '0.19.1'
1111
dependencies {
1212
api project(':lib')
1313
// misc useful utilities
@@ -72,8 +72,8 @@ p2deps {
7272
install 'org.eclipse.jdt.core'
7373
}
7474
into 'groovyCompileOnly', {
75-
p2repo 'https://download.eclipse.org/eclipse/updates/4.26/'
76-
p2repo 'https://groovy.jfrog.io/artifactory/plugins-release/org/codehaus/groovy/groovy-eclipse-integration/4.8.0/e4.26/'
75+
p2repo 'https://download.eclipse.org/eclipse/updates/4.23/'
76+
p2repo 'https://groovy.jfrog.io/artifactory/plugins-release/org/codehaus/groovy/groovy-eclipse-integration/4.8.0/e4.23/'
7777
install 'org.codehaus.groovy.eclipse.refactoring'
7878
install 'org.codehaus.groovy.eclipse.core'
7979
install 'org.eclipse.jdt.groovy.core'

lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import java.util.Map;
2525
import 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;
2730
import org.codehaus.groovy.eclipse.core.GroovyCoreActivator;
2831
import org.codehaus.groovy.eclipse.refactoring.formatter.DefaultGroovyFormatter;
2932
import org.codehaus.groovy.eclipse.refactoring.formatter.FormatterPreferencesOnStore;
@@ -37,7 +40,10 @@
3740
import org.eclipse.jface.text.TextSelection;
3841
import org.eclipse.text.edits.TextEdit;
3942

43+
import dev.equo.solstice.NestedJars;
44+
import dev.equo.solstice.ShimIdeBootstrapServices;
4045
import dev.equo.solstice.Solstice;
46+
import dev.equo.solstice.p2.CacheLocations;
4147

4248
/** Spotless-Formatter step which calls out to the Groovy-Eclipse formatter. */
4349
public 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
}

lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,11 @@ EquoBasedStepBuilder.State get() throws Exception {
7070
var query = model(formatterVersion).query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW);
7171
var classpath = new ArrayList<File>();
7272
var mavenDeps = new ArrayList<String>();
73-
mavenDeps.add("dev.equo.ide:solstice:0.18.0");
73+
mavenDeps.add("dev.equo.ide:solstice:0.19.1");
7474
mavenDeps.addAll(query.getJarsOnMavenCentral());
7575
classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps));
7676
classpath.addAll(query.getJarsNotOnMavenCentral());
77-
File nestedDir = new File("/Users/ntwigg/.equo/p2-blah");
78-
for (var nested : NestedJars.inFiles(query.getJarsNotOnMavenCentral()).extractAllNestedJars(nestedDir)) {
77+
for (var nested : NestedJars.inFiles(query.getJarsNotOnMavenCentral()).extractAllNestedJars()) {
7978
classpath.add(nested.getValue());
8079
}
8180
var jarState = JarState.preserveOrder(classpath);

0 commit comments

Comments
 (0)