Search in sources :

Example 76 with GeneratedFile

use of org.drools.codegen.common.GeneratedFile in project kogito-runtimes by kiegroup.

the class CodegenSvgTest method testExportedSVGRenamedAndMoved.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void testExportedSVGRenamedAndMoved(KogitoBuildContext.Builder contextBuilder) {
    KogitoBuildContext context = contextBuilder.withAddonsConfig(AddonsConfig.builder().withProcessSVG(true).build()).build();
    Collection<CollectedResource> collectedResources = CollectedResourceProducer.fromPaths(BASE_PATH);
    assertThat(collectedResources.stream().anyMatch(f -> f.resource().getSourcePath().endsWith(TEST_PROCESS_SOURCE))).isTrue();
    assertThat(collectedResources.stream().anyMatch(f -> f.resource().getSourcePath().endsWith(TEST_PROCESS_GENERATED_SVG_SOURCE))).isTrue();
    assertThat(collectedResources.stream().anyMatch(f -> f.resource().getSourcePath().endsWith(String.format(ProcessCodegen.SVG_EXPORT_NAME_EXPRESION, "hiring")))).isTrue();
    ProcessCodegen codeGenerator = ProcessCodegen.ofCollectedResources(context, collectedResources);
    Collection<GeneratedFile> generatedFiles = codeGenerator.generate();
    assertThat(generatedFiles).isNotEmpty();
    List<GeneratedFile> resources = generatedFiles.stream().filter(generatedFile -> generatedFile.type().equals(GeneratedFileType.INTERNAL_RESOURCE)).collect(Collectors.toList());
    assertThat(resources.size()).isEqualTo(1);
    assertThat("META-INF/processSVG/" + TEST_PROCESS_ID + ".svg").isEqualTo(resources.get(0).relativePath());
}
Also used : AddonsConfig(org.kie.kogito.codegen.api.AddonsConfig) ProcessCodegen(org.kie.kogito.codegen.process.ProcessCodegen) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Paths(java.nio.file.Paths) CollectedResourceProducer(org.kie.kogito.codegen.core.io.CollectedResourceProducer) CollectedResource(org.kie.kogito.codegen.api.io.CollectedResource) Path(java.nio.file.Path) GeneratedFile(org.drools.codegen.common.GeneratedFile) GeneratedFileType(org.drools.codegen.common.GeneratedFileType) MethodSource(org.junit.jupiter.params.provider.MethodSource) CollectedResource(org.kie.kogito.codegen.api.io.CollectedResource) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) ProcessCodegen(org.kie.kogito.codegen.process.ProcessCodegen) GeneratedFile(org.drools.codegen.common.GeneratedFile) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 77 with GeneratedFile

use of org.drools.codegen.common.GeneratedFile in project kogito-runtimes by kiegroup.

the class CodegenSvgTest method testWithoutSVGAddonNoRenamedAndMoved.

