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

Update PMD to 7.0.0 #689

Merged
merged 14 commits into from Apr 17, 2024
Merged
4 changes: 2 additions & 2 deletions .github/workflows/gradle-publish.yml
Expand Up @@ -20,10 +20,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Expand Up @@ -16,10 +16,10 @@ jobs:
environment: BRouter
steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
- name: Set up JDK 17
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One remark only, the BRouter server still uses JDK 11.
Therefore, the output lib cannot be used directly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to compile for older Java releases we should target a specific java version. It seems reasonable to target Java 11 but use JDK 17 to build.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For maximum compatibility with old Android versions (that do not contain newer Java API),
in the open source libraries I maintain, we may use Java 17 to compile,
but have sourceCompatibility and targetCompatibility with JavaVersion.VERSION_1_8.

For example:
https://github.com/mapsforge/mapsforge/blob/master/build.gradle#L32-L33
https://github.com/mapsforge/vtm/blob/master/build.gradle#L34-L35

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine, I could try sourceCompatibility and targetCompatibility next week with the test server.

uses: actions/setup-java@v4
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Create local.properties
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,6 +1,7 @@
*.iml
.gradle
.idea/
build
/local.properties
/.idea/caches
/.idea/gradle.xml
Expand All @@ -10,7 +11,6 @@
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
Expand Down
1 change: 0 additions & 1 deletion brouter-codec/.gitignore

This file was deleted.

3 changes: 1 addition & 2 deletions brouter-codec/build.gradle
@@ -1,8 +1,7 @@
plugins {
id 'java-library'
id 'brouter.library-conventions'
}

dependencies {
implementation project(':brouter-util')
testImplementation 'junit:junit:4.13.1'
}
3 changes: 0 additions & 3 deletions brouter-codec/src/main/AndroidManifest.xml

This file was deleted.

5 changes: 3 additions & 2 deletions brouter-codec/src/main/java/btools/codec/MicroCache2.java
@@ -1,6 +1,7 @@
package btools.codec;

import java.util.HashMap;
import java.util.Map;

