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 GraalVM Native Image compilation support #2268

Merged
merged 1 commit into from
Feb 17, 2021
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
6 changes: 6 additions & 0 deletions .changes/next-release/feature-AWSSDKforJavav2-61fb1a6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"category": "AWS SDK for Java v2",
"contributor": "",
"type": "feature",
"description": "Created a new archetype, `archetype-app-quickstart`, which allows you to create a simple application with SDK dependencies"
}
6 changes: 6 additions & 0 deletions .changes/next-release/feature-AWSSDKforJavav2-818e995.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"category": "AWS SDK for Java v2",
"contributor": "",
"type": "feature",
"description": "Add GraalVM Native Image configurations for SDK classes"
}
6 changes: 5 additions & 1 deletion archetypes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ This module contains maven archetypes for AWS Java SDK 2.x.

## Archetypes

- [archetype-lambda](archetype-lambda/README.md) - a lambda function template using AWS Java SDK 2.x
- [archetype-app-quickstart](archetype-app-quickstart/README.md) - a simple client application
template using the AWS SDK for Java 2.x
- [archetype-lambda](archetype-lambda/README.md) - an AWS Lambda function
template using the AWS SDK for Java 2.x


61 changes: 61 additions & 0 deletions archetypes/archetype-app-quickstart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Maven Archetype for client applications using the AWS SDK for Java 2.x

## Description
This is an Apache Maven Archetype to create a client application with
a dependency of [AWS Java SDK 2.x][aws-java-sdk-v2].

### Features

The generated application has the following features:

- Uses [Bill of Materials](BOM) to manage SDK dependencies
- Contains the code to create the SDK client
- Out-of-box support of GraalVM Native Image when `nativeImage` is enabled

## Usage

You can use `mvn archetype:generate` to generate a project using this archetype. See [maven archetype usage guidance][maven-archetype-usage] for more information.

- Interactive mode

```
mvn archetype:generate \
-DarchetypeGroupId=software.amazon.awssdk \
-DarchetypeArtifactId=archetype-app-quickstart \
-DarchetypeVersion=2.x
```

- Batch mode

```
mvn archetype:generate \
-DarchetypeGroupId=software.amazon.awssdk \
-DarchetypeArtifactId=archetype-app-quickstart \
-DarchetypeVersion=2.x \
-DgroupId=com.test \
-DnativeImage=true \
-DhttpClient=apache-client \
-DartifactId=sample-project \
-Dservice=s3 \
-DinteractiveMode=false
```

### Parameters

Parameter Name | Default Value | Description
---|---|---
`service` (required) | n/a | Specifies the service client to be used in the application, eg: s3, dynamodb. Only one service should be provided. You can find available services [here][java-sdk-v2-services].
`groupId`(required) | n/a | Specifies the group ID of the project
`artifactId`(required) | n/a | Specifies the artifact ID of the project
`nativeImage`(required) | n/a | Specifies whether GraalVM Native Image configuration should be included
`httpClient`(required) | n/a | Specifies the http client to be used by the SDK client. Available options are `url-connection-client` (sync), `apache-client` (sync), `netty-nio-client` (async). See [http clients][sdk-http-clients]
`javaSdkVersion` | Same version as the archetype version | Specifies the version of the AWS Java SDK 2.x to be used
`version` | 1.0-SNAPSHOT | Specifies the version of the project
`package` | ${groupId} | Specifies the package name for the classes


[aws-java-sdk-v2]: https://github.com/aws/aws-sdk-java-v2
[java-sdk-v2-services]: https://github.com/aws/aws-sdk-java-v2/tree/master/services
[sdk-http-clients]: https://github.com/aws/aws-sdk-java-v2/tree/master/http-clients
[maven-archetype-usage]: https://maven.apache.org/archetype/maven-archetype-plugin/usage.html
[graalvm]: https://www.graalvm.org/docs/getting-started/#native-images
174 changes: 174 additions & 0 deletions archetypes/archetype-app-quickstart/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License").
~ You may not use this file except in compliance with the License.
~ A copy of the License is located at
~
~ http://aws.amazon.com/apache2.0
~
~ or in the "license" file accompanying this file. This file is distributed
~ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
~ express or implied. See the License for the specific language governing
~ permissions and limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>archetypes</artifactId>
<groupId>software.amazon.awssdk</groupId>
<version>2.16.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>archetype-app-quickstart</artifactId>
<packaging>maven-archetype</packaging>
<name>AWS Java SDK :: Archetype App</name>
<description>
The AWS SDK for Java - Maven archetype for a sample application using AWS Java SDK 2.x
</description>

