Skip to content

Commit ccea63e

Browse files
committed
Merge branch 'release/0.23.0'
2 parents b3e3ab8 + fa414fa commit ccea63e

49 files changed

Lines changed: 1321 additions & 596 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ cache:
1616
- "$HOME/.gradle/caches/"
1717
- "$HOME/.gradle/wrapper/"
1818
install: true
19-
script: "./travis.sh"
19+
script:
20+
- "./travis.sh"
21+
- ./gradlew jacocoTestReport
2022
before_install:
2123
- openssl aes-256-cbc -K $encrypted_89c9bd3bab4e_key -iv $encrypted_89c9bd3bab4e_iv
2224
-in signingkey.gpg.enc -out signingkey.gpg -d
25+
after_success:
26+
- bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 76 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
# graph-dsl
22

3-
A groovy dsl for creating and traversing graphs. Graphs can be extended with types which allows developers to create a
4-
graph with the desired behavior and values for their algorithm.
3+
A groovy dsl for creating and traversing graphs. Graphs can be extended
4+
with types and plugins which allows developers to create graphs with
5+
the desired behavior and values for their algorithm.
56

7+
[![GitHub top language](https://img.shields.io/github/languages/top/moaxcp/graph-dsl.svg)]()
8+
[![GitHub last commit](https://img.shields.io/github/last-commit/moaxcp/graph-dsl.svg)]()
69
[![Build Status](https://travis-ci.org/moaxcp/graph-dsl.svg?branch=master)](https://travis-ci.org/moaxcp/graph-dsl)
10+
[![Maven Central](https://img.shields.io/maven-central/v/com.github.moaxcp/graph-dsl.svg)](https://mvnrepository.com/artifact/com.github.moaxcp/graph-dsl)
11+
[![Javadocs](https://www.javadoc.io/badge/com.github.moaxcp/graph-dsl.svg)](https://www.javadoc.io/doc/com.github.moaxcp/graph-dsl)
12+
[![Libraries.io for GitHub](https://img.shields.io/librariesio/github/moaxcp/graph-dsl.svg)](https://libraries.io/github/moaxcp/graph-dsl)
13+
[![license](https://img.shields.io/github/license/moaxcp/graph-dsl.svg)](LICENSE)
714

815
# Usage
916

@@ -52,15 +59,6 @@ There are a few rules the dsl follows as it is being processed.
5259
1. All referenced vertices are created if they don't exist.
5360
2. If an edge or vertex already exists it will be reused by and operation.
5461

55-
Future rules:
56-
57-
These rules will address the api leak with Vertex or Edge. When these objects are returned or in scope some properties
58-
may be changed which will break the graph. These rules will address those issues.
59-
60-
3. Changing name in Vertex renames the vertex in the graph
61-
4. Changing one or two in Edge moves the edge to different vertices. The vertices will be created if they do not exist.
62-
5. delegates in Vertex and Edge are read-only
63-
6462
## directed graphs
6563

6664
The Default behavior of a graph is undirected. These graphs have a set of edges where only one edge
@@ -163,9 +161,10 @@ an undirected graph are considered bi-directional in `classifyEdges`.
163161

164162
Vertex keys are used to refer to a Vertex in the dsl. Keys can be any object which implements equals and hashCode.
165163

166-
## Properties
164+
## Edge and Vertex are Maps
167165

168-
Properties can be added to Edge and Vertex dynamically simply by assigning them.
166+
Since Edge and Vertex are maps, all of the syntax for maps apply to them. In a dsl closure assignments create
167+
and entry in the Edge or Vertex.
169168

170169
```groovy
171170
edge(A, B) {
@@ -177,8 +176,23 @@ vertex step1, {
177176
}
178177
```
179178

179+
If non dsl entries are used in a dsl method they are added to the object.
180+
181+
```groovy
182+
edge(A, B, [weight:10]) //weight is a non dsl entry
183+
184+
vertex(step1, [connectsTo:step1, color:'red']) //color is a non dsl entry
185+
```
186+
180187
# Types
181188

189+
Types can be changed with the type methods.
190+
191+
```groovy
192+
type 'directed-graph'
193+
type graph.type.DirectedGraphType
194+
```
195+
182196
A graph's type determines specific behavior. A type can change a normal graph to an directed-graph. It can add wieght
183197
to the graph. It can change the graph to a DAG. Developers can make their own type and apply it to a graph. Types can:
184198

@@ -224,15 +238,6 @@ edge A, B, [weight:10]
224238
edge (A, B) { weight = 10 }
225239
```
226240

227-
Weight can be a lazy property by assigning a closure.
228-
229-
```groovy
230-
type 'weighted-graph'
231-
232-
edge(A, B) {
233-
weight = { queue.size() }
234-
}
235-
236241
## WeightedDirectedGraphType
237242

238243
```groovy
@@ -242,6 +247,40 @@ type 'weighted-directed-graph'
242247
WeightedDirectedGraphType is a directed graph where edges can have weight. Traversal methods follow edges with the least
243248
weight.
244249

250+
251+
# Plugins
252+
253+
Plugins may be applied with the plugin methods.
254+
255+
```groovy
256+
plugin 'graphviz'
257+
plugin graph.plugin.GraphViz
258+
```
259+
260+
## Graphviz
261+
262+
Graphviz is a graph visualization toolset. The project provides a dsl called dot for visualizing graphs. The graphviz
263+
plugin provides methods to create dot strings, BufferedImages and to view the graph. Edge and Vertex attributes will be used as dot attributes.
264+
265+
```groovy
266+
type 'directed-graph'
267+
plugin 'graphviz'
268+
vertex A {
269+
connectsTo B {
270+
connectsTo C, D
271+
}
272+
connectsTo D {
273+
connectsTo C
274+
connectsTo E
275+
}
276+
connectsFrom D
277+
}
278+
vertex F, [connectsTo:G]
279+
edge G, D
280+
image 'images/graphviz.png'
281+
```
282+
![Image of graph](/images/graphviz.png?raw=true "Grpah")
283+
245284
# Getting Started With Development/Contributing
246285

247286
## install git
@@ -302,8 +341,23 @@ If there are any issues contact me moaxcp@gmail.com.
302341

303342
# Releases
304343

344+
## 0.23.0
345+
346+
Adding graphviz plugin.
347+
348+
Vertices and edges are now maps. Closures in entries are not resolved as was the case when dynamic properties were set.
349+
350+
Example
351+
352+
```groovy
353+
edge.weight = { queue.size() }
354+
assert edge.weight == 10 //in 0.22.0 would call the closure. In this release the closure is returned.
355+
```
356+
305357
## 0.22.0
306358

359+
[#102](https://github.com/moaxcp/graph-dsl/issues/102) Switch from name to key
360+
307361
In this release Vertex.name has been repalced with Vertex.key. The key may be any object that implements equals and
308362
hashCode.
309363

build.gradle

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ versioneye {
3434

3535
jacocoTestReport {
3636
dependsOn test
37+
reports {
38+
xml.enabled = true
39+
}
3740
}
3841

3942
jacocoTestCoverageVerification {
4043
dependsOn test
4144
violationRules {
4245
rule {
4346
limit {
44-
minimum = 0.83
47+
minimum = 0.8
4548
}
4649
limit {
4750
counter = 'BRANCH'
@@ -87,6 +90,12 @@ jacocoTestCoverageVerification {
8790
}
8891
}
8992

93+
test {
94+
systemProperty 'com.athaydes.spockframework.report.hideEmptyBlocks', 'true'
95+
systemProperty 'com.athaydes.spockframework.report.showCodeBlocks', 'true'
96+
systemProperty 'com.athaydes.spockframework.report.projectVersion', version.toString()
97+
}
98+
9099
gradle.taskGraph.whenReady { graph ->
91100
if (graph.hasTask(':jacocoTestReport') || graph.hasTask(':jacocoTestCoverageVerification')) {
92101
compileGroovy.groovyOptions.optimizationOptions.all = false
@@ -102,16 +111,6 @@ codenarc {
102111
ignoreFailures = true
103112
}
104113

105-
repositories {
106-
jcenter()
107-
}
108-
109-
configurations {
110-
codnarc {
111-
extendsFrom compile
112-
}
113-
}
114-
115114
groovydoc {
116115
link 'https://docs.oracle.com/javase/8/docs/api/', 'java', 'javax', 'org'
117116
link "http://docs.groovy-lang.org/docs/groovy-$groovyVersion/html/api/", 'groovy', 'org'
@@ -202,15 +201,31 @@ nexusStaging {
202201
delayBetweenRetriesInMillis = 10000
203202
}
204203

204+
repositories {
205+
jcenter()
206+
}
207+
208+
configurations {
209+
codnarc {
210+
extendsFrom compile
211+
}
212+
}
213+
205214
dependencies {
206215
compile "org.codehaus.groovy:groovy:$groovyVersion"
216+
compile 'org.groovyfx:groovyfx:8.0.0'
217+
207218
testCompile( 'com.athaydes:spock-reports:1.3.2' ) {
208219
transitive = false
209220
}
210221
testCompile 'org.slf4j:slf4j-api:1.7.13'
211222
testCompile 'org.slf4j:slf4j-simple:1.7.13'
223+
212224
testCompile ('org.spockframework:spock-core:1.1-groovy-2.4') {
213225
exclude group: 'org.codehaus.groovy', module:'groovy-all'
214226
}
215227
testCompile "org.codehaus.groovy:groovy-all:$groovyVersion"
228+
testCompile 'cglib:cglib-nodep:3.2.5'
229+
230+
testCompile 'org.hamcrest:hamcrest-all:1.3'
216231
}

images/graphviz.png

15.3 KB
Loading

src/main/groovy/graph/Edge.groovy

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,38 @@
11
package graph
22

3-
import graph.internal.PropertyDelegator
4-
import groovy.transform.PackageScope
5-
import groovy.transform.ToString
63

74
/**
85
* An edge between two vertices. Properties may be added to Edge by setting values. Assigning a property to a
96
* {@link Closure} will make it lazy. When the property is read the value returned is the result of calling the closure.
107
* If a missing method is called on Edge and a property is set with a closure the closure will be called and the
118
* resulting value returned.
129
*/
13-
@ToString(includeNames=true)
14-
class Edge extends PropertyDelegator {
15-
Object one
16-
Object two
10+
class Edge {
11+
@Delegate
12+
Map map = [:]
1713

18-
@PackageScope
19-
void setOne(Object one) {
20-
this.one = one
14+
Object getOne() {
15+
get('one')
2116
}
2217

23-
@PackageScope
24-
void setTwo(Object two) {
25-
this.two = two
18+
Object setOne(Object value) {
19+
put('one', value)
2620
}
2721

28-
/**
29-
* Returns the property with the given name.
30-
* @param name
31-
* @return
32-
*/
33-
Object getAt(String name) {
34-
if (name == 'one') {
35-
return one
36-
}
37-
if (name == 'two') {
38-
return two
39-
}
40-
delegate[name]
22+
Object getTwo() {
23+
get('two')
24+
}
25+
26+
Object setTwo(Object value) {
27+
put('two', value)
28+
}
29+
30+
boolean asBoolean() {
31+
one && two
32+
}
33+
34+
boolean equals(Edge edge) {
35+
(one == edge.one || one == edge.two) && (two == edge.two || two == edge.one)
4136
}
4237

4338
/**
@@ -56,7 +51,7 @@ class Edge extends PropertyDelegator {
5651
return true
5752
}
5853
Edge rhs = (Edge) o
59-
(one == rhs.one || one == rhs.two) && (two == rhs.two || two == rhs.one)
54+
equals(rhs)
6055
}
6156

6257
/**

src/main/groovy/graph/EdgeSpec.groovy

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ abstract class EdgeSpec {
77
Graph graph
88

99
protected EdgeSpec(Graph graph) {
10-
if (this.graph) {
11-
throw new IllegalArgumentException('Graph already set.')
12-
}
1310
this.graph = graph
1411
}
1512

0 commit comments

Comments
 (0)