How I can get target JDK version in ClassProcessingBuilder?

Answered

I need to change the behavior of the IDEA compiler-plugin depending on the target Java version. 

How do I find this information?

PS: My class extends org.jetbrains.jps.incremental.instrumentation.ClassProcessingBuilder

7 comments
Avatar
Permanently deleted user
Comment actions Permalink

Hi Alexey,,

In IDEA, the JDK is set on a per-module basis, so the builder depends on this parameter, it should be ready to act differently for each module. There is a ModuleChunk object passed to In performBuild() method of your builder. The ModuleChunk represents a single module or a module cycle. If there are more than 1 module in the chunk, the JPS enforces constraint that all these modules have the same JDK associated.

You can retrieve the version information using the code like this:

static int getAssociatedSdkVersion(ModuleChunk chunk) {
// assuming all modules in the chunk have the same associated JDK;
// this constraint should be validated on build start
final JpsSdk<JpsDummyElement> sdk = chunk.representativeTarget().getModule().getSdk(JpsJavaSdkType.INSTANCE);
return JpsJavaSdkType.parseVersion(sdk != null? sdk.getVersionString() : null);
}
0
Comment actions Permalink

Thanks!

Судя по всему проще так...

 

А у вас не появилось в публичном репозитории jps-builders? А то не хочется обновлять это извращение https://github.com/maxifier/mxcache/tree/master/mxcache-idea-api-stubs

а текущая версия не поддерживает этого счастья с JpsSdk и ModuleBuildTarget.

0
Avatar
Permanently deleted user
Comment actions Permalink

jps-builders же часть community edition, должно быть доступно в общем репозитории

0
Comment actions Permalink

В github нашёл, но в maven-central нету. Может где-то есть в другом? Хранить у себя jar'ку странно как-то.

0
Comment actions Permalink

1. Всё же - есть ли (точнее нет- БУДЕТ ли) официально выложен проект jps-builders в мавен-централ? Неофициальные-то есть, но я лучше сам выложу.

2. Как соотнести тэги проекта (типа webstort/142.3016) и версии idea? Ломалась ли обратная совместимость? Чтобы свой плагин можно было в старые версии IDEA ставить.

0
Comment actions Permalink

1. У нас есть планы выложить артефакты jps-builders в публичный репозиторий, но точных сроков пока назвать не могу. Сейчас мы выкладываем архивы IDEA целиком, и наш официальный intellij-gradle-plugin умеет их оттуда скачивать, распаковывать и подключать отдельные JAR как зависимости.

2. Тэги в исходниках соответствуют номерам билдов, нумерация билдов сквозная по всем нашим IDE. Обратная совместимость иногда ломается, единственный надёжный способ проверки - поставить плагин в нужную версию IDE. Тот же intellij-gradle-plugin упрощает это, достаточно поменять версию IDEA в build.gradle и запустить.

0
Comment actions Permalink

1. Увы, это не подходит для библиотеки, выкладываемой на mvnrepository.com

2. Спасибо, понятно!

0

Please sign in to leave a comment.