Skip to content

Massive updat to IJ Aspects #515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
path: |
~/.cache/bazel
~/.cache/bazelisk
/var/tmp/_bazel_*
key: ${{ runner.os }}-bazel

- name: Setup Bazelisk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected final I getInfo() throws CoreException {
}

BazelElementInfoCache getInfoCache() {
return BazelElementInfoCache.getInstance();
return getModel().getModelManager().getModelInfoCache();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
* It's intended to be used as a singleton. There must only be one instance during the entire lifetime of the IDE. This
* instance is managed by {@link BazelCorePlugin}.
* </p>
* <p>
* In general the model manager is considered an internal manager to the model. It should only be interacted with from
* within the model. Please reach out if you have a different use case.
* </p>
*/
public class BazelModelManager implements BazelCoreSharedContstants {

Expand Down Expand Up @@ -121,16 +125,16 @@ public void saving(ISaveContext context) throws CoreException {
// TODO: save all existing Bazel mappings
}
};
private final IPath stateLocation;

private final IPath stateLocation;
private final BazelModel model;

private final JobsBasedExecutionService executionService =
new JobsBasedExecutionService(new ExtensibleCommandExecutor());

private BazelClasspathManager classpathManager;

private IntellijAspects aspects;
private volatile BazelClasspathManager classpathManager;
private volatile BazelElementInfoCache cache;
private volatile IntellijAspects aspects;

/**
* Creates a new model manager instance
Expand All @@ -140,7 +144,7 @@ public void saving(ISaveContext context) throws CoreException {
*/
public BazelModelManager(IPath stateLocation) {
this.stateLocation = stateLocation;
this.model = new BazelModel(this);
model = new BazelModel(this);
resourceChangeProcessor = new ResourceChangeProcessor(this);
}

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

/**
Expand All @@ -166,15 +170,22 @@ BazelModelCommandExecutionService getExecutionService() {
* {@return the aspects used by the model}
*/
public IntellijAspects getIntellijAspects() {
return requireNonNull(aspects, "Not initialized!");
return requireNonNull(aspects, "The model manager is not initialized!");
}

public BazelModel getModel() {
return model;
}

/**
* @return the resource change processor
* {@return the singleton instance of the {@link BazelElementInfoCache} used by the model}
*/
public BazelElementInfoCache getModelInfoCache() {
return requireNonNull(cache, "The model manager is not initialized!");
}

/**
* {@return the resource change processor}
*/
ResourceChangeProcessor getResourceChangeProcessor() {
return resourceChangeProcessor;
Expand Down Expand Up @@ -205,12 +216,10 @@ public void initialize(IWorkspace workspace) throws Exception {
}

// configure cache
BazelElementInfoCache.setInstance(
new CaffeineBasedBazelElementInfoCache(getCacheMaximumSize(), getCacheExpireAfterAccessDuration()));
cache = new CaffeineBasedBazelElementInfoCache(getCacheMaximumSize(), getCacheExpireAfterAccessDuration());

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

// initialize the classpath manager
classpathManager = new BazelClasspathManager(stateLocation.toFile(), this);
Expand Down Expand Up @@ -281,5 +290,10 @@ public void shutdown() {
}
workspace.removeResourceChangeListener(resourceChangeProcessor);
workspace.removeSaveParticipant(PLUGIN_ID);

// unset references
cache = null;
aspects = null;
classpathManager = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,16 @@ private void initializeClasspaths(List<BazelProject> projects, BazelWorkspace wo
monitor = monitor.split(work, format("Initializing Classpaths for %d projects", projects.size()));

// use the job to properly trigger the classpath manager
new InitializeOrRefreshClasspathJob(
var status = new InitializeOrRefreshClasspathJob(
projects.contains(workspace.getBazelProject()) ? projects.stream()
: concat(Stream.of(workspace.getBazelProject()), projects.stream()),
workspace.getParent().getModelManager().getClasspathManager(),
true).runInWorkspace(monitor);

// re-throw any error so we get proper reporting in the UI
if (status.matches(IStatus.ERROR)) {
throw new CoreException(status);
}
}

private void logSyncStats(String workspaceName, Duration duration, int projectsCount, int targetsCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
*/
package com.salesforce.bazel.eclipse.core.model.cache;

import static java.util.Objects.requireNonNull;

import java.util.Collection;
import java.util.concurrent.atomic.AtomicReference;

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

private static final AtomicReference<BazelElementInfoCache> cacheRef = new AtomicReference<>();

/**
* Returns the singleton cache instance
*
* @return the singleton cache instance (never <code>null</code>)
* @throws IllegalStateException
* if the cache has not been initalized yet
*/
public static final BazelElementInfoCache getInstance() throws IllegalStateException {
var cache = cacheRef.get();
if (cache == null) {
throw new IllegalStateException("BazelElementInfoCache not initialized.");
}
return cache;
}

/**
* Initializes the singleton instance.
*
* @param cache
* the singleton instance
* @throws IllegalStateException
* if the singleton cache instance was already initialized
*/
public static final void setInstance(BazelElementInfoCache cache) throws IllegalStateException {
if (!cacheRef.compareAndSet(null, requireNonNull(cache, "Cannot initialize NULL instance"))) {
throw new IllegalStateException("The cache was already initialized. Cannot initialize multiple times!");
}
}

/**
* Collects all elements available in the cache for the given workspace.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static boolean isJavaProtoTarget(TargetIdeInfo target) {
}

final ParsedBepOutput aspectsBuildResult;
final IntellijAspects intellijAspects;

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

public JavaAspectsInfo(ParsedBepOutput aspectsBuildResult, BazelWorkspace bazelWorkspace) throws CoreException {
public JavaAspectsInfo(ParsedBepOutput aspectsBuildResult, BazelWorkspace bazelWorkspace,
IntellijAspects intellijAspects) throws CoreException {
super(bazelWorkspace);
this.aspectsBuildResult = aspectsBuildResult;
this.intellijAspects = intellijAspects;

// build maps
ideInfoByTargetKey = new HashMap<>();
Expand All @@ -102,7 +105,7 @@ public JavaAspectsInfo(ParsedBepOutput aspectsBuildResult, BazelWorkspace bazelW
if (LOG.isDebugEnabled()) {
LOG.debug("Processing aspect: {}", outputArtifact);
}
var targetIdeInfo = TargetIdeInfo.fromProto(getAspects().readAspectFile(outputArtifact));
var targetIdeInfo = TargetIdeInfo.fromProto(intellijAspects.readAspectFile(outputArtifact));
if (targetIdeInfo == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Skipping empty aspect: {}", outputArtifact);
Expand Down Expand Up @@ -210,10 +213,6 @@ public TargetIdeInfo get(TargetKey targetKey) {
return ideInfoByTargetKey.get(targetKey);
}

public IntellijAspects getAspects() {
return bazelWorkspace.getParent().getModelManager().getIntellijAspects();
}

public List<BlazeJarLibrary> getLibraries(TargetKey targetKey) {
return librariesByTargetKey.get(targetKey);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public Map<BazelProject, CompileAndRuntimeClasspath> computeClasspaths(Collectio
currentShardCount,
shardsToBuild.size(),
targetsToBuild.size()));
var aspectsInfo = new JavaAspectsInfo(result, workspace);
var aspectsInfo = new JavaAspectsInfo(result, workspace, aspects);
for (BazelProject bazelProject : shard.keySet()) {
subMonitor.subTask(bazelProject.getName());
subMonitor.checkCanceled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public Map<BazelProject, CompileAndRuntimeClasspath> computeClasspaths(Collectio

// populate map from result
Map<BazelProject, CompileAndRuntimeClasspath> classpathsByProject = new HashMap<>();
var aspectsInfo = new JavaAspectsInfo(result, workspace);
var aspectsInfo = new JavaAspectsInfo(result, workspace, aspects);
for (BazelProject bazelProject : bazelProjects) {
monitor.subTask(bazelProject.getName());
monitor.checkCanceled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<booleanAttribute key="automaticAdd" value="false"/>
<booleanAttribute key="automaticValidate" value="false"/>
<stringAttribute key="bootstrap" value=""/>
<stringAttribute key="checked" value="com.salesforce.bazel.eclipse.core,com.salesforce.bazel.sdk"/>
<stringAttribute key="checked" value="[NONE]"/>
<booleanAttribute key="clearConfig" value="false"/>
<booleanAttribute key="clearws" value="true"/>
<booleanAttribute key="clearwslog" value="false"/>
Expand Down Expand Up @@ -42,11 +42,9 @@
<setEntry value="bcprov@default:default"/>
<setEntry value="ch.qos.logback.classic@2:true"/>
<setEntry value="ch.qos.logback.core@default:default"/>
<setEntry value="com.github.ben-manes.caffeine.guava@default:default"/>
<setEntry value="com.github.ben-manes.caffeine@default:default"/>
<setEntry value="com.google.gson@default:default"/>
<setEntry value="com.google.guava*32.1.3.jre@default:default"/>
<setEntry value="com.google.guava.failureaccess*1.0.2@default:default"/>
<setEntry value="com.google.guava.failureaccess@default:default"/>
<setEntry value="com.ibm.icu@default:default"/>
<setEntry value="com.sun.jna.platform@default:default"/>
<setEntry value="com.sun.jna@default:default"/>
Expand All @@ -58,12 +56,11 @@
<setEntry value="org.apache.ant@default:default"/>
<setEntry value="org.apache.aries.spifly.dynamic.bundle@1:true"/>
<setEntry value="org.apache.commons.cli@default:default"/>
<setEntry value="org.apache.commons.commons-codec*1.16.0@default:default"/>
<setEntry value="org.apache.commons.commons-codec@default:default"/>
<setEntry value="org.apache.commons.commons-compress@default:default"/>
<setEntry value="org.apache.commons.commons-io@default:default"/>
<setEntry value="org.apache.commons.jxpath*1.3.0.v200911051830@default:default"/>
<setEntry value="org.apache.commons.lang3*3.13.0@default:default"/>
<setEntry value="org.apache.commons.logging*1.2.0.v20180409-1502@default:default"/>
<setEntry value="org.apache.commons.jxpath@default:default"/>
<setEntry value="org.apache.commons.logging@default:default"/>
<setEntry value="org.apache.felix.gogo.command@default:default"/>
<setEntry value="org.apache.felix.gogo.runtime@default:default"/>
<setEntry value="org.apache.felix.gogo.shell@default:default"/>
Expand Down Expand Up @@ -162,7 +159,6 @@
<setEntry value="org.eclipse.xtext.xbase.lib@default:default"/>
<setEntry value="org.fusesource.jansi@default:default"/>
<setEntry value="org.gradle.toolingapi@default:default"/>
<setEntry value="org.hamcrest.core@default:default"/>
<setEntry value="org.hamcrest@default:default"/>
<setEntry value="org.jsr-305@default:default"/>
<setEntry value="org.junit@default:default"/>
Expand All @@ -189,7 +185,6 @@
<setEntry value="org.tukaani.xz@default:default"/>
<setEntry value="slf4j.api@2:true"/>
<setEntry value="wrapped.com.google.auto.value.auto-value-annotations@default:default"/>
<setEntry value="wrapped.com.google.protobuf.protobuf-java@default:default"/>
</setAttribute>
<setAttribute key="selected_workspace_bundles">
<setEntry value="com.salesforce.bazel.eclipse.core@default:default"/>
Expand All @@ -200,7 +195,7 @@
<booleanAttribute key="show_selected_only" value="false"/>
<stringAttribute key="templateConfig" value="${target_home}/configuration/config.ini"/>
<stringAttribute key="timestamp" value="1708258207165"/>
<booleanAttribute key="tracing" value="true"/>
<booleanAttribute key="tracing" value="false"/>
<mapAttribute key="tracingOptions">
<mapEntry key="com.perforce.team.core/debug" value="false"/>
<mapEntry key="com.perforce.team.core/debug/activation" value="false"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.pde.ui.RuntimeWorkbench">
<booleanAttribute key="append.args" value="true"/>
<booleanAttribute key="askclear" value="true"/>
<booleanAttribute key="automaticAdd" value="true"/>
<booleanAttribute key="automaticValidate" value="true"/>
<stringAttribute key="bootstrap" value=""/>
<stringAttribute key="checked" value="[NONE]"/>
<booleanAttribute key="clearConfig" value="true"/>
<booleanAttribute key="clearws" value="false"/>
<booleanAttribute key="clearwslog" value="false"/>
<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/Bazel Eclipse"/>
<booleanAttribute key="default" value="true"/>
<booleanAttribute key="includeOptional" value="true"/>
<stringAttribute key="location" value="${workspace_loc}/../runtime-bazel-eclipse"/>
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<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"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -console"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dorg.eclipse.swt.graphics.Resource.reportNonDisposed=true"/>
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="org.eclipse.sdk.ide"/>
<setAttribute key="selected_target_bundles">
<setEntry value="ch.qos.logback.classic@2:true"/>
<setEntry value="org.apache.aries.spifly.dynamic.bundle@1:true"/>
<setEntry value="org.apache.felix.scr@1:true"/>
<setEntry value="org.eclipse.core.runtime@default:true"/>
<setEntry value="org.eclipse.osgi.compatibility.state@default:false"/>
<setEntry value="org.eclipse.osgi@-1:true"/>
<setEntry value="slf4j.api@2:true"/>
</setAttribute>
<booleanAttribute key="show_selected_only" value="false"/>
<stringAttribute key="templateConfig" value="${target_home}/configuration/config.ini"/>
<booleanAttribute key="tracing" value="false"/>
<booleanAttribute key="useCustomFeatures" value="false"/>
<booleanAttribute key="useDefaultConfig" value="true"/>
<booleanAttribute key="useDefaultConfigArea" value="true"/>
<booleanAttribute key="useProduct" value="true"/>
</launchConfiguration>
Loading
Loading