Skip to content

Commit 2f440b2

Browse files
committed
Merge branch 'release/0.16.0'
2 parents 2e6a650 + b7171aa commit 2f440b2

21 files changed

Lines changed: 356 additions & 117 deletions

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ env:
77
- secure: SvDSFrQ5K5M6ChNoKkQr7K6Js98UkIzPali4p/RdmKo0WiA5+KqmUE+OPcHGhkjV+hcThRddoA0GrKNr5OlxeB1yh0idy1qQI3UPD+lPx1mu6Ootf9qOzhDEN9q8W4zkAYnpcN6EjwaqxUSG+jaD6SVfHo84D7CaG8FasfjbGjoe7q8n+IHebsWMuDfTU4f5jM/Vc2vsELX8f7DVpseCkO+hl158tldTTkeRQ0J1xzs2AJ+bViQrpUHFff1IjR5bGXnjr087Dfiw0owcJa90jcC59JhpSVh3Cc2KEO1z0Ww2j34XpwFUmPV0yeYlegEkyfpFXhCQUE4pe1D0RailDg9uWyKHvucxiYIUNNGuYiJ6ipPL7fn44fLzdBB2iaNFFZBMJbcHgrtuQ44W67Fn9bRPCsYbbcLzKqHGijWCzLlZd9ZEFT73uroRNwpN7jTNrloPlThL0Hnc1asY9fd/8y+51PYJgXardqArD5WrMrHMfghwnz8EozpInj+yAngGX3vyxZfc13Kp4g0pOnI508UAxbogZm4ZC39W+8ObmKHNb0ge00YVv3l5iWdPMk41edZYvhXmfuN40hQTcQuvJNHfq/aAxNwfsdR5k/2F3dGocD7qUBYdmsLG9L1VaHtf+0x+qbsL6U5RjzcuewXpD4F3YT2T3pFE8MViWXs/Or8=
88
- secure: j4xRmR3NcnlimR4HLlq3HfYHokW9RjuVmaUAaICuJ7R6ujoczvwIfOGfa7Y0OqQNcoNeyfAcgdukC+M7nurJHd1Hpb0usKri3yLK40ZVohSMhODAwe80JV6Xp2zgLvhvDdmZ5t8LSMDSRJ8eybaMIHjNBDF3X7mFYrYYfdRpZzfQRhayTGVCuu5fL0Wp6YPA1H5lR6IPuVS9oORD/XgD2TGOR2VuH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DktIYklJTD5hw0blG2AP3BcP7/Z66JzfTpzcP/0zVJx8OI9b8IhFaXF9sue2XpwGOR6WD0MCdVf6hkBb5v3qaXReg=
10+
- secure: nk3LnR4tVx7MXR4oGo3NUTEIjFi9hytdLl7OkXvG15IfC/ZM7FRhrfVAmLfGA0f9r5E1+OBloGxxdZoT7AyC77CjVbQm3I/y114q8ByJp2YlO8CkPJB4seWVNRohVcsmYkB+f8F1CyJPVkwWy5NcffAOo7f+s37sVOcW1W64i9hoHXi6URMhOzORkMck3tzj55Yf8sd02vRiLbWvJ/eSlkKqLUX+jHyzvH0b3ltltnh/s5EnCdxCjATpSBAwqsOl4qS6Eik/ph6yJHbSCQXOkUyoNQC39uPQrzABTe7ii2NStT1CKjrnQyb4QdO35ilUdiLundZUJnLs0j+uX/zXpqKaPQ80d06HC1MUEmm5LWAfXdgjK+oY00R95T6RmM+PRvxpcb7OkkGCC2IT81fgSdmTAFDd6XsfIUtXu4ueN8VG3GiCv/7JCAbQHgquFt+Cabqfza56bUnhRUJMhiTN37fcOAo6HSRO1LmZ0YnP+I8+LAJWBWT356x8sdj4iyEqHf0QeFw90Xz+eGlbnHMIZm8GTXIpygNYCp01+nizFhcgUjPW8dXzLMN0IEhEwOO9357/bjHYfWa7I0qWe2HGsYeyBuU4jow3kkJ6dbIIi+5kd3GgBSMGqrmmqQK70VYYsFPmX4LHvN6JagWs+bEY7xHsbzmTrOiAF8YoNIWXuYc=
1011
before_cache:
1112
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
1213
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/

