You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/11/06 12:34:55 UTC

[commons-net] branch master updated (d13fac3c -> 1efbde46)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git


    from d13fac3c Bump actions/upload-artifact from 3.1.0 to 3.1.1 #124
     new b6f063e6 Pick up SpotBugs version from parent POM
     new ce1c737d Replace CLIRR with JApiCmp
     new 2977f823 Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-net.git
     new 1efbde46 Add missing tests

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                            | 33 +++-------
 .../org/apache/commons/net/util/SubnetUtils.java   | 48 +++++++-------
 .../org/apache/commons/net/SubnetUtilsTest.java    | 77 +++++++++++++++-------
 3 files changed, 85 insertions(+), 73 deletions(-)


[commons-net] 04/04: Add missing tests

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit 1efbde46baab4223241635c484f0fd5447b9f1bb
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 6 07:34:50 2022 -0500

    Add missing tests
    
    - Format tweaks
    - Clean up SubnetUtils.SubnetInfo.toString()
---
 pom.xml                                            |  5 ++
 .../org/apache/commons/net/util/SubnetUtils.java   | 48 +++++++-------
 .../org/apache/commons/net/SubnetUtilsTest.java    | 77 +++++++++++++++-------
 3 files changed, 82 insertions(+), 48 deletions(-)

diff --git a/pom.xml b/pom.xml
index db05d984..0db5107f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -100,6 +100,11 @@ Supported protocols include: Echo, Finger, FTP, NNTP, NTP, POP3(S), SMTP(S), Tel
             <artifactId>junit-vintage-engine</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.ftpserver</groupId>
             <artifactId>ftpserver-core</artifactId>
diff --git a/src/main/java/org/apache/commons/net/util/SubnetUtils.java b/src/main/java/org/apache/commons/net/util/SubnetUtils.java
index 1a18afd5..f1014b1e 100644
--- a/src/main/java/org/apache/commons/net/util/SubnetUtils.java
+++ b/src/main/java/org/apache/commons/net/util/SubnetUtils.java
@@ -207,13 +207,13 @@ public class SubnetUtils {
         @Override
         public String toString() {
             final StringBuilder buf = new StringBuilder();
-            buf.append("CIDR Signature:\t[").append(getCidrSignature()).append("]")
-                .append(" Netmask: [").append(getNetmask()).append("]\n")
-                .append("Network:\t[").append(getNetworkAddress()).append("]\n")
-                .append("Broadcast:\t[").append(getBroadcastAddress()).append("]\n")
-                 .append("First Address:\t[").append(getLowAddress()).append("]\n")
-                 .append("Last Address:\t[").append(getHighAddress()).append("]\n")
-                 .append("# Addresses:\t[").append(getAddressCount()).append("]\n");
+            buf.append("CIDR Signature:\t[").append(getCidrSignature()).append("]\n")
+                .append("  Netmask: [").append(getNetmask()).append("]\n")
+                .append("  Network: [").append(getNetworkAddress()).append("]\n")
+                .append("  Broadcast: [").append(getBroadcastAddress()).append("]\n")
+                .append("  First address: [").append(getLowAddress()).append("]\n")
+                .append("  Last address: [").append(getHighAddress()).append("]\n")
+                .append("  Address Count: [").append(getAddressCountLong()).append("]\n");
             return buf.toString();
         }
     }
@@ -249,6 +249,7 @@ public class SubnetUtils {
 
         throw new IllegalArgumentException("Value [" + value + "] not in range ["+begin+","+end+"]");
     }
+
     /*
      * Convert a dotted decimal format address to a packed integer format
      */
@@ -262,19 +263,15 @@ public class SubnetUtils {
 
     private final int netmask;
 
-
     private final int address;
 
     private final int network;
 
-
     private final int broadcast;
 
     /** Whether the broadcast/network address are included in host count */
     private boolean inclusiveHostCount;
 
-
-
     /**
      * Constructor that takes a CIDR-notation string, e.g. "192.168.0.1/16"
      * @param cidrNotation A CIDR-notation string, e.g. "192.168.0.1/16"
@@ -287,25 +284,26 @@ public class SubnetUtils {
       if (!matcher.matches()) {
           throw new IllegalArgumentException(String.format(PARSE_FAIL, cidrNotation));
       }
-    this.address = matchAddress(matcher);
+      this.address = matchAddress(matcher);
 
-      /* Create a binary netmask from the number of bits specification /x */
+      // Create a binary netmask from the number of bits specification /x 
 
       final int trailingZeroes = NBITS - rangeCheck(Integer.parseInt(matcher.group(5)), 0, NBITS);
-      /*
-       * An IPv4 netmask consists of 32 bits, a contiguous sequence
-       * of the specified number of ones followed by all zeros.
-       * So, it can be obtained by shifting an unsigned integer (32 bits) to the left by
-       * the number of trailing zeros which is (32 - the # bits specification).
-       * Note that there is no unsigned left shift operator, so we have to use
-       * a long to ensure that the left-most bit is shifted out correctly.
-       */
+      
+      //
+      // An IPv4 netmask consists of 32 bits, a contiguous sequence
+      // of the specified number of ones followed by all zeros.
+      // So, it can be obtained by shifting an unsigned integer (32 bits) to the left by
+      // the number of trailing zeros which is (32 - the # bits specification).
+      // Note that there is no unsigned left shift operator, so we have to use
+      // a long to ensure that the left-most bit is shifted out correctly.
+      //
       this.netmask = (int) (0x0FFFFFFFFL << trailingZeroes );
 
-      /* Calculate base network address */
+      // Calculate base network address
       this.network = address & netmask;
 
-      /* Calculate broadcast address */
+      // Calculate broadcast address
       this.broadcast = network | ~netmask;
     }
 
