Skip to content

Commit f4d8557

Browse files
Merge branch 'processing:main' into main
2 parents 9a96dd6 + a22d1c1 commit f4d8557

File tree

15 files changed

+421
-72
lines changed

15 files changed

+421
-72
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,15 @@
16421642
"contributions": [
16431643
"doc"
16441644
]
1645+
},
1646+
{
1647+
"login": "catilac",
1648+
"name": "Moon",
1649+
"avatar_url": "https://avatars.githubusercontent.com/u/15107?v=4",
1650+
"profile": "https://softmoon.world",
1651+
"contributions": [
1652+
"code"
1653+
]
16451654
}
16461655
],
16471656
"repoType": "github",

.github/workflows/release-gradle.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ jobs:
153153
ORG_GRADLE_PROJECT_compose.desktop.mac.notarization.password: ${{ secrets.PROCESSING_APP_PASSWORD }}
154154
ORG_GRADLE_PROJECT_compose.desktop.mac.notarization.teamID: ${{ secrets.PROCESSING_TEAM_ID }}
155155
ORG_GRADLE_PROJECT_snapname: ${{ vars.SNAP_NAME }}
156+
ORG_GRADLE_PROJECT_snapconfinement: ${{ vars.SNAP_CONFINEMENT }}
156157

157158
- name: Sign files with Trusted Signing
158159
if: runner.os == 'Windows'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ _Note: due to GitHub's limitations, this repository's [Contributors](https://git
313313
<td align="center" valign="top" width="16.66%"><a href="https://github.com/aj-m"><img src="https://avatars.githubusercontent.com/u/2524348?v=4?s=120" width="120px;" alt="Andrew"/><br /><sub><b>Andrew</b></sub></a><br /><a href="https://github.com/processing/processing4/commits?author=aj-m" title="Code">💻</a></td>
314314
<td align="center" valign="top" width="16.66%"><a href="https://github.com/pnngocdoan"><img src="https://avatars.githubusercontent.com/u/113954980?v=4?s=120" width="120px;" alt="Ngoc Doan"/><br /><sub><b>Ngoc Doan</b></sub></a><br /><a href="https://github.com/processing/processing4/commits?author=pnngocdoan" title="Code">💻</a></td>
315315
<td align="center" valign="top" width="16.66%"><a href="https://github.com/manoellribeiro"><img src="https://avatars.githubusercontent.com/u/59377764?v=4?s=120" width="120px;" alt="Manoel Ribeiro"/><br /><sub><b>Manoel Ribeiro</b></sub></a><br /><a href="https://github.com/processing/processing4/commits?author=manoellribeiro" title="Documentation">📖</a></td>
316+
<td align="center" valign="top" width="16.66%"><a href="https://softmoon.world"><img src="https://avatars.githubusercontent.com/u/15107?v=4?s=120" width="120px;" alt="Moon"/><br /><sub><b>Moon</b></sub></a><br /><a href="https://github.com/processing/processing4/commits?author=catilac" title="Code">💻</a></td>
316317
</tr>
317318
</tbody>
318319
</table>

app/build.gradle.kts

Lines changed: 35 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ dependencies {
124124
testImplementation(libs.junitJupiterParams)
125125

126126
implementation(libs.clikt)
127+
implementation(libs.kotlinxSerializationJson)
127128
}
128129

129130
tasks.test {
@@ -228,61 +229,44 @@ tasks.register<Exec>("packageCustomMsi"){
228229

229230

230231
tasks.register("generateSnapConfiguration"){
231-
val name = findProperty("snapname") ?: rootProject.name
232+
onlyIf { OperatingSystem.current().isLinux }
233+
234+
val distributable = tasks.named<AbstractJPackageTask>("createDistributable").get()
235+
dependsOn(distributable)
236+
237+
val name = findProperty("snapname") as String? ?: rootProject.name
232238
val arch = when (System.getProperty("os.arch")) {
233239
"amd64", "x86_64" -> "amd64"
234240
"aarch64" -> "arm64"
235241
else -> System.getProperty("os.arch")
236242
}
237-
238-
onlyIf { OperatingSystem.current().isLinux }
239-
val distributable = tasks.named<AbstractJPackageTask>("createDistributable").get()
240-
dependsOn(distributable)
241-
243+
val confinement = findProperty("snapconfinement") as String? ?: "strict"
242244
val dir = distributable.destinationDir.get()
243-
val content = """
244-
name: $name
245-
version: $version
246-
base: core22
247-
summary: A creative coding editor
248-
description: |
249-
Processing is a flexible software sketchbook and a programming language designed for learning how to code.
250-
confinement: strict
251-
252-
apps:
253-
processing:
254-
command: opt/processing/bin/Processing
255-
desktop: opt/processing/lib/processing-Processing.desktop
256-
environment:
257-
LD_LIBRARY_PATH: ${'$'}SNAP/opt/processing/lib/runtime/lib:${'$'}LD_LIBRARY_PATH
258-
LIBGL_DRIVERS_PATH: ${'$'}SNAP/usr/lib/${'$'}SNAPCRAFT_ARCH_TRIPLET/dri
259-
plugs:
260-
- desktop
261-
- desktop-legacy
262-
- wayland
263-
- x11
264-
- network
265-
- opengl
266-
- home
267-
- removable-media
268-
- audio-playback
269-
- audio-record
270-
- pulseaudio
271-
- gpio
272-
273-
parts:
274-
processing:
275-
plugin: dump
276-
source: deb/processing_$version-1_$arch.deb
277-
source-type: deb
278-
stage-packages:
279-
- openjdk-17-jre
280-
override-prime: |
281-
snapcraftctl prime
282-
rm -vf usr/lib/jvm/java-17-openjdk-*/lib/security/cacerts
283-
chmod -R +x opt/processing/lib/app/resources/jdk
284-
""".trimIndent()
285-
dir.file("../snapcraft.yaml").asFile.writeText(content)
245+
val base = layout.projectDirectory.file("linux/snapcraft.base.yml")
246+
247+
doFirst {
248+
249+
var content = base
250+
.asFile
251+
.readText()
252+
.replace("\$name", name)
253+
.replace("\$arch", arch)
254+
.replace("\$version", version as String)
255+
.replace("\$confinement", confinement)
256+
.let {
257+
if (confinement != "classic") return@let it
258+
// If confinement is not strict, remove the PLUGS section
259+
val start = it.indexOf("# PLUGS START")
260+
val end = it.indexOf("# PLUGS END")
261+
if (start != -1 && end != -1) {
262+
val before = it.substring(0, start)
263+
val after = it.substring(end + "# PLUGS END".length)
264+
return@let before + after
265+
}
266+
return@let it
267+
}
268+
dir.file("../snapcraft.yaml").asFile.writeText(content)
269+
}
286270
}
287271

288272
tasks.register<Exec>("packageSnap"){
@@ -424,7 +408,6 @@ tasks.register<Copy>("renameWindres") {
424408
}
425409
tasks.register("includeProcessingResources"){
426410
dependsOn(
427-
"includeJdk",
428411
"includeCore",
429412
"includeJavaMode",
430413
"includeSharedAssets",
@@ -433,6 +416,7 @@ tasks.register("includeProcessingResources"){
433416
"includeJavaModeResources",
434417
"renameWindres"
435418
)
419+
mustRunAfter("includeJdk")
436420
finalizedBy("signResources")
437421
}
438422

@@ -539,6 +523,7 @@ afterEvaluate {
539523
dependsOn("includeProcessingResources")
540524
}
541525
tasks.named("createDistributable").configure {
526+
dependsOn("includeJdk")
542527
finalizedBy("setExecutablePermissions")
543528
}
544529
}

app/linux/snapcraft.base.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: $name
2+
version: $version
3+
base: core22
4+
summary: A creative coding editor
5+
description: |
6+
Processing is a flexible software sketchbook and a programming language designed for learning how to code.
7+
confinement: $confinement
8+
9+
apps:
10+
processing:
11+
command: opt/processing/bin/Processing
12+
desktop: opt/processing/lib/processing-Processing.desktop
13+
environment:
14+
LD_LIBRARY_PATH: $SNAP/opt/processing/lib/runtime/lib:$LD_LIBRARY_PATH
15+
LIBGL_DRIVERS_PATH: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/dri
16+
# PLUGS START
17+
plugs:
18+
- desktop
19+
- desktop-legacy
20+
- wayland
21+
- x11
22+
- network
23+
- opengl
24+
- home
25+
- removable-media
26+
- audio-playback
27+
- audio-record
28+
- pulseaudio
29+
- gpio
30+
# PLUGS END
31+
32+
parts:
33+
processing:
34+
plugin: dump
35+
source: deb/processing_$version-1_$arch.deb
36+
source-type: deb
37+
stage-packages:
38+
- openjdk-17-jre
39+
override-prime: |
40+
snapcraftctl prime
41+
rm -vf usr/lib/jvm/java-17-openjdk-*/lib/security/cacerts
42+
chmod -R +x opt/processing/lib/app/resources/jdk

app/src/processing/app/Base.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,6 @@ static public void main(final String[] args) {
166166
static private void createAndShowGUI(String[] args) {
167167
// these times are fairly negligible relative to Base.<init>
168168
// long t1 = System.currentTimeMillis();
169-
var preferences = java.util.prefs.Preferences.userRoot().node("org/processing/app");
170-
var installLocations = new ArrayList<>(List.of(preferences.get("installLocations", "").split(",")));
171-
var installLocation = System.getProperty("user.dir") + "^" + Base.getVersionName();
172-
173-
// Check if the installLocation is already in the list
174-
if (!installLocations.contains(installLocation)) {
175-
// Add the installLocation to the list
176-
installLocations.add(installLocation);
177-
178-
// Save the updated list back to preferences
179-
preferences.put("installLocations", String.join(",", installLocations));
180-
}
181169
// TODO: Cleanup old locations if no longer installed
182170
// TODO: Cleanup old locations if current version is installed in the same location
183171

app/src/processing/app/Platform.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ static public void init() {
105105
"An unknown error occurred while trying to load\n" +
106106
"platform-specific code for your machine.", e);
107107
}
108+
109+
// Fix the issue where `java.home` points to the JRE instead of the JDK. processing/processing4#1163
110+
System.setProperty("java.home", getJavaHome().getAbsolutePath());
108111
}
109112

110113

@@ -389,6 +392,7 @@ static public File getContentFile(String name) {
389392
}
390393

391394
static public File getJavaHome() {
395+
// Get the build in JDK location from the Jetpack Compose resources
392396
var resourcesDir = System.getProperty("compose.application.resources.dir");
393397
if(resourcesDir != null) {
394398
var jdkFolder = new File(resourcesDir,"jdk");
@@ -397,10 +401,13 @@ static public File getJavaHome() {
397401
}
398402
}
399403

404+
// If the JDK is set in the environment, use that.
400405
var home = System.getProperty("java.home");
401406
if(home != null){
402407
return new File(home);
403408
}
409+
410+
// Otherwise try to use the Ant embedded JDK.
404411
if (Platform.isMacOS()) {
405412
//return "Contents/PlugIns/jdk1.7.0_40.jdk/Contents/Home/jre/bin/java";
406413
File[] plugins = getContentFile("../PlugIns").listFiles((dir, name) -> dir.isDirectory() &&

app/src/processing/app/Processing.kt

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import com.github.ajalt.clikt.parameters.arguments.multiple
1010
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
13+
import processing.app.api.Contributions
14+
import processing.app.api.Sketchbook
1315
import processing.app.ui.Start
16+
import java.io.File
17+
import java.util.prefs.Preferences
18+
import kotlin.concurrent.thread
1419

1520
class Processing: SuspendingCliktCommand("processing"){
1621
val version by option("-v","--version")
@@ -29,6 +34,11 @@ class Processing: SuspendingCliktCommand("processing"){
2934
return
3035
}
3136

37+
thread {
38+
// Update the install locations in preferences
39+
updateInstallLocations()
40+
}
41+
3242
val subcommand = currentContext.invokedSubcommand
3343
if (subcommand == null) {
3444
Start.main(sketches.toTypedArray())
@@ -40,7 +50,9 @@ suspend fun main(args: Array<String>){
4050
Processing()
4151
.subcommands(
4252
LSP(),
43-
LegacyCLI(args)
53+
LegacyCLI(args),
54+
Contributions(),
55+
Sketchbook()
4456
)
4557
.main(args)
4658
}
@@ -49,6 +61,9 @@ class LSP: SuspendingCliktCommand("lsp"){
4961
override fun help(context: Context) = "Start the Processing Language Server"
5062
override suspend fun run(){
5163
try {
64+
// run in headless mode
65+
System.setProperty("java.awt.headless", "true")
66+
5267
// Indirect invocation since app does not depend on java mode
5368
Class.forName("processing.mode.java.lsp.PdeLanguageServer")
5469
.getMethod("main", Array<String>::class.java)
@@ -68,10 +83,9 @@ class LegacyCLI(val args: Array<String>): SuspendingCliktCommand("cli") {
6883

6984
override suspend fun run() {
7085
try {
71-
if (arguments.contains("--build")) {
72-
System.setProperty("java.awt.headless", "true")
73-
}
86+
System.setProperty("java.awt.headless", "true")
7487

88+
// Indirect invocation since app does not depend on java mode
7589
Class.forName("processing.mode.java.Commander")
7690
.getMethod("main", Array<String>::class.java)
7791
.invoke(null, arguments.toTypedArray())
@@ -80,3 +94,49 @@ class LegacyCLI(val args: Array<String>): SuspendingCliktCommand("cli") {
8094
}
8195
}
8296
}
97+
98+
fun updateInstallLocations(){
99+
val preferences = Preferences.userRoot().node("org/processing/app")
100+
val installLocations = preferences.get("installLocations", "")
101+
.split(",")
102+
.dropLastWhile { it.isEmpty() }
103+
.filter { install ->
104+
try{
105+
val (path, version) = install.split("^")
106+
val file = File(path)
107+
if(!file.exists() || file.isDirectory){
108+
return@filter false
109+
}
110+
// call the path to check if it is a valid install location
111+
val process = ProcessBuilder(path, "--version")
112+
.redirectErrorStream(true)
113+
.start()
114+
val exitCode = process.waitFor()
115+
if(exitCode != 0){
116+
return@filter false
117+
}
118+
val output = process.inputStream.bufferedReader().readText()
119+
return@filter output.contains(version)
120+
} catch (e: Exception){
121+
false
122+
}
123+
}
124+
.toMutableList()
125+
val command = ProcessHandle.current().info().command()
126+
if(command.isEmpty) {
127+
return
128+
}
129+
val installLocation = "${command.get()}^${Base.getVersionName()}"
130+
131+
132+
// Check if the installLocation is already in the list
133+
if (installLocations.contains(installLocation)) {
134+
return
135+
}
136+
137+
// Add the installLocation to the list
138+
installLocations.add(installLocation)
139+
140+
// Save the updated list back to preferences
141+
preferences.put("installLocations", java.lang.String.join(",", installLocations))
142+
}

0 commit comments

Comments
 (0)