Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ gen-external-apklibs
hs_err_pid*
replay_pid*

# Maven ignores
.kotlin
.gradle
.build/
/core/build/
/build/publish/
/app/build
/java/build/
/build/reports
/java/bin
/java/libraries/svg/bin
/java/preprocessor/build
/java/lsp/build
### Gradle ###
.gradle
**/build/
Expand Down Expand Up @@ -123,4 +136,16 @@ generated/
!java/libraries/serial/library/jssc.jar
/app/windows/obj
/java/gradle/build
/core/examples/build
/java/gradle/example/.processing
/app/windows/obj
/java/android/example/build
/java/android/example/.processing
/java/gradle/example/build
/java/gradle/example/gradle/wrapper/gradle-wrapper.jar
/java/gradle/example/gradle/wrapper/gradle-wrapper.properties
/java/gradle/example/gradlew
/java/gradle/example/gradlew.bat
/java/gradle/example/.kotlin/errors
/java/gradle/hotreload/build
*.iml
9 changes: 8 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
kotlin = "2.0.20"
compose-plugin = "1.7.1"
jogl = "2.5.0"
antlr = "4.13.2"
jupiter = "5.12.0"

[libraries]
Expand All @@ -25,6 +26,11 @@ netbeansSwing = { module = "org.netbeans.api:org-netbeans-swing-outline", versio
ant = { module = "org.apache.ant:ant", version = "1.10.14" }
lsp4j = { module = "org.eclipse.lsp4j:org.eclipse.lsp4j", version = "0.22.0" }
jsoup = { module = "org.jsoup:jsoup", version = "1.17.2" }
antlr4 = { module = "org.antlr:antlr4", version.ref = "antlr" }
antlr4Runtime = { module = "org.antlr:antlr4-runtime", version.ref = "antlr" }
composeGradlePlugin = { module = "org.jetbrains.compose:compose-gradle-plugin", version.ref = "compose-plugin" }
kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlinComposePlugin = { module = "org.jetbrains.kotlin.plugin.compose:org.jetbrains.kotlin.plugin.compose.gradle.plugin", version.ref = "kotlin" }
markdown = { module = "com.mikepenz:multiplatform-markdown-renderer-m2", version = "0.31.0" }
markdownJVM = { module = "com.mikepenz:multiplatform-markdown-renderer-jvm", version = "0.31.0" }
clikt = { module = "com.github.ajalt.clikt:clikt", version = "5.0.2" }
Expand All @@ -36,4 +42,5 @@ kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref =
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
download = { id = "de.undercouch.download", version = "5.6.0" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.30.0" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.30.0" }
gradlePublish = { id = "com.gradle.plugin-publish", version = "1.2.1" }
32 changes: 25 additions & 7 deletions java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
This the Java Mode in Processing. It compiles your sketches and runs them. It is the primary mode of Processing.

## Folders
- `application` assets for exporting applications within the mode
- `generated` generated antlr code for the mode, should be moved to a proper `antlr` plugin within gradle
- `application` assets for exporting applications within the mode (Deprecated)
- `generated` generated antlr code for the mode, should be moved to a proper `antlr` plugin within gradle (Deprecated)
- `gradle` the Processing java gradle plugin
- `libraries` libraries that are available within the mode
- `lsp` gradle build system for the language server protocol, in the future we should decouple the lsp from the java mode and pde and move all relevant code here. For now it can be found in `src/.../lsp`
- `mode` legacy files for `Ant`
Expand All @@ -13,8 +14,25 @@ This the Java Mode in Processing. It compiles your sketches and runs them. It is
- `test` tests for the mode
- `theme` assets for the mode, related to autocomplete and syntax highlighting

## Future plans
- Decouple the `lsp` and `preprocessor` from the mode and move them to their own repositories
- Move the `antlr` code to a proper plugin within gradle
- Create a gradle plugin to convert `.pde` file to `.java` files
- Create a gradle based version of Java mode.
## The Modern Build system

Since 2025 work has started on creating a new internal build system for the Java Mode based on Gradle.
The goal is to simplify by leaning more on Gradle, which provides a lot of the functionality that was build before out of the box and a lot more.

### How it used to work

The build system used to be based on some parts Ant, some parts eclipse (org.eclipse.jdt.core) and a lot of custom work build up over the years.

### How it will work going forward

The modern build system is based around Gradle, the main service (GradleService) for building a sketch with Gradle is included in `app` instead of into the Java mode as future modes are most likely also based on Gradle if they use `core` in some way. Most _Modes_ should/could probably be a Gradle plugin going forward.
Breaking the build system away from the java mode will mean that we create an island of isolation when it comes to the build system, allowing contributors to work on the build system without running the editor.
Another upside is that when we publish the Gradle plugin to the Gradle Plugin repository, it will become trivial to run Processing sketches outside the PDE and improvements made to the build system will be usable for everyone.
There is now also an opportunity for creating contributions that modify the build system in more subtle ways rather than having to make a complete new mode, e.g. a compilation step for shaders or some setup tweaks to make JavaFX work out of the box.
Furthermore, this change will embed Processing more into the wider Java ecosystem, if users want to upgrade from using Processing to Java whilst still using `core` that will become possible and won't need a rewrite of what they already created.

### How to work on the modern build system

If you want to work on the build system without the PDE, open `/java/gradle/example` into a new intellij IDEA window, this is set up to compile the Processing Java plugin and run sketches standalone.

Within the editor, the gradle plugin is embedded in Processing's embedded maven repository so that Gradle can find it.
41 changes: 41 additions & 0 deletions java/gradle/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
plugins{
`java-gradle-plugin`
alias(libs.plugins.gradlePublish)

kotlin("jvm") version libs.versions.kotlin
}

repositories {
mavenCentral()
maven("https://jogamp.org/deployment/maven")
}

dependencies{
implementation(project(":java:preprocessor"))

implementation(libs.composeGradlePlugin)
implementation(libs.kotlinGradlePlugin)
implementation(libs.kotlinComposePlugin)

testImplementation(project(":core"))
testImplementation(libs.junit)
}

// TODO: CI/CD for publishing the plugin to the Gradle Plugin Portal
gradlePlugin{
plugins{
create("processing.java"){
id = "org.processing.java"
implementationClass = "org.processing.java.gradle.ProcessingPlugin"
}
}
}
publishing{
repositories{
mavenLocal()
maven {
name = "App"
url = uri(project(":app").layout.buildDirectory.dir("resources-bundled/common/repository").get().asFile.absolutePath)
}
}
}
5 changes: 5 additions & 0 deletions java/gradle/example/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions java/gradle/example/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions java/gradle/example/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions java/gradle/example/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions java/gradle/example/.idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions java/gradle/example/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions java/gradle/example/brightness.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Brightness
* by Rusty Robison.
*
* Brightness is the relative lightness or darkness of a color.
* Move the cursor vertically over each bar to alter its brightness.
*/

int barWidth = 20;
int lastBar = -1;

/*
import controlP5.*;

ControlP5 cp5;
*/


void setup() {
size(640, 360, P2D);
colorMode(HSB, width, 100, height);
noStroke();
background(0);
}

void draw() {
int whichBar = mouseX / barWidth;
if (whichBar != lastBar) {
int barX = whichBar * barWidth;
fill(barX, 100, mouseY);
rect(barX, 0, barWidth, height);
lastBar = whichBar;
}
}
3 changes: 3 additions & 0 deletions java/gradle/example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins{
id("org.processing.java")
}
5 changes: 5 additions & 0 deletions java/gradle/example/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rootProject.name = "processing-gradle-plugin-demo"

pluginManagement {
includeBuild("../../../")
}
79 changes: 79 additions & 0 deletions java/gradle/src/main/kotlin/DependenciesTask.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.processing.java.gradle

import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.TaskAction
import java.io.File
import java.io.ObjectInputStream

/*
* The DependenciesTask resolves the dependencies for the sketch based on the libraries used
*/
abstract class DependenciesTask: DefaultTask() {
@InputFile
val librariesMetaData: RegularFileProperty = project.objects.fileProperty()

@InputFile
val sketchMetaData: RegularFileProperty = project.objects.fileProperty()

init{
librariesMetaData.convention(project.layout.buildDirectory.file("processing/libraries"))
sketchMetaData.convention(project.layout.buildDirectory.file("processing/sketch"))
}

@TaskAction
fun execute() {
val sketchMetaFile = sketchMetaData.get().asFile
val librariesMetaFile = librariesMetaData.get().asFile

val libraries = librariesMetaFile.inputStream().use { input ->
ObjectInputStream(input).readObject() as ArrayList<LibrariesTask.Library>
}

val sketch = sketchMetaFile.inputStream().use { input ->
ObjectInputStream(input).readObject() as PDETask.SketchMeta
}

val dependencies = mutableSetOf<File>()

// Loop over the import statements in the sketch and import the relevant jars from the libraries
sketch.importStatements.forEach import@{ statement ->
libraries.forEach { library ->
library.jars.forEach { jar ->
jar.classes.forEach { className ->
if (className.startsWith(statement)) {
dependencies.addAll(library.jars.map { it.path } )
return@import
}
}
}
}
}
project.dependencies.add("implementation", project.files(dependencies) )

// TODO: Mutating the dependencies of configuration ':implementation' after it has been resolved or consumed. This

// TODO: Add only if user is compiling for P2D or P3D
// Add JOGL and Gluegen dependencies
project.dependencies.add("runtimeOnly", "org.jogamp.jogl:jogl-all-main:2.5.0")
project.dependencies.add("runtimeOnly", "org.jogamp.gluegen:gluegen-rt:2.5.0")

val os = System.getProperty("os.name").lowercase()
val arch = System.getProperty("os.arch").lowercase()

val variant = when {
os.contains("mac") -> "macosx-universal"
os.contains("win") && arch.contains("64") -> "windows-amd64"
os.contains("linux") && arch.contains("aarch64") -> "linux-aarch64"
os.contains("linux") && arch.contains("arm") -> "linux-arm"
os.contains("linux") && arch.contains("amd64") -> "linux-amd64"
else -> throw GradleException("Unsupported OS/architecture: $os / $arch")
}

project.dependencies.add("runtimeOnly", "org.jogamp.gluegen:gluegen-rt:2.5.0:natives-$variant")
project.dependencies.add("runtimeOnly", "org.jogamp.jogl:nativewindow:2.5.0:natives-$variant")
project.dependencies.add("runtimeOnly", "org.jogamp.jogl:newt:2.5.0:natives-$variant")
}
}
Loading
Loading