mirror of
https://github.com/xerial/snappy-java.git
synced 2025-04-08 19:35:08 +02:00
Compare commits
636 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
65e1ec3de1 | ||
|
466d05f31f | ||
|
4277fbcdc8 | ||
|
266126036c | ||
|
b9a5d5f573 | ||
|
42e5928a28 | ||
|
d258a4aaa0 | ||
|
2abbbc7fbf | ||
|
ec23d7c611 | ||
|
192e0ee286 | ||
|
dfbf67a4cb | ||
|
f6b188896c | ||
|
1fe7685ae7 | ||
|
3b2138cc7c | ||
|
9c73c6e6a2 | ||
|
595c6d4a11 | ||
|
8a32b3c6cb | ||
|
85966bbb1b | ||
|
08c44a000f | ||
|
ac5d2cb3e1 | ||
|
899b9b2cdb | ||
|
da1af8b260 | ||
|
1af05fee67 | ||
|
5290e26ad9 | ||
|
01368fe0d5 | ||
|
341377bfed | ||
|
04c68883a6 | ||
|
bad35791e1 | ||
|
f3dc3cf88a | ||
|
5fc737773d | ||
|
98e9b432b8 | ||
|
bfa55cb989 | ||
|
26aa68b421 | ||
|
3e829907d3 | ||
|
fbcf0b2947 | ||
|
709dc7bed0 | ||
|
2276a67375 | ||
|
37fdbfa0b9 | ||
|
59bd3c6a00 | ||
|
a63c11efe0 | ||
|
2e7b665b0f | ||
|
4752b963a0 | ||
|
bfb4b7fb6f | ||
|
ca38ae715c | ||
|
27d3b331a4 | ||
|
296323110a | ||
|
69dd99ae75 | ||
|
ea902cfb33 | ||
|
7232cca1a1 | ||
|
0fc566aa9a | ||
|
c76775fd6a | ||
|
98d4bafe42 | ||
|
ec801afc85 | ||
|
a7fb7650e9 | ||
|
ebfbdead18 | ||
|
f54430e9d7 | ||
|
4b0900a835 | ||
|
4e37150be6 | ||
|
a13ad45c60 | ||
|
bce1ff6c8d | ||
|
a072b39bb3 | ||
|
5e4442bd8b | ||
|
f43681045a | ||
|
15ef8928c1 | ||
|
b5f3246597 | ||
|
5cce531e2d | ||
|
bb321e099a | ||
|
2ef01e39f5 | ||
|
4b7c727018 | ||
|
cc325aef28 | ||
|
e62daac2d1 | ||
|
d7356d5229 | ||
|
cb30492b7a | ||
|
08abfa4f85 | ||
|
4b2c1e89a4 | ||
|
0fff1ac8f5 | ||
|
e6d1196bc6 | ||
|
3c67a7b51c | ||
|
67f5d26981 | ||
|
ee96b64c7d | ||
|
0016fed5b4 | ||
|
681b2e1b96 | ||
|
9f8c3cf742 | ||
|
49d700175f | ||
|
1f07c3182c | ||
|
13f8db197c | ||
|
f2e97f27be | ||
|
98b22256fe | ||
|
9f29b5c0f8 | ||
|
55639b55de | ||
|
a5d81a6589 | ||
|
6495da1af2 | ||
|
bc15373ad7 | ||
|
bfda514819 | ||
|
634e1a2dc4 | ||
|
650587eb7b | ||
|
bfd480e696 | ||
|
d4ca6e330b | ||
|
db7f7103ad | ||
|
b6c8227bf2 | ||
|
25261c457e | ||
|
de674f6d73 | ||
|
f3baef0707 | ||
|
13b907da52 | ||
|
589b5d36a5 | ||
|
baa67e5d05 | ||
|
119cf4ceed | ||
|
67f8f8155b | ||
|
c8c8e1321b | ||
|
33b6510b6b | ||
|
f350a98189 | ||
|
bfdb45e0e6 | ||
|
d71e1584d0 | ||
|
2c3b7005e1 | ||
|
f8bc4cc078 | ||
|
33441eec73 | ||
|
8649a62eef | ||
|
60a0cad5cc | ||
|
737f3973ff | ||
|
d0042551e4 | ||
|
3bf67857fc | ||
|
820e2e074c | ||
|
27e2ce0fb0 | ||
|
f32d5b0d7c | ||
|
326f0b45ee | ||
|
b3895447ca | ||
|
256691eb1e | ||
|
5c35a0ff12 | ||
|
2737ea41c4 | ||
|
38bf5689dc | ||
|
b62a27f07a | ||
|
20dd4675d7 | ||
|
3bcc1c43e2 | ||
|
10f3b32d49 | ||
|
d8c5b8e4b6 | ||
|
fd504023f1 | ||
|
ad2e2d7378 | ||
|
4faf2a3768 | ||
|
d9b324ce43 | ||
|
4181327265 | ||
|
86ebb48261 | ||
|
f92925a4ad | ||
|
b780eae3a4 | ||
|
ccf61c1d06 | ||
|
d72a2bc805 | ||
|
027c0c2703 | ||
|
fba33f4eab | ||
|
0314c2501d | ||
|
bb51e7c8f2 | ||
|
e504c39559 | ||
|
18c53d5311 | ||
|
05c39b2ca9 | ||
|
509fe727e6 | ||
|
03fa8d0a83 | ||
|
7f5cd56d65 | ||
|
c5414ed458 | ||
|
079725743f | ||
|
745d4c440f | ||
|
180645b2ef | ||
|
e633200b11 | ||
|
e2a4b5a596 | ||
|
0957acd563 | ||
|
3c74e292ab | ||
|
8845930790 | ||
|
17aa698cdb | ||
|
39160ac5d2 | ||
|
5ad862e802 | ||
|
8707c34446 | ||
|
1a82fe10b7 | ||
|
92b6c9e4d7 | ||
|
785d43066c | ||
|
083827cf74 | ||
|
c515db5857 | ||
|
34fa6e9e65 | ||
|
2bc841b5da | ||
|
cecbb0d1e2 | ||
|
a794389cf2 | ||
|
ef87735ee9 | ||
|
608968912a | ||
|
e8dc8f387f | ||
|
e030a78600 | ||
|
5a46383c4f | ||
|
4dc5112a5a | ||
|
e7be5b3c94 | ||
|
21beeb5b54 | ||
|
5040e7c638 | ||
|
f760098351 | ||
|
37623d64c3 | ||
|
1247939d22 | ||
|
76f8ff902b | ||
|
d971f545f9 | ||
|
60758d8353 | ||
|
b4ef07f9c3 | ||
|
448679cf77 | ||
|
be7958f6e3 | ||
|
d74fcf63c2 | ||
|
169facb1a5 | ||
|
679b9b4b88 | ||
|
7b4564566a | ||
|
681da2d4ae | ||
|
3885fb05e8 | ||
|
f4dd0a5f0f | ||
|
35de895018 | ||
|
70ccd324da | ||
|
8ecc597a0e | ||
|
e4fb87eabf | ||
|
5a6b5b29ec | ||
|
2b34d549aa | ||
|
0e659e947e | ||
|
f281c0ac68 | ||
|
0d074b838e | ||
|
e2dc50bb05 | ||
|
a80d68d734 | ||
|
78354b69c7 | ||
|
1d01f870a1 | ||
|
19cfc8d9a8 | ||
|
f3d7c11a02 | ||
|
2702f510e8 | ||
|
a77381b794 | ||
|
3261bb1902 | ||
|
fd28fd029c | ||
|
a795d6b84c | ||
|
75a03b54fd | ||
|
f938b2cdd0 | ||
|
44db30a72e | ||
|
822513dbe6 | ||
|
110727ed69 | ||
|
7f47cf744a | ||
|
2191e85199 | ||
|
b38d6412ec | ||
|
a1f4fa3b10 | ||
|
585c6a135e | ||
|
5c556b4964 | ||
|
9471b0417e | ||
|
ab18bdb457 | ||
|
47168b2f03 | ||
|
a73e92aecc | ||
|
9ceebb8c21 | ||
|
84e68fe3c1 | ||
|
1c4a0e31e9 | ||
|
9532de9459 | ||
|
5df2667f0e | ||
|
126a1f4e2a | ||
|
d884e957a8 | ||
|
477b7c7e92 | ||
|
a300c63060 | ||
|
f73bb7e1ed | ||
|
56133ad7ec | ||
|
f30210faaa | ||
|
f368c0c7b9 | ||
|
fd26e3914d | ||
|
015b8a17b3 | ||
|
336dd795f3 | ||
|
173832eda7 | ||
|
c0e82b9a47 | ||
|
3d4fd649d0 | ||
|
1fba891de8 | ||
|
150083ca57 | ||
|
a1f6977faa | ||
|
1d1af59c06 | ||
|
3a9e115f9c | ||
|
5f06afd242 | ||
|
6cbc623c96 | ||
|
0a7f5b3b4f | ||
|
bb1c668e96 | ||
|
0ccff5c465 | ||
|
967d280f48 | ||
|
caf0f35716 | ||
|
a89a36bea1 | ||
|
cc1a886cb6 | ||
|
eb341bf08f | ||
|
cbe9a091e7 | ||
|
1412036023 | ||
|
34f014de5e | ||
|
7082397d2d | ||
|
5a750503cd | ||
|
0c097c2e6a | ||
|
377d3577ca | ||
|
0c71fb5a90 | ||
|
594ca5fddb | ||
|
edc4ec28bd | ||
|
30fc6f3a16 | ||
|
0f223298ba | ||
|
c068574a2a | ||
|
13794eba53 | ||
|
bdf8ab10b4 | ||
|
38b5af815f | ||
|
f48aef4e4d | ||
|
e94001da2e | ||
|
990f73398d | ||
|
8faa1d8171 | ||
|
acaca7f9b1 | ||
|
9df6ed7bbc | ||
|
9ad35088c3 | ||
|
d8277970cc | ||
|
f6aa5256a3 | ||
|
79697cf3d4 | ||
|
de99182a82 | ||
|
26eb048c45 | ||
|
820038c974 | ||
|
b40dffc4b9 | ||
|
73c67c7030 | ||
|
fc7cc3c285 | ||
|
03c4273aa4 | ||
|
e9a6ad470e | ||
|
0215276a14 | ||
|
40ebc5a48e | ||
|
a9a45d3cd0 | ||
|
6e35813580 | ||
|
aed3843f8e | ||
|
0bdda0f23d | ||
|
118aa3e6d2 | ||
|
454bb54306 | ||
|
d1a6d037d9 | ||
|
705f94997b | ||
|
8a3538bc51 | ||
|
1c527cb9e0 | ||
|
cda5eb03e2 | ||
|
2f38b2eae6 | ||
|
4eaa9a269c | ||
|
6514348da0 | ||
|
8686318c2c | ||
|
9c36cfa959 | ||
|
0ca520d245 | ||
|
0eac781725 | ||
|
417ab3eefb | ||
|
a468d08bca | ||
|
039082d8f8 | ||
|
6b2384d65c | ||
|
64e9238f6c | ||
|
abb3700425 | ||
|
1351428198 | ||
|
0587ad5bdb | ||
|
8ea939adea | ||
|
d2ed365d98 | ||
|
ff246c935e | ||
|
544a05f7aa | ||
|
411639cfd2 | ||
|
319bc402d0 | ||
|
2f190db71d | ||
|
93e6478a2a | ||
|
d5c089e8ea | ||
|
23cca45a0f | ||
|
ba3810299c | ||
|
13299c1fda | ||
|
8679292703 | ||
|
6a6ea45c4f | ||
|
a450805eeb | ||
|
1b7cc6444d | ||
|
dcdcc473b8 | ||
|
1ce0d34f27 | ||
|
a00267a687 | ||
|
f8327ae087 | ||
|
5ed8f91449 | ||
|
fd4adf0931 | ||
|
300e7eac4e | ||
|
9511da379d | ||
|
f80b3f0041 | ||
|
a5de996866 | ||
|
fb51d60017 | ||
|
1cf9516cd1 | ||
|
989e714bad | ||
|
b90841e676 | ||
|
5427c222a1 | ||
|
1695a7f365 | ||
|
51711eee17 | ||
|
64d2274d30 | ||
|
4ff7447abf | ||
|
3c570c9081 | ||
|
7133ff6168 | ||
|
73262d37e0 | ||
|
b0a242aac0 | ||
|
952fc5ec41 | ||
|
1aeaf20c8d | ||
|
a9aa74e316 | ||
|
c2478c8cf4 | ||
|
cccc33cb05 | ||
|
9f9241a4ab | ||
|
b2901ee3fd | ||
|
b6a1dea6ff | ||
|
b0a4d47ab7 | ||
|
6699b66367 | ||
|
e20494cfb2 | ||
|
3497e732ce | ||
|
ee4d27b16b | ||
|
2a6e0c3040 | ||
|
9cf04cdd6e | ||
|
32060010ea | ||
|
6b11e40607 | ||
|
361d5ed4ba | ||
|
0c73a857a2 | ||
|
0ab9de29cb | ||
|
cfaa5825a2 | ||
|
384b51dd94 | ||
|
ba5a2530ca | ||
|
56536a8c37 | ||
|
c794c99671 | ||
|
7977821eec | ||
|
d3dfa2f2eb | ||
|
4f644cc13e | ||
|
c20e36ce3f | ||
|
2ba15eb0d8 | ||
|
7c6bc8334e | ||
|
a31ada5a69 | ||
|
76667420ec | ||
|
f3bc28ece4 | ||
|
18d429e646 | ||
|
1afcb41368 | ||
|
2c2d1a0f93 | ||
|
ed8852874f | ||
|
2421cda7e2 | ||
|
61d95282a8 | ||
|
1cb0d1ad1b | ||
|
40b37ab343 | ||
|
eebcd4fc2d | ||
|
4f28bb679a | ||
|
8b038c8ed4 | ||
|
9d5bb7b8e5 | ||
|
6f798c6a9d | ||
|
23f528095c | ||
|
d127ab601a | ||
|
e2efc5b8d8 | ||
|
ecf1352e99 | ||
|
def87d8101 | ||
|
7c34e63fbb | ||
|
ebabccc829 | ||
|
eb25832561 | ||
|
e5b2c65c93 | ||
|
4ed4f5394b | ||
|
b12fa23bc8 | ||
|
ec2c1d5903 | ||
|
fb99f2dd10 | ||
|
92bcbb514e | ||
|
381469d886 | ||
|
8b907e0cae | ||
|
5c3e66c4bd | ||
|
8427461ece | ||
|
e329283744 | ||
|
b7f25dd022 | ||
|
5898066ebd | ||
|
9c89e5c3af | ||
|
0c00a0cd6a | ||
|
dc33aaf564 | ||
|
937470e098 | ||
|
524242ec85 | ||
|
fabfc98b8a | ||
|
57c5576151 | ||
|
803a46fd7f | ||
|
c88e150282 | ||
|
549e971765 | ||
|
05cb366fd2 | ||
|
5fdd82cdb5 | ||
|
300fc8e1ea | ||
|
3e650b17b7 | ||
|
47c05acd8a | ||
|
ef5f1cb0df | ||
|
0325e172f8 | ||
|
6e2af03387 | ||
|
6e1d9eb9ca | ||
|
7dc0ad5401 | ||
|
9ab5620220 | ||
|
c597ac2d45 | ||
|
a419c0795b | ||
|
6b4cb2c89d | ||
|
a2c09ecc3b | ||
|
d732857979 | ||
|
cdc1c7408a | ||
|
fc1de99c3a | ||
|
21adc98015 | ||
|
f72229f913 | ||
|
0fcee27d59 | ||
|
7e8346ba3c | ||
|
fb530fd0fb | ||
|
c365c444a5 | ||
|
a0a02e3170 | ||
|
d5a30c0fe8 | ||
|
fb7553c319 | ||
|
d197df096c | ||
|
e08d784358 | ||
|
f9ec0da1cb | ||
|
7d9da23d40 | ||
|
3c5878e70b | ||
|
229e51eb68 | ||
|
a1e701c8fa | ||
|
fa67fcbc3d | ||
|
8c1d4b0245 | ||
|
1ef5cce1b5 | ||
|
7352efda48 | ||
|
a3a3f2a464 | ||
|
7650aa29fb | ||
|
32505c396c | ||
|
1541bc9b91 | ||
|
f2ae38deab | ||
|
78c7823024 | ||
|
187f749fb1 | ||
|
1f54055894 | ||
|
60cc0c2e1d | ||
|
3a8e8c8f77 | ||
|
d39b23f35b | ||
|
eeb5a811b4 | ||
|
f94765b939 | ||
|
7a96d1fee9 | ||
|
ba55390f79 | ||
|
6a894340fc | ||
|
f9520f9d19 | ||
|
4fbfa72ebd | ||
|
f89a30c741 | ||
|
695af1b189 | ||
|
0df5e90422 | ||
|
b695e378b1 | ||
|
87c11d9034 | ||
|
99b297cfcd | ||
|
8c04209b55 | ||
|
738d88a86d | ||
|
00f53c49e4 | ||
|
29bfc49473 | ||
|
3a183de4f0 | ||
|
7d384a6fd6 | ||
|
789278d2c7 | ||
|
3ac8e1e7e7 | ||
|
b51c414b55 | ||
|
c975c27495 | ||
|
cfb114f92f | ||
|
fd07ae7afe | ||
|
fae5091f6a | ||
|
752cb02786 | ||
|
3ba45d5a36 | ||
|
e3d9fb48e9 | ||
|
82adf0aee2 | ||
|
e029c0e560 | ||
|
1198363176 | ||
|
b372a8152c | ||
|
0812a50c13 | ||
|
b7359e8c23 | ||
|
292e114e59 | ||
|
8dd2ebacf5 | ||
|
caf548321d | ||
|
7a5ddff89d | ||
|
eaac67b703 | ||
|
63b31b4098 | ||
|
e8beabfa8d | ||
|
737b2ea56b | ||
|
ee5cb32463 | ||
|
3d4bd9ae9c | ||
|
8c1383719a | ||
|
785eb80484 | ||
|
b1308103ed | ||
|
a41143b5d8 | ||
|
a180570fbc | ||
|
251e6196ab | ||
|
f38b91f18c | ||
|
08b4f6ae60 | ||
|
d8600ed65e | ||
|
6b4e2a1df6 | ||
|
73fa77bc4e | ||
|
ddac8ded5c | ||
|
3113ffb074 | ||
|
2902c04ecc | ||
|
68e1973d3d | ||
|
b8d4fdeead | ||
|
8a12982532 | ||
|
6feccf255e | ||
|
7fb7185916 | ||
|
71f1fd8b39 | ||
|
078b4c5085 | ||
|
14a82e8dac | ||
|
e5abaaccaa | ||
|
38aa42aa03 | ||
|
9215b09cc5 | ||
|
50930c8c3b | ||
|
ac168dfdce | ||
|
67e7cb57fd | ||
|
58016fd78d | ||
|
efd802162f | ||
|
272604b3b0 | ||
|
c8842a0603 | ||
|
aee2b85253 | ||
|
de3ad7bb52 | ||
|
66115a49ad | ||
|
02c14db79e | ||
|
d6908244a7 | ||
|
3cf34325d7 | ||
|
6b4df5a5f8 | ||
|
5bd06f4526 | ||
|
38ec9fd03b | ||
|
dcdada2ed4 | ||
|
2b6c8dc896 | ||
|
c5a3b102bc | ||
|
70ff167f6f | ||
|
50afc2cc9b | ||
|
3ae91f1cd8 | ||
|
16010e791c | ||
|
39606e5c4e | ||
|
e5d86ee61e | ||
|
09827ad9fe | ||
|
195310f3d4 | ||
|
7010fb0e41 | ||
|
de6864edeb | ||
|
50e67d710e | ||
|
d1745ebfcb | ||
|
0efe115bad | ||
|
708752efa5 | ||
|
62fe335057 | ||
|
b1b827695c | ||
|
1c702ba366 | ||
|
81536ea146 | ||
|
75cb0e5213 | ||
|
c4b3b0293a | ||
|
98955b14a1 | ||
|
f2e54dce56 | ||
|
dc2dd27f85 | ||
|
6d9925ba36 | ||
|
3fe32512e4 | ||
|
a6eb0a605d | ||
|
61691b8fe6 | ||
|
0dd3f488f6 | ||
|
d9294241a8 | ||
|
93e100005f | ||
|
2681311aa5 | ||
|
6136702f0a | ||
|
fb8b14bc30 | ||
|
6a66a08845 | ||
|
aacd802ee6 | ||
|
f446a39a00 | ||
|
622a1d71b1 | ||
|
b55d2a40dc | ||
|
bd8476bf84 | ||
|
0ecdb4d568 | ||
|
71a02f950b | ||
|
0521877d9a | ||
|
be0f2dd5d3 | ||
|
f48a29c4ae | ||
|
2d5db6d830 | ||
|
08fbe52c23 | ||
|
fec7847f12 | ||
|
baabd37418 |
2
.git-blame-ignore-revs
Normal file
2
.git-blame-ignore-revs
Normal file
@ -0,0 +1,2 @@
|
||||
# Scala Steward: Reformat with scalafmt 3.7.2
|
||||
2b37d1ce0bbed3d8d03a66292e7d90dcde805624
|
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
sbt text eol=lf
|
||||
|
9
.github/dependabot.yml
vendored
Normal file
9
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
# Set update schedule for GitHub Actions
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
# Check for updates to GitHub Actions every week
|
||||
interval: "weekly"
|
55
.github/release-drafter.yml
vendored
Normal file
55
.github/release-drafter.yml
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
name-template: 'v$RESOLVED_VERSION'
|
||||
tag-template: 'v$RESOLVED_VERSION'
|
||||
categories:
|
||||
- title: '🔥 Breaking Changes'
|
||||
labels:
|
||||
- 'breaking'
|
||||
- title: '🚀 Features'
|
||||
labels:
|
||||
- 'feature'
|
||||
- 'enhancement'
|
||||
- title: '🐛 Bug Fixes'
|
||||
labels:
|
||||
- 'bug'
|
||||
- title: '👋 Deprecated'
|
||||
labels:
|
||||
- 'deprecation'
|
||||
- title: '🔗 Dependency Updates'
|
||||
labels:
|
||||
- 'library-update'
|
||||
- 'dependencies'
|
||||
- title: '🛠 Internal Updates'
|
||||
labels:
|
||||
- 'internal'
|
||||
- 'kaizen'
|
||||
- 'test-library-update'
|
||||
- 'sbt-plugin-update'
|
||||
- title: '📚 Docs'
|
||||
labels:
|
||||
- 'doc'
|
||||
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
|
||||
|
||||
template: |
|
||||
## What's Changed
|
||||
|
||||
$CHANGES
|
||||
|
||||
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION
|
||||
|
||||
|
||||
autolabeler:
|
||||
- label: 'doc'
|
||||
files:
|
||||
- '*.md'
|
||||
- label: 'feature'
|
||||
title:
|
||||
- '/(support|feature)/i'
|
||||
- label: 'bug'
|
||||
title:
|
||||
- '/fix/i'
|
||||
- label: 'internal'
|
||||
title:
|
||||
- '/internal/i'
|
||||
- label: 'deprecation'
|
||||
title:
|
||||
- '/deprecate/i'
|
31
.github/release.yml
vendored
Normal file
31
.github/release.yml
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
changelog:
|
||||
categories:
|
||||
- title: '🔥 Breaking Changes'
|
||||
labels:
|
||||
- 'breaking'
|
||||
- title: '👋 Deprecated'
|
||||
labels:
|
||||
- 'deprecation'
|
||||
- title: '🚀 Features'
|
||||
labels:
|
||||
- 'feature'
|
||||
- 'enhancement'
|
||||
- title: '🐛 Bug Fixes'
|
||||
labels:
|
||||
- 'bug'
|
||||
- title: '🔗 Dependency Updates'
|
||||
labels:
|
||||
- 'library-update'
|
||||
- 'dependencies'
|
||||
- title: '🛠 Internal Updates'
|
||||
labels:
|
||||
- 'internal'
|
||||
- 'kaizen'
|
||||
- 'test-library-update'
|
||||
- 'sbt-plugin-update'
|
||||
- title: '📚 Docs'
|
||||
labels:
|
||||
- 'doc'
|
||||
- title: Other Changes
|
||||
labels:
|
||||
- "*"
|
48
.github/workflows/build-native.yml
vendored
Normal file
48
.github/workflows/build-native.yml
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
name: Build Native
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
paths:
|
||||
- 'src/main/resources/org/xerial/snappy/VERSION'
|
||||
- 'Makefile'
|
||||
- 'Makefile.common'
|
||||
- '**/*.h'
|
||||
- '**/*.cpp'
|
||||
- .github/workflows/build-native.yml
|
||||
pull_request:
|
||||
paths:
|
||||
- 'src/main/resources/org/xerial/snappy/VERSION'
|
||||
- 'Makefile'
|
||||
- 'Makefile.common'
|
||||
- '**/*.h'
|
||||
- '**/*.cpp'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
name: Build native libraries
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Setup cmake
|
||||
uses: jwlawson/actions-setup-cmake@v2.0
|
||||
with:
|
||||
cmake-version: '3.16.x'
|
||||
- name: Build native libraries
|
||||
run: make clean-native native-all
|
||||
env:
|
||||
OCI_EXE: docker
|
||||
- name: Create Pull Request
|
||||
if: ${{ github.event_name != 'pull_request' }}
|
||||
uses: peter-evans/create-pull-request@v7
|
||||
with:
|
||||
title: Update native libraries
|
||||
commit-message: Update native libraries for ${{ github.sha }}
|
||||
branch: update-native-libs
|
||||
labels: library-update
|
27
.github/workflows/release-drafter.yml
vendored
Normal file
27
.github/workflows/release-drafter.yml
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
name: Release Drafter
|
||||
|
||||
on:
|
||||
# pull_request event is required only for autolabeler
|
||||
pull_request:
|
||||
# Only following types are handled by the action, but one can default to all as well
|
||||
types: [opened, reopened, synchronize]
|
||||
# pull_request_target event is required for autolabeler to support PRs from forks
|
||||
pull_request_target:
|
||||
types: [opened, reopened, synchronize]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
update_PR_labels:
|
||||
permissions:
|
||||
contents: read
|
||||
# write permission is required for autolabeler
|
||||
# otherwise, read permission is required at least
|
||||
pull-requests: write
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# Runs only pull-request labeler
|
||||
- uses: release-drafter/release-drafter@v6
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
18
.github/workflows/release-note.yml
vendored
Normal file
18
.github/workflows/release-note.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
name: Release Note
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Create a new release note
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Create a release note
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
gh release create "$GITHUB_REF_NAME" --repo="$GITHUB_REPOSITORY" --generate-notes
|
37
.github/workflows/release.yml
vendored
Normal file
37
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
publish_jvm:
|
||||
name: Publish
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 10000
|
||||
# Fetch all tags so that sbt-dynver can find the previous release version
|
||||
- run: git fetch --tags -f
|
||||
# Install OpenJDK 11
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: '11'
|
||||
- name: Setup GPG
|
||||
env:
|
||||
PGP_SECRET: ${{ secrets.PGP_SECRET }}
|
||||
run: echo $PGP_SECRET | base64 --decode | gpg --import --batch --yes
|
||||
- name: Build bundle
|
||||
env:
|
||||
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
|
||||
run: |
|
||||
./sbt publishSigned
|
||||
- name: Release to Sonatype
|
||||
env:
|
||||
SONATYPE_USERNAME: '${{ secrets.SONATYPE_USER }}'
|
||||
SONATYPE_PASSWORD: '${{ secrets.SONATYPE_PASS }}'
|
||||
run: ./sbt sonatypeBundleRelease
|
39
.github/workflows/snapshot.yml
vendored
Normal file
39
.github/workflows/snapshot.yml
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
name: Snapshot Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- '**.scala'
|
||||
- '**.java'
|
||||
- '**.sbt'
|
||||
- 'src/main/resources/org/xerial/snappy/native/**'
|
||||
- '.github/workflows/snapshot.yml'
|
||||
tag:
|
||||
- '!*'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
publish_snapshots:
|
||||
name: Publish snapshots
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 10000
|
||||
# Fetch all tags so that sbt-dynver can find the previous release version
|
||||
- run: git fetch --tags
|
||||
- uses: olafurpg/setup-scala@v14
|
||||
with:
|
||||
java-version: adopt@1.11
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.cache
|
||||
key: ${{ runner.os }}-snapshot-${{ hashFiles('**/*.sbt') }}
|
||||
restore-keys: ${{ runner.os }}-snapshot-
|
||||
- name: Publish snapshots
|
||||
env:
|
||||
SONATYPE_USERNAME: '${{ secrets.SONATYPE_USER }}'
|
||||
SONATYPE_PASSWORD: '${{ secrets.SONATYPE_PASS }}'
|
||||
run: ./sbt publish
|
52
.github/workflows/test.yml
vendored
Normal file
52
.github/workflows/test.yml
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- '**.scala'
|
||||
- '**.java'
|
||||
- '**.sbt'
|
||||
- '.github/workflows/*.yml'
|
||||
- '**.so'
|
||||
- '**.dll'
|
||||
- 'src/main/resources/**'
|
||||
- 'project/build.properties'
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
paths:
|
||||
- '**.scala'
|
||||
- '**.java'
|
||||
- '**.sbt'
|
||||
- '.github/workflows/*.yml'
|
||||
- 'src/main/resources/org/xerial/snappy/**'
|
||||
- 'project/build.properties'
|
||||
|
||||
jobs:
|
||||
code_format:
|
||||
name: code format
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: scalafmt test
|
||||
run: ./sbt scalafmtCheckAll
|
||||
test-jdk:
|
||||
strategy:
|
||||
matrix:
|
||||
version: [ '8', '11', '17', '21' ]
|
||||
name: test jdk${{ matrix.version }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: ${{ matrix.version }}
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.cache
|
||||
key: ${{ runner.os }}-jdk${{ matrix.version }}-${{ hashFiles('**/*.sbt') }}
|
||||
restore-keys: ${{ runner.os }}-jdk${{ matrix.version }}-
|
||||
- name: Test
|
||||
run: ./sbt test
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -17,9 +17,14 @@ lib_managed/
|
||||
src_managed/
|
||||
project/boot/
|
||||
project/plugins/project/
|
||||
.bsp
|
||||
|
||||
# Scala-IDE specific
|
||||
.scala_dependencies
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
src/main/java/**/*.h
|
||||
|
||||
.metals
|
||||
.vscode
|
||||
.bloop
|
||||
|
5
.scalafmt.conf
Normal file
5
.scalafmt.conf
Normal file
@ -0,0 +1,5 @@
|
||||
version = 3.8.6
|
||||
runner.dialect = scala213source3
|
||||
maxColumn = 180
|
||||
style = defaultWithAlign
|
||||
optIn.breaksInsideChains = true
|
@ -1,6 +0,0 @@
|
||||
#Tue Mar 29 16:49:37 JST 2011
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
File diff suppressed because one or more lines are too long
@ -1,9 +0,0 @@
|
||||
#Tue Mar 29 16:49:37 JST 2011
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
fullBuildGoals=process-test-resources
|
||||
includeModules=false
|
||||
resolveWorkspaceProjects=true
|
||||
resourceFilterGoals=process-resources resources\:testResources
|
||||
skipCompilerPlugin=true
|
||||
version=1
|
26
.travis.yml
26
.travis.yml
@ -1,15 +1,19 @@
|
||||
language: scala
|
||||
scala:
|
||||
- 2.11.1
|
||||
jdk:
|
||||
- openjdk6
|
||||
- openjdk7
|
||||
- oraclejdk7
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
- master
|
||||
|
||||
script: ./sbt test
|
||||
language: java
|
||||
|
||||
jdk:
|
||||
- openjdk11
|
||||
|
||||
os: linux
|
||||
|
||||
arch:
|
||||
- s390x
|
||||
- ppc64le
|
||||
|
||||
script:
|
||||
# - sudo apt-get install -y openjdk-11-jdk;
|
||||
# - export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-s390x && export PATH=$JAVA_HOME/bin:$PATH;
|
||||
- ./sbt test
|
||||
|
119
BUILD.md
Executable file
119
BUILD.md
Executable file
@ -0,0 +1,119 @@
|
||||
# Notes for building snappy-java
|
||||
|
||||
snappy-java supports Windows, Mac OS X, Linux (x86, x86_64, arm, etc...). If your platform is not supported, you need to build native libraries by yourself.
|
||||
|
||||
## Requited Tools
|
||||
- Java 7 or higher
|
||||
- Maven3 (mvn)
|
||||
- GNU make, autotools
|
||||
|
||||
|
||||
## Building snappy-java
|
||||
|
||||
To build jar file of snappy-java, type:
|
||||
```
|
||||
$ make
|
||||
```
|
||||
A native library for your machine environment and a jar package target/snappy-java-(version).jar are produced in the target folder.
|
||||
|
||||
|
||||
### Rebuild the native library for your platform
|
||||
```
|
||||
$ make clean-native native
|
||||
```
|
||||
|
||||
## Platform specific tips
|
||||
|
||||
After snappy-java 1.1.3, we are using docker images of cross compilers. So no longer need to build native libraries by actually running the target OS.
|
||||
The following notes are obsolete, but preserved here for future references.
|
||||
|
||||
### Windows (32/64-bit)
|
||||
* GNU make
|
||||
* And also tar, curl, cp, rm, grep commands are needed. (I use Cygwin and MinGW for building snappy-java in Windows)
|
||||
|
||||
### Windows (32-bit only)
|
||||
* Install MinGW http://www.mingw.org/
|
||||
* Set PATH to the following command in MinGW package
|
||||
- mingw32-g++
|
||||
- strip
|
||||
|
||||
To build x86 (32bit) dll under 64-bit Windows, use "make win32" target.
|
||||
|
||||
### Windows (64-bit only)
|
||||
* Download MinGW-w64 http://sourceforge.net/projects/mingw-w64/
|
||||
* Set PATH to the following commands in the downloaded archive:
|
||||
- x86_64-w64-mingw32-g++
|
||||
- x86_64-w64-mingw32-strip
|
||||
|
||||
NOTICE: Do not use the Cygwin version of MinGW-w64. It fails to build assemblies for 64bit environment.
|
||||
|
||||
### Linux (32/64-bit)
|
||||
* gcc-4.5.x or higher is necessary because snappy-java uses -static-libstdc++ option. It is possible to use gcc-4.3.x but a dependency to libstdc++ remains in the generated jar file; That means if another version of libstdc++ is used, snappy-java might not work correctly.
|
||||
* You can build 32-bit native library with 64-bit Linux machine (do make linux32)
|
||||
|
||||
### Mac
|
||||
* Install gcc, make, etc. included in Mac OS X install disk. (X Code). And also intall libtool:
|
||||
|
||||
```
|
||||
$ brew install libtool
|
||||
```
|
||||
|
||||
## Building Linux x86\_64 binary
|
||||
|
||||
(obsolete: snappy-java now uses a docker image `xerial/centos5-linux-x86_86-pic` which contains g++ built with `-fPIC` option. )
|
||||
|
||||
snappy-java tries to static link libstdc++ to increase the availability for various Linux versions. However, standard distributions of 64-bit Linux OS rarely provide libstdc++ compiled with `-fPIC` option. I currently uses custom g++, compiled as follows:
|
||||
|
||||
```
|
||||
$ cd work
|
||||
$ wget (gcc-4.8.3 source)
|
||||
$ tar xvfz (gcc-4.8.3.tar.gz)
|
||||
$ cd gcc-4.8.3
|
||||
$ ./contrib/download_prerequisites
|
||||
$ cd ..
|
||||
$ mkdir objdir
|
||||
$ cd objdir
|
||||
$ ../gcc-4.8.3/configure --prefix=$HOME/local/gcc-4.8.3 CXXFLAGS=-fPIC CFLAGS=-fPIC --enable-languages=c,c++
|
||||
$ make
|
||||
$ make install
|
||||
```
|
||||
|
||||
This g++ build enables static linking of libstdc++. For more infomation on building GCC, see GCC's home page.
|
||||
|
||||
## Building Linux s390/s390x binaries
|
||||
|
||||
Older snapshots of snappy contain a buggy config.h.in that does not work properly on some big-endian platforms like Linux on IBM z (s390/s390x). Building snappy-java on s390/s390x requires fetching the snappy source from GitHub, and processing the source with autoconf to obtain a usable config.h. On a RHEL s390x system, these steps produced a working 64-bit snappy-java build (the process should be similar for other distributions):
|
||||
|
||||
$ sudo yum install java-1.7.1-ibm-devel libstdc++-static-devel
|
||||
$ export JAVA_HOME=/usr/lib/jvm/java-1.7.1-ibm-1.7.1.2.10-1jpp.3.el7_0.s390x
|
||||
$ make USE_GIT=1 GIT_REPO_URL=https://github.com/google/snappy.git GIT_SNAPPY_BRANCH=master IBM_JDK_7=1
|
||||
|
||||
## Activating SSE2/AVX2 instructions in BitShuffle
|
||||
|
||||
The most of the native libraries that snappy-java contains disable SSE2/AVX2 instructions in terms of portability (SSE2 is enabled only in Linux/x86_64 platforms). To enable AVX2 instructions, you need to compile as follows:
|
||||
|
||||
$ make CXXFLAGS_BITSHUFFLE=-mavx2 # -msse2 for SSE2 instructions
|
||||
|
||||
## Cross-compiling for other platforms (obsolete)
|
||||
The Makefile contains rules for cross-compiling the native library for other platforms so that the snappy-java JAR can support multiple platforms. For example, to build the native libraries for x86 Linux, x86 and x86-64 Windows, and soft- and hard-float ARM:
|
||||
|
||||
$ make linux32 win32 win64 linux-arm linux-armhf linux-aarch64
|
||||
|
||||
If you append `snappy` to the line above, it will also build the native library for the current platform and then build the snappy-java JAR (containing all native libraries built so far).
|
||||
|
||||
Of course, you must first have the necessary cross-compilers and development libraries installed for each target CPU and OS. For example, on Ubuntu 12.04 for x86-64, install the following packages for each target:
|
||||
|
||||
* linux32: `sudo apt-get install g++-multilib libc6-dev-i386 lib32stdc++6`
|
||||
* win32: `sudo apt-get install g++-mingw-w64-i686`
|
||||
* win64: `sudo apt-get install g++-mingw-w64-x86-64`
|
||||
* arm: `sudo apt-get install g++-arm-linux-gnueabi`
|
||||
* armhf: `sudo apt-get install g++-arm-linux-gnueabihf`
|
||||
* aarch64: `sudo apt-get install g++-aarch64-linux`
|
||||
|
||||
Unfortunately, cross-compiling for Mac OS X is not currently possible; you must compile within OS X.
|
||||
|
||||
If you are using Mac and openjdk7 (or higher), use the following option:
|
||||
|
||||
$ make native LIBNAME=libsnappyjava.dylib
|
||||
|
||||
|
78
INSTALL
78
INSTALL
@ -1,78 +0,0 @@
|
||||
[Installation note of snappy-java]
|
||||
|
||||
If your OS platform is one of the Windows/Linux/Mac OS X (32/64 bit Intel CPUs), the installation process described here is unnecessary. Simply put snappy-java-(version).jar to your Java classpath. If your OS is not listed above, create your own snappy-java-(version).jar file as follows.
|
||||
|
||||
|
||||
= Required tools for building snappy-java =
|
||||
|
||||
[For all platforms]
|
||||
|
||||
* Java 6 (JDK1.6) http://java.sun.com/
|
||||
- set JAVA_HOME environment variable to the Java installation folder (e.g. JAVA_HOME=C:/Program Files/Java/jdk1.6.0_24 in Windows)
|
||||
* Maven 3.x http://maven.apache.org/
|
||||
- Check mvn command can be used from your command line.
|
||||
|
||||
[Windows (32/64-bit)]
|
||||
* GNU make
|
||||
* And also tar, curl, cp, rm, grep commands are needed. (I use Cygwin and MinGW for building snappy-java in Windows)
|
||||
|
||||
[Windows (32-bit only)]
|
||||
* Install MinGW http://www.mingw.org/
|
||||
* Set PATH to the following command in MinGW package
|
||||
- mingw32-g++
|
||||
- strip
|
||||
|
||||
To build x86 (32bit) dll under 64-bit Windows, use "make win32" target.
|
||||
|
||||
[Windows (64-bit only)]
|
||||
* Download MinGW-w64 http://sourceforge.net/projects/mingw-w64/
|
||||
* Set PATH to the following commands in the downloaded archive:
|
||||
- x86_64-w64-mingw32-g++
|
||||
- x86_64-w64-mingw32-strip
|
||||
|
||||
NOTICE: Do not use the Cygwin version of MinGW-w64. It fails to build assemblies for 64bit environment.
|
||||
|
||||
[Linux (32/64-bit)]
|
||||
* gcc-4.5.x or higher is necessary because snappy-java uses -static-libstdc++ option. It is possible to use gcc-4.3.x but a dependency to libstdc++ remains in the generated jar file; That means if another version of libstdc++ is used, snappy-java might not work correctly.
|
||||
* You can build 32-bit native library with 64-bit Linux machine (do make linux32)
|
||||
|
||||
[Mac]
|
||||
* Install gcc, make, etc. included in Mac OS X install disk. (X Code)
|
||||
* Install mercurial using Mac Ports http://www.macports.org/
|
||||
|
||||
= Building snappy-java =
|
||||
|
||||
To build jar file of snappy-java, type:
|
||||
$ make
|
||||
|
||||
A native library for your machine environment and a jar package target/snappy-java-(version).jar are produced in the target folder.
|
||||
|
||||
= Building only the native library =
|
||||
$ make native
|
||||
|
||||
= Rebuild the native library for your platform =
|
||||
$ make clean-native native
|
||||
|
||||
|
||||
= Using system installed libsnappyjava (or snappyjava.dll) =
|
||||
|
||||
Set org.xerial.snappy.use.systemlib system property to true:
|
||||
|
||||
java -Djava.library.path=(path to the installed snappyjava lib) -Dorg.xerial.snappy.use.systemlib=true ...
|
||||
|
||||
With this setting snappy-java does not use bundled native libraries. Insted it tries to load native library installed at the path specified in java.library.path.
|
||||
|
||||
|
||||
= Configure snappy-java using property file =
|
||||
|
||||
Prepare org-xerial-snappy.properties file (under the root path of your library) in Java's property file format.
|
||||
Here is a list of the available properties:
|
||||
|
||||
* org.xerial.snappy.lib.path (directory containing a snappyjava's native library)
|
||||
* org.xerial.snappy.lib.name (library file name)
|
||||
* org.xerial.snappy.tempdir (temporary directory to extract a native library bundled in snappy-java)
|
||||
* org.xerial.snappy.use.systemlib (if this value is true, use system installed libsnappyjava.so looking the path specified by java.library.path)
|
||||
|
||||
|
||||
|
||||
|
248
Makefile
248
Makefile
@ -1,83 +1,138 @@
|
||||
|
||||
include Makefile.common
|
||||
|
||||
$(info OS_NAME:$(OS_NAME), OS_ARCH:$(OS_ARCH))
|
||||
|
||||
MVN:=mvn
|
||||
SBT:=./sbt
|
||||
|
||||
all: snappy
|
||||
|
||||
SNAPPY_OUT:=$(TARGET)/$(snappy)-$(os_arch)
|
||||
SNAPPY_ARCHIVE:=$(TARGET)/snappy-$(VERSION).tar.gz
|
||||
SNAPPY_CC:=snappy-sinksource.cc snappy-stubs-internal.cc snappy.cc
|
||||
SNAPPY_SRC_DIR:=$(TARGET)/snappy-$(VERSION)
|
||||
SNAPPY_OUT:=$(TARGET)/snappy-$(SNAPPY_VERSION)-$(os_arch)
|
||||
SNAPPY_ARCHIVE:=$(TARGET)/snappy-$(SNAPPY_VERSION).tar.gz
|
||||
SNAPPY_CC:=snappy-sinksource.cc snappy-stubs-internal.cc snappy-c.cc snappy.cc
|
||||
SNAPPY_SRC_DIR:=$(TARGET)/snappy-$(SNAPPY_VERSION)
|
||||
SNAPPY_SRC:=$(addprefix $(SNAPPY_SRC_DIR)/,$(SNAPPY_CC))
|
||||
SNAPPY_OBJ:=$(addprefix $(SNAPPY_OUT)/,$(patsubst %.cc,%.o,$(SNAPPY_CC)) SnappyNative.o)
|
||||
|
||||
SNAPPY_GIT_REPO_URL:=https://github.com/google/snappy
|
||||
# Change this variable to use a specific git commit
|
||||
SNAPPY_GIT_REV:=$(SNAPPY_VERSION)
|
||||
SNAPPY_UNPACKED:=$(TARGET)/snappy-extracted.log
|
||||
SNAPPY_GIT_UNPACKED:=$(TARGET)/snappy-git-extracted.log
|
||||
SNAPPY_CMAKE_CACHE=$(SNAPPY_OUT)/CMakeCache.txt
|
||||
|
||||
ifdef USE_GIT
|
||||
ifndef GIT_REPO_URL
|
||||
$(warning GIT_REPO_URL is not set when using git)
|
||||
endif
|
||||
ifndef GIT_SNAPPY_BRANCH
|
||||
$(warning GIT_SNAPPY_BRANCH is not set when using git)
|
||||
BITSHUFFLE_ARCHIVE:=$(TARGET)/bitshuffle-$(BITSHUFFLE_VERSION).tar.gz
|
||||
BITSHUFFLE_C:=bitshuffle_core.c iochain.c
|
||||
BITSHUFFLE_SRC_DIR:=$(TARGET)/bitshuffle-$(BITSHUFFLE_VERSION)/src
|
||||
BITSHUFFLE_SRC:=$(addprefix $(BITSHUFFLE_SRC_DIR)/,$(BITSHUFFLE_C))
|
||||
BITSHUFFLE_UNPACKED:=$(TARGET)/bitshuffle-extracted.log
|
||||
|
||||
$(BITSHUFFLE_ARCHIVE):
|
||||
@mkdir -p $(@D)
|
||||
curl -L -o$@ https://github.com/kiyo-masui/bitshuffle/archive/$(BITSHUFFLE_VERSION).tar.gz
|
||||
|
||||
$(BITSHUFFLE_UNPACKED): $(BITSHUFFLE_ARCHIVE)
|
||||
$(TAR) xvfz $< -C $(TARGET)
|
||||
touch $@
|
||||
|
||||
$(BITSHUFFLE_SRC): $(BITSHUFFLE_UNPACKED)
|
||||
|
||||
$(SNAPPY_OUT)/%.o: $(BITSHUFFLE_SRC_DIR)/%.c
|
||||
@mkdir -p $(@D)
|
||||
$(CXX) $(CXXFLAGS) $(CXXFLAGS_BITSHUFFLE) -c $< -o $@
|
||||
|
||||
SNAPPY_OBJ:=$(addprefix $(SNAPPY_OUT)/,$(patsubst %.cc,%.o,$(SNAPPY_CC)) $(patsubst %.c,%.o,$(BITSHUFFLE_C)) SnappyNative.o BitShuffleNative.o)
|
||||
|
||||
CXXFLAGS:=$(CXXFLAGS) -I$(SNAPPY_SRC_DIR) -I$(SNAPPY_OUT) -I$(BITSHUFFLE_SRC_DIR)
|
||||
|
||||
ifndef CXXFLAGS_BITSHUFFLE
|
||||
ifeq ($(OS_NAME)-$(OS_ARCH),Linux-x86_64)
|
||||
# SSE2 is supported in all the x86_64 platforms and AVX2 is only supported
|
||||
# in the small part of them. gcc in linux/x86_64 typically enables SSE2 by default though,
|
||||
# we explicitly set flags below to make this precondition clearer.
|
||||
CXXFLAGS_BITSHUFFLE:=-U__AVX2__ -msse2
|
||||
else
|
||||
# Undefined macros to generate a platform-independent binary
|
||||
CXXFLAGS_BITSHUFFLE:=-U__AVX2__ -U__SSE2__
|
||||
endif
|
||||
endif
|
||||
|
||||
CXXFLAGS:=$(CXXFLAGS) -I$(SNAPPY_SRC_DIR)
|
||||
|
||||
ifeq ($(OS_NAME),SunOS)
|
||||
TAR:= gtar
|
||||
else
|
||||
ifeq ($(OS_NAME),AIX)
|
||||
TAR:= gtar
|
||||
else
|
||||
TAR:= tar
|
||||
endif
|
||||
endif
|
||||
|
||||
$(SNAPPY_ARCHIVE):
|
||||
@mkdir -p $(@D)
|
||||
curl -o$@ http://snappy.googlecode.com/files/snappy-$(VERSION).tar.gz
|
||||
curl -L -o$@ https://github.com/google/snappy/releases/download/$(SNAPPY_VERSION)/snappy-$(SNAPPY_VERSION).tar.gz
|
||||
|
||||
$(SNAPPY_UNPACKED): $(SNAPPY_ARCHIVE)
|
||||
$(TAR) xvfz $< -C $(TARGET)
|
||||
$(TAR) xvfz $< -C $(TARGET)
|
||||
touch $@
|
||||
cd $(SNAPPY_SRC_DIR) && ./configure
|
||||
|
||||
$(SNAPPY_GIT_UNPACKED):
|
||||
@mkdir -p $(SNAPPY_OUT)
|
||||
rm -rf $(SNAPPY_SRC_DIR)
|
||||
@mkdir -p $(SNAPPY_SRC_DIR)
|
||||
git clone $(GIT_REPO_URL) $(SNAPPY_SRC_DIR)
|
||||
git --git-dir=$(SNAPPY_SRC_DIR)/.git --work-tree=$(SNAPPY_SRC_DIR) checkout -b local/snappy-$(GIT_SNAPPY_BRANCH) $(GIT_SNAPPY_BRANCH)
|
||||
git clone $(SNAPPY_GIT_REPO_URL) $(SNAPPY_SRC_DIR)
|
||||
git --git-dir=$(SNAPPY_SRC_DIR)/.git --work-tree=$(SNAPPY_SRC_DIR) checkout -b local/snappy-$(SNAPPY_VERSION) $(SNAPPY_GIT_REV)
|
||||
cd $(SNAPPY_SRC_DIR) && git submodule update --init
|
||||
touch $@
|
||||
cd $(SNAPPY_SRC_DIR) && ./configure
|
||||
|
||||
jni-header: $(SRC)/org/xerial/snappy/SnappyNative.h
|
||||
$(SNAPPY_CMAKE_CACHE): $(SNAPPY_GIT_UNPACKED)
|
||||
@mkdir -p $(SNAPPY_OUT)
|
||||
cd $(SNAPPY_OUT) && cmake $(SNAPPY_CMAKE_OPTS) ../../$(SNAPPY_SRC_DIR)
|
||||
touch $@
|
||||
|
||||
$(TARGET)/jni-classes/org/xerial/snappy/SnappyNative.class : $(SRC)/org/xerial/snappy/SnappyNative.java
|
||||
jni-header: $(SNAPPY_GIT_UNPACKED) $(BITSHUFFLE_UNPACKED) $(SRC)/org/xerial/snappy/SnappyNative.h $(SRC)/org/xerial/snappy/BitShuffleNative.h
|
||||
|
||||
snappy-header: $(SNAPPY_CMAKE_CACHE)
|
||||
|
||||
$(TARGET)/jni-classes/org/xerial/snappy/SnappyNative.class: $(SRC)/org/xerial/snappy/SnappyNative.java
|
||||
@mkdir -p $(TARGET)/jni-classes
|
||||
$(JAVAC) -source 1.6 -target 1.6 -d $(TARGET)/jni-classes -sourcepath $(SRC) $<
|
||||
$(JAVAC) -source 1.7 -target 1.7 -h $(SRC)/org/xerial/snappy/ -d $(TARGET)/jni-classes -sourcepath $(SRC) $<
|
||||
|
||||
$(SRC)/org/xerial/snappy/SnappyNative.h: $(TARGET)/jni-classes/org/xerial/snappy/SnappyNative.class
|
||||
$(JAVAH) -force -classpath $(TARGET)/jni-classes -o $@ org.xerial.snappy.SnappyNative
|
||||
|
||||
ifndef USE_GIT
|
||||
$(SNAPPY_SRC): $(SNAPPY_UNPACKED)
|
||||
else
|
||||
$(SNAPPY_SRC): $(SNAPPY_GIT_UNPACKED)
|
||||
$(TARGET)/jni-classes/org/xerial/snappy/BitShuffleNative.class: $(SRC)/org/xerial/snappy/BitShuffleNative.java
|
||||
@mkdir -p $(TARGET)/jni-classes
|
||||
$(JAVAC) -source 1.7 -target 1.7 -h $(SRC)/org/xerial/snappy/ -d $(TARGET)/jni-classes -sourcepath $(SRC) $<
|
||||
|
||||
$(SRC)/org/xerial/snappy/BitShuffleNative.h: $(TARGET)/jni-classes/org/xerial/snappy/BitShuffleNative.class
|
||||
|
||||
$(SNAPPY_SRC): $(SNAPPY_GIT_UNPACKED)
|
||||
|
||||
# aarch64 can use big-endian optimzied code
|
||||
ifeq ($(OS_ARCH),aarch64)
|
||||
ifeq ($(ENDIANESS),$(BIG_ENDIAN))
|
||||
SNAPPY_CXX_OPTS:=-DSNAPPY_IS_BIG_ENDIAN
|
||||
endif
|
||||
endif
|
||||
|
||||
$(SNAPPY_OUT)/%.o : $(SNAPPY_SRC_DIR)/%.cc
|
||||
$(SNAPPY_OUT)/%.o: $(SNAPPY_SRC_DIR)/%.cc
|
||||
@mkdir -p $(@D)
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
$(CXX) $(SNAPPY_CXX_OPTS) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
$(SNAPPY_OUT)/SnappyNative.o : $(SRC)/org/xerial/snappy/SnappyNative.cpp $(SRC)/org/xerial/snappy/SnappyNative.h
|
||||
$(SNAPPY_OUT)/SnappyNative.o: $(SRC)/org/xerial/snappy/SnappyNative.cpp $(SRC)/org/xerial/snappy/SnappyNative.h
|
||||
@mkdir -p $(@D)
|
||||
$(CXX) $(SNAPPY_CXX_OPTS) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
$(SNAPPY_OUT)/BitShuffleNative.o: $(SRC)/org/xerial/snappy/BitShuffleNative.cpp $(SRC)/org/xerial/snappy/BitShuffleNative.h
|
||||
@mkdir -p $(@D)
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
|
||||
$(SNAPPY_OUT)/$(LIBNAME): $(SNAPPY_OBJ)
|
||||
$(CXX) $(CXXFLAGS) -o $@ $+ $(LINKFLAGS)
|
||||
$(STRIP) $@
|
||||
$(CXX) $(CXXFLAGS) -o $@ $+ $(LINKFLAGS)
|
||||
# Workaround for strip Protocol error when using VirtualBox on Mac
|
||||
cp $@ /tmp/$(@F)
|
||||
$(STRIP) /tmp/$(@F)
|
||||
cp /tmp/$(@F) $@
|
||||
|
||||
clean-native:
|
||||
clean-native:
|
||||
rm -rf $(SNAPPY_OUT)
|
||||
|
||||
clean:
|
||||
@ -87,79 +142,106 @@ NATIVE_DIR:=src/main/resources/org/xerial/snappy/native/$(OS_NAME)/$(OS_ARCH)
|
||||
NATIVE_TARGET_DIR:=$(TARGET)/classes/org/xerial/snappy/native/$(OS_NAME)/$(OS_ARCH)
|
||||
NATIVE_DLL:=$(NATIVE_DIR)/$(LIBNAME)
|
||||
|
||||
snappy-jar-version:=snappy-java-$(shell perl -npe "s/version in ThisBuild\s+:=\s+\"(.*)\"/\1/" version.sbt | sed -e "/^$$/d")
|
||||
snappy-jar-version:=snappy-java-$(shell ./script/dynver.sh | cut -d'=' -f2 | sed 's/[ \"]//g')
|
||||
|
||||
ifndef USE_GIT
|
||||
native: $(SNAPPY_UNPACKED) $(NATIVE_DLL)
|
||||
else
|
||||
native: $(SNAPPY_GIT_UNPACKED) $(NATIVE_DLL)
|
||||
endif
|
||||
jar-version:
|
||||
echo $(snappy-jar-version)
|
||||
|
||||
native: jni-header snappy-header $(NATIVE_DLL)
|
||||
native-nocmake: jni-header $(NATIVE_DLL)
|
||||
snappy: native $(TARGET)/$(snappy-jar-version).jar
|
||||
|
||||
$(NATIVE_DLL): $(SNAPPY_OUT)/$(LIBNAME)
|
||||
@mkdir -p $(@D)
|
||||
cp $< $@
|
||||
@mkdir -p $(NATIVE_TARGET_DIR)
|
||||
cp $< $(NATIVE_TARGET_DIR)/$(LIBNAME)
|
||||
native-all: native native-arm clean-docker mac64 win32 win64 linux32 linux64 linux-ppc64le linux-riscv64 linux-s390x
|
||||
|
||||
ifdef CI
|
||||
# Clean docker images within CI to avoid no space left error
|
||||
DOCKER_POST_PROCESS:=docker system prune --all --force --volumes
|
||||
else
|
||||
DOCKER_POST_PROCESS:=
|
||||
endif
|
||||
|
||||
clean-docker:
|
||||
$(DOCKER_POST_PROCESS)
|
||||
|
||||
$(NATIVE_DLL): $(SNAPPY_OUT)/$(LIBNAME)
|
||||
@mkdir -p $(@D)
|
||||
cp $(SNAPPY_OUT)/$(LIBNAME) $@
|
||||
@mkdir -p $(NATIVE_TARGET_DIR)
|
||||
cp $(SNAPPY_OUT)/$(LIBNAME) $(NATIVE_TARGET_DIR)/$(LIBNAME)
|
||||
|
||||
package: $(TARGET)/$(snappy-jar-version).jar
|
||||
|
||||
$(TARGET)/$(snappy-jar-version).jar:
|
||||
$(SBT) package
|
||||
$(TARGET)/$(snappy-jar-version).jar:
|
||||
$(SBT) package
|
||||
|
||||
test: $(NATIVE_DLL)
|
||||
$(SBT) test
|
||||
|
||||
win32:
|
||||
$(MAKE) native CROSS_PREFIX=i686-w64-mingw32- OS_NAME=Windows OS_ARCH=x86
|
||||
DOCKER_RUN_OPTS:=--rm
|
||||
|
||||
# for cross-compilation on Ubuntu, install the g++-mingw-w64-x86-64 package
|
||||
win64:
|
||||
$(MAKE) native CROSS_PREFIX=x86_64-w64-mingw32- OS_NAME=Windows OS_ARCH=x86_64
|
||||
|
||||
mac32:
|
||||
win32: jni-header
|
||||
./docker/dockcross-windows-x86 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native snappy-header native CROSS_PREFIX=i686-w64-mingw32.static- OS_NAME=Windows OS_ARCH=x86 SNAPPY_CMAKE_OPTS="-DHAVE_SYS_UIO_H=0"'
|
||||
|
||||
win64: jni-header
|
||||
./docker/dockcross-windows-x64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native snappy-header native CROSS_PREFIX=x86_64-w64-mingw32.static- OS_NAME=Windows OS_ARCH=x86_64 SNAPPY_CMAKE_OPTS="-DHAVE_SYS_UIO_H=0"'
|
||||
|
||||
# deprecated
|
||||
mac32: jni-header
|
||||
$(MAKE) native OS_NAME=Mac OS_ARCH=x86
|
||||
|
||||
linux32:
|
||||
$(MAKE) native OS_NAME=Linux OS_ARCH=x86
|
||||
mac64: jni-header
|
||||
docker run -i $(DOCKER_RUN_OPTS) -v $$PWD:/workdir -e CROSS_TRIPLE=x86_64-apple-darwin multiarch/crossbuild make clean-native native OS_NAME=Mac OS_ARCH=x86_64
|
||||
|
||||
linux32: jni-header
|
||||
docker run $(DOCKER_RUN_OPTS) -i -v $$PWD:/work xerial/centos5-linux-x86_64-pic bash -c 'make clean-native native-nocmake OS_NAME=Linux OS_ARCH=x86'
|
||||
|
||||
linux64: jni-header
|
||||
docker run $(DOCKER_RUN_OPTS) -i -v $$PWD:/work xerial/centos5-linux-x86_64-pic bash -c 'make clean-native native-nocmake OS_NAME=Linux OS_ARCH=x86_64'
|
||||
|
||||
freebsd64:
|
||||
$(MAKE) native OS_NAME=FreeBSD OS_ARCH=x86_64
|
||||
|
||||
# for cross-compilation on Ubuntu, install the g++-arm-linux-gnueabi package
|
||||
linux-arm:
|
||||
$(MAKE) native CROSS_PREFIX=arm-linux-gnueabi- OS_NAME=Linux OS_ARCH=arm
|
||||
# For ARM
|
||||
native-arm: linux-arm64 linux-android-arm linux-android-aarch64 linux-arm linux-armv6 linux-armv7 windows-aarch64
|
||||
|
||||
# for cross-compilation on Ubuntu, install the g++-arm-linux-gnueabihf package
|
||||
linux-armhf:
|
||||
$(MAKE) native CROSS_PREFIX=arm-linux-gnueabihf- OS_NAME=Linux OS_ARCH=armhf
|
||||
|
||||
clean-native-linux32:
|
||||
$(MAKE) clean-native OS_NAME=Linux OS_ARCH=x86
|
||||
# TODO: CROSS_PREFIX can be replaced with ${CROSS_ROOT}/bin/${CROSS_TRIPLE}- in Makefile.common
|
||||
linux-arm: jni-header
|
||||
./docker/dockcross-armv5 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=/usr/xcc/armv5-unknown-linux-gnueabi/bin//armv5-unknown-linux-gnueabi- OS_NAME=Linux OS_ARCH=arm'
|
||||
|
||||
clean-native-win32:
|
||||
$(MAKE) clean-native OS_NAME=Windows OS_ARCH=x86
|
||||
linux-armv6: jni-header
|
||||
./docker/dockcross-armv6 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native OS_NAME=Linux OS_ARCH=armv6'
|
||||
|
||||
linux-armv7: jni-header
|
||||
./docker/dockcross-armv7 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native OS_NAME=Linux OS_ARCH=armv7'
|
||||
|
||||
linux-android-arm: jni-header
|
||||
./docker/dockcross-android-arm -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=/usr/arm-linux-androideabi/bin/arm-linux-androideabi- OS_NAME=Linux OS_ARCH=android-arm'
|
||||
|
||||
linux-android-aarch64: jni-header
|
||||
./docker/dockcross-android-arm64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native OS_NAME=Linux OS_ARCH=android-aarch64'
|
||||
|
||||
linux-ppc64le: jni-header
|
||||
./docker/dockcross-ppc64le -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=powerpc64le-unknown-linux-gnu- OS_NAME=Linux OS_ARCH=ppc64le'
|
||||
|
||||
linux-ppc64: jni-header
|
||||
./docker/dockcross-ppc64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=powerpc64-unknown-linux-gnu- OS_NAME=Linux OS_ARCH=ppc64'
|
||||
|
||||
linux-arm64: jni-header
|
||||
./docker/dockcross-arm64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=aarch64-unknown-linux-gnu- OS_NAME=Linux OS_ARCH=aarch64'
|
||||
|
||||
linux-riscv64: jni-header
|
||||
./docker/dockcross-riscv64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=/usr/xcc/riscv64-unknown-linux-gnu/bin/riscv64-unknown-linux-gnu- OS_NAME=Linux OS_ARCH=riscv64'
|
||||
|
||||
linux-s390x: jni-header
|
||||
./docker/dockcross-s390x -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=/usr/xcc/s390x-ibm-linux-gnu/bin/s390x-ibm-linux-gnu- OS_NAME=Linux OS_ARCH=s390x'
|
||||
|
||||
windows-aarch64: jni-header
|
||||
./docker/dockcross-windows-arm64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=/usr/xcc/aarch64-w64-mingw32-cross/bin/aarch64-w64-mingw32- OS_NAME=Windows OS_ARCH=aarch64'
|
||||
|
||||
javadoc:
|
||||
$(SBT) doc
|
||||
|
||||
install-m2:
|
||||
$(SBT) publishM2
|
||||
|
||||
googlecode-upload: googlecode-lib-upload googlecode-src-upload
|
||||
|
||||
googlecode-lib-upload: $(TARGET)/snappy-java-$(VERSION)-lib.upload
|
||||
googlecode-src-upload: $(TARGET)/snappy-java-$(VERSION)-src.upload
|
||||
|
||||
GOOGLECODE_USER:=leo@xerial.org
|
||||
|
||||
$(TARGET)/snappy-java-$(VERSION)-lib.upload:
|
||||
./googlecode_upload.py -s "library for all platforms" -p snappy-java -l "Type-Executable,Featured,OpSys-All" -u "$(GOOGLECODE_USER)" target/snappy-java-$(VERSION).jar
|
||||
touch $@
|
||||
|
||||
$(TARGET)/snappy-java-$(VERSION)-src.upload:
|
||||
./googlecode_upload.py -s "source code archive" -p snappy-java -l "Type-Source,OpSys-All" -u "$(GOOGLECODE_USER)" target/snappy-java-$(VERSION).tar.gz
|
||||
touch $@
|
||||
|
||||
|
||||
|
234
Makefile.common
234
Makefile.common
@ -1,20 +1,22 @@
|
||||
TARGET:=target
|
||||
SRC:=src/main/java
|
||||
include $(SRC)/org/xerial/snappy/VERSION
|
||||
include src/main/resources/org/xerial/snappy/VERSION
|
||||
|
||||
ifndef JAVA_HOME
|
||||
$(error Set JAVA_HOME environment variable)
|
||||
$(warning Set JAVA_HOME environment variable)
|
||||
endif
|
||||
|
||||
|
||||
JAVA := "$$JAVA_HOME/bin/java"
|
||||
JAVAC := "$$JAVA_HOME/bin/javac"
|
||||
JAVAC := "$$JAVA_HOME/bin/javac"
|
||||
JAVAH := "$$JAVA_HOME/bin/javah"
|
||||
|
||||
LITTLE_ENDIAN := "Little Endian"
|
||||
BIG_ENDIAN := "Big Endian"
|
||||
OSINFO_CLASS := org.xerial.snappy.OSInfo
|
||||
OSINFO_PROG := lib/org/xerial/snappy/OSInfo.class
|
||||
|
||||
## building OSInfo.java
|
||||
## building OSInfo.java
|
||||
#$(info compiling OSInfo.java)
|
||||
#$(shell mkdir -p lib)
|
||||
#$(shell $(JAVAC) src/main/java/org/xerial/snappy/OSInfo.java -d lib)
|
||||
@ -24,6 +26,12 @@ OS_ARCH := $(shell $(JAVA) -cp lib $(OSINFO_CLASS) --arch)
|
||||
LIB_FOLDER := $(shell $(JAVA) -cp lib $(OSINFO_CLASS))
|
||||
IBM_JDK_LIB := lib/inc_ibm
|
||||
|
||||
ifeq ($(OS_NAME),Mac)
|
||||
ENDIANESS:="Little Endian"
|
||||
else
|
||||
ENDIANESS:=$(shell lscpu | grep "Byte Order" |cut -d ":" -f2)
|
||||
endif
|
||||
|
||||
# Windows uses different path separators
|
||||
ifeq ($(OS_NAME),Windows)
|
||||
sep := ;
|
||||
@ -31,7 +39,7 @@ else
|
||||
sep := :
|
||||
endif
|
||||
|
||||
snappy := snappy-$(VERSION)
|
||||
snappy := snappy-$(SNAPPY_VERSION)
|
||||
|
||||
|
||||
jni_md := $(shell find -L "$(JAVA_HOME)" -name jni_md.h | head -1)
|
||||
@ -42,7 +50,8 @@ endif
|
||||
|
||||
# os=Default is meant to be generic unix/linux
|
||||
|
||||
known_os_archs := Linux-x86 Linux-x86_64 Linux-arm Linux-armhf Linux-ppc64 Mac-x86 Mac-x86_64 FreeBSD-x86_64 Windows-x86 Windows-x86_64 SunOS-x86 SunOS-sparc SunOS-x86_64 AIX-ppc64
|
||||
# To support new CPU architecture, add a new target name here
|
||||
known_os_archs := Linux-x86 Linux-x86_64 Linux-arm Linux-armv6 Linux-armv7 Linux-android-arm Linux-android-aarch64 Linux-aarch64 Linux-ppc Linux-ppc64 Linux-ppc64le Linux-s390 Linux-s390x Mac-x86 Mac-x86_64 Mac-aarch64 FreeBSD-x86_64 Windows-x86 Windows-x86_64 Windows-aarch64 SunOS-x86 SunOS-sparc SunOS-x86_64 AIX-ppc AIX-ppc64 Linux-riscv Linux-riscv64 Linux-loongarch Linux-loongarch64
|
||||
os_arch := $(OS_NAME)-$(OS_ARCH)
|
||||
IBM_JDK_7 := $(findstring IBM, $(shell $(JAVA) -version 2>&1 | grep IBM | grep "JRE 1.7"))
|
||||
|
||||
@ -67,68 +76,124 @@ CROSS_PREFIX :=
|
||||
|
||||
Default_CXX := $(CROSS_PREFIX)g++
|
||||
Default_STRIP := $(CROSS_PREFIX)strip
|
||||
Default_CXXFLAGS := -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden
|
||||
Default_CXXFLAGS := -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -std=c++11
|
||||
Default_LINKFLAGS := -shared -static
|
||||
Default_LIBNAME := libsnappyjava.so
|
||||
Default_SNAPPY_FLAGS :=
|
||||
Default_SNAPPY_FLAGS :=
|
||||
|
||||
Linux-x86_CXX := $(CROSS_PREFIX)g++
|
||||
Linux-x86_STRIP := $(CROSS_PREFIX)strip
|
||||
ifeq ($(IBM_JDK_7),)
|
||||
Linux-x86_CXXFLAGS := -include lib/inc_linux/jni_md.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -m32
|
||||
Linux-x86_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -m32 -U__SSE2__ -std=c++11
|
||||
else
|
||||
Linux-x86_CXXFLAGS := -include $(IBM_JDK_LIB)/jni_md.h -include $(IBM_JDK_LIB)/jniport.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -m32
|
||||
Linux-x86_CXXFLAGS := -include $(IBM_JDK_LIB)/jni_md.h -include $(IBM_JDK_LIB)/jniport.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -m32 -U__SSE2__ -std=c++11
|
||||
endif
|
||||
Linux-x86_LINKFLAGS := -shared -static-libgcc -static-libstdc++
|
||||
Linux-x86_LIBNAME := libsnappyjava.so
|
||||
Linux-x86_SNAPPY_FLAGS:=
|
||||
Linux-x86_SNAPPY_FLAGS:=
|
||||
|
||||
Linux-x86_64_CXX := $(CROSS_PREFIX)g++
|
||||
Linux-x86_64_CXX := $(CROSS_PREFIX)g++
|
||||
Linux-x86_64_STRIP := $(CROSS_PREFIX)strip
|
||||
ifeq ($(IBM_JDK_7),)
|
||||
Linux-x86_64_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -m64
|
||||
Linux-x86_64_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -m64 -std=c++11
|
||||
else
|
||||
Linux-x86_64_CXXFLAGS := -include $(IBM_JDK_LIB)/jni_md.h -include $(IBM_JDK_LIB)/jniport.h -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -m64
|
||||
Linux-x86_64_CXXFLAGS := -include $(IBM_JDK_LIB)/jni_md.h -include $(IBM_JDK_LIB)/jniport.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -m64 -std=c++11
|
||||
endif
|
||||
Linux-x86_64_LINKFLAGS := -shared -static-libgcc -static-libstdc++
|
||||
Linux-x86_64_LIBNAME := libsnappyjava.so
|
||||
Linux-x86_64_SNAPPY_FLAGS :=
|
||||
Linux-x86_64_SNAPPY_FLAGS :=
|
||||
|
||||
Linux-ppc64_CXX := g++
|
||||
Linux-ppc64_STRIP := strip
|
||||
Linux-ppc_CXX := g++
|
||||
Linux-ppc_STRIP := strip
|
||||
ifeq ($(IBM_JDK_7),)
|
||||
Linux-ppc64_CXXFLAGS := -DHAVE_CONFIG_H -Ilib/inc_linux -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -m64
|
||||
Linux-ppc_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -m32 -std=c++11
|
||||
else
|
||||
Linux-ppc64_CXXFLAGS := -DHAVE_CONFIG_H -include $(IBM_JDK_LIB)/jni_md.h -include $(IBM_JDK_LIB)/jniport.h -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -O2 -fPIC
|
||||
Linux-ppc_CXXFLAGS := -include lib/inc_linux/jni_md.h -include $(IBM_JDK_LIB)/jniport.h -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -O2 -fPIC -m32 -std=c++11
|
||||
endif
|
||||
Linux-ppc_LINKFLAGS := -shared -static-libgcc -static-libstdc++
|
||||
Linux-ppc_LIBNAME := libsnappyjava.so
|
||||
Linux-ppc_SNAPPY_FLAGS :=
|
||||
|
||||
Linux-ppc64le_CXX := $(CROSS_PREFIX)g++
|
||||
Linux-ppc64le_STRIP := $(CROSS_PREFIX)strip
|
||||
ifeq ($(IBM_JDK_7),)
|
||||
Linux-ppc64le_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -m64 -std=c++11
|
||||
else
|
||||
Linux-ppc64le_CXXFLAGS := -include $(IBM_JDK_LIB)/jni_md.h -include $(IBM_JDK_LIB)/jniport.h -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -O2 -fPIC -m64 -std=c++11
|
||||
endif
|
||||
# ppcle64 GLIBC is at 2.17; so disable __tls_get_addr_opt which is dependent on 2.22;
|
||||
Linux-ppc64le_LINKFLAGS := -shared -static-libgcc -static-libstdc++ -Wl,--no-tls-optimize,--no-tls-get-addr-optimize
|
||||
Linux-ppc64le_LIBNAME := libsnappyjava.so
|
||||
Linux-ppc64le_SNAPPY_FLAGS :=
|
||||
|
||||
Linux-ppc64_CXX := $(CROSS_PREFIX)g++
|
||||
Linux-ppc64_STRIP := $(CROSS_PREFIX)strip
|
||||
ifeq ($(IBM_JDK_7),)
|
||||
Linux-ppc64_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -m64 -std=c++11
|
||||
else
|
||||
Linux-ppc64_CXXFLAGS := -include $(IBM_JDK_LIB)/jni_md.h -include $(IBM_JDK_LIB)/jniport.h -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -O2 -fPIC -m64 -std=c++11
|
||||
endif
|
||||
Linux-ppc64_LINKFLAGS := -shared -static-libgcc -static-libstdc++
|
||||
Linux-ppc64_LIBNAME := libsnappyjava.so
|
||||
Linux-ppc64_SNAPPY_FLAGS :=
|
||||
|
||||
AIX-ppc_CXX := g++
|
||||
AIX-ppc_STRIP := strip
|
||||
AIX-ppc_LIBNAME := libsnappyjava.a
|
||||
ifeq ($(IBM_JDK_7),)
|
||||
AIX-ppc_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -maix32 -std=c++11
|
||||
else
|
||||
AIX-ppc_CXXFLAGS := -I$(JAVA_HOME)/include/aix -Ilib/inc_ibm -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -maix32 -std=c++11
|
||||
endif
|
||||
AIX-ppc_LINKFLAGS := -shared -static-libgcc -static-libstdc++ -lcrypt
|
||||
AIX-ppc_SNAPPY_FLAGS :=
|
||||
|
||||
AIX-ppc64_CXX := g++
|
||||
AIX-ppc64_STRIP := strip -X64
|
||||
AIX-ppc64_LIBNAME := libsnappyjava.a
|
||||
ifeq ($(IBM_JDK_7),)
|
||||
AIX-ppc64_CXXFLAGS := -DHAVE_CONFIG_H -Ilib/inc_linux -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -m64
|
||||
AIX-ppc64_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -maix64 -std=c++11
|
||||
else
|
||||
AIX-ppc64_CXXFLAGS := -DHAVE_CONFIG_H -I$(JAVA_HOME)/include/aix -Ilib/inc_ibm -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -maix64
|
||||
AIX-ppc64_CXXFLAGS := -I$(JAVA_HOME)/include/aix -Ilib/inc_ibm -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -maix64 -std=c++11
|
||||
endif
|
||||
AIX-ppc64_LINKFLAGS := -shared -static-libgcc -static-libstdc++ -lcrypt
|
||||
AIX-ppc64_SNAPPY_FLAGS :=
|
||||
|
||||
SunOS-x86_CXX := g++
|
||||
Linux-s390_CXX := g++
|
||||
Linux-s390_STRIP := strip
|
||||
ifeq ($(IBM_JDK_7),)
|
||||
Linux-s390_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -m31 -std=c++11
|
||||
else
|
||||
Linux-s390_CXXFLAGS := -I$(JAVA_HOME)/include/linux -Ilib/inc_ibm -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -m31 -std=c++11
|
||||
endif
|
||||
Linux-s390_LINKFLAGS := -shared -static-libgcc -static-libstdc++
|
||||
Linux-s390_LIBNAME := libsnappyjava.so
|
||||
Linux-s390_SNAPPY_FLAGS :=
|
||||
|
||||
Linux-s390x_CXX := $(CROSS_PREFIX)g++
|
||||
Linux-s390x_STRIP := $(CROSS_PREFIX)strip
|
||||
ifeq ($(IBM_JDK_7),)
|
||||
Linux-s390x_CXXFLAGS := -Ilib/inc_ibm -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -m64 -std=c++11
|
||||
else
|
||||
Linux-s390x_CXXFLAGS := -I$(JAVA_HOME)/include/linux -Ilib/inc_ibm -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -m64 -std=c++11
|
||||
endif
|
||||
Linux-s390x_LINKFLAGS := -shared -static-libgcc -static-libstdc++
|
||||
Linux-s390x_LIBNAME := libsnappyjava.so
|
||||
Linux-s390x_SNAPPY_FLAGS :=
|
||||
|
||||
SunOS-x86_CXX := g++
|
||||
SunOS-x86_STRIP := strip
|
||||
SunOS-x86_CXXFLAGS := -include lib/inc_linux/jni_md.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden
|
||||
SunOS-x86_LINKFLAGS := -shared -static-libgcc -static-libstdc++
|
||||
SunOS-x86_LIBNAME := libsnappyjava.so
|
||||
SunOS-x86_SNAPPY_FLAGS :=
|
||||
SunOS-x86_SNAPPY_FLAGS :=
|
||||
|
||||
SunOS-sparc_CXX := g++
|
||||
SunOS-sparc_CXX := g++
|
||||
SunOS-sparc_STRIP := strip
|
||||
SunOS-sparc_CXXFLAGS := -include lib/inc_linux/jni_md.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden
|
||||
SunOS-sparc_LINKFLAGS := -shared -static-libgcc -static-libstdc++
|
||||
SunOS-sparc_LIBNAME := libsnappyjava.so
|
||||
SunOS-sparc_SNAPPY_FLAGS :=
|
||||
SunOS-sparc_SNAPPY_FLAGS :=
|
||||
|
||||
SunOS-x86_64_CXX := g++
|
||||
SunOS-x86_64_STRIP := strip
|
||||
@ -144,66 +209,133 @@ SunOS-x86_64_SNAPPY_FLAGS :=
|
||||
|
||||
Linux-arm_CXX := $(CROSS_PREFIX)g++
|
||||
Linux-arm_STRIP := $(CROSS_PREFIX)strip
|
||||
Linux-arm_CXXFLAGS := -include lib/inc_linux/jni_md.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -mfloat-abi=softfp
|
||||
Linux-arm_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -mfloat-abi=softfp -std=c++11
|
||||
Linux-arm_LINKFLAGS := -shared -static-libgcc
|
||||
Linux-arm_LIBNAME := libsnappyjava.so
|
||||
Linux-arm_SNAPPY_FLAGS:=
|
||||
Linux-arm_SNAPPY_FLAGS:=
|
||||
|
||||
Linux-armhf_CXX := $(CROSS_PREFIX)g++
|
||||
Linux-armhf_STRIP := $(CROSS_PREFIX)strip
|
||||
Linux-armhf_CXXFLAGS := -include lib/inc_linux/jni_md.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -mfloat-abi=hard
|
||||
Linux-armhf_LINKFLAGS := -shared -static-libgcc
|
||||
Linux-armhf_LIBNAME := libsnappyjava.so
|
||||
Linux-armhf_SNAPPY_FLAGS:=
|
||||
Linux-armv6_CXX := ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-g++
|
||||
Linux-armv6_STRIP := ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-strip
|
||||
Linux-armv6_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -mfloat-abi=hard -std=c++11
|
||||
Linux-armv6_LINKFLAGS := -shared -static-libgcc -std=c++11
|
||||
Linux-armv6_LIBNAME := libsnappyjava.so
|
||||
Linux-armv6_SNAPPY_FLAGS:=
|
||||
|
||||
Linux-armv7_CXX := ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-g++
|
||||
Linux-armv7_STRIP := ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-strip
|
||||
Linux-armv7_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -mfloat-abi=softfp -std=c++11
|
||||
Linux-armv7_LINKFLAGS := -shared -static-libgcc
|
||||
Linux-armv7_LIBNAME := libsnappyjava.so
|
||||
Linux-armv7_SNAPPY_FLAGS:=
|
||||
|
||||
Linux-android-arm_CXX := $(CROSS_PREFIX)g++
|
||||
Linux-android-arm_STRIP := $(CROSS_ROOT)/bin/llvm-strip
|
||||
Linux-android-arm_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -std=c++11
|
||||
Linux-android-arm_LINKFLAGS := -shared -static-libgcc
|
||||
Linux-android-arm_LIBNAME := libsnappyjava.so
|
||||
Linux-android-arm_SNAPPY_FLAGS:=
|
||||
|
||||
Linux-android-aarch64_CXX := ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-g++
|
||||
Linux-android-aarch64_STRIP := ${CROSS_ROOT}/bin/llvm-strip
|
||||
Linux-android-aarch64_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -std=c++11
|
||||
Linux-android-aarch64_LINKFLAGS := -shared -static-libgcc
|
||||
Linux-android-aarch64_LIBNAME := libsnappyjava.so
|
||||
Linux-android-aarch64_SNAPPY_FLAGS:=
|
||||
|
||||
Linux-aarch64_CXX := $(CROSS_PREFIX)g++
|
||||
Linux-aarch64_STRIP := $(CROSS_PREFIX)strip
|
||||
Linux-aarch64_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -std=c++11
|
||||
Linux-aarch64_LINKFLAGS := -shared -static-libgcc -static-libstdc++
|
||||
Linux-aarch64_LIBNAME := libsnappyjava.so
|
||||
Linux-aarch64_SNAPPY_FLAGS:=
|
||||
|
||||
Mac-x86_CXX := g++ -arch i386
|
||||
Mac-x86_STRIP := strip -x
|
||||
Mac-x86_CXXFLAGS := -Ilib/inc_mac -I$(JAVA_HOME)/include -O2 -fPIC -mmacosx-version-min=10.4 -fvisibility=hidden
|
||||
Mac-x86_CXXFLAGS := -Ilib/inc_mac -I$(JAVA_HOME)/include -O2 -fPIC -mmacosx-version-min=10.4 -fvisibility=hidden -std=c++11
|
||||
Mac-x86_LINKFLAGS := -dynamiclib -static-libgcc
|
||||
Mac-x86_LIBNAME := libsnappyjava.jnilib
|
||||
Mac-x86_LIBNAME := libsnappyjava.dylib
|
||||
Mac-x86_SNAPPY_FLAGS :=
|
||||
|
||||
Mac-x86_64_CXX := g++ -arch $(OS_ARCH)
|
||||
Mac-x86_64_CXX := c++ -arch $(OS_ARCH)
|
||||
Mac-x86_64_STRIP := strip -x
|
||||
Mac-x86_64_CXXFLAGS := -Ilib/inc_mac -I$(JAVA_HOME)/include -O2 -fPIC -mmacosx-version-min=10.5 -fvisibility=hidden
|
||||
Mac-x86_64_LINKFLAGS := -dynamiclib
|
||||
Mac-x86_64_LIBNAME := libsnappyjava.jnilib
|
||||
Mac-x86_64_SNAPPY_FLAGS :=
|
||||
Mac-x86_64_CXXFLAGS := -Ilib/inc_mac -I$(JAVA_HOME)/include -O2 -fPIC -mmacosx-version-min=10.7 -fvisibility=hidden -stdlib=libc++ -std=c++11 -ftemplate-depth=1024
|
||||
Mac-x86_64_LINKFLAGS := -dynamiclib
|
||||
Mac-x86_64_LIBNAME := libsnappyjava.dylib
|
||||
Mac-x86_64_SNAPPY_FLAGS :=
|
||||
|
||||
Mac-aarch64_CXX := c++ -arch arm64
|
||||
Mac-aarch64_STRIP := strip -x
|
||||
Mac-aarch64_CXXFLAGS := -Ilib/inc_mac -I$(JAVA_HOME)/include -O2 -fPIC -mmacosx-version-min=10.7 -fvisibility=hidden -stdlib=libc++ -std=c++11
|
||||
Mac-aarch64_LINKFLAGS := -dynamiclib
|
||||
Mac-aarch64_LIBNAME := libsnappyjava.dylib
|
||||
|
||||
FreeBSD-x86_64_CXX := $(CROSS_PREFIX)g++
|
||||
FreeBSD-x86_64_STRIP := $(CROSS_PREFIX)strip
|
||||
FreeBSD-x86_64_CXXFLAGS := -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden
|
||||
FreeBSD-x86_64_CXXFLAGS := -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden -std=c++11
|
||||
FreeBSD-x86_64_LINKFLAGS := -shared -static-libgcc
|
||||
FreeBSD-x86_64_LIBNAME := libsnappyjava.so
|
||||
FreeBSD-x86_64_SNAPPY_FLAGS :=
|
||||
FreeBSD-x86_64_SNAPPY_FLAGS :=
|
||||
|
||||
Windows-x86_CXX := $(CROSS_PREFIX)g++
|
||||
Windows-x86_STRIP := $(CROSS_PREFIX)strip
|
||||
Windows-x86_CXXFLAGS := -Ilib/inc_win -O2
|
||||
Windows-x86_CXXFLAGS := -Ilib/inc_win -O2 -std=c++11
|
||||
Windows-x86_LINKFLAGS := -Wl,--kill-at -shared -static
|
||||
Windows-x86_LIBNAME := snappyjava.dll
|
||||
Windows-x86_SNAPPY_FLAGS :=
|
||||
Windows-x86_SNAPPY_FLAGS :=
|
||||
|
||||
Windows-x86_64_CXX := $(CROSS_PREFIX)g++
|
||||
Windows-x86_64_STRIP := $(CROSS_PREFIX)strip
|
||||
Windows-x86_64_CXXFLAGS := -Ilib/inc_win -O2
|
||||
Windows-x86_64_LINKFLAGS := -Wl,--kill-at -shared -static
|
||||
Windows-x86_64_CXXFLAGS := -Ilib/inc_win -O2 -std=c++11
|
||||
Windows-x86_64_LINKFLAGS := -Wl,--kill-at -shared -static
|
||||
Windows-x86_64_LIBNAME := snappyjava.dll
|
||||
Windows-x86_64_SNAPPY_FLAGS :=
|
||||
Windows-x86_64_SNAPPY_FLAGS :=
|
||||
|
||||
Linux-riscv_CXX := $(CROSS_PREFIX)g++
|
||||
Linux-riscv_STRIP := $(CROSS_PREFIX)strip
|
||||
Linux-riscv_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -std=c++11
|
||||
Linux-riscv_LINKFLAGS := -shared -static-libgcc -static-libstdc++
|
||||
Linux-riscv_LIBNAME := libsnappyjava.so
|
||||
Linux-riscv_SNAPPY_FLAGS:=
|
||||
|
||||
Linux-riscv64_CXX := $(CROSS_PREFIX)g++
|
||||
Linux-riscv64_STRIP := $(CROSS_PREFIX)strip
|
||||
Linux-riscv64_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -std=c++11
|
||||
Linux-riscv64_LINKFLAGS := -shared -static-libgcc -static-libstdc++
|
||||
Linux-riscv64_LIBNAME := libsnappyjava.so
|
||||
Linux-riscv64_SNAPPY_FLAGS:=
|
||||
|
||||
Windows-aarch64_CXX := $(CROSS_PREFIX)g++
|
||||
Windows-aarch64_STRIP := $(CROSS_PREFIX)strip
|
||||
Windows-aarch64_CXXFLAGS := -Ilib/inc_mac -I$(JAVA_HOME)/include -O2 -fPIC -march=armv8-a -fvisibility=hidden -D_WIN32 -DNOMINMAX -std=c++11
|
||||
Windows-aarch64_LINKFLAGS := -Wl,--kill-at -shared -static
|
||||
Windows-aarch64_LIBNAME := snappyjava.dll
|
||||
|
||||
Linux-loongarch_CXX := $(CROSS_PREFIX)g++
|
||||
Linux-loongarch_STRIP := $(CROSS_PREFIX)strip
|
||||
Linux-loongarch_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -std=c++11
|
||||
Linux-loongarch_LINKFLAGS := -shared
|
||||
Linux-loongarch_LIBNAME := libsnappyjava.so
|
||||
Linux-loongarch_SNAPPY_FLAGS:=
|
||||
|
||||
Linux-loongarch64_CXX := $(CROSS_PREFIX)g++
|
||||
Linux-loongarch64_STRIP := $(CROSS_PREFIX)strip
|
||||
Linux-loongarch64_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -std=c++11
|
||||
Linux-loongarch64_LINKFLAGS := -shared
|
||||
Linux-loongarch64_LIBNAME := libsnappyjava.so
|
||||
Linux-loongarch64_SNAPPY_FLAGS:=
|
||||
|
||||
|
||||
CXX := $($(os_arch)_CXX)
|
||||
STRIP := $($(os_arch)_STRIP)
|
||||
CXXFLAGS := $($(os_arch)_CXXFLAGS)
|
||||
LINKFLAGS := $($(os_arch)_LINKFLAGS)
|
||||
CXXFLAGS := $($(os_arch)_CXXFLAGS)
|
||||
LINKFLAGS := $($(os_arch)_LINKFLAGS)
|
||||
LIBNAME := $($(os_arch)_LIBNAME)
|
||||
SNAPPY_FLAGS := $($(os_arch)_SNAPPY_FLAGS)
|
||||
|
||||
|
||||
|
||||
CXXFLAGS := $(CXXFLAGS) -Ilib/include
|
||||
CXXFLAGS := $(CXXFLAGS) -DHAVE_CONFIG_H -DNDEBUG
|
||||
ifneq ($(jni_include),)
|
||||
CXXFLAGS := $(CXXFLAGS) -I"$(jni_include)"
|
||||
endif
|
||||
|
||||
|
||||
|
@ -28,8 +28,8 @@ DLL_DIR=src/main/resources/org/xerial/snappy/native
|
||||
|
||||
DLL_WIN=$(DLL_DIR)/Windows/x86/snappyjava.dll
|
||||
DLL_WIN64=$(DLL_DIR)/Windows/amd64/snappyjava.dll
|
||||
DLL_MAC=$(DLL_DIR)/Mac/x86_64/libsnappyjava.jnilib
|
||||
DLL_TIGER_MAC=$(DLL_DIR)/Mac/i386/libsnappyjava.jnilib
|
||||
DLL_MAC=$(DLL_DIR)/Mac/x86_64/libsnappyjava.dylib
|
||||
DLL_TIGER_MAC=$(DLL_DIR)/Mac/i386/libsnappyjava.dylib
|
||||
DLL_LINUX=$(DLL_DIR)/Linux/i386/libsnappyjava.so
|
||||
DLL_AMD64=$(DLL_DIR)/Linux/amd64/libsnappyjava.so
|
||||
|
||||
|
135
Milestone.md
135
Milestone.md
@ -1,11 +1,128 @@
|
||||
## Features under consideration
|
||||
* `SnappyIndexer` for parallel compression/decompression
|
||||
* CUI commands (snap/unsnap)
|
||||
|
||||
Since vesion 1.1.0.x, Java 6 (1.6) or higher is required.
|
||||
Since snappy-java 1.1.9.0, release notes will be available in the GitHub releases page https://github.com/xerial/snappy-java/releases
|
||||
|
||||
## snappy-java-1.1.1.4 (23 Oct 2014)
|
||||
* Fixes #88 and #89
|
||||
Since version 1.1.0.x, Java 6 (1.6) or higher is required.
|
||||
|
||||
## snappy-java-1.1.8.3 (2021-01-20)
|
||||
* Make pure-java Snappy thread-safe [#271](https://github.com/xerial/snappy-java/pull/271)
|
||||
* Improved SnappyFramedInput/OutputStream performance by using java.util.zip.CRC32C [#269](https://github.com/xerial/snappy-java/pull/269)
|
||||
|
||||
## snappy-java-1.1.8.2 (2020-11-28)
|
||||
* Support Apple Silicon (M1, Mac-aarch64)
|
||||
* Fixed the pure-java Snappy fallback logic when no native library for your platform is found.
|
||||
|
||||
## snappy-java-1.1.8.1 (2020-11-09)
|
||||
* Fixed an initialization issue when using a recent Mac OS X version [#265](https://github.com/xerial/snappy-java/pull/265)
|
||||
|
||||
## snappy-java-1.1.8 (2020-10-20)
|
||||
* Upgrade to [Snappy 1.1.8](https://github.com/google/snappy/releases/tag/1.1.8) with small performance improvements.
|
||||
|
||||
## snappy-java-1.1.7.8 (2020-10-20)
|
||||
* Big-endian support for pure-java Snappy implementation
|
||||
* linux-aarch64 (arm64) binary embeds libstdc++ for portability
|
||||
* internal: Fix make native-all target to support the latest version of dockcross
|
||||
|
||||
## snappy-java-1.1.7.7 (2020-08-25)
|
||||
* Built snappy-java with jdk8 to resolve #251 (java.lang.NoSuchMethodError)
|
||||
|
||||
## snappy-java-1.1.7.6 (2020-06-26)
|
||||
* Added an experimental support of pure-java Snappy https://github.com/xerial/snappy-java#using-pure-java-snappy-implementation
|
||||
* Pure-java snappy doesn't support Snappy.isValidCompressedBuffer methods, but the other methods, Snappy.compress, uncompress, SnappyInput/OutputStream, SnappyFramedInput/OutputStream, etc., should work as expected.
|
||||
* Changed the minimum JVM requirement to JDK 1.8
|
||||
|
||||
## snappy-java-1.1.7.5 (2020-05-06)
|
||||
* Fixes java.lang.NoClassDefFoundError: org/xerial/snappy/pool/DefaultPoolFactory in 1.1.7.4
|
||||
|
||||
## snapy-java-1.1.7.4 (2020-05-05)
|
||||
* __DO NOT USE THIS VERSION__ 1.1.7.4 misses a package for using SnappyFramed streams.
|
||||
* Caching internal buffers for SnappyFramed streams [#234](https://github.com/xerial/snappy-java/pull/234)
|
||||
* Fixed the native lib for ppc64le to work with glibc 2.17 (Previously it depended on 2.22)
|
||||
|
||||
## snappy-java-1.1.7.3 (2019-03-25)
|
||||
* Minor release
|
||||
* Output the snappy header even for the empty input to address Spark's [issue](https://issues.apache.org/jira/browse/SPARK-27267)
|
||||
* Fixed SnappyFramed stream to support Java 9
|
||||
|
||||
## snappy-java-1.1.7.2 (2018-05-21)
|
||||
* Fix for aarch64 endian issue
|
||||
|
||||
## snappy-java-1.1.7.1 (2017-12-07)
|
||||
* Fix for Android. No need to upgrade to this version if you are not using Android
|
||||
|
||||
## snappy-java-1.1.7 (2017-11-30)
|
||||
* Upgrade to [snappy-1.1.7](https://github.com/google/snappy/releases/tag/1.1.7)
|
||||
* Improved performance for big-endian architecture
|
||||
* The other performance improvement in [snappy-1.1.5](https://github.com/google/snappy/releases/tag/1.1.5)
|
||||
* (internal) Changed to use docker + cmake for building native libraries
|
||||
* Fix android architecture resolution
|
||||
* Add hadoop compatible SnappyHadoopCompatibleOutputStream
|
||||
|
||||
## snappy-java-1.1.4 (2017-05-22)
|
||||
* Upgrade to [snappy-1.1.4](https://github.com/google/snappy/releases/tag/1.1.4)
|
||||
* Improved performance compression (5%), decompression (20%)
|
||||
* Added BitShuffle API for fast and better integer and floating-point value compresssion
|
||||
* Added native libraries for s390x, AIX/Linux ppc64/ppc64le
|
||||
* Added prelimirary support Linux armv5, armv6, armv7, android-arm, aarch64
|
||||
* Using docker for cross-compiling native libraries for various platforms
|
||||
* Note: snappy-java for FreeBSD, SunOS are still using snappy 1.1.2. Your contributions of native libraries are welcome. Please send a pull request that contains the changes after running `make native test` in your platform.
|
||||
|
||||
## snappy-java-1.1.4-M3 (2017-02-16)
|
||||
* Fix native libraries for ppc64 (bigendian) and ppc64le (little endian)
|
||||
|
||||
## snappy-java-1.1.4-M2 (2017-02-13)
|
||||
* Added s390x and AIX ppc/ppc64 support.
|
||||
|
||||
## snappy-java-1.1.4-M1 (2017-02-10)
|
||||
* A preview release for 1.1.4
|
||||
|
||||
## snappy-java-1.1.3-M2 (2017-01-25)
|
||||
* Rename to BitShuffle.shuffle/unshuffle
|
||||
* Add ByteBuffer based APIs for bitshffle
|
||||
|
||||
## snappy-java-1.1.3-M1 (2017-01-19)
|
||||
* This is a preview release. Appreciate your feedback.
|
||||
* Upgraded to snappy 1.1.3 (Minor compression performance improvement)
|
||||
* Added support for armv5, armv6, armv7, android-arm, aarch64, ppc64
|
||||
* Added BitShuffle (<https://github.com/kiyo-masui/bitshuffle>) class for better primitive array compression
|
||||
* Using docker-based cross compilers for building native libraries
|
||||
* AIX, FreeBSD, SunOS, IBM s390x are still using snappy 1.1.2. Your contributions of native libraries are welcome. Please send a pull request that contains the changes after running `make native` in your platform.
|
||||
|
||||
## snappy-java-1.1.2.6 (2016-06-02)
|
||||
* Fix a bug in SnappyInputStream when reading compressed data that happened to have the same first byte with the stream magic header (#142)
|
||||
* Never use 1.1.2.5 (This is a broken build)
|
||||
|
||||
## snappy-java-1.1.2.4 (2016-03-30)
|
||||
* Improved `SnappyOutputStream.write(byte[], off, len)` performance.
|
||||
|
||||
## snappy-java-1.1.2.3 (2016-03-30)
|
||||
* Improved `SnappyInputStream.read(byte[], off, len)` performance.
|
||||
|
||||
## snappy-java-1.1.2.2 (2016-03-29)
|
||||
* Add AArch64 support
|
||||
|
||||
## snappy-java-1.1.2.1 (2016-01-22)
|
||||
* Fixed #131
|
||||
|
||||
## snappy-java-1.1.2 (22 September 2015)
|
||||
* This is a backward compatible release for 1.1.x.
|
||||
* Add AIX (32-bit) support.
|
||||
* There is no upgrade for the native libraries of the other platforms.
|
||||
* A major change since 1.1.1 is a support for reading concatenated results of SnappyOutputStream(s)
|
||||
|
||||
## snappy-java-1.1.2-RC2 (18 May 2015)
|
||||
* Fix #107: SnappyOutputStream.close() is not idempotent
|
||||
|
||||
## snappy-java-1.1.2-RC1 (13 May 2015)
|
||||
* SnappyInputStream now supports reading concatenated compressed results of SnappyOutputStream
|
||||
* There has been no compressed format change since 1.0.5.x. So You can read the compressed results interchangeably between these versions.
|
||||
* Fixes a problem when java.io.tmpdir does not exist.
|
||||
|
||||
## snappy-java-1.1.1.7 (14 Apr 2015)
|
||||
* Fixes #100
|
||||
|
||||
## snappy-java-1.1.1.6 (26 Oct 2014)
|
||||
* Fixes #88, #89, #90 and #91
|
||||
* Fixed the broken build of 1.1.1.4 and memory leak bug 1.1.1.5 (so never use these versions)
|
||||
|
||||
## snappy-java-1.0.5.4 (12 September 2014)
|
||||
* Embedded libstdc++ for Linux/amd64 native library (hotfix to 1.0.5.x series)
|
||||
@ -27,7 +144,7 @@ Since vesion 1.1.0.x, Java 6 (1.6) or higher is required.
|
||||
* Building with sbt
|
||||
|
||||
# snappy-java-1.0.5.2 (25 June 2014)
|
||||
* Maintanance release
|
||||
* Maintenance release
|
||||
* Add PowerPC support ppc64le, ppc64 (big-endian)
|
||||
|
||||
# snappy-java-1.1.1-M2 (12 June 2014)
|
||||
@ -81,7 +198,7 @@ Since vesion 1.1.0.x, Java 6 (1.6) or higher is required.
|
||||
|
||||
## snappy-java-1.0.3.2 (August 23rd, 2011)
|
||||
* Upgrade from the previous release is optional
|
||||
* Add system properites to switch sytem installed native library or bundled
|
||||
* Add system properties to switch system installed native library or bundled
|
||||
library (issue 20, issue 26)
|
||||
* source code tar ball (issue 25)
|
||||
* primitive array read/write support (issue 24)
|
||||
@ -92,7 +209,7 @@ Since vesion 1.1.0.x, Java 6 (1.6) or higher is required.
|
||||
* Rebuild win32 binary
|
||||
|
||||
## snappy-java-1.0.3 (July 11st, 2011)
|
||||
* Deprected SnappyException. Instead snappy-java uses IOException to issue
|
||||
* Deprecated SnappyException. Instead snappy-java uses IOException to issue
|
||||
errors. This change is necessary to support JNI code injection to a parent
|
||||
class loader.
|
||||
|
||||
|
9
NOTICE
9
NOTICE
@ -5,8 +5,8 @@ This product includes software developed by Apache
|
||||
PureJavaCrc32C from apache-hadoop-common http://hadoop.apache.org/
|
||||
(Apache 2.0 license)
|
||||
|
||||
This library containd statically linked libstdc++. This inclusion is allowed by
|
||||
"GCC RUntime Library Exception"
|
||||
This library contains statically linked libstdc++. This inclusion is allowed by
|
||||
"GCC Runtime Library Exception"
|
||||
http://gcc.gnu.org/onlinedocs/libstdc++/manual/license.html
|
||||
|
||||
== Contributors ==
|
||||
@ -15,3 +15,8 @@ http://gcc.gnu.org/onlinedocs/libstdc++/manual/license.html
|
||||
* Alec Wysoker
|
||||
* Performance and memory usage improvement
|
||||
|
||||
Third-Party Notices and Licenses:
|
||||
|
||||
- Hadoop: Apache Hadoop is used as a dependency
|
||||
License: Apache License 2.0
|
||||
Source/Reference: https://github.com/apache/hadoop/blob/trunk/NOTICE.txt
|
||||
|
260
README.md
260
README.md
@ -1,77 +1,47 @@
|
||||
The snappy-java is a Java port of the snappy
|
||||
<http://code.google.com/p/snappy/>, a fast C++ compresser/decompresser developed by Google.
|
||||
snappy-java
|
||||
[](https://travis-ci.org/xerial/snappy-java)
|
||||
[](https://maven-badges.herokuapp.com/maven-central/org.xerial.snappy/snappy-java/)
|
||||
[](https://javadoc.io/doc/org.xerial.snappy/snappy-java)
|
||||
===
|
||||
snappy-java is a Java port of the [snappy](https://github.com/google/snappy), a fast C++ compresser/decompresser developed by Google.
|
||||
|
||||
## Features
|
||||
* Fast compression/decompression tailored to 64-bit CPU architecture.
|
||||
* JNI-based implementation to achieve comparable performance to the native C++ version.
|
||||
## Features
|
||||
* Fast compression/decompression around 200~400MB/sec.
|
||||
* Less memory usage. SnappyOutputStream uses only 32KB+ in default.
|
||||
* JNI-based implementation to achieve comparable performance to the native C++ version.
|
||||
* Although snappy-java uses JNI, it can be used safely with multiple class loaders (e.g. Tomcat, etc.).
|
||||
* Supporting compression/decompression of Java primitive arrays (`float[]`, `double[]`, `int[]`, `short[]`, `long[]`, etc.)
|
||||
* Portable across various operating systems; Snappy-java contains native libraries built for Window/Mac/Linux (64-bit). snappy-java loads one of these libraries according to your machine environment (It looks system properties, `os.name` and `os.arch`).
|
||||
* Simple usage. Add the snappy-java-(version).jar file to your classpath. Then call compression/decompression methods in `org.xerial.snappy.Snappy`.
|
||||
* [Framing-format support](http://snappy.googlecode.com/svn/trunk/framing_format.txt) (Since 1.1.0 version)
|
||||
* Compression/decompression of Java primitive arrays (`float[]`, `double[]`, `int[]`, `short[]`, `long[]`, etc.)
|
||||
* To improve the compression ratios of these arrays, you can use a fast data-rearrangement implementation ([`BitShuffle`](https://oss.sonatype.org/service/local/repositories/releases/archive/org/xerial/snappy/snappy-java/1.1.8/snappy-java-1.1.8-javadoc.jar/!/org/xerial/snappy/BitShuffle.html)) before compression
|
||||
* Portable across various operating systems; Snappy-java contains native libraries built for Window/Mac/Linux, etc. snappy-java loads one of these libraries according to your machine environment (It looks system properties, `os.name` and `os.arch`).
|
||||
* Simple usage. Add the snappy-java-(version).jar file to your classpath. Then call compression/decompression methods in `org.xerial.snappy.Snappy`.
|
||||
* [Framing-format support](https://github.com/google/snappy/blob/master/framing_format.txt) (Since 1.1.0 version)
|
||||
* OSGi support
|
||||
* [Apache License Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). Free for both commercial and non-commercial use.
|
||||
|
||||
## Performance
|
||||
## Performance
|
||||
* Snappy's main target is very high-speed compression/decompression with reasonable compression size. So the compression ratio of snappy-java is modest and about the same as `LZF` (ranging 20%-100% according to the dataset).
|
||||
|
||||
* Here are some [benchmark results](https://github.com/ning/jvm-compressor-benchmark/wiki), comparing
|
||||
snappy-java and the other compressors
|
||||
`LZO-java`/`LZF`/`QuickLZ`/`Gzip`/`Bzip2`. Thanks [Tatu Saloranta @cotowncoder](http://twitter.com/#!/cowtowncoder) for providing the benchmark suite.
|
||||
* The benchmark result indicates snappy-java is the fastest compreesor/decompressor in Java
|
||||
* <http://ning.github.com/jvm-compressor-benchmark/results/canterbury-roundtrip-2011-07-28/index.html>
|
||||
* The decompression speed is twice as fast as the others:
|
||||
* <http://ning.github.com/jvm-compressor-benchmark/results/canterbury-uncompress-2011-07-28/index.html>
|
||||
`LZO-java`/`LZF`/`QuickLZ`/`Gzip`/`Bzip2`. Thanks [Tatu Saloranta @cotowncoder](http://twitter.com/#!/cowtowncoder) for providing the benchmark suite.
|
||||
* The benchmark result indicates snappy-java is the fastest compressor/decompressor in Java: https://ning.github.io/jvm-compressor-benchmark/results/canterbury-roundtrip-2011-07-28/index.html
|
||||
* The decompression speed is twice as fast as the others: https://ning.github.io/jvm-compressor-benchmark/results/canterbury-uncompress-2011-07-28/index.html
|
||||
|
||||
|
||||
## Download
|
||||
## Download
|
||||
|
||||
* [Release Notes](Milestone.md)
|
||||
[](https://maven-badges.herokuapp.com/maven-central/org.xerial.snappy/snappy-java/)
|
||||
[](https://javadoc.io/doc/org.xerial.snappy/snappy-java)
|
||||
|
||||
* [Release Notes](Milestone.md)
|
||||
|
||||
The current stable version is available from here:
|
||||
* Release version: http://central.maven.org/maven2/org/xerial/snappy/snappy-java/
|
||||
* Release version: https://repo1.maven.org/maven2/org/xerial/snappy/snappy-java/
|
||||
* Snapshot version (the latest beta version): https://oss.sonatype.org/content/repositories/snapshots/org/xerial/snappy/snappy-java/
|
||||
|
||||
For Maven user, see [pom.xml example](#using-with-maven).
|
||||
|
||||
## Usage
|
||||
First, import `org.xerial.snapy.Snappy` in your Java code:
|
||||
|
||||
```java
|
||||
import org.xerial.snappy.Snappy;
|
||||
```
|
||||
|
||||
Then use `Snappy.compress(byte[])` and `Snappy.uncompress(byte[])`:
|
||||
|
||||
```java
|
||||
String input = "Hello snappy-java! Snappy-java is a JNI-based wrapper of "
|
||||
+ "Snappy, a fast compresser/decompresser.";
|
||||
byte[] compressed = Snappy.compress(input.getBytes("UTF-8"));
|
||||
byte[] uncompressed = Snappy.uncompress(compressed);
|
||||
|
||||
String result = new String(uncompressed, "UTF-8");
|
||||
System.out.println(result);
|
||||
```
|
||||
|
||||
In addition, high-level methods (`Snappy.compress(String)`, `Snappy.compress(float[] ..)` etc. ) and low-level ones (e.g. `Snappy.rawCompress(.. )`, `Snappy.rawUncompress(..)`, etc.), which minimize memory copies, can be used.
|
||||
|
||||
### Stream-based API
|
||||
Stream-based compressor/decompressor `SnappyFramedOutputStream`/`SnappyFramedInputStream` are also available for reading/writing large data sets.
|
||||
|
||||
* See also [Javadoc API](https://oss.sonatype.org/service/local/repositories/releases/archive/org/xerial/snappy/snappy-java/1.1.0/snappy-java-1.1.0-javadoc.jar/!/index.html)
|
||||
|
||||
### Setting classpath
|
||||
If you have snappy-java-(VERSION).jar in the current directory, use `-classpath` option as follows:
|
||||
|
||||
$ javac -classpath ".;snappy-java-(VERSION).jar" Sample.java # in Windows
|
||||
or
|
||||
$ javac -classpath ".:snappy-java-(VERSION).jar" Sample.java # in Mac or Linux
|
||||
|
||||
|
||||
### Using with Maven
|
||||
* Snappy-java is available from Maven's central repository: <http://repo1.maven.org/maven2/org/xerial/snappy/snappy-java>
|
||||
|
||||
Add the following dependency to your pom.xml:
|
||||
|
||||
Snappy-java is available from Maven's central repository. Add the following dependency to your pom.xml:
|
||||
|
||||
<dependency>
|
||||
<groupId>org.xerial.snappy</groupId>
|
||||
@ -88,65 +58,84 @@ libraryDependencies += "org.xerial.snappy" % "snappy-java" % "(version)"
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
First, import `org.xerial.snapy.Snappy` in your Java code:
|
||||
|
||||
```java
|
||||
import org.xerial.snappy.Snappy;
|
||||
```
|
||||
|
||||
Then use `Snappy.compress(byte[])` and `Snappy.uncompress(byte[])`:
|
||||
|
||||
```java
|
||||
String input = "Hello snappy-java! Snappy-java is a JNI-based wrapper of "
|
||||
+ "Snappy, a fast compresser/decompresser.";
|
||||
byte[] compressed = Snappy.compress(input.getBytes("UTF-8"));
|
||||
byte[] uncompressed = Snappy.uncompress(compressed);
|
||||
|
||||
String result = new String(uncompressed, "UTF-8");
|
||||
System.out.println(result);
|
||||
```
|
||||
|
||||
In addition, high-level methods (`Snappy.compress(String)`, `Snappy.compress(float[] ..)` etc. ) and low-level ones (e.g. `Snappy.rawCompress(.. )`, `Snappy.rawUncompress(..)`, etc.), which minimize memory copies, can be used.
|
||||
|
||||
### Stream-based API
|
||||
Stream-based compressor/decompressor `SnappyOutputStream`/`SnappyInputStream` are also available for reading/writing large data sets. `SnappyFramedOutputStream`/`SnappyFramedInputStream` can be used for the [framing format](https://github.com/google/snappy/blob/master/framing_format.txt).
|
||||
|
||||
* See also [Javadoc API](https://oss.sonatype.org/service/local/repositories/releases/archive/org/xerial/snappy/snappy-java/1.1.3-M1/snappy-java-1.1.3-M1-javadoc.jar/!/index.html)
|
||||
|
||||
#### Compatibility Notes
|
||||
|
||||
The original Snappy format definition did not define a file format. It later added
|
||||
a "framing" format to define a file format, but by this point major software was
|
||||
already using an industry standard instead -- represented in this library by the
|
||||
`SnappyOutputStream` and `SnappyInputStream` methods.
|
||||
|
||||
For interoperability with other libraries, check that compatible formats are used.
|
||||
Note that not all libraries support all variants.
|
||||
|
||||
* `SnappyOutputStream` and `SnappyInputStream` use `[magic header:16 bytes]([block size:int32][compressed data:byte array])*` format. You can read the result of `Snappy.compress` with `SnappyInputStream`, but you cannot read the compressed data generated by `SnappyOutputStream` with `Snappy.uncompress`.
|
||||
* `SnappyHadoopCompatibleOutputStream` does not emit a file header but write out the current block size as a preemble to each block
|
||||
|
||||
#### Data format compatibility matrix:
|
||||
|
||||
| Write\Read | `Snappy.uncompress` | `SnappyInputStream` | `SnappyFramedInputStream` | `org.apache.hadoop.io.compress.SnappyCodec` |
|
||||
| --------------- |:-------------------:|:------------------:|:-----------------------:|:-------------------------------------------:|
|
||||
| `Snappy.compress` | ok | ok | x | x |
|
||||
| `SnappyOutputStream` | x | ok | x | x |
|
||||
| `SnappyFramedOutputStream` | x | x | ok | x |
|
||||
| `SnappyHadoopCompatibleOutputStream` | x | x | x | ok |
|
||||
|
||||
### BitShuffle API (Since 1.1.3-M2)
|
||||
|
||||
BitShuffle is an algorithm that reorders data bits (shuffle) for efficient compression (e.g., a sequence of integers, float values, etc.). To use BitShuffle routines, import `org.xerial.snapy.BitShuffle`:
|
||||
|
||||
```java
|
||||
import org.xerial.snappy.BitShuffle;
|
||||
|
||||
int[] data = new int[] {1, 3, 34, 43, 34};
|
||||
byte[] shuffledByteArray = BitShuffle.shuffle(data);
|
||||
byte[] compressed = Snappy.compress(shuffledByteArray);
|
||||
byte[] uncompressed = Snappy.uncompress(compressed);
|
||||
int[] result = BitShuffle.unshuffleIntArray(uncompress);
|
||||
|
||||
System.out.println(result);
|
||||
```
|
||||
|
||||
Shuffling and unshuffling of primitive arrays (e.g., `short[]`, `long[]`, `float[]`, `double[]`, etc.) are supported. See [Javadoc](http://static.javadoc.io/org.xerial.snappy/snappy-java/1.1.3-M1/org/xerial/snappy/BitShuffle.html) for the details.
|
||||
|
||||
### Setting classpath
|
||||
If you have snappy-java-(VERSION).jar in the current directory, use `-classpath` option as follows:
|
||||
|
||||
$ javac -classpath ".;snappy-java-(VERSION).jar" Sample.java # in Windows
|
||||
or
|
||||
$ javac -classpath ".:snappy-java-(VERSION).jar" Sample.java # in Mac or Linux
|
||||
|
||||
|
||||
## Public discussion group
|
||||
Post bug reports or feature request to the Issue Tracker: <https://github.com/xerial/snappy-java/issues>
|
||||
|
||||
Public discussion forum is here: <http://groups.google.com/group/xerial?hl=en Xerial Public Discussion Group>
|
||||
|
||||
|
||||
## Building from the source code
|
||||
See the [installation instruction](https://github.com/xerial/snappy-java/blob/develop/INSTALL). Building from the source code is an option when your OS platform and CPU architecture is not supported. To build snappy-java, you need Git, JDK (1.6 or higher), g++ compiler (mingw in Windows) etc.
|
||||
|
||||
$ git clone https://github.com/xerial/snappy-java.git
|
||||
$ cd snappy-java
|
||||
$ make
|
||||
|
||||
When building on Solaris use
|
||||
|
||||
$ gmake
|
||||
|
||||
A file `target/snappy-java-$(version).jar` is the product additionally containing the native library built for your platform.
|
||||
|
||||
## Building linux x86_64 binary
|
||||
|
||||
snappy-java tries to static link libstdc++ to increase the availability for various Linux versions. However, standard distributions of 64-bit Linux OS rarely provide libstdc++ compiled with `-fPIC` option. I currently uses custom g++, compiled as follows:
|
||||
|
||||
```
|
||||
$ cd work
|
||||
$ wget (gcc-4.8.3 source)
|
||||
$ tar xvfz (gcc-4.8.3.tar.gz)
|
||||
$ cd gcc-4.8.3
|
||||
$ ./contrib/download_prerequisites
|
||||
$ cd ..
|
||||
$ mkdir objdir
|
||||
$ cd objdir
|
||||
$ ../gcc-4.8.3/configure --prefix=$HOME/local/gcc-4.8.3 CXXFLAGS=-fPIC CFLAGS=-fPIC --enable-languages=c,c++
|
||||
$ make
|
||||
$ make install
|
||||
```
|
||||
|
||||
This g++ build enables static linking of libstdc++. For more infomation on building GCC, see GCC's home page.
|
||||
|
||||
## Cross-compiling for other platforms
|
||||
The Makefile contains rules for cross-compiling the native library for other platforms so that the snappy-java JAR can support multiple platforms. For example, to build the native libraries for x86 Linux, x86 and x86-64 Windows, and soft- and hard-float ARM:
|
||||
|
||||
$ make linux32 win32 win64 linux-arm linux-armhf
|
||||
|
||||
If you append `snappy` to the line above, it will also build the native library for the current platform and then build the snappy-java JAR (containing all native libraries built so far).
|
||||
|
||||
Of course, you must first have the necessary cross-compilers and development libraries installed for each target CPU and OS. For example, on Ubuntu 12.04 for x86-64, install the following packages for each target:
|
||||
|
||||
* linux32: `sudo apt-get install g++-multilib libc6-dev-i386 lib32stdc++6`
|
||||
* win32: `sudo apt-get install g++-mingw-w64-i686`
|
||||
* win64: `sudo apt-get install g++-mingw-w64-x86-64`
|
||||
* arm: `sudo apt-get install g++-arm-linux-gnueabi`
|
||||
* armhf: `sudo apt-get install g++-arm-linux-gnueabihf`
|
||||
|
||||
Unfortunately, cross-compiling for Mac OS X is not currently possible; you must compile within OS X.
|
||||
|
||||
If you are using Mac and openjdk7 (or higher), use the following option:
|
||||
|
||||
$ make native LIBNAME=libsnappyjava.dylib
|
||||
Public discussion forum is here: [Xerial Public Discussion Group](http://groups.google.com/group/xerial?hl=en)
|
||||
|
||||
## For developers
|
||||
|
||||
@ -154,16 +143,55 @@ snappy-java uses sbt (simple build tool for Scala) as a build tool. Here is a si
|
||||
|
||||
$ ./sbt # enter sbt console
|
||||
> ~test # run tests upon source code change
|
||||
> ~test-only * # run tests that matches a given name pattern
|
||||
> ~testOnly # run tests that matches a given name pattern
|
||||
> publishM2 # publish jar to $HOME/.m2/repository
|
||||
> package # create jar file
|
||||
|
||||
> findbugs # Produce findbugs report in target/findbugs
|
||||
> jacoco:cover # Report the code coverage of tests to target/jacoco folder
|
||||
|
||||
If you need to see detailed debug messages, launch sbt with `-Dloglevel=debug` option:
|
||||
|
||||
```
|
||||
$ ./sbt -Dloglevel=debug
|
||||
```
|
||||
|
||||
For the details of sbt usage, see my blog post: [Building Java Projects with sbt](http://xerial.org/blog/2014/03/24/sbt/)
|
||||
|
||||
### Building from the source code
|
||||
|
||||
See the [build instruction](https://github.com/xerial/snappy-java/blob/master/BUILD.md). Building from the source code is an option when your OS platform and CPU architecture is not supported. To build snappy-java, you need Git, JDK (1.6 or higher), g++ compiler (mingw in Windows) etc.
|
||||
|
||||
$ git clone https://github.com/xerial/snappy-java.git
|
||||
$ cd snappy-java
|
||||
$ make
|
||||
|
||||
When building on Solaris, use `gmake`:
|
||||
|
||||
$ gmake
|
||||
|
||||
A file `target/snappy-java-$(version).jar` is the product additionally containing the native library built for your platform.
|
||||
|
||||
### Creating a new release
|
||||
|
||||
GitHub action [https://github.com/xerial/snappy-java/blob/master/.github/workflows/release.yml] will publish a new relase to Maven Central (Sonatype) when a new tag vX.Y.Z is pushed.
|
||||
|
||||
## Miscellaneous Notes
|
||||
|
||||
### Using snappy-java with Tomcat 6 (or higher) Web Server
|
||||
|
||||
Simply put the snappy-java's jar to WEB-INF/lib folder of your web application. Usual JNI-library specific problem no longer exists since snappy-java version 1.0.3 or higher can be loaded by multiple class loaders.
|
||||
Simply put the snappy-java's jar to WEB-INF/lib folder of your web application. Usual JNI-library specific problem no longer exists since snappy-java version 1.0.3 or higher can be loaded by multiple class loaders.
|
||||
|
||||
|
||||
### Configure snappy-java using property file
|
||||
|
||||
Prepare org-xerial-snappy.properties file (under the root path of your library) in Java's property file format.
|
||||
Here is a list of the available properties:
|
||||
|
||||
* org.xerial.snappy.lib.path (directory containing a snappyjava's native library)
|
||||
* org.xerial.snappy.lib.name (library file name)
|
||||
* org.xerial.snappy.tempdir (temporary directory to extract a native library bundled in snappy-java)
|
||||
* org.xerial.snappy.use.systemlib (if this value is true, use system installed libsnappyjava.so looking the path specified by java.library.path)
|
||||
|
||||
----
|
||||
Snappy-java is developed by [Taro L. Saito](http://www.xerial.org/leo). Twitter [@taroleo](http://twitter.com/#!/taroleo)
|
||||
|
||||
|
12
SECURITY.md
Normal file
12
SECURITY.md
Normal file
@ -0,0 +1,12 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
| Version | Supported |
|
||||
| ------- | ------------------ |
|
||||
| 1.1.9.x | :white_check_mark: |
|
||||
| < 1.1.8.x | :x: |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
https://github.com/xerial/snappy-java/security/advisories
|
185
build.sbt
185
build.sbt
@ -1,107 +1,124 @@
|
||||
import SonatypeKeys._
|
||||
|
||||
sonatypeSettings
|
||||
|
||||
name := "snappy-java"
|
||||
|
||||
organization := "org.xerial.snappy"
|
||||
Global / onChangedBuildSource := ReloadOnSourceChanges
|
||||
|
||||
name := "snappy-java"
|
||||
organization := "org.xerial.snappy"
|
||||
organizationName := "xerial.org"
|
||||
description := "snappy-java: A fast compression/decompression library"
|
||||
|
||||
description := "snappy-java: A fast compression/decompression library"
|
||||
sonatypeProfileName := "org.xerial"
|
||||
ThisBuild / publishTo := sonatypePublishToBundle.value
|
||||
licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0.html"))
|
||||
homepage := Some(url("https://github.com/xerial/snappy-java"))
|
||||
scmInfo := Some(
|
||||
ScmInfo(
|
||||
browseUrl = url("https://github.com/xerial/snappy-java"),
|
||||
connection = "scm:git@github.com:xerial/snappy-java.git"
|
||||
)
|
||||
)
|
||||
developers := List(
|
||||
Developer(id = "leo", name = "Taro L. Saito", email = "leo@xerial.org", url = url("http://xerial.org/leo"))
|
||||
)
|
||||
|
||||
profileName := "org.xerial"
|
||||
// Use dynamic snapshot version strings for non tagged versions
|
||||
ThisBuild / dynverSonatypeSnapshots := true
|
||||
// Use coursier friendly version separator
|
||||
ThisBuild / dynverSeparator := "-"
|
||||
|
||||
pomExtra := {
|
||||
<url>https://github.comm/xerial/snappy-java</url>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache Software License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>leo</id>
|
||||
<name>Taro L. Saito</name>
|
||||
<email>leo@xerial.org</email>
|
||||
<organization>Xerial Project</organization>
|
||||
<roles>
|
||||
<role>Architect</role>
|
||||
<role>Project Manager</role>
|
||||
<role>Chief Developer</role>
|
||||
</roles>
|
||||
<timezone>+9</timezone>
|
||||
</developer>
|
||||
</developers>
|
||||
<issueManagement>
|
||||
<system>GitHub</system>
|
||||
<url>http://github.com/xerial/snappy-java/issues/list</url>
|
||||
</issueManagement>
|
||||
<inceptionYear>2011</inceptionYear>
|
||||
<scm>
|
||||
<connection>scm:git@github.com:xerial/snappy-java.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:xerial/snappy-java.git</developerConnection>
|
||||
<url>git@github.com:xerial/snappy-java.git</url>
|
||||
</scm>
|
||||
ThisBuild / scalaVersion := "2.12.11"
|
||||
|
||||
// For building jars for JDK8
|
||||
ThisBuild / javacOptions ++= {
|
||||
if (scala.util.Properties.isJavaAtLeast("9")) {
|
||||
// --release 8 option is not available in JDK8
|
||||
Seq("--release", "8")
|
||||
} else {
|
||||
Seq.empty
|
||||
}
|
||||
}
|
||||
Compile / compile / javacOptions ++= Seq("-encoding", "UTF-8", "-Xlint:unchecked", "-Xlint:deprecation")
|
||||
|
||||
doc / javacOptions := {
|
||||
val opts = Seq("-source", "1.8")
|
||||
if (scala.util.Properties.isJavaAtLeast("1.8"))
|
||||
opts ++ Seq("-Xdoclint:none")
|
||||
else
|
||||
opts
|
||||
}
|
||||
|
||||
scalaVersion := "2.11.1"
|
||||
// Configuration for SnappyHadoopCompatibleOutputStream testing
|
||||
Test / fork := true
|
||||
|
||||
javacOptions in (Compile, compile) ++= Seq("-encoding", "UTF-8", "-Xlint:unchecked", "-Xlint:deprecation", "-source", "1.6", "-target", "1.6")
|
||||
val libTemp = {
|
||||
val path = s"${System.getProperty("java.io.tmpdir")}/snappy_test_${System.currentTimeMillis()}"
|
||||
// certain older Linux systems (debian/trusty in Travis CI) requires the libsnappy.so, loaded by
|
||||
// libhadoop.so, be copied to the temp path before the child JVM is forked.
|
||||
// because of that, cannot define as an additional task in Test scope
|
||||
IO.copyFile(file("src/test/resources/lib/Linux/libsnappy.so"), file(s"$path/libsnappy.so"))
|
||||
IO.copyFile(file("src/test/resources/lib/Linux/libsnappy.so"), file(s"$path/libsnappy.so.1"))
|
||||
path
|
||||
}
|
||||
|
||||
val macOSXLibPath = s"$libTemp:${System.getenv("DYLD_LIBRARY_PATH")}"
|
||||
val linuxLibPath = s"$libTemp:${System.getenv("LD_LIBRARY_PATH")}"
|
||||
|
||||
// have to add to system dynamic library path since hadoop native library indirectly load libsnappy.1
|
||||
// can't use javaOptions in Test because it causes the expression to eval twice yielding different temp path values
|
||||
Test / envVars := Map("XERIAL_SNAPPY_LIB" -> libTemp, "DYLD_LIBRARY_PATH" -> macOSXLibPath, "LD_LIBRARY_PATH" -> linuxLibPath)
|
||||
|
||||
testOptions += Tests.Argument(TestFrameworks.JUnit, "-q", "-v")
|
||||
|
||||
concurrentRestrictions in Global := Seq(Tags.limit(Tags.Test, 1))
|
||||
Test / parallelExecution := false
|
||||
|
||||
autoScalaLibrary := false
|
||||
|
||||
crossPaths := false
|
||||
|
||||
logBuffered in Test := false
|
||||
|
||||
incOptions := incOptions.value.withNameHashing(true)
|
||||
crossPaths := false
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
"junit" % "junit" % "4.8.2" % "test",
|
||||
"org.codehaus.plexus" % "plexus-classworlds" % "2.4" % "test",
|
||||
"org.xerial.java" % "xerial-core" % "2.1" % "test",
|
||||
"org.xerial" % "xerial-core" % "3.2.3" % "test",
|
||||
"org.scalatest" % "scalatest_2.11" % "2.2.0" % "test",
|
||||
"org.osgi" % "org.osgi.core" % "4.3.0" % "provided",
|
||||
"com.novocode" % "junit-interface" % "0.10" % "test"
|
||||
"junit" % "junit" % "4.13.2" % "test",
|
||||
"org.codehaus.plexus" % "plexus-classworlds" % "2.8.0" % "test",
|
||||
"org.xerial.java" % "xerial-core" % "2.1" % "test",
|
||||
"org.wvlet.airframe" %% "airframe-log" % "2025.1.1" % "test",
|
||||
"org.osgi" % "org.osgi.core" % "6.0.0" % "provided",
|
||||
"com.github.sbt" % "junit-interface" % "0.13.3" % "test",
|
||||
"org.apache.hadoop" % "hadoop-common" % "3.4.1" % "test" exclude ("org.xerial.snappy", "snappy-java")
|
||||
)
|
||||
|
||||
enablePlugins(SbtOsgi)
|
||||
|
||||
osgiSettings
|
||||
|
||||
|
||||
OsgiKeys.exportPackage := Seq("org.xerial.snappy", "org.xerial.snappy.buffer")
|
||||
|
||||
OsgiKeys.exportPackage := Seq("org.xerial.snappy", "org.xerial.snappy.buffer", "org.xerial.snappy.pool")
|
||||
OsgiKeys.bundleSymbolicName := "org.xerial.snappy.snappy-java"
|
||||
|
||||
OsgiKeys.bundleActivator := Option("org.xerial.snappy.SnappyBundleActivator")
|
||||
|
||||
OsgiKeys.importPackage := Seq("""org.osgi.framework;version="[1.5,2)"""")
|
||||
OsgiKeys.bundleActivator := Option("org.xerial.snappy.SnappyBundleActivator")
|
||||
OsgiKeys.importPackage := Seq("""org.osgi.framework;version="[1.5,2)"""")
|
||||
OsgiKeys.requireCapability := """osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.7))""""
|
||||
|
||||
OsgiKeys.additionalHeaders := Map(
|
||||
"Bundle-NativeCode" -> Seq(
|
||||
"org/xerial/snappy/native/Windows/x86_64/snappyjava.dll;osname=win32;processor=x86-64",
|
||||
"org/xerial/snappy/native/Windows/x86/snappyjava.dll;osname=win32;processor=x86",
|
||||
"org/xerial/snappy/native/Mac/x86/libsnappyjava.jnilib;osname=macosx;processor=x86",
|
||||
"org/xerial/snappy/native/Mac/x86_64/libsnappyjava.jnilib;osname=macosx;processor=x86-64",
|
||||
"org/xerial/snappy/native/Linux/x86_64/libsnappyjava.so;osname=linux;processor=x86-64",
|
||||
"org/xerial/snappy/native/Linux/x86/libsnappyjava.so;osname=linux;processor=x86",
|
||||
"org/xerial/snappy/native/Linux/arm/libsnappyjava.so;osname=linux;processor=arm",
|
||||
"org/xerial/snappy/native/Linux/ppc64/libsnappyjava.so;osname=linux;processor=ppc64",
|
||||
"org/xerial/snappy/native/Linux/ppc64le/libsnappyjava.so;osname=linux;processor=ppc64le",
|
||||
"org/xerial/snappy/native/AIX/ppc64/libsnappyjava.a;osname=aix;processor=ppc64",
|
||||
"org/xerial/snappy/native/SunOS/x86/libsnappyjava.so;osname=sunos;processor=x86",
|
||||
"org/xerial/snappy/native/SunOS/x86_64/libsnappyjava.so;osname=sunos;processor=x86-64",
|
||||
"org/xerial/snappy/native/SunOS/sparc/libsnappyjava.so;osname=sunos;processor=sparc"
|
||||
).mkString(","),
|
||||
"Bundle-DocURL" -> "http://www.xerial.org/",
|
||||
"Bundle-License" -> "http://www.apache.org/licenses/LICENSE-2.0.txt",
|
||||
"Bundle-ActivationPolicy" -> "lazy",
|
||||
"Bundle-Name" -> "snappy-java: A fast compression/decompression library"
|
||||
"org/xerial/snappy/native/Windows/x86_64/snappyjava.dll;osname=win32;processor=x86-64",
|
||||
"org/xerial/snappy/native/Windows/x86_64/snappyjava.dll;osname=win32;processor=x64",
|
||||
"org/xerial/snappy/native/Windows/x86_64/snappyjava.dll;osname=win32;processor=amd64",
|
||||
"org/xerial/snappy/native/Windows/x86/snappyjava.dll;osname=win32;processor=x86",
|
||||
"org/xerial/snappy/native/Mac/x86/libsnappyjava.jnilib;osname=macosx;processor=x86",
|
||||
"org/xerial/snappy/native/Mac/x86_64/libsnappyjava.dylib;osname=macosx;processor=x86-64",
|
||||
"org/xerial/snappy/native/Mac/aarch64/libsnappyjava.dylib;osname=macosx;processor=aarch64",
|
||||
"org/xerial/snappy/native/Linux/x86_64/libsnappyjava.so;osname=linux;processor=x86-64",
|
||||
"org/xerial/snappy/native/Linux/x86_64/libsnappyjava.so;osname=linux;processor=x64",
|
||||
"org/xerial/snappy/native/Linux/x86_64/libsnappyjava.so;osname=linux;processor=amd64",
|
||||
"org/xerial/snappy/native/Linux/x86/libsnappyjava.so;osname=linux;processor=x86",
|
||||
"org/xerial/snappy/native/Linux/aarch64/libsnappyjava.so;osname=linux;processor=aarch64",
|
||||
"org/xerial/snappy/native/Linux/riscv64/libsnappyjava.so;osname=linux;processor=riscv64",
|
||||
"org/xerial/snappy/native/Linux/arm/libsnappyjava.so;osname=linux;processor=arm",
|
||||
"org/xerial/snappy/native/Linux/armv7/libsnappyjava.so;osname=linux;processor=arm_le",
|
||||
"org/xerial/snappy/native/Linux/ppc64/libsnappyjava.so;osname=linux;processor=ppc64le",
|
||||
"org/xerial/snappy/native/Linux/s390x/libsnappyjava.so;osname=linux;processor=s390x",
|
||||
"org/xerial/snappy/native/Linux/loongarch64/libsnappyjava.so;osname=linux;processor=loongarch64",
|
||||
"org/xerial/snappy/native/AIX/ppc/libsnappyjava.a;osname=aix;processor=ppc",
|
||||
"org/xerial/snappy/native/AIX/ppc64/libsnappyjava.a;osname=aix;processor=ppc64",
|
||||
"org/xerial/snappy/native/SunOS/x86/libsnappyjava.so;osname=sunos;processor=x86",
|
||||
"org/xerial/snappy/native/SunOS/x86_64/libsnappyjava.so;osname=sunos;processor=x86-64",
|
||||
"org/xerial/snappy/native/SunOS/sparc/libsnappyjava.so;osname=sunos;processor=sparc"
|
||||
).mkString(","),
|
||||
"Bundle-DocURL" -> "http://www.xerial.org/",
|
||||
"Bundle-License" -> "http://www.apache.org/licenses/LICENSE-2.0.txt",
|
||||
"Bundle-ActivationPolicy" -> "lazy",
|
||||
"Bundle-Name" -> "snappy-java: A fast compression/decompression library"
|
||||
)
|
||||
|
41
docker/Dockerfile.centos5-linux-x86_64-pic
Normal file
41
docker/Dockerfile.centos5-linux-x86_64-pic
Normal file
@ -0,0 +1,41 @@
|
||||
FROM centos:5
|
||||
MAINTAINER Taro L. Saito <leo@xerial.org>
|
||||
|
||||
RUN sed -i 's/enabled=1/enabled=0/' /etc/yum/pluginconf.d/fastestmirror.conf
|
||||
RUN sed -i 's/mirrorlist/#mirrorlist/' /etc/yum.repos.d/*.repo
|
||||
RUN sed -i 's|#baseurl=http://mirror.centos.org/centos/$releasever|baseurl=http://vault.centos.org/5.11|' /etc/yum.repos.d/*.repo
|
||||
|
||||
RUN yum -y install make gcc gcc-c++ glibc-devel perl wget bzip2 curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN mkdir /tmp/work \
|
||||
&& cd /tmp/work \
|
||||
&& wget http://www.netgull.com/gcc/releases/gcc-4.8.3/gcc-4.8.3.tar.gz \
|
||||
&& tar xvfz gcc-4.8.3.tar.gz \
|
||||
&& cd gcc-4.8.3 \
|
||||
&& ./contrib/download_prerequisites \
|
||||
&& cd .. \
|
||||
&& mkdir objdir
|
||||
|
||||
RUN cd /tmp/work/objdir \
|
||||
&& ../gcc-4.8.3/configure --prefix=/usr/local/gcc-4.8.3 CXXFLAGS=-fPIC CFLAGS=-fPIC --enable-languages=c,c++ \
|
||||
&& make
|
||||
|
||||
RUN cd /tmp/work/objdir \
|
||||
&& make install \
|
||||
&& rm -rf /tmp/work
|
||||
|
||||
#RUN mkdir /tmp/cmake \
|
||||
# && cd /tmp/cmake \
|
||||
# && wget --no-check-certificate https://cmake.org/files/v3.10/cmake-3.10.0.tar.gz \
|
||||
# && tar xvfz cmake-3.10.0.tar.gz \
|
||||
# && cd cmake-3.10.0 \
|
||||
# && CXX=/usr/local/gcc-4.8.3/bin/g++ ./bootstrap \
|
||||
# && make \
|
||||
# && make install \
|
||||
# && rm -rf /tmp/cmake
|
||||
|
||||
ENV PATH /usr/local/gcc-4.8.3/bin:$PATH
|
||||
ENV LD_LIBRARY_PATH /usr/local/gcc-4.8.3/lib64/:$LD_LIBRARY_PATH
|
||||
|
||||
WORKDIR /work
|
55
docker/Dockerfile.linux-ppc64
Normal file
55
docker/Dockerfile.linux-ppc64
Normal file
@ -0,0 +1,55 @@
|
||||
FROM dockcross/base:latest
|
||||
MAINTAINER Taro L. Saito "leo@xerial.org"
|
||||
|
||||
# Add the cross compiler sources
|
||||
RUN echo "deb http://emdebian.org/tools/debian/ jessie main" >> /etc/apt/sources.list && \
|
||||
dpkg --add-architecture powerpc && \
|
||||
curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | apt-key add -
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
crossbuild-essential-powerpc \
|
||||
gfortran-powerpc-linux-gnu \
|
||||
libbz2-dev:powerpc \
|
||||
libexpat1-dev:powerpc \
|
||||
ncurses-dev:powerpc \
|
||||
libssl-dev:powerpc
|
||||
|
||||
WORKDIR /usr/src
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y libglib2.0-dev zlib1g-dev libpixman-1-dev && \
|
||||
curl -L http://wiki.qemu-project.org/download/qemu-2.6.0.tar.bz2 | tar xj && \
|
||||
cd qemu-2.6.0 && \
|
||||
./configure --target-list=ppc64-linux-user --prefix=/usr && \
|
||||
make -j$(nproc) && \
|
||||
make install && \
|
||||
cd .. && rm -rf qemu-2.6.0
|
||||
|
||||
ENV CROSS_TRIPLE powerpc-linux-gnu
|
||||
ENV CROSS_ROOT /usr/${CROSS_TRIPLE}
|
||||
ENV AS=/usr/bin/${CROSS_TRIPLE}-as \
|
||||
AR=/usr/bin/${CROSS_TRIPLE}-ar \
|
||||
CC=/usr/bin/${CROSS_TRIPLE}-gcc \
|
||||
CPP=/usr/bin/${CROSS_TRIPLE}-cpp \
|
||||
CXX=/usr/bin/${CROSS_TRIPLE}-g++ \
|
||||
LD=/usr/bin/${CROSS_TRIPLE}-ld
|
||||
|
||||
ENV DEFAULT_DOCKCROSS_IMAGE dockcross/linux-ppc64
|
||||
WORKDIR /work
|
||||
|
||||
# Note: Toolchain file support is currently in debian Experimental according to:
|
||||
# https://wiki.debian.org/CrossToolchains#In_jessie_.28Debian_8.29
|
||||
# We can switch to that when it becomes stable.
|
||||
COPY Toolchain-ppc64.cmake /usr/lib/${CROSS_TRIPLE}/Toolchain.cmake
|
||||
ENV CMAKE_TOOLCHAIN_FILE /usr/lib/${CROSS_TRIPLE}/Toolchain.cmake
|
||||
|
||||
# Build-time metadata as defined at http://label-schema.org
|
||||
ARG BUILD_DATE
|
||||
ARG IMAGE
|
||||
ARG VCS_REF
|
||||
ARG VCS_URL
|
||||
LABEL org.label-schema.build-date=$BUILD_DATE \
|
||||
org.label-schema.name=$IMAGE \
|
||||
org.label-schema.vcs-ref=$VCS_REF \
|
||||
org.label-schema.vcs-url=$VCS_URL \
|
||||
org.label-schema.schema-version="1.0"
|
9
docker/Makefile
Normal file
9
docker/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
centos5-image:
|
||||
docker build -f Dockerfile.centos5-linux-x86_64-pic -t xerial/centos5-linux-x86_64:latest
|
||||
# dockerhub login
|
||||
# docker login --username=xerial
|
||||
# docker push xerial/centos5-linux-x86_64:latest
|
||||
|
||||
multiarch-crossbuild-image:
|
||||
docker build https://github.com/iwasakims/crossbuild.git#fix-osxcross-cmake -t xerial/crossbuild:latest
|
15
docker/Toolchain-ppc64.cmake
Normal file
15
docker/Toolchain-ppc64.cmake
Normal file
@ -0,0 +1,15 @@
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSTEM_VERSION 1)
|
||||
set(CMAKE_SYSTEM_PROCESSOR ppc64)
|
||||
|
||||
set(cross_triple "ppc64-linux-gnu")
|
||||
|
||||
set(CMAKE_C_COMPILER /usr/bin/${cross_triple}-cc)
|
||||
set(CMAKE_CXX_COMPILER /usr/bin/${cross_triple}-c++)
|
||||
set(CMAKE_Fortran_COMPILER /usr/bin/${cross_triple}-gfortran)
|
||||
|
||||
# Discard path returned by pkg-config and associated with HINTS in module
|
||||
# like FindOpenSSL.
|
||||
set(CMAKE_IGNORE_PATH /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/lib/)
|
||||
|
||||
set(CMAKE_CROSSCOMPILING_EMULATOR /usr/bin/qemu-ppc64)
|
200
docker/dockcross-aarch64
Executable file
200
docker/dockcross-aarch64
Executable file
@ -0,0 +1,200 @@
|
||||
#!/bin/bash
|
||||
|
||||
DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-arm64-lts
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Helpers
|
||||
#
|
||||
err() {
|
||||
echo -e >&2 ERROR: $@\\n
|
||||
}
|
||||
|
||||
die() {
|
||||
err $@
|
||||
exit 1
|
||||
}
|
||||
|
||||
has() {
|
||||
# eg. has command update
|
||||
local kind=$1
|
||||
local name=$2
|
||||
|
||||
type -t $kind:$name | grep -q function
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Command handlers
|
||||
#
|
||||
command:update-image() {
|
||||
docker pull $FINAL_IMAGE
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Pull the latest $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update-script() {
|
||||
if cmp -s <( docker run $FINAL_IMAGE ) $0; then
|
||||
echo $0 is up to date
|
||||
else
|
||||
echo -n Updating $0 '... '
|
||||
docker run $FINAL_IMAGE > $0 && echo ok
|
||||
fi
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Update $0 from $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update() {
|
||||
command:update-image
|
||||
command:update-script
|
||||
}
|
||||
|
||||
help:update() {
|
||||
echo Pull the latest $FINAL_IMAGE, and then update $0 from that.
|
||||
}
|
||||
|
||||
command:help() {
|
||||
if [[ $# != 0 ]]; then
|
||||
if ! has command $1; then
|
||||
err \"$1\" is not an dockcross command
|
||||
command:help
|
||||
elif ! has help $1; then
|
||||
err No help found for \"$1\"
|
||||
else
|
||||
help:$1
|
||||
fi
|
||||
else
|
||||
cat >&2 <<ENDHELP
|
||||
Usage: dockcross [options] [--] command [args]
|
||||
|
||||
By default, run the given *command* in an dockcross Docker container.
|
||||
|
||||
The *options* can be one of:
|
||||
|
||||
--args|-a Extra args to the *docker run* command
|
||||
--image|-i Docker cross-compiler image to use
|
||||
--config|-c Bash script to source before running this script
|
||||
|
||||
|
||||
Additionally, there are special update commands:
|
||||
|
||||
update-image
|
||||
update-script
|
||||
update
|
||||
|
||||
For update command help use: $0 help <command>
|
||||
ENDHELP
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Option processing
|
||||
#
|
||||
special_update_command=''
|
||||
while [[ $# != 0 ]]; do
|
||||
case $1 in
|
||||
|
||||
--)
|
||||
break
|
||||
;;
|
||||
|
||||
--args|-a)
|
||||
ARG_ARGS="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--config|-c)
|
||||
ARG_CONFIG="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--image|-i)
|
||||
ARG_IMAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
update|update-image|update-script)
|
||||
special_update_command=$1
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
err Unknown option \"$1\"
|
||||
command:help
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# The precedence for options is:
|
||||
# 1. command-line arguments
|
||||
# 2. environment variables
|
||||
# 3. defaults
|
||||
|
||||
# Source the config file if it exists
|
||||
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
|
||||
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
|
||||
|
||||
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
|
||||
|
||||
# Set the docker image
|
||||
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
|
||||
|
||||
# Handle special update command
|
||||
if [ "$special_update_command" != "" ]; then
|
||||
case $special_update_command in
|
||||
|
||||
update)
|
||||
command:update
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-image)
|
||||
command:update-image
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-script)
|
||||
command:update-script
|
||||
exit $?
|
||||
;;
|
||||
|
||||
esac
|
||||
fi
|
||||
|
||||
# Set the docker run extra args (if any)
|
||||
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
|
||||
|
||||
# If we are not running via boot2docker
|
||||
if [ -z $DOCKER_HOST ]; then
|
||||
USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )"
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Now, finally, run the command in a container
|
||||
#
|
||||
docker run --rm \
|
||||
-v $PWD:/work \
|
||||
$USER_IDS \
|
||||
$FINAL_ARGS \
|
||||
$FINAL_IMAGE "$@"
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# This image is not intended to be run manually.
|
||||
#
|
||||
# To create a dockcross helper script for the
|
||||
# dockcross/linux-armv7 image, run:
|
||||
#
|
||||
# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7
|
||||
# chmod +x dockcross-linux-armv7
|
||||
#
|
||||
# You may then wish to move the dockcross script to your PATH.
|
||||
#
|
||||
################################################################################
|
279
docker/dockcross-android-arm
Executable file
279
docker/dockcross-android-arm
Executable file
@ -0,0 +1,279 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DEFAULT_DOCKCROSS_IMAGE=dockcross/android-arm:20230116-670f7f7
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Helpers
|
||||
#
|
||||
err() {
|
||||
echo -e >&2 "ERROR: $*\n"
|
||||
}
|
||||
|
||||
die() {
|
||||
err "$*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
has() {
|
||||
# eg. has command update
|
||||
local kind=$1
|
||||
local name=$2
|
||||
|
||||
type -t $kind:$name | grep -q function
|
||||
}
|
||||
|
||||
# If OCI_EXE is not already set, search for a container executor (OCI stands for "Open Container Initiative")
|
||||
if [ -z "$OCI_EXE" ]; then
|
||||
if which podman >/dev/null 2>/dev/null; then
|
||||
OCI_EXE=podman
|
||||
elif which docker >/dev/null 2>/dev/null; then
|
||||
OCI_EXE=docker
|
||||
else
|
||||
die "Cannot find a container executor. Search for docker and podman."
|
||||
fi
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Command handlers
|
||||
#
|
||||
command:update-image() {
|
||||
$OCI_EXE pull $FINAL_IMAGE
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo "Pull the latest $FINAL_IMAGE ."
|
||||
}
|
||||
|
||||
command:update-script() {
|
||||
if cmp -s <( $OCI_EXE run --rm $FINAL_IMAGE ) $0; then
|
||||
echo "$0 is up to date"
|
||||
else
|
||||
echo -n "Updating $0 ... "
|
||||
$OCI_EXE run --rm $FINAL_IMAGE > $0 && echo ok
|
||||
fi
|
||||
}
|
||||
|
||||
help:update-script() {
|
||||
echo "Update $0 from $FINAL_IMAGE ."
|
||||
}
|
||||
|
||||
command:update() {
|
||||
command:update-image
|
||||
command:update-script
|
||||
}
|
||||
|
||||
help:update() {
|
||||
echo "Pull the latest $FINAL_IMAGE, and then update $0 from that."
|
||||
}
|
||||
|
||||
command:help() {
|
||||
if [[ $# != 0 ]]; then
|
||||
if ! has command $1; then
|
||||
err \"$1\" is not an dockcross command
|
||||
command:help
|
||||
elif ! has help $1; then
|
||||
err No help found for \"$1\"
|
||||
else
|
||||
help:$1
|
||||
fi
|
||||
else
|
||||
cat >&2 <<ENDHELP
|
||||
Usage: dockcross [options] [--] command [args]
|
||||
|
||||
By default, run the given *command* in an dockcross Docker container.
|
||||
|
||||
The *options* can be one of:
|
||||
|
||||
--args|-a Extra args to the *docker run* command
|
||||
--image|-i Docker cross-compiler image to use
|
||||
--config|-c Bash script to source before running this script
|
||||
|
||||
|
||||
Additionally, there are special update commands:
|
||||
|
||||
update-image
|
||||
update-script
|
||||
update
|
||||
|
||||
For update command help use: $0 help <command>
|
||||
ENDHELP
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Option processing
|
||||
#
|
||||
special_update_command=''
|
||||
while [[ $# != 0 ]]; do
|
||||
case $1 in
|
||||
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
|
||||
--args|-a)
|
||||
ARG_ARGS="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--config|-c)
|
||||
ARG_CONFIG="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--image|-i)
|
||||
ARG_IMAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
update|update-image|update-script)
|
||||
special_update_command=$1
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
err Unknown option \"$1\"
|
||||
command:help
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# The precedence for options is:
|
||||
# 1. command-line arguments
|
||||
# 2. environment variables
|
||||
# 3. defaults
|
||||
|
||||
# Source the config file if it exists
|
||||
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
|
||||
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
|
||||
|
||||
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
|
||||
|
||||
# Set the docker image
|
||||
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
|
||||
|
||||
# Handle special update command
|
||||
if [ "$special_update_command" != "" ]; then
|
||||
case $special_update_command in
|
||||
|
||||
update)
|
||||
command:update
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-image)
|
||||
command:update-image
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-script)
|
||||
command:update-script
|
||||
exit $?
|
||||
;;
|
||||
|
||||
esac
|
||||
fi
|
||||
|
||||
# Set the docker run extra args (if any)
|
||||
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
|
||||
|
||||
# Bash on Ubuntu on Windows
|
||||
UBUNTU_ON_WINDOWS=$([ -e /proc/version ] && grep -l Microsoft /proc/version || echo "")
|
||||
# MSYS, Git Bash, etc.
|
||||
MSYS=$([ -e /proc/version ] && grep -l MINGW /proc/version || echo "")
|
||||
# CYGWIN
|
||||
CYGWIN=$([ -e /proc/version ] && grep -l CYGWIN /proc/version || echo "")
|
||||
|
||||
if [ -z "$UBUNTU_ON_WINDOWS" -a -z "$MSYS" -a "$OCI_EXE" != "podman" ]; then
|
||||
USER_IDS=(-e BUILDER_UID="$( id -u )" -e BUILDER_GID="$( id -g )" -e BUILDER_USER="$( id -un )" -e BUILDER_GROUP="$( id -gn )")
|
||||
fi
|
||||
|
||||
# Change the PWD when working in Docker on Windows
|
||||
if [ -n "$UBUNTU_ON_WINDOWS" ]; then
|
||||
WSL_ROOT="/mnt/"
|
||||
CFG_FILE=/etc/wsl.conf
|
||||
if [ -f "$CFG_FILE" ]; then
|
||||
CFG_CONTENT=$(cat $CFG_FILE | sed -r '/[^=]+=[^=]+/!d' | sed -r 's/\s+=\s/=/g')
|
||||
eval "$CFG_CONTENT"
|
||||
if [ -n "$root" ]; then
|
||||
WSL_ROOT=$root
|
||||
fi
|
||||
fi
|
||||
HOST_PWD=`pwd -P`
|
||||
HOST_PWD=${HOST_PWD/$WSL_ROOT//}
|
||||
elif [ -n "$MSYS" ]; then
|
||||
HOST_PWD=$PWD
|
||||
HOST_PWD=${HOST_PWD/\//}
|
||||
HOST_PWD=${HOST_PWD/\//:\/}
|
||||
elif [ -n "$CYGWIN" ]; then
|
||||
for f in pwd readlink cygpath ; do
|
||||
test -n "$(type "${f}" )" || { echo >&2 "Missing functionality (${f}) (in cygwin)." ; exit 1 ; } ;
|
||||
done ;
|
||||
HOST_PWD="$( cygpath -w "$( readlink -f "$( pwd ;)" ; )" ; )" ;
|
||||
else
|
||||
HOST_PWD=$PWD
|
||||
[ -L $HOST_PWD ] && HOST_PWD=$(readlink $HOST_PWD)
|
||||
fi
|
||||
|
||||
# Mount Additional Volumes
|
||||
if [ -z "$SSH_DIR" ]; then
|
||||
SSH_DIR="$HOME/.ssh"
|
||||
fi
|
||||
|
||||
HOST_VOLUMES=
|
||||
if [ -e "$SSH_DIR" -a -z "$MSYS" ]; then
|
||||
if test -n "${CYGWIN}" ; then
|
||||
HOST_VOLUMES+="-v $(cygpath -w ${SSH_DIR} ; ):/home/$(id -un)/.ssh" ;
|
||||
else
|
||||
HOST_VOLUMES+="-v $SSH_DIR:/home/$(id -un)/.ssh" ;
|
||||
fi ;
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Now, finally, run the command in a container
|
||||
#
|
||||
TTY_ARGS=
|
||||
tty -s && [ -z "$MSYS" ] && TTY_ARGS=-ti
|
||||
CONTAINER_NAME=dockcross_$RANDOM
|
||||
$OCI_EXE run $TTY_ARGS --name $CONTAINER_NAME \
|
||||
--platform linux/amd64 \
|
||||
-v "$HOST_PWD":/work \
|
||||
$HOST_VOLUMES \
|
||||
"${USER_IDS[@]}" \
|
||||
$FINAL_ARGS \
|
||||
$FINAL_IMAGE "$@"
|
||||
run_exit_code=$?
|
||||
|
||||
# Attempt to delete container
|
||||
rm_output=$($OCI_EXE rm -f $CONTAINER_NAME 2>&1)
|
||||
rm_exit_code=$?
|
||||
if [[ $rm_exit_code != 0 ]]; then
|
||||
if [[ "$CIRCLECI" == "true" ]] && [[ $rm_output == *"Driver btrfs failed to remove"* ]]; then
|
||||
: # Ignore error because of https://circleci.com/docs/docker-btrfs-error/
|
||||
else
|
||||
echo "$rm_output"
|
||||
exit $rm_exit_code
|
||||
fi
|
||||
fi
|
||||
|
||||
exit $run_exit_code
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# This image is not intended to be run manually.
|
||||
#
|
||||
# To create a dockcross helper script for the
|
||||
# dockcross/android-arm:20230116-670f7f7 image, run:
|
||||
#
|
||||
# docker run --rm dockcross/android-arm:20230116-670f7f7 > dockcross-android-arm-20230116-670f7f7
|
||||
# chmod +x dockcross-android-arm-20230116-670f7f7
|
||||
#
|
||||
# You may then wish to move the dockcross script to your PATH.
|
||||
#
|
||||
################################################################################
|
278
docker/dockcross-android-arm64
Executable file
278
docker/dockcross-android-arm64
Executable file
@ -0,0 +1,278 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DEFAULT_DOCKCROSS_IMAGE=dockcross/android-arm64:20230421-a0eaff4
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Helpers
|
||||
#
|
||||
err() {
|
||||
echo -e >&2 "ERROR: $*\n"
|
||||
}
|
||||
|
||||
die() {
|
||||
err "$*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
has() {
|
||||
# eg. has command update
|
||||
local kind=$1
|
||||
local name=$2
|
||||
|
||||
type -t $kind:$name | grep -q function
|
||||
}
|
||||
|
||||
# If OCI_EXE is not already set, search for a container executor (OCI stands for "Open Container Initiative")
|
||||
if [ -z "$OCI_EXE" ]; then
|
||||
if which podman >/dev/null 2>/dev/null; then
|
||||
OCI_EXE=podman
|
||||
elif which docker >/dev/null 2>/dev/null; then
|
||||
OCI_EXE=docker
|
||||
else
|
||||
die "Cannot find a container executor. Search for docker and podman."
|
||||
fi
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Command handlers
|
||||
#
|
||||
command:update-image() {
|
||||
$OCI_EXE pull $FINAL_IMAGE
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo "Pull the latest $FINAL_IMAGE ."
|
||||
}
|
||||
|
||||
command:update-script() {
|
||||
if cmp -s <( $OCI_EXE run --rm $FINAL_IMAGE ) $0; then
|
||||
echo "$0 is up to date"
|
||||
else
|
||||
echo -n "Updating $0 ... "
|
||||
$OCI_EXE run --rm $FINAL_IMAGE > $0 && echo ok
|
||||
fi
|
||||
}
|
||||
|
||||
help:update-script() {
|
||||
echo "Update $0 from $FINAL_IMAGE ."
|
||||
}
|
||||
|
||||
command:update() {
|
||||
command:update-image
|
||||
command:update-script
|
||||
}
|
||||
|
||||
help:update() {
|
||||
echo "Pull the latest $FINAL_IMAGE, and then update $0 from that."
|
||||
}
|
||||
|
||||
command:help() {
|
||||
if [[ $# != 0 ]]; then
|
||||
if ! has command $1; then
|
||||
err \"$1\" is not an dockcross command
|
||||
command:help
|
||||
elif ! has help $1; then
|
||||
err No help found for \"$1\"
|
||||
else
|
||||
help:$1
|
||||
fi
|
||||
else
|
||||
cat >&2 <<ENDHELP
|
||||
Usage: dockcross [options] [--] command [args]
|
||||
|
||||
By default, run the given *command* in an dockcross Docker container.
|
||||
|
||||
The *options* can be one of:
|
||||
|
||||
--args|-a Extra args to the *docker run* command
|
||||
--image|-i Docker cross-compiler image to use
|
||||
--config|-c Bash script to source before running this script
|
||||
|
||||
|
||||
Additionally, there are special update commands:
|
||||
|
||||
update-image
|
||||
update-script
|
||||
update
|
||||
|
||||
For update command help use: $0 help <command>
|
||||
ENDHELP
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Option processing
|
||||
#
|
||||
special_update_command=''
|
||||
while [[ $# != 0 ]]; do
|
||||
case $1 in
|
||||
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
|
||||
--args|-a)
|
||||
ARG_ARGS="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--config|-c)
|
||||
ARG_CONFIG="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--image|-i)
|
||||
ARG_IMAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
update|update-image|update-script)
|
||||
special_update_command=$1
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
err Unknown option \"$1\"
|
||||
command:help
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# The precedence for options is:
|
||||
# 1. command-line arguments
|
||||
# 2. environment variables
|
||||
# 3. defaults
|
||||
|
||||
# Source the config file if it exists
|
||||
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
|
||||
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
|
||||
|
||||
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
|
||||
|
||||
# Set the docker image
|
||||
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
|
||||
|
||||
# Handle special update command
|
||||
if [ "$special_update_command" != "" ]; then
|
||||
case $special_update_command in
|
||||
|
||||
update)
|
||||
command:update
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-image)
|
||||
command:update-image
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-script)
|
||||
command:update-script
|
||||
exit $?
|
||||
;;
|
||||
|
||||
esac
|
||||
fi
|
||||
|
||||
# Set the docker run extra args (if any)
|
||||
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
|
||||
|
||||
# Bash on Ubuntu on Windows
|
||||
UBUNTU_ON_WINDOWS=$([ -e /proc/version ] && grep -l Microsoft /proc/version || echo "")
|
||||
# MSYS, Git Bash, etc.
|
||||
MSYS=$([ -e /proc/version ] && grep -l MINGW /proc/version || echo "")
|
||||
# CYGWIN
|
||||
CYGWIN=$([ -e /proc/version ] && grep -l CYGWIN /proc/version || echo "")
|
||||
|
||||
if [ -z "$UBUNTU_ON_WINDOWS" -a -z "$MSYS" -a "$OCI_EXE" != "podman" ]; then
|
||||
USER_IDS=(-e BUILDER_UID="$( id -u )" -e BUILDER_GID="$( id -g )" -e BUILDER_USER="$( id -un )" -e BUILDER_GROUP="$( id -gn )")
|
||||
fi
|
||||
|
||||
# Change the PWD when working in Docker on Windows
|
||||
if [ -n "$UBUNTU_ON_WINDOWS" ]; then
|
||||
WSL_ROOT="/mnt/"
|
||||
CFG_FILE=/etc/wsl.conf
|
||||
if [ -f "$CFG_FILE" ]; then
|
||||
CFG_CONTENT=$(cat $CFG_FILE | sed -r '/[^=]+=[^=]+/!d' | sed -r 's/\s+=\s/=/g')
|
||||
eval "$CFG_CONTENT"
|
||||
if [ -n "$root" ]; then
|
||||
WSL_ROOT=$root
|
||||
fi
|
||||
fi
|
||||
HOST_PWD=`pwd -P`
|
||||
HOST_PWD=${HOST_PWD/$WSL_ROOT//}
|
||||
elif [ -n "$MSYS" ]; then
|
||||
HOST_PWD=$PWD
|
||||
HOST_PWD=${HOST_PWD/\//}
|
||||
HOST_PWD=${HOST_PWD/\//:\/}
|
||||
elif [ -n "$CYGWIN" ]; then
|
||||
for f in pwd readlink cygpath ; do
|
||||
test -n "$(type "${f}" )" || { echo >&2 "Missing functionality (${f}) (in cygwin)." ; exit 1 ; } ;
|
||||
done ;
|
||||
HOST_PWD="$( cygpath -w "$( readlink -f "$( pwd ;)" ; )" ; )" ;
|
||||
else
|
||||
HOST_PWD=$PWD
|
||||
[ -L $HOST_PWD ] && HOST_PWD=$(readlink $HOST_PWD)
|
||||
fi
|
||||
|
||||
# Mount Additional Volumes
|
||||
if [ -z "$SSH_DIR" ]; then
|
||||
SSH_DIR="$HOME/.ssh"
|
||||
fi
|
||||
|
||||
HOST_VOLUMES=
|
||||
if [ -e "$SSH_DIR" -a -z "$MSYS" ]; then
|
||||
if test -n "${CYGWIN}" ; then
|
||||
HOST_VOLUMES+="-v $(cygpath -w ${SSH_DIR} ; ):/home/$(id -un)/.ssh" ;
|
||||
else
|
||||
HOST_VOLUMES+="-v $SSH_DIR:/home/$(id -un)/.ssh" ;
|
||||
fi ;
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Now, finally, run the command in a container
|
||||
#
|
||||
TTY_ARGS=
|
||||
tty -s && [ -z "$MSYS" ] && TTY_ARGS=-ti
|
||||
CONTAINER_NAME=dockcross_$RANDOM
|
||||
$OCI_EXE run $TTY_ARGS --name $CONTAINER_NAME \
|
||||
-v "$HOST_PWD":/work \
|
||||
$HOST_VOLUMES \
|
||||
"${USER_IDS[@]}" \
|
||||
$FINAL_ARGS \
|
||||
$FINAL_IMAGE "$@"
|
||||
run_exit_code=$?
|
||||
|
||||
# Attempt to delete container
|
||||
rm_output=$($OCI_EXE rm -f $CONTAINER_NAME 2>&1)
|
||||
rm_exit_code=$?
|
||||
if [[ $rm_exit_code != 0 ]]; then
|
||||
if [[ "$CIRCLECI" == "true" ]] && [[ $rm_output == *"Driver btrfs failed to remove"* ]]; then
|
||||
: # Ignore error because of https://circleci.com/docs/docker-btrfs-error/
|
||||
else
|
||||
echo "$rm_output"
|
||||
exit $rm_exit_code
|
||||
fi
|
||||
fi
|
||||
|
||||
exit $run_exit_code
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# This image is not intended to be run manually.
|
||||
#
|
||||
# To create a dockcross helper script for the
|
||||
# dockcross/android-arm64:20230421-a0eaff4 image, run:
|
||||
#
|
||||
# docker run --rm dockcross/android-arm64:20230421-a0eaff4 > dockcross-android-arm64-20230421-a0eaff4
|
||||
# chmod +x dockcross-android-arm64-20230421-a0eaff4
|
||||
#
|
||||
# You may then wish to move the dockcross script to your PATH.
|
||||
#
|
||||
################################################################################
|
242
docker/dockcross-arm64
Executable file
242
docker/dockcross-arm64
Executable file
@ -0,0 +1,242 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-arm64-lts
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Helpers
|
||||
#
|
||||
err() {
|
||||
echo -e >&2 ERROR: $@\\n
|
||||
}
|
||||
|
||||
die() {
|
||||
err $@
|
||||
exit 1
|
||||
}
|
||||
|
||||
has() {
|
||||
# eg. has command update
|
||||
local kind=$1
|
||||
local name=$2
|
||||
|
||||
type -t $kind:$name | grep -q function
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Command handlers
|
||||
#
|
||||
command:update-image() {
|
||||
docker pull $FINAL_IMAGE
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Pull the latest $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update-script() {
|
||||
if cmp -s <( docker run --rm $FINAL_IMAGE ) $0; then
|
||||
echo $0 is up to date
|
||||
else
|
||||
echo -n Updating $0 '... '
|
||||
docker run --rm $FINAL_IMAGE > $0 && echo ok
|
||||
fi
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Update $0 from $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update() {
|
||||
command:update-image
|
||||
command:update-script
|
||||
}
|
||||
|
||||
help:update() {
|
||||
echo Pull the latest $FINAL_IMAGE, and then update $0 from that.
|
||||
}
|
||||
|
||||
command:help() {
|
||||
if [[ $# != 0 ]]; then
|
||||
if ! has command $1; then
|
||||
err \"$1\" is not an dockcross command
|
||||
command:help
|
||||
elif ! has help $1; then
|
||||
err No help found for \"$1\"
|
||||
else
|
||||
help:$1
|
||||
fi
|
||||
else
|
||||
cat >&2 <<ENDHELP
|
||||
Usage: dockcross [options] [--] command [args]
|
||||
|
||||
By default, run the given *command* in an dockcross Docker container.
|
||||
|
||||
The *options* can be one of:
|
||||
|
||||
--args|-a Extra args to the *docker run* command
|
||||
--image|-i Docker cross-compiler image to use
|
||||
--config|-c Bash script to source before running this script
|
||||
|
||||
|
||||
Additionally, there are special update commands:
|
||||
|
||||
update-image
|
||||
update-script
|
||||
update
|
||||
|
||||
For update command help use: $0 help <command>
|
||||
ENDHELP
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Option processing
|
||||
#
|
||||
special_update_command=''
|
||||
while [[ $# != 0 ]]; do
|
||||
case $1 in
|
||||
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
|
||||
--args|-a)
|
||||
ARG_ARGS="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--config|-c)
|
||||
ARG_CONFIG="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--image|-i)
|
||||
ARG_IMAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
update|update-image|update-script)
|
||||
special_update_command=$1
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
err Unknown option \"$1\"
|
||||
command:help
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# The precedence for options is:
|
||||
# 1. command-line arguments
|
||||
# 2. environment variables
|
||||
# 3. defaults
|
||||
|
||||
# Source the config file if it exists
|
||||
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
|
||||
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
|
||||
|
||||
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
|
||||
|
||||
# Set the docker image
|
||||
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
|
||||
|
||||
# Handle special update command
|
||||
if [ "$special_update_command" != "" ]; then
|
||||
case $special_update_command in
|
||||
|
||||
update)
|
||||
command:update
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-image)
|
||||
command:update-image
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-script)
|
||||
command:update-script
|
||||
exit $?
|
||||
;;
|
||||
|
||||
esac
|
||||
fi
|
||||
|
||||
# Set the docker run extra args (if any)
|
||||
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
|
||||
|
||||
# Bash on Ubuntu on Windows
|
||||
UBUNTU_ON_WINDOWS=$([ -e /proc/version ] && grep -l Microsoft /proc/version || echo "")
|
||||
# MSYS, Git Bash, etc.
|
||||
MSYS=$([ -e /proc/version ] && grep -l MINGW /proc/version || echo "")
|
||||
|
||||
if [ -z "$UBUNTU_ON_WINDOWS" -a -z "$MSYS" ]; then
|
||||
USER_IDS=(-e BUILDER_UID="$( id -u )" -e BUILDER_GID="$( id -g )" -e BUILDER_USER="$( id -un )" -e BUILDER_GROUP="$( id -gn )")
|
||||
fi
|
||||
|
||||
# Change the PWD when working in Docker on Windows
|
||||
if [ -n "$UBUNTU_ON_WINDOWS" ]; then
|
||||
WSL_ROOT="/mnt/"
|
||||
CFG_FILE=/etc/wsl.conf
|
||||
if [ -f "$CFG_FILE" ]; then
|
||||
CFG_CONTENT=$(cat $CFG_FILE | sed -r '/[^=]+=[^=]+/!d' | sed -r 's/\s+=\s/=/g')
|
||||
eval "$CFG_CONTENT"
|
||||
if [ -n "$root" ]; then
|
||||
WSL_ROOT=$root
|
||||
fi
|
||||
fi
|
||||
HOST_PWD=`pwd -P`
|
||||
HOST_PWD=${HOST_PWD/$WSL_ROOT//}
|
||||
elif [ -n "$MSYS" ]; then
|
||||
HOST_PWD=$PWD
|
||||
HOST_PWD=${HOST_PWD/\//}
|
||||
HOST_PWD=${HOST_PWD/\//:\/}
|
||||
else
|
||||
HOST_PWD=$PWD
|
||||
fi
|
||||
|
||||
# Mount Additional Volumes
|
||||
if [ -z "$SSH_DIR" ]; then
|
||||
SSH_DIR="$HOME/.ssh"
|
||||
fi
|
||||
|
||||
HOST_VOLUMES=
|
||||
if [ -e "$SSH_DIR" ]; then
|
||||
HOST_VOLUMES+="-v $SSH_DIR:/home/$(id -un)/.ssh"
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Now, finally, run the command in a container
|
||||
#
|
||||
tty -s && TTY_ARGS=-ti || TTY_ARGS=
|
||||
CONTAINER_NAME=dockcross_$RANDOM
|
||||
docker run $TTY_ARGS --name $CONTAINER_NAME \
|
||||
-v "$HOST_PWD":/work \
|
||||
$HOST_VOLUMES \
|
||||
"${USER_IDS[@]}" \
|
||||
$FINAL_ARGS \
|
||||
$FINAL_IMAGE "$@"
|
||||
run_exit_code=$?
|
||||
|
||||
exit $run_exit_code
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# This image is not intended to be run manually.
|
||||
#
|
||||
# To create a dockcross helper script for the
|
||||
# dockcross/linux-arm64 image, run:
|
||||
#
|
||||
# docker run --rm dockcross/linux-arm64 > dockcross-linux-arm64
|
||||
# chmod +x dockcross-linux-arm64
|
||||
#
|
||||
# You may then wish to move the dockcross script to your PATH.
|
||||
#
|
||||
################################################################################
|
200
docker/dockcross-armv5
Executable file
200
docker/dockcross-armv5
Executable file
@ -0,0 +1,200 @@
|
||||
#!/bin/bash
|
||||
|
||||
DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-armv5
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Helpers
|
||||
#
|
||||
err() {
|
||||
echo -e >&2 ERROR: $@\\n
|
||||
}
|
||||
|
||||
die() {
|
||||
err $@
|
||||
exit 1
|
||||
}
|
||||
|
||||
has() {
|
||||
# eg. has command update
|
||||
local kind=$1
|
||||
local name=$2
|
||||
|
||||
type -t $kind:$name | grep -q function
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Command handlers
|
||||
#
|
||||
command:update-image() {
|
||||
docker pull $FINAL_IMAGE
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Pull the latest $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update-script() {
|
||||
if cmp -s <( docker run $FINAL_IMAGE ) $0; then
|
||||
echo $0 is up to date
|
||||
else
|
||||
echo -n Updating $0 '... '
|
||||
docker run $FINAL_IMAGE > $0 && echo ok
|
||||
fi
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Update $0 from $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update() {
|
||||
command:update-image
|
||||
command:update-script
|
||||
}
|
||||
|
||||
help:update() {
|
||||
echo Pull the latest $FINAL_IMAGE, and then update $0 from that.
|
||||
}
|
||||
|
||||
command:help() {
|
||||
if [[ $# != 0 ]]; then
|
||||
if ! has command $1; then
|
||||
err \"$1\" is not an dockcross command
|
||||
command:help
|
||||
elif ! has help $1; then
|
||||
err No help found for \"$1\"
|
||||
else
|
||||
help:$1
|
||||
fi
|
||||
else
|
||||
cat >&2 <<ENDHELP
|
||||
Usage: dockcross [options] [--] command [args]
|
||||
|
||||
By default, run the given *command* in an dockcross Docker container.
|
||||
|
||||
The *options* can be one of:
|
||||
|
||||
--args|-a Extra args to the *docker run* command
|
||||
--image|-i Docker cross-compiler image to use
|
||||
--config|-c Bash script to source before running this script
|
||||
|
||||
|
||||
Additionally, there are special update commands:
|
||||
|
||||
update-image
|
||||
update-script
|
||||
update
|
||||
|
||||
For update command help use: $0 help <command>
|
||||
ENDHELP
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Option processing
|
||||
#
|
||||
special_update_command=''
|
||||
while [[ $# != 0 ]]; do
|
||||
case $1 in
|
||||
|
||||
--)
|
||||
break
|
||||
;;
|
||||
|
||||
--args|-a)
|
||||
ARG_ARGS="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--config|-c)
|
||||
ARG_CONFIG="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--image|-i)
|
||||
ARG_IMAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
update|update-image|update-script)
|
||||
special_update_command=$1
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
err Unknown option \"$1\"
|
||||
command:help
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# The precedence for options is:
|
||||
# 1. command-line arguments
|
||||
# 2. environment variables
|
||||
# 3. defaults
|
||||
|
||||
# Source the config file if it exists
|
||||
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
|
||||
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
|
||||
|
||||
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
|
||||
|
||||
# Set the docker image
|
||||
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
|
||||
|
||||
# Handle special update command
|
||||
if [ "$special_update_command" != "" ]; then
|
||||
case $special_update_command in
|
||||
|
||||
update)
|
||||
command:update
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-image)
|
||||
command:update-image
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-script)
|
||||
command:update-script
|
||||
exit $?
|
||||
;;
|
||||
|
||||
esac
|
||||
fi
|
||||
|
||||
# Set the docker run extra args (if any)
|
||||
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
|
||||
|
||||
# If we are not running via boot2docker
|
||||
if [ -z $DOCKER_HOST ]; then
|
||||
USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )"
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Now, finally, run the command in a container
|
||||
#
|
||||
docker run --rm \
|
||||
-v $PWD:/work \
|
||||
$USER_IDS \
|
||||
$FINAL_ARGS \
|
||||
$FINAL_IMAGE "$@"
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# This image is not intended to be run manually.
|
||||
#
|
||||
# To create a dockcross helper script for the
|
||||
# dockcross/linux-armv7 image, run:
|
||||
#
|
||||
# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7
|
||||
# chmod +x dockcross-linux-armv7
|
||||
#
|
||||
# You may then wish to move the dockcross script to your PATH.
|
||||
#
|
||||
################################################################################
|
200
docker/dockcross-armv6
Executable file
200
docker/dockcross-armv6
Executable file
@ -0,0 +1,200 @@
|
||||
#!/bin/bash
|
||||
|
||||
DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-armv6-lts
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Helpers
|
||||
#
|
||||
err() {
|
||||
echo -e >&2 ERROR: $@\\n
|
||||
}
|
||||
|
||||
die() {
|
||||
err $@
|
||||
exit 1
|
||||
}
|
||||
|
||||
has() {
|
||||
# eg. has command update
|
||||
local kind=$1
|
||||
local name=$2
|
||||
|
||||
type -t $kind:$name | grep -q function
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Command handlers
|
||||
#
|
||||
command:update-image() {
|
||||
docker pull $FINAL_IMAGE
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Pull the latest $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update-script() {
|
||||
if cmp -s <( docker run $FINAL_IMAGE ) $0; then
|
||||
echo $0 is up to date
|
||||
else
|
||||
echo -n Updating $0 '... '
|
||||
docker run $FINAL_IMAGE > $0 && echo ok
|
||||
fi
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Update $0 from $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update() {
|
||||
command:update-image
|
||||
command:update-script
|
||||
}
|
||||
|
||||
help:update() {
|
||||
echo Pull the latest $FINAL_IMAGE, and then update $0 from that.
|
||||
}
|
||||
|
||||
command:help() {
|
||||
if [[ $# != 0 ]]; then
|
||||
if ! has command $1; then
|
||||
err \"$1\" is not an dockcross command
|
||||
command:help
|
||||
elif ! has help $1; then
|
||||
err No help found for \"$1\"
|
||||
else
|
||||
help:$1
|
||||
fi
|
||||
else
|
||||
cat >&2 <<ENDHELP
|
||||
Usage: dockcross [options] [--] command [args]
|
||||
|
||||
By default, run the given *command* in an dockcross Docker container.
|
||||
|
||||
The *options* can be one of:
|
||||
|
||||
--args|-a Extra args to the *docker run* command
|
||||
--image|-i Docker cross-compiler image to use
|
||||
--config|-c Bash script to source before running this script
|
||||
|
||||
|
||||
Additionally, there are special update commands:
|
||||
|
||||
update-image
|
||||
update-script
|
||||
update
|
||||
|
||||
For update command help use: $0 help <command>
|
||||
ENDHELP
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Option processing
|
||||
#
|
||||
special_update_command=''
|
||||
while [[ $# != 0 ]]; do
|
||||
case $1 in
|
||||
|
||||
--)
|
||||
break
|
||||
;;
|
||||
|
||||
--args|-a)
|
||||
ARG_ARGS="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--config|-c)
|
||||
ARG_CONFIG="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--image|-i)
|
||||
ARG_IMAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
update|update-image|update-script)
|
||||
special_update_command=$1
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
err Unknown option \"$1\"
|
||||
command:help
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# The precedence for options is:
|
||||
# 1. command-line arguments
|
||||
# 2. environment variables
|
||||
# 3. defaults
|
||||
|
||||
# Source the config file if it exists
|
||||
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
|
||||
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
|
||||
|
||||
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
|
||||
|
||||
# Set the docker image
|
||||
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
|
||||
|
||||
# Handle special update command
|
||||
if [ "$special_update_command" != "" ]; then
|
||||
case $special_update_command in
|
||||
|
||||
update)
|
||||
command:update
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-image)
|
||||
command:update-image
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-script)
|
||||
command:update-script
|
||||
exit $?
|
||||
;;
|
||||
|
||||
esac
|
||||
fi
|
||||
|
||||
# Set the docker run extra args (if any)
|
||||
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
|
||||
|
||||
# If we are not running via boot2docker
|
||||
if [ -z $DOCKER_HOST ]; then
|
||||
USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )"
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Now, finally, run the command in a container
|
||||
#
|
||||
docker run --rm \
|
||||
-v $PWD:/work \
|
||||
$USER_IDS \
|
||||
$FINAL_ARGS \
|
||||
$FINAL_IMAGE "$@"
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# This image is not intended to be run manually.
|
||||
#
|
||||
# To create a dockcross helper script for the
|
||||
# dockcross/linux-armv7 image, run:
|
||||
#
|
||||
# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7
|
||||
# chmod +x dockcross-linux-armv7
|
||||
#
|
||||
# You may then wish to move the dockcross script to your PATH.
|
||||
#
|
||||
################################################################################
|
278
docker/dockcross-armv7
Executable file
278
docker/dockcross-armv7
Executable file
@ -0,0 +1,278 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-armv7-lts:20230421-a0eaff4
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Helpers
|
||||
#
|
||||
err() {
|
||||
echo -e >&2 "ERROR: $*\n"
|
||||
}
|
||||
|
||||
die() {
|
||||
err "$*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
has() {
|
||||
# eg. has command update
|
||||
local kind=$1
|
||||
local name=$2
|
||||
|
||||
type -t $kind:$name | grep -q function
|
||||
}
|
||||
|
||||
# If OCI_EXE is not already set, search for a container executor (OCI stands for "Open Container Initiative")
|
||||
if [ -z "$OCI_EXE" ]; then
|
||||
if which podman >/dev/null 2>/dev/null; then
|
||||
OCI_EXE=podman
|
||||
elif which docker >/dev/null 2>/dev/null; then
|
||||
OCI_EXE=docker
|
||||
else
|
||||
die "Cannot find a container executor. Search for docker and podman."
|
||||
fi
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Command handlers
|
||||
#
|
||||
command:update-image() {
|
||||
$OCI_EXE pull $FINAL_IMAGE
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo "Pull the latest $FINAL_IMAGE ."
|
||||
}
|
||||
|
||||
command:update-script() {
|
||||
if cmp -s <( $OCI_EXE run --rm $FINAL_IMAGE ) $0; then
|
||||
echo "$0 is up to date"
|
||||
else
|
||||
echo -n "Updating $0 ... "
|
||||
$OCI_EXE run --rm $FINAL_IMAGE > $0 && echo ok
|
||||
fi
|
||||
}
|
||||
|
||||
help:update-script() {
|
||||
echo "Update $0 from $FINAL_IMAGE ."
|
||||
}
|
||||
|
||||
command:update() {
|
||||
command:update-image
|
||||
command:update-script
|
||||
}
|
||||
|
||||
help:update() {
|
||||
echo "Pull the latest $FINAL_IMAGE, and then update $0 from that."
|
||||
}
|
||||
|
||||
command:help() {
|
||||
if [[ $# != 0 ]]; then
|
||||
if ! has command $1; then
|
||||
err \"$1\" is not an dockcross command
|
||||
command:help
|
||||
elif ! has help $1; then
|
||||
err No help found for \"$1\"
|
||||
else
|
||||
help:$1
|
||||
fi
|
||||
else
|
||||
cat >&2 <<ENDHELP
|
||||
Usage: dockcross [options] [--] command [args]
|
||||
|
||||
By default, run the given *command* in an dockcross Docker container.
|
||||
|
||||
The *options* can be one of:
|
||||
|
||||
--args|-a Extra args to the *docker run* command
|
||||
--image|-i Docker cross-compiler image to use
|
||||
--config|-c Bash script to source before running this script
|
||||
|
||||
|
||||
Additionally, there are special update commands:
|
||||
|
||||
update-image
|
||||
update-script
|
||||
update
|
||||
|
||||
For update command help use: $0 help <command>
|
||||
ENDHELP
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Option processing
|
||||
#
|
||||
special_update_command=''
|
||||
while [[ $# != 0 ]]; do
|
||||
case $1 in
|
||||
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
|
||||
--args|-a)
|
||||
ARG_ARGS="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--config|-c)
|
||||
ARG_CONFIG="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--image|-i)
|
||||
ARG_IMAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
update|update-image|update-script)
|
||||
special_update_command=$1
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
err Unknown option \"$1\"
|
||||
command:help
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# The precedence for options is:
|
||||
# 1. command-line arguments
|
||||
# 2. environment variables
|
||||
# 3. defaults
|
||||
|
||||
# Source the config file if it exists
|
||||
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
|
||||
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
|
||||
|
||||
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
|
||||
|
||||
# Set the docker image
|
||||
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
|
||||
|
||||
# Handle special update command
|
||||
if [ "$special_update_command" != "" ]; then
|
||||
case $special_update_command in
|
||||
|
||||
update)
|
||||
command:update
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-image)
|
||||
command:update-image
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-script)
|
||||
command:update-script
|
||||
exit $?
|
||||
;;
|
||||
|
||||
esac
|
||||
fi
|
||||
|
||||
# Set the docker run extra args (if any)
|
||||
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
|
||||
|
||||
# Bash on Ubuntu on Windows
|
||||
UBUNTU_ON_WINDOWS=$([ -e /proc/version ] && grep -l Microsoft /proc/version || echo "")
|
||||
# MSYS, Git Bash, etc.
|
||||
MSYS=$([ -e /proc/version ] && grep -l MINGW /proc/version || echo "")
|
||||
# CYGWIN
|
||||
CYGWIN=$([ -e /proc/version ] && grep -l CYGWIN /proc/version || echo "")
|
||||
|
||||
if [ -z "$UBUNTU_ON_WINDOWS" -a -z "$MSYS" -a "$OCI_EXE" != "podman" ]; then
|
||||
USER_IDS=(-e BUILDER_UID="$( id -u )" -e BUILDER_GID="$( id -g )" -e BUILDER_USER="$( id -un )" -e BUILDER_GROUP="$( id -gn )")
|
||||
fi
|
||||
|
||||
# Change the PWD when working in Docker on Windows
|
||||
if [ -n "$UBUNTU_ON_WINDOWS" ]; then
|
||||
WSL_ROOT="/mnt/"
|
||||
CFG_FILE=/etc/wsl.conf
|
||||
if [ -f "$CFG_FILE" ]; then
|
||||
CFG_CONTENT=$(cat $CFG_FILE | sed -r '/[^=]+=[^=]+/!d' | sed -r 's/\s+=\s/=/g')
|
||||
eval "$CFG_CONTENT"
|
||||
if [ -n "$root" ]; then
|
||||
WSL_ROOT=$root
|
||||
fi
|
||||
fi
|
||||
HOST_PWD=`pwd -P`
|
||||
HOST_PWD=${HOST_PWD/$WSL_ROOT//}
|
||||
elif [ -n "$MSYS" ]; then
|
||||
HOST_PWD=$PWD
|
||||
HOST_PWD=${HOST_PWD/\//}
|
||||
HOST_PWD=${HOST_PWD/\//:\/}
|
||||
elif [ -n "$CYGWIN" ]; then
|
||||
for f in pwd readlink cygpath ; do
|
||||
test -n "$(type "${f}" )" || { echo >&2 "Missing functionality (${f}) (in cygwin)." ; exit 1 ; } ;
|
||||
done ;
|
||||
HOST_PWD="$( cygpath -w "$( readlink -f "$( pwd ;)" ; )" ; )" ;
|
||||
else
|
||||
HOST_PWD=$PWD
|
||||
[ -L $HOST_PWD ] && HOST_PWD=$(readlink $HOST_PWD)
|
||||
fi
|
||||
|
||||
# Mount Additional Volumes
|
||||
if [ -z "$SSH_DIR" ]; then
|
||||
SSH_DIR="$HOME/.ssh"
|
||||
fi
|
||||
|
||||
HOST_VOLUMES=
|
||||
if [ -e "$SSH_DIR" -a -z "$MSYS" ]; then
|
||||
if test -n "${CYGWIN}" ; then
|
||||
HOST_VOLUMES+="-v $(cygpath -w ${SSH_DIR} ; ):/home/$(id -un)/.ssh" ;
|
||||
else
|
||||
HOST_VOLUMES+="-v $SSH_DIR:/home/$(id -un)/.ssh" ;
|
||||
fi ;
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Now, finally, run the command in a container
|
||||
#
|
||||
TTY_ARGS=
|
||||
tty -s && [ -z "$MSYS" ] && TTY_ARGS=-ti
|
||||
CONTAINER_NAME=dockcross_$RANDOM
|
||||
$OCI_EXE run $TTY_ARGS --name $CONTAINER_NAME \
|
||||
-v "$HOST_PWD":/work \
|
||||
$HOST_VOLUMES \
|
||||
"${USER_IDS[@]}" \
|
||||
$FINAL_ARGS \
|
||||
$FINAL_IMAGE "$@"
|
||||
run_exit_code=$?
|
||||
|
||||
# Attempt to delete container
|
||||
rm_output=$($OCI_EXE rm -f $CONTAINER_NAME 2>&1)
|
||||
rm_exit_code=$?
|
||||
if [[ $rm_exit_code != 0 ]]; then
|
||||
if [[ "$CIRCLECI" == "true" ]] && [[ $rm_output == *"Driver btrfs failed to remove"* ]]; then
|
||||
: # Ignore error because of https://circleci.com/docs/docker-btrfs-error/
|
||||
else
|
||||
echo "$rm_output"
|
||||
exit $rm_exit_code
|
||||
fi
|
||||
fi
|
||||
|
||||
exit $run_exit_code
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# This image is not intended to be run manually.
|
||||
#
|
||||
# To create a dockcross helper script for the
|
||||
# dockcross/linux-armv7-lts:20230421-a0eaff4 image, run:
|
||||
#
|
||||
# docker run --rm dockcross/linux-armv7-lts:20230421-a0eaff4 > dockcross-linux-armv7-lts-20230421-a0eaff4
|
||||
# chmod +x dockcross-linux-armv7-lts-20230421-a0eaff4
|
||||
#
|
||||
# You may then wish to move the dockcross script to your PATH.
|
||||
#
|
||||
################################################################################
|
200
docker/dockcross-ppc64
Executable file
200
docker/dockcross-ppc64
Executable file
@ -0,0 +1,200 @@
|
||||
#!/bin/bash
|
||||
|
||||
DEFAULT_DOCKCROSS_IMAGE=xerial/linux-ppc64
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Helpers
|
||||
#
|
||||
err() {
|
||||
echo -e >&2 ERROR: $@\\n
|
||||
}
|
||||
|
||||
die() {
|
||||
err $@
|
||||
exit 1
|
||||
}
|
||||
|
||||
has() {
|
||||
# eg. has command update
|
||||
local kind=$1
|
||||
local name=$2
|
||||
|
||||
type -t $kind:$name | grep -q function
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Command handlers
|
||||
#
|
||||
command:update-image() {
|
||||
docker pull $FINAL_IMAGE
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Pull the latest $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update-script() {
|
||||
if cmp -s <( docker run $FINAL_IMAGE ) $0; then
|
||||
echo $0 is up to date
|
||||
else
|
||||
echo -n Updating $0 '... '
|
||||
docker run $FINAL_IMAGE > $0 && echo ok
|
||||
fi
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Update $0 from $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update() {
|
||||
command:update-image
|
||||
command:update-script
|
||||
}
|
||||
|
||||
help:update() {
|
||||
echo Pull the latest $FINAL_IMAGE, and then update $0 from that.
|
||||
}
|
||||
|
||||
command:help() {
|
||||
if [[ $# != 0 ]]; then
|
||||
if ! has command $1; then
|
||||
err \"$1\" is not an dockcross command
|
||||
command:help
|
||||
elif ! has help $1; then
|
||||
err No help found for \"$1\"
|
||||
else
|
||||
help:$1
|
||||
fi
|
||||
else
|
||||
cat >&2 <<ENDHELP
|
||||
Usage: dockcross [options] [--] command [args]
|
||||
|
||||
By default, run the given *command* in an dockcross Docker container.
|
||||
|
||||
The *options* can be one of:
|
||||
|
||||
--args|-a Extra args to the *docker run* command
|
||||
--image|-i Docker cross-compiler image to use
|
||||
--config|-c Bash script to source before running this script
|
||||
|
||||
|
||||
Additionally, there are special update commands:
|
||||
|
||||
update-image
|
||||
update-script
|
||||
update
|
||||
|
||||
For update command help use: $0 help <command>
|
||||
ENDHELP
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Option processing
|
||||
#
|
||||
special_update_command=''
|
||||
while [[ $# != 0 ]]; do
|
||||
case $1 in
|
||||
|
||||
--)
|
||||
break
|
||||
;;
|
||||
|
||||
--args|-a)
|
||||
ARG_ARGS="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--config|-c)
|
||||
ARG_CONFIG="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--image|-i)
|
||||
ARG_IMAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
update|update-image|update-script)
|
||||
special_update_command=$1
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
err Unknown option \"$1\"
|
||||
command:help
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# The precedence for options is:
|
||||
# 1. command-line arguments
|
||||
# 2. environment variables
|
||||
# 3. defaults
|
||||
|
||||
# Source the config file if it exists
|
||||
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
|
||||
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
|
||||
|
||||
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
|
||||
|
||||
# Set the docker image
|
||||
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
|
||||
|
||||
# Handle special update command
|
||||
if [ "$special_update_command" != "" ]; then
|
||||
case $special_update_command in
|
||||
|
||||
update)
|
||||
command:update
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-image)
|
||||
command:update-image
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-script)
|
||||
command:update-script
|
||||
exit $?
|
||||
;;
|
||||
|
||||
esac
|
||||
fi
|
||||
|
||||
# Set the docker run extra args (if any)
|
||||
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
|
||||
|
||||
# If we are not running via boot2docker
|
||||
if [ -z $DOCKER_HOST ]; then
|
||||
USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )"
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Now, finally, run the command in a container
|
||||
#
|
||||
docker run --rm \
|
||||
-v $PWD:/work \
|
||||
$USER_IDS \
|
||||
$FINAL_ARGS \
|
||||
$FINAL_IMAGE "$@"
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# This image is not intended to be run manually.
|
||||
#
|
||||
# To create a dockcross helper script for the
|
||||
# dockcross/linux-armv7 image, run:
|
||||
#
|
||||
# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7
|
||||
# chmod +x dockcross-linux-armv7
|
||||
#
|
||||
# You may then wish to move the dockcross script to your PATH.
|
||||
#
|
||||
################################################################################
|
200
docker/dockcross-ppc64le
Executable file
200
docker/dockcross-ppc64le
Executable file
@ -0,0 +1,200 @@
|
||||
#!/bin/bash
|
||||
|
||||
DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-ppc64le-lts
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Helpers
|
||||
#
|
||||
err() {
|
||||
echo -e >&2 ERROR: $@\\n
|
||||
}
|
||||
|
||||
die() {
|
||||
err $@
|
||||
exit 1
|
||||
}
|
||||
|
||||
has() {
|
||||
# eg. has command update
|
||||
local kind=$1
|
||||
local name=$2
|
||||
|
||||
type -t $kind:$name | grep -q function
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Command handlers
|
||||
#
|
||||
command:update-image() {
|
||||
docker pull $FINAL_IMAGE
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Pull the latest $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update-script() {
|
||||
if cmp -s <( docker run $FINAL_IMAGE ) $0; then
|
||||
echo $0 is up to date
|
||||
else
|
||||
echo -n Updating $0 '... '
|
||||
docker run $FINAL_IMAGE > $0 && echo ok
|
||||
fi
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Update $0 from $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update() {
|
||||
command:update-image
|
||||
command:update-script
|
||||
}
|
||||
|
||||
help:update() {
|
||||
echo Pull the latest $FINAL_IMAGE, and then update $0 from that.
|
||||
}
|
||||
|
||||
command:help() {
|
||||
if [[ $# != 0 ]]; then
|
||||
if ! has command $1; then
|
||||
err \"$1\" is not an dockcross command
|
||||
command:help
|
||||
elif ! has help $1; then
|
||||
err No help found for \"$1\"
|
||||
else
|
||||
help:$1
|
||||
fi
|
||||
else
|
||||
cat >&2 <<ENDHELP
|
||||
Usage: dockcross [options] [--] command [args]
|
||||
|
||||
By default, run the given *command* in an dockcross Docker container.
|
||||
|
||||
The *options* can be one of:
|
||||
|
||||
--args|-a Extra args to the *docker run* command
|
||||
--image|-i Docker cross-compiler image to use
|
||||
--config|-c Bash script to source before running this script
|
||||
|
||||
|
||||
Additionally, there are special update commands:
|
||||
|
||||
update-image
|
||||
update-script
|
||||
update
|
||||
|
||||
For update command help use: $0 help <command>
|
||||
ENDHELP
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Option processing
|
||||
#
|
||||
special_update_command=''
|
||||
while [[ $# != 0 ]]; do
|
||||
case $1 in
|
||||
|
||||
--)
|
||||
break
|
||||
;;
|
||||
|
||||
--args|-a)
|
||||
ARG_ARGS="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--config|-c)
|
||||
ARG_CONFIG="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--image|-i)
|
||||
ARG_IMAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
update|update-image|update-script)
|
||||
special_update_command=$1
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
err Unknown option \"$1\"
|
||||
command:help
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# The precedence for options is:
|
||||
# 1. command-line arguments
|
||||
# 2. environment variables
|
||||
# 3. defaults
|
||||
|
||||
# Source the config file if it exists
|
||||
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
|
||||
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
|
||||
|
||||
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
|
||||
|
||||
# Set the docker image
|
||||
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
|
||||
|
||||
# Handle special update command
|
||||
if [ "$special_update_command" != "" ]; then
|
||||
case $special_update_command in
|
||||
|
||||
update)
|
||||
command:update
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-image)
|
||||
command:update-image
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-script)
|
||||
command:update-script
|
||||
exit $?
|
||||
;;
|
||||
|
||||
esac
|
||||
fi
|
||||
|
||||
# Set the docker run extra args (if any)
|
||||
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
|
||||
|
||||
# If we are not running via boot2docker
|
||||
if [ -z $DOCKER_HOST ]; then
|
||||
USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )"
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Now, finally, run the command in a container
|
||||
#
|
||||
docker run --rm \
|
||||
-v $PWD:/work \
|
||||
$USER_IDS \
|
||||
$FINAL_ARGS \
|
||||
$FINAL_IMAGE "$@"
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# This image is not intended to be run manually.
|
||||
#
|
||||
# To create a dockcross helper script for the
|
||||
# dockcross/linux-armv7 image, run:
|
||||
#
|
||||
# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7
|
||||
# chmod +x dockcross-linux-armv7
|
||||
#
|
||||
# You may then wish to move the dockcross script to your PATH.
|
||||
#
|
||||
################################################################################
|
200
docker/dockcross-riscv64
Executable file
200
docker/dockcross-riscv64
Executable file
@ -0,0 +1,200 @@
|
||||
#!/bin/bash
|
||||
|
||||
DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-riscv64
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Helpers
|
||||
#
|
||||
err() {
|
||||
echo -e >&2 ERROR: $@\\n
|
||||
}
|
||||
|
||||
die() {
|
||||
err $@
|
||||
exit 1
|
||||
}
|
||||
|
||||
has() {
|
||||
# eg. has command update
|
||||
local kind=$1
|
||||
local name=$2
|
||||
|
||||
type -t $kind:$name | grep -q function
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Command handlers
|
||||
#
|
||||
command:update-image() {
|
||||
docker pull $FINAL_IMAGE
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Pull the latest $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update-script() {
|
||||
if cmp -s <( docker run $FINAL_IMAGE ) $0; then
|
||||
echo $0 is up to date
|
||||
else
|
||||
echo -n Updating $0 '... '
|
||||
docker run $FINAL_IMAGE > $0 && echo ok
|
||||
fi
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Update $0 from $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update() {
|
||||
command:update-image
|
||||
command:update-script
|
||||
}
|
||||
|
||||
help:update() {
|
||||
echo Pull the latest $FINAL_IMAGE, and then update $0 from that.
|
||||
}
|
||||
|
||||
command:help() {
|
||||
if [[ $# != 0 ]]; then
|
||||
if ! has command $1; then
|
||||
err \"$1\" is not an dockcross command
|
||||
command:help
|
||||
elif ! has help $1; then
|
||||
err No help found for \"$1\"
|
||||
else
|
||||
help:$1
|
||||
fi
|
||||
else
|
||||
cat >&2 <<ENDHELP
|
||||
Usage: dockcross [options] [--] command [args]
|
||||
|
||||
By default, run the given *command* in an dockcross Docker container.
|
||||
|
||||
The *options* can be one of:
|
||||
|
||||
--args|-a Extra args to the *docker run* command
|
||||
--image|-i Docker cross-compiler image to use
|
||||
--config|-c Bash script to source before running this script
|
||||
|
||||
|
||||
Additionally, there are special update commands:
|
||||
|
||||
update-image
|
||||
update-script
|
||||
update
|
||||
|
||||
For update command help use: $0 help <command>
|
||||
ENDHELP
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Option processing
|
||||
#
|
||||
special_update_command=''
|
||||
while [[ $# != 0 ]]; do
|
||||
case $1 in
|
||||
|
||||
--)
|
||||
break
|
||||
;;
|
||||
|
||||
--args|-a)
|
||||
ARG_ARGS="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--config|-c)
|
||||
ARG_CONFIG="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--image|-i)
|
||||
ARG_IMAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
update|update-image|update-script)
|
||||
special_update_command=$1
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
err Unknown option \"$1\"
|
||||
command:help
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# The precedence for options is:
|
||||
# 1. command-line arguments
|
||||
# 2. environment variables
|
||||
# 3. defaults
|
||||
|
||||
# Source the config file if it exists
|
||||
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
|
||||
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
|
||||
|
||||
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
|
||||
|
||||
# Set the docker image
|
||||
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
|
||||
|
||||
# Handle special update command
|
||||
if [ "$special_update_command" != "" ]; then
|
||||
case $special_update_command in
|
||||
|
||||
update)
|
||||
command:update
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-image)
|
||||
command:update-image
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-script)
|
||||
command:update-script
|
||||
exit $?
|
||||
;;
|
||||
|
||||
esac
|
||||
fi
|
||||
|
||||
# Set the docker run extra args (if any)
|
||||
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
|
||||
|
||||
# If we are not running via boot2docker
|
||||
if [ -z $DOCKER_HOST ]; then
|
||||
USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )"
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Now, finally, run the command in a container
|
||||
#
|
||||
docker run --rm \
|
||||
-v $PWD:/work \
|
||||
$USER_IDS \
|
||||
$FINAL_ARGS \
|
||||
$FINAL_IMAGE "$@"
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# This image is not intended to be run manually.
|
||||
#
|
||||
# To create a dockcross helper script for the
|
||||
# dockcross/linux-armv7 image, run:
|
||||
#
|
||||
# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7
|
||||
# chmod +x dockcross-linux-armv7
|
||||
#
|
||||
# You may then wish to move the dockcross script to your PATH.
|
||||
#
|
||||
################################################################################
|
199
docker/dockcross-s390x
Executable file
199
docker/dockcross-s390x
Executable file
@ -0,0 +1,199 @@
|
||||
#!/bin/bash
|
||||
DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-s390x:20210210-84c47e5
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Helpers
|
||||
#
|
||||
err() {
|
||||
echo -e >&2 ERROR: $@\\n
|
||||
}
|
||||
|
||||
die() {
|
||||
err $@
|
||||
exit 1
|
||||
}
|
||||
|
||||
has() {
|
||||
# eg. has command update
|
||||
local kind=$1
|
||||
local name=$2
|
||||
|
||||
type -t $kind:$name | grep -q function
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Command handlers
|
||||
#
|
||||
command:update-image() {
|
||||
docker pull $FINAL_IMAGE
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Pull the latest $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update-script() {
|
||||
if cmp -s <( docker run $FINAL_IMAGE ) $0; then
|
||||
echo $0 is up to date
|
||||
else
|
||||
echo -n Updating $0 '... '
|
||||
docker run $FINAL_IMAGE > $0 && echo ok
|
||||
fi
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Update $0 from $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update() {
|
||||
command:update-image
|
||||
command:update-script
|
||||
}
|
||||
|
||||
help:update() {
|
||||
echo Pull the latest $FINAL_IMAGE, and then update $0 from that.
|
||||
}
|
||||
|
||||
command:help() {
|
||||
if [[ $# != 0 ]]; then
|
||||
if ! has command $1; then
|
||||
err \"$1\" is not an dockcross command
|
||||
command:help
|
||||
elif ! has help $1; then
|
||||
err No help found for \"$1\"
|
||||
else
|
||||
help:$1
|
||||
fi
|
||||
else
|
||||
cat >&2 <<ENDHELP
|
||||
Usage: dockcross [options] [--] command [args]
|
||||
|
||||
By default, run the given *command* in an dockcross Docker container.
|
||||
|
||||
The *options* can be one of:
|
||||
|
||||
--args|-a Extra args to the *docker run* command
|
||||
--image|-i Docker cross-compiler image to use
|
||||
--config|-c Bash script to source before running this script
|
||||
|
||||
|
||||
Additionally, there are special update commands:
|
||||
|
||||
update-image
|
||||
update-script
|
||||
update
|
||||
|
||||
For update command help use: $0 help <command>
|
||||
ENDHELP
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Option processing
|
||||
#
|
||||
special_update_command=''
|
||||
while [[ $# != 0 ]]; do
|
||||
case $1 in
|
||||
|
||||
--)
|
||||
break
|
||||
;;
|
||||
|
||||
--args|-a)
|
||||
ARG_ARGS="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--config|-c)
|
||||
ARG_CONFIG="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--image|-i)
|
||||
ARG_IMAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
update|update-image|update-script)
|
||||
special_update_command=$1
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
err Unknown option \"$1\"
|
||||
command:help
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# The precedence for options is:
|
||||
# 1. command-line arguments
|
||||
# 2. environment variables
|
||||
# 3. defaults
|
||||
|
||||
# Source the config file if it exists
|
||||
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
|
||||
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
|
||||
|
||||
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
|
||||
|
||||
# Set the docker image
|
||||
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
|
||||
|
||||
# Handle special update command
|
||||
if [ "$special_update_command" != "" ]; then
|
||||
case $special_update_command in
|
||||
|
||||
update)
|
||||
command:update
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-image)
|
||||
command:update-image
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-script)
|
||||
command:update-script
|
||||
exit $?
|
||||
;;
|
||||
|
||||
esac
|
||||
fi
|
||||
|
||||
# Set the docker run extra args (if any)
|
||||
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
|
||||
|
||||
# If we are not running via boot2docker
|
||||
if [ -z $DOCKER_HOST ]; then
|
||||
USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )"
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Now, finally, run the command in a container
|
||||
#
|
||||
docker run --rm \
|
||||
-v $PWD:/work \
|
||||
$USER_IDS \
|
||||
$FINAL_ARGS \
|
||||
$FINAL_IMAGE "$@"
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# This image is not intended to be run manually.
|
||||
#
|
||||
# To create a dockcross helper script for the
|
||||
# dockcross/linux-armv7 image, run:
|
||||
#
|
||||
# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7
|
||||
# chmod +x dockcross-linux-armv7
|
||||
#
|
||||
# You may then wish to move the dockcross script to your PATH.
|
||||
#
|
||||
################################################################################
|
199
docker/dockcross-windows-arm64
Executable file
199
docker/dockcross-windows-arm64
Executable file
@ -0,0 +1,199 @@
|
||||
#!/bin/bash
|
||||
DEFAULT_DOCKCROSS_IMAGE=dockcross/windows-arm64
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Helpers
|
||||
#
|
||||
err() {
|
||||
echo -e >&2 ERROR: $@\\n
|
||||
}
|
||||
|
||||
die() {
|
||||
err $@
|
||||
exit 1
|
||||
}
|
||||
|
||||
has() {
|
||||
# eg. has command update
|
||||
local kind=$1
|
||||
local name=$2
|
||||
|
||||
type -t $kind:$name | grep -q function
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Command handlers
|
||||
#
|
||||
command:update-image() {
|
||||
docker pull $FINAL_IMAGE
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Pull the latest $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update-script() {
|
||||
if cmp -s <( docker run $FINAL_IMAGE ) $0; then
|
||||
echo $0 is up to date
|
||||
else
|
||||
echo -n Updating $0 '... '
|
||||
docker run $FINAL_IMAGE > $0 && echo ok
|
||||
fi
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Update $0 from $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update() {
|
||||
command:update-image
|
||||
command:update-script
|
||||
}
|
||||
|
||||
help:update() {
|
||||
echo Pull the latest $FINAL_IMAGE, and then update $0 from that.
|
||||
}
|
||||
|
||||
command:help() {
|
||||
if [[ $# != 0 ]]; then
|
||||
if ! has command $1; then
|
||||
err \"$1\" is not an dockcross command
|
||||
command:help
|
||||
elif ! has help $1; then
|
||||
err No help found for \"$1\"
|
||||
else
|
||||
help:$1
|
||||
fi
|
||||
else
|
||||
cat >&2 <<ENDHELP
|
||||
Usage: dockcross [options] [--] command [args]
|
||||
|
||||
By default, run the given *command* in an dockcross Docker container.
|
||||
|
||||
The *options* can be one of:
|
||||
|
||||
--args|-a Extra args to the *docker run* command
|
||||
--image|-i Docker cross-compiler image to use
|
||||
--config|-c Bash script to source before running this script
|
||||
|
||||
|
||||
Additionally, there are special update commands:
|
||||
|
||||
update-image
|
||||
update-script
|
||||
update
|
||||
|
||||
For update command help use: $0 help <command>
|
||||
ENDHELP
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Option processing
|
||||
#
|
||||
special_update_command=''
|
||||
while [[ $# != 0 ]]; do
|
||||
case $1 in
|
||||
|
||||
--)
|
||||
break
|
||||
;;
|
||||
|
||||
--args|-a)
|
||||
ARG_ARGS="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--config|-c)
|
||||
ARG_CONFIG="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--image|-i)
|
||||
ARG_IMAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
update|update-image|update-script)
|
||||
special_update_command=$1
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
err Unknown option \"$1\"
|
||||
command:help
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# The precedence for options is:
|
||||
# 1. command-line arguments
|
||||
# 2. environment variables
|
||||
# 3. defaults
|
||||
|
||||
# Source the config file if it exists
|
||||
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
|
||||
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
|
||||
|
||||
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
|
||||
|
||||
# Set the docker image
|
||||
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
|
||||
|
||||
# Handle special update command
|
||||
if [ "$special_update_command" != "" ]; then
|
||||
case $special_update_command in
|
||||
|
||||
update)
|
||||
command:update
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-image)
|
||||
command:update-image
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-script)
|
||||
command:update-script
|
||||
exit $?
|
||||
;;
|
||||
|
||||
esac
|
||||
fi
|
||||
|
||||
# Set the docker run extra args (if any)
|
||||
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
|
||||
|
||||
# If we are not running via boot2docker
|
||||
if [ -z $DOCKER_HOST ]; then
|
||||
USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )"
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Now, finally, run the command in a container
|
||||
#
|
||||
docker run --rm \
|
||||
-v $PWD:/work \
|
||||
$USER_IDS \
|
||||
$FINAL_ARGS \
|
||||
$FINAL_IMAGE "$@"
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# This image is not intended to be run manually.
|
||||
#
|
||||
# To create a dockcross helper script for the
|
||||
# dockcross/linux-armv7 image, run:
|
||||
#
|
||||
# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7
|
||||
# chmod +x dockcross-linux-armv7
|
||||
#
|
||||
# You may then wish to move the dockcross script to your PATH.
|
||||
#
|
||||
################################################################################
|
200
docker/dockcross-windows-x64
Executable file
200
docker/dockcross-windows-x64
Executable file
@ -0,0 +1,200 @@
|
||||
#!/bin/bash
|
||||
|
||||
DEFAULT_DOCKCROSS_IMAGE=dockcross/windows-x64
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Helpers
|
||||
#
|
||||
err() {
|
||||
echo -e >&2 ERROR: $@\\n
|
||||
}
|
||||
|
||||
die() {
|
||||
err $@
|
||||
exit 1
|
||||
}
|
||||
|
||||
has() {
|
||||
# eg. has command update
|
||||
local kind=$1
|
||||
local name=$2
|
||||
|
||||
type -t $kind:$name | grep -q function
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Command handlers
|
||||
#
|
||||
command:update-image() {
|
||||
docker pull $FINAL_IMAGE
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Pull the latest $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update-script() {
|
||||
if cmp -s <( docker run $FINAL_IMAGE ) $0; then
|
||||
echo $0 is up to date
|
||||
else
|
||||
echo -n Updating $0 '... '
|
||||
docker run $FINAL_IMAGE > $0 && echo ok
|
||||
fi
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Update $0 from $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update() {
|
||||
command:update-image
|
||||
command:update-script
|
||||
}
|
||||
|
||||
help:update() {
|
||||
echo Pull the latest $FINAL_IMAGE, and then update $0 from that.
|
||||
}
|
||||
|
||||
command:help() {
|
||||
if [[ $# != 0 ]]; then
|
||||
if ! has command $1; then
|
||||
err \"$1\" is not an dockcross command
|
||||
command:help
|
||||
elif ! has help $1; then
|
||||
err No help found for \"$1\"
|
||||
else
|
||||
help:$1
|
||||
fi
|
||||
else
|
||||
cat >&2 <<ENDHELP
|
||||
Usage: dockcross [options] [--] command [args]
|
||||
|
||||
By default, run the given *command* in an dockcross Docker container.
|
||||
|
||||
The *options* can be one of:
|
||||
|
||||
--args|-a Extra args to the *docker run* command
|
||||
--image|-i Docker cross-compiler image to use
|
||||
--config|-c Bash script to source before running this script
|
||||
|
||||
|
||||
Additionally, there are special update commands:
|
||||
|
||||
update-image
|
||||
update-script
|
||||
update
|
||||
|
||||
For update command help use: $0 help <command>
|
||||
ENDHELP
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Option processing
|
||||
#
|
||||
special_update_command=''
|
||||
while [[ $# != 0 ]]; do
|
||||
case $1 in
|
||||
|
||||
--)
|
||||
break
|
||||
;;
|
||||
|
||||
--args|-a)
|
||||
ARG_ARGS="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--config|-c)
|
||||
ARG_CONFIG="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--image|-i)
|
||||
ARG_IMAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
update|update-image|update-script)
|
||||
special_update_command=$1
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
err Unknown option \"$1\"
|
||||
command:help
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# The precedence for options is:
|
||||
# 1. command-line arguments
|
||||
# 2. environment variables
|
||||
# 3. defaults
|
||||
|
||||
# Source the config file if it exists
|
||||
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
|
||||
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
|
||||
|
||||
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
|
||||
|
||||
# Set the docker image
|
||||
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
|
||||
|
||||
# Handle special update command
|
||||
if [ "$special_update_command" != "" ]; then
|
||||
case $special_update_command in
|
||||
|
||||
update)
|
||||
command:update
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-image)
|
||||
command:update-image
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-script)
|
||||
command:update-script
|
||||
exit $?
|
||||
;;
|
||||
|
||||
esac
|
||||
fi
|
||||
|
||||
# Set the docker run extra args (if any)
|
||||
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
|
||||
|
||||
# If we are not running via boot2docker
|
||||
if [ -z $DOCKER_HOST ]; then
|
||||
USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )"
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Now, finally, run the command in a container
|
||||
#
|
||||
docker run --rm \
|
||||
-v $PWD:/work \
|
||||
$USER_IDS \
|
||||
$FINAL_ARGS \
|
||||
$FINAL_IMAGE "$@"
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# This image is not intended to be run manually.
|
||||
#
|
||||
# To create a dockcross helper script for the
|
||||
# dockcross/linux-armv7 image, run:
|
||||
#
|
||||
# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7
|
||||
# chmod +x dockcross-linux-armv7
|
||||
#
|
||||
# You may then wish to move the dockcross script to your PATH.
|
||||
#
|
||||
################################################################################
|
200
docker/dockcross-windows-x86
Executable file
200
docker/dockcross-windows-x86
Executable file
@ -0,0 +1,200 @@
|
||||
#!/bin/bash
|
||||
|
||||
DEFAULT_DOCKCROSS_IMAGE=dockcross/windows-x86
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Helpers
|
||||
#
|
||||
err() {
|
||||
echo -e >&2 ERROR: $@\\n
|
||||
}
|
||||
|
||||
die() {
|
||||
err $@
|
||||
exit 1
|
||||
}
|
||||
|
||||
has() {
|
||||
# eg. has command update
|
||||
local kind=$1
|
||||
local name=$2
|
||||
|
||||
type -t $kind:$name | grep -q function
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Command handlers
|
||||
#
|
||||
command:update-image() {
|
||||
docker pull $FINAL_IMAGE
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Pull the latest $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update-script() {
|
||||
if cmp -s <( docker run $FINAL_IMAGE ) $0; then
|
||||
echo $0 is up to date
|
||||
else
|
||||
echo -n Updating $0 '... '
|
||||
docker run $FINAL_IMAGE > $0 && echo ok
|
||||
fi
|
||||
}
|
||||
|
||||
help:update-image() {
|
||||
echo Update $0 from $FINAL_IMAGE .
|
||||
}
|
||||
|
||||
command:update() {
|
||||
command:update-image
|
||||
command:update-script
|
||||
}
|
||||
|
||||
help:update() {
|
||||
echo Pull the latest $FINAL_IMAGE, and then update $0 from that.
|
||||
}
|
||||
|
||||
command:help() {
|
||||
if [[ $# != 0 ]]; then
|
||||
if ! has command $1; then
|
||||
err \"$1\" is not an dockcross command
|
||||
command:help
|
||||
elif ! has help $1; then
|
||||
err No help found for \"$1\"
|
||||
else
|
||||
help:$1
|
||||
fi
|
||||
else
|
||||
cat >&2 <<ENDHELP
|
||||
Usage: dockcross [options] [--] command [args]
|
||||
|
||||
By default, run the given *command* in an dockcross Docker container.
|
||||
|
||||
The *options* can be one of:
|
||||
|
||||
--args|-a Extra args to the *docker run* command
|
||||
--image|-i Docker cross-compiler image to use
|
||||
--config|-c Bash script to source before running this script
|
||||
|
||||
|
||||
Additionally, there are special update commands:
|
||||
|
||||
update-image
|
||||
update-script
|
||||
update
|
||||
|
||||
For update command help use: $0 help <command>
|
||||
ENDHELP
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Option processing
|
||||
#
|
||||
special_update_command=''
|
||||
while [[ $# != 0 ]]; do
|
||||
case $1 in
|
||||
|
||||
--)
|
||||
break
|
||||
;;
|
||||
|
||||
--args|-a)
|
||||
ARG_ARGS="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--config|-c)
|
||||
ARG_CONFIG="$2"
|
||||
shift 2
|
||||
;;
|
||||
|
||||
--image|-i)
|
||||
ARG_IMAGE="$2"
|
||||
shift 2
|
||||
;;
|
||||
update|update-image|update-script)
|
||||
special_update_command=$1
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
err Unknown option \"$1\"
|
||||
command:help
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# The precedence for options is:
|
||||
# 1. command-line arguments
|
||||
# 2. environment variables
|
||||
# 3. defaults
|
||||
|
||||
# Source the config file if it exists
|
||||
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
|
||||
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
|
||||
|
||||
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
|
||||
|
||||
# Set the docker image
|
||||
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
|
||||
|
||||
# Handle special update command
|
||||
if [ "$special_update_command" != "" ]; then
|
||||
case $special_update_command in
|
||||
|
||||
update)
|
||||
command:update
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-image)
|
||||
command:update-image
|
||||
exit $?
|
||||
;;
|
||||
|
||||
update-script)
|
||||
command:update-script
|
||||
exit $?
|
||||
;;
|
||||
|
||||
esac
|
||||
fi
|
||||
|
||||
# Set the docker run extra args (if any)
|
||||
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
|
||||
|
||||
# If we are not running via boot2docker
|
||||
if [ -z $DOCKER_HOST ]; then
|
||||
USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )"
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Now, finally, run the command in a container
|
||||
#
|
||||
docker run --rm \
|
||||
-v $PWD:/work \
|
||||
$USER_IDS \
|
||||
$FINAL_ARGS \
|
||||
$FINAL_IMAGE "$@"
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# This image is not intended to be run manually.
|
||||
#
|
||||
# To create a dockcross helper script for the
|
||||
# dockcross/linux-armv7 image, run:
|
||||
#
|
||||
# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7
|
||||
# chmod +x dockcross-linux-armv7
|
||||
#
|
||||
# You may then wish to move the dockcross script to your PATH.
|
||||
#
|
||||
################################################################################
|
@ -1,248 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2006, 2007 Google Inc. All Rights Reserved.
|
||||
# Author: danderson@google.com (David Anderson)
|
||||
#
|
||||
# Script for uploading files to a Google Code project.
|
||||
#
|
||||
# This is intended to be both a useful script for people who want to
|
||||
# streamline project uploads and a reference implementation for
|
||||
# uploading files to Google Code projects.
|
||||
#
|
||||
# To upload a file to Google Code, you need to provide a path to the
|
||||
# file on your local machine, a small summary of what the file is, a
|
||||
# project name, and a valid account that is a member or owner of that
|
||||
# project. You can optionally provide a list of labels that apply to
|
||||
# the file. The file will be uploaded under the same name that it has
|
||||
# in your local filesystem (that is, the "basename" or last path
|
||||
# component). Run the script with '--help' to get the exact syntax
|
||||
# and available options.
|
||||
#
|
||||
# Note that the upload script requests that you enter your
|
||||
# googlecode.com password. This is NOT your Gmail account password!
|
||||
# This is the password you use on googlecode.com for committing to
|
||||
# Subversion and uploading files. You can find your password by going
|
||||
# to http://code.google.com/hosting/settings when logged in with your
|
||||
# Gmail account. If you have already committed to your project's
|
||||
# Subversion repository, the script will automatically retrieve your
|
||||
# credentials from there (unless disabled, see the output of '--help'
|
||||
# for details).
|
||||
#
|
||||
# If you are looking at this script as a reference for implementing
|
||||
# your own Google Code file uploader, then you should take a look at
|
||||
# the upload() function, which is the meat of the uploader. You
|
||||
# basically need to build a multipart/form-data POST request with the
|
||||
# right fields and send it to https://PROJECT.googlecode.com/files .
|
||||
# Authenticate the request using HTTP Basic authentication, as is
|
||||
# shown below.
|
||||
#
|
||||
# Licensed under the terms of the Apache Software License 2.0:
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Questions, comments, feature requests and patches are most welcome.
|
||||
# Please direct all of these to the Google Code users group:
|
||||
# http://groups.google.com/group/google-code-hosting
|
||||
|
||||
"""Google Code file uploader script.
|
||||
"""
|
||||
|
||||
__author__ = 'danderson@google.com (David Anderson)'
|
||||
|
||||
import httplib
|
||||
import os.path
|
||||
import optparse
|
||||
import getpass
|
||||
import base64
|
||||
import sys
|
||||
|
||||
|
||||
def upload(file, project_name, user_name, password, summary, labels=None):
|
||||
"""Upload a file to a Google Code project's file server.
|
||||
|
||||
Args:
|
||||
file: The local path to the file.
|
||||
project_name: The name of your project on Google Code.
|
||||
user_name: Your Google account name.
|
||||
password: The googlecode.com password for your account.
|
||||
Note that this is NOT your global Google Account password!
|
||||
summary: A small description for the file.
|
||||
labels: an optional list of label strings with which to tag the file.
|
||||
|
||||
Returns: a tuple:
|
||||
http_status: 201 if the upload succeeded, something else if an
|
||||
error occured.
|
||||
http_reason: The human-readable string associated with http_status
|
||||
file_url: If the upload succeeded, the URL of the file on Google
|
||||
Code, None otherwise.
|
||||
"""
|
||||
# The login is the user part of user@gmail.com. If the login provided
|
||||
# is in the full user@domain form, strip it down.
|
||||
if user_name.endswith('@gmail.com'):
|
||||
user_name = user_name[:user_name.index('@gmail.com')]
|
||||
|
||||
form_fields = [('summary', summary)]
|
||||
if labels is not None:
|
||||
form_fields.extend([('label', l.strip()) for l in labels])
|
||||
|
||||
content_type, body = encode_upload_request(form_fields, file)
|
||||
|
||||
upload_host = '%s.googlecode.com' % project_name
|
||||
upload_uri = '/files'
|
||||
auth_token = base64.b64encode('%s:%s'% (user_name, password))
|
||||
headers = {
|
||||
'Authorization': 'Basic %s' % auth_token,
|
||||
'User-Agent': 'Googlecode.com uploader v0.9.4',
|
||||
'Content-Type': content_type,
|
||||
}
|
||||
|
||||
server = httplib.HTTPSConnection(upload_host)
|
||||
server.request('POST', upload_uri, body, headers)
|
||||
resp = server.getresponse()
|
||||
server.close()
|
||||
|
||||
if resp.status == 201:
|
||||
location = resp.getheader('Location', None)
|
||||
else:
|
||||
location = None
|
||||
return resp.status, resp.reason, location
|
||||
|
||||
|
||||
def encode_upload_request(fields, file_path):
|
||||
"""Encode the given fields and file into a multipart form body.
|
||||
|
||||
fields is a sequence of (name, value) pairs. file is the path of
|
||||
the file to upload. The file will be uploaded to Google Code with
|
||||
the same file name.
|
||||
|
||||
Returns: (content_type, body) ready for httplib.HTTP instance
|
||||
"""
|
||||
BOUNDARY = '----------Googlecode_boundary_reindeer_flotilla'
|
||||
CRLF = '\r\n'
|
||||
|
||||
body = []
|
||||
|
||||
# Add the metadata about the upload first
|
||||
for key, value in fields:
|
||||
body.extend(
|
||||
['--' + BOUNDARY,
|
||||
'Content-Disposition: form-data; name="%s"' % key,
|
||||
'',
|
||||
value,
|
||||
])
|
||||
|
||||
# Now add the file itself
|
||||
file_name = os.path.basename(file_path)
|
||||
f = open(file_path, 'rb')
|
||||
file_content = f.read()
|
||||
f.close()
|
||||
|
||||
body.extend(
|
||||
['--' + BOUNDARY,
|
||||
'Content-Disposition: form-data; name="filename"; filename="%s"'
|
||||
% file_name,
|
||||
# The upload server determines the mime-type, no need to set it.
|
||||
'Content-Type: application/octet-stream',
|
||||
'',
|
||||
file_content,
|
||||
])
|
||||
|
||||
# Finalize the form body
|
||||
body.extend(['--' + BOUNDARY + '--', ''])
|
||||
|
||||
return 'multipart/form-data; boundary=%s' % BOUNDARY, CRLF.join(body)
|
||||
|
||||
|
||||
def upload_find_auth(file_path, project_name, summary, labels=None,
|
||||
user_name=None, password=None, tries=3):
|
||||
"""Find credentials and upload a file to a Google Code project's file server.
|
||||
|
||||
file_path, project_name, summary, and labels are passed as-is to upload.
|
||||
|
||||
Args:
|
||||
file_path: The local path to the file.
|
||||
project_name: The name of your project on Google Code.
|
||||
summary: A small description for the file.
|
||||
labels: an optional list of label strings with which to tag the file.
|
||||
config_dir: Path to Subversion configuration directory, 'none', or None.
|
||||
user_name: Your Google account name.
|
||||
tries: How many attempts to make.
|
||||
"""
|
||||
|
||||
while tries > 0:
|
||||
if user_name is None:
|
||||
# Read username if not specified or loaded from svn config, or on
|
||||
# subsequent tries.
|
||||
sys.stdout.write('Please enter your googlecode.com username: ')
|
||||
sys.stdout.flush()
|
||||
user_name = sys.stdin.readline().rstrip()
|
||||
if password is None:
|
||||
# Read password if not loaded from svn config, or on subsequent tries.
|
||||
print 'Please enter your googlecode.com password.'
|
||||
print '** Note that this is NOT your Gmail account password! **'
|
||||
print 'It is the password you use to access Subversion repositories,'
|
||||
print 'and can be found here: http://code.google.com/hosting/settings'
|
||||
password = getpass.getpass()
|
||||
|
||||
status, reason, url = upload(file_path, project_name, user_name, password,
|
||||
summary, labels)
|
||||
# Returns 403 Forbidden instead of 401 Unauthorized for bad
|
||||
# credentials as of 2007-07-17.
|
||||
if status in [httplib.FORBIDDEN, httplib.UNAUTHORIZED]:
|
||||
# Rest for another try.
|
||||
user_name = password = None
|
||||
tries = tries - 1
|
||||
else:
|
||||
# We're done.
|
||||
break
|
||||
|
||||
return status, reason, url
|
||||
|
||||
|
||||
def main():
|
||||
parser = optparse.OptionParser(usage='googlecode-upload.py -s SUMMARY '
|
||||
'-p PROJECT [options] FILE')
|
||||
parser.add_option('-s', '--summary', dest='summary',
|
||||
help='Short description of the file')
|
||||
parser.add_option('-p', '--project', dest='project',
|
||||
help='Google Code project name')
|
||||
parser.add_option('-u', '--user', dest='user',
|
||||
help='Your Google Code username')
|
||||
parser.add_option('-w', '--password', dest='password',
|
||||
help='Your Google Code password')
|
||||
parser.add_option('-l', '--labels', dest='labels',
|
||||
help='An optional list of comma-separated labels to attach '
|
||||
'to the file')
|
||||
|
||||
options, args = parser.parse_args()
|
||||
|
||||
if not options.summary:
|
||||
parser.error('File summary is missing.')
|
||||
elif not options.project:
|
||||
parser.error('Project name is missing.')
|
||||
elif len(args) < 1:
|
||||
parser.error('File to upload not provided.')
|
||||
elif len(args) > 1:
|
||||
parser.error('Only one file may be specified.')
|
||||
|
||||
file_path = args[0]
|
||||
|
||||
if options.labels:
|
||||
labels = options.labels.split(',')
|
||||
else:
|
||||
labels = None
|
||||
|
||||
status, reason, url = upload_find_auth(file_path, options.project,
|
||||
options.summary, labels,
|
||||
options.user, options.password)
|
||||
if url:
|
||||
print 'The file was uploaded successfully.'
|
||||
print 'URL: %s' % url
|
||||
return 0
|
||||
else:
|
||||
print 'An error occurred. Your file was not uploaded.'
|
||||
print 'Google Code upload server said: %s (%s)' % (reason, status)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
62
lib/inc_linux/config.h
Normal file
62
lib/inc_linux/config.h
Normal file
@ -0,0 +1,62 @@
|
||||
#ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_
|
||||
#define THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_
|
||||
|
||||
/* Define to 1 if the compiler supports __builtin_ctz and friends. */
|
||||
#define HAVE_BUILTIN_CTZ 1
|
||||
|
||||
/* Define to 1 if the compiler supports __builtin_expect. */
|
||||
#define HAVE_BUILTIN_EXPECT 1
|
||||
|
||||
/* Define to 1 if you have the <byteswap.h> header file. */
|
||||
/* #undef HAVE_BYTESWAP_H */
|
||||
|
||||
/* Define to 1 if you have a definition for mmap() in <sys/mman.h>. */
|
||||
#define HAVE_FUNC_MMAP 1
|
||||
|
||||
/* Define to 1 if you have a definition for sysconf() in <unistd.h>. */
|
||||
#define HAVE_FUNC_SYSCONF 1
|
||||
|
||||
/* Define to 1 to use the gflags package for command-line parsing. */
|
||||
/* #undef HAVE_GFLAGS */
|
||||
|
||||
/* Define to 1 if you have Google Test. */
|
||||
/* #undef HAVE_GTEST */
|
||||
|
||||
/* Define to 1 if you have the `lzo2' library (-llzo2). */
|
||||
/* #undef HAVE_LIBLZO2 */
|
||||
|
||||
/* Define to 1 if you have the `z' library (-lz). */
|
||||
#define HAVE_LIBZ 1
|
||||
|
||||
/* Define to 1 if you have the <stddef.h> header file. */
|
||||
#define HAVE_STDDEF_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/endian.h> header file. */
|
||||
/* #undef HAVE_SYS_ENDIAN_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/mman.h> header file. */
|
||||
#define HAVE_SYS_MMAN_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/resource.h> header file. */
|
||||
#define HAVE_SYS_RESOURCE_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/uio.h> header file. */
|
||||
#define HAVE_SYS_UIO_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to 1 if you have the <windows.h> header file. */
|
||||
/* #undef HAVE_WINDOWS_H */
|
||||
|
||||
/* Define to 1 if your processor stores words with the most significant byte
|
||||
first (like Motorola and SPARC, unlike Intel and VAX). */
|
||||
/* #undef SNAPPY_IS_BIG_ENDIAN */
|
||||
|
||||
#endif // THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_
|
@ -1,26 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -1951,9 +1951,10 @@ JNI_OnUnload(JavaVM *vm, void *reserved);
|
||||
#define JNI_VERSION_1_2 0x00010002
|
||||
#define JNI_VERSION_1_4 0x00010004
|
||||
#define JNI_VERSION_1_6 0x00010006
|
||||
#define JNI_VERSION_1_8 0x00010008
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* !_JAVASOFT_JNI_H_ */
|
||||
#endif /* !_JAVASOFT_JNI_H_ */
|
94
lib/inc_linux/snappy-stubs-public.h
Normal file
94
lib/inc_linux/snappy-stubs-public.h
Normal file
@ -0,0 +1,94 @@
|
||||
// Copyright 2011 Google Inc. All Rights Reserved.
|
||||
// Author: sesse@google.com (Steinar H. Gunderson)
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Various type stubs for the open-source version of Snappy.
|
||||
//
|
||||
// This file cannot include config.h, as it is included from snappy.h,
|
||||
// which is a public header. Instead, snappy-stubs-public.h is generated by
|
||||
// from snappy-stubs-public.h.in at configure time.
|
||||
|
||||
#ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
|
||||
#define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
|
||||
|
||||
#if 1 // HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif // HAVE_STDDEF_H
|
||||
|
||||
#if 1 // HAVE_STDDEF_H
|
||||
#include <stddef.h>
|
||||
#endif // HAVE_STDDEF_H
|
||||
|
||||
#if 1 // HAVE_SYS_UIO_H
|
||||
#include <sys/uio.h>
|
||||
#endif // HAVE_SYS_UIO_H
|
||||
|
||||
#define SNAPPY_MAJOR
|
||||
#define SNAPPY_MINOR
|
||||
#define SNAPPY_PATCHLEVEL
|
||||
#define SNAPPY_VERSION \
|
||||
((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace snappy {
|
||||
|
||||
#if 1 // HAVE_STDINT_H
|
||||
typedef int8_t int8;
|
||||
typedef uint8_t uint8;
|
||||
typedef int16_t int16;
|
||||
typedef uint16_t uint16;
|
||||
typedef int32_t int32;
|
||||
typedef uint32_t uint32;
|
||||
typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
#else
|
||||
typedef signed char int8;
|
||||
typedef unsigned char uint8;
|
||||
typedef short int16;
|
||||
typedef unsigned short uint16;
|
||||
typedef int int32;
|
||||
typedef unsigned int uint32;
|
||||
typedef long long int64;
|
||||
typedef unsigned long long uint64;
|
||||
#endif // HAVE_STDINT_H
|
||||
|
||||
typedef std::string string;
|
||||
|
||||
#if !1 // !HAVE_SYS_UIO_H
|
||||
// Windows does not have an iovec type, yet the concept is universally useful.
|
||||
// It is simple to define it ourselves, so we put it inside our own namespace.
|
||||
struct iovec {
|
||||
void* iov_base;
|
||||
size_t iov_len;
|
||||
};
|
||||
#endif // !HAVE_SYS_UIO_H
|
||||
|
||||
} // namespace snappy
|
||||
|
||||
#endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
|
@ -1,5 +0,0 @@
|
||||
|
||||
#ifndef __CONFIG_H
|
||||
#define __CONFIG_H
|
||||
|
||||
#endif // __CONFIG_H
|
Binary file not shown.
@ -1,2 +1,2 @@
|
||||
sbt.version=0.13.6
|
||||
sbt.version=1.10.7
|
||||
|
||||
|
@ -1,12 +1,5 @@
|
||||
|
||||
addSbtPlugin("com.github.gseitz" % "sbt-release" % "0.7.1")
|
||||
|
||||
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "0.2.1")
|
||||
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3")
|
||||
|
||||
addSbtPlugin("de.johoop" % "findbugs4sbt" % "1.3.0")
|
||||
|
||||
addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.5")
|
||||
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.7.0")
|
||||
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.12.2")
|
||||
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.1")
|
||||
addSbtPlugin("com.github.sbt" % "sbt-osgi" % "0.10.0")
|
||||
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.4")
|
||||
addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.1.0")
|
||||
|
739
sbt
739
sbt
@ -1,87 +1,107 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# A more capable sbt runner, coincidentally also called sbt.
|
||||
# Author: Paul Phillips <paulp@typesafe.com>
|
||||
# Author: Paul Phillips <paulp@improving.org>
|
||||
# https://github.com/paulp/sbt-extras
|
||||
#
|
||||
# Generated from http://www.opensource.org/licenses/bsd-license.php
|
||||
# Copyright (c) 2011, Paul Phillips. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of the author nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
set -o pipefail
|
||||
|
||||
declare -r sbt_release_version="1.9.6"
|
||||
declare -r sbt_unreleased_version="1.9.6"
|
||||
|
||||
declare -r latest_213="2.13.12"
|
||||
declare -r latest_212="2.12.18"
|
||||
declare -r latest_211="2.11.12"
|
||||
declare -r latest_210="2.10.7"
|
||||
declare -r latest_29="2.9.3"
|
||||
declare -r latest_28="2.8.2"
|
||||
|
||||
# todo - make this dynamic
|
||||
declare -r sbt_release_version="0.13.1"
|
||||
declare -r sbt_unreleased_version="0.13.2-SNAPSHOT" # -sbt-dev doesn't work at present
|
||||
declare -r buildProps="project/build.properties"
|
||||
|
||||
declare sbt_jar sbt_dir sbt_create sbt_launch_dir
|
||||
declare scala_version java_home sbt_explicit_version
|
||||
declare verbose debug quiet noshare batch trace_level log_level
|
||||
declare sbt_saved_stty
|
||||
declare -r sbt_launch_ivy_release_repo="https://repo.typesafe.com/typesafe/ivy-releases"
|
||||
declare -r sbt_launch_ivy_snapshot_repo="https://repo.scala-sbt.org/scalasbt/ivy-snapshots"
|
||||
declare -r sbt_launch_mvn_release_repo="https://repo1.maven.org/maven2"
|
||||
declare -r sbt_launch_mvn_snapshot_repo="https://repo.scala-sbt.org/scalasbt/maven-snapshots"
|
||||
|
||||
echoerr () { [[ -z "$quiet" ]] && echo "$@" >&2; }
|
||||
vlog () { [[ -n "$verbose$debug" ]] && echoerr "$@"; }
|
||||
dlog () { [[ -n "$debug" ]] && echoerr "$@"; }
|
||||
declare -r default_jvm_opts_common="-Xms512m -Xss2m -XX:MaxInlineLevel=18"
|
||||
declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy -Dsbt.coursier.home=project/.coursier"
|
||||
|
||||
# we'd like these set before we get around to properly processing arguments
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
-q|-quiet) quiet=true ;;
|
||||
-d|-debug) debug=true ;;
|
||||
-v|-verbose) verbose=true ;;
|
||||
*) ;;
|
||||
esac
|
||||
done
|
||||
declare sbt_jar sbt_dir sbt_create sbt_version sbt_script sbt_new
|
||||
declare sbt_explicit_version
|
||||
declare verbose noshare batch trace_level
|
||||
|
||||
# spaces are possible, e.g. sbt.version = 0.13.0
|
||||
build_props_sbt () {
|
||||
[[ -r "$buildProps" ]] && \
|
||||
grep '^sbt\.version' "$buildProps" | tr '=' ' ' | awk '{ print $2; }'
|
||||
declare java_cmd="java"
|
||||
declare sbt_launch_dir="$HOME/.sbt/launchers"
|
||||
declare sbt_launch_repo
|
||||
|
||||
# pull -J and -D options to give to java.
|
||||
declare -a java_args scalac_args sbt_commands residual_args
|
||||
|
||||
# args to jvm/sbt via files or environment variables
|
||||
declare -a extra_jvm_opts extra_sbt_opts
|
||||
|
||||
echoerr() { echo >&2 "$@"; }
|
||||
vlog() { [[ -n "$verbose" ]] && echoerr "$@"; }
|
||||
die() {
|
||||
echo "Aborting: $*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
update_build_props_sbt () {
|
||||
local ver="$1"
|
||||
local old="$(build_props_sbt)"
|
||||
setTrapExit() {
|
||||
# save stty and trap exit, to ensure echo is re-enabled if we are interrupted.
|
||||
SBT_STTY="$(stty -g 2>/dev/null)"
|
||||
export SBT_STTY
|
||||
|
||||
[[ -r "$buildProps" ]] && [[ "$ver" != "$old" ]] && {
|
||||
perl -pi -e "s/^sbt\.version\b.*\$/sbt.version=${ver}/" "$buildProps"
|
||||
grep -q '^sbt.version[ =]' "$buildProps" || printf "\nsbt.version=%s\n" "$ver" >> "$buildProps"
|
||||
|
||||
echoerr "!!!"
|
||||
echoerr "!!! Updated file $buildProps setting sbt.version to: $ver"
|
||||
echoerr "!!! Previous value was: $old"
|
||||
echoerr "!!!"
|
||||
# restore stty settings (echo in particular)
|
||||
onSbtRunnerExit() {
|
||||
[ -t 0 ] || return
|
||||
vlog ""
|
||||
vlog "restoring stty: $SBT_STTY"
|
||||
stty "$SBT_STTY"
|
||||
}
|
||||
}
|
||||
|
||||
sbt_version () {
|
||||
if [[ -n "$sbt_explicit_version" ]]; then
|
||||
echo "$sbt_explicit_version"
|
||||
else
|
||||
local v="$(build_props_sbt)"
|
||||
if [[ -n "$v" ]]; then
|
||||
echo "$v"
|
||||
else
|
||||
echo "$sbt_release_version"
|
||||
fi
|
||||
fi
|
||||
vlog "saving stty: $SBT_STTY"
|
||||
trap onSbtRunnerExit EXIT
|
||||
}
|
||||
|
||||
# restore stty settings (echo in particular)
|
||||
onSbtRunnerExit() {
|
||||
[[ -n "$sbt_saved_stty" ]] || return
|
||||
dlog ""
|
||||
dlog "restoring stty: $sbt_saved_stty"
|
||||
stty "$sbt_saved_stty"
|
||||
unset sbt_saved_stty
|
||||
}
|
||||
|
||||
# save stty and trap exit, to ensure echo is reenabled if we are interrupted.
|
||||
trap onSbtRunnerExit EXIT
|
||||
sbt_saved_stty="$(stty -g 2>/dev/null)"
|
||||
dlog "Saved stty: $sbt_saved_stty"
|
||||
|
||||
# this seems to cover the bases on OSX, and someone will
|
||||
# have to tell me about the others.
|
||||
get_script_path () {
|
||||
get_script_path() {
|
||||
local path="$1"
|
||||
[[ -L "$path" ]] || { echo "$path" ; return; }
|
||||
[[ -L "$path" ]] || {
|
||||
echo "$path"
|
||||
return
|
||||
}
|
||||
|
||||
local target="$(readlink "$path")"
|
||||
local -r target="$(readlink "$path")"
|
||||
if [[ "${target:0:1}" == "/" ]]; then
|
||||
echo "$target"
|
||||
else
|
||||
@ -89,23 +109,12 @@ get_script_path () {
|
||||
fi
|
||||
}
|
||||
|
||||
die() {
|
||||
echo "Aborting: $@"
|
||||
exit 1
|
||||
}
|
||||
script_path="$(get_script_path "${BASH_SOURCE[0]}")"
|
||||
declare -r script_path
|
||||
script_name="${script_path##*/}"
|
||||
declare -r script_name
|
||||
|
||||
make_url () {
|
||||
version="$1"
|
||||
|
||||
case "$version" in
|
||||
0.7.*) echo "http://simple-build-tool.googlecode.com/files/sbt-launch-0.7.7.jar" ;;
|
||||
0.10.* ) echo "$sbt_launch_repo/org.scala-tools.sbt/sbt-launch/$version/sbt-launch.jar" ;;
|
||||
0.11.[12]) echo "$sbt_launch_repo/org.scala-tools.sbt/sbt-launch/$version/sbt-launch.jar" ;;
|
||||
*) echo "$sbt_launch_repo/org.scala-sbt/sbt-launch/$version/sbt-launch.jar" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
init_default_option_file () {
|
||||
init_default_option_file() {
|
||||
local overriding_var="${!1}"
|
||||
local default_file="$2"
|
||||
if [[ ! -r "$default_file" && "$overriding_var" =~ ^@(.*)$ ]]; then
|
||||
@ -117,112 +126,280 @@ init_default_option_file () {
|
||||
echo "$default_file"
|
||||
}
|
||||
|
||||
declare -r cms_opts="-XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC"
|
||||
declare -r jit_opts="-XX:ReservedCodeCacheSize=256m -XX:+TieredCompilation"
|
||||
declare -r default_jvm_opts="-Dfile.encoding=UTF8 -XX:MaxPermSize=384m -Xms512m -Xmx1536m -Xss2m $jit_opts $cms_opts"
|
||||
declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy"
|
||||
declare -r latest_28="2.8.2"
|
||||
declare -r latest_29="2.9.3"
|
||||
declare -r latest_210="2.10.3"
|
||||
declare -r latest_211="2.11.0-M5"
|
||||
sbt_opts_file="$(init_default_option_file SBT_OPTS .sbtopts)"
|
||||
sbtx_opts_file="$(init_default_option_file SBTX_OPTS .sbtxopts)"
|
||||
jvm_opts_file="$(init_default_option_file JVM_OPTS .jvmopts)"
|
||||
|
||||
declare -r script_path="$(get_script_path "$BASH_SOURCE")"
|
||||
declare -r script_name="${script_path##*/}"
|
||||
build_props_sbt() {
|
||||
[[ -r "$buildProps" ]] &&
|
||||
grep '^sbt\.version' "$buildProps" | tr '=\r' ' ' | awk '{ print $2; }'
|
||||
}
|
||||
|
||||
# some non-read-onlies set with defaults
|
||||
declare java_cmd="java"
|
||||
declare sbt_opts_file="$(init_default_option_file SBT_OPTS .sbtopts)"
|
||||
declare jvm_opts_file="$(init_default_option_file JVM_OPTS .jvmopts)"
|
||||
declare sbt_launch_repo="http://typesafe.artifactoryonline.com/typesafe/ivy-releases"
|
||||
set_sbt_version() {
|
||||
sbt_version="${sbt_explicit_version:-$(build_props_sbt)}"
|
||||
[[ -n "$sbt_version" ]] || sbt_version=$sbt_release_version
|
||||
export sbt_version
|
||||
}
|
||||
|
||||
# pull -J and -D options to give to java.
|
||||
declare -a residual_args
|
||||
declare -a java_args
|
||||
declare -a scalac_args
|
||||
declare -a sbt_commands
|
||||
url_base() {
|
||||
local version="$1"
|
||||
|
||||
# args to jvm/sbt via files or environment variables
|
||||
declare -a extra_jvm_opts extra_sbt_opts
|
||||
case "$version" in
|
||||
0.7.*) echo "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/simple-build-tool" ;;
|
||||
0.10.*) echo "$sbt_launch_ivy_release_repo" ;;
|
||||
0.11.[12]) echo "$sbt_launch_ivy_release_repo" ;;
|
||||
0.*-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]) # ie "*-yyyymmdd-hhMMss"
|
||||
echo "$sbt_launch_ivy_snapshot_repo" ;;
|
||||
0.*) echo "$sbt_launch_ivy_release_repo" ;;
|
||||
*-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]) # ie "*-yyyymmddThhMMss"
|
||||
echo "$sbt_launch_mvn_snapshot_repo" ;;
|
||||
*) echo "$sbt_launch_mvn_release_repo" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# if set, use JAVA_HOME over java found in path
|
||||
[[ -e "$JAVA_HOME/bin/java" ]] && java_cmd="$JAVA_HOME/bin/java"
|
||||
make_url() {
|
||||
local version="$1"
|
||||
|
||||
# directory to store sbt launchers
|
||||
declare sbt_launch_dir="$HOME/.sbt/launchers"
|
||||
[[ -d "$sbt_launch_dir" ]] || mkdir -p "$sbt_launch_dir"
|
||||
[[ -w "$sbt_launch_dir" ]] || sbt_launch_dir="$(mktemp -d -t sbt_extras_launchers.XXXXXX)"
|
||||
local base="${sbt_launch_repo:-$(url_base "$version")}"
|
||||
|
||||
build_props_scala () {
|
||||
if [[ -r "$buildProps" ]]; then
|
||||
versionLine="$(grep '^build.scala.versions' "$buildProps")"
|
||||
versionString="${versionLine##build.scala.versions=}"
|
||||
echo "${versionString%% .*}"
|
||||
case "$version" in
|
||||
0.7.*) echo "$base/sbt-launch-0.7.7.jar" ;;
|
||||
0.10.*) echo "$base/org.scala-tools.sbt/sbt-launch/$version/sbt-launch.jar" ;;
|
||||
0.11.[12]) echo "$base/org.scala-tools.sbt/sbt-launch/$version/sbt-launch.jar" ;;
|
||||
0.*) echo "$base/org.scala-sbt/sbt-launch/$version/sbt-launch.jar" ;;
|
||||
*) echo "$base/org/scala-sbt/sbt-launch/$version/sbt-launch-${version}.jar" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
addJava() {
|
||||
vlog "[addJava] arg = '$1'"
|
||||
java_args+=("$1")
|
||||
}
|
||||
addSbt() {
|
||||
vlog "[addSbt] arg = '$1'"
|
||||
sbt_commands+=("$1")
|
||||
}
|
||||
addScalac() {
|
||||
vlog "[addScalac] arg = '$1'"
|
||||
scalac_args+=("$1")
|
||||
}
|
||||
addResidual() {
|
||||
vlog "[residual] arg = '$1'"
|
||||
residual_args+=("$1")
|
||||
}
|
||||
|
||||
addResolver() { addSbt "set resolvers += $1"; }
|
||||
|
||||
addDebugger() { addJava "-Xdebug" && addJava "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1"; }
|
||||
|
||||
setThisBuild() {
|
||||
vlog "[addBuild] args = '$*'"
|
||||
local key="$1" && shift
|
||||
addSbt "set $key in ThisBuild := $*"
|
||||
}
|
||||
setScalaVersion() {
|
||||
[[ "$1" == *"-SNAPSHOT" ]] && addResolver 'Resolver.sonatypeRepo("snapshots")'
|
||||
addSbt "++ $1"
|
||||
}
|
||||
setJavaHome() {
|
||||
java_cmd="$1/bin/java"
|
||||
setThisBuild javaHome "_root_.scala.Some(file(\"$1\"))"
|
||||
export JAVA_HOME="$1"
|
||||
export JDK_HOME="$1"
|
||||
export PATH="$JAVA_HOME/bin:$PATH"
|
||||
}
|
||||
|
||||
getJavaVersion() {
|
||||
local -r str=$("$1" -version 2>&1 | grep -E -e '(java|openjdk) version' | awk '{ print $3 }' | tr -d '"')
|
||||
|
||||
# java -version on java8 says 1.8.x
|
||||
# but on 9 and 10 it's 9.x.y and 10.x.y.
|
||||
if [[ "$str" =~ ^1\.([0-9]+)(\..*)?$ ]]; then
|
||||
echo "${BASH_REMATCH[1]}"
|
||||
# Fixes https://github.com/dwijnand/sbt-extras/issues/326
|
||||
elif [[ "$str" =~ ^([0-9]+)(\..*)?(-ea)?$ ]]; then
|
||||
echo "${BASH_REMATCH[1]}"
|
||||
elif [[ -n "$str" ]]; then
|
||||
echoerr "Can't parse java version from: $str"
|
||||
fi
|
||||
}
|
||||
|
||||
execRunner () {
|
||||
checkJava() {
|
||||
# Warn if there is a Java version mismatch between PATH and JAVA_HOME/JDK_HOME
|
||||
|
||||
[[ -n "$JAVA_HOME" && -e "$JAVA_HOME/bin/java" ]] && java="$JAVA_HOME/bin/java"
|
||||
[[ -n "$JDK_HOME" && -e "$JDK_HOME/lib/tools.jar" ]] && java="$JDK_HOME/bin/java"
|
||||
|
||||
if [[ -n "$java" ]]; then
|
||||
pathJavaVersion=$(getJavaVersion java)
|
||||
homeJavaVersion=$(getJavaVersion "$java")
|
||||
if [[ "$pathJavaVersion" != "$homeJavaVersion" ]]; then
|
||||
echoerr "Warning: Java version mismatch between PATH and JAVA_HOME/JDK_HOME, sbt will use the one in PATH"
|
||||
echoerr " Either: fix your PATH, remove JAVA_HOME/JDK_HOME or use -java-home"
|
||||
echoerr " java version from PATH: $pathJavaVersion"
|
||||
echoerr " java version from JAVA_HOME/JDK_HOME: $homeJavaVersion"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
java_version() {
|
||||
local -r version=$(getJavaVersion "$java_cmd")
|
||||
vlog "Detected Java version: $version"
|
||||
echo "$version"
|
||||
}
|
||||
|
||||
is_apple_silicon() { [[ "$(uname -s)" == "Darwin" && "$(uname -m)" == "arm64" ]]; }
|
||||
|
||||
# MaxPermSize critical on pre-8 JVMs but incurs noisy warning on 8+
|
||||
default_jvm_opts() {
|
||||
local -r v="$(java_version)"
|
||||
if [[ $v -ge 17 ]]; then
|
||||
echo "$default_jvm_opts_common"
|
||||
elif [[ $v -ge 10 ]]; then
|
||||
if is_apple_silicon; then
|
||||
# As of Dec 2020, JVM for Apple Silicon (M1) doesn't support JVMCI
|
||||
echo "$default_jvm_opts_common"
|
||||
else
|
||||
echo "$default_jvm_opts_common -XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler"
|
||||
fi
|
||||
elif [[ $v -ge 8 ]]; then
|
||||
echo "$default_jvm_opts_common"
|
||||
else
|
||||
echo "-XX:MaxPermSize=384m $default_jvm_opts_common"
|
||||
fi
|
||||
}
|
||||
|
||||
execRunner() {
|
||||
# print the arguments one to a line, quoting any containing spaces
|
||||
[[ "$verbose" || "$debug" ]] && echo "# Executing command line:" && {
|
||||
vlog "# Executing command line:" && {
|
||||
for arg; do
|
||||
if [[ -n "$arg" ]]; then
|
||||
if printf "%s\n" "$arg" | grep -q ' '; then
|
||||
printf "\"%s\"\n" "$arg"
|
||||
printf >&2 "\"%s\"\n" "$arg"
|
||||
else
|
||||
printf "%s\n" "$arg"
|
||||
printf >&2 "%s\n" "$arg"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
echo ""
|
||||
vlog ""
|
||||
}
|
||||
|
||||
setTrapExit
|
||||
|
||||
if [[ -n "$batch" ]]; then
|
||||
exec </dev/null
|
||||
"$@" </dev/null
|
||||
else
|
||||
"$@"
|
||||
fi
|
||||
exec "$@"
|
||||
}
|
||||
|
||||
jar_url () {
|
||||
make_url "$1"
|
||||
jar_url() { make_url "$1"; }
|
||||
|
||||
is_cygwin() { [[ "$(uname -a)" == "CYGWIN"* ]]; }
|
||||
|
||||
jar_file() {
|
||||
is_cygwin &&
|
||||
cygpath -w "$sbt_launch_dir/$1/sbt-launch.jar" ||
|
||||
echo "$sbt_launch_dir/$1/sbt-launch.jar"
|
||||
}
|
||||
|
||||
jar_file () {
|
||||
echo "$sbt_launch_dir/$1/sbt-launch.jar"
|
||||
}
|
||||
|
||||
download_url () {
|
||||
download_url() {
|
||||
local url="$1"
|
||||
local jar="$2"
|
||||
|
||||
echo "Downloading sbt launcher for $(sbt_version):"
|
||||
echo " From $url"
|
||||
echo " To $jar"
|
||||
|
||||
mkdir -p "${jar%/*}" && {
|
||||
if which curl >/dev/null; then
|
||||
curl --fail --silent "$url" --output "$jar"
|
||||
elif which wget >/dev/null; then
|
||||
wget --quiet -O "$jar" "$url"
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
curl --fail --silent --location "$url" --output "$jar"
|
||||
elif command -v wget >/dev/null 2>&1; then
|
||||
wget -q -O "$jar" "$url"
|
||||
fi
|
||||
} && [[ -r "$jar" ]]
|
||||
}
|
||||
|
||||
acquire_sbt_jar () {
|
||||
for_sbt_version="$(sbt_version)"
|
||||
sbt_url="$(jar_url "$for_sbt_version")"
|
||||
sbt_jar="$(jar_file "$for_sbt_version")"
|
||||
acquire_sbt_jar() {
|
||||
{
|
||||
sbt_jar="$(jar_file "$sbt_version")"
|
||||
[[ -r "$sbt_jar" ]]
|
||||
} || {
|
||||
sbt_jar="$HOME/.ivy2/local/org.scala-sbt/sbt-launch/$sbt_version/jars/sbt-launch.jar"
|
||||
[[ -r "$sbt_jar" ]]
|
||||
} || {
|
||||
sbt_jar="$(jar_file "$sbt_version")"
|
||||
jar_url="$(make_url "$sbt_version")"
|
||||
|
||||
[[ -r "$sbt_jar" ]] || download_url "$sbt_url" "$sbt_jar"
|
||||
echoerr "Downloading sbt launcher for ${sbt_version}:"
|
||||
echoerr " From ${jar_url}"
|
||||
echoerr " To ${sbt_jar}"
|
||||
|
||||
download_url "${jar_url}" "${sbt_jar}"
|
||||
|
||||
case "${sbt_version}" in
|
||||
0.*)
|
||||
vlog "SBT versions < 1.0 do not have published MD5 checksums, skipping check"
|
||||
echo ""
|
||||
;;
|
||||
*) verify_sbt_jar "${sbt_jar}" ;;
|
||||
esac
|
||||
}
|
||||
}
|
||||
|
||||
usage () {
|
||||
verify_sbt_jar() {
|
||||
local jar="${1}"
|
||||
local md5="${jar}.md5"
|
||||
md5url="$(make_url "${sbt_version}").md5"
|
||||
|
||||
echoerr "Downloading sbt launcher ${sbt_version} md5 hash:"
|
||||
echoerr " From ${md5url}"
|
||||
echoerr " To ${md5}"
|
||||
|
||||
download_url "${md5url}" "${md5}" >/dev/null 2>&1
|
||||
|
||||
if command -v md5sum >/dev/null 2>&1; then
|
||||
if echo "$(cat "${md5}") ${jar}" | md5sum -c -; then
|
||||
rm -rf "${md5}"
|
||||
return 0
|
||||
else
|
||||
echoerr "Checksum does not match"
|
||||
return 1
|
||||
fi
|
||||
elif command -v md5 >/dev/null 2>&1; then
|
||||
if [ "$(md5 -q "${jar}")" == "$(cat "${md5}")" ]; then
|
||||
rm -rf "${md5}"
|
||||
return 0
|
||||
else
|
||||
echoerr "Checksum does not match"
|
||||
return 1
|
||||
fi
|
||||
elif command -v openssl >/dev/null 2>&1; then
|
||||
if [ "$(openssl md5 -r "${jar}" | awk '{print $1}')" == "$(cat "${md5}")" ]; then
|
||||
rm -rf "${md5}"
|
||||
return 0
|
||||
else
|
||||
echoerr "Checksum does not match"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echoerr "Could not find an MD5 command"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
usage() {
|
||||
set_sbt_version
|
||||
cat <<EOM
|
||||
Usage: $script_name [options]
|
||||
|
||||
Note that options which are passed along to sbt begin with -- whereas
|
||||
options to this runner use a single dash. Any sbt command can be scheduled
|
||||
to run first by prefixing the command with --, so --warn, --error and so on
|
||||
are not special.
|
||||
|
||||
-h | -help print this message
|
||||
-v | -verbose this runner is chattier
|
||||
-d | -debug set sbt log level to Debug
|
||||
-q | -quiet set sbt log level to Error
|
||||
-v verbose operation (this runner is chattier)
|
||||
-d, -w, -q aliases for --debug, --warn, --error (q means quiet)
|
||||
-x debug this script
|
||||
-trace <level> display stack traces with a max of <level> frames (default: -1, traces suppressed)
|
||||
-debug-inc enable debugging log for the incremental compiler
|
||||
-no-colors disable ANSI color codes
|
||||
-sbt-create start sbt even if current directory contains no sbt project
|
||||
-sbt-dir <path> path to global settings/plugins directory (default: ~/.sbt/<version>)
|
||||
@ -233,77 +410,58 @@ Usage: $script_name [options]
|
||||
-jvm-debug <port> Turn on JVM debugging, open at the given port.
|
||||
-batch Disable interactive mode
|
||||
-prompt <expr> Set the sbt prompt; in expr, 's' is the State and 'e' is Extracted
|
||||
-script <file> Run the specified file as a scala script
|
||||
|
||||
# sbt version (default: from $buildProps if present, else latest release)
|
||||
!!! The only way to accomplish this pre-0.12.0 if there is a build.properties file which
|
||||
!!! contains an sbt.version property is to update the file on disk. That's what this does.
|
||||
-sbt-version <version> use the specified version of sbt (default: $sbt_release_version)
|
||||
-sbt-jar <path> use the specified jar as the sbt launcher
|
||||
-sbt-launch-dir <path> directory to hold sbt launchers (default: $sbt_launch_dir)
|
||||
-sbt-launch-repo <url> repo url for downloading sbt launcher jar (default: $sbt_launch_repo)
|
||||
# sbt version (default: sbt.version from $buildProps if present, otherwise $sbt_release_version)
|
||||
-sbt-version <version> use the specified version of sbt (default: $sbt_release_version)
|
||||
-sbt-force-latest force the use of the latest release of sbt: $sbt_release_version
|
||||
-sbt-dev use the latest pre-release version of sbt: $sbt_unreleased_version
|
||||
-sbt-jar <path> use the specified jar as the sbt launcher
|
||||
-sbt-launch-dir <path> directory to hold sbt launchers (default: $sbt_launch_dir)
|
||||
-sbt-launch-repo <url> repo url for downloading sbt launcher jar (default: $(url_base "$sbt_version"))
|
||||
|
||||
# scala version (default: as chosen by sbt)
|
||||
-28 use $latest_28
|
||||
-29 use $latest_29
|
||||
-210 use $latest_210
|
||||
-211 use $latest_211
|
||||
-scala-home <path> use the scala build at the specified directory
|
||||
-scala-version <version> use the specified version of scala
|
||||
-binary-version <version> use the specified scala version when searching for dependencies
|
||||
-28 use $latest_28
|
||||
-29 use $latest_29
|
||||
-210 use $latest_210
|
||||
-211 use $latest_211
|
||||
-212 use $latest_212
|
||||
-213 use $latest_213
|
||||
-scala-home <path> use the scala build at the specified directory
|
||||
-scala-version <version> use the specified version of scala
|
||||
-binary-version <version> use the specified scala version when searching for dependencies
|
||||
|
||||
# java version (default: java from PATH, currently $(java -version 2>&1 | grep version))
|
||||
-java-home <path> alternate JAVA_HOME
|
||||
-java-home <path> alternate JAVA_HOME
|
||||
|
||||
# passing options to the jvm - note it does NOT use JAVA_OPTS due to pollution
|
||||
# The default set is used if JVM_OPTS is unset and no -jvm-opts file is found
|
||||
<default> $default_jvm_opts
|
||||
JVM_OPTS environment variable holding either the jvm args directly, or
|
||||
the reference to a file containing jvm args if given path is prepended by '@' (e.g. '@/etc/jvmopts')
|
||||
Note: "@"-file is overridden by local '.jvmopts' or '-jvm-opts' argument.
|
||||
-jvm-opts <path> file containing jvm args (if not given, .jvmopts in project root is used if present)
|
||||
-Dkey=val pass -Dkey=val directly to the jvm
|
||||
-J-X pass option -X directly to the jvm (-J is stripped)
|
||||
<default> $(default_jvm_opts)
|
||||
JVM_OPTS environment variable holding either the jvm args directly, or
|
||||
the reference to a file containing jvm args if given path is prepended by '@' (e.g. '@/etc/jvmopts')
|
||||
Note: "@"-file is overridden by local '.jvmopts' or '-jvm-opts' argument.
|
||||
-jvm-opts <path> file containing jvm args (if not given, .jvmopts in project root is used if present)
|
||||
-Dkey=val pass -Dkey=val directly to the jvm
|
||||
-J-X pass option -X directly to the jvm (-J is stripped)
|
||||
|
||||
# passing options to sbt, OR to this runner
|
||||
SBT_OPTS environment variable holding either the sbt args directly, or
|
||||
the reference to a file containing sbt args if given path is prepended by '@' (e.g. '@/etc/sbtopts')
|
||||
Note: "@"-file is overridden by local '.sbtopts' or '-sbt-opts' argument.
|
||||
-sbt-opts <path> file containing sbt args (if not given, .sbtopts in project root is used if present)
|
||||
-S-X add -X to sbt's scalacOptions (-S is stripped)
|
||||
SBT_OPTS environment variable holding either the sbt args directly, or
|
||||
the reference to a file containing sbt args if given path is prepended by '@' (e.g. '@/etc/sbtopts')
|
||||
Note: "@"-file is overridden by local '.sbtopts' or '-sbt-opts' argument.
|
||||
-sbt-opts <path> file containing sbt args (if not given, .sbtopts in project root is used if present)
|
||||
-S-X add -X to sbt's scalacOptions (-S is stripped)
|
||||
|
||||
# passing options exclusively to this runner
|
||||
SBTX_OPTS environment variable holding either the sbt-extras args directly, or
|
||||
the reference to a file containing sbt-extras args if given path is prepended by '@' (e.g. '@/etc/sbtxopts')
|
||||
Note: "@"-file is overridden by local '.sbtxopts' or '-sbtx-opts' argument.
|
||||
-sbtx-opts <path> file containing sbt-extras args (if not given, .sbtxopts in project root is used if present)
|
||||
EOM
|
||||
exit 0
|
||||
}
|
||||
|
||||
addJava () {
|
||||
dlog "[addJava] arg = '$1'"
|
||||
java_args=( "${java_args[@]}" "$1" )
|
||||
}
|
||||
addSbt () {
|
||||
dlog "[addSbt] arg = '$1'"
|
||||
sbt_commands=( "${sbt_commands[@]}" "$1" )
|
||||
}
|
||||
addScalac () {
|
||||
dlog "[addScalac] arg = '$1'"
|
||||
scalac_args=( "${scalac_args[@]}" "$1" )
|
||||
}
|
||||
addResidual () {
|
||||
dlog "[residual] arg = '$1'"
|
||||
residual_args=( "${residual_args[@]}" "$1" )
|
||||
}
|
||||
addResolver () {
|
||||
addSbt "set resolvers += $1"
|
||||
}
|
||||
addDebugger () {
|
||||
addJava "-Xdebug"
|
||||
addJava "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1"
|
||||
}
|
||||
setScalaVersion () {
|
||||
[[ "$1" == *"-SNAPSHOT" ]] && addResolver 'Resolver.sonatypeRepo("snapshots")'
|
||||
addSbt "++ $1"
|
||||
}
|
||||
|
||||
process_args ()
|
||||
{
|
||||
require_arg () {
|
||||
process_args() {
|
||||
require_arg() {
|
||||
local type="$1"
|
||||
local opt="$2"
|
||||
local arg="$3"
|
||||
@ -314,45 +472,56 @@ process_args ()
|
||||
}
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-h|-help) usage; exit 1 ;;
|
||||
-v|-verbose) verbose=true && log_level=Info && shift ;;
|
||||
-d|-debug) debug=true && log_level=Debug && shift ;;
|
||||
-q|-quiet) quiet=true && log_level=Error && shift ;;
|
||||
-h | -help) usage ;;
|
||||
-v) verbose=true && shift ;;
|
||||
-d) addSbt "--debug" && shift ;;
|
||||
-w) addSbt "--warn" && shift ;;
|
||||
-q) addSbt "--error" && shift ;;
|
||||
-x) shift ;; # currently unused
|
||||
-trace) require_arg integer "$1" "$2" && trace_level="$2" && shift 2 ;;
|
||||
-debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;;
|
||||
|
||||
-trace) require_arg integer "$1" "$2" && trace_level="$2" && shift 2 ;;
|
||||
-ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;;
|
||||
-no-colors) addJava "-Dsbt.log.noformat=true" && shift ;;
|
||||
-no-share) noshare=true && shift ;;
|
||||
-sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;;
|
||||
-sbt-dir) require_arg path "$1" "$2" && sbt_dir="$2" && shift 2 ;;
|
||||
-debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;;
|
||||
-offline) addSbt "set offline := true" && shift ;;
|
||||
-jvm-debug) require_arg port "$1" "$2" && addDebugger "$2" && shift 2 ;;
|
||||
-batch) batch=true && shift ;;
|
||||
-prompt) require_arg "expr" "$1" "$2" && addSbt "set shellPrompt in ThisBuild := (s => { val e = Project.extract(s) ; $2 })" && shift 2 ;;
|
||||
-no-colors) addJava "-Dsbt.log.noformat=true" && addJava "-Dsbt.color=false" && shift ;;
|
||||
-sbt-create) sbt_create=true && shift ;;
|
||||
-sbt-dir) require_arg path "$1" "$2" && sbt_dir="$2" && shift 2 ;;
|
||||
-sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;;
|
||||
-ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;;
|
||||
-no-share) noshare=true && shift ;;
|
||||
-offline) addSbt "set offline in Global := true" && shift ;;
|
||||
-jvm-debug) require_arg port "$1" "$2" && addDebugger "$2" && shift 2 ;;
|
||||
-batch) batch=true && shift ;;
|
||||
-prompt) require_arg "expr" "$1" "$2" && setThisBuild shellPrompt "(s => { val e = Project.extract(s) ; $2 })" && shift 2 ;;
|
||||
-script) require_arg file "$1" "$2" && sbt_script="$2" && addJava "-Dsbt.main.class=sbt.ScriptMain" && shift 2 ;;
|
||||
|
||||
-sbt-create) sbt_create=true && shift ;;
|
||||
-sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;;
|
||||
-sbt-version) require_arg version "$1" "$2" && sbt_explicit_version="$2" && shift 2 ;;
|
||||
-sbt-dev) sbt_explicit_version="$sbt_unreleased_version" && shift ;;
|
||||
-sbt-launch-dir) require_arg path "$1" "$2" && sbt_launch_dir="$2" && shift 2 ;;
|
||||
-sbt-launch-repo) require_arg path "$1" "$2" && sbt_launch_repo="$2" && shift 2 ;;
|
||||
-scala-version) require_arg version "$1" "$2" && setScalaVersion "$2" && shift 2 ;;
|
||||
-binary-version) require_arg version "$1" "$2" && addSbt "set scalaBinaryVersion in ThisBuild := \"$2\"" && shift 2 ;;
|
||||
-scala-home) require_arg path "$1" "$2" && addSbt "set every scalaHome := Some(file(\"$2\"))" && shift 2 ;;
|
||||
-java-home) require_arg path "$1" "$2" && java_cmd="$2/bin/java" && shift 2 ;;
|
||||
-sbt-opts) require_arg path "$1" "$2" && sbt_opts_file="$2" && shift 2 ;;
|
||||
-jvm-opts) require_arg path "$1" "$2" && jvm_opts_file="$2" && shift 2 ;;
|
||||
-sbt-version) require_arg version "$1" "$2" && sbt_explicit_version="$2" && shift 2 ;;
|
||||
-sbt-force-latest) sbt_explicit_version="$sbt_release_version" && shift ;;
|
||||
-sbt-dev) sbt_explicit_version="$sbt_unreleased_version" && shift ;;
|
||||
-sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;;
|
||||
-sbt-launch-dir) require_arg path "$1" "$2" && sbt_launch_dir="$2" && shift 2 ;;
|
||||
-sbt-launch-repo) require_arg path "$1" "$2" && sbt_launch_repo="$2" && shift 2 ;;
|
||||
|
||||
-D*) addJava "$1" && shift ;;
|
||||
-J*) addJava "${1:2}" && shift ;;
|
||||
-S*) addScalac "${1:2}" && shift ;;
|
||||
-28) setScalaVersion "$latest_28" && shift ;;
|
||||
-29) setScalaVersion "$latest_29" && shift ;;
|
||||
-210) setScalaVersion "$latest_210" && shift ;;
|
||||
-211) setScalaVersion "$latest_211" && shift ;;
|
||||
-28) setScalaVersion "$latest_28" && shift ;;
|
||||
-29) setScalaVersion "$latest_29" && shift ;;
|
||||
-210) setScalaVersion "$latest_210" && shift ;;
|
||||
-211) setScalaVersion "$latest_211" && shift ;;
|
||||
-212) setScalaVersion "$latest_212" && shift ;;
|
||||
-213) setScalaVersion "$latest_213" && shift ;;
|
||||
|
||||
*) addResidual "$1" && shift ;;
|
||||
-scala-version) require_arg version "$1" "$2" && setScalaVersion "$2" && shift 2 ;;
|
||||
-binary-version) require_arg version "$1" "$2" && setThisBuild scalaBinaryVersion "\"$2\"" && shift 2 ;;
|
||||
-scala-home) require_arg path "$1" "$2" && setThisBuild scalaHome "_root_.scala.Some(file(\"$2\"))" && shift 2 ;;
|
||||
-java-home) require_arg path "$1" "$2" && setJavaHome "$2" && shift 2 ;;
|
||||
-sbt-opts) require_arg path "$1" "$2" && sbt_opts_file="$2" && shift 2 ;;
|
||||
-sbtx-opts) require_arg path "$1" "$2" && sbtx_opts_file="$2" && shift 2 ;;
|
||||
-jvm-opts) require_arg path "$1" "$2" && jvm_opts_file="$2" && shift 2 ;;
|
||||
|
||||
-D*) addJava "$1" && shift ;;
|
||||
-J*) addJava "${1:2}" && shift ;;
|
||||
-S*) addScalac "${1:2}" && shift ;;
|
||||
|
||||
new) sbt_new=true && : ${sbt_explicit_version:=$sbt_release_version} && addResidual "$1" && shift ;;
|
||||
|
||||
*) addResidual "$1" && shift ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
@ -362,58 +531,74 @@ process_args "$@"
|
||||
|
||||
# skip #-styled comments and blank lines
|
||||
readConfigFile() {
|
||||
while read line; do
|
||||
[[ $line =~ ^# ]] || [[ -z $line ]] || echo "$line"
|
||||
done < "$1"
|
||||
local end=false
|
||||
until $end; do
|
||||
read -r || end=true
|
||||
[[ $REPLY =~ ^# ]] || [[ -z $REPLY ]] || echo "$REPLY"
|
||||
done <"$1"
|
||||
}
|
||||
|
||||
# if there are file/environment sbt_opts, process again so we
|
||||
# can supply args to this runner
|
||||
if [[ -r "$sbt_opts_file" ]]; then
|
||||
vlog "Using sbt options defined in file $sbt_opts_file"
|
||||
while read opt; do extra_sbt_opts+=("$opt"); done < <(readConfigFile "$sbt_opts_file")
|
||||
while read -r opt; do extra_sbt_opts+=("$opt"); done < <(readConfigFile "$sbt_opts_file")
|
||||
elif [[ -n "$SBT_OPTS" && ! ("$SBT_OPTS" =~ ^@.*) ]]; then
|
||||
vlog "Using sbt options defined in variable \$SBT_OPTS"
|
||||
extra_sbt_opts=( $SBT_OPTS )
|
||||
IFS=" " read -r -a extra_sbt_opts <<<"$SBT_OPTS"
|
||||
else
|
||||
vlog "No extra sbt options have been defined"
|
||||
fi
|
||||
|
||||
[[ -n "$extra_sbt_opts" ]] && process_args "${extra_sbt_opts[@]}"
|
||||
# if there are file/environment sbtx_opts, process again so we
|
||||
# can supply args to this runner
|
||||
if [[ -r "$sbtx_opts_file" ]]; then
|
||||
vlog "Using sbt options defined in file $sbtx_opts_file"
|
||||
while read -r opt; do extra_sbt_opts+=("$opt"); done < <(readConfigFile "$sbtx_opts_file")
|
||||
elif [[ -n "$SBTX_OPTS" && ! ("$SBTX_OPTS" =~ ^@.*) ]]; then
|
||||
vlog "Using sbt options defined in variable \$SBTX_OPTS"
|
||||
IFS=" " read -r -a extra_sbt_opts <<<"$SBTX_OPTS"
|
||||
else
|
||||
vlog "No extra sbt options have been defined"
|
||||
fi
|
||||
|
||||
[[ -n "${extra_sbt_opts[*]}" ]] && process_args "${extra_sbt_opts[@]}"
|
||||
|
||||
# reset "$@" to the residual args
|
||||
set -- "${residual_args[@]}"
|
||||
argumentCount=$#
|
||||
|
||||
# set sbt version
|
||||
set_sbt_version
|
||||
|
||||
checkJava
|
||||
|
||||
# only exists in 0.12+
|
||||
setTraceLevel() {
|
||||
case "$(sbt_version)" in
|
||||
"0.7."* | "0.10."* | "0.11."* )
|
||||
echoerr "Cannot set trace level in sbt version $(sbt_version)"
|
||||
;;
|
||||
*)
|
||||
addSbt "set every traceLevel := $trace_level"
|
||||
;;
|
||||
case "$sbt_version" in
|
||||
"0.7."* | "0.10."* | "0.11."*) echoerr "Cannot set trace level in sbt version $sbt_version" ;;
|
||||
*) setThisBuild traceLevel "$trace_level" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# set scalacOptions if we were given any -S opts
|
||||
[[ ${#scalac_args[@]} -eq 0 ]] || addSbt "set scalacOptions in ThisBuild += \"${scalac_args[@]}\""
|
||||
[[ ${#scalac_args[@]} -eq 0 ]] || addSbt "set scalacOptions in ThisBuild += \"${scalac_args[*]}\""
|
||||
|
||||
# Update build.properties on disk to set explicit version - sbt gives us no choice
|
||||
[[ -n "$sbt_explicit_version" ]] && update_build_props_sbt "$sbt_explicit_version"
|
||||
vlog "Detected sbt version $(sbt_version)"
|
||||
[[ -n "$sbt_explicit_version" && -z "$sbt_new" ]] && addJava "-Dsbt.version=$sbt_explicit_version"
|
||||
vlog "Detected sbt version $sbt_version"
|
||||
|
||||
[[ -n "$scala_version" ]] && echoerr "Overriding scala version to $scala_version"
|
||||
if [[ -n "$sbt_script" ]]; then
|
||||
residual_args=("$sbt_script" "${residual_args[@]}")
|
||||
else
|
||||
# no args - alert them there's stuff in here
|
||||
((argumentCount > 0)) || {
|
||||
vlog "Starting $script_name: invoke with -help for other options"
|
||||
residual_args=(shell)
|
||||
}
|
||||
fi
|
||||
|
||||
# no args - alert them there's stuff in here
|
||||
(( argumentCount > 0 )) || {
|
||||
vlog "Starting $script_name: invoke with -help for other options"
|
||||
residual_args=( shell )
|
||||
}
|
||||
|
||||
# verify this is an sbt dir or -create was given
|
||||
[[ -r ./build.sbt || -d ./project || -n "$sbt_create" ]] || {
|
||||
# verify this is an sbt dir, -create was given or user attempts to run a scala script
|
||||
[[ -r ./build.sbt || -d ./project || -n "$sbt_create" || -n "$sbt_script" || -n "$sbt_new" ]] || {
|
||||
cat <<EOM
|
||||
$(pwd) doesn't appear to be an sbt project.
|
||||
If you want to start sbt anyway, run:
|
||||
@ -424,12 +609,17 @@ EOM
|
||||
}
|
||||
|
||||
# pick up completion if present; todo
|
||||
# shellcheck disable=SC1091
|
||||
[[ -r .sbt_completion.sh ]] && source .sbt_completion.sh
|
||||
|
||||
# directory to store sbt launchers
|
||||
[[ -d "$sbt_launch_dir" ]] || mkdir -p "$sbt_launch_dir"
|
||||
[[ -w "$sbt_launch_dir" ]] || sbt_launch_dir="$(mktemp -d -t sbt_extras_launchers.XXXXXX)"
|
||||
|
||||
# no jar? download it.
|
||||
[[ -r "$sbt_jar" ]] || acquire_sbt_jar || {
|
||||
# still no jar? uh-oh.
|
||||
echo "Download failed. Obtain the jar manually and place it at $sbt_jar"
|
||||
echo "Could not download and verify the launcher. Obtain the jar manually and place it at $sbt_jar"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@ -438,13 +628,13 @@ if [[ -n "$noshare" ]]; then
|
||||
addJava "$opt"
|
||||
done
|
||||
else
|
||||
case "$(sbt_version)" in
|
||||
"0.7."* | "0.10."* | "0.11."* | "0.12."* )
|
||||
case "$sbt_version" in
|
||||
"0.7."* | "0.10."* | "0.11."* | "0.12."*)
|
||||
[[ -n "$sbt_dir" ]] || {
|
||||
sbt_dir="$HOME/.sbt/$(sbt_version)"
|
||||
sbt_dir="$HOME/.sbt/$sbt_version"
|
||||
vlog "Using $sbt_dir as sbt dir, -sbt-dir to override."
|
||||
}
|
||||
;;
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ -n "$sbt_dir" ]]; then
|
||||
@ -454,25 +644,18 @@ fi
|
||||
|
||||
if [[ -r "$jvm_opts_file" ]]; then
|
||||
vlog "Using jvm options defined in file $jvm_opts_file"
|
||||
while read opt; do extra_jvm_opts+=("$opt"); done < <(readConfigFile "$jvm_opts_file")
|
||||
while read -r opt; do extra_jvm_opts+=("$opt"); done < <(readConfigFile "$jvm_opts_file")
|
||||
elif [[ -n "$JVM_OPTS" && ! ("$JVM_OPTS" =~ ^@.*) ]]; then
|
||||
vlog "Using jvm options defined in \$JVM_OPTS variable"
|
||||
extra_jvm_opts=( $JVM_OPTS )
|
||||
IFS=" " read -r -a extra_jvm_opts <<<"$JVM_OPTS"
|
||||
else
|
||||
vlog "Using default jvm options"
|
||||
extra_jvm_opts=( $default_jvm_opts )
|
||||
IFS=" " read -r -a extra_jvm_opts <<<"$( default_jvm_opts)"
|
||||
fi
|
||||
|
||||
# traceLevel is 0.12+
|
||||
[[ -n "$trace_level" ]] && setTraceLevel
|
||||
|
||||
|
||||
if [[ -n "$log_level" ]] && [[ "$log_level" != Info ]]; then
|
||||
sbt_commands=("set logLevel in Global := Level.$log_level" "${sbt_commands[@]}")
|
||||
fi
|
||||
|
||||
|
||||
# run sbt
|
||||
execRunner "$java_cmd" \
|
||||
"${extra_jvm_opts[@]}" \
|
||||
"${java_args[@]}" \
|
||||
|
21
script/dynver.sh
Executable file
21
script/dynver.sh
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Compute sbt-dynver-compatible version number
|
||||
BUILD_TIME=`date '+%Y%m%d-%H%M'`
|
||||
DYN_VER=`git describe --long --tags --abbrev=8 --match "v[0-9]*" --always --dirty="-${BUILD_TIME}"`
|
||||
GIT_DIST=`echo ${DYN_VER} | sed -re "s/v([^-]*)-([0-9]+)-g(.*)/\2/g"`
|
||||
GIT_TAG=`git describe --tags --dirty`
|
||||
RELEASE_VERSION=`echo ${DYN_VER} | sed -re "s/v([^-]*)-([0-9]+)-g(.*)/\1/g"`
|
||||
SNAPSHOT_VERSION=`echo ${DYN_VER} | sed -re "s/v([^-]*)-([0-9]+)-g(.*)/\1-\2-\3/g"`-SNAPSHOT
|
||||
|
||||
if [ ${GIT_DIST} -eq 0 ]; then
|
||||
if [ ${GIT_TAG} == *"-dirty" ]; then
|
||||
VERSION=${SNAPSHOT_VERSION}
|
||||
else
|
||||
VERSION=${RELEASE_VERSION}
|
||||
fi
|
||||
else
|
||||
VERSION=${SNAPSHOT_VERSION}
|
||||
fi
|
||||
|
||||
echo ${VERSION}
|
15
script/travis-deploy.sh
Executable file
15
script/travis-deploy.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
set -ev
|
||||
|
||||
VERSION=`perl -npe "s/version in ThisBuild\s+:=\s+\"(.*)\"/\1/" version.sbt | sed -e "/^$/d"`
|
||||
|
||||
# Deploy a snapshot version only for master branch and jdk8
|
||||
if [[ "$TRAVIS_JDK_VERSION" == "oraclejdk8" ]]; then
|
||||
if [[ "$TRAVIS_PULL_REQUEST" == "false" ]] && [[ "$VERSION" == *SNAPSHOT ]]; then
|
||||
./sbt "; test; publish";
|
||||
else
|
||||
./sbt test;
|
||||
fi;
|
||||
else
|
||||
./sbt test;
|
||||
fi;
|
117
src/checkstyle/checks.xml
Normal file
117
src/checkstyle/checks.xml
Normal file
@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE module PUBLIC
|
||||
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
||||
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
|
||||
<module name="Checker">
|
||||
<module name="FileTabCharacter"/>
|
||||
<module name="NewlineAtEndOfFile">
|
||||
<property name="lineSeparator" value="lf"/>
|
||||
</module>
|
||||
<module name="RegexpMultiline">
|
||||
<property name="format" value="\r"/>
|
||||
<property name="message" value="Line contains carriage return"/>
|
||||
</module>
|
||||
<module name="RegexpMultiline">
|
||||
<property name="format" value=" \n"/>
|
||||
<property name="message" value="Line has trailing whitespace"/>
|
||||
</module>
|
||||
<module name="RegexpMultiline">
|
||||
<property name="format" value="\{\n\n"/>
|
||||
<property name="message" value="Blank line after opening brace"/>
|
||||
</module>
|
||||
<module name="RegexpMultiline">
|
||||
<property name="format" value="\n\n\}"/>
|
||||
<property name="message" value="Blank line before closing brace"/>
|
||||
</module>
|
||||
<module name="RegexpMultiline">
|
||||
<property name="format" value="\n\n\n"/>
|
||||
<property name="message" value="Multiple consecutive blank lines"/>
|
||||
</module>
|
||||
<module name="RegexpMultiline">
|
||||
<property name="format" value="\n\n\Z"/>
|
||||
<property name="message" value="Blank line before end of file"/>
|
||||
</module>
|
||||
|
||||
<module name="TreeWalker">
|
||||
<module name="EmptyBlock">
|
||||
<property name="option" value="text"/>
|
||||
<property name="tokens" value="
|
||||
LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_IF,
|
||||
LITERAL_FOR, LITERAL_TRY, LITERAL_WHILE, INSTANCE_INIT, STATIC_INIT"/>
|
||||
</module>
|
||||
<module name="EmptyStatement"/>
|
||||
<module name="EmptyForInitializerPad"/>
|
||||
<module name="EmptyForIteratorPad">
|
||||
<property name="option" value="space"/>
|
||||
</module>
|
||||
<module name="MethodParamPad">
|
||||
<property name="allowLineBreaks" value="true"/>
|
||||
<property name="option" value="nospace"/>
|
||||
</module>
|
||||
<module name="ParenPad"/>
|
||||
<module name="TypecastParenPad"/>
|
||||
<module name="NeedBraces"/>
|
||||
<module name="LeftCurly">
|
||||
<property name="option" value="nl"/>
|
||||
<property name="tokens" value="CLASS_DEF, CTOR_DEF, INTERFACE_DEF, METHOD_DEF"/>
|
||||
</module>
|
||||
<module name="LeftCurly">
|
||||
<property name="option" value="eol"/>
|
||||
<property name="tokens" value="
|
||||
LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR,
|
||||
LITERAL_IF, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE"/>
|
||||
</module>
|
||||
<module name="RightCurly">
|
||||
<property name="option" value="alone"/>
|
||||
</module>
|
||||
<module name="GenericWhitespace"/>
|
||||
<module name="WhitespaceAfter"/>
|
||||
<module name="NoWhitespaceBefore"/>
|
||||
|
||||
<module name="UpperEll"/>
|
||||
<module name="DefaultComesLast"/>
|
||||
<module name="ArrayTypeStyle"/>
|
||||
<module name="MultipleVariableDeclarations"/>
|
||||
<module name="ModifierOrder"/>
|
||||
<module name="OneStatementPerLine"/>
|
||||
<module name="StringLiteralEquality"/>
|
||||
<module name="MutableException"/>
|
||||
<module name="EqualsHashCode"/>
|
||||
<module name="InnerAssignment"/>
|
||||
<module name="InterfaceIsType"/>
|
||||
<module name="HideUtilityClassConstructor"/>
|
||||
|
||||
<module name="MemberName"/>
|
||||
<module name="LocalVariableName"/>
|
||||
<module name="LocalFinalVariableName"/>
|
||||
<module name="TypeName"/>
|
||||
<module name="PackageName"/>
|
||||
<module name="ParameterName"/>
|
||||
<module name="StaticVariableName"/>
|
||||
<module name="ClassTypeParameterName">
|
||||
<property name="format" value="^[A-Z][0-9]?$"/>
|
||||
</module>
|
||||
<module name="MethodTypeParameterName">
|
||||
<property name="format" value="^[A-Z][0-9]?$"/>
|
||||
</module>
|
||||
|
||||
<module name="AvoidStarImport"/>
|
||||
<module name="RedundantImport"/>
|
||||
<module name="UnusedImports"/>
|
||||
|
||||
<module name="WhitespaceAround">
|
||||
<property name="allowEmptyConstructors" value="true"/>
|
||||
<property name="allowEmptyMethods" value="true"/>
|
||||
<property name="ignoreEnhancedForColon" value="false"/>
|
||||
<property name="tokens" value="
|
||||
ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN,
|
||||
BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, EQUAL, GE, GT, LAND, LE,
|
||||
LITERAL_ASSERT, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE,
|
||||
LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
|
||||
LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE,
|
||||
LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL,
|
||||
PLUS, PLUS_ASSIGN, QUESTION, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN,
|
||||
STAR, STAR_ASSIGN, TYPE_EXTENSION_AND"/>
|
||||
</module>
|
||||
</module>
|
||||
</module>
|
280
src/main/java/org/xerial/snappy/BitShuffle.java
Normal file
280
src/main/java/org/xerial/snappy/BitShuffle.java
Normal file
@ -0,0 +1,280 @@
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
//--------------------------------------
|
||||
// snappy-java Project
|
||||
//
|
||||
// BitShuffle.java
|
||||
// Since: 2016/03/31
|
||||
//
|
||||
// $URL$
|
||||
// $Author$
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class BitShuffle
|
||||
{
|
||||
static {
|
||||
try {
|
||||
impl = SnappyLoader.loadBitShuffleApi();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An instance of BitShuffleNative
|
||||
*/
|
||||
private static BitShuffleNative impl;
|
||||
|
||||
/**
|
||||
* Apply a bit-shuffling filter into the content in the given input buffer. After bit-shuffling,
|
||||
* you can retrieve the shuffled data from the output buffer [pos() ...limit())
|
||||
* (shuffled data size = limit() - pos() = remaining()).
|
||||
*
|
||||
* @param input buffer[pos() ... limit()) containing the input data
|
||||
* @param type element type of the input data
|
||||
* @param shuffled output of the shuffled data. Uses range [pos()..].
|
||||
* @return byte size of the shuffled data.
|
||||
* @throws SnappyError when the input is not a direct buffer
|
||||
* @throws IllegalArgumentException when the input length is not a multiple of the given type size
|
||||
*/
|
||||
public static int shuffle(ByteBuffer input, BitShuffleType type, ByteBuffer shuffled) throws IOException {
|
||||
if (!input.isDirect()) {
|
||||
throw new SnappyError(SnappyErrorCode.NOT_A_DIRECT_BUFFER, "input is not a direct buffer");
|
||||
}
|
||||
if (!shuffled.isDirect()) {
|
||||
throw new SnappyError(SnappyErrorCode.NOT_A_DIRECT_BUFFER, "destination is not a direct buffer");
|
||||
}
|
||||
|
||||
// input: input[pos(), limit())
|
||||
// output: shuffled
|
||||
int uPos = input.position();
|
||||
int uLen = input.remaining();
|
||||
int typeSize = type.getTypeSize();
|
||||
if (uLen % typeSize != 0) {
|
||||
throw new IllegalArgumentException("input length must be a multiple of the given type size: " + typeSize);
|
||||
}
|
||||
if (shuffled.remaining() < uLen) {
|
||||
throw new IllegalArgumentException("not enough space for output");
|
||||
}
|
||||
int numProcessed = impl.shuffleDirectBuffer(input, uPos, typeSize, uLen, shuffled, shuffled.position());
|
||||
assert(numProcessed == uLen);
|
||||
|
||||
// pos limit
|
||||
// [ ......BBBBBBB.........]
|
||||
shuffled.limit(shuffled.position() + numProcessed);
|
||||
return numProcessed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a bit-shuffling filter into the input short array.
|
||||
*
|
||||
* @param input
|
||||
* @return bit-shuffled byte array
|
||||
* @throws IOException
|
||||
*/
|
||||
public static byte[] shuffle(short[] input) throws IOException {
|
||||
if (input.length * 2 < input.length) {
|
||||
throw new SnappyError(SnappyErrorCode.TOO_LARGE_INPUT, "input array size is too large: " + input.length);
|
||||
}
|
||||
byte[] output = new byte[input.length * 2];
|
||||
int numProcessed = impl.shuffle(input, 0, 2, input.length * 2, output, 0);
|
||||
assert(numProcessed == input.length * 2);
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a bit-shuffling filter into the input int array.
|
||||
*
|
||||
* @param input
|
||||
* @return bit-shuffled byte array
|
||||
* @throws IOException
|
||||
*/
|
||||
public static byte[] shuffle(int[] input) throws IOException {
|
||||
if (input.length * 4 < input.length) {
|
||||
throw new SnappyError(SnappyErrorCode.TOO_LARGE_INPUT, "input array size is too large: " + input.length);
|
||||
}
|
||||
byte[] output = new byte[input.length * 4];
|
||||
int numProcessed = impl.shuffle(input, 0, 4, input.length * 4, output, 0);
|
||||
assert(numProcessed == input.length * 4);
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a bit-shuffling filter into the input long array.
|
||||
*
|
||||
* @param input
|
||||
* @return bit-shuffled byte array
|
||||
* @throws IOException
|
||||
*/
|
||||
public static byte[] shuffle(long[] input) throws IOException {
|
||||
if (input.length * 8 < input.length) {
|
||||
throw new SnappyError(SnappyErrorCode.TOO_LARGE_INPUT, "input array size is too large: " + input.length);
|
||||
}
|
||||
byte[] output = new byte[input.length * 8];
|
||||
int numProcessed = impl.shuffle(input, 0, 8, input.length * 8, output, 0);
|
||||
assert(numProcessed == input.length * 8);
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a bit-shuffling filter into the input float array.
|
||||
*
|
||||
* @param input
|
||||
* @return bit-shuffled byte array
|
||||
* @throws IOException
|
||||
*/
|
||||
public static byte[] shuffle(float[] input) throws IOException {
|
||||
if (input.length * 4 < input.length) {
|
||||
throw new SnappyError(SnappyErrorCode.TOO_LARGE_INPUT, "input array size is too large: " + input.length);
|
||||
}
|
||||
byte[] output = new byte[input.length * 4];
|
||||
int numProcessed = impl.shuffle(input, 0, 4, input.length * 4, output, 0);
|
||||
assert(numProcessed == input.length * 4);
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a bit-shuffling filter into the input double array.
|
||||
*
|
||||
* @param input
|
||||
* @return bit-shuffled byte array
|
||||
* @throws IOException
|
||||
*/
|
||||
public static byte[] shuffle(double[] input) throws IOException {
|
||||
if (input.length * 8 < input.length) {
|
||||
throw new SnappyError(SnappyErrorCode.TOO_LARGE_INPUT, "input array size is too large: " + input.length);
|
||||
}
|
||||
byte[] output = new byte[input.length * 8];
|
||||
int numProcessed = impl.shuffle(input, 0, 8, input.length * 8, output, 0);
|
||||
assert(numProcessed == input.length * 8);
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the input bit-shuffled byte array into an original array. The result is dumped
|
||||
* to the specified output buffer.
|
||||
*
|
||||
* @param shuffled buffer[pos() ... limit()) containing the input shuffled data
|
||||
* @param type element type of the input data
|
||||
* @param output output of the the original data. It uses buffer[pos()..]
|
||||
* @return byte size of the unshuffled data.
|
||||
* @throws IOException when failed to unshuffle the given input
|
||||
* @throws SnappyError when the input is not a direct buffer
|
||||
* @throws IllegalArgumentException when the length of input shuffled data is not a multiple of the given type size
|
||||
*/
|
||||
public static int unshuffle(ByteBuffer shuffled, BitShuffleType type, ByteBuffer output) throws IOException {
|
||||
if (!shuffled.isDirect()) {
|
||||
throw new SnappyError(SnappyErrorCode.NOT_A_DIRECT_BUFFER, "input is not a direct buffer");
|
||||
}
|
||||
if (!output.isDirect()) {
|
||||
throw new SnappyError(SnappyErrorCode.NOT_A_DIRECT_BUFFER, "destination is not a direct buffer");
|
||||
}
|
||||
|
||||
// input: input[pos(), limit())
|
||||
// output: shuffled
|
||||
int uPos = shuffled.position();
|
||||
int uLen = shuffled.remaining();
|
||||
int typeSize = type.getTypeSize();
|
||||
if (uLen % typeSize != 0) {
|
||||
throw new IllegalArgumentException("length of input shuffled data must be a multiple of the given type size: " + typeSize);
|
||||
}
|
||||
if (output.remaining() < uLen) {
|
||||
throw new IllegalArgumentException("not enough space for output");
|
||||
}
|
||||
int numProcessed = impl.unshuffleDirectBuffer(shuffled, uPos, typeSize, uLen, output, shuffled.position());
|
||||
assert(numProcessed == uLen);
|
||||
|
||||
// pos limit
|
||||
// [ ......BBBBBBB.........]
|
||||
shuffled.limit(shuffled.position() + numProcessed);
|
||||
return numProcessed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the input bit-shuffled byte array into an original short array.
|
||||
*
|
||||
* @param input
|
||||
* @return a short array
|
||||
* @throws IOException
|
||||
*/
|
||||
public static short[] unshuffleShortArray(byte[] input) throws IOException {
|
||||
short[] output = new short[input.length / 2];
|
||||
int numProcessed = impl.unshuffle(input, 0, 2, input.length, output, 0);
|
||||
assert(numProcessed == input.length);
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the input bit-shuffled byte array into an original int array.
|
||||
*
|
||||
* @param input
|
||||
* @return an int array
|
||||
* @throws IOException
|
||||
*/
|
||||
public static int[] unshuffleIntArray(byte[] input) throws IOException {
|
||||
int[] output = new int[input.length / 4];
|
||||
int numProcessed = impl.unshuffle(input, 0, 4, input.length, output, 0);
|
||||
assert(numProcessed == input.length);
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the input bit-shuffled byte array into an original long array.
|
||||
*
|
||||
* @param input
|
||||
* @return a long array
|
||||
* @throws IOException
|
||||
*/
|
||||
public static long[] unshuffleLongArray(byte[] input) throws IOException {
|
||||
long[] output = new long[input.length / 8];
|
||||
int numProcessed = impl.unshuffle(input, 0, 8, input.length, output, 0);
|
||||
assert(numProcessed == input.length);
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the input bit-shuffled byte array into an original float array.
|
||||
*
|
||||
* @param input
|
||||
* @return an float array
|
||||
* @throws IOException
|
||||
*/
|
||||
public static float[] unshuffleFloatArray(byte[] input) throws IOException {
|
||||
float[] output = new float[input.length / 4];
|
||||
int numProcessed = impl.unshuffle(input, 0, 4, input.length, output, 0);
|
||||
assert(numProcessed == input.length);
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the input bit-shuffled byte array into an original double array.
|
||||
*
|
||||
* @param input
|
||||
* @return a double array
|
||||
* @throws IOException
|
||||
*/
|
||||
public static double[] unshuffleDoubleArray(byte[] input) throws IOException {
|
||||
double[] output = new double[input.length / 8];
|
||||
int numProcessed = impl.unshuffle(input, 0, 8, input.length, output, 0);
|
||||
assert(numProcessed == input.length);
|
||||
return output;
|
||||
}
|
||||
}
|
133
src/main/java/org/xerial/snappy/BitShuffleNative.cpp
Executable file
133
src/main/java/org/xerial/snappy/BitShuffleNative.cpp
Executable file
@ -0,0 +1,133 @@
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
#include <bitshuffle.h>
|
||||
#include "BitShuffleNative.h"
|
||||
|
||||
inline void throw_exception(JNIEnv *env, jobject self, int errorCode)
|
||||
{
|
||||
jclass c = env->FindClass("org/xerial/snappy/SnappyNative");
|
||||
if(c==0)
|
||||
return;
|
||||
jmethodID mth_throwex = env->GetMethodID(c, "throw_error", "(I)V");
|
||||
if(mth_throwex == 0)
|
||||
return;
|
||||
env->CallVoidMethod(self, mth_throwex, (jint) errorCode);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_BitShuffleNative
|
||||
* Method: shuffle
|
||||
* Signature: (Ljava/lang/Object;IIILjava/lang/Object;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_shuffle
|
||||
(JNIEnv * env, jobject self, jobject input, jint inputOffset, jint typeSize, jint length, jobject output, jint outputOffset)
|
||||
{
|
||||
char* in = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
||||
char* out = (char*) env->GetPrimitiveArrayCritical((jarray) output, 0);
|
||||
if(in == 0 || out == 0) {
|
||||
// out of memory
|
||||
if(in != 0) {
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
}
|
||||
if(out != 0) {
|
||||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||
}
|
||||
throw_exception(env, self, 4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t processedBytes = bshuf_bitshuffle(
|
||||
in + inputOffset, out + outputOffset, (size_t) (length / typeSize), (size_t) typeSize, 0);
|
||||
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||
|
||||
return (jint) processedBytes;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_BitShuffleNative
|
||||
* Method: shuffleDirectBuffer
|
||||
* Signature: (Ljava/nio/ByteBuffer;IIILjava/nio/ByteBuffer;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_shuffleDirectBuffer
|
||||
(JNIEnv * env, jobject self, jobject input, jint inputOffset, jint typeSize, jint length, jobject output, jint outputOffset)
|
||||
{
|
||||
char* inputBuffer = (char*) env->GetDirectBufferAddress(input);
|
||||
char* outputBuffer = (char*) env->GetDirectBufferAddress(output);
|
||||
if(inputBuffer == 0 || outputBuffer == 0) {
|
||||
throw_exception(env, self, 3);
|
||||
return (jint) 0;
|
||||
}
|
||||
|
||||
int64_t processedBytes = bshuf_bitshuffle(
|
||||
inputBuffer + inputOffset, outputBuffer + outputOffset, (size_t) (length / typeSize), (size_t) typeSize, 0);
|
||||
|
||||
return (jint) processedBytes;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_BitShuffleNative
|
||||
* Method: unshuffle
|
||||
* Signature: (Ljava/lang/Object;IIILjava/lang/Object;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_unshuffle
|
||||
(JNIEnv * env, jobject self, jobject input, jint inputOffset, jint typeSize, jint length, jobject output, jint outputOffset)
|
||||
{
|
||||
char* in = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
||||
char* out = (char*) env->GetPrimitiveArrayCritical((jarray) output, 0);
|
||||
if(in == 0 || out == 0) {
|
||||
// out of memory
|
||||
if(in != 0) {
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
}
|
||||
if(out != 0) {
|
||||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||
}
|
||||
throw_exception(env, self, 4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t processedBytes = bshuf_bitunshuffle(
|
||||
in + inputOffset, out + outputOffset, (size_t) (length / typeSize), (size_t) typeSize, 0);
|
||||
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||
|
||||
return (jint) processedBytes;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_BitShuffleNative
|
||||
* Method: unshuffleDirectBuffer
|
||||
* Signature: (Ljava/nio/ByteBuffer;IIILjava/nio/ByteBuffer;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_unshuffleDirectBuffer
|
||||
(JNIEnv * env, jobject self, jobject input, jint inputOffset, jint typeSize, jint length, jobject output, jint outputOffset)
|
||||
{
|
||||
char* inputBuffer = (char*) env->GetDirectBufferAddress(input);
|
||||
char* outputBuffer = (char*) env->GetDirectBufferAddress(output);
|
||||
if(inputBuffer == 0 || outputBuffer == 0) {
|
||||
throw_exception(env, self, 3);
|
||||
return (jint) 0;
|
||||
}
|
||||
|
||||
int64_t processedBytes = bshuf_bitunshuffle(
|
||||
inputBuffer + inputOffset, outputBuffer + outputOffset, (size_t) (length / typeSize), (size_t) typeSize, 0);
|
||||
|
||||
return (jint) processedBytes;
|
||||
}
|
||||
|
45
src/main/java/org/xerial/snappy/BitShuffleNative.h
Normal file
45
src/main/java/org/xerial/snappy/BitShuffleNative.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_xerial_snappy_BitShuffleNative */
|
||||
|
||||
#ifndef _Included_org_xerial_snappy_BitShuffleNative
|
||||
#define _Included_org_xerial_snappy_BitShuffleNative
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_xerial_snappy_BitShuffleNative
|
||||
* Method: shuffle
|
||||
* Signature: (Ljava/lang/Object;IIILjava/lang/Object;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_shuffle
|
||||
(JNIEnv *, jobject, jobject, jint, jint, jint, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_BitShuffleNative
|
||||
* Method: shuffleDirectBuffer
|
||||
* Signature: (Ljava/nio/ByteBuffer;IIILjava/nio/ByteBuffer;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_shuffleDirectBuffer
|
||||
(JNIEnv *, jobject, jobject, jint, jint, jint, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_BitShuffleNative
|
||||
* Method: unshuffle
|
||||
* Signature: (Ljava/lang/Object;IIILjava/lang/Object;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_unshuffle
|
||||
(JNIEnv *, jobject, jobject, jint, jint, jint, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_BitShuffleNative
|
||||
* Method: unshuffleDirectBuffer
|
||||
* Signature: (Ljava/nio/ByteBuffer;IIILjava/nio/ByteBuffer;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_unshuffleDirectBuffer
|
||||
(JNIEnv *, jobject, jobject, jint, jint, jint, jobject, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
60
src/main/java/org/xerial/snappy/BitShuffleNative.java
Normal file
60
src/main/java/org/xerial/snappy/BitShuffleNative.java
Normal file
@ -0,0 +1,60 @@
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
//--------------------------------------
|
||||
// snappy-java Project
|
||||
//
|
||||
// BitShuffleNative.java
|
||||
// Since: 2016/03/31
|
||||
//
|
||||
// $URL$
|
||||
// $Author$
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* JNI interfaces of the {@link BitShuffle} implementation. The native method in this class is
|
||||
* defined in BitShuffleNative.h (genereted by javah) and BitShuffleNative.cpp
|
||||
* <p/>
|
||||
* <p>
|
||||
* <b> DO NOT USE THIS CLASS since the direct use of this class might break the
|
||||
* native library code loading in {@link SnappyLoader}. </b>
|
||||
* </p>
|
||||
*
|
||||
* @author leo
|
||||
*/
|
||||
public class BitShuffleNative
|
||||
{
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Bit-shuffling routines to improve compression of typed binary data.
|
||||
// A quick benchmark result can be found in a gist below;
|
||||
// https://gist.github.com/maropu/01103215df34b317a7a7
|
||||
// ------------------------------------------------------------------------
|
||||
public native int shuffle(Object input, int inputOffset, int typeSize, int byteLength, Object output, int outputOffset)
|
||||
throws IOException;
|
||||
|
||||
public native int shuffleDirectBuffer(ByteBuffer input, int inputOffset, int typeSize, int byteLength, ByteBuffer output, int outputOffset)
|
||||
throws IOException;
|
||||
|
||||
public native int unshuffle(Object input, int inputOffset, int typeSize, int byteLength, Object output, int outputOffset)
|
||||
throws IOException;
|
||||
|
||||
public native int unshuffleDirectBuffer(ByteBuffer input, int inputOffset, int typeSize, int byteLength, ByteBuffer output, int outputOffset)
|
||||
throws IOException;
|
||||
}
|
53
src/main/java/org/xerial/snappy/BitShuffleType.java
Normal file
53
src/main/java/org/xerial/snappy/BitShuffleType.java
Normal file
@ -0,0 +1,53 @@
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
//--------------------------------------
|
||||
// XerialJ
|
||||
//
|
||||
// SnappyErrorCode.java
|
||||
// Since: 2011/03/30 14:56:50
|
||||
//
|
||||
// $URL$
|
||||
// $Author$
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
/**
|
||||
* Type codes used in ByteBuffer based BitShuffle APIs
|
||||
*
|
||||
* @author leo
|
||||
*/
|
||||
public enum BitShuffleType
|
||||
{
|
||||
|
||||
BYTE(1),
|
||||
SHORT(2),
|
||||
INT(4),
|
||||
LONG(8),
|
||||
FLOAT(4),
|
||||
DOUBLE(8);
|
||||
|
||||
public final int id;
|
||||
|
||||
private BitShuffleType(int id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getTypeSize()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
}
|
@ -24,18 +24,18 @@
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Provides OS name and architecture name.
|
||||
*
|
||||
*
|
||||
* @author leo
|
||||
*
|
||||
*/
|
||||
public class OSInfo
|
||||
{
|
||||
public class OSInfo {
|
||||
private static HashMap<String, String> archMapping = new HashMap<String, String>();
|
||||
|
||||
public static final String X86 = "x86";
|
||||
@ -44,6 +44,12 @@ public class OSInfo
|
||||
public static final String IA64 = "ia64";
|
||||
public static final String PPC = "ppc";
|
||||
public static final String PPC64 = "ppc64";
|
||||
public static final String PPC64LE = "ppc64le";
|
||||
public static final String IBMZ = "s390";
|
||||
public static final String IBMZ_64 = "s390x";
|
||||
public static final String AARCH_64 = "aarch64";
|
||||
public static final String RISCV_64 = "riscv64";
|
||||
public static final String LOONGARCH_64 = "loongarch64";
|
||||
|
||||
static {
|
||||
// x86 mappings
|
||||
@ -75,22 +81,39 @@ public class OSInfo
|
||||
archMapping.put("power_pc", PPC);
|
||||
archMapping.put("power_rs", PPC);
|
||||
|
||||
//PowerPC 64bit Little Endian mappings
|
||||
archMapping.put(PPC64LE, PPC64LE);
|
||||
|
||||
// TODO: PowerPC 64bit mappings
|
||||
archMapping.put(PPC64, PPC64);
|
||||
archMapping.put("power64", PPC64);
|
||||
archMapping.put("powerpc64", PPC64);
|
||||
archMapping.put("power_pc64", PPC64);
|
||||
archMapping.put("power_rs64", PPC64);
|
||||
archMapping.put(PPC64, PPC64);
|
||||
archMapping.put("power64", PPC64);
|
||||
archMapping.put("powerpc64", PPC64);
|
||||
archMapping.put("power_pc64", PPC64);
|
||||
archMapping.put("power_rs64", PPC64);
|
||||
|
||||
// IBM z mappings
|
||||
archMapping.put(IBMZ, IBMZ);
|
||||
|
||||
// IBM z 64-bit mappings
|
||||
archMapping.put(IBMZ_64, IBMZ_64);
|
||||
|
||||
// Aarch64 mappings
|
||||
archMapping.put(AARCH_64, AARCH_64);
|
||||
|
||||
// RISC-V mappings
|
||||
archMapping.put(RISCV_64, RISCV_64);
|
||||
|
||||
// LoongArch64 mappings
|
||||
archMapping.put(LOONGARCH_64, LOONGARCH_64);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length >= 1) {
|
||||
if ("--os".equals(args[0])) {
|
||||
if(args.length >= 1) {
|
||||
if("--os".equals(args[0])) {
|
||||
System.out.print(getOSName());
|
||||
return;
|
||||
}
|
||||
else if ("--arch".equals(args[0])) {
|
||||
else if("--arch".equals(args[0])) {
|
||||
System.out.print(getArchName());
|
||||
return;
|
||||
}
|
||||
@ -107,27 +130,98 @@ public class OSInfo
|
||||
return translateOSNameToFolderName(System.getProperty("os.name"));
|
||||
}
|
||||
|
||||
public static String getArchName() {
|
||||
// if running Linux on ARM, need to determine ABI of JVM
|
||||
String osArch = System.getProperty("os.arch");
|
||||
if (osArch.startsWith("arm") && System.getProperty("os.name").contains("Linux")) {
|
||||
String javaHome = System.getProperty("java.home");
|
||||
|
||||
public static boolean isAndroid() {
|
||||
return System.getProperty("java.runtime.name", "").toLowerCase().contains("android");
|
||||
}
|
||||
|
||||
static String getHardwareName() {
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec("uname -m");
|
||||
p.waitFor();
|
||||
|
||||
InputStream in = p.getInputStream();
|
||||
try {
|
||||
int readLen = 0;
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
byte[] buf = new byte[32];
|
||||
while((readLen = in.read(buf, 0, buf.length)) >= 0) {
|
||||
b.write(buf, 0, readLen);
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
finally {
|
||||
if(in != null) {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Throwable e) {
|
||||
System.err.println("Error while running uname -m: " + e.getMessage());
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
static String resolveArmArchType() {
|
||||
if(System.getProperty("os.name").contains("Linux")) {
|
||||
String armType = getHardwareName();
|
||||
// armType (uname -m) can be armv5t, armv5te, armv5tej, armv5tejl, armv6, armv7, armv7l, i686
|
||||
if(armType.startsWith("armv6")) {
|
||||
// Raspberry PI
|
||||
return "armv6";
|
||||
}
|
||||
else if(armType.startsWith("armv7")) {
|
||||
// Generic
|
||||
return "armv7";
|
||||
}
|
||||
|
||||
// Java 1.8 introduces a system property to determine armel or armhf
|
||||
// http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8005545
|
||||
String abi = System.getProperty("sun.arch.abi");
|
||||
if(abi != null && abi.startsWith("gnueabihf")) {
|
||||
return "armv7";
|
||||
}
|
||||
|
||||
// For java7, we stil need to if run some shell commands to determine ABI of JVM
|
||||
try {
|
||||
// determine if first JVM found uses ARM hard-float ABI
|
||||
String[] cmdarray = { "/bin/sh", "-c", "find '" + javaHome +
|
||||
"' -name 'libjvm.so' | head -1 | xargs readelf -A | " +
|
||||
"grep 'Tag_ABI_VFP_args: VFP registers'" };
|
||||
int exitCode = Runtime.getRuntime().exec(cmdarray).waitFor();
|
||||
if (exitCode == 0)
|
||||
return "armhf";
|
||||
int exitCode = Runtime.getRuntime().exec("which readelf").waitFor();
|
||||
if(exitCode == 0) {
|
||||
String javaHome = System.getProperty("java.home");
|
||||
String[] cmdarray = {"/bin/sh", "-c", "find '" + javaHome +
|
||||
"' -name 'libjvm.so' | head -1 | xargs readelf -A | " +
|
||||
"grep 'Tag_ABI_VFP_args: VFP registers'"};
|
||||
exitCode = Runtime.getRuntime().exec(cmdarray).waitFor();
|
||||
if(exitCode == 0) {
|
||||
return "armv7";
|
||||
}
|
||||
}
|
||||
else {
|
||||
System.err.println("WARNING! readelf not found. Cannot check if running on an armhf system, " +
|
||||
"armel architecture will be presumed.");
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch(IOException e) {
|
||||
// ignored: fall back to "arm" arch (soft-float ABI)
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
catch(InterruptedException e) {
|
||||
// ignored: fall back to "arm" arch (soft-float ABI)
|
||||
}
|
||||
}
|
||||
}
|
||||
// Use armv5, soft-float ABI
|
||||
return "arm";
|
||||
}
|
||||
|
||||
public static String getArchName() {
|
||||
String osArch = System.getProperty("os.arch");
|
||||
// For Android
|
||||
if(isAndroid()) {
|
||||
return "android-arm";
|
||||
}
|
||||
|
||||
if(osArch.startsWith("arm")) {
|
||||
osArch = resolveArmArchType();
|
||||
}
|
||||
else {
|
||||
String lc = osArch.toLowerCase(Locale.US);
|
||||
if(archMapping.containsKey(lc))
|
||||
@ -137,20 +231,19 @@ public class OSInfo
|
||||
}
|
||||
|
||||
static String translateOSNameToFolderName(String osName) {
|
||||
if (osName.contains("Windows")) {
|
||||
if(osName.contains("Windows")) {
|
||||
return "Windows";
|
||||
}
|
||||
else if (osName.contains("Mac")) {
|
||||
else if(osName.contains("Mac")) {
|
||||
return "Mac";
|
||||
}
|
||||
else if (osName.contains("Linux")) {
|
||||
else if(osName.contains("Linux")) {
|
||||
return "Linux";
|
||||
}
|
||||
else if (osName.contains("AIX")) {
|
||||
return "AIX";
|
||||
}
|
||||
|
||||
else {
|
||||
else if(osName.contains("AIX")) {
|
||||
return "AIX";
|
||||
}
|
||||
else {
|
||||
return osName.replaceAll("\\W", "");
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
60
src/main/java/org/xerial/snappy/SnappyApi.java
Normal file
60
src/main/java/org/xerial/snappy/SnappyApi.java
Normal file
@ -0,0 +1,60 @@
|
||||
package org.xerial.snappy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* Snappy compressor/decompressor interface. The implementation can be JNI binding or pure-java Snappy implementation.
|
||||
*/
|
||||
public interface SnappyApi
|
||||
{
|
||||
// ------------------------------------------------------------------------
|
||||
// Generic compression/decompression routines.
|
||||
// ------------------------------------------------------------------------
|
||||
long rawCompress(long inputAddr, long inputSize, long destAddr)
|
||||
throws IOException;
|
||||
|
||||
long rawUncompress(long inputAddr, long inputSize, long destAddr)
|
||||
throws IOException;
|
||||
|
||||
int rawCompress(ByteBuffer input, int inputOffset, int inputLength, ByteBuffer compressed,
|
||||
int outputOffset)
|
||||
throws IOException;
|
||||
|
||||
int rawCompress(Object input, int inputOffset, int inputByteLength, Object output, int outputOffset)
|
||||
throws IOException;
|
||||
|
||||
int rawUncompress(ByteBuffer compressed, int inputOffset, int inputLength, ByteBuffer uncompressed,
|
||||
int outputOffset)
|
||||
throws IOException;
|
||||
|
||||
int rawUncompress(Object input, int inputOffset, int inputLength, Object output, int outputOffset)
|
||||
throws IOException;
|
||||
|
||||
// Returns the maximal size of the compressed representation of
|
||||
// input data that is "source_bytes" bytes in length;
|
||||
int maxCompressedLength(int source_bytes);
|
||||
|
||||
// This operation takes O(1) time.
|
||||
int uncompressedLength(ByteBuffer compressed, int offset, int len)
|
||||
throws IOException;
|
||||
|
||||
int uncompressedLength(Object input, int offset, int len)
|
||||
throws IOException;
|
||||
|
||||
long uncompressedLength(long inputAddr, long len)
|
||||
throws IOException;
|
||||
|
||||
boolean isValidCompressedBuffer(ByteBuffer compressed, int offset, int len)
|
||||
throws IOException;
|
||||
|
||||
boolean isValidCompressedBuffer(Object input, int offset, int len)
|
||||
throws IOException;
|
||||
|
||||
boolean isValidCompressedBuffer(long inputAddr, long offset, long len)
|
||||
throws IOException;
|
||||
|
||||
void arrayCopy(Object src, int offset, int byteLength, Object dest, int dOffset)
|
||||
throws IOException;
|
||||
|
||||
}
|
@ -1,67 +1,70 @@
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
//--------------------------------------
|
||||
// XerialJ
|
||||
//
|
||||
// SnappyBundleActivator.java
|
||||
// Since: 2011/06/22 10:01:46
|
||||
//
|
||||
// $URL$
|
||||
// $Author$
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
/**
|
||||
* OSGi bundle entry point
|
||||
*
|
||||
* @author leo
|
||||
*
|
||||
*/
|
||||
public class SnappyBundleActivator implements BundleActivator
|
||||
{
|
||||
/**
|
||||
* Name of the Snappy native library
|
||||
*/
|
||||
public static final String LIBRARY_NAME = "snappyjava";
|
||||
|
||||
/**
|
||||
* Make a call to {@link System#loadLibrary(String)} to load the native library which assumes
|
||||
* that the library is available on the path based on this {@link Bundle}'s {@link Manifest}.
|
||||
*/
|
||||
public void start(BundleContext context) throws Exception
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
//--------------------------------------
|
||||
// XerialJ
|
||||
//
|
||||
// SnappyBundleActivator.java
|
||||
// Since: 2011/06/22 10:01:46
|
||||
//
|
||||
// $URL$
|
||||
// $Author$
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
/**
|
||||
* OSGi bundle entry point
|
||||
*
|
||||
* @author leo
|
||||
*/
|
||||
public class SnappyBundleActivator
|
||||
implements BundleActivator
|
||||
{
|
||||
/**
|
||||
* Name of the Snappy native library
|
||||
*/
|
||||
public static final String LIBRARY_NAME = "snappyjava";
|
||||
|
||||
/**
|
||||
* Make a call to {@link System#loadLibrary(String)} to load the native library which assumes
|
||||
* that the library is available on the path based on this {@link Bundle}'s {@link Manifest}.
|
||||
*/
|
||||
public void start(BundleContext context)
|
||||
throws Exception
|
||||
{
|
||||
String library = System.mapLibraryName(LIBRARY_NAME);
|
||||
if (library.toLowerCase().endsWith(".dylib"))
|
||||
{
|
||||
// some MacOS JDK7+ vendors map to dylib instead of jnilib
|
||||
library = library.replace(".dylib", ".jnilib");
|
||||
}
|
||||
System.loadLibrary(library);
|
||||
SnappyLoader.setApi(new SnappyNative());
|
||||
}
|
||||
|
||||
public void stop(BundleContext context) throws Exception
|
||||
{
|
||||
SnappyLoader.setApi(null);
|
||||
SnappyLoader.cleanUpExtractedNativeLib();
|
||||
}
|
||||
}
|
||||
String library = System.mapLibraryName(LIBRARY_NAME);
|
||||
String osArch = System.getProperty("os.arch");
|
||||
|
||||
if (library.toLowerCase().endsWith(".dylib") && "x86".equals(osArch)) {
|
||||
// some MacOS JDK7+ vendors map to dylib instead of jnilib
|
||||
library = library.replace(".dylib", ".jnilib");
|
||||
}
|
||||
System.loadLibrary(library);
|
||||
SnappyLoader.setSnappyApi(new SnappyNative());
|
||||
}
|
||||
|
||||
public void stop(BundleContext context)
|
||||
throws Exception
|
||||
{
|
||||
SnappyLoader.setSnappyApi(null);
|
||||
SnappyLoader.cleanUpExtractedNativeLib();
|
||||
}
|
||||
}
|
||||
|
@ -1,117 +1,146 @@
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
//--------------------------------------
|
||||
// XerialJ
|
||||
//
|
||||
// SnappyCodec.java
|
||||
// Since: 2011/04/03 14:50:20
|
||||
//
|
||||
// $URL$
|
||||
// $Author$
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Preamble header for {@link SnappyOutputStream}.
|
||||
*
|
||||
* <p>
|
||||
* The magic header is the following 8 bytes data:
|
||||
*
|
||||
* <pre>
|
||||
* -126, 'S', 'N', 'A', 'P', 'P', 'Y', 0
|
||||
* </pre>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author leo
|
||||
*
|
||||
*/
|
||||
public class SnappyCodec
|
||||
{
|
||||
public static final byte[] MAGIC_HEADER = new byte[] { -126, 'S', 'N', 'A', 'P', 'P', 'Y', 0 };
|
||||
public static final int MAGIC_LEN = MAGIC_HEADER.length;
|
||||
public static final int HEADER_SIZE = MAGIC_LEN + 8;
|
||||
|
||||
public static final int DEFAULT_VERSION = 1;
|
||||
public static final int MINIMUM_COMPATIBLE_VERSION = 1;
|
||||
|
||||
public final byte[] magic;
|
||||
public final int version;
|
||||
public final int compatibleVersion;
|
||||
private final byte[] headerArray;
|
||||
|
||||
private SnappyCodec(byte[] magic, int version, int compatibleVersion) {
|
||||
this.magic = magic;
|
||||
this.version = version;
|
||||
this.compatibleVersion = compatibleVersion;
|
||||
|
||||
ByteArrayOutputStream header = new ByteArrayOutputStream(HEADER_SIZE);
|
||||
DataOutputStream d = new DataOutputStream(header);
|
||||
try {
|
||||
d.write(magic, 0, MAGIC_LEN);
|
||||
d.writeInt(version);
|
||||
d.writeInt(compatibleVersion);
|
||||
d.close();
|
||||
}
|
||||
catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
headerArray = header.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("version:%d, compatible version:%d", version, compatibleVersion);
|
||||
}
|
||||
|
||||
public static int headerSize() {
|
||||
return HEADER_SIZE;
|
||||
}
|
||||
|
||||
public int writeHeader(byte[] dst, int dstOffset) {
|
||||
System.arraycopy(headerArray, 0, dst, dstOffset, headerArray.length);
|
||||
return headerArray.length;
|
||||
}
|
||||
|
||||
public int writeHeader(OutputStream out) throws IOException {
|
||||
out.write(headerArray, 0, headerArray.length);
|
||||
return headerArray.length;
|
||||
}
|
||||
|
||||
public boolean isValidMagicHeader() {
|
||||
return Arrays.equals(MAGIC_HEADER, magic);
|
||||
}
|
||||
|
||||
public static SnappyCodec readHeader(InputStream in) throws IOException {
|
||||
DataInputStream d = new DataInputStream(in);
|
||||
byte[] magic = new byte[MAGIC_LEN];
|
||||
d.readFully(magic, 0, MAGIC_LEN);
|
||||
int version = d.readInt();
|
||||
int compatibleVersion = d.readInt();
|
||||
return new SnappyCodec(magic, version, compatibleVersion);
|
||||
}
|
||||
|
||||
public static SnappyCodec currentHeader = new SnappyCodec(MAGIC_HEADER, DEFAULT_VERSION, MINIMUM_COMPATIBLE_VERSION);
|
||||
|
||||
}
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
//--------------------------------------
|
||||
// XerialJ
|
||||
//
|
||||
// SnappyCodec.java
|
||||
// Since: 2011/04/03 14:50:20
|
||||
//
|
||||
// $URL$
|
||||
// $Author$
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Preamble header for {@link SnappyOutputStream}.
|
||||
* <p/>
|
||||
* <p>
|
||||
* The magic header is the following 8 bytes data:
|
||||
* <p/>
|
||||
* <pre>
|
||||
* -126, 'S', 'N', 'A', 'P', 'P', 'Y', 0
|
||||
* </pre>
|
||||
* <p/>
|
||||
* </p>
|
||||
*
|
||||
* @author leo
|
||||
*/
|
||||
public class SnappyCodec
|
||||
{
|
||||
static final byte[] MAGIC_HEADER = new byte[] {-126, 'S', 'N', 'A', 'P', 'P', 'Y', 0};
|
||||
public static final int MAGIC_LEN = MAGIC_HEADER.length;
|
||||
public static final int HEADER_SIZE = MAGIC_LEN + 8;
|
||||
public static final int MAGIC_HEADER_HEAD = SnappyOutputStream.readInt(MAGIC_HEADER, 0);
|
||||
|
||||
static {
|
||||
assert (MAGIC_HEADER_HEAD < 0);
|
||||
}
|
||||
|
||||
public static final int DEFAULT_VERSION = 1;
|
||||
public static final int MINIMUM_COMPATIBLE_VERSION = 1;
|
||||
public static final SnappyCodec currentHeader = new SnappyCodec(MAGIC_HEADER, DEFAULT_VERSION, MINIMUM_COMPATIBLE_VERSION);
|
||||
|
||||
public final byte[] magic;
|
||||
public final int version;
|
||||
public final int compatibleVersion;
|
||||
private final byte[] headerArray;
|
||||
|
||||
private SnappyCodec(byte[] magic, int version, int compatibleVersion)
|
||||
{
|
||||
this.magic = magic;
|
||||
this.version = version;
|
||||
this.compatibleVersion = compatibleVersion;
|
||||
|
||||
ByteArrayOutputStream header = new ByteArrayOutputStream(HEADER_SIZE);
|
||||
DataOutputStream d = new DataOutputStream(header);
|
||||
try {
|
||||
d.write(magic, 0, MAGIC_LEN);
|
||||
d.writeInt(version);
|
||||
d.writeInt(compatibleVersion);
|
||||
d.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
headerArray = header.toByteArray();
|
||||
}
|
||||
|
||||
public static byte[] getMagicHeader()
|
||||
{
|
||||
return MAGIC_HEADER.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("version:%d, compatible version:%d", version, compatibleVersion);
|
||||
}
|
||||
|
||||
public static int headerSize()
|
||||
{
|
||||
return HEADER_SIZE;
|
||||
}
|
||||
|
||||
public int writeHeader(byte[] dst, int dstOffset)
|
||||
{
|
||||
System.arraycopy(headerArray, 0, dst, dstOffset, headerArray.length);
|
||||
return headerArray.length;
|
||||
}
|
||||
|
||||
public int writeHeader(OutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
out.write(headerArray, 0, headerArray.length);
|
||||
return headerArray.length;
|
||||
}
|
||||
|
||||
public boolean isValidMagicHeader()
|
||||
{
|
||||
return Arrays.equals(MAGIC_HEADER, magic);
|
||||
}
|
||||
|
||||
public static boolean hasMagicHeaderPrefix(byte[] b) {
|
||||
int limit = Math.min(MAGIC_LEN, b.length);
|
||||
int i = 0;
|
||||
while(i < limit) {
|
||||
if(b[i] != MAGIC_HEADER[i]) {
|
||||
return false;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static SnappyCodec readHeader(InputStream in)
|
||||
throws IOException
|
||||
{
|
||||
DataInputStream d = new DataInputStream(in);
|
||||
byte[] magic = new byte[MAGIC_LEN];
|
||||
d.readFully(magic, 0, MAGIC_LEN);
|
||||
int version = d.readInt();
|
||||
int compatibleVersion = d.readInt();
|
||||
return new SnappyCodec(magic, version, compatibleVersion);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,62 +1,65 @@
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
//--------------------------------------
|
||||
// XerialJ
|
||||
//
|
||||
// SnappyError.java
|
||||
// Since: 2011/03/30 15:22:43
|
||||
//
|
||||
// $URL$
|
||||
// $Author$
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
/**
|
||||
* Used when serious errors (unchecked exception) are observed.
|
||||
*
|
||||
* @author leo
|
||||
*
|
||||
*/
|
||||
public class SnappyError extends Error
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public final SnappyErrorCode errorCode;
|
||||
|
||||
public SnappyError(SnappyErrorCode code) {
|
||||
super();
|
||||
this.errorCode = code;
|
||||
}
|
||||
|
||||
public SnappyError(SnappyErrorCode code, Error e) {
|
||||
super(e);
|
||||
this.errorCode = code;
|
||||
}
|
||||
|
||||
public SnappyError(SnappyErrorCode code, String message) {
|
||||
super(message);
|
||||
this.errorCode = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return String.format("[%s] %s", errorCode.name(), super.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
//--------------------------------------
|
||||
// XerialJ
|
||||
//
|
||||
// SnappyError.java
|
||||
// Since: 2011/03/30 15:22:43
|
||||
//
|
||||
// $URL$
|
||||
// $Author$
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
/**
|
||||
* Used when serious errors (unchecked exception) are observed.
|
||||
*
|
||||
* @author leo
|
||||
*/
|
||||
public class SnappyError
|
||||
extends Error
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public final SnappyErrorCode errorCode;
|
||||
|
||||
public SnappyError(SnappyErrorCode code)
|
||||
{
|
||||
super();
|
||||
this.errorCode = code;
|
||||
}
|
||||
|
||||
public SnappyError(SnappyErrorCode code, Error e)
|
||||
{
|
||||
super(e);
|
||||
this.errorCode = code;
|
||||
}
|
||||
|
||||
public SnappyError(SnappyErrorCode code, String message)
|
||||
{
|
||||
super(message);
|
||||
this.errorCode = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage()
|
||||
{
|
||||
return String.format("[%s] %s", errorCode.name(), super.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -1,64 +1,69 @@
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
//--------------------------------------
|
||||
// XerialJ
|
||||
//
|
||||
// SnappyErrorCode.java
|
||||
// Since: 2011/03/30 14:56:50
|
||||
//
|
||||
// $URL$
|
||||
// $Author$
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
/**
|
||||
* Error codes of snappy-java
|
||||
*
|
||||
* @author leo
|
||||
*
|
||||
*/
|
||||
public enum SnappyErrorCode {
|
||||
|
||||
// DO NOT change these error code IDs because these numbers are used inside SnappyNative.cpp
|
||||
UNKNOWN(0),
|
||||
FAILED_TO_LOAD_NATIVE_LIBRARY(1),
|
||||
PARSING_ERROR(2),
|
||||
NOT_A_DIRECT_BUFFER(3),
|
||||
OUT_OF_MEMORY(4),
|
||||
FAILED_TO_UNCOMPRESS(5),
|
||||
EMPTY_INPUT(6),
|
||||
INCOMPATIBLE_VERSION(7),
|
||||
INVALID_CHUNK_SIZE(8)
|
||||
;
|
||||
|
||||
public final int id;
|
||||
|
||||
private SnappyErrorCode(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static SnappyErrorCode getErrorCode(int id) {
|
||||
for (SnappyErrorCode code : SnappyErrorCode.values()) {
|
||||
if (code.id == id)
|
||||
return code;
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public static String getErrorMessage(int id) {
|
||||
return getErrorCode(id).name();
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
//--------------------------------------
|
||||
// XerialJ
|
||||
//
|
||||
// SnappyErrorCode.java
|
||||
// Since: 2011/03/30 14:56:50
|
||||
//
|
||||
// $URL$
|
||||
// $Author$
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
/**
|
||||
* Error codes of snappy-java
|
||||
*
|
||||
* @author leo
|
||||
*/
|
||||
public enum SnappyErrorCode
|
||||
{
|
||||
|
||||
// DO NOT change these error code IDs because these numbers are used inside SnappyNative.cpp
|
||||
UNKNOWN(0),
|
||||
FAILED_TO_LOAD_NATIVE_LIBRARY(1),
|
||||
PARSING_ERROR(2),
|
||||
NOT_A_DIRECT_BUFFER(3),
|
||||
OUT_OF_MEMORY(4),
|
||||
FAILED_TO_UNCOMPRESS(5),
|
||||
EMPTY_INPUT(6),
|
||||
INCOMPATIBLE_VERSION(7),
|
||||
INVALID_CHUNK_SIZE(8),
|
||||
UNSUPPORTED_PLATFORM(9),
|
||||
TOO_LARGE_INPUT(10);
|
||||
|
||||
public final int id;
|
||||
|
||||
private SnappyErrorCode(int id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static SnappyErrorCode getErrorCode(int id)
|
||||
{
|
||||
for (SnappyErrorCode code : SnappyErrorCode.values()) {
|
||||
if (code.id == id) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public static String getErrorMessage(int id)
|
||||
{
|
||||
return getErrorCode(id).name();
|
||||
}
|
||||
}
|
||||
|
@ -1,74 +1,82 @@
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
//--------------------------------------
|
||||
// XerialJ
|
||||
//
|
||||
// SnappyException.java
|
||||
// Since: 2011/03/30 14:56:14
|
||||
//
|
||||
// $URL$
|
||||
// $Author$
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Exception in snappy-java
|
||||
*
|
||||
* @deprecated Snappy-java now uses {@link IOException}
|
||||
* @author leo
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public class SnappyException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public final SnappyErrorCode errorCode;
|
||||
|
||||
public SnappyException(int code) {
|
||||
this(SnappyErrorCode.getErrorCode(code));
|
||||
}
|
||||
|
||||
public SnappyException(SnappyErrorCode errorCode) {
|
||||
super();
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public SnappyException(SnappyErrorCode errorCode, Exception e) {
|
||||
super(e);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public SnappyException(SnappyErrorCode errorCode, String message) {
|
||||
super(message);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public SnappyErrorCode getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public static void throwException(int errorCode) throws SnappyException {
|
||||
throw new SnappyException(errorCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return String.format("[%s] %s", errorCode.name(), super.getMessage());
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
//--------------------------------------
|
||||
// XerialJ
|
||||
//
|
||||
// SnappyException.java
|
||||
// Since: 2011/03/30 14:56:14
|
||||
//
|
||||
// $URL$
|
||||
// $Author$
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Exception in snappy-java
|
||||
*
|
||||
* @author leo
|
||||
* @deprecated Snappy-java now uses {@link IOException}
|
||||
*/
|
||||
@Deprecated
|
||||
public class SnappyException
|
||||
extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public final SnappyErrorCode errorCode;
|
||||
|
||||
public SnappyException(int code)
|
||||
{
|
||||
this(SnappyErrorCode.getErrorCode(code));
|
||||
}
|
||||
|
||||
public SnappyException(SnappyErrorCode errorCode)
|
||||
{
|
||||
super();
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public SnappyException(SnappyErrorCode errorCode, Exception e)
|
||||
{
|
||||
super(e);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public SnappyException(SnappyErrorCode errorCode, String message)
|
||||
{
|
||||
super(message);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public SnappyErrorCode getErrorCode()
|
||||
{
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public static void throwException(int errorCode)
|
||||
throws SnappyException
|
||||
{
|
||||
throw new SnappyException(errorCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage()
|
||||
{
|
||||
return String.format("[%s] %s", errorCode.name(), super.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -4,52 +4,70 @@
|
||||
package org.xerial.snappy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.invoke.LambdaMetafactory;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.Checksum;
|
||||
|
||||
/**
|
||||
* Constants and utilities for implementing x-snappy-framed.
|
||||
*
|
||||
*
|
||||
* @author Brett Okken
|
||||
* @since 1.1.0
|
||||
*/
|
||||
final class SnappyFramed {
|
||||
final class SnappyFramed
|
||||
{
|
||||
public static final int COMPRESSED_DATA_FLAG = 0x00;
|
||||
|
||||
public static final int UNCOMPRESSED_DATA_FLAG = 0x01;
|
||||
|
||||
public static final int STREAM_IDENTIFIER_FLAG = 0xff;
|
||||
|
||||
|
||||
private static final int MASK_DELTA = 0xa282ead8;
|
||||
|
||||
/**
|
||||
* Sun specific mechanisms to clean up resources associated with direct byte buffers.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final Class<? extends ByteBuffer> SUN_DIRECT_BUFFER = (Class<? extends ByteBuffer>) lookupClassQuietly("sun.nio.ch.DirectBuffer");
|
||||
private static final Method SUN_BUFFER_CLEANER;
|
||||
private static final Method SUN_CLEANER_CLEAN;
|
||||
|
||||
private static final Supplier<Checksum> CHECKSUM_SUPPLIER;
|
||||
|
||||
static
|
||||
{
|
||||
Method bufferCleaner = null;
|
||||
Method cleanerClean = null;
|
||||
try {
|
||||
//operate under the assumption that if the sun direct buffer class exists,
|
||||
//all of the sun classes exist
|
||||
if (SUN_DIRECT_BUFFER != null) {
|
||||
bufferCleaner = SUN_DIRECT_BUFFER.getMethod("cleaner", (Class[])null);
|
||||
Class<?> cleanClazz = lookupClassQuietly("sun.misc.Cleaner");
|
||||
cleanerClean = cleanClazz.getMethod("clean", (Class[])null);
|
||||
}
|
||||
} catch(Throwable t) {
|
||||
Logger.getLogger(SnappyFramed.class.getName()).log(Level.FINE, "Exception occurred attempting to lookup Sun specific DirectByteBuffer cleaner classes.", t);
|
||||
Supplier<Checksum> supplier = null;
|
||||
try
|
||||
{
|
||||
final Class<?> crc32cClazz = Class.forName("java.util.zip.CRC32C");
|
||||
// using LambdaMetafactory requires a caller sensitive lookup
|
||||
final MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
final MethodHandle conHandle = lookup.findConstructor(crc32cClazz, MethodType.methodType(void.class));
|
||||
|
||||
// use LambdaMetafactory to generate an implementation of Supplier<Checksum> which invokes
|
||||
// the java.util.zip.CRC32C default constructor
|
||||
supplier = (Supplier<Checksum>) LambdaMetafactory.metafactory(lookup,
|
||||
// method name on Supplier
|
||||
"get",
|
||||
// functional interface to be created by factory
|
||||
MethodType.methodType(Supplier.class),
|
||||
// type of the functional interface
|
||||
// uses a generic, so erasure to Object
|
||||
MethodType.methodType(Object.class),
|
||||
// the method handle to call
|
||||
conHandle,
|
||||
// type as used at call site
|
||||
MethodType.methodType(Checksum.class))
|
||||
.getTarget()
|
||||
.invoke();
|
||||
}
|
||||
SUN_BUFFER_CLEANER = bufferCleaner;
|
||||
SUN_CLEANER_CLEAN = cleanerClean;
|
||||
catch(Throwable t)
|
||||
{
|
||||
Logger.getLogger(SnappyFramed.class.getName())
|
||||
.log(Level.FINE, "java.util.zip.CRC32C not loaded, using PureJavaCrc32C", t);
|
||||
supplier = null;
|
||||
}
|
||||
|
||||
CHECKSUM_SUPPLIER = supplier != null ? supplier : PureJavaCrc32C::new;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,18 +76,18 @@ final class SnappyFramed {
|
||||
*/
|
||||
public static final byte[] HEADER_BYTES = new byte[] {
|
||||
(byte) STREAM_IDENTIFIER_FLAG, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61,
|
||||
0x50, 0x70, 0x59 };
|
||||
0x50, 0x70, 0x59};
|
||||
|
||||
public static int maskedCrc32c(byte[] data)
|
||||
public static Checksum getCRC32C()
|
||||
{
|
||||
return maskedCrc32c(data, 0, data.length);
|
||||
return CHECKSUM_SUPPLIER.get();
|
||||
}
|
||||
|
||||
public static int maskedCrc32c(byte[] data, int offset, int length)
|
||||
public static int maskedCrc32c(Checksum crc32c, byte[] data, int offset, int length)
|
||||
{
|
||||
final PureJavaCrc32C crc32c = new PureJavaCrc32C();
|
||||
crc32c.reset();
|
||||
crc32c.update(data, offset, length);
|
||||
return mask(crc32c.getIntegerValue());
|
||||
return mask((int) crc32c.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,10 +96,10 @@ final class SnappyFramed {
|
||||
* in Apache Hadoop: Rotate the checksum by 15 bits, then add the constant
|
||||
* 0xa282ead8 (using wraparound as normal for unsigned integers). This is
|
||||
* equivalent to the following C code:
|
||||
*
|
||||
* <p/>
|
||||
* <pre>
|
||||
* uint32_t mask_checksum(uint32_t x) {
|
||||
* return ((x >> 15) | (x << 17)) + 0xa282ead8;
|
||||
* return ((x >> 15) | (x << 17)) + 0xa282ead8;
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
@ -90,9 +108,9 @@ final class SnappyFramed {
|
||||
// Rotate right by 15 bits and add a constant.
|
||||
return ((crc >>> 15) | (crc << 17)) + MASK_DELTA;
|
||||
}
|
||||
|
||||
|
||||
static final int readBytes(ReadableByteChannel source, ByteBuffer dest) throws IOException
|
||||
static final int readBytes(ReadableByteChannel source, ByteBuffer dest)
|
||||
throws IOException
|
||||
{
|
||||
// tells how many bytes to read.
|
||||
final int expectedLength = dest.remaining();
|
||||
@ -105,47 +123,43 @@ final class SnappyFramed {
|
||||
totalRead = lastRead;
|
||||
|
||||
// if we did not read as many bytes as we had hoped, try reading again.
|
||||
if (lastRead < expectedLength)
|
||||
{
|
||||
if (lastRead < expectedLength) {
|
||||
// as long the buffer is not full (remaining() == 0) and we have not reached EOF (lastRead == -1) keep reading.
|
||||
while (dest.remaining() != 0 && lastRead != -1)
|
||||
{
|
||||
while (dest.remaining() != 0 && lastRead != -1) {
|
||||
lastRead = source.read(dest);
|
||||
|
||||
// if we got EOF, do not add to total read.
|
||||
if (lastRead != -1)
|
||||
{
|
||||
if (lastRead != -1) {
|
||||
totalRead += lastRead;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (totalRead > 0)
|
||||
{
|
||||
if (totalRead > 0) {
|
||||
dest.limit(dest.position());
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
dest.position(dest.limit());
|
||||
}
|
||||
|
||||
return totalRead;
|
||||
}
|
||||
|
||||
static int skip(final ReadableByteChannel source, final int skip, final ByteBuffer buffer) throws IOException
|
||||
|
||||
static int skip(final ReadableByteChannel source, final int skip, final ByteBuffer buffer)
|
||||
throws IOException
|
||||
{
|
||||
if (skip <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int toSkip = skip;
|
||||
int skipped = 0;
|
||||
while(toSkip > 0 && skipped != -1) {
|
||||
int skipped = 0;
|
||||
while (toSkip > 0 && skipped != -1) {
|
||||
buffer.clear();
|
||||
if (toSkip < buffer.capacity()) {
|
||||
buffer.limit(toSkip);
|
||||
}
|
||||
|
||||
|
||||
skipped = source.read(buffer);
|
||||
if (skipped > 0) {
|
||||
toSkip -= skipped;
|
||||
@ -155,32 +169,4 @@ final class SnappyFramed {
|
||||
buffer.clear();
|
||||
return skip - toSkip;
|
||||
}
|
||||
|
||||
private static Class<?> lookupClassQuietly(String name) {
|
||||
try {
|
||||
return SnappyFramed.class.getClassLoader().loadClass(name);
|
||||
} catch (Throwable t) {
|
||||
Logger.getLogger(SnappyFramed.class.getName()).log(Level.FINE, "Did not find requested class: " + name, t);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides jvm implementation specific operation to aggressively release resources associated with <i>buffer</i>.
|
||||
* @param buffer The {@code ByteBuffer} to release. Must not be {@code null}. Must be {@link ByteBuffer#isDirect() direct}.
|
||||
*/
|
||||
static void releaseDirectByteBuffer(ByteBuffer buffer)
|
||||
{
|
||||
assert buffer != null && buffer.isDirect();
|
||||
|
||||
if (SUN_DIRECT_BUFFER != null && SUN_DIRECT_BUFFER.isAssignableFrom(buffer.getClass())) {
|
||||
try {
|
||||
Object cleaner = SUN_BUFFER_CLEANER.invoke(buffer, (Object[]) null);
|
||||
SUN_CLEANER_CLEAN.invoke(cleaner, (Object[]) null);
|
||||
} catch (Throwable t) {
|
||||
Logger.getLogger(SnappyFramed.class.getName()).log(Level.FINE, "Exception occurred attempting to clean up Sun specific DirectByteBuffer.", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,30 @@
|
||||
package org.xerial.snappy;
|
||||
|
||||
import org.xerial.snappy.buffer.CachedBufferAllocator;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class SnappyHadoopCompatibleOutputStream extends SnappyOutputStream
|
||||
{
|
||||
public SnappyHadoopCompatibleOutputStream(OutputStream out)
|
||||
{
|
||||
this(out, DEFAULT_BLOCK_SIZE);
|
||||
}
|
||||
|
||||
public SnappyHadoopCompatibleOutputStream(OutputStream out, int blockSize)
|
||||
{
|
||||
super(out, blockSize, CachedBufferAllocator.getBufferAllocatorFactory());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int writeHeader()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBlockPreemble()
|
||||
{
|
||||
writeCurrentDataSize();
|
||||
}
|
||||
}
|
@ -5,19 +5,22 @@ import java.io.IOException;
|
||||
/**
|
||||
* Enhanced IOException with SnappyErrorCode
|
||||
*/
|
||||
public class SnappyIOException extends IOException {
|
||||
public class SnappyIOException
|
||||
extends IOException
|
||||
{
|
||||
private final SnappyErrorCode errorCode;
|
||||
|
||||
public SnappyIOException(SnappyErrorCode errorCode, String message) {
|
||||
public SnappyIOException(SnappyErrorCode errorCode, String message)
|
||||
{
|
||||
super(message);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
public String getMessage()
|
||||
{
|
||||
return String.format("[%s] %s", errorCode.name(), super.getMessage());
|
||||
}
|
||||
|
||||
public SnappyErrorCode getErrorCode() { return errorCode; }
|
||||
|
||||
}
|
||||
|
@ -30,30 +30,49 @@ import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* A stream filter for reading data compressed by {@link SnappyOutputStream}.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author leo
|
||||
*
|
||||
*/
|
||||
public class SnappyInputStream extends InputStream
|
||||
public class SnappyInputStream
|
||||
extends InputStream
|
||||
{
|
||||
private boolean finishedReading = false;
|
||||
public static final int MAX_CHUNK_SIZE = 512 * 1024 * 1024; // 512 MiB
|
||||
|
||||
private boolean finishedReading = false;
|
||||
protected final InputStream in;
|
||||
private final int maxChunkSize;
|
||||
|
||||
private byte[] compressed;
|
||||
private byte[] uncompressed;
|
||||
private int uncompressedCursor = 0;
|
||||
private int uncompressedLimit = 0;
|
||||
private byte[] compressed;
|
||||
private byte[] uncompressed;
|
||||
private int uncompressedCursor = 0;
|
||||
private int uncompressedLimit = 0;
|
||||
|
||||
private byte[] chunkSizeBuf = new byte[4];
|
||||
private byte[] header = new byte[SnappyCodec.headerSize()];
|
||||
|
||||
/**
|
||||
* Create a filter for reading compressed data as a uncompressed stream
|
||||
*
|
||||
*
|
||||
* @param input
|
||||
* @throws IOException
|
||||
*/
|
||||
public SnappyInputStream(InputStream input) throws IOException {
|
||||
public SnappyInputStream(InputStream input)
|
||||
throws IOException
|
||||
{
|
||||
this(input, MAX_CHUNK_SIZE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a filter for reading compressed data as a uncompressed stream with provided maximum chunk size
|
||||
*
|
||||
* @param input
|
||||
* @param maxChunkSize
|
||||
* @throws IOException
|
||||
*/
|
||||
public SnappyInputStream(InputStream input, int maxChunkSize)
|
||||
throws IOException
|
||||
{
|
||||
this.maxChunkSize = maxChunkSize;
|
||||
this.in = input;
|
||||
readHeader();
|
||||
}
|
||||
@ -65,34 +84,44 @@ public class SnappyInputStream extends InputStream
|
||||
* @see java.io.InputStream#close()
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
public void close()
|
||||
throws IOException
|
||||
{
|
||||
compressed = null;
|
||||
uncompressed = null;
|
||||
if (in != null)
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected void readHeader() throws IOException {
|
||||
byte[] header = new byte[SnappyCodec.headerSize()];
|
||||
protected void readHeader()
|
||||
throws IOException
|
||||
{
|
||||
int readBytes = 0;
|
||||
while (readBytes < header.length) {
|
||||
int ret = in.read(header, readBytes, header.length - readBytes);
|
||||
if (ret == -1)
|
||||
if (ret == -1) {
|
||||
break;
|
||||
}
|
||||
readBytes += ret;
|
||||
}
|
||||
|
||||
// Quick test of the header
|
||||
if(readBytes == 0) {
|
||||
if (readBytes == 0) {
|
||||
// Snappy produces at least 1-byte result. So the empty input is not a valid input
|
||||
throw new SnappyIOException(SnappyErrorCode.EMPTY_INPUT, "Cannot decompress empty stream");
|
||||
}
|
||||
if (readBytes < header.length || header[0] != SnappyCodec.MAGIC_HEADER[0]) {
|
||||
if (readBytes < header.length || !SnappyCodec.hasMagicHeaderPrefix(header)) {
|
||||
// do the default uncompression
|
||||
// (probably) compressed by Snappy.compress(byte[])
|
||||
readFully(header, readBytes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isValidHeader(byte[] header)
|
||||
throws IOException
|
||||
{
|
||||
SnappyCodec codec = SnappyCodec.readHeader(new ByteArrayInputStream(header));
|
||||
if (codec.isValidMagicHeader()) {
|
||||
// The input data is compressed by SnappyOutputStream
|
||||
@ -101,16 +130,17 @@ public class SnappyInputStream extends InputStream
|
||||
"Compressed with an incompatible codec version %d. At least version %d is required",
|
||||
codec.version, SnappyCodec.MINIMUM_COMPATIBLE_VERSION));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
// (probably) compressed by Snappy.compress(byte[])
|
||||
readFully(header, readBytes);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void readFully(byte[] fragment, int fragmentLength) throws IOException {
|
||||
if(fragmentLength == 0) {
|
||||
protected void readFully(byte[] fragment, int fragmentLength)
|
||||
throws IOException
|
||||
{
|
||||
if (fragmentLength == 0) {
|
||||
finishedReading = true;
|
||||
return;
|
||||
}
|
||||
@ -118,7 +148,7 @@ public class SnappyInputStream extends InputStream
|
||||
compressed = new byte[Math.max(8 * 1024, fragmentLength)]; // 8K
|
||||
System.arraycopy(fragment, 0, compressed, 0, fragmentLength);
|
||||
int cursor = fragmentLength;
|
||||
for (int readBytes = 0; (readBytes = in.read(compressed, cursor, compressed.length - cursor)) != -1;) {
|
||||
for (int readBytes = 0; (readBytes = in.read(compressed, cursor, compressed.length - cursor)) != -1; ) {
|
||||
cursor += readBytes;
|
||||
if (cursor >= compressed.length) {
|
||||
byte[] newBuf = new byte[(compressed.length * 2)];
|
||||
@ -135,7 +165,6 @@ public class SnappyInputStream extends InputStream
|
||||
Snappy.uncompress(compressed, 0, cursor, uncompressed, 0);
|
||||
this.uncompressedCursor = 0;
|
||||
this.uncompressedLimit = uncompressedLength;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,26 +175,48 @@ public class SnappyInputStream extends InputStream
|
||||
* @see java.io.InputStream#read(byte[], int, int)
|
||||
*/
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
return rawRead(b, off, len);
|
||||
public int read(byte[] b, int byteOffset, int byteLength)
|
||||
throws IOException
|
||||
{
|
||||
int writtenBytes = 0;
|
||||
for (; writtenBytes < byteLength; ) {
|
||||
|
||||
if (uncompressedCursor >= uncompressedLimit) {
|
||||
if (hasNextChunk()) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
return writtenBytes == 0 ? -1 : writtenBytes;
|
||||
}
|
||||
}
|
||||
int bytesToWrite = Math.min(uncompressedLimit - uncompressedCursor, byteLength - writtenBytes);
|
||||
System.arraycopy(uncompressed, uncompressedCursor, b, byteOffset + writtenBytes, bytesToWrite);
|
||||
writtenBytes += bytesToWrite;
|
||||
uncompressedCursor += bytesToWrite;
|
||||
}
|
||||
|
||||
return writtenBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read uncompressed data into the specified array
|
||||
*
|
||||
*
|
||||
* @param array
|
||||
* @param byteOffset
|
||||
* @param byteLength
|
||||
* @return written bytes
|
||||
* @throws IOException
|
||||
*/
|
||||
public int rawRead(Object array, int byteOffset, int byteLength) throws IOException {
|
||||
public int rawRead(Object array, int byteOffset, int byteLength)
|
||||
throws IOException
|
||||
{
|
||||
int writtenBytes = 0;
|
||||
for (; writtenBytes < byteLength;) {
|
||||
for (; writtenBytes < byteLength; ) {
|
||||
|
||||
if (uncompressedCursor >= uncompressedLimit) {
|
||||
if (hasNextChunk())
|
||||
if (hasNextChunk()) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
return writtenBytes == 0 ? -1 : writtenBytes;
|
||||
}
|
||||
@ -181,175 +232,235 @@ public class SnappyInputStream extends InputStream
|
||||
|
||||
/**
|
||||
* Read long array from the stream
|
||||
*
|
||||
* @param d
|
||||
* input
|
||||
* @param off
|
||||
* offset
|
||||
* @param len
|
||||
* the number of long elements to read
|
||||
*
|
||||
* @param d input
|
||||
* @param off offset
|
||||
* @param len the number of long elements to read
|
||||
* @return the total number of bytes read into the buffer, or -1 if there is
|
||||
* no more data because the end of the stream has been reached.
|
||||
* no more data because the end of the stream has been reached.
|
||||
* @throws IOException
|
||||
*/
|
||||
public int read(long[] d, int off, int len) throws IOException {
|
||||
public int read(long[] d, int off, int len)
|
||||
throws IOException
|
||||
{
|
||||
return rawRead(d, off * 8, len * 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read long array from the stream
|
||||
*
|
||||
*
|
||||
* @param d
|
||||
* @return the total number of bytes read into the buffer, or -1 if there is
|
||||
* no more data because the end of the stream has been reached.
|
||||
* no more data because the end of the stream has been reached.
|
||||
* @throws IOException
|
||||
*/
|
||||
public int read(long[] d) throws IOException {
|
||||
public int read(long[] d)
|
||||
throws IOException
|
||||
{
|
||||
return read(d, 0, d.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read double array from the stream
|
||||
*
|
||||
* @param d
|
||||
* input
|
||||
* @param off
|
||||
* offset
|
||||
* @param len
|
||||
* the number of double elements to read
|
||||
*
|
||||
* @param d input
|
||||
* @param off offset
|
||||
* @param len the number of double elements to read
|
||||
* @return the total number of bytes read into the buffer, or -1 if there is
|
||||
* no more data because the end of the stream has been reached.
|
||||
* no more data because the end of the stream has been reached.
|
||||
* @throws IOException
|
||||
*/
|
||||
public int read(double[] d, int off, int len) throws IOException {
|
||||
public int read(double[] d, int off, int len)
|
||||
throws IOException
|
||||
{
|
||||
return rawRead(d, off * 8, len * 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read double array from the stream
|
||||
*
|
||||
*
|
||||
* @param d
|
||||
* @return the total number of bytes read into the buffer, or -1 if there is
|
||||
* no more data because the end of the stream has been reached.
|
||||
* no more data because the end of the stream has been reached.
|
||||
* @throws IOException
|
||||
*/
|
||||
public int read(double[] d) throws IOException {
|
||||
public int read(double[] d)
|
||||
throws IOException
|
||||
{
|
||||
return read(d, 0, d.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read int array from the stream
|
||||
*
|
||||
*
|
||||
* @param d
|
||||
* @return the total number of bytes read into the buffer, or -1 if there is
|
||||
* no more data because the end of the stream has been reached.
|
||||
* no more data because the end of the stream has been reached.
|
||||
* @throws IOException
|
||||
*/
|
||||
public int read(int[] d) throws IOException {
|
||||
public int read(int[] d)
|
||||
throws IOException
|
||||
{
|
||||
return read(d, 0, d.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read int array from the stream
|
||||
*
|
||||
* @param d
|
||||
* input
|
||||
* @param off
|
||||
* offset
|
||||
* @param len
|
||||
* the number of int elements to read
|
||||
*
|
||||
* @param d input
|
||||
* @param off offset
|
||||
* @param len the number of int elements to read
|
||||
* @return the total number of bytes read into the buffer, or -1 if there is
|
||||
* no more data because the end of the stream has been reached.
|
||||
* no more data because the end of the stream has been reached.
|
||||
* @throws IOException
|
||||
*/
|
||||
public int read(int[] d, int off, int len) throws IOException {
|
||||
public int read(int[] d, int off, int len)
|
||||
throws IOException
|
||||
{
|
||||
return rawRead(d, off * 4, len * 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read float array from the stream
|
||||
*
|
||||
* @param d
|
||||
* input
|
||||
* @param off
|
||||
* offset
|
||||
* @param len
|
||||
* the number of float elements to read
|
||||
*
|
||||
* @param d input
|
||||
* @param off offset
|
||||
* @param len the number of float elements to read
|
||||
* @return the total number of bytes read into the buffer, or -1 if there is
|
||||
* no more data because the end of the stream has been reached.
|
||||
* no more data because the end of the stream has been reached.
|
||||
* @throws IOException
|
||||
*/
|
||||
public int read(float[] d, int off, int len) throws IOException {
|
||||
public int read(float[] d, int off, int len)
|
||||
throws IOException
|
||||
{
|
||||
return rawRead(d, off * 4, len * 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read float array from the stream
|
||||
*
|
||||
*
|
||||
* @param d
|
||||
* @return the total number of bytes read into the buffer, or -1 if there is
|
||||
* no more data because the end of the stream has been reached.
|
||||
* no more data because the end of the stream has been reached.
|
||||
* @throws IOException
|
||||
*/
|
||||
public int read(float[] d) throws IOException {
|
||||
public int read(float[] d)
|
||||
throws IOException
|
||||
{
|
||||
return read(d, 0, d.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read short array from the stream
|
||||
*
|
||||
* @param d
|
||||
* input
|
||||
* @param off
|
||||
* offset
|
||||
* @param len
|
||||
* the number of short elements to read
|
||||
*
|
||||
* @param d input
|
||||
* @param off offset
|
||||
* @param len the number of short elements to read
|
||||
* @return the total number of bytes read into the buffer, or -1 if there is
|
||||
* no more data because the end of the stream has been reached.
|
||||
* no more data because the end of the stream has been reached.
|
||||
* @throws IOException
|
||||
*/
|
||||
public int read(short[] d, int off, int len) throws IOException {
|
||||
public int read(short[] d, int off, int len)
|
||||
throws IOException
|
||||
{
|
||||
return rawRead(d, off * 2, len * 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read short array from the stream
|
||||
*
|
||||
*
|
||||
* @param d
|
||||
* @return the total number of bytes read into the buffer, or -1 if there is
|
||||
* no more data because the end of the stream has been reached.
|
||||
* no more data because the end of the stream has been reached.
|
||||
* @throws IOException
|
||||
*/
|
||||
public int read(short[] d) throws IOException {
|
||||
public int read(short[] d)
|
||||
throws IOException
|
||||
{
|
||||
return read(d, 0, d.length);
|
||||
}
|
||||
|
||||
protected boolean hasNextChunk() throws IOException {
|
||||
if (finishedReading)
|
||||
/**
|
||||
* Read next len bytes
|
||||
*
|
||||
* @param dest
|
||||
* @param offset
|
||||
* @param len
|
||||
* @return read bytes
|
||||
*/
|
||||
private int readNext(byte[] dest, int offset, int len)
|
||||
throws IOException
|
||||
{
|
||||
int readBytes = 0;
|
||||
while (readBytes < len) {
|
||||
int ret = in.read(dest, readBytes + offset, len - readBytes);
|
||||
if (ret == -1) {
|
||||
finishedReading = true;
|
||||
return readBytes;
|
||||
}
|
||||
readBytes += ret;
|
||||
}
|
||||
return readBytes;
|
||||
}
|
||||
|
||||
protected boolean hasNextChunk()
|
||||
throws IOException
|
||||
{
|
||||
if (finishedReading) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uncompressedCursor = 0;
|
||||
uncompressedLimit = 0;
|
||||
|
||||
int readBytes = 0;
|
||||
while (readBytes < 4) {
|
||||
int ret = in.read(chunkSizeBuf, readBytes, 4 - readBytes);
|
||||
if (ret == -1) {
|
||||
finishedReading = true;
|
||||
int readBytes = readNext(header, 0, 4);
|
||||
if (readBytes < 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int chunkSize = SnappyOutputStream.readInt(header, 0);
|
||||
if (chunkSize == SnappyCodec.MAGIC_HEADER_HEAD) {
|
||||
// Concatenated data
|
||||
int remainingHeaderSize = SnappyCodec.headerSize() - 4;
|
||||
readBytes = readNext(header, 4, remainingHeaderSize);
|
||||
if(readBytes < remainingHeaderSize) {
|
||||
throw new SnappyIOException(SnappyErrorCode.FAILED_TO_UNCOMPRESS, String.format("Insufficient header size in a concatenated block"));
|
||||
}
|
||||
|
||||
if (isValidHeader(header)) {
|
||||
return hasNextChunk();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
readBytes += ret;
|
||||
}
|
||||
int chunkSize = SnappyOutputStream.readInt(chunkSizeBuf, 0);
|
||||
|
||||
// chunkSize is negative
|
||||
if (chunkSize < 0) {
|
||||
throw new SnappyError(SnappyErrorCode.INVALID_CHUNK_SIZE, "chunkSize is too big or negative : " + chunkSize);
|
||||
}
|
||||
|
||||
// chunkSize is big
|
||||
if (chunkSize > maxChunkSize) {
|
||||
throw new SnappyError(SnappyErrorCode.FAILED_TO_UNCOMPRESS, String.format("Received chunkSize %,d is greater than max configured chunk size %,d", chunkSize, maxChunkSize));
|
||||
}
|
||||
|
||||
// extend the compressed data buffer size
|
||||
if (compressed == null || chunkSize > compressed.length) {
|
||||
compressed = new byte[chunkSize];
|
||||
// chunkSize exceeds limit
|
||||
try {
|
||||
compressed = new byte[chunkSize];
|
||||
}
|
||||
catch (java.lang.OutOfMemoryError e) {
|
||||
throw new SnappyError(SnappyErrorCode.INVALID_CHUNK_SIZE, e.getMessage());
|
||||
}
|
||||
}
|
||||
readBytes = 0;
|
||||
while (readBytes < chunkSize) {
|
||||
int ret = in.read(compressed, readBytes, chunkSize - readBytes);
|
||||
if (ret == -1)
|
||||
if (ret == -1) {
|
||||
break;
|
||||
}
|
||||
readBytes += ret;
|
||||
}
|
||||
if (readBytes < chunkSize) {
|
||||
@ -379,15 +490,19 @@ public class SnappyInputStream extends InputStream
|
||||
* @see java.io.InputStream#read()
|
||||
*/
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
public int read()
|
||||
throws IOException
|
||||
{
|
||||
if (uncompressedCursor < uncompressedLimit) {
|
||||
return uncompressed[uncompressedCursor++] & 0xFF;
|
||||
}
|
||||
else {
|
||||
if (hasNextChunk())
|
||||
if (hasNextChunk()) {
|
||||
return read();
|
||||
else
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -395,7 +510,9 @@ public class SnappyInputStream extends InputStream
|
||||
* @see java.io.InputStream#available()
|
||||
*/
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
public int available()
|
||||
throws IOException
|
||||
{
|
||||
if (uncompressedCursor < uncompressedLimit) {
|
||||
return uncompressedLimit - uncompressedCursor;
|
||||
}
|
||||
|
281
src/main/java/org/xerial/snappy/SnappyLoader.java
Executable file → Normal file
281
src/main/java/org/xerial/snappy/SnappyLoader.java
Executable file → Normal file
@ -19,13 +19,15 @@
|
||||
// SnappyLoader.java
|
||||
// Since: 2011/03/29
|
||||
//
|
||||
// $URL$
|
||||
// $URL$
|
||||
// $Author$
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
@ -36,10 +38,10 @@ import java.util.UUID;
|
||||
* user platform (<i>os.name</i> and <i>os.arch</i>). The natively compiled
|
||||
* libraries bundled to snappy-java contain the codes of the original snappy and
|
||||
* JNI programs to access Snappy.
|
||||
*
|
||||
* <p/>
|
||||
* In default, no configuration is required to use snappy-java, but you can load
|
||||
* your own native library created by 'make native' command.
|
||||
*
|
||||
* <p/>
|
||||
* This SnappyLoader searches for native libraries (snappyjava.dll,
|
||||
* libsnappy.so, etc.) in the following order:
|
||||
* <ol>
|
||||
@ -49,74 +51,85 @@ import java.util.UUID;
|
||||
* <li>(System property: <i>org.xerial.snappy.lib.path</i>)/(System property:
|
||||
* <i>org.xerial.lib.name</i>)
|
||||
* <li>One of the libraries embedded in snappy-java-(version).jar extracted into
|
||||
* (System property: <i>java.io.tempdir</i>). If
|
||||
* (System property: <i>java.io.tmpdir</i>). If
|
||||
* <i>org.xerial.snappy.tempdir</i> is set, use this folder instead of
|
||||
* <i>java.io.tempdir</i>.
|
||||
* <i>java.io.tmpdir</i>.
|
||||
* </ol>
|
||||
*
|
||||
* <p/>
|
||||
* <p>
|
||||
* If you do not want to use folder <i>java.io.tempdir</i>, set the System
|
||||
* If you do not want to use folder <i>java.io.tmpdir</i>, set the System
|
||||
* property <i>org.xerial.snappy.tempdir</i>. For example, to use
|
||||
* <i>/tmp/leo</i> as a temporary folder to copy native libraries, use -D option
|
||||
* of JVM:
|
||||
*
|
||||
* <p/>
|
||||
* <pre>
|
||||
* <code>
|
||||
* java -Dorg.xerial.snappy.tempdir="/tmp/leo" ...
|
||||
* </code>
|
||||
* </pre>
|
||||
*
|
||||
* <p/>
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @author leo
|
||||
*
|
||||
*/
|
||||
public class SnappyLoader
|
||||
{
|
||||
public static final String SNAPPY_SYSTEM_PROPERTIES_FILE = "org-xerial-snappy.properties";
|
||||
public static final String KEY_SNAPPY_LIB_PATH = "org.xerial.snappy.lib.path";
|
||||
public static final String KEY_SNAPPY_LIB_NAME = "org.xerial.snappy.lib.name";
|
||||
public static final String KEY_SNAPPY_TEMPDIR = "org.xerial.snappy.tempdir";
|
||||
public static final String KEY_SNAPPY_USE_SYSTEMLIB = "org.xerial.snappy.use.systemlib";
|
||||
public static final String SNAPPY_SYSTEM_PROPERTIES_FILE = "org-xerial-snappy.properties";
|
||||
public static final String KEY_SNAPPY_LIB_PATH = "org.xerial.snappy.lib.path";
|
||||
public static final String KEY_SNAPPY_LIB_NAME = "org.xerial.snappy.lib.name";
|
||||
public static final String KEY_SNAPPY_PUREJAVA = "org.xerial.snappy.purejava";
|
||||
public static final String KEY_SNAPPY_TEMPDIR = "org.xerial.snappy.tempdir";
|
||||
public static final String KEY_SNAPPY_USE_SYSTEMLIB = "org.xerial.snappy.use.systemlib";
|
||||
public static final String KEY_SNAPPY_DISABLE_BUNDLED_LIBS = "org.xerial.snappy.disable.bundled.libs"; // Depreciated, but preserved for backward compatibility
|
||||
|
||||
private static volatile boolean isLoaded = false;
|
||||
private static volatile SnappyNative api = null;
|
||||
private static boolean isLoaded = false;
|
||||
|
||||
private static volatile SnappyApi snappyApi = null;
|
||||
private static volatile BitShuffleNative bitshuffleApi = null;
|
||||
|
||||
private static File nativeLibFile = null;
|
||||
|
||||
static void cleanUpExtractedNativeLib() {
|
||||
if(nativeLibFile != null && nativeLibFile.exists())
|
||||
nativeLibFile.delete();
|
||||
static void cleanUpExtractedNativeLib()
|
||||
{
|
||||
if (nativeLibFile != null && nativeLibFile.exists()) {
|
||||
boolean deleted = nativeLibFile.delete();
|
||||
if (!deleted) {
|
||||
// Deleting native lib has failed, but it's not serious so simply ignore it here
|
||||
}
|
||||
snappyApi = null;
|
||||
bitshuffleApi = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the api instance.
|
||||
*
|
||||
* @param nativeCode
|
||||
* Set the `snappyApi` instance.
|
||||
*
|
||||
* @param apiImpl
|
||||
*/
|
||||
static synchronized void setApi(SnappyNative nativeCode)
|
||||
static synchronized void setSnappyApi(SnappyApi apiImpl)
|
||||
{
|
||||
api = nativeCode;
|
||||
snappyApi = apiImpl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* load system properties when configuration file of the name
|
||||
* {@link #SNAPPY_SYSTEM_PROPERTIES_FILE} is found
|
||||
*/
|
||||
private static void loadSnappySystemProperties() {
|
||||
private static void loadSnappySystemProperties()
|
||||
{
|
||||
try {
|
||||
InputStream is = Thread.currentThread().getContextClassLoader()
|
||||
.getResourceAsStream(SNAPPY_SYSTEM_PROPERTIES_FILE);
|
||||
|
||||
if (is == null)
|
||||
return; // no configuration file is found
|
||||
if (is == null) {
|
||||
return; // no configuration file is found
|
||||
}
|
||||
|
||||
// Load property file
|
||||
Properties props = new Properties();
|
||||
props.load(is);
|
||||
is.close();
|
||||
Enumeration< ? > names = props.propertyNames();
|
||||
Enumeration<?> names = props.propertyNames();
|
||||
while (names.hasMoreElements()) {
|
||||
String name = (String) names.nextElement();
|
||||
if (name.startsWith("org.xerial.snappy.")) {
|
||||
@ -136,69 +149,82 @@ public class SnappyLoader
|
||||
loadSnappySystemProperties();
|
||||
}
|
||||
|
||||
static synchronized SnappyNative load()
|
||||
static synchronized SnappyApi loadSnappyApi()
|
||||
{
|
||||
if (api != null)
|
||||
return api;
|
||||
|
||||
try {
|
||||
loadNativeLibrary();
|
||||
|
||||
setApi(new SnappyNative());
|
||||
isLoaded = true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, e.getMessage());
|
||||
if (snappyApi != null) {
|
||||
return snappyApi;
|
||||
}
|
||||
loadNativeLibrary();
|
||||
setSnappyApi(new SnappyNative());
|
||||
return snappyApi;
|
||||
}
|
||||
|
||||
return api;
|
||||
static synchronized BitShuffleNative loadBitShuffleApi()
|
||||
{
|
||||
if (bitshuffleApi != null) {
|
||||
return bitshuffleApi;
|
||||
}
|
||||
loadNativeLibrary();
|
||||
bitshuffleApi = new BitShuffleNative();
|
||||
return bitshuffleApi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a native library of snappy-java
|
||||
*/
|
||||
private static void loadNativeLibrary() {
|
||||
|
||||
nativeLibFile = findNativeLibrary();
|
||||
if (nativeLibFile != null) {
|
||||
// Load extracted or specified snappyjava native library.
|
||||
System.load(nativeLibFile.getAbsolutePath());
|
||||
}
|
||||
else {
|
||||
// Load preinstalled snappyjava (in the path -Djava.library.path)
|
||||
System.loadLibrary("snappyjava");
|
||||
private synchronized static void loadNativeLibrary()
|
||||
{
|
||||
if (!isLoaded) {
|
||||
try {
|
||||
nativeLibFile = findNativeLibrary();
|
||||
if (nativeLibFile != null) {
|
||||
// Load extracted or specified snappyjava native library.
|
||||
System.load(nativeLibFile.getAbsolutePath());
|
||||
} else {
|
||||
// Load preinstalled snappyjava (in the path -Djava.library.path)
|
||||
System.loadLibrary("snappyjava");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, e.getMessage());
|
||||
}
|
||||
isLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static boolean contentsEquals(InputStream in1, InputStream in2) throws IOException {
|
||||
if(!(in1 instanceof BufferedInputStream)) {
|
||||
in1 = new BufferedInputStream(in1);
|
||||
private static boolean contentsEquals(InputStream in1, InputStream in2)
|
||||
throws IOException
|
||||
{
|
||||
if (!(in1 instanceof BufferedInputStream)) {
|
||||
in1 = new BufferedInputStream(in1);
|
||||
}
|
||||
if(!(in2 instanceof BufferedInputStream)) {
|
||||
in2 = new BufferedInputStream(in2);
|
||||
if (!(in2 instanceof BufferedInputStream)) {
|
||||
in2 = new BufferedInputStream(in2);
|
||||
}
|
||||
|
||||
int ch = in1.read();
|
||||
while(ch != -1) {
|
||||
int ch2 = in2.read();
|
||||
if(ch != ch2)
|
||||
while (ch != -1) {
|
||||
int ch2 = in2.read();
|
||||
if (ch != ch2) {
|
||||
return false;
|
||||
}
|
||||
ch = in1.read();
|
||||
}
|
||||
int ch2 = in2.read();
|
||||
return ch2 == -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the specified library file to the target folder
|
||||
*
|
||||
*
|
||||
* @param libFolderForCurrentOS
|
||||
* @param libraryFileName
|
||||
* @param targetFolder
|
||||
* @return
|
||||
*/
|
||||
private static File extractLibraryFile(String libFolderForCurrentOS, String libraryFileName, String targetFolder) {
|
||||
private static File extractLibraryFile(String libFolderForCurrentOS, String libraryFileName, String targetFolder)
|
||||
{
|
||||
String nativeLibraryFilePath = libFolderForCurrentOS + "/" + libraryFileName;
|
||||
|
||||
// Attach UUID to the native library file to ensure multiple class loaders can read the libsnappy-java multiple times.
|
||||
@ -208,44 +234,61 @@ public class SnappyLoader
|
||||
|
||||
try {
|
||||
// Extract a native library file into the target directory
|
||||
InputStream reader = SnappyLoader.class.getResourceAsStream(nativeLibraryFilePath);
|
||||
FileOutputStream writer = new FileOutputStream(extractedLibFile);
|
||||
InputStream reader = null;
|
||||
FileOutputStream writer = null;
|
||||
try {
|
||||
byte[] buffer = new byte[8192];
|
||||
int bytesRead = 0;
|
||||
while ((bytesRead = reader.read(buffer)) != -1) {
|
||||
writer.write(buffer, 0, bytesRead);
|
||||
reader = getResourceAsInputStream(nativeLibraryFilePath);
|
||||
try {
|
||||
writer = new FileOutputStream(extractedLibFile);
|
||||
|
||||
byte[] buffer = new byte[8192];
|
||||
int bytesRead = 0;
|
||||
while ((bytesRead = reader.read(buffer)) != -1) {
|
||||
writer.write(buffer, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (writer != null) {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
|
||||
// Delete the extracted lib file on JVM exit.
|
||||
extractedLibFile.deleteOnExit();
|
||||
|
||||
if(writer != null)
|
||||
writer.close();
|
||||
if(reader != null)
|
||||
reader.close();
|
||||
}
|
||||
|
||||
// Set executable (x) flag to enable Java to load the native library
|
||||
extractedLibFile.setReadable(true);
|
||||
extractedLibFile.setWritable(true, true);
|
||||
extractedLibFile.setExecutable(true);
|
||||
|
||||
boolean success = extractedLibFile.setReadable(true) &&
|
||||
extractedLibFile.setWritable(true, true) &&
|
||||
extractedLibFile.setExecutable(true);
|
||||
if (!success) {
|
||||
// Setting file flag may fail, but in this case another error will be thrown in later phase
|
||||
}
|
||||
|
||||
// Check whether the contents are properly copied from the resource folder
|
||||
{
|
||||
InputStream nativeIn = SnappyLoader.class.getResourceAsStream(nativeLibraryFilePath);
|
||||
InputStream extractedLibIn = new FileInputStream(extractedLibFile);
|
||||
InputStream nativeIn = null;
|
||||
InputStream extractedLibIn = null;
|
||||
try {
|
||||
if(!contentsEquals(nativeIn, extractedLibIn))
|
||||
nativeIn = getResourceAsInputStream(nativeLibraryFilePath);
|
||||
extractedLibIn = new FileInputStream(extractedLibFile);
|
||||
|
||||
if (!contentsEquals(nativeIn, extractedLibIn)) {
|
||||
throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, String.format("Failed to write a native library file at %s", extractedLibFile));
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if(nativeIn != null)
|
||||
if (nativeIn != null) {
|
||||
nativeIn.close();
|
||||
if(extractedLibIn != null)
|
||||
}
|
||||
if (extractedLibIn != null) {
|
||||
extractedLibIn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,76 +300,84 @@ public class SnappyLoader
|
||||
}
|
||||
}
|
||||
|
||||
static File findNativeLibrary() {
|
||||
static File findNativeLibrary()
|
||||
{
|
||||
|
||||
boolean useSystemLib = Boolean.parseBoolean(System.getProperty(KEY_SNAPPY_USE_SYSTEMLIB, "false"));
|
||||
boolean disabledBundledLibs = Boolean
|
||||
.parseBoolean(System.getProperty(KEY_SNAPPY_DISABLE_BUNDLED_LIBS, "false"));
|
||||
if (useSystemLib || disabledBundledLibs)
|
||||
if (useSystemLib || disabledBundledLibs) {
|
||||
return null; // Use a pre-installed libsnappyjava
|
||||
}
|
||||
|
||||
// Try to load the library in org.xerial.snappy.lib.path */
|
||||
String snappyNativeLibraryPath = System.getProperty(KEY_SNAPPY_LIB_PATH);
|
||||
String snappyNativeLibraryName = System.getProperty(KEY_SNAPPY_LIB_NAME);
|
||||
|
||||
// Resolve the library file name with a suffix (e.g., dll, .so, etc.)
|
||||
if (snappyNativeLibraryName == null)
|
||||
// Resolve the library file name with a suffix (e.g., dll, .so, etc.)
|
||||
if (snappyNativeLibraryName == null) {
|
||||
snappyNativeLibraryName = System.mapLibraryName("snappyjava");
|
||||
}
|
||||
|
||||
if (snappyNativeLibraryPath != null) {
|
||||
File nativeLib = new File(snappyNativeLibraryPath, snappyNativeLibraryName);
|
||||
if (nativeLib.exists())
|
||||
if (nativeLib.exists()) {
|
||||
return nativeLib;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Load an OS-dependent native library inside a jar file
|
||||
snappyNativeLibraryPath = "/org/xerial/snappy/native/" + OSInfo.getNativeLibFolderPathForCurrentOS();
|
||||
boolean hasNativeLib = hasResource(snappyNativeLibraryPath + "/" + snappyNativeLibraryName);
|
||||
if(!hasNativeLib) {
|
||||
if(OSInfo.getOSName().equals("Mac")) {
|
||||
if (!hasNativeLib) {
|
||||
if (OSInfo.getOSName().equals("Mac")) {
|
||||
// Fix for openjdk7 for Mac
|
||||
String altName = "libsnappyjava.jnilib";
|
||||
if(hasResource(snappyNativeLibraryPath + "/" + altName)) {
|
||||
String altName = "libsnappyjava.dylib";
|
||||
if (hasResource(snappyNativeLibraryPath + "/" + altName)) {
|
||||
snappyNativeLibraryName = altName;
|
||||
hasNativeLib = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!hasNativeLib) {
|
||||
if (!hasNativeLib) {
|
||||
String errorMessage = String.format("no native library is found for os.name=%s and os.arch=%s", OSInfo.getOSName(), OSInfo.getArchName());
|
||||
throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, errorMessage);
|
||||
}
|
||||
|
||||
// Temporary folder for the native lib. Use the value of org.xerial.snappy.tempdir or java.io.tmpdir
|
||||
String tempFolder = new File(System.getProperty(KEY_SNAPPY_TEMPDIR,
|
||||
System.getProperty("java.io.tmpdir"))).getAbsolutePath();
|
||||
File tempFolder = new File(System.getProperty(KEY_SNAPPY_TEMPDIR, System.getProperty("java.io.tmpdir")));
|
||||
if (!tempFolder.exists()) {
|
||||
boolean created = tempFolder.mkdirs();
|
||||
if (!created) {
|
||||
// if created == false, it will fail eventually in the later part
|
||||
}
|
||||
}
|
||||
|
||||
// Extract and load a native library inside the jar file
|
||||
return extractLibraryFile(snappyNativeLibraryPath, snappyNativeLibraryName, tempFolder);
|
||||
return extractLibraryFile(snappyNativeLibraryPath, snappyNativeLibraryName, tempFolder.getAbsolutePath());
|
||||
}
|
||||
|
||||
|
||||
private static boolean hasResource(String path) {
|
||||
private static boolean hasResource(String path)
|
||||
{
|
||||
return SnappyLoader.class.getResource(path) != null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the snappy-java version by reading pom.properties embedded in jar.
|
||||
* This version data is used as a suffix of a dll file extracted from the
|
||||
* jar.
|
||||
*
|
||||
*
|
||||
* @return the version string
|
||||
*/
|
||||
public static String getVersion() {
|
||||
public static String getVersion()
|
||||
{
|
||||
|
||||
URL versionFile = SnappyLoader.class
|
||||
.getResource("/META-INF/maven/org.xerial.snappy/snappy-java/pom.properties");
|
||||
if (versionFile == null)
|
||||
if (versionFile == null) {
|
||||
versionFile = SnappyLoader.class.getResource("/org/xerial/snappy/VERSION");
|
||||
}
|
||||
|
||||
String version = "unknown";
|
||||
try {
|
||||
@ -334,8 +385,9 @@ public class SnappyLoader
|
||||
Properties versionData = new Properties();
|
||||
versionData.load(versionFile.openStream());
|
||||
version = versionData.getProperty("version", version);
|
||||
if (version.equals("unknown"))
|
||||
version = versionData.getProperty("VERSION", version);
|
||||
if (version.equals("unknown")) {
|
||||
version = versionData.getProperty("SNAPPY_VERSION", version);
|
||||
}
|
||||
version = version.trim().replaceAll("[^0-9M\\.]", "");
|
||||
}
|
||||
}
|
||||
@ -345,4 +397,15 @@ public class SnappyLoader
|
||||
return version;
|
||||
}
|
||||
|
||||
private static InputStream getResourceAsInputStream(String resourcePath) throws IOException {
|
||||
URL url = SnappyLoader.class.getResource(resourcePath);
|
||||
URLConnection connection = url.openConnection();
|
||||
if (connection instanceof JarURLConnection) {
|
||||
JarURLConnection jarConnection = (JarURLConnection) connection;
|
||||
jarConnection.setUseCaches(false); // workaround for https://bugs.openjdk.org/browse/JDK-8205976
|
||||
return jarConnection.getInputStream();
|
||||
} else {
|
||||
return connection.getInputStream();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,309 +1,299 @@
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <snappy.h>
|
||||
#include "SnappyNative.h"
|
||||
|
||||
void throw_exception(JNIEnv *env, jobject self, int errorCode)
|
||||
{
|
||||
jclass c = env->FindClass("org/xerial/snappy/SnappyNative");
|
||||
if(c==0)
|
||||
return;
|
||||
jmethodID mth_throwex = env->GetMethodID(c, "throw_error", "(I)V");
|
||||
if(mth_throwex == 0)
|
||||
return;
|
||||
env->CallVoidMethod(self, mth_throwex, (jint) errorCode);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_xerial_snappy_SnappyNative_nativeLibraryVersion
|
||||
(JNIEnv * env, jobject self)
|
||||
{
|
||||
return env->NewStringUTF("1.1.0");
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_rawCompress__JJJ
|
||||
(JNIEnv* env, jobject self, jlong srcAddr, jlong length, jlong destAddr) {
|
||||
size_t compressedLength;
|
||||
snappy::RawCompress((char*) srcAddr, (size_t) length, (char*) destAddr, &compressedLength);
|
||||
return (jlong) compressedLength;
|
||||
}
|
||||
|
||||
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__JJJ
|
||||
(JNIEnv* env, jobject self, jlong srcAddr, jlong length, jlong destAddr) {
|
||||
|
||||
size_t uncompressedLength;
|
||||
snappy::GetUncompressedLength((char*) srcAddr, (size_t) length, &uncompressedLength);
|
||||
bool ret = snappy::RawUncompress((char*) srcAddr, (size_t) length, (char*) destAddr);
|
||||
|
||||
if(!ret) {
|
||||
throw_exception(env, self, 5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (jlong) uncompressedLength;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_Snappy
|
||||
* Method: compress
|
||||
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;)J
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawCompress__Ljava_nio_ByteBuffer_2IILjava_nio_ByteBuffer_2I
|
||||
(JNIEnv* env, jobject self, jobject uncompressed, jint upos, jint ulen, jobject compressed, jint cpos)
|
||||
{
|
||||
char* uncompressedBuffer = (char*) env->GetDirectBufferAddress(uncompressed);
|
||||
char* compressedBuffer = (char*) env->GetDirectBufferAddress(compressed);
|
||||
if(uncompressedBuffer == 0 || compressedBuffer == 0) {
|
||||
throw_exception(env, self, 3);
|
||||
return (jint) 0;
|
||||
}
|
||||
|
||||
size_t compressedLength;
|
||||
snappy::RawCompress(uncompressedBuffer + upos, (size_t) ulen, compressedBuffer + cpos, &compressedLength);
|
||||
return (jint) compressedLength;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawCompress__Ljava_lang_Object_2IILjava_lang_Object_2I
|
||||
(JNIEnv * env, jobject self, jobject input, jint inputOffset, jint inputLen, jobject output, jint outputOffset)
|
||||
{
|
||||
char* in = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
||||
char* out = (char*) env->GetPrimitiveArrayCritical((jarray) output, 0);
|
||||
if(in == 0 || out == 0) {
|
||||
// out of memory
|
||||
if(in != 0) {
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
}
|
||||
if(out != 0) {
|
||||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||
}
|
||||
throw_exception(env, self, 4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t compressedLength;
|
||||
snappy::RawCompress(in + inputOffset, (size_t) inputLen, out + outputOffset, &compressedLength);
|
||||
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||
|
||||
return (jint) compressedLength;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__Ljava_lang_Object_2IILjava_lang_Object_2I
|
||||
(JNIEnv * env, jobject self, jobject input, jint inputOffset, jint inputLength, jobject output, jint outputOffset)
|
||||
{
|
||||
char* in = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
||||
char* out = (char*) env->GetPrimitiveArrayCritical((jarray) output, 0);
|
||||
if(in == 0 || out == 0) {
|
||||
// out of memory
|
||||
if(in != 0) {
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
}
|
||||
if(out != 0) {
|
||||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||
}
|
||||
throw_exception(env, self, 4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t uncompressedLength;
|
||||
snappy::GetUncompressedLength(in + inputOffset, (size_t) inputLength, &uncompressedLength);
|
||||
bool ret = snappy::RawUncompress(in + inputOffset, (size_t) inputLength, out + outputOffset);
|
||||
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||
|
||||
if(!ret) {
|
||||
throw_exception(env, self, 5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (jint) uncompressedLength;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_Snappy
|
||||
* Method: uncompress
|
||||
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;)Z
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__Ljava_nio_ByteBuffer_2IILjava_nio_ByteBuffer_2I
|
||||
(JNIEnv * env, jobject self, jobject compressed, jint cpos, jint clen, jobject decompressed, jint dpos)
|
||||
{
|
||||
char* compressedBuffer = (char*) env->GetDirectBufferAddress(compressed);
|
||||
char* decompressedBuffer = (char*) env->GetDirectBufferAddress(decompressed);
|
||||
if(compressedBuffer == 0 || decompressedBuffer == 0) {
|
||||
throw_exception(env, self, 3);
|
||||
return (jint) 0;
|
||||
}
|
||||
|
||||
size_t decompressedLength;
|
||||
snappy::GetUncompressedLength(compressedBuffer + cpos, (size_t) clen, &decompressedLength);
|
||||
bool ret = snappy::RawUncompress(compressedBuffer + cpos, (size_t) clen, decompressedBuffer + dpos);
|
||||
if(!ret) {
|
||||
throw_exception(env, self, 5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (jint) decompressedLength;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_Snappy
|
||||
* Method: maxCompressedLength
|
||||
* Signature: (J)J
|
||||
*/
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_maxCompressedLength
|
||||
(JNIEnv *, jobject, jint size)
|
||||
{
|
||||
size_t l = snappy::MaxCompressedLength((size_t) size);
|
||||
return (jint) l;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_Snappy
|
||||
* Method: getUncompressedLength
|
||||
* Signature: (Ljava/nio/ByteBuffer;)J
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_uncompressedLength__Ljava_nio_ByteBuffer_2II
|
||||
(JNIEnv * env, jobject self, jobject compressed, jint cpos, jint clen)
|
||||
{
|
||||
char* compressedBuffer = (char*) env->GetDirectBufferAddress(compressed);
|
||||
if(compressedBuffer == 0) {
|
||||
throw_exception(env, self, 3);
|
||||
return (jint) 0;
|
||||
}
|
||||
|
||||
size_t result;
|
||||
bool ret = snappy::GetUncompressedLength(compressedBuffer + cpos, (size_t) clen, &result);
|
||||
if(!ret) {
|
||||
throw_exception(env, self, 2);
|
||||
return 0;
|
||||
}
|
||||
return (jint) result;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_uncompressedLength__Ljava_lang_Object_2II
|
||||
(JNIEnv * env, jobject self, jobject input, jint offset, jint length)
|
||||
{
|
||||
char* in = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
||||
if(in == 0) {
|
||||
// out of memory
|
||||
throw_exception(env, self, 4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t result;
|
||||
bool ret = snappy::GetUncompressedLength(in + offset, (size_t) length, &result);
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
|
||||
if(!ret) {
|
||||
throw_exception(env, self, 2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (jint) result;
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_uncompressedLength__JJ
|
||||
(JNIEnv *env, jobject self, jlong inputAddr, jlong len) {
|
||||
|
||||
|
||||
size_t result;
|
||||
bool ret = snappy::GetUncompressedLength((char*) inputAddr, (size_t) len, &result);
|
||||
if(!ret) {
|
||||
throw_exception(env, self, 2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (jint) result;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_SnappyNative_isValidCompressedBuffer__Ljava_nio_ByteBuffer_2II
|
||||
(JNIEnv * env, jobject self, jobject compressed, jint cpos, jint clen)
|
||||
{
|
||||
char* compressedBuffer = (char*) env->GetDirectBufferAddress(compressed);
|
||||
if(compressedBuffer == 0) {
|
||||
throw_exception(env, self, 3);
|
||||
return (jint) 0;
|
||||
}
|
||||
bool ret = snappy::IsValidCompressedBuffer(compressedBuffer + cpos, (size_t) clen);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_SnappyNative_isValidCompressedBuffer__Ljava_lang_Object_2II
|
||||
(JNIEnv * env, jobject self, jobject input, jint offset, jint length)
|
||||
{
|
||||
char* in = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
||||
if(in == 0) {
|
||||
// out of memory
|
||||
throw_exception(env, self, 4);
|
||||
return 0;
|
||||
}
|
||||
bool ret = snappy::IsValidCompressedBuffer(in + offset, (size_t) length);
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_SnappyNative_isValidCompressedBuffer__JJJ
|
||||
(JNIEnv * env, jobject self, jlong inputAddr, jlong offset, jlong length)
|
||||
{
|
||||
if(inputAddr == 0) {
|
||||
// out of memory
|
||||
throw_exception(env, self, 4);
|
||||
return 0;
|
||||
}
|
||||
bool ret = snappy::IsValidCompressedBuffer((char*) (inputAddr + offset), (size_t) length);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_xerial_snappy_SnappyNative_arrayCopy
|
||||
(JNIEnv * env, jobject self, jobject input, jint offset, jint length, jobject output, jint output_offset)
|
||||
{
|
||||
char* src = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
||||
char* dest = (char*) env->GetPrimitiveArrayCritical((jarray) output, 0);
|
||||
if(src == 0 || dest == 0) {
|
||||
// out of memory
|
||||
if(src != 0) {
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, src, 0);
|
||||
}
|
||||
if(dest != 0) {
|
||||
env->ReleasePrimitiveArrayCritical((jarray) output, dest, 0);
|
||||
}
|
||||
throw_exception(env, self, 4);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(dest+output_offset, src+offset, (size_t) length);
|
||||
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, src, 0);
|
||||
env->ReleasePrimitiveArrayCritical((jarray) output, dest, 0);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <snappy.h>
|
||||
#include "SnappyNative.h"
|
||||
|
||||
inline void throw_exception(JNIEnv *env, jobject self, int errorCode)
|
||||
{
|
||||
jclass c = env->GetObjectClass(self);
|
||||
if(c==0)
|
||||
return;
|
||||
jmethodID mth_throwex = env->GetMethodID(c, "throw_error", "(I)V");
|
||||
if(mth_throwex == 0)
|
||||
return;
|
||||
env->CallVoidMethod(self, mth_throwex, (jint) errorCode);
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_xerial_snappy_SnappyNative_nativeLibraryVersion
|
||||
(JNIEnv * env, jobject self)
|
||||
{
|
||||
// TODO: Do we need to read this library version from resources/org/xerial/snappy/VERSION?
|
||||
return env->NewStringUTF("1.1.3");
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_rawCompress__JJJ
|
||||
(JNIEnv* env, jobject self, jlong srcAddr, jlong length, jlong destAddr) {
|
||||
size_t compressedLength;
|
||||
snappy::RawCompress((char*) srcAddr, (size_t) length, (char*) destAddr, &compressedLength);
|
||||
return (jlong) compressedLength;
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__JJJ
|
||||
(JNIEnv* env, jobject self, jlong srcAddr, jlong length, jlong destAddr) {
|
||||
|
||||
size_t uncompressedLength;
|
||||
snappy::GetUncompressedLength((char*) srcAddr, (size_t) length, &uncompressedLength);
|
||||
bool ret = snappy::RawUncompress((char*) srcAddr, (size_t) length, (char*) destAddr);
|
||||
|
||||
if(!ret) {
|
||||
throw_exception(env, self, 5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (jlong) uncompressedLength;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_Snappy
|
||||
* Method: compress
|
||||
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;)J
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawCompress__Ljava_nio_ByteBuffer_2IILjava_nio_ByteBuffer_2I
|
||||
(JNIEnv* env, jobject self, jobject uncompressed, jint upos, jint ulen, jobject compressed, jint cpos)
|
||||
{
|
||||
char* uncompressedBuffer = (char*) env->GetDirectBufferAddress(uncompressed);
|
||||
char* compressedBuffer = (char*) env->GetDirectBufferAddress(compressed);
|
||||
if(uncompressedBuffer == 0 || compressedBuffer == 0) {
|
||||
throw_exception(env, self, 3);
|
||||
return (jint) 0;
|
||||
}
|
||||
|
||||
size_t compressedLength;
|
||||
snappy::RawCompress(uncompressedBuffer + upos, (size_t) ulen, compressedBuffer + cpos, &compressedLength);
|
||||
return (jint) compressedLength;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawCompress__Ljava_lang_Object_2IILjava_lang_Object_2I
|
||||
(JNIEnv * env, jobject self, jobject input, jint inputOffset, jint inputLen, jobject output, jint outputOffset)
|
||||
{
|
||||
char* in = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
||||
char* out = (char*) env->GetPrimitiveArrayCritical((jarray) output, 0);
|
||||
if(in == 0 || out == 0) {
|
||||
// out of memory
|
||||
if(in != 0) {
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
}
|
||||
if(out != 0) {
|
||||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||
}
|
||||
throw_exception(env, self, 4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t compressedLength;
|
||||
snappy::RawCompress(in + inputOffset, (size_t) inputLen, out + outputOffset, &compressedLength);
|
||||
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||
|
||||
return (jint) compressedLength;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__Ljava_lang_Object_2IILjava_lang_Object_2I
|
||||
(JNIEnv * env, jobject self, jobject input, jint inputOffset, jint inputLength, jobject output, jint outputOffset)
|
||||
{
|
||||
char* in = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
||||
char* out = (char*) env->GetPrimitiveArrayCritical((jarray) output, 0);
|
||||
if(in == 0 || out == 0) {
|
||||
// out of memory
|
||||
if(in != 0) {
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
}
|
||||
if(out != 0) {
|
||||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||
}
|
||||
throw_exception(env, self, 4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t uncompressedLength;
|
||||
snappy::GetUncompressedLength(in + inputOffset, (size_t) inputLength, &uncompressedLength);
|
||||
bool ret = snappy::RawUncompress(in + inputOffset, (size_t) inputLength, out + outputOffset);
|
||||
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||
|
||||
if(!ret) {
|
||||
throw_exception(env, self, 5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (jint) uncompressedLength;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_Snappy
|
||||
* Method: uncompress
|
||||
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;)Z
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__Ljava_nio_ByteBuffer_2IILjava_nio_ByteBuffer_2I
|
||||
(JNIEnv * env, jobject self, jobject compressed, jint cpos, jint clen, jobject decompressed, jint dpos)
|
||||
{
|
||||
char* compressedBuffer = (char*) env->GetDirectBufferAddress(compressed);
|
||||
char* decompressedBuffer = (char*) env->GetDirectBufferAddress(decompressed);
|
||||
if(compressedBuffer == 0 || decompressedBuffer == 0) {
|
||||
throw_exception(env, self, 3);
|
||||
return (jint) 0;
|
||||
}
|
||||
|
||||
size_t decompressedLength;
|
||||
snappy::GetUncompressedLength(compressedBuffer + cpos, (size_t) clen, &decompressedLength);
|
||||
bool ret = snappy::RawUncompress(compressedBuffer + cpos, (size_t) clen, decompressedBuffer + dpos);
|
||||
if(!ret) {
|
||||
throw_exception(env, self, 5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (jint) decompressedLength;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_Snappy
|
||||
* Method: maxCompressedLength
|
||||
* Signature: (J)J
|
||||
*/
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_maxCompressedLength
|
||||
(JNIEnv *, jobject, jint size)
|
||||
{
|
||||
size_t l = snappy::MaxCompressedLength((size_t) size);
|
||||
return (jint) l;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_Snappy
|
||||
* Method: getUncompressedLength
|
||||
* Signature: (Ljava/nio/ByteBuffer;)J
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_uncompressedLength__Ljava_nio_ByteBuffer_2II
|
||||
(JNIEnv * env, jobject self, jobject compressed, jint cpos, jint clen)
|
||||
{
|
||||
char* compressedBuffer = (char*) env->GetDirectBufferAddress(compressed);
|
||||
if(compressedBuffer == 0) {
|
||||
throw_exception(env, self, 3);
|
||||
return (jint) 0;
|
||||
}
|
||||
|
||||
size_t result;
|
||||
bool ret = snappy::GetUncompressedLength(compressedBuffer + cpos, (size_t) clen, &result);
|
||||
if(!ret) {
|
||||
throw_exception(env, self, 2);
|
||||
return 0;
|
||||
}
|
||||
return (jint) result;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_uncompressedLength__Ljava_lang_Object_2II
|
||||
(JNIEnv * env, jobject self, jobject input, jint offset, jint length)
|
||||
{
|
||||
char* in = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
||||
if(in == 0) {
|
||||
// out of memory
|
||||
throw_exception(env, self, 4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t result;
|
||||
bool ret = snappy::GetUncompressedLength(in + offset, (size_t) length, &result);
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
|
||||
if(!ret) {
|
||||
throw_exception(env, self, 2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (jint) result;
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_uncompressedLength__JJ
|
||||
(JNIEnv *env, jobject self, jlong inputAddr, jlong len) {
|
||||
|
||||
|
||||
size_t result;
|
||||
bool ret = snappy::GetUncompressedLength((char*) inputAddr, (size_t) len, &result);
|
||||
if(!ret) {
|
||||
throw_exception(env, self, 2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (jint) result;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_SnappyNative_isValidCompressedBuffer__Ljava_nio_ByteBuffer_2II
|
||||
(JNIEnv * env, jobject self, jobject compressed, jint cpos, jint clen)
|
||||
{
|
||||
char* compressedBuffer = (char*) env->GetDirectBufferAddress(compressed);
|
||||
if(compressedBuffer == 0) {
|
||||
throw_exception(env, self, 3);
|
||||
return (jint) 0;
|
||||
}
|
||||
bool ret = snappy::IsValidCompressedBuffer(compressedBuffer + cpos, (size_t) clen);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_SnappyNative_isValidCompressedBuffer__Ljava_lang_Object_2II
|
||||
(JNIEnv * env, jobject self, jobject input, jint offset, jint length)
|
||||
{
|
||||
char* in = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
||||
if(in == 0) {
|
||||
// out of memory
|
||||
throw_exception(env, self, 4);
|
||||
return 0;
|
||||
}
|
||||
bool ret = snappy::IsValidCompressedBuffer(in + offset, (size_t) length);
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_SnappyNative_isValidCompressedBuffer__JJJ
|
||||
(JNIEnv * env, jobject self, jlong inputAddr, jlong offset, jlong length)
|
||||
{
|
||||
if(inputAddr == 0) {
|
||||
// out of memory
|
||||
throw_exception(env, self, 4);
|
||||
return 0;
|
||||
}
|
||||
bool ret = snappy::IsValidCompressedBuffer((char*) (inputAddr + offset), (size_t) length);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_xerial_snappy_SnappyNative_arrayCopy
|
||||
(JNIEnv * env, jobject self, jobject input, jint offset, jint length, jobject output, jint output_offset)
|
||||
{
|
||||
char* src = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
||||
char* dest = (char*) env->GetPrimitiveArrayCritical((jarray) output, 0);
|
||||
if(src == 0 || dest == 0) {
|
||||
// out of memory
|
||||
if(src != 0) {
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, src, 0);
|
||||
}
|
||||
if(dest != 0) {
|
||||
env->ReleasePrimitiveArrayCritical((jarray) output, dest, 0);
|
||||
}
|
||||
throw_exception(env, self, 4);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(dest+output_offset, src+offset, (size_t) length);
|
||||
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, src, 0);
|
||||
env->ReleasePrimitiveArrayCritical((jarray) output, dest, 0);
|
||||
}
|
||||
|
||||
|
0
src/main/java/org/xerial/snappy/SnappyNative.h
Executable file → Normal file
0
src/main/java/org/xerial/snappy/SnappyNative.h
Executable file → Normal file
@ -1,87 +1,114 @@
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
//--------------------------------------
|
||||
// snappy-java Project
|
||||
//
|
||||
// SnappyNative.java
|
||||
// Since: 2011/03/30
|
||||
//
|
||||
// $URL$
|
||||
// $Author$
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* JNI interface of the {@link Snappy} implementation. The native method in this class is
|
||||
* defined in SnappyNative.h (genereted by javah) and SnappyNative.cpp
|
||||
*
|
||||
* <p>
|
||||
* <b> DO NOT USE THIS CLASS since the direct use of this class might break the
|
||||
* native library code loading in {@link SnappyLoader}. </b>
|
||||
* </p>
|
||||
*
|
||||
* @author leo
|
||||
*
|
||||
*/
|
||||
public class SnappyNative
|
||||
{
|
||||
|
||||
public native String nativeLibraryVersion();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Generic compression/decompression routines.
|
||||
// ------------------------------------------------------------------------
|
||||
public native long rawCompress(long inputAddr, long inputSize, long destAddr) throws IOException;
|
||||
public native long rawUncompress(long inputAddr, long inputSize, long destAddr) throws IOException;
|
||||
|
||||
public native int rawCompress(ByteBuffer input, int inputOffset, int inputLength, ByteBuffer compressed,
|
||||
int outputOffset) throws IOException;
|
||||
|
||||
public native int rawCompress(Object input, int inputOffset, int inputByteLength, Object output, int outputOffset) throws IOException;
|
||||
|
||||
public native int rawUncompress(ByteBuffer compressed, int inputOffset, int inputLength, ByteBuffer uncompressed,
|
||||
int outputOffset) throws IOException;
|
||||
|
||||
public native int rawUncompress(Object input, int inputOffset, int inputLength, Object output, int outputOffset)
|
||||
throws IOException;
|
||||
|
||||
// Returns the maximal size of the compressed representation of
|
||||
// input data that is "source_bytes" bytes in length;
|
||||
public native int maxCompressedLength(int source_bytes);
|
||||
|
||||
// This operation takes O(1) time.
|
||||
public native int uncompressedLength(ByteBuffer compressed, int offset, int len) throws IOException;
|
||||
|
||||
public native int uncompressedLength(Object input, int offset, int len) throws IOException;
|
||||
|
||||
public native long uncompressedLength(long inputAddr, long len) throws IOException;
|
||||
|
||||
public native boolean isValidCompressedBuffer(ByteBuffer compressed, int offset, int len) throws IOException;
|
||||
|
||||
public native boolean isValidCompressedBuffer(Object input, int offset, int len) throws IOException;
|
||||
|
||||
public native boolean isValidCompressedBuffer(long inputAddr, long offset, long len) throws IOException;
|
||||
|
||||
public native void arrayCopy(Object src, int offset, int byteLength, Object dest, int dOffset) throws IOException;
|
||||
|
||||
public void throw_error(int errorCode) throws IOException {
|
||||
throw new IOException(String.format("%s(%d)", SnappyErrorCode.getErrorMessage(errorCode), errorCode));
|
||||
}
|
||||
|
||||
}
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
//--------------------------------------
|
||||
// snappy-java Project
|
||||
//
|
||||
// SnappyNative.java
|
||||
// Since: 2011/03/30
|
||||
//
|
||||
// $URL$
|
||||
// $Author$
|
||||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* JNI interface of the {@link Snappy} implementation. The native method in this class is
|
||||
* defined in SnappyNative.h (genereted by javah) and SnappyNative.cpp
|
||||
* <p/>
|
||||
* <p>
|
||||
* <b> DO NOT USE THIS CLASS since the direct use of this class might break the
|
||||
* native library code loading in {@link SnappyLoader}. </b>
|
||||
* </p>
|
||||
*
|
||||
* @author leo
|
||||
*/
|
||||
public class SnappyNative implements SnappyApi
|
||||
{
|
||||
|
||||
public native String nativeLibraryVersion();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Generic compression/decompression routines.
|
||||
// ------------------------------------------------------------------------
|
||||
@Override
|
||||
public native long rawCompress(long inputAddr, long inputSize, long destAddr)
|
||||
throws IOException;
|
||||
|
||||
@Override
|
||||
public native long rawUncompress(long inputAddr, long inputSize, long destAddr)
|
||||
throws IOException;
|
||||
|
||||
@Override
|
||||
public native int rawCompress(ByteBuffer input, int inputOffset, int inputLength, ByteBuffer compressed,
|
||||
int outputOffset)
|
||||
throws IOException;
|
||||
|
||||
@Override
|
||||
public native int rawCompress(Object input, int inputOffset, int inputByteLength, Object output, int outputOffset)
|
||||
throws IOException;
|
||||
|
||||
@Override
|
||||
public native int rawUncompress(ByteBuffer compressed, int inputOffset, int inputLength, ByteBuffer uncompressed,
|
||||
int outputOffset)
|
||||
throws IOException;
|
||||
|
||||
@Override
|
||||
public native int rawUncompress(Object input, int inputOffset, int inputLength, Object output, int outputOffset)
|
||||
throws IOException;
|
||||
|
||||
// Returns the maximal size of the compressed representation of
|
||||
// input data that is "source_bytes" bytes in length;
|
||||
@Override
|
||||
public native int maxCompressedLength(int source_bytes);
|
||||
|
||||
// This operation takes O(1) time.
|
||||
@Override
|
||||
public native int uncompressedLength(ByteBuffer compressed, int offset, int len)
|
||||
throws IOException;
|
||||
|
||||
@Override
|
||||
public native int uncompressedLength(Object input, int offset, int len)
|
||||
throws IOException;
|
||||
|
||||
@Override
|
||||
public native long uncompressedLength(long inputAddr, long len)
|
||||
throws IOException;
|
||||
|
||||
@Override
|
||||
public native boolean isValidCompressedBuffer(ByteBuffer compressed, int offset, int len)
|
||||
throws IOException;
|
||||
|
||||
@Override
|
||||
public native boolean isValidCompressedBuffer(Object input, int offset, int len)
|
||||
throws IOException;
|
||||
|
||||
@Override
|
||||
public native boolean isValidCompressedBuffer(long inputAddr, long offset, long len)
|
||||
throws IOException;
|
||||
|
||||
@Override
|
||||
public native void arrayCopy(Object src, int offset, int byteLength, Object dest, int dOffset)
|
||||
throws IOException;
|
||||
|
||||
public void throw_error(int errorCode)
|
||||
throws IOException
|
||||
{
|
||||
throw new IOException(String.format("%s(%d)", SnappyErrorCode.getErrorMessage(errorCode), errorCode));
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ import java.io.OutputStream;
|
||||
* The output data format is:
|
||||
* <ol>
|
||||
* <li>snappy codec header defined in {@link SnappyCodec} (8 bytes)
|
||||
* <li>codec version (4 bytes integer, at least 1) and compatible version (4 bytes integer)
|
||||
* <li>compressed block 1 : a pair of (compressed data size [4 byte integer.
|
||||
* Big-endian], compressed data...)
|
||||
* <li>compressed block 2
|
||||
@ -55,9 +56,12 @@ import java.io.OutputStream;
|
||||
*
|
||||
* @author leo
|
||||
*/
|
||||
public class SnappyOutputStream extends OutputStream {
|
||||
static final int MIN_BLOCK_SIZE = 1 * 1024;
|
||||
static final int DEFAULT_BLOCK_SIZE = 32 * 1024; // Use 32kb for the default block size
|
||||
public class SnappyOutputStream
|
||||
extends OutputStream
|
||||
{
|
||||
public static final int MAX_BLOCK_SIZE = 512 * 1024 * 1024; // 512 MiB
|
||||
public static final int MIN_BLOCK_SIZE = 1 * 1024;
|
||||
public static final int DEFAULT_BLOCK_SIZE = 32 * 1024; // Use 32kb for the default block size
|
||||
|
||||
protected final OutputStream out;
|
||||
private final int blockSize;
|
||||
@ -65,27 +69,36 @@ public class SnappyOutputStream extends OutputStream {
|
||||
private final BufferAllocator inputBufferAllocator;
|
||||
private final BufferAllocator outputBufferAllocator;
|
||||
|
||||
protected final byte[] inputBuffer;
|
||||
protected final byte[] outputBuffer;
|
||||
// The input and output buffer fields are set to null when closing this stream:
|
||||
protected byte[] inputBuffer;
|
||||
protected byte[] outputBuffer;
|
||||
private int inputCursor = 0;
|
||||
private int outputCursor = 0;
|
||||
private boolean headerWritten;
|
||||
private boolean closed;
|
||||
|
||||
public SnappyOutputStream(OutputStream out) {
|
||||
public SnappyOutputStream(OutputStream out)
|
||||
{
|
||||
this(out, DEFAULT_BLOCK_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param out
|
||||
* @param blockSize byte size of the internal buffer size
|
||||
* @throws IOException
|
||||
* @throws IllegalArgumentException when blockSize is larger than 512 MiB
|
||||
*/
|
||||
public SnappyOutputStream(OutputStream out, int blockSize) {
|
||||
this(out, blockSize, CachedBufferAllocator.factory);
|
||||
public SnappyOutputStream(OutputStream out, int blockSize)
|
||||
{
|
||||
this(out, blockSize, CachedBufferAllocator.getBufferAllocatorFactory());
|
||||
}
|
||||
|
||||
public SnappyOutputStream(OutputStream out, int blockSize, BufferAllocatorFactory bufferAllocatorFactory) {
|
||||
public SnappyOutputStream(OutputStream out, int blockSize, BufferAllocatorFactory bufferAllocatorFactory)
|
||||
{
|
||||
this.out = out;
|
||||
this.blockSize = Math.max(MIN_BLOCK_SIZE, blockSize);
|
||||
if (this.blockSize > MAX_BLOCK_SIZE){
|
||||
throw new IllegalArgumentException(String.format("Provided chunk size %,d larger than max %,d", this.blockSize, MAX_BLOCK_SIZE));
|
||||
}
|
||||
int inputSize = blockSize;
|
||||
int outputSize = SnappyCodec.HEADER_SIZE + 4 + Snappy.maxCompressedLength(blockSize);
|
||||
|
||||
@ -93,77 +106,103 @@ public class SnappyOutputStream extends OutputStream {
|
||||
this.outputBufferAllocator = bufferAllocatorFactory.getBufferAllocator(outputSize);
|
||||
|
||||
inputBuffer = inputBufferAllocator.allocate(inputSize);
|
||||
outputBuffer = inputBufferAllocator.allocate(outputSize);
|
||||
|
||||
outputCursor = SnappyCodec.currentHeader.writeHeader(outputBuffer, 0);
|
||||
outputBuffer = outputBufferAllocator.allocate(outputSize);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.io.OutputStream#write(byte[], int, int)
|
||||
*/
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
rawWrite(b, off, len);
|
||||
public void write(byte[] b, int byteOffset, int byteLength)
|
||||
throws IOException
|
||||
{
|
||||
if (closed) {
|
||||
throw new IOException("Stream is closed");
|
||||
}
|
||||
int cursor = 0;
|
||||
while (cursor < byteLength) {
|
||||
int readLen = Math.min(byteLength - cursor, blockSize - inputCursor);
|
||||
// copy the input data to uncompressed buffer
|
||||
if (readLen > 0) {
|
||||
System.arraycopy(b, byteOffset + cursor, inputBuffer, inputCursor, readLen);
|
||||
inputCursor += readLen;
|
||||
}
|
||||
if (inputCursor < blockSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
compressInput();
|
||||
cursor += readLen;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress the input long array data
|
||||
*
|
||||
* @param d input array
|
||||
* @param d input array
|
||||
* @param off offset in the array
|
||||
* @param len the number of elements in the array to copy
|
||||
* @throws IOException
|
||||
*/
|
||||
public void write(long[] d, int off, int len) throws IOException {
|
||||
public void write(long[] d, int off, int len)
|
||||
throws IOException
|
||||
{
|
||||
rawWrite(d, off * 8, len * 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress the input double array data
|
||||
*
|
||||
* @param f input array
|
||||
* @param f input array
|
||||
* @param off offset in the array
|
||||
* @param len the number of elements in the array to copy
|
||||
* @throws IOException
|
||||
*/
|
||||
public void write(double[] f, int off, int len) throws IOException {
|
||||
public void write(double[] f, int off, int len)
|
||||
throws IOException
|
||||
{
|
||||
rawWrite(f, off * 8, len * 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress the input float array data
|
||||
*
|
||||
* @param f input array
|
||||
* @param f input array
|
||||
* @param off offset in the array
|
||||
* @param len the number of elements in the array to copy
|
||||
* @throws IOException
|
||||
*/
|
||||
public void write(float[] f, int off, int len) throws IOException {
|
||||
public void write(float[] f, int off, int len)
|
||||
throws IOException
|
||||
{
|
||||
rawWrite(f, off * 4, len * 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress the input int array data
|
||||
*
|
||||
* @param f input array
|
||||
* @param f input array
|
||||
* @param off offset in the array
|
||||
* @param len the number of elements in the array to copy
|
||||
* @throws IOException
|
||||
*/
|
||||
public void write(int[] f, int off, int len) throws IOException {
|
||||
public void write(int[] f, int off, int len)
|
||||
throws IOException
|
||||
{
|
||||
rawWrite(f, off * 4, len * 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress the input short array data
|
||||
*
|
||||
* @param f input array
|
||||
* @param f input array
|
||||
* @param off offset in the array
|
||||
* @param len the number of elements in the array to copy
|
||||
* @throws IOException
|
||||
*/
|
||||
public void write(short[] f, int off, int len) throws IOException {
|
||||
public void write(short[] f, int off, int len)
|
||||
throws IOException
|
||||
{
|
||||
rawWrite(f, off * 2, len * 2);
|
||||
}
|
||||
|
||||
@ -173,7 +212,9 @@ public class SnappyOutputStream extends OutputStream {
|
||||
* @param d
|
||||
* @throws IOException
|
||||
*/
|
||||
public void write(long[] d) throws IOException {
|
||||
public void write(long[] d)
|
||||
throws IOException
|
||||
{
|
||||
write(d, 0, d.length);
|
||||
}
|
||||
|
||||
@ -183,7 +224,9 @@ public class SnappyOutputStream extends OutputStream {
|
||||
* @param f
|
||||
* @throws IOException
|
||||
*/
|
||||
public void write(double[] f) throws IOException {
|
||||
public void write(double[] f)
|
||||
throws IOException
|
||||
{
|
||||
write(f, 0, f.length);
|
||||
}
|
||||
|
||||
@ -193,7 +236,9 @@ public class SnappyOutputStream extends OutputStream {
|
||||
* @param f
|
||||
* @throws IOException
|
||||
*/
|
||||
public void write(float[] f) throws IOException {
|
||||
public void write(float[] f)
|
||||
throws IOException
|
||||
{
|
||||
write(f, 0, f.length);
|
||||
}
|
||||
|
||||
@ -203,7 +248,9 @@ public class SnappyOutputStream extends OutputStream {
|
||||
* @param f
|
||||
* @throws IOException
|
||||
*/
|
||||
public void write(int[] f) throws IOException {
|
||||
public void write(int[] f)
|
||||
throws IOException
|
||||
{
|
||||
write(f, 0, f.length);
|
||||
}
|
||||
|
||||
@ -213,11 +260,14 @@ public class SnappyOutputStream extends OutputStream {
|
||||
* @param f
|
||||
* @throws IOException
|
||||
*/
|
||||
public void write(short[] f) throws IOException {
|
||||
public void write(short[] f)
|
||||
throws IOException
|
||||
{
|
||||
write(f, 0, f.length);
|
||||
}
|
||||
|
||||
private boolean hasSufficientOutputBufferFor(int inputSize) {
|
||||
private boolean hasSufficientOutputBufferFor(int inputSize)
|
||||
{
|
||||
int maxCompressedSize = Snappy.maxCompressedLength(inputSize);
|
||||
return maxCompressedSize < outputBuffer.length - outputCursor - 4;
|
||||
}
|
||||
@ -225,31 +275,31 @@ public class SnappyOutputStream extends OutputStream {
|
||||
/**
|
||||
* Compress the raw byte array data.
|
||||
*
|
||||
* @param array array data of any type (e.g., byte[], float[], long[], ...)
|
||||
* @param array array data of any type (e.g., byte[], float[], long[], ...)
|
||||
* @param byteOffset
|
||||
* @param byteLength
|
||||
* @throws IOException
|
||||
*/
|
||||
public void rawWrite(Object array, int byteOffset, int byteLength) throws IOException {
|
||||
|
||||
if(inputCursor + byteLength < MIN_BLOCK_SIZE) {
|
||||
// copy the input data to uncompressed buffer
|
||||
Snappy.arrayCopy(array, byteOffset, byteLength, inputBuffer, inputCursor);
|
||||
inputCursor += byteLength;
|
||||
return;
|
||||
public void rawWrite(Object array, int byteOffset, int byteLength)
|
||||
throws IOException
|
||||
{
|
||||
if (closed) {
|
||||
throw new IOException("Stream is closed");
|
||||
}
|
||||
|
||||
compressInput();
|
||||
|
||||
for(int readBytes = 0; readBytes < byteLength; ) {
|
||||
int inputLen = Math.min(blockSize, byteLength - readBytes);
|
||||
if(!hasSufficientOutputBufferFor(inputLen)) {
|
||||
dumpOutput();
|
||||
int cursor = 0;
|
||||
while (cursor < byteLength) {
|
||||
int readLen = Math.min(byteLength - cursor, blockSize - inputCursor);
|
||||
// copy the input data to uncompressed buffer
|
||||
if (readLen > 0) {
|
||||
Snappy.arrayCopy(array, byteOffset + cursor, readLen, inputBuffer, inputCursor);
|
||||
inputCursor += readLen;
|
||||
}
|
||||
int compressedSize = Snappy.rawCompress(array, byteOffset + readBytes, inputLen, outputBuffer, outputCursor + 4);
|
||||
writeInt(outputBuffer, outputCursor, compressedSize);
|
||||
outputCursor += 4 + compressedSize;
|
||||
readBytes += inputLen;
|
||||
if (inputCursor < blockSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
compressInput();
|
||||
cursor += readLen;
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,8 +313,13 @@ public class SnappyOutputStream extends OutputStream {
|
||||
* @see java.io.OutputStream#write(int)
|
||||
*/
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
if(inputCursor >= inputBuffer.length) {
|
||||
public void write(int b)
|
||||
throws IOException
|
||||
{
|
||||
if (closed) {
|
||||
throw new IOException("Stream is closed");
|
||||
}
|
||||
if (inputCursor >= inputBuffer.length) {
|
||||
compressInput();
|
||||
}
|
||||
inputBuffer[inputCursor++] = (byte) b;
|
||||
@ -274,20 +329,27 @@ public class SnappyOutputStream extends OutputStream {
|
||||
* @see java.io.OutputStream#flush()
|
||||
*/
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
public void flush()
|
||||
throws IOException
|
||||
{
|
||||
if (closed) {
|
||||
throw new IOException("Stream is closed");
|
||||
}
|
||||
compressInput();
|
||||
dumpOutput();
|
||||
out.flush();
|
||||
}
|
||||
|
||||
static void writeInt(byte[] dst, int offset, int v) {
|
||||
static void writeInt(byte[] dst, int offset, int v)
|
||||
{
|
||||
dst[offset] = (byte) ((v >> 24) & 0xFF);
|
||||
dst[offset + 1] = (byte) ((v >> 16) & 0xFF);
|
||||
dst[offset + 2] = (byte) ((v >> 8) & 0xFF);
|
||||
dst[offset + 3] = (byte) ((v >> 0) & 0xFF);
|
||||
}
|
||||
|
||||
static int readInt(byte[] buffer, int pos) {
|
||||
static int readInt(byte[] buffer, int pos)
|
||||
{
|
||||
int b1 = (buffer[pos] & 0xFF) << 24;
|
||||
int b2 = (buffer[pos + 1] & 0xFF) << 16;
|
||||
int b3 = (buffer[pos + 2] & 0xFF) << 8;
|
||||
@ -295,22 +357,30 @@ public class SnappyOutputStream extends OutputStream {
|
||||
return b1 | b2 | b3 | b4;
|
||||
}
|
||||
|
||||
protected void dumpOutput() throws IOException {
|
||||
if(outputCursor > 0) {
|
||||
protected void dumpOutput()
|
||||
throws IOException
|
||||
{
|
||||
if (outputCursor > 0) {
|
||||
out.write(outputBuffer, 0, outputCursor);
|
||||
outputCursor = 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected void compressInput() throws IOException {
|
||||
if(inputCursor <= 0) {
|
||||
protected void compressInput()
|
||||
throws IOException
|
||||
{
|
||||
if (!headerWritten) {
|
||||
outputCursor = writeHeader();
|
||||
headerWritten = true;
|
||||
}
|
||||
if (inputCursor <= 0) {
|
||||
return; // no need to dump
|
||||
}
|
||||
|
||||
// Compress and dump the buffer content
|
||||
if(!hasSufficientOutputBufferFor(inputCursor)) {
|
||||
if (!hasSufficientOutputBufferFor(inputCursor)) {
|
||||
dumpOutput();
|
||||
}
|
||||
writeBlockPreemble();
|
||||
int compressedSize = Snappy.compress(inputBuffer, 0, inputCursor, outputBuffer, outputCursor + 4);
|
||||
// Write compressed data size
|
||||
writeInt(outputBuffer, outputCursor, compressedSize);
|
||||
@ -318,6 +388,24 @@ public class SnappyOutputStream extends OutputStream {
|
||||
inputCursor = 0;
|
||||
}
|
||||
|
||||
protected int writeHeader(){
|
||||
return SnappyCodec.currentHeader.writeHeader(outputBuffer, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally write a preemble before a block. Hadoop requires the actual block data size being written. This base
|
||||
* implementation does nothing. Derive implementation can call {@code writeCurrentDataSize()}.
|
||||
*/
|
||||
protected void writeBlockPreemble()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
protected void writeCurrentDataSize(){
|
||||
writeInt(outputBuffer, outputCursor, inputCursor);
|
||||
outputCursor += 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* close the stream
|
||||
*/
|
||||
@ -325,14 +413,22 @@ public class SnappyOutputStream extends OutputStream {
|
||||
* @see java.io.OutputStream#close()
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
public void close()
|
||||
throws IOException
|
||||
{
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
flush();
|
||||
out.close();
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
closed = true;
|
||||
inputBufferAllocator.release(inputBuffer);
|
||||
outputBufferAllocator.release(outputBuffer);
|
||||
inputBuffer = null;
|
||||
outputBuffer = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,2 +0,0 @@
|
||||
VERSION=1.1.1
|
||||
|
@ -3,9 +3,10 @@ package org.xerial.snappy.buffer;
|
||||
/**
|
||||
* BufferAllocator interface. The implementation of this interface must be thread-safe
|
||||
*/
|
||||
public interface BufferAllocator {
|
||||
public interface BufferAllocator
|
||||
{
|
||||
|
||||
public byte[] allocate(int size);
|
||||
public void release(byte[] buffer);
|
||||
|
||||
public void release(byte[] buffer);
|
||||
}
|
||||
|
@ -3,7 +3,8 @@ package org.xerial.snappy.buffer;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface BufferAllocatorFactory {
|
||||
public interface BufferAllocatorFactory
|
||||
{
|
||||
|
||||
BufferAllocator getBufferAllocator(int minSize);
|
||||
}
|
||||
|
@ -6,29 +6,45 @@ import java.util.*;
|
||||
/**
|
||||
* Cached buffer
|
||||
*/
|
||||
public class CachedBufferAllocator implements BufferAllocator {
|
||||
|
||||
public static BufferAllocatorFactory factory = new BufferAllocatorFactory() {
|
||||
public class CachedBufferAllocator
|
||||
implements BufferAllocator
|
||||
{
|
||||
private static BufferAllocatorFactory factory = new BufferAllocatorFactory()
|
||||
{
|
||||
@Override
|
||||
public BufferAllocator getBufferAllocator(int bufferSize) {
|
||||
public BufferAllocator getBufferAllocator(int bufferSize)
|
||||
{
|
||||
return CachedBufferAllocator.getAllocator(bufferSize);
|
||||
}
|
||||
};
|
||||
|
||||
public static void setBufferAllocatorFactory(BufferAllocatorFactory factory)
|
||||
{
|
||||
assert (factory != null);
|
||||
CachedBufferAllocator.factory = factory;
|
||||
}
|
||||
|
||||
public static BufferAllocatorFactory getBufferAllocatorFactory()
|
||||
{
|
||||
return factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use SoftReference so that having this queueTable does not prevent the GC of CachedBufferAllocator instances
|
||||
*/
|
||||
public static Map<Integer, SoftReference<CachedBufferAllocator>> queueTable = new HashMap<Integer, SoftReference<CachedBufferAllocator>>();
|
||||
private static final Map<Integer, SoftReference<CachedBufferAllocator>> queueTable = new HashMap<Integer, SoftReference<CachedBufferAllocator>>();
|
||||
|
||||
private final int bufferSize;
|
||||
private final Deque<byte[]> bufferQueue;
|
||||
|
||||
public CachedBufferAllocator(int bufferSize) {
|
||||
public CachedBufferAllocator(int bufferSize)
|
||||
{
|
||||
this.bufferSize = bufferSize;
|
||||
this.bufferQueue = new ArrayDeque<byte[]>();
|
||||
}
|
||||
|
||||
public static synchronized CachedBufferAllocator getAllocator(int bufferSize) {
|
||||
public static synchronized CachedBufferAllocator getAllocator(int bufferSize)
|
||||
{
|
||||
CachedBufferAllocator result = null;
|
||||
|
||||
if (queueTable.containsKey(bufferSize)) {
|
||||
@ -42,9 +58,10 @@ public class CachedBufferAllocator implements BufferAllocator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] allocate(int size) {
|
||||
synchronized(this) {
|
||||
if(bufferQueue.isEmpty()) {
|
||||
public byte[] allocate(int size)
|
||||
{
|
||||
synchronized (this) {
|
||||
if (bufferQueue.isEmpty()) {
|
||||
return new byte[size];
|
||||
}
|
||||
else {
|
||||
@ -52,9 +69,11 @@ public class CachedBufferAllocator implements BufferAllocator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release(byte[] buffer) {
|
||||
synchronized(this) {
|
||||
public void release(byte[] buffer)
|
||||
{
|
||||
synchronized (this) {
|
||||
bufferQueue.addLast(buffer);
|
||||
}
|
||||
}
|
||||
|
@ -3,24 +3,30 @@ package org.xerial.snappy.buffer;
|
||||
/**
|
||||
* Simple buffer allocator, which does not reuse the allocated buffer
|
||||
*/
|
||||
public class DefaultBufferAllocator implements BufferAllocator {
|
||||
public class DefaultBufferAllocator
|
||||
implements BufferAllocator
|
||||
{
|
||||
|
||||
public static BufferAllocatorFactory factory = new BufferAllocatorFactory() {
|
||||
public static BufferAllocatorFactory factory = new BufferAllocatorFactory()
|
||||
{
|
||||
public BufferAllocator singleton = new DefaultBufferAllocator();
|
||||
|
||||
@Override
|
||||
public BufferAllocator getBufferAllocator(int bufferSize) {
|
||||
public BufferAllocator getBufferAllocator(int bufferSize)
|
||||
{
|
||||
return singleton;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public byte[] allocate(int size) {
|
||||
public byte[] allocate(int size)
|
||||
{
|
||||
return new byte[size];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release(byte[] buffer) {
|
||||
public void release(byte[] buffer)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,44 +1,44 @@
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Snappy API for compressing/decompressing data.
|
||||
*
|
||||
* Usage
|
||||
* First, import {@link org.xerial.snappy.Snappy} in your Java code:
|
||||
* <code>
|
||||
* <pre>
|
||||
* import org.xerial.snappy.Snappy;
|
||||
* </pre>
|
||||
* </code>
|
||||
* Then use {@link org.xerial.snappy.Snappy#compress(byte[])} and {@link org.xerial.snappy.Snappy#uncompress(byte[])}:
|
||||
* <code>
|
||||
* <pre>
|
||||
* String input = "Hello snappy-java! Snappy-java is a JNI-based wrapper of Snappy, a fast compresser/decompresser.";
|
||||
* byte[] compressed = Snappy.compress(input.getBytes("UTF-8"));
|
||||
* byte[] uncompressed = Snappy.uncompress(compressed);
|
||||
* String result = new String(uncompressed, "UTF-8");
|
||||
* System.out.println(result);
|
||||
* </pre>
|
||||
* </code>
|
||||
*
|
||||
* <p>In addition, high-level methods (Snappy.compress(String), Snappy.compress(float[] ..) etc. ) and low-level ones (e.g. Snappy.rawCompress(.. ), Snappy.rawUncompress(..), etc.), which minimize memory copies, can be used. </p>
|
||||
*
|
||||
* <h3>Stream-based API</h3>
|
||||
* Stream-based compressor/decompressor SnappyOutputStream, SnappyInputStream are also available for reading/writing large data sets.
|
||||
*/
|
||||
package org.xerial.snappy;
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* Copyright 2011 Taro L. Saito
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Snappy API for compressing/decompressing data.
|
||||
* <p/>
|
||||
* Usage
|
||||
* First, import {@link org.xerial.snappy.Snappy} in your Java code:
|
||||
* <code>
|
||||
* <pre>
|
||||
* import org.xerial.snappy.Snappy;
|
||||
* </pre>
|
||||
* </code>
|
||||
* Then use {@link org.xerial.snappy.Snappy#compress(byte[])} and {@link org.xerial.snappy.Snappy#uncompress(byte[])}:
|
||||
* <code>
|
||||
* <pre>
|
||||
* String input = "Hello snappy-java! Snappy-java is a JNI-based wrapper of Snappy, a fast compresser/decompresser.";
|
||||
* byte[] compressed = Snappy.compress(input.getBytes("UTF-8"));
|
||||
* byte[] uncompressed = Snappy.uncompress(compressed);
|
||||
* String result = new String(uncompressed, "UTF-8");
|
||||
* System.out.println(result);
|
||||
* </pre>
|
||||
* </code>
|
||||
* <p/>
|
||||
* <p>In addition, high-level methods (Snappy.compress(String), Snappy.compress(float[] ..) etc. ) and low-level ones (e.g. Snappy.rawCompress(.. ), Snappy.rawUncompress(..), etc.), which minimize memory copies, can be used. </p>
|
||||
* <p/>
|
||||
* <h3>Stream-based API</h3>
|
||||
* Stream-based compressor/decompressor SnappyOutputStream, SnappyInputStream are also available for reading/writing large data sets.
|
||||
*/
|
||||
package org.xerial.snappy;
|
||||
|
||||
|
53
src/main/java/org/xerial/snappy/pool/BufferPool.java
Normal file
53
src/main/java/org/xerial/snappy/pool/BufferPool.java
Normal file
@ -0,0 +1,53 @@
|
||||
package org.xerial.snappy.pool;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* Makes various types of buffers available for use and potential re-use.
|
||||
*
|
||||
* <p>
|
||||
* Implementations must be safe for concurrent use by multiple threads.
|
||||
* </p>
|
||||
*
|
||||
* @author Brett Okken
|
||||
*/
|
||||
public interface BufferPool {
|
||||
|
||||
/**
|
||||
* Returns a {@code byte[]} of <i>size</i> or greater length.
|
||||
* @param size The minimum size array required. Must be {@code >= 0}.
|
||||
* @return A {@code byte[]} with length of at least <i>size</i>.
|
||||
* @see #releaseArray(byte[])
|
||||
*/
|
||||
public byte[] allocateArray(int size);
|
||||
|
||||
/**
|
||||
* Returns instance to pool for potential future reuse.
|
||||
* <p>
|
||||
* Must not be returned more than 1 time. Must not be used by caller after return.
|
||||
* </p>
|
||||
* @param buffer Instance to return to pool. Must not be {@code null}.
|
||||
* Must not be returned more than 1 time. Must not be used by caller after return.
|
||||
*/
|
||||
public void releaseArray(byte[] buffer);
|
||||
|
||||
/**
|
||||
* Returns a {@link ByteBuffer#allocateDirect(int) direct ByteBuffer} of <i>size</i> or
|
||||
* greater {@link ByteBuffer#capacity() capacity}.
|
||||
* @param size The minimum size buffer required. Must be {@code >= 0}.
|
||||
* @return A {@code ByteBuffer} of <i>size</i> or greater {@link ByteBuffer#capacity() capacity}.
|
||||
* @see #releaseDirect(ByteBuffer)
|
||||
* @see ByteBuffer#allocateDirect(int)
|
||||
*/
|
||||
public ByteBuffer allocateDirect(int size);
|
||||
|
||||
/**
|
||||
* Returns instance to pool for potential future reuse.
|
||||
* <p>
|
||||
* Must not be returned more than 1 time. Must not be used by caller after return.
|
||||
* </p>
|
||||
* @param buffer Instance to return to pool. Must not be {@code null}.
|
||||
* Must not be returned more than 1 time. Must not be used by caller after return.
|
||||
*/
|
||||
public void releaseDirect(ByteBuffer buffer);
|
||||
}
|
216
src/main/java/org/xerial/snappy/pool/CachingBufferPool.java
Normal file
216
src/main/java/org/xerial/snappy/pool/CachingBufferPool.java
Normal file
@ -0,0 +1,216 @@
|
||||
package org.xerial.snappy.pool;
|
||||
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* A {@link BufferPool} implementation which caches values at fixed sizes.
|
||||
* <p>
|
||||
* Pooled instances are held as {@link SoftReference} to allow GC if necessary.
|
||||
* </p>
|
||||
* <p>
|
||||
* The current fixed sizes are calculated as follows:
|
||||
* <ul>
|
||||
* <li>Values < 4KB return 4KB</li>
|
||||
* <li>4KB - 32KB to 2KB</li>
|
||||
* <li>32KB - 512KB to 16KB</li>
|
||||
* <li>512KB - 2MB to 128KB</li>
|
||||
* <li>2MB - 16MB to 512KB</li>
|
||||
* <li>16MB - 128MB to 4MB</li>
|
||||
* <li>128MB - 512MB to 16MB</li>
|
||||
* <li>512MB - 1.5 GB to 128MB</li>
|
||||
* <li>Values > 1.5GB return {@link Integer#MAX_VALUE}</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
* @author Brett Okken
|
||||
*/
|
||||
public final class CachingBufferPool implements BufferPool {
|
||||
|
||||
private static interface IntFunction<E> {
|
||||
public E create(int size);
|
||||
}
|
||||
|
||||
private static final IntFunction<byte[]> ARRAY_FUNCTION = new IntFunction<byte[]>() {
|
||||
@Override
|
||||
public byte[] create(int size) {
|
||||
return new byte[size];
|
||||
}
|
||||
};
|
||||
|
||||
private static final IntFunction<ByteBuffer> DBB_FUNCTION = new IntFunction<ByteBuffer>() {
|
||||
@Override
|
||||
public ByteBuffer create(int size) {
|
||||
return ByteBuffer.allocateDirect(size);
|
||||
}
|
||||
};
|
||||
|
||||
private static final CachingBufferPool INSTANCE = new CachingBufferPool();
|
||||
|
||||
private final ConcurrentMap<Integer, ConcurrentLinkedDeque<SoftReference<byte[]>>> bytes = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<Integer, ConcurrentLinkedDeque<SoftReference<ByteBuffer>>> buffers = new ConcurrentHashMap<>();
|
||||
|
||||
private CachingBufferPool() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns instance of {@link CachingBufferPool} for using cached buffers.
|
||||
* @return instance of {@link CachingBufferPool} for using cached buffers.
|
||||
*/
|
||||
public static BufferPool getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public byte[] allocateArray(int size) {
|
||||
if (size <= 0) {
|
||||
throw new IllegalArgumentException("size is invalid: " + size);
|
||||
}
|
||||
|
||||
return getOrCreate(size, bytes, ARRAY_FUNCTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void releaseArray(byte[] buffer) {
|
||||
if (buffer == null) {
|
||||
throw new IllegalArgumentException("buffer is null");
|
||||
}
|
||||
returnValue(buffer, buffer.length, bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ByteBuffer allocateDirect(int size) {
|
||||
if (size <= 0) {
|
||||
throw new IllegalArgumentException("size is invalid: " + size);
|
||||
}
|
||||
|
||||
return getOrCreate(size, buffers, DBB_FUNCTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void releaseDirect(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
throw new IllegalArgumentException("buffer is null");
|
||||
}
|
||||
buffer.clear();
|
||||
returnValue(buffer, buffer.capacity(), buffers);
|
||||
}
|
||||
|
||||
private static <E> E getOrCreate(final int size, final ConcurrentMap<Integer, ConcurrentLinkedDeque<SoftReference<E>>> map, final IntFunction<E> creator) {
|
||||
assert size > 0;
|
||||
final int adjustedSize = adjustSize(size);
|
||||
final ConcurrentLinkedDeque<SoftReference<E>> queue = optimisticGetEntry(adjustedSize, map);
|
||||
SoftReference<E> entry;
|
||||
while ((entry = queue.pollFirst()) != null) {
|
||||
final E val = entry.get();
|
||||
if (val != null) {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
return creator.create(adjustedSize);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is package scope to allow direct unit testing.
|
||||
*/
|
||||
static int adjustSize(int size) {
|
||||
assert size > 0;
|
||||
|
||||
switch (Integer.numberOfLeadingZeros(size)) {
|
||||
case 1: // 1GB - 2GB
|
||||
case 2: // 512MB
|
||||
//if 512MB - 1.5 GB round to nearest 128 MB (2^27), else Integer.MAX_VALUE
|
||||
return size <= 0x6000_0000 ? roundToPowers(size, 27) : Integer.MAX_VALUE;
|
||||
case 3: //256MB
|
||||
case 4: //128MB
|
||||
//if 128MB - 512MB, round to nearest 16 MB
|
||||
return roundToPowers(size, 24);
|
||||
case 5: // 64MB
|
||||
case 6: // 32MB
|
||||
case 7: // 16MB
|
||||
//if 16MB - 128MB, round to nearest 4MB
|
||||
return roundToPowers(size, 22);
|
||||
case 8: // 8MB
|
||||
case 9: // 4MB
|
||||
case 10: // 2MB
|
||||
//if 2MB - 16MB, round to nearest 512KB
|
||||
return roundToPowers(size, 19);
|
||||
case 11: // 1MB
|
||||
case 12: //512KB
|
||||
//if 512KB - 2MB, round to nearest 128KB
|
||||
return roundToPowers(size, 17);
|
||||
case 13: //256KB
|
||||
case 14: //128KB
|
||||
case 15: // 64KB
|
||||
case 16: // 32KB
|
||||
//if 32KB to 512KB, round to nearest 16KB
|
||||
return roundToPowers(size, 14);
|
||||
case 17: // 16KB
|
||||
case 18: // 8KB
|
||||
case 19: // 4KB
|
||||
// if 4KB - 32KB, round to nearest 2KB
|
||||
return roundToPowers(size, 11);
|
||||
default:
|
||||
return 4 * 1024;
|
||||
}
|
||||
}
|
||||
|
||||
private static int roundToPowers(int number, int bits) {
|
||||
final int mask = (0x7FFF_FFFF >> bits) << bits;
|
||||
final int floor = number & mask;
|
||||
return floor == number ? number : floor + (1 << bits);
|
||||
}
|
||||
|
||||
private static <E> ConcurrentLinkedDeque<SoftReference<E>> optimisticGetEntry(Integer key, ConcurrentMap<Integer, ConcurrentLinkedDeque<SoftReference<E>>> map) {
|
||||
ConcurrentLinkedDeque<SoftReference<E>> val = map.get(key);
|
||||
if (val == null) {
|
||||
map.putIfAbsent(key, new ConcurrentLinkedDeque<SoftReference<E>>());
|
||||
val = map.get(key);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
private static <E> void returnValue(E value, Integer size, ConcurrentMap<Integer, ConcurrentLinkedDeque<SoftReference<E>>> map) {
|
||||
final ConcurrentLinkedDeque<SoftReference<E>> queue = map.get(size);
|
||||
//no queue will exist if buffer was not originally obtained from this class
|
||||
if (queue != null) {
|
||||
//push this value onto deque first so that concurrent request can use it
|
||||
queue.addFirst(new SoftReference<E>(value));
|
||||
|
||||
//purge oldest entries have lost references
|
||||
SoftReference<E> entry;
|
||||
boolean lastEmpty = true;
|
||||
while(lastEmpty && (entry = queue.peekLast()) != null) {
|
||||
if (entry.get() == null) {
|
||||
queue.removeLastOccurrence(entry);
|
||||
} else {
|
||||
lastEmpty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CachingBufferPool [bytes=" + this.bytes + ", buffers=" + this.buffers + "]";
|
||||
}
|
||||
}
|
||||
|
37
src/main/java/org/xerial/snappy/pool/DefaultPoolFactory.java
Normal file
37
src/main/java/org/xerial/snappy/pool/DefaultPoolFactory.java
Normal file
@ -0,0 +1,37 @@
|
||||
package org.xerial.snappy.pool;
|
||||
|
||||
/**
|
||||
* Manages implementation of {@link BufferPool} to use by default. Setting the system property {@link #DISABLE_CACHING_PROPERTY} to {@code true} will
|
||||
* cause the {@link QuiescentBufferPool} to be used by default. Otherwise, {@link CachingBufferPool} will be used by default.
|
||||
* {@link #setDefaultPool(BufferPool)} can be used to explicitly control the implementation to use.
|
||||
*/
|
||||
public final class DefaultPoolFactory {
|
||||
|
||||
/**
|
||||
* Name of system property to disable use of {@link CachingBufferPool} by default.
|
||||
*/
|
||||
public static final String DISABLE_CACHING_PROPERTY = "org.xerial.snappy.pool.disable";
|
||||
|
||||
private static volatile BufferPool defaultPool = "true".equalsIgnoreCase(System.getProperty(DISABLE_CACHING_PROPERTY))
|
||||
? QuiescentBufferPool.getInstance()
|
||||
: CachingBufferPool.getInstance();
|
||||
|
||||
/**
|
||||
* @return The default instance to use.
|
||||
*/
|
||||
public static BufferPool getDefaultPool() {
|
||||
return defaultPool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default instance to use.
|
||||
* @param pool The default instance to use. Must not be {@code null}.
|
||||
* @see #getDefaultPool()
|
||||
*/
|
||||
public static void setDefaultPool(BufferPool pool) {
|
||||
if (pool == null) {
|
||||
throw new IllegalArgumentException("pool is null");
|
||||
}
|
||||
defaultPool = pool;
|
||||
}
|
||||
}
|
150
src/main/java/org/xerial/snappy/pool/DirectByteBuffers.java
Normal file
150
src/main/java/org/xerial/snappy/pool/DirectByteBuffers.java
Normal file
@ -0,0 +1,150 @@
|
||||
package org.xerial.snappy.pool;
|
||||
|
||||
import static java.lang.invoke.MethodHandles.constant;
|
||||
import static java.lang.invoke.MethodHandles.dropArguments;
|
||||
import static java.lang.invoke.MethodHandles.filterReturnValue;
|
||||
import static java.lang.invoke.MethodHandles.guardWithTest;
|
||||
import static java.lang.invoke.MethodHandles.lookup;
|
||||
import static java.lang.invoke.MethodType.methodType;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles.Lookup;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Utility to facilitate disposing of direct byte buffer instances.
|
||||
*/
|
||||
final class DirectByteBuffers {
|
||||
|
||||
/**
|
||||
* Sun specific mechanisms to clean up resources associated with direct byte buffers.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
static final Class<? extends ByteBuffer> DIRECT_BUFFER_CLAZZ = (Class<? extends ByteBuffer>) lookupClassQuietly("java.nio.DirectByteBuffer");
|
||||
|
||||
static final MethodHandle CLEAN_HANDLE;
|
||||
|
||||
static {
|
||||
// this approach is based off that used by apache lucene and documented here: https://issues.apache.org/jira/browse/LUCENE-6989
|
||||
// and https://github.com/apache/lucene-solr/blob/7e03427fa14a024ce257babcb8362d2451941e21/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java
|
||||
MethodHandle cleanHandle = null;
|
||||
try {
|
||||
final PrivilegedExceptionAction<MethodHandle> action = new PrivilegedExceptionAction<MethodHandle>() {
|
||||
|
||||
@Override
|
||||
public MethodHandle run() throws Exception {
|
||||
MethodHandle handle = null;
|
||||
if (DIRECT_BUFFER_CLAZZ != null) {
|
||||
final Lookup lookup = lookup();
|
||||
|
||||
try {
|
||||
// sun.misc.Unsafe unmapping (Java 9+)
|
||||
final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
|
||||
// first check if Unsafe has the right method, otherwise we can give up
|
||||
// without doing any security critical stuff:
|
||||
final MethodHandle unmapper = lookup.findVirtual(unsafeClass, "invokeCleaner", methodType(void.class, ByteBuffer.class));
|
||||
// fetch the unsafe instance and bind it to the virtual MH:
|
||||
final Field f = unsafeClass.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
final Object theUnsafe = f.get(null);
|
||||
handle = unmapper.bindTo(theUnsafe);
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(DirectByteBuffers.class.getName()).log(Level.FINE, "unable to use java 9 Unsafe.invokeCleaner", e);
|
||||
|
||||
// sun.misc.Cleaner unmapping (Java 8 and older)
|
||||
final Method m = DIRECT_BUFFER_CLAZZ.getMethod("cleaner");
|
||||
m.setAccessible(true);
|
||||
final MethodHandle directBufferCleanerMethod = lookup.unreflect(m);
|
||||
final Class<?> cleanerClass = directBufferCleanerMethod.type().returnType();
|
||||
|
||||
/*
|
||||
* "Compile" a MethodHandle that basically is equivalent to the following code:
|
||||
* void unmapper(ByteBuffer byteBuffer)
|
||||
* {
|
||||
* sun.misc.Cleaner cleaner = ((java.nio.DirectByteBuffer) byteBuffer).cleaner();
|
||||
* if (nonNull(cleaner))
|
||||
* {
|
||||
* cleaner.clean();
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* // the noop is needed because MethodHandles#guardWithTest always needs ELSE
|
||||
* noop(cleaner);
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
final MethodHandle cleanMethod = lookup.findVirtual(cleanerClass, "clean", methodType(void.class));
|
||||
final MethodHandle nonNullTest = lookup.findStatic(DirectByteBuffers.class, "nonNull", methodType(boolean.class, Object.class)).asType(methodType(boolean.class, cleanerClass));
|
||||
final MethodHandle noop = dropArguments(constant(Void.class, null).asType(methodType(void.class)), 0, cleanerClass);
|
||||
handle = filterReturnValue(directBufferCleanerMethod, guardWithTest(nonNullTest, cleanMethod, noop)).asType(methodType(void.class, ByteBuffer.class));
|
||||
}
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
};
|
||||
|
||||
cleanHandle = AccessController.doPrivileged(action);
|
||||
|
||||
} catch (Throwable t) {
|
||||
Logger.getLogger(DirectByteBuffers.class.getName()).log(Level.FINE, "Exception occurred attempting to lookup Sun specific DirectByteBuffer cleaner classes.", t);
|
||||
}
|
||||
CLEAN_HANDLE = cleanHandle;
|
||||
}
|
||||
|
||||
|
||||
private static Class<?> lookupClassQuietly(String name)
|
||||
{
|
||||
try {
|
||||
return DirectByteBuffers.class.getClassLoader().loadClass(name);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
Logger.getLogger(DirectByteBuffers.class.getName()).log(Level.FINE, "Did not find requested class: " + name, t);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
static boolean nonNull(Object o) {
|
||||
return o != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides jvm implementation specific operation to aggressively release resources associated with <i>buffer</i>.
|
||||
*
|
||||
* @param buffer The {@code ByteBuffer} to release. Must not be {@code null}. Must be {@link ByteBuffer#isDirect() direct}.
|
||||
*/
|
||||
public static void releaseDirectByteBuffer(final ByteBuffer buffer)
|
||||
{
|
||||
assert buffer != null && buffer.isDirect();
|
||||
|
||||
if (CLEAN_HANDLE != null && DIRECT_BUFFER_CLAZZ.isInstance(buffer)) {
|
||||
try {
|
||||
final PrivilegedExceptionAction<Void> pea = new PrivilegedExceptionAction<Void>() {
|
||||
@Override
|
||||
public Void run() throws Exception {
|
||||
try {
|
||||
CLEAN_HANDLE.invokeExact(buffer);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} catch (Throwable t) {
|
||||
//this will be an error
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
AccessController.doPrivileged(pea);
|
||||
} catch (Throwable t) {
|
||||
Logger.getLogger(DirectByteBuffers.class.getName()).log(Level.FINE, "Exception occurred attempting to clean up Sun specific DirectByteBuffer.", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package org.xerial.snappy.pool;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* A {@link BufferPool} implementation which does no pooling. New instances will be created for each call to allocate.
|
||||
* @author Brett Okken
|
||||
*/
|
||||
public final class QuiescentBufferPool implements BufferPool {
|
||||
|
||||
private static final QuiescentBufferPool INSTANCE = new QuiescentBufferPool();
|
||||
|
||||
private QuiescentBufferPool() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Instance of {@link BufferPool} which does no caching/reuse of instances.
|
||||
*/
|
||||
public static BufferPool getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code byte[]} of <i>size</i>.
|
||||
*/
|
||||
@Override
|
||||
public byte[] allocateArray(int size) {
|
||||
return new byte[size];
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing.
|
||||
*/
|
||||
@Override
|
||||
public void releaseArray(byte[] buffer) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ByteBuffer#allocateDirect(int) Allocates} a direct {@link ByteBuffer} of <i>size</i>.
|
||||
*/
|
||||
@Override
|
||||
public ByteBuffer allocateDirect(int size) {
|
||||
return ByteBuffer.allocateDirect(size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggressively releases native resources associated with <i>buffer</i>.
|
||||
*/
|
||||
@Override
|
||||
public void releaseDirect(ByteBuffer buffer) {
|
||||
assert buffer != null && buffer.isDirect();
|
||||
DirectByteBuffers.releaseDirectByteBuffer(buffer);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"resources": {
|
||||
"includes": [
|
||||
{"pattern":".*libsnappyjava.dylib"},
|
||||
{"pattern":".*libsnappyjava.so"},
|
||||
{"pattern":".*snappyjava.dll"},
|
||||
{"pattern":".*libsnappyjava.a"}
|
||||
]
|
||||
},
|
||||
"bundles": []
|
||||
}
|
2
src/main/resources/org/xerial/snappy/VERSION
Executable file
2
src/main/resources/org/xerial/snappy/VERSION
Executable file
@ -0,0 +1,2 @@
|
||||
SNAPPY_VERSION=1.1.10
|
||||
BITSHUFFLE_VERSION=0.3.4
|
BIN
src/main/resources/org/xerial/snappy/native/AIX/ppc/libsnappyjava.a
Executable file
BIN
src/main/resources/org/xerial/snappy/native/AIX/ppc/libsnappyjava.a
Executable file
Binary file not shown.
Binary file not shown.
BIN
src/main/resources/org/xerial/snappy/native/FreeBSD/x86/libsnappyjava.so
Executable file
BIN
src/main/resources/org/xerial/snappy/native/FreeBSD/x86/libsnappyjava.so
Executable file
Binary file not shown.
BIN
src/main/resources/org/xerial/snappy/native/FreeBSD/x86_64/libsnappyjava.so
Executable file
BIN
src/main/resources/org/xerial/snappy/native/FreeBSD/x86_64/libsnappyjava.so
Executable file
Binary file not shown.
BIN
src/main/resources/org/xerial/snappy/native/Linux/aarch64/libsnappyjava.so
Executable file
BIN
src/main/resources/org/xerial/snappy/native/Linux/aarch64/libsnappyjava.so
Executable file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user