From 8f310015263d5c5cc8752d47b2731ba23f6564a5 Mon Sep 17 00:00:00 2001 From: Roy Teeuwen Date: Wed, 31 Jul 2024 20:28:00 +0200 Subject: [PATCH 1/7] Start setting up sling feature maven plugin --- pom.xml | 88 +++++++++++++++++++ .../weavinghooks/it/WeavingHookIT.java | 35 ++++++++ 2 files changed, 123 insertions(+) create mode 100644 src/test/java/be/orbinson/sling/observability/weavinghooks/it/WeavingHookIT.java diff --git a/pom.xml b/pom.xml index f7f5d71..1e4423c 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,88 @@ + + it + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.2.0 + + + reserve-network-port + + reserve-network-port + + process-resources + + + http.port + + + + + + + org.apache.sling + feature-launcher-maven-plugin + 0.1.6 + + + + model + + org.apache.sling + org.apache.sling.starter + 12 + oak_tar + slingosgifeature + + + + + + + + ${http.port} + + + 180 + + + + + + + start + stop + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.3.1 + + + ${http.port} + ${project.build.directory}/../build.log + + + + + + integration-test + verify + + + + + + + @@ -134,5 +216,11 @@ 5.10.2 test + + org.apache.httpcomponents + httpclient + 4.5.14 + test + diff --git a/src/test/java/be/orbinson/sling/observability/weavinghooks/it/WeavingHookIT.java b/src/test/java/be/orbinson/sling/observability/weavinghooks/it/WeavingHookIT.java new file mode 100644 index 0000000..83c214d --- /dev/null +++ b/src/test/java/be/orbinson/sling/observability/weavinghooks/it/WeavingHookIT.java @@ -0,0 +1,35 @@ +package be.orbinson.sling.observability.weavinghooks.it; + +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.fail; + +public class WeavingHookIT { + + @Test + public void aaSlingAppIsUp() throws Exception { + + int port = Integer.getInteger("HTTP_PORT", 8080); + + try (CloseableHttpClient httpclient = HttpClients.createDefault()) { + HttpGet get = new HttpGet("http://localhost:" + port + "/"); + for (int i = 0; i < 30; i++) { + try (CloseableHttpResponse response = httpclient.execute(get)) { + System.out.println("Status line = " + response.getStatusLine().toString()); + int statusCode = response.getStatusLine().getStatusCode(); + if ((statusCode / 100 < 5)) { + System.out.println("App is ready"); + return; + } + Thread.sleep(1000l); + } + } + + fail("App is not yet ready, failing"); + } + } +} From 793ff00ee6be8d1e4295d2dd6df68510fd84f355 Mon Sep 17 00:00:00 2001 From: Roy Teeuwen Date: Thu, 1 Aug 2024 23:07:51 +0200 Subject: [PATCH 2/7] Add initial setup for integration tests --- README.md | 5 +- pom.xml | 101 +++++++++++++--- .../LogMethodWeavingHookConfiguration.java | 4 +- src/test/features/model.json | 109 ++++++++++++++++++ .../weavinghooks/servlet/TestServlet.java | 52 +++++++++ 5 files changed, 247 insertions(+), 24 deletions(-) create mode 100644 src/test/features/model.json create mode 100644 src/test/java/be/orbinson/sling/observability/weavinghooks/servlet/TestServlet.java diff --git a/README.md b/README.md index d0d36cf..ba2787c 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,7 @@ Example, search for your classname, method name and amount of parameters you wan ```json { "className": "my.package.MyClass", - "methodName": "doGet", - "amountOfParameters": 2 + "methodName": "doGet" } ``` @@ -24,4 +23,4 @@ To make the weaving hook work, either a framework restart of an entire java proc ## Future -- Add weaving hooks to create custom spans and metrics using OpenTelemetry \ No newline at end of file +- Add weaving hooks to create custom spans and metrics using OpenTelemetry diff --git a/pom.xml b/pom.xml index 1e4423c..f9aac0a 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,6 @@ be.orbinson.sling sling-observability-weavinghooks - bundle 0.0.1-SNAPSHOT Sling Observability Weaving Hooks @@ -16,22 +15,37 @@ - org.apache.felix - maven-bundle-plugin - 5.1.9 - true + biz.aQute.bnd + bnd-maven-plugin + 6.4.0 + + + bnd-process + + bnd-process + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.3.0 - ${basedir}/target/classes - - ${project.artifactId} - ${project.version} - asm,asm-util,asm-tree,asm-analysis - + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + org.apache.maven.plugins maven-compiler-plugin + 3.12.1 1.8 1.8 @@ -80,6 +94,25 @@ it + + biz.aQute.bnd + bnd-maven-plugin + 6.4.0 + true + + + test-jar + + test-jar + + + + + + + org.codehaus.mojo build-helper-maven-plugin @@ -99,6 +132,22 @@ + + org.apache.sling + slingfeature-maven-plugin + 1.8.4 + true + + true + + + + + attach-features + + + + org.apache.sling feature-launcher-maven-plugin @@ -108,20 +157,21 @@ model - org.apache.sling - org.apache.sling.starter - 12 - oak_tar + ${project.groupId} + ${project.artifactId} + ${project.version} + test slingosgifeature - - - - + ${http.port} + + + -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5000 + 180 @@ -222,5 +272,18 @@ 4.5.14 test + + javax.servlet + servlet-api + 2.5 + test + + + + org.apache.sling + feature-launcher-maven-plugin + 0.1.6 + + diff --git a/src/main/java/be/orbinson/sling/observability/weavinghooks/logmethod/LogMethodWeavingHookConfiguration.java b/src/main/java/be/orbinson/sling/observability/weavinghooks/logmethod/LogMethodWeavingHookConfiguration.java index d0adf09..3586c07 100644 --- a/src/main/java/be/orbinson/sling/observability/weavinghooks/logmethod/LogMethodWeavingHookConfiguration.java +++ b/src/main/java/be/orbinson/sling/observability/weavinghooks/logmethod/LogMethodWeavingHookConfiguration.java @@ -30,7 +30,7 @@ public class LogMethodWeavingHookConfiguration { String logLevel() default "info"; @AttributeDefinition(description = "Enable the trace visitor to show what the generated byte code is") - boolean enableTraceVisitor() default false; + boolean showGeneratedBytecode() default false; } private String className; @@ -43,7 +43,7 @@ void activate(Config config) { this.className = config.className(); this.methodName = config.methodName(); this.logLevel = config.logLevel(); - this.enableTraceVisitor = config.enableTraceVisitor(); + this.enableTraceVisitor = config.showGeneratedBytecode(); } public String getClassName() { diff --git a/src/test/features/model.json b/src/test/features/model.json new file mode 100644 index 0000000..b014762 --- /dev/null +++ b/src/test/features/model.json @@ -0,0 +1,109 @@ +{ + "id": "${project.groupId}:${project.artifactId}:model:test:${project.version}", + "bundles": [ + // OSGi + { + "id": "org.osgi:org.osgi.util.promise:1.1.1", + "start-order": "1" + }, + { + "id": "org.osgi:org.osgi.util.function:1.1.0", + "start-order": "1" + }, + { + "id": "org.osgi:org.osgi.util.converter:1.0.1", + "start-order": "1" + }, + { + "id": "org.apache.felix:org.apache.felix.scr:2.1.20", + "start-order": "1" + }, + { + "id": "org.apache.commons:commons-lang3:3.9", + "start-order": "1" + }, + { + "id": "commons-fileupload:commons-fileupload:1.4", + "start-order": "1" + }, + { + "id": "commons-io:commons-io:2.6", + "start-order": "1" + }, + { + "id": "org.apache.felix:org.apache.felix.webconsole:4.5.0", + "start-order": "1" + }, + { + "id": "org.apache.felix:org.apache.felix.configadmin:1.9.16", + "start-order": "1" + }, + // Logging + { + "id": "org.slf4j:jcl-over-slf4j:1.7.25", + "start-order": "1" + }, + { + "id": "org.slf4j:log4j-over-slf4j:1.7.25", + "start-order": "1" + }, + { + "id": "org.slf4j:slf4j-api:1.7.25", + "start-order": "1" + }, + { + "id": "org.apache.felix:org.apache.felix.log:1.2.2", + "start-order": "1" + }, + { + "id": "org.apache.sling:org.apache.sling.commons.log:5.1.12", + "start-order": "1" + }, + { + "id": "org.apache.sling:org.apache.sling.commons.logservice:1.1.0", + "start-order": "1" + }, + { + "id": "org.apache.sling:org.apache.sling.commons.log.webconsole:1.0.0", + "start-order": "5" + }, + // Servlet API + Sample for IT tests + { + "id": "org.apache.felix:org.apache.felix.http.servlet-api:1.1.2", + "start-order": "5" + }, + { + "id": "org.apache.felix:org.apache.felix.http.jetty:4.0.16", + "start-order": "5" + }, + // Actual project + { + "id": "${project.groupId}:${project.artifactId}:${project.version}", + "start-order": 1 + }, + { + "id": "${project.groupId}:${project.artifactId}:jar:tests:${project.version}", + "start-order": "5" + } + ], + "configurations": { + "org.apache.sling.commons.log.LogManager.factory.config~error.log": { + "org.apache.sling.commons.log.level": "info", + "org.apache.sling.commons.log.file": "logs/error.log", + "org.apache.sling.commons.log.names": [ + "org.apache", + "be.orbinson" + ] + }, + "be.orbinson.sling.observability.weavinghooks.logmethod.LogMethodWeavingHookConfiguration~TestServlet-methodOne": { + "className": "be.orbinson.sling.observability.weavinghooks.servlet.TestServlet", + "methodName": "methodWithOneParameter", + "showGeneratedBytecode": true + }, + "be.orbinson.sling.observability.weavinghooks.logmethod.LogMethodWeavingHookConfiguration~TestServlet-methodTwo": { + "className": "be.orbinson.sling.observability.weavinghooks.servlet.TestServlet", + "methodName": "methodWithTwoParameters", + "showGeneratedBytecode": true + } + } +} diff --git a/src/test/java/be/orbinson/sling/observability/weavinghooks/servlet/TestServlet.java b/src/test/java/be/orbinson/sling/observability/weavinghooks/servlet/TestServlet.java new file mode 100644 index 0000000..a64ad5b --- /dev/null +++ b/src/test/java/be/orbinson/sling/observability/weavinghooks/servlet/TestServlet.java @@ -0,0 +1,52 @@ +package be.orbinson.sling.observability.weavinghooks.servlet; + +import org.osgi.service.component.annotations.Component; +import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardContextSelect; +import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletPattern; + +import javax.servlet.*; +import java.io.IOException; + +/** + * Servlet used in Integration test to validate that logs are appended + */ +@HttpWhiteboardServletPattern("/test") +@HttpWhiteboardContextSelect("(osgi.http.whiteboard.context.name=org.osgi.service.http)") +@Component(service = Servlet.class) +public class TestServlet implements Servlet { + + + @Override + public void init(ServletConfig servletConfig) throws ServletException { + + } + + @Override + public ServletConfig getServletConfig() { + return null; + } + + @Override + public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException { + methodWithOneParameter("parameterOne"); + methodWithTwoParameters("parameterOne","parameterTwo"); + } + + private void methodWithOneParameter(String parameterOne) { + // do nothing + } + + private void methodWithTwoParameters(String parameterOne, String parameterTwo) { + // do nothing + } + + @Override + public String getServletInfo() { + return ""; + } + + @Override + public void destroy() { + + } +} From b60b4d582e589e91d6273496baad41d00d687a1d Mon Sep 17 00:00:00 2001 From: Roy Teeuwen Date: Fri, 2 Aug 2024 08:49:27 +0200 Subject: [PATCH 3/7] Finish weaving hook integration test --- pom.xml | 7 ++-- .../logmethod/LogMethodWeavingHook.java | 8 ++-- .../LogMethodWeavingHookConfiguration.java | 8 ++-- src/test/features/model.json | 22 +++++++++-- .../weavinghooks/it/WeavingHookIT.java | 39 +++++++++++-------- .../{servlet => testservlet}/TestServlet.java | 37 ++++++------------ 6 files changed, 64 insertions(+), 57 deletions(-) rename src/test/java/be/orbinson/sling/observability/weavinghooks/{servlet => testservlet}/TestServlet.java (50%) diff --git a/pom.xml b/pom.xml index f9aac0a..507b5e4 100644 --- a/pom.xml +++ b/pom.xml @@ -94,6 +94,7 @@ it + biz.aQute.bnd bnd-maven-plugin @@ -169,9 +170,9 @@ ${http.port} - - -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5000 - + + + 180 diff --git a/src/main/java/be/orbinson/sling/observability/weavinghooks/logmethod/LogMethodWeavingHook.java b/src/main/java/be/orbinson/sling/observability/weavinghooks/logmethod/LogMethodWeavingHook.java index 732fb54..ab2df5e 100644 --- a/src/main/java/be/orbinson/sling/observability/weavinghooks/logmethod/LogMethodWeavingHook.java +++ b/src/main/java/be/orbinson/sling/observability/weavinghooks/logmethod/LogMethodWeavingHook.java @@ -19,13 +19,13 @@ public class LogMethodWeavingHook implements WeavingHook { private final String className; private final String methodName; private final String logLevel; - private final boolean enableTraceVisitor; + private final boolean showGeneratedBytecode; public LogMethodWeavingHook(LogMethodWeavingHookConfiguration config) { this.className = config.getClassName(); this.methodName = config.getMethodName(); this.logLevel = config.getLogLevel(); - this.enableTraceVisitor = config.isEnableTraceVisitor(); + this.showGeneratedBytecode = config.isShowGeneratedBytecode(); } @Override @@ -41,7 +41,7 @@ private void addLogMethodToClass(WovenClass wovenClass) { final ClassReader cr = new ClassReader(wovenClass.getBytes()); final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); ClassVisitor logMethodClassVisitor; - if (enableTraceVisitor) { + if (showGeneratedBytecode) { StringWriter out = new StringWriter(); final TraceClassVisitor tcv = new TraceClassVisitor(cw, new PrintWriter(out)); logMethodClassVisitor = new LogMethodClassVisitor(tcv, className, methodName, logLevel); @@ -62,4 +62,4 @@ private void addDynamicImports(WovenClass wovenClass) { } -} \ No newline at end of file +} diff --git a/src/main/java/be/orbinson/sling/observability/weavinghooks/logmethod/LogMethodWeavingHookConfiguration.java b/src/main/java/be/orbinson/sling/observability/weavinghooks/logmethod/LogMethodWeavingHookConfiguration.java index 3586c07..564bd9a 100644 --- a/src/main/java/be/orbinson/sling/observability/weavinghooks/logmethod/LogMethodWeavingHookConfiguration.java +++ b/src/main/java/be/orbinson/sling/observability/weavinghooks/logmethod/LogMethodWeavingHookConfiguration.java @@ -36,14 +36,14 @@ public class LogMethodWeavingHookConfiguration { private String className; private String methodName; private String logLevel; - private boolean enableTraceVisitor; + private boolean showGeneratedBytecode; @Activate void activate(Config config) { this.className = config.className(); this.methodName = config.methodName(); this.logLevel = config.logLevel(); - this.enableTraceVisitor = config.showGeneratedBytecode(); + this.showGeneratedBytecode = config.showGeneratedBytecode(); } public String getClassName() { @@ -58,7 +58,7 @@ public String getLogLevel() { return logLevel; } - public boolean isEnableTraceVisitor() { - return enableTraceVisitor; + public boolean isShowGeneratedBytecode() { + return showGeneratedBytecode; } } diff --git a/src/test/features/model.json b/src/test/features/model.json index b014762..fadfabc 100644 --- a/src/test/features/model.json +++ b/src/test/features/model.json @@ -81,6 +81,7 @@ "id": "${project.groupId}:${project.artifactId}:${project.version}", "start-order": 1 }, + // Test OSGI servlet. Feature model only use a new version if the project succesfully compiled (so -DskipTests might be required) { "id": "${project.groupId}:${project.artifactId}:jar:tests:${project.version}", "start-order": "5" @@ -91,17 +92,30 @@ "org.apache.sling.commons.log.level": "info", "org.apache.sling.commons.log.file": "logs/error.log", "org.apache.sling.commons.log.names": [ - "org.apache", - "be.orbinson" + "org.apache" + ] + }, + "org.apache.sling.commons.log.LogManager.factory.config~weavinghook.log": { + "org.apache.sling.commons.log.level": "debug", + "org.apache.sling.commons.log.file": "logs/weavinghook.log", + "org.apache.sling.commons.log.names": [ + "be.orbinson.sling.observability.weavinghooks" + ] + }, + "org.apache.sling.commons.log.LogManager.factory.config~test.log": { + "org.apache.sling.commons.log.level": "info", + "org.apache.sling.commons.log.file": "logs/test.log", + "org.apache.sling.commons.log.names": [ + "be.orbinson.sling.observability.weavinghooks.testservlet" ] }, "be.orbinson.sling.observability.weavinghooks.logmethod.LogMethodWeavingHookConfiguration~TestServlet-methodOne": { - "className": "be.orbinson.sling.observability.weavinghooks.servlet.TestServlet", + "className": "be.orbinson.sling.observability.weavinghooks.testservlet.TestServlet", "methodName": "methodWithOneParameter", "showGeneratedBytecode": true }, "be.orbinson.sling.observability.weavinghooks.logmethod.LogMethodWeavingHookConfiguration~TestServlet-methodTwo": { - "className": "be.orbinson.sling.observability.weavinghooks.servlet.TestServlet", + "className": "be.orbinson.sling.observability.weavinghooks.testservlet.TestServlet", "methodName": "methodWithTwoParameters", "showGeneratedBytecode": true } diff --git a/src/test/java/be/orbinson/sling/observability/weavinghooks/it/WeavingHookIT.java b/src/test/java/be/orbinson/sling/observability/weavinghooks/it/WeavingHookIT.java index 83c214d..f813f5b 100644 --- a/src/test/java/be/orbinson/sling/observability/weavinghooks/it/WeavingHookIT.java +++ b/src/test/java/be/orbinson/sling/observability/weavinghooks/it/WeavingHookIT.java @@ -1,35 +1,40 @@ package be.orbinson.sling.observability.weavinghooks.it; +import org.apache.commons.codec.binary.Base64; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.fail; +import java.nio.charset.StandardCharsets; -public class WeavingHookIT { +import static org.junit.jupiter.api.Assertions.assertEquals; - @Test - public void aaSlingAppIsUp() throws Exception { +public class WeavingHookIT { - int port = Integer.getInteger("HTTP_PORT", 8080); + private static final int SLING_PORT = Integer.getInteger("HTTP_PORT", 8080); + /** + * Uses the {@link be.orbinson.sling.observability.weavinghooks.testservlet.TestServlet} that has two weaved methods on startup + */ + @Test + public void testServletShouldLogMethodParams() throws Exception { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { - HttpGet get = new HttpGet("http://localhost:" + port + "/"); - for (int i = 0; i < 30; i++) { - try (CloseableHttpResponse response = httpclient.execute(get)) { - System.out.println("Status line = " + response.getStatusLine().toString()); - int statusCode = response.getStatusLine().getStatusCode(); - if ((statusCode / 100 < 5)) { - System.out.println("App is ready"); - return; - } - Thread.sleep(1000l); - } + HttpGet get = new HttpGet("http://localhost:" + SLING_PORT + "/test"); + try (CloseableHttpResponse response = httpclient.execute(get)) { + String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); + assertEquals("OK", responseBody); } - fail("App is not yet ready, failing"); + HttpGet checkLogs = new HttpGet("http://localhost:" + SLING_PORT + "/system/console/slinglog/tailer.txt?name=/logs/test.log"); + checkLogs.addHeader("Authorization", "Basic " + Base64.encodeBase64String("admin:admin".getBytes(StandardCharsets.UTF_8))); + try (CloseableHttpResponse response = httpclient.execute(checkLogs)) { + String[] lines = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8).split("\n"); + assertEquals("TestServlet methodWithOneParameter, param_1: ", lines[0].substring(lines[0].indexOf("TestServlet"))); + assertEquals("TestServlet methodWithTwoParameters, param_1: , param_2: ", lines[1].substring(lines[1].indexOf("TestServlet"))); + } } } } diff --git a/src/test/java/be/orbinson/sling/observability/weavinghooks/servlet/TestServlet.java b/src/test/java/be/orbinson/sling/observability/weavinghooks/testservlet/TestServlet.java similarity index 50% rename from src/test/java/be/orbinson/sling/observability/weavinghooks/servlet/TestServlet.java rename to src/test/java/be/orbinson/sling/observability/weavinghooks/testservlet/TestServlet.java index a64ad5b..4a00daa 100644 --- a/src/test/java/be/orbinson/sling/observability/weavinghooks/servlet/TestServlet.java +++ b/src/test/java/be/orbinson/sling/observability/weavinghooks/testservlet/TestServlet.java @@ -1,35 +1,31 @@ -package be.orbinson.sling.observability.weavinghooks.servlet; +package be.orbinson.sling.observability.weavinghooks.testservlet; import org.osgi.service.component.annotations.Component; import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardContextSelect; import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletPattern; -import javax.servlet.*; +import javax.servlet.Servlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** - * Servlet used in Integration test to validate that logs are appended + * Servlet used in {@link be.orbinson.sling.observability.weavinghooks.it.WeavingHookIT} Integration test to validate that logs are appended */ @HttpWhiteboardServletPattern("/test") @HttpWhiteboardContextSelect("(osgi.http.whiteboard.context.name=org.osgi.service.http)") @Component(service = Servlet.class) -public class TestServlet implements Servlet { +public class TestServlet extends HttpServlet { @Override - public void init(ServletConfig servletConfig) throws ServletException { - - } - - @Override - public ServletConfig getServletConfig() { - return null; - } - - @Override - public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException { + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws IOException { methodWithOneParameter("parameterOne"); - methodWithTwoParameters("parameterOne","parameterTwo"); + methodWithTwoParameters("parameterOne", "parameterTwo"); + resp.getWriter().print("OK"); + resp.getWriter().flush(); } private void methodWithOneParameter(String parameterOne) { @@ -40,13 +36,4 @@ private void methodWithTwoParameters(String parameterOne, String parameterTwo) { // do nothing } - @Override - public String getServletInfo() { - return ""; - } - - @Override - public void destroy() { - - } } From 9f07319e4b2a80d461ba84ecf43d91008a650dcb Mon Sep 17 00:00:00 2001 From: Roy Teeuwen Date: Fri, 2 Aug 2024 17:06:20 +0200 Subject: [PATCH 4/7] Finalise the integration tests --- CHANGELOG.md | 10 +++++++ pom.xml | 27 +++++++++++++------ src/test/features/model.json | 2 +- .../{test => util}/ASMifierTester.java | 2 +- .../weavinghooks/{test => util}/MyClass.java | 2 +- .../{test => util}/TextifierTester.java | 2 +- 6 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 CHANGELOG.md rename src/test/java/be/orbinson/sling/observability/weavinghooks/{test => util}/ASMifierTester.java (92%) rename src/test/java/be/orbinson/sling/observability/weavinghooks/{test => util}/MyClass.java (83%) rename src/test/java/be/orbinson/sling/observability/weavinghooks/{test => util}/TextifierTester.java (92%) diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..71ebab9 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +- Initial release of the log method weaving hook \ No newline at end of file diff --git a/pom.xml b/pom.xml index 507b5e4..17db2ed 100644 --- a/pom.xml +++ b/pom.xml @@ -133,6 +133,21 @@ + + + org.apache.maven.plugins + maven-install-plugin + 3.1.2 + + + install-to-local-repo + + install + + pre-integration-test + + + org.apache.sling slingfeature-maven-plugin @@ -157,6 +172,7 @@ model + ${skipTests} ${project.groupId} ${project.artifactId} @@ -170,9 +186,9 @@ ${http.port} - - - + + + 180 @@ -280,11 +296,6 @@ test - - org.apache.sling - feature-launcher-maven-plugin - 0.1.6 - diff --git a/src/test/features/model.json b/src/test/features/model.json index fadfabc..30881d5 100644 --- a/src/test/features/model.json +++ b/src/test/features/model.json @@ -67,7 +67,7 @@ "id": "org.apache.sling:org.apache.sling.commons.log.webconsole:1.0.0", "start-order": "5" }, - // Servlet API + Sample for IT tests + // Servlet API for IT tests { "id": "org.apache.felix:org.apache.felix.http.servlet-api:1.1.2", "start-order": "5" diff --git a/src/test/java/be/orbinson/sling/observability/weavinghooks/test/ASMifierTester.java b/src/test/java/be/orbinson/sling/observability/weavinghooks/util/ASMifierTester.java similarity index 92% rename from src/test/java/be/orbinson/sling/observability/weavinghooks/test/ASMifierTester.java rename to src/test/java/be/orbinson/sling/observability/weavinghooks/util/ASMifierTester.java index 19dda29..f50c3bf 100644 --- a/src/test/java/be/orbinson/sling/observability/weavinghooks/test/ASMifierTester.java +++ b/src/test/java/be/orbinson/sling/observability/weavinghooks/util/ASMifierTester.java @@ -1,4 +1,4 @@ -package be.orbinson.sling.observability.weavinghooks.test; +package be.orbinson.sling.observability.weavinghooks.util; import org.junit.jupiter.api.Test; import org.objectweb.asm.ClassReader; diff --git a/src/test/java/be/orbinson/sling/observability/weavinghooks/test/MyClass.java b/src/test/java/be/orbinson/sling/observability/weavinghooks/util/MyClass.java similarity index 83% rename from src/test/java/be/orbinson/sling/observability/weavinghooks/test/MyClass.java rename to src/test/java/be/orbinson/sling/observability/weavinghooks/util/MyClass.java index 53ae6ea..42d91a8 100644 --- a/src/test/java/be/orbinson/sling/observability/weavinghooks/test/MyClass.java +++ b/src/test/java/be/orbinson/sling/observability/weavinghooks/util/MyClass.java @@ -1,4 +1,4 @@ -package be.orbinson.sling.observability.weavinghooks.test; +package be.orbinson.sling.observability.weavinghooks.util; import org.slf4j.LoggerFactory; diff --git a/src/test/java/be/orbinson/sling/observability/weavinghooks/test/TextifierTester.java b/src/test/java/be/orbinson/sling/observability/weavinghooks/util/TextifierTester.java similarity index 92% rename from src/test/java/be/orbinson/sling/observability/weavinghooks/test/TextifierTester.java rename to src/test/java/be/orbinson/sling/observability/weavinghooks/util/TextifierTester.java index 2870342..d739275 100644 --- a/src/test/java/be/orbinson/sling/observability/weavinghooks/test/TextifierTester.java +++ b/src/test/java/be/orbinson/sling/observability/weavinghooks/util/TextifierTester.java @@ -1,4 +1,4 @@ -package be.orbinson.sling.observability.weavinghooks.test; +package be.orbinson.sling.observability.weavinghooks.util; import org.junit.jupiter.api.Test; import org.objectweb.asm.ClassReader; From ba5795e91733bc0aa5ca46bd6b4299bfc6170988 Mon Sep 17 00:00:00 2001 From: Roy Teeuwen Date: Fri, 2 Aug 2024 17:06:29 +0200 Subject: [PATCH 5/7] Add github workflows --- .github/FUNDING.yml | 1 + .github/workflows/build.yml | 29 +++++++++ .github/workflows/release.yml | 107 ++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..e30577e --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: bdhoine,royteeuwen \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..42994e0 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,29 @@ +name: Build + +on: [ push, pull_request ] + +jobs: + build: + name: Maven build + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: 17 + + - name: Cache local Maven repository + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Build + run: mvn --batch-mode --update-snapshots install \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..897c539 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,107 @@ +name: Release + +on: + workflow_dispatch: + inputs: + central: + description: 'Release to Maven Central' + required: false + default: true + type: boolean + github: + description: 'Create GitHub release' + required: false + default: true + type: boolean + push: + description: 'Push changes' + required: false + default: true + type: boolean + +permissions: + contents: write + +jobs: + release: + name: Maven and GitHub release + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Cache local Maven repository + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Set up Java with Maven Central Repository + uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: 17 + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + gpg-passphrase: MAVEN_GPG_PASSPHRASE + + - name: Remove SNAPSHOT from version + run: mvn --batch-mode versions:set -DremoveSnapshot versions:commit + + - name: Set RELEASE_VERSION env variable + run: | + echo "RELEASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV + + - name: Update CHANGELOG.md + if: ${{ inputs.push }} + uses: thomaseizinger/keep-a-changelog-new-release@v1 + with: + version: ${{ env.RELEASE_VERSION }} + + - name: Get release info + id: changelog + uses: release-flow/keep-a-changelog-action/get-release-info@v1 + + - name: Deploy package + if: ${{ inputs.central }} + run: mvn --batch-mode deploy --activate-profiles release + env: + MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + + - name: Commit and push release + if: ${{ inputs.push }} + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "Create release ${{ steps.changelog.outputs.release-version }}" + tagging_message: ${{ steps.changelog.outputs.release-version }} + + - name: Create release + if: ${{ inputs.github }} + uses: softprops/action-gh-release@v1 + with: + name: ${{ steps.update-changelog.outputs.release-version }} + tag_name: ${{ steps.changelog.outputs.release-version }} + files: all/target/aem-groovy-console-all-*.zip + body: ${{ steps.changelog.outputs.release-notes }} + + - name: Next SNAPSHOT version + if: ${{ inputs.push }} + run: mvn --batch-mode versions:set -DnextSnapshot versions:commit + + - name: Set RELEASE_VERSION env variable + if: ${{ inputs.push }} + run: | + echo "RELEASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV + + - name: Commit and push development version + if: ${{ inputs.push }} + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "Bump development version to ${{ env.RELEASE_VERSION }}" \ No newline at end of file From 39c82b2e02386e4a6549cb4074cd01b711839072 Mon Sep 17 00:00:00 2001 From: Roy Teeuwen Date: Fri, 2 Aug 2024 17:11:13 +0200 Subject: [PATCH 6/7] Add requirements for releasing --- .github/workflows/build.yml | 5 +- pom.xml | 203 +++++++++++++++++++++++++++++++++--- 2 files changed, 192 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 42994e0..d43edd6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,4 +26,7 @@ jobs: ${{ runner.os }}-maven- - name: Build - run: mvn --batch-mode --update-snapshots install \ No newline at end of file + run: mvn --batch-mode --update-snapshots install + + - name: Integration Tests + run: mvn install -Pit \ No newline at end of file diff --git a/pom.xml b/pom.xml index 17db2ed..de5b9dc 100644 --- a/pom.xml +++ b/pom.xml @@ -11,9 +11,121 @@ 0.0.1-SNAPSHOT Sling Observability Weaving Hooks + Library of weaving hooks to ease the process of observability in out-of-the-box code + + https://github.com/orbinson/sling-observability-weavinghooks + + + + Barry d'Hoine + barrydhoine@gmail.com + bdhoine + + + Roy Teeuwen + roy@orbinson.be + royteeuwen + + + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0 + repo + + + + + scm:git:https://github.com/orbinson/sling-observability-weavinghooks.git + scm:git:https://github.com/orbinson/sling-observability-weavinghooks.git + https://github.com/orbinson/sling-observability-weavinghooks.git + + + + GitHub + https://github.com/orbinson/sling-observability-weavinghooks/issues + + + + + ossrh + Central Repository OSSRH - Snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots + + + ossrh + Central Repository OSSRH + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + localhost + 8080 + admin + admin + + orbinson + ${sonar.organization}_${project.artifactId} + https://sonarcloud.io + **/target/site/jacoco + + + org.apache.maven.plugins + maven-release-plugin + 3.0.1 + + [maven-scm] : + clean install + install + release + + + + org.apache.maven.plugins + maven-source-plugin + 3.3.0 + true + + + org.jacoco + jacoco-maven-plugin + + + prepare-agent + + prepare-agent + + + + report + + report + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.12.1 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-gpg-plugin + + + org.sonatype.plugins + nexus-staging-maven-plugin + biz.aQute.bnd bnd-maven-plugin @@ -42,24 +154,70 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.12.1 - - 1.8 - 1.8 - - + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrh + https://s01.oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + deploy + + sign + + + + + + + --pinentry-mode + loopback + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.4.1 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.1 + + + attach-sources + + jar-no-fork + + + + + + - - localhost - 8080 - admin - admin - @@ -225,6 +383,21 @@ + + release + + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + + From 7d69091fa148395f89f437e1db9547552eb9386e Mon Sep 17 00:00:00 2001 From: Roy Teeuwen Date: Fri, 2 Aug 2024 17:14:25 +0200 Subject: [PATCH 7/7] Add sonar tests --- .github/workflows/analyse.yml | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/analyse.yml diff --git a/.github/workflows/analyse.yml b/.github/workflows/analyse.yml new file mode 100644 index 0000000..bc9f520 --- /dev/null +++ b/.github/workflows/analyse.yml @@ -0,0 +1,39 @@ +name: Analyse + +on: [ push, pull_request ] + +jobs: + sonar: + name: SonarCloud + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: 17 + + - name: Cache local Maven repository + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Cache SonarCloud packages + uses: actions/cache@v3 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: Build and analyze + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \ No newline at end of file