%define srcver 4.4
%define qualifier 201406061215

Summary: Eclipse Compiler for Java
Name: ecj
Version: %{srcver}.0
Release: 1%{?_dist_release}

URL: http://www.eclipse.org
License: EPL
Group: Development/Languages

#Source0: ftp://sourceware.org/pub/java/ecj-latest.jar
#Source1: ecj-gij.sh.in
Source0: http://download.eclipse.org/eclipse/downloads/drops4/R-%{srcver}-%{qualifier}/%{name}src-%{srcver}.jar
Source1: ecj.sh.in
Source3: ecj-4.4.pom
Source4: ecj.1
Source5: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/plain/org.eclipse.jdt.core/scripts/binary/META-INF/MANIFEST.MF
# Always generate debug info when building RPMs (Andrew Haley)
Patch0: %{name}-rpmdebuginfo.patch
# build.xml fails to include a necessary .props file in the built ecj.jar
Patch1: %{name}-include-props.patch

BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildArch: noarch

BuildRequires: ant
BuildRequires: gzip
BuildRequires: java-1.7.0-openjdk-devel

Requires: java-headless
Requires: jpackage-utils

Provides: eclipse-ecj = %{version}-%{release}

%description
ECJ is the Java bytecode compiler of the Eclipse Platform.  It is also known as
the JDT Core batch compiler.

%prep
%setup -q -c
%patch0 -p1
%patch1 -b .sav

sed -i -e 's|debuglevel=\"lines,source\"|debug=\"yes\"|g' build.xml
sed -i -e "s/Xlint:none/Xlint:none -encoding cp1252/g" build.xml

cp %{SOURCE3} pom.xml
mkdir -p scripts/binary/META-INF/
cp %{SOURCE5} scripts/binary/META-INF/MANIFEST.MF

# JDTCompilerAdapter isn't used by the batch compiler
rm -f org/eclipse/jdt/core/JDTCompilerAdapter.java
cp %{SOURCE4} ecj.1

%build
ant
gzip ecj.1

%install
mkdir -p $RPM_BUILD_ROOT%{_javadir}
cp -a *.jar $RPM_BUILD_ROOT%{_javadir}/%{name}.jar
pushd $RPM_BUILD_ROOT%{_javadir}
ln -s %{name}.jar eclipse-%{name}.jar
ln -s %{name}.jar jdtcore.jar
popd

# Install the ecj wrapper script
install -p -D -m0755 %{SOURCE1} $RPM_BUILD_ROOT%{_bindir}/ecj
sed --in-place "s:@JAVADIR@:%{_javadir}:" $RPM_BUILD_ROOT%{_bindir}/ecj

# Install manpage
mkdir -p $RPM_BUILD_ROOT%{_mandir}/man1
install -m 644 -p ecj.1.gz $RPM_BUILD_ROOT%{_mandir}/man1/ecj.1.gz

# poms
install -d -m 755 $RPM_BUILD_ROOT%{_mavenpomdir}
install -pm 644 pom.xml \
    $RPM_BUILD_ROOT%{_mavenpomdir}/JPP-%{name}.pom

%clean
rm -rf $RPM_BUILD_ROOT

%files
%doc about.html
%{_mavenpomdir}/JPP-%{name}.pom
%{_bindir}/%{name}
%{_javadir}/%{name}.jar
%{_javadir}/eclipse-%{name}.jar
%{_javadir}/jdtcore.jar
%{_mandir}/man1/ecj.1.gz

%changelog
* Sun Jul 13 2014 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.4.0-1
- new upstream release.

* Sun Mar 20 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.6.2-1
- new upstream release

* Tue Aug 24 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.6.0-1
- new upstream release
- enabled AOT compile

* Mon Apr 19 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.5.1-1
- initial build for Vine Linux
