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

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  
  <groupId>info.julang</groupId>
  <artifactId>JSE</artifactId>
  <version>0.1.34</version>
  <!-- During regular development, use ${jse.version}. However, 
       (1) putting a variable here may cause an error when executing lifecycle mapping plugin inside Eclipse;
       (2) IMPORTANT: maven-install-plugin and maven-deploy-plugin are unable to use the version read from variable. -->

  <name>JSE</name>
  <url>https://julang.info</url>
  <description>Julian Script Engine</description>

  <licenses>
    <license>
      <name>MIT License</name>
      <url>https://opensource.org/licenses/MIT</url>
      <distribution>repo</distribution>
    </license>
  </licenses>

  <developers>
    <developer>
      <name>Ming Zhou</name>
      <email>zhoux738@umn.edu</email>
      <organization>Julian Script Engine Team</organization>
      <organizationUrl>https://julang.info</organizationUrl>
    </developer>
  </developers>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.antlr</groupId>
      <artifactId>antlr4-runtime</artifactId>
      <version>4.5</version>
    </dependency>
    <dependency>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>properties-maven-plugin</artifactId>
      <version>1.0.0</version>
    </dependency>
    <!-- JULENG: START -->
    <dependency>
      <groupId>info.julang.eng</groupId>
      <artifactId>juleng-maven-plugin</artifactId>
      <version>0.0.4</version>
    </dependency>
    <!-- JULENG: END -->
  </dependencies>
  
  <profiles>
    <profile>
      <id>jdk8OrBelow</id>
      <activation>
        <jdk>(, 1.9)</jdk>
      </activation>
      <properties>
        <test.argline></test.argline>
      </properties>
    </profile>
    <profile>
      <id>jdk9OrUp</id>
      <activation>
        <jdk>[1.9,)</jdk>
      </activation>
      <properties>
        <test.argline>--illegal-access=permit --add-opens java.base/java.lang.invoke=ALL-UNNAMED</test.argline>
      </properties>
    </profile>
	<profile>
		<id>release-sign-artifacts</id>
		<activation>
			<property>
				<name>releaseToMCR</name>
				<value>true</value>
			</property>
		</activation>
		<build>
			<plugins>
	            <plugin>
	              <groupId>org.apache.maven.plugins</groupId>
	              <artifactId>maven-source-plugin</artifactId>
	              <version>3.2.0</version>
	              <executions>
	                <execution>
	                  <id>attach-sources</id>
				      <phase>verify</phase>
	                  <goals>
	                    <goal>jar-no-fork</goal>
	                  </goals>
	                </execution>
	              </executions>
	            </plugin>
	         	<plugin>
				  <groupId>org.apache.maven.plugins</groupId>
				  <artifactId>maven-javadoc-plugin</artifactId>
				  <version>2.10.4</version>
				  <configuration>
				    <encoding>UTF-8</encoding>
					<source>8</source>
				    <excludePackageNames>
						info.julang.clapp*;info.julang.dev;info.julang.execution*;info.julang.hosting*;info.julang.jsr223;
						info.julang.interpretation*;info.julang.langspec;info.julang.memory*;info.julang.modulesystem*;
						info.julang.parser;info.julang.scanner;info.julang.typesystem*</excludePackageNames>
				  </configuration>
				  <executions>
				    <execution>
				      <id>attach-javadoc</id>
				      <phase>verify</phase>
				      <goals>
				        <goal>jar</goal>
				      </goals>
				    </execution>
				  </executions>
				</plugin>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-gpg-plugin</artifactId>
					<version>1.6</version>
					<executions>
						<execution>
							<id>sign-artifacts</id>
							<phase>verify</phase>
							<goals>
								<goal>sign</goal>
							</goals>
							<configuration>
				                <gpgArguments>
				                    <arg>--pinentry-mode</arg>
				                    <arg>loopback</arg>
				                </gpgArguments>
				            </configuration>
						</execution>
					</executions>
				</plugin>
			</plugins>
		</build>
	</profile>
  </profiles>
  
  <!-- Deployment to Maven central repository: START -->
  <!-- See https://central.sonatype.org/pages/apache-maven.html -->
  <distributionManagement>
	<snapshotRepository>
	  <id>ossrh</id>
	  <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
	</snapshotRepository>
	<repository>
	  <id>ossrh</id>
	  <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
	</repository>
  </distributionManagement>
		
  <scm>
	<connection>scm:git:git://github.com/zhoux738/JSE.git</connection>
	<developerConnection>scm:git:git@github.com:zhoux738/JSE.git</developerConnection>
	<url>https://github.com/zhoux738/JSE</url>
	<tag>HEAD</tag>
  </scm>
  <!-- Deployment to Maven central repository: END -->
  
  <build>    
    <plugins>
      <!-- [1] Read properties -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0.0</version>
        <executions>
          <execution>
              <phase>initialize</phase>
            <goals>
              <goal>read-project-properties</goal>
            </goals>
            <configuration>
              <files>
                <file>./build.properties</file>
              </files>
            </configuration>
          </execution>
        </executions>
      </plugin>
    
      <!-- JULENG: START -->
      <!-- [2.a] Generate source code for JuFC classes -->
      <plugin>
        <groupId>info.julang.eng</groupId>
        <artifactId>juleng-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <skip>${juleng.codegen.disable}</skip>
            </configuration>
          </execution>
        </executions>
      </plugin>
   
      <!-- [2.b] Extract documentation for JuFC classes (default is false) -->
      <!-- To only generate doc, run
           mvn clean generate-resources -Djuleng.codegen.disable=true -Djuleng.docgen.enable=true -Djuleng.docgen.clean=false -Djuleng.docgen.format=md -Djuleng.docgen.pattern=*
           Legal values for -Djuleng.docgen.format: json, md, html -->
      <plugin>
        <groupId>info.julang.eng</groupId>
        <artifactId>juleng-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>docgen</goal>
            </goals>
            <configuration>
              <enable>${juleng.docgen.enable}</enable>
              <pattern>${juleng.docgen.pattern}</pattern>
              <format>${juleng.docgen.format}</format>
              <clean>${juleng.docgen.clean}</clean>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- JULENG: END -->
        
      <!-- [3] Generate ANTLR parser/lexer. -->
      <!-- Alternatively one can run 'mvn antlr4:antlr4' to invoke it independently. -->
      <plugin>
        <groupId>org.antlr</groupId>
        <artifactId>antlr4-maven-plugin</artifactId>
        <version>4.5</version>
        <configuration>
          <visitor>true</visitor>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>antlr4</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      
      <!-- [4] Compile the main source. -->  
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
        <executions>
            <execution>
                <id>compile-main</id>
            </execution>
        </executions>
      </plugin>
      
      <!-- [5] Unit Tests (use -D skip.surefire.tests=true to skip) -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M4</version>
        <configuration>
          <includes>
            <include>**/*Test.java</include>
            <include>**/*Tests.java</include>
          </includes>
          <skipTests>${skip.surefire.tests}</skipTests>
          <argLine>${test.argline}</argLine>
        </configuration>
      </plugin>
      
      <!-- [6] IO Tests -->
      <!-- We use Maven's failsafe plugin to run IO-dependent tests. The real purpose of this plugin is to run 
           integration tests, but we defer such tests to our containerized harness. The tests here are configured 
           such that we can either run them individually/collectively from Eclipse, or run them as part of Maven 
           build from command line. The procedure involves:
       (1) Add the source folder for IO tests. IO tests are placed in a separate folder so that we can run all 
           unit tests easily from Eclipse (by selecting src/test/java and clicking "Runs As JUnit Test")  
       (2) Compile the new source folder. A small issue is that we have to put this in the phase of 
           integration-test. Ideally it should be part of pre-integration-test but configuring so would cause
           compiler plugin run before build helper plugin, despite the declared order of them in the pom file.
       (3) Run all IO tests from the newly compiled class files. -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
            <execution>
                <id>add-io-tests-source</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>add-test-source</goal>
                </goals>
                <configuration>
                    <sources>
                        <source>src/test/java-io</source>
                    </sources>
                </configuration>
            </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
        <executions>
            <execution>
                <id>compile-io-tests</id>
                <phase>integration-test</phase>
                <goals>
                   <goal>testCompile</goal>
                </goals>
                <configuration>
                    <testIncludes>
                        <include>**/*.java</include>
                        <include>**/*.jul</include>
                    </testIncludes>
                </configuration>
            </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>3.0.0-M4</version>
        <executions>
            <execution>
                <id>run-io-tests</id>
                <phase>integration-test</phase>
                <goals>
                    <goal>integration-test</goal>
                    <goal>verify</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <!-- classesDirectory is defaulted to project artifact, which in our case is CI-{VER}.jar 
                 (although it really should be JSE-{VER}.jar, but that's another story). The problem is
                 adding jars to class path will cause severe class loading issue if we still want to run 
                 it in the fashion of unit tests. So we replace jar with the raw class directory. -->
            <classesDirectory>${project.build.outputDirectory}</classesDirectory>
            <redirectTestOutputToFile>true</redirectTestOutputToFile>
            <testSourceDirectory>src/test/java-io</testSourceDirectory>
            <includes>
                <include>**/*TestSuite.*</include>
            </includes>
            <argLine>${test.argline}</argLine>
        </configuration>
      </plugin>
      
      <!-- [7] Assembling artifacts -->
      <!-- We generate two jars. JSE.jar for main delivery; CI.jar for continuous testing. -->
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <!-- Jar #1: CI executable for containerized testing -->
          <execution>
            <id>build-ci</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <finalName>CI-${project.version}</finalName>
              <appendAssemblyId>false</appendAssemblyId>
              <classifier>SNAPSHOT</classifier>
              <descriptors>
                <descriptor>./build/ci-assembly.xml</descriptor>
              </descriptors>
              <archive>
                 <manifest>
                   <mainClass>info.jultest.ci.CITestRunner</mainClass>
                 </manifest>
                 <manifestEntries>
                   <JSE-Version>${version}</JSE-Version>
                 </manifestEntries>
              </archive>
            </configuration>
          </execution>
          <!-- Jar #2: JSE executable -->
          <execution>
            <id>build-jse</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <finalName>JSE-${project.version}</finalName>
              <appendAssemblyId>false</appendAssemblyId>
              <descriptors>
                <descriptor>./build/assembly.xml</descriptor>
              </descriptors>
              <archive>
                 <manifest>
                   <mainClass>info.julang.CmdLineApplication</mainClass>
                 </manifest>
                 <manifestEntries>
                   <JSE-Version>${version}</JSE-Version>
                 </manifestEntries>
              </archive>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
    
    <resources>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.jul</include>
          <include>**/jse.*.template</include>
        </includes>
        <excludes>
          <exclude>**/*test*.*</exclude>
        </excludes>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>**/*</include>
        </includes>
      </resource>
    </resources>

    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        info.julang.eng
                                    </groupId>
                                    <artifactId>
                                        juleng-maven-plugin
                                    </artifactId>
                                    <versionRange>
                                        [0.0.3,)
                                    </versionRange>
                                    <goals>
                                        <goal>generate</goal>
                                        <goal>docgen</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>

            <!-- Deployment to Maven central repository: START -->
			<plugin>
				<artifactId>maven-deploy-plugin</artifactId>
				<version>2.8.2</version>
				<executions>
					<execution>
						<id>default-deploy</id>
						<phase>deploy</phase>
						<goals>
							<goal>deploy</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-release-plugin</artifactId>
				<version>2.5.3</version>
				<configuration>
					<localCheckout>true</localCheckout>
					<pushChanges>false</pushChanges>
					<mavenExecutorId>forked-path</mavenExecutorId>
					<arguments>-Dgpg.passphrase=${gpg.passphrase}</arguments>
				</configuration>
				<dependencies>
					<dependency>
						<groupId>org.apache.maven.scm</groupId>
						<artifactId>maven-scm-provider-gitexe</artifactId>
						<version>1.9.5</version>
					</dependency>
				</dependencies>
			</plugin>
			
			<plugin>
				<groupId>org.sonatype.plugins</groupId>
				<artifactId>nexus-staging-maven-plugin</artifactId>
				<version>1.6.7</version>
				<extensions>true</extensions>
				<configuration>
					<serverId>ossrh</serverId>
					<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
					<autoReleaseAfterClose>true</autoReleaseAfterClose>
				</configuration>
			</plugin>
		    <!-- Deployment to Maven central repository: END -->

            <!-- Putting a variable in version property (jse.version) causes an error 
                 when executing lifecycle-mapping plug-in inside Eclipse, but running 
                 Maven from cmdline is not affected. This plug-in is therefore commented out.
            <plugin>
             <groupId>org.eclipse.m2e</groupId>
             <artifactId>lifecycle-mapping</artifactId>
             <version>1.0.0</version>
             <configuration>
               <lifecycleMappingMetadata>
                 <pluginExecutions>
                   <pluginExecution>
                     <pluginExecutionFilter>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>properties-maven-plugin</artifactId>
                        <version>1.0.0</version>
                        <goals>
                          <goal>read-project-properties</goal>
                        </goals>
                     </pluginExecutionFilter>
                     <action>
                       <ignore/>
                     </action>
                   </pluginExecution>
                 </pluginExecutions>
               </lifecycleMappingMetadata>
             </configuration>
            </plugin>
            -->
        </plugins>
    </pluginManagement>
  </build>
</project>