README.md

Lines changed: 117 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ check the [wiki](https://github.com/moaxcp/graph-dsl/wiki).
88

99
```groovy
1010
#!/usr/bin/env groovy
11-
@Grab(group='com.github.moaxcp', module='graph-dsl', version='0.11.0')
11+
@Grab(group='com.github.moaxcp', module='graph-dsl', version='0.15.0')
1212
```
1313

1414
## Creating a graph
1515

16-
The basic graph structure is held in a map of named vertices and a set of edges.
17-
18-
All referenced vertices are created if they don't exist.
16+
The entry-point to the dsl is the `Graph.graph(Closure)` method. This method applies the closure to a new Graph object
17+
and returns it.
1918

2019
```groovy
2120
def graph = graph {
@@ -26,44 +25,65 @@ assert graph.edges.size() == 1
2625
assert graph.edges.first() == new Edge(one:'step1', two:'step2') //edge was created!
2726
```
2827

29-
This example of a graph creates two vertices named 'step1' and 'step2' as well as an edge between them. There are many
30-
other methods for creating vertices and edges.
28+
This example of a graph creates two vertices named 'step1' and 'step2' as well as an edge between them. The basic graph
29+
structure is held in a map of named Vertex objects and a set of Edge objects. Each Edge contains the names of the two
30+
vertices it connects.
31+
32+
There are a few rules the dsl follows as it is being processed:
33+
34+
1. At the end of an operation all referenced vertices are created if they don't exist.
35+
2. If an edge or vertex already exists it will be reused by and operation.
36+
37+
This gives the developer flexibility to create and modify the graph in many different ways.
3138

3239
```groovy
33-
graph.with {
40+
def workQueue = new LinkedList()
41+
graph {
3442
edge (A, B) {
35-
traits Mapping, Mapping
36-
queue = new LinkedList()
43+
traits Mapping, Weight
44+
queue = workQueue
3745
weight { queue.size() }
3846
}
3947
4048
vertex A(traits:Mapping) {
4149
action = {
4250
println "processing"
51+
workQueue << "work"
4352
}
4453
}
4554
4655
vertex B {
4756
traits Mapping
4857
action = {
49-
println "done processing"
58+
println "done processing ${workQueue.poll()}"
5059
}
5160
}
5261
}
5362
```
5463

64+
In this graph the edge method creates the vertices A and B as well as an edge. It also configures the edge to have a
65+
queue and a weight that is the size of the queue. The vertices A and B are also configured to perform an action. A adds
66+
work to the queue and B processes the work.
67+
5568
The Default behavior of a graph is that of an undirected graph. These graphs have a set of edges where only one edge
56-
can connect any two vertices. This behavior can be changed to a directed graph at any time using the DirectedGraphPlugin
69+
can connect any two vertices. An undirected graph can be changed to a directed graph at any time using
70+
`DirectedGraphPlugin`.
5771

5872
```groovy
59-
graph.apply DirectedGraphPlugin
73+
graph {
74+
//lots of code
75+
apply DirectedGraphPlugin
76+
//lots of code
77+
}
6078
```
6179

62-
Traits can be added to all edges and vertices.
80+
Traits can be added to all edges and vertices using `edgeTraits` and `vertexTraits`.
6381

6482
```groovy
65-
graph.edgeTraits Mapping, Weight
66-
graph.vertexTraits Mapping
83+
graph {
84+
edgeTraits Mapping, Weight
85+
vertexTraits Mapping
86+
}
6787
```
6888

6989
## Traversing a graph
@@ -74,23 +94,23 @@ Once a graph is created there is a dsl for depthFirstTraversal and breadthFirstT
7494
graph {
7595
apply DirectedGraphPlugin
7696
vertex A {
77-
edgesFirst 'B', 'D', 'E'
78-
edgesSecond 'D'
97+
connectsTo 'B', 'D', 'E'
98+
connectsFrom 'D'
7999
}
80-
100+
81101
vertex D {
82-
edgesFirst 'C', 'E'
83-
edgesSecond 'B'
102+
connectsTo 'C', 'E'
103+
connectsFrom 'B'
84104
}
85-
105+
86106
edge B, C
87107
depthFirstTraversal {
88108
root = 'A'
89109
preorder { vertex ->
90110
println vertex.name
91111
}
92112
}
93-
113+
94114
breadthFirstTraversal {
95115
root = 'A'
96116
visit { vertex ->
@@ -100,26 +120,29 @@ graph {
100120
}
101121
```
102122

103-
## Functional methods
123+
## Functional search methods
104124

105-
There are functional methods build on the depthFirstTraversal and breadthFirstTraversal method.
125+
There are functional search methods build on the depthFirstTraversal and breadthFirstTraversal method. These methods
126+
follow the standard names in groovy: each, find, inject, findAll, collect. The methods can specify which type of
127+
search to perform such as `eachBfs` or `eachDfs`. When a search type is not specified the methods default to depth
128+
first search.
106129

107130
```groovy
108131
eachBfs {
109132
println it.name
110133
}
111-
134+
112135
def vertex = findBfs {
113136
it.name == 'A'
114137
}
115-
138+
116139
def bfsOrder = collectBfs {
117140
it.name
118141
}
119142
```
120143

121-
Note: These methods are not yet implemented for depth first traversal. The depth first traversal methods will be the
122-
defaults for each, find, inject, findAll, and collect.
144+
Note: These methods are not yet implemented for depth first traversal. The depth first search methods will be the
145+
defaults when a search type is not specified.
123146

124147
## Edge Classification
125148

@@ -130,10 +153,70 @@ Depth first traversal supports edge classification where an edge is classified a
130153
* forward-edge - when the destination vertex is black
131154
* cross-edge - when the destination vertex is black and in a different tree
132155

156+
To classify edges use the `classifyEdges(Closure)` method.
157+
158+
```
159+
graph {
160+
//setup graph
161+
classifyEdges { from, to, edgeType ->
162+
println "$from $to is $edgeType"
163+
}
164+
}
165+
```
166+
167+
`classifyEdges` returns an EdgeClassification object. This object contains lists of all back edges, tree-edges,
168+
forward edges, and cross edges. There is also a new Graph called forest that gets created.
169+
`EdgeClassification.forrest` contains the forrest created by tree edges. It uses the vertex and edge objects
170+
from the original graph object.
171+
172+
# Plugins
173+
174+
Plugins provide graphs with extra functionality. They can:
175+
176+
1. Modify all edges and vertices by adding traits or replacing them
177+
2. modify the factories so they create different edges and vertices
178+
3. perform meta-programming on the graph to change or add methods
179+
180+
## DirectedGraphPlugin
181+
182+
The DirectedGraphPlugin changes the behavior of a graph to that of a directed graph. In a directed graph edges
183+
become directional. Only two edges can exist between any two vertices. In that case, the edges need to go in
184+
opposite directions.
185+
186+
Traversal methods will only follow out edges from a vertex.
187+
133188
## EdgeWeightPlugin
134189

135190
This plugin applies Weight to all edges and changes all traversal methods to follow edges in order of their weight.
136191

192+
## EdgeMapPlugin
193+
194+
All edges and all future edges will have the Mapping triat.
195+
196+
Note: will probably be deleted in the future.
197+
198+
## VertexMapPlugin
199+
200+
All vertices and all future vertices will have the Mapping trait.
201+
202+
Note: will probably be deleted in the future.
203+
204+
# Traits
205+
206+
Traits are standard groovy traits that developers or plugins can apply to Vertex or Edge
207+
delegates. The Vertex and Edge objects call their delegate when a method or property is
208+
missing. This allows properties and methods to be added to a Vertex or Edge at runtime.
209+
210+
## Mapping
211+
212+
Allows a vertex or edge to act like a Map. When a property is missing in the delegate this
213+
trait will return or set the value in its map.
214+
215+
## Weight
216+
217+
Adds a weight property to a vertex or map. The weight is set with the `weight` method passing
218+
in a closure. This makes the weight lazy so it can change dynamically.
219+
137220
# Getting Started With Development/Contributing
138221

139222
## install git
@@ -189,12 +272,17 @@ If there are any issues contact me moaxcp@gmail.com.
189272
* [groovy](http://www.groovy-lang.org/)
190273
* [spock](http://spockframework.org/)
191274
* [jacoco](http://www.eclemma.org/jacoco/)
192-
* [sonarqube.com](https://sonarqube.com/dashboard?id=com.github.moaxcp%3Agraph-dsl)
193275
* [travis-ci.org](https://travis-ci.org/moaxcp/graph-dsl)
194276
* [oss sonatype](https://oss.sonatype.org/#welcome)
195277

196278
# Releases
197279

280+
## 0.16.0
281+
282+
* [#80](https://github.com/moaxcp/graph-dsl/issues/80) Removed sonarqube since it no longer supports groovy
283+
* [#78](https://github.com/moaxcp/graph-dsl/issues/78) Changed edgesFirst and edgesSecond in dsl to connectsTo and connectsFrom.
284+
* [#77](https://github.com/moaxcp/graph-dsl/issues/77) renameOne and renameTwo in edge methods will not add extra vertex objects to the graph.
285+
198286
## 0.15.0
199287

200288
This release combines fixes for a few issues on github.

build.gradle

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
plugins {
1010
id 'net.ossindex.audit' version '0.1.1'
1111
id 'io.codearte.nexus-staging' version '0.8.0'
12-
id 'org.sonarqube' version '2.4'
12+
id "org.standardout.versioneye" version "1.4.0"
1313
}
1414

1515
apply plugin: 'idea'
@@ -25,14 +25,19 @@ description = 'A groovy dsl for creating and traversing graphs.'
2525

2626
sourceCompatibility = 1.8
2727
targetCompatibility = 1.8
28-
ext.groovyVersion = '2.5.0-alpha-1'
28+
ext.groovyVersion = '2.5.0-beta-1'
29+
30+
versioneye {
31+
includePlugins = true
32+
exclude configurations.findAll { !it.canBeResolved }*.name as String[]
33+
}
2934

3035
jacocoTestReport {
3136
dependsOn test
3237
}
3338

3439
gradle.taskGraph.whenReady { graph ->
35-
if (graph.hasTask(':jacocoTestReport') || graph.hasTask(':sonarqube')) {
40+
if (graph.hasTask(':jacocoTestReport')) {
3641
compileGroovy.groovyOptions.optimizationOptions.all = false
3742
logger.warn 'all groovy optimizations are turned off for jacoco'
3843
}

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
versioneye.projectid=585c8b96ec634d004c628b9c

graph-dsl.ipr

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project version="4">
3+
<component name="CompilerConfiguration">
4+
<option name="DEFAULT_COMPILER" value="Javac"/>
5+
<resourceExtensions>
6+
<entry name=".+\.(properties|xml|html|dtd|tld)"/>
7+
<entry name=".+\.(gif|png|jpeg|jpg)"/>
8+
</resourceExtensions>
9+
<wildcardResourcePatterns>
10+
<entry name="!?*.class"/>
11+
<entry name="!?*.scala"/>
12+
<entry name="!?*.java"/>
13+
<entry name="!?*.groovy"/>
14+
</wildcardResourcePatterns>
15+
<annotationProcessing enabled="false" useClasspath="true"/>
16+
<bytecodeTargetLevel target="1.8"/>
17+
</component>
18+
<component name="CopyrightManager" default="">
19+
<module2copyright/>
20+
</component>
21+
<component name="DependencyValidationManager">
22+
<option name="SKIP_IMPORT_STATEMENTS" value="false"/>
23+
</component>
24+
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false"/>
25+
<component name="GradleUISettings">
26+
<setting name="root"/>
27+
</component>
28+
<component name="GradleUISettings2">
29+
<setting name="root"/>
30+
</component>
31+
<component name="IdProvider" IDEtalkID="11DA1DB66DD62DDA1ED602B7079FE97C"/>
32+
<component name="JavadocGenerationManager">
33+
<option name="OUTPUT_DIRECTORY"/>
34+
<option name="OPTION_SCOPE" value="protected"/>
35+
<option name="OPTION_HIERARCHY" value="true"/>
36+
<option name="OPTION_NAVIGATOR" value="true"/>
37+
<option name="OPTION_INDEX" value="true"/>
38+
<option name="OPTION_SEPARATE_INDEX" value="true"/>
39+
<option name="OPTION_DOCUMENT_TAG_USE" value="false"/>
40+
<option name="OPTION_DOCUMENT_TAG_AUTHOR" value="false"/>
41+
<option name="OPTION_DOCUMENT_TAG_VERSION" value="false"/>
42+
<option name="OPTION_DOCUMENT_TAG_DEPRECATED" value="true"/>
43+
<option name="OPTION_DEPRECATED_LIST" value="true"/>
44+
<option name="OTHER_OPTIONS" value=""/>
45+
<option name="HEAP_SIZE"/>
46+
<option name="LOCALE"/>
47+
<option name="OPEN_IN_BROWSER" value="true"/>
48+
</component>
49+
<component name="ProjectModuleManager">
50+
<modules>
51+
<module filepath="$PROJECT_DIR$/graph-dsl.iml" fileurl="file://$PROJECT_DIR$/graph-dsl.iml"/>
52+
</modules>
53+
</component>
54+
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" assert-keyword="true" jdk-15="true" project-jdk-type="JavaSDK" assert-jdk-15="true" project-jdk-name="1.8">
55+
<output url="file://$PROJECT_DIR$/out"/>
56+
</component>
57+
<component name="SvnBranchConfigurationManager">
58+
<option name="mySupportsUserInfoFilter" value="true"/>
59+
</component>
60+
<component name="VcsDirectoryMappings">
61+
<mapping directory="" vcs=""/>
62+
</component>
63+
<component name="masterDetails">
64+
<states>
65+
<state key="ArtifactsStructureConfigurable.UI">
66+
<UIState>
67+
<splitter-proportions>
68+
<SplitterProportionsDataImpl/>
69+
</splitter-proportions>
70+
<settings/>
71+
</UIState>
72+
</state>
73+
<state key="Copyright.UI">
74+
<UIState>
75+
<splitter-proportions>
76+
<SplitterProportionsDataImpl/>
77+
</splitter-proportions>
78+
</UIState>
79+
</state>
80+
<state key="ProjectJDKs.UI">
81+
<UIState>
82+
<splitter-proportions>
83+
<SplitterProportionsDataImpl>
84+
<option name="proportions">
85+
<list>
86+
<option value="0.2"/>
87+
</list>
88+
</option>
89+
</SplitterProportionsDataImpl>
90+
</splitter-proportions>
91+
<last-edited>1.6</last-edited>
92+
</UIState>
93+
</state>
94+
<state key="ScopeChooserConfigurable.UI">
95+
<UIState>
96+
<splitter-proportions>
97+
<SplitterProportionsDataImpl/>
98+
</splitter-proportions>
99+
<settings/>
100+
</UIState>
101+
</state>
102+
</states>
103+
</component>
104+
</project>

0 commit comments

Comments
 (0)