Class Source

All Implemented Interfaces:
Serializable, InputLocationTracker

Description of the sources associated with a project main code or unit tests. The sources can be Java source files, generated source files, scripts or resources for examples. A source is specified by a mandatory directory element, which is relative to the POM. The directory content can optionally by reduced to a subset with the includes and excludes elements. The kind of sources (codes, resources, etc.) and their usage (main code, tests, etc.) is specified by the scope element.

Default source directories

If no source directories are specified, the defaults are src/${scope}/${lang} where ${scope} is the value of the scope element (typically main or test) and ${lang} is the value of the lang element (typically java or resources).
See Also:
  • Constructor Details

  • Method Details

    • getScope

      public String getScope()
      Specifies in which context the source files will be used - typically main or test.

      The main scope is used for specifying a directory containing the source of the project. The generated build system will compile the sources from this directory when the project is built. The path given in the directory field is relative to the project descriptor. The default directory for the default language (Java) is "src/main/java".

      The test scope is used for specifying a directory containing the unit test source of the project. The generated build system will compile these directories when the project is being tested. The path given in the directory field is relative to the project descriptor. The default directory for the default language (Java) is "src/test/java".

      If no scope is specified, the default is main.

      Returns:
      a String
    • getLang

      public String getLang()
      Specifies the language of the source files - typically java or resources. Resources is used as a generic term for scripting languages (e.g., JavaScript or Python) or markup languages (e.g. properties file, JSON or XML).

      The java language is used for specifying a directory containing the Java sources of the project. The generated build system will compile the sources from this directory using the Java compiler when the project is built. The path given in the directory field is relative to the project descriptor. The default directory for the main Java sources is "src/main/java".

      The resources language is used for specifying a directory containing the class-path or module-path resources such as properties files or scripts associated with a project. This directory is meant to be different from the main source directory, in that its contents will be copied to the output directory in most cases (since scripts are interpreted rather than compiled). The default directory for the main resources is "src/main/resources".

      If no language is specified, the default is java.

      Returns:
      a String
    • getModule

      public String getModule()
      Name of the Java module (or other language-specific module) which is built by the sources. This element can be specified in a Maven project containing multiple Java modules. It is generally not needed for non-modular projects, or for modular projects having only one module.

      If a module name is specified for resources or script files, then this value modifies the directory where the files will be copied. For example, if a Java module name is "foo.biz", then the foo/bar.properties resource file will be copied as foo.biz/foo/bar.properties.

      This element can be combined with the targetVersion element for specifying sources, scripts or resources that are specific to both a particular module and a target version.

      Returns:
      a String
    • getTargetVersion

      public String getTargetVersion()
      The version of the platform where the code will be executed. In a Java environment, this is the value of the --release compiler option. If a Java project contains multiple main sources with different target versions, then a multi-version JAR file will be created with the lowest version taken as the base version. If this element is omitted, then the default target version is the compiler default value, which is usually the version of the Java environment running Maven.

      If a target version, different from the base version, is specified for resources or script files, then this value modifies the directory where the files will be copied. For example, if targetVersion is 17, then the foo/bar.properties resource file will be copied as META-INF/versions/17/foo/bar.properties.

      This element can be combined with the module element for specifying sources, scripts or resources that are specific to both a particular module and a target version.

      Returns:
      a String
    • getTargetPath

      public String getTargetPath()
      Specifies an explicit target path, overriding the default value. The path is relative to the ${project.build.outputDirectory} directory, which is typically target/classes in a Java project.

      When a target path is explicitly specified, the values of the module and targetVersion elements are not used for inferring the path (they are still used as compiler options however). It means that for scripts and resources, the files below the path specified by directory are copied to the path specified by targetPath with the exact same directory structure. It is user's responsibility to put module and version components in the targetPath if needed.

      Note that for Java source files, a directory with the module name may still be generated despite above statement about module being ignored, because that directory is generated by the Java compiler rather than Maven.

      Returns:
      a String
    • isStringFiltering

      public boolean isStringFiltering()
      Whether resources are filtered to replace tokens with parameterized values. The values are taken from the properties element and from the properties in the files listed in the filters element.

      The default value is false.

      Returns:
      a boolean
    • isEnabled

      public boolean isEnabled()
      Whether the directory described by this source element should be included in the build. This flag provides an easy way to include or exclude some sources depending, for example, o property values defined in profiles. A use case is including optional resources only when the user confirmed a license agreement.

      The default value is true.

      Returns:
      a boolean
    • with

      @Nonnull public Source.Builder with()
      Creates a new builder with this object as the basis.
      Overrides:
      with in class FileSet
      Returns:
      a Builder
    • withIncludes

      @Nonnull public Source withIncludes(Collection<String> includes)
      Creates a new Source instance using the specified includes.
      Overrides:
      withIncludes in class FileSet
      Parameters:
      includes - the new Collection<String> to use
      Returns:
      a Source with the specified includes
    • withExcludes

      @Nonnull public Source withExcludes(Collection<String> excludes)
      Creates a new Source instance using the specified excludes.
      Overrides:
      withExcludes in class FileSet
      Parameters:
      excludes - the new Collection<String> to use
      Returns:
      a Source with the specified excludes
    • withDirectory

      @Nonnull public Source withDirectory(String directory)
      Creates a new Source instance using the specified directory.
      Overrides:
      withDirectory in class FileSet
      Parameters:
      directory - the new String to use
      Returns:
      a Source with the specified directory
    • withScope

      @Nonnull public Source withScope(String scope)
      Creates a new Source instance using the specified scope.
      Parameters:
      scope - the new String to use
      Returns:
      a Source with the specified scope
    • withLang

      @Nonnull public Source withLang(String lang)
      Creates a new Source instance using the specified lang.
      Parameters:
      lang - the new String to use
      Returns:
      a Source with the specified lang
    • withModule

      @Nonnull public Source withModule(String module)
      Creates a new Source instance using the specified module.
      Parameters:
      module - the new String to use
      Returns:
      a Source with the specified module
    • withTargetVersion

      @Nonnull public Source withTargetVersion(String targetVersion)
      Creates a new Source instance using the specified targetVersion.
      Parameters:
      targetVersion - the new String to use
      Returns:
      a Source with the specified targetVersion
    • withTargetPath

      @Nonnull public Source withTargetPath(String targetPath)
      Creates a new Source instance using the specified targetPath.
      Parameters:
      targetPath - the new String to use
      Returns:
      a Source with the specified targetPath
    • withStringFiltering

      @Nonnull public Source withStringFiltering(boolean stringFiltering)
      Creates a new Source instance using the specified stringFiltering.
      Parameters:
      stringFiltering - the new boolean to use
      Returns:
      a Source with the specified stringFiltering
    • withEnabled

      @Nonnull public Source withEnabled(boolean enabled)
      Creates a new Source instance using the specified enabled.
      Parameters:
      enabled - the new boolean to use
      Returns:
      a Source with the specified enabled
    • newInstance

      @Nonnull public static Source newInstance()
      Creates a new Source instance. Equivalent to newInstance(true).
      Returns:
      a new Source
      See Also:
    • newInstance

      @Nonnull public static Source newInstance(boolean withDefaults)
      Creates a new Source instance using default values or not. Equivalent to newBuilder(withDefaults).build().
      Parameters:
      withDefaults - the boolean indicating whether default values should be used
      Returns:
      a new Source
    • newBuilder

      @Nonnull public static Source.Builder newBuilder()
      Creates a new Source builder instance. Equivalent to newBuilder(true).
      Returns:
      a new Builder
      See Also:
    • newBuilder

      @Nonnull public static Source.Builder newBuilder(boolean withDefaults)
      Creates a new Source builder instance using default values or not.
      Parameters:
      withDefaults - the boolean indicating whether default values should be used
      Returns:
      a new Builder
    • newBuilder

      @Nonnull public static Source.Builder newBuilder(Source from)
      Creates a new Source builder instance using the specified object as a basis. Equivalent to newBuilder(from, false).
      Parameters:
      from - the Source instance to use as a basis
      Returns:
      a new Builder
    • newBuilder

      @Nonnull public static Source.Builder newBuilder(Source from, boolean forceCopy)
      Creates a new Source builder instance using the specified object as a basis.
      Parameters:
      from - the Source instance to use as a basis
      forceCopy - the boolean indicating if a copy should be forced
      Returns:
      a new Builder