import btools.util.ByteDataReader;
import btools.util.IByteArrayUnifier;
Expand Down Expand Up @@ -287,7 +288,7 @@ public boolean isInternal(int ilon, int ilat) {

@Override
public int encodeMicroCache(byte[] buffer) {
HashMap<Long, Integer> idMap = new HashMap<>();
Map<Long, Integer> idMap = new HashMap<>();
for (int n = 0; n < size; n++) { // loop over nodes
idMap.put(expandId(faid[n]), n);
}
Expand Down Expand Up @@ -418,7 +419,7 @@ public int encodeMicroCache(byte[] buffer) {
nlinks++;

if (isInternal) {
int nodeIdx = idx.intValue();
int nodeIdx = idx;
if (dodebug) System.out.println("*** target nodeIdx=" + nodeIdx);
if (nodeIdx == n) throw new RuntimeException("ups: self ref?");
nodeIdxDiff.encodeSignedValue(nodeIdx - n);
Expand Down
3 changes: 2 additions & 1 deletion brouter-codec/src/main/java/btools/codec/TagValueCoder.java
Expand Up @@ -4,6 +4,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;

import btools.util.BitCoderContext;

Expand Down Expand Up @@ -58,7 +59,7 @@ public void encodeDictionary(BitCoderContext bc) {
TagValueSet dummy = new TagValueSet(nextTagValueSetId++);
identityMap.put(dummy, dummy);
}
PriorityQueue<TagValueSet> queue = new PriorityQueue<>(2 * identityMap.size(), new TagValueSet.FrequencyComparator());
Queue<TagValueSet> queue = new PriorityQueue<>(2 * identityMap.size(), new TagValueSet.FrequencyComparator());
queue.addAll(identityMap.values());
while (queue.size() > 1) {
TagValueSet node = new TagValueSet(nextTagValueSetId++);
Expand Down
1 change: 0 additions & 1 deletion brouter-core/.gitignore

This file was deleted.

3 changes: 1 addition & 2 deletions brouter-core/build.gradle
@@ -1,13 +1,12 @@
plugins {
id 'java-library'
id 'brouter.library-conventions'
}

dependencies {
implementation project(':brouter-mapaccess')
implementation project(':brouter-util')
implementation project(':brouter-expressions')
implementation project(':brouter-codec')
testImplementation 'junit:junit:4.13.2'
}

// MapcreatorTest generates segments which are used in tests
Expand Down
3 changes: 0 additions & 3 deletions brouter-core/src/main/AndroidManifest.xml

This file was deleted.

4 changes: 2 additions & 2 deletions brouter-core/src/main/java/btools/router/OsmNogoPolygon.java
Expand Up @@ -168,7 +168,7 @@ public boolean isOnPolyline(long px, long py) {
Point p1 = points.get(0);
for (int i = 1; i <= i_last; i++) {
final Point p2 = points.get(i);
if (OsmNogoPolygon.isOnLine(px, py, p1.x, p1.y, p2.x, p2.y)) {
if (isOnLine(px, py, p1.x, p1.y, p2.x, p2.y)) {
return true;
}
p1 = p2;
Expand Down Expand Up @@ -234,7 +234,7 @@ public boolean isWithin(final long px, final long py) {
final long p1x = p1.x;
final long p1y = p1.y;

if (OsmNogoPolygon.isOnLine(px, py, p0x, p0y, p1x, p1y)) {
if (isOnLine(px, py, p0x, p0y, p1x, p1y)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion brouter-core/src/main/java/btools/router/OsmPath.java
Expand Up @@ -296,7 +296,7 @@ protected void addAddionalPenalty(OsmTrack refTrack, boolean detailMode, OsmPath
// apply a start-direction if appropriate (by faking the origin position)
if (isStartpoint) {
if (rc.startDirectionValid) {
double dir = rc.startDirection.intValue() * CheapRuler.DEG_TO_RAD;
double dir = rc.startDirection * CheapRuler.DEG_TO_RAD;
double[] lonlat2m = CheapRuler.getLonLatToMeterScales((lon0 + lat1) >> 1);
lon0 = lon1 - (int) (1000. * Math.sin(dir) / lonlat2m[0]);
lat0 = lat1 - (int) (1000. * Math.cos(dir) / lonlat2m[1]);
Expand Down
4 changes: 2 additions & 2 deletions brouter-core/src/main/java/btools/router/OsmTrack.java
Expand Up @@ -166,7 +166,7 @@ public void buildMap() {
}

public List<String> aggregateMessages() {
ArrayList<String> res = new ArrayList<>();
List<String> res = new ArrayList<>();
MessageData current = null;
for (OsmPathElement n : nodes) {
if (n.message != null && n.message.wayKeyValues != null) {
Expand All @@ -188,7 +188,7 @@ public List<String> aggregateMessages() {
}

public List<String> aggregateSpeedProfile() {
ArrayList<String> res = new ArrayList<>();
List<String> res = new ArrayList<>();
int vmax = -1;
int vmaxe = -1;
int vmin = -1;
Expand Down
10 changes: 5 additions & 5 deletions brouter-core/src/main/java/btools/router/RoutingEngine.java
Expand Up @@ -187,7 +187,7 @@ public void doRouting(long maxRunningTime) {
OsmTrack[] refTracks = new OsmTrack[nsections]; // used ways for alternatives
OsmTrack[] lastTracks = new OsmTrack[nsections];
OsmTrack track = null;
ArrayList<String> messageList = new ArrayList<>();
List<String> messageList = new ArrayList<>();
for (int i = 0; ; i++) {
track = findTrack(refTracks, lastTracks);
track.message = "track-length = " + track.distance + " filtered ascend = " + track.ascend
Expand Down Expand Up @@ -690,9 +690,9 @@ private boolean snappPathConnection(OsmTrack tt, OsmTrack t, MatchedWaypoint sta
return false;
}
}
ArrayList<OsmPathElement> removeBackList = new ArrayList<>();
ArrayList<OsmPathElement> removeForeList = new ArrayList<>();
ArrayList<Integer> removeVoiceHintList = new ArrayList<>();
List<OsmPathElement> removeBackList = new ArrayList<>();
List<OsmPathElement> removeForeList = new ArrayList<>();
List<Integer> removeVoiceHintList = new ArrayList<>();
OsmPathElement last = null;
OsmPathElement lastJunction = null;
CompactLongMap<OsmTrack.OsmPathElementHolder> lastJunctions = new CompactLongMap<>();
Expand Down Expand Up @@ -1246,7 +1246,7 @@ private OsmTrack _findTrack(String operationName, MatchedWaypoint startWp, Match
addToOpenset(startPath1);
addToOpenset(startPath2);
}
ArrayList<OsmPath> openBorderList = new ArrayList<>(4096);
List<OsmPath> openBorderList = new ArrayList<>(4096);
boolean memoryPanicMode = false;
boolean needNonPanicProcessing = false;

Expand Down
Expand Up @@ -101,7 +101,7 @@ private OsmNodeNamed readPosition(double lon, double lat, String name) {
* @throws UnsupportedEncodingException
*/
public Map<String, String> getUrlParams(String url) throws UnsupportedEncodingException {
HashMap<String, String> params = new HashMap<>();
Map<String, String> params = new HashMap<>();
String decoded = URLDecoder.decode(url, "UTF-8");
StringTokenizer tk = new StringTokenizer(decoded, "?&");
while (tk.hasMoreTokens()) {
Expand Down
1 change: 0 additions & 1 deletion brouter-expressions/.gitignore

This file was deleted.

3 changes: 1 addition & 2 deletions brouter-expressions/build.gradle
@@ -1,9 +1,8 @@
plugins {
id 'java-library'
id 'brouter.library-conventions'
}

dependencies {
implementation project(':brouter-util')
implementation project(':brouter-codec')
testImplementation 'junit:junit:4.13.1'
}
3 changes: 0 additions & 3 deletions brouter-expressions/src/main/AndroidManifest.xml

This file was deleted.

Expand Up @@ -242,15 +242,15 @@ private static BExpression parseRaw(BExpressionContext ctx, int level, String op
}
// parse operands
if (nops > 0) {
exp.op1 = BExpression.parse(ctx, level + 1, exp.typ == ASSIGN_EXP ? "=" : null);
exp.op1 = parse(ctx, level + 1, exp.typ == ASSIGN_EXP ? "=" : null);
}
if (nops > 1) {
if (ifThenElse) checkExpectedToken(ctx, "then");
exp.op2 = BExpression.parse(ctx, level + 1, null);
exp.op2 = parse(ctx, level + 1, null);
}
if (nops > 2) {
if (ifThenElse) checkExpectedToken(ctx, "else");
exp.op3 = BExpression.parse(ctx, level + 1, null);
exp.op3 = parse(ctx, level + 1, null);
}
if (brackets) {
checkExpectedToken(ctx, ")");
Expand Down