Record Class DefaultSourceRoot

java.lang.Object
java.lang.Record
org.apache.maven.impl.DefaultSourceRoot
Record Components:
scope - in which context the source files will be used (main or test)
language - language of the source files
moduleName - name of the Java module which is built by the sources
targetVersionOrNull - version of the platform where the code will be executed
directory - root directory where the sources are stored
includes - patterns for the files to include, or empty if unspecified
excludes - patterns for the files to exclude, or empty if nothing to exclude
stringFiltering - whether resources are filtered to replace tokens with parameterized values
targetPathOrNull - an explicit target path, overriding the default value
enabled - whether the directory described by this source element should be included in the build
All Implemented Interfaces:
SourceRoot

public record DefaultSourceRoot(ProjectScope scope, Language language, @Nullable String moduleName, @Nullable Version targetVersionOrNull, Path directory, List<String> includes, List<String> excludes, boolean stringFiltering, @Nullable Path targetPathOrNull, boolean enabled) extends Record implements SourceRoot
A default implementation of SourceRoot built from the model.
  • Constructor Details

    • DefaultSourceRoot

      public DefaultSourceRoot(ProjectScope scope, Language language, Path directory)
      Creates a simple instance with no Java module, no target version, and no include or exclude pattern.
      Parameters:
      scope - in which context the source files will be used (main or test)
      language - the language of the source files
      directory - the root directory where the sources are stored
    • DefaultSourceRoot

      public DefaultSourceRoot(@Nonnull ProjectScope scope, @Nonnull Language language, @Nullable String moduleName, @Nullable Version targetVersionOrNull, @Nullable Path directory, @Nullable List<String> includes, @Nullable List<String> excludes, boolean stringFiltering, @Nullable Path targetPathOrNull, boolean enabled)
      Canonical constructor.
      Parameters:
      scope - in which context the source files will be used (main or test)
      language - language of the source files
      moduleName - name of the Java module which is built by the sources
      targetVersionOrNull - version of the platform where the code will be executed
      directory - root directory where the sources are stored
      includes - patterns for the files to include, or null or empty if unspecified
      excludes - patterns for the files to exclude, or null or empty if nothing to exclude
      stringFiltering - whether resources are filtered to replace tokens with parameterized values
      targetPathOrNull - an explicit target path, overriding the default value
      enabled - whether the directory described by this source element should be included in the build
    • DefaultSourceRoot

      public DefaultSourceRoot(Path baseDir, ProjectScope scope, Resource resource)
      Creates a new instance from the given resource. This is used for migration from the previous way of declaring resources.

      Important: The targetPath from the resource is stored as-is (converted to a Path but not resolved against any directory). This preserves the Maven 3.x behavior where targetPath is relative to the output directory, not the project base directory. The actual resolution happens later via SourceRoot.targetPath(Project).

      Parameters:
      baseDir - the base directory for resolving relative paths (used only for the source directory)
      scope - the scope of the resource (main or test)
      resource - a resource element from the model
  • Method Details

    • fromModel

      public static DefaultSourceRoot fromModel(Session session, Path baseDir, Function<ProjectScope,String> outputDir, Source source)
      Creates a new instance from the given model.
      Parameters:
      session - the session of resolving extensible enumerations
      baseDir - the base directory for resolving relative paths
      outputDir - supplier of output directory relative to baseDir
      source - a source element from the model
    • matcher

      public PathMatcher matcher(Collection<String> defaultIncludes, boolean useDefaultExcludes)
      Returns a matcher combining the include and exclude patterns.
      Specified by:
      matcher in interface SourceRoot
      Parameters:
      defaultIncludes - the default includes if unspecified by the user
      useDefaultExcludes - whether to add the default set of patterns to exclude, mostly Source Code Management (SCM) files
      Returns:
      a matcher combining the include and exclude patterns
    • module

      public Optional<String> module()
      Returns the name of the Java module (or other language-specific module) which is built by the sources.
      Specified by:
      module in interface SourceRoot
      Returns:
      the name of the Java module (or other language-specific module) which is built by the sources
    • targetVersion

      public Optional<Version> targetVersion()
      Returns the version of the platform where the code will be executed.
      Specified by:
      targetVersion in interface SourceRoot
      Returns:
      the version of the platform where the code will be executed
    • targetPath

      public Optional<Path> targetPath()
      Returns an explicit target path, overriding the default value.

      The returned path, if present, is stored as provided in the configuration and is typically relative to the output directory. Use SourceRoot.targetPath(Project) to get the fully resolved absolute path.

      Specified by:
      targetPath in interface SourceRoot
      Returns:
      an explicit target path, overriding the default value
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • scope

      @Nonnull public ProjectScope scope()
      Returns the value of the scope record component.
      Specified by:
      scope in interface SourceRoot
      Returns:
      the value of the scope record component
    • language

      @Nonnull public Language language()
      Returns the value of the language record component.
      Specified by:
      language in interface SourceRoot
      Returns:
      the value of the language record component
    • moduleName

      @Nullable public String moduleName()
      Returns the value of the moduleName record component.
      Returns:
      the value of the moduleName record component
    • targetVersionOrNull

      @Nullable public Version targetVersionOrNull()
      Returns the value of the targetVersionOrNull record component.
      Returns:
      the value of the targetVersionOrNull record component
    • directory

      @Nonnull public Path directory()
      Returns the value of the directory record component.
      Specified by:
      directory in interface SourceRoot
      Returns:
      the value of the directory record component
    • includes

      @Nonnull public List<String> includes()
      Returns the value of the includes record component.
      Specified by:
      includes in interface SourceRoot
      Returns:
      the value of the includes record component
    • excludes

      @Nonnull public List<String> excludes()
      Returns the value of the excludes record component.
      Specified by:
      excludes in interface SourceRoot
      Returns:
      the value of the excludes record component
    • stringFiltering

      public boolean stringFiltering()
      Returns the value of the stringFiltering record component.
      Specified by:
      stringFiltering in interface SourceRoot
      Returns:
      the value of the stringFiltering record component
    • targetPathOrNull

      @Nullable public Path targetPathOrNull()
      Returns the value of the targetPathOrNull record component.
      Returns:
      the value of the targetPathOrNull record component
    • enabled

      public boolean enabled()
      Returns the value of the enabled record component.
      Specified by:
      enabled in interface SourceRoot
      Returns:
      the value of the enabled record component