Skip to content
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

fix: Properly support non-Java Bazel 8 projects in IntelliJ #7006

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void prepareProjectAspect(Project project) throws SyncFailedException {
final var templateAspects = AspectRepositoryProvider.findAspectTemplateDirectory()
.orElseThrow(() -> new SyncFailedException("Couldn't find aspect template directory"));

writeJavaInfo(manager, realizedAspectsPath, templateAspects);
writeJavaInfo(manager, realizedAspectsPath, templateAspects, project);
writeCodeGeneratorInfo(manager, project, realizedAspectsPath, templateAspects);
}

Expand Down Expand Up @@ -106,25 +106,29 @@ private void writeCodeGeneratorInfo(
}

private void writeJavaInfo(
BlazeProjectDataManager manager,
Path realizedAspectsPath,
File templateAspects) throws SyncFailedException {
BlazeProjectDataManager manager,
Path realizedAspectsPath,
File templateAspects, Project project) throws SyncFailedException {
var realizedFile = realizedAspectsPath.resolve(REALIZED_JAVA);
var templateWriter = new TemplateWriter(templateAspects.toPath());
var templateVariableMap = getJavaStringStringMap(manager);
var templateVariableMap = getJavaStringStringMap(manager, project);
if (!templateWriter.writeToFile(TEMPLATE_JAVA, realizedFile, templateVariableMap)) {
throw new SyncFailedException("Could not create template for: " + REALIZED_JAVA);
}
}

private static @NotNull Map<String, String> getJavaStringStringMap(BlazeProjectDataManager manager) {
private static @NotNull Map<String, String> getJavaStringStringMap(BlazeProjectDataManager manager, Project project) throws SyncFailedException {
var projectData = Optional.ofNullable(manager.getBlazeProjectData()); // It can be empty on intial sync. Fall back to no lauguage support
var blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
var activeLanguages = projectData.map(it -> it.getWorkspaceLanguageSettings().getActiveLanguages()).orElse(ImmutableSet.of());
var isJavaEnabled = activeLanguages.contains(LanguageClass.JAVA)
&& blazeProjectData != null
&& blazeProjectData.getExternalWorkspaceData().getByRepoName("rules_java") != null;
var isAtLeastBazel8 = projectData.map(it -> it.getBlazeVersionData().bazelIsAtLeastVersion(8, 0, 0)).orElse(false);
return Map.of(
"bazel8OrAbove", isAtLeastBazel8 ? "true" : "false",
"isJavaEnabled", activeLanguages.contains(LanguageClass.JAVA) ? "true" : "false"
);
return Map.of(
"bazel8OrAbove", isAtLeastBazel8 ? "true" : "false",
"isJavaEnabled", isJavaEnabled ? "true" : "false"
);
}

private static List<String> ruleNamesForLanguageClass(LanguageClass languageClass, ProjectViewSet viewSet) {
Expand Down
Loading