-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
- Loading branch information
Showing
15 changed files
with
165 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
buildSrc/src/main/java/org/opensearch/gradle/jvm/JvmTestSuiteHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.gradle.jvm; | ||
|
||
import org.gradle.api.Project; | ||
import org.gradle.api.plugins.JvmTestSuitePlugin; | ||
import org.gradle.api.plugins.jvm.JvmTestSuite; | ||
import org.gradle.testing.base.TestSuite; | ||
import org.gradle.testing.base.TestingExtension; | ||
|
||
import java.util.Optional; | ||
|
||
public final class JvmTestSuiteHelper { | ||
private JvmTestSuiteHelper() {} | ||
|
||
/** | ||
* Gets the default test suite. This method assumes the Java plugin is applied, | ||
* adapted from {@link org.gradle.api.plugins.internal.JavaPluginHelper} since it is not | ||
* available in Gradle releases predated 8.1. | ||
*/ | ||
public static Optional<JvmTestSuite> getDefaultTestSuite(Project project) { | ||
TestingExtension testing = project.getExtensions().findByType(TestingExtension.class); | ||
if (testing == null) { | ||
return Optional.empty(); | ||
} | ||
|
||
TestSuite defaultTestSuite = testing.getSuites().findByName(JvmTestSuitePlugin.DEFAULT_TEST_SUITE_NAME); | ||
if (!(defaultTestSuite instanceof JvmTestSuite)) { | ||
return Optional.empty(); | ||
} | ||
|
||
return Optional.of((JvmTestSuite) defaultTestSuite); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
buildSrc/src/main/java/org/opensearch/gradle/test/TestSuiteConventionMappings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.gradle.test; | ||
|
||
import org.gradle.api.Project; | ||
import org.gradle.api.internal.ConventionMapping; | ||
import org.opensearch.gradle.jvm.JvmTestSuiteHelper; | ||
|
||
// Temporary workaround for https://docs.gradle.org/8.1/userguide/upgrading_version_8.html#test_task_default_classpath | ||
interface TestSuiteConventionMappings { | ||
default void applyConventionMapping(Project project, ConventionMapping conventionMapping) { | ||
JvmTestSuiteHelper.getDefaultTestSuite(project).ifPresent(defaultTestSuite -> { | ||
conventionMapping.map("testClassesDirs", () -> { return defaultTestSuite.getSources().getOutput().getClassesDirs(); }); | ||
|
||
conventionMapping.map("classpath", () -> { return defaultTestSuite.getSources().getRuntimeClasspath(); }); | ||
}); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
buildSrc/src/main/java/org/opensearch/gradle/test/TestTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.gradle.test; | ||
|
||
import groovy.lang.Closure; | ||
|
||
import org.gradle.api.Task; | ||
import org.gradle.api.tasks.CacheableTask; | ||
import org.gradle.api.tasks.testing.Test; | ||
|
||
@CacheableTask | ||
public class TestTask extends Test implements TestSuiteConventionMappings { | ||
@SuppressWarnings("rawtypes") | ||
@Override | ||
public Task configure(Closure closure) { | ||
final Task t = super.configure(closure); | ||
applyConventionMapping(getProject(), getConventionMapping()); | ||
return t; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters