Skip to content

Modernize codebase with Java improvements #2277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.maven.api;

import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;

/**
* Represents a Java toolchain in the Maven build system.
Expand All @@ -41,5 +42,6 @@
@Experimental
public interface JavaToolchain extends Toolchain {

@Nonnull
String getJavaHome();
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ public interface Lifecycle extends ExtensibleEnum {
* @return the unique identifier for this lifecycle
*/
@Override
@Nonnull
String id();

/**
* Collection of main phases for this lifecycle.
*
* @return the collection of top-level phases in this lifecycle
*/
@Nonnull
Collection<Phase> phases();

/**
Expand All @@ -78,6 +80,7 @@ public interface Lifecycle extends ExtensibleEnum {
*
* @return the collection of phases in Maven 3 compatible ordering
*/
@Nonnull
default Collection<Phase> v3phases() {
return phases();
}
Expand All @@ -87,6 +90,7 @@ default Collection<Phase> v3phases() {
*
* @return a stream of all phases in this lifecycle, including nested phases
*/
@Nonnull
default Stream<Phase> allPhases() {
return phases().stream().flatMap(Phase::allPhases);
}
Expand All @@ -97,11 +101,12 @@ default Stream<Phase> allPhases() {
*
* @return the collection of phase aliases
*/
@Nonnull
Collection<Alias> aliases();

/**
* A phase in the lifecycle.
*
* <p>
* A phase is identified by its name. It also contains a list of plugins bound to that phase,
* a list of {@link Link links}, and a list of sub-phases. This forms a tree of phases.
*/
Expand Down Expand Up @@ -167,7 +172,9 @@ interface Phase {
* @return a stream of all phases
*/
@Nonnull
Stream<Phase> allPhases();
default Stream<Phase> allPhases() {
return Stream.concat(Stream.of(this), phases().stream().flatMap(Lifecycle.Phase::allPhases));
}
}

/**
Expand All @@ -180,13 +187,15 @@ interface Alias {
*
* @return the Maven 3 phase name
*/
@Nonnull
String v3Phase();

/**
* Returns the Maven 4 phase name.
*
* @return the Maven 4 phase name
*/
@Nonnull
String v4Phase();
}

Expand All @@ -206,13 +215,15 @@ enum Kind {
*
* @return the link kind
*/
@Nonnull
Kind kind();

/**
* Returns the pointer to the target phase.
*
* @return the phase pointer
*/
@Nonnull
Pointer pointer();
}

Expand All @@ -228,13 +239,15 @@ enum Type {
*
* @return the phase name
*/
@Nonnull
String phase();

/**
* Returns the type of pointer (PROJECT, DEPENDENCIES, or CHILDREN).
*
* @return the pointer type
*/
@Nonnull
Type type();
}

Expand All @@ -244,6 +257,7 @@ interface PhasePointer extends Pointer {
*
* @return the PROJECT pointer type
*/
@Nonnull
default Type type() {
return Type.PROJECT;
}
Expand All @@ -255,13 +269,15 @@ interface DependenciesPointer extends Pointer {
*
* @return the dependency scope, or "all" if not specified
*/
@Nonnull
String scope(); // default: all

/**
* Returns the type of pointer, which is always DEPENDENCIES for a DependenciesPointer.
*
* @return the DEPENDENCIES pointer type
*/
@Nonnull
default Type type() {
return Type.DEPENDENCIES;
}
Expand All @@ -273,6 +289,7 @@ interface ChildrenPointer extends Pointer {
*
* @return the CHILDREN pointer type
*/
@Nonnull
default Type type() {
return Type.CHILDREN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.Map;

import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable;
import org.apache.maven.api.toolchain.ToolchainModel;

/**
Expand Down Expand Up @@ -69,13 +71,15 @@ public interface Toolchain {
*
* @return the toolchain type
*/
@Nonnull
String getType();

/**
* Gets the underlying toolchain model.
*
* @return the toolchain model
*/
@Nonnull
ToolchainModel getModel();

/**
Expand All @@ -84,7 +88,8 @@ public interface Toolchain {
* @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);
@Nullable
String findTool(@Nonnull String toolName);

/**
* Let the toolchain decide if it matches requirements defined
Expand All @@ -93,5 +98,5 @@ public interface Toolchain {
* @param requirements key value pair, may not be {@code null}
* @return {@code true} if the requirements match, otherwise {@code false}
*/
boolean matchesRequirements(Map<String, String> requirements);
boolean matchesRequirements(@Nonnull Map<String, String> requirements);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.apache.maven.api.annotations.Consumer;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.plugin.descriptor.lifecycle.Lifecycle;

/**
Expand All @@ -37,5 +38,6 @@
@Consumer
public interface LifecycleProvider {

@Nonnull
List<Lifecycle> getLifecycles();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.function.Supplier;

import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable;
import org.apache.maven.api.annotations.Provider;

/**
Expand All @@ -46,7 +48,7 @@ public interface Log {
*
* @param content the message to log
*/
void debug(CharSequence content);
void debug(@Nullable CharSequence content);

/**
* Sends a message (and accompanying exception) to the user in the <b>debug</b> error level.
Expand All @@ -55,19 +57,19 @@ public interface Log {
* @param content the message to log
* @param error the error that caused this log
*/
void debug(CharSequence content, Throwable error);
void debug(@Nullable CharSequence content, @Nullable Throwable error);

/**
* Sends an exception to the user in the <b>debug</b> error level.
* The stack trace for this exception will be output when this error level is enabled.
*
* @param error the error that caused this log
*/
void debug(Throwable error);
void debug(@Nullable Throwable error);

void debug(Supplier<String> content);
void debug(@Nonnull Supplier<String> content);

void debug(Supplier<String> content, Throwable error);
void debug(@Nonnull Supplier<String> content, @Nullable Throwable error);

/**
* {@return true if the <b>info</b> error level is enabled}
Expand All @@ -79,7 +81,7 @@ public interface Log {
*
* @param content the message to log
*/
void info(CharSequence content);
void info(@Nullable CharSequence content);

/**
* Sends a message (and accompanying exception) to the user in the <b>info</b> error level.
Expand All @@ -88,19 +90,19 @@ public interface Log {
* @param content the message to log
* @param error the error that caused this log
*/
void info(CharSequence content, Throwable error);
void info(@Nullable CharSequence content, @Nullable Throwable error);

/**
* Sends an exception to the user in the <b>info</b> error level.
* The stack trace for this exception will be output when this error level is enabled.
*
* @param error the error that caused this log
*/
void info(Throwable error);
void info(@Nullable Throwable error);

void info(Supplier<String> content);
void info(@Nonnull Supplier<String> content);

void info(Supplier<String> content, Throwable error);
void info(@Nonnull Supplier<String> content, @Nullable Throwable error);

/**
* {@return true if the <b>warn</b> error level is enabled}
Expand All @@ -112,7 +114,7 @@ public interface Log {
*
* @param content the message to log
*/
void warn(CharSequence content);
void warn(@Nullable CharSequence content);

/**
* Sends a message (and accompanying exception) to the user in the <b>warn</b> error level.
Expand All @@ -121,19 +123,19 @@ public interface Log {
* @param content the message to log
* @param error the error that caused this log
*/
void warn(CharSequence content, Throwable error);
void warn(@Nullable CharSequence content, @Nullable Throwable error);

/**
* Sends an exception to the user in the <b>warn</b> error level.
* The stack trace for this exception will be output when this error level is enabled.
*
* @param error the error that caused this log
*/
void warn(Throwable error);
void warn(@Nullable Throwable error);

void warn(Supplier<String> content);
void warn(@Nonnull Supplier<String> content);

void warn(Supplier<String> content, Throwable error);
void warn(@Nonnull Supplier<String> content, @Nullable Throwable error);

/**
* {@return true if the <b>error</b> error level is enabled}
Expand All @@ -145,7 +147,7 @@ public interface Log {
*
* @param content the message to log
*/
void error(CharSequence content);
void error(@Nullable CharSequence content);

/**
* Sends a message (and accompanying exception) to the user in the <b>error</b> error level.
Expand All @@ -154,17 +156,17 @@ public interface Log {
* @param content the message to log
* @param error the error that caused this log
*/
void error(CharSequence content, Throwable error);
void error(@Nullable CharSequence content, @Nullable Throwable error);

/**
* Sends an exception to the user in the <b>error</b> error level.
* The stack trace for this exception will be output when this error level is enabled.
*
* @param error the error that caused this log
*/
void error(Throwable error);
void error(@Nullable Throwable error);

void error(Supplier<String> content);
void error(@Nonnull Supplier<String> content);

void error(Supplier<String> content, Throwable error);
void error(@Nonnull Supplier<String> content, @Nullable Throwable error);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.apache.maven.api.services;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.apache.maven.api.ProducedArtifact;
import org.apache.maven.api.Service;
Expand Down Expand Up @@ -51,7 +51,7 @@ public interface ArtifactInstaller extends Service {
* {@code artifact} is {@code null}
*/
default void install(Session session, ProducedArtifact artifact) {
install(session, Collections.singletonList(artifact));
install(session, List.of(artifact));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.maven.api.services;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -62,7 +61,7 @@ static ArtifactInstallerRequest build(Session session, Collection<ProducedArtifa
class ArtifactInstallerRequestBuilder {
Session session;
RequestTrace trace;
Collection<ProducedArtifact> artifacts = Collections.emptyList();
Collection<ProducedArtifact> artifacts = List.of();

ArtifactInstallerRequestBuilder() {}

Expand All @@ -80,7 +79,7 @@ public ArtifactInstallerRequestBuilder trace(RequestTrace trace) {

@Nonnull
public ArtifactInstallerRequestBuilder artifacts(@Nullable Collection<ProducedArtifact> artifacts) {
this.artifacts = artifacts != null ? artifacts : Collections.emptyList();
this.artifacts = artifacts != null ? artifacts : List.of();
return this;
}

Expand Down
Loading