Skip to content

Commit

Permalink
Merge pull request #171 from jenetics/releases/r3.1.0
Browse files Browse the repository at this point in the history
v3.1.0.
  • Loading branch information
jenetics authored Nov 6, 2023
2 parents afff91f + 2885601 commit e6357d2
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, macos-latest ]
java-version: [ 17, 18 ]
java-version: [ 17, 21 ]
steps:
- uses: actions/checkout@v2

Expand Down
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

**JPX** is a Java library for creating, reading and writing [GPS](https://en.wikipedia.org/wiki/Global_Positioning_System) data in [GPX](https://en.wikipedia.org/wiki/GPS_Exchange_Format) format. It is a *full* implementation of version [1.1](http://www.topografix.com/GPX/1/1/) and version [1.0](http://www.topografix.com/gpx_manual.asp) of the GPX format. The data classes are completely immutable and allows a functional programming style. They are working also nicely with the Java [Stream](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/stream/Stream.html) API. It is also possible to convert the location information into strings which are compatible to the [ISO 6709](http://en.wikipedia.org/wiki/ISO_6709) standard.

Beside the basic functionality of reading and writing GPX files, the library also allows to manipulate the read GPX object in a functional way.
Besides the basic functionality of reading and writing GPX files, the library also allows manipulating the read GPX object in a functional way.


## Dependencies

No external dependencies are needed by the _JPX_ library. It only needs **Java 17** to compile and run.
No external dependencies are needed by the _JPX_ library. It only needs **Java 17** to compile and run. It also runs and compiles with **Java 21**.


## Building JPX

For building the JPX library you have to check out the master branch from Github.
For building the JPX library you have to check out the `master` branch from GitHub.

$ git clone https://github.com/jenetics/jpx.git

Expand Down Expand Up @@ -314,7 +314,7 @@ org.acme.NonValidatingDocumentBuilder

The library is licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html).

