Class AbstractProject

java.lang.Object
org.jdrupes.builder.core.AbstractProvider
org.jdrupes.builder.core.AbstractProject
All Implemented Interfaces:
Project, ResourceProvider
Direct Known Subclasses:
BootstrapBuild, BootstrapRoot

public abstract class AbstractProject extends AbstractProvider implements Project
A default implementation of a Project.
  • Constructor Details

    • AbstractProject

      protected AbstractProject(NamedParameter<?>... params)

      Base class constructor for all projects. The behavior depends on whether the project is a root project (implements RootProject) or a subproject and on whether the project specifies a parent project.

      RootProjects must invoke this constructor with a null parent project class.

      A sub project that wants to specify a parent project must invoke this constructor with the parent project's class. If a sub project does not specify a parent project, the root project is used as parent. In both cases, the constructor adds a Intend.Forward dependency between the parent project and the new project. This can then be overridden in the sub project's constructor.

      Parameters:
      params -

      the named parameters

      • parent - the class of the parent project
      • name - the name of the project. If not provided the name is set to the (simple) class name
      • directory - the directory of the project. If not provided, the directory is set to the name with uppercase letters converted to lowercase for subprojects. For root projects the directory is always set to the current working
  • Method Details

    • parent

      protected static NamedParameter<Class<? extends Project>> parent(Class<? extends Project> parentProject)
      Named parameter for specifying the parent project.
      Parameters:
      parentProject - the parent project
      Returns:
      the named parameter
    • name

      protected static NamedParameter<String> name(String name)
      Named parameter for specifying the name.
      Parameters:
      name - the name
      Returns:
      the named parameter
    • directory

      protected static NamedParameter<Path> directory(Path directory)
      Named parameter for specifying the directory.
      Parameters:
      directory - the directory
      Returns:
      the named parameter
    • jdbldDirectory

      protected static NamedParameter<Path> jdbldDirectory()
      Hack to pass context().jdbldDirectory() as named parameter for the directory to the constructor. This is required because you cannot "refer to an instance method while explicitly invoking a constructor".
      Returns:
      the named parameter
    • rootProject

      public final RootProject rootProject()
      Description copied from interface: Project
      Returns the root project.
      Specified by:
      rootProject in interface Project
      Returns:
      the project
    • project

      public ResourceProvider project(Class<? extends Project> prjCls)
      Description copied from interface: Project
      Returns the instance of the given project class. Projects are created lazily by the builder and must be accessed via this method.
      Specified by:
      project in interface Project
      Parameters:
      prjCls - the requested project's type
      Returns:
      the project
    • name

      public String name()
      Description copied from interface: Project
      Returns the project's name.
      Specified by:
      name in interface Project
      Returns:
      the string
    • directory

      public Path directory()
      Description copied from interface: Project
      Returns the project's directory.
      Specified by:
      directory in interface Project
      Returns:
      the path
    • generator

      public Project generator(Generator provider)
      Generator.
      Specified by:
      generator in interface Project
      Parameters:
      provider - the provider
      Returns:
      the project
    • dependency

      public Project dependency(Intend intend, ResourceProvider provider)
      Description copied from interface: Project

      Adds a provider that contributes resources to the project with the given intended usage.

      While this could be used to add a Generator to the project as a provider with Intend.Supply, it is recommended to use one of the "generator" methods for better readability.

      Specified by:
      dependency in interface Project
      Parameters:
      intend - the dependency type
      provider - the provider
      Returns:
      the project for method chaining
      See Also:
    • providers

      Description copied from interface: Project
      Returns the providers that have been added with one of the given intended usages as Stream. The stream may only be terminated after all projects have been created.
      Specified by:
      providers in interface Project
      Parameters:
      intends - the intends
      Returns:
      the stream
    • getFrom

      public <T extends Resource> Stream<T> getFrom(Stream<ResourceProvider> providers, ResourceRequest<T> request)
      Description copied from interface: Project
      Invoke the given providers for the given request and return the resulting stream. This method terminates the stream of providers.
      Specified by:
      getFrom in interface Project
      Type Parameters:
      T - the generic type
      Parameters:
      providers - the providers
      request - the request
      Returns:
      the stream
    • context

      Description copied from interface: Project
      Returns the build context.
      Specified by:
      context in interface Project
      Returns:
      the builder configuration
    • get

      public <T> T get(PropertyKey property)
      Description copied from interface: Project
      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.
      Specified by:
      get in interface Project
      Type Parameters:
      T - the generic type
      Parameters:
      property - the property
      Returns:
      the t
    • set

      public AbstractProject set(PropertyKey property, Object value)
      Description copied from interface: Project

      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 set matches the type of the property. An implementation must check this at runtime by verifying that the given value is assignable to the default value.

      Specified by:
      set in interface Project
      Parameters:
      property - the property
      value - the value
      Returns:
      the project
    • doProvide

      protected <R extends Resource> Stream<R> doProvide(ResourceRequest<R> requested)
      A project itself does not provide any resources. Rather, requests for resources are forwarded to the project's providers with intend Intend.Forward, Intend.Expose or Intend.Supply.
      Specified by:
      doProvide in class AbstractProvider
      Type Parameters:
      R - the generic type
      Parameters:
      requested - the requested
      Returns:
      the provided resources
    • commandAlias

      public RootProject commandAlias(String name, ResourceRequest<?>... requests)
      Parameters:
      name - the name
      requests - the requests
      Returns:
      the root project
    • readString

      public String readString(Path path)
      Convenience method for reading the content of a file into a String.
      Parameters:
      path - the path
      Returns:
      the string
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      To string.
      Overrides:
      toString in class AbstractProvider
      Returns:
      the string