<commit_before>package org.skyve.toolchain;

import com.squareup.javapoet.*;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.skyve.impl.generate.DialectOptions;
import org.skyve.impl.generate.DomainGenerator;
import org.skyve.impl.generate.ViewGenerator;
import org.skyve.impl.metadata.repository.AbstractRepository;
import org.skyve.impl.metadata.repository.LocalDesignRepository;
import org.skyve.metadata.model.document.Bizlet;
import org.skyve.persistence.DocumentQuery;
import org.skyve.persistence.Persistence;
import org.skyve.toolchain.config.GenerateDomainConfig;
import org.skyve.toolchain.config.GenerateEditViewConfig;
import org.skyve.util.DataBuilder;
import org.skyve.util.test.SkyveFactory;
import org.skyve.util.test.SkyveFixture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.enterprise.inject.Default;
import javax.inject.Inject;
import javax.lang.model.element.Modifier;
import java.io.IOException;
import java.nio.file.*;
import java.util.List;

@Mojo(name = "newScaffoldedDocument")
public class NewScaffoldedDocumentMojo extends NewDocumentMojo {

    private static final Logger LOGGER = LoggerFactory.getLogger(NewScaffoldedDocumentMojo.class);

    /**
     * Relative source directory.
     */
    @Parameter(required = true, defaultValue = "src/main/java/")
    private String srcDir;

    /**
     * Relative generated directory.
     */
    @Parameter(required = true, defaultValue = "src/generated/java/")
    private String generatedDir;

    /**
     * Relative test directory.
     */
    @Parameter(required = true, defaultValue = "src/test/java/")
    private String testDir;

    /**
     * Relative generated test directory.
     */
    @Parameter(required = true, defaultValue = "src/generatedTest/java/")
    private String generatedTestDir;

    @Parameter()
    private String customer;

    @Parameter()
    private GenerateDomainConfig generateDomainConfig;

    @Parameter()
    private GenerateEditViewConfig generateEditViewConfig;

    @Override
    public void execute() throws MojoExecutionException {
        super.execute();

        createExtensionClass();
        createBizletClass();
        createFactoryClass();
        createServiceClass();
        generateDomain();
        generateEditView();
    }

    private void createExtensionClass() {
        final TypeSpec documentExtension = TypeSpec.classBuilder(getExtensionName())
                .addModifiers(Modifier.PUBLIC)
                .superclass(ClassName.get("modules." + moduleName + ".domain", documentName))
                .build();

        final JavaFile javaFile = JavaFile.builder("modules." + moduleName + "." + documentName, documentExtension)
                .indent("\t")
                .build();

        try {
            javaFile.writeTo(Paths.get(srcDir));
        } catch (IOException e) {
            LOGGER.warn("Failed to scaffold document extension.", e);
        }
    }

    private void createBizletClass() {
        final String bizletName = documentName + "Bizlet";
        final TypeSpec documentBizlet = TypeSpec.classBuilder(bizletName)
                .addModifiers(Modifier.PUBLIC)
                .superclass(ParameterizedTypeName.get(ClassName.get(Bizlet.class), ClassName.get("modules." + moduleName + "." + documentName, getExtensionName())))
                .build();

        final JavaFile javaFile = JavaFile.builder("modules." + moduleName + "." + documentName, documentBizlet)
                .indent("\t")
                .build();

        try {
            javaFile.writeTo(Paths.get(srcDir));
        } catch (IOException e) {
            LOGGER.warn("Failed to scaffold document Bizlet.", e);
        }
    }

