diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..022ada3aef81d7d0203adb9e1634700d47e5080c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +# This workflow will build a Java project with Maven +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Java CI with Maven + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + jdk8: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 8 + uses: actions/setup-java@v1 + with: + java-version: 8 + - name: Build with Maven + run: mvn -B package --file pom.xml + + jdk11: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Build with Maven + run: mvn -B package --file pom.xml diff --git a/pom.xml b/pom.xml index d35680ec7fa15a63002ef4990aa9b6bf87e004d2..ded380a29b4a8f02b37968c0811fb324efd04cb4 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ <groupId>com.github.jnr</groupId> <artifactId>jnr-netdb</artifactId> <packaging>jar</packaging> - <version>1.1.6</version> + <version>1.2.0</version> <name>jnr-netdb</name> <description>Lookup TCP and UDP services from java</description> <url>http://github.com/jnr/jnr-netdb</url> @@ -38,8 +38,8 @@ <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <maven.compiler.source>1.5</maven.compiler.source> - <maven.compiler.target>1.5</maven.compiler.target> + <maven.compiler.source>8</maven.compiler.source> + <maven.compiler.target>8</maven.compiler.target> </properties> <dependencies> @@ -54,10 +54,53 @@ <dependency> <groupId>com.github.jnr</groupId> <artifactId>jnr-ffi</artifactId> - <version>2.1.0</version> + <version>2.2.0</version> <scope>compile</scope> </dependency> </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>2.3.1</version> + <configuration> + <archive> + <manifestEntries> + <Automatic-Module-Name>org.jnrproject.netdb</Automatic-Module-Name> + </manifestEntries> + </archive> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.1</version> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>java9</id> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <!-- Use -release compiler option rather than source/target if 9+ --> + <release>${maven.compiler.target}</release> + </configuration> + </plugin> + </plugins> + </build> + <activation> + <jdk>[9,)</jdk> + </activation> + </profile> + </profiles> + </project> diff --git a/src/test/java/jnr/netdb/FileProtocolDBTest.java b/src/test/java/jnr/netdb/FileProtocolDBTest.java index de84ad44697a71306b3f26934bddbca17fb56d87..db6db0a09662371c35260433843d00f6ce755a10 100644 --- a/src/test/java/jnr/netdb/FileProtocolDBTest.java +++ b/src/test/java/jnr/netdb/FileProtocolDBTest.java @@ -34,17 +34,32 @@ public class FileProtocolDBTest { @Test public void canLookupIpProtocolByName() { ProtocolsDB db = FileProtocolsDB.getInstance(); - Protocol p = db.getProtocolByName("ip"); - assertNotNull("could not lookup ip protocol", p); - assertEquals("incorrect proto number", 0, p.getProto()); - assertEquals("incorrect name", "ip", p.getName()); + // we try ip first and then ipv4 due to jnr/jnr-netdb#4 + Protocol p = Protocol.getProtocolByName("ip"); + if (p != null) { + assertEquals("incorrect proto number", 0, p.getProto()); + assertEquals("incorrect name", "ip", p.getName()); + } else { + p = Protocol.getProtocolByName("ipv4"); + assertNotNull("could not lookup ipv4 protocol", p); + assertEquals("incorrect proto number", 4, p.getProto()); + assertEquals("incorrect name", "ipv4", p.getName()); + } } @Test public void canLookupIpProtocolByNumber() { ProtocolsDB db = FileProtocolsDB.getInstance(); - Protocol p = db.getProtocolByNumber(0); - assertNotNull("could not lookup ip protocol", p); - assertEquals("incorrect proto number", 0, p.getProto()); - assertEquals("incorrect name", "ip", p.getName()); + // we try ip first and then ipv4 due to jnr/jnr-netdb#4 + Protocol p = Protocol.getProtocolByName("ip"); + if (p != null) { + p = Protocol.getProtocolByNumber(0); + assertEquals("incorrect proto number", 0, p.getProto()); + assertEquals("incorrect name", "ip", p.getName()); + } else { + p = Protocol.getProtocolByNumber(4); + assertNotNull("could not lookup ip protocol", p); + assertEquals("incorrect proto number", 4, p.getProto()); + assertEquals("incorrect name", "ipv4", p.getName()); + } } } diff --git a/src/test/java/jnr/netdb/NativeProtocolsDBTest.java b/src/test/java/jnr/netdb/NativeProtocolsDBTest.java index aca1aab53a2775ce09273782413ad059d20a8357..671d21b5b0f368be32d84977008701c6fb0539c9 100644 --- a/src/test/java/jnr/netdb/NativeProtocolsDBTest.java +++ b/src/test/java/jnr/netdb/NativeProtocolsDBTest.java @@ -34,18 +34,33 @@ public class NativeProtocolsDBTest { @Test public void canLookupIpProtocolByName() { ProtocolsDB db = NativeProtocolsDB.getInstance(); - Protocol p = db.getProtocolByName("ip"); - assertNotNull("could not lookup ip protocol", p); - assertEquals("incorrect proto number", 0, p.getProto()); - assertEquals("incorrect name", "ip", p.getName()); + // we try ip first and then ipv4 due to jnr/jnr-netdb#4 + Protocol p = Protocol.getProtocolByName("ip"); + if (p != null) { + assertEquals("incorrect proto number", 0, p.getProto()); + assertEquals("incorrect name", "ip", p.getName()); + } else { + p = Protocol.getProtocolByName("ipv4"); + assertNotNull("could not lookup ipv4 protocol", p); + assertEquals("incorrect proto number", 4, p.getProto()); + assertEquals("incorrect name", "ipv4", p.getName()); + } } @Test public void canLookupIpProtocolByNumber() { ProtocolsDB db = NativeProtocolsDB.getInstance(); - Protocol p = db.getProtocolByNumber(0); - assertNotNull("could not lookup ip protocol", p); - assertEquals("incorrect proto number", 0, p.getProto()); - assertEquals("incorrect name", "ip", p.getName()); + // we try ip first and then ipv4 due to jnr/jnr-netdb#4 + Protocol p = Protocol.getProtocolByName("ip"); + if (p != null) { + p = Protocol.getProtocolByNumber(0); + assertEquals("incorrect proto number", 0, p.getProto()); + assertEquals("incorrect name", "ip", p.getName()); + } else { + p = Protocol.getProtocolByNumber(4); + assertNotNull("could not lookup ip protocol", p); + assertEquals("incorrect proto number", 4, p.getProto()); + assertEquals("incorrect name", "ipv4", p.getName()); + } } @Test public void canLookupTcpProtocolByName() { diff --git a/src/test/java/jnr/netdb/ProtocolTest.java b/src/test/java/jnr/netdb/ProtocolTest.java index c7a23a4e240ba7b637f2661cec98914460dfe738..dbf5363e9c995bbde6715444ed24b8708e14f965 100644 --- a/src/test/java/jnr/netdb/ProtocolTest.java +++ b/src/test/java/jnr/netdb/ProtocolTest.java @@ -33,10 +33,17 @@ public class ProtocolTest { } @Test public void canLookupIpProtocolByName() { + // we try ip first and then ipv4 due to jnr/jnr-netdb#4 Protocol p = Protocol.getProtocolByName("ip"); - assertNotNull("could not lookup ip protocol", p); - assertEquals("incorrect proto number", 0, p.getProto()); - assertEquals("incorrect name", "ip", p.getName()); + if (p != null) { + assertEquals("incorrect proto number", 0, p.getProto()); + assertEquals("incorrect name", "ip", p.getName()); + } else { + p = Protocol.getProtocolByName("ipv4"); + assertNotNull("could not lookup ipv4 protocol", p); + assertEquals("incorrect proto number", 4, p.getProto()); + assertEquals("incorrect name", "ipv4", p.getName()); + } } @Test public void returnsNullOnUnknownProtocol() { @@ -45,10 +52,18 @@ public class ProtocolTest { } @Test public void canLookupIpProtocolByNumber() { - Protocol p = Protocol.getProtocolByNumber(0); - assertNotNull("could not lookup ip protocol", p); - assertEquals("incorrect proto number", 0, p.getProto()); - assertEquals("incorrect name", "ip", p.getName()); + // we try ip first and then ipv4 due to jnr/jnr-netdb#4 + Protocol p = Protocol.getProtocolByName("ip"); + if (p != null) { + p = Protocol.getProtocolByNumber(0); + assertEquals("incorrect proto number", 0, p.getProto()); + assertEquals("incorrect name", "ip", p.getName()); + } else { + p = Protocol.getProtocolByNumber(4); + assertNotNull("could not lookup ip protocol", p); + assertEquals("incorrect proto number", 4, p.getProto()); + assertEquals("incorrect name", "ipv4", p.getName()); + } } @Test public void returnsNullOnInvalidNumber() {