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
15 changes: 15 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ jobs:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Restore gradle.properties
env:
GRADLE_PROPERTIES: ${{ secrets.GRADLE_PROPERTIES }}
shell: bash
run: |
mkdir -p ~/.gradle/
echo "GRADLE_USER_HOME=${HOME}/.gradle" >> $GITHUB_ENV
echo "${GRADLE_PROPERTIES}" > ~/.gradle/gradle.properties
- name: Restore gpg key
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
shell: bash
run: |
mkdir /home/runner/.gnupg
echo -n "${{ secrets.GPG_PRIVATE_KEY }}" | base64 --decode > /home/runner/.gnupg/secring.gpg
- name: Execute Gradle build
run: ./gradlew clean build --refresh-dependencies --info
- name: Upload test reports
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: Sonatype Publish
name: Publish Central Portal

on:
workflow_dispatch:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ hs_err_pid*
/build/
gradle.properties
/bin/

.idea
139 changes: 52 additions & 87 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import com.vanniktech.maven.publish.SonatypeHost

plugins {
id 'java'
id 'maven-publish'
id 'signing'
id 'checkstyle'
id 'com.diffplug.spotless' version '6.25.0'
id 'com.github.spotbugs' version '6.0.7'
id 'com.github.ben-manes.versions' version '0.51.0'
id 'com.vanniktech.maven.publish' version '0.32.0'
id 'com.diffplug.spotless' version '7.0.3'
id 'com.github.spotbugs' version '6.1.11'
id 'com.github.ben-manes.versions' version '0.52.0'
}

group 'com.formkiq'
version '2.5.0'
version '2.6.0'

