public final class DependencyTracker extends java.lang.Object implements SymbolDependencyContainer
A DependencyTracker can include predefined dependencies loaded from a file (for example to track versions of runtime dependencies used in the generator), or dependencies that are accumulated dynamically as code is generated.
Notes:
Dependencies can be loaded from a JSON file to more easily track dependencies used at runtime by generated code. This feature can also be used to generate the dependencies tracked by the generated from from other dependency graph formats like lockfiles.
The JSON file has the following format:
{
"version": "1.0",
"dependencies": [
{
"packageName": "string",
"version": "string",
"dependencyType": "string",
"properties": {
"x": true,
"y": [10],
"z": "string"
}
}
]
}
List
, map values are converted to
a Map
, boolean values to Java's boolean, numeric values to an
appropriate Number
type, and string values to String
.Constructor and Description |
---|
DependencyTracker() |
Modifier and Type | Method and Description |
---|---|
void |
addDependencies(SymbolDependencyContainer container)
Adds dependencies from a
SymbolDependencyContainer . |
void |
addDependenciesFromJson(java.net.URL jsonFile)
Loads predefined dependencies from a JSON file (for example, to track
known dependencies used by generated code at runtime).
|
void |
addDependency(java.lang.String packageName,
java.lang.String version,
java.lang.String dependencyType)
Adds a dependency.
|
void |
addDependency(SymbolDependency dependency)
Adds a dependency.
|
SymbolDependency |
getByName(java.lang.String name)
Gets the first found dependency by name.
|
SymbolDependency |
getByName(java.lang.String name,
java.lang.String dependencyType)
Gets the first found dependency by name and dependency type.
|
java.util.List<SymbolDependency> |
getByProperty(java.lang.String property)
Gets a list of matching dependencies that contain a property named
property . |
java.util.List<SymbolDependency> |
getByProperty(java.lang.String property,
java.lang.Object value)
Gets a list of matching dependencies that contain a property named
property with a value of value . |
java.util.List<SymbolDependency> |
getByType(java.lang.String dependencyType)
Gets a list of matching dependencies that have a dependency type
matching
dependencyType . |
java.util.List<SymbolDependency> |
getDependencies()
Gets the list of dependencies that this object introduces.
|
public java.util.List<SymbolDependency> getDependencies()
SymbolDependencyContainer
A dependency is a dependency on another package that a Symbol or type requires. It is quite different from a reference since a reference only refers to a symbol; a reference provides no context as to whether or not a dependency is required or the dependency's coordinates.
getDependencies
in interface SymbolDependencyContainer
public SymbolDependency getByName(java.lang.String name)
name
- Package name of the dependency to get.java.lang.IllegalArgumentException
- if the dependency cannot be found.public SymbolDependency getByName(java.lang.String name, java.lang.String dependencyType)
name
- Package name of the dependency to get.dependencyType
- The dependency type of package to find.java.lang.IllegalArgumentException
- if the dependency cannot be found.public java.util.List<SymbolDependency> getByType(java.lang.String dependencyType)
dependencyType
.dependencyType
- Dependency type to find.public java.util.List<SymbolDependency> getByProperty(java.lang.String property)
property
.property
- Property to find.public java.util.List<SymbolDependency> getByProperty(java.lang.String property, java.lang.Object value)
property
with a value of value
.property
- Property to find.value
- Value to match.public void addDependency(SymbolDependency dependency)
dependency
- Dependency to add.public void addDependency(java.lang.String packageName, java.lang.String version, java.lang.String dependencyType)
packageName
- Name of the dependency.version
- Version of the dependency.dependencyType
- Type of dependency (e.g., "dev", "test", "runtime", etc).
This value wholly depends on the type of dependency graph
being generated.public void addDependencies(SymbolDependencyContainer container)
SymbolDependencyContainer
.container
- Container to copy depdencies from.public void addDependenciesFromJson(java.net.URL jsonFile)
DependencyTracker tracker = new DependencyTracker();
tracker.addDependenciesFromJson(getClass().getResource("some-file.json"));
jsonFile
- URL location of the JSON file.