You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by ma...@apache.org on 2023/05/24 15:47:39 UTC

[opennlp] branch OPENNLP-1496_Migrate_OpenNLP_towards_JDK_17 created (now 7232a2cc)

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

mawiesne pushed a change to branch OPENNLP-1496_Migrate_OpenNLP_towards_JDK_17
in repository https://gitbox.apache.org/repos/asf/opennlp.git


      at 7232a2cc OPENNLP-1496 Migrate OpenNLP towards JDK 17

This branch includes the following new commits:

     new 7232a2cc OPENNLP-1496 Migrate OpenNLP towards JDK 17

The 1 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.



[opennlp] 01/01: OPENNLP-1496 Migrate OpenNLP towards JDK 17

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

mawiesne pushed a commit to branch OPENNLP-1496_Migrate_OpenNLP_towards_JDK_17
in repository https://gitbox.apache.org/repos/asf/opennlp.git

commit 7232a2ccbcbfe45900e3cde51338627950693319
Author: Martin Wiesner <ma...@hs-heilbronn.de>
AuthorDate: Wed May 24 17:47:29 2023 +0200

    OPENNLP-1496 Migrate OpenNLP towards JDK 17
    
    - switches Java version and compiler target '17'
    - adapts CLITest to use lightweight JUnit5 extension and related annotations thereby dropping deprecated custom 'NoExitSecurityManager'
    - adapts github workflows config files
---
 .github/workflows/maven.yml                        |  2 +-
 .github/workflows/publish-snapshots.yml            |  2 +-
 opennlp-tools/pom.xml                              |  8 ++
 .../test/java/opennlp/tools/cmdline/CLITest.java   | 91 +++-------------------
 pom.xml                                            |  2 +-
 5 files changed, 22 insertions(+), 83 deletions(-)

diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index 56286d8b..5ccec404 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -24,7 +24,7 @@ jobs:
     strategy:
       matrix:
         os: [ubuntu-latest, windows-latest]
-        java: [ 11, 17, 19 ]
+        java: [ 17, 19 ]
         experimental: [false]
 #        include:
 #          - java: 18-ea
diff --git a/.github/workflows/publish-snapshots.yml b/.github/workflows/publish-snapshots.yml
index a5dd55f2..2c4dd748 100644
--- a/.github/workflows/publish-snapshots.yml
+++ b/.github/workflows/publish-snapshots.yml
@@ -42,7 +42,7 @@ jobs:
         uses: actions/setup-java@v3
         with:
           distribution: adopt
-          java-version: 11
+          java-version: 17
       - id: extract_version
         name: Extract version
         shell: bash
diff --git a/opennlp-tools/pom.xml b/opennlp-tools/pom.xml
index 0f7a19ac..5a70549b 100644
--- a/opennlp-tools/pom.xml
+++ b/opennlp-tools/pom.xml
@@ -76,6 +76,14 @@
       <artifactId>slf4j-simple</artifactId>
       <scope>test</scope>
     </dependency>
+
+    <!-- JUnit5 extension used in CLITest to prevent System.exit(..) calls terminating test runs -->
+    <dependency>
+      <groupId>com.ginsberg</groupId>
+      <artifactId>junit5-system-exit</artifactId>
+      <version>1.1.2</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
diff --git a/opennlp-tools/src/test/java/opennlp/tools/cmdline/CLITest.java b/opennlp-tools/src/test/java/opennlp/tools/cmdline/CLITest.java
index 62860312..b58c82f5 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/cmdline/CLITest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/cmdline/CLITest.java
@@ -17,105 +17,45 @@
 
 package opennlp.tools.cmdline;
 
-import java.security.Permission;
-
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
+import com.ginsberg.junit.exit.ExpectSystemExitWithStatus;
 import org.junit.jupiter.api.Test;
 
 public class CLITest {
 
-  private static class ExitException extends SecurityException {
-
-    private static final long serialVersionUID = 6144359372794123631L;
-    
-    private final int status;
-
-    public ExitException(int status) {
-      this.status = status;
-    }
-
-    int status() {
-      return status;
-    }
-  }
-
-  /**
-   * A <code>SecurityManager</code> which prevents System.exit anything else is allowed.
-   */
-  private static class NoExitSecurityManager extends SecurityManager {
-
-    @Override
-    public void checkPermission(Permission perm) {
-    }
-
-    @Override
-    public void checkPermission(Permission perm, Object context) {
-    }
-
-    @Override
-    public void checkExit(int status) {
-      super.checkExit(status);
-
-      throw new ExitException(status);
-    }
-  }
-
-  private final SecurityManager originalSecurityManager = System.getSecurityManager();
-
-  @BeforeEach
-  void installNoExitSecurityManager() {
-    System.setSecurityManager(new NoExitSecurityManager());
-  }
-
   /**
    * Ensure the main method does not fail to print help message.
    */
   @Test
+  @ExpectSystemExitWithStatus(0)
   void testMainHelpMessage() {
-
-    try {
-      CLI.main(new String[] {});
-    } catch (ExitException e) {
-      Assertions.assertEquals(0, e.status());
-    }
+    CLI.main(new String[] {});
   }
 
   /**
    * Ensure the main method prints error and returns 1.
    */
   @Test
+  @ExpectSystemExitWithStatus(1)
   void testUnknownToolMessage() {
-    try {
-      CLI.main(new String[] {"unknown name"});
-    } catch (ExitException e) {
-      Assertions.assertEquals(1, e.status());
-    }
+    CLI.main(new String[] {"unknown name"});
   }
 
   /**
    * Ensure the tool checks the parameter and returns 1.
    */
   @Test
+  @ExpectSystemExitWithStatus(1)
   void testToolParameterMessage() {
-    try {
-      CLI.main(new String[] {"DoccatTrainer", "-param", "value"});
-    } catch (ExitException e) {
-      Assertions.assertEquals(1, e.status());
-    }
+    CLI.main(new String[] {"DoccatTrainer", "-param", "value"});
   }
 
   /**
    * Ensure the main method prints error and returns -1
    */
   @Test
+  @ExpectSystemExitWithStatus(-1)
   void testUnknownFileMessage() {
-    try {
-      CLI.main(new String[] {"Doccat", "unknown.model"});
-    } catch (ExitException e) {
-      Assertions.assertEquals(-1, e.status());
-    }
+    CLI.main(new String[] {"Doccat", "unknown.model"});
   }
 
 
@@ -123,20 +63,11 @@ public class CLITest {
    * Ensure all tools do not fail printing help message;
    */
   @Test
+  @ExpectSystemExitWithStatus(0)
   void testHelpMessageOfTools() {
-
     for (String toolName : CLI.getToolNames()) {
-      try {
-        CLI.main(new String[] {toolName, "help"});
-      } catch (ExitException e) {
-        Assertions.assertEquals(0, e.status());
-      }
+      CLI.main(new String[] {toolName, "help"});
     }
   }
 
-  @AfterEach
-  void restoreSecurityManager() {
-    System.setSecurityManager(originalSecurityManager);
-  }
-
 }
diff --git a/pom.xml b/pom.xml
index 828d06a5..9b41ea3e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -164,7 +164,7 @@
 
 	<properties>
 		<!-- Build Properties -->
-		<java.version>11</java.version>
+		<java.version>17</java.version>
 		<maven.version>3.3.9</maven.version>
 		<commons.io.version>2.11.0</commons.io.version>
 		<enforcer.plugin.version>3.3.0</enforcer.plugin.version>