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

Add support for test-jar artifacts #281

Merged
merged 3 commits into from Aug 10, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy-documentation.yml
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
graalvm-version: [ dev ]
graalvm-version: [ latest ]
java-version: [ 11 ]
os: [ ubuntu-20.04 ]
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-snapshots.yml
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
graalvm-version: [ dev ]
graalvm-version: [ latest ]
java-version: [ 11 ]
os: [ ubuntu-20.04 ]
steps:
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/test-native-gradle-plugin.yml
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
fail-fast: false
matrix:
graalvm-version: [ dev ]
graalvm-version: [ latest ] # dev
java-version: [ 11 ]
os: [ ubuntu-20.04 ]
steps:
Expand All @@ -53,8 +53,10 @@ jobs:
strategy:
fail-fast: false
matrix:
gradle-version: ["current", "7.3.3", "7.2", "7.1", "6.8.3", "6.7.1"]
graalvm-version: [ dev ]
gradle-version: ["current", "6.7.1"]
# Following versions are disabled temporarily in order to speed up PR testing
# "7.3.3", "7.2", "7.1", "6.8.3"
graalvm-version: [ latest ] # dev
java-version: [ 11 ]
os: [ ubuntu-20.04 ]
steps:
Expand All @@ -81,7 +83,7 @@ jobs:
strategy:
fail-fast: false
matrix:
graalvm-version: [ dev ]
graalvm-version: [ latest ]
java-version: [ 11 ]
os: [ windows-latest ]
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-native-maven-plugin.yml
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
fail-fast: false
matrix:
graalvm-version: [ dev ]
graalvm-version: [ latest ] # dev
java-version: [ 11 ]
os: [ ubuntu-20.04 ]
steps:
Expand All @@ -55,7 +55,7 @@ jobs:
strategy:
fail-fast: false
matrix:
graalvm-version: [ dev ]
graalvm-version: [ latest ] # dev
java-version: [ 11 ]
os: [ windows-latest ]
steps:
Expand Down
2 changes: 1 addition & 1 deletion docs/src/docs/asciidoc/announcement.adoc
Expand Up @@ -144,7 +144,7 @@ Adding our new plugin to the existing _Maven_ project requires adding the follow
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/docs/asciidoc/maven-plugin.adoc
Expand Up @@ -40,7 +40,7 @@ Add the following profile to your `pom.xml` file to register the `native-maven-p
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
Expand Down
2 changes: 1 addition & 1 deletion native-maven-plugin/reproducers/issue-144/pom.xml
Expand Up @@ -92,7 +92,7 @@
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
Expand Down
Expand Up @@ -49,13 +49,13 @@ class JavaApplicationFunctionalTest extends AbstractGraalVMMavenFunctionalTest {

when:
mvn '-Pnative', '-DskipTests', '-DnativeDryRun', '-DuseArgFile=false',
'-Dclasspath=/testcp', '-Ddebug', '-Dfallback=false', '-Dverbose', '-DsharedLibrary',
'-Dclasspath=/', '-Ddebug', '-Dfallback=false', '-Dverbose', '-DsharedLibrary',
'-DquickBuild',
'package'

then:
buildSucceeded
outputContains "native-image -cp /testcp -g --no-fallback --verbose --shared -Ob"
outputContains "native-image -cp / -g --no-fallback --verbose --shared -Ob"
}

def "can build and execute a native image with the Maven plugin"() {
Expand Down
Expand Up @@ -277,16 +277,20 @@ protected List<String> getBuildArgs() throws MojoExecutionException {
return Collections.unmodifiableList(cliArgs);
}

protected Path processArtifact(Artifact artifact, String artifactType) throws MojoExecutionException {
protected Path processSupportedArtifacts(Artifact artifact) throws MojoExecutionException {
return processArtifact(artifact, "jar", "test-jar", "war");
}

protected Path processArtifact(Artifact artifact, String... artifactTypes) throws MojoExecutionException {
File artifactFile = artifact.getFile();

if (artifactFile == null) {
logger.debug("Missing artifact file for artifact " + artifact + " (type: " + artifact.getType() + ")");
return null;
}

if (!artifactType.equals(artifact.getType())) {
logger.warn("Ignoring non-jar type ImageClasspath Entry " + artifact);
if (Arrays.stream(artifactTypes).noneMatch(a -> a.equals(artifact.getType()))) {
logger.warn("Ignoring ImageClasspath Entry '" + artifact + "' with unsupported type '" + artifact.getType() + "'");
return null;
}
if (!artifactFile.exists()) {
Expand All @@ -302,7 +306,7 @@ protected Path processArtifact(Artifact artifact, String artifactType) throws Mo
}

protected void addArtifactToClasspath(Artifact artifact) throws MojoExecutionException {
Optional.ofNullable(processArtifact(artifact, "jar")).ifPresent(imageClasspath::add);
Optional.ofNullable(processSupportedArtifacts(artifact)).ifPresent(imageClasspath::add);
}

protected void warnIfWrongMetaInfLayout(Path jarFilePath, Artifact artifact) throws MojoExecutionException {
Expand Down Expand Up @@ -380,6 +384,7 @@ protected void populateClasspath() throws MojoExecutionException {
populateApplicationClasspath();
addDependenciesToClasspath();
}
imageClasspath.removeIf(entry -> !entry.toFile().exists());
}

protected String getClasspath() throws MojoExecutionException {
Expand Down
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2020, 2022, 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;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;

/**
* Mojo used to invoke native image building by attaching it to a phase.
* Deprecated in favor of compile-no-fork goal.
*/
@Deprecated
@Mojo(name = "build", defaultPhase = LifecyclePhase.PACKAGE,
requiresDependencyResolution = ResolutionScope.RUNTIME,
requiresDependencyCollection = ResolutionScope.RUNTIME)
public class DeprecatedNativeBuildMojo extends NativeCompileNoForkMojo {

@Override
public void execute() throws MojoExecutionException {
logger.warn("'native:build' goal is deprecated. Use 'native:compile-no-fork' instead.");
super.execute();
}

}
Expand Up @@ -63,7 +63,7 @@
* This goal runs native builds. It functions the same as the native:compile goal, but it
* does not fork the build, so it is suitable for attaching to the build lifecycle.
*/
@Mojo(name = "build", defaultPhase = LifecyclePhase.PACKAGE,
@Mojo(name = "compile-no-fork", defaultPhase = LifecyclePhase.PACKAGE,
requiresDependencyResolution = ResolutionScope.RUNTIME,
requiresDependencyCollection = ResolutionScope.RUNTIME)
public class NativeCompileNoForkMojo extends AbstractNativeMojo {
Expand Down
2 changes: 1 addition & 1 deletion samples/java-application-with-reflection/pom.xml
Expand Up @@ -131,7 +131,7 @@
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
Expand Down
2 changes: 1 addition & 1 deletion samples/java-application-with-resources/pom.xml
Expand Up @@ -100,7 +100,7 @@
<id>build-native</id>
<goals>
<goal>generateResourceConfig</goal>
<goal>build</goal>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
Expand Down
4 changes: 2 additions & 2 deletions samples/java-application-with-tests/pom.xml
Expand Up @@ -95,7 +95,7 @@
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
Expand Down Expand Up @@ -191,7 +191,7 @@
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
<configuration>
Expand Down
4 changes: 2 additions & 2 deletions samples/java-application/pom.xml
Expand Up @@ -79,7 +79,7 @@
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
Expand Down Expand Up @@ -126,7 +126,7 @@
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
Expand Down
2 changes: 1 addition & 1 deletion samples/java-library/pom.xml
Expand Up @@ -79,7 +79,7 @@
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
Expand Down
4 changes: 2 additions & 2 deletions samples/metadata-repo-integration/pom.xml
Expand Up @@ -80,7 +80,7 @@
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
Expand Down Expand Up @@ -109,7 +109,7 @@
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
Expand Down
4 changes: 2 additions & 2 deletions samples/native-config-integration/pom.xml
Expand Up @@ -84,7 +84,7 @@
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
Expand Down Expand Up @@ -128,7 +128,7 @@
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
Expand Down