Skip to content

Commit 6be535c

Browse files
committed
Restructure project
Move some stuff to a buildSrc Gradle plugin so it can be shared with a new submodule (coming later) and remove the unncessary com/demonwav/mcdev directory structure in the Kotlin source directory. Kotlin does not require files to be in the full package directory like Java, and the official style guide says to prefer not laying them out like Java for non-shared modules. This project has existed longer than that style guide, and that's a lot of files to move, so I just never felt like move them until now.
1 parent c2d22d4 commit 6be535c

File tree

618 files changed

+174
-156
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

618 files changed

+174
-156
lines changed

.gitignore

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,29 @@
1-
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
2-
3-
*.iml
4-
5-
## Directory-based project format:
61
.idea/
7-
8-
## File-based project format:
2+
.idea_modules/
3+
*.iml
94
*.ipr
105
*.iws
116

12-
## Plugin-specific files:
13-
14-
# IntelliJ
15-
/out/
7+
**/out/
8+
**/build/
169

17-
# mpeltonen/sbt-idea plugin
18-
.idea_modules/
19-
20-
# JIRA plugin
21-
atlassian-ide-plugin.xml
22-
23-
# Crashlytics plugin (for Android Studio and IntelliJ)
2410
com_crashlytics_export_strings.xml
2511
crashlytics.properties
2612
crashlytics-build.properties
2713

2814
*.class
29-
30-
# Mobile Tools for Java (J2ME)
31-
.mtj.tmp/
32-
33-
# Package Files #
15+
*.jar
3416
*.war
3517
*.ear
3618
*.zip
3719

38-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
3920
hs_err_pid*
4021

41-
/classes/
42-
/target/
43-
/build/
44-
.gradle/
22+
**/.gradle/
4523
.sandbox/
4624

4725
/gen/
4826

49-
5027
.DS_Store
28+
29+
!gradle/wrapper/gradle-wrapper.jar

build.gradle.kts

Lines changed: 25 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ buildscript {
1919
}
2020

2121
plugins {
22+
mcdev
2223
kotlin("jvm") version "1.3.31" // kept in sync with IntelliJ's bundled dep
2324
groovy
2425
idea
@@ -27,7 +28,7 @@ plugins {
2728
id("org.jlleitschuh.gradle.ktlint") version "9.3.0"
2829
}
2930

30-
apply(from = "gradle/attach-sources.gradle.kts")
31+
// apply(from = "gradle/attach-sources.gradle.kts")
3132

3233
val coroutineVersion = "1.2.1" // Coroutine version also kept in sync with IntelliJ's bundled dep
3334

@@ -38,20 +39,21 @@ val downloadIdeaSources: String by project
3839

3940
// configurations
4041
val idea by configurations
42+
val jflex by configurations
43+
val jflexSkeleton by configurations
44+
val grammarKit by configurations
45+
4146
val gradleToolingExtension: Configuration by configurations.creating {
4247
extendsFrom(idea)
4348
}
44-
val jflex: Configuration by configurations.creating
45-
val jflexSkeleton: Configuration by configurations.creating
46-
val grammarKit: Configuration by configurations.creating
4749
val testLibs: Configuration by configurations.creating {
4850
isTransitive = false
4951
}
5052

5153
group = "com.demonwav.minecraft-dev"
5254
version = "$ideaVersionName-$coreVersion"
5355

54-
val gradleToolingExtensionSourceSet = sourceSets.create("gradle-tooling-extension") {
56+
val gradleToolingExtensionSourceSet: SourceSet = sourceSets.create("gradle-tooling-extension") {
5557
configurations.named(compileOnlyConfigurationName) {
5658
extendsFrom(gradleToolingExtension)
5759
}
@@ -74,12 +76,14 @@ dependencies {
7476
// Add tools.jar for the JDI API
7577
implementation(files(Jvm.current().toolsJar))
7678

77-
implementation(files(gradleToolingExtensionJar))
78-
79+
// Kotlin
80+
compileOnly(kotlin("stdlib-jdk8"))
81+
compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion")
7982
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:$coroutineVersion") {
8083
isTransitive = false
8184
}
82-
compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion")
85+
86+
implementation(files(gradleToolingExtensionJar))
8387

8488
implementation("com.extracraftx.minecraft:TemplateMakerFabric:0.3.0")
8589

@@ -147,6 +151,7 @@ tasks.withType<KotlinCompile>().configureEach {
147151
jvmTarget = JavaVersion.VERSION_1_8.toString()
148152
freeCompilerArgs = listOf("-Xjvm-default=enable")
149153
}
154+
this.javaPackagePrefix
150155
}
151156

152157
tasks.withType<GroovyCompile>().configureEach {
@@ -247,92 +252,30 @@ tasks.register("format") {
247252
dependsOn(licenseFormat, ktlintFormat)
248253
}
249254

250-
// Credit for this intellij-rust
251-
// https://github.com/intellij-rust/intellij-rust/blob/d6b82e6aa2f64b877a95afdd86ec7b84394678c3/build.gradle#L131-L181
252-
fun generateLexer(name: String, flex: String, pack: String) = tasks.register<JavaExec>(name) {
253-
val src = "src/main/grammars/$flex.flex"
254-
val dst = "gen/com/demonwav/mcdev/$pack"
255-
val output = "$dst/$flex.java"
256-
257-
classpath = jflex
258-
main = "jflex.Main"
259-
260-
doFirst {
261-
args(
262-
"--skel", jflexSkeleton.singleFile.absolutePath,
263-
"-d", dst,
264-
src
265-
)
255+
val generateAtLexer by lexer("AtLexer", "com/demonwav/mcdev/platform/mcp/at/gen")
256+
val generateAtParser by parser("AtParser", "com/demonwav/mcdev/platform/mcp/at/gen")
266257

267-
// Delete current lexer
268-
delete(output)
269-
}
258+
val generateNbttLexer by lexer("NbttLexer", "com/demonwav/mcdev/nbt/lang/gen")
259+
val generateNbttParser by parser("NbttParser", "com/demonwav/mcdev/nbt/lang/gen")
270260

271-
inputs.files(src, jflexSkeleton)
272-
outputs.file(output)
273-
}
261+
val generateLangLexer by lexer("LangLexer", "com/demonwav/mcdev/translations/lang/gen")
262+
val generateLangParser by parser("LangParser", "com/demonwav/mcdev/translations/lang/gen")
274263

275-
fun generatePsiAndParser(name: String, bnf: String, pack: String) = tasks.register<JavaExec>(name) {
276-
val src = "src/main/grammars/$bnf.bnf".replace('/', File.separatorChar)
277-
val dstRoot = "gen"
278-
val dst = "$dstRoot/com/demonwav/mcdev/$pack".replace('/', File.separatorChar)
279-
val psiDir = "$dst/psi/".replace('/', File.separatorChar)
280-
val parserDir = "$dst/parser/".replace('/', File.separatorChar)
281-
282-
doFirst {
283-
delete(psiDir, parserDir)
284-
}
285-
286-
classpath = grammarKit
287-
main = "org.intellij.grammar.Main"
288-
289-
if (JavaVersion.current().isJava9Compatible) {
290-
jvmArgs(
291-
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
292-
"--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED",
293-
"--add-opens", "java.base/java.util=ALL-UNNAMED"
294-
)
295-
}
296-
297-
args(dstRoot, src)
298-
299-
inputs.file(src)
300-
outputs.dirs(
301-
mapOf(
302-
"psi" to psiDir,
303-
"parser" to parserDir
304-
)
305-
)
306-
}
307-
308-
val generateAtLexer = generateLexer("generateAtLexer", "AtLexer", "platform/mcp/at/gen/")
309-
val generateAtPsiAndParser = generatePsiAndParser("generateAtPsiAndParser", "AtParser", "platform/mcp/at/gen")
310-
311-
val generateNbttLexer = generateLexer("generateNbttLexer", "NbttLexer", "nbt/lang/gen/")
312-
val generateNbttPsiAndParser = generatePsiAndParser("generateNbttPsiAndParser", "NbttParser", "nbt/lang/gen")
313-
314-
val generateLangLexer = generateLexer("generateLangLexer", "LangLexer", "translations/lang/gen/")
315-
val generateLangPsiAndParser = generatePsiAndParser("generateLangPsiAndParser", "LangParser", "translations/lang/gen")
316-
317-
val generateTranslationTemplateLexer = generateLexer(
318-
"generateTranslationTemplateLexer",
319-
"TranslationTemplateLexer",
320-
"translations/lang/gen/"
321-
)
264+
val generateTranslationTemplateLexer by lexer("TranslationTemplateLexer", "com/demonwav/mcdev/translations/lang/gen")
322265

323266
val generate by tasks.registering {
324267
group = "minecraft"
325268
description = "Generates sources needed to compile the plugin."
269+
outputs.dir("gen")
326270
dependsOn(
327271
generateAtLexer,
328-
generateAtPsiAndParser,
272+
generateAtParser,
329273
generateNbttLexer,
330-
generateNbttPsiAndParser,
274+
generateNbttParser,
331275
generateLangLexer,
332-
generateLangPsiAndParser,
276+
generateLangParser,
333277
generateTranslationTemplateLexer
334278
)
335-
outputs.dir("gen")
336279
}
337280

338281
sourceSets.named("main") { java.srcDir(generate) }
@@ -343,12 +286,9 @@ tasks.clean { delete(generate) }
343286
tasks.runIde {
344287
maxHeapSize = "2G"
345288

289+
jvmArgs("--add-exports=java.base/jdk.internal.vm=ALL-UNNAMED")
346290
System.getProperty("debug")?.let {
347291
systemProperty("idea.ProcessCanceledException", "disabled")
348292
systemProperty("idea.debug.mode", "true")
349293
}
350294
}
351-
352-
inline fun <reified T : Task> TaskContainer.existing() = existing(T::class)
353-
inline fun <reified T : Task> TaskContainer.register(name: String, configuration: Action<in T>) =
354-
register(name, T::class, configuration)

buildSrc/build.gradle.kts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Minecraft Dev for IntelliJ
3+
*
4+
* https://minecraftdev.org
5+
*
6+
* Copyright (c) 2020 minecraft-dev
7+
*
8+
* MIT License
9+
*/
10+
11+
plugins {
12+
`kotlin-dsl`
13+
}
14+
15+
repositories {
16+
mavenCentral()
17+
}
18+
19+
dependencies {
20+
implementation("com.google.code.gson:gson:2.8.6")
21+
}

gradle/attach-sources.gradle.kts renamed to buildSrc/src/main/kotlin/mcdev.gradle.kts

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,56 @@
88
* MIT License
99
*/
1010

11-
import com.github.salomonbrys.kotson.fromJson
1211
import com.google.gson.Gson
1312
import com.google.gson.GsonBuilder
13+
import com.google.gson.reflect.TypeToken
14+
import java.net.HttpURLConnection
15+
import java.net.URL
1416
import java.util.Properties
1517
import java.util.zip.ZipFile
16-
import java.net.URL
17-
import java.net.HttpURLConnection
1818

19-
buildscript {
20-
repositories {
21-
mavenCentral()
22-
}
23-
dependencies {
24-
classpath("com.google.code.gson:gson:2.8.6")
25-
classpath("com.github.salomonbrys.kotson:kotson:2.5.0")
26-
}
27-
}
28-
29-
/*
30-
* This file and the task `resolveIntellijLibSources` below attempts to find sources for IntelliJ's dependencies (the
31-
* jars in its lib/ dir) which are in Maven Central. This check isn't perfect and may miss some, but grabs most of them.
32-
* The task writes the result to `.gradle/intellij-deps.json`.
33-
*
34-
* At configuration time if `.gradle/intellij-deps.json` exists the below code not in a task will add those dependencies
35-
* explicitly, causing Gradle to download the sources for those dependencies, and allowing IntelliJ to pick up those
36-
* sources. None of this affects the actual build or any of the code, this only exists to help ease development by
37-
* making library sources available in the dev environment.
38-
*/
19+
val jflex: Configuration by configurations.creating
20+
val jflexSkeleton: Configuration by configurations.creating
21+
val grammarKit: Configuration by configurations.creating
22+
val compileOnly by configurations
3923

24+
// Analyze dependencies
4025
val fileName = ".gradle/intellij-deps.json"
41-
4226
val jsonFile = file("$projectDir/$fileName")
27+
28+
val ideaVersion: String by project
29+
val ideaVersionName: String by project
30+
31+
data class DepList(val intellijVersion: String, val intellijVersionName: String, val deps: List<Dep>)
32+
data class Dep(val groupId: String, val artifactId: String, val version: String)
33+
4334
if (jsonFile.exists()) {
44-
val deps = jsonFile.bufferedReader().use { reader ->
45-
Gson().fromJson<List<Dep>>(reader)
35+
val deps: DepList = jsonFile.bufferedReader().use { reader ->
36+
Gson().fromJson(reader, object : TypeToken<DepList>() {}.type)
4637
}
47-
dependencies {
48-
for ((groupId, artifactId, version) in deps) {
49-
"compileOnly"(
50-
group = groupId,
51-
name = artifactId,
52-
version = version
53-
)
38+
if (ideaVersion != deps.intellijVersion || ideaVersionName != deps.intellijVersionName) {
39+
println("IntelliJ library sources file definition is out of date, deleting")
40+
jsonFile.delete()
41+
} else {
42+
dependencies {
43+
for ((groupId, artifactId, version) in deps.deps) {
44+
compileOnly(
45+
group = groupId,
46+
name = artifactId,
47+
version = version
48+
)
49+
}
5450
}
5551
}
5652
}
5753

58-
data class Dep(val groupId: String, val artifactId: String, val version: String)
59-
6054
tasks.register("resolveIntellijLibSources") {
6155
group = "minecraft"
62-
val config = project.configurations["compileClasspath"]
63-
dependsOn(config)
56+
val compileClasspath by project.configurations
57+
dependsOn(compileClasspath)
6458

6559
doLast {
66-
val files = config.resolvedConfiguration.files
60+
val files = compileClasspath.resolvedConfiguration.files
6761
val deps = files.asSequence()
6862
.map { it.toPath() }
6963
.filter {
@@ -104,8 +98,9 @@ tasks.register("resolveIntellijLibSources") {
10498
}
10599
}.toList()
106100

101+
val depList = DepList(ideaVersion, ideaVersionName, deps.sortedWith(compareBy<Dep> { it.groupId }.thenBy { it.artifactId }))
107102
jsonFile.bufferedWriter().use { writer ->
108-
GsonBuilder().setPrettyPrinting().create().toJson(deps, writer)
103+
GsonBuilder().setPrettyPrinting().create().toJson(depList, writer)
109104
}
110105
}
111106
}

0 commit comments

Comments
 (0)