import BaseApplicationGenerator from '../base-application/index.mjs';
import { GENERATOR_CUCUMBER, GENERATOR_BOOTSTRAP_APPLICATION } from '../generator-list.mjs';
import writeTask from './files.mjs';
import cleanupTask from './cleanup.mjs';
export default class CucumberGenerator extends BaseApplicationGenerator {
    async beforeQueue() {
        if (!this.fromBlueprint) {
            await this.composeWithBlueprints(GENERATOR_CUCUMBER);
        }
        if (!this.delegateToBlueprint) {
            await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
        }
    }
    get writing() {
        return this.asWritingTaskGroup({
            cleanupTask,
            writeTask,
        });
    }
    get [BaseApplicationGenerator.WRITING]() {
        return this.delegateTasksToBlueprint(() => this.writing);
    }
    get postWriting() {
        return this.asPostWritingTaskGroup({
            addDependencies({ application, source }) {
                if (application.buildToolMaven) {
                    source.addMavenDefinition?.({
                        dependencies: [
                            { groupId: 'io.cucumber', artifactId: 'cucumber-junit-platform-engine', scope: 'test' },
                            { groupId: 'io.cucumber', artifactId: 'cucumber-java', scope: 'test' },
                            { groupId: 'io.cucumber', artifactId: 'cucumber-spring', scope: 'test' },
                            { groupId: 'org.junit.platform', artifactId: 'junit-platform-console', scope: 'test' },
                            { groupId: 'org.testng', artifactId: 'testng', scope: 'test' },
                        ],
                        plugins: [{ groupId: 'org.apache.maven.plugins', artifactId: 'maven-antrun-plugin' }],
                        pluginManagement: [
                            {
                                groupId: 'org.apache.maven.plugins',
                                artifactId: 'maven-antrun-plugin',
                                additionalContent: `
<executions>
  <execution>
  <!--Work around. Surefire does not use JUnit's Test Engine discovery functionality -->
  <id>prepare cucumber feature files</id>
  <phase>integration-test</phase>
  <goals>
    <goal>run</goal>
  </goals>
  <configuration>
    <target>
        <echo message="Running JUnit Platform CLI"/>
        <java classname="org.junit.platform.console.ConsoleLauncher"
              fork="true"
              failonerror="true"
              newenvironment="true"
              maxmemory="512m"
              classpathref="maven.test.classpath">
            <jvmarg value="-Dspring.profiles.active=testprod"/>${application.reactive
                                    ? `
            <jvmarg value="-XX:+AllowRedefinitionToAddDeleteMethods"/>`
                                    : ''}
            <arg value="--include-engine"/>
            <arg value="cucumber"/>
            <arg value="--scan-classpath"/>
            <arg value="\${project.build.testOutputDirectory}"/>
        </java>
    </target>
  </configuration>
  </execution>
</executions>
`,
                            },
                        ],
                    });
                }
            },
        });
    }
    get [BaseApplicationGenerator.POST_WRITING]() {
        return this.delegateTasksToBlueprint(() => this.postWriting);
    }
}
