File classpathx-mail.spec of Package classpathx-mail

# spec file for package classpathx-mail
# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

%define jmailver 1.3.1
%define inetlibver 1.1.1

Name:           classpathx-mail
Version:        1.1.1
Release:        0
Summary:        GNU JavaMail is a free implementation of the JavaMail API specification
License:        GPL-2.0+
Group:          Development/Libraries/Java
# see bz157685
Patch1:         %{name}-docbuild.patch
Patch2:         %{name}-add-inetlib.patch
Patch3:         %{name}-remove-inetlib.patch
# see bz157685
Patch4:         classpath-inetlib-docbuild.patch
PreReq:         coreutils
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildArch:      noarch
BuildRequires:  ant
BuildRequires:  jaf >= 1.0
BuildRequires:  javapackages-tools
BuildRequires:  jce
BuildRequires:  perl
# gnu-crypto is required for pre-1.5 JVMs only
#BuildRequires:  gnu-crypto
%if %defined suse_version
BuildRequires:  java-devel
BuildRequires:  java-sasl
Requires:       jaf >= 1.0
Requires:       java-sasl
Requires:       jce
Requires(preun):  /usr/sbin/update-alternatives
Requires(post):  /usr/sbin/update-alternatives
Provides:       gnu-javamail = 1.0
Provides:       javamail = %{jmailver}
Obsoletes:      gnu-javamail <= 1.0

GNU JavaMail is a free implementation of the JavaMail API
specification, version 1.3. All the code has been written from scratch
without reference to Sun's code, which allows GNU JavaMail to be used
on a completely free operating system such as GNU/Linux or the Hurd.
The code is optimized to work with free Java implementations, nothing
prevents it from being used with any compliant JVM. GNU JavaMail
provides a protocol-independent framework for building mail client
applications in Java. The API itself provides a complete MIME
implementation, and drivers for individual messaging protocols, known
as providers, can be plugged into the JavaMail framework dynamically.
Several providers, implementing Internet standard protocols, are
included with GNU JavaMail. These include: SMTP IMAP POP3 NNTP
including posting to news servers The UNIX mbox format Dan Bernstein's
Maildir format All these providers are feature-complete, and provide
cryptographically secure access where relevant.

%package        javadoc
Summary:        GNU JavaMail(tm)
Group:          Development/Languages/Java
Provides:       javamail-javadoc = 0:%{jmailver}
PreReq:         coreutils
#BuildRequires: java-javadoc
# there's no classpathx-jaf in SUSE
#BuildRequires:  jaf-javadoc

%description    javadoc
GNU JavaMail(tm) is a free implementation of the JavaMail API.


%setup -q -n mail-%{version}
%patch1 -p0
%patch2 -p0
%patch3 -p0
rm -f
bunzip2 -dc %{SOURCE1} | tar -xf -
pushd inetlib-%{inetlibver}
%patch4 -p0
  mkdir -p source/org/jpackage/mail
  mv source/gnu/inet source/org/jpackage/mail
# assume no filename contains spaces
perl -p -i -e 's/gnu(.)inet/org${1}jpackage${1}mail${1}inet/' `grep gnu.inet -lr *`

# build inetlib
pushd inetlib-%{inetlibver}
  export CLASSPATH=%(build-classpath jce sasl)
  ant  -Dj2se.apidoc=%{_javadocdir}/java inetlib.jar doc
mkdir classes
cp -r inetlib-%{inetlibver}/classes/org classes
# build mail
export CLASSPATH=%(build-classpath activation)
ant \
  -Dj2se.apidoc=%{_javadocdir}/java \
  -Djaf.apidoc=%{_javadocdir}/jaf \ \
  dist javadoc
# build monolithic
mkdir monolithic
pushd monolithic
for jar in gnumail gnumail-providers ; do jar xf ../$jar.jar; done
jar cf ../monolithic.jar *
rm -Rf monolithic

install -dm 755 $RPM_BUILD_ROOT%{_javadir}/classpathx-mail
install -pm 644 gnumail.jar \
ln -s mail-%{jmailver}-api-%{version}.jar \
ln -s mail-%{jmailver}-api.jar \
# Providers
install -pm 644 gnumail-providers.jar \
ln -s mail-%{jmailver}-providers-%{version}.jar \
ln -s mail-%{jmailver}-providers.jar \
for prov in imap nntp pop3 smtp ; do
  ln -s mail-%{jmailver}-providers.jar \
  ln -s providers.jar $RPM_BUILD_ROOT%{_javadir}/classpathx-mail/$prov.jar
install -pm 644 monolithic.jar \
ln -s classpathx-mail-%{jmailver}-monolithic-%{version}.jar $RPM_BUILD_ROOT%{_javadir}/classpathx-mail-%{jmailver}-monolithic.jar
touch $RPM_BUILD_ROOT%{_javadir}/javamail.jar # for %ghost
install -dm 755 $RPM_BUILD_ROOT%{_javadocdir}/%{name}-%{jmailver}
cp -pR docs/* $RPM_BUILD_ROOT%{_javadocdir}/%{name}-%{jmailver}
ln -s %{name}-%{jmailver} $RPM_BUILD_ROOT%{_javadocdir}/%{name} # ghost symlink


%triggerpostun -- classpathx-mail-monolithic <= 0:1.1.1-1jpp
# Remove file from old monolithic subpackage
rm -f %{_javadir}/javamail.jar
# Recreate the link as update-alternatives could not do it
ln -s %{_sysconfdir}/alternatives/javamail %{_javadir}/javamail.jar

/usr/sbin/update-alternatives --install %{_javadir}/javamail.jar javamail %{_javadir}/classpathx-mail-1.3.1-monolithic.jar 010301

if [ "$1" = "0" ]; then
    /usr/sbin/update-alternatives --remove javamail %{_javadir}/classpathx-mail-1.3.1-monolithic.jar

%post javadoc
rm -f %{_javadocdir}/%{name}
ln -s %{name}-%{jmailver} %{_javadocdir}/%{name}

%postun javadoc
if [ "$1" = "0" ]; then
    rm -f %{_javadocdir}/%{name}

%dir %{_javadir}/classpathx-mail
# Monolithic jar
%ghost %{_javadir}/javamail.jar

%files javadoc
%doc %{_javadocdir}/%{name}-%{jmailver}
%ghost %{_javadocdir}/%{name}