use of org.openntf.nsfodp.commons.odp.JavaSource in project org.openntf.nsfodp by OpenNTF.
the class ODPCompiler method importJavaElements.
private void importJavaElements(NDXLImporter importer, NDatabase database, JavaSourceClassLoader classLoader, Set<String> compiledClassNames) throws Exception {
subTask(Messages.ODPCompiler_importingJava);
Map<Path, List<JavaSource>> javaSourceFiles = odp.getJavaSourceFiles();
for (Map.Entry<Path, List<JavaSource>> entry : javaSourceFiles.entrySet()) {
for (JavaSource source : entry.getValue()) {
Path filePath = entry.getKey().relativize(source.getDataFile());
String className = ODPUtil.toJavaClassName(filePath);
compiledClassNames.remove(className);
byte[] byteCode = classLoader.getClassByteCode(className);
Document dxlDoc = source.getDxl();
// $NON-NLS-1$
DXLUtil.writeItemFileData(dxlDoc, "$ClassData0", byteCode);
// $NON-NLS-1$
DXLUtil.writeItemNumber(dxlDoc, "$ClassSize0", byteCode.length);
List<String> classIndexItem = new ArrayList<>();
// $NON-NLS-1$
classIndexItem.add("WEB-INF/classes/" + ODPUtil.toJavaPath(className));
// Also look for any inner classes that were compiled
List<String> innerClasses = classLoader.getCompiledClassNames().stream().filter(// $NON-NLS-1$ //$NON-NLS-2$
cname -> cname.matches("^" + Pattern.quote(className) + "[\\.\\$].+$")).collect(Collectors.toList());
for (int i = 0; i < innerClasses.size(); i++) {
String innerClassName = innerClasses.get(i);
compiledClassNames.remove(innerClassName);
byte[] innerByteCode = classLoader.getClassByteCode(innerClassName);
// $NON-NLS-1$
DXLUtil.writeItemFileData(dxlDoc, "$ClassData" + (i + 1), innerByteCode);
// $NON-NLS-1$
DXLUtil.writeItemNumber(dxlDoc, "$ClassSize" + (i + 1), innerByteCode.length);
// $NON-NLS-1$
classIndexItem.add("WEB-INF/classes/" + ODPUtil.toJavaPath(innerClassName));
}
// $NON-NLS-1$
DXLUtil.writeItemString(dxlDoc, "$ClassIndexItem", true, classIndexItem.toArray(new CharSequence[classIndexItem.size()]));
importDxl(importer, NSFODPDomUtil.getXmlString(dxlDoc, null), database, MessageFormat.format(Messages.ODPCompiler_javaClassLabel, className));
}
}
// Create standalone class files for remaining classes
for (String leftoverClassName : compiledClassNames) {
// $NON-NLS-1$
String fileName = "WEB-INF/classes/" + ODPUtil.toJavaPath(leftoverClassName);
byte[] leftoverByteCode = classLoader.getClassByteCode(leftoverClassName);
// $NON-NLS-1$ //$NON-NLS-2$
CompilerUtil.importFileResource(importer, leftoverByteCode, database, fileName, "~C4g", "w");
}
}
Aggregations