##
##  mybatis.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package versions
%define       V_mybatis       3.5.10
%define       V_jdbc_mysql    5.1.49
%define       V_jdbc_pgsql    42.4.0
%define       V_jdbc_h2_vers  2.4.240
%define       V_jdbc_h2_date  2025-09-22

#   package information
Name:         mybatis
Summary:      RDBMS Schema-Migration and Java ORM Toolkit
URL:          http://www.mybatis.org/
Vendor:       C. Begin, B. Goodin, L. Meadors, N. Maves, J. Butler, K. Grabfelder
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Database
License:      Apache
Version:      %{V_mybatis}
Release:      20250924

#   list of sources
Source0:      https://github.com/mybatis/mybatis-3/releases/download/mybatis-%{V_mybatis}/mybatis-%{V_mybatis}.zip
Source1:      https://github.com/h2database/h2database/releases/download/version-%{V_jdbc_h2_vers}/h2-%{V_jdbc_h2_date}.zip
Source2:      http://ftp.gwdg.de/pub/misc/mysql/Downloads/Connector-J/mysql-connector-java-%{V_jdbc_mysql}.tar.gz
Source3:      http://jdbc.postgresql.org/download/postgresql-%{V_jdbc_pgsql}.jar
Source4:      mybatis.sh

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101, java, JAVA-JDK

%description
    The MyBatis data mapper framework makes it easier to use a
    relational database with object-oriented applications. MyBatis
    couples objects with stored procedures or SQL statements using a
    XML descriptor. Simplicity is the biggest advantage of the MyBatis
    data mapper over object relational mapping tools. To use the MyBatis
    data mapper, you rely on your own objects, XML, and SQL. There is
    little to learn that you don't already know. With the MyBatis Data
    Mapper, you have the full power of both SQL and stored procedures
    at your fingertips. Additionally, MyBatis has a command-line
    interface (CLI) based tool for flexible database schema migrations
    (upgrading/downgrading).

%track
    prog mybatis = {
        version   = %{V_mybatis}
        url       = https://github.com/mybatis/mybatis-3/releases
        regex     = mybatis-(__VER__)\.zip
    }
    prog mybatis:jdbc-mysql = {
        version   = %{V_jdbc_mysql}
        url       = http://dev.mysql.com/downloads/connector/j/5.1.html
        regex     = mysql-connector-java-(__VER__)\.tar\.gz
    }
    prog mybatis:jdbc-pgsql = {
        version   = %{V_jdbc_pgsql}
        url       = https://jdbc.postgresql.org/download.html
        regex     = postgresql-(\d+\.\d+\.\d+)\.jar
    }
    prog mybatis:jdbc-h2 = {
        version   = %{V_jdbc_h2_date}
        url       = http://www.h2database.com/html/download.html
        regex     = h2-(\d+-\d+-\d+)\.zip
    }

%prep
    %setup -q -c
    %setup -q -T -D -a 1
    %setup -q -T -D -a 2

%build

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/lib/mybatis \
        $RPM_BUILD_ROOT%{l_prefix}/lib/mybatis/optional \
        $RPM_BUILD_ROOT%{l_prefix}/lib/mybatis/jdbc
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE mybatis.sh} \
        $RPM_BUILD_ROOT%{l_prefix}/bin/mybatis-migrate
    %{l_shtool} install -c -m 644 \
        mybatis-%{V_mybatis}/mybatis-%{V_mybatis}.jar \
        $RPM_BUILD_ROOT%{l_prefix}/lib/mybatis/mybatis.jar
    %{l_shtool} install -c -m 644 \
        h2/bin/h2-*.jar \
        $RPM_BUILD_ROOT%{l_prefix}/lib/mybatis/jdbc/jdbc-h2.jar
    %{l_shtool} install -c -m 644 \
        mysql-*/mysql-connector-java-*-bin.jar \
        $RPM_BUILD_ROOT%{l_prefix}/lib/mybatis/jdbc/jdbc-mysql.jar
    %{l_shtool} install -c -m 644 \
        %{SOURCE3} \
        $RPM_BUILD_ROOT%{l_prefix}/lib/mybatis/jdbc/jdbc-pgsql.jar
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

