diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2cf7d4ff..040ef691 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,9 +4,11 @@ on: push: branches: - master + - 'release/**' pull_request: branches: - master + - 'release/**' permissions: checks: write @@ -19,13 +21,13 @@ jobs: strategy: fail-fast: false matrix: - os: [ ubuntu-latest ] - java: [ '11', '17' ] + os: [ ubuntu-latest, windows-latest ] + java: [ '8', '11', '17', '20' ] arch: [ 'x64' ] -# include: -# - os: windows-latest -# java: '17' -# arch: x86 + include: + - os: windows-latest + java: '17' + arch: x86 name: Java ${{ matrix.java }}/${{ matrix.arch }}/${{ matrix.os }} runs-on: ${{ matrix.os }} @@ -42,6 +44,7 @@ jobs: cache: maven - name: Build with Maven + shell: bash run: | mvn verify \ -B \ @@ -75,8 +78,8 @@ jobs: filename: ${{ matrix.java }}-${{ matrix.arch }}-${{ matrix.os }} path: target/jacoco-${{ matrix.java }}-${{ matrix.arch }}-${{ matrix.os }}.exec - coverage: - name: JaCoCo Report + report: + name: JUnit Reports/JaCoCo Merge runs-on: ubuntu-latest needs: build steps: @@ -100,7 +103,7 @@ jobs: with: name: classes - - name: Merge and output + - name: Merge JaCoCo and output run: mvn -B jacoco:merge jacoco:report - name: Upload @@ -125,7 +128,7 @@ jobs: analyze: name: Analyze Code runs-on: ubuntu-latest - needs: coverage + needs: report if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.owner.login == 'dnsjava' }} steps: - name: Checkout @@ -139,6 +142,9 @@ jobs: with: cache: maven + # doesn't work with PRs from forks, see + # https://portal.productboard.com/sonarsource/1-sonarcloud/c/50-sonarcloud-analyzes-external-pull-request + # or https://jira.sonarsource.com/browse/MMF-1371 (not public anymore) - name: Run SonarQube env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.adoc b/README.adoc index d4b44e1b..c936e906 100644 --- a/README.adoc +++ b/README.adoc @@ -1,9 +1,9 @@ -= dnsjava += dnsjava-actions-test -image:https://github.com/dnsjava/dnsjava/actions/workflows/build.yml/badge.svg["GitHub CI Build Status",link="https://github.com/dnsjava/dnsjava/actions/workflows/build.yml"] -image:https://codecov.io/gh/dnsjava/dnsjava/branch/master/graph/badge.svg?token=FKmcwl1Oys["codecov",link="https://codecov.io/gh/dnsjava/dnsjava"] -image:https://maven-badges.herokuapp.com/maven-central/dnsjava/dnsjava/badge.svg["Maven Central",link="https://search.maven.org/artifact/dnsjava/dnsjava"] -image:https://javadoc.io/badge/dnsjava/dnsjava.svg["Javadocs",link="https://javadoc.io/doc/dnsjava/dnsjava"] +image:https://github.com/dnsjava/dnsjava-actions-test/actions/workflows/build.yml/badge.svg["GitHub CI Build Status",link="https://github.com/dnsjava/dnsjava-actions-test/actions/workflows/build.yml"] +image:https://codecov.io/gh/dnsjava/dnsjava-actions-test/branch/master/graph/badge.svg?token=FKmcwl1Oys["codecov",link="https://codecov.io/gh/dnsjava/dnsjava-actions-test"] +image:https://maven-badges.herokuapp.com/maven-central/dnsjava/dnsjava-actions-test/badge.svg["Maven Central",link="https://search.maven.org/artifact/dnsjava/dnsjava-actions-test"] +image:https://javadoc.io/badge/dnsjava/dnsjava-actions-test.svg["Javadocs",link="https://javadoc.io/doc/dnsjava/dnsjava-actions-test"] == Overview diff --git a/src/main/java/org/xbill/DNS/TypeBitmap.java b/src/main/java/org/xbill/DNS/TypeBitmap.java index d42e4253..4190b4fc 100644 --- a/src/main/java/org/xbill/DNS/TypeBitmap.java +++ b/src/main/java/org/xbill/DNS/TypeBitmap.java @@ -55,7 +55,7 @@ public TypeBitmap(DNSInput in) throws WireParseException { if ((current & (1 << (7 - j))) == 0) { continue; } - int typecode = mapbase * 256 + +i * 8 + j; + int typecode = mapbase * 256 + i * 8 + j; types.add(typecode); } } @@ -106,8 +106,7 @@ private static void mapToWire(DNSOutput out, TreeSet map, int mapbase) int[] array = new int[arraylength]; out.writeU8(mapbase); out.writeU8(arraylength); - for (Integer integer : map) { - int typecode = integer; + for (int typecode : map) { array[(typecode & 0xFF) / 8] |= 1 << (7 - typecode % 8); } for (int j = 0; j < arraylength; j++) { @@ -116,7 +115,7 @@ private static void mapToWire(DNSOutput out, TreeSet map, int mapbase) } public void toWire(DNSOutput out) { - if (types.size() == 0) { + if (types.isEmpty()) { return; } @@ -127,7 +126,7 @@ public void toWire(DNSOutput out) { int t = type; int base = t >> 8; if (base != mapbase) { - if (map.size() > 0) { + if (!map.isEmpty()) { mapToWire(out, map, mapbase); map.clear(); } diff --git a/src/test/java/org/xbill/DNS/TypeBitmapTest.java b/src/test/java/org/xbill/DNS/TypeBitmapTest.java index ab94b5e2..e3100caa 100644 --- a/src/test/java/org/xbill/DNS/TypeBitmapTest.java +++ b/src/test/java/org/xbill/DNS/TypeBitmapTest.java @@ -34,6 +34,7 @@ // package org.xbill.DNS; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; @@ -47,13 +48,66 @@ void empty() { @Test void typeA() { - TypeBitmap typeBitmap = new TypeBitmap(new int[] {1}); + TypeBitmap typeBitmap = new TypeBitmap(new int[] {Type.A}); assertEquals("A", typeBitmap.toString()); } @Test void typeNSandSOA() { - TypeBitmap typeBitmap = new TypeBitmap(new int[] {2, 6}); + TypeBitmap typeBitmap = new TypeBitmap(new int[] {Type.NS, Type.SOA}); assertEquals("NS SOA", typeBitmap.toString()); } + + @Test + void typeNSandSOAArray() { + int[] typeArray = new int[] {Type.NS, Type.SOA}; + TypeBitmap typeBitmap = new TypeBitmap(typeArray); + assertArrayEquals(typeArray, typeBitmap.toArray()); + } + + @Test + void typeAAndSOAToWire() { + int[] typeArray = new int[] {Type.A, Type.SOA}; + TypeBitmap typeBitmap = new TypeBitmap(typeArray); + DNSOutput out = new DNSOutput(); + typeBitmap.toWire(out); + assertArrayEquals(new byte[] {0, 1, 0b0100_0010}, out.toByteArray()); + } + + @Test + void typeAandNSEC3ToWireAndBack() throws WireParseException { + int[] typeArray = new int[] {Type.A, Type.NSEC3}; + byte[] wire = + new byte[] { + // block + 0, + // size + 7, + // 0-7 + 0b0100_0000, + // 8-15, + 0, + // 16-23, + 0, + // 24-31, + 0, + // 32-39 + 0, + // 40-47 + 0, + // 48-55 + 0b0010_0000 + }; + + // Test serialization + TypeBitmap typeBitmapOut = new TypeBitmap(typeArray); + DNSOutput out = new DNSOutput(); + typeBitmapOut.toWire(out); + assertArrayEquals(wire, out.toByteArray()); + + // Test parsing + DNSInput in = new DNSInput(wire); + TypeBitmap typeBitmapIn = new TypeBitmap(in); + assertArrayEquals(typeArray, typeBitmapIn.toArray()); + } }