spotbugs {
excludeFilter = file("$rootDir/config/spotbugs/spotbugs-exclude.xml")
Expand All @@ -23,15 +23,15 @@ spotless {
}

spotbugsMain {
reports {
html {
enabled = true
reports {
html {
required.set(true)
}
}
}
}
}

checkstyle {
toolVersion '8.29'
toolVersion = '10.12.1'
configFile file("config/checkstyle/checkstyle.xml")
configProperties = [project_loc: "${projectDir}"]
ignoreFailures = false
Expand All @@ -41,96 +41,61 @@ checkstyle {
checkstyleMain.dependsOn spotlessApply

repositories {
jcenter()
}

check {
dependsOn(tasks.publishToMavenLocal)
mavenLocal()
mavenCentral()
}

java {
withJavadocJar()
withSourcesJar()

toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

javadoc {
if(JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}

artifacts {
archives jar

archives javadocJar
archives sourcesJar
}

afterEvaluate {
tasks.getByName('spotlessCheck').dependsOn(tasks.getByName('spotlessApply'))
}


dependencies {
implementation group: 'com.amazonaws', name: 'aws-lambda-java-core', version: '1.2.3'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
implementation group: 'com.amazonaws', name: 'aws-lambda-java-events', version: '3.11.4'
testImplementation group: 'junit', name: 'junit', version:'4.+'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.13.1'
implementation group: 'joda-time', name: 'joda-time', version: '2.14.0'

testImplementation group: 'com.amazonaws', name: 'aws-lambda-java-events', version: '3.15.0'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version:'5.11.4'
testImplementation group: 'org.mock-server', name: 'mockserver-netty', version: '5.15.0'
testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.9'
testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.17'
}

publishing {
publications {
mavenJava(MavenPublication) {
artifactId = 'lambda-runtime-graalvm'
from components.java

pom {
name = 'FormKiQ Lambda Runtime Graalvm'
description = 'Lambda Runtime Graalvm'
url = 'https://github.com/formkiq/lambda-runtime-graalvm'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'mfriesen'
name = 'Mike Friesen'
email = 'mike@formkiq.com'
}
}
scm {
connection = 'scm:git:git://github.com/formkiq/lambda-runtime-graalvm.git'
developerConnection = 'scm:git:ssh://github.com/formkiq/lambda-runtime-graalvm.git'
url = 'https://github.com/formkiq/lambda-runtime-graalvm.git'
}
mavenPublishing {

publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)

pom {
name = "FormKiQ Lambda Runtime Graalvm"
description = "Lambda Runtime Graalvm"
inceptionYear = "2020"
url = "https://github.com/formkiq/lambda-runtime-graalvm"
licenses {
license {
name = "The Apache License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
distribution = "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
}
repositories {
maven {
credentials {
username project.repoUser
password project.repoPassword
}
url "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
//url "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
}
developers {
developer {
id = 'mfriesen'
name = 'Mike Friesen'
}
}
scm {
url = 'https://github.com/formkiq/lambda-runtime-graalvm.git'
connection = 'scm:git:git://github.com/formkiq/lambda-runtime-graalvm.git'
developerConnection = 'scm:git:ssh://github.com/formkiq/lambda-runtime-graalvm.git'
}
}
}

signing {
sign publishing.publications.mavenJava
}
compileJava.dependsOn(tasks.spotlessApply)
check.dependsOn(tasks.publishToMavenLocal)

check {
dependsOn(tasks.publishToMavenLocal)
test {
failFast = true
useJUnitPlatform()
}
3 changes: 2 additions & 1 deletion config/checkstyle/import-control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<allow pkg="com.amazonaws.services.lambda.runtime" />
<allow pkg="com.google.gson" />
<allow pkg="com.sun.net.httpserver" />


<allow pkg="org.joda.time" />
<allow pkg="java.io" />
<allow pkg="java.lang.reflect" />
<allow pkg="java.net" />
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.formkiq.lambda.runtime.graalvm;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.List;

/** {@link ExclusionStrategy} for Aws Events. */
public class AwsEventsExclusionStrategy implements ExclusionStrategy {

/** Skip Classes. */
private static final Collection<Class<?>> CLASSES = List.of(ByteBuffer.class);

/** Skip Fields. */
private static final Collection<String> FIELDS = List.of("approximateCreationDateTime");

@Override
public boolean shouldSkipField(final FieldAttributes fieldAttributes) {
return FIELDS.contains(fieldAttributes.getName());
}

@Override
public boolean shouldSkipClass(final Class<?> clazz) {
return CLASSES.contains(clazz);
}
}
Original file line number Diff line number Diff line change
@@ -1,76 +1,61 @@
package com.formkiq.lambda.runtime.graalvm;

import com.amazonaws.services.lambda.runtime.events.DynamodbEvent;
import com.amazonaws.services.lambda.runtime.events.SQSEvent;
import com.amazonaws.services.lambda.runtime.events.models.dynamodb.AttributeValue;
import com.amazonaws.services.lambda.runtime.events.models.dynamodb.StreamRecord;
import com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.FieldNamingStrategy;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.List;
import java.util.Locale;
import java.util.stream.Stream;

/** AWS Events Field {@link FieldNamingStrategy}. */
public class AwsEventsFieldNamingStrategy implements FieldNamingStrategy {

/** {@link DynamodbEvent} Field Mapping. */
private static final Map<Class<?>, Map<String, String>> FIELD_MAPPING =
Map.of(
DynamodbEvent.class,
Map.of("records", "Records"),
StreamRecord.class,
Map.of(
"newImage",
"NewImage",
"oldImage",
"OldImage",
"keys",
"Keys",
"sequenceNumber",
"SequenceNumber",
"sizeBytes",
"SizeBytes",
"streamViewType",
"StreamViewType"),
AttributeValue.class,
Map.of(
"s",
"S",
"n",
"N",
"sS",
"SS",
"nS",
"NS",
"m",
"M",
"l",
"L",
"nULLValue",
"NULLValue",
"bOOL",
"BOOL"),
S3EventNotification.class,
Map.of("records", "Records"),
S3EventNotification.S3EventNotificationRecord.class,
Map.of("eventTime", "EventTime"),
S3EventNotification.ResponseElementsEntity.class,
Map.of("xAmzId2", "x-amz-id-2", "xAmzRequestId", "x-amz-request-id"),
SQSEvent.class,
Map.of("records", "Records"),
SQSEvent.SQSMessage.class,
Map.of("eventSourceArn", "eventSourceARN"));

@Override
public String translateName(final Field field) {

String fieldName = field.getName();
public String translateName(final Field f) {
return f.getName();
}

Map<String, String> fields = FIELD_MAPPING.get(field.getDeclaringClass());
@Override
public List<String> alternateNames(final Field field) {
String fieldName = translateName(field);

return Stream.of(
FieldNamingPolicy.UPPER_CAMEL_CASE.translateName(field),
separateCamelCaseIncludeDigit(fieldName, '-').toLowerCase(Locale.ENGLISH),
convertUpperCaseSuffix(fieldName, "Arn"),
fieldName.toLowerCase(),
fieldName.toUpperCase())
.filter(s -> !s.isBlank() && !s.equals(fieldName))
.distinct()
.toList();
}

if (fields != null && fields.containsKey(fieldName)) {
fieldName = fields.get(fieldName);
static String convertUpperCaseSuffix(final String input, final String ext) {
String s = "";
if (input.endsWith(ext)) {
s = input.substring(0, input.length() - ext.length()) + ext.toUpperCase();
}
return s;
}

return fieldName;
/**
* Converts the field name that uses camel-case define word separation into separate words that
* are separated by the provided {@code separator}.
*
* @param name {@link String}
* @param separator char
* @return String
*/
static String separateCamelCaseIncludeDigit(final String name, final char separator) {
StringBuilder translation = new StringBuilder();
for (int i = 0, length = name.length(); i < length; i++) {
char character = name.charAt(i);
if ((Character.isUpperCase(character) || Character.isDigit(character))
&& !translation.isEmpty()) {
translation.append(separator);
}
translation.append(character);
}
return translation.toString();
}
}
Loading