Skip to content

Commit

Permalink
Merge pull request #841 from lonvia/update-deps
Browse files Browse the repository at this point in the history
Update dependencies and overhaul command line parsing
  • Loading branch information
lonvia authored Oct 29, 2024
2 parents f55d1df + 50c5fd5 commit 07ed5bc
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 118 deletions.
12 changes: 6 additions & 6 deletions app/opensearch/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ sourceSets {
}

dependencies {
implementation 'org.opensearch.client:opensearch-java:2.10.1'
implementation 'org.apache.httpcomponents.client5:httpclient5:5.3.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.0'
implementation 'org.opensearch.client:opensearch-java:2.16.0'
implementation 'org.apache.httpcomponents.client5:httpclient5:5.4'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.18.0'

implementation 'org.codelibs.opensearch:opensearch-runner:2.13.0.0'
implementation 'org.codelibs.opensearch:opensearch-runner:2.17.1.0'

// updates for indirect dependencies
implementation 'io.netty:netty-codec:4.1.109.Final'
implementation 'io.netty:netty-codec-http:4.1.109.Final'
implementation 'io.netty:netty-codec:4.1.114.Final'
implementation 'io.netty:netty-codec-http:4.1.114.Final'
}

tasks.named('jar') {
Expand Down
36 changes: 18 additions & 18 deletions buildSrc/shared.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,34 @@ sourceSets {
}

dependencies {
implementation 'org.apache.logging.log4j:log4j-core:2.23.1'
implementation 'org.apache.logging.log4j:log4j-api:2.23.1'
implementation 'org.postgresql:postgresql:42.7.2'
implementation 'org.slf4j:slf4j-api:2.0.13'
implementation 'org.apache.logging.log4j:log4j-slf4j2-impl:2.23.1'
implementation 'com.beust:jcommander:1.82'
implementation 'org.apache.commons:commons-lang3:3.14.0'
implementation 'org.springframework:spring-jdbc:5.3.32'
implementation 'org.apache.logging.log4j:log4j-core:2.24.1'
implementation 'org.apache.logging.log4j:log4j-api:2.24.1'
implementation 'org.postgresql:postgresql:42.7.4'
implementation 'org.slf4j:slf4j-api:2.0.16'
implementation 'org.apache.logging.log4j:log4j-slf4j2-impl:2.24.1'
implementation 'org.jcommander:jcommander:2.0'
implementation 'org.apache.commons:commons-lang3:3.17.0'
implementation 'org.springframework:spring-jdbc:5.3.39'
implementation ('org.apache.commons:commons-dbcp2:2.12.0') {
exclude(module: 'commons-logging')
}
implementation 'org.locationtech.jts:jts-core:1.19.0'
implementation 'org.locationtech.jts:jts-core:1.20.0'
implementation 'com.sparkjava:spark-core:2.9.4'
implementation 'net.postgis:postgis-jdbc:2023.1.0'
implementation 'net.postgis:postgis-jdbc:2024.1.0'
implementation 'org.json:json:20240303'

testImplementation(platform("org.junit:junit-bom:5.10.2"))
testImplementation 'com.h2database:h2:2.2.224'
testImplementation(platform("org.junit:junit-bom:5.11.3"))
testImplementation 'com.h2database:h2:2.3.232'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core:5.11.0'
testImplementation 'org.mockito:mockito-core:5.14.2'

testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

// updates for indirect dependencies
implementation 'org.eclipse.jetty:jetty-server:9.4.54.v20240208'
implementation 'org.eclipse.jetty:jetty-webapp:9.4.54.v20240208'
implementation 'org.eclipse.jetty.websocket:websocket-server:9.4.54.v20240208'
implementation 'org.eclipse.jetty.websocket:websocket-servlet:9.4.54.v20240208'
implementation 'org.eclipse.jetty:jetty-server:9.4.56.v20240826'
implementation 'org.eclipse.jetty:jetty-webapp:9.4.56.v20240826'
implementation 'org.eclipse.jetty.websocket:websocket-server:9.4.56.v20240826'
implementation 'org.eclipse.jetty.websocket:websocket-servlet:9.4.56.v20240826'
}

tasks.named('test') {
Expand All @@ -76,4 +76,4 @@ tasks.named('test') {

test {
systemProperty "sun.net.http.allowRestrictedHeaders", "true"
}
}
5 changes: 0 additions & 5 deletions src/main/java/de/komoot/photon/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ private static CommandLineArgs parseCommandLine(String[] rawArgs) {
final JCommander jCommander = new JCommander(args);
try {
jCommander.parse(rawArgs);

// Cors arguments are mutually exclusive.
if (args.isCorsAnyOrigin() && args.getCorsOrigin().length > 0) {
throw new ParameterException("Use only one cors configuration type");
}
} catch (ParameterException e) {
LOGGER.warn("Could not start photon: {}", e.getMessage());
jCommander.usage();
Expand Down
72 changes: 38 additions & 34 deletions src/main/java/de/komoot/photon/CommandLineArgs.java
Original file line number Diff line number Diff line change
@@ -1,83 +1,87 @@
package de.komoot.photon;

import com.beust.jcommander.Parameter;
import de.komoot.photon.utils.StringArrayConverter;
import com.beust.jcommander.Parameters;
import de.komoot.photon.utils.CorsMutuallyExclusiveValidator;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
* Command Line Arguments parsed by {@link com.beust.jcommander.JCommander} and used to start photon.
*/
@Parameters(parametersValidators = CorsMutuallyExclusiveValidator.class)
public class CommandLineArgs {

@Parameter(names = "-structured", description = "Enable support for structured queries")
@Parameter(names = "-structured", description = "Enable support for structured queries.")
private boolean supportStructuredQueries = false;

@Parameter(names = "-cluster", description = "Name of ElasticSearch cluster to put the server into")
@Parameter(names = "-cluster", description = "Name of ElasticSearch cluster to put the server into.")
private String cluster = "photon";

@Parameter(names = "-transport-addresses", description = "Comma-separated list of addresses of external ElasticSearch nodes the client can connect to (default is an empty string which forces an internal node to start)", converter = StringArrayConverter.class)
private String[] transportAddresses = new String[]{};
@Parameter(names = "-transport-addresses", description = "Comma-separated list of addresses of external ElasticSearch nodes the client can connect to. An empty list (the default) forces an internal node to start.")
private List<String> transportAddresses = new ArrayList<>();

@Parameter(names = "-nominatim-import", description = "Import nominatim database into photon (this will delete previous index)")
@Parameter(names = "-nominatim-import", description = "Import nominatim database into photon (deleting the previous index).")
private boolean nominatimImport = false;

@Parameter(names = "-nominatim-update-init-for", description = "Set up tracking of updates in the Nominatim database for the given user and exit")
@Parameter(names = "-nominatim-update-init-for", description = "Set up tracking of updates in the Nominatim database for the given user and exit.")
private String nominatimUpdateInit = null;

@Parameter(names = "-nominatim-update", description = "Fetch updates from nominatim database into photon and exit (updates the index only without offering an API)")
@Parameter(names = "-nominatim-update", description = "Fetch updates from nominatim database into photon and exit (updates the index only without offering an API).")
private boolean nominatimUpdate = false;

@Parameter(names = "-languages", description = "[import-only] Comma-separated list of languages for which names should be imported (default is 'en,fr,de,it')", converter = StringArrayConverter.class)
private String[] languages = new String[]{};
@Parameter(names = "-languages", description = "Comma-separated list of languages to use. On import sets the name translations to use (default: de,en,fr,it). When running, the languages to be searched may be further restricted.")
private List<String> languages = new ArrayList<>();

@Parameter(names = "-default-language", description = "Language to return results in when no explicit language is chosen by the user")
@Parameter(names = "-default-language", description = "Language to return results in when no explicit language is chosen by the user.")
private String defaultLanguage = "default";

@Parameter(names = "-country-codes", description = "[import-only] Comma-separated list of country codes for countries the importer should import, comma separated (default is empty which imports the full database)", converter = StringArrayConverter.class)
private String[] countryCodes = new String[]{};
@Parameter(names = "-country-codes", description = "[import-only] Comma-separated list of country codes for countries the importer should import, comma separated. An empty list means the full database is imported.")
private List<String> countryCodes = new ArrayList<>();

@Parameter(names = "-extra-tags", description = "Comma-separated list of additional tags to save for each place (default: None)", converter = StringArrayConverter.class)
private String[] extraTags = new String[]{};
@Parameter(names = "-extra-tags", description = "Comma-separated list of additional tags to save for each place.")
private List<String> extraTags = new ArrayList<>();

@Parameter(names = "-synonym-file", description = "File with synonym and classification terms")
@Parameter(names = "-synonym-file", description = "File with synonym and classification terms.")
private String synonymFile = null;

@Parameter(names = "-query-timeout", description = "Time after which to cancel queries to the ES database (in seconds).")
private int queryTimeout = 7;

@Parameter(names = "-json", description = "Read from nominatim database and dump it to the given file in a json-like format (useful for developing)")
@Parameter(names = "-json", description = "Read from nominatim database and dump it to the given file in a json-like format (useful for developing).")
private String jsonDump = null;

@Parameter(names = "-host", description = "Hostname of the PostgreSQL database")
@Parameter(names = "-host", description = "Hostname of the PostgreSQL database.")
private String host = "127.0.0.1";

@Parameter(names = "-port", description = "Port of the PostgreSQL database")
@Parameter(names = "-port", description = "Port of the PostgreSQL database.")
private Integer port = 5432;

@Parameter(names = "-database", description = "Database name of the Nominatim database")
@Parameter(names = "-database", description = "Database name of the Nominatim database.")
private String database = "nominatim";

@Parameter(names = "-user", description = "Username in the PostgreSQL database")
@Parameter(names = "-user", description = "Username in the PostgreSQL database.")
private String user = "nominatim";

@Parameter(names = "-password", description = "Password for the PostgreSQL database")
@Parameter(names = "-password", description = "Password for the PostgreSQL database.")
private String password = null;

@Parameter(names = "-data-dir", description = "Photon data directory")
@Parameter(names = "-data-dir", description = "Photon data directory.")
private String dataDirectory = new File(".").getAbsolutePath();

@Parameter(names = "-listen-port", description = "Port for the Photon server to listen to")
@Parameter(names = "-listen-port", description = "Port for the Photon server to listen to.")
private int listenPort = 2322;

@Parameter(names = "-listen-ip", description = "Address for the Photon server to listen to")
@Parameter(names = "-listen-ip", description = "Address for the Photon server to listen to.")
private String listenIp = "0.0.0.0";

@Parameter(names = "-cors-any", description = "Enable cross-site resource sharing for any origin")
@Parameter(names = "-cors-any", description = "Enable cross-site resource sharing for any origin.")
private boolean corsAnyOrigin = false;

@Parameter(names = "-cors-origin", description = "Enable cross-site resource sharing for the specified origins, comma separated", converter = StringArrayConverter.class)
private String[] corsOrigin = new String[]{};
@Parameter(names = "-cors-origin", description = "Comma-separated list of origins for which to enable cross-site resource sharing.")
private List<String> corsOrigin = new ArrayList<>();

@Parameter(names = "-enable-update-api", description = "Enable the additional endpoint /nominatim-update, which allows to trigger updates from a nominatim database")
private boolean enableUpdateApi = false;
Expand All @@ -92,11 +96,11 @@ public class CommandLineArgs {
private int maxReverseResults = 50;

public String[] getLanguages(boolean useDefaultIfEmpty) {
if (useDefaultIfEmpty && languages.length == 0) {
if (useDefaultIfEmpty && languages.isEmpty()) {
return new String[]{"en", "de", "fr", "it"};
}

return languages;
return languages.toArray(new String[0]);
}

public String[] getLanguages() {
Expand All @@ -108,7 +112,7 @@ public String getCluster() {
}

public String[] getTransportAddresses() {
return this.transportAddresses;
return this.transportAddresses.toArray(new String[0]);
}

public boolean isNominatimImport() {
Expand All @@ -128,11 +132,11 @@ public String getDefaultLanguage() {
}

public String[] getCountryCodes() {
return this.countryCodes;
return this.countryCodes.toArray(new String[0]);
}

public String[] getExtraTags() {
return this.extraTags;
return this.extraTags.toArray(new String[0]);
}

public String getSynonymFile() {
Expand Down Expand Up @@ -184,7 +188,7 @@ public boolean isCorsAnyOrigin() {
}

public String[] getCorsOrigin() {
return this.corsOrigin;
return this.corsOrigin.toArray(new String[0]);
}

public boolean isEnableUpdateApi() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package de.komoot.photon.utils;

import com.beust.jcommander.IParametersValidator;
import com.beust.jcommander.ParameterException;

import java.util.List;
import java.util.Map;

import static java.lang.Boolean.TRUE;

public class CorsMutuallyExclusiveValidator implements IParametersValidator {
@Override
public void validate(Map<String, Object> parameters) throws ParameterException {
if (parameters.get("-cors-any") == TRUE && parameters.get("-cors-origin") != null) {
throw new ParameterException("Use only one cors configuration type.");
}
}
}
22 changes: 0 additions & 22 deletions src/main/java/de/komoot/photon/utils/StringArrayConverter.java

This file was deleted.

33 changes: 0 additions & 33 deletions src/test/java/de/komoot/photon/utils/StringArrayConverterTest.java

This file was deleted.

0 comments on commit 07ed5bc

Please sign in to comment.