List of usage examples for javax.tools JavaFileObject delete
boolean delete();
From source file:com.thoratou.exact.processors.ExactProcessor.java
private void writeSources(HashMap<String, List<PathStep>> mergedMap) throws IOException, ClassNotFoundException, ExactException { //use all annotation data to generate parsing files for (Map.Entry<String, List<PathStep>> entryList : mergedMap.entrySet()) { VelocityEngine engine = new VelocityEngine(); //needed it avoid global instead of local variable modification engine.setProperty(RuntimeConstants.VM_CONTEXT_LOCALSCOPE, true); //read file into JAR InputStream configStream = getClass().getResourceAsStream("/xmlreader.vm"); BufferedReader configReader = new BufferedReader(new InputStreamReader(configStream, "UTF-8")); String className = entryList.getKey(); List<PathStep> steps = entryList.getValue(); VelocityContext context = new VelocityContext(); context.put("class", className); //logger.info("class : "+className); //ugly temp code String[] split = className.split("\\."); StringBuffer packageBuffer = new StringBuffer(); for (int i = 0; i < split.length - 1; i++) { packageBuffer.append(split[i]); if (i != split.length - 2) { packageBuffer.append("."); }//from ww w . jav a 2s . co m } String packageName = packageBuffer.toString(); //logger.info("package : "+packageName); context.put("package", packageName); String simpleName = split[split.length - 1]; //logger.info("simpleclass : "+simpleName); context.put("simpleclass", simpleName); context.put("steps", steps); context.put("kindmap", PathStep.ReverseKindMap); context.put("startmap", PathStep.ReverseStartMap); context.put("typemap", PathStep.ReverseTypeMap); context.put("listtypemap", PathStep.ReverseListTypeMap); context.put("indentutil", new IndentUtil()); context.put("processingutil", new ProcessingUtil()); Set<String> bomList = new HashSet<String>(); registerBomListFromSteps(steps, bomList); context.put("bomlist", bomList); Set<String> extensionList = new HashSet<String>(); Map<String, ExtensionVelocityData> extensionMap = new HashMap<String, ExtensionVelocityData>(); registerExtensionListFromSteps(steps, extensionList, extensionMap); context.put("extensionlist", extensionList); context.put("extensionmap", extensionMap); logger.info("input velocity data : " + className + " , " + steps.toString()); //StringWriter writer = new StringWriter(); //String packagePath = packageName.replace(".","/"); //String fullFile = packagePath+"/"+simpleName+"XmlReader.java"; //logger.info(fullFile); Filer filer = processingEnv.getFiler(); JavaFileObject sourceFile = filer.createSourceFile(className + "XmlReader"); Writer sourceWriter = sourceFile.openWriter(); engine.evaluate(context, sourceWriter, "", configReader); sourceWriter.close(); sourceFile.delete(); //logger.info("final velocity data : "+writer.getBuffer().toString()); } }