add ooxml-schemas enum classes to poi-ooxml-schemas
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1841274 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c18375a4d0
commit
e930d76d7b
@ -17,6 +17,18 @@
|
|||||||
|
|
||||||
package org.apache.poi.ooxml.util;
|
package org.apache.poi.ooxml.util;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
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 java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@ -26,30 +38,11 @@ import java.security.AccessController;
|
|||||||
import java.security.CodeSource;
|
import java.security.CodeSource;
|
||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.Vector;
|
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.util.IOUtils;
|
|
||||||
import org.apache.poi.util.StringUtil;
|
|
||||||
import org.apache.poi.util.SuppressForbidden;
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a 'lite' version of the ooxml-schemas.jar
|
* Build a 'lite' version of the ooxml-schemas.jar
|
||||||
*
|
*
|
||||||
@ -194,28 +187,39 @@ public final class OOXMLLite {
|
|||||||
|
|
||||||
//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);
|
||||||
Map<String, Class<?>> classes = getLoadedClasses(_ooxmlJar.getName());
|
Set<Class<?>> classes = getLoadedClasses(_ooxmlJar.getName());
|
||||||
Set<String> packages = new HashSet<>();
|
Set<String> packages = new HashSet<>();
|
||||||
for (Class<?> cls : classes.values()) {
|
for (Class<?> cls : classes) {
|
||||||
copyFile(cls);
|
copyFile(cls);
|
||||||
packages.add(cls.getPackage().getName());
|
packages.add(cls.getPackage().getName());
|
||||||
|
|
||||||
if(cls.isInterface()){
|
if (cls.isInterface()) {
|
||||||
/// Copy classes and interfaces declared as members of this class
|
/// Copy classes and interfaces declared as members of this class
|
||||||
for(Class<?> fc : cls.getDeclaredClasses()){
|
for (Class<?> fc : cls.getDeclaredClasses()) {
|
||||||
copyFile(fc);
|
copyFile(fc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String pkg : packages) {
|
for (String pkg : packages) {
|
||||||
Reflections reflections = new Reflections(pkg);
|
Reflections reflections = new Reflections(pkg);
|
||||||
for (Class listClass : reflections.getSubTypesOf(List.class)) {
|
Set<Class<? extends List>> listClasses = reflections.getSubTypesOf(List.class);
|
||||||
for (Class<?> compare : classes.values()){
|
listClasses.removeAll(classes);
|
||||||
|
for (Class listClass : listClasses) {
|
||||||
|
for (Class<?> compare : classes) {
|
||||||
if (listClass.getName().startsWith(compare.getName())) {
|
if (listClass.getName().startsWith(compare.getName())) {
|
||||||
copyFile(listClass);
|
copyFile(listClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Set<Class<? extends StringEnumAbstractBase>> 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
|
//finally copy the compiled .xsb files
|
||||||
@ -307,10 +311,10 @@ public final class OOXMLLite {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param ptrn the pattern to filter output
|
* @param ptrn the pattern to filter output
|
||||||
* @return the classes loaded by the system class loader keyed by class name
|
* @return the classes loaded by the system class loader
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static Map<String, Class<?>> getLoadedClasses(String ptrn) {
|
private static Set<Class<?>> getLoadedClasses(String ptrn) {
|
||||||
// make the field accessible, we defer this from static initialization to here to
|
// 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
|
// 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
|
// without failing, see https://issues.apache.org/bugzilla/show_bug.cgi?id=56550
|
||||||
@ -331,7 +335,7 @@ public final class OOXMLLite {
|
|||||||
ClassLoader appLoader = ClassLoader.getSystemClassLoader();
|
ClassLoader appLoader = ClassLoader.getSystemClassLoader();
|
||||||
try {
|
try {
|
||||||
Vector<Class<?>> classes = (Vector<Class<?>>) _classes.get(appLoader);
|
Vector<Class<?>> classes = (Vector<Class<?>>) _classes.get(appLoader);
|
||||||
Map<String, Class<?>> map = new HashMap<>();
|
Set<Class<?>> set = new HashSet<>();
|
||||||
for (Class<?> cls : classes) {
|
for (Class<?> cls : classes) {
|
||||||
// e.g. proxy-classes, ...
|
// e.g. proxy-classes, ...
|
||||||
ProtectionDomain pd = cls.getProtectionDomain();
|
ProtectionDomain pd = cls.getProtectionDomain();
|
||||||
@ -343,10 +347,10 @@ public final class OOXMLLite {
|
|||||||
|
|
||||||
String jar = loc.toString();
|
String jar = loc.toString();
|
||||||
if (jar.contains(ptrn)) {
|
if (jar.contains(ptrn)) {
|
||||||
map.put(cls.getName(), cls);
|
set.add(cls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return map;
|
return set;
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user