You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2021/05/21 22:32:10 UTC

svn commit: r1890090 - in /poi/trunk: ./ poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/ poi-examples/src/main/java/org/apache/poi/examples/ss/ poi-examples/src/test/java/org/apache/poi/integration/

Author: kiwiwings
Date: Fri May 21 22:32:09 2021
New Revision: 1890090

URL: http://svn.apache.org/viewvc?rev=1890090&view=rev
Log:
add forbidden-apis plugin to gradle builds

Modified:
    poi/trunk/build.gradle
    poi/trunk/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/InCellLists.java
    poi/trunk/poi-examples/src/main/java/org/apache/poi/examples/ss/ToCSV.java
    poi/trunk/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java

Modified: poi/trunk/build.gradle
URL: http://svn.apache.org/viewvc/poi/trunk/build.gradle?rev=1890090&r1=1890089&r2=1890090&view=diff
==============================================================================
--- poi/trunk/build.gradle (original)
+++ poi/trunk/build.gradle Fri May 21 22:32:09 2021
@@ -18,10 +18,12 @@
 buildscript {
     repositories {
         maven { url "https://plugins.gradle.org/m2/" }
+        mavenCentral()
     }
 
     dependencies {
         classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.1.1"
+        classpath "de.thetaphi:forbiddenapis:3.1"
     }
 }
 
