This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch maven-4.0.x
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/maven-4.0.x by this push:
new 7fcd684d8a feat: introduce Logger/LogEventBuilder API and deprecate
plugin.Log in 4.0.0 (#14066)
7fcd684d8a is described below
commit 7fcd684d8aa1c552657eae4d2e88572b4e72bccc
Author: Guillaume Nodet <[email protected]>
AuthorDate: Mon Nov 23 08:32:51 2026 +0100
feat: introduce Logger/LogEventBuilder API and deprecate plugin.Log in
4.0.0 (#14066)
Introduces `maven-api-log` module with `Logger`/`LogEventBuilder`/`LogLevel`
interfaces (`@since 4.0.0`), backed by a SLF4J `DefaultLogger`
implementation
that replaces the internal `DefaultLog`. All deprecated methods retain their
existing signatures — no binary compatibility break.
- New `api/maven-api-log` module: `Logger`, `LogEventBuilder`, `LogLevel`
interfaces
wired into the build; `DefaultLog` becomes a compatibility bridge
delegating to
`DefaultLogger`
- `org.apache.maven.api.plugin.Log` deprecated (`since="4.0.0",
forRemoval=true`)
in favour of `org.apache.maven.api.logging.Logger`
- `ModelProcessor.read(XmlReaderRequest)` deprecated; new `read(Source,
Map)` method
added, honouring the `"strict"` option from the options map (default
`true`)
- `Session.getDegreeOfConcurrency()` deprecated; noun-style
`degreeOfConcurrency()`
bridge added
- ~60 `getX()` accessor methods deprecated across `Artifact`,
`ArtifactCoordinates`,
`Dependency`, `DependencyCoordinates`, `DownloadedArtifact`, `Event`,
`Exclusion`,
`LocalRepository`, `Node`, `Project`, `RemoteRepository`, `Repository`,
`Session`,
`VersionConstraint`, `VersionRange`; noun-style `default` bridge methods
added for each
- Test coverage updated: `DefaultLoggerTest` refactored with extracted
helpers,
`MojoExtension` wired to bind `Logger` in test DI module
---
api/maven-api-core/pom.xml | 4 +
.../main/java/org/apache/maven/api/Artifact.java | 83 ++++-
.../org/apache/maven/api/ArtifactCoordinates.java | 70 +++-
.../main/java/org/apache/maven/api/Dependency.java | 24 ++
.../apache/maven/api/DependencyCoordinates.java | 47 +++
.../org/apache/maven/api/DownloadedArtifact.java | 13 +
.../src/main/java/org/apache/maven/api/Event.java | 57 ++++
.../main/java/org/apache/maven/api/Exclusion.java | 30 ++
.../java/org/apache/maven/api/LocalRepository.java | 13 +
.../src/main/java/org/apache/maven/api/Node.java | 61 ++++
.../main/java/org/apache/maven/api/Project.java | 214 +++++++++++++
.../org/apache/maven/api/RemoteRepository.java | 26 ++
.../main/java/org/apache/maven/api/Repository.java | 24 ++
.../main/java/org/apache/maven/api/Session.java | 12 +
.../org/apache/maven/api/VersionConstraint.java | 30 ++
.../java/org/apache/maven/api/VersionRange.java | 52 +++
.../main/java/org/apache/maven/api/plugin/Log.java | 4 +
.../apache/maven/api/di/MojoExecutionScoped.java | 2 +-
api/{maven-api-core => maven-api-log}/pom.xml | 41 +--
.../apache/maven/api/logging/LogEventBuilder.java | 191 +++++++++++
.../org/apache/maven/api/logging/LogLevel.java} | 23 +-
.../java/org/apache/maven/api/logging/Logger.java | 348 ++++++++++++++++++++
.../org/apache/maven/api/logging/package-info.java | 42 +++
.../maven/api/services/model/ModelProcessor.java | 35 ++
api/pom.xml | 1 +
.../scope/internal/MojoExecutionScopeModule.java | 5 +
.../org/apache/maven/internal/impl/DefaultLog.java | 1 +
.../apache/maven/internal/impl/DefaultLogger.java | 355 +++++++++++++++++++++
.../maven/plugin/DefaultBuildPluginManager.java | 6 +
.../plugin/internal/DefaultMavenPluginManager.java | 10 +-
.../maven/internal/impl/DefaultLoggerTest.java | 307 ++++++++++++++++++
.../apache/maven/testing/plugin/MojoExtension.java | 9 +
pom.xml | 5 +
33 files changed, 2084 insertions(+), 61 deletions(-)
diff --git a/api/maven-api-core/pom.xml b/api/maven-api-core/pom.xml
index 104d6375b7..b4e7c92e4a 100644
--- a/api/maven-api-core/pom.xml
+++ b/api/maven-api-core/pom.xml
@@ -35,6 +35,10 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-annotations</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-api-log</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-di</artifactId>
diff --git
a/api/maven-api-core/src/main/java/org/apache/maven/api/Artifact.java
b/api/maven-api-core/src/main/java/org/apache/maven/api/Artifact.java
index 7303e8e61c..b065feea0a 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/Artifact.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Artifact.java
@@ -46,33 +46,60 @@ public interface Artifact {
*/
@Nonnull
default String key() {
- String c = getClassifier();
- return getGroupId()
- + ':'
- + getArtifactId()
- + ':'
- + getExtension()
- + (c.isEmpty() ? "" : ":" + c)
- + ':'
- + getVersion();
+ String c = classifier();
+ return groupId() + ':' + artifactId() + ':' + extension() +
(c.isEmpty() ? "" : ":" + c) + ':' + version();
+ }
+
+ /**
+ * {@return the groupId}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default String groupId() {
+ return getGroupId();
}
/**
* {@return the group identifier of the artifact}
*
* @see ArtifactCoordinates#getGroupId()
+ * @deprecated Use {@link #groupId()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getGroupId();
+ /**
+ * {@return the artifactId}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default String artifactId() {
+ return getArtifactId();
+ }
+
/**
* {@return the identifier of the artifact}
*
* @see ArtifactCoordinates#getArtifactId()
+ * @deprecated Use {@link #artifactId()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getArtifactId();
+ /**
+ * {@return the version}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default Version version() {
+ return getVersion();
+ }
+
/**
* {@return the version of the artifact}
* Contrarily to {@link ArtifactCoordinates},
@@ -81,36 +108,74 @@ default String key() {
* those keywords are replaced by, for example, the actual timestamp.
*
* @see ArtifactCoordinates#getVersionConstraint()
+ * @deprecated Use {@link #version()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
Version getVersion();
+ /**
+ * {@return the baseVersion}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default Version baseVersion() {
+ return getBaseVersion();
+ }
+
/**
* {@return the version or meta-version of the artifact}
* A meta-version is a version suffixed with the {@code SNAPSHOT} keyword.
* Meta-versions are represented in a base version by their symbols (e.g.,
{@code SNAPSHOT}),
* while they are replaced by, for example, the actual timestamp in the
{@linkplain #getVersion() version}.
+ * @deprecated Use {@link #baseVersion()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
Version getBaseVersion();
+ /**
+ * {@return the classifier}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default String classifier() {
+ return getClassifier();
+ }
+
/**
* Returns the classifier of the artifact.
*
* @return the classifier or an empty string if none, never {@code null}
* @see ArtifactCoordinates#getClassifier()
+ * @deprecated Use {@link #classifier()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getClassifier();
+ /**
+ * {@return the extension}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default String extension() {
+ return getExtension();
+ }
+
/**
* Returns the file extension of the artifact.
* The dot separator is <em>not</em> included in the returned string.
*
* @return the file extension or an empty string if none, never {@code
null}
* @see ArtifactCoordinates#getExtension()
+ * @deprecated Use {@link #extension()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getExtension();
/**
diff --git
a/api/maven-api-core/src/main/java/org/apache/maven/api/ArtifactCoordinates.java
b/api/maven-api-core/src/main/java/org/apache/maven/api/ArtifactCoordinates.java
index be1a1e14ee..bd3a8a09d8 100644
---
a/api/maven-api-core/src/main/java/org/apache/maven/api/ArtifactCoordinates.java
+++
b/api/maven-api-core/src/main/java/org/apache/maven/api/ArtifactCoordinates.java
@@ -32,40 +32,100 @@
@Experimental
@Immutable
public interface ArtifactCoordinates {
+ /**
+ * {@return the groupId}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default String groupId() {
+ return getGroupId();
+ }
+
/**
* {@return the group identifier of the artifact}
+ * @deprecated Use {@link #groupId()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getGroupId();
+ /**
+ * {@return the artifactId}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default String artifactId() {
+ return getArtifactId();
+ }
+
/**
* {@return the identifier of the artifact}
+ * @deprecated Use {@link #artifactId()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getArtifactId();
+ /**
+ * {@return the classifier}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default String classifier() {
+ return getClassifier();
+ }
+
/**
* Returns the classifier of the artifact.
*
* @return the classifier or an empty string if none, never {@code null}
+ * @deprecated Use {@link #classifier()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getClassifier();
+ /**
+ * {@return the versionConstraint}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default VersionConstraint versionConstraint() {
+ return getVersionConstraint();
+ }
+
/**
* {@return the specific version, range of versions or meta-version of the
artifact}
* A meta-version is a version suffixed with the {@code SNAPSHOT} keyword.
+ * @deprecated Use {@link #versionConstraint()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
VersionConstraint getVersionConstraint();
+ /**
+ * {@return the extension}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default String extension() {
+ return getExtension();
+ }
+
/**
* Returns the file extension of the artifact.
* The dot separator is <em>not</em> included in the returned string.
*
* @return the file extension or an empty string if none, never {@code
null}
+ * @deprecated Use {@link #extension()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getExtension();
/**
@@ -78,14 +138,14 @@ public interface ArtifactCoordinates {
*/
@Nonnull
default String getId() {
- String c = getClassifier();
- return getGroupId()
+ String c = classifier();
+ return groupId()
+ ':'
- + getArtifactId()
+ + artifactId()
+ ':'
- + getExtension()
+ + extension()
+ (c.isEmpty() ? "" : ":" + c)
+ ':'
- + getVersionConstraint();
+ + versionConstraint();
}
}
diff --git
a/api/maven-api-core/src/main/java/org/apache/maven/api/Dependency.java
b/api/maven-api-core/src/main/java/org/apache/maven/api/Dependency.java
index 5a2ad2b9d4..47689c8935 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/Dependency.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Dependency.java
@@ -35,6 +35,16 @@
@Experimental
@Immutable
public interface Dependency extends Artifact {
+ /**
+ * {@return the type}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default Type type() {
+ return getType();
+ }
+
/**
* {@return the type of the dependency}
* A dependency can be a <abbr>JAR</abbr> file,
@@ -42,17 +52,31 @@ public interface Dependency extends Artifact {
* a <abbr>JAR</abbr> containing test classes, <i>etc.</i>
*
* @see DependencyCoordinates#getType()
+ * @deprecated Use {@link #type()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
Type getType();
+ /**
+ * {@return the scope}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default DependencyScope scope() {
+ return getScope();
+ }
+
/**
* {@return the time at which the dependency will be used}
* It may be, for example, at compile time only, at run time or at test
time.
*
* @see DependencyCoordinates#getScope()
+ * @deprecated Use {@link #scope()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
DependencyScope getScope();
/**
diff --git
a/api/maven-api-core/src/main/java/org/apache/maven/api/DependencyCoordinates.java
b/api/maven-api-core/src/main/java/org/apache/maven/api/DependencyCoordinates.java
index cbcc264db6..c3d526c0b9 100644
---
a/api/maven-api-core/src/main/java/org/apache/maven/api/DependencyCoordinates.java
+++
b/api/maven-api-core/src/main/java/org/apache/maven/api/DependencyCoordinates.java
@@ -38,33 +38,80 @@
@Experimental
@Immutable
public interface DependencyCoordinates extends ArtifactCoordinates {
+ /**
+ * {@return the type}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default Type type() {
+ return getType();
+ }
+
/**
* {@return the type of the dependency}
* A dependency can be a <abbr>JAR</abbr> file,
* a modular-<abbr>JAR</abbr> if it is intended to be placed on the module
path,
* a <abbr>JAR</abbr> containing test classes, a POM file, <i>etc.</i>
+ * @deprecated Use {@link #type()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
Type getType();
+ /**
+ * {@return the scope}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default DependencyScope scope() {
+ return getScope();
+ }
+
/**
* {@return the time at which the dependency will be used}
* It may be, for example, at compile time only, at run time, or at test
time.
+ * @deprecated Use {@link #scope()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
DependencyScope getScope();
+ /**
+ * {@return the optional}
+ *
+ * @since 4.0.0
+ */
+ default Boolean optional() {
+ return getOptional();
+ }
+
/**
* Returns whether the dependency is optional, mandatory, or of
unspecified obligation.
*
* @return {@code Boolean.TRUE} and {@code Boolean.FALSE} if optional, or
{@code null} if unspecified
+ * @deprecated Use {@link #optional()} instead.
*/
@Nullable
+ @Deprecated(since = "4.0.0", forRemoval = true)
Boolean getOptional();
+ /**
+ * {@return the exclusions}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default Collection<Exclusion> exclusions() {
+ return getExclusions();
+ }
+
/**
* {@return transitive dependencies to exclude}
+ * @deprecated Use {@link #exclusions()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
Collection<Exclusion> getExclusions();
}
diff --git
a/api/maven-api-core/src/main/java/org/apache/maven/api/DownloadedArtifact.java
b/api/maven-api-core/src/main/java/org/apache/maven/api/DownloadedArtifact.java
index 10e9deb898..d51485df98 100644
---
a/api/maven-api-core/src/main/java/org/apache/maven/api/DownloadedArtifact.java
+++
b/api/maven-api-core/src/main/java/org/apache/maven/api/DownloadedArtifact.java
@@ -22,6 +22,7 @@
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
+import org.apache.maven.api.annotations.Nonnull;
/**
* An {@link Artifact} that has been resolved, i.e. downloaded to the local
repository.
@@ -32,8 +33,20 @@
@Immutable
public interface DownloadedArtifact extends Artifact {
+ /**
+ * {@return the path}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default Path path() {
+ return getPath();
+ }
+
/**
* {@return the actual file that has been downloaded in the file system}
+ * @deprecated Use {@link #path()} instead.
*/
+ @Deprecated(since = "4.0.0", forRemoval = true)
Path getPath();
}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/Event.java
b/api/maven-api-core/src/main/java/org/apache/maven/api/Event.java
index 0323abd435..46dbefd936 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/Event.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Event.java
@@ -33,42 +33,99 @@
@Experimental
public interface Event {
+ /**
+ * {@return the type}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default EventType type() {
+ return getType();
+ }
+
/**
* Gets the type of the event.
*
* @return the type of the event, never {@code null}
+ * @deprecated Use {@link #type()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
EventType getType();
+ /**
+ * {@return the session}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default Session session() {
+ return getSession();
+ }
+
/**
* Gets the session from which this event originates.
*
* @return the current session, never {@code null}
+ * @deprecated Use {@link #session()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
Session getSession();
+ /**
+ * {@return the project}
+ *
+ * @since 4.0.0
+ */
+ default Optional<Project> project() {
+ return getProject();
+ }
+
/**
* Gets the current project (if any).
*
* @return the current project or {@code empty()} if not applicable
+ * @deprecated Use {@link #project()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
Optional<Project> getProject();
+ /**
+ * {@return the mojoExecution}
+ *
+ * @since 4.0.0
+ */
+ default Optional<MojoExecution> mojoExecution() {
+ return getMojoExecution();
+ }
+
/**
* Gets the current mojo execution (if any).
*
* @return the current mojo execution or {@code empty()} if not applicable
+ * @deprecated Use {@link #mojoExecution()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
Optional<MojoExecution> getMojoExecution();
+ /**
+ * {@return the exception}
+ *
+ * @since 4.0.0
+ */
+ default Optional<Exception> exception() {
+ return getException();
+ }
+
/**
* Gets the exception that caused the event (if any).
*
* @return the exception or {@code empty()} if none
+ * @deprecated Use {@link #exception()} instead.
*/
+ @Deprecated(since = "4.0.0", forRemoval = true)
Optional<Exception> getException();
}
diff --git
a/api/maven-api-core/src/main/java/org/apache/maven/api/Exclusion.java
b/api/maven-api-core/src/main/java/org/apache/maven/api/Exclusion.java
index 99f9263c32..1d3bee030b 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/Exclusion.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Exclusion.java
@@ -29,9 +29,39 @@
*/
@Experimental
public interface Exclusion {
+ /**
+ * Returns the groupId for this exclusion, or {@code null} if unset.
+ *
+ * @return the groupId, or {@code null}
+ * @since 4.0.0
+ */
@Nullable
+ default String groupId() {
+ return getGroupId();
+ }
+
+ /**
+ * @deprecated Use {@link #groupId()} instead.
+ */
+ @Nullable
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getGroupId();
+ /**
+ * Returns the artifactId for this exclusion, or {@code null} if unset.
+ *
+ * @return the artifactId, or {@code null}
+ * @since 4.0.0
+ */
+ @Nullable
+ default String artifactId() {
+ return getArtifactId();
+ }
+
+ /**
+ * @deprecated Use {@link #artifactId()} instead.
+ */
@Nullable
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getArtifactId();
}
diff --git
a/api/maven-api-core/src/main/java/org/apache/maven/api/LocalRepository.java
b/api/maven-api-core/src/main/java/org/apache/maven/api/LocalRepository.java
index cea61bc3c5..afbc53802f 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/LocalRepository.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/LocalRepository.java
@@ -46,6 +46,19 @@
@Immutable
public interface LocalRepository extends Repository {
+ /**
+ * {@return the path}
+ *
+ * @since 4.0.0
+ */
@Nonnull
+ default Path path() {
+ return getPath();
+ }
+
+ /**
+ * @deprecated Use {@link #path()} instead.
+ */
+ @Deprecated(since = "4.0.0", forRemoval = true)
Path getPath();
}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/Node.java
b/api/maven-api-core/src/main/java/org/apache/maven/api/Node.java
index 75038ea736..2993887eb5 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/Node.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Node.java
@@ -40,40 +40,101 @@
@Provider
public interface Node {
+ /**
+ * Returns the artifact for this node, or {@code null} for the root node.
+ *
+ * @return the artifact, or {@code null}
+ * @since 4.0.0
+ */
+ @Nullable
+ default Artifact artifact() {
+ return getArtifact();
+ }
+
/**
* @return artifact for this node
+ * @deprecated Use {@link #artifact()} instead.
*/
@Nullable
+ @Deprecated(since = "4.0.0", forRemoval = true)
Artifact getArtifact();
+ /**
+ * Returns the dependency for this node, or {@code null} for the root node.
+ *
+ * @return the dependency, or {@code null}
+ * @since 4.0.0
+ */
+ @Nullable
+ default Dependency dependency() {
+ return getDependency();
+ }
+
/**
* @return dependency for this node
+ * @deprecated Use {@link #dependency()} instead.
*/
@Nullable
+ @Deprecated(since = "4.0.0", forRemoval = true)
Dependency getDependency();
+ /**
+ * {@return the children}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default List<Node> children() {
+ return getChildren();
+ }
+
/**
* Gets the child nodes of this node.
*
* @return the child nodes of this node, never {@code null}
+ * @deprecated Use {@link #children()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
List<Node> getChildren();
+ /**
+ * {@return the remoteRepositories}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default List<RemoteRepository> remoteRepositories() {
+ return getRemoteRepositories();
+ }
+
/**
* @return repositories of this node
+ * @deprecated Use {@link #remoteRepositories()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
List<RemoteRepository> getRemoteRepositories();
+ /**
+ * {@return the repository}
+ *
+ * @since 4.0.0
+ */
+ default Optional<RemoteRepository> repository() {
+ return getRepository();
+ }
+
/**
* Returns the remote repository from which this artifact was downloaded,
if known.
*
* @return an {@code Optional} containing the repository, or empty if not
available
* (e.g. local artifact, root node, or when the local repository
manager
* does not track artifact origins such as {@code
SimpleLocalRepositoryManager})
+ * @deprecated Use {@link #repository()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
Optional<RemoteRepository> getRepository();
/**
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/Project.java
b/api/maven-api-core/src/main/java/org/apache/maven/api/Project.java
index 22115c3572..edc2e36b22 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/Project.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Project.java
@@ -50,24 +50,70 @@
@Experimental
public interface Project {
+ /**
+ * {@return the groupId}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default String groupId() {
+ return getGroupId();
+ }
+
/**
* {@return the project groupId}.
+ * @deprecated Use {@link #groupId()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getGroupId();
+ /**
+ * {@return the artifactId}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default String artifactId() {
+ return getArtifactId();
+ }
+
/**
* {@return the project artifactId}.
+ * @deprecated Use {@link #artifactId()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getArtifactId();
+ /**
+ * {@return the version}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default String version() {
+ return getVersion();
+ }
+
/**
* {@return the project version}.
+ * @deprecated Use {@link #version()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getVersion();
+ /**
+ * {@return the packaging}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default Packaging packaging() {
+ return getPackaging();
+ }
+
/**
* {@return the project packaging}.
* <p>
@@ -76,8 +122,10 @@ public interface Project {
* {@link #getArtifacts()} to gain access to POM or build artifact.
*
* @see #getArtifacts()
+ * @deprecated Use {@link #packaging()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
Packaging getPackaging();
/**
@@ -90,30 +138,63 @@ default Language getLanguage() {
return getPackaging().language();
}
+ /**
+ * {@return the pomArtifact}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default ProducedArtifact pomArtifact() {
+ return getPomArtifact();
+ }
+
/**
* {@return the project POM artifact}, which is the artifact of the POM of
this project. Every project have a POM
* artifact, even if the existence of backing POM file is NOT a
requirement (i.e. for some transient projects).
*
* @see org.apache.maven.api.services.ArtifactManager#getPath(Artifact)
+ * @deprecated Use {@link #pomArtifact()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
default ProducedArtifact getPomArtifact() {
return getArtifacts().get(0);
}
+ /**
+ * {@return the mainArtifact}
+ *
+ * @since 4.0.0
+ */
+ default Optional<ProducedArtifact> mainArtifact() {
+ return getMainArtifact();
+ }
+
/**
* {@return the project main artifact}, which is the artifact produced by
this project build, if applicable.
* This artifact MAY be absent if the project is actually not producing
any main artifact (i.e. "pom" packaging).
*
* @see #getPackaging()
* @see org.apache.maven.api.services.ArtifactManager#getPath(Artifact)
+ * @deprecated Use {@link #mainArtifact()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
default Optional<ProducedArtifact> getMainArtifact() {
List<ProducedArtifact> artifacts = getArtifacts();
return artifacts.size() == 2 ? Optional.of(artifacts.get(1)) :
Optional.empty();
}
+ /**
+ * {@return the artifacts}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default List<ProducedArtifact> artifacts() {
+ return getArtifacts();
+ }
+
/**
* {@return the project artifacts as immutable list}. Elements are the
project POM artifact and the artifact
* produced by this project build, if applicable. Hence, the returned list
may have one or two elements
@@ -126,27 +207,63 @@ default Optional<ProducedArtifact> getMainArtifact() {
* @see #getPomArtifact()
* @see #getMainArtifact()
* @see org.apache.maven.api.services.ArtifactManager#getPath(Artifact)
+ * @deprecated Use {@link #artifacts()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
List<ProducedArtifact> getArtifacts();
+ /**
+ * {@return the model}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default Model model() {
+ return getModel();
+ }
+
/**
* {@return the project model}.
+ * @deprecated Use {@link #model()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
Model getModel();
+ /**
+ * {@return the build}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default Build build() {
+ return getBuild();
+ }
+
/**
* Shorthand method.
*
* @return the build element of the project model
+ * @deprecated Use {@link #build()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
default Build getBuild() {
Build build = getModel().getBuild();
return build != null ? build : Build.newInstance();
}
+ /**
+ * {@return the pomPath}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default Path pomPath() {
+ return getPomPath();
+ }
+
/**
* Returns the path to the pom file for this project.
* A project is usually read from a file named {@code pom.xml},
@@ -159,18 +276,32 @@ default Build getBuild() {
*
* @return the path of the pom
* @see #getBasedir()
+ * @deprecated Use {@link #pomPath()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
Path getPomPath();
+ /**
+ * {@return the basedir}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default Path basedir() {
+ return getBasedir();
+ }
+
/**
* Returns the project base directory, i.e. the directory containing the
project.
* A project is usually read from the file system and this will point to
* the directory containing the POM file.
*
* @return the path of the directory containing the project
+ * @deprecated Use {@link #basedir()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
Path getBasedir();
/**
@@ -292,16 +423,40 @@ default Path getOutputDirectory(@Nullable ProjectScope
scope) {
return getBasedir().resolve(dir);
}
+ /**
+ * {@return the dependencies}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default List<DependencyCoordinates> dependencies() {
+ return getDependencies();
+ }
+
/**
* {@return the project direct dependencies (directly specified or
inherited)}.
+ * @deprecated Use {@link #dependencies()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
List<DependencyCoordinates> getDependencies();
+ /**
+ * {@return the managedDependencies}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default List<DependencyCoordinates> managedDependencies() {
+ return getManagedDependencies();
+ }
+
/**
* {@return the project managed dependencies (directly specified or
inherited)}.
+ * @deprecated Use {@link #managedDependencies()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
List<DependencyCoordinates> getManagedDependencies();
/**
@@ -335,6 +490,16 @@ default String getId() {
*/
boolean isRootProject();
+ /**
+ * {@return the rootDirectory}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default Path rootDirectory() {
+ return getRootDirectory();
+ }
+
/**
* Gets the root directory of the project, which is the parent directory
* containing the {@code .mvn} directory or flagged with {@code
root="true"}.
@@ -342,10 +507,21 @@ default String getId() {
* @return the root directory of the project
* @throws IllegalStateException if the root directory could not be found
* @see Session#getRootDirectory()
+ * @deprecated Use {@link #rootDirectory()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
Path getRootDirectory();
+ /**
+ * {@return the parent}
+ *
+ * @since 4.0.0
+ */
+ default Optional<Project> parent() {
+ return getParent();
+ }
+
/**
* Returns project parent project, if any.
* <p>
@@ -355,10 +531,22 @@ default String getId() {
*
* @return an optional containing the parent project
* @see Model#getParent()
+ * @deprecated Use {@link #parent()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
Optional<Project> getParent();
+ /**
+ * {@return the declaredProfiles}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default List<Profile> declaredProfiles() {
+ return getDeclaredProfiles();
+ }
+
/**
* Returns all profiles defined in this project.
* <p>
@@ -368,10 +556,22 @@ default String getId() {
* @return a non-null, possibly empty list of profiles defined in this
project
* @see Profile
* @see #getEffectiveProfiles()
+ * @deprecated Use {@link #declaredProfiles()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
List<Profile> getDeclaredProfiles();
+ /**
+ * {@return the effectiveProfiles}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default List<Profile> effectiveProfiles() {
+ return getEffectiveProfiles();
+ }
+
/**
* Returns all profiles defined in this project and all of its parent
projects.
* <p>
@@ -382,10 +582,22 @@ default String getId() {
* @return a non-null, possibly empty list of all profiles from this
project and its parents
* @see Profile
* @see #getDeclaredProfiles()
+ * @deprecated Use {@link #effectiveProfiles()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
List<Profile> getEffectiveProfiles();
+ /**
+ * {@return the declaredActiveProfiles}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default List<Profile> declaredActiveProfiles() {
+ return getDeclaredActiveProfiles();
+ }
+
/**
* Returns all active profiles for the current project build.
* <p>
@@ -403,8 +615,10 @@ default String getId() {
* @return a non-null, possibly empty list of active profiles for this
project
* @see Profile
* @see #getEffectiveActiveProfiles()
+ * @deprecated Use {@link #declaredActiveProfiles()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
List<Profile> getDeclaredActiveProfiles();
/**
diff --git
a/api/maven-api-core/src/main/java/org/apache/maven/api/RemoteRepository.java
b/api/maven-api-core/src/main/java/org/apache/maven/api/RemoteRepository.java
index a2fea88a19..7fb286ecfc 100644
---
a/api/maven-api-core/src/main/java/org/apache/maven/api/RemoteRepository.java
+++
b/api/maven-api-core/src/main/java/org/apache/maven/api/RemoteRepository.java
@@ -56,9 +56,35 @@
@Immutable
public interface RemoteRepository extends Repository {
+ /**
+ * {@return the url}
+ *
+ * @since 4.0.0
+ */
@Nonnull
+ default String url() {
+ return getUrl();
+ }
+
+ /**
+ * @deprecated Use {@link #url()} instead.
+ */
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getUrl();
+ /**
+ * {@return the protocol}
+ *
+ * @since 4.0.0
+ */
@Nonnull
+ default String protocol() {
+ return getProtocol();
+ }
+
+ /**
+ * @deprecated Use {@link #protocol()} instead.
+ */
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getProtocol();
}
diff --git
a/api/maven-api-core/src/main/java/org/apache/maven/api/Repository.java
b/api/maven-api-core/src/main/java/org/apache/maven/api/Repository.java
index 82c5a1b1c4..7f29b8fae7 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/Repository.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Repository.java
@@ -58,19 +58,43 @@ public interface Repository {
*/
String CENTRAL_ID = "central";
+ /**
+ * {@return the id}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default String id() {
+ return getId();
+ }
+
/**
* Gets the identifier of this repository.
*
* @return the (case-sensitive) identifier, never {@code null}
+ * @deprecated Use {@link #id()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getId();
+ /**
+ * {@return the type}
+ *
+ * @since 4.0.0
+ */
+ @Nonnull
+ default String type() {
+ return getType();
+ }
+
/**
* Gets the type of the repository, for example "default".
*
* @return the (case-sensitive) type of the repository, never {@code null}
+ * @deprecated Use {@link #type()} instead.
*/
@Nonnull
+ @Deprecated(since = "4.0.0", forRemoval = true)
String getType();
}
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/Session.java
b/api/maven-api-core/src/main/java/org/apache/maven/api/Session.java
index 20fdbcfb04..7623a33d98 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/Session.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Session.java
@@ -128,7 +128,19 @@ default Map<String, String> getEffectiveProperties() {
* Returns the degree of concurrency for the build.
*
* @return the degree of concurrency
+ * @since 4.0.0
*/
+ default int degreeOfConcurrency() {
+ return getDegreeOfConcurrency();
+ }
+
+ /**
+ * Returns the degree of concurrency for the build.
+ *
+ * @return the degree of concurrency
+ * @deprecated Use {@link #degreeOfConcurrency()} instead.
+ */
+ @Deprecated(since = "4.0.0", forRemoval = true)
int getDegreeOfConcurrency();
/**
diff --git
a/api/maven-api-core/src/main/java/org/apache/maven/api/VersionConstraint.java
b/api/maven-api-core/src/main/java/org/apache/maven/api/VersionConstraint.java
index 5d5ac0fc4f..5a8b1760b3 100644
---
a/api/maven-api-core/src/main/java/org/apache/maven/api/VersionConstraint.java
+++
b/api/maven-api-core/src/main/java/org/apache/maven/api/VersionConstraint.java
@@ -37,20 +37,50 @@
*/
@Experimental
public interface VersionConstraint {
+ /**
+ * Returns the range of this constraint, or {@code null} if the constraint
is a recommended version.
+ * <p>
+ * Note: exactly one of {@link #versionRange()} or {@link
#recommendedVersion()} is non-{@code null}.
+ *
+ * @return the version range, or {@code null}
+ * @since 4.0.0
+ */
+ @Nullable
+ default VersionRange versionRange() {
+ return getVersionRange();
+ }
+
/**
* Returns the range of this constraint, or {@code null} if none.
* <p>
* Note: only one, this method or {@link #getRecommendedVersion()} method
must return non-{@code null} value.
+ * @deprecated Use {@link #versionRange()} instead.
*/
@Nullable
+ @Deprecated(since = "4.0.0", forRemoval = true)
VersionRange getVersionRange();
+ /**
+ * Returns the recommended version of this constraint, or {@code null} if
the constraint is a range.
+ * <p>
+ * Note: exactly one of {@link #versionRange()} or {@link
#recommendedVersion()} is non-{@code null}.
+ *
+ * @return the recommended version, or {@code null}
+ * @since 4.0.0
+ */
+ @Nullable
+ default Version recommendedVersion() {
+ return getRecommendedVersion();
+ }
+
/**
* Returns the recommended version of this constraint, or {@code null} if
none.
* <p>
* Note: only one, this method or {@link #getVersionRange()} method must
return non-{@code null} value.
+ * @deprecated Use {@link #recommendedVersion()} instead.
*/
@Nullable
+ @Deprecated(since = "4.0.0", forRemoval = true)
Version getRecommendedVersion();
/**
diff --git
a/api/maven-api-core/src/main/java/org/apache/maven/api/VersionRange.java
b/api/maven-api-core/src/main/java/org/apache/maven/api/VersionRange.java
index 224b5d6f75..7a7d508474 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/VersionRange.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/VersionRange.java
@@ -44,16 +44,42 @@ public interface VersionRange {
*/
boolean contains(@Nonnull Version version);
+ /**
+ * Returns the upper boundary of this range, or {@code null} for an
unbounded range (e.g. {@code [1.0,)}).
+ *
+ * @return the upper boundary, or {@code null}
+ * @since 4.0.0
+ */
+ @Nullable
+ default Boundary upperBoundary() {
+ return getUpperBoundary();
+ }
+
/**
* Returns the upper boundary of this range, or {@code null} if none.
+ * @deprecated Use {@link #upperBoundary()} instead.
*/
@Nullable
+ @Deprecated(since = "4.0.0", forRemoval = true)
Boundary getUpperBoundary();
+ /**
+ * Returns the lower boundary of this range, or {@code null} for an
unbounded range (e.g. {@code (,2.0]}).
+ *
+ * @return the lower boundary, or {@code null}
+ * @since 4.0.0
+ */
+ @Nullable
+ default Boundary lowerBoundary() {
+ return getLowerBoundary();
+ }
+
/**
* Returns the lower boundary of this range, or {@code null} if none.
+ * @deprecated Use {@link #lowerBoundary()} instead.
*/
@Nullable
+ @Deprecated(since = "4.0.0", forRemoval = true)
Boundary getLowerBoundary();
/**
@@ -69,12 +95,38 @@ public interface VersionRange {
interface Boundary {
/**
* The bounding version.
+ *
+ * @return the bounding version
+ * @since 4.0.0
+ */
+ default Version version() {
+ return getVersion();
+ }
+
+ /**
+ * The bounding version.
+ *
+ * @deprecated Use {@link #version()} instead.
*/
+ @Deprecated(since = "4.0.0", forRemoval = true)
Version getVersion();
/**
* Returns {@code true} if version is included of the range.
+ *
+ * @return {@code true} if inclusive
+ * @since 4.0.0
+ */
+ default boolean inclusive() {
+ return isInclusive();
+ }
+
+ /**
+ * Returns {@code true} if version is included of the range.
+ *
+ * @deprecated Use {@link #inclusive()} instead.
*/
+ @Deprecated(since = "4.0.0", forRemoval = true)
boolean isInclusive();
}
}
diff --git
a/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/Log.java
b/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/Log.java
index a50d86c48b..19bfa603dc 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/Log.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/Log.java
@@ -32,7 +32,11 @@
* rather than formatting first by calling <code>toString()</code>.
*
* @since 4.0.0
+ * @deprecated Use {@link org.apache.maven.api.logging.Logger} instead, which
provides a richer API
+ * including structured key-value pairs, lazy message evaluation,
and a fluent builder.
+ * Inject {@code org.apache.maven.api.logging.Logger} in your Mojo
instead of {@code Log}.
*/
+@Deprecated(since = "4.0.0", forRemoval = true)
@Experimental
@Provider
public interface Log {
diff --git
a/api/maven-api-di/src/main/java/org/apache/maven/api/di/MojoExecutionScoped.java
b/api/maven-api-di/src/main/java/org/apache/maven/api/di/MojoExecutionScoped.java
index 729ec5e107..141936b656 100644
---
a/api/maven-api-di/src/main/java/org/apache/maven/api/di/MojoExecutionScoped.java
+++
b/api/maven-api-di/src/main/java/org/apache/maven/api/di/MojoExecutionScoped.java
@@ -34,7 +34,7 @@
* <ul>
* <li>{@code org.apache.maven.api.MojoExecution}</li>
* <li>{@code org.apache.maven.api.Project}</li>
- * <li>{@code org.apache.maven.api.plugin.Log}</li>
+ * <li>{@code org.apache.maven.api.logging.Logger}</li>
* </ul>
*
* @since 4.0.0
diff --git a/api/maven-api-core/pom.xml b/api/maven-api-log/pom.xml
similarity index 60%
copy from api/maven-api-core/pom.xml
copy to api/maven-api-log/pom.xml
index 104d6375b7..14001aab9c 100644
--- a/api/maven-api-core/pom.xml
+++ b/api/maven-api-log/pom.xml
@@ -26,50 +26,23 @@
<version>4.0.0-SNAPSHOT</version>
</parent>
- <artifactId>maven-api-core</artifactId>
- <name>Maven 4 API :: Core</name>
- <description>Maven 4 API - Maven Core API</description>
+ <artifactId>maven-api-log</artifactId>
+ <name>Maven 4 API :: Logging</name>
+ <description>Maven 4 API - Unified Logging API (Logger, LogEventBuilder,
LogLevel).</description>
+
+ <properties>
+ <javaModuleName>org.apache.maven.api.logging</javaModuleName>
+ </properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-annotations</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-api-di</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-api-model</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-api-settings</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-api-toolchain</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-api-plugin</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-api-xml</artifactId>
- </dependency>
-
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
-
</project>
diff --git
a/api/maven-api-log/src/main/java/org/apache/maven/api/logging/LogEventBuilder.java
b/api/maven-api-log/src/main/java/org/apache/maven/api/logging/LogEventBuilder.java
new file mode 100644
index 0000000000..5a61e7a2ad
--- /dev/null
+++
b/api/maven-api-log/src/main/java/org/apache/maven/api/logging/LogEventBuilder.java
@@ -0,0 +1,191 @@
+/*
+ * 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.api.logging;
+
+import org.apache.maven.api.annotations.Experimental;
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.annotations.Nullable;
+
+/**
+ * Fluent builder for a single log statement.
+ * <p>
+ * Instances are obtained from {@link Logger#atTrace()}, {@link
Logger#atDebug()}, etc.
+ * A builder <em>must</em> be consumed in a single chained call; it must not be
+ * stored in a variable across statements, as implementations may reuse
+ * thread-local state for zero-allocation dispatch.
+ * <p>
+ * When the target level is disabled the {@code Logger} returns a shared
+ * {@code NopLogEventBuilder} singleton, making the entire fluent call chain a
no-op
+ * with zero allocations.
+ *
+ * <pre>{@code
+ * log.atInfo()
+ * .withKeyValue("module", module.getId())
+ * .log("Compiling {} source files", count);
+ * }</pre>
+ *
+ * <h2>Message format</h2>
+ * <p>
+ * The {@code log(String format, Object...)} family of methods uses a simple
+ * positional placeholder syntax: each occurrence of {@code {}} in the format
+ * string is replaced, in order, by the string representation of the
corresponding
+ * argument. No index, type specifier, or locale conversion is supported —
this is
+ * intentionally simpler than {@link java.text.MessageFormat} and avoids the
+ * injection risk of {@code printf}-style specifiers.
+ * <p>
+ * Example: {@code log("Building {} module(s) in {}", count, dir)} produces
+ * {@code "Building 3 module(s) in /tmp/build"} when {@code count=3} and
+ * {@code dir="/tmp/build"}.
+ * <p>
+ * This convention is the same as the one used by SLF4J
+ * (<a
href="https://www.slf4j.org/api/org/slf4j/helpers/MessageFormatter.html">MessageFormatter</a>),
+ * which is widely used in the Java ecosystem and is already the format
employed
+ * by {@code plugin.Log}, the API this interface replaces.
+ *
+ * @since 4.0.0
+ */
+@Experimental
+public interface LogEventBuilder {
+
+ /**
+ * Attaches a structured key-value pair to this log event.
+ * <p>
+ * Structured key-value pairs are consumed by structured log appenders
+ * (e.g. JSON, ECS, or Logstash layouts in Logback or Log4j 2) that capture
+ * fields alongside the message text — rather than embedding metadata
inside the
+ * message string itself. This enables log aggregators such as
Elasticsearch or
+ * Splunk to filter and correlate events by field values directly.
+ * <p>
+ * In a Maven context, typical uses include attaching build metadata such
as
+ * project coordinates, mojo identifiers, and elapsed time as first-class
indexed
+ * fields. When running with a plain-text appender these pairs are
silently ignored
+ * or appended after the message, depending on the appender configuration.
+ *
+ * @param key the field name, never {@code null}
+ * @param value the string value
+ * @return this builder
+ */
+ @Nonnull
+ LogEventBuilder withKeyValue(@Nonnull String key, String value);
+
+ /**
+ * Attaches a structured key-value pair with a {@code long} value.
+ * <p>
+ * See {@link #withKeyValue(String, String)} for the purpose of structured
key-value pairs.
+ *
+ * @param key the field name, never {@code null}
+ * @param value the numeric value
+ * @return this builder
+ */
+ @Nonnull
+ LogEventBuilder withKeyValue(@Nonnull String key, long value);
+
+ /**
+ * Attaches a structured key-value pair with a {@code boolean} value.
+ * <p>
+ * See {@link #withKeyValue(String, String)} for the purpose of structured
key-value pairs.
+ *
+ * @param key the field name, never {@code null}
+ * @param value the boolean value
+ * @return this builder
+ */
+ @Nonnull
+ LogEventBuilder withKeyValue(@Nonnull String key, boolean value);
+
+ /**
+ * Attaches a {@link Throwable} to this log event.
+ *
+ * @param t the throwable, may be {@code null} (no-op)
+ * @return this builder
+ */
+ @Nonnull
+ LogEventBuilder withThrowable(@Nullable Throwable t);
+
+ /**
+ * Overrides the project identifier for this event.
+ * <p>
+ * <strong>Note:</strong> enrichment via this method is best-effort and
+ * implementation-defined. Implementations that do not support per-event
+ * project context may silently ignore the supplied value.
+ *
+ * @param projectId the project id, or {@code null} to clear
+ * @return this builder
+ */
+ @Nonnull
+ LogEventBuilder withProjectId(@Nullable String projectId);
+
+ /**
+ * Overrides the mojo execution identifier for this event.
+ * <p>
+ * <strong>Note:</strong> enrichment via this method is best-effort and
+ * implementation-defined. Implementations that do not support per-event
+ * mojo context may silently ignore the supplied value.
+ *
+ * @param mojoId the mojo id, or {@code null} to clear
+ * @return this builder
+ */
+ @Nonnull
+ LogEventBuilder withMojoId(@Nullable String mojoId);
+
+ /**
+ * Emits the log event with the given pre-formatted message.
+ *
+ * @param message the message, never {@code null}
+ */
+ void log(@Nonnull String message);
+
+ /**
+ * Emits the log event with a SLF4J-style {@code {}} template and a single
argument.
+ * <p>
+ * Fast path that avoids varargs array allocation.
+ *
+ * @param format the message template
+ * @param arg the single argument
+ */
+ void log(@Nonnull String format, Object arg);
+
+ /**
+ * Emits the log event with a SLF4J-style {@code {}} template and two
arguments.
+ * <p>
+ * Fast path that avoids varargs array allocation.
+ *
+ * @param format the message template
+ * @param arg1 the first argument
+ * @param arg2 the second argument
+ */
+ void log(@Nonnull String format, Object arg1, Object arg2);
+
+ /**
+ * Emits the log event with a SLF4J-style {@code {}} template and any
number of arguments.
+ *
+ * @param format the message template
+ * @param args the arguments
+ */
+ void log(@Nonnull String format, Object... args);
+
+ /**
+ * Emits the log event with a lazily-evaluated message supplier.
+ * <p>
+ * The supplier is only invoked when the level is enabled. When this
builder
+ * is a NOP instance the supplier is never called.
+ *
+ * @param messageSupplier a supplier of the log message, never {@code null}
+ */
+ void log(@Nonnull java.util.function.Supplier<String> messageSupplier);
+}
diff --git
a/api/maven-api-core/src/main/java/org/apache/maven/api/DownloadedArtifact.java
b/api/maven-api-log/src/main/java/org/apache/maven/api/logging/LogLevel.java
similarity index 66%
copy from
api/maven-api-core/src/main/java/org/apache/maven/api/DownloadedArtifact.java
copy to
api/maven-api-log/src/main/java/org/apache/maven/api/logging/LogLevel.java
index 10e9deb898..5aa5865be9 100644
---
a/api/maven-api-core/src/main/java/org/apache/maven/api/DownloadedArtifact.java
+++ b/api/maven-api-log/src/main/java/org/apache/maven/api/logging/LogLevel.java
@@ -16,24 +16,27 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.api;
-
-import java.nio.file.Path;
+package org.apache.maven.api.logging;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
/**
- * An {@link Artifact} that has been resolved, i.e. downloaded to the local
repository.
+ * Log severity levels.
*
* @since 4.0.0
*/
@Experimental
@Immutable
-public interface DownloadedArtifact extends Artifact {
-
- /**
- * {@return the actual file that has been downloaded in the file system}
- */
- Path getPath();
+public enum LogLevel {
+ /** Finest-grained diagnostic events; only useful during deep debugging. */
+ TRACE,
+ /** Diagnostic events useful during development and troubleshooting. */
+ DEBUG,
+ /** Informational messages about normal operation. */
+ INFO,
+ /** Potentially harmful situations that should be investigated. */
+ WARN,
+ /** Error events that may still allow the build to continue. */
+ ERROR
}
diff --git
a/api/maven-api-log/src/main/java/org/apache/maven/api/logging/Logger.java
b/api/maven-api-log/src/main/java/org/apache/maven/api/logging/Logger.java
new file mode 100644
index 0000000000..54e8226998
--- /dev/null
+++ b/api/maven-api-log/src/main/java/org/apache/maven/api/logging/Logger.java
@@ -0,0 +1,348 @@
+/*
+ * 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.api.logging;
+
+import java.util.function.Supplier;
+
+import org.apache.maven.api.annotations.Experimental;
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.annotations.Nullable;
+import org.apache.maven.api.annotations.Provider;
+
+/**
+ * Unified logging interface for Maven plugins and CLI bootstrap code.
+ * <p>
+ * Unified interface that supports a fluent builder API, structured key-value
+ * pairs, and lazy message evaluation. Used by both mojo logging and CLI
+ * bootstrap logging.
+ * <p>
+ * Instances are obtained via dependency injection. A {@code @Singleton} bean
+ * may hold a long-lived {@code Logger} instance safely.
+ *
+ * <h2>Fluent API (preferred)</h2>
+ * <pre>{@code
+ * log.atInfo()
+ * .withKeyValue("artifact", artifact.getId())
+ * .log("Resolved {} files", count);
+ * }</pre>
+ *
+ * <h2>Legacy convenience methods</h2>
+ * <pre>{@code
+ * log.info("Compiling {} source files", count);
+ * log.warn("Deprecated configuration key: {}", key, e);
+ * }</pre>
+ *
+ * @since 4.0.0
+ */
+@Experimental
+@Provider
+public interface Logger {
+
+ /**
+ * The name of this logger, typically the fully qualified class name of
+ * the component that owns it.
+ *
+ * @return the logger name, never {@code null}
+ */
+ @Nonnull
+ String name();
+
+ /**
+ * Returns {@code true} if the given level is enabled for this logger.
+ *
+ * @param level the level to test, never {@code null}
+ * @return {@code true} if enabled
+ */
+ boolean isEnabled(@Nonnull LogLevel level);
+
+ /** @return {@code true} if {@link LogLevel#TRACE} is enabled */
+ default boolean isTraceEnabled() {
+ return isEnabled(LogLevel.TRACE);
+ }
+
+ /** @return {@code true} if {@link LogLevel#DEBUG} is enabled */
+ default boolean isDebugEnabled() {
+ return isEnabled(LogLevel.DEBUG);
+ }
+
+ /** @return {@code true} if {@link LogLevel#INFO} is enabled */
+ default boolean isInfoEnabled() {
+ return isEnabled(LogLevel.INFO);
+ }
+
+ /** @return {@code true} if {@link LogLevel#WARN} is enabled */
+ default boolean isWarnEnabled() {
+ return isEnabled(LogLevel.WARN);
+ }
+
+ /** @return {@code true} if {@link LogLevel#ERROR} is enabled */
+ default boolean isErrorEnabled() {
+ return isEnabled(LogLevel.ERROR);
+ }
+
+ // ---- Fluent entry points ----
+
+ /**
+ * Returns a {@link LogEventBuilder} for {@link LogLevel#TRACE}.
+ * <p>
+ * When TRACE is disabled, returns a singleton no-op builder (zero
allocations).
+ *
+ * @return a log builder, never {@code null}
+ */
+ @Nonnull
+ LogEventBuilder atTrace();
+
+ /**
+ * Returns a {@link LogEventBuilder} for {@link LogLevel#DEBUG}.
+ *
+ * @return a log builder, never {@code null}
+ */
+ @Nonnull
+ LogEventBuilder atDebug();
+
+ /**
+ * Returns a {@link LogEventBuilder} for {@link LogLevel#INFO}.
+ *
+ * @return a log builder, never {@code null}
+ */
+ @Nonnull
+ LogEventBuilder atInfo();
+
+ /**
+ * Returns a {@link LogEventBuilder} for {@link LogLevel#WARN}.
+ *
+ * @return a log builder, never {@code null}
+ */
+ @Nonnull
+ LogEventBuilder atWarn();
+
+ /**
+ * Returns a {@link LogEventBuilder} for {@link LogLevel#ERROR}.
+ *
+ * @return a log builder, never {@code null}
+ */
+ @Nonnull
+ LogEventBuilder atError();
+
+ /**
+ * Returns a {@link LogEventBuilder} for the given level.
+ *
+ * @param level the target level, never {@code null}
+ * @return a log builder, never {@code null}
+ */
+ @Nonnull
+ LogEventBuilder at(@Nonnull LogLevel level);
+
+ // ---- Legacy convenience: trace ----
+
+ /** Logs a TRACE message. */
+ default void trace(@Nonnull String message) {
+ atTrace().log(message);
+ }
+
+ /** Logs a TRACE message with one {@code {}} argument. */
+ default void trace(@Nonnull String format, @Nullable Object arg) {
+ atTrace().log(format, arg);
+ }
+
+ /** Logs a TRACE message with two {@code {}} arguments. */
+ default void trace(@Nonnull String format, @Nullable Object arg1,
@Nullable Object arg2) {
+ atTrace().log(format, arg1, arg2);
+ }
+
+ /** Logs a TRACE message with varargs arguments. */
+ default void trace(@Nonnull String format, Object... args) {
+ atTrace().log(format, args);
+ }
+
+ /** Logs a TRACE message with a throwable. */
+ default void trace(@Nonnull String message, @Nullable Throwable t) {
+ atTrace().withThrowable(t).log(message);
+ }
+
+ /** Logs a lazily-evaluated TRACE message. */
+ default void trace(@Nonnull Supplier<String> message) {
+ atTrace().log(message);
+ }
+
+ /** Logs a lazily-evaluated TRACE message with a throwable. */
+ default void trace(@Nonnull Supplier<String> message, @Nullable Throwable
t) {
+ atTrace().withThrowable(t).log(message);
+ }
+
+ // ---- Legacy convenience: debug ----
+
+ /** Logs a DEBUG message. */
+ default void debug(@Nonnull String message) {
+ atDebug().log(message);
+ }
+
+ /** Logs a DEBUG message with one {@code {}} argument. */
+ default void debug(@Nonnull String format, @Nullable Object arg) {
+ atDebug().log(format, arg);
+ }
+
+ /** Logs a DEBUG message with two {@code {}} arguments. */
+ default void debug(@Nonnull String format, @Nullable Object arg1,
@Nullable Object arg2) {
+ atDebug().log(format, arg1, arg2);
+ }
+
+ /** Logs a DEBUG message with varargs arguments. */
+ default void debug(@Nonnull String format, Object... args) {
+ atDebug().log(format, args);
+ }
+
+ /** Logs a DEBUG message with a throwable. */
+ default void debug(@Nonnull String message, @Nullable Throwable t) {
+ atDebug().withThrowable(t).log(message);
+ }
+
+ /** Logs a lazily-evaluated DEBUG message. */
+ default void debug(@Nonnull Supplier<String> message) {
+ atDebug().log(message);
+ }
+
+ /** Logs a lazily-evaluated DEBUG message with a throwable. */
+ default void debug(@Nonnull Supplier<String> message, @Nullable Throwable
t) {
+ atDebug().withThrowable(t).log(message);
+ }
+
+ // ---- Legacy convenience: info ----
+
+ /** Logs an INFO message. */
+ default void info(@Nonnull String message) {
+ atInfo().log(message);
+ }
+
+ /** Logs an INFO message with one {@code {}} argument. */
+ default void info(@Nonnull String format, @Nullable Object arg) {
+ atInfo().log(format, arg);
+ }
+
+ /** Logs an INFO message with two {@code {}} arguments. */
+ default void info(@Nonnull String format, @Nullable Object arg1, @Nullable
Object arg2) {
+ atInfo().log(format, arg1, arg2);
+ }
+
+ /** Logs an INFO message with varargs arguments. */
+ default void info(@Nonnull String format, Object... args) {
+ atInfo().log(format, args);
+ }
+
+ /** Logs an INFO message with a throwable. */
+ default void info(@Nonnull String message, @Nullable Throwable t) {
+ atInfo().withThrowable(t).log(message);
+ }
+
+ /** Logs a lazily-evaluated INFO message. */
+ default void info(@Nonnull Supplier<String> message) {
+ atInfo().log(message);
+ }
+
+ /** Logs a lazily-evaluated INFO message with a throwable. */
+ default void info(@Nonnull Supplier<String> message, @Nullable Throwable
t) {
+ atInfo().withThrowable(t).log(message);
+ }
+
+ // ---- Legacy convenience: warn ----
+
+ /** Logs a WARN message. */
+ default void warn(@Nonnull String message) {
+ atWarn().log(message);
+ }
+
+ /** Logs a WARN message with one {@code {}} argument. */
+ default void warn(@Nonnull String format, @Nullable Object arg) {
+ atWarn().log(format, arg);
+ }
+
+ /** Logs a WARN message with two {@code {}} arguments. */
+ default void warn(@Nonnull String format, @Nullable Object arg1, @Nullable
Object arg2) {
+ atWarn().log(format, arg1, arg2);
+ }
+
+ /** Logs a WARN message with varargs arguments. */
+ default void warn(@Nonnull String format, Object... args) {
+ atWarn().log(format, args);
+ }
+
+ /** Logs a WARN message with a throwable. */
+ default void warn(@Nonnull String message, @Nullable Throwable t) {
+ atWarn().withThrowable(t).log(message);
+ }
+
+ /** Logs a lazily-evaluated WARN message. */
+ default void warn(@Nonnull Supplier<String> message) {
+ atWarn().log(message);
+ }
+
+ /** Logs a lazily-evaluated WARN message with a throwable. */
+ default void warn(@Nonnull Supplier<String> message, @Nullable Throwable
t) {
+ atWarn().withThrowable(t).log(message);
+ }
+
+ // ---- Legacy convenience: error ----
+
+ /** Logs an ERROR message. */
+ default void error(@Nonnull String message) {
+ atError().log(message);
+ }
+
+ /** Logs an ERROR message with one {@code {}} argument. */
+ default void error(@Nonnull String format, @Nullable Object arg) {
+ atError().log(format, arg);
+ }
+
+ /** Logs an ERROR message with two {@code {}} arguments. */
+ default void error(@Nonnull String format, @Nullable Object arg1,
@Nullable Object arg2) {
+ atError().log(format, arg1, arg2);
+ }
+
+ /** Logs an ERROR message with varargs arguments. */
+ default void error(@Nonnull String format, Object... args) {
+ atError().log(format, args);
+ }
+
+ /** Logs an ERROR message with a throwable. */
+ default void error(@Nonnull String message, @Nullable Throwable t) {
+ atError().withThrowable(t).log(message);
+ }
+
+ /** Logs a lazily-evaluated ERROR message. */
+ default void error(@Nonnull Supplier<String> message) {
+ atError().log(message);
+ }
+
+ /** Logs a lazily-evaluated ERROR message with a throwable. */
+ default void error(@Nonnull Supplier<String> message, @Nullable Throwable
t) {
+ atError().withThrowable(t).log(message);
+ }
+
+ // ---- Child logger ----
+
+ /**
+ * Returns a child logger whose name is this logger's name with
+ * {@code "." + name} appended.
+ *
+ * @param name the child suffix, never {@code null}
+ * @return a child {@code Logger} instance, never {@code null}
+ */
+ @Nonnull
+ Logger child(@Nonnull String name);
+}
diff --git
a/api/maven-api-log/src/main/java/org/apache/maven/api/logging/package-info.java
b/api/maven-api-log/src/main/java/org/apache/maven/api/logging/package-info.java
new file mode 100644
index 0000000000..84b6c0743d
--- /dev/null
+++
b/api/maven-api-log/src/main/java/org/apache/maven/api/logging/package-info.java
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+/**
+ * Maven unified logging API — a first-class, SLF4J-free logging facade for
+ * plugins and extensions.
+ *
+ * <h2>Core types</h2>
+ * <dl>
+ * <dt>{@link org.apache.maven.api.logging.Logger}</dt>
+ * <dd>The primary logging interface injected by the container. Supports a
fluent builder
+ * API ({@code atInfo()...log(...)}) as well as SLF4J-style convenience
methods
+ * ({@code info(...)}, {@code warn(...)}, etc.).</dd>
+ *
+ * <dt>{@link org.apache.maven.api.logging.LogEventBuilder}</dt>
+ * <dd>Fluent builder for a single log event, obtained from {@code
Logger.at(LogLevel)}.
+ * When the target level is disabled, returns a no-op singleton (zero
allocations).</dd>
+ *
+ * <dt>{@link org.apache.maven.api.logging.LogLevel}</dt>
+ * <dd>Ordered severity enumeration: {@code TRACE}, {@code DEBUG}, {@code
INFO},
+ * {@code WARN}, {@code ERROR}.</dd>
+ * </dl>
+ *
+ * @since 4.0.0
+ */
+package org.apache.maven.api.logging;
diff --git
a/api/maven-api-spi/src/main/java/org/apache/maven/api/services/model/ModelProcessor.java
b/api/maven-api-spi/src/main/java/org/apache/maven/api/services/model/ModelProcessor.java
index 091e8f45fd..0baeabbf71 100644
---
a/api/maven-api-spi/src/main/java/org/apache/maven/api/services/model/ModelProcessor.java
+++
b/api/maven-api-spi/src/main/java/org/apache/maven/api/services/model/ModelProcessor.java
@@ -20,12 +20,15 @@
import java.io.IOException;
import java.nio.file.Path;
+import java.util.Map;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable;
import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.Source;
import org.apache.maven.api.services.xml.XmlReaderException;
import org.apache.maven.api.services.xml.XmlReaderRequest;
+import org.apache.maven.api.spi.ModelParserException;
/**
* Locates and reads POM files from the filesystem.
@@ -41,6 +44,36 @@ public interface ModelProcessor {
@Nullable
Path locateExistingPom(@Nonnull Path project);
+ /**
+ * Reads the model from the specified source.
+ *
+ * <p>The default implementation bridges to {@link
#read(XmlReaderRequest)} for backward
+ * compatibility with existing implementations. Implementors are
encouraged to override
+ * this method directly; the deprecated {@link #read(XmlReaderRequest)}
overload will
+ * be removed in a future major version.
+ *
+ * @param source the source to read the model from, must not be {@code
null}
+ * @param options optional reading options, may be {@code null}
+ * @return the deserialized model, never {@code null}
+ * @throws ModelParserException if the model could not be deserialized
+ * @since 4.0.0
+ */
+ @Nonnull
+ default Model read(@Nonnull Source source, @Nullable Map<String, ?>
options) throws ModelParserException {
+ Object strictValue = options != null ?
options.get(org.apache.maven.api.spi.ModelParser.STRICT) : null;
+ boolean strict = strictValue == null ||
Boolean.parseBoolean(strictValue.toString());
+ try {
+ XmlReaderRequest request = XmlReaderRequest.builder()
+ .path(source.getPath())
+ .inputStream(source.getPath() == null ?
source.openStream() : null)
+ .strict(strict)
+ .build();
+ return read(request);
+ } catch (XmlReaderException | IOException e) {
+ throw new ModelParserException(e.getMessage(), e);
+ }
+ }
+
/**
* Reads the model from the specified byte stream. The stream will be
automatically closed before the method
* returns.
@@ -49,6 +82,8 @@ public interface ModelProcessor {
* @return The deserialized model, never {@code null}.
* @throws IOException If the model could not be deserialized.
* @throws XmlReaderException If the input format could not be parsed.
+ * @deprecated Use {@link #read(Source, Map)} instead.
*/
+ @Deprecated(since = "4.0.0", forRemoval = true)
Model read(XmlReaderRequest request) throws IOException,
XmlReaderException;
}
diff --git a/api/pom.xml b/api/pom.xml
index ba5c47f3a1..049d4bb976 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -40,6 +40,7 @@
<module>maven-api-settings</module>
<module>maven-api-toolchain</module>
<module>maven-api-metadata</module>
+ <module>maven-api-log</module>
<module>maven-api-core</module>
<module>maven-api-spi</module>
<module>maven-api-cli</module>
diff --git
a/impl/maven-core/src/main/java/org/apache/maven/execution/scope/internal/MojoExecutionScopeModule.java
b/impl/maven-core/src/main/java/org/apache/maven/execution/scope/internal/MojoExecutionScopeModule.java
index a477ec868c..e2aaaa8f79 100644
---
a/impl/maven-core/src/main/java/org/apache/maven/execution/scope/internal/MojoExecutionScopeModule.java
+++
b/impl/maven-core/src/main/java/org/apache/maven/execution/scope/internal/MojoExecutionScopeModule.java
@@ -19,6 +19,7 @@
package org.apache.maven.execution.scope.internal;
import com.google.inject.AbstractModule;
+import org.apache.maven.api.logging.Logger;
import org.apache.maven.api.plugin.Log;
import org.apache.maven.execution.scope.MojoExecutionScoped;
import org.apache.maven.plugin.MojoExecution;
@@ -45,6 +46,10 @@ protected void configure() {
bind(MojoExecution.class)
.toProvider(MojoExecutionScope.seededKeyProvider(MojoExecution.class))
.in(scope);
+ bind(Logger.class)
+ .toProvider(MojoExecutionScope.seededKeyProvider(Logger.class))
+ .in(scope);
+ //noinspection deprecation
bind(Log.class)
.toProvider(MojoExecutionScope.seededKeyProvider(Log.class))
.in(scope);
diff --git
a/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLog.java
b/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLog.java
index b1cf40cc40..0a73c49e7a 100644
---
a/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLog.java
+++
b/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLog.java
@@ -26,6 +26,7 @@
import static java.util.Objects.requireNonNull;
+@Deprecated(since = "4.0.0", forRemoval = true)
public class DefaultLog implements Log {
private final Logger logger;
diff --git
a/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLogger.java
b/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLogger.java
new file mode 100644
index 0000000000..3796ffca63
--- /dev/null
+++
b/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLogger.java
@@ -0,0 +1,355 @@
+/*
+ * 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.internal.impl;
+
+import java.util.function.Supplier;
+
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.annotations.Nullable;
+import org.apache.maven.api.logging.LogEventBuilder;
+import org.apache.maven.api.logging.LogLevel;
+import org.apache.maven.api.logging.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.spi.LoggingEventBuilder;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Default {@link Logger} implementation backed by an SLF4J {@link
org.slf4j.Logger}.
+ */
+public class DefaultLogger implements Logger {
+ private static final LogEventBuilder NOP_BUILDER = new
NopLogEventBuilder();
+
+ private final org.slf4j.Logger logger;
+
+ public DefaultLogger(org.slf4j.Logger logger) {
+ this.logger = requireNonNull(logger, "logger cannot be null");
+ }
+
+ @Override
+ @Nonnull
+ public String name() {
+ return logger.getName();
+ }
+
+ @Override
+ public boolean isEnabled(@Nonnull LogLevel level) {
+ requireNonNull(level, "level cannot be null");
+ return switch (level) {
+ case TRACE -> logger.isTraceEnabled();
+ case DEBUG -> logger.isDebugEnabled();
+ case INFO -> logger.isInfoEnabled();
+ case WARN -> logger.isWarnEnabled();
+ case ERROR -> logger.isErrorEnabled();
+ };
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder atTrace() {
+ return at(LogLevel.TRACE);
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder atDebug() {
+ return at(LogLevel.DEBUG);
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder atInfo() {
+ return at(LogLevel.INFO);
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder atWarn() {
+ return at(LogLevel.WARN);
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder atError() {
+ return at(LogLevel.ERROR);
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder at(@Nonnull LogLevel level) {
+ if (!isEnabled(level)) {
+ return NOP_BUILDER;
+ }
+ return new DefaultLogEventBuilder(logger, level);
+ }
+
+ @Override
+ @Nonnull
+ public Logger child(@Nonnull String name) {
+ requireNonNull(name, "name cannot be null");
+ if (name.isEmpty()) {
+ throw new IllegalArgumentException("child logger name cannot be
empty");
+ }
+ String parentName = logger.getName();
+ String childName = parentName.isEmpty() ? name : parentName + "." +
name;
+ return new DefaultLogger(LoggerFactory.getLogger(childName));
+ }
+
+ private static final class NopLogEventBuilder implements LogEventBuilder {
+ @Override
+ @Nonnull
+ public LogEventBuilder withKeyValue(@Nonnull String key, String value)
{
+ return this;
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder withKeyValue(@Nonnull String key, long value) {
+ return this;
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder withKeyValue(@Nonnull String key, boolean
value) {
+ return this;
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder withThrowable(Throwable t) {
+ return this;
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder withProjectId(@Nullable String projectId) {
+ return this;
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder withMojoId(@Nullable String mojoId) {
+ return this;
+ }
+
+ @Override
+ public void log(@Nonnull String message) {}
+
+ @Override
+ public void log(@Nonnull String format, Object arg) {}
+
+ @Override
+ public void log(@Nonnull String format, Object arg1, Object arg2) {}
+
+ @Override
+ public void log(@Nonnull String format, Object... args) {}
+
+ @Override
+ public void log(@Nonnull Supplier<String> messageSupplier) {}
+ }
+
+ private static final class DefaultLogEventBuilder implements
LogEventBuilder {
+ private final org.slf4j.Logger logger;
+ private final LogLevel level;
+ private Throwable throwable;
+ private LoggingEventBuilder slf4jBuilder;
+
+ DefaultLogEventBuilder(org.slf4j.Logger logger, LogLevel level) {
+ this.logger = logger;
+ this.level = level;
+ }
+
+ private LoggingEventBuilder ensureBuilder() {
+ if (slf4jBuilder == null) {
+ slf4jBuilder = switch (level) {
+ case TRACE -> logger.atTrace();
+ case DEBUG -> logger.atDebug();
+ case INFO -> logger.atInfo();
+ case WARN -> logger.atWarn();
+ case ERROR -> logger.atError();
+ };
+ if (throwable != null) {
+ slf4jBuilder.setCause(throwable);
+ }
+ }
+ return slf4jBuilder;
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder withKeyValue(@Nonnull String key, String value)
{
+ ensureBuilder().addKeyValue(key, value);
+ return this;
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder withKeyValue(@Nonnull String key, long value) {
+ ensureBuilder().addKeyValue(key, value);
+ return this;
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder withKeyValue(@Nonnull String key, boolean
value) {
+ ensureBuilder().addKeyValue(key, value);
+ return this;
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder withThrowable(Throwable t) {
+ if (slf4jBuilder != null) {
+ slf4jBuilder.setCause(t);
+ } else {
+ this.throwable = t;
+ }
+ return this;
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder withProjectId(@Nullable String projectId) {
+ return this;
+ }
+
+ @Override
+ @Nonnull
+ public LogEventBuilder withMojoId(@Nullable String mojoId) {
+ return this;
+ }
+
+ @Override
+ public void log(@Nonnull String message) {
+ if (slf4jBuilder != null) {
+ slf4jBuilder.log(message);
+ return;
+ }
+ if (throwable != null) {
+ switch (level) {
+ case TRACE -> logger.trace(message, throwable);
+ case DEBUG -> logger.debug(message, throwable);
+ case INFO -> logger.info(message, throwable);
+ case WARN -> logger.warn(message, throwable);
+ case ERROR -> logger.error(message, throwable);
+ default -> throw new IllegalStateException("Unexpected
level: " + level);
+ }
+ } else {
+ switch (level) {
+ case TRACE -> logger.trace(message);
+ case DEBUG -> logger.debug(message);
+ case INFO -> logger.info(message);
+ case WARN -> logger.warn(message);
+ case ERROR -> logger.error(message);
+ default -> throw new IllegalStateException("Unexpected
level: " + level);
+ }
+ }
+ }
+
+ @Override
+ public void log(@Nonnull String format, Object arg) {
+ if (slf4jBuilder != null) {
+ slf4jBuilder.log(format, arg);
+ return;
+ }
+ if (throwable != null) {
+ switch (level) {
+ case TRACE -> logger.trace(format, arg, throwable);
+ case DEBUG -> logger.debug(format, arg, throwable);
+ case INFO -> logger.info(format, arg, throwable);
+ case WARN -> logger.warn(format, arg, throwable);
+ case ERROR -> logger.error(format, arg, throwable);
+ default -> throw new IllegalStateException("Unexpected
level: " + level);
+ }
+ } else {
+ switch (level) {
+ case TRACE -> logger.trace(format, arg);
+ case DEBUG -> logger.debug(format, arg);
+ case INFO -> logger.info(format, arg);
+ case WARN -> logger.warn(format, arg);
+ case ERROR -> logger.error(format, arg);
+ default -> throw new IllegalStateException("Unexpected
level: " + level);
+ }
+ }
+ }
+
+ @Override
+ public void log(@Nonnull String format, Object arg1, Object arg2) {
+ if (slf4jBuilder != null) {
+ slf4jBuilder.log(format, arg1, arg2);
+ return;
+ }
+ if (throwable != null) {
+ switch (level) {
+ case TRACE -> logger.trace(format, arg1, arg2, throwable);
+ case DEBUG -> logger.debug(format, arg1, arg2, throwable);
+ case INFO -> logger.info(format, arg1, arg2, throwable);
+ case WARN -> logger.warn(format, arg1, arg2, throwable);
+ case ERROR -> logger.error(format, arg1, arg2, throwable);
+ default -> throw new IllegalStateException("Unexpected
level: " + level);
+ }
+ } else {
+ switch (level) {
+ case TRACE -> logger.trace(format, arg1, arg2);
+ case DEBUG -> logger.debug(format, arg1, arg2);
+ case INFO -> logger.info(format, arg1, arg2);
+ case WARN -> logger.warn(format, arg1, arg2);
+ case ERROR -> logger.error(format, arg1, arg2);
+ default -> throw new IllegalStateException("Unexpected
level: " + level);
+ }
+ }
+ }
+
+ @Override
+ public void log(@Nonnull String format, Object... args) {
+ if (slf4jBuilder != null) {
+ slf4jBuilder.log(format, args);
+ return;
+ }
+ if (throwable != null) {
+ Object[] withThrowable = new Object[args.length + 1];
+ System.arraycopy(args, 0, withThrowable, 0, args.length);
+ withThrowable[args.length] = throwable;
+ switch (level) {
+ case TRACE -> logger.trace(format, withThrowable);
+ case DEBUG -> logger.debug(format, withThrowable);
+ case INFO -> logger.info(format, withThrowable);
+ case WARN -> logger.warn(format, withThrowable);
+ case ERROR -> logger.error(format, withThrowable);
+ default -> throw new IllegalStateException("Unexpected
level: " + level);
+ }
+ } else {
+ switch (level) {
+ case TRACE -> logger.trace(format, args);
+ case DEBUG -> logger.debug(format, args);
+ case INFO -> logger.info(format, args);
+ case WARN -> logger.warn(format, args);
+ case ERROR -> logger.error(format, args);
+ default -> throw new IllegalStateException("Unexpected
level: " + level);
+ }
+ }
+ }
+
+ @Override
+ public void log(@Nonnull Supplier<String> messageSupplier) {
+ requireNonNull(messageSupplier, "messageSupplier cannot be null");
+ log(messageSupplier.get());
+ }
+ }
+}
diff --git
a/impl/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java
b/impl/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java
index 476f2aadcd..1164ef1b71 100644
---
a/impl/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java
+++
b/impl/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java
@@ -36,6 +36,7 @@
import org.apache.maven.execution.MojoExecutionListener;
import org.apache.maven.execution.scope.internal.MojoExecutionScope;
import org.apache.maven.internal.impl.DefaultLog;
+import org.apache.maven.internal.impl.DefaultLogger;
import org.apache.maven.internal.impl.DefaultMojoExecution;
import org.apache.maven.internal.impl.InternalMavenSession;
import org.apache.maven.model.Plugin;
@@ -122,6 +123,11 @@ public void executeMojo(MavenSession session,
MojoExecution mojoExecution)
try {
scope.seed(MavenProject.class, project);
scope.seed(MojoExecution.class, mojoExecution);
+ scope.seed(
+ org.apache.maven.api.logging.Logger.class,
+ new DefaultLogger(LoggerFactory.getLogger(
+
mojoExecution.getMojoDescriptor().getImplementation())));
+ //noinspection deprecation
scope.seed(
org.apache.maven.api.plugin.Log.class,
new DefaultLog(LoggerFactory.getLogger(
diff --git
a/impl/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java
b/impl/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java
index d881c31b38..b95a8b9d0a 100644
---
a/impl/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java
+++
b/impl/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java
@@ -68,6 +68,7 @@
import org.apache.maven.execution.scope.internal.MojoExecutionScope;
import org.apache.maven.execution.scope.internal.MojoExecutionScopeModule;
import org.apache.maven.internal.impl.DefaultLog;
+import org.apache.maven.internal.impl.DefaultLogger;
import org.apache.maven.internal.impl.DefaultMojoExecution;
import org.apache.maven.internal.impl.InternalMavenSession;
import org.apache.maven.internal.impl.SisuDiBridgeModule;
@@ -563,7 +564,7 @@ private <T> T loadV4Mojo(
Project project = sessionV4.getProject(session.getCurrentProject());
org.apache.maven.api.MojoExecution execution = new
DefaultMojoExecution(sessionV4, mojoExecution);
- org.apache.maven.api.plugin.Log log = new DefaultLog(
+ org.apache.maven.api.logging.Logger log = new DefaultLogger(
LoggerFactory.getLogger(mojoExecution.getMojoDescriptor().getImplementation()));
try {
Injector injector = Injector.create();
@@ -573,7 +574,12 @@ private <T> T loadV4Mojo(
injector.bindInstance(Session.class, sessionV4);
injector.bindInstance(Project.class, project);
injector.bindInstance(org.apache.maven.api.MojoExecution.class,
execution);
- injector.bindInstance(org.apache.maven.api.plugin.Log.class, log);
+ injector.bindInstance(org.apache.maven.api.logging.Logger.class,
log);
+ //noinspection deprecation
+ injector.bindInstance(
+ org.apache.maven.api.plugin.Log.class,
+ new DefaultLog(LoggerFactory.getLogger(
+
mojoExecution.getMojoDescriptor().getImplementation())));
Map<Class<? extends Service>, Supplier<? extends Service>>
services = sessionV4.getAllServices();
services.forEach((itf, svc) ->
injector.bindSupplier((Class<Service>) itf, (Supplier<Service>) svc));
diff --git
a/impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultLoggerTest.java
b/impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultLoggerTest.java
new file mode 100644
index 0000000000..dedfb67a6b
--- /dev/null
+++
b/impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultLoggerTest.java
@@ -0,0 +1,307 @@
+/*
+ * 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.internal.impl;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.maven.api.logging.LogEventBuilder;
+import org.apache.maven.api.logging.Logger;
+import org.junit.jupiter.api.Test;
+import org.slf4j.spi.LoggingEventBuilder;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests for {@link DefaultLogger}.
+ */
+class DefaultLoggerTest {
+
+ @Test
+ void warnWithSupplierAndThrowableDelegatesToWarn() {
+ org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);
+ when(mockLogger.isWarnEnabled()).thenReturn(true);
+
+ Logger log = new DefaultLogger(mockLogger);
+ RuntimeException ex = new RuntimeException("test");
+ log.warn(() -> "warning message", ex);
+
+ verify(mockLogger).warn("warning message", ex);
+ }
+
+ @Test
+ void traceMethodsDelegateToSlf4jTrace() {
+ org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);
+ when(mockLogger.isTraceEnabled()).thenReturn(true);
+
+ Logger log = new DefaultLogger(mockLogger);
+ log.trace("trace message");
+
+ verify(mockLogger).trace("trace message");
+ }
+
+ @Test
+ void traceIsNoOpWhenDisabled() {
+ org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);
+ when(mockLogger.isTraceEnabled()).thenReturn(false);
+
+ Logger log = new DefaultLogger(mockLogger);
+ log.trace("should not be logged");
+
+ verify(mockLogger).isTraceEnabled();
+ verifyNoMoreInteractions(mockLogger);
+ }
+
+ @Test
+ void childCreatesChildLoggerWithAppendedName() {
+ org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);
+ when(mockLogger.getName()).thenReturn("org.example.MyMojo");
+
+ Logger log = new DefaultLogger(mockLogger);
+ Logger child = log.child("sub");
+
+ assertNotSame(log, child);
+ assertEquals("org.example.MyMojo.sub", child.name());
+ }
+
+ @Test
+ void childRejectsEmptyName() {
+ org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);
+ Logger log = new DefaultLogger(mockLogger);
+
+ assertThrows(IllegalArgumentException.class, () -> log.child(""));
+ }
+
+ // ---- Fluent builder: key-value pairs ----
+
+ @Test
+ void fluentBuilderWithKeyValueDelegatesToSlf4jAddKeyValue() {
+ org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);
+ LoggingEventBuilder mockBuilder = mock(LoggingEventBuilder.class);
+ when(mockLogger.isInfoEnabled()).thenReturn(true);
+ when(mockLogger.atInfo()).thenReturn(mockBuilder);
+ when(mockBuilder.addKeyValue("module",
"compiler")).thenReturn(mockBuilder);
+ when(mockBuilder.addKeyValue("count", 3L)).thenReturn(mockBuilder);
+
+ Logger log = new DefaultLogger(mockLogger);
+ log.atInfo()
+ .withKeyValue("module", "compiler")
+ .withKeyValue("count", 3L)
+ .log("Building {} modules", 3);
+
+ verify(mockBuilder).addKeyValue("module", "compiler");
+ verify(mockBuilder).addKeyValue("count", 3L);
+ verify(mockBuilder).log("Building {} modules", 3);
+ }
+
+ @Test
+ void fluentBuilderBooleanKeyValueDelegatesToSlf4j() {
+ org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);
+ LoggingEventBuilder mockBuilder = mock(LoggingEventBuilder.class);
+ when(mockLogger.isDebugEnabled()).thenReturn(true);
+ when(mockLogger.atDebug()).thenReturn(mockBuilder);
+ when(mockBuilder.addKeyValue("incremental",
true)).thenReturn(mockBuilder);
+
+ Logger log = new DefaultLogger(mockLogger);
+ log.atDebug().withKeyValue("incremental", true).log("Compile");
+
+ verify(mockBuilder).addKeyValue("incremental", true);
+ verify(mockBuilder).log("Compile");
+ }
+
+ // ---- NOP builder laziness ----
+
+ @Test
+ void nopBuilderDoesNotInvokeMessageSupplier() {
+ org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);
+ when(mockLogger.isTraceEnabled()).thenReturn(false);
+
+ AtomicBoolean supplierCalled = new AtomicBoolean(false);
+ Logger log = new DefaultLogger(mockLogger);
+ log.atTrace().log(() -> {
+ supplierCalled.set(true);
+ return "expensive message";
+ });
+
+ assertFalse(supplierCalled.get(), "Supplier must not be called when
TRACE is disabled");
+ }
+
+ @Test
+ void nopBuilderReturnsSameInstanceForAllChainedCalls() {
+ org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);
+ when(mockLogger.isDebugEnabled()).thenReturn(false);
+
+ Logger log = new DefaultLogger(mockLogger);
+ LogEventBuilder b1 = log.atDebug();
+ LogEventBuilder b2 = b1.withKeyValue("k", "v");
+ LogEventBuilder b3 = b2.withKeyValue("n", 42L);
+ LogEventBuilder b4 = b3.withThrowable(null);
+
+ assertSame(b1, b2, "NOP builder must return itself from
withKeyValue(String,String)");
+ assertSame(b2, b3, "NOP builder must return itself from
withKeyValue(String,long)");
+ assertSame(b3, b4, "NOP builder must return itself from
withThrowable");
+ }
+
+ // ---- withThrowable after builder already initialised ----
+
+ @Test
+ void withThrowableAfterKeyValueSetsSlf4jCause() {
+ org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);
+ LoggingEventBuilder mockBuilder = mock(LoggingEventBuilder.class);
+ when(mockLogger.isErrorEnabled()).thenReturn(true);
+ when(mockLogger.atError()).thenReturn(mockBuilder);
+ when(mockBuilder.addKeyValue("phase",
"compile")).thenReturn(mockBuilder);
+
when(mockBuilder.setCause(org.mockito.ArgumentMatchers.any())).thenReturn(mockBuilder);
+
+ RuntimeException ex = new RuntimeException("fail");
+ Logger log = new DefaultLogger(mockLogger);
+ log.atError()
+ .withKeyValue("phase", "compile") // triggers ensureBuilder()
→ slf4jBuilder is now set
+ .withThrowable(ex) // must call slf4jBuilder.setCause(ex), not
store in field
+ .log("Build failed");
+
+ verify(mockBuilder).setCause(ex);
+ verify(mockBuilder).log("Build failed");
+ }
+
+ @Test
+ void withThrowableBeforeKeyValueStoresAndPassesToBuilder() {
+ org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);
+ LoggingEventBuilder mockBuilder = mock(LoggingEventBuilder.class);
+ when(mockLogger.isWarnEnabled()).thenReturn(true);
+ when(mockLogger.atWarn()).thenReturn(mockBuilder);
+ when(mockBuilder.addKeyValue("key", "val")).thenReturn(mockBuilder);
+
when(mockBuilder.setCause(org.mockito.ArgumentMatchers.any())).thenReturn(mockBuilder);
+
+ RuntimeException ex = new RuntimeException("warn");
+ Logger log = new DefaultLogger(mockLogger);
+ log.atWarn()
+ .withThrowable(ex) // stored in field — builder not yet
initialised
+ .withKeyValue("key", "val") // triggers ensureBuilder() → must
pass stored throwable
+ .log("Warning");
+
+ // The throwable is passed via setCause inside ensureBuilder() when
slf4jBuilder is first created
+ verify(mockBuilder).setCause(ex);
+ verify(mockBuilder).addKeyValue("key", "val");
+ verify(mockBuilder).log("Warning");
+ }
+
+ // ---- ModelProcessor bridge: strict option handling ----
+
+ /**
+ * Verifies that the default {@code read(Source, Map)} bridge in {@link
org.apache.maven.api.services.model.ModelProcessor}
+ * passes {@code strict=true} to the underlying {@code
read(XmlReaderRequest)} when options is {@code null}.
+ */
+ @Test
+ void modelProcessorReadBridgeUsesStrictTrueByDefault() throws Exception {
+ final boolean[] strictSeen = {false};
+ org.apache.maven.api.services.model.ModelProcessor processor =
modelProcessorCapturingStrict(strictSeen);
+
+ java.nio.file.Path tmp = java.nio.file.Files.createTempFile("pom",
".xml");
+ try {
+ java.nio.file.Files.writeString(tmp, "<project/>");
+ org.apache.maven.api.services.Source source = pathSource(tmp);
+ try {
+ processor.read(source, null);
+ } catch (Exception ignored) {
+ }
+ assertTrue(strictSeen[0], "strict must be true when options is
null");
+ } finally {
+ java.nio.file.Files.deleteIfExists(tmp);
+ }
+ }
+
+ /**
+ * Verifies that the default {@code read(Source, Map)} bridge honours the
+ * {@code "strict"} option when explicitly set to {@code "false"}.
+ */
+ @Test
+ void modelProcessorReadBridgeRespectsStrictFalseOption() throws Exception {
+ final boolean[] strictSeen = {true};
+ org.apache.maven.api.services.model.ModelProcessor processor =
modelProcessorCapturingStrict(strictSeen);
+
+ java.nio.file.Path tmp = java.nio.file.Files.createTempFile("pom",
".xml");
+ try {
+ java.nio.file.Files.writeString(tmp, "<project/>");
+ org.apache.maven.api.services.Source source = pathSource(tmp);
+ java.util.Map<String, Object> options =
+
java.util.Map.of(org.apache.maven.api.spi.ModelParser.STRICT, "false");
+ try {
+ processor.read(source, options);
+ } catch (Exception ignored) {
+ }
+ assertFalse(strictSeen[0], "strict must be false when options
contains \"strict\"=\"false\"");
+ } finally {
+ java.nio.file.Files.deleteIfExists(tmp);
+ }
+ }
+
+ // ---- helpers ----
+
+ private static org.apache.maven.api.services.model.ModelProcessor
modelProcessorCapturingStrict(
+ boolean[] strictOut) {
+ return new org.apache.maven.api.services.model.ModelProcessor() {
+ @Override
+ public java.nio.file.Path locateExistingPom(java.nio.file.Path
project) {
+ return null;
+ }
+
+ @Override
+ @SuppressWarnings("deprecation")
+ public org.apache.maven.api.model.Model
read(org.apache.maven.api.services.xml.XmlReaderRequest request)
+ throws java.io.IOException,
org.apache.maven.api.services.xml.XmlReaderException {
+ strictOut[0] = request.isStrict();
+ return org.apache.maven.api.model.Model.newInstance();
+ }
+ };
+ }
+
+ private static org.apache.maven.api.services.Source
pathSource(java.nio.file.Path path) {
+ return new org.apache.maven.api.services.Source() {
+ @Override
+ public java.nio.file.Path getPath() {
+ return path;
+ }
+
+ @Override
+ public java.io.InputStream openStream() throws java.io.IOException
{
+ return java.nio.file.Files.newInputStream(path);
+ }
+
+ @Override
+ public String getLocation() {
+ return path.toString();
+ }
+
+ @Override
+ public org.apache.maven.api.services.Source resolve(
+ @org.apache.maven.api.annotations.Nonnull String relative)
{
+ return pathSource(path.getParent().resolve(relative));
+ }
+ };
+ }
+}
diff --git
a/impl/maven-testing/src/main/java/org/apache/maven/testing/plugin/MojoExtension.java
b/impl/maven-testing/src/main/java/org/apache/maven/testing/plugin/MojoExtension.java
index fb5a804088..3ec89a04f9 100644
---
a/impl/maven-testing/src/main/java/org/apache/maven/testing/plugin/MojoExtension.java
+++
b/impl/maven-testing/src/main/java/org/apache/maven/testing/plugin/MojoExtension.java
@@ -47,6 +47,7 @@
import org.apache.maven.api.di.Priority;
import org.apache.maven.api.di.Provides;
import org.apache.maven.api.di.Singleton;
+import org.apache.maven.api.logging.Logger;
import org.apache.maven.api.model.Build;
import org.apache.maven.api.model.ConfigurationContainer;
import org.apache.maven.api.model.Model;
@@ -79,6 +80,7 @@
import org.apache.maven.impl.model.DefaultModelPathTranslator;
import org.apache.maven.impl.model.DefaultPathTranslator;
import org.apache.maven.internal.impl.DefaultLog;
+import org.apache.maven.internal.impl.DefaultLogger;
import org.apache.maven.internal.xml.XmlPlexusConfiguration;
import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;
import org.apache.maven.model.v4.MavenMerger;
@@ -538,6 +540,13 @@ Log createLog() {
return new DefaultLog(LoggerFactory.getLogger("anonymous"));
}
+ @Provides
+ @Singleton
+ @Priority(-10)
+ Logger createLogger() {
+ return new DefaultLogger(LoggerFactory.getLogger("anonymous"));
+ }
+
@Provides
static RepositorySystemSupplier newRepositorySystemSupplier() {
return new RepositorySystemSupplier();
diff --git a/pom.xml b/pom.xml
index ee146bbccf..60db39d4cd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -269,6 +269,11 @@ under the License.
<artifactId>maven-api-plugin</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-api-log</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-xml</artifactId>