<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you 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

      https://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>
    <parent>
        <groupId>org.apache.tsfile</groupId>
        <artifactId>tsfile-parent</artifactId>
        <version>2.4.0</version>
    </parent>
    <artifactId>tsfile-python</artifactId>
    <packaging>pom</packaging>
    <name>TsFile: Python</name>
    <properties>
        <unity.version>2.6.0</unity.version>
        <!-- Tell Sonar where to find the sources -->
        <sonar.sources>tsfile</sonar.sources>
        <sonar.cfamily.build-wrapper-output>${project.build.directory}/build-wrapper-output</sonar.cfamily.build-wrapper-output>
    </properties>
    <build>
        <sourceDirectory>${project.basedir}</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>com.diffplug.spotless</groupId>
                <artifactId>spotless-maven-plugin</artifactId>
                <version>${spotless.version}</version>
                <configuration>
                    <python>
                        <includes>
                            <include>examples/**/*.py</include>
                            <include>tests/**/*.py</include>
                            <include>tsfile/**/*.py</include>
                            <include>setup.py</include>
                        </includes>
                        <black>
                            <version>${black.version}</version>
                            <pathToExe>${project.basedir}/${python.venv.bin}black</pathToExe>
                        </black>
                    </python>
                    <lineEndings>UNIX</lineEndings>
                    <skip>${spotless.skip}</skip>
                </configuration>
                <executions>
                    <execution>
                        <id>spotless-check</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <phase>process-sources</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <!-- Create python virtual environment -->
                    <execution>
                        <id>python-venv</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${python.exe.bin}</executable>
                            <arguments>
                                <argument>-m</argument>
                                <argument>venv</argument>
                                <argument>${project.basedir}/venv</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>python-upgrade-pip</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${python.venv.bin}${python.exe.bin}</executable>
                            <arguments>
                                <argument>-m</argument>
                                <argument>pip</argument>
                                <argument>install</argument>
                                <argument>--upgrade</argument>
                                <argument>pip</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>python-install-requirements</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${python.venv.bin}${python.exe.bin}</executable>
                            <arguments>
                                <argument>-m</argument>
                                <argument>pip</argument>
                                <argument>install</argument>
                                <argument>-r</argument>
                                <argument>${project.basedir}/requirements.txt</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>compile-python-code</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${python.venv.bin}${python.exe.bin}</executable>
                            <arguments>
                                <argument>setup.py</argument>
                                <argument>build_ext</argument>
                                <argument>--inplace</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>python-install-test-requirements</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <skip>${skipTests:-false}</skip>
                            <executable>${python.venv.bin}${python.exe.bin}</executable>
                            <arguments>
                                <argument>-m</argument>
                                <argument>pip</argument>
                                <argument>install</argument>
                                <argument>pytest</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>run-python-tests</id>
                        <phase>test</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <skip>${skipTests:-false}</skip>
                            <executable>${python.venv.bin}pytest</executable>
                            <arguments>
                                <argument>${project.basedir}/tests</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>build-whl</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${python.venv.bin}${python.exe.bin}</executable>
                            <arguments>
                                <argument>setup.py</argument>
                                <argument>bdist_wheel</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>${basedir}/tsfile</directory>
                            <includes>
                                <include>*.so*</include>
                                <include>*.dylib</include>
                                <include>*.dll</include>
                                <include>*.h</include>
                                <include>*.cpp</include>
                            </includes>
                        </fileset>
                        <fileset>
                            <directory>tsfile.egg-info</directory>
                        </fileset>
                        <fileset>
                            <directory>build</directory>
                        </fileset>
                        <fileset>
                            <directory>dist</directory>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>groovy-maven-plugin</artifactId>
                <version>2.1.1</version>
                <executions>
                    <!-- rename the cmake binary and generate a script that adds the sonar build-wrapper -->
                    <execution>
                        <id>sync-project-version</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <source>${project.basedir}/VersionUpdater.groovy</source>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.groovy</groupId>
                        <artifactId>groovy</artifactId>
                        <version>${groovy.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>
