Skip to content

Commit e097d68

Browse files
committed
Enhance PDE source set and preprocessing in ProcessingPlugin
Added comments and structure for improved clarity. Also added a placeholder test for internal libraries in ProcessingPluginTest.
1 parent 2b8b151 commit e097d68

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ abstract class LibrariesTask : DefaultTask() {
5555
.listFiles{ file -> file.extension == "jar" }
5656
?.map{ file ->
5757

58-
// Inside of each jar, look for the defined classes
58+
// Inside each jar, look for the defined classes
5959
val jar = JarFile(file)
6060
val classes = jar.entries().asSequence()
6161
.filter { entry -> entry.name.endsWith(".class") }

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,29 +154,38 @@ class ProcessingPlugin @Inject constructor(private val objectFactory: ObjectFact
154154

155155
}
156156

157+
// For every Java Source Set (main, test, etc) add a PDE source set that includes .pde files
158+
// and a task to process them before compilation
157159
project.extensions.getByType(JavaPluginExtension::class.java).sourceSets.first().let{ sourceSet ->
158160
val pdeSourceSet = objectFactory.newInstance(
159161
DefaultPDESourceDirectorySet::class.java,
160162
objectFactory.sourceDirectorySet("${sourceSet.name}.pde", "${sourceSet.name} Processing Source")
161-
).apply {
162-
filter.include("**/*.pde")
163-
filter.exclude("${project.layout.buildDirectory.asFile.get().name}/**")
163+
)
164164

165+
// Configure the PDE source set to include all .pde files in the sketch folder except those in the build directory
166+
pdeSourceSet.apply {
165167
srcDir("./")
166168
srcDir("$workingDir/unsaved")
169+
170+
filter.include("**/*.pde")
171+
filter.exclude("${project.layout.buildDirectory.asFile.get().name}/**")
167172
}
168173
sourceSet.allSource.source(pdeSourceSet)
174+
175+
// Add top level java source files
169176
sourceSet.java.srcDir(project.layout.projectDirectory).apply {
170177
include("/*.java")
171178
}
172179

180+
// Scan the libraries before compiling the sketches
173181
val librariesTaskName = sourceSet.getTaskName("scanLibraries", "PDE")
174182
val librariesScan = project.tasks.register(librariesTaskName, LibrariesTask::class.java) { task ->
175183
task.description = "Scans the libraries in the sketchbook"
176184
task.librariesDirectory.set(sketchbook?.let { File(it, "libraries") })
177185
// TODO: Save the libraries metadata to settings folder to share between sketches
178186
}
179187

188+
// Create a task to process the .pde files before compiling the java sources
180189
val pdeTaskName = sourceSet.getTaskName("preprocess", "PDE")
181190
val pdeTask = project.tasks.register(pdeTaskName, PDETask::class.java) { task ->
182191
task.description = "Processes the ${sourceSet.name} PDE"
@@ -194,7 +203,7 @@ class ProcessingPlugin @Inject constructor(private val objectFactory: ObjectFact
194203
// TODO: Save the libraries metadata to settings folder to share between sketches
195204
}
196205

197-
// Make sure that the PDE task runs before the java compilation task
206+
// Make sure that the PDE tasks runs before the java compilation task
198207
project.tasks.named(sourceSet.compileJavaTaskName) { task ->
199208
task.dependsOn(pdeTaskName, depsTaskName)
200209
}

java/gradle/src/test/kotlin/ProcessingPluginTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ class ProcessingPluginTest{
270270
}
271271
}
272272

273+
@Test
274+
fun testUseInternalLibraries(){
275+
276+
}
277+
273278
@Test
274279
fun testUseCodeJar(){
275280
// TODO: test if adding jars to the code folder works

0 commit comments

Comments
 (0)