]> source.dussan.org Git - poi.git/commitdiff
try to fix no-scratchpad build
authorAndreas Beeker <kiwiwings@apache.org>
Wed, 1 Sep 2021 22:32:48 +0000 (22:32 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Wed, 1 Sep 2021 22:32:48 +0000 (22:32 +0000)
remove or set-to-static scratchpad dependency from modules

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1892795 13f79535-47bb-0310-9956-ffa450edef68

20 files changed:
build.gradle
jenkins/create_jobs.groovy
poi-examples/build.gradle
poi-examples/src/main/java9/module-info.java
poi-excelant/build.gradle
poi-excelant/src/main/java9/module-info.java
poi-excelant/src/test/java9/module-info.java
poi-integration/build.gradle
poi-integration/src/test/java/org/apache/poi/stress/FileHandlerFactory.java [deleted file]
poi-integration/src/test/java/org/apache/poi/stress/FileHandlerKnown.java
poi-integration/src/test/java/org/apache/poi/stress/HPSFFileHandler.java
poi-integration/src/test/java/org/apache/poi/stress/StressMap.java
poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java
poi-integration/src/test/java9/module-info.java
poi-ooxml/build.gradle
poi-ooxml/src/test/java/org/apache/poi/extractor/ooxml/TestExtractorFactory.java
poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java
poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java
poi-ooxml/src/test/java/org/apache/poi/ss/tests/usermodel/TestEmbedOLEPackage.java
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

index 38f45d8684a7738678100de931cc160867cf751b..8d40eb11526ba5b96e7156b47a015b3e6b6448f8 100644 (file)
@@ -120,6 +120,8 @@ subprojects {
                TEST9_SRC = 'src/test/java9'
                TEST9_OUT = "${buildDir}/classes/java9/test/"
                VERSIONS9 = 'META-INF/versions/9'
+
+        NO_SCRATCHPAD = (findProperty("scratchpad.ignore") == "true")
     }
 
     tasks.withType(JavaCompile) {
index 15ea158dc902324d6f175b208a752bc4bfbce48e..b8f490e2724a95bdc6ec54869b5aaa68c40b3143 100644 (file)
@@ -63,7 +63,7 @@ def poijobs = [
         ],
         [ name: 'POI-DSL-Gradle', trigger: triggerSundays, email: 'centic@apache.org', gradle: true
         ],
-        [ name: 'POI-DSL-no-scratchpad', trigger: triggerSundays, noScratchpad: true
+        [ name: 'POI-DSL-no-scratchpad', trigger: triggerSundays, noScratchpad: true, gradle: true
         ],
         [ name: 'POI-DSL-SonarQube', jdk: '1.11', trigger: 'H 7 * * *', maven: true, sonar: true, skipcigame: true,
           email: 'kiwiwings@apache.org',
@@ -445,17 +445,9 @@ poijobs.each { poijob ->
                     gradle {
                         tasks('clean jenkins')
                         useWrapper(true)
-                    }
-                } else if (poijob.noScratchpad) {
-                    ant {
-                        targets(['clean', 'compile'] + (poijob.properties ?: []))
-                        prop('coverage.enabled', true)
-                        antInstallation(antRT)
-                    }
-                    ant {
-                        targets(['-Dscratchpad.ignore=true', 'jacocotask', 'test-all', 'testcoveragereport'] + (poijob.properties ?: []))
-                        prop('coverage.enabled', true)
-                        antInstallation(antRT)
+                        if (poijob.noScratchpad) {
+                            switches('-Pscratchpad.ignore=true')
+                        }
                     }
                 } else {
                     ant {
index fe8feea87f7845320fe48e778415465663f7cd68..4aff0b8a6bdddbc05e6332b12dc48745234135e4 100644 (file)
@@ -28,20 +28,29 @@ sourceSets {
 
 dependencies {
     api project(':poi-ooxml')
-    api project(':poi-scratchpad')
+//    api project(':poi-scratchpad')
     implementation project(path: ':poi-ooxml', configuration: 'archives')
     implementation project(path: ':poi-ooxml-full', configuration: 'archives')
-    implementation project(path: ':poi-scratchpad', configuration: 'archives')
+
+    if (NO_SCRATCHPAD) {
+        compileOnly project(path: ':poi-scratchpad', configuration: 'archives')
+    } else {
+        implementation project(path: ':poi-scratchpad', configuration: 'archives')
+    }
 
     implementation "org.apache.logging.log4j:log4j-core:${log4jVersion}"
 
-       testImplementation project(path: ':poi-ooxml', configuration: 'tests')
+       testImplementation(project(path: ':poi-ooxml', configuration: 'tests')) {
+        if (NO_SCRATCHPAD) {
+            exclude group: 'org.apache.poi', module: 'poi-scratchpad'
+        }
+    }
        testImplementation project(path: ':poi', configuration: 'tests')
 }
 
 final String MODULE_NAME = 'org.apache.poi.examples'
 final Pattern MODULE_REGEX = ~'\\.jar$'
-final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
+final List MODULE_COMPILE_PATH = sourceSets.main.compileClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
 
 task compileJava9(type: JavaCompile) {
     dependsOn 'compileJava', ':poi-ooxml:jar', ':poi-scratchpad:jar'
@@ -53,7 +62,7 @@ task compileJava9(type: JavaCompile) {
     classpath = files()
     options.compilerArgs = [
         '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
-        '--module-path', files(MAIN_MODULE_PATH).asPath
+        '--module-path', files(MODULE_COMPILE_PATH).asPath
     ]
 }
 
index 68b580e3eeff87f9a7d6effaa2d47a910c4fad22..db16935d94c77392015f102648bf9e641c87fbb4 100644 (file)
@@ -18,7 +18,7 @@
 module org.apache.poi.examples {
 
     requires transitive org.apache.poi.ooxml;
-    requires transitive org.apache.poi.scratchpad;
+    requires static org.apache.poi.scratchpad;
     requires java.xml;
 
     exports org.apache.poi.examples.crypt;
index ee7cd664c0571d293b4cb2342d1db83d5d3be547..e22a80f1f28ee9d55aa86a0b38da40906173ee26 100644 (file)
@@ -38,14 +38,13 @@ dependencies {
     api 'org.apache.ant:ant:1.10.9'
 
     api project(':poi-ooxml')
-    api project(':poi-scratchpad')
     api project(path: ':poi-ooxml', configuration: 'archives')
-    api project(path: ':poi-scratchpad', configuration: 'archives')
 
     testImplementation project(path: ':poi-ooxml-lite-agent', configuration: 'archives')
     testImplementation project(path: ':poi', configuration: 'tests')
-    testImplementation project(path: ':poi-ooxml', configuration: 'tests')
-    testImplementation project(path: ':poi-scratchpad', configuration: 'tests')
+    testImplementation(project(path: ':poi-ooxml', configuration: 'tests')) {
+        exclude group: 'org.apache.poi', module: 'poi-scratchpad'
+    }
     testImplementation 'com.google.guava:guava:30.0-jre'
     testImplementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.1'
 }
index 43b64560a7d05a86797d637e589a58e60d7ea767..743b172ad1e07192885565d24dbb19f413246610 100644 (file)
@@ -19,7 +19,6 @@ module org.apache.poi.excelant {
 
     requires ant;
     requires org.apache.poi.ooxml;
-    requires org.apache.poi.scratchpad;
 
     exports org.apache.poi.ss.excelant;
     exports org.apache.poi.ss.excelant.util;
index a26d9bd04dd0b4bfb1cc253151d0279f824565f7..97c40ae4b61ab59b3091fb8522fccb4aa5daf6c7 100644 (file)
@@ -19,7 +19,6 @@ module org.apache.poi.excelant {
 
     requires ant;
     requires org.apache.poi.ooxml;
-    requires org.apache.poi.scratchpad;
 
     exports org.apache.poi.ss.excelant;
     exports org.apache.poi.ss.excelant.util;
index 97a16100f09573e0dedcf0921061e4443d9bb5a0..28e961ed4a660bd05edf5a5868c779f2d67e1033 100644 (file)
@@ -44,13 +44,34 @@ dependencies {
     testImplementation 'org.apache.commons:commons-collections4:4.4'
     testImplementation 'com.google.guava:guava:30.0-jre'
 
-    testImplementation project(':poi-ooxml')
-    testImplementation project(':poi-scratchpad')
-    testImplementation project(':poi-examples')
-    testImplementation project(path:':poi-examples', configuration:'archives')
+    testImplementation(project(':poi-ooxml')) {
+        if (NO_SCRATCHPAD) {
+            exclude group: 'org.apache.poi', module: 'poi-scratchpad'
+        }
+    }
+    if (NO_SCRATCHPAD) {
+        testCompileOnly project(':poi-scratchpad')
+        testCompileOnly project(path:':poi-scratchpad', configuration:'tests')
+    } else {
+        testImplementation project(':poi-scratchpad')
+        testImplementation project(path:':poi-scratchpad', configuration:'tests')
+    }
+    testImplementation(project(':poi-examples')) {
+        if (NO_SCRATCHPAD) {
+            exclude group: 'org.apache.poi', module: 'poi-scratchpad'
+        }
+    }
+    testImplementation(project(path:':poi-examples', configuration:'archives')) {
+        if (NO_SCRATCHPAD) {
+            exclude group: 'org.apache.poi', module: 'poi-scratchpad'
+        }
+    }
     testImplementation project(path:':poi', configuration:'tests')
-    testImplementation project(path:':poi-ooxml', configuration:'tests')
-    testImplementation project(path:':poi-scratchpad', configuration:'tests')
+    testImplementation(project(path:':poi-ooxml', configuration:'tests')) {
+        if (NO_SCRATCHPAD) {
+            exclude group: 'org.apache.poi', module: 'poi-scratchpad'
+        }
+    }
     testImplementation project(path: ':poi-ooxml-lite-agent', configuration: 'archives')
     testImplementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.1'
 }
@@ -58,7 +79,8 @@ dependencies {
 final String MODULE_NAME = 'org.apache.poi.stress'
 final Pattern MODULE_NOT_REGEX = ~'((poi|poi-scratchpad|poi-ooxml)[/\\\\][^/\\\\]+$|batik-script)'
 final Pattern MODULE_REGEX = ~'\\.jar$'
-final List TEST_MODULE_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique()
+final List MODULE_COMPILE_PATH = sourceSets.test.compileClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique()
+final List MODULE_RUNTIME_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique()
 
 final String OOXML_LITE_AGENT = "../build/dist/maven/poi-ooxml-lite-agent/poi-ooxml-lite-agent-${project.version}.jar"
 final String OOXML_LITE_REPORT = '../build/ooxml-lite-report'
@@ -79,7 +101,7 @@ task compileTest9(type: JavaCompile) {
     source = file(TEST9_SRC)
     options.compilerArgs = [
         '--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
-        '--module-path', files(TEST_MODULE_PATH).asPath
+        '--module-path', files(MODULE_COMPILE_PATH).asPath
     ]
     classpath = files()
 }
@@ -141,9 +163,12 @@ test {
         if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
             jvmArgs += [
                 '--add-modules', MODULE_NAME,
-                '--module-path', '../build/dist/maven/poi-integration-tests' + File.pathSeparator + files(TEST_MODULE_PATH).asPath,
+                '--module-path', '../build/dist/maven/poi-integration-tests' + File.pathSeparator + files(MODULE_RUNTIME_PATH).asPath,
             ]
         }
+        if (NO_SCRATCHPAD) {
+            systemProperty 'scratchpad.ignore', 'true'
+        }
     }
 }
 
diff --git a/poi-integration/src/test/java/org/apache/poi/stress/FileHandlerFactory.java b/poi-integration/src/test/java/org/apache/poi/stress/FileHandlerFactory.java
deleted file mode 100644 (file)
index 8be52b3..0000000
+++ /dev/null
@@ -1,120 +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.stress;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-public class FileHandlerFactory {
-    // map from patterns for mimetypes to the FileHandlers that should be able to
-    // work with that file
-    // use a Set<Pair> to have a defined order of applying the matches
-    private static final Map<Pattern, FileHandler> MIME_TYPES = new HashMap<>();
-    static {
-        ////////////////// Word
-
-        MIME_TYPES.put(Pattern.compile("application/vnd.ms-word.document.macroenabled.12"), new XWPFFileHandler());
-        MIME_TYPES.put(Pattern.compile("application/vnd.ms-word.template.macroenabled.12"), new XWPFFileHandler());
-
-        // application/msword
-        MIME_TYPES.put(Pattern.compile(".*msword.*"), new HWPFFileHandler());
-        // application/vnd.ms-word
-        MIME_TYPES.put(Pattern.compile(".*ms-word.*"), new HWPFFileHandler());
-
-        // application/vnd.openxmlformats-officedocument.wordprocessingml.document
-        MIME_TYPES.put(Pattern.compile(".*wordprocessingml.*"), new XWPFFileHandler());
-
-        ////////////////// Excel
-        MIME_TYPES.put(Pattern.compile("application/vnd.ms-excel.addin.macroEnabled.12"), new XSSFFileHandler());
-        MIME_TYPES.put(Pattern.compile("application/vnd.ms-excel.sheet.binary.macroEnabled.12"), new XSSFFileHandler());
-
-        // application/msexcel
-        MIME_TYPES.put(Pattern.compile(".*msexcel.*"), new HSSFFileHandler());
-        // application/vnd.ms-excel
-        MIME_TYPES.put(Pattern.compile(".*ms-excel.*"), new HSSFFileHandler());
-
-        // application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
-        MIME_TYPES.put(Pattern.compile(".*spreadsheetml.*"), new XSSFFileHandler());
-
-        ////////////////// Powerpoint
-
-        // application/vnd.ms-powerpoint
-        MIME_TYPES.put(Pattern.compile("application/vnd.ms-powerpoint"), new HSLFFileHandler());
-        // application/vnd.ms-officetheme
-        MIME_TYPES.put(Pattern.compile("application/vnd.ms-officetheme"), new HSLFFileHandler());
-
-        // application/vnd.openxmlformats-officedocument.presentationml.presentation
-        MIME_TYPES.put(Pattern.compile(".*presentationml.*"), new XSLFFileHandler());
-        // application/vnd.ms-powerpoint.presentation.macroenabled.12
-        MIME_TYPES.put(Pattern.compile("application/vnd.ms-powerpoint.presentation.macroenabled.12"), new XSLFFileHandler());
-        // application/vnd.ms-powerpoint.slideshow.macroenabled.12
-        MIME_TYPES.put(Pattern.compile("application/vnd.ms-powerpoint.slideshow.macroenabled.12"), new XSLFFileHandler());
-
-        ////////////////// Mail/TNEF
-
-        // application/vnd.ms-tnef
-        MIME_TYPES.put(Pattern.compile(".*ms-tnef.*"), new HMEFFileHandler());
-
-        // application/vnd.ms-outlook
-        MIME_TYPES.put(Pattern.compile("application/vnd.ms-outlook"), new HSMFFileHandler());
-
-        ////////////////// Visio
-
-        // application/vnd.visio
-        MIME_TYPES.put(Pattern.compile("application/vnd.visio.*"), new HDGFFileHandler());
-
-        // application/vnd.ms-visio.drawing
-        MIME_TYPES.put(Pattern.compile(".*vnd.ms-visio\\."), new XDGFFileHandler());
-
-        //application/vnd.ms-visio.viewer
-        MIME_TYPES.put(Pattern.compile(".*visio.*"), new HDGFFileHandler());
-
-
-        ////////////////// Publisher
-
-        // application/x-mspublisher
-        MIME_TYPES.put(Pattern.compile("application/x-mspublisher"), new HPBFFileHandler());
-
-
-        ////////////////// Others
-
-        // special type used by Tika
-        MIME_TYPES.put(Pattern.compile("application/x-tika-ooxml.*"), new OPCFileHandler());
-        // special type used by Tika
-        MIME_TYPES.put(Pattern.compile("application/x-tika-msoffice.*"), new POIFSFileHandler());
-
-        // application/x-tika-old-excel
-        MIME_TYPES.put(Pattern.compile("application/x-tika-old-excel"), new POIFSFileHandler());
-
-        // application/vnd.openxmlformats-officedocument.drawingml.chart+xml
-        // ?!MIME_TYPES.put(Pattern.compile(".*drawingml.*"), ".dwg");
-
-        // application/vnd.openxmlformats-officedocument.vmlDrawing
-        // ?!MIME_TYPES.put(Pattern.compile(".*vmlDrawing.*"), ".dwg");
-    }
-
-    public static FileHandler getHandler(String mimeType) {
-        for(Map.Entry<Pattern,FileHandler> entry : MIME_TYPES.entrySet()) {
-            if(entry.getKey().matcher(mimeType).matches()) {
-                return entry.getValue();
-            }
-        }
-
-        return null;
-    }
-}
index aa3c827f1f027510eb120c779faee756bfb85889..a4385746107771ecc576e75f182576e4a380f211 100644 (file)
@@ -22,29 +22,33 @@ import java.util.function.Supplier;
 
 @SuppressWarnings("unused")
 public enum FileHandlerKnown {
-    HDGF(HDGFFileHandler::new),
-    HMEF(HMEFFileHandler::new),
-    HPBF(HPBFFileHandler::new),
-    HPSF(HPSFFileHandler::new),
-    HSLF(HSLFFileHandler::new),
-    HSMF(HSMFFileHandler::new),
-    HSSF(HSSFFileHandler::new),
-    HWPF(HWPFFileHandler::new),
-    OPC(OPCFileHandler::new),
-    POIFS(POIFSFileHandler::new),
-    XDGF(XDGFFileHandler::new),
-    XSLF(XSLFFileHandler::new),
-    XSSFB(XSSFBFileHandler::new),
-    XSSF(XSSFFileHandler::new),
-    XWPF(XWPFFileHandler::new),
-    OWPF(OWPFFileHandler::new),
-    NULL(NullFileHandler::new)
+    HDGF,
+    HMEF,
+    HPBF,
+    HPSF,
+    HSLF,
+    HSMF,
+    HSSF,
+    HWPF,
+    OPC,
+    POIFS,
+    XDGF,
+    XSLF,
+    XSSFB,
+    XSSF,
+    XWPF,
+    OWPF,
+    NULL
     ;
 
-    public final Supplier<FileHandler> fileHandler;
-
-    FileHandlerKnown(Supplier<FileHandler> fileHandler) {
-        this.fileHandler = fileHandler;
+    public FileHandler getHandler() {
+        try {
+            // Because of no-scratchpad handling, we need to resort to reflection here
+            String n = name().replace("NULL", "Null");
+            return (FileHandler)Class.forName("org.apache.poi.stress." + n + "FileHandler").newInstance();
+        } catch (Exception e) {
+            return new NullFileHandler();
+        }
     }
 
     private static class NullFileHandler implements FileHandler {
index 3caf166f31d892c11a49e9b0c022d04ab08b708a..274a3880e671b045557dbac5a0c1fbc63efaaf96 100644 (file)
@@ -18,6 +18,8 @@ package org.apache.poi.stress;
 
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.fail;
 import static org.junit.jupiter.api.Assumptions.assumeFalse;
 
@@ -31,10 +33,12 @@ import java.util.Set;
 
 import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.examples.hpsf.CopyCompare;
+import org.apache.poi.extractor.POITextExtractor;
 import org.apache.poi.hpsf.DocumentSummaryInformation;
 import org.apache.poi.hpsf.HPSFPropertiesOnlyDocument;
 import org.apache.poi.hpsf.PropertySet;
 import org.apache.poi.hpsf.SummaryInformation;
+import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.DocumentInputStream;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@@ -56,6 +60,35 @@ class HPSFFileHandler extends POIFSFileHandler {
         "document/word2.doc"
     );
 
+    @Override
+    public void handleExtracting(File file) throws Exception {
+        if (!Boolean.getBoolean("scratchpad.ignore")) {
+            super.handleExtracting(file);
+            return;
+        }
+
+        long length = file.length();
+        long modified = file.lastModified();
+
+        try (POIFSFileSystem poifs = new POIFSFileSystem(file);
+             HPSFPropertiesExtractor extractor = new HPSFPropertiesExtractor(poifs)) {
+
+            String fileAndParentName = file.getParentFile().getName() + "/" + file.getName();
+            String relPath = file.getPath().replaceAll(".*test-data", "test-data").replace('\\', '/');
+
+            assertFalse(EXPECTED_EXTRACTOR_FAILURES.contains(fileAndParentName),
+                "Expected Extraction to fail for file " + relPath + " and handler " + this + ", but did not fail!");
+            assertNotNull(extractor.getDocumentSummaryInformationText());
+            assertNotNull(extractor.getSummaryInformationText());
+            String text = extractor.getText();
+            //System.out.println(text);
+            assertNotNull(text);
+        }
+
+        assertEquals(length, file.length(), "File should not be modified by extractor");
+        assertEquals(modified, file.lastModified(), "File should not be modified by extractor");
+    }
+
     @Override
     public void handleFile(InputStream stream, String path) throws Exception {
         POIFSFileSystem poifs = new POIFSFileSystem(stream);
index f69fbfbf4f8207b79f1c12b380e271c5790267cb..cf533c5b4f1a61b3c1e448c3ab2fa9207d55a848 100644 (file)
@@ -18,12 +18,14 @@ package org.apache.poi.stress;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.AbstractMap.SimpleEntry;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.function.BiConsumer;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
@@ -40,7 +42,8 @@ import org.apache.poi.ss.usermodel.WorkbookFactory;
 public class StressMap {
     private final MultiValuedMap<String, ExcInfo> exMap = new ArrayListValuedHashMap<>();
     private final Map<String,String> handlerMap = new LinkedHashMap<>();
-
+    private final boolean SCRATCH_IGNORE = Boolean.getBoolean("scratchpad.ignore");
+    private final Pattern SCRATCH_HANDLER = Pattern.compile("(HSLF|HWPF|HSMF|HMEF)");
 
     public void load(File mapFile) throws IOException {
         try (Workbook wb = WorkbookFactory.create(mapFile)) {
@@ -79,7 +82,6 @@ public class StressMap {
 
         handlerMap.clear();
 
-        boolean IGNORE_SCRATCHPAD = Boolean.getBoolean("scratchpad.ignore");
         boolean isFirst = true;
         for (Row row : sh) {
             if (isFirst) {
@@ -87,7 +89,7 @@ public class StressMap {
                 continue;
             }
             Cell cell = row.getCell(2);
-            if (IGNORE_SCRATCHPAD || cell == null || cell.getCellType() != CellType.STRING) {
+            if (SCRATCH_IGNORE || cell == null || cell.getCellType() != CellType.STRING) {
                 cell = row.getCell(1);
             }
             handlerMap.put(row.getCell(0).getStringCellValue(), cell.getStringCellValue());
@@ -103,20 +105,38 @@ public class StressMap {
         exMap.clear();
 
         Iterator<Row> iter = sh.iterator();
-        List<BiConsumer<ExcInfo,String>> cols = initCols(iter.next());
+        List<Map.Entry<String, BiConsumer<ExcInfo,String>>> cols = initCols(iter.next());
+
+        int idx = 0, handlerIdx = -1;
+        for (Map.Entry<String, BiConsumer<ExcInfo, String>> e : cols) {
+            if ("Handler".equals(e.getKey())) {
+                handlerIdx = idx;
+            }
+            idx++;
+        }
 
         while (iter.hasNext()) {
+            Row row = iter.next();
+
+            if (SCRATCH_IGNORE && handlerIdx > -1) {
+                String handler = row.getCell(handlerIdx).getStringCellValue();
+                if (SCRATCH_HANDLER.matcher(handler).find()) {
+                    // ignore exception of ignored files
+                    continue;
+                }
+            }
+
             ExcInfo info = new ExcInfo();
-            for (Cell cell : iter.next()) {
+            for (Cell cell : row) {
                 if (cell.getCellType() == CellType.STRING) {
-                    cols.get(cell.getColumnIndex()).accept(info, cell.getStringCellValue());
+                    cols.get(cell.getColumnIndex()).getValue().accept(info, cell.getStringCellValue());
                 }
             }
             exMap.put(info.getFile(), info);
         }
     }
 
-    private static List<BiConsumer<ExcInfo,String>> initCols(Row row) {
+    private static List<Map.Entry<String, BiConsumer<ExcInfo,String>>> initCols(Row row) {
         Map<String,BiConsumer<ExcInfo,String>> m = new HashMap<>();
         m.put("File", ExcInfo::setFile);
         m.put("Tests", ExcInfo::setTests);
@@ -128,7 +148,7 @@ public class StressMap {
         return StreamSupport
             .stream(row.spliterator(), false)
             .map(Cell::getStringCellValue)
-            .map(v -> m.getOrDefault(v, (e,s) -> {}))
+            .map(v -> new SimpleEntry<>(v, m.getOrDefault(v, (e,s) -> {})))
             .collect(Collectors.toList());
     }
 
index f35f3b27fb91e72e61120fab7e06e0f0736f1327..9d803f8e06f47c35a5e5e9c5d93f5ec149e1b266 100644 (file)
@@ -66,7 +66,7 @@ import org.opentest4j.AssertionFailedError;
  *  that we do not remove expected sanity checks.
  */
 // also need to set JVM parameter: -Djunit.jupiter.execution.parallel.enabled=true
-@Execution(ExecutionMode.CONCURRENT)
+//@Execution(ExecutionMode.CONCURRENT)
 public class TestAllFiles {
     private static final String DEFAULT_TEST_DATA_PATH = "test-data";
     public static final File ROOT_DIR = new File(System.getProperty("POI.testdata.path", DEFAULT_TEST_DATA_PATH));
@@ -78,6 +78,27 @@ public class TestAllFiles {
         "**/right-to-left.xlsx" //the threaded comments in this file cause XSSF clone to fail
     };
 
+    // cheap workaround of skipping the few problematic files
+    public static final String[] SCAN_EXCLUDES_NOSCRATCHPAD = {
+        "**/.svn/**",
+        "lost+found",
+        "**/.git/**",
+        "**/right-to-left.xlsx",
+        "document/word2.doc",
+        "document/cpansearch.perl.org_src_tobyink_acme-rundoc-0.001_word-lib_hello_world.docm",
+        "hpsf/Test0313rur.adm",
+        "spreadsheet/43493.xls",
+        "spreadsheet/44958.xls",
+        "spreadsheet/44958_1.xls",
+        "spreadsheet/46904.xls",
+        "spreadsheet/51832.xls",
+        "spreadsheet/60284.xls",
+        "spreadsheet/testArraysAndTables.xls",
+        "spreadsheet/testEXCEL_3.xls",
+        "spreadsheet/testEXCEL_4.xls",
+        "poifs/unknown_properties.msg"
+    };
+
     private static final Set<String> EXPECTED_FAILURES = StressTestUtils.unmodifiableHashSet(
             "document/truncated62886.docx"
     );
@@ -86,10 +107,11 @@ public class TestAllFiles {
         StressMap sm = new StressMap();
         sm.load(new File(ROOT_DIR, "spreadsheet/stress.xls"));
 
+        boolean noScratch = Boolean.getBoolean("scratchpad.ignore");
+
         DirectoryScanner scanner = new DirectoryScanner();
         scanner.setBasedir(ROOT_DIR);
-        scanner.setExcludes(SCAN_EXCLUDES);
-
+        scanner.setExcludes(noScratch ? SCAN_EXCLUDES_NOSCRATCHPAD : SCAN_EXCLUDES);
         scanner.scan();
 
         final List<Arguments> result = new ArrayList<>(100);
@@ -121,7 +143,7 @@ public class TestAllFiles {
         if (StressTestUtils.excludeFile(file, EXPECTED_FAILURES)) return;
 
         System.out.println("Running extractFiles on "+file);
-        FileHandler fileHandler = handler.fileHandler.get();
+        FileHandler fileHandler = handler.getHandler();
         assertNotNull(fileHandler, "Did not find a handler for file " + file);
         Executable exec = () -> fileHandler.handleExtracting(new File(ROOT_DIR, file));
         verify(file, exec, exClass, exMessage, password);
@@ -135,7 +157,7 @@ public class TestAllFiles {
     @MethodSource("handleFiles")
     void handleFile(String file, FileHandlerKnown handler, String password, Class<? extends Throwable> exClass, String exMessage) throws IOException {
         System.out.println("Running handleFiles on "+file);
-        FileHandler fileHandler = handler.fileHandler.get();
+        FileHandler fileHandler = handler.getHandler();
         assertNotNull(fileHandler, "Did not find a handler for file " + file);
         try (InputStream stream = new BufferedInputStream(new FileInputStream(new File(ROOT_DIR, file)), 64 * 1024)) {
             Executable exec = () -> fileHandler.handleFile(stream, file);
@@ -151,7 +173,7 @@ public class TestAllFiles {
     @MethodSource("handleAdditionals")
     void handleAdditional(String file, FileHandlerKnown handler, String password, Class<? extends Throwable> exClass, String exMessage) {
         System.out.println("Running additionals on "+file);
-        FileHandler fileHandler = handler.fileHandler.get();
+        FileHandler fileHandler = handler.getHandler();
         assertNotNull(fileHandler, "Did not find a handler for file " + file);
         Executable exec = () -> fileHandler.handleAdditional(new File(ROOT_DIR, file));
         verify(file, exec, exClass, exMessage, password);
index 782edf74dbc34e58bd556302bde088ed4aba28e5..82eb9f6591e7ea76a09c5a3966e89a2ac1aa6f54 100644 (file)
@@ -24,6 +24,7 @@ module org.apache.poi.stress {
 
     requires org.apache.commons.collections4;
     requires org.apache.poi.examples;
+    requires static org.apache.poi.scratchpad;
 
     exports org.apache.poi.stress;
 
index 5d57783622d3669d4dab49a25d4616b994407aa7..1179633f17778a529d39542a3709bbc8b316850b 100644 (file)
@@ -64,11 +64,12 @@ dependencies {
 
     api 'de.rototor.pdfbox:graphics2d:0.32'
 
-
-    testImplementation project(':poi-scratchpad')
+    if (!NO_SCRATCHPAD) {
+         testImplementation project(':poi-scratchpad')
+         testImplementation project(path:':poi-scratchpad', configuration:'tests')
+    }
     testImplementation project(path:':poi', configuration:'tests')
     testImplementation project(path:':poi-ooxml-lite-agent', configuration: 'archives')
-    testImplementation project(path:':poi-scratchpad', configuration:'tests')
     testImplementation 'org.xmlunit:xmlunit-core:2.8.0'
     testImplementation 'org.reflections:reflections:0.9.12'
     testImplementation 'org.openjdk.jmh:jmh-core:1.26'
@@ -219,6 +220,12 @@ test {
 
     systemProperties['junit.jupiter.execution.parallel.enabled'] = 'true'
 
+    if (NO_SCRATCHPAD) {
+        useJUnitPlatform {
+            excludeTags 'scratchpad.ignore'
+        }
+    }
+
     doFirst {
         jvmArgs += [
             "-javaagent:${OOXML_LITE_AGENT}=${OOXML_LITE_REPORT}|${OOXML_LITE_INCLUDES}",
@@ -226,7 +233,7 @@ test {
         if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
             jvmArgs += [
                 '--add-modules', MODULE_NAME,
-                '--module-path', '../build/dist/maven/poi-ooxml-tests' + java.io.File.pathSeparator + files(TEST_MODULE_PATH).asPath,
+                '--module-path', '../build/dist/maven/poi-ooxml-tests' + File.pathSeparator + files(TEST_MODULE_PATH).asPath,
             ]
         }
     }
index 55e56107d6827b2d4d6e170bf89cd678dd4863d6..a00e232e290bdff47811b5ec943b9e60945d63f1 100644 (file)
@@ -45,6 +45,7 @@ import org.apache.poi.poifs.filesystem.FileMagic;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor;
 import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
+import org.junit.jupiter.api.Tag;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
@@ -54,6 +55,7 @@ import org.junit.jupiter.params.provider.ValueSource;
 /**
  * Test that the extractor factory plays nicely
  */
+@Tag("scratchpad.ignore")
 class TestExtractorFactory {
 
     private static final POIDataSamples ssTests = POIDataSamples.getSpreadSheetInstance();
index 30529032267aa013edd99b341a20867f991840ec..502a125613d65442c9438c7b423f549ba9f39ee0 100644 (file)
@@ -160,6 +160,7 @@ import org.etsi.uri.x01903.v13.QualifyingPropertiesType;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Tag;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.ValueSource;
@@ -924,6 +925,7 @@ class TestSignatureInfo {
 
     @Test
     @DisabledOnJreEx("1.8.0_292")
+    @Tag("scratchpad.ignore")
     void testSignatureImage() throws Exception {
         initKeyPair();
 
index 6f4f27c4865adef06c1307f31a126e230b8fdeeb..d51ac67e3bccb4b755e054c62450bcd50609a3e7 100644 (file)
@@ -42,11 +42,13 @@ import org.apache.poi.poifs.crypt.EncryptionInfo;
 import org.apache.poi.poifs.crypt.EncryptionMode;
 import org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionHeader;
 import org.apache.poi.poifs.storage.RawDataUtil;
+import org.junit.jupiter.api.Tag;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.MethodSource;
 
+@Tag("scratchpad.ignore")
 class TestHxxFEncryption {
     public static Stream<Arguments> data() throws IOException {
         final String base64 =
index 4c085df879c4b36aa5e4cd57c29bb237c5e7abb0..183bab321f780b56e9df42bcff15cb350b25aa3f 100644 (file)
@@ -63,8 +63,10 @@ import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.usermodel.XSSFObjectData;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
 import org.junit.jupiter.api.Test;
 
+@Tag("scratchpad.ignore")
 class TestEmbedOLEPackage {
     private static byte[] samplePPT, samplePPTX, samplePNG;
 
index 25a16e0f6956df5d4d52649426e3731efc650855..cb736d599ef7303d34bc6aeb4be22fd4a76f8dcc 100644 (file)
@@ -111,6 +111,7 @@ import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
 import org.apache.xmlbeans.XmlException;
 import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Tag;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.CsvSource;
@@ -3439,6 +3440,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
 
 
     @Test
+    @Tag("scratchpad.ignore")
     void testXLSXinPPT() throws Exception {
         assumeFalse(Boolean.getBoolean("scratchpad.ignore"));