Skip to content

Commit 8e717d1

Browse files
authored
Massive updat to IJ Aspects (#515)
* Fix target platform to not bring in transitives The transitives cause issues in self-hosted Eclipse with duplicate bundles. We should be a good citizen and not contribute duplicate bundles to the target platform. * Add duplicate Guava because See protocolbuffers/protobuf#21173 * Launch configs * Remove singleton pattern from info cache class The lifetime of the cache is tightly coupled to the model manager. Thus, it makes sense to move this into the model manager class, which forces better design. * Fix a problem where errors are not propagated properly to the UI * Massive update to IJ Aspects The IJ Aspects progressed quite a bit. A new templating system was introduced to create aspects with different behavior depending on the Bazel version. Additional the design was modified so that aspects are no longer added as a repository but become part of the workspace, i.e. they are copied into the workspace during sync. This seems to work better with Bazel caching (according to the IJ Aspects commit history). When importing aspects we no longer consume them as a repository. Instead we build them directly in the IJ repository and then copy & extract into our zip archive. The zip archive is later extracted into a temp location for better working with multiple Bazel workspaces. * Add macOS cache location
1 parent ba9f253 commit 8e717d1

27 files changed

Lines changed: 3502 additions & 220 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ jobs:
6666
path: |
6767
~/.cache/bazel
6868
~/.cache/bazelisk
69+
/var/tmp/_bazel_*
6970
key: ${{ runner.os }}-bazel
7071

7172
- name: Setup Bazelisk

bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/BazelElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected final I getInfo() throws CoreException {
142142
}
143143

144144
BazelElementInfoCache getInfoCache() {
145-
return BazelElementInfoCache.getInstance();
145+
return getModel().getModelManager().getModelInfoCache();
146146
}
147147

148148
/**

bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/BazelModelManager.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
* It's intended to be used as a singleton. There must only be one instance during the entire lifetime of the IDE. This
5252
* instance is managed by {@link BazelCorePlugin}.
5353
* </p>
54+
* <p>
55+
* In general the model manager is considered an internal manager to the model. It should only be interacted with from
56+
* within the model. Please reach out if you have a different use case.
57+
* </p>
5458
*/
5559
public class BazelModelManager implements BazelCoreSharedContstants {
5660

@@ -121,16 +125,16 @@ public void saving(ISaveContext context) throws CoreException {
121125
// TODO: save all existing Bazel mappings
122126
}
123127
};
124-
private final IPath stateLocation;
125128

129+
private final IPath stateLocation;
126130
private final BazelModel model;
127131

128132
private final JobsBasedExecutionService executionService =
129133
new JobsBasedExecutionService(new ExtensibleCommandExecutor());
130134

131-
private BazelClasspathManager classpathManager;
132-
133-
private IntellijAspects aspects;
135+
private volatile BazelClasspathManager classpathManager;
136+
private volatile BazelElementInfoCache cache;
137+
private volatile IntellijAspects aspects;
134138

135139
/**
136140
* Creates a new model manager instance
@@ -140,7 +144,7 @@ public void saving(ISaveContext context) throws CoreException {
140144
*/
141145
public BazelModelManager(IPath stateLocation) {
142146
this.stateLocation = stateLocation;
143-
this.model = new BazelModel(this);
147+
model = new BazelModel(this);
144148
resourceChangeProcessor = new ResourceChangeProcessor(this);
145149
}
146150

@@ -152,7 +156,7 @@ public BazelProject getBazelProject(IProject project) {
152156
* @return the classpath manager used by this model manager
153157
*/
154158
public BazelClasspathManager getClasspathManager() {
155-
return requireNonNull(classpathManager, "not initialized");
159+
return requireNonNull(classpathManager, "The model manager is not initialized!");
156160
}
157161

158162
/**
@@ -166,15 +170,22 @@ BazelModelCommandExecutionService getExecutionService() {
166170
* {@return the aspects used by the model}
167171
*/
168172
public IntellijAspects getIntellijAspects() {
169-
return requireNonNull(aspects, "Not initialized!");
173+
return requireNonNull(aspects, "The model manager is not initialized!");
170174
}
171175

172176
public BazelModel getModel() {
173177
return model;
174178
}
175179

176180
/**
177-
* @return the resource change processor
181+
* {@return the singleton instance of the {@link BazelElementInfoCache} used by the model}
182+
*/
183+
public BazelElementInfoCache getModelInfoCache() {
184+
return requireNonNull(cache, "The model manager is not initialized!");
185+
}
186+
187+
/**
188+
* {@return the resource change processor}
178189
*/
179190
ResourceChangeProcessor getResourceChangeProcessor() {
180191
return resourceChangeProcessor;
@@ -205,12 +216,10 @@ public void initialize(IWorkspace workspace) throws Exception {
205216
}
206217

207218
// configure cache
208-
BazelElementInfoCache.setInstance(
209-
new CaffeineBasedBazelElementInfoCache(getCacheMaximumSize(), getCacheExpireAfterAccessDuration()));
219+
cache = new CaffeineBasedBazelElementInfoCache(getCacheMaximumSize(), getCacheExpireAfterAccessDuration());
210220

211221
// ensure aspects are usable
212222
aspects = new IntellijAspects(stateLocation.append("intellij-aspects").toPath());
213-
aspects.makeAvailable();
214223

215224
// initialize the classpath manager
216225
classpathManager = new BazelClasspathManager(stateLocation.toFile(), this);
@@ -281,5 +290,10 @@ public void shutdown() {
281290
}
282291
workspace.removeResourceChangeListener(resourceChangeProcessor);
283292
workspace.removeSaveParticipant(PLUGIN_ID);
293+
294+
// unset references
295+
cache = null;
296+
aspects = null;
297+
classpathManager = null;
284298
}
285299
}

bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/SynchronizeProjectViewJob.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,16 @@ private void initializeClasspaths(List<BazelProject> projects, BazelWorkspace wo
515515
monitor = monitor.split(work, format("Initializing Classpaths for %d projects", projects.size()));
516516

517517
// use the job to properly trigger the classpath manager
518-
new InitializeOrRefreshClasspathJob(
518+
var status = new InitializeOrRefreshClasspathJob(
519519
projects.contains(workspace.getBazelProject()) ? projects.stream()
520520
: concat(Stream.of(workspace.getBazelProject()), projects.stream()),
521521
workspace.getParent().getModelManager().getClasspathManager(),
522522
true).runInWorkspace(monitor);
523+
524+
// re-throw any error so we get proper reporting in the UI
525+
if (status.matches(IStatus.ERROR)) {
526+
throw new CoreException(status);
527+
}
523528
}
524529

525530
private void logSyncStats(String workspaceName, Duration duration, int projectsCount, int targetsCount,

bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/cache/BazelElementInfoCache.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
*/
1414
package com.salesforce.bazel.eclipse.core.model.cache;
1515

16-
import static java.util.Objects.requireNonNull;
17-
1816
import java.util.Collection;
19-
import java.util.concurrent.atomic.AtomicReference;
2017

2118
import com.salesforce.bazel.eclipse.core.model.BazelElement;
2219
import com.salesforce.bazel.eclipse.core.model.BazelElementInfo;
@@ -36,37 +33,6 @@
3633
*/
3734
public abstract sealed class BazelElementInfoCache permits CaffeineBasedBazelElementInfoCache {
3835

39-
private static final AtomicReference<BazelElementInfoCache> cacheRef = new AtomicReference<>();
40-
41-
/**
42-
* Returns the singleton cache instance
43-
*
44-
* @return the singleton cache instance (never <code>null</code>)
45-
* @throws IllegalStateException
46-
* if the cache has not been initalized yet
47-
*/
48-
public static final BazelElementInfoCache getInstance() throws IllegalStateException {
49-
var cache = cacheRef.get();
50-
if (cache == null) {
51-
throw new IllegalStateException("BazelElementInfoCache not initialized.");
52-
}
53-
return cache;
54-
}
55-
56-
/**
57-
* Initializes the singleton instance.
58-
*
59-
* @param cache
60-
* the singleton instance
61-
* @throws IllegalStateException
62-
* if the singleton cache instance was already initialized
63-
*/
64-
public static final void setInstance(BazelElementInfoCache cache) throws IllegalStateException {
65-
if (!cacheRef.compareAndSet(null, requireNonNull(cache, "Cannot initialize NULL instance"))) {
66-
throw new IllegalStateException("The cache was already initialized. Cannot initialize multiple times!");
67-
}
68-
}
69-
7036
/**
7137
* Collects all elements available in the cache for the given workspace.
7238
*

bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/JavaAspectsInfo.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ static boolean isJavaProtoTarget(TargetIdeInfo target) {
7474
}
7575

7676
final ParsedBepOutput aspectsBuildResult;
77+
final IntellijAspects intellijAspects;
7778

7879
/** index of all aspects loaded from the build output */
7980
final Map<TargetKey, TargetIdeInfo> ideInfoByTargetKey;
@@ -84,9 +85,11 @@ static boolean isJavaProtoTarget(TargetIdeInfo target) {
8485
/** index of jars based on their root relative path, which allows lookup of jdeps entries */
8586
final Map<String, BlazeJarLibrary> libraryByJdepsRootRelativePath;
8687

87-
public JavaAspectsInfo(ParsedBepOutput aspectsBuildResult, BazelWorkspace bazelWorkspace) throws CoreException {
88+
public JavaAspectsInfo(ParsedBepOutput aspectsBuildResult, BazelWorkspace bazelWorkspace,
89+
IntellijAspects intellijAspects) throws CoreException {
8890
super(bazelWorkspace);
8991
this.aspectsBuildResult = aspectsBuildResult;
92+
this.intellijAspects = intellijAspects;
9093

9194
// build maps
9295
ideInfoByTargetKey = new HashMap<>();
@@ -102,7 +105,7 @@ public JavaAspectsInfo(ParsedBepOutput aspectsBuildResult, BazelWorkspace bazelW
102105
if (LOG.isDebugEnabled()) {
103106
LOG.debug("Processing aspect: {}", outputArtifact);
104107
}
105-
var targetIdeInfo = TargetIdeInfo.fromProto(getAspects().readAspectFile(outputArtifact));
108+
var targetIdeInfo = TargetIdeInfo.fromProto(intellijAspects.readAspectFile(outputArtifact));
106109
if (targetIdeInfo == null) {
107110
if (LOG.isDebugEnabled()) {
108111
LOG.debug("Skipping empty aspect: {}", outputArtifact);
@@ -210,10 +213,6 @@ public TargetIdeInfo get(TargetKey targetKey) {
210213
return ideInfoByTargetKey.get(targetKey);
211214
}
212215

213-
public IntellijAspects getAspects() {
214-
return bazelWorkspace.getParent().getModelManager().getIntellijAspects();
215-
}
216-
217216
public List<BlazeJarLibrary> getLibraries(TargetKey targetKey) {
218217
return librariesByTargetKey.get(targetKey);
219218
}

bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/ProjectPerPackageProvisioningStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public Map<BazelProject, CompileAndRuntimeClasspath> computeClasspaths(Collectio
183183
currentShardCount,
184184
shardsToBuild.size(),
185185
targetsToBuild.size()));
186-
var aspectsInfo = new JavaAspectsInfo(result, workspace);
186+
var aspectsInfo = new JavaAspectsInfo(result, workspace, aspects);
187187
for (BazelProject bazelProject : shard.keySet()) {
188188
subMonitor.subTask(bazelProject.getName());
189189
subMonitor.checkCanceled();

bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/ProjectPerTargetProvisioningStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public Map<BazelProject, CompileAndRuntimeClasspath> computeClasspaths(Collectio
108108

109109
// populate map from result
110110
Map<BazelProject, CompileAndRuntimeClasspath> classpathsByProject = new HashMap<>();
111-
var aspectsInfo = new JavaAspectsInfo(result, workspace);
111+
var aspectsInfo = new JavaAspectsInfo(result, workspace, aspects);
112112
for (BazelProject bazelProject : bazelProjects) {
113113
monitor.subTask(bazelProject.getName());
114114
monitor.checkCanceled();

bundles/com.salesforce.bazel.eclipse.jdtls/.settings/JDT.LS Bazel.launch

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<booleanAttribute key="automaticAdd" value="false"/>
88
<booleanAttribute key="automaticValidate" value="false"/>
99
<stringAttribute key="bootstrap" value=""/>
10-
<stringAttribute key="checked" value="com.salesforce.bazel.eclipse.core,com.salesforce.bazel.sdk"/>
10+
<stringAttribute key="checked" value="[NONE]"/>
1111
<booleanAttribute key="clearConfig" value="false"/>
1212
<booleanAttribute key="clearws" value="true"/>
1313
<booleanAttribute key="clearwslog" value="false"/>
@@ -42,11 +42,9 @@
4242
<setEntry value="bcprov@default:default"/>
4343
<setEntry value="ch.qos.logback.classic@2:true"/>
4444
<setEntry value="ch.qos.logback.core@default:default"/>
45-
<setEntry value="com.github.ben-manes.caffeine.guava@default:default"/>
4645
<setEntry value="com.github.ben-manes.caffeine@default:default"/>
4746
<setEntry value="com.google.gson@default:default"/>
48-
<setEntry value="com.google.guava*32.1.3.jre@default:default"/>
49-
<setEntry value="com.google.guava.failureaccess*1.0.2@default:default"/>
47+
<setEntry value="com.google.guava.failureaccess@default:default"/>
5048
<setEntry value="com.ibm.icu@default:default"/>
5149
<setEntry value="com.sun.jna.platform@default:default"/>
5250
<setEntry value="com.sun.jna@default:default"/>
@@ -58,12 +56,11 @@
5856
<setEntry value="org.apache.ant@default:default"/>
5957
<setEntry value="org.apache.aries.spifly.dynamic.bundle@1:true"/>
6058
<setEntry value="org.apache.commons.cli@default:default"/>
61-
<setEntry value="org.apache.commons.commons-codec*1.16.0@default:default"/>
59+
<setEntry value="org.apache.commons.commons-codec@default:default"/>
6260
<setEntry value="org.apache.commons.commons-compress@default:default"/>
6361
<setEntry value="org.apache.commons.commons-io@default:default"/>
64-
<setEntry value="org.apache.commons.jxpath*1.3.0.v200911051830@default:default"/>
65-
<setEntry value="org.apache.commons.lang3*3.13.0@default:default"/>
66-
<setEntry value="org.apache.commons.logging*1.2.0.v20180409-1502@default:default"/>
62+
<setEntry value="org.apache.commons.jxpath@default:default"/>
63+
<setEntry value="org.apache.commons.logging@default:default"/>
6764
<setEntry value="org.apache.felix.gogo.command@default:default"/>
6865
<setEntry value="org.apache.felix.gogo.runtime@default:default"/>
6966
<setEntry value="org.apache.felix.gogo.shell@default:default"/>
@@ -162,7 +159,6 @@
162159
<setEntry value="org.eclipse.xtext.xbase.lib@default:default"/>
163160
<setEntry value="org.fusesource.jansi@default:default"/>
164161
<setEntry value="org.gradle.toolingapi@default:default"/>
165-
<setEntry value="org.hamcrest.core@default:default"/>
166162
<setEntry value="org.hamcrest@default:default"/>
167163
<setEntry value="org.jsr-305@default:default"/>
168164
<setEntry value="org.junit@default:default"/>
@@ -189,7 +185,6 @@
189185
<setEntry value="org.tukaani.xz@default:default"/>
190186
<setEntry value="slf4j.api@2:true"/>
191187
<setEntry value="wrapped.com.google.auto.value.auto-value-annotations@default:default"/>
192-
<setEntry value="wrapped.com.google.protobuf.protobuf-java@default:default"/>
193188
</setAttribute>
194189
<setAttribute key="selected_workspace_bundles">
195190
<setEntry value="com.salesforce.bazel.eclipse.core@default:default"/>
@@ -200,7 +195,7 @@
200195
<booleanAttribute key="show_selected_only" value="false"/>
201196
<stringAttribute key="templateConfig" value="${target_home}/configuration/config.ini"/>
202197
<stringAttribute key="timestamp" value="1708258207165"/>
203-
<booleanAttribute key="tracing" value="true"/>
198+
<booleanAttribute key="tracing" value="false"/>
204199
<mapAttribute key="tracingOptions">
205200
<mapEntry key="com.perforce.team.core/debug" value="false"/>
206201
<mapEntry key="com.perforce.team.core/debug/activation" value="false"/>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<launchConfiguration type="org.eclipse.pde.ui.RuntimeWorkbench">
3+
<booleanAttribute key="append.args" value="true"/>
4+
<booleanAttribute key="askclear" value="true"/>
5+
<booleanAttribute key="automaticAdd" value="true"/>
6+
<booleanAttribute key="automaticValidate" value="true"/>
7+
<stringAttribute key="bootstrap" value=""/>
8+
<stringAttribute key="checked" value="[NONE]"/>
9+
<booleanAttribute key="clearConfig" value="true"/>
10+
<booleanAttribute key="clearws" value="false"/>
11+
<booleanAttribute key="clearwslog" value="false"/>
12+
<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/Bazel Eclipse"/>
13+
<booleanAttribute key="default" value="true"/>
14+
<booleanAttribute key="includeOptional" value="true"/>
15+
<stringAttribute key="location" value="${workspace_loc}/../runtime-bazel-eclipse"/>
16+
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
17+
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
18+
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>
19+
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
20+
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
21+
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -console"/>
22+
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
23+
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dorg.eclipse.swt.graphics.Resource.reportNonDisposed=true"/>
24+
<stringAttribute key="pde.version" value="3.3"/>
25+
<stringAttribute key="product" value="org.eclipse.sdk.ide"/>
26+
<setAttribute key="selected_target_bundles">
27+
<setEntry value="ch.qos.logback.classic@2:true"/>
28+
<setEntry value="org.apache.aries.spifly.dynamic.bundle@1:true"/>
29+
<setEntry value="org.apache.felix.scr@1:true"/>
30+
<setEntry value="org.eclipse.core.runtime@default:true"/>
31+
<setEntry value="org.eclipse.osgi.compatibility.state@default:false"/>
32+
<setEntry value="org.eclipse.osgi@-1:true"/>
33+
<setEntry value="slf4j.api@2:true"/>
34+
</setAttribute>
35+
<booleanAttribute key="show_selected_only" value="false"/>
36+
<stringAttribute key="templateConfig" value="${target_home}/configuration/config.ini"/>
37+
<booleanAttribute key="tracing" value="false"/>
38+
<booleanAttribute key="useCustomFeatures" value="false"/>
39+
<booleanAttribute key="useDefaultConfig" value="true"/>
40+
<booleanAttribute key="useDefaultConfigArea" value="true"/>
41+
<booleanAttribute key="useProduct" value="true"/>
42+
</launchConfiguration>

0 commit comments

Comments
 (0)