3abc0ea0713eb541b21667f7abe2abf55d5286ed
[jackhill/guix/guix.git] / gnu / packages / java-compression.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2019 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2017, 2018 Julien Lepiller <julien@lepiller.eu>
4 ;;; Copyright © 2018 Marius Bakke <mbakke@fastmail.com>
5 ;;; Copyright © 2018 Mark H Weaver <mhw@netris.org>
6 ;;; Copyright © 2018, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
7 ;;;
8 ;;; This file is part of GNU Guix.
9 ;;;
10 ;;; GNU Guix is free software; you can redistribute it and/or modify it
11 ;;; under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or (at
13 ;;; your option) any later version.
14 ;;;
15 ;;; GNU Guix is distributed in the hope that it will be useful, but
16 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
19 ;;;
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22
23 (define-module (gnu packages java-compression)
24 #:use-module ((guix licenses) #:prefix license:)
25 #:use-module (guix utils)
26 #:use-module (guix packages)
27 #:use-module (guix download)
28 #:use-module (guix git-download)
29 #:use-module (guix build-system ant)
30 #:use-module (gnu packages)
31 #:use-module (gnu packages compression)
32 #:use-module (gnu packages java)
33 #:use-module (gnu packages perl)
34 #:use-module (gnu packages python-compression))
35
36 (define-public java-snappy
37 (package
38 (name "java-snappy")
39 (version "1.1.7.3")
40 (source
41 (origin
42 (method git-fetch)
43 (uri (git-reference
44 (url "https://github.com/xerial/snappy-java")
45 (commit version)))
46 (sha256
47 (base32 "07c145w1kv8g7dbwpy5xss142il7zr0qq78p2ih76azgl97n5cba"))
48 (file-name (git-file-name name version))))
49 (build-system ant-build-system)
50 (arguments
51 `(#:jar-name "snappy.jar"
52 #:source-dir "src/main/java"
53 #:phases
54 (modify-phases %standard-phases
55 (add-after 'unpack 'make-git-checkout-writable
56 (lambda _
57 (for-each make-file-writable (find-files "."))
58 #t))
59 (add-before 'build 'remove-binaries
60 (lambda _
61 (delete-file "lib/org/xerial/snappy/OSInfo.class")
62 (delete-file-recursively "src/main/resources/org/xerial/snappy/native")
63 #t))
64 (add-before 'build 'build-jni
65 (lambda _
66 ;; Rebuild one of the binaries we removed earlier
67 (invoke "javac" "src/main/java/org/xerial/snappy/OSInfo.java"
68 "-d" "lib")
69 ;; Link to the dynamic bitshuffle and snappy, not the static ones
70 (substitute* "Makefile.common"
71 (("-shared")
72 "-shared -lbitshuffle -lsnappy"))
73 (substitute* "Makefile"
74 ;; Don't try to use git, don't download bitshuffle source
75 ;; and don't build it.
76 (("\\$\\(SNAPPY_GIT_UNPACKED\\) ")
77 "")
78 ((": \\$\\(SNAPPY_GIT_UNPACKED\\)")
79 ":")
80 (("\\$\\(BITSHUFFLE_UNPACKED\\) ")
81 "")
82 ((": \\$\\(SNAPPY_SOURCE_CONFIGURED\\)") ":")
83 ;; What we actually want to build
84 (("SNAPPY_OBJ:=.*")
85 "SNAPPY_OBJ:=$(addprefix $(SNAPPY_OUT)/, \
86 SnappyNative.o BitShuffleNative.o)\n")
87 ;; Since we removed the directory structure in "native" during
88 ;; the previous phase, we need to recreate it.
89 (("NAME\\): \\$\\(SNAPPY_OBJ\\)")
90 "NAME): $(SNAPPY_OBJ)\n\t@mkdir -p $(@D)"))
91 ;; Finally we can run the Makefile to build the dynamic library.
92 ;; Use the -nocmake target to avoid a dependency on cmake,
93 ;; which in turn requires the "git_unpacked" directory.
94 (invoke "make" "native-nocmake")))
95 ;; Once we have built the shared library, we need to place it in the
96 ;; "build" directory so it can be added to the jar file.
97 (add-after 'build-jni 'copy-jni
98 (lambda _
99 (copy-recursively "src/main/resources/org/xerial/snappy/native"
100 "build/classes/org/xerial/snappy/native")
101 #t))
102 (add-before 'check 'fix-failing
103 (lambda _
104 (with-directory-excursion "src/test/java/org/xerial/snappy"
105 ;; This package assumes maven build, which puts results in "target".
106 ;; We put them in "build" instead, so fix that.
107 (substitute* "SnappyLoaderTest.java"
108 (("target/classes") "build/classes"))
109 ;; This requires Hadoop, which is not in Guix yet.
110 (delete-file "SnappyHadoopCompatibleOutputStreamTest.java"))
111 #t)))))
112 (inputs
113 `(("osgi-framework" ,java-osgi-framework)))
114 (propagated-inputs
115 `(("bitshuffle" ,bitshuffle-for-snappy)
116 ("snappy" ,snappy)))
117 (native-inputs
118 `(("junit" ,java-junit)
119 ("hamcrest" ,java-hamcrest-core)
120 ("xerial-core" ,java-xerial-core)
121 ("classworlds" ,java-plexus-classworlds)
122 ("commons-lang" ,java-commons-lang)
123 ("commons-io" ,java-commons-io)
124 ("perl" ,perl)))
125 (home-page "https://github.com/xerial/snappy-java")
126 (synopsis "Compression/decompression algorithm in Java")
127 (description "Snappy-java is a Java port of snappy, a fast C++
128 compressor/decompressor.")
129 (license license:asl2.0)))
130
131 (define-public java-snappy-1
132 (package
133 (inherit java-snappy)
134 (name "java-snappy")
135 (version "1.0.3-rc3")
136 (source
137 (origin
138 (method git-fetch)
139 (uri (git-reference
140 (url (string-append "https://github.com/xerial/snappy-java"))
141 (commit (string-append "snappy-java-" version))))
142 (sha256
143 (base32 "0gbg3xmhniyh5p6w5zqj16fr15fa8j4raswd8pj00l4ixf5qa6m4"))
144 (file-name (git-file-name name version))))
145 (arguments
146 `(#:jar-name "snappy.jar"
147 #:source-dir "src/main/java"
148 #:phases
149 (modify-phases %standard-phases
150 (add-before 'build 'remove-binaries
151 (lambda _
152 (delete-file "lib/org/xerial/snappy/OSInfo.class")
153 (delete-file-recursively "src/main/resources/org/xerial/snappy/native")
154 #t))
155 (add-before 'build 'build-jni
156 (lambda _
157 ;; Rebuild one of the binaries we removed earlier
158 (invoke "javac" "src/main/java/org/xerial/snappy/OSInfo.java"
159 "-d" "lib")
160 ;; Link to the dynamic snappy, not the static ones
161 (substitute* "Makefile.common"
162 (("-shared") "-shared -lsnappy"))
163 (substitute* "Makefile"
164 ;; Don't download the sources here.
165 (("\\$\\(SNAPPY_UNPACKED\\) ") "")
166 ((": \\$\\(SNAPPY_UNPACKED\\) ") ":")
167 ;; What we actually want to build
168 (("SNAPPY_OBJ:=.*")
169 "SNAPPY_OBJ:=$(addprefix $(SNAPPY_OUT)/, SnappyNative.o)\n")
170 ;; Since we removed the directory structure in "native" during
171 ;; the previous phase, we need to recreate it.
172 (("NAME\\): \\$\\(SNAPPY_OBJ\\)")
173 "NAME): $(SNAPPY_OBJ)\n\t@mkdir -p $(@D)"))
174 ;; Finally we can run the Makefile to build the dynamic library.
175 (invoke "make" "native")))
176 ;; Once we have built the shared library, we need to place it in the
177 ;; "build" directory so it can be added to the jar file.
178 (add-after 'build-jni 'copy-jni
179 (lambda _
180 (copy-recursively "src/main/resources/org/xerial/snappy/native"
181 "build/classes/org/xerial/snappy/native")
182 #t))
183 (add-before 'check 'fix-tests
184 (lambda _
185 (mkdir-p "src/test/resources/org/xerial/snappy/")
186 (copy-recursively "src/test/java/org/xerial/snappy/testdata"
187 "src/test/resources/org/xerial/snappy/testdata")
188 (install-file "src/test/java/org/xerial/snappy/alice29.txt"
189 "src/test/resources/org/xerial/snappy/")
190 #t)))))))
191
192 (define-public java-iq80-snappy
193 (package
194 (name "java-iq80-snappy")
195 (version "0.4")
196 (source
197 (origin
198 (method git-fetch)
199 (uri (git-reference
200 (url "https://github.com/dain/snappy")
201 (commit (string-append "snappy-" version))))
202 (sha256
203 (base32 "1mswh207065rdzbxk6rxaqlxhbg1ngxa0vjc20knsn31kqbq1bcz"))
204 (file-name (git-file-name name version))))
205 (build-system ant-build-system)
206 (arguments
207 `(#:jar-name "iq80-snappy.jar"
208 #:source-dir "src/main/java"
209 #:test-dir "src/test"
210 #:phases
211 (modify-phases %standard-phases
212 (replace 'check
213 (lambda _
214 (define (test class)
215 (invoke "java" "-cp" (string-append (getenv "CLASSPATH")
216 ":build/classes"
217 ":build/test-classes")
218 "-Dtest.resources.dir=src/test/resources"
219 "org.testng.TestNG" "-testclass"
220 class))
221 (invoke "ant" "compile-tests")
222 (test "org.iq80.snappy.SnappyFramedStreamTest")
223 (test "org.iq80.snappy.SnappyStreamTest")
224 #t))
225 (add-before 'build 'remove-hadoop-dependency
226 (lambda _
227 ;; We don't have hadoop
228 (delete-file "src/main/java/org/iq80/snappy/HadoopSnappyCodec.java")
229 (delete-file "src/test/java/org/iq80/snappy/TestHadoopSnappyCodec.java")
230 #t))
231 (replace 'install (install-from-pom "pom.xml")))))
232 (home-page "https://github.com/dain/snappy")
233 (native-inputs
234 `(("guava" ,java-guava)
235 ("java-snappy" ,java-snappy)
236 ("hamcrest" ,java-hamcrest-core)
237 ("testng" ,java-testng)))
238 (synopsis "Java port of the Snappy (de)compressor")
239 (description
240 "Iq80-snappy is a port of the Snappy compressor and decompressor rewritten
241 in pure Java. This compression code produces a byte-for-byte exact copy of the
242 output created by the original C++ code, and is extremely fast.")
243 (license license:asl2.0)))
244
245 (define-public java-jbzip2
246 (package
247 (name "java-jbzip2")
248 (version "0.9.1")
249 (source (origin
250 (method url-fetch)
251 (uri (string-append "https://storage.googleapis.com/"
252 "google-code-archive-source/v2/"
253 "code.google.com/jbzip2/"
254 "source-archive.zip"))
255 (file-name (string-append name "-" version ".zip"))
256 (sha256
257 (base32
258 "0ncmhlqmrfmj96nqf6p77b9ws35lcfsvpfxzwxi2asissc83z1l3"))))
259 (build-system ant-build-system)
260 (native-inputs
261 `(("unzip" ,unzip)
262 ("java-junit" ,java-junit)))
263 (arguments
264 `(#:tests? #f ; no tests
265 #:jar-name "jbzip2.jar"
266 #:source-dir "tags/release-0.9.1/src"
267 #:phases
268 (modify-phases %standard-phases
269 (add-after 'unpack 'fix-encoding-problems
270 (lambda _
271 ;; Some of the files we're patching are
272 ;; ISO-8859-1-encoded, so choose it as the default
273 ;; encoding so the byte encoding is preserved.
274 (with-fluids ((%default-port-encoding #f))
275 (substitute* "tags/release-0.9.1/src/org/itadaki/bzip2/HuffmanAllocator.java"
276 (("Milidi.") "Milidiu")))
277 #t)))))
278 (home-page "https://code.google.com/archive/p/jbzip2/")
279 (synopsis "Java bzip2 compression/decompression library")
280 (description "Jbzip2 is a Java bzip2 compression/decompression library.
281 It can be used as a replacement for the Apache @code{CBZip2InputStream} /
282 @code{CBZip2OutputStream} classes.")
283 (license license:expat)))
284
285 (define-public java-xz
286 (package
287 (name "java-xz")
288 (version "1.6")
289 (source (origin
290 (method url-fetch)
291 (uri (string-append "https://tukaani.org/xz/xz-java-" version ".zip"))
292 (sha256
293 (base32
294 "1z3p1ri1gvl07inxn0agx44ck8n7wrzfmvkz8nbq3njn8r9wba8x"))))
295 (build-system ant-build-system)
296 (arguments
297 `(#:tests? #f; no tests
298 #:phases
299 (modify-phases %standard-phases
300 (add-after 'unpack 'chdir
301 (lambda _
302 ;; Our build system enters the first directory in the archive, but
303 ;; the package is not contained in a subdirectory
304 (chdir "..")
305 #t))
306 (add-before 'install 'generate-pom
307 (lambda _
308 (copy-file "maven/pom_template.xml" "pom.xml")
309 (substitute* "pom.xml"
310 (("@VERSION@") ,version)
311 (("@TITLE@") "XZ data compression")
312 (("@HOMEPAGE@") "http://tukaani.org/xz/java.html"))
313 #t))
314 (add-before 'install 'rename-jar
315 (lambda _
316 (rename-file "build/jar/xz.jar"
317 (string-append "build/jar/xz-" ,version ".jar"))
318 #t))
319 (replace 'install
320 (install-from-pom "pom.xml")))))
321 (native-inputs
322 `(("unzip" ,unzip)))
323 (home-page "https://tukaani.org")
324 (synopsis "XZ in Java")
325 (description "Tukaani-xz is an implementation of xz compression/decompression
326 algorithms in Java.")
327 (license license:public-domain)))