Search in sources :

Example 1 with KogitoGAV

use of org.kie.kogito.KogitoGAV in project kogito-runtimes by kiegroup.

the class DecisionModelResourcesProviderGenerator method setupResourcesVariable.

private void setupResourcesVariable(final ClassOrInterfaceDeclaration typeDeclaration) {
    final List<MethodDeclaration> getResourcesMethods = typeDeclaration.getMethodsBySignature("getResources");
    final ClassOrInterfaceType applicationClass = StaticJavaParser.parseClassOrInterfaceType(applicationCanonicalName);
    if (getResourcesMethods.size() != 1) {
        throw new InvalidTemplateException(generator, "A \"getResources()\" method was not found");
    }
    final MethodDeclaration getResourcesMethod = getResourcesMethods.get(0);
    final BlockStmt body = getResourcesMethod.getBody().orElseThrow(() -> new RuntimeException("Can't find the body of the \"get()\" method."));
    final VariableDeclarator resourcePathsVariable = getResourcesMethod.findFirst(VariableDeclarator.class).orElseThrow(() -> new RuntimeException("Can't find a variable declaration in the \"get()\" method."));
    if (!context.getGAV().isPresent()) {
        LOGGER.error("Impossible to obtain project group-artifact-id, using empty value");
    }
    KogitoGAV gav = context.getGAV().orElse(KogitoGAV.EMPTY_GAV);
    for (DMNResource resource : resources) {
        final MethodCallExpr add = new MethodCallExpr(resourcePathsVariable.getNameAsExpression(), "add");
        final MethodCallExpr getResAsStream = getReadResourceMethod(applicationClass, resource.getCollectedResource());
        final MethodCallExpr isr = new MethodCallExpr("readResource").addArgument(getResAsStream);
        add.addArgument(newObject(DefaultDecisionModelResource.class, newGAV(gav), new StringLiteralExpr(resource.getDmnModel().getNamespace()), new StringLiteralExpr(resource.getDmnModel().getName()), makeDecisionModelMetadata(resource), isr));
        body.addStatement(body.getStatements().size() - 1, add);
    }
}
Also used : MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) DefaultDecisionModelResource(org.kie.kogito.dmn.DefaultDecisionModelResource) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) KogitoGAV(org.kie.kogito.KogitoGAV) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) InvalidTemplateException(org.kie.kogito.codegen.api.template.InvalidTemplateException) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 2 with KogitoGAV

use of org.kie.kogito.KogitoGAV in project kogito-runtimes by kiegroup.

the class AbstractKieMojo method discoverKogitoRuntimeContext.

protected KogitoBuildContext discoverKogitoRuntimeContext(ClassLoader classLoader) {
    AppPaths appPaths = AppPaths.fromProjectDir(projectDir.toPath(), outputDirectory.toPath());
    KogitoBuildContext context = contextBuilder().withClassAvailabilityResolver(this::hasClassOnClasspath).withApplicationProperties(appPaths.getResourceFiles()).withPackageName(appPackageName()).withAddonsConfig(AddonsConfigDiscovery.discover(this::hasClassOnClasspath)).withClassLoader(classLoader).withAppPaths(appPaths).withGAV(new KogitoGAV(project.getGroupId(), project.getArtifactId(), project.getVersion())).build();
    additionalProperties(context);
    return context;
}
Also used : AppPaths(org.kie.kogito.codegen.api.utils.AppPaths) KogitoGAV(org.kie.kogito.KogitoGAV) SpringBootKogitoBuildContext(org.kie.kogito.codegen.api.context.impl.SpringBootKogitoBuildContext) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) JavaKogitoBuildContext(org.kie.kogito.codegen.api.context.impl.JavaKogitoBuildContext) QuarkusKogitoBuildContext(org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext)

Example 3 with KogitoGAV

use of org.kie.kogito.KogitoGAV in project kogito-runtimes by kiegroup.

the class KogitoQuarkusResourceUtils method kogitoBuildContext.

