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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 4 additions & 56 deletions compat/maven-plugin-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ under the License.
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-support</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.woodstox</groupId>
<artifactId>woodstox-core</artifactId>
Expand Down Expand Up @@ -92,62 +96,6 @@ under the License.

<build>
<plugins>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<configuration>
<velocityBasedir>${project.basedir}/../../src/mdo</velocityBasedir>
</configuration>
<executions>
<execution>
<id>velocity-lifecycle</id>
<goals>
<goal>velocity</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<templates>
<template>reader-stax.vm</template>
<template>writer-stax.vm</template>
</templates>
<params>
<param>packageModelV4=org.apache.maven.api.plugin.descriptor.lifecycle</param>
<param>packageToolV4=org.apache.maven.plugin.lifecycle.io</param>
</params>
<models>
<model>../../api/maven-api-plugin/src/main/mdo/lifecycle.mdo</model>
</models>
<version>2.0.0</version>
</configuration>
</execution>
<execution>
<id>velocity-plugin</id>
<goals>
<goal>velocity</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<templates>
<template>reader-stax.vm</template>
<template>writer-stax.vm</template>
</templates>
<params>
<param>packageModelV3=org.apache.maven.plugin.descriptor</param>
<param>packageModelV4=org.apache.maven.api.plugin.descriptor</param>
<param>packageToolV4=org.apache.maven.plugin.descriptor.io</param>
</params>
<models>
<model>../../api/maven-api-plugin/src/main/mdo/plugin.mdo</model>
</models>
<version>2.0.0</version>
</configuration>
</execution>
<execution>
<id>modello-site-docs</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.siom79.japicmp</groupId>
<artifactId>japicmp-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
import org.apache.maven.properties.internal.SystemProperties;

import static java.util.Objects.requireNonNull;
import static org.apache.maven.cling.invoker.Utils.getCanonicalPath;
import static org.apache.maven.cling.invoker.Utils.or;
import static org.apache.maven.cling.invoker.Utils.prefix;
import static org.apache.maven.cling.invoker.Utils.stripLeadingAndTrailingQuotes;
import static org.apache.maven.cling.invoker.Utils.toMap;
import static org.apache.maven.cling.invoker.CliUtils.getCanonicalPath;
import static org.apache.maven.cling.invoker.CliUtils.or;
import static org.apache.maven.cling.invoker.CliUtils.prefix;
import static org.apache.maven.cling.invoker.CliUtils.stripLeadingAndTrailingQuotes;
import static org.apache.maven.cling.invoker.CliUtils.toMap;

