Class Build
Supportive wrapper to manage a build. Nothing here is required. This class merely helps to
organize named targets, and update them according to a command line interface call. Ultimately
Machine.update(Target) is called, which can also be done directly.
Typical Usage in a file called src/buma/Buma.java:
- Optionally call
initLogging(OutputStream)for a reduced logging format. - Call the
Build(String, Path)constructor. - Optionally call
addBuildInspectionTargets(), a wrapper foraddDependencyTreeTarget()andaddTargetlisterTarget()which are nice defaults to get a quick overview about defined targets. - Optionally run
parseCmdline(String[])on yourmain's argument list to get a list of targets (for later, see below) and a map of parameterskey=valuethat may be used while creating the targets. - Use
add(String, Target)oraddAlias(String, String, Target)to add targets. - Call
updateAll(List)with the list of requested targets returned byparseCmdline.
Machine.update(Target) without even using this class.
NOTE:It is not necessary to register every target with the add* methods. In
particular technical intermediate dependencies that need not be called from the command line need
not be registered. By adding them as dependencies to other targets, they are linked into the
dependency graph anyway.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordProvided byparseCmdline(String[])static final recordProvided bytopologicallySorted(). -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBuild(String defaultTarget, SupplyOrThrow<StateStore> stateStoreSupplier) Creates the wrapper and specifies a default target.Creates the wrapper and specifies a default target. -
Method Summary
Modifier and TypeMethodDescription<T extends Target>
TAdds a target with description.<T extends Target>
Tadd(T target) Adds a target without description.<T extends Target>
TAdds a target under a different name with description.<T extends Target>
TCallsaddAlias(String, String, Target)with an empty description.voidShortcut for callingaddTargetlisterTarget()andaddDependencyTreeTarget().Adds a target with the name "dependencytree" to print a dependency tree in graphviz format.Adds a target with the name "targetlist" to print the list of targets we know about.getTargets(String... targetNames) Provides theTargetobjects for the given names.static voidinitLogging(OutputStream out) Initialize logging with a simple plain format.parseCmdline(String[] argv) Two types of command line arguments are handled.voidtargetsAndProperties(String[] argv) Deprecated.booleanLooks up the target name and calls aMachineinstance with the target found.voidTo be called with a list if target after after targets have been added.
-
Field Details
-
machine
TheMachinewe work with here.
-
-
Constructor Details
-
Build
Creates the wrapper and specifies a default target. Furtheradd(Target)calls must make sure the default target actually exists.- Parameters:
defaultTarget- to update if the command does not specify onestateStore- path for the file to keep state hashes for targets
-
Build
Creates the wrapper and specifies a default target. Furtheradd(Target)calls must make sure the default target actually exists.- Parameters:
defaultTarget- to update if the command does not specify onestateStoreSupplier- passed toMachine(SupplyOrThrow)
-
-
Method Details
-
getMachine
-
updateAll
To be called with a list if target after after targets have been added. A typical build script may have code likepublic static void main(String[] argv) { Build build = new Build(...); Cmdline cmdline = build.parseCmdline(argv); ListRunningtargets = targetsAndProperties(argv); ... // add targets with build.add() or build.addAlias() ... build.updateAll(targets); targetsAndPropertiesearly may be necessary if properties set on the command line are used during setup of the targets.- Parameters:
targets- list of targets to be updated- Throws:
BuildProblemException- as the need arises
-
targetsAndProperties
Deprecated.Rather useparseCmdline(java.lang.String[])to avoid confusion over the priority between system properties set with-Dkey=valueas a JVM argument andkey=valueas a main method argument.Two types of command line arguments are handled. If the argument contains a '=', it is split at the '=' into key and value and the pair is entered into the system properties. Otherwise the argument is treated as a target name and returned in the result list. If there are no targets, the default target is added to the result list. -
parseCmdline
Two types of command line arguments are handled. If the argument contains a '=', it is split at the '=' into key and value and the pair is entered into the the map returned as part of the result. Otherwise the argument is treated as a target name and returned in the result's list.If there are no targets, the default target is added to the result list.
-
getTargets
Provides theTargetobjects for the given names.- Parameters:
targetNames- to look up- Returns:
- a list of targets found
- Throws:
BuildProblemException- if a requested name has no target registered
-
addBuildInspectionTargets
public void addBuildInspectionTargets()Shortcut for callingaddTargetlisterTarget()andaddDependencyTreeTarget(). -
addTargetlisterTarget
Adds a target with the name "targetlist" to print the list of targets we know about. -
addDependencyTreeTarget
Adds a target with the name "dependencytree" to print a dependency tree in graphviz format. -
add
Adds a target without description.- Type Parameters:
T- the effective subclass of Target provided- Parameters:
target- to add- Returns:
- the target provided
-
add
Adds a target with description.- Type Parameters:
T- the effective subclass of Target provided- Parameters:
description- shown in output for option-tor bydescriptions()target- to add- Returns:
- the target provided
-
addAlias
Adds a target under a different name with description.- Type Parameters:
T- the effective subclass of Target provided- Parameters:
name- to use instead ofTarget.getName()description- shown in output for option-tor bydescriptions()target- to add- Returns:
- the target provided
-
addAlias
CallsaddAlias(String, String, Target)with an empty description. -
update
Looks up the target name and calls aMachineinstance with the target found.- Parameters:
name- of the target to update- Returns:
- true if the target was valid and its update was initiated. If false is returned, an error message describing valid targets was printed already.
- Throws:
BuildProblemException
-
descriptions
-
printDependencyTree
public void printDependencyTree() -
topologicallySorted
-
initLogging
Initialize logging with a simple plain format. If this method was called already, it is a NO-OP.Note: You may set the logging level with the environment variable
BUMA_LOGLEVEL, for example as
in bash.export BUMA_LOGLEVEL=FINEST
-
parseCmdline(java.lang.String[])to avoid confusion over the priority between system properties set with-Dkey=valueas a JVM argument andkey=valueas a main method argument.