    private void createFactoryClass() {
        final String factoryName = documentName + "Factory";

        final ClassName extensionClassName = ClassName.get("modules." + moduleName + "." + documentName, getExtensionName());
        final MethodSpec crudInstance = MethodSpec.methodBuilder("crudInstance")
                .addModifiers(Modifier.PUBLIC)
                .returns(extensionClassName)
                .addAnnotation(AnnotationSpec.builder(ClassName.get(SkyveFixture.class)).addMember("types", "$T.$L", SkyveFixture.FixtureType.class, SkyveFixture.FixtureType.crud).build())
                .addStatement("return new $T().factoryBuild($T.MODULE_NAME, $T.DOCUMENT_NAME)", DataBuilder.class, extensionClassName, extensionClassName)
                .build();

        final TypeSpec documentFactory = TypeSpec.classBuilder(factoryName)
                .addModifiers(Modifier.PUBLIC)
                .addAnnotation(AnnotationSpec.builder(ClassName.get(SkyveFactory.class)).build())
                .addMethod(crudInstance)
                .build();

        final JavaFile javaFile = JavaFile.builder("modules." + moduleName + "." + documentName, documentFactory)
                .indent("\t")
                .build();

        try {
            javaFile.writeTo(Paths.get(srcDir));
        } catch (IOException e) {<commit_msg>Fixed issue with scaffolded document factory where it was not including the fixture type.<commit_after>package org.skyve.toolchain;

import com.squareup.javapoet.*;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.skyve.impl.generate.DialectOptions;
import org.skyve.impl.generate.DomainGenerator;
import org.skyve.impl.generate.ViewGenerator;
import org.skyve.impl.metadata.repository.AbstractRepository;
import org.skyve.impl.metadata.repository.LocalDesignRepository;
import org.skyve.metadata.model.document.Bizlet;
import org.skyve.persistence.DocumentQuery;
import org.skyve.persistence.Persistence;
import org.skyve.toolchain.config.GenerateDomainConfig;
import org.skyve.toolchain.config.GenerateEditViewConfig;
import org.skyve.util.DataBuilder;
import org.skyve.util.test.SkyveFactory;
import org.skyve.util.test.SkyveFixture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.enterprise.inject.Default;
import javax.inject.Inject;
import javax.lang.model.element.Modifier;
import java.io.IOException;
import java.nio.file.*;
import java.util.List;

@Mojo(name = "newScaffoldedDocument")
public class NewScaffoldedDocumentMojo extends NewDocumentMojo {

    private static final Logger LOGGER = LoggerFactory.getLogger(NewScaffoldedDocumentMojo.class);

    /**
     * Relative source directory.
     */
    @Parameter(required = true, defaultValue = "src/main/java/")
    private String srcDir;

    /**
     * Relative generated directory.
     */
    @Parameter(required = true, defaultValue = "src/generated/java/")
    private String generatedDir;

    /**
     * Relative test directory.
     */
    @Parameter(required = true, defaultValue = "src/test/java/")
    private String testDir;

    /**
     * Relative generated test directory.
     */
    @Parameter(required = true, defaultValue = "src/generatedTest/java/")
    private String generatedTestDir;

    @Parameter()
    private String customer;

    @Parameter()
    private GenerateDomainConfig generateDomainConfig;

    @Parameter()
    private GenerateEditViewConfig generateEditViewConfig;

    @Override
    public void execute() throws MojoExecutionException {
        super.execute();

        createExtensionClass();
        createBizletClass();
        createFactoryClass();
        createServiceClass();
        generateDomain();
        generateEditView();
    }

    private void createExtensionClass() {
        final TypeSpec documentExtension = TypeSpec.classBuilder(getExtensionName())
                .addModifiers(Modifier.PUBLIC)
                .superclass(ClassName.get("modules." + moduleName + ".domain", documentName))
                .build();

        final JavaFile javaFile = JavaFile.builder("modules." + moduleName + "." + documentName, documentExtension)
                .indent("\t")
                .build();

        try {
            javaFile.writeTo(Paths.get(srcDir));
        } catch (IOException e) {
            LOGGER.warn("Failed to scaffold document extension.", e);
        }
    }

    private void createBizletClass() {
        final String bizletName = documentName + "Bizlet";
        final TypeSpec documentBizlet = TypeSpec.classBuilder(bizletName)
                .addModifiers(Modifier.PUBLIC)
                .superclass(ParameterizedTypeName.get(ClassName.get(Bizlet.class), ClassName.get("modules." + moduleName + "." + documentName, getExtensionName())))
                .build();

        final JavaFile javaFile = JavaFile.builder("modules." + moduleName + "." + documentName, documentBizlet)
                .indent("\t")
                .build();

        try {
            javaFile.writeTo(Paths.get(srcDir));
        } catch (IOException e) {
            LOGGER.warn("Failed to scaffold document Bizlet.", e);
        }
    }

    private void createFactoryClass() {
        final String factoryName = documentName + "Factory";

        final ClassName extensionClassName = ClassName.get("modules." + moduleName + "." + documentName, getExtensionName());
        final MethodSpec crudInstance = MethodSpec.methodBuilder("crudInstance")
                .addModifiers(Modifier.PUBLIC)
                .returns(extensionClassName)
                .addAnnotation(AnnotationSpec.builder(ClassName.get(SkyveFixture.class)).addMember("types", "$T.$L", SkyveFixture.FixtureType.class, SkyveFixture.FixtureType.crud).build())
                .addStatement("return new $T().fixture($L).factoryBuild($T.MODULE_NAME, $T.DOCUMENT_NAME)", DataBuilder.class, SkyveFixture.FixtureType.crud, extensionClassName, extensionClassName)
                .build();

        final TypeSpec documentFactory = TypeSpec.classBuilder(factoryName)
                .addModifiers(Modifier.PUBLIC)
                .addAnnotation(AnnotationSpec.builder(ClassName.get(SkyveFactory.class)).build())
                .addMethod(crudInstance)
                .build();

        final JavaFile javaFile = JavaFile.builder("modules." + moduleName + "." + documentName, documentFactory)
                .indent("\t")
                .build();

        try {
            javaFile.writeTo(Paths.get(srcDir));
        } catch (IOException e) {
{'fraction_non_alphanumeric': 0.1110791918031217, 'fraction_numerical': 0.00038303169587283346, 'mean_word_length': 2.9908291937332825, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1569515', 'n_tokens_mistral': 2876, 'n_tokens_neox': 2751, 'n_words': 530}