This is an automated email from the ASF dual-hosted git repository. hboutemy pushed a commit to branch maven-extension-demo in repository https://gitbox.apache.org/repos/asf/maven-studies.git
The following commit(s) were added to refs/heads/maven-extension-demo by this push: new e07d5c232 clarify object vs component e07d5c232 is described below commit e07d5c23273ba75298f35db58249ce10239831e7 Author: Hervé Boutemy <hbout...@apache.org> AuthorDate: Mon May 27 08:04:40 2024 +0200 clarify object vs component --- .../demo/extension/ExecutionListenerDemo.java | 21 +++++++-------- src/site/apt/index.apt | 30 ++++++++++++---------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/apache/maven/demo/extension/ExecutionListenerDemo.java b/src/main/java/org/apache/maven/demo/extension/ExecutionListenerDemo.java index a5c18cf84..820525ee1 100644 --- a/src/main/java/org/apache/maven/demo/extension/ExecutionListenerDemo.java +++ b/src/main/java/org/apache/maven/demo/extension/ExecutionListenerDemo.java @@ -19,24 +19,25 @@ package org.apache.maven.demo.extension; * under the License. */ -import javax.inject.Named; -import javax.inject.Singleton; - import org.apache.maven.execution.AbstractExecutionListener; import org.apache.maven.execution.ExecutionEvent; /** - * Execution Listener demo. - * <b>Question:</b> how to inject it to Maven runtime? LifecycleParticipant can get original ExecutionListener from - * request and replace with this class that should delegate to original listener (set <a href= - * "https://maven.apache.org/ref/3.6.3/maven-embedder/xref/org/apache/maven/cli/MavenCli.html#L1446">by CLI</a> to + * Execution Listener demo.<br> + * <b>Question:</b> how to instantiate and inject it to Maven runtime?<br> + * <b>Answer</b>: LifecycleParticipant (injected by Plexus/Sisu) can get original ExecutionListener from + * request and replace with this class that should delegate to original listener<br> + * <b>Example</b>: Maven's <a href= + * "https://maven.apache.org/ref/current/maven-embedder/xref/org/apache/maven/cli/MavenCli.html#L1446">CLI</a> creates + * a new instance of * <a href= * "https://maven.apache.org/ref/current/maven-embedder/apidocs/org/apache/maven/cli/event/ExecutionEventLogger.html" - * >ExecutionEventLogger</a> that displays to console). + * >ExecutionEventLogger</a> that displays to console, and calls + * {@code eventSpyDispatcher.chainListener(executionListener)}. + * * @see org.apache.maven.execution.MavenExecutionRequest#setExecutionListener(org.apache.maven.execution.ExecutionListener) */ -@Named( "demo" ) -@Singleton +// notice: just an object, not a Plexus/Sisu/JSR 330 component public class ExecutionListenerDemo extends AbstractExecutionListener { diff --git a/src/site/apt/index.apt b/src/site/apt/index.apt index 3f7fbb9eb..7a64a3abe 100644 --- a/src/site/apt/index.apt +++ b/src/site/apt/index.apt @@ -23,11 +23,11 @@ 2018-07-22 ----- -Maven Extension Demo Study +Maven Core Extension Demo Study - Demo of Maven Extensions: + Demo of Maven Core Extensions: - * classical types of extensions, + * classical types of core extensions, * how to write them, @@ -40,22 +40,25 @@ Maven Extension Demo Study {{{./xref/}Code provided here}} demoes one specific type of extension: {{{/examples/maven-3-lifecycle-extensions.html}Maven 3 lifecycle extension}}, and the different results obtained when injecting this extension in the different ways available. - Maven lifecycle participation can be provided though 3 APIs: + Maven lifecycle participation can be provided through 3 APIs: - [[1]] {{{/ref/current/maven-core/apidocs/index.html?org/apache/maven/execution/AbstractExecutionListener.html}<<<org.apache.maven.execution.AbstractExecutionListener>>>}}, + [[1]] {{{/ref/current/maven-core/apidocs/org/apache/maven/execution/AbstractExecutionListener.html}<<<org.apache.maven.execution.AbstractExecutionListener>>>}} object, + instantiated and added to listeners like {{{/ref/current/maven-embedder/xref/org/apache/maven/cli/MavenCli.html#L1446}Maven CLI does}} using + internal {{{/ref/current/maven-core/apidocs/org/apache/maven/eventspy/internal/EventSpyDispatcher.html}<<<eventSpyDispatcher.chainListener(executionListener)>>> API}} + ({{{https://maven.apache.org/ref/current/maven-core/xref/org/apache/maven/eventspy/internal/EventSpyDispatcher.html}source}}) or copying the small implementation, - [[2]] {{{/ref/current/maven-core/apidocs/index.html?org/apache/maven/AbstractMavenLifecycleParticipant.html}<<<org.apache.maven.AbstractMavenLifecycleParticipant>>>}}, + [[2]] {{{/ref/current/maven-core/apidocs/org/apache/maven/AbstractMavenLifecycleParticipant.html}<<<org.apache.maven.AbstractMavenLifecycleParticipant>>>}} Plexus/Sisu/JSR-330 component, - [[3]] {{{/ref/current/maven-core/apidocs/index.html?org/apache/maven/eventspy/AbstractEventSpy.html}<<<org.apache.maven.eventspy.AbstractEventSpy>>>}}. + [[3]] {{{/ref/current/maven-core/apidocs/org/apache/maven/eventspy/AbstractEventSpy.html}<<<org.apache.maven.eventspy.AbstractEventSpy>>>}} Plexus/Sisu/JSR-330 component. [] This study implements each API (see {{{./apidocs/}javadoc}}) then tests implementations in ITs that configure the extension in different ways: - verification done after IT execution check expected differences (see {{{/invoker-report.html}ITs results}}). + verification done after IT execution checks expected differences (see {{{./invoker-report.html}ITs results}}). -* Classical Types of Extensions +* Classical Types of Core Extensions - A Maven extension is a library that goes into + A Maven core extension is a library that goes into {{{/guides/mini/guide-maven-classloading.html#Core_Classloader}Maven Core classloader}}, then is really in the core execution of Maven, unlike a plugin that runs in a child classloader separated from other plugins. @@ -69,12 +72,11 @@ Maven Extension Demo Study [] -* Configuring Maven Extensions +* Configuring Maven Core Extensions There are multiple methods available to declare a library as an extension: - [[1]] classical POM's {{{/ref/current/maven-model/maven.html#class_build}<<<project.build.extensions.extension>>>}} or - {{{/ref/current/maven-model/maven.html#class_plugin}<<<project.build.plugins.plugin.extensions>>>}} (since Maven 2), + [[1]] classical POM's {{{/ref/current/maven-model/maven.html#class_build}<<<project.build.extensions.extension>>>}} (since Maven 2), [[2]] put jars in Maven <<<$\{maven.home\}/lib>>> (since Maven 2) or <<<$\{maven.home\}/lib/ext>>> (since Maven 3), @@ -87,7 +89,7 @@ Maven Extension Demo Study Declaring an extension in POM is the most classical and flexible way to do: the only drawback is that the extension is activated after POM reading, which can be too late for some very specific use cases like - {{{https://maven.apache.org/ref/current/maven-core/apidocs/org/apache/maven/eventspy/package-summary.html}EventSpy}}. + {{{/ref/current/maven-core/apidocs/org/apache/maven/eventspy/package-summary.html}EventSpy}}. Installing an extension directly inside Maven installation avoids the previous limitation, but is not flexible.