Skip to content
Open
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 @@ -124,4 +137,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
10 changes: 10 additions & 0 deletions app/utils/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("java")
alias(libs.plugins.mavenPublish)
}

repositories {
Expand All @@ -11,6 +12,15 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter")
}

publishing{
repositories{
maven {
name = "App"
url = uri(project(":app").layout.buildDirectory.dir("resources-bundled/common/repository").get().asFile.absolutePath)
}
}
}

tasks.test {
useJUnitPlatform()
}
5 changes: 5 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ plugins {

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

sourceSets{
main{
java{
srcDirs("src")
exclude("**/*.jnilib")
}
resources{
srcDirs("src")
Expand Down Expand Up @@ -76,3 +78,6 @@ tasks.withType<Jar> {
tasks.compileJava{
options.encoding = "UTF-8"
}
tasks.javadoc{
options.encoding = "UTF-8"
}
18 changes: 10 additions & 8 deletions core/src/processing/core/PApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ public class PApplet implements PConstants {
protected boolean exitCalled;

// ok to be static because it's not possible to mix enabled/disabled
static protected boolean disableAWT;
static protected boolean disableAWT = System.getProperty("processing.awt.disable", "false").equals("true");;

// messages to send if attached as an external vm

Expand Down Expand Up @@ -9940,19 +9940,21 @@ static public void runSketch(final String[] args,
System.exit(1);
}

boolean external = false;
int[] location = null;
int[] editorLocation = null;
boolean external = System.getProperty("processing.external", "false").equals("true");;
int[] location = System.getProperty("processing.location", null) != null ?
parseInt(split(System.getProperty("processing.location"), ',')) : null;

int[] editorLocation = System.getProperty("processing.editor.location", null) != null ?
parseInt(split(System.getProperty("processing.editor.location"), ',')) : null;
String name = null;
int windowColor = 0;
int stopColor = 0xff808080;
boolean hideStop = false;
boolean hideStop = System.getProperty("processing.stop.hide", "false").equals("true");

int displayNum = -1; // use default
boolean present = false;
boolean fullScreen = false;
float uiScale = 0;
boolean present = System.getProperty("processing.present", "false").equals("true");
boolean fullScreen = System.getProperty("processing.fullscreen", "false").equals("true");
float uiScale = parseInt(System.getProperty("processing.uiScale", "0"), 0);

String param, value;
String folder = calcSketchPath();
Expand Down
84 changes: 84 additions & 0 deletions java/gradle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Processing Gradle Plugin

This folder contains the source for the Processing Gradle plugin.
The plugin will transform any Processing sketch into a Gradle project for easy compilation and advanced features.

## Usage

Add the following files to any Processing sketch alongside the `.pde` files

```kotlin
// build.gradle.kts
plugins {
id("org.processing.java") version "4.5.3" // version of Processing you would like to use.
}

// settings.gradle.kts - create the file but leave blank
```

This will make the Processing sketch a fully fledges Gradle project, usable with any editor that supports gradle.
Including the `gradle` command if installed.

The plugin will add the `sketch` command to the Gradle tasks lists, so run the sketch with `gradle sketch`, this will
build and launch your sketch.

The sketch can also be bundled into a standalone app by using the `gradle export` command.
Or run in fullscreen with `gradle present`

To include libraries into your sketch add `processing.sketchbook=/path/to/sketchbook` to a `gradle.properties` file in
the same folder.

To use any kind of dependency add as a normal gradle dependency, the plugin has already automatically added the Maven
Central repository.

```kotlin
// build.gradle.kts
plugins {
id("org.processing.java") version "4.5.3"
}

dependencies {
implementation("com.lowagie:itext:2.1.7")
}
```

To use an older version of Processing just change the plugin version:

```kotlin
// build.gradle.kts
plugins {
id("org.processing.java") version "4.5.0"
}
```

Other gradle plugins are also supported

```kotlin
// build.gradle.kts
plugins {
id("org.processing.java") version "4.5.3"
id("com.gradleup.shadow") version "<version>"
}
```

If you want to combine multiple sketches into a single project

```kotlin
// sketch-a/build.gradle.kts
plugins {
id("org.processing.java") version "4.5.3"
}

// sketch-b/build.gradle.kts
plugins {
id("org.processing.java") version "4.5.3"
}

// build.gradle.kts
plugins {
id("org.processing.java") version "4.5.3" apply false
}
// settings.gradle.kts - create the file but leave blank
```

Then run all sketches at once with `gradle sketch`
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)
}
}
}
28 changes: 28 additions & 0 deletions java/gradle/example/brightness.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 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;


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