org.sonatype.aether.test.util
Class DependencyGraphParser

java.lang.Object
  extended by org.sonatype.aether.test.util.DependencyGraphParser

public class DependencyGraphParser
extends Object

Creates a dependency tree from a text description.

Definition

The description format is based on 'mvn dependency:tree'. Line format:
 [level]dependencyDefinition[;key=value;key=value;...]
 
A dependencyDefinition is of the form:
 (id|[(id)]gid:aid:ext:ver[:scope])
 
It may also be (null) to indicate an "empty" node with no dependency.

Levels

If level 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. A level definition has to follow this format:

 '[| ]*[+\\]- '
 

ID

An ID may be used to reference a previously built node. An ID is of the form:
 '[0-9a-zA-Z]+'
 
To define a node with an ID, prefix the definition with an id in parens:
 (id)gid:aid:ext:ver
 
To insert a previously defined node into the graph, use a caret followed by the ID:
 ^id
 

Comments

A hash starts a comment. A comment ends with the end of the line. Empty lines are ignored.

Example

 gid:aid:ext:ver
 +- gid:aid2:ext:ver:scope
 |  \- (id1)gid:aid3:ext:ver
 +- gid:aid4:ext:ver:scope
 \- ^id1
 

Multiple definitions in one resource

By using parseMultiple(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.

Author:
Benjamin Hanzelmann

Constructor Summary
DependencyGraphParser()
          Create a parser with an empty prefix.
DependencyGraphParser(String prefix)
          Create a parser with the given prefix.
DependencyGraphParser(String prefix, Collection<String> substitutions)
          Create a parser with the given prefix and the given substitution strings.
 
Method Summary
 String dump(DependencyNode root)
           
 Collection<String> getSubstitutions()
           
 DependencyNode parse(String resource)
          Parse the graph definition read from the given resource.
 DependencyNode parse(URL resource)
          Parse the graph definition read from the given URL.
 DependencyNode parseLiteral(String dependencyGraph)
          Parse the given graph definition.
 List<DependencyNode> parseMultiple(String resource)
          Parse multiple graphs in one resource, divided by "---".
 void setSubstitutions(Collection<String> substitutions)
           
 void setSubstitutions(String... substitutions)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DependencyGraphParser

public DependencyGraphParser(String prefix,
                             Collection<String> substitutions)
Create a parser with the given prefix and the given substitution strings.

See Also:
parse(String)

DependencyGraphParser

public DependencyGraphParser(String prefix)
Create a parser with the given prefix.

See Also:
parse(String)

DependencyGraphParser

public DependencyGraphParser()
Create a parser with an empty prefix.

Method Detail

parseLiteral

public DependencyNode parseLiteral(String dependencyGraph)
                            throws IOException
Parse the given graph definition.

Throws:
IOException

parse

public DependencyNode parse(String resource)
                     throws IOException
Parse the graph definition read from the given resource. If a prefix is set, this method will load the resource from 'prefix + resource'.

Throws:
IOException

parseMultiple

public List<DependencyNode> parseMultiple(String resource)
                                   throws IOException
Parse multiple graphs in one resource, divided by "---".

Throws:
IOException

parse

public DependencyNode parse(URL resource)
                     throws IOException
Parse the graph definition read from the given URL.

Throws:
IOException

dump

public String dump(DependencyNode root)

getSubstitutions

public Collection<String> getSubstitutions()

setSubstitutions

public void setSubstitutions(Collection<String> substitutions)

setSubstitutions

public void setSubstitutions(String... substitutions)


Copyright © 2010-2011 Sonatype, Inc.. All Rights Reserved.