From eaec3186c51643aef8e218bb6e50abca15823334 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Tue, 4 Aug 2026 23:20:55 +0200 Subject: [PATCH] Verify that the debug level of extensions is respected --- .../it/MavenITgh12668ExtensionDebugLevel.java | 142 ++++++++++++++++++ .../apache/maven/it/TestSuiteOrdering.java | 1 + .../src/test/resources-filtered/bootstrap.txt | 1 + .../extension/pom.xml | 60 ++++++++ .../apache/maven/its/gh12668/Extension.java | 53 +++++++ .../project-build/pom.xml | 37 +++++ .../project-core/.mvn/extensions.xml | 8 + .../project-core/pom.xml | 27 ++++ 8 files changed, 329 insertions(+) create mode 100644 core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12668ExtensionDebugLevel.java create mode 100644 core-it-suite/src/test/resources/gh-12668-extension-debug-level/extension/pom.xml create mode 100644 core-it-suite/src/test/resources/gh-12668-extension-debug-level/extension/src/main/java/org/apache/maven/its/gh12668/Extension.java create mode 100644 core-it-suite/src/test/resources/gh-12668-extension-debug-level/project-build/pom.xml create mode 100644 core-it-suite/src/test/resources/gh-12668-extension-debug-level/project-core/.mvn/extensions.xml create mode 100644 core-it-suite/src/test/resources/gh-12668-extension-debug-level/project-core/pom.xml diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12668ExtensionDebugLevel.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12668ExtensionDebugLevel.java new file mode 100644 index 000000000..4c4d00eff --- /dev/null +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12668ExtensionDebugLevel.java @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License 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. + */ +package org.apache.maven.it; + +import java.io.File; +import java.util.List; + +import org.apache.maven.shared.verifier.VerificationException; +import org.apache.maven.shared.verifier.Verifier; +import org.apache.maven.shared.verifier.util.ResourceExtractor; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +/** + * Verify that the debug level of extensions is respected. + * gh-12668 + */ +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class MavenITgh12668ExtensionDebugLevel extends AbstractMavenIntegrationTestCase { + + public MavenITgh12668ExtensionDebugLevel() { + super("[3.9.0,)"); + } + + @Test + @Order(1) + public void installExtension() throws Exception { + File projectDir = ResourceExtractor.simpleExtractResources(getClass(), "/gh-12668-extension-debug-level"); + + Verifier extensionVerifier = newVerifier(new File(projectDir, "extension").getAbsolutePath()); + extensionVerifier.addCliArgument("install"); + extensionVerifier.execute(); + extensionVerifier.verifyErrorFreeLog(); + } + + @Test + public void projectBuildExtensionDebug() throws Exception { + File projectDir = ResourceExtractor.simpleExtractResources(getClass(), "/gh-12668-extension-debug-level"); + + Verifier verifier = newVerifier(new File(projectDir, "project-build").getAbsolutePath()); + verifier.addCliArgument("validate"); + verifier.addCliArgument("-X"); + verifier.setLogFileName("debug.log"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + verifier.verifyTextInLog("[DEBUG] extension afterProjectsRead called"); + verifier.verifyTextInLog("[INFO] extension afterProjectsRead called"); + + verifier.verifyTextInLog("[DEBUG] extension afterSessionEnd called"); + verifier.verifyTextInLog("[INFO] extension afterSessionEnd called"); + } + + @Test + public void projectBuildExtensionInfo() throws Exception { + File projectDir = ResourceExtractor.simpleExtractResources(getClass(), "/gh-12668-extension-debug-level"); + + Verifier verifier = newVerifier(new File(projectDir, "project-build").getAbsolutePath()); + verifier.addCliArgument("validate"); + verifier.setLogFileName("info.log"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + verifyTextNotInLog(verifier, "[DEBUG] extension afterProjectsRead called"); + verifier.verifyTextInLog("[INFO] extension afterProjectsRead called"); + + verifyTextNotInLog(verifier, "[DEBUG] extension afterSessionEnd called"); + verifier.verifyTextInLog("[INFO] extension afterSessionEnd called"); + } + + @Test + public void coreExtensionDebug() throws Exception { + File projectDir = ResourceExtractor.simpleExtractResources(getClass(), "/gh-12668-extension-debug-level"); + + Verifier verifier = newVerifier(new File(projectDir, "project-core").getAbsolutePath()); + verifier.addCliArgument("validate"); + verifier.addCliArgument("-X"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + verifier.verifyTextInLog("[DEBUG] extension afterSessionStart called"); + verifier.verifyTextInLog("[INFO] extension afterSessionStart called"); + + verifier.verifyTextInLog("[DEBUG] extension afterProjectsRead called"); + verifier.verifyTextInLog("[INFO] extension afterProjectsRead called"); + + verifier.verifyTextInLog("[DEBUG] extension afterSessionEnd called"); + verifier.verifyTextInLog("[INFO] extension afterSessionEnd called"); + } + + @Test + public void coreExtensionInfo() throws Exception { + File projectDir = ResourceExtractor.simpleExtractResources(getClass(), "/gh-12668-extension-debug-level"); + + Verifier verifier = newVerifier(new File(projectDir, "project-core").getAbsolutePath()); + verifier.addCliArgument("validate"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + verifyTextNotInLog(verifier, "[DEBUG] extension afterSessionStart called"); + verifier.verifyTextInLog("[INFO] extension afterSessionStart called"); + + verifyTextNotInLog(verifier, "[DEBUG] extension afterProjectsRead called"); + verifier.verifyTextInLog("[INFO] extension afterProjectsRead called"); + + verifyTextNotInLog(verifier, "[DEBUG] extension afterSessionEnd called"); + verifier.verifyTextInLog("[INFO] extension afterSessionEnd called"); + } + + private void verifyTextNotInLog(Verifier verifier, String text) throws VerificationException { + List lines = verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false); + + boolean textFound = false; + for (String line : lines) { + if (line.contains(text)) { + textFound = true; + break; + } + } + if (textFound) { + throw new VerificationException("Text found in log: " + text); + } + } +} diff --git a/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java b/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java index 8acd0b027..8a7964ad5 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java @@ -121,6 +121,7 @@ public TestSuiteOrdering() { * a fail fast technique as well. */ + suite.addTestSuite(MavenITgh12668ExtensionDebugLevel.class); suite.addTestSuite(MavenITgh12288SettingsProfileAetherPropertiesTest.class); suite.addTestSuite(MavenITgh10312TerminallyDeprecatedMethodInGuiceTest.class); suite.addTestSuite(MavenITgh10937QuotedPipesInMavenOptsTest.class); diff --git a/core-it-suite/src/test/resources-filtered/bootstrap.txt b/core-it-suite/src/test/resources-filtered/bootstrap.txt index dfb54b74b..8398de19a 100644 --- a/core-it-suite/src/test/resources-filtered/bootstrap.txt +++ b/core-it-suite/src/test/resources-filtered/bootstrap.txt @@ -166,6 +166,7 @@ org.eclipse.aether:aether-spi:0.9.0.M2 org.eclipse.sisu:org.eclipse.sisu.inject:0.0.0.M5 org.eclipse.sisu:org.eclipse.sisu.plexus:0.0.0.M5 org.eclipse.sisu:sisu-maven-plugin:0.9.0.M4 +org.eclipse.sisu:sisu-maven-plugin:1.1.0 org.junit:junit-bom:5.9.1:pom org.junit.jupiter:junit-jupiter:5.9.1 org.junit.jupiter:junit-jupiter-engine:5.9.1 diff --git a/core-it-suite/src/test/resources/gh-12668-extension-debug-level/extension/pom.xml b/core-it-suite/src/test/resources/gh-12668-extension-debug-level/extension/pom.xml new file mode 100644 index 000000000..8a9f4bcd8 --- /dev/null +++ b/core-it-suite/src/test/resources/gh-12668-extension-debug-level/extension/pom.xml @@ -0,0 +1,60 @@ + + + + 4.0.0 + + org.apache.maven.its.gh12668 + extension + 1.0 + + + + org.apache.maven + maven-core + 3.8.6 + provided + + + org.slf4j + slf4j-api + 1.7.36 + provided + + + + + + + org.eclipse.sisu + sisu-maven-plugin + 1.1.0 + + + index-project + + main-index + + + + + + + + diff --git a/core-it-suite/src/test/resources/gh-12668-extension-debug-level/extension/src/main/java/org/apache/maven/its/gh12668/Extension.java b/core-it-suite/src/test/resources/gh-12668-extension-debug-level/extension/src/main/java/org/apache/maven/its/gh12668/Extension.java new file mode 100644 index 000000000..009a74fdf --- /dev/null +++ b/core-it-suite/src/test/resources/gh-12668-extension-debug-level/extension/src/main/java/org/apache/maven/its/gh12668/Extension.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License 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. + */ +package org.apache.maven.its.mng7160; + +import javax.inject.Named; +import javax.inject.Singleton; + +import org.apache.maven.AbstractMavenLifecycleParticipant; +import org.apache.maven.MavenExecutionException; +import org.apache.maven.execution.MavenSession; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Singleton +@Named +public class Extension extends AbstractMavenLifecycleParticipant { + + private final Logger logger = LoggerFactory.getLogger(Extension.class); + + @Override + public void afterProjectsRead(MavenSession session) throws MavenExecutionException { + logger.debug("extension afterProjectsRead called"); + logger.info("extension afterProjectsRead called"); + } + + @Override + public void afterSessionStart(MavenSession session) throws MavenExecutionException { + logger.debug("extension afterSessionStart called"); + logger.info("extension afterSessionStart called"); + } + + @Override + public void afterSessionEnd(MavenSession session) throws MavenExecutionException { + logger.debug("extension afterSessionEnd called"); + logger.info("extension afterSessionEnd called"); + } +} diff --git a/core-it-suite/src/test/resources/gh-12668-extension-debug-level/project-build/pom.xml b/core-it-suite/src/test/resources/gh-12668-extension-debug-level/project-build/pom.xml new file mode 100644 index 000000000..934dd58e1 --- /dev/null +++ b/core-it-suite/src/test/resources/gh-12668-extension-debug-level/project-build/pom.xml @@ -0,0 +1,37 @@ + + + + 4.0.0 + + org.apache.maven.its.gh12668 + project1 + 1.0 + + + + + org.apache.maven.its.gh12668 + extension + 1.0 + + + + + diff --git a/core-it-suite/src/test/resources/gh-12668-extension-debug-level/project-core/.mvn/extensions.xml b/core-it-suite/src/test/resources/gh-12668-extension-debug-level/project-core/.mvn/extensions.xml new file mode 100644 index 000000000..ae4b3a13d --- /dev/null +++ b/core-it-suite/src/test/resources/gh-12668-extension-debug-level/project-core/.mvn/extensions.xml @@ -0,0 +1,8 @@ + + + org.apache.maven.its.gh12668 + extension + 1.0 + plugin + + diff --git a/core-it-suite/src/test/resources/gh-12668-extension-debug-level/project-core/pom.xml b/core-it-suite/src/test/resources/gh-12668-extension-debug-level/project-core/pom.xml new file mode 100644 index 000000000..216326e0a --- /dev/null +++ b/core-it-suite/src/test/resources/gh-12668-extension-debug-level/project-core/pom.xml @@ -0,0 +1,27 @@ + + + + 4.0.0 + + org.apache.maven.its.gh12668 + project1 + 1.0 + +