<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>jp.seraphyware.charactermanaj</groupId>
	<artifactId>CharacterManaJ</artifactId>
	<version>0.9.9.9</version>

	<url>https://osdn.net/projects/charactermanaj/</url>

	<scm>
		<connection>scm:git:https://scm.osdn.net/gitroot/charactermanaj/CharacterManaJ.git</connection>
		<tag>HEAD</tag>
		<url>https://osdn.net/projects/charactermanaj/scm/git/CharacterManaJ/</url>
	</scm>

	<organization>
		<name>seraphyware</name>
		<url>https://osdn.net/projects/charactermanaj/</url>
	</organization>

	<developers>
		<developer>
			<id>seraphy</id>
			<name>seraphy</name>
			<email>seraphy@users.osdn.me</email>
			<url>https://osdn.net/users/seraphy/</url>
			<organization>seraphyware</organization>
			<roles>
				<role>architect</role>
				<role>developer</role>
			</roles>
			<timezone>Asia/Tokyo</timezone>
		</developer>
	</developers>

	<properties>
		<mainClass>charactermanaj.CharacterManaJ</mainClass>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<maven.compiler.source>1.6</maven.compiler.source>
		<maven.compiler.target>1.6</maven.compiler.target>
		<animalSnifferArtifact>java16</animalSnifferArtifact>
		<animalSnifferArtifactVersion>1.1</animalSnifferArtifactVersion>
		<maven.build.timestamp.format>yyyy-MM-dd</maven.build.timestamp.format>
	</properties>

	<dependencies>
		<!-- https://mvnrepository.com/artifact/com.apple/AppleJavaExtensions -->
		<dependency>
			<groupId>com.apple</groupId>
			<artifactId>AppleJavaExtensions</artifactId>
			<version>1.4</version>
			<scope>provided</scope>
		</dependency>

		<!-- テスト -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11</version>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<!-- 現在時刻からユニークなビルド番号を生成する
				(使うか否かに関わらず、SCMの設定が必要。
				buildNumberの連番を使う場合はローカルにプロパティファイルが作成される) -->
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>buildnumber-maven-plugin</artifactId>
				<version>1.4</version>
				<executions>
					<execution>
						<phase>validate</phase>
						<goals>
							<goal>create</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<doCheck>false</doCheck>
					<doUpdate>true</doUpdate>
					<format>{0,date,yyyyMM}.{0,date,ddHHmm}</format>
					<items>
						<item>timestamp</item>
					</items>
				</configuration>
			</plugin>
			<plugin>
				<!-- コンパイラープラグイン -->
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<source>${maven.compiler.source}</source>
					<target>${maven.compiler.target}</target>
					<compilerArgument>-Xlint:all</compilerArgument>
				</configuration>
			</plugin>
			<plugin>
				<!-- 互換性チェック -->
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>animal-sniffer-maven-plugin</artifactId>
				<version>1.16</version>
				<configuration>
					<signature>
						<groupId>org.codehaus.mojo.signature</groupId>
						<artifactId>${animalSnifferArtifact}</artifactId>
						<version>${animalSnifferArtifactVersion}</version>
					</signature>
					<ignoreDependencies>true</ignoreDependencies>
				</configuration>
				<executions>
					<execution>
						<id>check-java-api</id>
						<phase>test</phase>
						<goals>
							<goal>check</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<!-- 実行可能jar本体のパッケージを行う (package時) -->
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<version>3.1.0</version>
				<configuration>
					<finalName>${project.artifactId}</finalName>
					<archive>
						<manifest>
							<mainClass>${mainClass}</mainClass>
							<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
							<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
						</manifest>
						<manifestEntries>
							<!-- 起動時のスプラッシュ画像 -->
							<SplashScreen-Image>splash.png</SplashScreen-Image>
							<Build-At>${maven.build.timestamp}</Build-At>
							<Built-By>${project.developers[0].id}</Built-By>
							<Build-Timestamp>${maven.build.timestamp}</Build-Timestamp>
							<Specification-Title>${project.name}</Specification-Title>
							<Specification-Version>${project.version}</Specification-Version>
							<Specification-Vendor>${project.organization.name}</Specification-Vendor>
							<Implementation-Title>${project.name}</Implementation-Title>
							<Implementation-Version>${project.version}.${buildNumber}</Implementation-Version>
							<Implementation-Vendor-Id>${project.organization.name}</Implementation-Vendor-Id>
							<Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
						</manifestEntries>
					</archive>
				</configuration>
			</plugin>
		</plugins>
	</build>

	<profiles>
		<profile>
			<!-- Windowsの場合のビルド -->
			<id>windows-profile</id>
			<activation>
				<os>
					<family>windows</family>
				</os>
			</activation>
			<properties>
				<copyJrePath>${java.home}</copyJrePath>
			</properties>
			<build>
				<plugins>
					<plugin>
						<!-- Launch4jによるjarファイルのexe化を行う. http://launch4j.sourceforge.net/docs.html
							プラグインが1.7.25の場合、使用するのはLaunch4j 3.12 である。
							https://github.com/lukaszlenart/launch4j-maven-plugin/blob/master/pom.xml -->
						<groupId>com.akathist.maven.plugins.launch4j</groupId>
						<artifactId>launch4j-maven-plugin</artifactId>
						<version>1.7.25</version>
   						<executions>
							<execution>
								<id>l4j-gui</id>
								<phase>package</phase>
								<goals>
									<goal>launch4j</goal>
								</goals>
								<configuration>
									<headerType>gui</headerType>
									<outfile>target/${project.artifactId}.exe</outfile>
									<jar>target/${project.artifactId}.jar</jar>
									<errTitle>Failed to execute the ${project.artifactId}</errTitle>
									<icon>icon.ico</icon>
									<downloadUrl>https://adoptopenjdk.net/</downloadUrl>
									<supportUrl>https://osdn.net/projects/charactermanaj/</supportUrl>
									<objs>
										<!-- 標準のLaunch4jの起動をカスタマイズして、JREがバンドル位置にも
										レジストリにも見つからなかった場合は、ユーザーに場所の選択を問い合わせる -->
										<obj>src/Launch4JStub/w32api/crt2.o</obj>
										<obj>src/Launch4JStub/head/head.o</obj>
										<obj>src/Launch4JStub/head/guihead.o</obj>
									</objs>
									<libs>
										<lib>src/Launch4jStub/w32api/libmingw32.a</lib>
										<lib>src/Launch4jStub/w32api/libgcc.a</lib>
										<lib>src/Launch4jStub/w32api/libmsvcrt.a</lib>
										<lib>src/Launch4jStub/w32api/libkernel32.a</lib>
										<lib>src/Launch4jStub/w32api/libuser32.a</lib>
										<lib>src/Launch4jStub/w32api/libadvapi32.a</lib>
										<lib>src/Launch4jStub/w32api/libshell32.a</lib>
										<lib>src/Launch4jStub/w32api/libshfolder.a</lib>
									</libs>
									<jre>
										<path>jre</path>
										<minVersion>1.6.0</minVersion>
										<initialHeapSize>64</initialHeapSize>
										<maxHeapSize>128</maxHeapSize>
									</jre>
									<versionInfo>
										<fileVersion>${project.version}</fileVersion>
										<txtFileVersion>${project.version}.${buildNumber}</txtFileVersion>
										<fileDescription>${project.artifactId} ${project.version} ${buildNumber}</fileDescription>
										<copyright><![CDATA[${maven.build.timestamp} ${project.developers[0].id}]]></copyright>
										<productVersion>${project.version}</productVersion>
										<txtProductVersion>${project.version}</txtProductVersion>
										<productName>${project.artifactId}</productName>
										<internalName>${project.artifactId}</internalName>
										<originalFilename>${project.artifactId}.exe</originalFilename>
									</versionInfo>
								</configuration>
							</execution>
						</executions>
					</plugin>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-assembly-plugin</artifactId>
						<version>2.6</version>
						<executions>
							<execution>
								<!-- JREつきの配布用zipを生成する -->
								<id>create-distribution-with-jre</id>
								<phase>package</phase>
								<goals>
									<goal>single</goal>
								</goals>
								<configuration>
									<finalName>${project.artifactId}_${project.version}_with_JRE</finalName>
									<appendAssemblyId>false</appendAssemblyId>
									<descriptors>
										<descriptor>src/main/assembly/charactermanaj_with_jre_zip.xml</descriptor>
									</descriptors>
								</configuration>
							</execution>
							<execution>
								<!-- JRE無しの配布用zipを生成する -->
								<id>create-distribution</id>
								<phase>package</phase>
								<goals>
									<goal>single</goal>
								</goals>
								<configuration>
									<finalName>${project.artifactId}_${project.version}</finalName>
									<appendAssemblyId>false</appendAssemblyId>
									<descriptors>
										<descriptor>src/main/assembly/charactermanaj_zip.xml</descriptor>
									</descriptors>
								</configuration>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>

		<profile>
			<!-- MAC OSXの場合のビルド -->
			<id>osx-profile</id>
			<activation>
				<os>
					<family>mac</family>
				</os>
			</activation>
			<properties>
				<copyJrePath>${java.home}</copyJrePath>
			</properties>
			<build>
				<plugins>
					<plugin>
						<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-antrun-plugin -->
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-antrun-plugin</artifactId>
						<version>1.8</version>
						<executions>
							<execution>
								<phase>package</phase>
								<configuration>
									<target>
										<delete dir="${project.build.directory}/appbundle" />
										<mkdir dir="${project.build.directory}/appbundle" />
										<copy todir="${project.build.directory}/appbundle">
											<fileset
												dir="${project.basedir}/src/main/attachment/bundle">
												<include name="**/*" />
												<exclude name="**/Info.plist" />
											</fileset>
										</copy>
										<copy todir="${project.build.directory}/appbundle">
											<filterset>
												<!-- ${project.developers[0].name} だと、うまく変数展開できないため -->
												<filter token="NSHumanReadableCopyright"
													value="${maven.build.timestamp} ${project.organization.name} ${project.organization.url}" />
												<!--  内部用バージョンだが、iosではiTunes ConnectのApp一般情報のバージョンと同一であること。
													a.b.cの3つに整数が連結された形式が推奨される。 -->
												<filter token="BundleVersion" value="${project.version}" />
												<!-- ビルド連番を表す。a.b.cの3つに整数が連結された形式が推奨とされているが、
													実際は、ただの連番(整数値)で良い。iTunes Connectにアップロードする際に、
													アップロードするごとに異なる値でなければならないため、連番の類が適当とされる -->
												<filter token="BundleShortVersionString" value="${buildNumber}" />
											</filterset>
											<fileset
												dir="${project.basedir}/src/main/attachment/bundle">
												<include name="**/Info.plist" />
											</fileset>
										</copy>
										<copy
											todir="${project.build.directory}/appbundle/CharacterManaJ.app/Contents/Resources">
											<fileset dir="${project.basedir}">
												<include name="icon.icns" />
											</fileset>
											<fileset dir="${project.build.directory}">
												<include name="${project.artifactId}.jar" />
											</fileset>
										</copy>

										<chmod dir="${project.build.directory}/appbundle/CharacterManaJ.app/Contents/MacOS"
											perm="a+rx" includes="JavaLaunch"/>
										<copy todir="${project.build.directory}/appbundle">
											<fileset dir="${project.basedir}/src/main/attachment">
												<include name="README_mac.txt"/>
											</fileset>
										</copy>
										<chmod dir="${project.build.directory}/appbundle/CharacterManaJ.app/Contents/Characters"
											perm="g+srw" type="dir"/>
										<chmod dir="${project.build.directory}/appbundle/CharacterManaJ.app/Contents/Characters"
											perm="g+rw" includes="**/*" type="file"/>

										<delete file="${project.build.directory}/${project.artifactId}_${project.version}.dmg"/>
										<exec executable="hdiutil">
											<arg value="create"/>
											<arg value="-fs"/>
											<arg value="HFS+"/>
											<arg value="-format"/>
											<arg value="UDZO"/>
											<arg value="-srcfolder"/>
											<arg value="${project.build.directory}/appbundle"/>
											<arg value="-volname"/>
											<arg value="${project.artifactId}_${project.version}.dmg"/>
											<arg value="${project.build.directory}/${project.artifactId}_${project.version}.dmg"/>
										</exec>
										<exec executable="hdiutil">
											<arg value="internet-enable"/>
											<arg value="-yes"/>
											<arg value="${project.build.directory}/${project.artifactId}_${project.version}.dmg"/>
										</exec>

										<delete dir="${project.build.directory}/appbundle/CharacterManaJ.app/Contents/Plugins/JRE"/>
										<copy todir="${project.build.directory}/appbundle/CharacterManaJ.app/Contents/Plugins/JRE">
											<fileset dir="${copyJrePath}">
												<include name="**/*"/>
												<exclude name="man/**"/>
												<exclude name="demo/**"/>
												<exclude name="include/**"/>
											</fileset>
										</copy>
										<chmod dir="${project.build.directory}/appbundle/CharacterManaJ.app/Contents/Plugins/JRE"
											perm="a+rx" includes="bin/*"/>
										<delete file="${project.build.directory}/${project.artifactId}_${project.version}_with_jre.dmg"/>
										<exec executable="hdiutil">
											<arg value="create"/>
											<arg value="-fs"/>
											<arg value="HFS+"/>
											<arg value="-format"/>
											<arg value="UDZO"/>
											<arg value="-srcfolder"/>
											<arg value="${project.build.directory}/appbundle"/>
											<arg value="-volname"/>
											<arg value="${project.artifactId}_${project.version}.dmg"/>
											<arg value="${project.build.directory}/${project.artifactId}_${project.version}_with_jre.dmg"/>
										</exec>
										<exec executable="hdiutil">
											<arg value="internet-enable"/>
											<arg value="-yes"/>
											<arg value="${project.build.directory}/${project.artifactId}_${project.version}_with_jre.dmg"/>
										</exec>
									</target>
								</configuration>
								<goals>
									<goal>run</goal>
								</goals>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>
	</profiles>
</project>
