<?xml version="1.0" encoding="UTF-8"?>
<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>com.github.nbbrd.java-sql-util</groupId>
        <artifactId>java-sql-parent</artifactId>
        <version>1.0.7</version>
    </parent>

    <artifactId>java-sql-lhod</artifactId>
    <packaging>jar</packaging>

    <name>java-sql-lhod</name>
    <description>Java SQL utilities - LHOD</description>
    <url>https://github.com/nbbrd/java-sql-util</url>

    <dependencies>
        <!-- compile only -->
        <dependency>
            <groupId>org.checkerframework</groupId>
            <artifactId>checker-qual</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.github.nbbrd.java-service-util</groupId>
            <artifactId>java-service-processor</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.github.nbbrd.java-design-util</groupId>
            <artifactId>java-design-processor</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- compile and runtime -->
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>java-sql-odbc</artifactId>
            <version>${project.version}</version>
        </dependency>
        
        <!-- test only -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.github.nbbrd.spreadsheet4j</groupId>
            <artifactId>spreadsheet-fastexcel</artifactId>
            <version>2.5.9</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    
    <profiles>
        <!-- Repack single-file-lib -->
        <profile>
            <id>repack-single-file-lib</id>
            <activation>
                <property>
                    <name>!skipRepackSingleFileLib</name>
                </property>
            </activation>
            <properties>
                <repack.basedir>${project.build.directory}/unpack</repack.basedir>
                <repack.prefix>internal</repack.prefix>
                <repack.pacdir>${project.build.directory}/repack</repack.pacdir>
            </properties>
            <build>
                <plugins>
                    <!-- Step 1: unpack source code -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>3.8.1</version>
                        <executions>
                            <execution>
                                <id>repack-step1</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>com.github.nbbrd.picocsv</groupId>
                                            <artifactId>picocsv</artifactId>
                                            <version>2.6.0</version>
                                            <classifier>sources</classifier>
                                            <includes>**/Csv.java</includes>
                                        </artifactItem>
                                    </artifactItems>
                                    <outputDirectory>${repack.basedir}</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- Step 2: move files to right folder and replace package declaration & imports -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>repack-step2</id>
                                <phase>initialize</phase>
                                <configuration>
                                    <target>
                                        <move todir="${repack.pacdir}/${repack.prefix}" preservelastmodified="true">
                                            <fileset dir="${repack.basedir}" />
                                        </move>
                                        <replaceregexp byline="true" match="(package|import|import static) nbbrd.picocsv" replace="\1 ${repack.prefix}.nbbrd.picocsv">
                                            <fileset dir="${repack.pacdir}/${repack.prefix}"/>
                                        </replaceregexp>
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- Step 3: add repacked folder as source folder -->
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <version>3.6.1</version>
                        <executions>
                            <execution>
                                <id>repack-step3</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>add-source</goal>
                                </goals>
                                <configuration>
                                    <sources>
                                        <source>${repack.pacdir}</source>
                                    </sources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
