You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by jo...@apache.org on 2019/05/13 15:01:55 UTC

[cayenne] branch master updated: Ant cgen couldn't find third-party classes with Java 11 to generate Property instances for them.

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

johnthuss pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/master by this push:
     new 0cff591  Ant cgen couldn't find third-party classes with Java 11 to generate Property instances for them.
0cff591 is described below

commit 0cff591a809e1e0722c93a906e6a1ab653a149c9
Author: John Huss <jo...@apache.org>
AuthorDate: Mon May 13 09:49:17 2019 -0500

    Ant cgen couldn't find third-party classes with Java 11 to generate Property instances for them.
    
    This now follows the same classloader pattern used already by DbGeneratorTask.
---
 .../src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java | 5 +++++
 cayenne-cgen/src/main/java/org/apache/cayenne/gen/PropertyUtils.java | 1 +
 2 files changed, 6 insertions(+)

diff --git a/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java b/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
index dbbd9e3..5d1fc56 100644
--- a/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
+++ b/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java
@@ -103,6 +103,8 @@ public class CayenneGeneratorTask extends CayenneTask {
     public void execute() throws BuildException {
         validateAttributes();
 
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
         injector = new ToolsInjectorBuilder()
                 .addModule(new ToolsModule(LoggerFactory.getLogger(CayenneGeneratorTask.class)))
                 .create();
@@ -113,6 +115,7 @@ public class CayenneGeneratorTask extends CayenneTask {
         loadAction.setMainDataMapFile(map);
         loadAction.setAdditionalDataMapFiles(additionalMaps);
         try {
+            Thread.currentThread().setContextClassLoader(CayenneGeneratorTask.class.getClassLoader());
 
             DataMap dataMap = loadAction.getMainDataMap();
 
@@ -140,6 +143,8 @@ public class CayenneGeneratorTask extends CayenneTask {
         }
         catch (Exception e) {
             throw new BuildException(e);
+        } finally {
+            Thread.currentThread().setContextClassLoader(loader);
         }
     }
 
diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/PropertyUtils.java b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/PropertyUtils.java
index 06e0422..fb5371e 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/PropertyUtils.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/PropertyUtils.java
@@ -371,6 +371,7 @@ public class PropertyUtils {
                 }
             }
         } catch (DIRuntimeException ex) {
+            System.out.println("WARN: Class not found: " + attrType + ". Will use default PropertyDescriptor.");
             return PropertyDescriptor.defaultDescriptor();
         }
         return PropertyDescriptor.defaultDescriptor();