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);
}
}
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;
}
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;
}
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;
}
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());
}
Aggregations