Skip to content

Commit

Permalink
Remove ktlint and dependency analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
DenWav committed Sep 5, 2024
1 parent 8467b15 commit b2eab2c
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 253 deletions.
29 changes: 1 addition & 28 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -143,33 +143,6 @@ dependencies {
gradleToolingExtension(libs.annotations)
}

val artifactType = Attribute.of("artifactType", String::class.java)
val filtered = Attribute.of("filtered", Boolean::class.javaObjectType)

dependencies {
attributesSchema {
attribute(filtered)
}
artifactTypes.getByName("jar") {
attributes.attribute(filtered, false)
}

registerTransform(Filter::class) {
from.attribute(filtered, false).attribute(artifactType, "jar")
to.attribute(filtered, true).attribute(artifactType, "jar")

parameters {
ideaVersion.set(libs.versions.intellij.ide)
ideaVersionName.set(providers.gradleProperty("ideaVersionName"))
depsFile.set(layout.projectDirectory.file(".gradle/intellij-deps.json"))
}
}
}

configurations.compileClasspath {
attributes.attribute(filtered, true)
}

changelog {
version = coreVersion
groups.empty()
Expand Down Expand Up @@ -255,7 +228,7 @@ license {
.startsWith("src/test/resources")
}

this.tasks {
tasks {
register("gradle") {
files.from(
fileTree(project.projectDir) {
Expand Down
1 change: 0 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,5 @@ dependencies {
implementation(libs.kotlin.plugin)
implementation(libs.intellij.plugin)
implementation(libs.licenser.plugin)
implementation(libs.ktlint.plugin)
implementation(libs.changelog.plugin)
}
112 changes: 0 additions & 112 deletions buildSrc/src/main/kotlin/Filter.kt

This file was deleted.

1 change: 0 additions & 1 deletion buildSrc/src/main/kotlin/ParserExec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Classpath
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.OutputDirectory
Expand Down
98 changes: 2 additions & 96 deletions buildSrc/src/main/kotlin/mcdev-core.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import java.net.HttpURLConnection
import java.net.URI
import java.util.Properties
import java.util.zip.ZipFile
import org.cadixdev.gradle.licenser.header.HeaderStyle
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.kotlin.dsl.maven
Expand All @@ -32,15 +26,13 @@ import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jlleitschuh.gradle.ktlint.tasks.BaseKtLintCheckTask

plugins {
java
idea
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.intellij.platform")
id("org.cadixdev.licenser")
id("org.jlleitschuh.gradle.ktlint")
}

java {
Expand Down Expand Up @@ -105,7 +97,7 @@ val libs = the<LibrariesForLibs>()
dependencies {
implementation(libs.kotlin.stdlib)
implementation(libs.kotlin.reflect)
implementation(libs.bundles.coroutines)
compileOnly(libs.bundles.coroutines)

testImplementation(libs.junit.api)
testCompileOnly(libs.junit.vintage) // Hack to get tests to compile and run
Expand Down Expand Up @@ -135,10 +127,6 @@ idea {
}
}

tasks.withType<BaseKtLintCheckTask>().configureEach {
workerMaxHeapSize = "512m"
}

tasks.runIde {
maxHeapSize = "2G"
jvmArgs("--add-exports=java.base/jdk.internal.vm=ALL-UNNAMED")
Expand All @@ -157,87 +145,5 @@ tasks.test {
tasks.register("format") {
group = "minecraft"
description = "Formats source code according to project style"
dependsOn(tasks.licenseFormat, tasks.ktlintFormat)
}

// Analyze dependencies
val fileName = ".gradle/intellij-deps.json"
val jsonFile = file("$projectDir/$fileName")

val ideaVersion: String by project
val ideaVersionName: String by project

if (jsonFile.exists()) {
val deps: DepList = jsonFile.bufferedReader().use { reader ->
Gson().fromJson(reader, DepList::class.java)
}
if (ideaVersion != deps.intellijVersion || ideaVersionName != deps.intellijVersionName) {
println("IntelliJ library sources file definition is out of date, deleting")
jsonFile.delete()
} else {
dependencies {
for ((groupId, artifactId, version) in deps.deps) {
compileOnly(
group = groupId,
name = artifactId,
version = version
)
}
}
}
}

tasks.register("resolveIntellijLibSources") {
group = "minecraft"
val compileClasspath by project.configurations
dependsOn(compileClasspath)

doLast {
val files = compileClasspath.resolvedConfiguration.files
val deps = files.asSequence()
.map { it.toPath() }
.filter {
it.map { part -> part.toString() }.containsAll(listOf("com.jetbrains.intellij.idea", "ideaIC", "lib"))
}
.filter { it.fileName.toString().endsWith(".jar") }
.mapNotNull { lib ->
val name = lib.fileName.toString()
return@mapNotNull ZipFile(lib.toFile()).use { zipFile ->
val pomEntry = zipFile.stream()
.filter { entry ->
val entryName = entry.name
entryName.contains("META-INF/maven")
&& entryName.split('/').any { name.contains(it) }
&& entryName.endsWith("pom.properties")
}
.findFirst()
.orElse(null) ?: return@use null
return@use zipFile.getInputStream(pomEntry).use { input ->
val props = Properties()
props.load(input)
Dep(props["groupId"].toString(), props["artifactId"].toString(), props["version"].toString())
}
}
}.filter { dep ->
// Check if this dependency is available in Maven Central
val groupPath = dep.groupId.replace('.', '/')
val (_, artifact, ver) = dep
val url = "https://repo.maven.apache.org/maven2/$groupPath/$artifact/$ver/$artifact-$ver-sources.jar"
return@filter with(URI.create(url).toURL().openConnection() as HttpURLConnection) {
try {
requestMethod = "GET"
val code = responseCode
return@with code in 200..299
} finally {
disconnect()
}
}
}.toList()

val depList = DepList(ideaVersion, ideaVersionName, deps.sortedWith(compareBy<Dep> { it.groupId }.thenBy { it.artifactId }))
jsonFile.parentFile.mkdirs()
jsonFile.bufferedWriter().use { writer ->
GsonBuilder().setPrettyPrinting().create().toJson(depList, writer)
}
}
dependsOn(tasks.licenseFormat)
}
12 changes: 0 additions & 12 deletions buildSrc/src/main/kotlin/util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import java.io.ByteArrayOutputStream
import org.cadixdev.gradle.licenser.LicenseExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.TaskContainer
import org.gradle.api.tasks.util.PatternFilterable
import org.gradle.kotlin.dsl.RegisteringDomainObjectDelegateProviderWithTypeAndAction
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.registering
import org.gradle.kotlin.dsl.configure

fun <T> ListProperty<T>.addProvider(provider: Provider<T>) = add(provider)

typealias TaskDelegate<T> = RegisteringDomainObjectDelegateProviderWithTypeAndAction<out TaskContainer, T>

Expand Down Expand Up @@ -74,6 +65,3 @@ fun Project.parser(bnf: String, pack: String): TaskDelegate<ParserExec> {
this.grammarKit.setFrom(grammarKit)
}
}

data class DepList(val intellijVersion: String, val intellijVersionName: String, val deps: List<Dep>)
data class Dep(val groupId: String, val artifactId: String, val version: String)
3 changes: 0 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ junit-platform = "1.10.2"
asm = "9.6"
fuel = "2.3.1"
licenser = "0.6.1"
ktlint = "10.3.0"
changelog = "2.2.0"
intellij-plugin = "2.0.1"
intellij-ide = "2023.2.2"
Expand All @@ -18,7 +17,6 @@ kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
intellij-platform = { id = "org.jetbrains.intellij.platform", version.ref = "intellij-plugin" }
idea-ext = { id = "org.jetbrains.gradle.plugin.idea-ext", version.ref = "idea-ext" }
licenser = { id = "org.cadixdev.licenser", version.ref = "licenser" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }

[libraries]
Expand All @@ -28,7 +26,6 @@ kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref =

intellij-plugin = { module = "org.jetbrains.intellij.platform:org.jetbrains.intellij.platform.gradle.plugin", version.ref = "intellij-plugin" }
licenser-plugin = { module = "org.cadixdev.licenser:org.cadixdev.licenser.gradle.plugin", version.ref = "licenser" }
ktlint-plugin = { module = "org.jlleitschuh.gradle.ktlint:org.jlleitschuh.gradle.ktlint.gradle.plugin", version.ref = "ktlint" }
changelog-plugin = { module = "org.jetbrains.changelog:org.jetbrains.changelog.gradle.plugin", version.ref = "changelog" }

coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
Expand Down

0 comments on commit b2eab2c

Please sign in to comment.