Skip to content

Commit 897b11d

Browse files
committed
A Preference page to control usage of Javac backend
1 parent 0b282b5 commit 897b11d

File tree

18 files changed

+387
-13
lines changed

18 files changed

+387
-13
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pipeline {
2626
-Dtycho.buildqualifier.format="'z'yyyyMMdd-HHmm" \
2727
-Pp2-repo \
2828
-Djava.io.tmpdir=$WORKSPACE/tmp -Dproject.build.sourceEncoding=UTF-8 \
29-
-pl org.eclipse.jdt.core.javac,org.eclipse.jdt.core.javac.feature,org.eclipse.jdt.core.tests.model,org.eclipse.jdt.core.tests.compiler,repository
29+
-pl org.eclipse.jdt.core.javac,org.eclipse.jdt.core.javac.configurator,org.eclipse.jdt.javac.ui,org.eclipse.jdt.javac.feature,org.eclipse.jdt.core.tests.model,org.eclipse.jdt.core.tests.compiler,repository
3030
3131
mvn verify --batch-mode -pl org.eclipse.jdt.core.compiler.batch,org.eclipse.jdt.core,org.eclipse.jdt.core.tests.javac -Dmaven.repo.local=$WORKSPACE/.m2/repository \
3232
--fail-at-end -Ptest-on-javase-25 -Pbree-libs \
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
4+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5+
<classpathentry kind="src" path="src"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>org.eclipse.jdt.core.javac.configurator</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.pde.ManifestBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.SchemaBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>org.eclipse.pde.PluginNature</nature>
26+
<nature>org.eclipse.jdt.core.javanature</nature>
27+
</natures>
28+
</projectDescription>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
3+
org.eclipse.jdt.core.compiler.compliance=21
4+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
5+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
6+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
8+
org.eclipse.jdt.core.compiler.release=enabled
9+
org.eclipse.jdt.core.compiler.source=21
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: API to configure Javac backend
4+
Bundle-SymbolicName: org.eclipse.jdt.core.javac.configurator
5+
Bundle-Version: 1.0.0.qualifier
6+
Export-Package: org.eclipse.jdt.core.javac.configurator;x-friends:="org.eclipse.jdt.javac.ui"
7+
Bundle-Activator: org.eclipse.jdt.core.javac.configurator.JavacConfigurationActivator
8+
Bundle-Vendor: Eclipse JDT-LS
9+
Require-Bundle: org.eclipse.core.runtime
10+
Bundle-RequiredExecutionEnvironment: JavaSE-21
11+
Automatic-Module-Name: org.eclipse.jdt.core.javac.configurator
12+
Bundle-ActivationPolicy: lazy
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
instructions.configure = \
2+
setStartLevel(startLevel:3); \
3+
markStarted(started: true);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source.. = src/
2+
output.. = bin/
3+
bin.includes = META-INF/,\
4+
.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Red Hat, Inc. and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*******************************************************************************/
11+
package org.eclipse.jdt.core.javac.configurator;
12+
13+
import java.util.Map;
14+
import java.util.Objects;
15+
16+
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
17+
import org.eclipse.core.runtime.preferences.InstanceScope;
18+
import org.osgi.framework.BundleActivator;
19+
import org.osgi.framework.BundleContext;
20+
21+
/// Activates the bundle, configure system properties according to preferences
22+
/// and set up preference listener.
23+
///
24+
/// ⚠️ This bundle must *NOT* depend on JDT Core, as it has to start before.
25+
/// It also deals with startLevels and autostart (in p2.inf), keep it minimal
26+
public class JavacConfigurationActivator implements BundleActivator {
27+
28+
/// Value can be {@link #ENABLED} or {@link #DISABLED} as we want to distinguish
29+
/// unset vs false and boolean preferences don't allow that
30+
/// TODO consider drill down to individual properties?
31+
public static final String PREF_JAVAC_ENABLED = "javacEnabled";
32+
public static String ENABLED = "enabled";
33+
public static String DISABLED = "disabled";
34+
35+
/// Those are the value of system properties to fully enable Javac backend
36+
public static Map<String, String> SYSTEM_PROPERTIES = Map.of(
37+
"ICompilationUnitResolver", "org.eclipse.jdt.core.dom.JavacCompilationUnitResolver",
38+
"AbstractImageBuilder.compilerFactory", "org.eclipse.jdt.internal.javac.JavacCompilerFactory",
39+
"CompilationUnit.DOM_BASED_OPERATIONS", "true",
40+
"ICompletionEngineProvider", "org.eclipse.jdt.core.dom.DOMCompletionEngineProvider",
41+
"SourceIndexer.DOM_BASED_INDEXER", "true",
42+
"MatchLocator.DOM_BASED_MATCH", "true",
43+
"IJavaSearchDelegate", "org.eclipse.jdt.internal.core.search.DOMJavaSearchDelegate");
44+
45+
private static BundleContext context;
46+
private static JavacConfigurationActivator instance;
47+
private IEclipsePreferences instancePreferences;
48+
49+
public JavacConfigurationActivator() {
50+
instance = this;
51+
}
52+
public static JavacConfigurationActivator getInstance() {
53+
return instance;
54+
}
55+
56+
static BundleContext getContext() {
57+
return context;
58+
}
59+
60+
public void start(BundleContext bundleContext) throws Exception {
61+
JavacConfigurationActivator.context = bundleContext;
62+
instancePreferences = InstanceScope.INSTANCE.getNode(symbolicName());
63+
// ensure the initial value is available from preference store
64+
instancePreferences.put(PREF_JAVAC_ENABLED, isJavacEnabled() ? ENABLED : DISABLED);
65+
instancePreferences.flush();
66+
instancePreferences.addPreferenceChangeListener(event -> {
67+
refreshSystemProperties();
68+
});
69+
refreshSystemProperties();
70+
}
71+
public static String symbolicName() {
72+
return JavacConfigurationActivator.context.getBundle().getSymbolicName();
73+
}
74+
75+
private void refreshSystemProperties() {
76+
// Those need to be in sync with system properties usually
77+
// added to eclipse.ini thanks to p2.inf instructions
78+
if (isJavacEnabled()) {
79+
SYSTEM_PROPERTIES.entrySet().forEach(e -> System.setProperty(e.getKey(), e.getValue()));
80+
} else {
81+
SYSTEM_PROPERTIES.keySet().forEach(System::clearProperty);
82+
}
83+
}
84+
85+
public boolean isJavacEnabled() {
86+
boolean enabled = System.getProperty("ICompilationUnitResolver", "").toLowerCase().contains("javac");
87+
String pref = instancePreferences.get(PREF_JAVAC_ENABLED, null);
88+
if (pref != null) {
89+
enabled = Objects.equals(pref, ENABLED);
90+
}
91+
return enabled;
92+
}
93+
94+
public void stop(BundleContext bundleContext) throws Exception {
95+
JavacConfigurationActivator.context = null;
96+
}
97+
98+
}

org.eclipse.jdt.core.javac.feature/feature.xml

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<feature
3+
id="org.eclipse.jdt.javac.feature"
4+
label="Javac backend for JDT integration in Eclipse IDE"
5+
version="1.0.0.qualifier">
6+
7+
<plugin
8+
id="org.eclipse.jdt.core.javac"
9+
version="0.0.0"/>
10+
<plugin
11+
id="org.eclipse.jdt.core.javac.configurator"
12+
version="0.0.0"/>
13+
<plugin
14+
id="org.eclipse.jdt.javac.ui"
15+
version="0.0.0"/>
16+
17+
</feature>

0 commit comments

Comments
 (0)