Copyright 2016-2022 Franz Wilhelmstötter
Copyright 2016-2023 Franz Wilhelmstötter

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -330,6 +330,22 @@ The library is licensed under the [Apache License, Version 2.0](http://www.apach

## Release notes

### [3.1.0](https://github.com/jenetics/jpx/releases/tag/v3.1.0)

#### Improvements

* [#170](https://github.com/jenetics/jpx/issues/170): GPX files with invalid version number are now readable in _LENIENT_ mode.
```java
final GPX gpx;
try (InputStream in = new FileInputStream(resource)) {
gpx = GPX.Reader.of(Mode.LENIENT).read(in);
}
```

#### Bugs

* [#167](https://github.com/jenetics/jpx/issues/167): Fixing a test case for Windows.

### [3.0.1](https://github.com/jenetics/jpx/releases/tag/v3.0.1)

#### Bugs
Expand Down
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
*/
plugins {
base
id("me.champeau.jmh") version "0.6.6" apply false
id("me.champeau.jmh") version "0.7.2" apply false
}

rootProject.version = JPX.VERSION

tasks.named<Wrapper>("wrapper") {
version = "7.4"
version = "8.4"
distributionType = Wrapper.DistributionType.ALL
}

Expand All @@ -51,7 +51,7 @@ allprojects {
}

configurations.all {
resolutionStrategy.failOnVersionConflict()
resolutionStrategy.preferProjectModules()
}
}

Expand Down Expand Up @@ -129,7 +129,7 @@ fun setupTestReporting(project: Project) {
project.apply(plugin = "jacoco")

project.configure<JacocoPluginExtension> {
toolVersion = "0.8.7"
toolVersion = "0.8.9"
}

project.tasks {
Expand Down
6 changes: 6 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

/*
* Java GPX Library (@__identifier__@).
* Copyright (c) @__year__@ Franz Wilhelmstötter
Expand Down Expand Up @@ -33,6 +35,10 @@ repositories {
gradlePluginPortal()
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "17"
}

configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Env.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object Env {
* Information about the library and author.
*/
object JPX {
const val VERSION = "3.0.1"
const val VERSION = "3.1.0"
const val ID = "jpx"
const val NAME = "jpx"
const val GROUP = "io.jenetics"
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
41 changes: 28 additions & 13 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,11 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,18 +198,28 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
15 changes: 9 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
2 changes: 1 addition & 1 deletion jpx/src/main/java/io/jenetics/jpx/GPX.java
Original file line number Diff line number Diff line change
Expand Up @@ -1966,7 +1966,7 @@ private static String keywords(final GPX gpx) {
private static XMLReaders
readers(final Function<? super String, Length> lengthParser) {
return new XMLReaders()
.v00(XMLReader.attr("version").map(Version::of))
.v00(XMLReader.attr("version").map(Version::of, Version.V11))
.v00(XMLReader.attr("creator"))
.v11(Metadata.READER)
.v10(XMLReader.elem("name"))
Expand Down
17 changes: 16 additions & 1 deletion jpx/src/main/java/io/jenetics/jpx/XMLReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ public abstract T read(final XMLStreamReaderAdapter xml, final boolean lenient)
* {@code null}
*/
public <B> XMLReader<B> map(final Function<? super T, ? extends B> mapper) {
return map(mapper, null);
}

/**
* Create a new reader for the new mapped type {@code B}.
*
* @param mapper the mapper function
* @param devault the default value if the mapping function fails and the
* reader is in {@link io.jenetics.jpx.GPX.Reader.Mode#LENIENT} mode
* @param <B> the target type of the new reader
* @return a new reader
* @throws NullPointerException if the given {@code mapper} function is
* {@code null}
*/
public <B> XMLReader<B> map(final Function<? super T, ? extends B> mapper, B devault) {
requireNonNull(mapper);

return new XMLReader<B>(_name, _type) {
Expand All @@ -147,7 +162,7 @@ public B read(final XMLStreamReaderAdapter xml, final boolean lenient)
e
);
} else {
return null;
return devault;
}
}
}
Expand Down
29 changes: 23 additions & 6 deletions jpx/src/test/java/io/jenetics/jpx/GPXTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void validEmptyElements(final String resource, final GPX expected)
{
try (InputStream in = getClass().getResourceAsStream(resource)) {
final GPX gpx = GPX.Reader.DEFAULT.read(in);
Assert.assertEquals(gpx, expected);
assertThat(gpx).isEqualTo(expected);
}
}

Expand Down Expand Up @@ -256,7 +256,7 @@ public void ignoreExtensions() throws IOException {

final String[] names = gpx.wayPoints()
.map(WayPoint::getName)
.map(Optional::get)
.map(Optional::orElseThrow)
.toArray(String[]::new);

Assert.assertEquals(names, new String[]{"Wien", "Eferding", "Freistadt", "Gmunden"});
Expand Down Expand Up @@ -483,9 +483,9 @@ public void readWriteRandomNonIndentedGPX() throws IOException {
final GPX read = GPX.Reader.DEFAULT.read(bin);


if (!read.equals(gpx)) {
System.out.println(bout);
}
//if (!read.equals(gpx)) {
// System.out.println(bout);
//}
Assert.assertEquals(read, gpx);
}

Expand Down Expand Up @@ -929,7 +929,7 @@ public void issue162_NumberFormattingParsing() {
.build();

final var string = GPX.Writer.DEFAULT.toString(gpx);
assertThat(string).isEqualTo("""
assertThat(string).isEqualToIgnoringNewLines("""
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.1" creator="JPX - https://github.com/jenetics/jpx" \
xmlns="http://www.topografix.com/GPX/1/1">
Expand All @@ -943,4 +943,21 @@ public void issue162_NumberFormattingParsing() {
assertThat(gpx2).isEqualTo(gpx);
}

@Test
public void issue170_InvalidGPXVersion() throws IOException {
final var resource = "/io/jenetics/jpx/ISSUE-170.gpx";
final GPX gpx;
try (InputStream in = getClass().getResourceAsStream(resource)) {
gpx = GPX.Reader.of(Mode.LENIENT).read(in);
}

assertThat(gpx.getVersion()).isEqualTo("1.1");
assertThat(gpx.getCreator()).isEqualTo("Zepp App");
assertThat(gpx.getTracks()).hasSize(1);
assertThat(gpx.getTracks().get(0).getName().orElseThrow())
.isEqualTo("20230507 mile iles");
assertThat(gpx.getTracks().get(0).getSegments()).hasSize(1);
assertThat(gpx.getTracks().get(0).getSegments().get(0)).hasSize(2);
}

}
Loading

0 comments on commit e6357d2

Please sign in to comment.