GraphGists

Neo4j for Neo4j Dependency Graph using Maven dependency:list converted to Cypher

Introduction

Neo4j github is missing an overview document due to difficulty in maintaining an up to date version manually.

This GIST is a first version of a way of using Neo4j to understand Neo4j!

Maven → Neo4j

Maven is the build tool used for Neo4j and comes with plugins for listing dependencies. Unfortunately the graphml output does not play nicely with the graphml APOC import tool due to naming conventions. This could be fixed by updating the APOC code to support Maven graphml formats but this GIST shows a way of converting tgf output into Cypher to get it working as-is.

On Windows if you have built Neo4j successfully you can create a pom.tgf file for each pom.xml with the following command.

mvn dependency:tree "-DoutputFile=pom.tgf" "-DoutputType=tgf"

The tgf format is very simple and easy to convert to Cypher. To do this I split the tgf file in to two parts. The nodes.tgf and the edges.tgf, nodes are above the # marker and edges are below the # marker. I then used awk (via Cygwin) to generate the Cypher to load the dependencies.

For this example I use the pom.tgf in neo4j\packaging\standalone\standalone-community

cat nodes.tgf | awk -F "[ :]" '{print "CREATE (n:Package {name:'"'"'"$3"'"'"', mvnid:'"'"'"$1"'"'"', org:'"'"'"$2"'"'"', build:'"'"'"$4"'"'"', version:'                   "'"'"$5"'"'"'});" }' > nodes.cypher

and

 cat edges.tgf | awk '{print "MATCH (a:Package),(b:Package) WHERE a.mvnid = '"'"'"$1"'"'"' AND b.mvnid = '"'"'"$2"'"'"' CREATE (a)-[r:"$3"]->(b);"}' > ed                   ges.cypher

Then cypher-shell to run nodes.cypher and then edges.cypher.

Setup

MATCH (n1)-[r]->(n2) RETURN r, n1, n2 LIMIT 250;