@@ -324,10 +322,10 @@ public class SubnetUtils {
             throw new IllegalArgumentException(String.format(PARSE_FAIL, mask));
         }
 
-        /* Calculate base network address */
+        // Calculate base network address
         this.network = this.address & this.netmask;
 
-        /* Calculate broadcast address */
+        // Calculate broadcast address
         this.broadcast = this.network | ~this.netmask;
     }
 
diff --git a/src/test/java/org/apache/commons/net/SubnetUtilsTest.java b/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
index 4b0769ea..a4715989 100644
--- a/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
+++ b/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
@@ -17,6 +17,10 @@
 
 package org.apache.commons.net;
 
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
 import org.apache.commons.net.util.SubnetUtils;
 import org.apache.commons.net.util.SubnetUtils.SubnetInfo;
 
@@ -40,6 +44,15 @@ public class SubnetUtilsTest extends TestCase {
         assertFalse(info.isInRange("10.10.2.1"));
         assertFalse(info.isInRange("192.168.1.1"));
         assertFalse(info.isInRange("192.168.0.255"));
+        //
+        assertEquals(-1062731775, info.asInteger("192.168.0.1"));
+        assertThrows(IllegalArgumentException.class, () -> info.asInteger("bad"));
+        //
+        assertArrayEquals(new String[] { "192.168.0.1", "192.168.0.2", "192.168.0.3", "192.168.0.4", "192.168.0.5", "192.168.0.6" }, info.getAllAddresses());
+    }
+
+    public void testAddressIllegalArgument() {
+        assertThrows(IllegalArgumentException.class, () -> new SubnetUtils("bad"));
     }
 
     /**
@@ -318,26 +331,32 @@ public class SubnetUtilsTest extends TestCase {
         assertTrue(info.isInRange("10.213.255.255"));
     }
 
+    public void testNext() {
+        final SubnetUtils utils = new SubnetUtils("192.168.0.1/29");
+        assertEquals("192.168.0.2", utils.getNext().getInfo().getAddress());
+    }
+
     public void testParseSimpleNetmask() {
         final String address = "192.168.0.1";
-        final String masks[] = new String[] { "255.0.0.0", "255.255.0.0", "255.255.255.0", "255.255.255.248" };
-        final String bcastAddresses[] = new String[] { "192.255.255.255", "192.168.255.255", "192.168.0.255",
+        final String masks[] = { "255.0.0.0", "255.255.0.0", "255.255.255.0", "255.255.255.248" };
+        final String bcastAddresses[] = { "192.255.255.255", "192.168.255.255", "192.168.0.255",
                 "192.168.0.7" };
-        final String lowAddresses[] = new String[] { "192.0.0.1", "192.168.0.1", "192.168.0.1", "192.168.0.1" };
-        final String highAddresses[] = new String[] { "192.255.255.254", "192.168.255.254", "192.168.0.254",
+        final String lowAddresses[] = { "192.0.0.1", "192.168.0.1", "192.168.0.1", "192.168.0.1" };
+        final String highAddresses[] = { "192.255.255.254", "192.168.255.254", "192.168.0.254",
                 "192.168.0.6" };
-        final String nextAddresses[] = new String[] { "192.168.0.2", "192.168.0.2", "192.168.0.2",
+        final String nextAddresses[] = { "192.168.0.2", "192.168.0.2", "192.168.0.2",
                 "192.168.0.2" };
-        final String previousAddresses[] = new String[] { "192.168.0.0", "192.168.0.0", "192.168.0.0",
+        final String previousAddresses[] = { "192.168.0.0", "192.168.0.0", "192.168.0.0",
                 "192.168.0.0" };
-        final String networkAddresses[] = new String[] { "192.0.0.0", "192.168.0.0", "192.168.0.0", "192.168.0.0" };
-        final String cidrSignatures[] = new String[] { "192.168.0.1/8", "192.168.0.1/16", "192.168.0.1/24",
+        final String networkAddresses[] = { "192.0.0.0", "192.168.0.0", "192.168.0.0", "192.168.0.0" };
+        final String cidrSignatures[] = { "192.168.0.1/8", "192.168.0.1/16", "192.168.0.1/24",
                 "192.168.0.1/29" };
-        final int usableAddresses[] = new int[] { 16777214, 65534, 254, 6 };
+        final int usableAddresses[] = { 16777214, 65534, 254, 6 };
 
         for (int i = 0; i < masks.length; ++i) {
             final SubnetUtils utils = new SubnetUtils(address, masks[i]);
             final SubnetInfo info = utils.getInfo();
+            assertEquals(address, info.getAddress());
             assertEquals(bcastAddresses[i], info.getBroadcastAddress());
             assertEquals(cidrSignatures[i], info.getCidrSignature());
             assertEquals(lowAddresses[i], info.getLowAddress());
@@ -351,13 +370,13 @@ public class SubnetUtilsTest extends TestCase {
 
     public void testParseSimpleNetmaskExclusive() {
         final String address = "192.168.15.7";
-        final String masks[] = new String[] { "255.255.255.252", "255.255.255.254", "255.255.255.255" };
-        final String bcast[] = new String[] { "192.168.15.7", "192.168.15.7", "192.168.15.7" };
-        final String netwk[] = new String[] { "192.168.15.4", "192.168.15.6", "192.168.15.7" };
-        final String lowAd[] = new String[] { "192.168.15.5", "0.0.0.0", "0.0.0.0" };
-        final String highA[] = new String[] { "192.168.15.6", "0.0.0.0", "0.0.0.0" };
-        final String cidrS[] = new String[] { "192.168.15.7/30", "192.168.15.7/31", "192.168.15.7/32" };
-        final int usableAd[] = new int[] { 2, 0, 0 };
+        final String masks[] = { "255.255.255.252", "255.255.255.254", "255.255.255.255" };
+        final String bcast[] = { "192.168.15.7", "192.168.15.7", "192.168.15.7" };
+        final String netwk[] = { "192.168.15.4", "192.168.15.6", "192.168.15.7" };
+        final String lowAd[] = { "192.168.15.5", "0.0.0.0", "0.0.0.0" };
+        final String highA[] = { "192.168.15.6", "0.0.0.0", "0.0.0.0" };
+        final String cidrS[] = { "192.168.15.7/30", "192.168.15.7/31", "192.168.15.7/32" };
+        final int usableAd[] = { 2, 0, 0 };
         // low and high addresses don't exist
 
         for (int i = 0; i < masks.length; ++i) {
@@ -375,13 +394,13 @@ public class SubnetUtilsTest extends TestCase {
 
     public void testParseSimpleNetmaskInclusive() {
         final String address = "192.168.15.7";
-        final String masks[] = new String[] { "255.255.255.252", "255.255.255.254", "255.255.255.255" };
-        final String bcast[] = new String[] { "192.168.15.7", "192.168.15.7", "192.168.15.7" };
-        final String netwk[] = new String[] { "192.168.15.4", "192.168.15.6", "192.168.15.7" };
-        final String lowAd[] = new String[] { "192.168.15.4", "192.168.15.6", "192.168.15.7" };
-        final String highA[] = new String[] { "192.168.15.7", "192.168.15.7", "192.168.15.7" };
-        final String cidrS[] = new String[] { "192.168.15.7/30", "192.168.15.7/31", "192.168.15.7/32" };
-        final int usableAd[] = new int[] { 4, 2, 1 };
+        final String masks[] = { "255.255.255.252", "255.255.255.254", "255.255.255.255" };
+        final String bcast[] = { "192.168.15.7", "192.168.15.7", "192.168.15.7" };
+        final String netwk[] = { "192.168.15.4", "192.168.15.6", "192.168.15.7" };
+        final String lowAd[] = { "192.168.15.4", "192.168.15.6", "192.168.15.7" };
+        final String highA[] = { "192.168.15.7", "192.168.15.7", "192.168.15.7" };
+        final String cidrS[] = { "192.168.15.7/30", "192.168.15.7/31", "192.168.15.7/32" };
+        final int usableAd[] = { 4, 2, 1 };
 
         for (int i = 0; i < masks.length; ++i) {
             final SubnetUtils utils = new SubnetUtils(address, masks[i]);
@@ -396,6 +415,18 @@ public class SubnetUtilsTest extends TestCase {
         }
     }
 
+    public void testPrevious() {
+        final SubnetUtils utils = new SubnetUtils("192.168.0.1/29");
+        assertEquals("192.168.0.0", utils.getPrevious().getInfo().getAddress());
+    }
+
+    public void testToString() {
+        final SubnetUtils utils = new SubnetUtils("192.168.0.1/29");
+        assertDoesNotThrow(() -> utils.toString());
+        final SubnetInfo info = utils.getInfo();
+        assertDoesNotThrow(() -> info.toString());
+    }
+
     public void testZeroAddressAndCidr() {
         final SubnetUtils snu = new SubnetUtils("0.0.0.0/0");
         assertNotNull(snu);


[commons-net] 01/04: Pick up SpotBugs version from parent POM

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit b6f063e6e1b155ec3ba71c46cb273d2cef418192
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 6 06:58:23 2022 -0500

    Pick up SpotBugs version from parent POM
---
 pom.xml | 2 --
 1 file changed, 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 60f03f2e..7f8f167d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -127,7 +127,6 @@ Supported protocols include: Echo, Finger, FTP, NNTP, NTP, POP3(S), SMTP(S), Tel
                 <plugin>
                     <groupId>com.github.spotbugs</groupId>
                     <artifactId>spotbugs-maven-plugin</artifactId>
-                    <version>${commons.spotbugs.version}</version>
                     <configuration>
                         <excludeFilterFile>findbugs-exclude-filter.xml</excludeFilterFile>
                     </configuration>
@@ -390,7 +389,6 @@ Supported protocols include: Echo, Finger, FTP, NNTP, NTP, POP3(S), SMTP(S), Tel
             <plugin>
                 <groupId>com.github.spotbugs</groupId>
                 <artifactId>spotbugs-maven-plugin</artifactId>
-                <version>${commons.spotbugs.version}</version>
                 <configuration>
                     <excludeFilterFile>findbugs-exclude-filter.xml</excludeFilterFile>
                 </configuration>


[commons-net] 03/04: Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-net.git

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit 2977f823e8bf71e63694e4f2c63b1b58dded2013
Merge: ce1c737d d13fac3c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 6 07:07:29 2022 -0500

    Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-net.git

 .github/workflows/codeql-analysis.yml     | 2 +-
 .github/workflows/coverage.yml            | 4 ++--
 .github/workflows/maven.yml               | 4 ++--
 .github/workflows/maven_adhoc.yml         | 2 +-
 .github/workflows/scorecards-analysis.yml | 2 +-
 src/changes/changes.xml                   | 6 +++---
 6 files changed, 10 insertions(+), 10 deletions(-)


[commons-net] 02/04: Replace CLIRR with JApiCmp

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit ce1c737ddccdb85bba0232b2754ba6e76abbc119
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 6 07:07:17 2022 -0500

    Replace CLIRR with JApiCmp
    
    Add JaCoCo
---
 pom.xml | 26 +++-----------------------
 1 file changed, 3 insertions(+), 23 deletions(-)

diff --git a/pom.xml b/pom.xml
index 7f8f167d..db05d984 100644
--- a/pom.xml
+++ b/pom.xml
@@ -52,12 +52,13 @@ Supported protocols include: Echo, Finger, FTP, NNTP, NTP, POP3(S), SMTP(S), Tel
 
         <commons.scmPubCheckoutDirectory>site-content</commons.scmPubCheckoutDirectory>
         <commons.scmPubUrl>https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-net</commons.scmPubUrl>
+        <japicmp.skip>false</japicmp.skip>
+        <jacoco.skip>false</jacoco.skip>
 
         <!-- Current release -->
         <commons.release.version>3.9.0</commons.release.version>
         <commons.rc.version>RC1</commons.rc.version>
-        <commons.release.desc>(Requires Java ${maven.compiler.target} or
-            later)</commons.release.desc>
+        <commons.release.desc>(Requires Java ${maven.compiler.target} or later)</commons.release.desc>
 
         <!-- Release plugin defines -->
         <commons.bc.version>3.8.0</commons.bc.version>
@@ -338,17 +339,6 @@ Supported protocols include: Echo, Finger, FTP, NNTP, NTP, POP3(S), SMTP(S), Tel
                 </configuration>
             </plugin>
 
-            <!-- drop examples from CLI invocations -->
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>clirr-maven-plugin</artifactId>
-                <configuration>
-                    <excludes>
-                        <exclude>**/examples/**</exclude>
-                    </excludes>
-                </configuration>
-            </plugin>
-
             <!-- Allow exec:java to launch examples from the classpath For example: mvn -q exec:java -Dexec.arguments=FTPClientExample,-A,-l,hostname -->
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
@@ -394,16 +384,6 @@ Supported protocols include: Echo, Finger, FTP, NNTP, NTP, POP3(S), SMTP(S), Tel
                 </configuration>
             </plugin>
 
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>clirr-maven-plugin</artifactId>
-                <configuration>
-                    <excludes>
-                        <exclude>**/examples/**</exclude>
-                    </excludes>
-                </configuration>
-            </plugin>
-
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-javadoc-plugin</artifactId>