Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,28 @@
import org.apache.maven.api.annotations.ThreadSafe;

/**
* This interface forms the contract required for Mojos to interact with the Maven infrastructure.
* It features an {@link #execute()} method, which triggers the Mojo's build-process behavior,
* and can throw a {@link MojoException} if error conditions occur.
* Represents the contract for Mojos to interact with the Maven infrastructure.
* Implementations of this interface define specific build-process behaviors
* that are triggered during a Maven build lifecycle.
*
* The primary entry point is the {@link #execute()} method, which encapsulates
* the behavior of the Mojo and serves as the integration point with Maven. This
* method may throw an {@link Exception} to signal any issues that prevent
* successful execution of the Mojo.
*
* <p>
* Annotations:
* </p>
* <ul>
* <li>{@link Experimental}: Indicates that this interface or its implementation
* may still be evolving and could change in future versions.</li>
* <li>{@link FunctionalInterface}: Denotes that this is a functional interface,
* allowing implementations as lambda expressions or method references.</li>
* <li>{@link Consumer}: Signifies that this type is intended to be implemented
* or extended by Maven plugins or extensions and consumed by Maven itself.</li>
* <li>{@link ThreadSafe}: Implies that implementations of this interface must
* be safe to invoke from multiple threads concurrently.</li>
* </ul>
*
* @since 4.0.0
*/
Expand All @@ -35,11 +54,15 @@
@ThreadSafe
public interface Mojo {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a small incoherence between the javadoc on the class which talks about MojoException, which is not the only exception thrown anymore.
Going through AI, It came up with:

/**
 * Represents the contract for Mojos to interact with the Maven infrastructure.
 * Implementations of this interface define specific build-process behaviors
 * that are triggered during a Maven build lifecycle.
 *
 * The primary entry point is the {@link #execute()} method, which encapsulates
 * the behavior of the Mojo and serves as the integration point with Maven.
 * This method may throw an {@link Exception} to signal any issues that prevent
 * successful execution of the Mojo.
 *
 * <p>Annotations:</p>
 * <ul>
 *   <li>{@link Experimental}: Indicates that this interface or its implementation
 *       may still be evolving and could change in future versions.</li>
 *   <li>{@link FunctionalInterface}: Denotes that this is a functional interface,
 *       allowing implementations as lambda expressions or method references.</li>
 *   <li>{@link Consumer}: Signifies that this type is intended to be implemented
 *       or extended by Maven plugins or extensions and consumed by Maven itself.</li>
 *   <li>{@link ThreadSafe}: Implies that implementations of this interface must
 *       be safe to invoke from multiple threads concurrently.</li>
 * </ul>
 *
 * @since 4.0.0
 */
@Experimental
@FunctionalInterface
@Consumer
@ThreadSafe
public interface Mojo {
    /**
     * Executes the behavior defined by this {@code Mojo}. This method is invoked
     * during the Maven build lifecycle to perform the Mojo's designated task.
     *
     * <p>Implementations should handle any task-specific logic and may communicate
     * errors by throwing an {@link Exception}. Error conditions should provide
     * sufficient detail to aid troubleshooting.</p>
     *
     * @throws Exception if any issue occurs that prevents the successful execution
     *                   of the Mojo
     */
    void execute() throws Exception;
}

which looks better to me. Wdyt ?

/**
* Perform whatever build-process behavior this {@code Mojo} implements.
* This is the main trigger for the {@code Mojo} inside the Maven system,
* and allows the {@code Mojo} to communicate errors.
* Executes the behavior defined by this {@code Mojo}. This method is invoked
* during the Maven build lifecycle to perform the Mojo's designated task.
*
* <p>Implementations should handle any task-specific logic and may communicate
* errors by throwing an {@link Exception}. Error conditions should provide
* sufficient detail to aid troubleshooting.</p>
*
* @throws MojoException if a problem occurs
* @throws Exception if any issue occurs that prevents the successful execution
* of the Mojo
*/
void execute();
void execute() throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public DefaultBuildPluginManager(
* @throws PluginResolutionException The plugin could be found but could not be resolved.
* @throws InvalidPluginDescriptorException
*/
@Override
public PluginDescriptor loadPlugin(
Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session)
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
Expand All @@ -92,6 +93,7 @@ public PluginDescriptor loadPlugin(
// Mojo execution
// ----------------------------------------------------------------------

@Override
public void executeMojo(MavenSession session, MojoExecution mojoExecution)
throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException {
MavenProject project = session.getCurrentProject();
Expand Down Expand Up @@ -201,6 +203,7 @@ public void executeMojo(MavenSession session, MojoExecution mojoExecution)
* call, which is not nice.
* @throws PluginResolutionException
*/
@Override
public ClassRealm getPluginRealm(MavenSession session, PluginDescriptor pluginDescriptor)
throws PluginResolutionException, PluginManagerException {
ClassRealm pluginRealm = pluginDescriptor.getClassRealm();
Expand All @@ -213,6 +216,7 @@ public ClassRealm getPluginRealm(MavenSession session, PluginDescriptor pluginDe
return pluginDescriptor.getClassRealm();
}

@Override
public MojoDescriptor getMojoDescriptor(
Plugin plugin, String goal, List<RemoteRepository> repositories, RepositorySystemSession session)
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
Expand All @@ -228,8 +232,14 @@ private static class MojoWrapper implements Mojo {
}

@Override
public void execute() {
mojoV4.execute();
public void execute() throws MojoExecutionException {
try {
mojoV4.execute();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new MojoExecutionException(e);
}
}

@Override
Expand Down