public static KogitoBuildContext kogitoBuildContext(Path outputTarget, Iterable<Path> paths, IndexView index, Dependency appArtifact) {
    // scan and parse paths
    AppPaths.BuildTool buildTool;
    if (System.getProperty("org.gradle.appname") == null) {
        buildTool = AppPaths.BuildTool.MAVEN;
    } else {
        buildTool = AppPaths.BuildTool.GRADLE;
    }
    AppPaths appPaths = AppPaths.fromQuarkus(outputTarget, paths, buildTool);
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    KogitoBuildContext context = QuarkusKogitoBuildContext.builder().withApplicationPropertyProvider(new KogitoQuarkusApplicationPropertiesProvider()).withClassLoader(classLoader).withClassAvailabilityResolver(className -> classAvailabilityResolver(classLoader, index, className)).withAppPaths(appPaths).withGAV(new KogitoGAV(appArtifact.getGroupId(), appArtifact.getArtifactId(), appArtifact.getVersion())).build();
    if (!context.hasClassAvailable(QuarkusKogitoBuildContext.QUARKUS_REST)) {
        LOGGER.info("Disabling REST generation because class '" + QuarkusKogitoBuildContext.QUARKUS_REST + "' is not available");
        context.setApplicationProperty(KogitoBuildContext.KOGITO_GENERATE_REST, "false");
    }
    if (!context.hasClassAvailable(QuarkusKogitoBuildContext.QUARKUS_DI)) {
        LOGGER.info("Disabling dependency injection generation because class '" + QuarkusKogitoBuildContext.QUARKUS_DI + "' is not available");
        context.setApplicationProperty(KogitoBuildContext.KOGITO_GENERATE_DI, "false");
    }
    return context;
}
Also used : KiePath(org.kie.memorycompiler.resources.KiePath) DotName(org.jboss.jandex.DotName) LoggerFactory(org.slf4j.LoggerFactory) AdditionalStaticResourceBuildItem(io.quarkus.vertx.http.deployment.spi.AdditionalStaticResourceBuildItem) GeneratedFileWriter(org.kie.kogito.codegen.core.utils.GeneratedFileWriter) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ArrayList(java.util.ArrayList) GeneratedBeanBuildItem(io.quarkus.arc.deployment.GeneratedBeanBuildItem) CompositeIndex(org.jboss.jandex.CompositeIndex) AppPaths(org.kie.kogito.codegen.api.utils.AppPaths) Dependency(io.quarkus.maven.dependency.Dependency) ResourceReader(org.kie.memorycompiler.resources.ResourceReader) Path(java.nio.file.Path) IndexView(org.jboss.jandex.IndexView) GeneratedResourceBuildItem(io.quarkus.deployment.builditem.GeneratedResourceBuildItem) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) Logger(org.slf4j.Logger) GeneratedFileType(org.kie.kogito.codegen.api.GeneratedFileType) Files(java.nio.file.Files) Collection(java.util.Collection) NativeImageResourceBuildItem(io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) KogitoGAV(org.kie.kogito.KogitoGAV) QuarkusKogitoBuildContext(org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext) Paths(java.nio.file.Paths) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) Collections(java.util.Collections) AppPaths(org.kie.kogito.codegen.api.utils.AppPaths) KogitoGAV(org.kie.kogito.KogitoGAV) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) QuarkusKogitoBuildContext(org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext)

Example 4 with KogitoGAV

use of org.kie.kogito.KogitoGAV in project kogito-runtimes by kiegroup.

the class SpringBootModelEventEmitterTest method makeModel.

private DecisionModelResource makeModel() {
    final DecisionModelResource model = mock(DecisionModelResource.class);
    when(model.getGav()).thenReturn(new KogitoGAV("groupId", "artifactId", "version"));
    when(model.getModelName()).thenReturn("name");
    when(model.getNamespace()).thenReturn("namespace");
    when(model.getModelMetadata()).thenReturn(new DecisionModelMetadata("http://www.omg.org/spec/DMN/20151101/dmn.xsd"));
    when(model.get()).thenReturn("model");
    return model;
}
Also used : DecisionModelMetadata(org.kie.kogito.decision.DecisionModelMetadata) DecisionModelResource(org.kie.kogito.decision.DecisionModelResource) KogitoGAV(org.kie.kogito.KogitoGAV)

Example 5 with KogitoGAV

use of org.kie.kogito.KogitoGAV in project kogito-runtimes by kiegroup.

the class DecisionModelEventTest method testGetters.

@Test
public void testGetters() {
    final KogitoGAV gav = new KogitoGAV("groupID", "artifactId", "version");
    final DecisionModelEvent e = new DecisionModelEvent(gav, "name", "namespace", new DecisionModelMetadata("http://www.omg.org/spec/DMN/20151101/dmn.xsd"), "definition");
    assertEquals(gav.getGroupId(), e.getGav().getGroupId());
    assertEquals(gav.getArtifactId(), e.getGav().getArtifactId());
    assertEquals(gav.getVersion(), e.getGav().getVersion());
    assertEquals("name", e.getName());
    assertEquals("namespace", e.getNamespace());
    assertEquals(ModelDomain.DECISION, e.getModelMetadata().getModelDomain());
    assertEquals("http://www.omg.org/spec/DMN/20151101/dmn.xsd", e.getModelMetadata().getSpecVersion());
    assertEquals("definition", e.getDefinition());
}
Also used : DecisionModelMetadata(org.kie.kogito.decision.DecisionModelMetadata) KogitoGAV(org.kie.kogito.KogitoGAV) DecisionModelEvent(org.kie.kogito.tracing.event.model.models.DecisionModelEvent) Test(org.junit.jupiter.api.Test)

Aggregations

KogitoGAV (org.kie.kogito.KogitoGAV)10 Test (org.junit.jupiter.api.Test)4 DecisionModelMetadata (org.kie.kogito.decision.DecisionModelMetadata)3 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)2 KogitoBuildContext (org.kie.kogito.codegen.api.context.KogitoBuildContext)2 QuarkusKogitoBuildContext (org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext)2 AppPaths (org.kie.kogito.codegen.api.utils.AppPaths)2 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)1 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)1 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)1 GeneratedBeanBuildItem (io.quarkus.arc.deployment.GeneratedBeanBuildItem)1 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)1 GeneratedResourceBuildItem (io.quarkus.deployment.builditem.GeneratedResourceBuildItem)1 NativeImageResourceBuildItem (io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem)1 Dependency (io.quarkus.maven.dependency.Dependency)1 ResolvedDependency (io.quarkus.maven.dependency.ResolvedDependency)1 AdditionalStaticResourceBuildItem (io.quarkus.vertx.http.deployment.spi.AdditionalStaticResourceBuildItem)1 IOException (java.io.IOException)1