gitgabrio commented on code in PR #3881:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3881#discussion_r2030848956
##########
kogito-maven-plugin/src/main/java/org/kie/kogito/maven/plugin/util/MojoUtil.java:
##########
@@ -107,6 +107,25 @@ private static KieModuleModel getDependencyKieModel(final
File jar) throws IOExc
return null;
}
+ public static boolean hasClassOnClasspath(final MavenProject project,
String className) {
+ try {
+ Set<Artifact> elements = project.getArtifacts();
+ URL[] urls = new URL[elements.size()];
+
+ int i = 0;
+ for (Artifact artifact : elements) {
+ urls[i] = artifact.getFile().toURI().toURL();
+ i++;
+ }
+ try (URLClassLoader cl = new URLClassLoader(urls)) {
Review Comment:
HI @yesamer
Probably this snippet could be moved somewhere in the common library: I'm
expecting it needed also when invoking from Gradle: wdyt ?
##########
kogito-maven-plugin/src/main/java/org/kie/kogito/maven/plugin/GenerateModelMojo.java:
##########
@@ -83,11 +76,17 @@ public class GenerateModelMojo extends AbstractKieMojo {
/**
* The <code>maven-compiler-plugin</code> version to use.
- * Default to <b>3.8.1</b>
+ * Default to <b>3.10.2</b>
*/
- @Parameter(defaultValue = "3.8.1", property = "version.compiler.plugin")
+ @Parameter(defaultValue = "3.10.2", property = "version.compiler.plugin")
private String compilerPluginVersion;
+ @Parameter(defaultValue = "1.8", property = "maven.compiler.source")
+ private String compilerSourceJavaVersion;
Review Comment:
I'm not sure about this 1.8 versions: IINW, we should aim at 17
##########
kogito-maven-plugin/src/main/java/org/kie/kogito/maven/plugin/AbstractKieMojo.java:
##########
@@ -153,127 +86,29 @@ protected ClassLoader projectClassLoader() throws
MojoExecutionException {
null);
}
- protected String appPackageName() {
- return DroolsModelBuildContext.DEFAULT_PACKAGE_NAME;
- }
-
- private void additionalProperties(KogitoBuildContext context) {
-
- classToCheckForREST().ifPresent(restClass -> {
- if (!context.hasClassAvailable(restClass)) {
- getLog().info("Disabling REST generation because class '" +
restClass + "' is not available");
-
context.setApplicationProperty(DroolsModelBuildContext.KOGITO_GENERATE_REST,
"false");
- }
- });
- classToCheckForDI().ifPresent(diClass -> {
- if (!context.hasClassAvailable(diClass)) {
- getLog().info("Disabling dependency injection generation
because class '" + diClass + "' is not available");
-
context.setApplicationProperty(DroolsModelBuildContext.KOGITO_GENERATE_DI,
"false");
- }
- });
-
- overwritePropertiesIfNeeded(context);
- }
-
- void overwritePropertiesIfNeeded(KogitoBuildContext context) {
- overwritePropertyIfNeeded(context, RuleCodegen.GENERATOR_NAME,
generateRules);
- overwritePropertyIfNeeded(context, ProcessCodegen.GENERATOR_NAME,
generateProcesses);
- overwritePropertyIfNeeded(context, PredictionCodegen.GENERATOR_NAME,
generatePredictions);
- overwritePropertyIfNeeded(context, DecisionCodegen.GENERATOR_NAME,
generateDecisions);
- overwritePropertyIfNeeded(context,
PersistenceGenerator.GENERATOR_NAME, Boolean.toString(persistence));
- }
-
- static void overwritePropertyIfNeeded(KogitoBuildContext context, String
generatorName, String propertyValue) {
- if (propertyValue != null && !propertyValue.isEmpty()) {
- context.setApplicationProperty(Generator.CONFIG_PREFIX +
generatorName, propertyValue);
- }
- }
-
- private KogitoBuildContext.Builder contextBuilder() {
- switch (discoverFramework()) {
- case QUARKUS:
- return QuarkusKogitoBuildContext.builder();
- case SPRING:
- return SpringBootKogitoBuildContext.builder();
- default:
- return JavaKogitoBuildContext.builder();
- }
- }
-
- private Optional<String> classToCheckForREST() {
- switch (discoverFramework()) {
- case QUARKUS:
- return Optional.of(QuarkusKogitoBuildContext.QUARKUS_REST);
- case SPRING:
- return Optional.of(SpringBootKogitoBuildContext.SPRING_REST);
- default:
- return Optional.empty();
- }
- }
-
- private Optional<String> classToCheckForDI() {
- switch (discoverFramework()) {
- case QUARKUS:
- return Optional.of(QuarkusKogitoBuildContext.QUARKUS_DI);
- case SPRING:
- return Optional.of(SpringBootKogitoBuildContext.SPRING_DI);
- default:
- return Optional.empty();
- }
- }
-
- private enum Framework {
- QUARKUS,
- SPRING,
- NONE
- }
-
- private Framework discoverFramework() {
+ protected CodeGenManagerUtil.Framework discoverFramework() {
if (hasDependency("quarkus")) {
- return Framework.QUARKUS;
+ return CodeGenManagerUtil.Framework.QUARKUS;
}
if (hasDependency("spring")) {
- return Framework.SPRING;
+ return CodeGenManagerUtil.Framework.SPRING;
}
- return Framework.NONE;
+ return CodeGenManagerUtil.Framework.NONE;
}
private boolean hasDependency(String dependency) {
return project.getDependencies().stream().anyMatch(d ->
d.getArtifactId().contains(dependency));
}
- private boolean hasClassOnClasspath(String className) {
- try {
- Set<Artifact> elements = project.getArtifacts();
- URL[] urls = new URL[elements.size()];
-
- int i = 0;
- Iterator<Artifact> it = elements.iterator();
- while (it.hasNext()) {
- Artifact artifact = it.next();
-
- urls[i] = artifact.getFile().toURI().toURL();
- i++;
- }
- try (URLClassLoader cl = new URLClassLoader(urls)) {
- cl.loadClass(className);
- }
- return true;
- } catch (Exception e) {
- return false;
- }
- }
-
protected File getSourcesPath() {
// using runtime BT instead of static AppPaths.MAVEN to allow
// invocation from GRADLE
return Path.of(baseDir.getAbsolutePath(),
AppPaths.BT.GENERATED_SOURCES_PATH.toString()).toFile();
Review Comment:
This one could be moved to the common library, with `baseDir` as parameter:
that way any "build engine" will retrieve the sources path with the same method
--
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]