<?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>

    <groupId>io.github.atkawa7</groupId>
    <artifactId>polly-http</artifactId>
    <version>0.0.19</version>

    <name>polly-http</name>
    <description>polly-http</description>
    <url>https://github.com/atkawa7/polly-http</url>
    <licenses>
        <license>
            <name>Apache License</name>
            <url>https://raw.githubusercontent.com/atkawa7/polly-http/LICENSE.txt</url>
            <distribution>https://github.com/atkawa7/polly-http</distribution>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>atkawa7</name>
            <email>atkawa7@yahoo.com</email>
            <organization>atkawa7</organization>
            <organizationUrl>https://github.com/atkawa7</organizationUrl>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:git://github.com/atkawa7/polly-http.git</connection>
        <developerConnection>scm:git:git@github.com:atkawa7/polly-http.git</developerConnection>
        <tag>polly-http-0.0.19</tag>
        <url>https://github.com/atkawa7/polly-http</url>
    </scm>

    <distributionManagement>
        <repository>
            <id>ossrh</id>
            <name>Central Repository OSSRH</name>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.38</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.36</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.36</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.19.2</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>4.12.0</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents.client5</groupId>
            <artifactId>httpclient5</artifactId>
            <version>5.5</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.jqwik</groupId>
            <artifactId>jqwik</artifactId>
            <version>1.9.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>3.27.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.code-intelligence</groupId>
            <artifactId>jazzer-junit</artifactId>
            <version>0.24.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>aws-core</artifactId>
            <version>2.34.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>s3</artifactId>
            <version>2.34.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>oauth.signpost</groupId>
            <artifactId>signpost-core</artifactId>
            <version>2.1.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.github.scribejava</groupId>
            <artifactId>scribejava-core</artifactId>
            <version>8.3.3</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.4.0</version>
                <executions>
                    <execution>
                        <id>regex-property</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>regex-property</goal>
                        </goals>
                        <configuration>
                            <name>groupId.path</name>
                            <value>${project.groupId}</value>
                            <regex>\.</regex>
                            <replacement>/</replacement>
                            <failIfNoMatch>true</failIfNoMatch>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                        <phase>deploy</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>3.0.0-M1</version>
                <executions>
                    <execution>
                        <id>deploy</id>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                        <phase>deploy</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <source>8</source>
                    <detectJavaApiLink>false</detectJavaApiLink>
                    <additionalJOption>-Xdoclint:none</additionalJOption>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <phase>deploy</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>3.0.0-M4</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <executions>
                    <execution>
                        <id>default-compile</id>
                        <phase>compile</phase>
                        <goals><goal>compile</goal></goals>
                        <configuration>
                            <release>8</release>
                        </configuration>
                    </execution>
                    <execution>
                        <id>java-11</id>
                        <phase>compile</phase>
                        <goals><goal>compile</goal></goals>
                        <configuration>
                            <release>11</release>
                            <compileSourceRoots>
                                <compileSourceRoot>${project.basedir}/src/main/java11</compileSourceRoot>
                            </compileSourceRoots>
                            <multiReleaseOutput>true</multiReleaseOutput>
                        </configuration>
                    </execution>
                    <execution>
                        <id>default-testCompile</id>
                        <phase>test-compile</phase>
                        <goals><goal>testCompile</goal></goals>
                        <configuration>
                            <compileSourceRoots>
                                <compileSourceRoot>${project.basedir}/src/test/java</compileSourceRoot>
                                <compileSourceRoot>${project.basedir}/src/main/java11</compileSourceRoot>
                            </compileSourceRoots>
                            <release>11</release>
                        </configuration>
                    </execution>
                </executions>

            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <Multi-Release>true</Multi-Release>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>1.6</version>
                <configuration>
                    <gpgArguments>
                        <arg>--pinentry-mode</arg>
                        <arg>loopback</arg>
                    </gpgArguments>
                </configuration>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                        <phase>verify</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>hash-artifacts</id>
                        <phase>verify</phase>
                        <configuration>
                            <target>
                                <checksum fileext=".sha256" algorithm="SHA-256">
                                    <fileset dir="${project.build.directory}">
                                        <include name="*.jar" />
                                        <include name="*.pom" />
                                    </fileset>
                                </checksum>
                                <checksum fileext=".sha512" algorithm="SHA-512">
                                    <fileset dir="${project.build.directory}">
                                        <include name="*.jar" />
                                        <include name="*.pom" />
                                    </fileset>
                                </checksum>
                                <checksum fileext=".md5" algorithm="MD5">
                                    <fileset dir="${project.build.directory}">
                                        <include name="*.jar" />
                                        <include name="*.pom" />
                                    </fileset>
                                </checksum>
                                <checksum fileext=".sha1" algorithm="SHA-1">
                                    <fileset dir="${project.build.directory}">
                                        <include name="*.jar" />
                                        <include name="*.pom" />
                                    </fileset>
                                </checksum>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.5.0</version>
                <executions>
                    <execution>
                        <id>make-project-zip</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <finalName>${project.artifactId}-${project.version}</finalName>
                            <appendAssemblyId>false</appendAssemblyId>
                            <descriptors>
                                <descriptor>src/assembly/central-upload.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.gmavenplus</groupId>
                <artifactId>gmavenplus-plugin</artifactId>
                <version>3.0.2</version>
                <executions>
                    <execution>
                        <id>upload-bundle</id>
                        <phase>none</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <scripts>
                                <script>
                                    import java.net.HttpURLConnection
                                    import java.nio.file.Files
                                    import java.nio.file.Paths
                                    import java.util.Base64
                                    import java.util.UUID

                                    def version = project.version
                                    def artifactId = project.artifactId
                                    def zipPath = Paths.get("target/${project.artifactId}-${project.version}.zip")
                                    if (!Files.exists(zipPath)) throw new FileNotFoundException(zipPath.toString())

                                    // Retrieve credentials from Maven settings (settings.xml)
                                    def server = session.settings.getServer("ossrh")
                                    if (!server) throw new RuntimeException("Missing &lt;server&gt; with id='ossrh' in settings.xml")

                                    def username = server.username
                                    def password = server.password
                                    if (!username || !password) throw new RuntimeException("Username or password not defined in settings.xml")

                                    def authString = "${username}:${password}"
                                    def encodedAuth = Base64.encoder.encodeToString(authString.bytes)

                                    def zipFile = "target/${project.artifactId}-${project.version}.zip"

                                    def command = [
                                    "curl", "--fail", "--show-error",
                                    "--request", "POST",
                                    "--header", "Authorization: Bearer ${encodedAuth}",
                                    "--form", "bundle=@${zipFile}",
                                    "--form", "name=${project.artifactId}-${project.version}",
                                    "--form", "publishingType=USER_MANAGED",
                                    "https://central.sonatype.com/api/v1/publisher/upload"
                                    ]
                                    def process = new ProcessBuilder(command as String[])
                                    .redirectErrorStream(true)
                                    .start()

                                    process.inputStream.eachLine { println it }

                                    def exitCode = process.waitFor()
                                    if (exitCode != 0) {
                                    throw new RuntimeException("curl failed with exit code ${exitCode}")
                                    }

                                </script>
                            </scripts>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy</artifactId>
                        <version>3.0.25</version>
                    </dependency>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-ant</artifactId>
                        <version>3.0.25</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>
