File bouncycastle.spec of Package bouncycastle

#
# spec file for package bouncycastle
#
# Copyright (c) 2014 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 ver  1.46
%define archivever  jdk16-%(echo %{ver}|sed 's|\\\.||')
%define classname   org.bouncycastle.jce.provider.BouncyCastleProvider

Summary:        Bouncy Castle Crypto Package for Java
License:        MIT
Group:          Development/Libraries/Java
Name:           bouncycastle
Version:        %{ver}
Release:        0
Url:            http://www.%{name}.org/
# Original source http://www.bouncycastle.org/download/bcprov-%{archivever}.tar.gz
# is modified to
# bcprov-%{archivever}-FEDORA.tar.gz with patented algorithms removed.
# Specifically: IDEA algorithms got removed.
Source0:        bcprov-%{archivever}-FEDORA.tar.gz
#Source1:        http://repo2.maven.org/maven2/org/bouncycastle/bcprov-jdk16/%{version}/bcprov-jdk16-%{version}.pom
Source1:        bcprov-jdk16-%{version}.pom
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  javapackages-tools
Requires(post):   javapackages-tools
Requires(postun): javapackages-tools
BuildArch:      noarch
BuildRequires:  java-devel
BuildRequires:  unzip
#FIXME: this is needed for initialize of NSS crypto backend, will be required (not required(post) by openjdk)
BuildRequires:  mozilla-nss
Requires:       java
BuildRequires:  junit

Provides:       bcprov = %{version}-%{release}

%description
The Bouncy Castle Crypto package is a Java implementation of cryptographic
algorithms. The package is organised so that it contains a light-weight API
suitable for use in any environment (including the newly released J2ME) with
the additional infrastructure to conform the algorithms to the JCE framework.

%package javadoc
Summary:        Javadoc for %{name}
Group:          Development/Libraries/Java
BuildArch:      noarch
Requires:       %{name} = %{version}-%{release}
Requires:       javapackages-tools

%description javadoc
API documentation for the %{name} package.

%prep
%setup -q -n bcprov-%{archivever}

# Remove provided binaries
find . -type f -name "*.class" -exec rm -f {} \;
find . -type f -name "*.jar" -exec rm -f {} \;

mkdir src
unzip -qq src.zip -d src/

%build
pushd src
  export CLASSPATH=$(build-classpath junit)
  %javac -g -source 1.5 -target 1.5 -encoding UTF-8 $(find . -type f -name "*.java")
  jarfile="../bcprov-%{version}.jar"
  # Exclude all */test/* files except org.bouncycastle.util.test, cf. upstream
  files="$(find . -type f \( -name '*.class' -o -name '*.properties' \) -not -path '*/test/*')"
  files="$files $(find . -type f -path '*/org/bouncycastle/util/test/*.class')"
  files="$files $(find . -type f -path '*/org/bouncycastle/jce/provider/test/*.class')"
  files="$files $(find . -type f -path '*/org/bouncycastle/ocsp/test/*.class')"
  test ! -d classes && mf="" \
    || mf="`find classes/ -type f -name "*.mf" 2>/dev/null`"
  test -n "$mf" && jar cvfm $jarfile $mf $files \
    || %jar cvf $jarfile $files
popd

%install
install -dm 755 %{buildroot}%{_sysconfdir}/java/security/security.d
touch %{buildroot}%{_sysconfdir}/java/security/security.d/2000-%{classname}

# install bouncy castle provider
install -dm 755 %{buildroot}%{_javadir}
install -pm 644 bcprov-%{version}.jar \
  %{buildroot}%{_javadir}/bcprov-%{version}.jar
pushd %{buildroot}%{_javadir}
  ln -sf bcprov-%{version}.jar bcprov.jar
popd

# javadoc
mkdir -p %{buildroot}%{_javadocdir}/%{name}
cp -pr docs/* %{buildroot}%{_javadocdir}/%{name}

# maven pom
install -dm 755 %{buildroot}%{_mavenpomdir}
install -pm 644 %{SOURCE1} %{buildroot}%{_mavenpomdir}/JPP-bcprov.pom
%add_maven_depmap JPP-bcprov.pom bcprov.jar

%check
pushd src
  export CLASSPATH=$PWD:$(build-classpath junit)
  for test in $(find . -name AllTests.class) ; do
    test=${test#./} ; test=${test%.class} ; test=${test//\//.}
    # TODO: failures; get them fixed and remove || :
    %java org.junit.runner.JUnitCore $test || :
  done
popd

%post
{
  # Rebuild the list of security providers in classpath.security
  suffix=security/classpath.security
  secfiles="/usr/lib/$suffix /usr/lib64/$suffix"

  for secfile in $secfiles
  do
    # check if this classpath.security file exists
    [ -f "$secfile" ] || continue

    sed -i '/^security\.provider\./d' "$secfile"

    count=0
    for provider in $(ls /etc/java/security/security.d)
    do
      count=$((count + 1))
      echo "security.provider.${count}=${provider#*-}" >> "$secfile"
    done
  done
} || :

%postun
if [ $1 -eq 0 ] ; then

  {
    # Rebuild the list of security providers in classpath.security
    suffix=security/classpath.security
    secfiles="/usr/lib/$suffix /usr/lib64/$suffix"

    for secfile in $secfiles
    do
      # check if this classpath.security file exists
      [ -f "$secfile" ] || continue

      sed -i '/^security\.provider\./d' "$secfile"

      count=0
      for provider in $(ls /etc/java/security/security.d)
      do
        count=$((count + 1))
        echo "security.provider.${count}=${provider#*-}" >> "$secfile"
      done
    done
  } || :

fi

%files
%defattr(0644,root,root,0755)
%doc *.html
%{_javadir}/bcprov.jar
%{_javadir}/bcprov-%{version}.jar
%{_javadir}/*
%config(noreplace) %{_sysconfdir}/java/security/security.d/2000-%{classname}
%{_mavenpomdir}/JPP-bcprov.pom
%{_mavendepmapfragdir}/%{name}

%files javadoc
%defattr(0644,root,root,0755)
%{_javadocdir}/%{name}/

%changelog
openSUSE Build Service is sponsored by