Skip to content

Commit 6812454

Browse files
committed
Merge branch 'gradle-runner' into gradle-runner-final
2 parents e0cfc91 + 046a216 commit 6812454

File tree

36 files changed

+1354
-66
lines changed

36 files changed

+1354
-66
lines changed

.idea/jarRepositories.xml

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package processing.app.gradle;
2+
3+
import processing.app.Mode;
4+
import processing.app.Sketch;
5+
import processing.app.ui.Editor;
6+
7+
import java.io.PrintStream;
8+
9+
public class GradleService {
10+
public GradleService(Mode mode, Editor editor) { }
11+
12+
public void setEnabled(boolean enabled) {}
13+
public boolean getEnabled() { return false; }
14+
public void prepare(){}
15+
public void run() {}
16+
public void export(){}
17+
public void stop() {}
18+
public void startService() {}
19+
public void setSketch(Sketch sketch) {}
20+
public void setErr(PrintStream err) {}
21+
public void setOut(PrintStream out) {}
22+
}

app/build.gradle.kts

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import org.gradle.internal.jvm.Jvm
2+
import org.gradle.kotlin.dsl.support.zipTo
23
import org.gradle.internal.os.OperatingSystem
34
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
5+
import org.jetbrains.compose.ExperimentalComposeLibrary
46
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
57
import org.jetbrains.compose.desktop.application.tasks.AbstractJPackageTask
68
import org.jetbrains.compose.internal.de.undercouch.gradle.tasks.download.Download
@@ -49,14 +51,18 @@ compose.desktop {
4951
application {
5052
mainClass = "processing.app.ProcessingKt"
5153

52-
jvmArgs(*listOf(
53-
Pair("processing.version", rootProject.version),
54-
Pair("processing.revision", findProperty("revision") ?: Int.MAX_VALUE),
55-
Pair("processing.contributions.source", "https://contributions.processing.org/contribs"),
56-
Pair("processing.download.page", "https://processing.org/download/"),
57-
Pair("processing.download.latest", "https://processing.org/download/latest.txt"),
58-
Pair("processing.tutorials", "https://processing.org/tutorials/"),
59-
).map { "-D${it.first}=${it.second}" }.toTypedArray())
54+
55+
val variables = mapOf(
56+
"processing.group" to (rootProject.group.takeIf { it != "" } ?: "processing"),
57+
"processing.version" to rootProject.version,
58+
"processing.revision" to (findProperty("revision") ?: Int.MAX_VALUE),
59+
"processing.contributions.source" to "https://contributions.processing.org/contribs",
60+
"processing.download.page" to "https://processing.org/download/",
61+
"processing.download.latest" to "https://processing.org/download/latest.txt",
62+
"processing.tutorials" to "https://processing.org/tutorials/"
63+
)
64+
65+
jvmArgs(*variables.entries.map { "-D${it.key}=${it.value}" }.toTypedArray())
6066

6167
nativeDistributions{
6268
modules("jdk.jdi", "java.compiler", "jdk.accessibility", "java.management.rmi", "java.scripting", "jdk.httpserver")
@@ -111,21 +117,22 @@ dependencies {
111117
implementation(compose.ui)
112118
implementation(compose.components.resources)
113119
implementation(compose.components.uiToolingPreview)
120+
implementation(compose.materialIconsExtended)
114121

115122
implementation(compose.desktop.currentOs)
116123

117124
implementation(libs.compottie)
118125
implementation(libs.kaml)
119126
implementation(libs.markdown)
120127
implementation(libs.markdownJVM)
128+
implementation(gradleApi())
129+
implementation(libs.clikt)
130+
implementation(libs.kotlinxSerializationJson)
121131

122132
testImplementation(kotlin("test"))
123133
testImplementation(libs.mockitoKotlin)
124134
testImplementation(libs.junitJupiter)
125135
testImplementation(libs.junitJupiterParams)
126-
127-
implementation(libs.clikt)
128-
implementation(libs.kotlinxSerializationJson)
129136
}
130137

131138
tasks.test {
@@ -390,32 +397,14 @@ tasks.register<Copy>("includeJavaModeResources") {
390397
from(java.layout.buildDirectory.dir("resources-bundled"))
391398
into(composeResources("../"))
392399
}
393-
// TODO: Move to java mode
394-
tasks.register<Copy>("renameWindres") {
395-
dependsOn("includeSharedAssets","includeJavaModeResources")
396-
val dir = composeResources("modes/java/application/launch4j/bin/")
397-
val os = DefaultNativePlatform.getCurrentOperatingSystem()
398-
val platform = when {
399-
os.isWindows -> "windows"
400-
os.isMacOsX -> "macos"
401-
else -> "linux"
402-
}
403-
from(dir) {
404-
include("*-$platform*")
405-
rename("(.*)-$platform(.*)", "$1$2")
406-
}
407-
duplicatesStrategy = DuplicatesStrategy.INCLUDE
408-
into(dir)
409-
}
410400
tasks.register("includeProcessingResources"){
411401
dependsOn(
412402
"includeCore",
413403
"includeJavaMode",
414404
"includeSharedAssets",
415405
"includeProcessingExamples",
416406
"includeProcessingWebsiteExamples",
417-
"includeJavaModeResources",
418-
"renameWindres"
407+
"includeJavaModeResources"
419408
)
420409
mustRunAfter("includeJdk")
421410
finalizedBy("signResources")
@@ -495,9 +484,9 @@ tasks.register("signResources"){
495484
}
496485
file(composeResources("Info.plist")).delete()
497486
}
487+
}
498488

499489

500-
}
501490
tasks.register("setExecutablePermissions") {
502491
description = "Sets executable permissions on binaries in Processing.app resources"
503492
group = "compose desktop"
@@ -522,6 +511,8 @@ tasks.register("setExecutablePermissions") {
522511
afterEvaluate {
523512
tasks.named("prepareAppResources").configure {
524513
dependsOn("includeProcessingResources")
514+
// Make sure all libraries are bundled in the maven repository distributed with the app
515+
dependsOn(listOf("core","java:preprocessor", "java:gradle", "java:gradle:hotreload").map { project(":$it").tasks.named("publishAllPublicationsToAppRepository") })
525516
}
526517
tasks.named("createDistributable").configure {
527518
dependsOn("includeJdk")

app/src/main/resources/defaults.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ console.temp.days = 7
186186
console.scrollback.lines = 500
187187
console.scrollback.chars = 40000
188188

189+
# run java sketches with Gradle aka the Modern Build System
190+
run.use_gradle = false
191+
189192
# Any additional Java options when running.
190193
# If you change this and can't run things, it's your own durn fault.
191194
run.options =

app/src/processing/app/Language.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ static public Language init() {
183183
return instance;
184184
}
185185

186-
187186
static private String get(String key) {
188187
LanguageBundle bundle = init().bundle;
189188

app/src/processing/app/Preferences.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ static public String getSketchbookPath() {
393393

394394

395395
static protected void setSketchbookPath(String path) {
396+
// Unify path seperator for all platforms
397+
path = path.replace(File.separatorChar, '/');
396398
set("sketchbook.path.four", path); //$NON-NLS-1$
397399
}
398400
}

app/src/processing/app/Preferences.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ fun loadPreferences(): Properties{
3434
}
3535
}
3636

37+
// TODO: Move this to a more appropriate place
3738
@Composable
3839
fun watchFile(file: File): Any? {
3940
val scope = rememberCoroutineScope()

app/src/processing/app/Processing.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ 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.gradle.api.Sketch
1314
import processing.app.api.Contributions
1415
import processing.app.api.Sketchbook
1516
import processing.app.ui.Start
@@ -51,6 +52,7 @@ suspend fun main(args: Array<String>){
5152
.subcommands(
5253
LSP(),
5354
LegacyCLI(args),
55+
Sketch(),
5456
Contributions(),
5557
Sketchbook()
5658
)

app/src/processing/app/Sketch.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
* Stores information about files in the current sketch.
5151
*/
5252
public class Sketch {
53+
public static final String PROPERTIES_NAME = "sketch.properties";
54+
5355
private final Editor editor;
5456
private final Mode mode;
5557

@@ -1305,7 +1307,7 @@ static protected Settings loadProperties(File folder) throws IOException {
13051307
}
13061308
return null;
13071309
*/
1308-
return new Settings(new File(folder, "sketch.properties"));
1310+
return new Settings(new File(folder, PROPERTIES_NAME));
13091311
}
13101312

13111313

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package processing.app.gradle
2+
3+
import com.sun.jdi.Bootstrap
4+
import com.sun.jdi.VirtualMachine
5+
import com.sun.jdi.connect.AttachingConnector
6+
import kotlinx.coroutines.delay
7+
import processing.app.Messages
8+
import kotlin.time.Duration.Companion.seconds
9+
import kotlin.time.TimeSource
10+
11+
class Debugger {
12+
companion object {
13+
suspend fun connect(port: Int?): VirtualMachine? {
14+
try {
15+
Messages.log("Attaching to VM $port")
16+
val connector = Bootstrap.virtualMachineManager().allConnectors()
17+
.firstOrNull { it.name() == "com.sun.jdi.SocketAttach" }
18+
as AttachingConnector?
19+
?: throw IllegalStateException("No socket attach connector found")
20+
val args = connector.defaultArguments()
21+
args["port"]?.setValue(port?.toString() ?: "5005")
22+
23+
// Try to attach the debugger, retrying if it fails
24+
// TODO: Stop retrying after the job has been cancelled / failed
25+
val start = TimeSource.Monotonic.markNow()
26+
while (start.elapsedNow() < 10.seconds) {
27+
try {
28+
val sketch = connector.attach(args)
29+
sketch.resume()
30+
Messages.log("Attached to VM: ${sketch.name()}")
31+
return sketch
32+
} catch (e: Exception) {
33+
Messages.log("Error while attaching to VM: ${e.message}... Retrying")
34+
}
35+
delay(250)
36+
}
37+
} catch (e: Exception) {
38+
Messages.log("Error while attaching to VM: ${e.message}")
39+
return null
40+
}
41+
return null
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)