Class Source
- All Implemented Interfaces:
Serializable
,InputLocationTracker
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 aresrc/${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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Builder class used to create Source instances. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Source
(Source.Builder builder) Constructor for this class, to be called from its subclasses andSource.Builder
. -
Method Summary
Modifier and TypeMethodDescriptiongetLang()
Specifies the language of the source files - typicallyjava
orresources
.Name of the Java module (or other language-specific module) which is built by the sources.getScope()
Specifies in which context the source files will be used - typicallymain
ortest
.Specifies an explicit target path, overriding the default value.The version of the platform where the code will be executed.boolean
Whether the directory described by this source element should be included in the build.boolean
Whether resources are filtered to replace tokens with parameterized values.static Source.Builder
Creates a newSource
builder instance.static Source.Builder
newBuilder
(boolean withDefaults) Creates a newSource
builder instance using default values or not.static Source.Builder
newBuilder
(Source from) Creates a newSource
builder instance using the specified object as a basis.static Source.Builder
newBuilder
(Source from, boolean forceCopy) Creates a newSource
builder instance using the specified object as a basis.static Source
Creates a newSource
instance.static Source
newInstance
(boolean withDefaults) Creates a newSource
instance using default values or not.with()
Creates a new builder with this object as the basis.withDirectory
(String directory) Creates a newSource
instance using the specified directory.withEnabled
(boolean enabled) Creates a newSource
instance using the specified enabled.withExcludes
(Collection<String> excludes) Creates a newSource
instance using the specified excludes.withIncludes
(Collection<String> includes) Creates a newSource
instance using the specified includes.Creates a newSource
instance using the specified lang.withModule
(String module) Creates a newSource
instance using the specified module.Creates a newSource
instance using the specified scope.withStringFiltering
(boolean stringFiltering) Creates a newSource
instance using the specified stringFiltering.withTargetPath
(String targetPath) Creates a newSource
instance using the specified targetPath.withTargetVersion
(String targetVersion) Creates a newSource
instance using the specified targetVersion.Methods inherited from class org.apache.maven.api.model.FileSet
getDirectory, newBuilder, newBuilder, toString
Methods inherited from class org.apache.maven.api.model.PatternSet
getExcludes, getImportedFrom, getIncludes, getLocation, getLocationKeys, getLocationKeyStream, newBuilder, newBuilder
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.maven.api.model.InputLocationTracker
getImportedFrom, getLocation
-
Constructor Details
-
Source
Constructor for this class, to be called from its subclasses andSource.Builder
.- See Also:
-
-
Method Details
-
getScope
Specifies in which context the source files will be used - typicallymain
ortest
.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
Specifies the language of the source files - typicallyjava
orresources
. 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
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 asfoo.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
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 thefoo/bar.properties
resource file will be copied asMETA-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
Specifies an explicit target path, overriding the default value. The path is relative to the${project.build.outputDirectory}
directory, which is typicallytarget/classes
in a Java project.When a target path is explicitly specified, the values of the
module
andtargetVersion
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 bydirectory
are copied to the path specified bytargetPath
with the exact same directory structure. It is user's responsibility to put module and version components in thetargetPath
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 theproperties
element and from the properties in the files listed in thefilters
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
Creates a new builder with this object as the basis. -
withIncludes
Creates a newSource
instance using the specified includes.- Overrides:
withIncludes
in classFileSet
- Parameters:
includes
- the newCollection<String>
to use- Returns:
- a
Source
with the specified includes
-
withExcludes
Creates a newSource
instance using the specified excludes.- Overrides:
withExcludes
in classFileSet
- Parameters:
excludes
- the newCollection<String>
to use- Returns:
- a
Source
with the specified excludes
-
withDirectory
Creates a newSource
instance using the specified directory.- Overrides:
withDirectory
in classFileSet
- Parameters:
directory
- the newString
to use- Returns:
- a
Source
with the specified directory
-
withScope
Creates a newSource
instance using the specified scope.- Parameters:
scope
- the newString
to use- Returns:
- a
Source
with the specified scope
-
withLang
Creates a newSource
instance using the specified lang.- Parameters:
lang
- the newString
to use- Returns:
- a
Source
with the specified lang
-
withModule
Creates a newSource
instance using the specified module.- Parameters:
module
- the newString
to use- Returns:
- a
Source
with the specified module
-
withTargetVersion
Creates a newSource
instance using the specified targetVersion.- Parameters:
targetVersion
- the newString
to use- Returns:
- a
Source
with the specified targetVersion
-
withTargetPath
Creates a newSource
instance using the specified targetPath.- Parameters:
targetPath
- the newString
to use- Returns:
- a
Source
with the specified targetPath
-
withStringFiltering
Creates a newSource
instance using the specified stringFiltering.- Parameters:
stringFiltering
- the newboolean
to use- Returns:
- a
Source
with the specified stringFiltering
-
withEnabled
Creates a newSource
instance using the specified enabled.- Parameters:
enabled
- the newboolean
to use- Returns:
- a
Source
with the specified enabled
-
newInstance
Creates a newSource
instance. Equivalent tonewInstance(true)
.- Returns:
- a new
Source
- See Also:
-
newInstance
Creates a newSource
instance using default values or not. Equivalent tonewBuilder(withDefaults).build()
.- Parameters:
withDefaults
- the boolean indicating whether default values should be used- Returns:
- a new
Source
-
newBuilder
Creates a newSource
builder instance. Equivalent tonewBuilder(true)
.- Returns:
- a new
Builder
- See Also:
-
newBuilder
Creates a newSource
builder instance using default values or not.- Parameters:
withDefaults
- the boolean indicating whether default values should be used- Returns:
- a new
Builder
-
newBuilder
Creates a newSource
builder instance using the specified object as a basis. Equivalent tonewBuilder(from, false)
.- Parameters:
from
- theSource
instance to use as a basis- Returns:
- a new
Builder
-
newBuilder
Creates a newSource
builder instance using the specified object as a basis.- Parameters:
from
- theSource
instance to use as a basisforceCopy
- the boolean indicating if a copy should be forced- Returns:
- a new
Builder
-