Skip to content

Commit

Permalink
Merge pull request #43 from DeepBlueRobotics/clean-devices-before-gen…
Browse files Browse the repository at this point in the history
…eration

Clean Generated Device Files Before Regenerating Them
  • Loading branch information
brettle authored May 29, 2024
2 parents 8f7afca + 8406762 commit c042b52
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "com.github.node-gradle.node" version "2.2.4"
id "com.github.node-gradle.node" version "2.2.4"
}

apply plugin: 'java-library'
Expand All @@ -25,21 +25,26 @@ dependencies {

// To please the Windows CI server (and perhaps other Windows machines),
// the template directory needs to be passed to the asyncapi generator as
// an archive.
// an archive.
def templateDir = "${projectDir}/asyncapi-template"
task archiveTemplate(type: Tar) {
archiveFileName = "asyncapi-template.tar"
destinationDirectory = file("$buildDir/tmp")

from(templateDir) {
exclude "node_modules"
into "asyncapi-template" // npm requires that everything be in a top-level folder
exclude "node_modules"
into "asyncapi-template" // npm requires that everything be in a top-level folder
}
}

// Add a task to generate java source code for the devices using npx to run
// the asyncapi generator.
task generateDeviceFiles(type: NpxTask) {
// Clean the output directory first (See #40)
doFirst {
delete outputs
}

def outputDir = "${buildDir}/generated/sources/asyncapi"

// Define the command line that npx should use
Expand All @@ -54,12 +59,16 @@ task generateDeviceFiles(type: NpxTask) {
// when necessary.
inputs.files(archiveTemplate.outputs)
outputs.dir(outputDir).withPropertyName("outputDir")

}

// Include the generated files in the source to compile.
sourceSets.main.java.srcDirs generateDeviceFiles.outputs

// Add a task to manually clean the generated devices folder.
task cleanDeviceFiles(type: Delete) {
delete generateDeviceFiles.outputs
}

// Use a version of node and npm that is known to work.
node {
download = true
Expand Down

0 comments on commit c042b52

Please sign in to comment.