<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<parent>
		<groupId>org.springframework.boot.ide</groupId>
		<artifactId>org.springframework.boot.ide</artifactId>
		<version>4.5.1-SNAPSHOT</version>
		<relativePath>../pom.xml</relativePath>
	</parent>

	<artifactId>org.springframework.boot.ide.product</artifactId>

	<packaging>eclipse-repository</packaging>

	<properties>
		<dist.accessKey>${accessKey}</dist.accessKey>
		<dist.secretKey>${secretKey}</dist.secretKey>
	</properties>

	<build>
		<plugins>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-install-plugin</artifactId>
				<version>2.5.2</version>
				<executions>
					<execution>
						<id>default-install</id>
						<phase>none</phase>
					</execution>
				</executions>
			</plugin>

			<plugin>
				<groupId>org.eclipse.tycho</groupId>
				<artifactId>tycho-p2-repository-plugin</artifactId>
				<version>${tycho-version}</version>
				<configuration>
					<includeAllDependencies>false</includeAllDependencies>
				</configuration>
			</plugin>
			  
			<plugin>
				<groupId>org.eclipse.tycho</groupId>
				<artifactId>tycho-p2-publisher-plugin</artifactId>
				<version>${tycho-version}</version>
				<configuration>
					<publishArtifacts>true</publishArtifacts>
				</configuration>
			</plugin>

			<plugin>
				<groupId>org.eclipse.tycho</groupId>
				<artifactId>target-platform-configuration</artifactId>
				<version>${tycho-version}</version>
				<configuration>
					<executionEnvironment>JavaSE-9</executionEnvironment>
				</configuration>
			</plugin>

			<plugin>
				<groupId>org.eclipse.tycho</groupId>
				<artifactId>tycho-p2-director-plugin</artifactId>
				<version>${tycho-version}</version>
				<executions>
					<execution>
						<id>materialize-products</id>
						<goals>
							<goal>materialize-products</goal>
						</goals>
						<phase>package</phase>
					</execution>
					<execution>
						<id>archive-products</id>
						<goals>
							<goal>archive-products</goal>
						</goals>
						<phase>verify</phase>
					</execution>
				</executions>
				<configuration>
					<products>
						<product>
							<id>org.springframework.boot.ide.branding.sts4</id>
							<rootFolder>sts-${unqualifiedVersion}.${p2.qualifier}</rootFolder>
							<rootFolders>
								<macosx>SpringToolSuite4.app</macosx>
							</rootFolders>
							<archiveFileName>spring-tool-suite-4-${unqualifiedVersion}.${p2.qualifier}-${dist.target}</archiveFileName>
						</product>
					</products>
					<formats>
						<linux>tar.gz</linux>
						<macosx>tar.gz</macosx>
					</formats>
				</configuration>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-antrun-plugin</artifactId>
				<version>1.7</version>
				<executions>

					<execution>
						<id>osx-app-signing</id>
						<phase>package</phase>
						<configuration>
							<skip>${skip.osx.signing}</skip>
							<target>

								<taskdef resource="net/sf/antcontrib/antcontrib.properties" />

								<exec executable="codesign" failonerror="true">
									<arg value="--verbose"/>
								    <arg value="--keychain"/>
								    <arg value="${env.KEYCHAIN}"/>
								    <arg value="-s"/>
								    <arg value="Developer ID Application: Trevor Marshall"/>
								    <arg value="${project.build.directory}/products/org.springframework.boot.ide.branding.sts4/macosx/cocoa/x86_64/SpringToolSuite4.app"/>
								</exec>

							</target>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>

					<execution>
						<id>osx-dmg-creation</id>
						<phase>verify</phase>
						<configuration>
							<target>

								<exec executable="/usr/local/bin/appdmg" failonerror="true">
									<arg value="${project.build.directory}/../spring-tool-suite-4-dmg-config-${dist.target.major}.json"/>
									<arg value="${project.build.directory}/products/spring-tool-suite-4-${unqualifiedVersion}.${p2.qualifier}-${dist.target}-macosx.cocoa.x86_64.dmg"/>
								</exec>

								<delete file="${project.build.directory}/products/spring-tool-suite-4-${unqualifiedVersion}.${p2.qualifier}-${dist.target}-macosx.cocoa.x86_64.tar.gz"/>
								
							</target>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>

					<execution>
						<id>osx-dmg-signing</id>
						<phase>verify</phase>
						<configuration>
							<skip>${skip.osx.signing}</skip>
							<target>

								<taskdef resource="net/sf/antcontrib/antcontrib.properties" />

								<property name="dmgName" value="${project.build.directory}/products/spring-tool-suite-4-${unqualifiedVersion}.${p2.qualifier}-${dist.target}-macosx.cocoa.x86_64.dmg" />

								<exec executable="codesign" failonerror="true">
									<arg value="--verbose"/>
								    <arg value="--keychain"/>
								    <arg value="${env.KEYCHAIN}"/>
								    <arg value="-s"/>
								    <arg value="Developer ID Application: Trevor Marshall"/>
								    <arg value="${dmgName}"/>
								</exec>

							</target>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>

					<execution>
						<id>upload-product-bundles</id>
						<phase>deploy</phase>
						<configuration>
							<target>

								<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
								<taskdef resource="org/springframework/build/aws/ant/antlib.xml" />

								<checksum file="${project.build.directory}/products/spring-tool-suite-4-${unqualifiedVersion}.${p2.qualifier}-${dist.target}-macosx.cocoa.x86_64.dmg" algorithm="SHA1" fileext=".sha1" />
								<checksum file="${project.build.directory}/products/spring-tool-suite-4-${unqualifiedVersion}.${p2.qualifier}-${dist.target}-macosx.cocoa.x86_64.dmg" algorithm="MD5" fileext=".md5" />
								<checksum file="${project.build.directory}/products/spring-tool-suite-4-${unqualifiedVersion}.${p2.qualifier}-${dist.target}-linux.gtk.x86_64.tar.gz" algorithm="SHA1" fileext=".sha1" />
								<checksum file="${project.build.directory}/products/spring-tool-suite-4-${unqualifiedVersion}.${p2.qualifier}-${dist.target}-linux.gtk.x86_64.tar.gz" algorithm="MD5" fileext=".md5" />
								<checksum file="${project.build.directory}/products/spring-tool-suite-4-${unqualifiedVersion}.${p2.qualifier}-${dist.target}-win32.win32.x86_64.zip" algorithm="SHA1" fileext=".sha1" />
								<checksum file="${project.build.directory}/products/spring-tool-suite-4-${unqualifiedVersion}.${p2.qualifier}-${dist.target}-win32.win32.x86_64.zip" algorithm="MD5" fileext=".md5" />

								<s3 accessKey="${dist.accessKey}" secretKey="${dist.secretKey}">

									<delete bucketName="${dist.bucket}">
										<fileset dir="${dist.path.product}">
											<include name="spring-tool-suite-4*.zip" />
											<include name="spring-tool-suite-4*.zip.md5" />
											<include name="spring-tool-suite-4*.zip.sha1" />
											<include name="spring-tool-suite-4*.tar.gz" />
											<include name="spring-tool-suite-4*.tar.gz.md5" />
											<include name="spring-tool-suite-4*.tar.gz.sha1" />
											<include name="spring-tool-suite-4*.dmg" />
											<include name="spring-tool-suite-4*.dmg.md5" />
											<include name="spring-tool-suite-4*.dmg.sha1" />
										</fileset>
									</delete>

									<upload bucketName="${dist.bucket}" toDir="${dist.path.product}"
										publicRead="true">
										<fileset dir="${project.build.directory}/products">
											<include name="spring-tool-suite-4*.zip" />
											<include name="spring-tool-suite-4*.zip.md5" />
											<include name="spring-tool-suite-4*.zip.sha1" />
											<include name="spring-tool-suite-4*.tar.gz" />
											<include name="spring-tool-suite-4*.tar.gz.md5" />
											<include name="spring-tool-suite-4*.tar.gz.sha1" />
											<include name="spring-tool-suite-4*.dmg" />
											<include name="spring-tool-suite-4*.dmg.md5" />
											<include name="spring-tool-suite-4*.dmg.sha1" />
										</fileset>
									</upload>

								</s3>

							</target>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>

					<execution>
						<id>update-nightly-downloads</id>
						<phase>deploy</phase>
						<configuration>
							<skip>${skip.update-nightly-download-page}</skip>
							<target>
								<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
								<taskdef resource="org/springframework/build/aws/ant/antlib.xml" />

								<copy file="${project.build.directory}/../../common/html/nightly-generic-snippet.html" tofile="${project.build.directory}/../../common/html/sts4-nightly-${dist.target.major}.html"/>
		
								<replace file="${project.build.directory}/../../common/html/sts4-nightly-${dist.target.major}.html" token="@QUALIFIER@" value="${unqualifiedVersion}.${p2.qualifier}" summary="yes" />
								<replace file="${project.build.directory}/../../common/html/sts4-nightly-${dist.target.major}.html" token="@TARGET@" value="${dist.target}" summary="yes" />
								<replace file="${project.build.directory}/../../common/html/sts4-nightly-${dist.target.major}.html" token="@MAJOR-TARGET@" value="${dist.target.major}" summary="yes" />

								<s3 accessKey="${dist.accessKey}" secretKey="${dist.secretKey}">
									<upload bucketName="${dist.bucket}" file="${project.build.directory}/../../common/html/sts4-nightly-${dist.target.major}.html"
										toFile="snapshot/STS4/sts4-nightly-${dist.target.major}.html" publicRead="true">
									</upload>
								</s3>
							</target>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>

					<execution>
						<id>zip-sts-repository</id>
						<phase>install</phase>
						<configuration>
							<target>

								<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
								<taskdef resource="org/springframework/build/aws/ant/antlib.xml" />

								<property name="dist.full.version" value="${unqualifiedVersion}.${p2.qualifier}-${dist.target}" />
								<property name="dist.file.name" value="${dist.project}-${dist.full.version}-updatesite.zip" />

								<zip zipfile="${project.build.directory}/repository/${dist.file.name}" filesonly="true">
									<zipfileset
										dir="${project.build.directory}/repository">
										<exclude name="*.zip" />
										<exclude name="**/*.gz" />
									</zipfileset>
								</zip>

								<checksum file="${project.build.directory}/repository/${dist.file.name}" algorithm="SHA1" fileext=".sha1" />
								<checksum file="${project.build.directory}/repository/${dist.file.name}" algorithm="MD5" fileext=".md5" />

							</target>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>

					<execution>
						<id>upload-sts-repository</id>
						<phase>deploy</phase>
						<configuration>
							<target>

								<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
								<taskdef resource="org/springframework/build/aws/ant/antlib.xml" />

								<s3 accessKey="${dist.accessKey}" secretKey="${dist.secretKey}">

									<delete bucketName="${dist.bucket}">
										<fileset dir="${dist.path.repo}">
											<include name="p2.index" />
											<include name="site.xml" />
											<include name="content.jar" />
											<include name="artifacts.xml.xz" />
											<include name="content.jar" />
											<include name="content.xml.xz" />
											<include name="plugins/**" />
											<include name="features/**" />
											<include name="binary/**" />
											<include name="*.zip" />
											<include name="*.sha1" />
											<include name="*.md5" />
										</fileset>
									</delete>

									<upload bucketName="${dist.bucket}" toDir="${dist.path.repo}" publicRead="true">
										<fileset
											dir="${project.build.directory}/repository">
											<include name="**/*" />
											<include name="**" />
										</fileset>
									</upload>

								</s3>

							</target>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>

				</executions>
				<dependencies>
					<dependency>
						<groupId>org.springframework.build</groupId>
						<artifactId>org.springframework.build.aws.ant</artifactId>
						<version>3.1.0.RELEASE</version>
					</dependency>
					<dependency>
						<groupId>net.java.dev.jets3t</groupId>
						<artifactId>jets3t</artifactId>
						<version>0.8.1</version>
					</dependency>
					<dependency>
						<groupId>ant-contrib</groupId>
						<artifactId>ant-contrib</artifactId>
						<version>20020829</version>
					</dependency>
				</dependencies>
			</plugin>

		</plugins>

	</build>
</project>
