<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm</artifactId>
        <relativePath>../pom.xml</relativePath>
        <version>1.2.4</version>
    </parent>

    <artifactId>cucumber-jython</artifactId>
    <packaging>jar</packaging>
    <name>Cucumber-JVM: Jython</name>

    <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-core</artifactId>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>gherkin</artifactId>
        </dependency>
        <dependency>
            <groupId>org.python</groupId>
            <artifactId>jython-standalone</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.cobertura</groupId>
            <artifactId>cobertura</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>bin</directory>
                            <includes>
                                <include>*.jar</include>
                            </includes>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>generate-i18n-resources</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <target>
                                <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="maven.plugin.classpath" />
                                <groovy><![CDATA[
import groovy.text.SimpleTemplateEngine
import gherkin.I18n

def unsupported = ["ar", "bg", "el", "en_old", "fa", "he", "hi", "kn", "is", "ja", "ko", "pa", "pl", "ru", "sr_cyrl", "th", "tl", "tt", "uk", "uz", "zh_cn", "zh_tw"]
def engine = new SimpleTemplateEngine()
def templateSource = new File(project.baseDir, "src${File.separator}main${File.separator}code_generator${File.separator}I18n.jython.txt").getText()

I18n.all.each { i18n ->
  if (!unsupported.contains(i18n.underscoredIsoCode)) {
    def binding = ["i18n":i18n]
    template = engine.createTemplate(templateSource).make(binding)
    file = new File(project.baseDir, "target${File.separator}generated-resources${File.separator}i18n${File.separator}cucumber${File.separator}runtime${File.separator}jython${File.separator}i18n${File.separator}${i18n.underscoredIsoCode.toUpperCase()}.py")
    file.parentFile.mkdirs()
    file.write(template.toString(), "UTF-8")
  }
}
      ]]></groovy>

                            </target>
                        </configuration>
                    </execution>
                    <execution>
                        <id>package-egg</id>
                        <phase>package</phase>
                        <configuration>
                            <target>
                                <copy file="${project.build.directory}/${project.build.finalName}-shaded.jar" tofile="${basedir}/bin/cucumber-jython-shaded.jar" />
                                <!-- todo: make an egg -->
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jython-cli-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <!-- also run the CLI test to ensure that stuff works via the CLI as well -->
                                <echo message="Running jython tests via the CLI..." />
                                <java jar="${maven.dependency.org.python.jython-standalone.jar.path}" fork="true" failonerror="true" newenvironment="true" maxmemory="512m">
                                    <arg value="-S" />
                                    <arg value="bin/cucumber-jvm.py" />
                                    <arg value="--glue" />
                                    <arg value="src/test/resources" />
                                    <arg value="src/test/resources" />
                                </java>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-resource</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>add-resource</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>${basedir}/target/generated-resources/i18n</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
