mirror of https://github.com/apache/poi.git
Fail build if test-cases fail in OOXMLLite execution to avoid missing included schema-classes. Also adjust how we look for test-classes so that we print out the ones that we skip with known ones excluded. Also print out skipped inner classes.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1637475 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5f50592706
commit
b604190ffa
|
@ -1034,7 +1034,8 @@ under the License.
|
||||||
<zipfileset includes="**/*" src="${ooxml.security.jar}"/>
|
<zipfileset includes="**/*" src="${ooxml.security.jar}"/>
|
||||||
</jar>
|
</jar>
|
||||||
|
|
||||||
<java classname="org.apache.poi.util.OOXMLLite" fork="yes">
|
<java classname="org.apache.poi.util.OOXMLLite" fork="yes"
|
||||||
|
failonerror="true">
|
||||||
<classpath>
|
<classpath>
|
||||||
<pathelement path="${ooxml.lite-merged.dir}/ooxml-lite-merged.jar"/>
|
<pathelement path="${ooxml.lite-merged.dir}/ooxml-lite-merged.jar"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -35,6 +35,7 @@ import java.util.jar.JarFile;
|
||||||
|
|
||||||
import junit.framework.JUnit4TestAdapter;
|
import junit.framework.JUnit4TestAdapter;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
import junit.framework.TestResult;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
import junit.textui.TestRunner;
|
import junit.textui.TestRunner;
|
||||||
|
|
||||||
|
@ -88,6 +89,7 @@ public final class OOXMLLite {
|
||||||
else if (args[i].equals("-test")) test = args[++i];
|
else if (args[i].equals("-test")) test = args[++i];
|
||||||
else if (args[i].equals("-ooxml")) ooxml = args[++i];
|
else if (args[i].equals("-ooxml")) ooxml = args[++i];
|
||||||
}
|
}
|
||||||
|
|
||||||
OOXMLLite builder = new OOXMLLite(dest, test, ooxml);
|
OOXMLLite builder = new OOXMLLite(dest, test, ooxml);
|
||||||
builder.build();
|
builder.build();
|
||||||
}
|
}
|
||||||
|
@ -97,23 +99,24 @@ public final class OOXMLLite {
|
||||||
List<String> lst = new ArrayList<String>();
|
List<String> lst = new ArrayList<String>();
|
||||||
//collect unit tests
|
//collect unit tests
|
||||||
System.out.println("Collecting unit tests from " + _testDir);
|
System.out.println("Collecting unit tests from " + _testDir);
|
||||||
collectTests(_testDir, _testDir, lst, ".+?\\.Test.+?\\.class$", ".+TestUnfixedBugs.class");
|
collectTests(_testDir, _testDir, lst, ".+.class$",
|
||||||
System.out.println("Found " + lst.size() + " tests");
|
".+(TestUnfixedBugs|MemoryUsage|TestDataProvider|TestDataSamples|All.+Tests|ZipFileAssert|PkiTestUtils|TestCellFormatPart\\$\\d|TestSignatureInfo\\$\\d).class");
|
||||||
|
System.out.println("Found " + lst.size() + " classes");
|
||||||
|
|
||||||
TestSuite suite = new TestSuite();
|
TestSuite suite = new TestSuite();
|
||||||
for (String arg : lst) {
|
for (String arg : lst) {
|
||||||
//ignore inner classes defined in tests
|
//ignore inner classes defined in tests
|
||||||
if (arg.indexOf('$') != -1) continue;
|
if (arg.indexOf('$') != -1) {
|
||||||
|
System.out.println("Inner class " + arg + " not included");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
String cls = arg.replace(".class", "");
|
String cls = arg.replace(".class", "");
|
||||||
try {
|
try {
|
||||||
Class<?> testclass = Class.forName(cls);
|
Class<?> testclass = Class.forName(cls);
|
||||||
boolean isTest = TestCase.class.isAssignableFrom(testclass);
|
boolean isTest = TestCase.class.isAssignableFrom(testclass);
|
||||||
if (!isTest) {
|
if (!isTest) {
|
||||||
for (Method m : testclass.getDeclaredMethods()) {
|
isTest = checkForTestAnnotation(testclass);
|
||||||
isTest = m.isAnnotationPresent(Test.class);
|
|
||||||
if (isTest) break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isTest) {
|
if (isTest) {
|
||||||
|
@ -124,8 +127,13 @@ public final class OOXMLLite {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("Resulting TestSuite has " + suite.testCount() + " TestCases");
|
||||||
|
|
||||||
//run tests
|
//run tests
|
||||||
TestRunner.run(suite);
|
TestResult result = TestRunner.run(suite);
|
||||||
|
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
|
//see what classes from the ooxml-schemas.jar are loaded
|
||||||
System.out.println("Copying classes to " + _destDest);
|
System.out.println("Copying classes to " + _destDest);
|
||||||
|
@ -152,14 +160,33 @@ public final class OOXMLLite {
|
||||||
//finally copy the compiled .xsb files
|
//finally copy the compiled .xsb files
|
||||||
System.out.println("Copying .xsb resources");
|
System.out.println("Copying .xsb resources");
|
||||||
JarFile jar = new JarFile(_ooxmlJar);
|
JarFile jar = new JarFile(_ooxmlJar);
|
||||||
for(Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements(); ){
|
try {
|
||||||
JarEntry je = e.nextElement();
|
for(Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements(); ){
|
||||||
if(je.getName().matches("schemaorg_apache_xmlbeans/system/\\w+/\\w+\\.xsb")) {
|
JarEntry je = e.nextElement();
|
||||||
File destFile = new File(_destDest, je.getName());
|
if(je.getName().matches("schemaorg_apache_xmlbeans/system/\\w+/\\w+\\.xsb")) {
|
||||||
copyFile(jar.getInputStream(je), destFile);
|
File destFile = new File(_destDest, je.getName());
|
||||||
|
copyFile(jar.getInputStream(je), destFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
jar.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkForTestAnnotation(Class<?> testclass) {
|
||||||
|
for (Method m : testclass.getDeclaredMethods()) {
|
||||||
|
if(m.isAnnotationPresent(Test.class)) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jar.close();
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -194,12 +221,14 @@ public final class OOXMLLite {
|
||||||
Vector<Class<?>> classes = (Vector<Class<?>>) _classes.get(appLoader);
|
Vector<Class<?>> classes = (Vector<Class<?>>) _classes.get(appLoader);
|
||||||
Map<String, Class<?>> map = new HashMap<String, Class<?>>();
|
Map<String, Class<?>> map = new HashMap<String, Class<?>>();
|
||||||
for (Class<?> cls : classes) {
|
for (Class<?> cls : classes) {
|
||||||
try {
|
// e.g. proxy-classes, ...
|
||||||
String jar = cls.getProtectionDomain().getCodeSource().getLocation().toString();
|
if(cls.getProtectionDomain() == null ||
|
||||||
if(jar.indexOf(ptrn) != -1) map.put(cls.getName(), cls);
|
cls.getProtectionDomain().getCodeSource() == null) {
|
||||||
} catch (NullPointerException e) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String jar = cls.getProtectionDomain().getCodeSource().getLocation().toString();
|
||||||
|
if(jar.indexOf(ptrn) != -1) map.put(cls.getName(), cls);
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
|
@ -216,6 +245,6 @@ public final class OOXMLLite {
|
||||||
} finally {
|
} finally {
|
||||||
destStream.close();
|
destStream.close();
|
||||||
}
|
}
|
||||||
|
//System.out.println("Copied file to " + destFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue