Skip to content

chore: upgrade AspectjGradlePlugin to latest and example project to java 11 #189

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

Merged
merged 5 commits into from
Nov 26, 2020
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
5 changes: 2 additions & 3 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ jobs:
- name: Capture branch and tag
id: branch_name
run: |
echo ::set-env name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/}
echo ::set-env name=SOURCE_TAG::${GITHUB_REF#refs/tags/}

echo "SOURCE_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "SOURCE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: install dependencies
run: make dev-docs
- name: Build docs website
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ jobs:
- name: Capture branch and tag
id: branch_name
run: |
echo ::set-env name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/}
echo ::set-env name=SOURCE_TAG::${GITHUB_REF#refs/tags/}

echo "SOURCE_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "SOURCE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: install dependencies
run: make dev-docs
- name: Build docs website
Expand Down
8 changes: 5 additions & 3 deletions docs/content/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ And configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lambd
```groovy
plugins{
id 'java'
id 'aspectj.AspectjGradlePlugin' version '0.0.3'
id 'aspectj.AspectjGradlePlugin' version '0.0.6'
}
repositories {
jcenter()
Expand All @@ -94,8 +94,10 @@ dependencies {
}
```

**Note:** Please add `aspectjVersion = '1.9.6'` to the `gradle.properties` file. The aspectj plugin works at the moment with gradle 5.x only.
Please refer to [open issue](https://github.com/awslabs/aws-lambda-powertools-java/issues/146) for more details.
**Note:**

Please add `aspectjVersion = '1.9.6'` to the `gradle.properties` file. The aspectj plugin works at the moment with gradle 5.x only if
you are using `java 8` as runtime. Please refer to [open issue](https://github.com/awslabs/aws-lambda-powertools-java/issues/146) for more details.

## Environment variables

Expand Down
5 changes: 4 additions & 1 deletion example/HelloWorldFunction/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins{
id 'java'
id 'aspectj.AspectjGradlePlugin' version '0.0.3'
id 'aspectj.AspectjGradlePlugin' version '0.0.6'
}

repositories {
Expand All @@ -23,6 +23,9 @@ dependencies {
implementation 'software.amazon.lambda:powertools-parameters:1.0.0'
aspectpath 'software.amazon.lambda:powertools-parameters:1.0.0'

implementation 'software.amazon.lambda:powertools-validation:1.0.0'
aspectpath 'software.amazon.lambda:powertools-validation:1.0.0'

implementation 'com.amazonaws:aws-lambda-java-core:1.2.0'
implementation 'com.amazonaws:aws-lambda-java-events:3.1.0'

Expand Down
9 changes: 5 additions & 4 deletions example/HelloWorldFunction/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<packaging>jar</packaging>
<name>A sample Hello World created for SAM CLI.</name>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<log4j.version>2.13.2</log4j.version>
</properties>

Expand Down Expand Up @@ -80,9 +80,10 @@
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<!-- Refer https://github.com/awslabs/aws-lambda-powertools-java/issues/50 -->
<groupId>com.nickwongdev</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>
<version>1.12.6</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
Expand Down
7 changes: 1 addition & 6 deletions example/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Description: >
Globals:
Function:
Timeout: 20
Runtime: java11

Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: HelloWorldFunction
Handler: helloworld.App::handleRequest
Runtime: java8
MemorySize: 512
Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
Variables:
Expand All @@ -35,7 +35,6 @@ Resources:
Properties:
CodeUri: HelloWorldFunction
Handler: helloworld.AppValidation::handleRequest
Runtime: java8
MemorySize: 512
Tracing: Active
Events:
Expand All @@ -50,7 +49,6 @@ Resources:
Properties:
CodeUri: HelloWorldFunction
Handler: helloworld.AppStream::handleRequest
Runtime: java8
MemorySize: 512
Tracing: Active
Environment:
Expand All @@ -68,7 +66,6 @@ Resources:
Properties:
CodeUri: HelloWorldFunction
Handler: helloworld.AppParams::handleRequest
Runtime: java8
MemorySize: 512
Tracing: Active
Policies:
Expand Down Expand Up @@ -148,7 +145,6 @@ Resources:
Properties:
CodeUri: HelloWorldFunction
Handler: helloworld.AppSqsEvent::handleRequest
Runtime: java8
MemorySize: 512
Tracing: Active
Policies:
Expand All @@ -174,7 +170,6 @@ Resources:
Properties:
CodeUri: HelloWorldFunction
Handler: helloworld.AppSqsEventUtil::handleRequest
Runtime: java8
MemorySize: 512
Tracing: Active
Policies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,8 @@ public static boolean isColdStart() {
public static void coldStartDone() {
IS_COLD_START = false;
}

public static boolean isSamLocal() {
return "true".equals(System.getenv("AWS_SAM_LOCAL"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.coldStartDone;
import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.isColdStart;
import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.isHandlerMethod;
import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.isSamLocal;
import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.placedOnRequestHandler;
import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.placedOnStreamHandler;
import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.serviceName;
Expand Down Expand Up @@ -62,7 +63,9 @@ public Object around(ProceedingJoinPoint pjp,
}
throw e;
} finally {
AWSXRay.endSubsegment();
if (!isSamLocal()) {
AWSXRay.endSubsegment();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor;
import software.amazon.lambda.powertools.tracing.handlers.PowerToolDisabled;
import software.amazon.lambda.powertools.tracing.handlers.PowerToolDisabledForStream;
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabled;
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabledForStream;
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabledForStreamWithNoMetaData;
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabledWithException;
import software.amazon.lambda.powertools.tracing.handlers.PowerTracerToolEnabledWithNoMetaData;
import software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor;

import static org.apache.commons.lang3.reflect.FieldUtils.writeStaticField;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.mockito.MockitoAnnotations.openMocks;

class LambdaTracingAspectTest {
private RequestHandler<Object, Object> requestHandler;
Expand All @@ -49,7 +49,7 @@ class LambdaTracingAspectTest {

@BeforeEach
void setUp() throws IllegalAccessException {
initMocks(this);
openMocks(this);
writeStaticField(LambdaHandlerProcessor.class, "IS_COLD_START", null, true);
setupContext();
requestHandler = new PowerTracerToolEnabled();
Expand Down