diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverResult.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverResult.java index 456cd6b505be..e70cc4b4bd14 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverResult.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverResult.java @@ -18,16 +18,11 @@ */ package org.apache.maven.api.services; -import java.io.IOException; -import java.lang.module.ModuleDescriptor; import java.nio.file.Path; import java.util.List; import java.util.Map; -import java.util.Optional; import org.apache.maven.api.Dependency; -import org.apache.maven.api.DependencyScope; -import org.apache.maven.api.JavaPathType; import org.apache.maven.api.Node; import org.apache.maven.api.PathType; import org.apache.maven.api.annotations.Experimental; @@ -102,45 +97,4 @@ public interface DependencyResolverResult extends Result getDependencies(); - - /** - * Returns the Java module name of the dependency at the given path. - * The given dependency should be one of the paths returned by {@link #getDependencies()}. - * The module name is extracted from the {@code module-info.class} file if present, otherwise from - * the {@code "Automatic-Module-Name"} attribute of the {@code META-INF/MANIFEST.MF} file if present. - * - *

A typical usage is to invoke this method for all dependencies having a - * {@link DependencyScope#TEST TEST} or {@link DependencyScope#TEST_ONLY TEST_ONLY} - * {@linkplain Dependency#getScope() scope}. An {@code --add-reads} option may need - * to be generated for compiling and running the test classes that use such dependencies.

- * - * @param dependency path to the dependency for which to get the module name - * @return module name of the dependency at the given path, or empty if the dependency is not modular - * @throws IOException if the module information of the specified dependency cannot be read - */ - Optional getModuleName(@Nonnull Path dependency) throws IOException; - - /** - * Returns the Java module descriptor of the dependency at the given path. - * The given dependency should be one of the paths returned by {@link #getDependencies()}. - * The module descriptor is extracted from the {@code module-info.class} file if present. - * - *

{@link #getModuleName(Path)} is preferred when only the module name is desired, - * because a name may be present even if the descriptor is absent. This method is for - * cases when more information is desired, such as the set of exported packages.

- * - * @param dependency path to the dependency for which to get the module name - * @return module name of the dependency at the given path, or empty if the dependency is not modular - * @throws IOException if the module information of the specified dependency cannot be read - */ - Optional getModuleDescriptor(@Nonnull Path dependency) throws IOException; - - /** - * If the module path contains at least one filename-based auto-module, prepares a warning message. - * The module path is the collection of dependencies associated with {@link JavaPathType#MODULES}. - * It is caller's responsibility to send the message to a logger. - * - * @return warning message if at least one filename-based auto-module was found - */ - Optional warningForFilenameBasedAutomodules(); } diff --git a/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultDependencyResolverResult.java b/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultDependencyResolverResult.java index fa7ace6e0d05..ea27f21f74cd 100644 --- a/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultDependencyResolverResult.java +++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultDependencyResolverResult.java @@ -27,7 +27,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import java.util.function.Predicate; @@ -35,7 +34,6 @@ import org.apache.maven.api.JavaPathType; import org.apache.maven.api.Node; import org.apache.maven.api.PathType; -import org.apache.maven.api.services.DependencyResolverException; import org.apache.maven.api.services.DependencyResolverRequest; import org.apache.maven.api.services.DependencyResolverResult; @@ -378,18 +376,6 @@ public Map getDependencies() { return dependencies; } - @Override - public Optional getModuleDescriptor(Path dependency) throws IOException { - Object value = cache.getModuleInfo(dependency).descriptors.get(dependency); - return (value instanceof ModuleDescriptor moduleDescriptor) ? Optional.of(moduleDescriptor) : Optional.empty(); - } - - @Override - public Optional getModuleName(Path dependency) throws IOException { - return Optional.ofNullable( - name(cache.getModuleInfo(dependency).descriptors.get(dependency))); - } - /** * Returns the module name for the given value of the {@link PathModularization#descriptors} map. */ @@ -402,13 +388,4 @@ private static String name(final Object value) { return null; } } - - @Override - public Optional warningForFilenameBasedAutomodules() { - try { - return cache.warningForFilenameBasedAutomodules(dispatchedPaths.get(JavaPathType.MODULES)); - } catch (IOException e) { - throw new DependencyResolverException("Cannot read module information.", e); - } - } } diff --git a/impl/maven-impl/src/main/java/org/apache/maven/impl/PathModularizationCache.java b/impl/maven-impl/src/main/java/org/apache/maven/impl/PathModularizationCache.java index e04ce136da24..8aa51074e719 100644 --- a/impl/maven-impl/src/main/java/org/apache/maven/impl/PathModularizationCache.java +++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/PathModularizationCache.java @@ -20,13 +20,10 @@ import java.io.IOException; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.StringJoiner; import java.util.function.Predicate; import org.apache.maven.api.JavaPathType; @@ -158,32 +155,4 @@ Optional selectPathType(Set types, Predicate filte } return Optional.ofNullable(selected); } - - /** - * If the module-path contains a filename-based auto-module, prepares a warning message. - * It is caller's responsibility to send the message to a logger. - * - * @param modulePaths content of the module path, or {@code null} if none - * @return warning message if at least one filename-based auto-module was found - * @throws IOException if an error occurred while reading module information - */ - Optional warningForFilenameBasedAutomodules(Collection modulePaths) throws IOException { - if (modulePaths == null) { - return Optional.empty(); - } - var automodulesDetected = new ArrayList(); - for (Path p : modulePaths) { - getModuleInfo(p).addIfFilenameBasedAutomodules(automodulesDetected); - } - if (automodulesDetected.isEmpty()) { - return Optional.empty(); - } - String lineSeparator = System.lineSeparator(); - var joiner = new StringJoiner( - lineSeparator + " - ", - "Filename-based automodules detected on the module path: " + lineSeparator + " - ", - lineSeparator + "Please don't publish this project to a public artifact repository."); - automodulesDetected.forEach(joiner::add); - return Optional.of(joiner.toString()); - } }