Class AbstractProject

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

public abstract class AbstractProject extends AbstractProvider implements Project

A default implementation of a Project.

Noteworthy features:

  • Providers are added to a project successively in its constructor. This implies that the list of providers is incomplete during the execution of the constructor and may only be accesses via the lazily evaluated Stream return by providers. The only place where the registered providers are accessed is the private method dependencies. Therefore this method checks if access to providers is unlocked. Unlocking happens via unlockProviders() after new instances of projects have been created, either in AbstractProject for regular projects or in DefaultBuildContext for the root 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 Intent.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.

        If a project implements MergedTestProject and does not specify a directory, its directory is set to the parent project's directory.

        For root projects the directory is always set to the current working directory.

  • 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

      Description copied from interface: Project
      Returns the root project.
      Specified by:
      rootProject in interface Project
      Returns:
      the project
    • project

      public Project 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
    • parentProject

      Description copied from interface: Project
      Returns the parent project. The root project has no parent.
      Specified by:
      parentProject in interface Project
      Returns:
      the parent project
    • name

      public String name()
      Description copied from interface: ResourceProvider
      Returns the name of this resource provider.
      Specified by:
      name in interface ResourceProvider
      Overrides:
      name in class AbstractProvider
      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)
      Description copied from interface: Project

      Adds a provider to the project that generates resources which are then provided by the project. For "normal" projects, the generated resources are assumed to be provided to dependents of the project, so the invocation is shorthand for
      dependency(Intent.Supply, generator).

      For projects that implement MergedTestProject, generated resources are usually intended to be used by the project itself only, so the invocation is short for dependency(Intent.Consume, generator).

      Specified by:
      generator in interface Project
      Parameters:
      provider - the provider
      Returns:
      the project
    • dependency

      public Project dependency(Intent intent, 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 Intent.Supply, it is recommended to use one of the "generator" methods for better readability.

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

      Description copied from interface: Project
      Return a provider selection without any restrictions.
      Specified by:
      providers in interface Project
      Returns:
      the provider selection
    • providers

      Description copied from interface: Project
      Return a provider selection that is restricted to the given intents.
      Specified by:
      providers in interface Project
      Parameters:
      intends - the intents
      Returns:
      the provider selection
    • 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 property type
      Parameters:
      property - the property
      Returns:
      the property
    • 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 <T extends Resource> Stream<T> doProvide(ResourceRequest<T> request)
      Description copied from class: AbstractProvider
      Invoked by ResourceProviderSpi.provide(ResourceRequest) after checking if the invocation is allowed.
      Specified by:
      doProvide in class AbstractProvider
      Type Parameters:
      T - the generic type
      Parameters:
      request - the request for resources
      Returns:
      the stream
    • projects

      public Stream<Project> projects(String pattern)
      Provide the projects matching the given ant-style path pattern.
      Parameters:
      pattern - the pattern
      Returns:
      the stream
      See Also:
    • hashCode

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

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

      public String toString()
      Overrides:
      toString in class AbstractProvider