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"
}
}
apply plugin: 'jacoco'
apply plugin: 'maven-publish'
apply plugin: 'signing'
-
+ apply plugin: 'de.thetaphi.forbiddenapis'
version = '5.0.1-SNAPSHOT'
ext {
}
}
+ 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
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;
*/
@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.
* @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);
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");
}
}
* 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
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;
*/
@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;
// 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;
}
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;
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);
}
@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)) {
@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)) {