Skip to content

Commit 3fbfddb

Browse files
authored
Merge branch 'main' into addDependencyUpdates
2 parents 0e18502 + 275d789 commit 3fbfddb

File tree

15 files changed

+1437
-117
lines changed

15 files changed

+1437
-117
lines changed

app/src/processing/app/Processing.kt

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,27 @@ import com.github.ajalt.clikt.parameters.options.flag
1111
import com.github.ajalt.clikt.parameters.options.help
1212
import com.github.ajalt.clikt.parameters.options.option
1313
import processing.app.api.Contributions
14+
import processing.app.api.SketchCommand
1415
import processing.app.api.Sketchbook
1516
import processing.app.ui.Start
1617
import java.io.File
1718
import java.util.prefs.Preferences
1819
import kotlin.concurrent.thread
1920

21+
22+
23+
suspend fun main(args: Array<String>){
24+
Processing()
25+
.subcommands(
26+
LSP(),
27+
LegacyCLI(args),
28+
Contributions(),
29+
Sketchbook(),
30+
SketchCommand()
31+
)
32+
.main(args)
33+
}
34+
2035
class Processing: SuspendingCliktCommand("processing"){
2136
val version by option("-v","--version")
2237
.flag()
@@ -46,16 +61,6 @@ class Processing: SuspendingCliktCommand("processing"){
4661
}
4762
}
4863

49-
suspend fun main(args: Array<String>){
50-
Processing()
51-
.subcommands(
52-
LSP(),
53-
LegacyCLI(args),
54-
Contributions(),
55-
Sketchbook()
56-
)
57-
.main(args)
58-
}
5964

6065
class LSP: SuspendingCliktCommand("lsp"){
6166
override fun help(context: Context) = "Start the Processing Language Server"
@@ -74,7 +79,6 @@ class LSP: SuspendingCliktCommand("lsp"){
7479
}
7580
}
7681

