diff --git a/build.gradle.kts b/build.gradle.kts index 405e584ef6d..4716dcd06c2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -115,6 +115,8 @@ extra["JDK_18"] = jdkPath("1.8") extra["JDK_9"] = jdkPathIfFound("9") extra["versions.intellij"] = "IC-172.4343.14" +extra["versions.intellijSdk"] = "172.4343.14" +extra["versions.androidBuildTools"] = "r23.0.1" extra["versions.protobuf-java"] = "2.6.1" extra["versions.javax.inject"] = "1" extra["versions.jsr305"] = "1.3.9" diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index cf1cb30f333..cb339856b8d 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -31,7 +31,12 @@ plugins { `kotlin-dsl` } -extra["versions.intellij"] = "172.4343.14" +extra["versions.intellijSdk"] = "172.4343.14" +extra["versions.androidBuildTools"] = "r23.0.1" +extra["versions.androidDxSources"] = "5.0.0_r2" + +extra["customDepsRepo"] = "$rootDir/repo" +extra["customDepsOrg"] = "kotlin.build.custom.deps" repositories { extra["buildSrcKotlinRepo"]?.let { @@ -63,4 +68,4 @@ samWithReceiver { fun Project.`samWithReceiver`(configure: org.jetbrains.kotlin.samWithReceiver.gradle.SamWithReceiverExtension.() -> Unit): Unit = extensions.configure("samWithReceiver", configure) -tasks["build"].dependsOn(":prepare-deps:android-dx:build") +tasks["build"].dependsOn(":prepare-deps:android-dx:build", ":prepare-deps:intellij-sdk:build") diff --git a/buildSrc/prepare-deps/android-dx/build.gradle.kts b/buildSrc/prepare-deps/android-dx/build.gradle.kts index 4ba355a3d0a..20a6bd51ee7 100644 --- a/buildSrc/prepare-deps/android-dx/build.gradle.kts +++ b/buildSrc/prepare-deps/android-dx/build.gradle.kts @@ -1,4 +1,8 @@ +import org.gradle.api.publish.ivy.internal.artifact.DefaultIvyArtifact +import org.gradle.api.publish.ivy.internal.publication.DefaultIvyConfiguration +import org.gradle.api.publish.ivy.internal.publication.DefaultIvyPublicationIdentity +import org.gradle.api.publish.ivy.internal.publisher.IvyDescriptorFileGenerator import java.io.File import org.gradle.internal.os.OperatingSystem import org.gradle.jvm.tasks.Jar @@ -15,16 +19,21 @@ val toolsOs by lazy { } } -val buildToolsVersion = "r23.0.1" +val buildToolsVersion = rootProject.extra["versions.androidBuildTools"] as String +val dxSourcesVersion = rootProject.extra["versions.androidDxSources"] as String repositories { ivy { artifactPattern("https://dl-ssl.google.com/android/repository/[artifact]_[revision](-[classifier]).[ext]") - artifactPattern("https://android.googlesource.com/platform/dalvik/+archive/android-5.0.0_r2/[artifact].[ext]") + artifactPattern("https://android.googlesource.com/platform/dalvik/+archive/android-$dxSourcesVersion/[artifact].[ext]") } } -val dxRepoDir = File(buildDir, "libs") +val customDepsRepoDir = File(buildDir, "repo") +val customDepsOrg: String by rootProject.extra +val dxModuleName = "android-dx" +val dxRevision = buildToolsVersion +val dxRepoModuleDir = File(customDepsRepoDir, "$customDepsOrg/$dxModuleName/$dxRevision") val buildToolsZip by configurations.creating val dxSourcesTar by configurations.creating @@ -37,12 +46,12 @@ dependencies { val unzipDxJar by tasks.creating { dependsOn(buildToolsZip) inputs.files(buildToolsZip) - outputs.files(File(dxRepoDir, "dx.jar")) + outputs.files(File(dxRepoModuleDir, "dx.jar")) doFirst { project.copy { from(zipTree(buildToolsZip.singleFile).files) include("**/dx.jar") - into(dxRepoDir) + into(dxRepoModuleDir) } } } @@ -66,15 +75,32 @@ val untarDxSources by tasks.creating { val prepareDxSourcesJar by tasks.creating(Jar::class) { dependsOn(untarDxSources) from("$dxSourcesTargetDir/src") - destinationDir = dxRepoDir + destinationDir = dxRepoModuleDir baseName = "dx" classifier = "sources" } -val build by tasks.creating { +val prepareIvyXml by tasks.creating { dependsOn(unzipDxJar, prepareDxSourcesJar) + inputs.files(unzipDxJar, prepareDxSourcesJar) + val ivyFile = File(dxRepoModuleDir, "$dxModuleName.ivy.xml") + outputs.file(ivyFile) + doLast { + with(IvyDescriptorFileGenerator(DefaultIvyPublicationIdentity(customDepsOrg, dxModuleName, dxRevision))) { + addConfiguration(DefaultIvyConfiguration("default")) + addConfiguration(DefaultIvyConfiguration("sources")) + addArtifact(DefaultIvyArtifact(File(dxRepoModuleDir, "dx.jar"), "dx", "jar", "jar", null).also { it.conf = "default" }) + addArtifact(DefaultIvyArtifact(File(dxRepoModuleDir, "dx-sources.jar"), "dx", "jar", "sources", "sources").also { it.conf = "sources" }) + writeTo(ivyFile) + } + } +} + +val build by tasks.creating { + dependsOn(unzipDxJar, prepareDxSourcesJar, prepareIvyXml) } val clean by tasks.creating(Delete::class) { + delete(dxRepoModuleDir) delete(buildDir) } diff --git a/buildSrc/prepare-deps/intellij-sdk/build.gradle.kts b/buildSrc/prepare-deps/intellij-sdk/build.gradle.kts index 05dd76222c5..b9f1f17d489 100644 --- a/buildSrc/prepare-deps/intellij-sdk/build.gradle.kts +++ b/buildSrc/prepare-deps/intellij-sdk/build.gradle.kts @@ -9,7 +9,7 @@ import org.gradle.internal.os.OperatingSystem val intellijRepo = "https://www.jetbrains.com/intellij-repository" val intellijReleaseType = "releases" // or "snapshots" val intellijSdkDependencyName = "ideaIC" // or "ideaIU" -val intellijVersion = rootProject.extra["versions.intellij"] as String +val intellijVersion = rootProject.extra["versions.intellijSdk"] as String repositories { maven { setUrl("$intellijRepo/$intellijReleaseType") } @@ -21,7 +21,11 @@ val jpsStandalone by configurations.creating val jpsBuildTest by configurations.creating val intellijCore by configurations.creating -val repoDir = File(buildDir, "repo") +val customDepsRepoDir = File(buildDir, "repo") +val customDepsOrg: String by rootProject.extra +val customDepsRevision = intellijVersion +val customDepsRepoModulesDir = File(customDepsRepoDir, "$customDepsOrg/$customDepsRevision") +val repoDir = customDepsRepoModulesDir dependencies { intellijSdk("com.jetbrains.intellij.idea:$intellijSdkDependencyName:$intellijVersion") @@ -54,51 +58,54 @@ val copyIntellijSdkSources by tasks.creating { configureExtractFromConfiguration val copyJpsBuildTest by tasks.creating { configureExtractFromConfigurationTask(jpsBuildTest) { it.singleFile } } -fun createIvyDependency(baseDir: File, file: File, configuration: String, extension: String?, type: String) : DefaultIvyArtifact { - val relativePath = baseDir.toURI().relativize(file.toURI()).path - val name = if (extension != null) relativePath.removeSuffix(".$extension") else relativePath - val artifact = DefaultIvyArtifact(file, name, extension, type, null) - artifact.conf = configuration - return artifact -} - -fun makeIvyXml(name: String, ivyFile: File, jarFiles: FileCollection, baseDir: File, sourcesJar: File): File { - val generator = IvyDescriptorFileGenerator(DefaultIvyPublicationIdentity("com.jetbrains", name, intellijVersion)) - generator.addConfiguration(DefaultIvyConfiguration("default")) - generator.addConfiguration(DefaultIvyConfiguration("compile")) - generator.addConfiguration(DefaultIvyConfiguration("sources")) - jarFiles.forEach { - generator.addArtifact(createIvyDependency(baseDir, it, "compile", "jar", "jar")) +fun writeIvyXml(moduleName: String, jarFiles: FileCollection, baseDir: File, sourcesJar: File) { + with(IvyDescriptorFileGenerator(DefaultIvyPublicationIdentity(customDepsOrg, moduleName, intellijVersion))) { + addConfiguration(DefaultIvyConfiguration("default")) + addConfiguration(DefaultIvyConfiguration("sources")) + jarFiles.asFileTree.files.forEach { + if (it.isFile && it.extension == "jar") { + val relativeName = it.toRelativeString(baseDir).removeSuffix(".jar") + addArtifact(DefaultIvyArtifact(it, relativeName, "jar", "jar", null).also { it.conf = "default" }) + } + } + val sourcesArtifactName = sourcesJar.name.removeSuffix(".jar").substringBefore("-") + addArtifact(DefaultIvyArtifact(sourcesJar, sourcesArtifactName, "jar", "sources", "sources").also { it.conf = "sources" }) + writeTo(File(customDepsRepoModulesDir, "$moduleName.ivy.xml")) } - val relativeSourcesPath = baseDir.toURI().relativize(sourcesJar.parentFile.toURI()).path - val sourcesArtifactName = sourcesJar.name.removeSuffix(".jar").substringBefore("-") - val artifact = DefaultIvyArtifact(sourcesJar, "$relativeSourcesPath/$sourcesArtifactName", "jar", "sources", "sources") - artifact.conf = "sources" - generator.addArtifact(artifact) - generator.writeTo(ivyFile) - return ivyFile } val prepareIvyXml by tasks.creating { dependsOn(unzipIntellijSdk, unzipIntellijCore, unzipJpsStandalone, copyIntellijSdkSources, copyJpsBuildTest) - inputs.dir(File(repoDir, intellijSdk.name)) + val intellijSdkDir = File(repoDir, intellijSdk.name) + inputs.dir(intellijSdkDir) + outputs.file(File(repoDir, "${intellijSdk.name}.ivy.xml")) val flatDeps = listOf(intellijCore, jpsStandalone, jpsBuildTest) flatDeps.forEach { inputs.dir(File(repoDir, it.name)) + outputs.file(File(repoDir, "${it.name}.ivy.xml")) } inputs.dir(File(repoDir, intellijSources.name)) - val ivyXml = File(repoDir, "ivy.xml") - outputs.files(ivyXml) - val sourcesFile = File(repoDir, "${intellijSources.name}/${intellijSources.singleFile.name}") +// outputs.files("$repoDir/intellij.plugin.*.ivy.xml") doFirst { - makeIvyXml(intellijSdk.name, File(repoDir, "${intellijSdk.name}.ivy.xml"), - files("$repoDir/${intellijSdk.name}/lib").filter { !it.name.startsWith("kotlin-") }, - repoDir, sourcesFile) - File(repoDir, "${intellijSdk.name}/plugins").listFiles { it: File -> it.isDirectory }.forEach { - makeIvyXml(it.name, File(repoDir, "intellij.plugin.${it.name}.ivy.xml"), files("$it/lib"), repoDir, sourcesFile) + val sourcesFile = File(repoDir, "${intellijSources.name}/${intellijSources.singleFile.name}") + writeIvyXml(intellijSdk.name, + files("$intellijSdkDir/lib/").filter { !it.name.startsWith("kotlin-") }, + File(intellijSdkDir, "lib"), + sourcesFile) + File(intellijSdkDir, "plugins").listFiles { it: File -> it.isDirectory }.forEach { + writeIvyXml("intellij.plugin.${it.name}", files("$it/lib/"), File(it, "lib"), sourcesFile) } flatDeps.forEach { - makeIvyXml(it.name, File(repoDir, "${it.name}.ivy.xml"), files("$repoDir/${it.name}"), repoDir, sourcesFile) + writeIvyXml(it.name, files("$repoDir/${it.name}"), File(repoDir, it.name), sourcesFile) } } -} \ No newline at end of file +} + +val build by tasks.creating { + dependsOn(prepareIvyXml) +} + +val clean by tasks.creating(Delete::class) { + delete(customDepsRepoModulesDir) + delete(buildDir) +} diff --git a/buildSrc/src/main/kotlin/AndroidSdkDependencies.kt b/buildSrc/src/main/kotlin/AndroidSdkDependencies.kt index 1629aeac60c..18c67b128a3 100644 --- a/buildSrc/src/main/kotlin/AndroidSdkDependencies.kt +++ b/buildSrc/src/main/kotlin/AndroidSdkDependencies.kt @@ -3,9 +3,12 @@ import org.gradle.api.Project import org.gradle.api.artifacts.dsl.RepositoryHandler import org.gradle.api.artifacts.repositories.IvyArtifactRepository +import org.gradle.kotlin.dsl.extra fun RepositoryHandler.androidDxJarRepo(project: Project): IvyArtifactRepository = ivy { - artifactPattern("${project.rootDir.absoluteFile.toURI().toURL()}/buildSrc/prepare-deps/android-dx/build/libs/[artifact](-[classifier]).jar") + val baseDir = File("${project.rootDir}/buildSrc/prepare-deps/android-dx/build/repo") + ivyPattern("${baseDir.canonicalPath}/[organisation]/[module]/[revision]/[module].ivy.xml") + artifactPattern("${baseDir.canonicalPath}/[organisation]/[module]/[revision]/[artifact](-[classifier]).jar") } -fun androidDxJar() = "my-custom-deps:dx:0" +fun Project.androidDxJar() = "kotlin.build.custom.deps:android-dx:${rootProject.extra["versions.androidBuildTools"]}" diff --git a/buildSrc/src/main/kotlin/intellijPluginHelpers.kt b/buildSrc/src/main/kotlin/intellijPluginHelpers.kt index 61e174e8aae..8358bb966e2 100644 --- a/buildSrc/src/main/kotlin/intellijPluginHelpers.kt +++ b/buildSrc/src/main/kotlin/intellijPluginHelpers.kt @@ -2,6 +2,7 @@ import org.gradle.api.GradleException import org.gradle.api.Project +import org.gradle.api.artifacts.ModuleDependency import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.FileTree import org.gradle.api.tasks.util.PatternFilterable @@ -10,6 +11,28 @@ import org.gradle.kotlin.dsl.extra import org.gradle.kotlin.dsl.the import org.jetbrains.intellij.IntelliJPluginExtension import org.jetbrains.intellij.dependency.PluginDependency +import org.gradle.api.artifacts.dsl.RepositoryHandler +import org.gradle.api.artifacts.repositories.IvyArtifactRepository + +fun RepositoryHandler.intellijSdkRepo(project: Project): IvyArtifactRepository = ivy { + val baseDir = File("${project.rootDir.absoluteFile}/buildSrc/prepare-deps/intellij-sdk/build/repo") + setUrl(baseDir) + ivyPattern("${baseDir.canonicalPath}/[organisation]/[revision]/[module].ivy.xml") + artifactPattern("${baseDir.canonicalPath}/[organisation]/[revision]/[module]/lib/[artifact](-[classifier]).jar") + artifactPattern("${baseDir.canonicalPath}/[organisation]/[revision]/[module]/[artifact].jar") + artifactPattern("${baseDir.canonicalPath}/[organisation]/[revision]/[module]/[artifact](-[revision])(-[classifier]).jar") + artifactPattern("${baseDir.canonicalPath}/[organisation]/[revision]/intellijSources/[artifact]-[revision]-[classifier].[ext]") +} + +fun Project.intellijDep() = "kotlin.build.custom.deps:intellijSdk:${rootProject.extra["versions.intellijSdk"]}" + +fun Project.intellijCoreDep() = "kotlin.build.custom.deps:intellijCore:${rootProject.extra["versions.intellijSdk"]}" + +fun ModuleDependency.includeJars(vararg names: String) { + names.forEach { + artifact { name = it; extension = "jar" } + } +} fun Project.configureIntellijPlugin(body: (IntelliJPluginExtension.() -> Unit) = {}) { diff --git a/compiler/tests-common/build.gradle.kts b/compiler/tests-common/build.gradle.kts index 35d7fc1acbd..edc6b0a6dce 100644 --- a/compiler/tests-common/build.gradle.kts +++ b/compiler/tests-common/build.gradle.kts @@ -1,11 +1,12 @@ apply { plugin("kotlin") } -configureIntellijPlugin { - setExtraDependencies("intellij-core") -} +//configureIntellijPlugin { +// setExtraDependencies("intellij-core") +//} repositories { + intellijSdkRepo(project) androidDxJarRepo(project) } @@ -33,13 +34,11 @@ dependencies { testCompile(projectTests(":compiler:tests-common-jvm6")) testCompileOnly(project(":kotlin-reflect-api")) testCompile(commonDep("junit:junit")) - testCompile(androidDxJar()) -} - -afterEvaluate { - dependencies { - testCompile(intellijCoreJar()) - testCompile(intellij { include("openapi.jar", "idea.jar", "idea_rt.jar", "guava-*.jar", "trove4j.jar", "picocontainer.jar", "asm-all.jar") }) + testCompile(androidDxJar()) { isTransitive = false } + testCompile(intellijCoreDep()) { includeJars("intellij-core"); isTransitive = false } + testCompile(intellijDep()) { + includeJars("openapi", "idea", "idea_rt", "guava-21.0", "trove4j", "picocontainer", "asm-all") + isTransitive = false } }