Add some love to the API (#1310)

This commit is contained in:
Guillaume Nodet 2023-11-17 16:52:15 +01:00 committed by GitHub
parent 518b988a09
commit 29e239000b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 77 additions and 16 deletions

View File

@ -28,7 +28,7 @@
<artifactId>maven-api-core</artifactId> <artifactId>maven-api-core</artifactId>
<name>Maven 4 API :: Core</name> <name>Maven 4 API :: Core</name>
<description>Maven 4 API - Maven Core APIs.</description> <description>Maven 4 API - Maven Core API</description>
<dependencies> <dependencies>
<dependency> <dependency>

View File

@ -37,6 +37,7 @@ public interface Artifact {
* *
* @return the unique identifier * @return the unique identifier
*/ */
@Nonnull
default String key() { default String key() {
return getGroupId() return getGroupId()
+ ':' + ':'

View File

@ -75,6 +75,7 @@ public interface ArtifactCoordinate {
/** /**
* Unique id identifying this artifact * Unique id identifying this artifact
*/ */
@Nonnull
default String getId() { default String getId() {
return getGroupId() return getGroupId()
+ ":" + getArtifactId() + ":" + getArtifactId()

View File

@ -22,7 +22,7 @@
import org.apache.maven.api.annotations.Nullable; import org.apache.maven.api.annotations.Nullable;
/** /**
* A dependency exlusion. * A dependency exclusion.
* *
* @since 4.0.0 * @since 4.0.0
* @see DependencyCoordinate#getExclusions() * @see DependencyCoordinate#getExclusions()

View File

@ -26,6 +26,7 @@
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable; import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Provider;
/** /**
* Represents a dependency node within a Maven project's dependency collector. * Represents a dependency node within a Maven project's dependency collector.
@ -35,6 +36,7 @@
*/ */
@Experimental @Experimental
@Immutable @Immutable
@Provider
public interface Node { public interface Node {
/** /**
@ -78,13 +80,15 @@ public interface Node {
* @param filter the filter to apply * @param filter the filter to apply
* @return a new filtered graph * @return a new filtered graph
*/ */
Node filter(Predicate<Node> filter); @Nonnull
Node filter(@Nonnull Predicate<Node> filter);
/** /**
* Returns a string representation of this dependency node. * Returns a string representation of this dependency node.
* *
* @return the string representation * @return the string representation
*/ */
@Nonnull
String asString(); String asString();
/** /**

View File

@ -20,6 +20,8 @@
import java.util.function.Supplier; import java.util.function.Supplier;
import org.apache.maven.api.annotations.Provider;
/** /**
* This interface supplies the API for providing feedback to the user from the <code>Mojo</code>, using standard * This interface supplies the API for providing feedback to the user from the <code>Mojo</code>, using standard
* <code>Maven</code> channels.<br> * <code>Maven</code> channels.<br>
@ -30,6 +32,7 @@
* *
* @since 4.0.0 * @since 4.0.0
*/ */
@Provider
public interface Log { public interface Log {
/** /**
* @return true if the <b>debug</b> error level is enabled * @return true if the <b>debug</b> error level is enabled

View File

@ -26,6 +26,7 @@
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/** /**
* Used to configure injection of Plexus components by * Used to configure injection of Plexus components by
@ -44,11 +45,13 @@
* role of the component to inject. * role of the component to inject.
* @return the role * @return the role
*/ */
@Nonnull
Class<?> role() default Object.class; Class<?> role() default Object.class;
/** /**
* hint of the component to inject. * hint of the component to inject.
* @return the hint * @return the hint
*/ */
@Nonnull
String hint() default ""; String hint() default "";
} }

View File

@ -26,6 +26,7 @@
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/** /**
* Used if your Mojo needs to fork a <a href="/ref/3.0.4/maven-core/lifecycles.html">lifecycle</a>. * Used if your Mojo needs to fork a <a href="/ref/3.0.4/maven-core/lifecycles.html">lifecycle</a>.
@ -44,6 +45,7 @@
* Only one of {@link #customPhase()} and {@link #phase()} must be set. * Only one of {@link #customPhase()} and {@link #phase()} must be set.
* @return the phase * @return the phase
*/ */
@Nonnull
LifecyclePhase phase() default LifecyclePhase.NONE; LifecyclePhase phase() default LifecyclePhase.NONE;
/** /**
@ -52,6 +54,7 @@
* Only one of {@link #customPhase()} and {@link #phase()} must be set. * Only one of {@link #customPhase()} and {@link #phase()} must be set.
* @return the custom phase id * @return the custom phase id
*/ */
@Nonnull
String customPhase() default ""; String customPhase() default "";
/** /**
@ -59,6 +62,7 @@
* another goal of the same plugin. * another goal of the same plugin.
* @return the goal * @return the goal
*/ */
@Nonnull
String goal() default ""; String goal() default "";
/** /**
@ -68,5 +72,6 @@
* @see <a href="https://maven.apache.org/maven-plugin-api/lifecycle-mappings.html">Lifecycle Mappings</a> * @see <a href="https://maven.apache.org/maven-plugin-api/lifecycle-mappings.html">Lifecycle Mappings</a>
* @return the lifecycle id * @return the lifecycle id
*/ */
@Nonnull
String lifecycle() default ""; String lifecycle() default "";
} }

View File

@ -27,6 +27,7 @@
import org.apache.maven.api.ResolutionScope; import org.apache.maven.api.ResolutionScope;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/** /**
* This annotation will mark your class as a Mojo (ie. goal in a Maven plugin). * This annotation will mark your class as a Mojo (ie. goal in a Maven plugin).
@ -43,30 +44,35 @@
* goal name (required). * goal name (required).
* @return the goal name * @return the goal name
*/ */
@Nonnull
String name(); String name();
/** /**
* default phase to bind your mojo. * default phase to bind your mojo.
* @return the default phase * @return the default phase
*/ */
@Nonnull
LifecyclePhase defaultPhase() default LifecyclePhase.NONE; LifecyclePhase defaultPhase() default LifecyclePhase.NONE;
/** /**
* the required dependency resolution scope. * the required dependency resolution scope.
* @return the required dependency resolution scope * @return the required dependency resolution scope
*/ */
@Nonnull
ResolutionScope requiresDependencyResolution() default ResolutionScope.NONE; ResolutionScope requiresDependencyResolution() default ResolutionScope.NONE;
/** /**
* the required dependency collection scope. * the required dependency collection scope.
* @return the required dependency collection scope * @return the required dependency collection scope
*/ */
@Nonnull
ResolutionScope requiresDependencyCollection() default ResolutionScope.NONE; ResolutionScope requiresDependencyCollection() default ResolutionScope.NONE;
/** /**
* your Mojo instantiation strategy. (Only <code>per-lookup</code> and <code>singleton</code> are supported) * your Mojo instantiation strategy. (Only <code>per-lookup</code> and <code>singleton</code> are supported)
* @return the instantiation strategy * @return the instantiation strategy
*/ */
@Nonnull
InstantiationStrategy instantiationStrategy() default InstantiationStrategy.PER_LOOKUP; InstantiationStrategy instantiationStrategy() default InstantiationStrategy.PER_LOOKUP;
/** /**
@ -91,5 +97,6 @@
* configurator bean name. * configurator bean name.
* @return the configurator bean name * @return the configurator bean name
*/ */
@Nonnull
String configurator() default ""; String configurator() default "";
} }

View File

@ -26,6 +26,7 @@
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/** /**
* Used to configure your Mojo parameters to be injected by * Used to configure your Mojo parameters to be injected by
@ -48,12 +49,14 @@
* name of the bean property used to get/set the field: by default, field name is used. * name of the bean property used to get/set the field: by default, field name is used.
* @return the name of the bean property * @return the name of the bean property
*/ */
@Nonnull
String name() default ""; String name() default "";
/** /**
* alias supported to get parameter value. * alias supported to get parameter value.
* @return the alias * @return the alias
*/ */
@Nonnull
String alias() default ""; String alias() default "";
/** /**
@ -61,6 +64,7 @@
* properties. * properties.
* @return property name * @return property name
*/ */
@Nonnull
String property() default ""; String property() default "";
/** /**
@ -70,6 +74,7 @@
* PluginParameterExpressionEvaluator</a>. * PluginParameterExpressionEvaluator</a>.
* @return the default value * @return the default value
*/ */
@Nonnull
String defaultValue() default ""; String defaultValue() default "";
/** /**

View File

@ -25,6 +25,7 @@
import org.apache.maven.api.Service; import org.apache.maven.api.Service;
import org.apache.maven.api.Session; import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
/** /**
* Installs {@link Artifact}s to the local repository. * Installs {@link Artifact}s to the local repository.
@ -39,7 +40,7 @@ public interface ArtifactInstaller extends Service {
* @throws ArtifactInstallerException in case of an error * @throws ArtifactInstallerException in case of an error
* @throws IllegalArgumentException in case {@code request} is {@code null} * @throws IllegalArgumentException in case {@code request} is {@code null}
*/ */
void install(ArtifactInstallerRequest request); void install(@Nonnull ArtifactInstallerRequest request);
/** /**
* @param session the repository session * @param session the repository session

View File

@ -22,6 +22,8 @@
import org.apache.maven.api.Service; import org.apache.maven.api.Service;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable;
/** /**
* Service used to interact with the end user. * Service used to interact with the end user.
@ -37,7 +39,8 @@ public interface Prompter extends Service {
* @return the string entered by the user * @return the string entered by the user
* @throws PrompterException if an exception occurs * @throws PrompterException if an exception occurs
*/ */
default String prompt(String message) throws PrompterException { @Nonnull
default String prompt(@Nullable String message) throws PrompterException {
return prompt(message, null, null); return prompt(message, null, null);
} }
@ -49,7 +52,8 @@ default String prompt(String message) throws PrompterException {
* @return the string entered by the user * @return the string entered by the user
* @throws PrompterException if an exception occurs * @throws PrompterException if an exception occurs
*/ */
default String prompt(String message, String defaultReply) throws PrompterException { @Nonnull
default String prompt(@Nullable String message, @Nullable String defaultReply) throws PrompterException {
return prompt(message, null, defaultReply); return prompt(message, null, defaultReply);
} }
@ -61,7 +65,8 @@ default String prompt(String message, String defaultReply) throws PrompterExcept
* @return the string entered by the user * @return the string entered by the user
* @throws PrompterException if an exception occurs * @throws PrompterException if an exception occurs
*/ */
default String prompt(String message, List<String> possibleValues) throws PrompterException { @Nonnull
default String prompt(@Nullable String message, @Nullable List<String> possibleValues) throws PrompterException {
return prompt(message, possibleValues, null); return prompt(message, possibleValues, null);
} }
@ -74,7 +79,9 @@ default String prompt(String message, List<String> possibleValues) throws Prompt
* @return the string entered by the user * @return the string entered by the user
* @throws PrompterException if an exception occurs * @throws PrompterException if an exception occurs
*/ */
String prompt(String message, List<String> possibleValues, String defaultReply) throws PrompterException; @Nonnull
String prompt(@Nullable String message, @Nullable List<String> possibleValues, @Nullable String defaultReply)
throws PrompterException;
/** /**
* Prompts the user for a password. * Prompts the user for a password.
@ -83,7 +90,8 @@ default String prompt(String message, List<String> possibleValues) throws Prompt
* @return the password entered by the user * @return the password entered by the user
* @throws PrompterException if an exception occurs * @throws PrompterException if an exception occurs
*/ */
String promptForPassword(String message) throws PrompterException; @Nonnull
String promptForPassword(@Nullable String message) throws PrompterException;
/** /**
* Displays a message to the user. * Displays a message to the user.
@ -91,5 +99,5 @@ default String prompt(String message, List<String> possibleValues) throws Prompt
* @param message the message to display * @param message the message to display
* @throws PrompterException if an exception occurs * @throws PrompterException if an exception occurs
*/ */
void showMessage(String message) throws PrompterException; void showMessage(@Nullable String message) throws PrompterException;
} }

View File

@ -97,6 +97,7 @@ default void write(@Nonnull T content, @Nonnull Writer writer) throws XmlWriterE
* @throws XmlReaderException if an error occurs during the parsing * @throws XmlReaderException if an error occurs during the parsing
* @see #toXmlString(Object) * @see #toXmlString(Object)
*/ */
@Nonnull
default T fromXmlString(@Nonnull String xml) throws XmlReaderException { default T fromXmlString(@Nonnull String xml) throws XmlReaderException {
return read(new StringReader(xml)); return read(new StringReader(xml));
} }
@ -109,6 +110,7 @@ default T fromXmlString(@Nonnull String xml) throws XmlReaderException {
* @throws XmlWriterException if an error occurs during the transformation * @throws XmlWriterException if an error occurs during the transformation
* @see #fromXmlString(String) * @see #fromXmlString(String)
*/ */
@Nonnull
default String toXmlString(@Nonnull T content) throws XmlWriterException { default String toXmlString(@Nonnull T content) throws XmlWriterException {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
write(content, sw); write(content, sw);

View File

@ -27,6 +27,7 @@
import org.apache.maven.api.annotations.Immutable; import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.NotThreadSafe; import org.apache.maven.api.annotations.NotThreadSafe;
import org.apache.maven.api.annotations.Nullable;
/** /**
* An XML reader request. * An XML reader request.
@ -37,20 +38,27 @@
@Immutable @Immutable
public interface XmlReaderRequest { public interface XmlReaderRequest {
@Nullable
Path getPath(); Path getPath();
@Nullable
URL getURL(); URL getURL();
@Nullable
InputStream getInputStream(); InputStream getInputStream();
@Nullable
Reader getReader(); Reader getReader();
@Nullable
Transformer getTransformer(); Transformer getTransformer();
boolean isStrict(); boolean isStrict();
@Nullable
String getModelId(); String getModelId();
@Nullable
String getLocation(); String getLocation();
boolean isAddDefaultEntities(); boolean isAddDefaultEntities();

View File

@ -23,6 +23,8 @@
import java.nio.file.Path; import java.nio.file.Path;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable;
/** /**
* An XML writer request. * An XML writer request.
@ -33,12 +35,16 @@
@Experimental @Experimental
public interface XmlWriterRequest<T> { public interface XmlWriterRequest<T> {
@Nullable
Path getPath(); Path getPath();
@Nullable
OutputStream getOutputStream(); OutputStream getOutputStream();
@Nullable
Writer getWriter(); Writer getWriter();
@Nonnull
T getContent(); T getContent();
static <T> XmlWriterRequestBuilder<T> builder() { static <T> XmlWriterRequestBuilder<T> builder() {

View File

@ -27,7 +27,7 @@
</parent> </parent>
<artifactId>maven-api-meta</artifactId> <artifactId>maven-api-meta</artifactId>
<name>Maven 4 API Meta annotations</name> <name>Maven 4 API :: Meta annotations</name>
<description>Java annotations for Maven 4 Immutable API.</description> <description>Maven 4 API - Java meta annotations.</description>
</project> </project>

View File

@ -29,7 +29,7 @@ under the License.
<artifactId>maven-api-model</artifactId> <artifactId>maven-api-model</artifactId>
<name>Maven 4 API :: Model</name> <name>Maven 4 API :: Model</name>
<description>Maven 4 API - Immutable Model for Maven POM (Project Object Model)</description> <description>Maven 4 API - Immutable Model for Maven POM (Project Object Model).</description>
<dependencies> <dependencies>
<dependency> <dependency>

View File

@ -29,7 +29,7 @@ under the License.
<artifactId>maven-api-settings</artifactId> <artifactId>maven-api-settings</artifactId>
<name>Maven 4 API :: Settings</name> <name>Maven 4 API :: Settings</name>
<description>Maven 4 API - Immutable Settings model</description> <description>Maven 4 API - Immutable Settings model.</description>
<dependencies> <dependencies>
<dependency> <dependency>

View File

@ -27,8 +27,8 @@
</parent> </parent>
<artifactId>maven-api-xml</artifactId> <artifactId>maven-api-xml</artifactId>
<name>Maven 4 API XML</name> <name>Maven 4 API :: XML</name>
<description>Maven 4 API immutable XML helper.</description> <description>Maven 4 API - Immutable XML.</description>
<dependencies> <dependencies>
<dependency> <dependency>

View File

@ -30,6 +30,8 @@
/** /**
* An immutable xml node. * An immutable xml node.
* *
* TODO: v4: add support for namespaces
*
* @since 4.0.0 * @since 4.0.0
*/ */
@Experimental @Experimental

View File

@ -0,0 +1,5 @@
// CHECKSTYLE_OFF: RegexpHeader
/**
* Maven immutable XML api.
*/
package org.apache.maven.api.xml;