fjtirado commented on code in PR #3881:
URL: 
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3881#discussion_r2030945036


##########
kogito-codegen-modules/kogito-codegen-manager/src/main/java/org/kie/kogito/codegen/manager/util/CodeGenManagerUtil.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.codegen.manager.util;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.lang.reflect.Modifier;
+import java.net.URLClassLoader;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.PathMatcher;
+import java.util.Optional;
+import java.util.function.Predicate;
+import java.util.stream.Stream;
+
+import org.drools.codegen.common.AppPaths;
+import org.drools.codegen.common.DroolsModelBuildContext;
+import org.drools.model.codegen.project.RuleCodegen;
+import org.kie.kogito.KogitoGAV;
+import org.kie.kogito.codegen.api.Generator;
+import org.kie.kogito.codegen.api.context.KogitoBuildContext;
+import org.kie.kogito.codegen.api.context.impl.JavaKogitoBuildContext;
+import org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext;
+import org.kie.kogito.codegen.api.context.impl.SpringBootKogitoBuildContext;
+import org.kie.kogito.codegen.decision.DecisionCodegen;
+import org.kie.kogito.codegen.prediction.PredictionCodegen;
+import org.kie.kogito.codegen.process.ProcessCodegen;
+import org.kie.kogito.codegen.process.persistence.PersistenceGenerator;
+import org.reflections.Reflections;
+import org.reflections.util.ConfigurationBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CodeGenManagerUtil {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(CodeGenManagerUtil.class);
+    public static final PathMatcher DRL_FILE_MATCHER = 
FileSystems.getDefault().getPathMatcher("glob:**.drl");
+
+    public enum Framework {
+        QUARKUS,
+        SPRING,
+        NONE

Review Comment:
   I'm not sure if it is wise to keep NONE (or pure Java) code generator. Is is 
really need? Does somebody knows what is used for? 
   Note this is probably not something to dicuss on the PR, but as overall 
strategy



##########
kogito-codegen-modules/kogito-codegen-manager/src/main/java/org/kie/kogito/codegen/manager/CompilerHelper.java:
##########
@@ -93,21 +98,37 @@ static void 
compileAndWriteClasses(Collection<GeneratedFile> generatedClasses, C
         }
 
         if (sources.length > 0) {
+            CompilationResult result = JAVA_COMPILER.compile(sources, srcMfs, 
trgMfs, classLoader, javaCompilerSettings);
 
-            CompilationResult result = JAVA_COMPILER.compile(sources, srcMfs, 
trgMfs, cl, settings);
             if (result.getErrors().length > 0) {
-                throw new 
MojoFailureException(Arrays.toString(result.getErrors()));
+                throw new 
IllegalStateException(Arrays.stream(result.getErrors())
+                        .map(CompilationProblem::getMessage)
+                        .collect(Collectors.joining(",")));
             }
 
             for (PortablePath path : trgMfs.getFilePaths()) {
                 byte[] data = trgMfs.getBytes(path);
-                writeGeneratedFile(new 
GeneratedFile(GeneratedFileType.COMPILED_CLASS, path.asString(), data), 
fileWriter, log);
+                writeGeneratedFile(new 
GeneratedFile(GeneratedFileType.COMPILED_CLASS, path.asString(), data), 
fileWriter);
             }
         }
     }
 
-    private static GeneratedFileWriter getGeneratedFileWriter(File baseDir) {
-        return generatedFileWriterBuilder
-                .build(Path.of(baseDir.getAbsolutePath()));
+    static GeneratedFileWriter getGeneratedFileWriter(File baseDir) {
+        return 
GENERATED_FILE_WRITER_BUILDER.build(Path.of(baseDir.getAbsolutePath()));
+    }
+
+    static JavaCompilerSettings getJavaCompilerSettings(List<String> 
runtimeClassPathElements,

Review Comment:
   Picky comment. 
   Since we are changing notation of methods in other places (nice addition), I 
think this method should be called buildJavaCompilerSettings



##########
kogito-codegen-modules/kogito-codegen-manager/src/main/java/org/kie/kogito/codegen/manager/util/CodeGenManagerUtil.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.codegen.manager.util;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.lang.reflect.Modifier;
+import java.net.URLClassLoader;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.PathMatcher;
+import java.util.Optional;
+import java.util.function.Predicate;
+import java.util.stream.Stream;
+
+import org.drools.codegen.common.AppPaths;
+import org.drools.codegen.common.DroolsModelBuildContext;
+import org.drools.model.codegen.project.RuleCodegen;
+import org.kie.kogito.KogitoGAV;
+import org.kie.kogito.codegen.api.Generator;
+import org.kie.kogito.codegen.api.context.KogitoBuildContext;
+import org.kie.kogito.codegen.api.context.impl.JavaKogitoBuildContext;
+import org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext;
+import org.kie.kogito.codegen.api.context.impl.SpringBootKogitoBuildContext;
+import org.kie.kogito.codegen.decision.DecisionCodegen;
+import org.kie.kogito.codegen.prediction.PredictionCodegen;
+import org.kie.kogito.codegen.process.ProcessCodegen;
+import org.kie.kogito.codegen.process.persistence.PersistenceGenerator;
+import org.reflections.Reflections;
+import org.reflections.util.ConfigurationBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CodeGenManagerUtil {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(CodeGenManagerUtil.class);
+    public static final PathMatcher DRL_FILE_MATCHER = 
FileSystems.getDefault().getPathMatcher("glob:**.drl");
+
+    public enum Framework {
+        QUARKUS,
+        SPRING,
+        NONE
+    }
+
+    public record ProjectParameters(CodeGenManagerUtil.Framework framework,
+            String generateDecisions,
+            String generatePredictions,
+            String generateProcesses,
+            String generateRules,
+            Boolean persistence) {

Review Comment:
   I would add a couple of static methods to build ProjectParameters without 
having to pass so many nulls lates



##########
kogito-codegen-modules/kogito-codegen-manager/src/main/java/org/kie/kogito/codegen/manager/CompilerHelper.java:
##########
@@ -93,21 +98,37 @@ static void 
compileAndWriteClasses(Collection<GeneratedFile> generatedClasses, C
         }
 
         if (sources.length > 0) {
+            CompilationResult result = JAVA_COMPILER.compile(sources, srcMfs, 
trgMfs, classLoader, javaCompilerSettings);
 
-            CompilationResult result = JAVA_COMPILER.compile(sources, srcMfs, 
trgMfs, cl, settings);
             if (result.getErrors().length > 0) {
-                throw new 
MojoFailureException(Arrays.toString(result.getErrors()));
+                throw new 
IllegalStateException(Arrays.stream(result.getErrors())
+                        .map(CompilationProblem::getMessage)
+                        .collect(Collectors.joining(",")));
             }
 
             for (PortablePath path : trgMfs.getFilePaths()) {
                 byte[] data = trgMfs.getBytes(path);
-                writeGeneratedFile(new 
GeneratedFile(GeneratedFileType.COMPILED_CLASS, path.asString(), data), 
fileWriter, log);
+                writeGeneratedFile(new 
GeneratedFile(GeneratedFileType.COMPILED_CLASS, path.asString(), data), 
fileWriter);
             }
         }
     }
 
-    private static GeneratedFileWriter getGeneratedFileWriter(File baseDir) {
-        return generatedFileWriterBuilder
-                .build(Path.of(baseDir.getAbsolutePath()));
+    static GeneratedFileWriter getGeneratedFileWriter(File baseDir) {
+        return 
GENERATED_FILE_WRITER_BUILDER.build(Path.of(baseDir.getAbsolutePath()));
+    }
+
+    static JavaCompilerSettings getJavaCompilerSettings(List<String> 
runtimeClassPathElements,
+            String sourceEncoding,
+            String sourceVersion,
+            String targetVersion) {
+        JavaCompilerSettings settings = new JavaCompilerSettings();
+        for (String path : runtimeClassPathElements) {
+            File pathFile = new File(path);
+            settings.addClasspath(pathFile);

Review Comment:
   ```suggestion
               settings.addClasspath(new File(path));
   ```



##########
kogito-codegen-modules/kogito-codegen-manager/src/test/java/org/kie/kogito/codegen/manager/util/CodeGenManagerUtilTest.java:
##########
@@ -60,17 +50,18 @@ class AbstractKieMojoTest {
     @MethodSource("getGeneratorNamesStream")
     void overwritePropertiesIfNeededWithNull(String generatorName) {
         String expectedWrittenProperty = Generator.CONFIG_PREFIX + 
generatorName;
-        AbstractKieMojo abstractKieMojo = new AbstractKieMojo() {
-            @Override
-            public void execute() throws MojoExecutionException, 
MojoFailureException {
-            }
-        };
-        KogitoBuildContext kogitoBuildContextMocked = 
mock(KogitoBuildContext.class);
-        abstractKieMojo.overwritePropertiesIfNeeded(kogitoBuildContextMocked);
+        KogitoBuildContext kogitoBuildContextMocked = 
Mockito.mock(KogitoBuildContext.class);
+        CodeGenManagerUtil.ProjectParameters parameters = new 
CodeGenManagerUtil.ProjectParameters(CodeGenManagerUtil.Framework.QUARKUS,
+                null,

Review Comment:
   These are the nulls referred in a previous comment



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to