diff --git a/Nx/build.gradle.kts b/Nx/build.gradle.kts index 6c97e95..8dfe56e 100644 --- a/Nx/build.gradle.kts +++ b/Nx/build.gradle.kts @@ -1,26 +1,50 @@ +import java.nio.file.Paths +import kotlin.io.path.pathString + +/* +External Configuration Properties +================================= +Below values can be overridden when invoking gradle build using property arguments, for example: + +./gradlew build -Pversion=2.0 + + group => The group ID + version => The version + targetJreVersion => Version number assigned to sourceCompatibility and targetCompatibility + nuixEngineDir => Overrides value to engine release otherwise pulled from ENV var NUIX_ENGINE_DIR + tempDir => Used to override temp directory for testing which would otherwise default to dir in localappdata + testDataDir => Directory tests can load test data they depend on from + rubyExamplesDirectory => Directory containing Ruby script files used to test various aspects from scripting +testOutputDirectoryRoot => Root directory where tests may write data while running. Each test run will create a timestamp subdirectory + nuixUsername => Username used to authenticate with CLS (Cloud License Server). Otherwise, would be pulled from ENV var NUIX_USERNAME + nuixPassword => Password used to authenticate with CLS (Cloud License Server). Otherwise, would be pulled from ENV var NUIX_PASSWORD +*/ + plugins { id("java") } -group = "com.nuix.nx" -version = "1.19.0" +group = findProperty("group") ?: "com.nuix.nx" +version = findProperty("version") ?: "1.19.0" -val sourceCompatibility = 11 -val targetCompatibility = 11 +val sourceCompatibility = findProperty("targetJreVersion") ?: 11 +val targetCompatibility = findProperty("targetJreVersion") ?: 11 -// Directory containing Nuix Engine release -val nuixEngineDirectory: String = System.getenv("NUIX_ENGINE_DIR") +// Directory containing Nuix Engine release. We first attempt to pull from ENV +var nuixEngineDirectory: String = System.getenv("NUIX_ENGINE_DIR") +// If we have it provided externally via a property, use that instead +if (properties.containsKey("nuixEngineDir")) { + nuixEngineDirectory = findProperty("nuixEngineDir").toString() +} +// Finally, if we don't have a value, throw exception since we require this println("NUIX_ENGINE_DIR: ${nuixEngineDirectory}") if (nuixEngineDirectory.isEmpty()) { throw InvalidUserDataException("Please populate the environment variable 'NUIX_ENGINE_DIR' with directory containing a Nuix Engine release") } -val engineLibDir = "${nuixEngineDirectory}\\lib" +val engineLibDir = Paths.get(nuixEngineDirectory, "lib").pathString println("engineLibDir: ${engineLibDir}") -val nuixAppLibDir = "C:\\Program Files\\Nuix\\Nuix 100.2\\lib" -println("nuixAppLibDir: ${nuixAppLibDir}") - repositories { mavenCentral() } @@ -73,7 +97,7 @@ fun configureTestEnvironment(test: Test) { println("Running 'configureTestEnvironment'...") // Engine runtime temp directory - val nuixTempDirectory = findProperty("tempDir") ?: "${System.getenv("LOCALAPPDATA")}\\Temp\\Nuix" + val nuixTempDirectory = findProperty("tempDir") ?: Paths.get(System.getenv("LOCALAPPDATA"),"Temp","Nuix").pathString // Args passed to JVM running tests test.jvmArgs( @@ -84,18 +108,24 @@ fun configureTestEnvironment(test: Test) { ) // Directory used to store data a test may rely on (like sample data) - val testDataDirectory = "${projectDir}\\..\\..\\TestData" + val testDataDirectory = findProperty("testDataDir") ?: Paths.get("$projectDir", "..", "..", "TestData").pathString // Directory used to store data a test may rely on (like sample data) - val rubyExamplesDirectory = "${projectDir}\\..\\..\\Examples" + val rubyExamplesDirectory = findProperty("rubyExamplesDirectory") + ?: Paths.get("$projectDir", "..", "..", "Examples").pathString // Directory that tests may write data to, unique to each test invocation - val testOutputDirectory = "${projectDir}\\..\\..\\TestOutput\\${System.currentTimeMillis()}" + val testOutputDirectoryRoot = findProperty("testOutputDirectoryRoot") + ?: Paths.get("$projectDir", "..", "..", "TestOutput").pathString + val testOutputDirectory = Paths.get(testOutputDirectoryRoot.toString(), "${System.currentTimeMillis()}").pathString + + val binDir = Paths.get(nuixEngineDirectory,"bin").pathString + val binX86Dir = Paths.get(nuixEngineDirectory,"bin","x86").pathString // Configure ENV vars for JVM tests run in test.setEnvironment( // Add our engine release's bin and bin/x86 to PATH - Pair("PATH", "${System.getenv("PATH")};${nuixEngineDirectory}\\bin;${nuixEngineDirectory}\\bin\\x86"), + Pair("PATH", "${System.getenv("PATH")};${binDir};${binX86Dir}"), // Define where tests can place re-usable test data Pair("TEST_DATA_DIRECTORY", testDataDirectory), @@ -107,8 +137,8 @@ fun configureTestEnvironment(test: Test) { Pair("RUBY_EXAMPLES_DIRECTORY", rubyExamplesDirectory), // Forward ENV username and password - Pair("NUIX_USERNAME", System.getenv("NUIX_USERNAME")), - Pair("NUIX_PASSWORD", System.getenv("NUIX_PASSWORD")), + Pair("NUIX_USERNAME", findProperty("nuixUsername") ?: System.getenv("NUIX_USERNAME")), + Pair("NUIX_PASSWORD", findProperty("nuixPassword") ?: System.getenv("NUIX_PASSWORD")), // Forward LOCALAPPDATA and APPDATA Pair("LOCALAPPDATA", System.getenv("LOCALAPPDATA")), @@ -128,7 +158,7 @@ tasks.create("nxOnlyJar") { println("Producing NX only JAR file") from(sourceSets.main.get().output) exclude("com/nuix/innovation/enginewrapper/**") - destinationDirectory.set(File("${projectDir}/../../JAR")) + destinationDirectory.set(Paths.get("$projectDir","..","..","JAR").toFile()) } // Copies plug-in JAR to lib directory of engine release we're running against @@ -168,5 +198,5 @@ tasks.test { // Customize where Javadoc output is written to tasks.getByName("javadoc") { - setDestinationDir(File("${projectDir}/../../docs")) + setDestinationDir(Paths.get("$projectDir","..","..","docs").toFile()) } \ No newline at end of file