private Map enhance(StoreDesc sdesc, List<Map> entities, List<String> classNames) throws Exception { File outDir1 = new File(sdesc.getBaseDir(), "classes"); if (!outDir1.exists()) { outDir1.mkdirs(); } File[] locations = new File[1]; locations[0] = outDir1; System.out.println("Enhancer.enhance:" + sdesc); FileSystemClassLoader fscl = new FileSystemClassLoader(this.getClass().getClassLoader(), locations); JDOEnhancer enhancer = m_nucleusService.getEnhancer(sdesc); enhancer.setClassLoader(fscl); if (enhancer != null) { for (String className : classNames) { File file = new File(outDir1, className.replace(".", "/")); if (jdoStore(entities, className)) { System.out.println("DomainObjectsServiceImpl.enhancer.add:" + file); enhancer.addClasses(file.toString() + ".class"); } } enhancer.enhance(); } try { System.out.println("Enhancer.close:" + sdesc); m_nucleusService.close(sdesc); } catch (Exception e) { System.out.println("Nucleus.close.ex:" + e); } return new HashMap(); }
public Map compile(StoreDesc sdesc, List<Map> entities, List<String> srcFiles) throws Exception { File outDir1 = new File(sdesc.getBaseDir(), "classes"); if (!outDir1.exists()) { outDir1.mkdirs(); } File[] locations = new File[1]; locations[0] = outDir1; FileSystemClassLoader fscl = new FileSystemClassLoader(this.getClass().getClassLoader(), locations); JDOEnhancer enhancer = m_nucleusService.getEnhancer(sdesc); enhancer.setClassLoader(fscl); final Options options = new Options(); options.put(Options.KEY_SOURCE_VERSION, Options.VERSION_1_6); options.put(Options.KEY_TARGET_VERSION, Options.VERSION_1_6); options.put(Options.KEY_CLASS_LOADER_WRITER, createClassWriter(outDir1)); options.put(Options.KEY_CLASS_LOADER, fscl); CompilationUnit[] cus = new CompilationUnit[srcFiles.size()]; int i = 0; for (String src : srcFiles) { cus[i++] = createCompileUnit(src); } CompilationResult result = m_javaCompiler.compile(cus, options); System.out.println("result:" + result); if (result != null && result.getErrors() != null) { List<String> errorList = new ArrayList(); for (CompilerMessage msg : result.getErrors()) { String ms = msg.getFile() + ":" + msg.getLine() + "=>" + msg.getMessage(); errorList.add(ms); } Map retMap = new HashMap(); System.out.println("result:" + errorList); retMap.put("errors", errorList); return retMap; } else { if (enhancer != null) { for (int c = 0; c < cus.length; c++) { String className = cus[c].getMainClassName(); File file = new File(outDir1, className.replace(".", "/")); if (jdoStore(entities, className)) { System.out.println("DomainObjectsServiceImpl.enhancer.add:" + file); enhancer.addClasses(file.toString() + ".class"); } } enhancer.enhance(); } try { m_nucleusService.close(sdesc); } catch (Exception e) { System.out.println("CLOSE:" + e); } return new HashMap(); } }