/*
  Copyright 2025 MJM, All Rights Reserved.
 */

plugins {
  id 'com.tridium.niagara-signing'
  id 'com.tridium.niagara' apply false
  id 'com.tridium.niagara-module' apply false
  id 'com.tridium.niagara-rjs' apply false
}

import com.tridium.gradle.plugins.niagara.task.RunNiagaraTestTask

def getGradleProperty(String propName) {
  if (gradle.hasProperty(propName)) {
    gradle.getProperty(propName)
  } else {
    // Get system property, or, failing that, fall back to environment variable
    // This allows setting, e.g., -Pniagara_home=blah
    System.getProperty(propName) ?: System.getenv(propName)
  }
}

ext.niagara_home = getGradleProperty('niagara_home')
ext.niagara_dev_home = getGradleProperty('niagara_dev_home')
ext.niagara_user_home = getGradleProperty('niagara_user_home')


gradle.beforeProject { p ->
  configure(p) {
    def vendorSettings = file("${rootDir}/vendor.gradle")
    if (vendorSettings.exists()) {
      apply from: vendorSettings
    }
    apply from: "${rootDir}/gradle/niagara.gradle"
    tasks.withType(RunNiagaraTestTask) { RunNiagaraTestTask task ->
      task.groups = []
    }
  }
}

subprojects { Project p ->
  p.pluginManager.withPlugin('com.tridium.niagara-module') {
    p.niagaraModule {
      certAlias = "my-cert2"
    }
  }
}