<properties>
<maven.archetype.version>3.2.0</maven.archetype.version>
<maven.resource.plugin.version>3.2.0</maven.resource.plugin.version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
</properties>

<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>archetype-tools</artifactId>
<version>${awsjavasdk.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<!-- Filtering the resource properties to get ${project.version} from archetype metadata.
See https://stackoverflow.com/a/22300149 -->
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>META-INF/maven/archetype-metadata.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>META-INF/maven/archetype-metadata.xml</exclude>
</excludes>
</resource>
</resources>
<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>${maven.archetype.version}</version>
</extension>
</extensions>

<plugins>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>${maven.archetype.version}</version>
<configuration>
<noLog>true</noLog>
<ignoreEOLStyle>true</ignoreEOLStyle>
<skip>${skip.unit.tests}</skip>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>verify</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- Copy the global.vm and serviceMapping.vm from archetype-tools -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin.version}</version>
<executions>
<execution>
<id>unpack-archetype-tools</id>
<phase>process-classes</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>software.amazon.awssdk</groupId>
<artifactId>archetype-tools</artifactId>
<version>${project.version}</version>
<outputDirectory>${basedir}/target/classes/archetype-resources</outputDirectory>
<includes>**/*.vm</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>

<!-- workaround to copy the global.vm and serviceMapping.vm to the sub folders
because global.vm is not so global any more
see https://github.com/aws/aws-sdk-java-v2/issues/1981 -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven.resource.plugin.version}</version>
<executions>
<execution>
<id>copy-resources-to-sub-folder</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/archetype-resources/src/main/java</outputDirectory>
<encoding>UTF-8</encoding>
<resources>
<resource>
<directory>${basedir}/target/classes/archetype-resources</directory>
<includes>
<include>global.vm</include>
<include>serviceMapping.vm</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-resources-to-sub-folder-2</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes</outputDirectory>
<encoding>UTF-8</encoding>
<resources>
<resource>
<directory>${basedir}/target/classes/archetype-resources</directory>
<includes>
<include>global.vm</include>
<include>serviceMapping.vm</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="archetype-app-quickstart"
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/test/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="false" encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>simplelogger.properties</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory/>
<includes>
<include>.gitignore</include>
<include>README.md</include>
</includes>
</fileSet>
</fileSets>
<requiredProperties>
<requiredProperty key="javaSdkVersion">
<defaultValue>${project.version}</defaultValue>
<validationRegex>\d+\.\d+.\d+</validationRegex>
</requiredProperty>
<requiredProperty key="service">
</requiredProperty>
<requiredProperty key="httpClient">
<validationRegex>(url-connection-client|apache-client|netty-nio-client)</validationRegex>
</requiredProperty>
<requiredProperty key="nativeImage">
<validationRegex>(true|false)</validationRegex>
</requiredProperty>
</requiredProperties>
</archetype-descriptor>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Eclipse
.classpath
.project
.settings/

# Intellij
.idea/
*.iml
*.iws

# Mac
.DS_Store

# Maven
target/

**/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#[[#]]# App

This project contains a maven application with [AWS Java SDK 2.x](https://github.com/aws/aws-sdk-java-v2) dependencies.

#[[##]]# Prerequisites
- Java 1.8+
- Apache Maven
- GraalVM Native Image (optional)

#[[##]]# Development

Below is the structure of the generated project.

```
├── src
│   ├── main
│   │   ├── java
│   │   │   └── package
│   │   │   ├── App.java
│   │   │   ├── DependencyFactory.java
│   │   │   └── Handler.java
│   │   └── resources
│   │   └── simplelogger.properties
│   └── test
│   └── java
│   └── package
│   └── HandlerTest.java
```

- `App.java`: main entry of the application
- `DependencyFactory.java`: creates the SDK client
- `Handler.java`: you can invoke the api calls using the SDK client here.

#[[####]]# Building the project
```
mvn clean package
```

#if( $nativeImage == 'true')
#[[####]]# Building the native image

Note that it requires `native-image` installed in your environment

```
mvn clean package -P native-image
```
After it finishes, you can find the generated native image in the `target
` folder.

You can run the following command to execute it.

```
target/${artifactId}
```
#end
Loading