@@ -17,7 +17,6 @@ import java.net.Socket
1717import java.util.*
1818import javax.inject.Inject
1919
20- // TODO: CI/CD for publishing the plugin
2120class ProcessingPlugin @Inject constructor(private val objectFactory : ObjectFactory ) : Plugin<Project> {
2221 override fun apply (project : Project ) {
2322 val sketchName = project.layout.projectDirectory.asFile.name.replace(Regex (" [^a-zA-Z0-9_]" ), " _" )
@@ -32,6 +31,7 @@ class ProcessingPlugin @Inject constructor(private val objectFactory: ObjectFact
3231
3332 // TODO: Setup sketchbook when using as a standalone plugin, use the Java Preferences
3433 val sketchbook = project.findProperty(" processing.sketchbook" ) as String?
34+ val settings = project.findProperty(" processing.settings" ) as String?
3535
3636 // Apply the Java plugin to the Project
3737 project.plugins.apply (JavaPlugin ::class .java)
@@ -46,13 +46,12 @@ class ProcessingPlugin @Inject constructor(private val objectFactory: ObjectFact
4646 project.tasks.findByName(" wrapper" )?.enabled = false
4747 }
4848
49- // Add the compose plugin to wrap the sketch in an executable
50- project.plugins.apply (" org.jetbrains.compose" )
51-
5249 // Add kotlin support
5350 project.plugins.apply (" org.jetbrains.kotlin.jvm" )
5451 // Add jetpack compose support
5552 project.plugins.apply (" org.jetbrains.kotlin.plugin.compose" )
53+ // Add the compose plugin to wrap the sketch in an executable
54+ project.plugins.apply (" org.jetbrains.compose" )
5655
5756 // Add the Processing core library (within Processing from the internal maven repo and outside from the internet)
5857 project.dependencies.add(" implementation" , " $processingGroup :core:${processingVersion} " )
@@ -129,8 +128,7 @@ class ProcessingPlugin @Inject constructor(private val objectFactory: ObjectFact
129128
130129 }
131130
132- project.extensions.getByType(JavaPluginExtension ::class .java).sourceSets.all { sourceSet ->
133- // For each java source set (mostly main) add a new source set for the PDE files
131+ project.extensions.getByType(JavaPluginExtension ::class .java).sourceSets.first().let { sourceSet ->
134132 val pdeSourceSet = objectFactory.newInstance(
135133 DefaultPDESourceDirectorySet ::class .java,
136134 objectFactory.sourceDirectorySet(" ${sourceSet.name} .pde" , " ${sourceSet.name} Processing Source" )
@@ -142,43 +140,37 @@ class ProcessingPlugin @Inject constructor(private val objectFactory: ObjectFact
142140 srcDir(" $workingDir /unsaved" )
143141 }
144142 sourceSet.allSource.source(pdeSourceSet)
143+ sourceSet.java.srcDir(project.layout.projectDirectory).apply {
144+ include(" **/*.java" )
145+ exclude(" ${project.layout.buildDirectory.asFile.get()} /**/*" )
146+ }
145147
146148 val librariesTaskName = sourceSet.getTaskName(" scanLibraries" , " PDE" )
147149 val librariesScan = project.tasks.register(librariesTaskName, LibrariesTask ::class .java) { task ->
148150 task.description = " Scans the libraries in the sketchbook"
149151 task.librariesDirectory.set(sketchbook?.let { File (it, " libraries" ) })
152+ // TODO: Save the libraries metadata to settings folder to share between sketches
150153 }
151154
152155 val pdeTaskName = sourceSet.getTaskName(" preprocess" , " PDE" )
153156 val pdeTask = project.tasks.register(pdeTaskName, PDETask ::class .java) { task ->
154157 task.description = " Processes the ${sourceSet.name} PDE"
155158 task.source = pdeSourceSet
156159 task.sketchName = sketchName
157- task.workingDir = workingDir
158- task.sketchBook = sketchbook
159160
160161 // Set the output of the pre-processor as the input for the java compiler
161162 sourceSet.java.srcDir(task.outputDirectory)
162-
163- task.doLast {
164- // Copy java files from the root to the generated directory
165- project.copy { copyTask ->
166- copyTask.from(project.layout.projectDirectory){ from ->
167- from.include(" *.java" )
168- }
169- copyTask.into(task.outputDirectory)
170- }
171- }
172163 }
173164
174165 val depsTaskName = sourceSet.getTaskName(" addLegacyDependencies" , " PDE" )
175166 project.tasks.register(depsTaskName, DependenciesTask ::class .java){ task ->
167+ task.librariesMetaData
176168 task.dependsOn(pdeTask, librariesScan)
169+ // TODO: Save the libraries metadata to settings folder to share between sketches
177170 }
178171
179- project.tasks.named(
180- sourceSet.compileJavaTaskName
181- ) { task ->
172+ // Make sure that the PDE task runs before the java compilation task
173+ project.tasks.named(sourceSet.compileJavaTaskName) { task ->
182174 task.dependsOn(pdeTaskName, depsTaskName)
183175 }
184176 }
0 commit comments