Package bm.target

Class FixedStateTarget

java.lang.Object
bm.target.FixedStateTarget
All Implemented Interfaces:
StateProvider, Target

public class FixedStateTarget extends Object implements Target
A target with a state that cannot be changed by "building" it. Its behaviour is dictated by the constructor parameters which set it to either being always outdated or not, with or without a builder to be run if it is supposed to be run.
  • Constructor Details

    • FixedStateTarget

      public FixedStateTarget(Consumer<Consumer<byte[]>> stateBytesGenerator, String name, List<? extends Target> dependencies, ConsumeOrThrow<FixedStateTarget> builder)
      Creates a target with a fixed state generator. NOTE: This is public for experimental reasons only. For normal usage consider one of the factory methods.
      Parameters:
      stateBytesGenerator - a function to generate a few fake state bytes and fill them into the provided consumer
      name - of the target
      dependencies - on which this target depends
      builder - to be run if the build system decides so
  • Method Details

    • alias

      public static Target alias(String name, Target dependency)
      Creates a target with no builder which is never outdated itself. In effect, it will trigger building the dependency and look as if it was build itself if dependency was changed, so it is an alias for the dependency
      Parameters:
      name - of the target
      dependency - on which it depends
      Returns:
      the alias target
    • runAlways

      public static Target runAlways(String name, ConsumeOrThrow<FixedStateTarget> builder)
      Creates a target with no dependencies with a build which is always run.

      NOTE: This is done by creating a fake state each time the state is asked, so the state "now" is always different from the state "last time", meaning the builder is run. But this also has the effect that targets depending on this one will always be re-created, as the assumption is that the builder, if run, creates some new state.

      Parameters:
      name - of the target
      builder - to always run
      Returns:
      the target which always runs its builder
    • runAlways

      public static Target runAlways(String name, List<? extends Target> dependencies, ConsumeOrThrow<FixedStateTarget> builder)
      Creates a target with dependencies with a build which is always run.

      NOTE: see note for runAlways(String, ConsumeOrThrow)

      Parameters:
      name - of the target
      dependencies - on which it depends
      builder - to always run
      Returns:
      the target which always runs its builder
    • onDependencyChange

      public static Target onDependencyChange(String name, List<? extends Target> dependencies, ConsumeOrThrow<FixedStateTarget> builder)
      Creates a target with dependencies which runs the builder only if any of these change.
      Parameters:
      name - of the target
      dependencies - on which it depends
      builder - to eventually run
      Returns:
      the target
    • onDependencyChange

      public static Target onDependencyChange(String name, List<? extends Target> dependencies)
      Similar to alias(java.lang.String, bm.machine.Target) but for multiple dependencies
      Parameters:
      name - of the target
      dependencies - on which it depends
      Returns:
      the target
    • getName

      public String getName()
      Description copied from interface: Target
      The name of the target, unique within the graph of targets. It is used as the key for keeping a persistent state of the target in a StateStore. Some state stores have restrictions on characters which cannot be used.

      Note: using a non unique name can only be detected during the build and only if both targets of the same name are traversed.

      Specified by:
      getName in interface Target
      Returns:
      the name
    • getDependencies

      public List<Target> getDependencies()
      Description copied from interface: Target
      Return the list of targets this one depends on when being build. This should list all targets whose change should trigger a rebuild of this target.
      Specified by:
      getDependencies in interface Target
      Returns:
      the dependencies of this target
    • addState

      public void addState(Consumer<byte[]> sink)
      Description copied from interface: StateProvider
      Given a sink for byte[] this method should provide bytes representing a target's value. If the value changes, the bytes provided must change too. But the bytes may also change if the value was not actually changed, though this will result in unnecessary builts of a target.

      This should not mingle in any dependency data.

      As examples consider the full byte content of a file or only its last modified time. The latter changes even if a file is overwritten by itself, but for some cases, i.e. huge files, the time stamp may be preferable.

      Specified by:
      addState in interface StateProvider
      Parameters:
      sink - into which to fill the state representing bytes
    • recreate

      public void recreate() throws BuildProblemException
      Description copied from interface: Target
      Recreate this target.
      Specified by:
      recreate in interface Target
      Throws:
      BuildProblemException - as needed
    • toString

      public String toString()
      Overrides:
      toString in class Object