@@ -17,33 +17,71 @@ import javax.inject.Inject
1717
1818class ProcessingPlugin @Inject constructor(private val objectFactory : ObjectFactory ) : Plugin<Project> {
1919 override fun apply (project : Project ) {
20+ val sketchName = project.layout.projectDirectory.asFile.name.replace(Regex (" [^a-zA-Z0-9_]" ), " _" )
21+
2022 val isProcessing = project.findProperty(" processing.version" ) != null
21- val processingVersion = project.findProperty(" processing.version" ) as String? ? : " 4.0.0 "
23+ val processingVersion = project.findProperty(" processing.version" ) as String? ? : " 4.3.4 "
2224 val processingGroup = project.findProperty(" processing.group" ) as String? ? : " org.processing"
25+ val workingDir = project.findProperty(" processing.workingDir" ) as String?
26+
27+ // Grab the settings from the most likely location
28+ var settingsFolder = (project.findProperty(" processing.settings" ) as String? )?.let { File (it) }
29+ if (settingsFolder == null ) {
30+ val osName = System .getProperty(" os.name" ).lowercase()
31+ if (osName.contains(" win" )) {
32+ settingsFolder = File (System .getenv(" APPDATA" ), " Processing" )
33+ } else if (osName.contains(" mac" )) {
34+ settingsFolder = File (System .getProperty(" user.home" ), " Library/Processing" )
35+ } else if (osName.contains(" nix" ) || osName.contains(" nux" )) {
36+ settingsFolder = File (System .getProperty(" user.home" ), " .processing" )
37+ }
38+ }
2339
40+ val preferences = File (settingsFolder, " preferences.txt" )
41+ val prefs = Properties ()
42+ prefs.load(preferences.inputStream())
43+ prefs.setProperty(" export.application.fullscreen" , " false" )
44+ prefs.setProperty(" export.application.present" , " false" )
45+ prefs.setProperty(" export.application.stop" , " false" )
46+ prefs.store(preferences.outputStream(), null )
47+
48+ val sketchbook = prefs.getProperty(" sketchbook.path.four" )
49+
50+ // Apply the Java plugin to the Project
2451 project.plugins.apply (JavaPlugin ::class .java)
2552
2653 if (isProcessing){
27- project.layout.buildDirectory.set(File (project.findProperty(" processing.workingDir" ) as String ))
54+ // Set the build directory to a temp file so it doesn't clutter up the sketch folder
55+ // Only if the build directory doesn't exist, otherwise proceed as normal
56+ if (! project.layout.buildDirectory.asFile.get().exists()) {
57+ project.layout.buildDirectory.set(File (project.findProperty(" processing.workingDir" ) as String ))
58+ }
59+ // Disable the wrapper in the sketch to keep it cleaner
2860 project.tasks.findByName(" wrapper" )?.enabled = false
2961 }
3062
63+ // Add the compose plugin to wrap the sketch in an executable
3164 project.plugins.apply (" org.jetbrains.compose" )
65+
66+ // TODO: Do we need these?
67+ // Add kotlin support
3268 project.plugins.apply (" org.jetbrains.kotlin.jvm" )
69+ // Add jetpack compose support
3370 project.plugins.apply (" org.jetbrains.kotlin.plugin.compose" )
3471
35- // TODO: Add to tests
72+ // Add the Processing core library (within Processing from the internal maven repo and outside from the internet)
3673 project.dependencies.add(" implementation" , " $processingGroup :core:${processingVersion} " )
37- // TODO: Add tests to test if code jars are working
74+
75+ // Add the jars in the code folder
3876 project.dependencies.add(" implementation" , project.fileTree(" src" ).apply { include(" **/code/*.jar" ) })
3977
40- // Base JOGL and Gluegen dependencies
78+ // Add JOGL and Gluegen dependencies
4179 // TODO: Add only if user is compiling for P2D or P3D
80+ // TODO: Would require adding this after pre-processing
4281 project.dependencies.add(" runtimeOnly" , " org.jogamp.jogl:jogl-all-main:2.5.0" )
4382 project.dependencies.add(" runtimeOnly" , " org.jogamp.gluegen:gluegen-rt-main:2.5.0" )
4483
4584 // TODO: Only add the native dependencies for the platform the user is building for
46-
4785 // MacOS specific native dependencies
4886 project.dependencies.add(" runtimeOnly" , " org.jogamp.jogl:jogl-all:2.5.0:natives-macosx-universal" )
4987 project.dependencies.add(" runtimeOnly" , " org.jogamp.gluegen:gluegen-rt:2.5.0:natives-macosx-universal" )
@@ -62,47 +100,53 @@ class ProcessingPlugin @Inject constructor(private val objectFactory: ObjectFact
62100 project.dependencies.add(" runtimeOnly" , " org.jogamp.jogl:nativewindow:2.5.0:natives-windows-amd64" )
63101 project.dependencies.add(" runtimeOnly" , " org.jogamp.jogl:nativewindow:2.5.0:natives-linux-amd64" )
64102
103+ // Add the repositories necessary for building the sketch
65104 project.repositories.add(project.repositories.maven { it.setUrl(" https://jogamp.org/deployment/maven" ) })
66105 project.repositories.add(project.repositories.mavenCentral())
67106 project.repositories.add(project.repositories.mavenLocal())
68107
108+ // Configure the compose Plugin
69109 project.extensions.configure(ComposeExtension ::class .java) { extension ->
70110 extension.extensions.getByType(DesktopExtension ::class .java).application { application ->
71- application.mainClass = project.layout.projectDirectory.asFile.name.replace(Regex (" [^a-zA-Z0-9_]" ), " _" )
111+ // Set the class to be executed initially
112+ application.mainClass = sketchName
72113 application.nativeDistributions.modules(" java.management" )
73114 }
74115 }
75116
76- project.tasks.create(" sketch" ).apply {
77- group = " processing"
78- description = " Runs the Processing sketch"
79- dependsOn(" run" )
80- }
81- project.tasks.create(" present" ).apply {
82- group = " processing"
83- description = " Presents the Processing sketch"
84- doFirst{
85- project.tasks.withType(JavaExec ::class .java).configureEach{ task ->
86- task.systemProperty(" processing.fullscreen" , " true" )
117+ // Add convenience tasks for running, presenting, and exporting the sketch outside of Processing
118+ if (! isProcessing) {
119+ project.tasks.create(" sketch" ).apply {
120+ group = " processing"
121+ description = " Runs the Processing sketch"
122+ dependsOn(" run" )
123+ }
124+ project.tasks.create(" present" ).apply {
125+ group = " processing"
126+ description = " Presents the Processing sketch"
127+ doFirst {
128+ project.tasks.withType(JavaExec ::class .java).configureEach { task ->
129+ task.systemProperty(" processing.fullscreen" , " true" )
130+ }
87131 }
132+ finalizedBy(" run" )
88133 }
89- finalizedBy(" run" )
90- }
91- project.tasks.create(" export" ).apply {
92- group = " processing"
93- description = " Creates a distributable version of the Processing sketch"
94-
95- dependsOn(" createDistributable" )
96- doLast{
97- project.copy {
98- it.from(project.tasks.named(" createDistributable" ).get().outputs.files)
99- it.into(project.layout.projectDirectory)
134+ project.tasks.create(" export" ).apply {
135+ group = " processing"
136+ description = " Creates a distributable version of the Processing sketch"
137+
138+ dependsOn(" createDistributable" )
139+ doLast {
140+ project.copy {
141+ it.from(project.tasks.named(" createDistributable" ).get().outputs.files)
142+ it.into(project.layout.projectDirectory)
143+ }
100144 }
101145 }
102146 }
103147
104148 project.extensions.getByType(JavaPluginExtension ::class .java).sourceSets.all { sourceSet ->
105- // TODO: also supporting normal gradle setup
149+ // For each java source set (mostly main) add a new source set for the PDE files
106150 val pdeSourceSet = objectFactory.newInstance(
107151 DefaultPDESourceDirectorySet ::class .java,
108152 objectFactory.sourceDirectorySet(" ${sourceSet.name} .pde" , " ${sourceSet.name} Processing Source" )
@@ -114,42 +158,26 @@ class ProcessingPlugin @Inject constructor(private val objectFactory: ObjectFact
114158 }
115159 sourceSet.allSource.source(pdeSourceSet)
116160
117- val outputDirectory = project.layout.buildDirectory.file( " generated/pde/" + sourceSet.name).get().asFile
161+ val outputDirectory = project.layout.buildDirectory.asFile.get().resolve( " generated/pde/" + sourceSet.name)
118162 sourceSet.java.srcDir(outputDirectory)
119163
120164 val taskName = sourceSet.getTaskName(" preprocess" , " PDE" )
121165 project.tasks.register(taskName, ProcessingTask ::class .java) { task ->
122166 task.description = " Processes the ${sourceSet.name} PDE"
123167 task.source = pdeSourceSet
124168 task.outputDirectory = outputDirectory
169+ task.sketchName = sketchName
170+ task.workingDir = workingDir
171+ task.sketchBook = sketchbook
125172 }
126173
127174 project.tasks.named(
128175 sourceSet.compileJavaTaskName
129- ) { task -> task.dependsOn(taskName) }
130- }
131-
132- // TODO: get this data from code used within the editor
133- var settingsFolder = File (System .getProperty(" user.home" )," .processing" )
134- val osName = System .getProperty(" os.name" ).lowercase()
135- if (osName.contains(" win" )) {
136- settingsFolder = File (System .getenv(" APPDATA" ), " Processing" )
137- } else if (osName.contains(" mac" )) {
138- settingsFolder = File (System .getProperty(" user.home" ), " Library/Processing" )
139- }else if (osName.contains(" nix" ) || osName.contains(" nux" )) {
140- settingsFolder = File (System .getProperty(" user.home" ), " .processing" )
176+ ) { task ->
177+ task.dependsOn(taskName)
178+ }
141179 }
142180
143- val preferences = File (settingsFolder, " preferences.txt" )
144- val prefs = Properties ()
145- prefs.load(preferences.inputStream())
146- prefs.setProperty(" export.application.fullscreen" , " false" )
147- prefs.setProperty(" export.application.present" , " false" )
148- prefs.setProperty(" export.application.stop" , " false" )
149- prefs.store(preferences.outputStream(), null )
150-
151- val sketchbook = prefs.getProperty(" sketchbook.path.four" )
152-
153181 // TODO: Move to ProcessingTask after reading the libs from the sketch
154182 File (sketchbook, " libraries" ).listFiles { file -> file.isDirectory }?.forEach{
155183 project.dependencies.add(" implementation" , project.fileTree(it).apply { include(" **/*.jar" ) })
0 commit comments