Skip to content

Commit 22a2934

Browse files
committed
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.
1 parent 4d9e123 commit 22a2934

File tree

19 files changed

+3372
-140
lines changed

19 files changed

+3372
-140
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ public void initialize(IWorkspace workspace) throws Exception {
220220

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

225224
// initialize the classpath manager
226225
classpathManager = new BazelClasspathManager(stateLocation.toFile(), this);

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.sdk/META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ Export-Package: com.salesforce.bazel.sdk;uses:="org.osgi.framework,org.eclipse.c
3030
Import-Package: com.google.common.annotations;version="32.1.2",
3131
com.google.common.collect;version="32.1.2",
3232
com.google.protobuf;version="3.22.0",
33+
org.apache.velocity;version="[2.4.0,3.0.0)",
34+
org.apache.velocity.app;version="[2.4.0,3.0.0)",
35+
org.apache.velocity.context;version="[2.4.0,3.0.0)",
3336
org.eclipse.core.runtime;version="[3.7.0,4.0.0)",
3437
org.fusesource.jansi;version="2.4.0",
3538
org.osgi.framework;version="[1.10.0,2.0.0)",

bundles/com.salesforce.bazel.sdk/aspects/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@ The update is a bit automated.
1616

1717
### Notes
1818

19-
If you get a build error about `no such package '@intellij_....//'` copy the relevant `http_archive` entry from the [IJ WORKSPACE file](https://github.com/bazelbuild/intellij/blob/master/WORKSPACE) and add it to `import/WORKSPACE`.
20-
21-
19+
Depending on the changes upstream you have to do quite some work to get it back going.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.4.1
1+
8.1.1
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# external repo
2-
intellij/
3-
intellij_platform_sdk/
1+
# external repo and outputs
2+
intellij*
3+
aspect_*.jar
44

55
# bazel symlinks
66
bazel-*

bundles/com.salesforce.bazel.sdk/aspects/import/BUILD

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,56 @@
1+
load("@aspect_bazel_lib//lib:run_binary.bzl", "run_binary")
2+
load("@bazel_skylib//rules:write_file.bzl", "write_file")
13
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files", "pkg_mkdirs", "strip_prefix")
24
load("@rules_pkg//pkg:zip.bzl", "pkg_zip")
35

6+
write_file(
7+
name = "generate_extract_aspect_lib_jar_sh",
8+
out = "extract_aspect_lib_jar.sh",
9+
content = [
10+
"#!/usr/bin/env bash",
11+
"set -o errexit -o nounset -o pipefail",
12+
"$JAVABASE/bin/jar xf $2 || fail \"Failed to extract $2\"",
13+
"$JAVABASE/bin/jar xf $3 || fail \"Failed to extract $3\"",
14+
"mkdir -p $1",
15+
"mv aspect/* $1",
16+
],
17+
is_executable = True,
18+
)
19+
20+
sh_binary(
21+
name = "extract_aspect_lib_jar_binary",
22+
srcs = [":extract_aspect_lib_jar.sh"],
23+
)
24+
25+
run_binary(
26+
name = "aspect_lib",
27+
srcs = [
28+
"aspect_lib.jar",
29+
"aspect_template_lib.jar",
30+
"@bazel_tools//tools/jdk:current_java_runtime",
31+
],
32+
args = [
33+
"$(@D)",
34+
"$(location aspect_lib.jar)",
35+
"$(location aspect_template_lib.jar)",
36+
],
37+
env = {
38+
"JAVABASE": "$(JAVABASE)",
39+
},
40+
out_dirs = ["aspect_lib"],
41+
progress_message = "Extracting aspect_lib.jar and aspect_template_lib.jar",
42+
tool = ":extract_aspect_lib_jar_binary",
43+
toolchains = [
44+
"@bazel_tools//tools/jdk:current_java_runtime",
45+
],
46+
)
47+
448
pkg_files(
549
name = "intelli_aspects",
650
srcs = [
7-
"@intellij//aspect:aspect_files",
51+
":aspect_lib",
852
],
9-
# this magic is needed to get the jars inside the 'tools' directory
10-
strip_prefix = strip_prefix.from_pkg("//aspect"),
53+
strip_prefix = "aspect_lib/",
1154
)
1255

1356
pkg_zip(
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
###############################################################################
2-
# Bazel now uses Bzlmod by default to manage external dependencies.
3-
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
4-
#
5-
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
6-
###############################################################################
1+
module(
2+
name = "intellij_aspects_import",
3+
bazel_compatibility = [">=8.1.0"],
4+
)
5+
6+
bazel_dep(name = "aspect_bazel_lib", version = "2.14.0")
7+
bazel_dep(name = "bazel_skylib", version = "1.7.1")
8+
bazel_dep(name = "rules_pkg", version = "1.1.0")

0 commit comments

Comments
 (0)