User talk:Paint Ninja/Installer
see Actions.java
, Action.java
, ClientInstall/ServerInstall/ExtractAction.java
example with ExtractAction
:
final Actions action = Actions.EXTRACT;
action.getAction(installProfile, monitor)
will refer to the BiFunction<Install, ProgressCallback, Action>
action
inside the Actions.java
enum which Actions.EXTRACT
specifically populates as a new instance of
ExtractAction.java
as the BiFunction
(a BiFunction
being an Object
that takes two inputs, can do some work and has one output).
The Install installProfile
and ProgressCallback monitor
arguments are then applied to the BiFunction
,
which causes ExtractAction
's constructor to be called with those arguments.
ExtractAction
's constructor calls its parent constructor (Action.java) with super(profile, monitor, true)
.
true being isClient
here.
Action.java
's constructor populates some variables and instantiates PostProcessors.java
, which calls
the installProfile
's getProcessors("client")
and getData(true)
methods and stores their results in a
List<Processor>
and a Map<String, String>
, respectively. Install#getProcessors()
will return an empty list
and Install#getData()
will return a new, empty HashMap
, this is just to set things up for when the action
is ran.
action.getAction(installProfile, monitor).run(target, a -> true)
The ExtractAction.java
overrides the run(File, Predicate<String>)
method. In this case, the args from the
run method invocation above provide the target directory to extract to and what's basically an unused
truthy boolean value.
This run method returns true if successful and false otherwise. It gets the path
variable from the parsed
installProfile
, which is the Maven artifact path for the 'main' jar and is an instance of Artifact.java
.
Artifact.java
uses an Adapter
subclass that implements a JSON deserializer and serializer that gets the
JSON primitive String and calls the Artifact#from(String) to split the maven descriptor into its parts and
build a path to it inside the Installer jar.
It then calls DownloadUtils#extractFile(Artifact, File, String) with the Maven artifact path to extract from,
the target path to put it in when extracted and a null
(meaning don't verify its checksum after extracting it).
Extracting the Artifact
is easier than it sounds, it just grabs a file embedded within the jar under the
maven folder (similar to how the install_profile.json is obtained) and copies it to the target path,
overwriting any existing files there and creating directories to put them in when necessary.
if (action.getAction(installProfile, monitor).run(target, a -> true)) {