karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [32/35] karaf-boot git commit: Add META-INF to Private-Packages to add the persistence.xml
Date Mon, 09 May 2016 14:48:51 GMT
Add META-INF to Private-Packages to add the persistence.xml


Project: http://git-wip-us.apache.org/repos/asf/karaf-boot/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-boot/commit/4860b601
Tree: http://git-wip-us.apache.org/repos/asf/karaf-boot/tree/4860b601
Diff: http://git-wip-us.apache.org/repos/asf/karaf-boot/diff/4860b601

Branch: refs/heads/master
Commit: 4860b601478eed6a0dac8d4058ce37d329f7e1c4
Parents: a55895f
Author: Christian Schneider <chris@die-schneider.net>
Authored: Tue Apr 26 14:14:07 2016 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Tue Apr 26 14:14:07 2016 +0200

----------------------------------------------------------------------
 samples/jpa/pom.xml                             |  2 +-
 .../karaf/boot/jpa/impl/JpaProcessor.java       | 39 +++++++++++++++++++-
 2 files changed, 39 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/4860b601/samples/jpa/pom.xml
----------------------------------------------------------------------
diff --git a/samples/jpa/pom.xml b/samples/jpa/pom.xml
index 1c51404..f745ab2 100644
--- a/samples/jpa/pom.xml
+++ b/samples/jpa/pom.xml
@@ -26,7 +26,7 @@
             <version>${project.version}</version>
         </dependency>
     </dependencies>
-
+    
     <build>
         <plugins>
             <plugin>

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/4860b601/starters/karaf-boot-starter-jpa/src/main/java/org/apache/karaf/boot/jpa/impl/JpaProcessor.java
----------------------------------------------------------------------
diff --git a/starters/karaf-boot-starter-jpa/src/main/java/org/apache/karaf/boot/jpa/impl/JpaProcessor.java
b/starters/karaf-boot-starter-jpa/src/main/java/org/apache/karaf/boot/jpa/impl/JpaProcessor.java
index f257238..f160fec 100644
--- a/starters/karaf-boot-starter-jpa/src/main/java/org/apache/karaf/boot/jpa/impl/JpaProcessor.java
+++ b/starters/karaf-boot-starter-jpa/src/main/java/org/apache/karaf/boot/jpa/impl/JpaProcessor.java
@@ -1,6 +1,9 @@
 package org.apache.karaf.boot.jpa.impl;
 
+import java.io.CharArrayWriter;
 import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Reader;
 import java.io.Writer;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -48,13 +51,18 @@ public class JpaProcessor extends AbstractProcessor {
         }
         if (!units.isEmpty()) {
             try {
-                FileObject o = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT,
+                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");
+            } catch (Exception e) {
+                processingEnv.getMessager().printMessage(Kind.ERROR, "Error writing to META-INF/org.apache.karaf.boot.bnd:
" + e.getMessage());
+            }
         }
         return true;
     }
@@ -168,4 +176,33 @@ public class JpaProcessor extends AbstractProcessor {
         }
     }
 
+    private PrintWriter appendResource(String resource) throws IOException {
+        try {
+            FileObject o = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT,
"",
+                                                                   resource);
+            return new PrintWriter(o.openWriter());
+        } catch (Exception e) {
+            try {
+                FileObject o = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT,
"",
+                                                                    resource);
+                CharArrayWriter baos = new CharArrayWriter();
+                try (Reader r = o.openReader(true)) {
+                    char[] buf = new char[4096];
+                    int l;
+                    while ((l = r.read(buf)) > 0) {
+                        baos.write(buf, 0, l);
+                    }
+                }
+                o.delete();
+                o = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT,
"", resource);
+                Writer w = o.openWriter();
+                w.write(baos.toCharArray());
+                return new PrintWriter(w);
+            } catch (Exception e2) {
+                e2.addSuppressed(e);
+                e2.printStackTrace();
+                throw e2;
+            }
+        }
+    }
 }


Mime
View raw message