diff --git a/base/src/com/google/idea/blaze/base/sync/aspects/strategy/SyncAspectTemplateProvider.java b/base/src/com/google/idea/blaze/base/sync/aspects/strategy/SyncAspectTemplateProvider.java index 7f56bb247be..020146ae02d 100644 --- a/base/src/com/google/idea/blaze/base/sync/aspects/strategy/SyncAspectTemplateProvider.java +++ b/base/src/com/google/idea/blaze/base/sync/aspects/strategy/SyncAspectTemplateProvider.java @@ -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); } @@ -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 getJavaStringStringMap(BlazeProjectDataManager manager) { + private static @NotNull Map 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 ruleNamesForLanguageClass(LanguageClass languageClass, ProjectViewSet viewSet) {