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 http://bugs.opensuse.org/
#


%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
Url:            http://java.sun.com/products/javamail/
Source0:        http://ftp.gnu.org/gnu/classpathx/mail-%{version}.tar.bz2
Source1:        http://ftp.gnu.org/gnu/classpath/inetlib-%{inetlibver}.tar.bz2
# 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
%endif
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

%description
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.



%{summary}.

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

%build
# build inetlib
pushd inetlib-%{inetlibver}
  export CLASSPATH=%(build-classpath jce sasl)
  ant -Dant.build.javac.source=1.4 -Dant.build.javac.target=1.4  -Dj2se.apidoc=%{_javadocdir}/java inetlib.jar doc
popd
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 \
  -Dant.build.javac.source=1.4 -Dant.build.javac.target=1.4 \
  dist javadoc
# build monolithic
mkdir monolithic
pushd monolithic
for jar in gnumail gnumail-providers ; do jar xf ../$jar.jar; done
rm -f META-INF/MANIFEST.MF
jar cf ../monolithic.jar *
popd
rm -Rf monolithic

%install
rm -rf $RPM_BUILD_ROOT
install -dm 755 $RPM_BUILD_ROOT%{_javadir}/classpathx-mail
# API
install -pm 644 gnumail.jar \
  $RPM_BUILD_ROOT%{_javadir}/classpathx-mail/mail-%{jmailver}-api-%{version}.jar
ln -s mail-%{jmailver}-api-%{version}.jar \
  $RPM_BUILD_ROOT%{_javadir}/classpathx-mail/mail-%{jmailver}-api.jar
ln -s mail-%{jmailver}-api.jar \
  $RPM_BUILD_ROOT%{_javadir}/classpathx-mail/mailapi.jar
# Providers
install -pm 644 gnumail-providers.jar \
  $RPM_BUILD_ROOT%{_javadir}/classpathx-mail/mail-%{jmailver}-providers-%{version}.jar
ln -s mail-%{jmailver}-providers-%{version}.jar \
  $RPM_BUILD_ROOT%{_javadir}/classpathx-mail/mail-%{jmailver}-providers.jar
ln -s mail-%{jmailver}-providers.jar \
  $RPM_BUILD_ROOT%{_javadir}/classpathx-mail/providers.jar
for prov in imap nntp pop3 smtp ; do
  ln -s mail-%{jmailver}-providers.jar \
    $RPM_BUILD_ROOT%{_javadir}/classpathx-mail/$prov-%{jmailver}.jar
  ln -s providers.jar $RPM_BUILD_ROOT%{_javadir}/classpathx-mail/$prov.jar
done
install -pm 644 monolithic.jar \
  $RPM_BUILD_ROOT%{_javadir}/classpathx-mail-%{jmailver}-monolithic-%{version}.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

%clean
rm -rf $RPM_BUILD_ROOT

%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

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

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

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

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

%files
%defattr(644,root,root,755)
%doc AUTHORS ChangeLog COPYING
%dir %{_javadir}/classpathx-mail
%{_javadir}/classpathx-mail/mail-%{jmailver}-api-%{version}.jar
%{_javadir}/classpathx-mail/mail-%{jmailver}-api.jar
%{_javadir}/classpathx-mail/mailapi.jar
%{_javadir}/classpathx-mail/mail-%{jmailver}-providers-%{version}.jar
%{_javadir}/classpathx-mail/mail-%{jmailver}-providers.jar
%{_javadir}/classpathx-mail/providers.jar
%{_javadir}/classpathx-mail/imap-%{jmailver}.jar
%{_javadir}/classpathx-mail/imap.jar
%{_javadir}/classpathx-mail/nntp-%{jmailver}.jar
%{_javadir}/classpathx-mail/nntp.jar
%{_javadir}/classpathx-mail/pop3-%{jmailver}.jar
%{_javadir}/classpathx-mail/pop3.jar
%{_javadir}/classpathx-mail/smtp-%{jmailver}.jar
%{_javadir}/classpathx-mail/smtp.jar
# Monolithic jar
%{_javadir}/classpathx-mail-%{jmailver}-monolithic-%{version}.jar
%{_javadir}/classpathx-mail-%{jmailver}-monolithic.jar
%ghost %{_javadir}/javamail.jar

%files javadoc
%defattr(644,root,root,755)
%doc %{_javadocdir}/%{name}-%{jmailver}
%ghost %{_javadocdir}/%{name}

%changelog