Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the agent-filter file #78

Merged
merged 23 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
@SuppressWarnings("unused")
public class UniqueIdTrackingTestExecutionListener implements TestExecutionListener {

private static final String OUTPUT_DIR_SYSTEM_PROPERTY = "graalvm.testids.outputdir";

static final String FILE_NAME = "test_ids.txt";

private final List<String> uniqueIds = new ArrayList<>();
Expand Down Expand Up @@ -105,11 +107,17 @@ public void testPlanExecutionFinished(TestPlan testPlan) {
@SuppressWarnings("ResultOfMethodCallIgnored")
private static File getFile() {

File buildDir;
File buildDir = null;

String buildDirProp = System.getProperty(OUTPUT_DIR_SYSTEM_PROPERTY, null);
if (buildDirProp != null) {
buildDir = new File(buildDirProp);
}

if (new File("pom.xml").exists()) {
if (buildDir == null && new File("pom.xml").exists()) {
buildDir = new File("target");
} else {
}
if (buildDir == null) {
buildDir = new File("build");
}

Expand Down
49 changes: 20 additions & 29 deletions native-gradle-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,10 @@ nativeBuild {
runtimeArgs("--help") // Passes '--help' to built image, during "nativeRun" task
systemProperties = [name1: 'value1', name2: 'value2'] // Sets system properties for the native image builder
agent = false // Can be also set on command line using '-Pagent'
persistConfig = false // Used in conjunction with 'agent' to save its output to META-INF
}

nativeTest {
agent = false // Can be also set on command line using '-Pagent'
persistConfig = false // Used in conjunction with 'agent' to save its output to META-INF
//...
// all of the options from 'nativeBuild' block are supported here except for changing main class name.
// Note that 'nativeBuild' configuration is separate to 'nativeTest' one and that they don't inherit settings from each other.
Expand All @@ -97,29 +95,25 @@ Kotlin
</summary>

```kotlin
tasks {
nativeBuild {
imageName.set("application")
mainClass.set("org.test.Main") // Main class
buildArgs("--no-server") // Arguments to be passed to native-image invocation
debug.set(false) // Determines if debug info should be generated
verbose.set(false)
fallback.set(false)
classpath("dir1", "dir2") // Adds "dir1" and "dir2" to the classpath
jvmArgs("flag") // Passes 'flag' directly to the JVM running the native image builder
runtimeArgs("--help") // Passes '--help' to built image, during "nativeRun" task
systemProperties.put("key1", "value1") // Sets a system property for the native-image builder
agent.set(false) // Can be also set on command line using '-Pagent'
persistConfig.set(false) // Used in conjunction with 'agent' to save its output to META-INF
}

nativeTest {
agent.set(false) // Can be also set on command line using '-Pagent'
persistConfig.set(false) // Used in conjunction with 'agent' to save its output to META-INF
//...
// all of the options from 'nativeBuild' block are supported here except for changing main class name
// Note that 'nativeBuild' configuration is separate to 'nativeTest' one and that they don't inherit settings from each other
}
nativeBuild {
imageName.set("application")
mainClass.set("org.test.Main") // Main class
buildArgs("--no-server") // Arguments to be passed to native-image invocation
debug.set(false) // Determines if debug info should be generated
verbose.set(false)
fallback.set(false)
classpath("dir1", "dir2") // Adds "dir1" and "dir2" to the classpath
jvmArgs("flag") // Passes 'flag' directly to the JVM running the native image builder
runtimeArgs("--help") // Passes '--help' to built image, during "nativeRun" task
systemProperties.put("key1", "value1") // Sets a system property for the native-image builder
agent.set(false) // Can be also set on command line using '-Pagent'
}

nativeTest {
agent.set(false) // Can be also set on command line using '-Pagent'
//...
// all of the options from 'nativeBuild' block are supported here except for changing main class name
// Note that 'nativeBuild' configuration is separate to 'nativeTest' one and that they don't inherit settings from each other
}
```

Expand All @@ -128,10 +122,7 @@ tasks {
<br />


> :information_source: Most of the plugin configuration syntax and tasks from `io.micronaut.application` and `com.palantir.graal` plugins is out of the box supported at the moment via aliasing.
> However, this behaviour should be considered transitional and therefore deprecated.

> :information_source: Also note that for options that can be set using command-line, if both DSL and command-line options are present, command-line options take precedence.
> :information_source: For options that can be set using command-line, if both DSL and command-line options are present, command-line options take precedence.

### Available tasks:
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,34 @@ configurations {
gradlePlugin.testSourceSets(sourceSets.functionalTest)
configurations.functionalTestImplementation.extendsFrom(configurations.testImplementation)

['functionalTest', 'fullFunctionalTest'].each {
def graalVm = javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(11))
vendor.set(JvmVendorSpec.matching("GraalVM"))
}

['functionalTest', 'fullFunctionalTest', 'configCacheFunctionalTest'].each {
// Add a task to run the functional tests
tasks.register(it, Test) {
// Any change to samples invalidates functional tests
inputs.files(files("src/samples"))
inputs.files(configurations.functionalTestCommonRepository)
systemProperty('common.repo.url', configurations.functionalTestCommonRepository.incoming.files.files[0])
systemProperty('versions.junit', project.properties.junit_jupiter_version)
environment('GRAALVM_HOME', javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(11))
vendor.set(JvmVendorSpec.matching("GraalVM Community"))
}.forUseAtConfigurationTime().get().metadata.installationPath.asFile.absolutePath)
environment('GRAALVM_HOME', graalVm.forUseAtConfigurationTime().get().metadata.installationPath.asFile.absolutePath)
testClassesDirs = sourceSets.functionalTest.output.classesDirs
classpath = sourceSets.functionalTest.runtimeClasspath
javaLauncher.set(graalVm)
}
}

tasks.named('fullFunctionalTest') {
systemProperty('full.coverage', 'true')
}

tasks.named('configCacheFunctionalTest') {
systemProperty('config.cache', 'true')
}

tasks.named('check') {
// Run the functional tests as part of `check`
dependsOn(tasks.fullFunctionalTest)
Expand Down
3 changes: 2 additions & 1 deletion native-gradle-plugin/config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
<module name="LineLength">
<property name="max" value="250"/>
</module>
<module name="SuppressWarningsFilter" />
<module name="TreeWalker">

<module name="SuppressWarningsHolder" />
<!-- Disallows direct calls to "AnnotatedElement.get(Declared)Annotation(s)". This check can yield false positives,
i.e., it will match any ".get(Declared)Annotation(s)" calls that are not preceded by "GuardedAnnotationAccess"
since checkstyle relies only on pattern matching and it cannot determine the type of the call's receiver object. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,25 @@ import org.graalvm.buildtools.gradle.fixtures.AbstractFunctionalTest
class JavaApplicationFunctionalTest extends AbstractFunctionalTest {
def "can build a native image for a simple application"() {
gradleVersion = version
def nativeApp = file("build/native/java-application")
def nativeApp = file("build/native/nativeBuild/java-application")
debug = true

given:
withSample("java-application")

buildFile << """
// force realization of the run task to verify that it
// doesn't accidentally introduce a dependency
tasks.getByName('run')
""".stripIndent()

when:
run 'nativeBuild'

then:
tasks {
succeeded ':jar', ':nativeBuild'
// doesNotContain ':build'
doesNotContain ':build', ':run'
}

and:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright (c) 2021, 2021 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or
* data (collectively the "Software"), free of charge and under any and all
* copyright rights in the Software, and any and all patent rights owned or
* freely licensable by each licensor hereunder covering either (i) the
* unmodified Software as contributed to or provided by such licensor, or (ii)
* the Larger Works (as defined below), to deal in both
*
* (a) the Software, and
*
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
*
* The above copyright notice and either this complete permission notice or at a
* minimum a reference to the UPL must be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.graalvm.buildtools.gradle

import org.graalvm.buildtools.gradle.fixtures.AbstractFunctionalTest
import spock.lang.Unroll

class JavaApplicationWithAgentFunctionalTest extends AbstractFunctionalTest {

@Unroll("agent is passed and generates resources files on Gradle #version with JUnit Platform #junitVersion")
def "agent is passed"() {
gradleVersion = version
debug = true
given:
withSample("java-application-with-reflection")

when:
run 'nativeTest'

then:
tasks {
succeeded ':jar',
':filterAgentTestResources',
':nativeTest'
doesNotContain ':build'
}

then:
outputContains """
[ 4 containers found ]
[ 0 containers skipped ]
[ 4 containers started ]
[ 0 containers aborted ]
[ 4 containers successful ]
[ 0 containers failed ]
[ 7 tests found ]
[ 0 tests skipped ]
[ 7 tests started ]
[ 0 tests aborted ]
[ 7 tests successful ]
[ 0 tests failed ]
""".trim()

and:
['jni', 'proxy', 'reflect', 'resource', 'serialization'].each { name ->
assert file("build/native/agent-output/test/${name}-config.json").exists()
}

where:
version << TESTED_GRADLE_VERSIONS
junitVersion = System.getProperty('versions.junit')
}

@Unroll("agent property takes precedence on Gradle #version with JUnit Platform #junitVersion")
def "agent property takes precedence"() {
gradleVersion = version

given:
withSample("java-application-with-reflection")

when:
fails 'nativeTest', '-Pagent=false'

then:
outputContains """org.graalvm.demo.ApplicationTest > message is hello native FAILED"""

where:
version << TESTED_GRADLE_VERSIONS
junitVersion = System.getProperty('versions.junit')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class JavaApplicationWithTestsFunctionalTest extends AbstractFunctionalTest {
@Unroll("can execute tests in a native image on Gradle #version with JUnit Platform #junitVersion")
def "can build a native image and run it"() {
gradleVersion = version
def nativeTestsApp = file("build/native/native-tests")
def nativeTestsApp = file("build/native/nativeTestBuild/java-application-tests")

given:
withSample("java-application-with-tests")
Expand All @@ -61,6 +61,8 @@ class JavaApplicationWithTestsFunctionalTest extends AbstractFunctionalTest {
succeeded ':testClasses', ':nativeTestBuild'
// doesNotContain ':build'
}
outputDoesNotContain "Running in 'test discovery' mode. Note that this is a fallback mode."
outputContains "Running in 'test listener' mode."

and:
nativeTestsApp.exists()
Expand Down Expand Up @@ -109,6 +111,9 @@ class JavaApplicationWithTestsFunctionalTest extends AbstractFunctionalTest {
}

then:
outputDoesNotContain "Running in 'test discovery' mode. Note that this is a fallback mode."
outputContains "Running in 'test listener' mode."

outputContains """
[ 3 containers found ]
[ 0 containers skipped ]
Expand Down
Loading