77-
7882
class LegacyCLI(val args: Array<String>): SuspendingCliktCommand("cli") {
7983
override val treatUnknownOptionsAsArgs = true
8084

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package processing.app.api
2+
3+
import com.github.ajalt.clikt.command.SuspendingCliktCommand
4+
import com.github.ajalt.clikt.core.Context
5+
import com.github.ajalt.clikt.core.subcommands
6+
import com.github.ajalt.clikt.parameters.arguments.argument
7+
import com.github.ajalt.clikt.parameters.arguments.help
8+
import com.github.ajalt.clikt.parameters.options.flag
9+
import com.github.ajalt.clikt.parameters.options.help
10+
import com.github.ajalt.clikt.parameters.options.option
11+
import processing.app.Language
12+
import processing.app.Platform
13+
import processing.app.Preferences
14+
import java.io.File
15+
16+
class SketchCommand: SuspendingCliktCommand("sketch"){
17+
override fun help(context: Context) = "Manage a Processing sketch"
18+
override suspend fun run() {
19+
20+
}
21+
init {
22+
subcommands(Format())
23+
}
24+
25+
class Format: SuspendingCliktCommand("format"){
26+
override fun help(context: Context) = "Format a Processing sketch"
27+
val file by argument("file")
28+
.help("Path to the sketch file to format")
29+
val inPlace by option("-i","--inplace")
30+
.flag()
31+
.help("Format the file in place, otherwise prints to stdout")
32+
33+
override suspend fun run(){
34+
try {
35+
Platform.init()
36+
Language.init()
37+
Preferences.init()
38+
39+
// run in headless mode
40+
System.setProperty("java.awt.headless", "true")
41+
42+
val clazz = Class.forName("processing.mode.java.AutoFormat")
43+
// Indirect invocation since app does not depend on java mode
44+
val formatter = clazz
45+
.getDeclaredConstructor()
46+
.newInstance()
47+
48+
val method = clazz.getMethod("format", String::class.java)
49+
val code = File(file).readText()
50+
51+
val formatted = method.invoke(formatter, code) as String
52+
if(inPlace) {
53+
File(file).writeText(formatted)
54+
return
55+
}
56+
println(formatted)
57+
} catch (e: Exception) {
58+
throw InternalError("Failed to invoke main method", e)
59+
}
60+
}
61+
}
62+
}

gradle/libs.versions.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
kotlin = "2.0.20"
33
compose-plugin = "1.7.1"
44
jogl = "2.5.0"
5+
antlr = "4.13.2"
56
jupiter = "5.12.0"
67

78
[libraries]
@@ -25,6 +26,11 @@ netbeansSwing = { module = "org.netbeans.api:org-netbeans-swing-outline", versio
2526
ant = { module = "org.apache.ant:ant", version = "1.10.14" }
2627
lsp4j = { module = "org.eclipse.lsp4j:org.eclipse.lsp4j", version = "0.22.0" }
2728
jsoup = { module = "org.jsoup:jsoup", version = "1.17.2" }
29+
antlr4 = { module = "org.antlr:antlr4", version.ref = "antlr" }
30+
antlr4Runtime = { module = "org.antlr:antlr4-runtime", version.ref = "antlr" }
31+
composeGradlePlugin = { module = "org.jetbrains.compose:compose-gradle-plugin", version.ref = "compose-plugin" }
32+
kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
33+
kotlinComposePlugin = { module = "org.jetbrains.kotlin.plugin.compose:org.jetbrains.kotlin.plugin.compose.gradle.plugin", version.ref = "kotlin" }
2834
markdown = { module = "com.mikepenz:multiplatform-markdown-renderer-m2", version = "0.31.0" }
2935
markdownJVM = { module = "com.mikepenz:multiplatform-markdown-renderer-jvm", version = "0.31.0" }
3036
clikt = { module = "com.github.ajalt.clikt:clikt", version = "5.0.2" }
@@ -38,3 +44,4 @@ serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref
3844
download = { id = "de.undercouch.download", version = "5.6.0" }
3945
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.30.0" }
4046
versions = { id = "com.github.ben-manes.versions", version = "0.52.0" }
47+
gradlePublish = { id = "com.gradle.plugin-publish", version = "1.2.1" }

java/build.gradle.kts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
plugins {
2-
id("java")
2+
java
33
}
44

55
repositories{
66
mavenCentral()
77
google()
8-
maven { url = uri("https://jogamp.org/deployment/maven") }
8+
maven("https://jogamp.org/deployment/maven")
99
}
1010

1111
sourceSets{
@@ -48,13 +48,15 @@ tasks.compileJava{
4848
// LEGACY TASKS
4949
// Most of these are shims to be compatible with the old build system
5050
// They should be removed in the future, as we work towards making things more Gradle-native
51-
tasks.register<Copy>("extraResources"){
52-
dependsOn(":java:copyCore")
51+
val javaMode = { path : String -> layout.buildDirectory.dir("resources-bundled/common/modes/java/$path") }
52+
53+
val bundle = tasks.register<Copy>("extraResources"){
54+
dependsOn("copyCore")
5355
from(".")
5456
include("keywords.txt")
5557
include("theme/**/*")
5658
include("application/**/*")
57-
into( layout.buildDirectory.dir("resources-bundled/common/modes/java"))
59+
into(javaMode(""))
5860
}
5961
tasks.register<Copy>("copyCore"){
6062
val coreProject = project(":core")
@@ -66,8 +68,8 @@ tasks.register<Copy>("copyCore"){
6668
into(coreProject.layout.projectDirectory.dir("library"))
6769
}
6870

69-
val libraries = arrayOf("dxf","io","net","pdf","serial","svg")
70-
libraries.forEach { library ->
71+
val legacyLibraries = arrayOf("dxf","io","net","serial","svg")
72+
legacyLibraries.forEach { library ->
7173
tasks.register<Copy>("library-$library-extraResources"){
7274
val build = project(":java:libraries:$library").tasks.named("build")
7375
build.configure {
@@ -78,10 +80,30 @@ libraries.forEach { library ->
7880
include("*.properties")
7981
include("library/**/*")
8082
include("examples/**/*")
81-
into( layout.buildDirectory.dir("resources-bundled/common/modes/java/libraries/$library"))
83+
into( javaMode("/libraries/$library"))
84+
}
85+
bundle.configure {
86+
dependsOn("library-$library-extraResources")
87+
}
88+
}
89+
90+
val libraries = arrayOf("pdf")
91+
libraries.forEach { library ->
92+
val name = "create-$library-library"
93+
tasks.register<Copy>(name) {
94+
group = "libraries"
95+
val project = project(":java:libraries:$library")
96+
val libraryTask = project.tasks.named("createLibrary")
97+
dependsOn(libraryTask)
98+
99+
from(project.layout.buildDirectory.dir("library"))
100+
into(javaMode("/libraries/$library"))
101+
}
102+
bundle.configure {
103+
dependsOn(name)
82104
}
83-
tasks.named("extraResources"){ dependsOn("library-$library-extraResources") }
84105
}
106+
85107
tasks.jar { dependsOn("extraResources") }
86108
tasks.processResources{ finalizedBy("extraResources") }
87109
tasks.compileTestJava{ finalizedBy("extraResources") }
Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
1-
ant.importBuild("build.xml")
1+
plugins{
2+
java
3+
}
4+
5+
sourceSets {
6+
main {
7+
java {
8+
srcDirs("src")
9+
}
10+
}
11+
}
12+
repositories{
13+
mavenCentral()
14+
maven("https://jogamp.org/deployment/maven/")
15+
}
16+
17+
dependencies{
18+
compileOnly(project(":core"))
19+
20+
implementation("com.lowagie:itext:2.1.7")
21+
}
22+
23+
tasks.register<Copy>("createLibrary"){
24+
dependsOn("jar")
25+
into(layout.buildDirectory.dir("library"))
26+
27+
from(layout.projectDirectory){
28+
include ("library.properties")
29+
include("examples/**")
30+
}
31+
32+
from(configurations.runtimeClasspath){
33+
into("library")
34+
}
35+
36+
from(tasks.jar) {
37+
into("library")
38+
}
39+
}

java/lsp/build.gradle.kts

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)