Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions docs/src/docs/asciidoc/gradle-plugin.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ nativeBuild {
verbose = true // Add verbose output, defaults to false
fallback = true // Sets the fallback mode of native-image, defaults to false
server = true // Sets the server mode, defaults to false
sharedLibrary = false // Determines if image is a shared library, defaults to false if `java-library` plugin isn't included

systemProperties = [name1: 'value1', name2: 'value2'] // Sets the system properties to use for the native image builder
configurationFileDirectories.from(file('src/my-config')) // Adds a native image configuration file directory, containing files like reflection configuration

Expand All @@ -171,6 +173,8 @@ nativeBuild {
verbose.set(true) // Add verbose output, defaults to false
fallback.set(true) // Sets the fallback mode of native-image, defaults to false
server.set(true) // Sets the server mode, defaults to false
sharedLibrary.set(false) // Determines if image is a shared library, defaults to false if `java-library` plugin isn't included

systemProperties.putAll(mapOf(name1 to "value1", name2 to "value2")) // Sets the system properties to use for the native image builder
configurationFileDirectories.from(file("src/my-config")) // Adds a native image configuration file directory, containing files like reflection configuration

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 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

class JavaLibraryFunctionalTest extends AbstractFunctionalTest {

def "can build a native image for a simple library"() {
gradleVersion = version

def libExt = ""
if (IS_LINUX) {
libExt = ".so"
} else if (IS_WINDOWS) {
libExt = ".dll"
} else if (IS_MAC) {
libExt = ".dylib"
}

def library = file("build/native/nativeBuild/java-library" + libExt)
debug = true

given:
withSample("java-library")

when:
run 'nativeBuild'

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

outputContains "-H:+SharedLibrary"

and:
library.exists()

where:
version << TESTED_GRADLE_VERSIONS
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ private void configureJavaProject(Project project, Provider<NativeImageService>
project.getExtensions().findByType(JavaApplication.class).getMainClass()
));

project.getPlugins().withId("java-library", p -> buildExtension.getSharedLibrary().convention(true));

registerServiceProvider(project, nativeImageServiceProvider);

// Register Native Image tasks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ public abstract class NativeImageOptions {
@Input
public abstract Property<Boolean> getAgent();

/**
* Gets the value which determines if shared library is being built.
*
* @return The value which determines if shared library is being built.
*/
@Input
public abstract Property<Boolean> getSharedLibrary();

/**
* Returns the toolchain used to invoke native-image. Currently pointing
* to a Java launcher due to Gradle limitations.
Expand Down Expand Up @@ -210,6 +218,7 @@ public NativeImageOptions(ObjectFactory objectFactory,
getFallback().convention(false);
getVerbose().convention(false);
getAgent().convention(false);
getSharedLibrary().convention(false);
getImageName().convention(defaultImageName);
getJavaLauncher().convention(
toolchains.launcherFor(spec -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public List<String> asArguments() {
appendBooleanOption(cliArgs, options.getFallback().map(NEGATE), "--no-fallback");
appendBooleanOption(cliArgs, options.getVerbose(), "--verbose");
appendBooleanOption(cliArgs, options.getServer(), "-Dcom.oracle.graalvm.isaot=true");
appendBooleanOption(cliArgs, options.getSharedLibrary(), "--shared");
if (getOutputDirectory().isPresent()) {
cliArgs.add("-H:Path=" + getOutputDirectory().get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ abstract class AbstractFunctionalTest extends Specification {
String gradleVersion
boolean debug

boolean IS_WINDOWS = System.getProperty("os.name", "unknown").contains("Windows");
boolean IS_LINUX = System.getProperty("os.name", "unknown").contains("Linux");
boolean IS_MAC = System.getProperty("os.name", "unknown").contains("Mac");

private StringWriter outputWriter
private StringWriter errorOutputWriter
private String output
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 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.maven

class JavaLibraryFunctionalTest extends AbstractGraalVMMavenFunctionalTest {
def "can build native image of a library with the Maven plugin"() {
withSample("java-library")

def libExt = ""
if (IS_LINUX) {
libExt = ".so"
} else if (IS_WINDOWS) {
libExt = ".dll"
} else if (IS_MAC) {
libExt = ".dylib"
}

def library = file("target/java-library" + libExt)

when:
mvn '-Pnative', '-DskipTests', 'package'

then:
buildSucceeded
outputContains "--shared"
and:
library.exists()

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ abstract class AbstractGraalVMMavenFunctionalTest extends Specification {

MavenExecutionResult result

boolean IS_WINDOWS = System.getProperty("os.name", "unknown").contains("Windows");
boolean IS_LINUX = System.getProperty("os.name", "unknown").contains("Linux");
boolean IS_MAC = System.getProperty("os.name", "unknown").contains("Mac");

def setup() {
executor = new IsolatedMavenExecutor(
new File(System.getProperty("java.executable")),
Expand Down
66 changes: 66 additions & 0 deletions samples/java-library/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 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.
*/

plugins {
id 'java-library'
id 'org.graalvm.buildtools.native'
}

repositories {
mavenCentral()
}

def junitVersion = providers.gradleProperty('junit.jupiter.version')
.forUseAtConfigurationTime()
.get()

dependencies {
testImplementation(platform("org.junit:junit-bom:${junitVersion}"))
testImplementation('org.junit.jupiter:junit-jupiter')
}

nativeBuild {
verbose=true
}

test {
useJUnitPlatform()
}
3 changes: 3 additions & 0 deletions samples/java-library/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
native.gradle.plugin.version = 0.9.3-SNAPSHOT
junit.jupiter.version = 5.7.2
junit.platform.version = 1.7.2
Loading