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 5ebbc9783d0e..d222789f7ad3 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 @@ -35,7 +35,8 @@ public interface Artifact /** * Returns a unique identifier for this artifact. - * The identifier is composed of groupId, artifactId, version, classifier, extension + * The identifier is composed of groupId, artifactId, version, classifier, extension. + * * @return the unique identifier */ default String key() @@ -50,7 +51,7 @@ default String key() /** * The groupId of the artifact. * - * @return The groupId. + * @return the groupId */ @Nonnull String getGroupId(); @@ -58,7 +59,7 @@ default String key() /** * The artifactId of the artifact. * - * @return The artifactId. + * @return the artifactId */ @Nonnull String getArtifactId(); @@ -66,7 +67,7 @@ default String key() /** * The version of the artifact. * - * @return The version. + * @return the version */ @Nonnull Version getVersion(); @@ -74,7 +75,7 @@ default String key() /** * The classifier of the artifact. * - * @return The classifier or an empty string if none, never {@code null}. + * @return the classifier or an empty string if none, never {@code null} */ @Nonnull String getClassifier(); @@ -82,7 +83,7 @@ default String key() /** * The file extension of the artifact. * - * @return The extension. + * @return the extension */ @Nonnull String getExtension(); @@ -90,7 +91,7 @@ default String key() /** * Determines whether this artifact uses a snapshot version. * - * @return {@code true} if the artifact is a snapshot, {@code false} otherwise. + * @return {@code true} if the artifact is a snapshot, {@code false} otherwise * @see org.apache.maven.api.Session#isVersionSnapshot(String) */ boolean isSnapshot(); diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/ArtifactCoordinate.java b/api/maven-api-core/src/main/java/org/apache/maven/api/ArtifactCoordinate.java index 1f11e321986f..3e66594dfad5 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/ArtifactCoordinate.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/ArtifactCoordinate.java @@ -37,7 +37,7 @@ public interface ArtifactCoordinate /** * The groupId of the artifact. * - * @return The groupId. + * @return the groupId */ @Nonnull String getGroupId(); @@ -45,7 +45,7 @@ public interface ArtifactCoordinate /** * The artifactId of the artifact. * - * @return The artifactId. + * @return the artifactId */ @Nonnull String getArtifactId(); @@ -53,7 +53,7 @@ public interface ArtifactCoordinate /** * The classifier of the artifact. * - * @return The classifier or an empty string if none, never {@code null}. + * @return the classifier or an empty string if none, never {@code null} */ @Nonnull String getClassifier(); @@ -61,7 +61,7 @@ public interface ArtifactCoordinate /** * The version of the artifact. * - * @return The version. + * @return the version */ @Nonnull VersionRange getVersion(); @@ -69,7 +69,7 @@ public interface ArtifactCoordinate /** * The extension of the artifact. * - * @return The extension or an empty string if none, never {@code null}. + * @return the extension or an empty string if none, never {@code null} */ @Nonnull String getExtension(); 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 51fa632efcc8..0283f41c5d07 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 @@ -27,11 +27,12 @@ public interface Dependency extends Artifact /** * The artifact type. * - * @return The artifact type, never {@code null}. + * @return the artifact type, never {@code null} */ @Nonnull Type getType(); + @Nonnull Scope getScope(); boolean isOptional(); diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/DependencyCoordinate.java b/api/maven-api-core/src/main/java/org/apache/maven/api/DependencyCoordinate.java index e5ea7a4cb6c2..675a00f0d374 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/DependencyCoordinate.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/DependencyCoordinate.java @@ -37,7 +37,7 @@ public interface DependencyCoordinate extends ArtifactCoordinate /** * The type of the artifact. * - * @return The type. + * @return the type */ @Nonnull Type getType(); 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 0a30dba8fd51..4d23939a7c6b 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 @@ -38,7 +38,7 @@ public interface Event /** * Gets the type of the event. * - * @return The type of the event, never {@code null}. + * @return the type of the event, never {@code null} */ @Nonnull EventType getType(); @@ -46,7 +46,7 @@ public interface Event /** * Gets the session from which this event originates. * - * @return The current session, never {@code null}. + * @return the current session, never {@code null} */ @Nonnull Session getSession(); @@ -54,7 +54,7 @@ public interface Event /** * Gets the current project (if any). * - * @return The current project or {@code empty()} if not applicable. + * @return the current project or {@code empty()} if not applicable */ @Nonnull Optional getProject(); @@ -62,7 +62,7 @@ public interface Event /** * Gets the current mojo execution (if any). * - * @return The current mojo execution or {@code empty()} if not applicable. + * @return the current mojo execution or {@code empty()} if not applicable */ @Nonnull Optional getMojoExecution(); @@ -70,7 +70,7 @@ public interface Event /** * Gets the exception that caused the event (if any). * - * @return The exception or {@code empty()} if none. + * @return the exception or {@code empty()} if none */ Optional getException(); 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 f0bb78b17353..d23c8f60e74b 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 @@ -67,8 +67,8 @@ public interface Node /** * Traverses this node and potentially its children using the specified visitor. * - * @param visitor The visitor to call back, must not be {@code null}. - * @return {@code true} to visit siblings nodes of this node as well, {@code false} to skip siblings. + * @param visitor the visitor to call back, must not be {@code null} + * @return {@code true} to visit siblings nodes of this node as well, {@code false} to skip siblings */ boolean accept( @Nonnull NodeVisitor visitor ); 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 10551d737c5d..896943d197a1 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 @@ -38,7 +38,7 @@ public interface Repository /** * Gets the identifier of this repository. * - * @return The (case-sensitive) identifier, never {@code null}. + * @return the (case-sensitive) identifier, never {@code null} */ @Nonnull String getId(); @@ -46,7 +46,7 @@ public interface Repository /** * Gets the type of the repository, for example "default". * - * @return The (case-sensitive) type of the repository, never {@code null}. + * @return the (case-sensitive) type of the repository, never {@code null} */ @Nonnull 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 5e0e3808d108..38168906cda5 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 @@ -56,15 +56,27 @@ public interface Session @Nonnull SessionData getData(); + /** + * Gets the user properties to use for interpolation. The user properties have been configured directly by the user, + * e.g. via the {@code -Dkey=value} parameter on the command line. + * + * @return the user properties, never {@code null} + */ @Nonnull Map getUserProperties(); + /** + * Gets the system properties to use for interpolation. The system properties are collected from the runtime + * environment such as {@link System#getProperties()} and environment variables. + * + * @return the system properties, never {@code null} + */ @Nonnull Map getSystemProperties(); /** * Returns the current maven version - * @return the maven version, never {@code null}. + * @return the maven version, never {@code null} */ @Nonnull String getMavenVersion(); diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/SessionData.java b/api/maven-api-core/src/main/java/org/apache/maven/api/SessionData.java index 8a8ef19401f0..2df695ec3fba 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/SessionData.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/SessionData.java @@ -47,8 +47,8 @@ public interface SessionData /** * Associates the specified session data with the given key. * - * @param key The key under which to store the session data, must not be {@code null}. - * @param value The data to associate with the key, may be {@code null} to remove the mapping. + * @param key the key under which to store the session data, must not be {@code null} + * @param value the data to associate with the key, may be {@code null} to remove the mapping */ void set( @Nonnull Object key, @Nullable Object value ); @@ -56,9 +56,9 @@ public interface SessionData * Associates the specified session data with the given key if the key is currently mapped to the given value. This * method provides an atomic compare-and-update of some key's value. * - * @param key The key under which to store the session data, must not be {@code null}. - * @param oldValue The expected data currently associated with the key, may be {@code null}. - * @param newValue The data to associate with the key, may be {@code null} to remove the mapping. + * @param key the key under which to store the session data, must not be {@code null} + * @param oldValue the expected data currently associated with the key, may be {@code null} + * @param newValue the data to associate with the key, may be {@code null} to remove the mapping * @return {@code true} if the key mapping was successfully updated from the old value to the new value, * {@code false} if the current key mapping didn't match the expected value and was not updated. */ @@ -67,8 +67,8 @@ public interface SessionData /** * Gets the session data associated with the specified key. * - * @param key The key for which to retrieve the session data, must not be {@code null}. - * @return The session data associated with the key or {@code null} if none. + * @param key the key for which to retrieve the session data, must not be {@code null} + * @return the session data associated with the key or {@code null} if none */ @Nullable Object get( @Nonnull Object key ); @@ -76,9 +76,9 @@ public interface SessionData /** * Retrieve of compute the data associated with the specified key. * - * @param key The key for which to retrieve the session data, must not be {@code null}. - * @param supplier The supplier will compute the new value. - * @return The session data associated with the key. + * @param key the key for which to retrieve the session data, must not be {@code null} + * @param supplier the supplier will compute the new value + * @return the session data associated with the key */ @Nullable Object computeIfAbsent( @Nonnull Object key, @Nonnull Supplier supplier ); diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/Toolchain.java b/api/maven-api-core/src/main/java/org/apache/maven/api/Toolchain.java index 1d013ff19354..3bc15e48f650 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/Toolchain.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Toolchain.java @@ -41,7 +41,7 @@ public interface Toolchain /** * Gets the platform tool executable. * - * @param toolName the tool platform independent tool name. + * @param toolName the tool platform independent tool name * @return file representing the tool executable, or null if the tool cannot be found */ String findTool( String toolName ); 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 fb3e39b2f630..83117b6813b3 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 @@ -36,8 +36,8 @@ public interface VersionRange /** * Determines whether the specified version is contained within this range. * - * @param version The version to test, must not be {@code null}. - * @return {@code true} if this range contains the specified version, {@code false} otherwise. + * @param version the version to test, must not be {@code null} + * @return {@code true} if this range contains the specified version, {@code false} otherwise */ boolean contains( @Nonnull Version version ); diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/Mojo.java b/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/Mojo.java index a6217bff2a96..384616d2ab53 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/Mojo.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/Mojo.java @@ -39,7 +39,7 @@ public interface Mojo * This is the main trigger for the Mojo inside the Maven system, and allows * the Mojo to communicate errors. * - * @throws MojoException if a problem occurs. + * @throws MojoException if a problem occurs */ void execute(); diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/MojoException.java b/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/MojoException.java index 5e5b0c7eee1c..bd93e606733d 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/MojoException.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/plugin/MojoException.java @@ -37,7 +37,7 @@ public class MojoException protected String longMessage; /** - * Construct a new MojoExecutionException exception providing the source and a short and long message: + * Construct a new MojoException exception providing the source and a short and long message: * these messages are used to improve the message written at the end of Maven build. */ public MojoException( Object source, String shortMessage, String longMessage ) @@ -47,15 +47,6 @@ public MojoException( Object source, String shortMessage, String longMessage ) this.longMessage = longMessage; } - /** - * Construct a new MojoExecutionException exception wrapping an underlying Exception - * and providing a message. - */ - public MojoException( String message, Exception cause ) - { - super( message, cause ); - } - /** * Construct a new MojoExecutionException exception wrapping an underlying Throwable * and providing a message. @@ -78,7 +69,6 @@ public MojoException( String message ) * * @param cause the cause which is saved for later retrieval by the {@link #getCause()} method. * A {@code null} value is permitted, and indicates that the cause is nonexistent or unknown. - * @since 3.8.3 */ public MojoException( Throwable cause ) { diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactDeployerException.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactDeployerException.java index fbb206a53489..9fba9f02628b 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactDeployerException.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactDeployerException.java @@ -37,7 +37,7 @@ public class ArtifactDeployerException private static final long serialVersionUID = 7421964724059077698L; /** - * @param message The message of the error. + * @param message the message of the error * @param e {@link Exception} */ public ArtifactDeployerException( String message, Exception e ) diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactInstaller.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactInstaller.java index 937af56607f2..35046c6d3f5a 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactInstaller.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactInstaller.java @@ -38,8 +38,8 @@ public interface ArtifactInstaller extends Service { /** * @param request {@link ArtifactInstallerRequest} - * @throws ArtifactInstallerException in case of an error. - * @throws IllegalArgumentException in case {@code request} is {@code null}. + * @throws ArtifactInstallerException in case of an error + * @throws IllegalArgumentException in case {@code request} is {@code null} */ void install( ArtifactInstallerRequest request ); diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactInstallerException.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactInstallerException.java index e6c6dc6abd81..d045a5f82a73 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactInstallerException.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactInstallerException.java @@ -35,7 +35,7 @@ public class ArtifactInstallerException private static final long serialVersionUID = 3652561971360586373L; /** - * @param message The message of the error. + * @param message the message of the error * @param e {@link Exception} */ public ArtifactInstallerException( String message, Exception e ) diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactResolver.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactResolver.java index 99f49d241d2b..b695bb24e8e7 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactResolver.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactResolver.java @@ -38,9 +38,9 @@ public interface ArtifactResolver extends Service /** * @param request {@link ArtifactResolverRequest} * @return {@link ArtifactResolverResult} - * @throws ArtifactResolverException in case of an error. + * @throws ArtifactResolverException in case of an error * @throws IllegalArgumentException in case of parameter {@code buildingRequest} is {@code null} or - * parameter {@code mavenArtifact} is {@code null} or invalid. + * parameter {@code mavenArtifact} is {@code null} or invalid */ ArtifactResolverResult resolve( ArtifactResolverRequest request ); @@ -50,7 +50,7 @@ public interface ArtifactResolver extends Service * @return {@link ArtifactResolverResult} * @throws ArtifactResolverException in case of an error. * @throws IllegalArgumentException in case of parameter {@code buildingRequest} is {@code null} or - * parameter {@code coordinate} is {@code null} or invalid. + * parameter {@code coordinate} is {@code null} or invalid */ default ArtifactResolverResult resolve( Session session, Collection coordinates ) diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactResolverException.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactResolverException.java index ba6e5482cf34..2928c984d90d 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactResolverException.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactResolverException.java @@ -34,8 +34,8 @@ public class ArtifactResolverException private static final long serialVersionUID = 7252294837746943917L; /** - * @param message The message for the exception. - * @param e The exception itself. + * @param message the message for the exception + * @param e the exception itself */ public ArtifactResolverException( String message, Exception e ) { diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderProblem.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/BuilderProblem.java similarity index 70% rename from api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderProblem.java rename to api/maven-api-core/src/main/java/org/apache/maven/api/services/BuilderProblem.java index fef6ceae0dd4..d1bcf501b50f 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderProblem.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/BuilderProblem.java @@ -20,6 +20,9 @@ */ import org.apache.maven.api.annotations.Experimental; +import org.apache.maven.api.annotations.Immutable; +import org.apache.maven.api.annotations.Nonnull; +import org.apache.maven.api.annotations.Nullable; /** * Describes a problem that was encountered during project building. A problem can either be an exception that was @@ -28,7 +31,8 @@ * @since 4.0 */ @Experimental -public interface ProjectBuilderProblem +@Immutable +public interface BuilderProblem { /** @@ -37,15 +41,16 @@ public interface ProjectBuilderProblem * track the problem back to its origin. A concrete example for such a source hint can be the file path or URL from * which the settings were read. * - * @return The hint about the source of the problem or an empty string if unknown, never {@code null}. + * @return the hint about the source of the problem or an empty string if unknown, never {@code null} */ + @Nonnull String getSource(); /** * Gets the one-based index of the line containing the problem. The line number should refer to some text file that * is given by {@link #getSource()}. * - * @return The one-based index of the line containing the problem or a non-positive value if unknown. + * @return the one-based index of the line containing the problem or a non-positive value if unknown */ int getLineNumber(); @@ -53,7 +58,7 @@ public interface ProjectBuilderProblem * Gets the one-based index of the column containing the problem. The column number should refer to some text file * that is given by {@link #getSource()}. * - * @return The one-based index of the column containing the problem or non-positive value if unknown. + * @return the one-based index of the column containing the problem or non-positive value if unknown */ int getColumnNumber(); @@ -62,29 +67,47 @@ public interface ProjectBuilderProblem * {@link #getSource()}, {@link #getLineNumber()} and {@link #getColumnNumber()}. The exact syntax of the returned * value is undefined. * - * @return The location of the problem, never {@code null}. + * @return the location of the problem, never {@code null} */ + @Nonnull String getLocation(); /** * Gets the exception that caused this problem (if any). * - * @return The exception that caused this problem or {@code null} if not applicable. + * @return the exception that caused this problem or {@code null} if not applicable */ + @Nullable Exception getException(); /** * Gets the message that describes this problem. * - * @return The message describing this problem, never {@code null}. + * @return the message describing this problem, never {@code null} */ + @Nonnull String getMessage(); /** * Gets the severity level of this problem. * - * @return The severity level of this problem, never {@code null}. + * @return the severity level of this problem, never {@code null} */ - ProjectBuilderProblemSeverity getSeverity(); + @Nonnull + Severity getSeverity(); + /** + * The different severity levels for a problem, in decreasing order. + * + * @since 4.0 + */ + @Experimental + enum Severity + { + + FATAL, // + ERROR, // + WARNING // + + } } diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCollector.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCollector.java index e21b2c46925d..a8a651c38911 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCollector.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCollector.java @@ -45,9 +45,9 @@ public interface DependencyCollector extends Service * Note that this operation is only concerned about determining the coordinates of the * transitive dependencies and does not actually resolve the artifact files. * - * @param request The dependency collection request, must not be {@code null}. - * @return The collection result, never {@code null}. - * @throws DependencyCollectorException If the dependency tree could not be built. + * @param request the dependency collection request, must not be {@code null} + * @return the collection result, never {@code null} + * @throws DependencyCollectorException if the dependency tree could not be built * @throws IllegalArgumentException if an argument is null or invalid * * @see DependencyCollector#collect(Session, Project) @@ -62,10 +62,10 @@ public interface DependencyCollector extends Service * only concerned about determining the coordinates of the transitive dependencies and does not actually resolve the * artifact files. * - * @param session The {@link Session}, must not be {@code null}. - * @param root The Maven Dependency, must not be {@code null}. - * @return The collection result, never {@code null}. - * @throws DependencyCollectorException If the dependency tree could not be built. + * @param session the {@link Session}, must not be {@code null} + * @param root the Maven Dependency, must not be {@code null} + * @return the collection result, never {@code null} + * @throws DependencyCollectorException if the dependency tree could not be built * @throws IllegalArgumentException if an argument is null or invalid * @see #collect(DependencyCollectorRequest) */ @@ -81,10 +81,10 @@ default DependencyCollectorResult collect( @Nonnull Session session, * only concerned about determining the coordinates of the transitive dependencies and does not actually resolve the * artifact files. * - * @param session The {@link Session}, must not be {@code null}. - * @param project The {@link Project}, must not be {@code null}. - * @return The collection result, never {@code null}. - * @throws DependencyCollectorException If the dependency tree could not be built. + * @param session the {@link Session}, must not be {@code null} + * @param project the {@link Project}, must not be {@code null} + * @return the collection result, never {@code null} + * @throws DependencyCollectorException if the dependency tree could not be built * @throws IllegalArgumentException if an argument is null or invalid * @see #collect(DependencyCollectorRequest) */ @@ -100,10 +100,10 @@ default DependencyCollectorResult collect( @Nonnull Session session, * only concerned about determining the coordinates of the transitive dependencies and does not actually resolve the * artifact files. * - * @param session The {@link Session}, must not be {@code null}. - * @param artifact The {@link Artifact}, must not be {@code null}. - * @return The collection result, never {@code null}. - * @throws DependencyCollectorException If the dependency tree could not be built. + * @param session the {@link Session}, must not be {@code null} + * @param artifact the {@link Artifact}, must not be {@code null} + * @return the collection result, never {@code null} + * @throws DependencyCollectorException if the dependency tree could not be built * @throws IllegalArgumentException if an argument is null or invalid * @see #collect(DependencyCollectorRequest) */ diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCollectorException.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCollectorException.java index 019fedb6b31b..d173c0f789f3 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCollectorException.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCollectorException.java @@ -37,8 +37,8 @@ public class DependencyCollectorException private static final long serialVersionUID = -3134726259840210686L; /** - * @param message The message you would give for the exception. - * @param cause The cause which is related to the message. + * @param message the message you would give for the exception + * @param cause the cause which is related to the message */ public DependencyCollectorException( String message, Throwable cause ) { diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCollectorRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCollectorRequest.java index 345db90bac5f..f94b1e9a1a13 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCollectorRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCollectorRequest.java @@ -134,8 +134,8 @@ public DependencyCollectorRequestBuilder session( @Nonnull Session session ) * as a label for the root node of the graph in case no root dependency was specified. As such, the configured * root artifact is ignored if {@link #root(DependencyCoordinate)} has been set. * - * @param rootArtifact The root artifact for the dependency graph, may be {@code null}. - * @return This request for chaining, never {@code null}. + * @param rootArtifact the root artifact for the dependency graph, may be {@code null} + * @return this request for chaining, never {@code null} */ @Nonnull public DependencyCollectorRequestBuilder rootArtifact( @Nullable Artifact rootArtifact ) @@ -146,7 +146,7 @@ public DependencyCollectorRequestBuilder rootArtifact( @Nullable Artifact rootAr /** * @param root The root dependency - * @return This request for chaining, never {@code null}. + * @return this request for chaining, never {@code null} */ @Nonnull public DependencyCollectorRequestBuilder root( @Nonnull DependencyCoordinate root ) @@ -160,8 +160,8 @@ public DependencyCollectorRequestBuilder root( @Nonnull DependencyCoordinate roo * direct dependencies from the request will be merged with the direct dependencies from the root dependency's * artifact descriptor, giving higher priority to the dependencies from the request. * - * @param dependencies The direct dependencies, may be {@code null}. - * @return This request for chaining, never {@code null}. + * @param dependencies the direct dependencies, may be {@code null} + * @return this request for chaining, never {@code null} */ @Nonnull public DependencyCollectorRequestBuilder dependencies( @Nullable List dependencies ) @@ -173,8 +173,8 @@ public DependencyCollectorRequestBuilder dependencies( @Nullable List getExceptions(); /** * Gets the root node of the dependency graph. * - * @return The root node of the dependency graph or {@code null} if none. + * @return the root node of the dependency graph or {@code null} if none */ Node getRoot(); diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCoordinateFactory.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCoordinateFactory.java index d3c7a6ffd7c3..809a418a136d 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCoordinateFactory.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCoordinateFactory.java @@ -41,7 +41,7 @@ public interface DependencyCoordinateFactory extends Service * Creates a new {@link DependencyCoordinate} object from the request. * * @param request the request containing the various data - * @return a new {@link DependencyCoordinate} object. + * @return a new {@link DependencyCoordinate} object * * @throws IllegalArgumentException if {@code request} is null or * if {@code request.getSession()} is null or invalid diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/LookupException.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/LookupException.java index d88549112e87..abfa15da1716 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/LookupException.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/LookupException.java @@ -31,8 +31,8 @@ public class LookupException extends MavenException { /** - * @param message The message to give. - * @param e The {@link Exception}. + * @param message the message to give + * @param e the {@link Exception} */ public LookupException( String message, Exception e ) { @@ -40,7 +40,7 @@ public LookupException( String message, Exception e ) } /** - * @param e The {@link Exception}. + * @param e the {@link Exception} */ public LookupException( Exception e ) { diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/MessageBuilder.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/MessageBuilder.java index 1d86911995b6..446d0bc692c1 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/MessageBuilder.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/MessageBuilder.java @@ -141,7 +141,7 @@ public interface MessageBuilder * Append formatted content to the buffer. * @see String#format(String, Object...) * @param pattern a format string - * @param args arguments referenced by the format specifiers in the format string. + * @param args arguments referenced by the format specifiers in the format string * @return the current builder */ @Nonnull diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilder.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilder.java index e75ea4af547f..6a453075d8db 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilder.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilder.java @@ -50,14 +50,14 @@ public interface ProjectBuilder extends Service /** * Creates a {@link org.apache.maven.api.Project} from a POM file. * - * @param session The {@link Session}, must not be {@code null}. - * @param source The {@link ProjectBuilderSource}, must not be {@code null}. + * @param session the {@link Session}, must not be {@code null} + * @param source the {@link Source}, must not be {@code null} * @throws ProjectBuilderException if the project cannot be created * @throws IllegalArgumentException if an argument is {@code null} or invalid * @see #build(ProjectBuilderRequest) */ @Nonnull - default ProjectBuilderResult build( @Nonnull Session session, @Nonnull ProjectBuilderSource source ) + default ProjectBuilderResult build( @Nonnull Session session, @Nonnull Source source ) { return build( ProjectBuilderRequest.build( session, source ) ); } @@ -65,8 +65,8 @@ default ProjectBuilderResult build( @Nonnull Session session, @Nonnull ProjectBu /** * Creates a {@link org.apache.maven.api.Project} from a POM file. * - * @param session The {@link Session}, must not be {@code null}. - * @param path The {@link Path}, must not be {@code null}. + * @param session the {@link Session}, must not be {@code null} + * @param path the {@link Path}, must not be {@code null} * @throws ProjectBuilderException if the project cannot be created * @throws IllegalArgumentException if an argument is {@code null} or invalid * @see #build(ProjectBuilderRequest) @@ -80,8 +80,8 @@ default ProjectBuilderResult build( @Nonnull Session session, @Nonnull Path path /** * Creates a {@link org.apache.maven.api.Project} from an artifact. * - * @param session The {@link Session}, must not be {@code null}. - * @param artifact The {@link Artifact}, must not be {@code null}. + * @param session the {@link Session}, must not be {@code null} + * @param artifact the {@link Artifact}, must not be {@code null} * @throws ProjectBuilderException if the project cannot be created * @throws IllegalArgumentException if an argument is {@code null} or invalid * @see #build(ProjectBuilderRequest) @@ -95,8 +95,8 @@ default ProjectBuilderResult build( @Nonnull Session session, @Nonnull Artifact /** * Creates a {@link org.apache.maven.api.Project} from a coordinate. * - * @param session The {@link Session}, must not be {@code null}. - * @param coordinate The {@link ArtifactCoordinate}, must not be {@code null}. + * @param session the {@link Session}, must not be {@code null} + * @param coordinate the {@link ArtifactCoordinate}, must not be {@code null} * @throws ProjectBuilderException if the project cannot be created * @throws IllegalArgumentException if an argument is {@code null} or invalid * @see #build(ProjectBuilderRequest) diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderException.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderException.java index 2256bd144611..918913c0a22e 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderException.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderException.java @@ -31,8 +31,8 @@ public class ProjectBuilderException extends MavenException { /** - * @param message The message to give. - * @param e The {@link Exception}. + * @param message the message to give + * @param e the {@link Exception} */ public ProjectBuilderException( String message, Exception e ) { diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderRequest.java index 2e259091a3ae..174bcadbd967 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderRequest.java @@ -52,7 +52,7 @@ public interface ProjectBuilderRequest Optional getPath(); @Nonnull - Optional getSource(); + Optional getSource(); @Nonnull Optional getArtifact(); @@ -69,7 +69,7 @@ public interface ProjectBuilderRequest boolean isResolveDependencies(); @Nonnull - static ProjectBuilderRequest build( @Nonnull Session session, @Nonnull ProjectBuilderSource source ) + static ProjectBuilderRequest build( @Nonnull Session session, @Nonnull Source source ) { return builder() .session( nonNull( session, "session cannot be null" ) ) @@ -115,7 +115,7 @@ class ProjectBuilderRequestBuilder { Session session; Path path; - ProjectBuilderSource source; + Source source; Artifact artifact; ArtifactCoordinate coordinate; boolean allowStubModel; @@ -139,7 +139,7 @@ public ProjectBuilderRequestBuilder path( Path path ) return this; } - public ProjectBuilderRequestBuilder source( ProjectBuilderSource source ) + public ProjectBuilderRequestBuilder source( Source source ) { this.source = source; return this; @@ -179,7 +179,7 @@ private static class DefaultProjectBuilderRequest extends BaseRequest implements ProjectBuilderRequest { private final Path path; - private final ProjectBuilderSource source; + private final Source source; private final Artifact artifact; private final ArtifactCoordinate coordinate; private final boolean allowStubModel; @@ -190,7 +190,7 @@ private static class DefaultProjectBuilderRequest extends BaseRequest @SuppressWarnings( "checkstyle:ParameterNumber" ) DefaultProjectBuilderRequest( @Nonnull Session session, @Nullable Path path, - @Nullable ProjectBuilderSource source, + @Nullable Source source, @Nullable Artifact artifact, @Nullable ArtifactCoordinate coordinate, boolean allowStubModel, @@ -218,7 +218,7 @@ public Optional getPath() @Nonnull @Override - public Optional getSource() + public Optional getSource() { return Optional.ofNullable( source ); } diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderResult.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderResult.java index a76b6cab2ffb..0019b66aacda 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderResult.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderResult.java @@ -42,7 +42,7 @@ public interface ProjectBuilderResult * ::} but some of these coordinates may still be unknown at the point the exception * is thrown so this information is merely meant to assist the user. * - * @return The identifier of the project or an empty string if not known, never {@code null}. + * @return the identifier of the project or an empty string if not known, never {@code null} */ @Nonnull String getProjectId(); @@ -50,7 +50,7 @@ public interface ProjectBuilderResult /** * Gets the POM file from which the project was built. * - * @return The optional POM file. + * @return the optional POM file */ @Nonnull Optional getPomFile(); @@ -67,15 +67,15 @@ public interface ProjectBuilderResult /** * Gets the problems that were encountered during the project building. * - * @return The problems that were encountered during the project building, can be empty but never {@code null}. + * @return the problems that were encountered during the project building, can be empty but never {@code null} */ @Nonnull - Collection getProblems(); + Collection getProblems(); /** * Gets the result of the dependency resolution for the project. * - * @return The result of the dependency resolution for the project. + * @return the result of the dependency resolution for the project */ @Nonnull Optional getDependencyResolverResult(); diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/PrompterException.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/PrompterException.java index 4f892c749412..9a0de36c2953 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/PrompterException.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/PrompterException.java @@ -31,8 +31,8 @@ public class PrompterException extends MavenException { /** - * @param message The message to give. - * @param e The {@link Exception}. + * @param message the message to give + * @param e the {@link Exception} */ public PrompterException( String message, Exception e ) { diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/SettingsBuilder.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/SettingsBuilder.java new file mode 100644 index 000000000000..624a74f91125 --- /dev/null +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/SettingsBuilder.java @@ -0,0 +1,71 @@ +package org.apache.maven.api.services; + +/* + * 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. + */ + +import java.nio.file.Path; + +import org.apache.maven.api.Service; +import org.apache.maven.api.Session; +import org.apache.maven.api.annotations.Nonnull; + +/** + * Builds the effective settings from a user settings file and/or a global settings file. + */ +public interface SettingsBuilder extends Service +{ + + /** + * Builds the effective settings of the specified settings files. + * + * @param request the settings building request that holds the parameters, must not be {@code null} + * @return the result of the settings building, never {@code null} + * @throws SettingsBuilderException if the effective settings could not be built + */ + @Nonnull + SettingsBuilderResult build( @Nonnull SettingsBuilderRequest request ); + + /** + * Builds the effective settings of the specified settings sources. + * + * @return the result of the settings building, never {@code null} + * @throws SettingsBuilderException if the effective settings could not be built + */ + @Nonnull + default SettingsBuilderResult build( @Nonnull Session session, + @Nonnull Source globalSettingsSource, + @Nonnull Source userSettingsSource ) + { + return build( SettingsBuilderRequest.build( session, globalSettingsSource, userSettingsSource ) ); + } + + /** + * Builds the effective settings of the specified settings paths. + * + * @return the result of the settings building, never {@code null} + * @throws SettingsBuilderException if the effective settings could not be built + */ + @Nonnull + default SettingsBuilderResult build( @Nonnull Session session, + @Nonnull Path globalSettingsPath, + @Nonnull Path userSettingsPath ) + { + return build( SettingsBuilderRequest.build( session, globalSettingsPath, userSettingsPath ) ); + } +} diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderProblemSeverity.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/SettingsBuilderException.java similarity index 68% rename from api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderProblemSeverity.java rename to api/maven-api-core/src/main/java/org/apache/maven/api/services/SettingsBuilderException.java index 6af0257098fc..665b9086eb59 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderProblemSeverity.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/SettingsBuilderException.java @@ -9,7 +9,7 @@ * "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 + * 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 @@ -22,16 +22,22 @@ import org.apache.maven.api.annotations.Experimental; /** - * The different severity levels for a problem, in decreasing order. + * The Exception class throw by the {@link SettingsBuilder}. * * @since 4.0 */ @Experimental -public enum ProjectBuilderProblemSeverity +public class SettingsBuilderException + extends MavenException { + /** + * @param message the message to give + * @param e the {@link Exception} + */ + public SettingsBuilderException( String message, Exception e ) + { + super( message, e ); + } - FATAL, // - ERROR, // - WARNING // - + // TODO: add SettingsBuilderResult } diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/SettingsBuilderRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/SettingsBuilderRequest.java new file mode 100644 index 000000000000..0523f4d2320c --- /dev/null +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/SettingsBuilderRequest.java @@ -0,0 +1,204 @@ +package org.apache.maven.api.services; + +/* + * 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. + */ + +import java.nio.file.Path; +import java.util.Optional; + +import org.apache.maven.api.Session; +import org.apache.maven.api.annotations.Experimental; +import org.apache.maven.api.annotations.Immutable; +import org.apache.maven.api.annotations.Nonnull; +import org.apache.maven.api.annotations.NotThreadSafe; +import org.apache.maven.api.annotations.Nullable; + +import static org.apache.maven.api.services.BaseRequest.nonNull; + +/** + * Collects settings that control the building of effective settings. + */ +@Experimental +@Immutable +public interface SettingsBuilderRequest +{ + + @Nonnull + Session getSession(); + + /** + * Gets the global settings path. + * + * @return the global settings path or {@code null} if none + */ + @Nonnull + Optional getGlobalSettingsPath(); + + /** + * Gets the global settings source. + * + * @return the global settings source or {@code null} if none + */ + @Nonnull + Optional getGlobalSettingsSource(); + + /** + * Gets the user settings path. + * + * @return the user settings path or {@code null} if none + */ + @Nonnull + Optional getUserSettingsPath(); + + /** + * Gets the user settings source. + * + * @return the user settings source or {@code null} if none + */ + @Nonnull + Optional getUserSettingsSource(); + + @Nonnull + static SettingsBuilderRequest build( @Nonnull Session session, + @Nonnull Source globalSettingsSource, + @Nonnull Source userSettingsSource ) + { + return builder() + .session( nonNull( session, "session cannot be null" ) ) + .globalSettingsSource( nonNull( globalSettingsSource, "globalSettingsSource cannot be null" ) ) + .userSettingsSource( nonNull( userSettingsSource, "userSettingsSource cannot be null" ) ) + .build(); + } + + @Nonnull + static SettingsBuilderRequest build( @Nonnull Session session, + @Nonnull Path globalSettingsPath, + @Nonnull Path userSettingsPath ) + { + return builder() + .session( nonNull( session, "session cannot be null" ) ) + .globalSettingsPath( nonNull( globalSettingsPath, "globalSettingsPath cannot be null" ) ) + .userSettingsPath( nonNull( userSettingsPath, "userSettingsPath cannot be null" ) ) + .build(); + } + + @Nonnull + static SettingsBuilderRequestBuilder builder() + { + return new SettingsBuilderRequestBuilder(); + } + + @NotThreadSafe + class SettingsBuilderRequestBuilder + { + Session session; + Path globalSettingsPath; + Source globalSettingsSource; + Path userSettingsPath; + Source userSettingsSource; + + public SettingsBuilderRequestBuilder session( Session session ) + { + this.session = session; + return this; + } + + public SettingsBuilderRequestBuilder globalSettingsPath( Path globalSettingsPath ) + { + this.globalSettingsPath = globalSettingsPath; + return this; + } + + public SettingsBuilderRequestBuilder globalSettingsSource( Source globalSettingsSource ) + { + this.globalSettingsSource = globalSettingsSource; + return this; + } + + public SettingsBuilderRequestBuilder userSettingsPath( Path userSettingsPath ) + { + this.userSettingsPath = userSettingsPath; + return this; + } + + public SettingsBuilderRequestBuilder userSettingsSource( Source userSettingsSource ) + { + this.userSettingsSource = userSettingsSource; + return this; + } + + public SettingsBuilderRequest build() + { + return new DefaultSettingsBuilderRequest( session, + globalSettingsPath, globalSettingsSource, + userSettingsPath, userSettingsSource ); + } + + private static class DefaultSettingsBuilderRequest extends BaseRequest + implements SettingsBuilderRequest + { + private final Path globalSettingsPath; + private final Source globalSettingsSource; + private final Path userSettingsPath; + private final Source userSettingsSource; + + @SuppressWarnings( "checkstyle:ParameterNumber" ) + DefaultSettingsBuilderRequest( @Nonnull Session session, + @Nullable Path globalSettingsPath, + @Nullable Source globalSettingsSource, + @Nullable Path userSettingsPath, + @Nullable Source userSettingsSource ) + { + super( session ); + this.globalSettingsPath = globalSettingsPath; + this.globalSettingsSource = globalSettingsSource; + this.userSettingsPath = userSettingsPath; + this.userSettingsSource = userSettingsSource; + } + + @Nonnull + @Override + public Optional getGlobalSettingsPath() + { + return Optional.ofNullable( globalSettingsPath ); + } + + @Nonnull + @Override + public Optional getGlobalSettingsSource() + { + return Optional.ofNullable( globalSettingsSource ); + } + + @Nonnull + @Override + public Optional getUserSettingsPath() + { + return Optional.ofNullable( userSettingsPath ); + } + + @Nonnull + @Override + public Optional getUserSettingsSource() + { + return Optional.ofNullable( userSettingsSource ); + } + } + } +} diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/SettingsBuilderResult.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/SettingsBuilderResult.java new file mode 100644 index 000000000000..8cd1fc5757ad --- /dev/null +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/SettingsBuilderResult.java @@ -0,0 +1,48 @@ +package org.apache.maven.api.services; + +/* + * 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. + */ + +import java.util.List; + +import org.apache.maven.api.annotations.Nonnull; +import org.apache.maven.api.settings.Settings; + +public interface SettingsBuilderResult +{ + + /** + * Gets the assembled settings. + * + * @return the assembled settings, never {@code null} + */ + @Nonnull + Settings getEffectiveSettings(); + + /** + * Gets the problems that were encountered during the settings building. Note that only problems of severity + * {@link BuilderProblem.Severity#WARNING} and below are reported here. Problems with a higher severity level cause + * the settings builder to fail with a {@link SettingsBuilderException}. + * + * @return the problems that were encountered during the settings building, can be empty but never {@code null} + */ + @Nonnull + List getProblems(); + +} diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderSource.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java similarity index 96% rename from api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderSource.java rename to api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java index 1add18cb12fb..08eea48c300d 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectBuilderSource.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java @@ -30,7 +30,7 @@ * @since 4.0 */ @Experimental -public interface ProjectBuilderSource +public interface Source { InputStream getInputStream() throws IOException; diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainManagerException.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainManagerException.java index 2c8a2bd8fe59..eb543818041c 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainManagerException.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainManagerException.java @@ -31,8 +31,8 @@ public class ToolchainManagerException extends MavenException { /** - * @param message The message to give. - * @param e The {@link Exception}. + * @param message the message to give + * @param e the {@link Exception} */ public ToolchainManagerException( String message, Exception e ) { diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilder.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilder.java new file mode 100644 index 000000000000..5e57291cf26e --- /dev/null +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilder.java @@ -0,0 +1,42 @@ +package org.apache.maven.api.services; + +/* + * 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. + */ + +import org.apache.maven.api.Service; +import org.apache.maven.api.annotations.Experimental; + +/** + * Builds the effective toolchains from a user toolchains file and/or a global toolchains file. + */ +@Experimental + +public interface ToolchainsBuilder extends Service +{ + + /** + * Builds the effective toolchains of the specified toolchains files. + * + * @param request the toolchains building request that holds the parameters, must not be {@code null} + * @return the result of the toolchains building, never {@code null} + * @throws ToolchainsBuilderException if the effective toolchains could not be built + */ + ToolchainsBuilderResult build( ToolchainsBuilderRequest request ); + +} diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilderException.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilderException.java new file mode 100644 index 000000000000..19bd724ed86f --- /dev/null +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilderException.java @@ -0,0 +1,43 @@ +package org.apache.maven.api.services; + +/* + * 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. + */ + +import org.apache.maven.api.annotations.Experimental; + +/** + * The Exception class throw by the {@link ToolchainsBuilder}. + * + * @since 4.0 + */ +@Experimental +public class ToolchainsBuilderException + extends MavenException +{ + /** + * @param message the message to give + * @param e the {@link Exception} + */ + public ToolchainsBuilderException( String message, Exception e ) + { + super( message, e ); + } + + // TODO: add ToolchainsBuilderResult +} diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilderRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilderRequest.java new file mode 100644 index 000000000000..085950b2ffa9 --- /dev/null +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilderRequest.java @@ -0,0 +1,196 @@ +package org.apache.maven.api.services; + +/* + * 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. + */ + +import java.nio.file.Path; +import java.util.Optional; + +import org.apache.maven.api.Session; +import org.apache.maven.api.annotations.Nonnull; +import org.apache.maven.api.annotations.NotThreadSafe; +import org.apache.maven.api.annotations.Nullable; + +import static org.apache.maven.api.services.BaseRequest.nonNull; + +public interface ToolchainsBuilderRequest +{ + @Nonnull + Session getSession(); + + /** + * Gets the global Toolchains path. + * + * @return the global Toolchains path or {@code null} if none + */ + @Nonnull + Optional getGlobalToolchainsPath(); + + /** + * Gets the global Toolchains source. + * + * @return the global Toolchains source or {@code null} if none + */ + @Nonnull + Optional getGlobalToolchainsSource(); + + /** + * Gets the user Toolchains path. + * + * @return the user Toolchains path or {@code null} if none + */ + @Nonnull + Optional getUserToolchainsPath(); + + /** + * Gets the user Toolchains source. + * + * @return the user Toolchains source or {@code null} if none + */ + @Nonnull + Optional getUserToolchainsSource(); + + @Nonnull + static ToolchainsBuilderRequest build( @Nonnull Session session, + @Nonnull Source globalToolchainsSource, + @Nonnull Source userToolchainsSource ) + { + return builder() + .session( nonNull( session, "session cannot be null" ) ) + .globalToolchainsSource( nonNull( globalToolchainsSource, "globalToolchainsSource cannot be null" ) ) + .userToolchainsSource( nonNull( userToolchainsSource, "userToolchainsSource cannot be null" ) ) + .build(); + } + + @Nonnull + static ToolchainsBuilderRequest build( @Nonnull Session session, + @Nonnull Path globalToolchainsPath, + @Nonnull Path userToolchainsPath ) + { + return builder() + .session( nonNull( session, "session cannot be null" ) ) + .globalToolchainsPath( nonNull( globalToolchainsPath, "globalToolchainsPath cannot be null" ) ) + .userToolchainsPath( nonNull( userToolchainsPath, "userToolchainsPath cannot be null" ) ) + .build(); + } + + @Nonnull + static ToolchainsBuilderRequestBuilder builder() + { + return new ToolchainsBuilderRequestBuilder(); + } + + @NotThreadSafe + class ToolchainsBuilderRequestBuilder + { + Session session; + Path globalToolchainsPath; + Source globalToolchainsSource; + Path userToolchainsPath; + Source userToolchainsSource; + + public ToolchainsBuilderRequestBuilder session( Session session ) + { + this.session = session; + return this; + } + + public ToolchainsBuilderRequestBuilder globalToolchainsPath( Path globalToolchainsPath ) + { + this.globalToolchainsPath = globalToolchainsPath; + return this; + } + + public ToolchainsBuilderRequestBuilder globalToolchainsSource( Source globalToolchainsSource ) + { + this.globalToolchainsSource = globalToolchainsSource; + return this; + } + + public ToolchainsBuilderRequestBuilder userToolchainsPath( Path userToolchainsPath ) + { + this.userToolchainsPath = userToolchainsPath; + return this; + } + + public ToolchainsBuilderRequestBuilder userToolchainsSource( Source userToolchainsSource ) + { + this.userToolchainsSource = userToolchainsSource; + return this; + } + + public ToolchainsBuilderRequest build() + { + return new ToolchainsBuilderRequestBuilder.DefaultToolchainsBuilderRequest( session, + globalToolchainsPath, globalToolchainsSource, + userToolchainsPath, userToolchainsSource ); + } + + private static class DefaultToolchainsBuilderRequest extends BaseRequest + implements ToolchainsBuilderRequest + { + private final Path globalToolchainsPath; + private final Source globalToolchainsSource; + private final Path userToolchainsPath; + private final Source userToolchainsSource; + + @SuppressWarnings( "checkstyle:ParameterNumber" ) + DefaultToolchainsBuilderRequest( @Nonnull Session session, + @Nullable Path globalToolchainsPath, + @Nullable Source globalToolchainsSource, + @Nullable Path userToolchainsPath, + @Nullable Source userToolchainsSource ) + { + super( session ); + this.globalToolchainsPath = globalToolchainsPath; + this.globalToolchainsSource = globalToolchainsSource; + this.userToolchainsPath = userToolchainsPath; + this.userToolchainsSource = userToolchainsSource; + } + + @Nonnull + @Override + public Optional getGlobalToolchainsPath() + { + return Optional.ofNullable( globalToolchainsPath ); + } + + @Nonnull + @Override + public Optional getGlobalToolchainsSource() + { + return Optional.ofNullable( globalToolchainsSource ); + } + + @Nonnull + @Override + public Optional getUserToolchainsPath() + { + return Optional.ofNullable( userToolchainsPath ); + } + + @Nonnull + @Override + public Optional getUserToolchainsSource() + { + return Optional.ofNullable( userToolchainsSource ); + } + } + } +} diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilderResult.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilderResult.java new file mode 100644 index 000000000000..5be2cea19b05 --- /dev/null +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ToolchainsBuilderResult.java @@ -0,0 +1,47 @@ +package org.apache.maven.api.services; + +/* + * 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. + */ + +import java.util.List; + +import org.apache.maven.api.annotations.Nonnull; +import org.apache.maven.api.toolchain.PersistedToolchains; + +public interface ToolchainsBuilderResult +{ + /** + * Gets the assembled toolchains. + * + * @return the assembled toolchains, never {@code null} + */ + @Nonnull + PersistedToolchains getEffectiveToolchains(); + + /** + * Gets the problems that were encountered during the settings building. Note that only problems of severity + * {@link BuilderProblem.Severity#WARNING} and below are reported here. Problems with a higher severity level cause + * the settings builder to fail with a {@link ToolchainsBuilderException}. + * + * @return the problems that were encountered during the settings building, can be empty but never {@code null} + */ + @Nonnull + List getProblems(); + +} diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionParser.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionParser.java index ed5e69ba75c7..700019d715b7 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionParser.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionParser.java @@ -36,9 +36,9 @@ public interface VersionParser extends Service /** * Parses the specified version string, for example "1.0". * - * @param version The version string to parse, must not be {@code null}. - * @return The parsed version, never {@code null}. - * @throws VersionParserException If the string violates the syntax rules of this scheme. + * @param version the version string to parse, must not be {@code null} + * @return the parsed version, never {@code null} + * @throws VersionParserException if the string violates the syntax rules of this scheme * @see org.apache.maven.api.Session#parseVersion(String) */ @Nonnull @@ -47,9 +47,9 @@ public interface VersionParser extends Service /** * Parses the specified version range specification, for example "[1.0,2.0)". * - * @param range The range specification to parse, must not be {@code null}. - * @return The parsed version range, never {@code null}. - * @throws VersionParserException If the range specification violates the syntax rules of this scheme. + * @param range the range specification to parse, must not be {@code null} + * @return the parsed version range, never {@code null} + * @throws VersionParserException if the range specification violates the syntax rules of this scheme */ @Nonnull VersionRange parseVersionRange( @Nonnull String range ); diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionParserException.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionParserException.java index f0c4481132e2..ba016dc0f0e1 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionParserException.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionParserException.java @@ -31,8 +31,8 @@ public class VersionParserException extends MavenException { /** - * @param message The message to give. - * @param e The {@link Exception}. + * @param message the message to give + * @param e the {@link Exception} */ public VersionParserException( String message, Exception e ) { diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/xml/XmlReaderException.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/xml/XmlReaderException.java index 2cc30c0c26cf..23141db4cc9a 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/xml/XmlReaderException.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/xml/XmlReaderException.java @@ -33,8 +33,8 @@ public class XmlReaderException { /** - * @param message The message for the exception. - * @param e The exception itself. + * @param message the message for the exception + * @param e the exception itself */ public XmlReaderException( String message, Exception e ) { diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/xml/XmlReaderRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/xml/XmlReaderRequest.java index 05e4423039bf..086594d62534 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/xml/XmlReaderRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/xml/XmlReaderRequest.java @@ -65,7 +65,7 @@ interface Transformer * @param source The source value * @param fieldName A description of the field being interpolated. The implementation may use this to * log stuff. - * @return The interpolated value. + * @return the interpolated value */ String transform( String source, String fieldName ); } diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/xml/XmlWriterException.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/xml/XmlWriterException.java index 099b6ea12b19..4202ab2ef385 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/xml/XmlWriterException.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/xml/XmlWriterException.java @@ -33,8 +33,8 @@ public class XmlWriterException { /** - * @param message The message for the exception. - * @param e The exception itself. + * @param message the message for the exception + * @param e the exception itself */ public XmlWriterException( String message, Exception e ) { diff --git a/api/maven-api-model/src/main/mdo/maven.mdo b/api/maven-api-model/src/main/mdo/maven.mdo index 7bd835d0987b..b6ef13a14125 100644 --- a/api/maven-api-model/src/main/mdo/maven.mdo +++ b/api/maven-api-model/src/main/mdo/maven.mdo @@ -2304,7 +2304,7 @@ /** * Gets the identifier of the plugin. * - * @return The plugin id in the form {@code ::}, never {@code null}. + * @return the plugin id in the form {@code ::}, never {@code null} */ public String getId() { diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectBuilder.java index 959f8fc69823..4944df1354b6 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectBuilder.java @@ -40,11 +40,10 @@ import org.apache.maven.api.services.DependencyCollectorResult; import org.apache.maven.api.services.ProjectBuilder; import org.apache.maven.api.services.ProjectBuilderException; -import org.apache.maven.api.services.ProjectBuilderProblem; -import org.apache.maven.api.services.ProjectBuilderProblemSeverity; +import org.apache.maven.api.services.BuilderProblem; import org.apache.maven.api.services.ProjectBuilderRequest; import org.apache.maven.api.services.ProjectBuilderResult; -import org.apache.maven.api.services.ProjectBuilderSource; +import org.apache.maven.api.services.Source; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.model.building.ModelProblem; @@ -91,7 +90,7 @@ public ProjectBuilderResult build( ProjectBuilderRequest request ) } else if ( request.getSource().isPresent() ) { - ProjectBuilderSource source = request.getSource().get(); + Source source = request.getSource().get(); ModelSource modelSource = new ModelSource() { @Override @@ -153,14 +152,14 @@ public Optional getProject() @Nonnull @Override - public Collection getProblems() + public Collection getProblems() { return new MappedCollection<>( res.getProblems(), this::toProblem ); } - private ProjectBuilderProblem toProblem( ModelProblem problem ) + private BuilderProblem toProblem( ModelProblem problem ) { - return new ProjectBuilderProblem() + return new BuilderProblem() { @Override public String getSource() @@ -228,9 +227,9 @@ public String getMessage() } @Override - public ProjectBuilderProblemSeverity getSeverity() + public Severity getSeverity() { - return ProjectBuilderProblemSeverity.valueOf( problem.getSeverity().name() ); + return Severity.valueOf( problem.getSeverity().name() ); } }; } diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultSettingsBuilder.java b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultSettingsBuilder.java new file mode 100644 index 000000000000..f3f4d14a9023 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultSettingsBuilder.java @@ -0,0 +1,188 @@ +package org.apache.maven.internal.impl; + +/* + * 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. + */ + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.maven.api.annotations.Nonnull; +import org.apache.maven.api.services.BuilderProblem; +import org.apache.maven.api.services.SettingsBuilder; +import org.apache.maven.api.services.SettingsBuilderException; +import org.apache.maven.api.services.SettingsBuilderRequest; +import org.apache.maven.api.services.SettingsBuilderResult; +import org.apache.maven.api.services.Source; +import org.apache.maven.api.settings.Settings; +import org.apache.maven.settings.building.DefaultSettingsBuildingRequest; +import org.apache.maven.settings.building.SettingsBuildingException; +import org.apache.maven.settings.building.SettingsBuildingResult; +import org.apache.maven.settings.building.SettingsProblem; +import org.apache.maven.settings.building.SettingsSource; + +@Named +@Singleton +public class DefaultSettingsBuilder implements SettingsBuilder +{ + + private final org.apache.maven.settings.building.SettingsBuilder builder; + + @Inject + public DefaultSettingsBuilder( org.apache.maven.settings.building.SettingsBuilder builder ) + { + this.builder = builder; + } + + @Nonnull + @Override + public SettingsBuilderResult build( SettingsBuilderRequest request ) + throws SettingsBuilderException, IllegalArgumentException + { + DefaultSession session = ( DefaultSession ) request.getSession(); + try + { + DefaultSettingsBuildingRequest req = new DefaultSettingsBuildingRequest(); + req.setUserProperties( toProperties( session.getUserProperties() ) ); + req.setSystemProperties( toProperties( session.getSystemProperties() ) ); + if ( request.getGlobalSettingsSource().isPresent() ) + { + req.setGlobalSettingsSource( new MappedSettingsSource( request.getGlobalSettingsSource().get() ) ); + } + if ( request.getGlobalSettingsPath().isPresent() ) + { + req.setGlobalSettingsFile( request.getGlobalSettingsPath().get().toFile() ); + } + if ( request.getUserSettingsSource().isPresent() ) + { + req.setUserSettingsSource( new MappedSettingsSource( request.getUserSettingsSource().get() ) ); + } + if ( request.getUserSettingsPath().isPresent() ) + { + req.setUserSettingsFile( request.getUserSettingsPath().get().toFile() ); + } + SettingsBuildingResult result = builder.build( req ); + return new SettingsBuilderResult() + { + @Override + public Settings getEffectiveSettings() + { + return result.getEffectiveSettings(); + } + + @Override + public List getProblems() + { + return new MappedList<>( result.getProblems(), MappedBuilderProblem::new ); + } + }; + } + catch ( SettingsBuildingException e ) + { + throw new SettingsBuilderException( "Unable to build settings", e ); + } + } + + private Properties toProperties( Map map ) + { + Properties properties = new Properties(); + properties.putAll( map ); + return properties; + } + + private static class MappedSettingsSource implements SettingsSource + { + private final Source source; + + MappedSettingsSource( Source source ) + { + this.source = source; + } + + @Override + public InputStream getInputStream() throws IOException + { + return source.getInputStream(); + } + + @Override + public String getLocation() + { + return source.getLocation(); + } + } + + private static class MappedBuilderProblem implements BuilderProblem + { + private final SettingsProblem problem; + + MappedBuilderProblem( SettingsProblem problem ) + { + this.problem = problem; + } + + @Override + public String getSource() + { + return problem.getSource(); + } + + @Override + public int getLineNumber() + { + return problem.getLineNumber(); + } + + @Override + public int getColumnNumber() + { + return problem.getColumnNumber(); + } + + @Override + public String getLocation() + { + return problem.getLocation(); + } + + @Override + public Exception getException() + { + return problem.getException(); + } + + @Override + public String getMessage() + { + return problem.getMessage(); + } + + @Override + public Severity getSeverity() + { + return Severity.valueOf( problem.getSeverity().name() ); + } + } +} diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultToolchainsBuilder.java b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultToolchainsBuilder.java new file mode 100644 index 000000000000..41b7fdf69d15 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultToolchainsBuilder.java @@ -0,0 +1,187 @@ +package org.apache.maven.internal.impl; + +/* + * 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. + */ + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.maven.api.annotations.Nonnull; +import org.apache.maven.api.services.BuilderProblem; +import org.apache.maven.api.services.ToolchainsBuilder; +import org.apache.maven.api.services.ToolchainsBuilderException; +import org.apache.maven.api.services.ToolchainsBuilderRequest; +import org.apache.maven.api.services.ToolchainsBuilderResult; +import org.apache.maven.api.services.Source; +import org.apache.maven.toolchain.building.DefaultToolchainsBuildingRequest; +import org.apache.maven.toolchain.building.ToolchainsBuildingException; +import org.apache.maven.toolchain.building.ToolchainsBuildingResult; +import org.apache.maven.api.toolchain.PersistedToolchains; + +@Named +@Singleton +public class DefaultToolchainsBuilder implements ToolchainsBuilder +{ + + private final org.apache.maven.toolchain.building.ToolchainsBuilder builder; + + @Inject + public DefaultToolchainsBuilder( org.apache.maven.toolchain.building.ToolchainsBuilder builder ) + { + this.builder = builder; + } + + @Nonnull + @Override + public ToolchainsBuilderResult build( ToolchainsBuilderRequest request ) + throws ToolchainsBuilderException, IllegalArgumentException + { + DefaultSession session = ( DefaultSession ) request.getSession(); + try + { + DefaultToolchainsBuildingRequest req = new DefaultToolchainsBuildingRequest(); + if ( request.getGlobalToolchainsSource().isPresent() ) + { + req.setGlobalToolchainsSource( + new MappedToolchainsSource( request.getGlobalToolchainsSource().get() ) ); + } + else if ( request.getGlobalToolchainsPath().isPresent() ) + { + req.setGlobalToolchainsSource( new org.apache.maven.building.FileSource( + request.getGlobalToolchainsPath().get().toFile() ) ); + } + if ( request.getUserToolchainsSource().isPresent() ) + { + req.setUserToolchainsSource( new MappedToolchainsSource( request.getUserToolchainsSource().get() ) ); + } + else if ( request.getUserToolchainsPath().isPresent() ) + { + req.setUserToolchainsSource( new org.apache.maven.building.FileSource( + request.getUserToolchainsPath().get().toFile() ) ); + } + ToolchainsBuildingResult result = builder.build( req ); + return new ToolchainsBuilderResult() + { + @Override + public PersistedToolchains getEffectiveToolchains() + { + return result.getEffectiveToolchains(); + } + + @Override + public List getProblems() + { + return new MappedList<>( result.getProblems(), MappedBuilderProblem::new ); + } + }; + } + catch ( ToolchainsBuildingException e ) + { + throw new ToolchainsBuilderException( "Unable to build Toolchains", e ); + } + } + + private Properties toProperties( Map map ) + { + Properties properties = new Properties(); + properties.putAll( map ); + return properties; + } + + private static class MappedToolchainsSource implements org.apache.maven.building.Source + { + private final Source source; + + MappedToolchainsSource( Source source ) + { + this.source = source; + } + + @Override + public InputStream getInputStream() throws IOException + { + return source.getInputStream(); + } + + @Override + public String getLocation() + { + return source.getLocation(); + } + } + + private static class MappedBuilderProblem implements BuilderProblem + { + private final org.apache.maven.building.Problem problem; + + MappedBuilderProblem( org.apache.maven.building.Problem problem ) + { + this.problem = problem; + } + + @Override + public String getSource() + { + return problem.getSource(); + } + + @Override + public int getLineNumber() + { + return problem.getLineNumber(); + } + + @Override + public int getColumnNumber() + { + return problem.getColumnNumber(); + } + + @Override + public String getLocation() + { + return problem.getLocation(); + } + + @Override + public Exception getException() + { + return problem.getException(); + } + + @Override + public String getMessage() + { + return problem.getMessage(); + } + + @Override + public Severity getSeverity() + { + return Severity.valueOf( problem.getSeverity().name() ); + } + } +}