/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ import org.opensearch.gradle.test.RestIntegTestTask import java.util.concurrent.Callable apply plugin: 'java' apply plugin: 'idea' apply plugin: 'opensearch.opensearchplugin' apply plugin: 'opensearch.pluginzip' apply plugin: 'opensearch.yaml-rest-test' apply plugin: 'jacoco' apply plugin: 'io.freefair.lombok' def pluginName = 'opensearch-geospatial' def pluginDescription = 'OpenSearch Geospatial plugin to host geospatial features' def projectPath = 'org.opensearch' def pathToPlugin = 'geospatial.plugin' def pluginClassName = 'GeospatialPlugin' tasks.register("preparePluginPathDirs") { mustRunAfter clean doLast { def newPath = pathToPlugin.replace(".", "/") mkdir "src/main/java/org/opensearch/$newPath" mkdir "src/test/java/org/opensearch/$newPath" mkdir "src/yamlRestTest/java/org/opensearch/$newPath" } } opensearchplugin { name pluginName description pluginDescription classname "${projectPath}.${pathToPlugin}.${pluginClassName}" licenseFile rootProject.file('LICENSE') noticeFile rootProject.file('NOTICE') extendedPlugins = ['opensearch-job-scheduler'] } // This requires an additional Jar not published as part of build-tools loggerUsageCheck.enabled = false // No need to validate pom, as we do not upload to maven/sonatype validateNebulaPom.enabled = false buildscript { ext { opensearch_version = System.getProperty("opensearch.version", "3.0.0-SNAPSHOT") buildVersionQualifier = System.getProperty("build.version_qualifier", "") isSnapshot = "true" == System.getProperty("build.snapshot", "true") // 2.2.0-SNAPSHOT -> 2.2.0.0-SNAPSHOT version_tokens = opensearch_version.tokenize('-') opensearch_build = version_tokens[0] + '.0' plugin_no_snapshot = opensearch_build if (buildVersionQualifier) { opensearch_build += "-${buildVersionQualifier}" plugin_no_snapshot += "-${buildVersionQualifier}" } if (isSnapshot) { opensearch_build += "-SNAPSHOT" } opensearch_group = "org.opensearch" } repositories { mavenLocal() maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" } mavenCentral() maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath "${opensearch_group}.gradle:build-tools:${opensearch_version}" classpath "com.diffplug.spotless:spotless-plugin-gradle:5.6.1" classpath "io.freefair.gradle:lombok-plugin:6.4.3" } } apply plugin: "com.diffplug.spotless" ext { isSnapshot = "true" == System.getProperty("build.snapshot", "true") } allprojects { group = opensearch_group version = "${opensearch_build}" targetCompatibility = JavaVersion.VERSION_11 sourceCompatibility = JavaVersion.VERSION_11 } repositories { mavenLocal() maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" } mavenCentral() maven { url "https://plugins.gradle.org/m2/" } } compileJava { options.compilerArgs.addAll(["-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor']) } compileTestJava { options.compilerArgs.addAll(["-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor']) } test { include '**/*Tests.class' systemProperty 'tests.security.manager', 'false' } publishing { repositories { maven { name = "Snapshots" url = "https://aws.oss.sonatype.org/content/repositories/snapshots" credentials { username "$System.env.SONATYPE_USERNAME" password "$System.env.SONATYPE_PASSWORD" } } } publications { pluginZip(MavenPublication) { publication -> pom { name = pluginName description = pluginDescription groupId = "org.opensearch.plugin" licenses { license { name = "The Apache License, Version 2.0" url = "http://www.apache.org/licenses/LICENSE-2.0.txt" } } developers { developer { name = "OpenSearch" url = "https://github.com/opensearch-project/geospatial" } } } } } } configurations { zipArchive } //****************************************************************************/ // Dependencies //****************************************************************************/ dependencies { implementation "org.opensearch.plugin:geo:${opensearch_version}" api project(":libs:h3") yamlRestTestRuntimeOnly "org.apache.logging.log4j:log4j-core:${versions.log4j}" testImplementation "org.hamcrest:hamcrest:${versions.hamcrest}" testImplementation 'org.json:json:20230227' implementation "org.apache.commons:commons-lang3:3.12.0" implementation "org.locationtech.spatial4j:spatial4j:${versions.spatial4j}" implementation "org.locationtech.jts:jts-core:${versions.jts}" implementation "org.apache.commons:commons-csv:1.10.0" zipArchive group: 'org.opensearch.plugin', name:'opensearch-job-scheduler', version: "${opensearch_build}" compileOnly "org.opensearch:opensearch-job-scheduler-spi:${opensearch_build}" } licenseHeaders.enabled = true dependencyLicenses.enabled = false thirdPartyAudit.enabled = false loggerUsageCheck.enabled = false def opensearch_tmp_dir = rootProject.file('build/private/opensearch_tmp').absoluteFile opensearch_tmp_dir.mkdirs() task integTest(type: RestIntegTestTask) { description = "Run tests against a cluster" testClassesDirs = sourceSets.test.output.classesDirs classpath = sourceSets.test.runtimeClasspath } tasks.named("check").configure { dependsOn(integTest) } def _numNodes = findProperty('numNodes') as Integer ?: 1 integTest { systemProperty 'tests.security.manager', 'false' systemProperty 'java.io.tmpdir', opensearch_tmp_dir.absolutePath // allows integration test classes to access test resource from project root path systemProperty('project.root', project.rootDir.absolutePath) systemProperty "https", System.getProperty("https") systemProperty "user", System.getProperty("user") systemProperty "password", System.getProperty("password") doFirst { // Tell the test JVM if the cluster JVM is running under a debugger so that tests can // use longer timeouts for requests. def isDebuggingCluster = getDebug() || System.getProperty("test.debug") != null systemProperty 'cluster.debug', isDebuggingCluster // Set number of nodes system property to be used in tests systemProperty 'cluster.number_of_nodes', "${_numNodes}" // There seems to be an issue when running multi node run or integ tasks with unicast_hosts // not being written, the waitForAllConditions ensures it's written getClusters().forEach { cluster -> cluster.waitForAllConditions() } } // The --debug-jvm command-line option makes the cluster debuggable; this makes the tests debuggable if (System.getProperty("test.debug") != null) { jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005' } } testClusters.integTest { testDistribution = "ARCHIVE" // Cluster shrink exception thrown if we try to set numberOfNodes to 1, so only apply if > 1 if (_numNodes > 1) numberOfNodes = _numNodes // When running integration tests it doesn't forward the --debug-jvm to the cluster anymore // i.e. we have to use a custom property to flag when we want to debug opensearch JVM // since we also support multi node integration tests we increase debugPort per node if (System.getProperty("cluster.debug") != null) { def debugPort = 5005 nodes.forEach { node -> node.jvmArgs("-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=${debugPort}") debugPort += 1 } } // This installs our plugin into the testClusters plugin(project.tasks.bundlePlugin.archiveFile) plugin(provider(new Callable(){ @Override RegularFile call() throws Exception { return new RegularFile() { @Override File getAsFile() { return configurations.zipArchive.asFileTree.getSingleFile() } } } })) // opensearch-geospatial plugin is being added to the list of plugins for the testCluster during build before // the opensearch-job-scheduler plugin, which is causing build failures. From the stack trace, this looks like a bug. // // Exception in thread "main" java.lang.IllegalArgumentException: Missing plugin [opensearch-job-scheduler], dependency of [opensearch-geospatial] // at org.opensearch.plugins.PluginsService.addSortedBundle(PluginsService.java:515) // // A temporary hack is to reorder the plugins list after evaluation but prior to task execution when the plugins are installed. // See https://github.com/opensearch-project/anomaly-detection/blob/fd547014fdde5114bbc9c8e49fe7aaa37eb6e793/build.gradle#L400-L422 nodes.each { node -> def plugins = node.plugins def firstPlugin = plugins.get(0) plugins.remove(0) plugins.add(firstPlugin) } } testClusters.yamlRestTest { plugin(provider(new Callable(){ @Override RegularFile call() throws Exception { return new RegularFile() { @Override File getAsFile() { return configurations.zipArchive.asFileTree.getSingleFile() } } } })) } run { useCluster testClusters.integTest } tasks.withType(RestIntegTestTask)*.configure { classpath += files(project.configurations.runtimeClasspath.findAll { it.name.contains("log4j-core") }) } task integTestRemote(type: RestIntegTestTask) { testClassesDirs = sourceSets.test.output.classesDirs classpath = sourceSets.test.runtimeClasspath systemProperty "https", System.getProperty("https") systemProperty "user", System.getProperty("user") systemProperty "password", System.getProperty("password") systemProperty 'cluster.number_of_nodes', "${_numNodes}" systemProperty 'tests.security.manager', 'false' // Run tests with remote cluster only if rest case is defined if (System.getProperty("tests.rest.cluster") != null) { filter { includeTestsMatching "org.opensearch.geospatial.*IT" } } } spotless { java { removeUnusedImports() importOrder 'java', 'javax', 'org', 'com' eclipse().configFile rootProject.file('formatterConfig.xml') trimTrailingWhitespace() endWithNewline() } } jacocoTestReport { dependsOn test reports { xml.enabled = true html.enabled = true } } check.dependsOn jacocoTestCoverageVerification jacocoTestCoverageVerification.dependsOn jacocoTestReport // updateVersion: Task to auto increment to the next development iteration task updateVersion { onlyIf { System.getProperty('newVersion') } doLast { ext.newVersion = System.getProperty('newVersion') println "Setting version to ${newVersion}." // String tokenization to support -SNAPSHOT ant.replaceregexp(file:'build.gradle', match: '"opensearch.version", "\\d.*"', replace: '"opensearch.version", "' + newVersion.tokenize('-')[0] + '-SNAPSHOT"', flags:'g', byline:true) } }