Class DependencyGraphParser
- java.lang.Object
-
- org.eclipse.aether.internal.test.util.DependencyGraphParser
-
public class DependencyGraphParser extends java.lang.Object
Creates a dependency graph from a text description.Definition
Each (non-empty) line in the input defines one node of the resulting graph:line ::= (indent? ("(null)" | node | reference))? comment? comment ::= "#" rest-of-line indent ::= "| "* ("+" | "\\") "- " reference ::= "^" id node ::= coords (range)? space (scope("<" premanagedScope)?)? space "optional"? space ("relocations=" coords ("," coords)*)? ("(" id ")")? coords ::= groupId ":" artifactId (":" extension (":" classifier)?)? ":" version
The special token(null)
may be used to indicate an "empty" root node with no dependency.If
indent
is empty, the line defines the root node. Only one root node may be defined. The level is calculated by the distance from the beginning of the line. One level is three characters of indentation.The
^id
syntax allows to reuse a previously built node to share common sub graphs among different parent nodes.Example
gid:aid:ver +- gid:aid2:ver scope | \- gid:aid3:ver (id1) # assign id for reference below +- gid:aid4:ext:ver scope \- ^id1 # reuse previous node
Multiple definitions in one resource
By using
parseMultiResource(String)
, definitions divided by a line beginning with "---" can be read from the same resource. The rest of the line is ignored.Substitutions
You may define substitutions (see
setSubstitutions(String...)
,DependencyGraphParser(String, Collection)
). Every '%s' in the definition will be substituted by the next String in the defined substitutions.Example
parser.setSubstitutions( "foo", "bar" ); String def = "gid:%s:ext:ver\n" + "+- gid:%s:ext:ver";
The first node will have "foo" as its artifact id, the second node (child to the first) will have "bar" as its artifact id.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
DependencyGraphParser.LineContext
(package private) class
DependencyGraphParser.NodeEntry
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
prefix
private java.util.Collection<java.lang.String>
substitutions
private VersionScheme
versionScheme
-
Constructor Summary
Constructors Constructor Description DependencyGraphParser()
Create a parser with an empty prefix.DependencyGraphParser(java.lang.String prefix)
Create a parser with the given prefix.DependencyGraphParser(java.lang.String prefix, java.util.Collection<java.lang.String> substitutions)
Create a parser with the given prefix and the given substitution strings.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addNode(DependencyNode root, int level, java.util.List<DependencyGraphParser.NodeEntry> entries)
private DependencyNode
build(DependencyNode parent, DependencyGraphParser.LineContext ctx, boolean isRoot)
private static DependencyGraphParser.LineContext
createContext(java.lang.String line)
private static java.lang.String
cutComment(java.lang.String line)
java.lang.String
dump(DependencyNode root)
java.util.Collection<java.lang.String>
getSubstitutions()
private static boolean
isEmpty(java.lang.String line)
private boolean
isEOFMarker(java.lang.String line)
private DependencyNode
parse(java.io.BufferedReader in)
DependencyNode
parse(java.net.URL resource)
Parse the graph definition read from the given URL.DependencyNode
parseLiteral(java.lang.String dependencyGraph)
Parse the given graph definition.java.util.List<DependencyNode>
parseMultiResource(java.lang.String resource)
Parse multiple graphs in one resource, divided by "---".DependencyNode
parseResource(java.lang.String resource)
Parse the graph definition read from the given classpath resource.void
setSubstitutions(java.lang.String... substitutions)
void
setSubstitutions(java.util.Collection<java.lang.String> substitutions)
-
-
-
Field Detail
-
versionScheme
private final VersionScheme versionScheme
-
prefix
private final java.lang.String prefix
-
substitutions
private java.util.Collection<java.lang.String> substitutions
-
-
Constructor Detail
-
DependencyGraphParser
public DependencyGraphParser(java.lang.String prefix, java.util.Collection<java.lang.String> substitutions)
Create a parser with the given prefix and the given substitution strings.- See Also:
parseResource(String)
-
DependencyGraphParser
public DependencyGraphParser(java.lang.String prefix)
Create a parser with the given prefix.- See Also:
parseResource(String)
-
DependencyGraphParser
public DependencyGraphParser()
Create a parser with an empty prefix.
-
-
Method Detail
-
parseLiteral
public DependencyNode parseLiteral(java.lang.String dependencyGraph) throws java.io.IOException
Parse the given graph definition.- Throws:
java.io.IOException
-
parseResource
public DependencyNode parseResource(java.lang.String resource) throws java.io.IOException
Parse the graph definition read from the given classpath resource. If a prefix is set, this method will load the resource from 'prefix + resource'.- Throws:
java.io.IOException
-
parseMultiResource
public java.util.List<DependencyNode> parseMultiResource(java.lang.String resource) throws java.io.IOException
Parse multiple graphs in one resource, divided by "---".- Throws:
java.io.IOException
-
parse
public DependencyNode parse(java.net.URL resource) throws java.io.IOException
Parse the graph definition read from the given URL.- Throws:
java.io.IOException
-
parse
private DependencyNode parse(java.io.BufferedReader in) throws java.io.IOException
- Throws:
java.io.IOException
-
isEOFMarker
private boolean isEOFMarker(java.lang.String line)
-
isEmpty
private static boolean isEmpty(java.lang.String line)
-
cutComment
private static java.lang.String cutComment(java.lang.String line)
-
build
private DependencyNode build(DependencyNode parent, DependencyGraphParser.LineContext ctx, boolean isRoot)
-
dump
public java.lang.String dump(DependencyNode root)
-
addNode
private void addNode(DependencyNode root, int level, java.util.List<DependencyGraphParser.NodeEntry> entries)
-
createContext
private static DependencyGraphParser.LineContext createContext(java.lang.String line)
-
getSubstitutions
public java.util.Collection<java.lang.String> getSubstitutions()
-
setSubstitutions
public void setSubstitutions(java.util.Collection<java.lang.String> substitutions)
-
setSubstitutions
public void setSubstitutions(java.lang.String... substitutions)
-
-