%define javaver         1.8.0
%define priority        18000
%define gurlhandler     /desktop/gnome/url-handlers
%define jnlphandler     %{gurlhandler}/jnlp
%define jnlpshandler    %{gurlhandler}/jnlps
%define javadir         %{_jvmdir}/java-%{javaver}-openjdk
%define jredir          %{_jvmdir}/jre-%{javaver}-openjdk
%define binsuffix       .itweb
%define preffered_java  java-%{javaver}-openjdk

Name:           icedtea-web
Version:        1.7.1
Release:        11
Summary:        Free Software web browser plugin running Java applets
License:        LGPLv2+ and GPLv2 with exceptions
URL:            http://icedtea.classpath.org/wiki/IcedTea-Web
Source0:        http://icedtea.classpath.org/download/source/%{name}-%{version}.tar.gz

BuildArch:      noarch
BuildRequires:  gcc-c++ junit hamcrest libappstream-glib tagsoup
BuildRequires:  desktop-file-utils glib2-devel autoconf automake gcc
BuildRequires:  javapackages-tools javapackages-local %{preffered_java}-devel
Requires:       mozilla-filesystem%{?_isa}
Requires:       %{preffered_java} javapackages-tools tagsoup
Recommends:     bash-completion

Requires(post): chkconfig >= 1.7 GConf2
Requires(post): javapackages-tools %{_sbindir}/alternatives
Requires(postun): javapackages-tools GConf2
Requires(postun): %{_sbindir}/alternatives chkconfig >= 1.7

Provides:       java-plugin = 1:%{javaver} javaws = 1:%{javaver}
Provides:       %{preffered_java}-plugin = 1:%{version}
Provides:       %{name}-javadoc = %{version}-%{release}
Obsoletes:      %{name}-javadoc < %{version}-%{release}

%description
The IcedTea-Web project provides a Free Software web browser plugin
for running applets written in the Java programming language and an
implementation of Java Web Start, originally based on the NetX
project.

%package devel
Summary:    Header files for ${name}
Requires:   %{name} = %{version}-%{release}
BuildArch:  noarch

%description devel
Header files for ${name}.

%package_help

%prep
%autosetup -n %{name}-%{version} -p1

%build
autoreconf -vfi
CXXFLAGS="$RPM_OPT_FLAGS $RPM_LD_FLAGS" \
%configure \
    --with-pkgversion=fedora-%{release}-%{_arch} \
    --docdir=%{_datadir}/javadoc/%{name} \
    --with-jdk-home=%{javadir} \
    --with-jre-home=%{jredir} \
    --libdir=%{_libdir} \
    --program-suffix=%{binsuffix} \
    --disable-native-plugin \
    --prefix=%{_prefix}
%make_build

%install
%make_install

mkdir -p %{buildroot}%{_sysconfdir}/bash_completion.d/
mv completion/javaws.bash %{buildroot}%{_sysconfdir}/bash_completion.d/
mv completion/policyeditor.bash %{buildroot}%{_sysconfdir}/bash_completion.d/
mv completion/itweb-settings.bash %{buildroot}%{_sysconfdir}/bash_completion.d/

mv %{buildroot}/%{_mandir}/man1/javaws.1 %{buildroot}/%{_mandir}/man1/javaws.itweb.1

install -d -m 755 %{buildroot}%{_datadir}/{applications,pixmaps}
desktop-file-install --vendor ''\
  --dir %{buildroot}%{_datadir}/applications javaws.desktop
desktop-file-install --vendor ''\
  --dir %{buildroot}%{_datadir}/applications itweb-settings.desktop
desktop-file-install --vendor ''\
  --dir %{buildroot}%{_datadir}/applications policyeditor.desktop

DESTDIR=%{buildroot} appstream-util install metadata/%{name}.metainfo.xml
DESTDIR=%{buildroot} appstream-util install metadata/%{name}-javaws.appdata.xml

mkdir -p %{buildroot}%{_javadir}
pushd %{buildroot}%{_javadir}
ln -s ../%{name}/netx.jar %{name}.jar
ln -s ../%{name}/plugin.jar %{name}-plugin.jar
popd
mkdir -p %{buildroot}/%{_mavenpomdir}
cp metadata/%{name}.pom %{buildroot}/%{_mavenpomdir}/%{name}.pom
cp metadata/%{name}-plugin.pom %{buildroot}/%{_mavenpomdir}/%{name}-plugin.pom

%add_maven_depmap %{name}.pom %{name}.jar
%add_maven_depmap %{name}-plugin.pom %{name}-plugin.jar

cp netx.build/lib/src.zip %{buildroot}%{_datadir}/%{name}/netx.src.zip
cp liveconnect/lib/src.zip %{buildroot}%{_datadir}/%{name}/plugin.src.zip

%find_lang %{name} --all-name --with-man

%check
#make check
appstream-util validate %{buildroot}/%{_datadir}/appdata/*.xml || :

%post
alternatives \
  --install %{_bindir}/javaws javaws.%{_arch} %{_prefix}/bin/javaws%{binsuffix} %{priority} \
  --family  %{preffered_java}.%{_arch} \
  --slave   %{_bindir}/itweb-settings itweb-settings %{_prefix}/bin/itweb-settings%{binsuffix} \
  --slave   %{_bindir}/policyeditor policyeditor %{_prefix}/bin/policyeditor%{binsuffix} \
  --slave   %{_bindir}/ControlPanel ControlPanel %{_prefix}/bin/itweb-settings%{binsuffix} \
  --slave   %{_mandir}/man1/javaws.1.gz javaws.1.gz %{_mandir}/man1/javaws%{binsuffix}.1.gz \
  --slave   %{_mandir}/man1/ControlPanel.1.gz ControlPanel.1.gz %{_mandir}/man1/itweb-settings.1.gz

gconftool-2 -s %{jnlphandler}/command  '%{_prefix}/bin/javaws%{binsuffix} %s' --type String &> /dev/null || :
gconftool-2 -s %{jnlphandler}/enabled  --type Boolean true &> /dev/null || :
gconftool-2 -s %{jnlpshandler}/command '%{_prefix}/bin/javaws%{binsuffix} %s' --type String &> /dev/null || :
gconftool-2 -s %{jnlpshandler}/enabled --type Boolean true &> /dev/null || :

%posttrans
update-desktop-database &> /dev/null || :
exit 0

%postun
update-desktop-database &> /dev/null || :
if [ $1 -eq 0 ]
then
  alternatives --remove javaws %{_prefix}/bin/javaws%{binsuffix}
  gconftool-2 -u %{jnlphandler}/command &> /dev/null || :
  gconftool-2 -u %{jnlphandler}/enabled &> /dev/null || :
  gconftool-2 -u %{jnlpshandler}/command &> /dev/null || :
  gconftool-2 -u %{jnlpshandler}/enabled &> /dev/null || :
fi
exit 0

%files
%defattr(-,root,root)
%license COPYING
%{_sysconfdir}/bash_completion.d/*
%{_bindir}/*
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/*.jar
%{_datadir}/%{name}/*.png
%{_datadir}/appdata/*.xml
%{_datadir}/pixmaps/*
%{_datadir}/java/*
%{_datadir}/javadoc/*
%{_datadir}/maven-poms/*
%{_datadir}/applications/*
%{_datadir}/maven-metadata/*

%files devel
%defattr(-,root,root)
%{_datadir}/%{name}/*.zip

%files help
%doc NEWS README
%defattr(-,root,root)
%{_mandir}/*

%changelog
* Fri Feb 14 2020 wangzhishun1<wangzhishun1@huawei.com> - 1.7.1-11
- Package init
