Skip to content

Commit

Permalink
Ported to Neo4j 4.1.6 which removed an internal API around arguments …
Browse files Browse the repository at this point in the history
…processing

I back-ported some of the work done to port to Neo4j 4.2 which also had that change.
  • Loading branch information
craigtaverner committed Nov 11, 2021
1 parent b99dcaa commit 407e379
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 11 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ This will run all tests which involves importing some OSM files. If you want to

The build will produce two jars and copy them to the local maven repository:

* `target/osm-0.2.3-neo4j-4.1.3.jar` is aimed to be used as a dependency in maven projects that depend on this library
* `target/osm-0.2.3-neo4j-4.1.3-procedures.jar` including procedures, this jar can be copied directly into a Neo4j installation's `plugins` folder
* `target/osm-0.2.3-neo4j-4.1.6.jar` is aimed to be used as a dependency in maven projects that depend on this library
* `target/osm-0.2.3-neo4j-4.1.6-procedures.jar` including procedures, this jar can be copied directly into a Neo4j installation's `plugins` folder

We plan to make a third jar `target/osm-0.2.3-neo4j-4.1.3-all.jar` including all dependencies to faciliate running the command-line importer.
We plan to make a third jar `target/osm-0.2.3-neo4j-4.1.6-all.jar` including all dependencies to faciliate running the command-line importer.
But until then you need to copy and reference all dependencies as described below.

## Running
Expand All @@ -47,10 +47,10 @@ Get all dependencies together:

mvn dependency:copy-dependencies

To run with the jar at `target/osm-0.2.3-neo4j-4.1.3.jar`:
To run with the jar at `target/osm-0.2.3-neo4j-4.1.6.jar`:

java -Xms1280m -Xmx1280m \
-cp "target/osm-0.2.3-neo4j-4.1.3.jar:target/dependency/*" org.neo4j.gis.osm.OSMImportTool \
-cp "target/osm-0.2.3-neo4j-4.1.6.jar:target/dependency/*" org.neo4j.gis.osm.OSMImportTool \
--skip-duplicate-nodes --delete --into target/neo4j --database map2 samples/map2.osm.bz2

This will import the `samples/map2.osm.bz2` file into the database at `target/neo4j/data/databases/map2`.
Expand Down Expand Up @@ -118,7 +118,7 @@ To help build graphs that can be used for routing, two procedures have been adde
* `spatial.osm.routeIntersection(node,false,false,false)`
* `spatial.osm.routePointOfInterest(node,ways)`

These can be installed into an installation of Neo4j by copying the `osm-0.2.3-neo4j-4.1.3-procedures.jar` file into the `plugins` folder, and restarting the database.
These can be installed into an installation of Neo4j by copying the `osm-0.2.3-neo4j-4.1.6-procedures.jar` file into the `plugins` folder, and restarting the database.

### Creating a routing graph of intersections

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.neo4j.gis</groupId>
<artifactId>osm</artifactId>
<packaging>jar</packaging>
<version>0.2.3-neo4j-4.1.3</version>
<version>0.2.3-neo4j-4.1.6</version>
<name>OpenStreetMap for Neo4j</name>
<description>OpenStreetMap data model and importer tool for Neo4j</description>

Expand All @@ -13,7 +13,7 @@
<javac.target>11</javac.target>
<jmh.version>1.19</jmh.version>
<compress.version>1.16.1</compress.version>
<neo4j.version>4.1.3</neo4j.version>
<neo4j.version>4.1.6</neo4j.version>
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
<maven-source-plugin-version>3.1.0</maven-source-plugin-version>
<maven-assembly-plugin.version>2.5.4</maven-assembly-plugin.version>
Expand Down
48 changes: 45 additions & 3 deletions src/main/java/org/neo4j/gis/osm/OSMImportTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
Expand Down Expand Up @@ -178,7 +179,7 @@ String argument() {

void printUsage(PrintStream out) {
out.println(argument() + spaceInBetweenArgumentAndUsage() + usage);
for (String line : Args.splitLongLine(descriptionWithDefaultValue().replace("`", ""), 80)) {
for (String line : splitLongLine(descriptionWithDefaultValue().replace("`", ""), 80)) {
out.println("\t" + line);
}
}
Expand Down Expand Up @@ -307,7 +308,7 @@ public static void main(String[] incomingArguments, boolean defaultSettingsSuita

Collector badCollector = getBadCollector(badTolerance, skipBadRelationships, skipDuplicateNodes, skipBadEntriesLogging, badOutput);

dbConfig = loadDbConfig(args.interpretOption(Options.ADDITIONAL_CONFIG.key(), Converters.optional(), Converters.toFile(), Validators.REGEX_FILE_EXISTS));
dbConfig = loadDbConfig(args.interpretOption(Options.ADDITIONAL_CONFIG.key(), Converters.optional(), Converters.toFile(), f -> Validators.REGEX_FILE_EXISTS.validate(f.getAbsolutePath())));
boolean allowCacheOnHeap = args.getBoolean(Options.CACHE_ON_HEAP.key(), (Boolean) Options.CACHE_ON_HEAP.defaultValue());
configuration = importConfiguration(processors, defaultSettingsSuitableForTests, maxMemory, homeDir, allowCacheOnHeap, defaultHighIO);
in = defaultSettingsSuitableForTests ? new ByteArrayInputStream(EMPTY_BYTE_ARRAY) : System.in;
Expand Down Expand Up @@ -593,7 +594,7 @@ private static void printIndented(Object value, PrintStream out) {

private static void printUsage(PrintStream out) {
out.println("Neo4j OpenStreetMap Import Tool");
for (String line : Args.splitLongLine("osm-import is used to create a new Neo4j database from data in OSM XML files.", 80)) {
for (String line : splitLongLine("osm-import is used to create a new Neo4j database from data in OSM XML files.", 80)) {
out.println("\t" + line);
}
out.println("Usage:");
Expand Down Expand Up @@ -639,6 +640,47 @@ public String getReference(Anchor anchor) {
}
}

/*
* Copied from org.neo4j.internal.helpers.Args, which had this method up to Neo4j 4.1, but removed in 4.2.
*/
public static String[] splitLongLine( String description, int maxLength )
{
List<String> lines = new ArrayList<>();
while ( !description.isEmpty() )
{
String line = description.substring( 0, Math.min( maxLength, description.length() ) );
int position = line.indexOf( '\n' );
if ( position > -1 )
{
line = description.substring( 0, position );
lines.add( line );
description = description.substring( position );
if ( !description.isEmpty() )
{
description = description.substring( 1 );
}
}
else
{
position = description.length() > maxLength ?
findSpaceBefore( description, maxLength ) : description.length();
line = description.substring( 0, position );
lines.add( line );
description = description.substring( position );
}
}
return lines.toArray( new String[0] );
}

private static int findSpaceBefore( String description, int position )
{
while ( !Character.isWhitespace( description.charAt( position ) ) )
{
position--;
}
return position + 1;
}

private enum Anchor {
ID_SPACES("import-tool-id-spaces"),
RELATIONSHIP("import-tool-header-format-rels");
Expand Down

0 comments on commit 407e379

Please sign in to comment.