Class VariationDiffRenderer
java.lang.Object
org.variantsync.diffdetective.variation.diff.render.VariationDiffRenderer
A VariationDiffRenderer renders VariationDiffs and CommitDiffs.
The renderer may be configured with
RenderOptions
.
Internally, this renderer will invoke a python render script.- Author:
- Paul Bittner
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final Supplier<PythonCommand>
private static final Path
private static final Path
private final Supplier<PythonCommand>
private final Path
-
Constructor Summary
ModifierConstructorDescriptionprivate
VariationDiffRenderer
(Supplier<PythonCommand> pythonCommandFactory, Path workDir) -
Method Summary
Modifier and TypeMethodDescriptionstatic VariationDiffRenderer
FromThirdPartyApplication
(Path relativePathFromWorkDirToDiffDetectiveSources, Path workDir) Combination ofWithinDiffDetective()
andFromThirdPartyApplication(Supplier, Path)
.static VariationDiffRenderer
FromThirdPartyApplication
(Supplier<PythonCommand> pythonCommandFactory, Path workDir) Creates a renderer that operates from a third party application (i.e., a program that uses DiffDetective as a library).boolean
Invokesrender(PatchDiff, Path, RenderOptions)
with thedefault render options
.boolean
render
(PatchDiff patchDiff, Path directory, RenderOptions<? super DiffLinesLabel> options) Invokesrender(VariationDiff, GitPatch, Path, RenderOptions)
by extracting the given patchDiff's VariationDiff.boolean
render
(PatchDiff patchDiff, Path directory, RenderOptions<? super DiffLinesLabel> options, LineGraphExportOptions<? super DiffLinesLabel> exportOptions) Invokesrender(VariationDiff, GitPatch, Path, RenderOptions, LineGraphExportOptions)
by extracting the given patchDiff's VariationDiff.<L extends Label>
booleanrender
(VariationDiff<? extends L> tree, String treeAndFileName, Path directory, RenderOptions<? super L> options) <L extends Label>
booleanrender
(VariationDiff<? extends L> tree, String treeAndFileName, Path directory, RenderOptions<? super L> options, LineGraphExportOptions<? super L> exportOptions) Invokesrender(VariationDiff, String, Path, RenderOptions, LineGraphExportOptions, BiFunction)
with the a default tree header factory.private <L extends Label>
booleanrender
(VariationDiff<? extends L> tree, String treeAndFileName, Path directory, RenderOptions<? super L> options, LineGraphExportOptions<? super L> exportOptions, BiFunction<String, VariationDiffSource, String> treeHeader) Renders the given VariationDiff to an image file.<L extends Label>
booleanrender
(VariationDiff<L> tree, String treeAndFileName, Path directory) Invokesrender(VariationDiff, String, Path, RenderOptions)
with thedefault render options
.<L extends Label>
booleanrender
(VariationDiff<L> tree, GitPatch patch, Path directory, RenderOptions<? super L> options) <L extends Label>
booleanrender
(VariationDiff<L> tree, GitPatch patch, Path directory, RenderOptions<? super L> options, LineGraphExportOptions<? super L> exportOptions) Invokesrender(VariationDiff, String, Path, RenderOptions, LineGraphExportOptions)
by creating a name for the tree and its produced image file.boolean
renderFile
(Path lineGraphFile) InvokesrenderFile(Path, RenderOptions)
with thedefault render options
.<L extends Label>
booleanrenderFile
(Path lineGraphFile, RenderOptions<? super L> options) Renders the given linegraph file with the given options.<L extends Label>
booleanrenderWithTreeFormat
(VariationDiff<? extends L> tree, String treeAndFileName, Path directory, RenderOptions<? super L> options) Invokesrender(VariationDiff, String, Path, RenderOptions, LineGraphExportOptions, BiFunction)
with the a default tree header factory.static VariationDiffRenderer
Use this method only in DiffDetective and not from a project using DiffDetective as a library.
-
Field Details
-
DiffDetectiveRenderScriptPath
-
DiffDetectiveWorkDir
-
DiffDetectivePythonCommand
-
workDir
-
pythonCommandFactory
-
-
Constructor Details
-
VariationDiffRenderer
-
-
Method Details
-
WithinDiffDetective
Use this method only in DiffDetective and not from a project using DiffDetective as a library. Creates a preconfigured renderer that uses the python virtual environment shipped with DiffDetective's source code.- Returns:
- A renderer that may be used from applications within DiffDetective itself.
-
FromThirdPartyApplication
public static VariationDiffRenderer FromThirdPartyApplication(Supplier<PythonCommand> pythonCommandFactory, Path workDir) Creates a renderer that operates from a third party application (i.e., a program that uses DiffDetective as a library).- Parameters:
pythonCommandFactory
- A factory to create a python command that renders the given path. The factory thus specifies the python instance to run and the location of the render script. DiffDetective comes with a render script in linegraph/renderLinegraph.py. However, when invoking this method from a third party application, the location of this script is unknown. Thus, pythonCommandFactory has to locate this script and create a PythonCommand running it. Assume r is an absolute path to renderLinegraph.py on your file system and you want to use python3. Then a possible a value for pythonCommandFactory would be: () -> PythonCommand.Python3(r);workDir
- Working directory, to run the rendering in.- Returns:
- A renderer that uses the given python instance and render script to render diff trees.
-
FromThirdPartyApplication
public static VariationDiffRenderer FromThirdPartyApplication(Path relativePathFromWorkDirToDiffDetectiveSources, Path workDir) Combination ofWithinDiffDetective()
andFromThirdPartyApplication(Supplier, Path)
. This method produces a renderer that uses the virtual environment within DiffDetective's source code but that can be used from another application. Use this, when you integrated DiffDetective as a library in your project but you still have the DiffDetective repository cloned on your disk.- Parameters:
relativePathFromWorkDirToDiffDetectiveSources
- Path relative from the given working directory to the root directory of your local copy of the DiffDetective git repository.workDir
- Path to your working directory. May be absolute or relative.- Returns:
- A renderer that uses the python virtual environment in the DiffDetective source files from an external application.
-
render
Invokesrender(PatchDiff, Path, RenderOptions)
with thedefault render options
. -
render
public boolean render(PatchDiff patchDiff, Path directory, RenderOptions<? super DiffLinesLabel> options) Invokesrender(VariationDiff, GitPatch, Path, RenderOptions)
by extracting the given patchDiff's VariationDiff. -
render
public boolean render(PatchDiff patchDiff, Path directory, RenderOptions<? super DiffLinesLabel> options, LineGraphExportOptions<? super DiffLinesLabel> exportOptions) Invokesrender(VariationDiff, GitPatch, Path, RenderOptions, LineGraphExportOptions)
by extracting the given patchDiff's VariationDiff. -
render
public <L extends Label> boolean render(VariationDiff<L> tree, GitPatch patch, Path directory, RenderOptions<? super L> options) -
render
public <L extends Label> boolean render(VariationDiff<L> tree, GitPatch patch, Path directory, RenderOptions<? super L> options, LineGraphExportOptions<? super L> exportOptions) Invokesrender(VariationDiff, String, Path, RenderOptions, LineGraphExportOptions)
by creating a name for the tree and its produced image file. The createdtreeAndFileName
is the given patches file name and commit hash, separated byLineGraphConstants.TREE_NAME_SEPARATOR
. -
render
public <L extends Label> boolean render(VariationDiff<L> tree, String treeAndFileName, Path directory) Invokesrender(VariationDiff, String, Path, RenderOptions)
with thedefault render options
. -
render
public <L extends Label> boolean render(VariationDiff<? extends L> tree, String treeAndFileName, Path directory, RenderOptions<? super L> options) -
render
public <L extends Label> boolean render(VariationDiff<? extends L> tree, String treeAndFileName, Path directory, RenderOptions<? super L> options, LineGraphExportOptions<? super L> exportOptions) Invokesrender(VariationDiff, String, Path, RenderOptions, LineGraphExportOptions, BiFunction)
with the a default tree header factory. The tree header factory uses the giventreeAndFileName
to createLineGraphConstants.LG_TREE_HEADER + " " + treeAndFileName + LineGraphConstants.TREE_NAME_SEPARATOR + "0"
. -
renderWithTreeFormat
public <L extends Label> boolean renderWithTreeFormat(VariationDiff<? extends L> tree, String treeAndFileName, Path directory, RenderOptions<? super L> options) Invokesrender(VariationDiff, String, Path, RenderOptions, LineGraphExportOptions, BiFunction)
with the a default tree header factory. The tree header factory uses the giventreeAndFileName
to createLineGraphConstants.LG_TREE_HEADER + " " + treeAndFileName + LineGraphConstants.TREE_NAME_SEPARATOR + "0"
. -
render
private <L extends Label> boolean render(VariationDiff<? extends L> tree, String treeAndFileName, Path directory, RenderOptions<? super L> options, LineGraphExportOptions<? super L> exportOptions, BiFunction<String, VariationDiffSource, String> treeHeader) Renders the given VariationDiff to an image file. First, exports the tree to a linegraph file. Second, invokes a python render script with the produced linegraph file as input. The python script will produce an image file at the given directory.- Parameters:
tree
- The tree to render.treeAndFileName
- A name for the written file as well as the tree (used as a caption in the produced image).directory
- The directory to which the rendered file should be written to.options
- Configuration options for the rendering process.exportOptions
- Configuration options for the intermediate export to the linegraph format. Should be compatible with the render options. Most of the time, you just want to useRenderOptions.toLineGraphOptions()
here.treeHeader
- A factory that produces a name for the given tree in the intermediate linegraph file. The function is invoked on the given treeAndFileName as first argument and the given VariationDiff's source as second argument.- Returns:
- True iff rendering was successful. False iff an error occurred.
-
renderFile
InvokesrenderFile(Path, RenderOptions)
with thedefault render options
. -
renderFile
Renders the given linegraph file with the given options.- Parameters:
lineGraphFile
- The path of a linegraph file in which only VariationDiffs are stored.options
- Configuration options for the rendering process.- Returns:
- True iff rendering was successful. False iff an error occurred.
-