Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into instanceof-and-cast
Browse files Browse the repository at this point in the history
# Conflicts:
#	compat/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java
  • Loading branch information
breun committed Jan 8, 2025
2 parents 7a5d1bb + 7546361 commit 213c8b3
Show file tree
Hide file tree
Showing 26 changed files with 208 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface Dependency extends Artifact {
/**
* {@return the type of the dependency}
* A dependency can be a <abbr>JAR</abbr> file,
* a modular-<abbr>JAR</abbr> if it is intended to be placed on the module-path,
* a modular-<abbr>JAR</abbr> if it is intended to be placed on the module path,
* a <abbr>JAR</abbr> containing test classes, <i>etc.</i>
*
* @see DependencyCoordinates#getType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

/**
* {@code ArtifactCoordinates} completed with information about how the artifact will be used.
* This information include the dependency type (main classes, test classes, <i>etc.</i>),
* a scope (compile-time, run-time <i>etc.</i>), an obligation (whether the dependency
* This information includes the dependency type (main classes, test classes, <i>etc.</i>),
* a scope (compile, runtime <i>etc.</i>), an obligation (whether the dependency
* is optional or mandatory), and possible exclusions for transitive dependencies.
* The {@linkplain #getVersionConstraint() version} and the {@linkplain #getOptional() obligation}
* may not be defined precisely.
Expand All @@ -41,21 +41,21 @@ public interface DependencyCoordinates extends ArtifactCoordinates {
/**
* {@return the type of the dependency}
* A dependency can be a <abbr>JAR</abbr> file,
* a modular-<abbr>JAR</abbr> if it is intended to be placed on the module-path,
* a modular-<abbr>JAR</abbr> if it is intended to be placed on the module path,
* a <abbr>JAR</abbr> containing test classes, <i>etc.</i>
*/
@Nonnull
Type getType();

/**
* {@return the time at which the dependency will be used}
* If may be, for example, at compile time only, at run time or at test time.
* It may be, for example, at compile time only, at run time or at test time.
*/
@Nonnull
DependencyScope getScope();

/**
* Returns whether the dependency is optional, mandatory or of unspecified obligation.
* Returns whether the dependency is optional, mandatory, or of unspecified obligation.
*
* @return the obligation, or {@code null} if unspecified
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@

/**
* The option of a Java command-line tool where to place the paths to some dependencies.
* A {@code PathType} can identify the class-path, the module-path, the patches for a specific module,
* A {@code PathType} can identify the class path, the module path, the patches for a specific module,
* or another kind of path.
*
* <p>One path type is handled in a special way: unlike other options,
* the paths specified in a {@code --patch-module} Java option is effective only for a specified module.
* This type is created by calls to {@link #patchModule(String)} and a new instance must be created for
* every module to patch.</p>
*
* <p>Path types are often exclusive. For example, a dependency should not be both on the Java class-path
* and on the Java module-path.</p>
* <p>Path types are often exclusive. For example, a dependency should not be both on the Java class path
* and on the Java module path.</p>
*
* <h2>Relationship with Java compiler standard location</h2>
* This enumeration is closely related to the {@link JavaFileManager.Location} enumerations.
Expand All @@ -63,16 +63,16 @@ public enum JavaPathType implements PathType {
* The Java tools location is {@link StandardLocation#CLASS_PATH}.
*
* <h4>Context-sensitive interpretation</h4>
* A dependency with this path type will not necessarily be placed on the class-path.
* A dependency with this path type will not necessarily be placed on the class path.
* There are two circumstances where the dependency may nevertheless be placed somewhere else:
*
* <ul>
* <li>If {@link #MODULES} path type is also set, then the dependency can be placed either on the
* class-path or on the module-path, but only one of those. The choice is up to the plugin,
* class path or on the module path, but only one of those. The choice is up to the plugin,
* possibly using heuristic rules (Maven 3 behavior).</li>
* <li>If a {@link #patchModule(String)} is also set and the main JAR file is placed on the module-path,
* <li>If a {@link #patchModule(String)} is also set and the main JAR file is placed on the module path,
* then the test dependency will be placed on the Java {@code --patch-module} option instead of the
* class-path.</li>
* class path.</li>
* </ul>
*/
CLASSES(StandardLocation.CLASS_PATH, "--class-path"),
Expand All @@ -83,16 +83,16 @@ public enum JavaPathType implements PathType {
* The Java tools location is {@link StandardLocation#MODULE_PATH}.
*
* <h4>Context-sensitive interpretation</h4>
* A dependency with this flag will not necessarily be placed on the module-path.
* A dependency with this flag will not necessarily be placed on the module path.
* There are two circumstances where the dependency may nevertheless be placed somewhere else:
*
* <ul>
* <li>If {@link #CLASSES} path type is also set, then the dependency <em>should</em> be placed on the
* module-path, but is also compatible with placement on the class-path. Compatibility can
* module path, but is also compatible with placement on the class path. Compatibility can
* be achieved, for example, by repeating in the {@code META-INF/services/} directory the services
* that are declared in the {@code module-info.class} file. In that case, the path type can be chosen
* by the plugin.</li>
* <li>If a {@link #patchModule(String)} is also set and the main JAR file is placed on the module-path,
* <li>If a {@link #patchModule(String)} is also set and the main JAR file is placed on the module path,
* then the test dependency will be placed on the Java {@code --patch-module} option instead of the
* {@code --module-path} option.</li>
* </ul>
Expand Down Expand Up @@ -151,8 +151,8 @@ public enum JavaPathType implements PathType {
* one specific module. Used for compilation and execution among others.
*
* <h4>Context-sensitive interpretation</h4>
* This path type makes sense only when a main module is added on the module-path by another dependency.
* In no main module is found, the patch dependency may be added on the class-path or module-path
* This path type makes sense only when a main module is added on the module path by another dependency.
* In no main module is found, the patch dependency may be added on the class path or module path
* depending on whether {@link #CLASSES} or {@link #MODULES} is present.
*
* @param moduleName name of the module on which to apply the path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

/**
* The option of a command-line tool where to place the paths to some dependencies.
* A {@code PathType} can identify the Java class-path, the Java module-path,
* A {@code PathType} can identify the Java class-path, the Java module path,
* or another kind of path for another programming language for example.
* Path types are often exclusive. For example, a dependency should not be
* both on the Java class-path and on the Java module-path.
* both on the Java class path and on the Java module path.
*
* @see org.apache.maven.api.services.DependencyResolverResult#getDispatchedPaths()
*
Expand Down
26 changes: 13 additions & 13 deletions api/maven-api-core/src/main/java/org/apache/maven/api/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* <p>
* It provides information about the file type (or extension) of the associated artifact,
* its default classifier, and how the artifact will be used in the build when creating
* class-paths or module-paths.
* class paths or module paths.
* <p>
* For example, the type {@code java-source} has a {@code jar} extension and a
* {@code sources} classifier. The artifact and its dependencies should be added
Expand All @@ -54,47 +54,47 @@ public interface Type extends ExtensibleEnum {
String BOM = "bom";

/**
* Artifact type name for a JAR file that can be placed either on the class-path or on the module-path.
* Artifact type name for a JAR file that can be placed either on the class path or on the module path.
* The path (classes or modules) is chosen by the plugin, possibly using heuristic rules.
* This is the behavior of Maven 3.
*/
String JAR = "jar";

/**
* Artifact type name for a fat-JAR file that can be only on the class-path.
* Artifact type name for a fat-JAR file that can be only on the class path.
* The fat-JAR is a self-contained JAR and its transitive dependencies will not be resolved, if any.
* This type is new in Maven 4.
*/
String FATJAR = "fatjar";

/**
* Artifact type name for a JAR file to unconditionally place on the class-path.
* Artifact type name for a JAR file to unconditionally place on the class path.
* If the JAR is modular, its module information are ignored.
* This type is new in Maven 4.
*/
String CLASSPATH_JAR = "classpath-jar";

/**
* Artifact type name for a JAR file to unconditionally place on the module-path.
* Artifact type name for a JAR file to unconditionally place on the module path.
* If the JAR is not modular, then it is loaded by Java as an unnamed module.
* This type is new in Maven 4.
*/
String MODULAR_JAR = "modular-jar";

/**
* Artifact type name for a JAR file that can be placed either on the annotation processor class-path
* or module-path. The path (classes or modules) is chosen by the plugin, possibly using heuristic rules.
* Artifact type name for a JAR file that can be placed either on the annotation processor class path
* or module path. The path (classes or modules) is chosen by the plugin, possibly using heuristic rules.
*/
String PROCESSOR = "processor";

/**
* Artifact type name for a JAR file to unconditionally place on the annotation processor class-path.
* Artifact type name for a JAR file to unconditionally place on the annotation processor class path.
* If the JAR is modular, its module information are ignored.
*/
String CLASSPATH_PROCESSOR = "classpath-processor";

/**
* Artifact type name for a JAR file to unconditionally place on the annotation processor module-path.
* Artifact type name for a JAR file to unconditionally place on the annotation processor module path.
* If the JAR is not modular, then it is loaded by Java as an unnamed module.
*/
String MODULAR_PROCESSOR = "modular-processor";
Expand All @@ -115,9 +115,9 @@ public interface Type extends ExtensibleEnum {
String MAVEN_PLUGIN = "maven-plugin";

/**
* Artifact type name for a JAR file containing test classes. If the main artifact is placed on the class-path
* ({@value #JAR} or {@value #CLASSPATH_JAR} types), then the test artifact will also be placed on the class-path.
* Otherwise, if the main artifact is placed on the module-path ({@value #JAR} or {@value #MODULAR_JAR} types),
* Artifact type name for a JAR file containing test classes. If the main artifact is placed on the class path
* ({@value #JAR} or {@value #CLASSPATH_JAR} types), then the test artifact will also be placed on the class path.
* Otherwise, if the main artifact is placed on the module path ({@value #JAR} or {@value #MODULAR_JAR} types),
* then the test artifact will be added using {@code --patch-module} option.
*/
String TEST_JAR = "test-jar";
Expand Down Expand Up @@ -173,7 +173,7 @@ public interface Type extends ExtensibleEnum {
* and no heuristic rule will be involved.
*
* <p>It is nevertheless common to specify two or more types of path. For example,
* a Java library may be compatible with either the class-path or the module-path,
* a Java library may be compatible with either the class path or the module path,
* and the user may have provided no instruction about which type to use. In such
* case, the plugin may apply rules for choosing a path. See for example
* {@link JavaPathType#CLASSES} and {@link JavaPathType#MODULES}.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public interface DependencyResolverResult {

/**
* Returns the file paths of all dependencies, regardless on which tool option those paths should be placed.
* The returned list may contain a mix of Java class-path, Java module-path, and other types of path elements.
* This collection has the same content than {@code getDependencies.values()} except that it does not contain
* The returned list may contain a mix of Java class path, Java module path, and other types of path elements.
* This collection has the same content as {@code getDependencies.values()} except that it does not contain
* null elements.
*
* @return the paths of all dependencies
Expand Down Expand Up @@ -136,8 +136,8 @@ public interface DependencyResolverResult {
Optional<ModuleDescriptor> 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 to {@link JavaPathType#MODULES}.
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public ModelSource resolve(ModelLocator locator, String relative) {

@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}

return this == o || o.getClass() == getClass() && Objects.equals(path, ((PathSource) o).path);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.api.services;

import java.nio.file.Paths;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;

class PathSourceTest {

@Test
void testEquals() {
PathSource source = new PathSource(Paths.get("/tmp"));
assertFalse(source.equals(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ protected MavenProject getProjectWithDependencies(File pom) throws Exception {
} catch (Exception e) {
Throwable cause = e.getCause();
if (cause instanceof ModelBuildingException modelBuildingException) {
String message = "In: " + pom + "\n\n";
StringBuilder message = new StringBuilder("In: " + pom + "\n\n");
for (ModelProblem problem : modelBuildingException.getProblems()) {
message += problem + "\n";
message.append(problem).append("\n");
}
System.out.println(message);
fail(message);
fail(message.toString());
}

throw e;
Expand Down
2 changes: 1 addition & 1 deletion compat/maven-model-builder/src/site/apt/index.apt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Maven Model Builder
({{{./xref/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.html}source}}).

By default, every model field is inherited as-is from parent, with a few exceptions that are intentionally not inherited:
<<<modelVersion>>>, <<<artifactId>>>, <<<profiles>>> (injected in phase 1) and <<<prerequisites>>>.
<<<modelVersion>>>, <<<artifactId>>>, <<<packaging>>>, <<<profiles>>> (injected in phase 1) and <<<prerequisites>>>.

Notice that the 5 URLs from the model (<<<project.url>>>, <<<project.scm.connection>>>, <<<project.scm.developerConnection>>>,
<<<project.scm.url>>> and <<<project.distributionManagement.site.url>>>) have a special inheritance handling:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,19 @@ private Model loadPom(
if (logger.isDebugEnabled()) {
String problem = (problems.size() == 1) ? "problem" : "problems";
String problemPredicate = problem + ((problems.size() == 1) ? " was" : " were");
String message = String.format(
StringBuilder message = new StringBuilder(String.format(
"%s %s encountered while building the effective model for %s during %s\n",
problems.size(),
problemPredicate,
request.getArtifact(),
RequestTraceHelper.interpretTrace(true, request.getTrace()));
message += StringUtils.capitalizeFirstLetter(problem);
RequestTraceHelper.interpretTrace(true, request.getTrace())));
message.append(StringUtils.capitalizeFirstLetter(problem));
for (ModelProblem modelProblem : problems) {
message += String.format(
message.append(String.format(
"\n* %s @ %s",
modelProblem.getMessage(), ModelProblemUtils.formatLocation(modelProblem, null));
modelProblem.getMessage(), ModelProblemUtils.formatLocation(modelProblem, null)));
}
logger.warn(message);
logger.warn(message.toString());
} else {
logger.warn(
"{} {} encountered while building the effective model for {} during {} (use -X to see details)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,18 @@ protected Parser createParser() {
}

@Test
void defaultFs(@TempDir(cleanup = CleanupMode.ON_SUCCESS) Path tempDir) throws Exception {
invoke(tempDir, Arrays.asList("clean", "verify"));
void defaultFs(
@TempDir(cleanup = CleanupMode.ON_SUCCESS) Path cwd,
@TempDir(cleanup = CleanupMode.ON_SUCCESS) Path userHome)
throws Exception {
invoke(cwd, userHome, Arrays.asList("clean", "verify"));
}

@Disabled("Until we move off fully from File")
@Test
void jimFs() throws Exception {
try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) {
invoke(fs.getPath("/"), Arrays.asList("clean", "verify"));
invoke(fs.getPath("/cwd"), fs.getPath("/home"), Arrays.asList("clean", "verify"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void main(String... args) {
}
""";

protected void invoke(Path cwd, Collection<String> goals) throws Exception {
protected void invoke(Path cwd, Path userHome, Collection<String> goals) throws Exception {
// works only in recent Maven4
Assumptions.assumeTrue(
Files.isRegularFile(Paths.get(System.getProperty("maven.home"))
Expand All @@ -104,6 +104,7 @@ protected void invoke(Path cwd, Collection<String> goals) throws Exception {
new ProtoLogger(),
new JLineMessageBuilderFactory())
.cwd(cwd)
.userHome(userHome)
.build()));
String log = Files.readString(logFile);
System.out.println(log);
Expand Down
Loading

0 comments on commit 213c8b3

Please sign in to comment.