Skip to content
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,8 +19,10 @@
package org.apache.maven.api.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* The annotated element can be {@code null}.
Expand All @@ -31,4 +33,5 @@
@Experimental
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
public @interface Nullable {}
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,25 @@ class Builder {

private final Logger logger;
private Lookup lookup = EMPTY_LOOKUP;

@Nullable
private Path cwd;

@Nullable
private Path mavenHome;

@Nullable
private Path userHome;

@Nullable
private InputStream stdIn;

@Nullable
private OutputStream stdOut;

@Nullable
private OutputStream stdErr;

private boolean embedded = false;

private Builder(
Expand Down Expand Up @@ -361,12 +374,25 @@ private static class ParserRequestImpl implements ParserRequest {
private final MessageBuilderFactory messageBuilderFactory;
private final List<String> args;
private final Lookup lookup;

@Nullable
private final Path cwd;

@Nullable
private final Path mavenHome;

@Nullable
private final Path userHome;

@Nullable
private final InputStream stdIn;

@Nullable
private final OutputStream stdOut;

@Nullable
private final OutputStream stdErr;

private final boolean embedded;

private ParserRequestImpl(
Expand All @@ -376,12 +402,12 @@ private ParserRequestImpl(
Logger logger,
MessageBuilderFactory messageBuilderFactory,
Lookup lookup,
Path cwd,
Path mavenHome,
Path userHome,
InputStream stdIn,
OutputStream stdOut,
OutputStream stdErr,
@Nullable Path cwd,
@Nullable Path mavenHome,
@Nullable Path userHome,
@Nullable InputStream stdIn,
@Nullable OutputStream stdOut,
@Nullable OutputStream stdErr,
boolean embedded) {
this.command = requireNonNull(command, "command");
this.commandName = requireNonNull(commandName, "commandName");
Expand Down Expand Up @@ -428,31 +454,37 @@ public Lookup lookup() {
return lookup;
}

@Nullable
@Override
public Path cwd() {
return cwd;
}

@Nullable
@Override
public Path mavenHome() {
return mavenHome;
}

@Nullable
@Override
public Path userHome() {
return userHome;
}

@Nullable
@Override
public InputStream stdIn() {
return stdIn;
}

@Nullable
@Override
public OutputStream stdOut() {
return stdOut;
}

@Nullable
@Override
public OutputStream stdErr() {
return stdErr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.maven.api.annotations.Nullable;
import org.apache.maven.api.cli.Logger;

import static java.util.Objects.requireNonNull;
Expand All @@ -34,10 +35,10 @@ public class AccumulatingLogger implements Logger {
private final AtomicReference<List<Entry>> entries = new AtomicReference<>(new CopyOnWriteArrayList<>());

@Override
public void log(Level level, String message, Throwable error) {
public void log(Level level, String message, @Nullable Throwable error) {
requireNonNull(level, "level");
requireNonNull(message, "message");
entries.get().add(new Entry(level, message, error));
requireNonNull(entries.get()).add(new Entry(level, message, error));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;

/**
* Indicates when the dependency will be used.
Expand Down Expand Up @@ -106,6 +107,7 @@ public enum DependencyScope {
*
* @param id the identifier of the scope (case-sensitive)
*/
@Nullable
public static DependencyScope forId(String id) {
return IDS.get(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

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

/**
* The option of a Java command-line tool where to place the paths to some dependencies.
Expand Down Expand Up @@ -170,13 +171,15 @@ public static Modular patchModule(@Nonnull String moduleName) {
*
* @see #location()
*/
@Nullable
private final JavaFileManager.Location location;

/**
* The tools option for this path, or {@code null} if none.
*
* @see #option()
*/
@Nullable
private final String option;

/**
Expand All @@ -185,7 +188,7 @@ public static Modular patchModule(@Nonnull String moduleName) {
* @param location the {@code javax.tool} enumeration value, or {@code null} if none.
* @param option the Java tools option for this path, or {@code null} if none
*/
JavaPathType(JavaFileManager.Location location, String option) {
JavaPathType(@Nullable JavaFileManager.Location location, @Nullable String option) {
this.location = location;
this.option = option;
}
Expand Down Expand Up @@ -260,7 +263,7 @@ public String[] option(Iterable<? extends Path> paths) {
/**
* Implementation shared with {@link Modular}.
*/
final String[] format(String moduleName, Iterable<? extends Path> paths) {
final String[] format(@Nullable String moduleName, Iterable<? extends Path> paths) {
if (option == null) {
throw new IllegalStateException("No option is associated to this path type.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,29 @@ static Builder newBuilder() {
}

class Builder {
@Nullable
private Map<String, String> userProperties;

@Nullable
private Map<String, String> systemProperties;

@Nullable
private Instant startTime;

@Nullable
private Path topDirectory;

@Nullable
private Path rootDirectory;

private Builder() {}

private Builder(
Map<String, String> userProperties,
Map<String, String> systemProperties,
Instant startTime,
Path topDirectory,
Path rootDirectory) {
@Nullable Map<String, String> userProperties,
@Nullable Map<String, String> systemProperties,
@Nullable Instant startTime,
@Nullable Path topDirectory,
@Nullable Path rootDirectory) {
this.userProperties = userProperties;
this.systemProperties = systemProperties;
this.startTime = startTime;
Expand Down Expand Up @@ -163,7 +172,12 @@ public Builder withRootDirectory(@Nullable Path rootDirectory) {
}

public ProtoSession build() {
return new Impl(userProperties, systemProperties, startTime, topDirectory, rootDirectory);
return new Impl(
requireNonNull(userProperties, "userProperties cannot be null"),
requireNonNull(systemProperties, "systemProperties cannot be null"),
requireNonNull(startTime, "startTime cannot be null"),
requireNonNull(topDirectory, "topDirectory cannot be null"),
rootDirectory);
}

private static class Impl implements ProtoSession {
Expand All @@ -172,14 +186,16 @@ private static class Impl implements ProtoSession {
private final Map<String, String> effectiveProperties;
private final Instant startTime;
private final Path topDirectory;

@Nullable
private final Path rootDirectory;

private Impl(
Map<String, String> userProperties,
Map<String, String> systemProperties,
Instant startTime,
Path topDirectory,
Path rootDirectory) {
@Nonnull Map<String, String> userProperties,
@Nonnull Map<String, String> systemProperties,
@Nonnull Instant startTime,
@Nonnull Path topDirectory,
@Nullable Path rootDirectory) {
this.userProperties = Map.copyOf(userProperties);
this.systemProperties = Map.copyOf(systemProperties);
Map<String, String> cp = new HashMap<>(systemProperties);
Expand Down
39 changes: 33 additions & 6 deletions api/maven-api-core/src/main/java/org/apache/maven/api/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ default Map<String, String> getEffectiveProperties() {
* @see ArtifactCoordinatesFactory#create(Session, String, String, String, String)
*/
@Nonnull
ArtifactCoordinates createArtifactCoordinates(String groupId, String artifactId, String version, String extension);
ArtifactCoordinates createArtifactCoordinates(
@Nullable String groupId,
@Nullable String artifactId,
@Nullable String version,
@Nullable String extension);

/**
* Shortcut for {@code getService(ArtifactFactory.class).create(...)}.
Expand All @@ -280,7 +284,12 @@ default Map<String, String> getEffectiveProperties() {
*/
@Nonnull
ArtifactCoordinates createArtifactCoordinates(
String groupId, String artifactId, String version, String classifier, String extension, String type);
@Nullable String groupId,
@Nullable String artifactId,
@Nullable String version,
@Nullable String classifier,
@Nullable String extension,
@Nullable String type);

/**
* Shortcut for {@code getService(ArtifactFactory.class).create(...)}.
Expand Down Expand Up @@ -327,7 +336,11 @@ ArtifactCoordinates createArtifactCoordinates(
* @see org.apache.maven.api.services.ArtifactFactory#create(Session, String, String, String, String)
*/
@Nonnull
Artifact createArtifact(String groupId, String artifactId, String version, String extension);
Artifact createArtifact(
@Nullable String groupId,
@Nullable String artifactId,
@Nullable String version,
@Nullable String extension);

/**
* Shortcut for {@code getService(ArtifactFactory.class).create(...)}.
Expand All @@ -344,7 +357,12 @@ ArtifactCoordinates createArtifactCoordinates(
*/
@Nonnull
Artifact createArtifact(
String groupId, String artifactId, String version, String classifier, String extension, String type);
@Nullable String groupId,
@Nullable String artifactId,
@Nullable String version,
@Nullable String classifier,
@Nullable String extension,
@Nullable String type);

/**
* Shortcut for {@code getService(ArtifactFactory.class).createProduced(...)}.
Expand All @@ -358,7 +376,11 @@ Artifact createArtifact(
* @see org.apache.maven.api.services.ArtifactFactory#createProduced(Session, String, String, String, String)
*/
@Nonnull
ProducedArtifact createProducedArtifact(String groupId, String artifactId, String version, String extension);
ProducedArtifact createProducedArtifact(
@Nullable String groupId,
@Nullable String artifactId,
@Nullable String version,
@Nullable String extension);

/**
* Shortcut for {@code getService(ArtifactFactory.class).createProduced(...)}.
Expand All @@ -375,7 +397,12 @@ Artifact createArtifact(
*/
@Nonnull
ProducedArtifact createProducedArtifact(
String groupId, String artifactId, String version, String classifier, String extension, String type);
@Nullable String groupId,
@Nullable String artifactId,
@Nullable String version,
@Nullable String classifier,
@Nullable String extension,
@Nullable String type);

/**
* Shortcut for {@code getService(ArtifactResolver.class).resolve(...)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public static boolean deployBuildPom(@Nullable Map<String, ?> userProperties) {
return doGet(userProperties, Constants.MAVEN_DEPLOY_BUILD_POM, true);
}

private static boolean doGet(Map<String, ?> userProperties, String key, boolean def) {
private static boolean doGet(@Nullable Map<String, ?> userProperties, String key, boolean def) {
return doGet(userProperties != null ? userProperties.get(key) : null, def);
}

private static boolean doGet(Object val, boolean def) {
private static boolean doGet(@Nullable Object val, boolean def) {
if (val instanceof Boolean bool) {
return bool;
} else if (val != null) {
Expand Down
Loading