Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jar with dependencies #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 16 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>neomvn</groupId>
Expand All @@ -16,12 +15,12 @@
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
<version>1.9.M05</version>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-lucene-index</artifactId>
<version>1.9.M05</version>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down Expand Up @@ -49,13 +48,24 @@
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>com.github.rickardoberg.neomvn.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
Expand Down
78 changes: 35 additions & 43 deletions src/main/java/com/github/rickardoberg/neomvn/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Model>()
{
{
public void accept( Model model )
{
String groupId = getGroupId( model );
Expand All @@ -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<Model>()
{
{
public void accept( Model item )
{
dependencies( item );
}
} );
} );

tx.success();
tx.finish();
}
finally
{
Expand Down Expand Up @@ -151,7 +150,6 @@ public boolean accept( File dir, String name )
if (count%1000 == 0)
{
tx.success();
tx.finish();
tx=graphDatabaseService.beginTx();
}
}
Expand Down Expand Up @@ -241,36 +239,30 @@ 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<Node>()
visitVersion( getGroupId( model ), model.getArtifactId(), getVersion( model ), new Visitor<Node>()
{
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<Node>()
{
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<Node>()
{
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();
} finally
{
tx.finish();
}
tx.success();
}

private String getVersion( final Dependency dependency )
Expand Down