[ 
https://issues.apache.org/jira/browse/DRILL-7483?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16997421#comment-16997421
 ] 

ASF GitHub Bot commented on DRILL-7483:
---------------------------------------

vvysotskyi commented on pull request #1935: DRILL-7483: Add support for 12 and 
13 java versions
URL: https://github.com/apache/drill/pull/1935#discussion_r358248527
 
 

 ##########
 File path: 
metastore/iceberg-metastore/src/test/java/org/apache/drill/metastore/iceberg/schema/TestIcebergTableSchema.java
 ##########
 @@ -238,63 +238,120 @@ void addFields(JDefinedClass jDefinedClass) {
    * Generates and loads class at the runtime with specified fields.
    * Fields may or may not be annotated.
    */
-  private abstract class ClassGenerator {
-
-    final int DEFAULT_FIELD_MODE = JMod.PRIVATE;
+  private static abstract class ClassGenerator {
 
     private final String name;
 
     ClassGenerator(String name) {
       this.name = name;
     }
 
-    Class<?> generate() throws JClassAlreadyExistsException, IOException, 
ClassNotFoundException {
-      JCodeModel jCodeModel = prepareModel();
-      ByteArrayStreamCodeWriter codeWriter = new ByteArrayStreamCodeWriter();
-      jCodeModel.build(codeWriter);
+    Class<?> generate() {
+      ClassWriter classWriter = generateClass();
 
-      String sourceCode = codeWriter.sourceCode();
-      return CompilerUtils.CACHED_COMPILER.loadFromJava(name, sourceCode);
+      byte[] bytes = classWriter.toByteArray();
+      return new ClassLoader() {
+        public Class<?> injectClass(String name, byte[] classBytes) {
+          return defineClass(name, classBytes, 0, classBytes.length);
+        }
+      }.injectClass(name, bytes);
     }
 
-    private JCodeModel prepareModel() throws JClassAlreadyExistsException {
-      JCodeModel jCodeModel = new JCodeModel();
-      JPackage jPackage = jCodeModel._package("");
-      JDefinedClass jDefinedClass = jPackage._class(name);
-      addFields(jDefinedClass);
-      return jCodeModel;
+    public FieldVisitor addField(ClassWriter classWriter, int access, String 
fieldName, Class<?> clazz, Class<?>... genericTypes) {
+      String descriptor = Type.getType(clazz).getDescriptor();
+
+      String signature = null;
+
+      if (genericTypes.length > 0) {
+        FieldSignatureBuilder fieldSignatureBuilder = 
FieldSignatureBuilder.builder()
+            .declareType(clazz)
+            .startGeneric();
+        for (Class<?> genericType : genericTypes) {
+          fieldSignatureBuilder
+              .declareType(genericType)
+              .endType();
+        }
+        signature = fieldSignatureBuilder
+            .endGeneric()
+            .endType()
+            .buildSignature();
+      }
+
+      return classWriter.visitField(access, fieldName, descriptor, signature, 
null);
     }
 
-    void annotate(JFieldVar field) {
-      annotate(field, MetadataType.ALL);
+    void annotate(FieldVisitor field) {
+      
field.visitAnnotation(Type.getType(MetastoreFieldDefinition.class).getDescriptor(),
 true);
     }
 
-    void annotate(JFieldVar field, MetadataType... scopes) {
-      JAnnotationUse annotate = field.annotate(MetastoreFieldDefinition.class);
-      assert scopes.length != 0;
-      JAnnotationArrayMember scopesParam = annotate.paramArray("scopes");
-      Stream.of(scopes).forEach(scopesParam::param);
+    private ClassWriter generateClass() {
+      ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
+      classWriter.visit(V1_8, ACC_PUBLIC, name, null, 
Type.getInternalName(Object.class), null);
+      addFields(classWriter);
+      classWriter.visitEnd();
+
+      return classWriter;
     }
 
-    abstract void addFields(JDefinedClass jDefinedClass);
+    abstract void addFields(ClassWriter classWriter);
+  }
 
-    private class ByteArrayStreamCodeWriter extends CodeWriter {
+  /**
+   * Helper class for constructing field type signature string.
 
 Review comment:
   Thanks, done.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Add support for 12 and 13 java versions
> ---------------------------------------
>
>                 Key: DRILL-7483
>                 URL: https://issues.apache.org/jira/browse/DRILL-7483
>             Project: Apache Drill
>          Issue Type: Improvement
>          Components: Tools, Build &amp; Test
>    Affects Versions: 1.16.0
>            Reporter: Vitalii Diravka
>            Assignee: Vova Vysotskyi
>            Priority: Major
>             Fix For: 1.17.0
>
>
> The latest versions are Java 13, released in October 2019
> {code:java}
> [INFO] --- maven-enforcer-plugin:3.0.0-M2:enforce 
> (validate_java_and_maven_version) @ drill-root ---
> [WARNING] Rule 1: org.apache.maven.plugins.enforcer.RequireJavaVersion failed 
> with message:
> Detected JDK Version: 13.0.1 is not in the allowed range [1.8,12)
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to