From 0345110611a3c4d7dfff0e5200566ccc05784edc Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sun, 16 Aug 2015 20:51:40 +0000 Subject: [PATCH] Try to make Sonar builds run again: add missing dependency, add ooxml-schema-security, don't depend on dir test-data and build-directory directly, don't override a POILogger that is set via System Properties git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1696165 13f79535-47bb-0310-9956-ffa450edef68 --- sonar/ooxml-schema-security/pom.xml | 84 +++++++++++++++++++ sonar/ooxml/pom.xml | 24 +++++- sonar/pom.xml | 4 +- .../poi/poifs/crypt/TestSignatureInfo.java | 33 ++++++-- .../poi/xssf/usermodel/TestXSSFBugs.java | 7 +- .../poi/xssf/usermodel/TestXSSFHyperlink.java | 14 +--- .../poi/hdf/extractor/TestWordDocument.java | 5 +- .../poi/poifs/storage/TestRawDataBlock.java | 11 +-- .../poifs/storage/TestRawDataBlockList.java | 9 -- 9 files changed, 148 insertions(+), 43 deletions(-) create mode 100644 sonar/ooxml-schema-security/pom.xml diff --git a/sonar/ooxml-schema-security/pom.xml b/sonar/ooxml-schema-security/pom.xml new file mode 100644 index 000000000..7debcf290 --- /dev/null +++ b/sonar/ooxml-schema-security/pom.xml @@ -0,0 +1,84 @@ + + 4.0.0 + + org.apache.poi + poi-parent + 3.12-SNAPSHOT + + poi-ooxml-schema-security + jar + + Apach POI - Openxmlformats Security-Schema package + + + + target/generated-sources/* + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.6 + + + build-jar + generate-sources + + + + + + + + + run + + + + + + + + maven-resources-plugin + 2.6 + + + copy-sources + generate-sources + + copy-resources + + + ${basedir}/src/main/resources + + + target/jar + + + + + + + + + + + + ${project.groupId} + poi-main + ${project.version} + + + ${project.groupId} + poi-scratchpad + ${project.version} + + + diff --git a/sonar/ooxml/pom.xml b/sonar/ooxml/pom.xml index 994b232ea..4df81fe12 100644 --- a/sonar/ooxml/pom.xml +++ b/sonar/ooxml/pom.xml @@ -22,7 +22,6 @@ copy-sources - generate-sources copy-resources @@ -38,7 +37,6 @@ copy-resources - generate-resources copy-resources @@ -54,7 +52,6 @@ copy-tests - generate-test-sources copy-resources @@ -97,6 +94,11 @@ poi-ooxml-schema-encryption ${project.version} + + ${project.groupId} + poi-ooxml-schema-security + ${project.version} + ${project.groupId} poi-main @@ -116,6 +118,22 @@ 2.6.0 + + org.bouncycastle + bcpkix-jdk15on + 1.51 + + + org.bouncycastle + bcprov-jdk15on + 1.51 + + + org.apache.santuario + xmlsec + 2.0.1 + + junit diff --git a/sonar/pom.xml b/sonar/pom.xml index 99796faaf..6117e9355 100644 --- a/sonar/pom.xml +++ b/sonar/pom.xml @@ -56,6 +56,7 @@ main ooxml-schema ooxml-schema-encryption + ooxml-schema-security ooxml scratchpad excelant @@ -100,7 +101,8 @@ true org.apache.poi.util.NullLogger - -Duser.language=en -Duser.country=US + + -Duser.language=en -Duser.country=US -Xmx512m **/All*Tests.java **/TestUnfixedBugs.java diff --git a/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java b/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java index d0eeb3d47..0835c566b 100644 --- a/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java +++ b/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java @@ -33,6 +33,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.lang.reflect.Method; import java.net.ConnectException; import java.net.HttpURLConnection; @@ -632,13 +633,31 @@ public class TestSignatureInfo { private static File copy(File input) throws IOException { String extension = input.getName().replaceAll(".*?(\\.[^.]+)?$", "$1"); - if (extension == null || "".equals(extension)) extension = ".zip"; - File tmpFile = new File("build", "sigtest"+extension); - FileOutputStream fos = new FileOutputStream(tmpFile); - FileInputStream fis = new FileInputStream(input); - IOUtils.copy(fis, fos); - fis.close(); - fos.close(); + if (extension == null || "".equals(extension)) { + extension = ".zip"; + } + + // ensure that we create the "build" directory as it might not be existing + // in the Sonar Maven runs where we are at a different source directory + File buildDir = new File("build"); + if(!buildDir.exists()) { + assertTrue("Failed to create " + buildDir.getAbsolutePath(), + buildDir.mkdirs()); + } + File tmpFile = new File(buildDir, "sigtest"+extension); + + OutputStream fos = new FileOutputStream(tmpFile); + try { + InputStream fis = new FileInputStream(input); + try { + IOUtils.copy(fis, fos); + } finally { + fis.close(); + } + } finally { + fos.close(); + } + return tmpFile; } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index 2a7752c52..1409d4227 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -1923,6 +1923,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { @Test public void test57196_WorkbookEvaluator() { + String previousLogger = System.getProperty("org.apache.poi.util.POILogger"); //System.setProperty("org.apache.poi.util.POILogger", "org.apache.poi.util.SystemOutLogger"); //System.setProperty("poi.log.level", "3"); try { @@ -1990,7 +1991,11 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { workbookEvaluator.setDebugEvaluationOutputForNextEval(true); workbookEvaluator.evaluate(new XSSFEvaluationCell(cell)); } finally { - System.clearProperty("org.apache.poi.util.POILogger"); + if(previousLogger == null) { + System.clearProperty("org.apache.poi.util.POILogger"); + } else { + System.setProperty("org.apache.poi.util.POILogger", previousLogger); + } System.clearProperty("poi.log.level"); } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java index fbec25c67..6f8c3f087 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.usermodel; +import java.io.IOException; + import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; import org.apache.poi.ss.usermodel.BaseTestHyperlink; @@ -32,15 +34,6 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink { super(XSSFITestDataProvider.instance); } - @Override - protected void setUp() { - // Use system out logger - System.setProperty( - "org.apache.poi.util.POILogger", - "org.apache.poi.util.SystemOutLogger" - ); - } - public void testLoadExisting() { XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx"); assertEquals(3, workbook.getNumberOfSheets()); @@ -94,7 +87,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink { } } - public void testInvalidURLs() { + public void testInvalidURLs() throws IOException { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFCreationHelper createHelper = workbook.getCreationHelper(); @@ -111,6 +104,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink { } } + workbook.close(); } public void testLoadSave() { diff --git a/src/scratchpad/testcases/org/apache/poi/hdf/extractor/TestWordDocument.java b/src/scratchpad/testcases/org/apache/poi/hdf/extractor/TestWordDocument.java index f0941674f..e8c04a331 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdf/extractor/TestWordDocument.java +++ b/src/scratchpad/testcases/org/apache/poi/hdf/extractor/TestWordDocument.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import org.apache.poi.POIDataSamples; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFTestDataSamples; import org.apache.poi.hwpf.extractor.WordExtractor; @@ -38,7 +39,7 @@ public class TestWordDocument { //WordDocument.main(new String[] {"test-data/document/Word95.doc", "/tmp/test.doc"}); //WordDocument.main(new String[] {"test-data/document/Word6.doc", "/tmp/test.doc"}); - WordDocument.main(new String[] {"test-data/document/53446.doc", "/tmp/test.doc"}); + WordDocument.main(new String[] {POIDataSamples.getDocumentInstance().getFile("53446.doc").getAbsolutePath(), "/tmp/test.doc"}); } @SuppressWarnings("deprecation") @@ -53,7 +54,7 @@ public class TestWordDocument { assertTrue("Had: " + text, text.contains("Just a \u201Ctest\u201D")); extractor.close(); - WordDocument wordDoc = new WordDocument("test-data/document/47304.doc"); + WordDocument wordDoc = new WordDocument(POIDataSamples.getDocumentInstance().getFile("47304.doc").getAbsolutePath()); StringWriter docTextWriter = new StringWriter(); PrintWriter out = new PrintWriter(docTextWriter); diff --git a/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java b/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java index 5b632ce83..f7be2acf7 100644 --- a/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java +++ b/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java @@ -33,15 +33,6 @@ import org.apache.poi.util.DummyPOILogger; * @author Marc Johnson */ public final class TestRawDataBlock extends TestCase { - static { - // We always want to use our own - // logger - System.setProperty( - "org.apache.poi.util.POILogger", - "org.apache.poi.util.DummyPOILogger" - ); - } - /** * Test creating a normal RawDataBlock */ @@ -130,7 +121,7 @@ public final class TestRawDataBlock extends TestCase { assertEquals( "7 - Unable to read entire block; "+bts+" read before EOF; expected 512 bytes. Your document was either written by software that ignores the spec, or has been truncated!", - (String)(logger.logged.get(0)) + logger.logged.get(0) ); } else { assertEquals(0, logger.logged.size()); diff --git a/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java b/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java index 6dabfc043..91be31e34 100644 --- a/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java +++ b/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java @@ -32,15 +32,6 @@ import org.apache.poi.util.DummyPOILogger; * @author Marc Johnson */ public final class TestRawDataBlockList extends TestCase { - static { - // We always want to use our own - // logger - System.setProperty( - "org.apache.poi.util.POILogger", - "org.apache.poi.util.DummyPOILogger" - ); - } - /** * Test creating a normal RawDataBlockList */