Skip to content

Commit e164fe4

Browse files
committed
Gradle variables from Processing, Group resolution
1 parent 672c2ac commit e164fe4

File tree

4 files changed

+47
-21
lines changed

4 files changed

+47
-21
lines changed

app/build.gradle.kts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,18 @@ compose.desktop {
4949
application {
5050
mainClass = "processing.app.ui.Start"
5151

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())
52+
53+
val variables = mapOf(
54+
"processing.group" to (rootProject.group.takeIf { it != "" } ?: "processing"),
55+
"processing.version" to rootProject.version,
56+
"processing.revision" to (findProperty("revision") ?: Int.MAX_VALUE),
57+
"processing.contributions.source" to "https://contributions.processing.org/contribs",
58+
"processing.download.page" to "https://processing.org/download/",
59+
"processing.download.latest" to "https://processing.org/download/latest.txt",
60+
"processing.tutorials" to "https://processing.org/tutorials/",
61+
)
62+
63+
jvmArgs(*variables.entries.map { "-D${it.key}=${it.value}" }.toTypedArray())
6064

6165
nativeDistributions{
6266
modules("jdk.jdi", "java.compiler", "jdk.accessibility", "java.management.rmi")

app/src/processing/app/gradle/GradleService.kt

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,36 @@ class GradleService(val editor: Editor) {
134134

135135

136136

137-
fun ProjectConnection.newSketchBuild(): BuildLauncher{
137+
private fun ProjectConnection.newSketchBuild(): BuildLauncher{
138138
finishedTasks.clear()
139-
// TODO: Research if we can generate these programmatically
140-
// Ideally they would not be placed into the sketch folder
141139

142-
val initGradle = kotlin.io.path.createTempDirectory().resolve("init.gradle.kts").apply {
140+
val workingDir = kotlin.io.path.createTempDirectory()
141+
val group = System.getProperty("processing.group", "org.processing")
142+
143+
val variables = mapOf(
144+
"group" to group,
145+
"version" to Base.getVersionName(),
146+
"sketchFolder" to folder.absolutePath,
147+
"workingDir" to workingDir.toAbsolutePath().toString(),
148+
"settings" to Platform.getSettingsFolder().absolutePath.toString()
149+
)
150+
151+
val initGradle = workingDir.resolve("init.gradle.kts").apply {
143152
val content = """
144153
beforeSettings{
145154
pluginManagement {
146155
repositories {
147156
maven { url = uri("${Platform.getContentFile("repository").absolutePath}") }
148-
//mavenLocal()
149157
gradlePluginPortal()
150158
}
151159
}
152160
}
161+
allprojects{
162+
repositories {
163+
maven { url = uri("${Platform.getContentFile("repository").absolutePath}") }
164+
mavenCentral()
165+
}
166+
}
153167
""".trimIndent()
154168

155169
writeText(content)
@@ -161,20 +175,24 @@ class GradleService(val editor: Editor) {
161175
Messages.log("build.gradle.kts not found in ${folder}, creating one")
162176
// TODO: Allow for other plugins to be registered
163177
// TODO: Allow for the whole configuration to be overridden
178+
// TODO: Move this to java mode
164179
val content = """
165180
// Managed by: Processing ${Base.getVersionName()}
166181
// If you delete this comment Processing will no longer update the build scripts
167182
168183
plugins{
169-
id("processing.java.gradle") version "${Base.getVersionName()}"
184+
id("org.processing.gradle") version "${Base.getVersionName()}"
170185
}
171186
""".trimIndent()
172187
buildGradle.writeText(content)
173188
}
174189

175190
return this.newBuild()
176191
// .setJavaHome(Platform.getJavaHome())
177-
.withArguments("--init-script", initGradle.toAbsolutePath().toString())
192+
.withArguments(
193+
"--init-script", initGradle.toAbsolutePath().toString(),
194+
*variables.entries.map { "-Pprocessing.${it.key}=${it.value}" }.toTypedArray()
195+
)
178196
.addProgressListener(ProgressListener { event ->
179197
val name = event.descriptor.name
180198
if(event is TaskStartEvent) {

java/gradle/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dependencies{
2222
gradlePlugin{
2323
plugins{
2424
create("processing"){
25-
id = "processing.java.gradle"
25+
id = "org.processing.gradle"
2626
implementationClass = "org.processing.java.gradle.ProcessingPlugin"
2727
}
2828
}

java/gradle/src/main/kotlin/ProcessingPlugin.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,23 @@ import javax.inject.Inject
1717

1818
class ProcessingPlugin @Inject constructor(private val objectFactory: ObjectFactory) : Plugin<Project> {
1919
override fun apply(project: Project) {
20+
val isProcessing = project.findProperty("processing.version") != null
21+
val processingVersion = project.findProperty("processing.version") as String? ?: "4.0.0"
22+
val processingGroup = project.findProperty("processing.group") as String? ?: "org.processing"
23+
2024
project.plugins.apply(JavaPlugin::class.java)
2125

22-
// TODO: Only set the build directory when run from the Processing plugin
23-
project.layout.buildDirectory.set(project.layout.projectDirectory.dir(".processing"))
26+
if(isProcessing){
27+
project.layout.buildDirectory.set(File(project.findProperty("processing.workingDir") as String))
28+
project.tasks.findByName("wrapper")?.enabled = false
29+
}
2430

2531
project.plugins.apply("org.jetbrains.compose")
2632
project.plugins.apply("org.jetbrains.kotlin.jvm")
2733
project.plugins.apply("org.jetbrains.kotlin.plugin.compose")
2834

2935
// TODO: Add to tests
30-
project.dependencies.add("implementation", "org.processing:core:4.4.0")
36+
project.dependencies.add("implementation", "$processingGroup:core:${processingVersion}")
3137
// TODO: Add tests to test if code jars are working
3238
project.dependencies.add("implementation", project.fileTree("src").apply { include("**/code/*.jar") })
3339

@@ -66,8 +72,6 @@ class ProcessingPlugin @Inject constructor(private val objectFactory: ObjectFact
6672
application.nativeDistributions.modules("java.management")
6773
}
6874
}
69-
// TODO: Also only do within Processing
70-
project.tasks.findByName("wrapper")?.enabled = false
7175

7276
project.tasks.create("sketch").apply {
7377
group = "processing"

0 commit comments

Comments
 (0)