<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->
<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>org.apache.hadoop</groupId>
    <artifactId>hadoop-project</artifactId>
    <version>2.7.2-mrs-1.6.0</version>
    <relativePath>../hadoop-project</relativePath>
  </parent>
  <groupId>org.apache.hadoop</groupId>
  <artifactId>hadoop-dist</artifactId>
  <version>2.7.2-mrs-1.6.0</version>
  <description>Apache Hadoop Distribution</description>
  <name>Apache Hadoop Distribution</name>
  <packaging>jar</packaging>

  <!-- Using dependencies to ensure this module is the last one -->
  <dependencies>
    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-common</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-hdfs</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-mapreduce-client-app</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-yarn-api</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.huawei.datasight</groupId>
      <artifactId>datasight-hadoop-trace-ping</artifactId>
      <version>2.7.2-mrs-1.6.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.rat</groupId>
        <artifactId>apache-rat-plugin</artifactId>
        <configuration>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>dist</id>
      <activation>
        <activeByDefault>false</activeByDefault>
        <property>
          <name>tar</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>dist</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <target>
                    <echo file="${project.build.directory}/dist-layout-stitching.sh">
                      run() {
                        echo "\$ ${@}"
                        "${@}"
                        res=$?
                        if [ $res != 0 ]; then
                          echo
                          echo "Failed!"
                          echo
                          exit $res
                        fi
                      }

                      ROOT=`cd ../..;pwd`
                      echo
                      echo "Current directory `pwd`"
                      echo
                      run rm -rf hadoop
                      run mkdir hadoop
                      run cd hadoop
                      run cp $ROOT/LICENSE.txt .
                      run cp $ROOT/NOTICE.txt .
                      run cp $ROOT/README.txt .
                      run cp -r -u $ROOT/hadoop-common-project/hadoop-common/target/hadoop-common-${project.version}/* .
                      run cp -r -u $ROOT/hadoop-common-project/hadoop-nfs/target/hadoop-nfs-${project.version}/* .
                      run cp -r -u $ROOT/hadoop-hdfs-project/hadoop-hdfs/target/hadoop-hdfs-${project.version}/* .
                      run cp -r -u $ROOT/hadoop-hdfs-project/hadoop-hdfs-httpfs/target/hadoop-hdfs-httpfs-${project.version}/* .
                      run cp -r -u $ROOT/hadoop-common-project/hadoop-kms/target/hadoop-kms-${project.version}/* .
                      run cp -r -u $ROOT/hadoop-hdfs-project/hadoop-hdfs-nfs/target/hadoop-hdfs-nfs-${project.version}/* .
                      run cp -r -u $ROOT/hadoop-hdfs-project/hadoop-hdfs-colocation/target/hadoop-hdfs-colocation-${project.version}/* .
                      run cp -r -u $ROOT/hadoop-yarn-project/target/hadoop-yarn-project-${project.version}/* .
                      run cp -r -u $ROOT/hadoop-mapreduce-project/target/hadoop-mapreduce-${project.version}/* .
                      run cp -r -u $ROOT/hadoop-tools/hadoop-tools-dist/target/hadoop-tools-dist-${project.version}/* .
		      run cp -r -u $ROOT/hadoop-hdfs-project/hadoop-hdfs-datamovement/target/hadoop-hdfs-datamovement-${project.version}/* .
                      run cp -r -u $ROOT/hadoop-datasight/target/hadoop-datasight-${project.version}.jar ./share/hadoop/yarn
	              run cp -r -u $ROOT/hadoop-tools/hadoop-hdfs-restore/target/hadoop-hdfs-restore-${project.version}.jar ./share/hadoop/tools/lib
				  #run cp ${superior.home}/superior $PWD/bin/superior
				  run cp $ROOT/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-superior/superior-client/src/main/bin/superior $PWD/bin/superior
	              run cp -r -u $ROOT/hadoop-tools/hadoop-hdfs-restore/src/main/bin/hdfs-restore.sh ./sbin
                  run cp -r -u $ROOT/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-superior/superior-yarn-scheduler/target/superior-yarn-scheduler-${superior-version}.jar ./share/hadoop/yarn/lib   
                  run cp -r -u $ROOT/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-superior/superior-client/target/superior-client-${superior-version}.jar ./share/hadoop/yarn/lib
                      #for health trace tool
 	              run cp -r -u $ROOT/datasight-hadoop-project/datasight-hadoop-tools/datasight-hadoop-trace-ping/target/datasight-hadoop-trace-ping-${project.version}.jar ./share/hadoop/common/
 	              run mkdir datasight-bin
 	              run cp -r -u  $ROOT/datasight-hadoop-project/datasight-hadoop-tools/datasight-hadoop-trace-ping/src/main/bin/healthchecktool.sh ./datasight-bin
 	              run dos2unix $PWD/datasight-bin/*.sh
                      run chmod 500 $PWD/datasight-bin/*.sh
                      run find ./ -iname "*test*.jar" -delete
                      run find ./ -iname "*.java" -delete
                      run rm -rf share/hadoop/mapreduce/sources
                      run rm -rf share/hadoop/common/sources
                      run rm -rf share/hadoop/hdfs/sources
                      run rm -rf share/hadoop/yarn/sources
                      run rm -rf share/hadoop/tools/sources
                      run rm -rf share/hadoop/yarn/superior*.jar
                      run chmod 500 share/hadoop/hdfs/lib/*.jar
                      run dos2unix $PWD/sbin/*.sh
                      run dos2unix $PWD/bin/hadoop*
                      run dos2unix $PWD/bin/yarn*
                      run dos2unix $PWD/bin/mapred*
					  run dos2unix $PWD/bin/superior*
                      run dos2unix $PWD/etc/hadoop/*.sh

		      # Change permissions for all the directories
                      chmod 0700 $(find $ROOT/hadoop-dist/target/hadoop -type d)

                      echo
                      echo "Hadoop dist layout available at: ${project.build.directory}/hadoop"
                      echo
                      run cd ..
                      run rm -rf hadoop-client
                      run mkdir hadoop-client
                      run cd hadoop-client                      
                      run cp -r $ROOT/hadoop-client/target/hadoop-client-${project.version}/share/hadoop/client/lib .
                      run cp -r -u $ROOT/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-superior/superior-yarn-scheduler/target/superior-yarn-scheduler-${superior-version}.jar ./lib   
                      run cp -r -u $ROOT/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-superior/superior-client/target/superior-client-${superior-version}.jar ./lib
                      run cp $ROOT/hadoop-client/target/hadoop-client-${project.version}.jar .
                      echo
                      echo "Hadoop client dist layout available at: ${project.build.directory}/hadoop-client"
                      echo
                    </echo>
                    <exec executable="sh" dir="${project.build.directory}" failonerror="true">
                      <arg line="./dist-layout-stitching.sh"/>
                    </exec>
                  </target>
                </configuration>
              </execution>
              <execution>
                <id>tar</id>
                <phase>package</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <target if="tar">
                    <!-- Complements the assembly -->
                    <tstamp>
                      <format property="NOW" pattern="yyyy-MM-dd HH:mm:ss" locale="en" />
                    </tstamp>
                    <!-- property setting for version.properties file. -->
                    <property name="project.vendor" value="Huawei"/>

                    <!-- add version.properties file in tar. -->
                    <propertyfile
			file="${project.build.directory}/hadoop/version.properties"
			comment="Project properties" >
		         <entry  key="name" value="DataSightHadoop"/>
                         <entry  key="title" value="DataSight BasePlatform ${project.name}"/>
                         <entry  key="version" value="2.7.2"/>
                         <entry  key="HW_display_version" value="${release.package.version}"/>
                         <entry  key="HW_internal_version" value="${release.project.version}"/>
                         <entry  key="vendor" value="Huawei"/>
                         <entry  key="buildtime" value="@NOW"/>
                    </propertyfile>
                    <replace file="${project.build.directory}/hadoop/version.properties" token="@NOW" value="${NOW}" />
                    <propertyfile
			file="${project.build.directory}/hadoop-client/version.properties"
			comment="Project properties" >
		         <entry  key="name" value="DataSightHadoop"/>
                         <entry  key="title" value="DataSight BasePlatform Hadoop Client"/>
                         <entry  key="version" value="2.7.2"/>
                         <entry  key="HW_display_version" value="${release.package.version}"/>
                         <entry  key="HW_internal_version" value="${release.project.version}"/>
                         <entry  key="vendor" value="Huawei"/>
                         <entry  key="buildtime" value="@NOW"/>
                    </propertyfile>
                    <replace file="${project.build.directory}/hadoop-client/version.properties" token="@NOW" value="${NOW}" />
                    <echo file="${project.build.directory}/dist-tar-stitching.sh">
                      run() {
                        echo "\$ ${@}"
                        "${@}"
                        res=$?
                        if [ $res != 0 ]; then
                          echo
                          echo "Failed!"
                          echo
                          exit $res
                        fi
                      }
                      find . -type f | xargs chmod 500
                      find . -type f -name "*.txt" | xargs chmod 400
                      run chmod 400 ${project.build.directory}/hadoop/version.properties
                      run chmod 600 ${project.build.directory}/hadoop/etc/hadoop/*
                      run rm -rf hadoop/bin/test-container-executor
                      run rm -rf hadoop/share/hadoop/kms/tomcat/webapps/kms/WEB-INF/lib/antlr-*.jar
                      run rm -rf hadoop/share/hadoop/kms/tomcat/webapps/kms/WEB-INF/lib/api-asn1-ber-*.jar
                      run rm -rf hadoop/share/hadoop/kms/tomcat/webapps/kms/WEB-INF/lib/api-ldap-model-*.jar
                      run rm -rf hadoop/share/hadoop/kms/tomcat/webapps/kms/WEB-INF/lib/mina-core-*.jar
                      run rm -rf hadoop/share/hadoop/kms/tomcat/webapps/kms/WEB-INF/lib/ehcache-core-*.jar
                      run tar cf DataSight_Hadoop_${release.package.version}_Hadoop.tar hadoop
                      run gzip -f DataSight_Hadoop_${release.package.version}_Hadoop.tar
                      echo
                      echo "Hadoop dist tar available at: ${project.build.directory}/DataSight_Hadoop_${release.package.version}_Hadoop.tar.gz"
                      echo
                      run tar cf DataSight_Hadoop_${release.package.version}_Hadoop-Client.tar hadoop-client
                      run gzip -f DataSight_Hadoop_${release.package.version}_Hadoop-Client.tar
                      echo
                      echo "Hadoop dist tar available at: ${project.build.directory}/DataSight_Hadoop_${release.package.version}_Hadoop-Client.tar.gz"
                      echo
                    </echo>
                    <replace file="${project.build.directory}/dist-tar-stitching.sh" token="\" value="/" />
                    <exec executable="sh" dir="${project.build.directory}" failonerror="true">
                      <arg line="./dist-tar-stitching.sh"/>
                    </exec>
                  </target>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
