Interface Project
- All Superinterfaces:
ResourceProvider
- All Known Subinterfaces:
RootProject
- All Known Implementing Classes:
AbstractProject, BootstrapBuild, BootstrapRoot
Projects are used to structure the build configuration. Every
build configuration has a single root project and can have
sub-projects. The root project is the entry point for the build.
The resources provided by the builder are usually provided by the
root project that serves as n entry point to the build configuration.
Projects are ResourceProviders that obtain resources from related
ResourceProviders. Projects can be thought of as routers for
resources with their behavior depending on the intended usage of the
resources from the related providers. The intended usage is specified
by the Intend that attributes the relationship between a project
and its related resource providers.
Attributing relationships to providers
Intend Supply
Resources from a provider added with Intend.Supply are provided
by the project to entities that depend on the project. Intend.Supply
implies that the resources are genuinely generated for the project
(typically by a Generator that belongs to the project).
Intend Consume
Resources from a provider added with Intend.Consume (typically
another project) are only available to a project's generators
through provided(ResourceRequest).
Intend Expose
Resources from a provider added with Intend.Expose (typically
another project) are provided by the project to entities that
depend on the project. They are also available to a project's
generators through provided(ResourceRequest).
Intend Forward
Resources from a provider added with Intend.Forward (typically
another project) are provided by the project to entities that
depend on the project. They are not intended to be used by a
project's generators, although these cannot be prevented from
accessing them through ResourceProvider.provide(ResourceRequest).
Factory methods
As a convenience, the interface also defines factory methods for objects used for defining the project.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumThe common project properties. -
Method Summary
Modifier and TypeMethodDescriptiondefault PathReturns the directory where the project'sGenerators should create the artifacts.context()Returns the build context.default <T extends ResourceProvider>
Tdependency(Intend intend, Function<Project, T> supplier) Uses the supplier to create a provider, passing this project as argument and adds the result as a dependency to this project.dependency(Intend intend, ResourceProvider provider) Adds a provider that contributes resources to the project with the given intended usage.Returns the project's directory.default FromHelperfrom(Stream<ResourceProvider> providers) Returns a newFromHelperinstance for a subsequent call toFromHelper.get(ResourceRequest).default FromHelperRetrieves the providers with the specified intend(s) (seeproviders(Set)) and returns a newFromHelperinstance for a subsequent call toFromHelper.get(ResourceRequest).default FromHelperfrom(ResourceProvider provider) "Syntactic sugar" that allows to obtain resources from a provider withfrom(provider).get(resourceRequest)instead ofcontext().get(provider, resourceRequest).default <T extends Generator>
TUses the supplier to create a provider, passing this project as argument and adds the result as a generator to this project.Adds a provider to the project that generates resources which are then provided by the project.<T> Tget(PropertyKey property) Returns value of the given property of the project.get(ResourceRequest<T> request) Returns resources provided by the project.name()Returns the project's name.default <T extends Resource>
TnewResource(ResourceType<T> type, Object... args) Returns a new resource with the given type.Returns the instance of the given project class.provided(ResourceRequest<T> requested) Returns all resources that are provided for the given request by providers associated withIntend.ConsumeorIntend.Expose.Returns the providers that have been added with one of the given intended usages asStream.default Stream<ResourceProvider> Returns the providers that have been added with the given intended usage asStream.default StringreadString(Path path) Convenience method for reading the content of a file into a String.default Pathrelativize(Path other) Short fordirectory().relativize(other).Returns the root project.set(PropertyKey property, Object value) Sets the given property to the given value.Methods inherited from interface ResourceProvider
provide
-
Method Details
-
rootProject
-
project
-
name
-
directory
-
context
-
buildDirectory
Returns the directory where the project'sGenerators should create the artifacts. This is short fordirectory().resolve((Path) get(Properties.BuildDirectory)).- Returns:
- the path
-
generator
-
generator
Uses the supplier to create a provider, passing this project as argument and adds the result as a generator to this project. This is a convenience method to add a provider to the project by writing (in a project's constructor):
generator(Provider::new);instead of:
generator(new Provider(this));- Type Parameters:
T- the generic type- Parameters:
supplier- the supplier- Returns:
- the project for method chaining
-
dependency
Adds a provider that contributes resources to the project with the given intended usage.
While this could be used to add a
Generatorto the project as a provider withIntend.Supply, it is recommended to use one of the "generator" methods for better readability.- Parameters:
intend- the dependency typeprovider- the provider- Returns:
- the project for method chaining
- See Also:
-
dependency
Uses the supplier to create a provider, passing this project as argument and adds the result as a dependency to this project. This is a convenience method to add a provider to the project by writing (in a project's constructor):
dependency(intend, Provider::new);instead of:
dependency(intend, new Provider(this));- Type Parameters:
T- the generic type- Parameters:
intend- the intendsupplier- the supplier- Returns:
- the project for method chaining
-
providers
-
providers
-
provided
Returns all resources that are provided for the given request by providers associated withIntend.ConsumeorIntend.Expose.- Type Parameters:
T- the requested type- Parameters:
requested- the requested- Returns:
- the provided resources
-
relativize
Short fordirectory().relativize(other).- Parameters:
other- the other path- Returns:
- the relativized path
-
set
Sets the given property to the given value.
Regrettably, there is no way to enforce at compile time that the type of the value passed to
setmatches the type of the property. An implementation must check this at runtime by verifying that the given value is assignable to the default value.- Parameters:
property- the propertyvalue- the value- Returns:
- the project
-
get
Returns value of the given property of the project. If the property is not set, the parent project's value is returned. If neither is set, the property's default value is returned.- Type Parameters:
T- the generic type- Parameters:
property- the property- Returns:
- the t
-
get
Returns resources provided by the project. Short forcontext().get(this, request).- Type Parameters:
T- the generic type- Parameters:
request- the request- Returns:
- the stream
-
from
"Syntactic sugar" that allows to obtain resources from a provider withfrom(provider).get(resourceRequest)instead ofcontext().get(provider, resourceRequest).- Parameters:
provider- the provider- Returns:
- the stream of resources
-
from
Returns a newFromHelperinstance for a subsequent call toFromHelper.get(ResourceRequest).- Parameters:
providers- the providers- Returns:
- the stream of resources
-
from
Retrieves the providers with the specified intend(s) (seeproviders(Set)) and returns a newFromHelperinstance for a subsequent call toFromHelper.get(ResourceRequest).- Parameters:
intend- the intendintends- the intends- Returns:
- the from helper
-
newResource
Returns a new resource with the given type. Short for invokingResourceFactory.create(ResourceType, Project, Object...)with the current project as first argument and the given arguments appended.- Type Parameters:
T- the generic type- Parameters:
type- the typeargs- the args- Returns:
- the t
-
readString
Convenience method for reading the content of a file into a String. The path is resolved against the project's directory.- Parameters:
path- the path- Returns:
- the string
-