]> granicus.if.org Git - icu/commitdiff
ICU-21569 Fix Java7 breakage in LSTM & add Java7 CI
authorFrank Yung-Fong Tang <ftang@google.com>
Thu, 27 May 2021 21:57:01 +0000 (21:57 +0000)
committerFrank Yung-Fong Tang <ftang@google.com>
Thu, 27 May 2021 23:11:51 +0000 (16:11 -0700)
See #1734

.github/workflows/icu_ci.yml
icu4j/main/tests/core/src/com/ibm/icu/dev/test/rbbi/LSTMBreakEngineTest.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/rbbi/RBBILSTMTest.java

index 628d5db04b7c14b899b752c98f501bac7bdd8cc9..da95c6d2c40221caa0842fecd887d1ea68fadf98 100644 (file)
@@ -30,6 +30,51 @@ jobs:
            # Regex note: (?! ... ) is a negative lookahead. Succeed if the pattern is not present. 
           set +o pipefail && make doc 2>&1 | tee doxygen.log && ( ! grep -P 'warning:(?! .* file .?Doxyfile)' doxygen.log )
 
+  # Java7 ICU4J build and unit test
+  java7-icu4j-build-and-test:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout and setup
+        uses: actions/checkout@v2
+        with:
+          lfs: true
+      - name: Checkout lfs objects
+        run: git lfs pull
+      - uses: actions/setup-java@v1
+        with:
+          java-version: '8'
+      - name: Cache for Java 7 tarball
+        id: cache-java7
+        uses: actions/cache@v2
+        with:
+          path: java7-tarball
+          key: ${{ runner.os }}-java7-tarball
+      - name: Download Java 7
+        if: steps.cache-java7.outputs.cache-hit != 'true'
+        run: |
+          mkdir -p java7-tarball
+          download_url="https://download.java.net/openjdk/jdk7u75/ri/openjdk-7u75-b13-linux-x64-18_dec_2014.tar.gz"
+          wget -O java7-tarball/java_package.tar.gz $download_url
+          pushd java7-tarball
+          gunzip java_package.tar.gz
+          tar xvf java_package.tar
+          popd
+      - name: Configure Ant build to use Java 7 JRE
+        run: |
+          echo "java7.bootclasspath" > $RUNNER_TEMP/draft
+          ls java7-tarball/java-se-7u75-ri/jre/lib/*.jar|paste -sd ":" - >> $RUNNER_TEMP/draft
+          paste -sd "=" < $RUNNER_TEMP/draft >  icu4j/build-local.properties
+      - name: ICU4J
+        run: |
+          cd icu4j;
+          ant init;
+          ant check;
+      - name: List failures (if any)
+        run: |
+          [ -d icu4j/out/junit-results ] && cd icu4j && cat `find out/junit-results -name "*.txt" -exec grep -l FAILED {} \;`;
+        if: ${{ failure() }}
+
+
   # ICU4J build and unit test under Java11
   java11-icu4j-build-and-test:
     runs-on: ubuntu-latest
index 0208e68fe2946d9fd7c14dcb01ac16b76ee9c0cb..8d248a551a2c35fda3468b946c6035c89f4c02e4 100644 (file)
@@ -9,8 +9,6 @@ import java.io.InputStreamReader;
 import java.nio.charset.StandardCharsets;
 import java.text.CharacterIterator;
 import java.text.StringCharacterIterator;
-import java.util.Iterator;
-import java.util.stream.Stream;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -66,52 +64,54 @@ public class LSTMBreakEngineTest extends TestFmwk {
             errln("Could not open test data file " + filename);
             return;
         }
-        Stream<String> lines = (new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))).lines();
-        Iterator<String> iterator = lines.iterator();
+        BufferedReader br = (new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)));
         int caseNum = 0;
         String expected = "";
         String actual = "";
         LSTMBreakEngine engine = null;
-        while (iterator.hasNext()) {
-            String line = iterator.next();
-            String fields[] = line.split("\t");
-            if (fields[0].equals("Model:")) {
-                engine = createEngineFromTestData(fields[1], script);
-            } else if (fields[0].equals("Input:")) {
-                caseNum++;
-                int length = fields[1].length();
-                CharacterIterator input = new StringCharacterIterator(fields[1]);
-                DictionaryBreakEngine.DequeI foundBreaks = new DictionaryBreakEngine.DequeI();
-                int ret = engine.findBreaks(input, 0, length, foundBreaks);
-                StringBuilder sb = new StringBuilder();
-                sb.append('{');
-                for (int i = 0; i < foundBreaks.size(); i++) {
-                    sb.append(foundBreaks.elementAt(i)).append(", ");
-                }
-                sb.append(length).append('}');
-                actual =  sb.toString();
-            } else if (fields[0].equals("Output:")) {
-                StringBuilder sb = new StringBuilder();
-                int sep;
-                int start = 0;
-                int curr = 0;
-                sb.append('{');
-                while ((sep = fields[1].indexOf('|', start)) >= 0) {
-                    int len = sep - start;
-                    if (len > 0) {
-                        if (curr > 0) {
-                            sb.append(", ");
+        String line;
+        try {
+            while ((line = br.readLine()) != null) {
+                String fields[] = line.split("\t");
+                if (fields[0].equals("Model:")) {
+                    engine = createEngineFromTestData(fields[1], script);
+                } else if (fields[0].equals("Input:")) {
+                    caseNum++;
+                    int length = fields[1].length();
+                    CharacterIterator input = new StringCharacterIterator(fields[1]);
+                    DictionaryBreakEngine.DequeI foundBreaks = new DictionaryBreakEngine.DequeI();
+                    int ret = engine.findBreaks(input, 0, length, foundBreaks);
+                    StringBuilder sb = new StringBuilder();
+                    sb.append('{');
+                    for (int i = 0; i < foundBreaks.size(); i++) {
+                        sb.append(foundBreaks.elementAt(i)).append(", ");
+                    }
+                    sb.append(length).append('}');
+                    actual =  sb.toString();
+                } else if (fields[0].equals("Output:")) {
+                    StringBuilder sb = new StringBuilder();
+                    int sep;
+                    int start = 0;
+                    int curr = 0;
+                    sb.append('{');
+                    while ((sep = fields[1].indexOf('|', start)) >= 0) {
+                        int len = sep - start;
+                        if (len > 0) {
+                            if (curr > 0) {
+                                sb.append(", ");
+                            }
+                            curr += len;
+                            sb.append(curr);
                         }
-                        curr += len;
-                        sb.append(curr);
+                        start = sep + 1;
                     }
-                    start = sep + 1;
+                    sb.append('}');
+                    expected =  sb.toString();
+                    assertEquals(line + " Test Case#" + caseNum , expected, actual);
                 }
-                sb.append('}');
-                expected =  sb.toString();
-
-                assertEquals(line + " Test Case#" + caseNum , expected, actual);
             }
+        } catch (IOException e) {
+            errln("Exception while reading lines of test data file " + filename + e.toString());
         }
     }
 }
index 06eb2f40ae88d3530e1d4aa3598d824529bd4de6..441ec7d6fda8f3c36c237f25d4af319360dbe81d 100644 (file)
@@ -9,8 +9,6 @@ import java.io.InputStreamReader;
 import java.nio.charset.StandardCharsets;
 import java.text.CharacterIterator;
 import java.text.StringCharacterIterator;
-import java.util.Iterator;
-import java.util.stream.Stream;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -56,63 +54,65 @@ public class RBBILSTMTest extends TestFmwk {
             errln("Could not open test data file " + filename);
             return;
         }
-        Stream<String> lines = (new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))).lines();
-        Iterator<String> iterator = lines.iterator();
+        BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
         int caseNum = 0;
         String expected = "";
         String actual = "";
         LSTMBreakEngine engine = null;
-        while (iterator.hasNext()) {
-            String line = iterator.next();
-            String fields[] = line.split("\t");
-            if (fields[0].equals("Model:")) {
-                String actualModelName = LSTMBreakEngine.createData(script).fName;
-                if (!actualModelName.equals(fields[1])) {
-                    errln("The name of the built in model " + actualModelName +
-                        " does not match the model (" + fields[1] + ") expected for this test");
-                    return;
-                }
-            } else if (fields[0].equals("Input:")) {
-                caseNum++;
-                int length = fields[1].length();
-                String input = "prefix " + fields[1] + " suffix";
-                bi.setText(input);
-                System.out.println("Input = " + input);
-                StringBuilder sb = new StringBuilder();
-                sb.append('{');
-                for (int bp = bi.first(); bp != BreakIterator.DONE; bp = bi.next()) {
-                    sb.append(bp);
-                    if (bp != input.length()) {
-                        sb.append(", ");
+        String line;
+        try {
+            while ((line = br.readLine()) != null) {
+                String fields[] = line.split("\t");
+                if (fields[0].equals("Model:")) {
+                    String actualModelName = LSTMBreakEngine.createData(script).fName;
+                    if (!actualModelName.equals(fields[1])) {
+                        errln("The name of the built in model " + actualModelName +
+                            " does not match the model (" + fields[1] + ") expected for this test");
+                        return;
                     }
-                }
-                sb.append('}');
-                actual =  sb.toString();
-            } else if (fields[0].equals("Output:")) {
-                StringBuilder sb = new StringBuilder();
-                int sep;
-                int start = 0;
-                int curr = 0;
-                sb.append("{0, ");
-                String input = "prefix| |" + fields[1] + "| |suffix";
-                while ((sep = input.indexOf('|', start)) >= 0) {
-                    int len = sep - start;
-                    if (len > 0) {
-                        if (curr > 0) {
+                } else if (fields[0].equals("Input:")) {
+                    caseNum++;
+                    int length = fields[1].length();
+                    String input = "prefix " + fields[1] + " suffix";
+                    bi.setText(input);
+                    System.out.println("Input = " + input);
+                    StringBuilder sb = new StringBuilder();
+                    sb.append('{');
+                    for (int bp = bi.first(); bp != BreakIterator.DONE; bp = bi.next()) {
+                        sb.append(bp);
+                        if (bp != input.length()) {
                             sb.append(", ");
                         }
-                        curr += len;
-                        sb.append(curr);
                     }
-                    start = sep + 1;
+                    sb.append('}');
+                    actual =  sb.toString();
+                } else if (fields[0].equals("Output:")) {
+                    StringBuilder sb = new StringBuilder();
+                    int sep;
+                    int start = 0;
+                    int curr = 0;
+                    sb.append("{0, ");
+                    String input = "prefix| |" + fields[1] + "| |suffix";
+                    while ((sep = input.indexOf('|', start)) >= 0) {
+                        int len = sep - start;
+                        if (len > 0) {
+                            if (curr > 0) {
+                                sb.append(", ");
+                            }
+                            curr += len;
+                            sb.append(curr);
+                        }
+                        start = sep + 1;
+                    }
+                    sb.append(", ").append(curr + input.length() - start);
+                    sb.append('}');
+                    expected =  sb.toString();
+                    assertEquals(input + " Test Case#" + caseNum , expected, actual);
+                    actual = "";
                 }
-                sb.append(", ").append(curr + input.length() - start);
-                sb.append('}');
-                expected =  sb.toString();
-
-                assertEquals(input + " Test Case#" + caseNum , expected, actual);
-                actual = "";
             }
+        } catch (IOException e) {
+           errln("Exception while reading lines of test data file " + filename + e.toString());
         }
     }
 }