public abstract class BaseParser implements Parser {

Expand Down Expand Up @@ -335,7 +335,7 @@ protected Path getTopDirectory(LocalContext context) {

@Nullable
protected Path getRootDirectory(LocalContext context) {
return Utils.findRoot(context.topDirectory);
return CliUtils.findRoot(context.topDirectory);
}

protected Map<String, String> populateSystemProperties(LocalContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class CWD implements Supplier<Path> {
* Creates instance out of {@link Path}.
*/
public static CWD create(Path path) {
return new CWD(Utils.getCanonicalPath(path));
return new CWD(CliUtils.getCanonicalPath(path));
}

private Path directory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
/**
* Various utilities, mostly to bridge "old" and "new" stuff, like Properties vs Maps, File vs Paths, etc.
*/
public final class Utils {
private Utils() {}
public final class CliUtils {
private CliUtils() {}

@Nonnull
public static String stripLeadingAndTrailingQuotes(String str) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.apache.maven.jline.MessageUtils;

import static java.util.Objects.requireNonNull;
import static org.apache.maven.cling.invoker.Utils.toMap;
import static org.apache.maven.cling.invoker.CliUtils.toMap;

public abstract class CommonsCliOptions implements Options {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public LookupContext(InvokerRequest invokerRequest) {
public LookupContext(InvokerRequest invokerRequest, boolean containerCapsuleManaged) {
this.invokerRequest = requireNonNull(invokerRequest);
this.cwd = CWD.create(invokerRequest.cwd());
this.installationDirectory = Utils.getCanonicalPath(invokerRequest.installationDirectory());
this.userDirectory = Utils.getCanonicalPath(invokerRequest.userHomeDirectory());
this.installationDirectory = CliUtils.getCanonicalPath(invokerRequest.installationDirectory());
this.userDirectory = CliUtils.getCanonicalPath(invokerRequest.userHomeDirectory());
this.containerCapsuleManaged = containerCapsuleManaged;
this.logger = invokerRequest.parserRequest().logger();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@
import org.slf4j.spi.LocationAwareLogger;

import static java.util.Objects.requireNonNull;
import static org.apache.maven.cling.invoker.Utils.toMavenExecutionRequestLoggingLevel;
import static org.apache.maven.cling.invoker.Utils.toProperties;
import static org.apache.maven.cling.invoker.CliUtils.toMavenExecutionRequestLoggingLevel;
import static org.apache.maven.cling.invoker.CliUtils.toProperties;

/**
* Lookup invoker implementation, that boots up DI container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.codehaus.plexus.DefaultPlexusContainer;

import static java.util.Objects.requireNonNull;
import static org.apache.maven.cling.invoker.Utils.toPlexusLoggingLevel;
import static org.apache.maven.cling.invoker.CliUtils.toPlexusLoggingLevel;

/**
* Container capsule backed by Plexus Container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import org.slf4j.ILoggerFactory;

import static java.util.Objects.requireNonNull;
import static org.apache.maven.cling.invoker.Utils.toPlexusLoggingLevel;
import static org.apache.maven.cling.invoker.CliUtils.toPlexusLoggingLevel;

/**
* Container capsule backed by Plexus Container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.apache.maven.api.services.InterpolatorException;
import org.apache.maven.cling.invoker.CommonsCliOptions;

import static org.apache.maven.cling.invoker.Utils.createInterpolator;
import static org.apache.maven.cling.invoker.CliUtils.createInterpolator;

public class CommonsCliMavenOptions extends CommonsCliOptions implements MavenOptions {
public static CommonsCliMavenOptions parse(String source, String[] args) throws ParseException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
import org.apache.maven.api.services.model.ModelProcessor;
import org.apache.maven.api.toolchain.PersistedToolchains;
import org.apache.maven.cling.event.ExecutionEventLogger;
import org.apache.maven.cling.invoker.CliUtils;
import org.apache.maven.cling.invoker.LookupContext;
import org.apache.maven.cling.invoker.LookupInvoker;
import org.apache.maven.cling.invoker.Utils;
import org.apache.maven.cling.transfer.ConsoleMavenTransferListener;
import org.apache.maven.cling.transfer.QuietMavenTransferListener;
import org.apache.maven.cling.transfer.SimplexTransferListener;
Expand Down Expand Up @@ -257,7 +257,7 @@ protected void populateRequest(MavenContext context, Lookup lookup, MavenExecuti

// project present, but we could not determine rootDirectory: extra work needed
if (context.invokerRequest.rootDirectory().isEmpty()) {
Path rootDirectory = Utils.findMandatoryRoot(context.invokerRequest.topDirectory());
Path rootDirectory = CliUtils.findMandatoryRoot(context.invokerRequest.topDirectory());
request.setMultiModuleProjectDirectory(rootDirectory.toFile());
request.setRootDirectory(rootDirectory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.apache.maven.api.services.InterpolatorException;
import org.apache.maven.cling.invoker.CommonsCliOptions;

import static org.apache.maven.cling.invoker.Utils.createInterpolator;
import static org.apache.maven.cling.invoker.CliUtils.createInterpolator;

/**
* Implementation of {@link EncryptOptions} (base + mvnenc).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.apache.maven.api.services.InterpolatorException;
import org.apache.maven.cling.invoker.CommonsCliOptions;

import static org.apache.maven.cling.invoker.Utils.createInterpolator;
import static org.apache.maven.cling.invoker.CliUtils.createInterpolator;

/**
* Implementation of {@link ShellOptions} (base + shell).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.
*/
package org.apache.maven.internal.impl;

import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;

class CoreUtils {
public static <T> T nonNull(T t) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Or should we use Objects.requireNonNull(T) instead? The exception is not the same (NullPointerException instead of IllegalArgumentException), but the former became the standard usage in the JDK API. It is also consistent with the code that just rely on implicit null-check, especially since Java 14 automatically generates an exception message with the name of the parameter that was null. Finally, Objects.requireNonNull(T) as some JVM-level optimization (the @ForceInline annotation) that we can't reproduce in our own null-check method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: the automatically generated message cited in above comment is for implicit null-checks, not for the exception thrown by Objects.requireNonNull(T). I would propose that when a method uses the parameter immediately like below:

public void foo(String biz) {
   if (biz.equals("foo")) {
   }
}

If biz is null, Java 14 and latter while automatically generates a message saying "Cannot invoke "String.equals(Object)" because "biz" is null". Therefore, it may be better (compared to no message at all) to not invoke a method such as nonNull if we accept that the exception is NullPointerException. For cases where the implicit null check would be too late, the Objects.requireNonNull methods throw an exception of type consistent with the implicit null checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, agreed, Eliotte raised the same issue a while ago. Though the point of this PR was just to avoid the Utils class name clash, so we can create a subsequent PR to remove those custom methods.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also agreed. This PR is an improvement by itself, so merge it and then fix that.

if (t == null) {
throw new IllegalArgumentException();
}
return t;
}

public static <T> T nonNull(T t, String name) {
if (t == null) {
throw new IllegalArgumentException(name + " cannot be null");
}
return t;
}

public static <T> T cast(Class<T> clazz, Object o, String name) {
if (!clazz.isInstance(o)) {
if (o == null) {
throw new IllegalArgumentException(name + " is null");
}
throw new IllegalArgumentException(name + " is not an instance of " + clazz.getName());
}
return clazz.cast(o);
}

public static <U, V> List<V> map(Collection<U> list, Function<U, V> mapper) {
return list.stream().map(mapper).filter(Objects::nonNull).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.apache.maven.project.MavenProject;
import org.eclipse.sisu.Typed;

import static org.apache.maven.impl.Utils.nonNull;
import static org.apache.maven.internal.impl.CoreUtils.nonNull;

@Named
@Typed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import org.apache.maven.project.artifact.ProjectArtifact;
import org.eclipse.aether.util.artifact.ArtifactIdUtils;

import static org.apache.maven.impl.Utils.nonNull;
import static org.apache.maven.internal.impl.CoreUtils.nonNull;

public class DefaultProject implements Project {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
import org.apache.maven.project.MavenProject;
import org.eclipse.sisu.Typed;

import static org.apache.maven.impl.Utils.map;
import static org.apache.maven.impl.Utils.nonNull;
import static org.apache.maven.internal.impl.CoreUtils.map;
import static org.apache.maven.internal.impl.CoreUtils.nonNull;

@Named
@Typed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;

import static org.apache.maven.impl.Utils.map;
import static org.apache.maven.impl.Utils.nonNull;
import static org.apache.maven.internal.impl.CoreUtils.map;
import static org.apache.maven.internal.impl.CoreUtils.nonNull;

public class DefaultSession extends AbstractSession implements InternalMavenSession {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.apache.maven.impl.resolver.type.DefaultType;

import static java.util.function.Function.identity;
import static org.apache.maven.impl.Utils.nonNull;
import static org.apache.maven.internal.impl.CoreUtils.nonNull;

@Named
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.impl.InternalSession;

import static org.apache.maven.impl.Utils.cast;
import static org.apache.maven.internal.impl.CoreUtils.cast;

public interface InternalMavenSession extends InternalSession {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@
import org.eclipse.aether.repository.ArtifactRepository;
import org.eclipse.aether.transfer.TransferResource;

import static org.apache.maven.impl.Utils.map;
import static org.apache.maven.impl.Utils.nonNull;
import static org.apache.maven.impl.ImplUtils.map;
import static org.apache.maven.impl.ImplUtils.nonNull;

public abstract class AbstractSession implements InternalSession {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.maven.api.Version;
import org.apache.maven.api.annotations.Nonnull;

import static org.apache.maven.impl.Utils.nonNull;
import static org.apache.maven.impl.ImplUtils.nonNull;

/**
* A wrapper class around a maven resolver artifact.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.maven.api.VersionConstraint;
import org.apache.maven.api.annotations.Nonnull;

import static org.apache.maven.impl.Utils.nonNull;
import static org.apache.maven.impl.ImplUtils.nonNull;

/**
* A wrapper class around a maven resolver artifact.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.maven.api.services.ArtifactCoordinatesFactoryRequest;
import org.eclipse.aether.artifact.ArtifactType;

import static org.apache.maven.impl.Utils.nonNull;
import static org.apache.maven.impl.ImplUtils.nonNull;

@Named
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.eclipse.aether.deployment.DeployRequest;
import org.eclipse.aether.deployment.DeploymentException;

import static org.apache.maven.impl.Utils.nonNull;
import static org.apache.maven.impl.ImplUtils.nonNull;

/**
* Implementation of {@link ArtifactDeployer} service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.apache.maven.api.services.ArtifactFactoryRequest;
import org.eclipse.aether.artifact.ArtifactType;

import static org.apache.maven.impl.Utils.nonNull;
import static org.apache.maven.impl.ImplUtils.nonNull;

@Named
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.eclipse.aether.installation.InstallRequest;
import org.eclipse.aether.installation.InstallationException;

import static org.apache.maven.impl.Utils.nonNull;
import static org.apache.maven.impl.ImplUtils.nonNull;

@Named
@Singleton
Expand Down
Loading