Interface ModelSource

All Superinterfaces:
Source

public interface ModelSource extends Source
Represents a source for loading Maven Project Object Model (POM) files. This interface extends the basic Source interface with specific functionality for handling Maven POM files and resolving related project POMs.

The interface provides two types of sources:

  • Build sources: Used for POM files of projects being built by Maven in the filesystem. These sources support resolving related POMs using the ModelSource.ModelLocator.
  • Resolved sources: Used for artifacts that have been resolved by Maven from repositories (using groupId:artifactId:version coordinates) and downloaded to the local repository. These sources do not support resolving other sources.
Since:
4.0.0
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Interface for locating POM files within a project structure.
  • Method Summary

    Modifier and Type
    Method
    Description
    default String
    Returns the model identifier in the format groupId:artifactId:version if this source represents a resolved artifact with known coordinates.
    resolve(ModelSource.ModelLocator modelLocator, String relative)
    Resolves a relative path to another POM file using the provided model locator.

    Methods inherited from interface org.apache.maven.api.services.Source

    getLocation, getPath, openStream, resolve
  • Method Details

    • getModelId

      @Nullable default String getModelId()
      Returns the model identifier in the format groupId:artifactId:version if this source represents a resolved artifact with known coordinates.

      This method is primarily used by resolved sources to provide the model ID without requiring the XML to be parsed. For build sources, this typically returns null since the coordinates are determined by parsing the POM.

      Returns:
      the model identifier, or null if not available or not applicable
      Since:
      4.0.0
    • resolve

      Resolves a relative path to another POM file using the provided model locator. This method is specifically used to locate POM files for subprojects or related projects referenced from the current POM.

      The resolution process typically involves:

      • Normalizing the relative path for the current platform
      • Resolving the path against the current POM's location
      • Using the model locator to find an existing POM at the resolved location
      Parameters:
      modelLocator - the locator to use for finding the related POM file
      relative - the relative path to resolve
      Returns:
      a new ModelSource for the resolved POM, or null if:
      • This is not a build source
      • No POM can be found at the resolved location
      Throws:
      NullPointerException - if modelLocator or relative is null