<?xml version="1.0" encoding="UTF-8"?>
<!-- 
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you 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.
-->
<project default="pljava" name="DdlUtils" basedir=".">
	<!-- Allow values set at the commandline or in the environment to override the defaults -->
	<property environment="env" />
	<!-- Load the jdbc properties as specified by the jdbc.properties.file variable-->
	<property file="jdbc.properties.postgresql" />
	<!-- Load the build properties -->
	<property file="build.properties" />


	<!-- The classpath used for running the tasks -->
	<path id="project.class.path">
		<fileset dir="../lib">
			<include name="**/*.jar" />
		</fileset>               
	</path>

	<target name="init" depends="compile-pljava,install" >
		<echo message="============================================================" />
		<echo message="     PostgreSQL database install PLJAVA for Adempiere ERP" />
		<echo message="	  	Adempiere Licese is GNU GPL License" />
		<echo message="============================================================" />
		<echo message="" file="log/psql.log" append="false" />
		<echo append="false" file="log/build.log" message="#Build log:${line.separator}${line.separator}" />
                
	</target>
        
        <target name="compile-pljava">
		   <echo message="Compile PLJAVA ... "/> 
                   <unjar src="pljava/pljava-src-1.3.0.zip" dest="pljava" />	                  
                   <exec dir="pljava/pljava-1.3.0/" executable="make"/>	
                   <copy file="pljava/pljava-1.3.0/build/objs/pljava.so" 
			tofile="${postgresql.home}/lib/pljava.so" filtering="yes" overwrite="yes" />   
                        
                   <exec dir="pljava/pljava-1.3.0/" executable="make">	
                       <arg line="install" />
                       <env key="PATH" value="${postgresql.home}/bin:$PATH"/>
		   </exec>
                       <!--copy todir="${postgresql.home}/lib">
                          <fileset dir="${postgresql.home}/lib/pgxs">
                            <include name="libpljava**/*.*"/>            
                          </fileset>
                        </copy-->                                                                        
                        <!--copy todir="${postgresql.home}/lib">
                          <fileset dir="${postgresql.home}/lib/postgresql">
                            <include name="libpljava**/*.*"/>            
                          </fileset>
                        </copy-->  
                     
                        <mkdir dir="${postgresql.home}/jlib"/>
                        <copy file="pljava/pljava-1.3.0/build/deploy.jar" 
			tofile="${postgresql.home}/jlib/deploy.jar" filtering="yes" overwrite="no" />
                        <copy file="pljava/pljava-1.3.0/build/pljava.jar" 
			tofile="${postgresql.home}/jlib/pljava.jar" filtering="yes" overwrite="no" />
               
                        <echo append='true' file="${postgresql.pgdata}/postgresql.conf" message="listen_addresses = '*'${line.separator}"/>
                        <echo append='true' file="${postgresql.pgdata}/postgresql.conf" message="custom_variable_classes = 'pljava'${line.separator}"/>
                        <echo append='true' file="${postgresql.pgdata}/postgresql.conf" message="pljava.classpath = '${postgresql.home}/jlib/pljava.jar'${line.separator}"/>
                        <echo append='true' file="${postgresql.pgdata}/postgresql.conf" message="pljava.release_lingering_savepoints = true${line.separator}"/>
                        <echo append='true' file="${postgresql.pgdata}/postgresql.conf" message="pljava.vmoptions = '-Xmx64M -Dbackchannel.port=48'${line.separator}"/>
                        <echo append='true' file="${postgresql.pgdata}/postgresql.conf" message="pljava.debug = false${line.separator}"/>                        
                        <echo append='true' file="${postgresql.pgdata}/pg_hba.conf" message="host all all 127.0.01/32 trust${line.separator}"/>                        
                        
                        <!--exec dir="${postgresql.home}/bin" executable="${postgresql.home}/bin/pg_ctl" resultproperty="psql.result" output="log/psql.log" append="true">
			<arg line="-l log/psql.log restart -D ${postgresql.pgdata}" />			
                        </exec-->                             
	</target>
        
        <target name="install">
            
             <path id="pljava.class.path">
                 <fileset dir="../lib">
			<include name="**/*.jar" />
		</fileset>               
                <pathelement location="${postgresql.home}/jlib/deploy.jar"/>
                <pathelement location="${postgresql.home}/jlib/pljava.jar"/>
             </path>   
                
		<echo message="Installing PLJAVA ... "/>               
                   <java classname="org.postgresql.pljava.deploy.Deployer">
                     <arg line="-install -host ${postgresql.host} -port ${postgresql.port} -database ${postgresql.database} -user ${postgresql.user} -password ${postgresql.password}"/>
                     <classpath refid="pljava.class.path"/>
                   </java>			
                                           
                        
	</target>
</project>