@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(); processor.process(writer, units); Assert.assertEquals(expected, writer.getBuffer().toString()); }
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Map<PersistentUnit, List<? extends AnnotationMirror>> units = new HashMap<PersistentUnit, List<? extends AnnotationMirror>>(); for (Element elem : roundEnv.getElementsAnnotatedWith(PersistentUnit.class)) { PersistentUnit pu = elem.getAnnotation(PersistentUnit.class); units.put(pu, elem.getAnnotationMirrors()); } if (!units.isEmpty()) { try { FileObject o = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", "META-INF/persistence.xml"); process(o.openWriter(), units); processingEnv.getMessager().printMessage(Kind.NOTE, "Generated META-INF/persistence.xml"); } catch (Exception e) { processingEnv.getMessager().printMessage(Kind.ERROR, "Error: " + e.getMessage()); } try (PrintWriter w = appendResource("META-INF/org.apache.karaf.boot.bnd")) { w.println("Private-Package: META-INF.*"); w.println("Meta-Persistence: META-INF/persistence.xml"); if (useHibernate) { w.println("Import-Package: org.hibernate.proxy, javassist.util.proxy"); } } catch (Exception e) { processingEnv.getMessager().printMessage(Kind.ERROR, "Error writing to META-INF/org.apache.karaf.boot.bnd: " + e.getMessage()); } } return true; }
JpaProcessor extends AbstractProcessor { @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Map<PersistentUnit, List<? extends AnnotationMirror>> units = new HashMap<PersistentUnit, List<? extends AnnotationMirror>>(); for (Element elem : roundEnv.getElementsAnnotatedWith(PersistentUnit.class)) { PersistentUnit pu = elem.getAnnotation(PersistentUnit.class); units.put(pu, elem.getAnnotationMirrors()); } if (!units.isEmpty()) { try { FileObject o = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", "META-INF/persistence.xml"); process(o.openWriter(), units); processingEnv.getMessager().printMessage(Kind.NOTE, "Generated META-INF/persistence.xml"); } catch (Exception e) { processingEnv.getMessager().printMessage(Kind.ERROR, "Error: " + e.getMessage()); } try (PrintWriter w = appendResource("META-INF/org.apache.karaf.boot.bnd")) { w.println("Private-Package: META-INF.*"); w.println("Meta-Persistence: META-INF/persistence.xml"); if (useHibernate) { w.println("Import-Package: org.hibernate.proxy, javassist.util.proxy"); } } catch (Exception e) { processingEnv.getMessager().printMessage(Kind.ERROR, "Error writing to META-INF/org.apache.karaf.boot.bnd: " + e.getMessage()); } } return true; } }
JpaProcessor extends AbstractProcessor { @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Map<PersistentUnit, List<? extends AnnotationMirror>> units = new HashMap<PersistentUnit, List<? extends AnnotationMirror>>(); for (Element elem : roundEnv.getElementsAnnotatedWith(PersistentUnit.class)) { PersistentUnit pu = elem.getAnnotation(PersistentUnit.class); units.put(pu, elem.getAnnotationMirrors()); } if (!units.isEmpty()) { try { FileObject o = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", "META-INF/persistence.xml"); process(o.openWriter(), units); processingEnv.getMessager().printMessage(Kind.NOTE, "Generated META-INF/persistence.xml"); } catch (Exception e) { processingEnv.getMessager().printMessage(Kind.ERROR, "Error: " + e.getMessage()); } try (PrintWriter w = appendResource("META-INF/org.apache.karaf.boot.bnd")) { w.println("Private-Package: META-INF.*"); w.println("Meta-Persistence: META-INF/persistence.xml"); if (useHibernate) { w.println("Import-Package: org.hibernate.proxy, javassist.util.proxy"); } } catch (Exception e) { processingEnv.getMessager().printMessage(Kind.ERROR, "Error writing to META-INF/org.apache.karaf.boot.bnd: " + e.getMessage()); } } return true; } JpaProcessor(); }
JpaProcessor extends AbstractProcessor { @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Map<PersistentUnit, List<? extends AnnotationMirror>> units = new HashMap<PersistentUnit, List<? extends AnnotationMirror>>(); for (Element elem : roundEnv.getElementsAnnotatedWith(PersistentUnit.class)) { PersistentUnit pu = elem.getAnnotation(PersistentUnit.class); units.put(pu, elem.getAnnotationMirrors()); } if (!units.isEmpty()) { try { FileObject o = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", "META-INF/persistence.xml"); process(o.openWriter(), units); processingEnv.getMessager().printMessage(Kind.NOTE, "Generated META-INF/persistence.xml"); } catch (Exception e) { processingEnv.getMessager().printMessage(Kind.ERROR, "Error: " + e.getMessage()); } try (PrintWriter w = appendResource("META-INF/org.apache.karaf.boot.bnd")) { w.println("Private-Package: META-INF.*"); w.println("Meta-Persistence: META-INF/persistence.xml"); if (useHibernate) { w.println("Import-Package: org.hibernate.proxy, javassist.util.proxy"); } } catch (Exception e) { processingEnv.getMessager().printMessage(Kind.ERROR, "Error writing to META-INF/org.apache.karaf.boot.bnd: " + e.getMessage()); } } return true; } JpaProcessor(); @Override Set<String> getSupportedAnnotationTypes(); @Override boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv); void process(Writer writer, Map<PersistentUnit, List<? extends AnnotationMirror>> units); }
JpaProcessor extends AbstractProcessor { @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Map<PersistentUnit, List<? extends AnnotationMirror>> units = new HashMap<PersistentUnit, List<? extends AnnotationMirror>>(); for (Element elem : roundEnv.getElementsAnnotatedWith(PersistentUnit.class)) { PersistentUnit pu = elem.getAnnotation(PersistentUnit.class); units.put(pu, elem.getAnnotationMirrors()); } if (!units.isEmpty()) { try { FileObject o = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", "META-INF/persistence.xml"); process(o.openWriter(), units); processingEnv.getMessager().printMessage(Kind.NOTE, "Generated META-INF/persistence.xml"); } catch (Exception e) { processingEnv.getMessager().printMessage(Kind.ERROR, "Error: " + e.getMessage()); } try (PrintWriter w = appendResource("META-INF/org.apache.karaf.boot.bnd")) { w.println("Private-Package: META-INF.*"); w.println("Meta-Persistence: META-INF/persistence.xml"); if (useHibernate) { w.println("Import-Package: org.hibernate.proxy, javassist.util.proxy"); } } catch (Exception e) { processingEnv.getMessager().printMessage(Kind.ERROR, "Error writing to META-INF/org.apache.karaf.boot.bnd: " + e.getMessage()); } } return true; } JpaProcessor(); @Override Set<String> getSupportedAnnotationTypes(); @Override boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv); void process(Writer writer, Map<PersistentUnit, List<? extends AnnotationMirror>> units);  }