From ec54f7984396861fce3ebdcb443dd129a2d1a0ce Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Fri, 13 Feb 2015 10:58:10 +0100 Subject: [PATCH 1/3] Switched to latest stable Neo4j (2.1.7) - also required small changes in transaction handling --- pom.xml | 9 ++--- .../com/github/rickardoberg/neomvn/Main.java | 38 ++++++++----------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/pom.xml b/pom.xml index b2acc03..6dd0def 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,6 @@ - + 4.0.0 neomvn @@ -16,12 +15,12 @@ org.neo4j neo4j-kernel - 1.9.M05 + 2.1.7 org.neo4j neo4j-lucene-index - 1.9.M05 + 2.1.7 org.slf4j diff --git a/src/main/java/com/github/rickardoberg/neomvn/Main.java b/src/main/java/com/github/rickardoberg/neomvn/Main.java index 48199d4..d9449bd 100644 --- a/src/main/java/com/github/rickardoberg/neomvn/Main.java +++ b/src/main/java/com/github/rickardoberg/neomvn/Main.java @@ -62,25 +62,25 @@ public Main(File repository) throws ParserConfigurationException, IOException, S FileUtils.deleteRecursively( dbPath ); graphDatabaseService = new GraphDatabaseFactory().newEmbeddedDatabase( dbPath.getAbsolutePath() ); - groups = graphDatabaseService.index().forNodes( "groups" ); - artifacts = graphDatabaseService.index().forNodes( "artifacts" ); - versions = graphDatabaseService.index().forNodes( "versions" ); - - has_artifact = DynamicRelationshipType.withName( "HAS_ARTIFACT" ); - has_version = DynamicRelationshipType.withName( "HAS_VERSION" ); - has_dependency = DynamicRelationshipType.withName( "HAS_DEPENDENCY" ); - - logger = LoggerFactory.getLogger( getClass() ); - this.repository = repository; - try { tx = graphDatabaseService.beginTx(); + groups = graphDatabaseService.index().forNodes( "groups" ); + artifacts = graphDatabaseService.index().forNodes( "artifacts" ); + versions = graphDatabaseService.index().forNodes( "versions" ); + + has_artifact = DynamicRelationshipType.withName( "HAS_ARTIFACT" ); + has_version = DynamicRelationshipType.withName( "HAS_VERSION" ); + has_dependency = DynamicRelationshipType.withName( "HAS_DEPENDENCY" ); + + logger = LoggerFactory.getLogger( getClass() ); + this.repository = repository; + // Add versions logger.info( "Versions" ); visitPoms( repository, new Visitor() - { + { public void accept( Model model ) { String groupId = getGroupId( model ); @@ -91,20 +91,19 @@ public void accept( Model model ) name = artifactId; artifact( groupId, artifactId, version, name); } - }); + }); // Add dependencies logger.info( "Dependencies" ); visitPoms( repository, new Visitor() - { + { public void accept( Model item ) { dependencies( item ); } - } ); + } ); tx.success(); - tx.finish(); } finally { @@ -151,7 +150,6 @@ public boolean accept( File dir, String name ) if (count%1000 == 0) { tx.success(); - tx.finish(); tx=graphDatabaseService.beginTx(); } } @@ -266,11 +264,7 @@ public void accept( Node dependencyVersionNode ) } } ); - tx.success(); - } finally - { - tx.finish(); - } + tx.success(); } private String getVersion( final Dependency dependency ) From adc490793099d18025120ddfd9ed95f518816266 Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Fri, 13 Feb 2015 11:13:31 +0100 Subject: [PATCH 2/3] Build a "complete" JAR (with dependencies) --- README.md | 7 +++++-- pom.xml | 13 ++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4b9a401..304e87f 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,13 @@ WARNING: if you open webadmin and use the graph visualization, whatever you do d Usage ----- -* Clone and build using Maven +* Clone and build using Maven, e.g., +``` +mvn clean package +``` * Run the Main class from command line with location of Maven repo as argument. Example: ``` -java -jar neomvn-1.0-SNAPSHOT.jar /Users/rickard/.m2/repository +java -jar target/neomvn-1.0-SNAPSHOT-jar-with-dependencies.jar /Users/rickard/.m2/repository ``` * This will import and index your local Maven repository into a Neo4j graph database created under "neomvn" directory, from where the tool was invoked. diff --git a/pom.xml b/pom.xml index 6dd0def..191023a 100644 --- a/pom.xml +++ b/pom.xml @@ -48,13 +48,24 @@ org.apache.maven.plugins - maven-jar-plugin + maven-assembly-plugin + + + package + + single + + + com.github.rickardoberg.neomvn.Main + + jar-with-dependencies + From 12ad94cb50e309f567c5d7e9a35153942613a962 Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Fri, 13 Feb 2015 11:20:22 +0100 Subject: [PATCH 3/3] Bugfix: Dropped remaining try block start --- .../com/github/rickardoberg/neomvn/Main.java | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/github/rickardoberg/neomvn/Main.java b/src/main/java/com/github/rickardoberg/neomvn/Main.java index d9449bd..5472769 100644 --- a/src/main/java/com/github/rickardoberg/neomvn/Main.java +++ b/src/main/java/com/github/rickardoberg/neomvn/Main.java @@ -239,30 +239,28 @@ private String getGroupId( Model model ) private void dependencies( final Model model ) { Transaction tx = graphDatabaseService.beginTx(); - try - { - visitVersion( getGroupId( model ), model.getArtifactId(), getVersion( model ), new Visitor() + visitVersion( getGroupId( model ), model.getArtifactId(), getVersion( model ), new Visitor() + { + public void accept( final Node versionNode ) { - public void accept( final Node versionNode ) + // Found artifact, now add dependencies + for ( final Dependency dependency : model.getDependencies() ) { - // Found artifact, now add dependencies - for ( final Dependency dependency : model.getDependencies() ) - { - visitVersion( dependency.getGroupId(), dependency.getArtifactId(), getVersion( dependency ), - new Visitor() - { - public void accept( Node dependencyVersionNode ) - { - Relationship dependencyRel = versionNode.createRelationshipTo( - dependencyVersionNode, has_dependency ); - - dependencyRel.setProperty( "scope", withDefault(dependency.getScope(), "compile" )); - dependencyRel.setProperty( "optional", withDefault(dependency.isOptional(), Boolean.FALSE )); - } - } ); - } + visitVersion( dependency.getGroupId(), dependency.getArtifactId(), getVersion( dependency ), + new Visitor() + { + public void accept( Node dependencyVersionNode ) + { + Relationship dependencyRel = versionNode.createRelationshipTo( + dependencyVersionNode, has_dependency ); + + dependencyRel.setProperty( "scope", withDefault(dependency.getScope(), "compile" )); + dependencyRel.setProperty( "optional", withDefault(dependency.isOptional(), Boolean.FALSE )); + } + } ); } - } ); + } + } ); tx.success(); }