JpaProcessor implements BootPlugin { public void process(Writer writer, List<Class<?>> annotatedList) throws Exception { Set<String> puNames = new HashSet<String>(); XMLOutputFactory xof = XMLOutputFactory.newInstance(); XMLStreamWriter w = new IndentingXMLStreamWriter(xof.createXMLStreamWriter(writer)); w.setDefaultNamespace("http: w.writeStartDocument(); w.writeStartElement("persistence"); w.writeAttribute("verson", "2.0"); for (Class<?> annotated : annotatedList) { PersistentUnit pu = annotated.getAnnotation(PersistentUnit.class); if (pu.name() == null || pu.name().isEmpty()) { throw new IOException("Missing persistent unit name"); } if (!puNames.add(pu.name())) { throw new IOException("Duplicate persistent unit name: " + pu.name()); } w.writeStartElement("persistence-unit"); w.writeAttribute("name", pu.name()); w.writeAttribute("transaction-type", pu.transactionType().toString()); writeElement(w, "description", pu.description()); String providerName = getProvider(pu); writeElement(w, "provider", providerName); writeElement(w, "jta-data-source", pu.jtaDataSource()); writeElement(w, "non-jta-data-source", pu.nonJtaDataSource()); Map<String, String> props = new HashMap<>(); addProperties(pu, props); addAnnProperties(annotated, props); if (props.size() > 0) { w.writeStartElement("properties"); for (String key : props.keySet()) { w.writeEmptyElement("property"); w.writeAttribute("name", key); w.writeAttribute("value", props.get(key)); } w.writeEndElement(); } w.writeEndElement(); } w.writeEndElement(); w.writeEndDocument(); w.flush(); w.close(); } JpaProcessor(); @Override Map<String, List<String>> enhance(List<Class<?>> annotatedList, File generatedDir,
                                StreamFactory streamFactory); void process(Writer writer, List<Class<?>> annotatedList); @Override Class<? extends Annotation> getAnnotation();  }
@Ignore @Test public void testProcess() throws Exception { JpaProcessor processor = new JpaProcessor(); Map<PersistentUnit, List<? extends AnnotationMirror>> units = new HashMap<>(); PersistentUnit pu = getTestPersitentUnit(); units.put(pu, Collections.emptyList()); URL url = this.getClass().getResource("/expected_persistence.xml"); byte[] encoded = Files.readAllBytes(new File(url.toURI()).toPath()); String expected = new String(encoded, Charset.forName("utf-8")); StringWriter writer = new StringWriter(); }