Skip to content

Commit 3080a38

Browse files
authored
2.6.0 (#22)
* Improved aws-lambda-java-events support using GSON Field Name Strategy * #21 - Add AWS Lambda JSON logging support * Migrated from OSSRH to Central Portal
1 parent 5e8c685 commit 3080a38

File tree

13 files changed

+331
-226
lines changed

13 files changed

+331
-226
lines changed

.github/workflows/main.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ jobs:
2727
java-version: '17'
2828
distribution: 'temurin'
2929
cache: gradle
30+
- name: Restore gradle.properties
31+
env:
32+
GRADLE_PROPERTIES: ${{ secrets.GRADLE_PROPERTIES }}
33+
shell: bash
34+
run: |
35+
mkdir -p ~/.gradle/
36+
echo "GRADLE_USER_HOME=${HOME}/.gradle" >> $GITHUB_ENV
37+
echo "${GRADLE_PROPERTIES}" > ~/.gradle/gradle.properties
38+
- name: Restore gpg key
39+
env:
40+
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
41+
shell: bash
42+
run: |
43+
mkdir /home/runner/.gnupg
44+
echo -n "${{ secrets.GPG_PRIVATE_KEY }}" | base64 --decode > /home/runner/.gnupg/secring.gpg
3045
- name: Execute Gradle build
3146
run: ./gradlew clean build --refresh-dependencies --info
3247
- name: Upload test reports

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
66
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
77

8-
name: Sonatype Publish
8+
name: Publish Central Portal
99

1010
on:
1111
workflow_dispatch:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ hs_err_pid*
2727
/build/
2828
gradle.properties
2929
/bin/
30+
31+
.idea

build.gradle

Lines changed: 52 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
import com.vanniktech.maven.publish.SonatypeHost
12

23
plugins {
34
id 'java'
4-
id 'maven-publish'
5-
id 'signing'
65
id 'checkstyle'
7-
id 'com.diffplug.spotless' version '6.25.0'
8-
id 'com.github.spotbugs' version '6.0.7'
9-
id 'com.github.ben-manes.versions' version '0.51.0'
6+
id 'com.vanniktech.maven.publish' version '0.32.0'
7+
id 'com.diffplug.spotless' version '7.0.3'
8+
id 'com.github.spotbugs' version '6.1.11'
9+
id 'com.github.ben-manes.versions' version '0.52.0'
1010
}
1111

1212
group 'com.formkiq'
13-
version '2.5.0'
13+
version '2.6.0'
1414

1515
spotbugs {
1616
excludeFilter = file("$rootDir/config/spotbugs/spotbugs-exclude.xml")
@@ -23,15 +23,15 @@ spotless {
2323
}
2424

2525
spotbugsMain {
26-
reports {
27-
html {
28-
enabled = true
26+
reports {
27+
html {
28+
required.set(true)
29+
}
2930
}
30-
}
31-
}
31+
}
3232

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

4343
repositories {
44-
jcenter()
45-
}
46-
47-
check {
48-
dependsOn(tasks.publishToMavenLocal)
44+
mavenLocal()
45+
mavenCentral()
4946
}
5047

5148
java {
52-
withJavadocJar()
53-
withSourcesJar()
54-
5549
toolchain {
5650
languageVersion.set(JavaLanguageVersion.of(17))
5751
}
5852
}
5953

60-
javadoc {
61-
if(JavaVersion.current().isJava9Compatible()) {
62-
options.addBooleanOption('html5', true)
63-
}
64-
}
65-
66-
artifacts {
67-
archives jar
68-
69-
archives javadocJar
70-
archives sourcesJar
71-
}
72-
73-
afterEvaluate {
74-
tasks.getByName('spotlessCheck').dependsOn(tasks.getByName('spotlessApply'))
75-
}
76-
77-
7854
dependencies {
7955
implementation group: 'com.amazonaws', name: 'aws-lambda-java-core', version: '1.2.3'
80-
implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
81-
implementation group: 'com.amazonaws', name: 'aws-lambda-java-events', version: '3.11.4'
82-
testImplementation group: 'junit', name: 'junit', version:'4.+'
56+
implementation group: 'com.google.code.gson', name: 'gson', version: '2.13.1'
57+
implementation group: 'joda-time', name: 'joda-time', version: '2.14.0'
58+
59+
testImplementation group: 'com.amazonaws', name: 'aws-lambda-java-events', version: '3.15.0'
60+
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version:'5.11.4'
8361
testImplementation group: 'org.mock-server', name: 'mockserver-netty', version: '5.15.0'
84-
testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.9'
62+
testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.17'
8563
}
8664

87-
publishing {
88-
publications {
89-
mavenJava(MavenPublication) {
90-
artifactId = 'lambda-runtime-graalvm'
91-
from components.java
92-
93-
pom {
94-
name = 'FormKiQ Lambda Runtime Graalvm'
95-
description = 'Lambda Runtime Graalvm'
96-
url = 'https://github.com/formkiq/lambda-runtime-graalvm'
97-
licenses {
98-
license {
99-
name = 'The Apache License, Version 2.0'
100-
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
101-
}
102-
}
103-
developers {
104-
developer {
105-
id = 'mfriesen'
106-
name = 'Mike Friesen'
107-
108-
}
109-
}
110-
scm {
111-
connection = 'scm:git:git://github.com/formkiq/lambda-runtime-graalvm.git'
112-
developerConnection = 'scm:git:ssh://github.com/formkiq/lambda-runtime-graalvm.git'
113-
url = 'https://github.com/formkiq/lambda-runtime-graalvm.git'
114-
}
65+
mavenPublishing {
66+
67+
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
68+
69+
pom {
70+
name = "FormKiQ Lambda Runtime Graalvm"
71+
description = "Lambda Runtime Graalvm"
72+
inceptionYear = "2020"
73+
url = "https://github.com/formkiq/lambda-runtime-graalvm"
74+
licenses {
75+
license {
76+
name = "The Apache License, Version 2.0"
77+
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
78+
distribution = "http://www.apache.org/licenses/LICENSE-2.0.txt"
11579
}
116-
}
117-
}
118-
repositories {
119-
maven {
120-
credentials {
121-
username project.repoUser
122-
password project.repoPassword
123-
}
124-
url "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
125-
//url "https://oss.sonatype.org/content/repositories/snapshots/"
126-
}
127-
}
80+
}
81+
developers {
82+
developer {
83+
id = 'mfriesen'
84+
name = 'Mike Friesen'
85+
}
86+
}
87+
scm {
88+
url = 'https://github.com/formkiq/lambda-runtime-graalvm.git'
89+
connection = 'scm:git:git://github.com/formkiq/lambda-runtime-graalvm.git'
90+
developerConnection = 'scm:git:ssh://github.com/formkiq/lambda-runtime-graalvm.git'
91+
}
92+
}
12893
}
12994

130-
signing {
131-
sign publishing.publications.mavenJava
132-
}
95+
compileJava.dependsOn(tasks.spotlessApply)
96+
check.dependsOn(tasks.publishToMavenLocal)
13397

134-
check {
135-
dependsOn(tasks.publishToMavenLocal)
98+
test {
99+
failFast = true
100+
useJUnitPlatform()
136101
}

config/checkstyle/import-control.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
<allow pkg="com.amazonaws.services.lambda.runtime" />
1111
<allow pkg="com.google.gson" />
1212
<allow pkg="com.sun.net.httpserver" />
13-
13+
14+
<allow pkg="org.joda.time" />
1415
<allow pkg="java.io" />
1516
<allow pkg="java.lang.reflect" />
1617
<allow pkg="java.net" />
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
44
networkTimeout=10000
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.formkiq.lambda.runtime.graalvm;
2+
3+
import com.google.gson.ExclusionStrategy;
4+
import com.google.gson.FieldAttributes;
5+
import java.nio.ByteBuffer;
6+
import java.util.Collection;
7+
import java.util.List;
8+
9+
/** {@link ExclusionStrategy} for Aws Events. */
10+
public class AwsEventsExclusionStrategy implements ExclusionStrategy {
11+
12+
/** Skip Classes. */
13+
private static final Collection<Class<?>> CLASSES = List.of(ByteBuffer.class);
14+
15+
/** Skip Fields. */
16+
private static final Collection<String> FIELDS = List.of("approximateCreationDateTime");
17+
18+
@Override
19+
public boolean shouldSkipField(final FieldAttributes fieldAttributes) {
20+
return FIELDS.contains(fieldAttributes.getName());
21+
}
22+
23+
@Override
24+
public boolean shouldSkipClass(final Class<?> clazz) {
25+
return CLASSES.contains(clazz);
26+
}
27+
}
Lines changed: 46 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,61 @@
11
package com.formkiq.lambda.runtime.graalvm;
22

3-
import com.amazonaws.services.lambda.runtime.events.DynamodbEvent;
4-
import com.amazonaws.services.lambda.runtime.events.SQSEvent;
5-
import com.amazonaws.services.lambda.runtime.events.models.dynamodb.AttributeValue;
6-
import com.amazonaws.services.lambda.runtime.events.models.dynamodb.StreamRecord;
7-
import com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification;
3+
import com.google.gson.FieldNamingPolicy;
84
import com.google.gson.FieldNamingStrategy;
95
import java.lang.reflect.Field;
10-
import java.util.Map;
6+
import java.util.List;
7+
import java.util.Locale;
8+
import java.util.stream.Stream;
119

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

15-
/** {@link DynamodbEvent} Field Mapping. */
16-
private static final Map<Class<?>, Map<String, String>> FIELD_MAPPING =
17-
Map.of(
18-
DynamodbEvent.class,
19-
Map.of("records", "Records"),
20-
StreamRecord.class,
21-
Map.of(
22-
"newImage",
23-
"NewImage",
24-
"oldImage",
25-
"OldImage",
26-
"keys",
27-
"Keys",
28-
"sequenceNumber",
29-
"SequenceNumber",
30-
"sizeBytes",
31-
"SizeBytes",
32-
"streamViewType",
33-
"StreamViewType"),
34-
AttributeValue.class,
35-
Map.of(
36-
"s",
37-
"S",
38-
"n",
39-
"N",
40-
"sS",
41-
"SS",
42-
"nS",
43-
"NS",
44-
"m",
45-
"M",
46-
"l",
47-
"L",
48-
"nULLValue",
49-
"NULLValue",
50-
"bOOL",
51-
"BOOL"),
52-
S3EventNotification.class,
53-
Map.of("records", "Records"),
54-
S3EventNotification.S3EventNotificationRecord.class,
55-
Map.of("eventTime", "EventTime"),
56-
S3EventNotification.ResponseElementsEntity.class,
57-
Map.of("xAmzId2", "x-amz-id-2", "xAmzRequestId", "x-amz-request-id"),
58-
SQSEvent.class,
59-
Map.of("records", "Records"),
60-
SQSEvent.SQSMessage.class,
61-
Map.of("eventSourceArn", "eventSourceARN"));
62-
6313
@Override
64-
public String translateName(final Field field) {
65-
66-
String fieldName = field.getName();
14+
public String translateName(final Field f) {
15+
return f.getName();
16+
}
6717

68-
Map<String, String> fields = FIELD_MAPPING.get(field.getDeclaringClass());
18+
@Override
19+
public List<String> alternateNames(final Field field) {
20+
String fieldName = translateName(field);
21+
22+
return Stream.of(
23+
FieldNamingPolicy.UPPER_CAMEL_CASE.translateName(field),
24+
separateCamelCaseIncludeDigit(fieldName, '-').toLowerCase(Locale.ENGLISH),
25+
convertUpperCaseSuffix(fieldName, "Arn"),
26+
fieldName.toLowerCase(),
27+
fieldName.toUpperCase())
28+
.filter(s -> !s.isBlank() && !s.equals(fieldName))
29+
.distinct()
30+
.toList();
31+
}
6932

70-
if (fields != null && fields.containsKey(fieldName)) {
71-
fieldName = fields.get(fieldName);
33+
static String convertUpperCaseSuffix(final String input, final String ext) {
34+
String s = "";
35+
if (input.endsWith(ext)) {
36+
s = input.substring(0, input.length() - ext.length()) + ext.toUpperCase();
7237
}
38+
return s;
39+
}
7340

74-
return fieldName;
41+
/**
42+
* Converts the field name that uses camel-case define word separation into separate words that
43+
* are separated by the provided {@code separator}.
44+
*
45+
* @param name {@link String}
46+
* @param separator char
47+
* @return String
48+
*/
49+
static String separateCamelCaseIncludeDigit(final String name, final char separator) {
50+
StringBuilder translation = new StringBuilder();
51+
for (int i = 0, length = name.length(); i < length; i++) {
52+
char character = name.charAt(i);
53+
if ((Character.isUpperCase(character) || Character.isDigit(character))
54+
&& !translation.isEmpty()) {
55+
translation.append(separator);
56+
}
57+
translation.append(character);
58+
}
59+
return translation.toString();
7560
}
7661
}

0 commit comments

Comments
 (0)