diff --git a/build.xml b/build.xml
index d15b45b74b..207acc4c68 100644
--- a/build.xml
+++ b/build.xml
@@ -42,7 +42,7 @@ under the License.
The Apache POI project Ant build.
-
+
@@ -81,7 +81,7 @@ under the License.
user.language and user.country are required as we have locale-sensitive formatters
-->
-
+
@@ -130,8 +130,12 @@ under the License.
-
-
+
+
+
+
+
+
@@ -331,8 +335,11 @@ under the License.
-
-
+
+
+
+
+
@@ -397,7 +404,8 @@ under the License.
-
+
+
@@ -1015,8 +1023,6 @@ under the License.
compile-scratchpad, compile-examples, compile-excelant"
description="Compiles the POI main classes, scratchpad and examples"/>
-
-
+
@@ -1297,6 +1304,7 @@ under the License.
+
-
@@ -1385,9 +1393,7 @@ under the License.
-
+
@@ -1564,6 +1570,7 @@ under the License.
+
@@ -1598,6 +1605,7 @@ under the License.
+
@@ -1620,7 +1628,7 @@ under the License.
-
@@ -1638,7 +1646,7 @@ under the License.
-
@@ -1650,6 +1658,7 @@ under the License.
+
@@ -1677,57 +1686,28 @@ under the License.
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
+
+
-
-
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1736,6 +1716,15 @@ under the License.
+
+
+
+
+
+
+
+
+
@@ -1953,14 +1942,15 @@ under the License.
-
+
-
+
+
@@ -1971,33 +1961,39 @@ under the License.
+
+
+
+
+
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
+
@@ -2112,6 +2108,7 @@ under the License.
lib/**,
bin/**,
out/**,
+ tmp/**,
sonar/**/target/**,
sonar/*/src/**,
compile-lib/**,
@@ -2167,14 +2164,12 @@ under the License.
-
-
-
diff --git a/jenkins/create_jobs.groovy b/jenkins/create_jobs.groovy
index 6e683bfb83..60795db960 100644
--- a/jenkins/create_jobs.groovy
+++ b/jenkins/create_jobs.groovy
@@ -114,7 +114,8 @@ def defaultTrigger = 'H/15 * * * *' // check SCM every 60/15 = 4 minutes
def defaultEmail = 'dev@poi.apache.org'
def defaultAnt = 'Ant 1.9.9'
// currently a lot of H?? slaves don't have Ant installed ... H21 seems to have a SVN problem
-def defaultSlaves = '(ubuntu||beam)&&!cloud-slave&&!H15&&!H17&&!H18&&!H24&&!ubuntu-4&&!H21'
+// H35 fails with ImageIO create cache file errors, although the java.io.tmpdir is writable
+def defaultSlaves = '(ubuntu||beam)&&!cloud-slave&&!H15&&!H17&&!H18&&!H24&&!ubuntu-4&&!H21&&!H35'
def jdkMapping = [
'1.6': 'JDK 1.6 (latest)',
@@ -376,7 +377,7 @@ poijobs.each { poijob ->
}
} else if (poijob.noScratchpad) {
ant {
- targets(['clean', 'compile-all'] + (poijob.properties ?: []))
+ targets(['clean', 'compile'] + (poijob.properties ?: []))
prop('coverage.enabled', true)
antInstallation(antRT)
}
@@ -529,20 +530,18 @@ on that machine correctly.
*/
matrixJob('POI-DSL-Test-Environment') {
description(
- '''
-Check installed version of Java/Ant on all build-nodes
+'''Check installed version of Java/Ant on all build-nodes
This job is used to verify which machines actually have the required programs installed.
-Unfortunately we often see builds break because of changes/new machines...'''
- )
+Unfortunately we often see builds break because of changes/new machines...''')
/*throttleConcurrentBuilds {
maxPerNode(1)
maxTotal(1)
}*/
logRotator {
- numToKeep(5)
+ numToKeep(1)
artifactNumToKeep(1)
}
axes {
@@ -559,37 +558,54 @@ Unfortunately we often see builds break because of changes/new machines...'''
'JDK 11 b23 (early access build) (Windows Only)',
'JDK 12 (latest)',
- 'JDK 12 b8 (early access build) (Windows Only)'
- )
- label('Nodes',
- 'arm1',
- 'beam1','beam2','beam3','beam4','beam5','beam6','beam7','beam8','beam9',
- 'beam10','beam11','beam12','beam13','beam14','beam15','beam16',
- 'H0','H1','H10','H11','H12','H13','H14','H15','H16','H17','H18','H19',
- 'H2','H20','H21','H22','H23','H24','H25','H26','H27','H28','H29',
- 'H3','H30','H31','H32','H33','H34','H35',
- 'H4','H5','H6','H7','H8','H9',
- 'ubuntu-1','ubuntu-2','ubuntu-4','ubuntu-6','ubuntu-eu2','ubuntu-eu3','ubuntu-ppc64le','ubuntu-us1',
- 'windows-2012-1','windows-2012-2','windows-2012-3','windows-2016-1','windows-2016-2','windows-2016-3'
+ 'OpenJDK 12 b18 (early access build)'
)
+ elasticAxis {
+ name('Nodes')
+ labelString('!cloud-slave&&!H15&&!H17&&!H18&&!H24&&!ubuntu-4&&!H21&&!H35&&!websites1&&!couchdb&&!plc4x&&!ppc64le')
+ ignoreOffline(true)
+ }
}
steps {
- /*if (poijob.windows) {
- context.batchFile(cmd)
- } else {*/
- shell('''
-which javac
+ conditionalSteps {
+ condition {
+ fileExists('/usr', BaseDir.WORKSPACE)
+ runner('DontRun')
+ steps {
+ shell(
+'''which javac
javac -version
echo 'Using Ant: ${ant.version} from ${ant.home}' > build.xml
''')
- //}
- ant {
- antInstallation(defaultAnt)
- }
- }
+ ant {
+ antInstallation(defaultAnt)
+ }
- publishers {
- mailer('centic@poi.apache.org' /* defaultEmail */, false, false)
+ }
+ }
+ }
+ conditionalSteps {
+ condition {
+ fileExists('c:\\windows', BaseDir.WORKSPACE)
+ runner('DontRun')
+ steps {
+ batchFile {
+ command(
+'''@echo off
+echo .
+where javac.exe
+echo .
+javac -version
+echo .
+echo ^^^^Using Ant: ${ant.version} from ${ant.home}^^^ > build.xml
+''')
+ }
+ ant {
+ antInstallation(defaultAnt + ' (Windows)')
+ }
+ }
+ }
+ }
}
}
diff --git a/sonar/examples/pom.xml b/sonar/examples/pom.xml
index 441dfad7a9..22c576a20d 100644
--- a/sonar/examples/pom.xml
+++ b/sonar/examples/pom.xml
@@ -6,7 +6,7 @@
org.apache.poi
poi-parent
- 4.0.1-SNAPSHOT
+ 4.0.2-SNAPSHOT
poi-examples
jar
diff --git a/sonar/excelant/pom.xml b/sonar/excelant/pom.xml
index b9814037f3..220d4eb1e9 100644
--- a/sonar/excelant/pom.xml
+++ b/sonar/excelant/pom.xml
@@ -6,7 +6,7 @@
org.apache.poi
poi-parent
- 4.0.1-SNAPSHOT
+ 4.0.2-SNAPSHOT
poi-excelant
jar
diff --git a/sonar/main/pom.xml b/sonar/main/pom.xml
index d188c14f56..9bd0af96a2 100644
--- a/sonar/main/pom.xml
+++ b/sonar/main/pom.xml
@@ -6,7 +6,7 @@
org.apache.poi
poi-parent
- 4.0.1-SNAPSHOT
+ 4.0.2-SNAPSHOT
poi-main
jar
@@ -103,7 +103,7 @@
maven-surefire-plugin
${maven.plugin.surefire.version}
- @{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=target/tmp -XX:-OmitStackTraceInFastThrow
+ @{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=${basedir}/target/tmp -XX:-OmitStackTraceInFastThrow
diff --git a/sonar/ooxml-schema-encryption/pom.xml b/sonar/ooxml-schema-encryption/pom.xml
index 5b2489a7be..d768a5f4b3 100644
--- a/sonar/ooxml-schema-encryption/pom.xml
+++ b/sonar/ooxml-schema-encryption/pom.xml
@@ -6,7 +6,7 @@
org.apache.poi
poi-parent
- 4.0.1-SNAPSHOT
+ 4.0.2-SNAPSHOT
..
poi-ooxml-schema-encryption
diff --git a/sonar/ooxml-schema-security/pom.xml b/sonar/ooxml-schema-security/pom.xml
index d872d9b59a..06318b2be9 100644
--- a/sonar/ooxml-schema-security/pom.xml
+++ b/sonar/ooxml-schema-security/pom.xml
@@ -6,7 +6,7 @@
org.apache.poi
poi-parent
- 4.0.1-SNAPSHOT
+ 4.0.2-SNAPSHOT
..
poi-ooxml-schema-security
diff --git a/sonar/ooxml-schema/pom.xml b/sonar/ooxml-schema/pom.xml
index 92c2e264af..7bb69433da 100644
--- a/sonar/ooxml-schema/pom.xml
+++ b/sonar/ooxml-schema/pom.xml
@@ -6,7 +6,7 @@
org.apache.poi
poi-parent
- 4.0.1-SNAPSHOT
+ 4.0.2-SNAPSHOT
..
poi-ooxml-schema
diff --git a/sonar/ooxml/pom.xml b/sonar/ooxml/pom.xml
index c61f42ecde..dc4ffc8373 100644
--- a/sonar/ooxml/pom.xml
+++ b/sonar/ooxml/pom.xml
@@ -6,7 +6,7 @@
org.apache.poi
poi-parent
- 4.0.1-SNAPSHOT
+ 4.0.2-SNAPSHOT
poi-ooxml
jar
@@ -93,7 +93,7 @@
maven-surefire-plugin
${maven.plugin.surefire.version}
- @{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=target/tmp -XX:-OmitStackTraceInFastThrow
+ @{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=${basedir}/target/tmp -XX:-OmitStackTraceInFastThrow
diff --git a/sonar/pom.xml b/sonar/pom.xml
index 0316403a05..3fcaf93e5d 100644
--- a/sonar/pom.xml
+++ b/sonar/pom.xml
@@ -4,7 +4,7 @@
org.apache.poi
poi-parent
pom
- 4.0.1-SNAPSHOT
+ 4.0.2-SNAPSHOT
Apache POI - the Java API for Microsoft Documents
Maven build of Apache POI for Sonar checks
http://poi.apache.org/
@@ -117,7 +117,7 @@
org.apache.poi.util.NullLogger
- @{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=target/tmp
+ @{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=${basedir}/target/tmp
**/All*Tests.java
diff --git a/sonar/scratchpad/pom.xml b/sonar/scratchpad/pom.xml
index e7ef7303a4..a980e15568 100644
--- a/sonar/scratchpad/pom.xml
+++ b/sonar/scratchpad/pom.xml
@@ -6,7 +6,7 @@
org.apache.poi
poi-parent
- 4.0.1-SNAPSHOT
+ 4.0.2-SNAPSHOT
poi-scratchpad
jar
diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateTable.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateTable.java
index c2fc068afe..ad2b6adcdd 100644
--- a/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateTable.java
+++ b/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateTable.java
@@ -19,7 +19,6 @@ package org.apache.poi.xssf.usermodel.examples;
import java.io.FileOutputStream;
import java.io.IOException;
-import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.usermodel.XSSFCell;
@@ -36,8 +35,8 @@ public class CreateTable {
public static void main(String[] args) throws IOException {
- try (Workbook wb = new XSSFWorkbook()) {
- XSSFSheet sheet = (XSSFSheet) wb.createSheet();
+ try (XSSFWorkbook wb = new XSSFWorkbook()) {
+ XSSFSheet sheet = wb.createSheet();
// Set which area the table should be placed in
AreaReference reference = wb.getCreationHelper().createAreaReference(
@@ -78,10 +77,6 @@ public class CreateTable {
}
}
}
- // Create the columns
- table.createColumn("Column 1");
- table.createColumn("Column 2");
- table.createColumn("Column 3");
// Save
try (FileOutputStream fileOut = new FileOutputStream("ooxml-table.xlsx")) {
diff --git a/src/integrationtest/build.xml b/src/integrationtest/build.xml
index 26bd57e108..a228a22374 100644
--- a/src/integrationtest/build.xml
+++ b/src/integrationtest/build.xml
@@ -82,7 +82,9 @@ Before running this, you should execute the "assemble" target in the main build.
-
+
+
+
diff --git a/src/integrationtest/org/apache/poi/BaseIntegrationTest.java b/src/integrationtest/org/apache/poi/BaseIntegrationTest.java
index 291618f680..304794b231 100644
--- a/src/integrationtest/org/apache/poi/BaseIntegrationTest.java
+++ b/src/integrationtest/org/apache/poi/BaseIntegrationTest.java
@@ -16,17 +16,24 @@
==================================================================== */
package org.apache.poi;
-import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;
-import org.apache.poi.hssf.OldExcelFormatException;
-import org.apache.poi.hwpf.OldWordFileFormatException;
-import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
-import org.apache.poi.stress.*;
-import org.junit.Assume;
+import static org.junit.Assert.assertNotNull;
-import java.io.*;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.zip.ZipException;
-import static org.junit.Assert.assertNotNull;
+import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
+import org.apache.poi.stress.FileHandler;
+import org.apache.poi.stress.HSLFFileHandler;
+import org.apache.poi.stress.HSSFFileHandler;
+import org.apache.poi.stress.HWPFFileHandler;
+import org.apache.poi.stress.XSLFFileHandler;
+import org.apache.poi.stress.XSSFFileHandler;
+import org.apache.poi.stress.XWPFFileHandler;
+import org.junit.Assume;
public class BaseIntegrationTest {
private final File rootDir;
@@ -53,12 +60,13 @@ public class BaseIntegrationTest {
// use XWPF instead of HWPF and XSSF instead of HSSF as the file seems to have the wrong extension
handleWrongExtension(inputFile, e);
- } catch (OldWordFileFormatException | OldExcelFormatException | OldPowerPointFormatException e) {
- // at least perform extracting tests on these old files
} catch (OldFileFormatException e) {
- // Not even text extraction is supported for these: handler.handleExtracting(inputFile);
- //noinspection ConstantConditions
- Assume.assumeFalse("File " + file + " excluded because it is unsupported old Excel format", true);
+ if (e.getClass().equals(OldFileFormatException.class)) {
+ // Not even text extraction is supported for these: handler.handleExtracting(inputFile);
+ //noinspection ConstantConditions
+ Assume.assumeFalse("File " + file + " excluded because it is unsupported old Excel format", true);
+ }
+ // otherwise try at least to perform extracting tests on these old files
} catch (EncryptedDocumentException e) {
// Do not try to read encrypted files
//noinspection ConstantConditions
diff --git a/src/integrationtest/org/apache/poi/TestAllFiles.java b/src/integrationtest/org/apache/poi/TestAllFiles.java
index 7d4495d87c..61c47b9e88 100644
--- a/src/integrationtest/org/apache/poi/TestAllFiles.java
+++ b/src/integrationtest/org/apache/poi/TestAllFiles.java
@@ -90,6 +90,7 @@ import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class TestAllFiles {
private static final File ROOT_DIR = new File("test-data");
+ private static final boolean IGNORE_SCRATCHPAD = Boolean.getBoolean("scratchpad.ignore");
public static final String[] SCAN_EXCLUDES = new String[] { "**/.svn/**", "lost+found", "**/.git/**" };
@@ -98,6 +99,7 @@ public class TestAllFiles {
// map file extensions to the actual mappers
public static final Map HANDLERS = new HashMap<>();
+
static {
// Excel
HANDLERS.put(".xls", new HSSFFileHandler());
@@ -107,17 +109,17 @@ public class TestAllFiles {
HANDLERS.put(".xlsb", new XSSFBFileHandler());
// Word
- HANDLERS.put(".doc", new HWPFFileHandler());
+ HANDLERS.put(".doc", IGNORE_SCRATCHPAD ? new HPSFFileHandler() : new HWPFFileHandler());
HANDLERS.put(".docx", new XWPFFileHandler());
HANDLERS.put(".dotx", new XWPFFileHandler());
HANDLERS.put(".docm", new XWPFFileHandler());
// OpenXML4J files
- HANDLERS.put(".ooxml", new OPCFileHandler()); // OPCPackage
- HANDLERS.put(".zip", new OPCFileHandler()); // OPCPackage
+ HANDLERS.put(".ooxml", new OPCFileHandler());
+ HANDLERS.put(".zip", new OPCFileHandler());
// Powerpoint
- HANDLERS.put(".ppt", new HSLFFileHandler());
+ HANDLERS.put(".ppt", IGNORE_SCRATCHPAD ? new HPSFFileHandler() : new HSLFFileHandler());
HANDLERS.put(".pptx", new XSLFFileHandler());
HANDLERS.put(".pptm", new XSLFFileHandler());
HANDLERS.put(".ppsm", new XSLFFileHandler());
@@ -126,13 +128,13 @@ public class TestAllFiles {
HANDLERS.put(".potx", new XSLFFileHandler());
// Outlook
- HANDLERS.put(".msg", new HSMFFileHandler());
+ HANDLERS.put(".msg", IGNORE_SCRATCHPAD ? new HPSFFileHandler() : new HSMFFileHandler());
// Publisher
- HANDLERS.put(".pub", new HPBFFileHandler());
+ HANDLERS.put(".pub", IGNORE_SCRATCHPAD ? new HPSFFileHandler() : new HPBFFileHandler());
// Visio - binary
- HANDLERS.put(".vsd", new HDGFFileHandler());
+ HANDLERS.put(".vsd", IGNORE_SCRATCHPAD ? new HPSFFileHandler() : new HDGFFileHandler());
// Visio - ooxml
HANDLERS.put(".vsdm", new XDGFFileHandler());
@@ -153,7 +155,7 @@ public class TestAllFiles {
HANDLERS.put(".adm", new HPSFFileHandler());
// Microsoft TNEF
- HANDLERS.put(".dat", new HMEFFileHandler());
+ HANDLERS.put(".dat", IGNORE_SCRATCHPAD ? new HPSFFileHandler() : new HMEFFileHandler());
// TODO: are these readable by some of the formats?
HANDLERS.put(".wri", new NullFileHandler());
@@ -300,7 +302,7 @@ public class TestAllFiles {
"spreadsheet/54764-2.xlsx", // see TestXSSFBugs.bug54764()
"spreadsheet/54764.xlsx", // see TestXSSFBugs.bug54764()
"poifs/unknown_properties.msg", // POIFS properties corrupted
- "poifs/only-zero-byte-streams.ole2", // No actual contents
+ (IGNORE_SCRATCHPAD ? "" : "poifs/only-zero-byte-streams.ole2"), // No actual contents
"spreadsheet/poc-xmlbomb.xlsx", // contains xml-entity-expansion
"spreadsheet/poc-xmlbomb-empty.xlsx", // contains xml-entity-expansion
"spreadsheet/poc-shared-strings.xlsx", // contains shared-string-entity-expansion
@@ -438,8 +440,17 @@ public class TestAllFiles {
}
}
- // let some file handlers do additional stuff
- handler.handleAdditional(inputFile);
+ try {
+ // let some file handlers do additional stuff
+ handler.handleAdditional(inputFile);
+ } catch (AssumptionViolatedException e) {
+ // file handler ignored this file
+ } catch (Exception e) {
+ if(!EXPECTED_FAILURES.contains(file) && !AbstractFileHandler.EXPECTED_EXTRACTOR_FAILURES.contains(file)) {
+ System.out.println("Failed: " + file);
+ throw new Exception("While handling " + file, e);
+ }
+ }
}
public static String getExtension(String file) {
diff --git a/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java b/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java
index 480a7faf61..7f9c22ff41 100644
--- a/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java
+++ b/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java
@@ -79,26 +79,26 @@ public abstract class AbstractFileHandler implements FileHandler {
long modified = file.lastModified();
POITextExtractor extractor = null;
- try {
+ try {
extractor = ExtractorFactory.createExtractor(file);
assertNotNull("Should get a POITextExtractor but had none for file " + file, extractor);
assertNotNull("Should get some text but had none for file " + file, extractor.getText());
-
+
// also try metadata
@SuppressWarnings("resource")
POITextExtractor metadataExtractor = extractor.getMetadataTextExtractor();
assertNotNull(metadataExtractor.getText());
- assertFalse("Expected Extraction to fail for file " + file + " and handler " + this + ", but did not fail!",
+ assertFalse("Expected Extraction to fail for file " + file + " and handler " + this + ", but did not fail!",
EXPECTED_EXTRACTOR_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName()));
-
+
assertEquals("File should not be modified by extractor", length, file.length());
assertEquals("File should not be modified by extractor", modified, file.lastModified());
-
+
handleExtractingAsStream(file);
-
- if(extractor instanceof POIOLE2TextExtractor) {
+
+ if (extractor instanceof POIOLE2TextExtractor) {
try (HPSFPropertiesExtractor hpsfExtractor = new HPSFPropertiesExtractor((POIOLE2TextExtractor) extractor)) {
assertNotNull(hpsfExtractor.getDocumentSummaryInformationText());
assertNotNull(hpsfExtractor.getSummaryInformationText());
@@ -115,6 +115,10 @@ public abstract class AbstractFileHandler implements FileHandler {
String msg = "org.apache.poi.EncryptedDocumentException: Export Restrictions in place - please install JCE Unlimited Strength Jurisdiction Policy files";
assumeFalse(msg.equals(e.getMessage()));
throw e;
+ } catch (IllegalStateException e) {
+ if (!e.getMessage().contains("POI Scratchpad jar missing") || !Boolean.getBoolean("scratchpad.ignore")) {
+ throw e;
+ }
} finally {
IOUtils.closeQuietly(extractor);
}
diff --git a/src/java/org/apache/poi/hssf/eventusermodel/MissingRecordAwareHSSFListener.java b/src/java/org/apache/poi/hssf/eventusermodel/MissingRecordAwareHSSFListener.java
index ea9b70d88d..f154a1f86c 100644
--- a/src/java/org/apache/poi/hssf/eventusermodel/MissingRecordAwareHSSFListener.java
+++ b/src/java/org/apache/poi/hssf/eventusermodel/MissingRecordAwareHSSFListener.java
@@ -94,8 +94,6 @@ public final class MissingRecordAwareHSSFListener implements HSSFListener {
break;
case RowRecord.sid:
RowRecord rowrec = (RowRecord) record;
- //System.out.println("Row " + rowrec.getRowNumber() + " found, first column at "
- // + rowrec.getFirstCol() + " last column at " + rowrec.getLastCol());
// If there's a jump in rows, fire off missing row records
if (lastRowRow + 1 < rowrec.getRowNumber()) {
diff --git a/src/java/org/apache/poi/hssf/record/UnknownRecord.java b/src/java/org/apache/poi/hssf/record/UnknownRecord.java
index 189b582472..ef324a681f 100644
--- a/src/java/org/apache/poi/hssf/record/UnknownRecord.java
+++ b/src/java/org/apache/poi/hssf/record/UnknownRecord.java
@@ -80,13 +80,10 @@ public final class UnknownRecord extends StandardRecord {
public UnknownRecord(RecordInputStream in) {
_sid = in.getSid();
_rawData = in.readRemainder();
-// if (false && getBiffName(_sid) == null) {
-// // unknown sids in the range 0x0004-0x0013 are probably 'sub-records' of ObjectRecord
-// // those sids are in a different number space.
-// // TODO - put unknown OBJ sub-records in a different class
-// System.out.println("Unknown record 0x" +
-// Integer.toHexString(_sid).toUpperCase(Locale.ROOT));
-// }
+
+ // TODO - put unknown OBJ sub-records in a different class
+ // unknown sids in the range 0x0004-0x0013 are probably 'sub-records' of ObjectRecord
+ // those sids are in a different number space.
}
/**
diff --git a/src/java/org/apache/poi/ss/format/CellFormatPart.java b/src/java/org/apache/poi/ss/format/CellFormatPart.java
index 2651edd8c6..e56aa3d867 100644
--- a/src/java/org/apache/poi/ss/format/CellFormatPart.java
+++ b/src/java/org/apache/poi/ss/format/CellFormatPart.java
@@ -54,26 +54,22 @@ public class CellFormatPart {
private final CellFormatter format;
private final CellFormatType type;
- private static final Map NAMED_COLORS;
+ static final Map NAMED_COLORS;
static {
NAMED_COLORS = new TreeMap<>(
String.CASE_INSENSITIVE_ORDER);
- Map colors = HSSFColor.getIndexHash();
- for (HSSFColor color : colors.values()) {
- Class extends HSSFColor> type = color.getClass();
- String name = type.getSimpleName();
- if (name.equals(name.toUpperCase(Locale.ROOT))) {
- short[] rgb = color.getTriplet();
- Color c = new Color(rgb[0], rgb[1], rgb[2]);
- NAMED_COLORS.put(name, c);
- if (name.indexOf('_') > 0)
- NAMED_COLORS.put(name.replace('_', ' '), c);
- if (name.indexOf("_PERCENT") > 0)
- NAMED_COLORS.put(name.replace("_PERCENT", "%").replace('_',
- ' '), c);
- }
+ for (HSSFColor.HSSFColorPredefined color : HSSFColor.HSSFColorPredefined.values()) {
+ String name = color.name();
+ short[] rgb = color.getTriplet();
+ Color c = new Color(rgb[0], rgb[1], rgb[2]);
+ NAMED_COLORS.put(name, c);
+ if (name.indexOf('_') > 0)
+ NAMED_COLORS.put(name.replace('_', ' '), c);
+ if (name.indexOf("_PERCENT") > 0)
+ NAMED_COLORS.put(name.replace("_PERCENT", "%").replace('_',
+ ' '), c);
}
}
diff --git a/src/java/org/apache/poi/ss/formula/Formula.java b/src/java/org/apache/poi/ss/formula/Formula.java
index b0a2842040..50ae3d2aea 100644
--- a/src/java/org/apache/poi/ss/formula/Formula.java
+++ b/src/java/org/apache/poi/ss/formula/Formula.java
@@ -48,19 +48,15 @@ public class Formula {
private Formula(byte[] byteEncoding, int encodedTokenLen) {
_byteEncoding = byteEncoding.clone();
_encodedTokenLen = encodedTokenLen;
-// if (false) { // set to true to eagerly check Ptg decoding
-// LittleEndianByteArrayInputStream in = new LittleEndianByteArrayInputStream(byteEncoding);
-// Ptg.readTokens(encodedTokenLen, in);
-// int nUnusedBytes = _byteEncoding.length - in.getReadIndex();
-// if (nUnusedBytes > 0) {
-// // TODO - this seems to occur when IntersectionPtg is present
-// // This example file "IntersectionPtg.xls"
-// // used by test: TestIntersectionPtg.testReading()
-// // has 10 bytes unused at the end of the formula
-// // 10 extra bytes are just 0x01 and 0x00
-// System.out.println(nUnusedBytes + " unused bytes at end of formula");
-// }
-// }
+
+ // TODO - this seems to occur when IntersectionPtg is present
+ // This example file "IntersectionPtg.xls"
+ // used by test: TestIntersectionPtg.testReading()
+ // has 10 bytes unused at the end of the formula
+ // 10 extra bytes are just 0x01 and 0x00
+ // LittleEndianByteArrayInputStream in = new LittleEndianByteArrayInputStream(byteEncoding);
+ // Ptg.readTokens(encodedTokenLen, in);
+ // int nUnusedBytes = _byteEncoding.length - in.getReadIndex();
}
/**
* Convenience method for {@link #read(int, LittleEndianInput, int)}
diff --git a/src/java/org/apache/poi/ss/formula/FormulaParser.java b/src/java/org/apache/poi/ss/formula/FormulaParser.java
index 3b82daad91..bd0c9995bf 100644
--- a/src/java/org/apache/poi/ss/formula/FormulaParser.java
+++ b/src/java/org/apache/poi/ss/formula/FormulaParser.java
@@ -234,7 +234,6 @@ public final class FormulaParser {
_inIntersection = false;
}
_pointer += Character.charCount(look);
- //System.out.println(new StringBuilder("Got char: ").appendCodePoint(look)).toString();
}
private void resetPointer(int ptr) {
_pointer = ptr;
diff --git a/src/java/org/apache/poi/ss/formula/eval/OperandResolver.java b/src/java/org/apache/poi/ss/formula/eval/OperandResolver.java
index 7258b98c25..26de08c534 100644
--- a/src/java/org/apache/poi/ss/formula/eval/OperandResolver.java
+++ b/src/java/org/apache/poi/ss/formula/eval/OperandResolver.java
@@ -88,8 +88,7 @@ public final class OperandResolver {
CellRangeAddress range = cell.getArrayFormulaRange();
int relativeRowIndex = cell.getRowIndex() - range.getFirstRow();
int relativeColIndex = cell.getColumnIndex() - range.getFirstColumn();
- //System.out.println("Row: " + relativeRowIndex + " Col: " + relativeColIndex);
-
+
if (ae.isColumn()) {
if (ae.isRow()) {
return ae.getRelativeValue(0, 0);
diff --git a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
index e1e5b7a2c1..b805d0cc85 100644
--- a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
+++ b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
@@ -450,7 +450,6 @@ public class DataFormatter implements Observer {
// Strip custom text in quotes and escaped characters for now as it can cause performance problems in fractions.
//String strippedFormatStr = formatStr.replaceAll("\\\\ ", " ").replaceAll("\\\\.", "").replaceAll("\"[^\"]*\"", " ").replaceAll("\\?", "#");
- //System.out.println("formatStr: "+strippedFormatStr);
return new FractionFormat(defaultFractionWholePartFormat, defaultFractionFractionPartFormat);
}
diff --git a/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java b/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java
index f49929e212..412cacfeac 100644
--- a/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java
+++ b/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java
@@ -16,24 +16,20 @@
==================================================================== */
package org.apache.poi.ooxml.extractor;
-import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import org.apache.poi.EncryptedDocumentException;
+import org.apache.poi.extractor.OLE2ExtractorFactory;
import org.apache.poi.extractor.POIOLE2TextExtractor;
import org.apache.poi.extractor.POITextExtractor;
-import org.apache.poi.extractor.OLE2ExtractorFactory;
-import org.apache.poi.hsmf.MAPIMessage;
-import org.apache.poi.hsmf.datatypes.AttachmentChunks;
-import org.apache.poi.hsmf.extractor.OutlookTextExtactor;
import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
-import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
@@ -46,9 +42,9 @@ import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.Entry;
import org.apache.poi.poifs.filesystem.FileMagic;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.NotOLE2FileException;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.sl.extractor.SlideShowExtractor;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.NotImplemented;
@@ -311,6 +307,7 @@ public final class ExtractorFactory {
throw new IllegalStateException("The extractor didn't know which POIFS it came from!");
}
+ // provide ExcelExtractor also in OOXML module, because scratchpad is not necessary for it
if (ext instanceof ExcelExtractor) {
// These are in MBD... under the root
Iterator it = root.getEntries();
@@ -320,34 +317,14 @@ public final class ExtractorFactory {
dirs.add(entry);
}
}
- } else if (ext instanceof WordExtractor) {
- // These are in ObjectPool -> _... under the root
+ } else {
try {
- DirectoryEntry op = (DirectoryEntry) root.getEntry("ObjectPool");
- Iterator it = op.getEntries();
- while (it.hasNext()) {
- Entry entry = it.next();
- if (entry.getName().startsWith("_")) {
- dirs.add(entry);
- }
- }
- } catch (FileNotFoundException e) {
- logger.log(POILogger.INFO, "Ignoring FileNotFoundException while extracting Word document", e.getLocalizedMessage());
- // ignored here
- }
- //} else if(ext instanceof PowerPointExtractor) {
- // Tricky, not stored directly in poifs
- // TODO
- } else if (ext instanceof OutlookTextExtactor) {
- // Stored in the Attachment blocks
- MAPIMessage msg = ((OutlookTextExtactor)ext).getMAPIMessage();
- for (AttachmentChunks attachment : msg.getAttachmentFiles()) {
- if (attachment.getAttachData() != null) {
- byte[] data = attachment.getAttachData().getValue();
- nonPOIFS.add( new ByteArrayInputStream(data) );
- } else if (attachment.getAttachmentDirectory() != null) {
- dirs.add(attachment.getAttachmentDirectory().getDirectory());
- }
+ Class> clazz = Class.forName("org.apache.poi.extractor.ole2.OLE2ScratchpadExtractorFactory");
+ Method m = clazz.getDeclaredMethod("identifyEmbeddedResources", POIOLE2TextExtractor.class, List.class, List.class);
+ m.invoke(null, ext, dirs, nonPOIFS);
+ } catch (ReflectiveOperationException e) {
+ logger.log(POILogger.WARN, "POI Scratchpad jar not included ", e.getLocalizedMessage());
+ return new POITextExtractor[0];
}
}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
index 97b4ab8cb0..9f07b18bac 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
@@ -170,16 +170,24 @@ public class XSLFPictureShape extends XSLFSimpleShape
@SuppressWarnings("WeakerAccess")
protected String getBlipLink(){
- String link = getBlip().getLink();
- if (link.isEmpty()) return null;
- return link;
+ CTBlip blip = getBlip();
+ if (blip != null) {
+ String link = blip.getLink();
+ return (link.isEmpty()) ? null : link;
+ } else {
+ return null;
+ }
}
@SuppressWarnings("WeakerAccess")
protected String getBlipId(){
- String id = getBlip().getEmbed();
- if (id.isEmpty()) return null;
- return id;
+ CTBlip blip = getBlip();
+ if (blip != null) {
+ String id = blip.getEmbed();
+ return (id.isEmpty()) ? null : id;
+ } else {
+ return null;
+ }
}
@Override
diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
index 6fbcb14035..ed52e0e16b 100644
--- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
@@ -381,7 +381,10 @@ public class SXSSFWorkbook implements Workbook {
Enumeration extends ZipArchiveEntry> en = zipEntrySource.getEntries();
while (en.hasMoreElements()) {
ZipArchiveEntry ze = en.nextElement();
- zos.putArchiveEntry(new ZipArchiveEntry(ze.getName()));
+ ZipArchiveEntry zeOut = new ZipArchiveEntry(ze.getName());
+ zeOut.setSize(ze.getSize());
+ zeOut.setTime(ze.getTime());
+ zos.putArchiveEntry(zeOut);
try (final InputStream is = zipEntrySource.getInputStream(ze)) {
if (is instanceof ZipArchiveThresholdInputStream) {
// #59743 - disable Threshold handling for SXSSF copy
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java
index ae206f3c34..be632b3c46 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java
@@ -47,7 +47,7 @@ public class XSSFColor extends ExtendedColor {
* @deprecated 3.17 beta 1 - pass the workbook styles indexed color map, if any
*/
@Deprecated
- @Removal(version="3.19")
+ @Removal(version="4.2")
public XSSFColor(CTColor color) {
this(color, new DefaultIndexedColorMap());
}
@@ -59,6 +59,7 @@ public class XSSFColor extends ExtendedColor {
* @deprecated 4.0.0 - use the factory {@link #from(CTColor, IndexedColorMap)} method instead to check for null CTColor instances. Make private eventually
*/
@Deprecated
+ @Removal(version = "4.2")
public XSSFColor(CTColor color, IndexedColorMap map) {
this.ctColor = color;
this.indexedColorMap = map;
@@ -72,7 +73,7 @@ public class XSSFColor extends ExtendedColor {
* @see #from(CTColor, IndexedColorMap)
*/
@Deprecated
- @Removal(version="4.1")
+ @Removal(version="4.2")
public XSSFColor() {
this(CTColor.Factory.newInstance(), new DefaultIndexedColorMap());
}
@@ -84,7 +85,18 @@ public class XSSFColor extends ExtendedColor {
public XSSFColor(IndexedColorMap colorMap) {
this(CTColor.Factory.newInstance(), colorMap);
}
-
+
+ /**
+ * Create an instance of XSSFColor from the awt Color
+ * @param clr awt Color
+ * @deprecated 3.17 beta 1 - pass the workbook styles indexed color map, if any
+ */
+ @Deprecated
+ @Removal(version="4.2")
+ public XSSFColor(java.awt.Color clr) {
+ this(clr, new DefaultIndexedColorMap());
+ }
+
/**
* TEST ONLY
* @param clr awt Color
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
index d776f8fc00..bbd7eda838 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
@@ -4109,18 +4109,17 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
int tableNumber = getPackagePart().getPackage().getPartsByContentType(XSSFRelation.TABLE.getContentType()).size() + 1;
// the id could already be taken after insertion/deletion of different tables
- outerloop:
- while(true) {
+ boolean loop = true;
+ while(loop) {
+ loop = false;
for (PackagePart packagePart : getPackagePart().getPackage().getPartsByContentType(XSSFRelation.TABLE.getContentType())) {
String fileName = XSSFRelation.TABLE.getFileName(tableNumber);
if(fileName.equals(packagePart.getPartName().getName())) {
// duplicate found, increase the number and start iterating again
tableNumber++;
- continue outerloop;
+ loop = true;
}
}
-
- break;
}
RelationPart rp = createRelationship(XSSFRelation.TABLE, XSSFFactory.getInstance(), tableNumber, false);
diff --git a/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java b/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java
index 46681f71e1..196499efdc 100644
--- a/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java
+++ b/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java
@@ -33,27 +33,18 @@ import org.apache.poi.POIDataSamples;
import org.apache.poi.UnsupportedFileFormatException;
import org.apache.poi.extractor.POIOLE2TextExtractor;
import org.apache.poi.extractor.POITextExtractor;
-import org.apache.poi.hdgf.extractor.VisioTextExtractor;
-import org.apache.poi.hpbf.extractor.PublisherTextExtractor;
-import org.apache.poi.hsmf.extractor.OutlookTextExtactor;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.extractor.EventBasedExcelExtractor;
import org.apache.poi.hssf.extractor.ExcelExtractor;
-import org.apache.poi.hwpf.extractor.Word6Extractor;
-import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.ooxml.extractor.ExtractorFactory;
import org.apache.poi.ooxml.extractor.POIXMLTextExtractor;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.sl.extractor.SlideShowExtractor;
-import org.apache.poi.xdgf.extractor.XDGFVisioExtractor;
-import org.apache.poi.xssf.extractor.XSSFBEventBasedExcelExtractor;
import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
-import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.xmlbeans.XmlException;
import org.junit.Test;
@@ -108,21 +99,21 @@ public class TestExtractorFactory {
}
private static final Object[] TEST_SET = {
- "Excel", xls, ExcelExtractor.class, 200,
- "Excel - xlsx", xlsx, XSSFExcelExtractor.class, 200,
- "Excel - xltx", xltx, XSSFExcelExtractor.class, -1,
- "Excel - xlsb", xlsb, XSSFBEventBasedExcelExtractor.class, -1,
- "Word", doc, WordExtractor.class, 120,
- "Word - docx", docx, XWPFWordExtractor.class, 120,
- "Word - dotx", dotx, XWPFWordExtractor.class, -1,
- "Word 6", doc6, Word6Extractor.class, 20,
- "Word 95", doc95, Word6Extractor.class, 120,
- "PowerPoint", ppt, SlideShowExtractor.class, 120,
- "PowerPoint - pptx", pptx, SlideShowExtractor.class, 120,
- "Visio", vsd, VisioTextExtractor.class, 50,
- "Visio - vsdx", vsdx, XDGFVisioExtractor.class, 20,
- "Publisher", pub, PublisherTextExtractor.class, 50,
- "Outlook msg", msg, OutlookTextExtactor.class, 50,
+ "Excel", xls, "ExcelExtractor", 200,
+ "Excel - xlsx", xlsx, "XSSFExcelExtractor", 200,
+ "Excel - xltx", xltx, "XSSFExcelExtractor", -1,
+ "Excel - xlsb", xlsb, "XSSFBEventBasedExcelExtractor", -1,
+ "Word", doc, "WordExtractor", 120,
+ "Word - docx", docx, "XWPFWordExtractor", 120,
+ "Word - dotx", dotx, "XWPFWordExtractor", -1,
+ "Word 6", doc6, "Word6Extractor", 20,
+ "Word 95", doc95, "Word6Extractor", 120,
+ "PowerPoint", ppt, "SlideShowExtractor", 120,
+ "PowerPoint - pptx", pptx, "SlideShowExtractor", 120,
+ "Visio", vsd, "VisioTextExtractor", 50,
+ "Visio - vsdx", vsdx, "XDGFVisioExtractor", 20,
+ "Publisher", pub, "PublisherTextExtractor", 50,
+ "Outlook msg", msg, "OutlookTextExtactor", 50,
// TODO Support OOXML-Strict, see bug #57699
// xlsxStrict
@@ -138,7 +129,7 @@ public class TestExtractorFactory {
public void testFile() throws Exception {
for (int i = 0; i < TEST_SET.length; i += 4) {
try (POITextExtractor ext = ExtractorFactory.createExtractor((File) TEST_SET[i + 1])) {
- testExtractor(ext, (String) TEST_SET[i], (Class) TEST_SET[i + 2], (Integer) TEST_SET[i + 3]);
+ testExtractor(ext, (String) TEST_SET[i], (String) TEST_SET[i + 2], (Integer) TEST_SET[i + 3]);
}
}
}
@@ -180,15 +171,15 @@ public class TestExtractorFactory {
}
try (FileInputStream fis = new FileInputStream(testFile);
POITextExtractor ext = poifsIS.apply(fis)) {
- testExtractor(ext, (String) TEST_SET[i], (Class) TEST_SET[i + 2], (Integer) TEST_SET[i + 3]);
+ testExtractor(ext, (String) TEST_SET[i], (String) TEST_SET[i + 2], (Integer) TEST_SET[i + 3]);
} catch (IllegalArgumentException e) {
fail("failed to process "+testFile);
}
}
}
- private void testExtractor(final POITextExtractor ext, final String testcase, final Class extrClass, final Integer minLength) {
- assertTrue("invalid extractor for " + testcase, extrClass.isInstance(ext));
+ private void testExtractor(final POITextExtractor ext, final String testcase, final String extrClass, final Integer minLength) {
+ assertEquals("invalid extractor for " + testcase, extrClass, ext.getClass().getSimpleName());
final String actual = ext.getText();
if (minLength == -1) {
assertContains(actual.toLowerCase(Locale.ROOT), "test");
@@ -215,7 +206,7 @@ public class TestExtractorFactory {
try (final OPCPackage pkg = OPCPackage.open(testFile, PackageAccess.READ);
final POITextExtractor ext = ExtractorFactory.createExtractor(pkg)) {
- testExtractor(ext, (String) TEST_SET[i], (Class) TEST_SET[i + 2], (Integer) TEST_SET[i + 3]);
+ testExtractor(ext, (String) TEST_SET[i], (String) TEST_SET[i + 2], (Integer) TEST_SET[i + 3]);
pkg.revert();
}
}
@@ -334,16 +325,22 @@ public class TestExtractorFactory {
int numWord = 0, numXls = 0, numPpt = 0, numMsg = 0, numWordX = 0;
for (POITextExtractor embed : embeds) {
assertTrue(embed.getText().length() > 20);
- if (embed instanceof SlideShowExtractor) {
- numPpt++;
- } else if (embed instanceof ExcelExtractor) {
- numXls++;
- } else if (embed instanceof WordExtractor) {
- numWord++;
- } else if (embed instanceof OutlookTextExtactor) {
- numMsg++;
- } else if (embed instanceof XWPFWordExtractor) {
- numWordX++;
+ switch (embed.getClass().getSimpleName()) {
+ case "SlideShowExtractor":
+ numPpt++;
+ break;
+ case "ExcelExtractor":
+ numXls++;
+ break;
+ case "WordExtractor":
+ numWord++;
+ break;
+ case "OutlookTextExtactor":
+ numMsg++;
+ break;
+ case "XWPFWordExtractor":
+ numWordX++;
+ break;
}
}
diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/util/OOXMLLite.java b/src/ooxml/testcases/org/apache/poi/ooxml/util/OOXMLLite.java
deleted file mode 100644
index 450f958ae6..0000000000
--- a/src/ooxml/testcases/org/apache/poi/ooxml/util/OOXMLLite.java
+++ /dev/null
@@ -1,375 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ooxml.util;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.CodeSource;
-import java.security.PrivilegedAction;
-import java.security.ProtectionDomain;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.Vector;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import java.util.regex.Pattern;
-
-import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.StringUtil;
-import org.apache.poi.util.SuppressForbidden;
-import org.apache.xmlbeans.StringEnumAbstractBase;
-import org.junit.Test;
-import org.junit.internal.TextListener;
-import org.junit.runner.Description;
-import org.junit.runner.JUnitCore;
-import org.junit.runner.Result;
-import org.reflections.Reflections;
-
-import junit.framework.TestCase;
-
-/**
- * Build a 'lite' version of the ooxml-schemas.jar
- *
- * @author Yegor Kozlov
- */
-public final class OOXMLLite {
- private static final Pattern SCHEMA_PATTERN = Pattern.compile("schemaorg_apache_xmlbeans/(system|element)/.*\\.xsb");
-
- /**
- * Destination directory to copy filtered classes
- */
- private File _destDest;
-
- /**
- * Directory with the compiled ooxml tests
- */
- private File _testDir;
-
- /**
- * Reference to the ooxml-schemas.jar
- */
- private File _ooxmlJar;
-
-
- OOXMLLite(String dest, String test, String ooxmlJar) {
- _destDest = new File(dest);
- _testDir = new File(test);
- _ooxmlJar = new File(ooxmlJar);
- }
-
- public static void main(String[] args) throws IOException {
- System.out.println("Free memory (bytes): " +
- Runtime.getRuntime().freeMemory());
- long maxMemory = Runtime.getRuntime().maxMemory();
- System.out.println("Maximum memory (bytes): " +
- (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory));
- System.out.println("Total memory (bytes): " +
- Runtime.getRuntime().totalMemory());
-
- String dest = null, test = null, ooxml = null;
-
- for (int i = 0; i < args.length; i++) {
- switch (args[i]) {
- case "-dest":
- dest = args[++i]; // lgtm[java/index-out-of-bounds]
- break;
- case "-test":
- test = args[++i]; // lgtm[java/index-out-of-bounds]
- break;
- case "-ooxml":
- ooxml = args[++i]; // lgtm[java/index-out-of-bounds]
- break;
- }
- }
- OOXMLLite builder = new OOXMLLite(dest, test, ooxml);
- builder.build();
- }
-
- void build() throws IOException {
- List> lst = new ArrayList<>();
- //collect unit tests
- String exclude = StringUtil.join("|",
- "BaseTestXWorkbook",
- "BaseTestXSheet",
- "BaseTestXRow",
- "BaseTestXCell",
- "BaseTestXSSFPivotTable",
- "TestSXSSFWorkbook\\$\\d",
- "TestUnfixedBugs",
- "MemoryUsage",
- "TestDataProvider",
- "TestDataSamples",
- "All.+Tests",
- "ZipFileAssert",
- "AesZipFileZipEntrySource",
- "TempFileRecordingSXSSFWorkbookWithCustomZipEntrySource",
- "PkiTestUtils",
- "TestCellFormatPart\\$\\d",
- "TestSignatureInfo\\$\\d",
- "TestCertificateEncryption\\$CertData",
- "TestPOIXMLDocument\\$OPCParser",
- "TestPOIXMLDocument\\$TestFactory",
- "TestXSLFTextParagraph\\$DrawTextParagraphProxy",
- "TestXSSFExportToXML\\$\\d",
- "TestXSSFExportToXML\\$DummyEntityResolver",
- "TestFormulaEvaluatorOnXSSF\\$Result",
- "TestFormulaEvaluatorOnXSSF\\$SS",
- "TestMultiSheetFormulaEvaluatorOnXSSF\\$Result",
- "TestMultiSheetFormulaEvaluatorOnXSSF\\$SS",
- "TestXSSFBugs\\$\\d",
- "AddImageBench",
- "AddImageBench_jmhType_B\\d",
- "AddImageBench_benchCreatePicture_jmhTest",
- "TestEvilUnclosedBRFixingInputStream\\$EvilUnclosedBRFixingInputStream",
- "TempFileRecordingSXSSFWorkbookWithCustomZipEntrySource\\$TempFileRecordingSheetDataWriterWithDecorator",
- "TestXSSFBReader\\$1",
- "TestXSSFBReader\\$TestSheetHandler",
- "TestFormulaEvaluatorOnXSSF\\$1",
- "TestMultiSheetFormulaEvaluatorOnXSSF\\$1",
- "TestZipPackagePropertiesMarshaller\\$1",
- "SLCommonUtils",
- "TestPPTX2PNG\\$1",
- "TestMatrixFormulasFromXMLSpreadsheet\\$1",
- "TestMatrixFormulasFromXMLSpreadsheet\\$Navigator",
- "TestPOIXMLDocument\\$UncaughtHandler",
- "TestOleShape\\$Api",
- "TestOleShape\\$1",
- "TestPOIXMLDocument\\$1",
- "TestXMLSlideShow\\$1",
- "TestXMLSlideShow\\$BufAccessBAOS",
- "TestXDDFChart\\$1",
- "TestOOXMLLister\\$1",
- "TestOOXMLPrettyPrint\\$1"
- );
- System.out.println("Collecting unit tests from " + _testDir);
- collectTests(_testDir, _testDir, lst, ".+.class$", ".+(" + exclude + ").class");
- System.out.println("Found " + lst.size() + " classes");
-
- //run tests
- JUnitCore jUnitCore = new JUnitCore();
- jUnitCore.addListener(new TextListener(System.out) {
- private final Set classes = new HashSet<>();
- private int count;
-
- @Override
- public void testStarted(Description description) {
- // count how many test-classes we already saw
- classes.add(description.getClassName());
- count++;
- if(count % 100 == 0) {
- System.out.println();
- System.out.println(classes.size() + "/" + lst.size() + ": " + description.getDisplayName());
- }
-
- super.testStarted(description);
- }
- });
- Result result = jUnitCore.run(lst.toArray(new Class>[0]));
- if (!result.wasSuccessful()) {
- throw new RuntimeException("Tests did not succeed, cannot build ooxml-lite jar");
- }
-
- //see what classes from the ooxml-schemas.jar are loaded
- System.out.println("Copying classes to " + _destDest);
- Set> classes = getLoadedClasses(_ooxmlJar.getName());
- Set packages = new HashSet<>();
- for (Class> cls : classes) {
- copyFile(cls);
- packages.add(cls.getPackage().getName());
-
- if (cls.isInterface()) {
- /// Copy classes and interfaces declared as members of this class
- for (Class> fc : cls.getDeclaredClasses()) {
- copyFile(fc);
- }
- }
- }
- for (String pkg : packages) {
- Reflections reflections = new Reflections(pkg);
- Set> listClasses = reflections.getSubTypesOf(List.class);
- listClasses.removeAll(classes);
- for (Class listClass : listClasses) {
- for (Class> compare : classes) {
- if (listClass.getName().startsWith(compare.getName())) {
- copyFile(listClass);
- }
- }
- }
- Set> enumClasses = reflections.getSubTypesOf(StringEnumAbstractBase.class);
- listClasses.removeAll(classes);
- for (Class enumClass : enumClasses) {
- for (Class> compare : classes) {
- if (enumClass.getName().startsWith(compare.getName())) {
- copyFile(enumClass);
- }
- }
- }
- }
-
- //finally copy the compiled .xsb files
- System.out.println("Copying .xsb resources");
- try (JarFile jar = new JarFile(_ooxmlJar)) {
- for (Enumeration e = jar.entries(); e.hasMoreElements(); ) {
- JarEntry je = e.nextElement();
- if (SCHEMA_PATTERN.matcher(je.getName()).matches()) {
- File destFile = new File(_destDest, je.getName());
- IOUtils.copy(jar.getInputStream(je), destFile);
- }
- }
- }
- }
-
- private void copyFile(Class> cls) throws IOException {
- String className = cls.getName();
- String classRef = className.replace('.', '/') + ".class";
- File destFile = new File(_destDest, classRef);
- IOUtils.copy(cls.getResourceAsStream('/' + classRef), destFile);
- }
-
- private static boolean checkForTestAnnotation(Class> testclass) {
- for (Method m : testclass.getDeclaredMethods()) {
- if(m.isAnnotationPresent(Test.class)) {
- return true;
- }
- }
-
- // also check super classes
- if(testclass.getSuperclass() != null) {
- for (Method m : testclass.getSuperclass().getDeclaredMethods()) {
- if(m.isAnnotationPresent(Test.class)) {
- return true;
- }
- }
- }
-
- System.out.println("Class " + testclass.getName() + " does not derive from TestCase and does not have a @Test annotation");
-
- // Should we also look at superclasses to find cases
- // where we have abstract base classes with derived tests?
- // if(checkForTestAnnotation(testclass.getSuperclass())) return true;
-
- return false;
- }
-
- /**
- * Recursively collect classes from the supplied directory
- *
- * @param arg the directory to search in
- * @param out output
- * @param ptrn the pattern (regexp) to filter found files
- */
- private static void collectTests(File root, File arg, List> out, String ptrn, String exclude) {
- if (arg.isDirectory()) {
- File files[] = arg.listFiles();
- if (files != null) {
- for (File f : files) {
- collectTests(root, f, out, ptrn, exclude);
- }
- }
- } else {
- String path = arg.getAbsolutePath();
- String prefix = root.getAbsolutePath();
- String cls = path.substring(prefix.length() + 1).replace(File.separator, ".");
- if(!cls.matches(ptrn)) {
- return;
- }
- if (cls.matches(exclude)) {
- return;
- }
- //ignore inner classes defined in tests
- if (cls.indexOf('$') != -1) {
- System.out.println("Inner class " + cls + " not included");
- return;
- }
-
- cls = cls.replace(".class", "");
-
- try {
- Class> testclass = Class.forName(cls);
- if (TestCase.class.isAssignableFrom(testclass)
- || checkForTestAnnotation(testclass)) {
- out.add(testclass);
- }
- } catch (Throwable e) { // NOSONAR
- System.out.println("Class " + cls + " is not in classpath");
- }
- }
- }
-
- /**
- *
- * @param ptrn the pattern to filter output
- * @return the classes loaded by the system class loader
- */
- @SuppressWarnings("unchecked")
- private static Set> getLoadedClasses(String ptrn) {
- // make the field accessible, we defer this from static initialization to here to
- // allow JDKs which do not have this field (e.g. IBM JDK) to at least load the class
- // without failing, see https://issues.apache.org/bugzilla/show_bug.cgi?id=56550
- final Field _classes = AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- @SuppressForbidden("TODO: Reflection works until Java 8 on Oracle/Sun JDKs, but breaks afterwards (different classloader types, access checks)")
- public Field run() {
- try {
- Field fld = ClassLoader.class.getDeclaredField("classes");
- fld.setAccessible(true);
- return fld;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- }
- });
-
- ClassLoader appLoader = ClassLoader.getSystemClassLoader();
- try {
- Vector> classes = (Vector>) _classes.get(appLoader);
- Set> set = new HashSet<>();
- for (Class> cls : classes) {
- // e.g. proxy-classes, ...
- ProtectionDomain pd = cls.getProtectionDomain();
- if (pd == null) {
- continue;
- }
- CodeSource cs = pd.getCodeSource();
- if (cs == null) {
- continue;
- }
- URL loc = cs.getLocation();
- if (loc == null) {
- continue;
- }
-
- String jar = loc.toString();
- if (jar.contains(ptrn)) {
- set.add(cls);
- }
- }
- return set;
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/util/OOXMLLiteAgent.java b/src/ooxml/testcases/org/apache/poi/ooxml/util/OOXMLLiteAgent.java
new file mode 100644
index 0000000000..48c9240e98
--- /dev/null
+++ b/src/ooxml/testcases/org/apache/poi/ooxml/util/OOXMLLiteAgent.java
@@ -0,0 +1,78 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ooxml.util;
+
+import java.io.IOException;
+import java.lang.instrument.ClassFileTransformer;
+import java.lang.instrument.Instrumentation;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.security.ProtectionDomain;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Stream;
+
+/**
+ * OOXMLLiteAgent is the replacement for the former OOXMLLite, because in Java 12
+ * it isn't possible to access the privates :) of the ClassLoader
+ */
+public class OOXMLLiteAgent {
+
+ static class LoggingTransformer implements ClassFileTransformer {
+ final Path path;
+ final Pattern includes;
+ final Set fileHashes = new HashSet<>();
+
+ public LoggingTransformer(String agentArgs) {
+ String args[] = (agentArgs == null ? "" : agentArgs).split("\\|",2);
+ path = Paths.get(args.length >= 1 ? args[0] : "ooxml-lite.out");
+ includes = Pattern.compile(args.length >= 2 ? args[1] : ".*/schemas/.*");
+
+ try {
+ if (Files.exists(path)) {
+ try (Stream stream = Files.lines(path)) {
+ stream.forEach((s) -> fileHashes.add(s.hashCode()));
+ }
+ } else {
+ Files.createFile(path);
+ }
+ } catch (IOException ignored) {
+ }
+ }
+
+ public byte[] transform(ClassLoader loader, String className, Class redefiningClass, ProtectionDomain domain, byte[] bytes) {
+ if (path != null && className != null && !fileHashes.contains(className.hashCode()) && includes.matcher(className).find()) {
+ try {
+ // TODO: check if this is atomic ... as transform() is probably called synchronized, it doesn't matter anyway
+ Files.write(path, (className+"\n").getBytes(StandardCharsets.ISO_8859_1), StandardOpenOption.APPEND);
+ fileHashes.add(className.hashCode());
+ } catch (IOException ignroed) {
+ }
+ }
+ return bytes;
+ }
+ }
+
+ public static void premain(String agentArgs, Instrumentation inst) {
+ inst.addTransformer(new LoggingTransformer(agentArgs));
+ }
+}
diff --git a/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestHxxFEncryption.java b/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestHxxFEncryption.java
index 16d5a52a67..25443d786f 100644
--- a/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestHxxFEncryption.java
+++ b/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestHxxFEncryption.java
@@ -23,6 +23,7 @@ import static org.apache.poi.POIDataSamples.getSpreadSheetInstance;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -35,9 +36,8 @@ import java.util.Collection;
import org.apache.poi.POIDataSamples;
import org.apache.poi.POIDocument;
import org.apache.poi.extractor.POITextExtractor;
-import org.apache.poi.ooxml.extractor.ExtractorFactory;
-import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
+import org.apache.poi.ooxml.extractor.ExtractorFactory;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionHeader;
import org.apache.poi.poifs.storage.RawDataUtil;
@@ -64,21 +64,24 @@ public class TestHxxFEncryption {
@Parameters(name="{1}")
public static Collection