@ParameterizedTest
@MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders")
public void testWithoutSVGAddonNoRenamedAndMoved(KogitoBuildContext.Builder contextBuilder) {
    KogitoBuildContext context = contextBuilder.withAddonsConfig(AddonsConfig.builder().withProcessSVG(false).build()).build();
    Collection<CollectedResource> collectedResources = CollectedResourceProducer.fromPaths(BASE_PATH);
    assertThat(collectedResources.stream().anyMatch(f -> f.resource().getSourcePath().endsWith(TEST_PROCESS_SOURCE))).isTrue();
    assertThat(collectedResources.stream().anyMatch(f -> f.resource().getSourcePath().endsWith(TEST_PROCESS_GENERATED_SVG_SOURCE))).isTrue();
    ProcessCodegen codeGenerator = ProcessCodegen.ofCollectedResources(context, collectedResources);
    Collection<GeneratedFile> generatedFiles = codeGenerator.generate();
    assertThat(generatedFiles).isNotEmpty();
    List<GeneratedFile> resources = generatedFiles.stream().filter(generatedFile -> generatedFile.type().equals(GeneratedFileType.INTERNAL_RESOURCE)).collect(Collectors.toList());
    assertThat(resources.size()).isZero();
}
Also used : AddonsConfig(org.kie.kogito.codegen.api.AddonsConfig) ProcessCodegen(org.kie.kogito.codegen.process.ProcessCodegen) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Paths(java.nio.file.Paths) CollectedResourceProducer(org.kie.kogito.codegen.core.io.CollectedResourceProducer) CollectedResource(org.kie.kogito.codegen.api.io.CollectedResource) Path(java.nio.file.Path) GeneratedFile(org.drools.codegen.common.GeneratedFile) GeneratedFileType(org.drools.codegen.common.GeneratedFileType) MethodSource(org.junit.jupiter.params.provider.MethodSource) CollectedResource(org.kie.kogito.codegen.api.io.CollectedResource) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) ProcessCodegen(org.kie.kogito.codegen.process.ProcessCodegen) GeneratedFile(org.drools.codegen.common.GeneratedFile) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 78 with GeneratedFile

use of org.drools.codegen.common.GeneratedFile in project kogito-runtimes by kiegroup.

the class DroolsModelBuilder method generateCanonicalModelSources.

public Collection<GeneratedFile> generateCanonicalModelSources() {
    List<GeneratedFile> modelFiles = new ArrayList<>();
    List<org.drools.modelcompiler.builder.GeneratedFile> legacyModelFiles = new ArrayList<>();
    for (KogitoPackageSources pkgSources : modelBuilder.getPackageSources()) {
        pkgSources.collectGeneratedFiles(legacyModelFiles);
        modelFiles.addAll(generateInternalResource(pkgSources));
    }
    modelFiles.addAll(convertGeneratedRuleFile(legacyModelFiles));
    return modelFiles;
}
Also used : ArrayList(java.util.ArrayList) KogitoPackageSources(org.drools.model.project.codegen.KogitoPackageSources) GeneratedFile(org.drools.codegen.common.GeneratedFile)

Example 79 with GeneratedFile

use of org.drools.codegen.common.GeneratedFile in project kogito-runtimes by kiegroup.

the class AbstractProtoGenerator method generateProtoFiles.

@Override
public Collection<GeneratedFile> generateProtoFiles() {
    List<GeneratedFile> generatedFiles = new ArrayList<>();
    modelClasses.stream().map(this::generateModelClassProto).filter(Optional::isPresent).map(Optional::get).forEach(generatedFiles::add);
    try {
        this.generateProtoListingFile(generatedFiles).ifPresent(generatedFiles::add);
    } catch (IOException e) {
        throw new UncheckedIOException("Error during proto listing file creation", e);
    }
    return generatedFiles;
}
Also used : Optional(java.util.Optional) ArrayList(java.util.ArrayList) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) GeneratedFile(org.drools.codegen.common.GeneratedFile)

Aggregations

GeneratedFile (org.drools.codegen.common.GeneratedFile)79 KogitoBuildContext (org.kie.kogito.codegen.api.context.KogitoBuildContext)39 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)36 MethodSource (org.junit.jupiter.params.provider.MethodSource)36 CompilationUnit (com.github.javaparser.ast.CompilationUnit)21 Collection (java.util.Collection)20 ArrayList (java.util.ArrayList)19 List (java.util.List)19 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)15 Collectors (java.util.stream.Collectors)15 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)15 File (java.io.File)13 Test (org.junit.jupiter.api.Test)12 Paths (java.nio.file.Paths)11 Collections (java.util.Collections)10 GeneratedFileType (org.drools.codegen.common.GeneratedFileType)10 CollectedResourceProducer (org.kie.kogito.codegen.core.io.CollectedResourceProducer)10 Path (java.nio.file.Path)9 Optional (java.util.Optional)9 CollectedResource (org.kie.kogito.codegen.api.io.CollectedResource)8