Split IDE part from kotlinx-serialization-compiler-plugin

This commit is contained in:
Leonid Startsev
2018-09-10 17:53:12 +03:00
parent 9ca0643b1a
commit 23fd0a6ec9
47 changed files with 81 additions and 111 deletions
@@ -0,0 +1,29 @@
description = "Kotlinx Serialization IDEA Plugin"
plugins {
kotlin("jvm")
id("jps-compatible")
}
jvmTarget = "1.6"
dependencies {
compile(project(":kotlinx-serialization-compiler-plugin"))
compile(project(":idea"))
compile(project(":idea:idea-gradle"))
compile(project(":idea:idea-maven"))
compileOnly(intellijDep())
excludeInAndroidStudio(rootProject) { compileOnly(intellijPluginDep("maven")) }
compileOnly(intellijPluginDep("gradle"))
}
sourceSets {
"main" { projectDefault() }
"test" {}
}
runtimeJar()
ideaPlugin()
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlinx.serialization.idea
import com.intellij.openapi.externalSystem.model.DataNode
import com.intellij.openapi.externalSystem.model.project.ModuleData
import org.jetbrains.kotlin.idea.configuration.GradleProjectImportHandler
import org.jetbrains.kotlin.idea.facet.KotlinFacet
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
class KotlinSerializationGradleImportHandler : GradleProjectImportHandler {
override fun importBySourceSet(facet: KotlinFacet, sourceSetNode: DataNode<GradleSourceSetData>) {
KotlinSerializationImportHandler.modifyCompilerArguments(facet, PLUGIN_GRADLE_JAR)
}
override fun importByModule(facet: KotlinFacet, moduleNode: DataNode<ModuleData>) {
KotlinSerializationImportHandler.modifyCompilerArguments(facet, PLUGIN_GRADLE_JAR)
}
private val PLUGIN_GRADLE_JAR = "kotlinx-gradle-serialization-plugin"
}
@@ -0,0 +1,44 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlinx.serialization.idea
import com.intellij.util.PathUtil
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.idea.facet.KotlinFacet
import java.io.File
internal object KotlinSerializationImportHandler {
private val PLUGIN_JPS_JAR :String
get() = File(PathUtil.getJarPathForClass(this::class.java)).absolutePath
fun modifyCompilerArguments(facet: KotlinFacet, buildSystemPluginJar: String) {
val facetSettings = facet.configuration.settings
val commonArguments = facetSettings.compilerArguments ?: CommonCompilerArguments.DummyImpl()
val oldPluginClasspaths = (commonArguments.pluginClasspaths ?: emptyArray()).filterTo(mutableListOf()) {
val lastIndexOfFile = it.lastIndexOfAny(charArrayOf('/', File.separatorChar))
if (lastIndexOfFile < 0) {
return@filterTo true
}
!it.drop(lastIndexOfFile + 1).matches("$buildSystemPluginJar-.*\\.jar".toRegex())
}
val newPluginClasspaths = oldPluginClasspaths + PLUGIN_JPS_JAR
commonArguments.pluginClasspaths = newPluginClasspaths.toTypedArray()
facetSettings.compilerArguments = commonArguments
}
}
@@ -0,0 +1,18 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlinx.serialization.idea
import org.jetbrains.idea.maven.project.MavenProject
import org.jetbrains.kotlin.idea.facet.KotlinFacet
import org.jetbrains.kotlin.idea.maven.MavenProjectImportHandler
class KotlinSerializationMavenImportHandler: MavenProjectImportHandler {
override fun invoke(facet: KotlinFacet, mavenProject: MavenProject) {
KotlinSerializationImportHandler.modifyCompilerArguments(facet, PLUGIN_MAVEN_JAR)
}
private val PLUGIN_MAVEN_JAR = "kotlinx-maven-serialization-plugin"
}