You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/10/28 11:05:07 UTC

[camel] branch main updated (be5270c6418 -> 714d9d57b63)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


    from be5270c6418 Regen for commit 9836d058cce9872c9cdf4adbff3a36e89e4e8d36
     new 90fd7cd3424 Java DSL - Include more detailed compilation error in exception.
     new 714d9d57b63 Java DSL - Fix classloading to use same loader in the same compilation unit.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/dsl/java/joor/ByteArrayClassLoader.java  |  2 +-
 .../apache/camel/dsl/java/joor/MultiCompile.java   | 24 ++++++++++++++++------
 2 files changed, 19 insertions(+), 7 deletions(-)


[camel] 01/02: Java DSL - Include more detailed compilation error in exception.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 90fd7cd3424264189c0db37d8a38b9a9258baab6
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Oct 28 11:10:25 2022 +0200

    Java DSL - Include more detailed compilation error in exception.
---
 .../apache/camel/dsl/java/joor/MultiCompile.java   | 26 ++++++++++++++++------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/MultiCompile.java b/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/MultiCompile.java
index a9d1ccbeca9..66beffe4f74 100644
--- a/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/MultiCompile.java
+++ b/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/MultiCompile.java
@@ -35,11 +35,16 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.StringJoiner;
+import java.util.stream.Collectors;
 
+import javax.tools.Diagnostic;
+import javax.tools.DiagnosticCollector;
 import javax.tools.FileObject;
 import javax.tools.ForwardingJavaFileManager;
 import javax.tools.JavaCompiler;
 import javax.tools.JavaCompiler.CompilationTask;
+import javax.tools.JavaFileObject;
 import javax.tools.SimpleJavaFileObject;
 import javax.tools.StandardJavaFileManager;
 import javax.tools.ToolProvider;
@@ -64,8 +69,8 @@ public final class MultiCompile {
     /**
      * Compiles multiple files as one unit
      *
-     * @param  unit the files to compile in the same unit
-     * @return      the compilation result
+     * @param unit the files to compile in the same unit
+     * @return the compilation result
      */
     public static CompilationUnit.Result compileUnit(CompilationUnit unit) {
         CompilationUnit.Result result = CompilationUnit.result();
@@ -122,12 +127,19 @@ public final class MultiCompile {
                 options.addAll(Arrays.asList("-classpath", classpath.toString()));
             }
 
-            CompilationTask task = compiler.getTask(out, fileManager, null, options, null, files);
+            DiagnosticCollector<javax.tools.JavaFileObject> dc = new DiagnosticCollector<>();
+            CompilationTask task = compiler.getTask(out, fileManager, dc, options, null, files);
 
-            task.call();
-
-            if (fileManager.isEmpty()) {
-                throw new ReflectException("Compilation error: " + out);
+            boolean success = task.call();
+            if (!success || fileManager.isEmpty()) {
+                if (dc.getDiagnostics().isEmpty()) {
+                    throw new ReflectException("Compilation error:\n" + out);
+                } else {
+                    // grab detailed error so we can see compilation errors
+                    StringJoiner sj = new StringJoiner("\n");
+                    dc.getDiagnostics().stream().filter(d -> Diagnostic.Kind.ERROR.equals(d.getKind())).forEach(d -> sj.add(d.toString()));
+                    throw new ReflectException("Compilation error:\n" + sj + "\n" + out);
+                }
             }
 
             // This method is called by client code from two levels up the current stack frame


[camel] 02/02: Java DSL - Fix classloading to use same loader in the same compilation unit.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 714d9d57b631b47c3d6f896bd83ffe4bb42b0e5a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Oct 28 13:04:41 2022 +0200

    Java DSL - Fix classloading to use same loader in the same compilation unit.
---
 .../org/apache/camel/dsl/java/joor/ByteArrayClassLoader.java   |  2 +-
 .../main/java/org/apache/camel/dsl/java/joor/MultiCompile.java | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/ByteArrayClassLoader.java b/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/ByteArrayClassLoader.java
index da1dd726116..ed6f8d8914c 100644
--- a/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/ByteArrayClassLoader.java
+++ b/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/ByteArrayClassLoader.java
@@ -22,11 +22,11 @@ import java.util.Map;
  * {@link ClassLoader} that loads byte code from a byte array.
  */
 final class ByteArrayClassLoader extends ClassLoader {
+
     private final Map<String, byte[]> classes;
 
     public ByteArrayClassLoader(Map<String, byte[]> classes) {
         super(ByteArrayClassLoader.class.getClassLoader());
-
         this.classes = classes;
     }
 
diff --git a/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/MultiCompile.java b/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/MultiCompile.java
index 66beffe4f74..c275e7f157f 100644
--- a/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/MultiCompile.java
+++ b/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/MultiCompile.java
@@ -36,7 +36,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.StringJoiner;
-import java.util.stream.Collectors;
 
 import javax.tools.Diagnostic;
 import javax.tools.DiagnosticCollector;
@@ -69,8 +68,8 @@ public final class MultiCompile {
     /**
      * Compiles multiple files as one unit
      *
-     * @param unit the files to compile in the same unit
-     * @return the compilation result
+     * @param  unit the files to compile in the same unit
+     * @return      the compilation result
      */
     public static CompilationUnit.Result compileUnit(CompilationUnit unit) {
         CompilationUnit.Result result = CompilationUnit.result();
@@ -137,7 +136,8 @@ public final class MultiCompile {
                 } else {
                     // grab detailed error so we can see compilation errors
                     StringJoiner sj = new StringJoiner("\n");
-                    dc.getDiagnostics().stream().filter(d -> Diagnostic.Kind.ERROR.equals(d.getKind())).forEach(d -> sj.add(d.toString()));
+                    dc.getDiagnostics().stream().filter(d -> Diagnostic.Kind.ERROR.equals(d.getKind()))
+                            .forEach(d -> sj.add(d.toString()));
                     throw new ReflectException("Compilation error:\n" + sj + "\n" + out);
                 }
             }
@@ -146,6 +146,7 @@ public final class MultiCompile {
             // We need a private-access lookup from the class in that stack frame in order to get
             // private-access to any local interfaces at that location.
             int index = 2;
+            ByteArrayClassLoader c = new ByteArrayClassLoader(fileManager.classes());
             for (CharSequenceJavaFileObject f : files) {
                 String className = f.getClassName();
 
@@ -177,7 +178,6 @@ public final class MultiCompile {
                 } else {
                     // Otherwise, use an arbitrary class loader. This approach doesn't allow for
                     // loading private-access interfaces in the compiled class's type hierarchy
-                    ByteArrayClassLoader c = new ByteArrayClassLoader(fileManager.classes());
                     final Map<String, byte[]> byteCodes = new HashMap<>();
                     Class<?> clazz = fileManager.loadAndReturnMainClass(className,
                             (name, bytes) -> {