@@ -94,7 +96,7 @@ subprojects {
     apply plugin: 'jacoco'
     apply plugin: 'maven-publish'
     apply plugin: 'signing'
-
+    apply plugin: 'de.thetaphi.forbiddenapis'
 
     version = '5.0.1-SNAPSHOT'
     ext {
@@ -304,6 +306,19 @@ subprojects {
         }
     }
 
+    forbiddenApis {
+        bundledSignatures = [ 'jdk-unsafe', 'jdk-deprecated', 'jdk-internal', 'jdk-non-portable', 'jdk-reflection' ]
+        signaturesFiles = files('../src/resources/devtools/forbidden-signatures.txt')
+        ignoreFailures = false
+        suppressAnnotations = [ 'org.apache.poi.util.SuppressForbidden' ]
+        // forbiddenapis bundled signatures max supported version is 14
+        targetCompatibility = (JavaVersion.VERSION_14.isCompatibleWith(JavaVersion.current()) ? JavaVersion.current() : JavaVersion.VERSION_14)
+    }
+
+    forbiddenApisMain {
+        signaturesFiles = files('../src/resources/devtools/forbidden-signatures-prod.txt')
+    }
+
     task jenkins
     jenkins.dependsOn build
     jenkins.dependsOn check

Modified: poi/trunk/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/InCellLists.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/InCellLists.java?rev=1890090&r1=1890089&r2=1890090&view=diff
==============================================================================
--- poi/trunk/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/InCellLists.java (original)
+++ poi/trunk/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/InCellLists.java Fri May 21 22:32:09 2021
@@ -18,12 +18,13 @@
 
 package org.apache.poi.examples.hssf.usermodel;
 
-import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFCellStyle;
 import org.apache.poi.hssf.usermodel.HSSFDataFormat;
@@ -49,6 +50,8 @@ import org.apache.poi.hssf.usermodel.HSS
  */
 @SuppressWarnings({"java:S106","java:S4823"})
 public class InCellLists {
+    private static final Logger LOG = LogManager.getLogger(InCellLists.class);
+
 
     // This character looks like a solid, black, loser case letter 'o'
     // positioned up from the base line of the text.
@@ -65,7 +68,7 @@ public class InCellLists {
      * @param outputFilename A String that encapsulates the name of and path to
      *                       the Excel spreadsheet file this code will create.
      */
-    public void demonstrateMethodCalls(String outputFilename) throws IOException {
+    public void demonstrateMethodCalls(String outputFilename) {
         try (HSSFWorkbook workbook = new HSSFWorkbook()) {
             HSSFSheet sheet = workbook.createSheet("In Cell Lists");
             HSSFRow row = sheet.createRow(0);
@@ -161,14 +164,11 @@ public class InCellLists {
             row.setHeight((short) 2800);
 
             // Save the completed workbook
-            try (FileOutputStream fos = new FileOutputStream(new File(outputFilename))) {
+            try (FileOutputStream fos = new FileOutputStream(outputFilename)) {
                 workbook.write(fos);
             }
         } catch (IOException ioEx) {
-            System.out.println("Caught a: " + ioEx.getClass().getName());
-            System.out.println("Message: " + ioEx.getMessage());
-            System.out.println("Stacktrace follows...........");
-            ioEx.printStackTrace(System.out);
+            LOG.atWarn().withThrowable(ioEx).log("Unexpected IOException");
         }
     }
 
@@ -496,10 +496,10 @@ public class InCellLists {
      * complex list structures descending through two, three or even more
      * levels.
      */
-    public final class MultiLevelListItem {
+    public static final class MultiLevelListItem {
 
-        private String itemText;
-        private List<String> lowerLevelItems;
+        private final String itemText;
+        private final List<String> lowerLevelItems;
 
         /**
          * Create a new instance of the MultiLevelListItem class using the

Modified: poi/trunk/poi-examples/src/main/java/org/apache/poi/examples/ss/ToCSV.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-examples/src/main/java/org/apache/poi/examples/ss/ToCSV.java?rev=1890090&r1=1890089&r2=1890090&view=diff
==============================================================================
--- poi/trunk/poi-examples/src/main/java/org/apache/poi/examples/ss/ToCSV.java (original)
+++ poi/trunk/poi-examples/src/main/java/org/apache/poi/examples/ss/ToCSV.java Fri May 21 22:32:09 2021
@@ -28,6 +28,8 @@ import java.nio.charset.StandardCharsets
 import java.nio.file.Files;
 import java.util.ArrayList;
 
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.usermodel.DataFormatter;
@@ -132,6 +134,7 @@ import org.apache.poi.ss.usermodel.Workb
  */
 @SuppressWarnings({"java:S106","java:S4823","java:S1192"})
 public class ToCSV {
+    private static final Logger LOG = LogManager.getLogger(ToCSV.class);
 
     private Workbook workbook;
     private ArrayList<ArrayList<String>> csvData;
@@ -691,10 +694,7 @@ public class ToCSV {
         // program. It should however, ideally be replaced with one or more
         // catch clauses optimised to handle more specific problems.
         catch(Exception ex) {
-            System.out.println("Caught an: " + ex.getClass().getName());
-            System.out.println("Message: " + ex.getMessage());
-            System.out.println("Stacktrace follows:.....");
-            ex.printStackTrace(System.out);
+            LOG.atWarn().withThrowable(ex).log("Unexpected exception");
             converted = false;
         }
 

Modified: poi/trunk/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java?rev=1890090&r1=1890089&r2=1890090&view=diff
==============================================================================
--- poi/trunk/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java (original)
+++ poi/trunk/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java Fri May 21 22:32:09 2021
@@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Asse
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
 import java.nio.charset.StandardCharsets;
 
 import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
@@ -37,11 +38,11 @@ public class TestXLSX2CSV {
 	private final UnsynchronizedByteArrayOutputStream errorBytes = new UnsynchronizedByteArrayOutputStream();
 
 	@BeforeEach
-	public void setUp() {
+	public void setUp() throws UnsupportedEncodingException {
 		// remember and replace default error streams
 		err = System.err;
 
-		PrintStream error = new PrintStream(errorBytes);
+		PrintStream error = new PrintStream(errorBytes, true, "UTF-8");
 		System.setErr(error);
 	}
 
@@ -77,7 +78,7 @@ public class TestXLSX2CSV {
 	@Test
 	public void testSampleFile() throws Exception {
 		final UnsynchronizedByteArrayOutputStream outputBytes = new UnsynchronizedByteArrayOutputStream();
-		PrintStream out = new PrintStream(outputBytes);
+		PrintStream out = new PrintStream(outputBytes, true, "UTF-8");
 
 		// The package open is instantaneous, as it should be.
 		try (OPCPackage p = OPCPackage.open(XSSFTestDataSamples.getSampleFile("sample.xlsx").getAbsolutePath(), PackageAccess.READ)) {
@@ -96,7 +97,7 @@ public class TestXLSX2CSV {
 	@Test
 	public void testMinColumns() throws Exception {
 		final UnsynchronizedByteArrayOutputStream outputBytes = new UnsynchronizedByteArrayOutputStream();
-		PrintStream out = new PrintStream(outputBytes);
+		PrintStream out = new PrintStream(outputBytes, true, "UTF-8");
 
 		// The package open is instantaneous, as it should be.
 		try (OPCPackage p = OPCPackage.open(XSSFTestDataSamples.getSampleFile("sample.xlsx").getAbsolutePath(), PackageAccess.READ)) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org