Skip to content

Commit

Permalink
add build logic back into examples so CI passes
Browse files Browse the repository at this point in the history
  • Loading branch information
skovati committed Oct 9, 2024
1 parent fe56e02 commit 6206045
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion procedural/examples/foo-procedures/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'java'
id "gov.nasa.ammos.aerie.procedural.plugin" version "0.0.1"
// id "gov.nasa.ammos.aerie.procedural.plugin" version "0.0.1"
id 'com.gradleup.shadow' version '8.3.3' // delete once ^ is published
}

java {
Expand Down Expand Up @@ -28,3 +29,68 @@ dependencies {
test {
useJUnitPlatform()
}

// delete below once

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

tasks.register('buildAllSchedulingProcedureJars') {
group = 'SchedulingProcedureJars'

dependsOn "generateSchedulingProcedureJarTasks"
dependsOn {
tasks.findAll { task -> task.name.startsWith('buildSchedulingProcedureJar_') }
}
}

tasks.create("generateSchedulingProcedureJarTasks") {
group = 'SchedulingProcedureJars'

final proceduresDir = findFirstMatchingBuildDir("generated/procedures")

if (proceduresDir == null) {
println "No generated procedures folder found"
return
}
println "Generating jar tasks for the following procedures directory: ${proceduresDir}"

final files = file(proceduresDir).listFiles()
if (files.length == 0) {
println "No procedures available within folder ${proceduresDir}"
return
}

files.toList().each { file ->
final nameWithoutExtension = file.name.replace(".java", "")
final taskName = "buildSchedulingProcedureJar_${nameWithoutExtension}"

println "Generating ${taskName} task, which will build ${nameWithoutExtension}.jar"

tasks.create(taskName, ShadowJar) {
group = 'SchedulingProcedureJars'
configurations = [project.configurations.compileClasspath]
from sourceSets.main.output
archiveBaseName = "" // clear
archiveClassifier.set(nameWithoutExtension) // set output jar name
manifest {
attributes 'Main-Class': getMainClassFromGeneratedFile(file)
}
minimize()
} }
}

private String findFirstMatchingBuildDir(String pattern) {
String found = null
final generatedDir = file("build/generated/sources")
generatedDir.mkdirs()
generatedDir.eachDirRecurse { dir -> if (dir.path.contains(pattern)) found = dir.path }
return found
}

private static String getMainClassFromGeneratedFile(File file) {
final fileString = file.toString()
final prefix = "build/generated/sources/annotationProcessor/java/main/"
final index = fileString.indexOf(prefix) + prefix.length()
final trimmed = fileString.substring(index).replace(".java", "")
return trimmed.replace("/", ".")
}

0 comments on commit 6206045

Please sign in to comment.