<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2011-2026 Lime Mojito Pty Ltd
  ~
  ~    Licensed under the Apache License, Version 2.0 (the "License");
  ~    you may not use this file except in compliance with the License.
  ~    You may obtain a copy of the License at
  ~
  ~        http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~    Unless required by applicable law or agreed to in writing, software
  ~    distributed under the License is distributed on an "AS IS" BASIS,
  ~    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~    See the License for the specific language governing permissions and
  ~    limitations under the License.
  ~
  -->

<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>
    <name>${project.artifactId}</name>

    <artifactId>java-cdk-development</artifactId>
    <version>17.0.27</version>
    <packaging>pom</packaging>
    <description>
        * A basic setup for cdk development using a simple automated deployment to the "current" account as setup in
        aws credentials. Requires cdk.json file to be configured to match pom.xml. Example cdk.json file included
        for java based cdk deployment using maven. Note JAVA_HOME must be set to match the version of java in use so
        that CDK's spawned maven process does not become confused with the compile java version.
        * Packaging for child projects should be jar.
        * Set cdk main class in properties of pom.xml.
        * Code jar dependencies as dependencies, these will be included in the build to target/dependencies which may
        be referenced from CDK code.
        * See development-test/jar-lambda-poc-cdk for an example.
    </description>

    <parent>
        <groupId>com.limemojito.oss.standards</groupId>
        <artifactId>jar-development</artifactId>
        <version>17.0.27</version>
        <relativePath>../jar-development</relativePath>
    </parent>

    <properties>
        <cdk.main.class>SET THIS FOR CDK DEPLOYMENTS</cdk.main.class>
        <cdk.build.properties>${project.build.directory}/cdk.properties</cdk.build.properties>
    </properties>

    <dependencies>
        <dependency>
            <groupId>software.amazon.awscdk</groupId>
            <artifactId>aws-cdk-lib</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>import-cdk-properties</id>
                        <!-- This import occurs AFTER check-for-cdk-skip, so that we know the cdk build state -->
                        <phase>initialize</phase>
                        <goals>
                            <goal>read-project-properties</goal>
                        </goals>
                        <configuration>
                            <files>
                                <file>${cdk.build.properties}</file>
                            </files>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>check-for-cdk-skip</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <target>
                                <condition property="cdk.skip" else="false">
                                    <or>
                                        <equals arg1="${lime.fast-build}" arg2="true"/>
                                        <not>
                                            <!-- Skip CDK if no source -->
                                            <available file="${project.build.sourceDirectory}"/>
                                        </not>
                                    </or>
                                </condition>
                                <!--suppress UnresolvedMavenProperty -->
                                <echo level="info"
                                      message="cdk.skip is ${cdk.skip}"/>
                                <!--suppress MavenModelInspection -->
                                <echo file="${cdk.build.properties}"
                                      message="cdk.skip=${cdk.skip}"/>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <configuration>
                    <!-- For when we are called BY cdk -->
                    <mainClass>${cdk.main.class}</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <id>cdk-bootstrap</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>post-integration-test</phase>
                        <configuration>
                            <environmentVariables>
                                <JSII_SILENCE_WARNING_UNTESTED_NODE_VERSION>true
                                </JSII_SILENCE_WARNING_UNTESTED_NODE_VERSION>
                            </environmentVariables>
                            <executable>cdk</executable>
                            <commandlineArgs>--ci true bootstrap</commandlineArgs>
                            <!--suppress MavenModelInspection -->
                            <skip>${cdk.skip}</skip>
                        </configuration>
                    </execution>
                    <execution>
                        <id>cdk-deploy</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>post-integration-test</phase>
                        <configuration>
                            <!--suppress MavenModelInspection -->
                            <skip>${cdk.skip}</skip>
                            <environmentVariables>
                                <JSII_SILENCE_WARNING_UNTESTED_NODE_VERSION>true
                                </JSII_SILENCE_WARNING_UNTESTED_NODE_VERSION>
                            </environmentVariables>
                            <executable>cdk</executable>
                            <commandlineArgs>--ci true deploy --require-approval never</commandlineArgs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <stripVersion>true</stripVersion>
                            <excludeTransitive>true</excludeTransitive>
                            <!--suppress MavenModelInspection -->
                            <skip>${cdk.skip}</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
