pax_global_header 0000666 0000000 0000000 00000000064 13744017712 0014520 g ustar 00root root 0000000 0000000 52 comment=d22bd004391c531a95e3a607b46f6089bd96b5d3
hawtjni-hawtjni-project-1.18/ 0000775 0000000 0000000 00000000000 13744017712 0016223 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/.gitignore 0000664 0000000 0000000 00000000167 13744017712 0020217 0 ustar 00root root 0000000 0000000 .classpath
.project
.settings
*.iml
*.ipr
*.iws
.idea
webgen/out
webgen/webgen.cache
target
dependency-reduced-pom.xml
hawtjni-hawtjni-project-1.18/.travis.yml 0000664 0000000 0000000 00000000602 13744017712 0020332 0 ustar 00root root 0000000 0000000 language: java
jobs:
include:
- arch: amd64
- arch: ppc64le
before_install:
- mkdir -p /opt/maven
- curl https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz|tar -xz --strip 1 -C /opt/maven
- export MAVEN_HOME=/opt/maven
- export PATH=${MAVEN_HOME}/bin:${PATH}
after_failure: print_surefire_reports.sh
hawtjni-hawtjni-project-1.18/changelog.md 0000664 0000000 0000000 00000051042 13744017712 0020476 0 ustar 00root root 0000000 0000000 # 
## HawtJNI 1.18, released 2020-10-21
* [`84606da`](https://github.com/fusesource/hawtjni/commit/84606dacef9bced4d21c2d47bb641b2737738ceb) Bump junit from 4.13 to 4.13.1 in /hawtjni-example
* [`de46737`](https://github.com/fusesource/hawtjni/commit/de4673789a0f0892516450f837c301f5e81246d0) Merge pull request #70 from Siddhesh-Ghadi/ci-power
* [`c06f662`](https://github.com/fusesource/hawtjni/commit/c06f662b9e7ef74dd98bf73f9458cae7a3f5fd86) Add ppc64le support on travis-ci
* [`2976527`](https://github.com/fusesource/hawtjni/commit/2976527a43ec256c98c383110d436bba7aff8c9c) Add doc to setup the native build environment macOS
* [`c00e2d2`](https://github.com/fusesource/hawtjni/commit/c00e2d22b4dfa105d31754bf044874845d7cacb5) Support for shared pointers, fixes #57
* [`5b4e5ad`](https://github.com/fusesource/hawtjni/commit/5b4e5ad74e63f1c1c180b2169eedd20c9b64e716) Merge pull request #59 from voutilad/master
* [`8678713`](https://github.com/fusesource/hawtjni/commit/8678713caf00652f4f7d52e36b8b384cf611dde5) Merge pull request #61 from remkop/master
* [`d145a1d`](https://github.com/fusesource/hawtjni/commit/d145a1dea37bbd8f98c9f1e6f21d756f849d7979) Do not force JDK 11 but rather support it
* [`8ee5b21`](https://github.com/fusesource/hawtjni/commit/8ee5b2113069399c79610a1de6e01af7d5ae8c45) Updated to work with JDK11
* [`d1f1492`](https://github.com/fusesource/hawtjni/commit/d1f14926156d103357e7761c4182085b27e7c663) Fix example on OSX
* [`b7277af`](https://github.com/fusesource/hawtjni/commit/b7277aff8f3b01c1c462ede437efb3a4a33973ff) prepare 1.17 release website
* [`56b5bd0`](https://github.com/fusesource/hawtjni/commit/56b5bd0dd3e9a3091905cf262dbe232b65447e07) use hawtjni-maven-plugin for Maven Central badge
* [`c14fec0`](https://github.com/fusesource/hawtjni/commit/c14fec00b9976ff6b84e62e483d678594a7d3832) Support for OSX Catalina
* [`2c64ed4`](https://github.com/fusesource/hawtjni/commit/2c64ed4134de9b3cefd9423382a59f60c8f3ad25) jansi/#162 fix issue where bitModel could not be retrieved on GraalVM
* [`e7806ff`](https://github.com/fusesource/hawtjni/commit/e7806ff89508fce6a61c300ea9a16992324c0ce1) support for OpenBSD
## HawtJNI 1.17, released 2019-04-03
* [`1c4a17b`](https://github.com/fusesource/hawtjni/commit/1c4a17b31bf988f99df6da7085f86829b935c342) Remove shared_ptr support until it's working
* [`d3f9d0a`](https://github.com/fusesource/hawtjni/commit/d3f9d0ab71fd25d8d6f6eb9c3de6c6b47ddae92e) Keep (long*) for standard pointers
* [`906aa15`](https://github.com/fusesource/hawtjni/commit/906aa158c24d3603aca6f3766b7fa0da306d23d6) Merge branch 'calin-iorgulescu-master'
* [`c5130eb`](https://github.com/fusesource/hawtjni/commit/c5130eb900279531f67d4734ccf1ad2f2ad95a70) Fix typo
* [`9d38df2`](https://github.com/fusesource/hawtjni/commit/9d38df2f4a25ee55fbb0dc921fb2004b33c59541) Merge branch 'master' of https://github.com/calin-iorgulescu/hawtjni into calin-iorgulescu-master
* [`1c42406`](https://github.com/fusesource/hawtjni/commit/1c42406ec55ed1955d2fc573e3002e5fa557c984) Merge branch 'master' of https://github.com/batterseapower/hawtjni into batterseapower-master
* [`55afd36`](https://github.com/fusesource/hawtjni/commit/55afd361a8fe44d4d6126de30b279c5b941894ba) Add 10.14 in OSX SDK version list
* [`d094c95`](https://github.com/fusesource/hawtjni/commit/d094c95e7fd0fb879f896b49c796a92adee72369) Merge pull request #45 from wjsl/osx10.13
* [`d028542`](https://github.com/fusesource/hawtjni/commit/d028542040a23e090633ab0b192ca9c08f7838e2) Merge pull request #48 from castortech/master
* [`c0cfb25`](https://github.com/fusesource/hawtjni/commit/c0cfb2558b8e11edd224f08fd7da6daa84876b34) Merge branch 'master' into master
* [`73e0b4f`](https://github.com/fusesource/hawtjni/commit/73e0b4f68d4597295bcb6d0196a1c030ff14589a) Merge pull request #55 from tdemande/hawtjni-issue-54
* [`ec9cc6c`](https://github.com/fusesource/hawtjni/commit/ec9cc6c3ce72b7fcd99d356f1abbc0f36fbb9a29) Merge branch 'hawtjni_shared_pointer' of https://github.com/ossdev07/hawtjni into ossdev07-hawtjni_shared_pointer
* [`bd514b7`](https://github.com/fusesource/hawtjni/commit/bd514b71878415e7091b914420a291310de3ec30) Implement a different strategy with sha1 checksum for extracting libraries, fixes #56
* [`40e0b2f`](https://github.com/fusesource/hawtjni/commit/40e0b2f27a2218b4d10ae3989a4ed74bcf40562d) Formatting
* [`bc3f187`](https://github.com/fusesource/hawtjni/commit/bc3f187087a043caa6737a78c10f982159bd8c2c) #54 Also search in base dir when finding/extracting native lib
* [`8f464d0`](https://github.com/fusesource/hawtjni/commit/8f464d07bc9a807acf33f0f2e355065471f15235) Implement new JNIField accessor model: allow support for separate getter/setter methods for individual fields.
* [`5f52fee`](https://github.com/fusesource/hawtjni/commit/5f52fee5720c5cbeeaae71cfaa90611bcba56e8d) StructsGenerator: Fix bug where a JniClass extending another class that has only ignored fields would generate calls to cache the fields.
* [`2b88a8f`](https://github.com/fusesource/hawtjni/commit/2b88a8f56fdbbf0e71b213f15b333a681e7dc72f) StructsGenerator: Fix bug where an empty field declaration would be created if only skipped fields are declared in a struct.
* [`235f0b9`](https://github.com/fusesource/hawtjni/commit/235f0b985acba4559cfda588a0312287f9420791) Change maven settings to allow building.
* [`839ddcf`](https://github.com/fusesource/hawtjni/commit/839ddcf2bff9e53020f162feeac7258ea6ac97db) added icon for hawtjni-runtime artifact in Central
* [`27af76b`](https://github.com/fusesource/hawtjni/commit/27af76b5f73af61ef592cc66ed65fb12438cc166) Update StructsGenerator.java
* [`f29f849`](https://github.com/fusesource/hawtjni/commit/f29f84960133e5a5740bcd6b6120b8bb7f172f0d) added Automatic-Module-Name to manifest for Java 9 auto-module name
* [`1c2d511`](https://github.com/fusesource/hawtjni/commit/1c2d511d970ad07924ebdbb1e8566fb56e2edf6c) Hawtjni: Shared_pointer support added in hawtjni
* [`7a6082f`](https://github.com/fusesource/hawtjni/commit/7a6082faed85ea73945065466e68ad6035cf724d) fixed typo
* [`35c061c`](https://github.com/fusesource/hawtjni/commit/35c061ca7ffedb11fa52a18c8c087a41bbb5cd88) added Runtime API as a feature
* [`6c1f140`](https://github.com/fusesource/hawtjni/commit/6c1f140970a59727a102b8ee2daef909eb991b78) Added customization for the Windows build.
* [`98b1531`](https://github.com/fusesource/hawtjni/commit/98b1531628f236aa9a68fd49b67ac09f1b547868) Added missing case of "no directory" as per method documentation.
* [`a103c50`](https://github.com/fusesource/hawtjni/commit/a103c50b1b1b357d6a5d932cac7ebc599bb0d16b) Added support to detect newer versions of Visual Studio as candidates for msbuild
* [`6f891af`](https://github.com/fusesource/hawtjni/commit/6f891af96768e77f5e800fd0f723712b87e30735) Updated documentation to clearly indicate the vcbuild is deprecated and that msbuild is supported.
* [`84aa381`](https://github.com/fusesource/hawtjni/commit/84aa381836dae2b784ea685b71c54c6eb6622646) update changelog.md for 1.16 release
* [`3fffa67`](https://github.com/fusesource/hawtjni/commit/3fffa67c2b23f92a1c57552e3779c58382795855) fixed and improved changelog.md formatting
* [`2c7134b`](https://github.com/fusesource/hawtjni/commit/2c7134b4ee612af788d8486181459580811ba1d6) Add 10.13 in OSX SDK version list
## HawtJNI 1.16, released 2018-02-02
* [`2e99592`](https://github.com/fusesource/hawtjni/commit/2e99592f7be976a935beeed7d7395d4a5787e04e) fixed site build
* [`14f1d05`](https://github.com/fusesource/hawtjni/commit/14f1d0564d6e2c71c74288e537fcfa4acf7f4c18) renamed maven-hawtjni-plugin to hawtjni-maven-plugin
* [`743d57b`](https://github.com/fusesource/hawtjni/commit/743d57b25337dc1e0b5dcfc7dce63b15a4433f78) switched Maven plugin from javadoc annotations to Java5 annotations
* [`4a42ee6`](https://github.com/fusesource/hawtjni/commit/4a42ee611ad66c71a6d4b32d41b78ca02ca225e4) [#36](http://github.com/fusesource/hawtjni/issues/36) added info on loaded native library
* [`16c5d82`](https://github.com/fusesource/hawtjni/commit/16c5d820e84864fe437ce77a33011b50b2a6f66d) Merge pull request [#37](http://github.com/fusesource/hawtjni/issues/37) from ghost/patch-1
* [`45e8a55`](https://github.com/fusesource/hawtjni/commit/45e8a557788a8dbf9fd134df6f8e99f456e3324f) [#43](http://github.com/fusesource/hawtjni/issues/43) mark HawtJNI annotations @Documented
* [`f0c3b54`](https://github.com/fusesource/hawtjni/commit/f0c3b547aeecd508498871583595ab7adff54ea3) s/your/you're/
## [HawtJNI 1.15](http://fusesource.github.io/hawtjni/blog/releases/release-1-15.html), released 2017-05-04
* [`7537b9d`](https://github.com/fusesource/hawtjni/commit/7537b9d19be9806b210674ccad4b96d90a11d50b) Update changelog
* [`906cedb`](https://github.com/fusesource/hawtjni/commit/906cedb80b9661d0ea08f524fb464243610653a9) Default to extract in the users' home folder in case the temp directory is not writable
* [`ed95784`](https://github.com/fusesource/hawtjni/commit/ed95784f9a4d3ed1afb0a14bd3dccc815d3e3cbe) search in library.$name.path like in META-INF/native resources
* [`477c8cc`](https://github.com/fusesource/hawtjni/commit/477c8ccac78c3695ebcf6299d8b201adb3394d34) Fix some other problems with platform, especially on windows when compiling for the non native platform
* [`58834e8`](https://github.com/fusesource/hawtjni/commit/58834e835c6f196f6188c6f35aa9c349db610d84) Upgrade some plugins
* [`992ee3f`](https://github.com/fusesource/hawtjni/commit/992ee3fa28f30823913fe95a790fe3a08d19bdf3) Fix bad naming for the extracted file when the version contains a dot
* [`6b58328`](https://github.com/fusesource/hawtjni/commit/6b58328635bd181c18048387aa7d83fda51d5be8) Do not include the extension in the windows project name, [#23](http://github.com/fusesource/hawtjni/issues/23)
* [`9165154`](https://github.com/fusesource/hawtjni/commit/916515413152d2b25268d0f813c1f0f411388b3a) Merge pull request [#30](http://github.com/fusesource/hawtjni/issues/30) from felixvf/fix_lib64_bug
* [`1cb6770`](https://github.com/fusesource/hawtjni/commit/1cb6770dc7348958d96b38d8d0b1f4b065f43da5) Merge pull request [#34](http://github.com/fusesource/hawtjni/issues/34) from hboutemy/master
* [`4c430c6`](https://github.com/fusesource/hawtjni/commit/4c430c6d4454b37e035c1fb7ae284b8d3ac99c03) Merge pull request [#20](http://github.com/fusesource/hawtjni/issues/20) from felixvf/fix_bug_18
* [`f99972b`](https://github.com/fusesource/hawtjni/commit/f99972b7892fd621dca1442b8c8f3234edd4b02f) Better exception reporting when unable to load a library, fixes [#27](http://github.com/fusesource/hawtjni/issues/27)
* [`1c5b81f`](https://github.com/fusesource/hawtjni/commit/1c5b81fb386f74e47e776f3ba2775d15003f2ae9) Allow the windows project name to be specified, fixes [#23](http://github.com/fusesource/hawtjni/issues/23)
* [`ef3437c`](https://github.com/fusesource/hawtjni/commit/ef3437cde117c04793d773b25bd0627e5e260e66) Allow the -Dplatform=xxx setting to be used when doing the actual native build
* [`0072848`](https://github.com/fusesource/hawtjni/commit/0072848253e100c98745725bdf5224e63103fad7) Remove explicit array creation when using var args
* [`c6fb914`](https://github.com/fusesource/hawtjni/commit/c6fb9149b43292564bbc854d9942d4898a7f728d) Remove unused imports
* [`145f3ee`](https://github.com/fusesource/hawtjni/commit/145f3ee50204c8b8f8ae728cc91533dd19424d7d) Fix typos in method names
* [`81a35e1`](https://github.com/fusesource/hawtjni/commit/81a35e1a923bb1c7b0e6ffbdd66a08c83e119324) prepare gh-pages publication with scm-publish plugin
* [`b3982d5`](https://github.com/fusesource/hawtjni/commit/b3982d573b04878918aebe5435a5f64af6a4401f) Use latest version of maven javadoc plugin
* [`cb2ad85`](https://github.com/fusesource/hawtjni/commit/cb2ad85bc551e1628be25181acd6f9e97e04afab) Merge branch 'hboutemy-hawtjni-31'
* [`cd20329`](https://github.com/fusesource/hawtjni/commit/cd20329a801e5d904d7a43c46d3cb150b4767b66) [#31](http://github.com/fusesource/hawtjni/issues/31) fixed API doc generation and misc other Maven-related conf
* [`784a50f`](https://github.com/fusesource/hawtjni/commit/784a50f22d0abd1d4fa05f1fb720e70623092e63) Fix libdir to "/lib". Prevent any variation such as "/lib64".
* [`401ce1c`](https://github.com/fusesource/hawtjni/commit/401ce1cc6f053fccae386977b695ae7a5948ef4d) Update readme.md
* [`a73fc16`](https://github.com/fusesource/hawtjni/commit/a73fc165306a139e8cbb82f9dc28002c05d6d206) Merge pull request [#11](http://github.com/fusesource/hawtjni/issues/11) from OhmData/travis
* [`098c501`](https://github.com/fusesource/hawtjni/commit/098c501c90feb20749105840eaca1f51fbae2559) Simplify the fallback case a bit
* [`40f9f23`](https://github.com/fusesource/hawtjni/commit/40f9f23b4839941e217a8415eb9799aa539e0e36) Merge pull request [#22](http://github.com/fusesource/hawtjni/issues/22) from slaunay/use-java7-chmod-with-unix-chmod-fallback
## [HawtJNI 1.14](http://fusesource.github.io/hawtjni/blog/releases/release-1.14.html), released 2016-06-20
* [`e2522b0`](https://github.com/fusesource/hawtjni/commit/e2522b0ddd9f8975dc3a1cc99534ea458b807ddd) Merge pull request [#26](http://github.com/fusesource/hawtjni/issues/26) from michael-o/freebsd
* [`6dc93fe`](https://github.com/fusesource/hawtjni/commit/6dc93fe4c3b67e68d9805b6f0cc7f2b7c36d5b06) Improve FreeBSD support
* [`2d49307`](https://github.com/fusesource/hawtjni/commit/2d493076d264f6d8e2ac81ada4da4fcd78b2dabf) Deploy to sonatype.
## [HawtJNI 1.12](http://fusesource.github.io/hawtjni/blog/releases/release-1.12.html), released 2016-04-26
* [`70f24ba`](https://github.com/fusesource/hawtjni/commit/70f24ba7438a698d8e1e0de599b304774e01f5d4) Don't build the website by default.
* [`ef93152`](https://github.com/fusesource/hawtjni/commit/ef931527b4ca915a53c59eb6f6ef0222f8cf3c12) Better JDK detection on OS X.
* [`61ac652`](https://github.com/fusesource/hawtjni/commit/61ac6525a42117f0ea8820417d00616ef7f27452) Use Files.setPosixFilePermissions for chmod
* [`57e5b32`](https://github.com/fusesource/hawtjni/commit/57e5b3262a86ac0541585f3b3a40bf3b8933561b) Define JNI64 not only in case of \_\_x86\_64\_\_ but in general for any \_LP64 platform.
## [HawtJNI 1.11](http://fusesource.github.io/hawtjni/blog/releases/release-1.11.html), released 2015-04-21
* [`e1da91a`](https://github.com/fusesource/hawtjni/commit/e1da91aec68eda9f40350b062c4fed4e75fb4cb1) Update xbean version used.
* [`354e277`](https://github.com/fusesource/hawtjni/commit/354e2773cfb60008fd7500eef52ea7de8e9bb74a) Disable deployment of website since web host is not there anymore.
* [`08cfdd0`](https://github.com/fusesource/hawtjni/commit/08cfdd0995bb298d88e87d559d2ce39018e6b509) Update parent pom.
* [`86e97d1`](https://github.com/fusesource/hawtjni/commit/86e97d161d956009bbc92f2913dd570ece2ec3da) Merge pull request [#19](http://github.com/fusesource/hawtjni/issues/19) from jerrydlamme/master
* [`1e2ee63`](https://github.com/fusesource/hawtjni/commit/1e2ee6330f6832a374e29b78a1fff2df62d4a52c) Added architecture specific native library loading path
* [`d10c4b0`](https://github.com/fusesource/hawtjni/commit/d10c4b0914301810297f0f917ce3dba3e8868ff1) Merge pull request [#16](http://github.com/fusesource/hawtjni/issues/16) from NJAldwin/use-absolute-path
* [`3d3aa0b`](https://github.com/fusesource/hawtjni/commit/3d3aa0be17cc8d35e251ea3594b1e684ce919d0d) Ensure absolute path is used for library
* [`8c28532`](https://github.com/fusesource/hawtjni/commit/8c2853238e31b6e92f61fbdeda84314e5a529254) Merge pull request [#13](http://github.com/fusesource/hawtjni/issues/13) from batterseapower/master
* [`c10adf5`](https://github.com/fusesource/hawtjni/commit/c10adf5139969f1bfa6cb6e8dd6af204d64280a9) Version bumps and markup fixes necessary for building on JDK8
* [`aed6cbd`](https://github.com/fusesource/hawtjni/commit/aed6cbd06b4579170617dae7146ec9c61b70d82c) Build a stock travis
* [`efa684c`](https://github.com/fusesource/hawtjni/commit/efa684c0a87136f16b0bca67bc518ee9bf698f85) Ignore IDEA project files.
* [`18cb7e5`](https://github.com/fusesource/hawtjni/commit/18cb7e5d98e0edf687ba2d02c724c36d631e9f65) prepare for next development iteration
* [`f3bd38e`](https://github.com/fusesource/hawtjni/commit/f3bd38e1d83a5563c63b1bbebadf0c77c1fb54b8) Upgrade parent pom version.
* [`175faf0`](https://github.com/fusesource/hawtjni/commit/175faf07fbc2ec1c42582d0b935bb05fd46fc33f) Merge pull request [#8](http://github.com/fusesource/hawtjni/issues/8) from normanmaurer/netty\_needs
* [`b3f8609`](https://github.com/fusesource/hawtjni/commit/b3f8609c6682bda6d6c112c2e19c0c6cdc6dcfc6) Allow to also use generate mojo with existing native src files
* [`c27b5a0`](https://github.com/fusesource/hawtjni/commit/c27b5a0c4640bce9437488275b0d8c360c45c1e6) Avoid warning.
* [`c1980ef`](https://github.com/fusesource/hawtjni/commit/c1980ef32387547b0a5bba408abb00cbceaf6705) Add support for building against the Oracle JDK on OS X.
## [HawtJNI 1.10](http://fusesource.github.io/hawtjni/blog/releases/release-1.10.html), released 2014-02-12
* `efa684c` Ignore IDEA project files.
* `18cb7e5` prepare for next development iteration
* `f3bd38e` Upgrade parent pom version.
* `175faf0` Merge pull request [#8](http://github.com/fusesource/hawtjni/issues/8) from normanmaurer/netty\_needs
* `b3f8609` Allow to also use generate mojo with existing native src files
* `c27b5a0` Avoid warning.
* `c1980ef` Add support for building against the Oracle JDK on OS X.
## [HawtJNI 1.9](http://fusesource.github.io/hawtjni/blog/releases/release-1-9.html), released 2013-09-09
* [`1d27b2f`](https://github.com/fusesource/hawtjni/commit/1d27b2f1396920be7fce0be8b1995ac0459c69ef) Improve the generated build settings.
* [`d9cd0ab`](https://github.com/fusesource/hawtjni/commit/d9cd0ab660ac5acbdc5f84c806ba14b77e197385) Should fix issue [#7](http://github.com/fusesource/hawtjni/issues/7). We now do a write barrier before setting the 'cached' field to 1 so that reader don't see this get re-ordered before all the fields are readable.
## [HawtJNI 1.8](http://fusesource.github.io/hawtjni/blog/releases/release-1-8.html), released 2013-05-13
* [`92c2661`](https://github.com/fusesource/hawtjni/commit/92c266170ce98edc200c656bd034a237098b8aa5) Simplify shared lib extraction.
## [HawtJNI 1.7](http://fusesource.github.io/hawtjni/blog/releases/release-1-7.html), released 2013-03-20
* [`3567b1d`](https://github.com/fusesource/hawtjni/commit/3567b1d89d458bddb651df252f3bb275c9076e1a) Support explicitly configuring which build tool to use on windows.
* [`d566bf7`](https://github.com/fusesource/hawtjni/commit/d566bf7de5d6a67fa7c7b3e04352ca2630fb55fe) Fix for automake 1.11
## [HawtJNI 1.6](http://fusesource.github.io/hawtjni/blog/releases/release-1-6.html), released 2012-08-09
* [`11df668`](https://github.com/fusesource/hawtjni/commit/11df668cb0d1269c0f98d9c09d80c56cf0770421) Updating hawtjni generate projects so that they work on OS X Lion.
* [`f0e3ace`](https://github.com/fusesource/hawtjni/commit/f0e3ace6422e5c5413445229ac79d27f68b1485b) Fixes [#2](http://github.com/fusesource/hawtjni/issues/2) : Support passing the JNIEnv pointer to native methods.
## [HawtJNI 1.5](http://fusesource.github.io/hawtjni/blog/releases/release-1-5.html), released 2011-09-21
* [`15d5b1a`](https://github.com/fusesource/hawtjni/commit/15d5b1a4c928fb8c39eee0705316478af30704b5) Only include config.h if it's available.
## [HawtJNI 1.4](http://fusesource.github.io/hawtjni/blog/releases/release-1-4.html), released 2011-08-18
* Add more options to the maven hawtjni plugin so that you can build jars containing
native libs in a different module from the one which generates the native package for
the jar.
## [HawtJNI 1.3](http://fusesource.github.io/hawtjni/blog/releases/release-1-3.html), released 2011-08-08
* Add hawtjni_attach_thread and hawtjni_dettach_thread helper methods
* Fully support binding against C++ source code / classes.
* Support using private fields in struct bound classes.
* Avoid "jump to label from here crosses initialization" compiler error message.
* Provide better error messages when a user does not properly setup a C++ method binding.
* Support mapping a class to a differently named structure name.
* Support picking the OS X SDK version via a configure option.
* Added pointer math support class to be able to do pointer math in java land without going into a JNI layer.
## [HawtJNI 1.2](http://fusesource.github.io/hawtjni/blog/releases/release-1-2.html), released 2011-06-11
* Adding bit model to the name of the extracted library to support hosts running both 32 and 64 bits JVM.
* Converted website to a scalate based static website
## [HawtJNI 1.1](http://fusesource.github.io/hawtjni/blog/releases/release-1-1.html), released 2010-11-04
----
* Generate a .vcxproj for for compatibility with the new Windows 7.1 SDK
* Fixed callback failures on 32 bit platforms
## [HawtJNI 1.0](http://fusesource.github.io/hawtjni/blog/releases/2010/04/release-1-0.html), released 2010-02-24
* Initial release
hawtjni-hawtjni-project-1.18/hawtjni-example/ 0000775 0000000 0000000 00000000000 13744017712 0021320 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-example/pom.xml 0000664 0000000 0000000 00000013374 13744017712 0022645 0 ustar 00root root 0000000 0000000
4.0.0
org.fusesource.hawtjni
hawtjni-project
1.18
hawtjni-example
HawtJNI Example
org.fusesource.hawtjni
hawtjni-runtime
${project.version}
junit
junit
4.13.1
test
log4j
log4j
1.2.17
test
org.fusesource.hawtjni
hawtjni-maven-plugin
${project.version}
generate
build
package-jar
package-source
org.apache.maven.plugins
maven-shade-plugin
3.2.3
package
shade
junit:junit
*:*
META-INF/MANIFEST.MF
mac
mac
org.fusesource.hawtjni
hawtjni-maven-plugin
osname=MacOS;processor=x86-64
osname=MacOS;processor=x86
*
--with-universal
osx
hawtjni-hawtjni-project-1.18/hawtjni-example/src/ 0000775 0000000 0000000 00000000000 13744017712 0022107 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-example/src/main/ 0000775 0000000 0000000 00000000000 13744017712 0023033 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-example/src/main/java/ 0000775 0000000 0000000 00000000000 13744017712 0023754 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-example/src/main/java/test/ 0000775 0000000 0000000 00000000000 13744017712 0024733 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-example/src/main/java/test/Example.java 0000775 0000000 0000000 00000027406 13744017712 0027205 0 ustar 00root root 0000000 0000000 /*******************************************************************************
* Copyright (C) 2009-2011 FuseSource Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package test;
import java.util.Arrays;
import org.fusesource.hawtjni.runtime.*;
import static org.fusesource.hawtjni.runtime.ArgFlag.*;
import static org.fusesource.hawtjni.runtime.FieldFlag.*;
import static org.fusesource.hawtjni.runtime.MethodFlag.*;
/**
*
* @author Hiram Chirino
*/
@JniClass
public class Example {
private static final Library LIBRARY = new Library("hawtjni-example", Example.class);
static {
LIBRARY.load();
init();
}
public static final void main(String args[]) {
System.out.println("Checking Operating System Constants:");
System.out.println(" O_RDONLY: "+O_RDONLY);
System.out.println(" O_WRONLY: "+O_WRONLY);
System.out.println(" O_RDWR: "+O_RDWR);
System.out.println("");
System.out.println("Allocating c structures on the heap...");
int COUNT = 10;
// We track memory pointers with longs.
long []ptrArray = new long[COUNT];
long last=0;
for( int i=0; i < COUNT; i++ ) {
// Allocate heap space of the structure..
ptrArray[i] = malloc(bar.SIZEOF);
// Configure some data for a structure...
bar f = new bar();
f.a = i;
f.b = 1;
byte[] src = "hello world".getBytes();
System.arraycopy(src, 0, f.c, 0, src.length);
f.c5 = 0;
f.prev = last;
// Copy the data values into the allocated space.
memmove(ptrArray[i], f, bar.SIZEOF);
last = ptrArray[i];
}
// Display a couple of structures...
System.out.println("Dump of the first 2 structures:");
print_foo(ptrArray[0]);
print_foo(ptrArray[1]);
System.out.println("Passing a pointer array to a c function...");
long rc = foowork(ptrArray, COUNT);
System.out.println("Function result (expecting 55): "+rc);
System.out.println("freein up allocated memory.");
for( int i=0; i < COUNT; i++ ) {
free(ptrArray[i]);
}
}
// Example of how to load constants.
@JniMethod(flags={CONSTANT_INITIALIZER})
private static final native void init();
@JniField(flags={CONSTANT})
public static int O_RDONLY;
@JniField(flags={CONSTANT})
public static int O_WRONLY;
@JniField(flags={CONSTANT})
public static int O_RDWR;
@JniMethod(cast="void *")
public static final native long malloc(
@JniArg(cast="size_t") long size);
public static final native void free(
@JniArg(cast="void *") long ptr);
public static final native void memmove (
@JniArg(cast="void *") long dest,
@JniArg(cast="const void *") long src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *") long dest,
@JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) byte[] src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *") long dest,
@JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) char[] src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *") long dest,
@JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) short[] src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *") long dest,
@JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) int[] src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *") long dest,
@JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) long[] src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *") long dest,
@JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) float[] src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *") long dest,
@JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) double[] src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *", flags={NO_IN, CRITICAL}) byte[] dest,
@JniArg(cast="const void *") long src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *", flags={NO_IN, CRITICAL}) char[] dest,
@JniArg(cast="const void *") long src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *", flags={NO_IN, CRITICAL}) short[] dest,
@JniArg(cast="const void *") long src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *", flags={NO_IN, CRITICAL}) int[] dest,
@JniArg(cast="const void *") long src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *", flags={NO_IN, CRITICAL}) long[] dest,
@JniArg(cast="const void *") long src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *", flags={NO_IN, CRITICAL}) float[] dest,
@JniArg(cast="const void *") long src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *", flags={NO_IN, CRITICAL}) double[] dest,
@JniArg(cast="const void *") long src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *", flags={NO_IN, CRITICAL}) byte[] dest,
@JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) char[] src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *", flags={NO_IN, CRITICAL}) int[] dest,
@JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) byte[] src,
@JniArg(cast="size_t") long size);
@JniMethod(cast="void *")
public static final native long memset (
@JniArg(cast="void *") long buffer,
int c,
@JniArg(cast="size_t") long num);
public static final native int strlen(
@JniArg(cast="char *")long s);
@JniClass(name="foo", flags={ClassFlag.STRUCT})
static public class bar {
static {
LIBRARY.load();
init();
}
@JniMethod(flags={CONSTANT_INITIALIZER})
private static final native void init();
// public static final native int foo_sizeof ();
@JniField(flags={CONSTANT}, accessor="sizeof(struct foo)")
public static int SIZEOF;
public int a;
@JniField(cast="size_t")
public long b;
public byte c[] = new byte[20];
@JniField(accessor="c[5]")
public byte c5;
@JniField(cast="struct foo *")
public long prev;
@JniField(getter = "get_d()", setter = "set_d()", flags = { GETTER_NONMEMBER, SETTER_NONMEMBER })
private float d;
@JniField(getter = "get_sp()", setter = "set_sp()", flags={ SHARED_PTR, GETTER_NONMEMBER, SETTER_NONMEMBER })
private long CheckStr;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + a;
result = prime * result + (int) (b ^ (b >>> 32));
result = prime * result + Arrays.hashCode(c);
result = prime * result + c5;
result = prime * result + (int) (prev ^ (prev >>> 32));
result = prime * result + Float.valueOf(d).hashCode();
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
bar other = (bar) obj;
if (a != other.a)
return false;
if (b != other.b)
return false;
if (!Arrays.equals(c, other.c))
return false;
if (c5 != other.c5)
return false;
if (prev != other.prev)
return false;
if (d != other.d) {
return false;
}
return true;
}
@Override
public String toString() {
return "foo [a=" + a + ", b=" + b + ", c=" + Arrays.toString(c) + ", c5=" + c5 + ", prev=" + prev + ", d=" + d + "]";
}
}
public static final native void memmove (
@JniArg(cast="void *") long dest,
@JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) bar src,
@JniArg(cast="size_t") long size);
public static final native void memmove (
@JniArg(cast="void *", flags={NO_IN, CRITICAL}) bar dest,
@JniArg(cast="const void *") long src,
@JniArg(cast="size_t") long size);
public static final native void print_foo(@JniArg(cast="struct foo *")long ptr);
public static final native long foowork (@JniArg(cast="struct foo **") long[] foos, int count);
@JniMethod(cast = "struct foo *")
public static final native long foo_add(@JniArg(cast="struct foo *")long ptr, int count);
@JniMethod(cast = "char *")
public static final native long char_add(@JniArg(cast="char *")long ptr, int count);
@JniClass(flags={ClassFlag.STRUCT, ClassFlag.TYPEDEF})
static public class point {
static {
LIBRARY.load();
init();
}
@JniMethod(flags={CONSTANT_INITIALIZER})
private static final native void init();
@JniField(flags={CONSTANT}, accessor="sizeof(point)")
public static int SIZEOF;
public int x;
public int y;
}
public static final native void callmeback(
@JniArg(cast="void (*)(int)", flags = ArgFlag.POINTER_ARG)
long ptr);
@JniClass(flags={ClassFlag.STRUCT, ClassFlag.CPP})
static class Range {
static {
LIBRARY.load();
}
@JniMethod(flags={MethodFlag.CPP_NEW})
public static final native long Range();
@JniMethod(flags={MethodFlag.CPP_NEW})
public static final native long Range(int start, int end);
@JniMethod(flags={MethodFlag.CPP_DELETE})
public static final native void delete(long ptr);
@JniMethod(flags={MethodFlag.CPP_METHOD})
public static final native void dump(long ptr);
}
public static final native void passingtheenv (String msg, JNIEnv env);
@JniClass(flags={ClassFlag.STRUCT})
static class ClassWithAccessors {
static {
LIBRARY.load();
}
@JniField(getter = "get_e()", setter = "set_e()")
private float e;
}
}
hawtjni-hawtjni-project-1.18/hawtjni-example/src/main/java/test/ObjectiveCExample.java 0000664 0000000 0000000 00000005546 13744017712 0031141 0 ustar 00root root 0000000 0000000 /*******************************************************************************
* Copyright (C) 2009-2011 FuseSource Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package test;
import org.fusesource.hawtjni.runtime.JniArg;
import org.fusesource.hawtjni.runtime.JniClass;
import org.fusesource.hawtjni.runtime.JniMethod;
import org.fusesource.hawtjni.runtime.Library;
import static org.fusesource.hawtjni.runtime.ArgFlag.*;
import static org.fusesource.hawtjni.runtime.MethodFlag.*;
/**
*
* @author Hiram Chirino
*/
@JniClass(conditional="defined(__APPLE__)")
public class ObjectiveCExample {
private static final Library LIBRARY = new Library("hawtjni-example", Example.class);
static {
LIBRARY.load();
}
public static final void main(String args[]) {
// Memory pool...
long NSAutoreleasePool = objc_getClass("NSAutoreleasePool");
long pool = $($(NSAutoreleasePool, alloc), init);
// Allocate and use a simple Objective C object
long NSString = objc_getClass("NSString");
long id = $(NSString, stringWithUTF8String, "Hello");
long value = $(id, length);
System.out.println("The length was: "+value);
// Release the pool to release the allocations..
$(pool, release);
}
public static final long stringWithUTF8String = sel_registerName("stringWithUTF8String:");
public static final long release = sel_registerName("release");
public static final long alloc = sel_registerName("alloc");
public static final long init = sel_registerName("init");
public static final long length = sel_registerName("length");
@JniMethod(cast="SEL", flags={POINTER_RETURN})
public static final native long sel_registerName(String selectorName);
@JniMethod(cast="id", flags={POINTER_RETURN})
public static final native long objc_getClass(String className);
@JniMethod(cast="id", flags={POINTER_RETURN}, accessor="reinterpret_cast (objc_msgSend)")
public static final native long $(
@JniArg(cast="id", flags={POINTER_ARG})long id,
@JniArg(cast="SEL", flags={POINTER_ARG})long sel
);
@JniMethod(cast="id", flags={POINTER_RETURN}, accessor="reinterpret_cast (objc_msgSend)")
public static final native long $(
@JniArg(cast="id", flags={POINTER_ARG})long id,
@JniArg(cast="SEL", flags={POINTER_ARG})long sel,
String arg0);
}
hawtjni-hawtjni-project-1.18/hawtjni-example/src/main/native-package/ 0000775 0000000 0000000 00000000000 13744017712 0025712 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-example/src/main/native-package/src/ 0000775 0000000 0000000 00000000000 13744017712 0026501 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-example/src/main/native-package/src/foo.cpp 0000664 0000000 0000000 00000002661 13744017712 0027775 0 ustar 00root root 0000000 0000000 /*******************************************************************************
* Copyright (C) 2009-2011 FuseSource Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
#include "foo.h"
#include
float get_d(struct foo *arg) {
return 0.0f;
}
void set_d(struct foo *arg, float d) {
}
std::shared_ptr get_sp(long CheckStr) {
return std::make_shared (CheckStr);
}
void set_sp(struct foo *arg, std::shared_ptr ptr) {
}
void print_foo(struct foo *arg) {
printf("foo@%p: { a: %d, b: %d, c: \"%s\", prev: @%p, d: %f, Checkstr: %p}\n", arg, arg->a, (int)arg->b, arg->c, arg->prev, get_d(arg), get_sp(arg->CheckStr).get());
}
long foowork(struct foo **arg, int count) {
long rc=0;
int i=0;
for( i=0; i < count; i++ ) {
rc = rc + (*arg)->a;
rc = rc + (*arg)->b;
arg++;
}
return rc;
}
void callmeback(void (*thecallback)(int number)) {
thecallback(69);
}
struct foo * foo_add(struct foo *arg, int count) {
return arg+count;
}
char * char_add(char *arg, int count) {
return arg+count;
}
void passingtheenv (const char *who, JNIEnv *env) {
printf("%s, the JNIEnv is at: %p\n", who, env);
}
hawtjni-hawtjni-project-1.18/hawtjni-example/src/main/native-package/src/foo.h 0000664 0000000 0000000 00000002712 13744017712 0027437 0 ustar 00root root 0000000 0000000 /*******************************************************************************
* Copyright (C) 2009-2011 FuseSource Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
#ifndef INCLUDED_FOO_H
#define INCLUDED_FOO_H
#include
#include
#include "jni.h"
#ifdef __cplusplus
extern "C" {
#endif
struct foo {
int a;
size_t b;
char c[20];
struct foo *prev;
long CheckStr;
};
typedef struct _point {
int x;
int y;
} point;
struct ClassWithAccessors {
float e;
float (*get_e)();
void (*set_e)(float e);
};
float get_d(struct foo *arg);
void set_d(struct foo *arg, float d);
float ClassWithAccessors_get_e(struct foo *arg);
void ClassWithAccessors_set_e(struct foo *arg, float e);
struct foo * foo_add(struct foo *arg, int count);
char * char_add(char *arg, int count);
void print_foo(struct foo *arg);
long foowork(struct foo **arg, int count);
void callmeback(void (*thecallback)(int number));
void passingtheenv (const char *who, JNIEnv *env);
#ifdef __cplusplus
} /* extern "C" */
#endif
std::shared_ptr get_sp(long CheckStr);
void set_sp(struct foo *arg, std::shared_ptr);
#endif /* INCLUDED_FOO_H */
hawtjni-hawtjni-project-1.18/hawtjni-example/src/main/native-package/src/hawtjni-example.h 0000664 0000000 0000000 00000002433 13744017712 0031751 0 ustar 00root root 0000000 0000000 /*******************************************************************************
* Copyright (C) 2009-2011 FuseSource Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
#ifndef INCLUDED_PLATFORM_H
#define INCLUDED_PLATFORM_H
#ifdef HAVE_CONFIG_H
/* configure based build.. we will use what it discovered about the platform */
#include "config.h"
#else
#ifdef WIN32
/* Windows based build */
#define HAVE_STDLIB_H 1
#define HAVE_STRINGS_H 1
#endif
#endif
#include
#ifdef __APPLE__
#import
#endif
#ifdef HAVE_UNISTD_H
#include
#endif
#ifdef HAVE_STDLIB_H
#include
#endif
#ifdef HAVE_STRINGS_H
#include
#endif
#include
#include "foo.h"
#include "stdio.h"
class Range {
public:
int start;
int end;
Range() {
start = 0;
end = 0;
}
Range(const int s, const int e) {
start = s;
end = e;
}
void dump() {
printf("range: %d-%d\n", start, end);
}
};
#endif /* INCLUDED_PLATFORM_H */
hawtjni-hawtjni-project-1.18/hawtjni-example/src/test/ 0000775 0000000 0000000 00000000000 13744017712 0023066 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-example/src/test/java/ 0000775 0000000 0000000 00000000000 13744017712 0024007 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-example/src/test/java/test/ 0000775 0000000 0000000 00000000000 13744017712 0024766 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-example/src/test/java/test/ExampleTest.java 0000664 0000000 0000000 00000005064 13744017712 0030071 0 ustar 00root root 0000000 0000000 package test;
import static org.junit.Assert.*;
import static test.Example.*;
import org.fusesource.hawtjni.runtime.Callback;
import org.fusesource.hawtjni.runtime.JNIEnv;
import org.junit.Test;
import static org.fusesource.hawtjni.runtime.PointerMath.*;
import test.Example.bar;
public class ExampleTest {
static private int staticCallbackResult;
private int instanceCallbackResult;
@Test
public void testPointerMath() {
long values[] = new long[]{
0, Long.MAX_VALUE, Long.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE,
0+1, Long.MAX_VALUE+1, Long.MIN_VALUE+1, Integer.MAX_VALUE+1, Integer.MIN_VALUE+1,
0-1, Long.MAX_VALUE-1, Long.MIN_VALUE-1, Integer.MAX_VALUE-1, Integer.MIN_VALUE-1};
for( long i: values ) {
assertEquals(char_add(i, 1), add(i, 1) );
assertEquals(char_add(i, -1), add(i, -1) );
}
}
@Test
public void test() {
// Allocate and initialize some memory on the heap.
long ptr = malloc(bar.SIZEOF);
memset(ptr, 0, bar.SIZEOF);
// Configure an object that can be mapped to a C structure.
bar expected = new bar();
expected.a = 35;
expected.b = Integer.MAX_VALUE;
System.arraycopy("Hello World!".getBytes(), 0, expected.c, 0, 5);
// Marshal the object to the allocated heap memory
memmove(ptr, expected, bar.SIZEOF);
// Unmarshal the object from the allocated heap memory.
bar acutal = new bar();
memmove(acutal, ptr, bar.SIZEOF);
assertEquals(expected, acutal);
Callback callback = new Callback(this, "instanceCallback", 1);
callmeback(callback.getAddress());
assertEquals(69, instanceCallbackResult);
callback.dispose();
long r1 = Range.Range();
Range.dump(r1);
long r2 = Range.Range(10,100);
Range.dump(r2);
Range.delete(r1);
Range.delete(r2);
callback = new Callback(ExampleTest.class, "staticCallback", 1);
callmeback(callback.getAddress());
assertEquals(69, staticCallbackResult);
callback.dispose();
// Heap memory is not GCed, we must manually free it.
free(ptr);
passingtheenv("Hiram", null);
}
public long instanceCallback(long value) {
this.instanceCallbackResult = (int) value;
return 0;
}
static public long staticCallback(long value) {
staticCallbackResult = (int) value;
return 0;
}
}
hawtjni-hawtjni-project-1.18/hawtjni-generator/ 0000775 0000000 0000000 00000000000 13744017712 0021653 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-generator/pom.xml 0000664 0000000 0000000 00000010712 13744017712 0023171 0 ustar 00root root 0000000 0000000
4.0.0
org.fusesource.hawtjni
hawtjni-project
1.18
hawtjni-generator
HawtJNI Generator
This module contains the JNI code generation tools.
org.fusesource.hawtjni
hawtjni-runtime
${project.version}
xbean-finder
org.apache.xbean
4.16
org.ow2.asm
asm
8.0.1
org.ow2.asm
asm-commons
8.0.1
commons-cli
commons-cli
1.0
org.apache.maven.plugins
maven-shade-plugin
3.2.3
package
shade
junit:junit
*:*
META-INF/DEPENDENCIES
META-INF/LICENSE*
META-INF/NOTICE
META-INF/MANIFEST.MF
module-info.class
org.apache.xbean:xbean-finder
org/apache/xbean/asm7/original/commons/AsmConstants.class
org/apache/xbean/asm7/original/commons/EmptyVisitor*
hawtjni-hawtjni-project-1.18/hawtjni-generator/src/ 0000775 0000000 0000000 00000000000 13744017712 0022442 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-generator/src/main/ 0000775 0000000 0000000 00000000000 13744017712 0023366 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-generator/src/main/java/ 0000775 0000000 0000000 00000000000 13744017712 0024307 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-generator/src/main/java/org/ 0000775 0000000 0000000 00000000000 13744017712 0025076 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-generator/src/main/java/org/fusesource/ 0000775 0000000 0000000 00000000000 13744017712 0027261 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-generator/src/main/java/org/fusesource/hawtjni/ 0000775 0000000 0000000 00000000000 13744017712 0030725 5 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-generator/src/main/java/org/fusesource/hawtjni/generator/ 0000775 0000000 0000000 00000000000 13744017712 0032713 5 ustar 00root root 0000000 0000000 CleanupClass.java 0000775 0000000 0000000 00000010531 13744017712 0036057 0 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-generator/src/main/java/org/fusesource/hawtjni/generator /*******************************************************************************
* Copyright (C) 2009-2011 FuseSource Corp.
* Copyright (c) 2004, 2008 IBM Corporation and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*******************************************************************************/
package org.fusesource.hawtjni.generator;
import java.io.*;
import java.util.*;
import org.fusesource.hawtjni.generator.model.JNIClass;
import org.fusesource.hawtjni.generator.model.JNIMethod;
/**
*
* @author Hiram Chirino
*/
public abstract class CleanupClass extends JNIGenerator {
String classSourcePath;
String[] sourcePath;
String classSource;
HashMap files;
int usedCount, unusedCount;
String[] getArgNames(JNIMethod method) {
int n_args = method.getParameters().size();
if (n_args == 0)
return new String[0];
String name = method.getName();
String params = "";
int index = 0;
while (true) {
index = classSource.indexOf(name, index + 1);
if (!Character.isWhitespace(classSource.charAt(index - 1)))
continue;
if (index == -1)
return null;
int parantesesStart = classSource.indexOf("(", index);
if (classSource.substring(index + name.length(), parantesesStart).trim().length() == 0) {
int parantesesEnd = classSource.indexOf(")", parantesesStart);
params = classSource.substring(parantesesStart + 1, parantesesEnd);
break;
}
}
String[] names = new String[n_args];
StringTokenizer tk = new StringTokenizer(params, ",");
for (int i = 0; i < names.length; i++) {
String s = tk.nextToken().trim();
StringTokenizer tk1 = new StringTokenizer(s, " ");
String s1 = null;
while (tk1.hasMoreTokens()) {
s1 = tk1.nextToken();
}
names[i] = s1.trim();
}
return names;
}
void loadClassSource() {
if (classSourcePath == null)
return;
File f = new File(classSourcePath);
classSource = loadFile(f);
}
void loadFiles() {
// BAD - holds on to a lot of memory
if (sourcePath == null)
return;
files = new HashMap();
for (int i = 0; i < sourcePath.length; i++) {
File file = new File(sourcePath[i]);
if (file.exists()) {
if (!file.isDirectory()) {
if (file.getAbsolutePath().endsWith(".java")) {
files.put(file, loadFile(file));
}
} else {
loadDirectory(file);
}
}
}
}
String loadFile(File file) {
try {
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
StringBuffer str = new StringBuffer();
char[] buffer = new char[1024];
int read;
while ((read = br.read(buffer)) != -1) {
str.append(buffer, 0, read);
}
fr.close();
return str.toString();
} catch (IOException e) {
e.printStackTrace(System.out);
}
return "";
}
void loadDirectory(File file) {
String[] entries = file.list();
for (int i = 0; i < entries.length; i++) {
String entry = entries[i];
File f = new File(file, entry);
if (!f.isDirectory()) {
if (f.getAbsolutePath().endsWith(".java")) {
files.put(f, loadFile(f));
}
} else {
loadDirectory(f);
}
}
}
public void generate(JNIClass clazz) {
loadFiles();
loadClassSource();
}
public void setSourcePath(String[] sourcePath) {
this.sourcePath = sourcePath;
files = null;
}
public void setClassSourcePath(String classSourcePath) {
this.classSourcePath = classSourcePath;
}
}
CleanupConstants.java 0000775 0000000 0000000 00000007376 13744017712 0037003 0 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-generator/src/main/java/org/fusesource/hawtjni/generator /*******************************************************************************
* Copyright (C) 2009-2011 FuseSource Corp.
* Copyright (c) 2004, 2007 IBM Corporation and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*******************************************************************************/
package org.fusesource.hawtjni.generator;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.List;
import org.fusesource.hawtjni.generator.model.JNIClass;
import org.fusesource.hawtjni.generator.model.JNIField;
import org.fusesource.hawtjni.generator.model.ReflectClass;
/**
*
* @author Hiram Chirino
*/
public class CleanupConstants extends CleanupClass {
String getFieldValue(JNIField field) {
String name = field.getName();
int index = 0;
while (true) {
index = classSource.indexOf(name, index + 1);
if (index == -1)
return null;
int equalsIndex = classSource.indexOf("=", index);
if (classSource.substring(index + name.length(), equalsIndex).trim().length() == 0) {
int semiIndex = classSource.indexOf(";", equalsIndex);
return classSource.substring(equalsIndex + 1, semiIndex).trim();
}
}
}
public void generate(JNIClass clazz) {
unusedCount = usedCount = 0;
super.generate(clazz);
List fields = clazz.getDeclaredFields();
generate(fields);
output("used=" + usedCount + " unused=" + unusedCount + " total=" + (unusedCount + usedCount));
}
public void generate(List fields) {
sortFields(fields);
for (JNIField field : fields) {
if ((field.getModifiers() & Modifier.FINAL) == 0)
continue;
generate(field);
}
}
public void generate(JNIField field) {
String name = field.getName();
Collection values = files.values();
for (String str : values) {
if (str.indexOf(name) != -1) {
int modifiers = field.getModifiers();
String modifiersStr = Modifier.toString(modifiers);
output("\t");
output(modifiersStr);
if (modifiersStr.length() > 0)
output(" ");
output(field.getType().getTypeSignature3(false));
output(" ");
output(field.getName());
output(" = ");
output(getFieldValue(field));
outputln(";");
usedCount++;
return;
}
}
unusedCount++;
// output("NOT USED=" + field.toString() + " \n");
}
public static void main(String[] args) {
if (args.length < 3) {
System.out.println("Usage: java CleanupConstants ");
return;
}
try {
CleanupConstants gen = new CleanupConstants();
String clazzName = args[0];
String classSource = args[1];
String[] sourcePath = new String[args.length - 2];
System.arraycopy(args, 2, sourcePath, 0, sourcePath.length);
Class> clazz = Class.forName(clazzName);
gen.setSourcePath(sourcePath);
gen.setClassSourcePath(classSource);
gen.generate(new ReflectClass(clazz));
} catch (Exception e) {
System.out.println("Problem");
e.printStackTrace(System.out);
}
}
}
CleanupNatives.java 0000775 0000000 0000000 00000007512 13744017712 0036430 0 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-generator/src/main/java/org/fusesource/hawtjni/generator /*******************************************************************************
* Copyright (C) 2009-2011 FuseSource Corp.
* Copyright (c) 2004, 2007 IBM Corporation and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*******************************************************************************/
package org.fusesource.hawtjni.generator;
import java.util.*;
import java.io.File;
import java.lang.reflect.*;
import org.fusesource.hawtjni.generator.model.JNIClass;
import org.fusesource.hawtjni.generator.model.JNIMethod;
import org.fusesource.hawtjni.generator.model.ReflectClass;
/**
*
* @author Hiram Chirino
*/
public class CleanupNatives extends CleanupClass {
public CleanupNatives() {
}
public void generate(JNIClass clazz) {
unusedCount = usedCount = 0;
super.generate(clazz);
List methods = clazz.getDeclaredMethods();
generate(methods);
output("used=" + usedCount + " unused=" + unusedCount + " total=" + (unusedCount + usedCount));
}
public void generate(List methods) {
sortMethods(methods);
for (JNIMethod method : methods) {
if ((method.getModifiers() & Modifier.NATIVE) == 0)
continue;
generate(method);
}
}
public void generate(JNIMethod method) {
String name = method.getName();
Set keys = files.keySet();
for (File key : keys) {
String str = (String) files.get(key);
if (str.indexOf(name) != -1) {
// int modifiers = method.getModifiers();
// Class clazz = method.getDeclaringClass();
// String modifiersStr = Modifier.toString(modifiers);
// output(modifiersStr);
// if (modifiersStr.length() > 0) output(" ");
// output(getTypeSignature3(method.getReturnType()));
// output(" " );
// output(method.getName());
// output("(");
// Class[] paramTypes = method.getParameterTypes();
// String[] paramNames = getArgNames(method);
// for (int i = 0; i < paramTypes.length; i++) {
// Class paramType = paramTypes[i];
// if (i != 0) output(", ");
// String sig = getTypeSignature3(paramType);
// if (clazz.getPackage().equals(paramType.getPackage())) sig =
// getClassName(paramType);
// output(sig);
// output(" ");
// output(paramNames[i]);
// }
// outputln(");");
usedCount++;
return;
}
}
unusedCount++;
output("NOT USED=" + method.toString() + "\n");
}
public static void main(String[] args) {
if (args.length < 2) {
System.out.println("Usage: java CleanupNatives ");
return;
}
try {
CleanupNatives gen = new CleanupNatives();
String clazzName = args[0];
String classSource = args[1];
String[] sourcePath = new String[args.length - 2];
System.arraycopy(args, 2, sourcePath, 0, sourcePath.length);
Class> clazz = Class.forName(clazzName);
gen.setSourcePath(sourcePath);
gen.setClassSourcePath(classSource);
gen.generate(new ReflectClass(clazz));
} catch (Exception e) {
System.out.println("Problem");
e.printStackTrace(System.out);
}
}
}
ConstantsGenerator.java 0000775 0000000 0000000 00000004700 13744017712 0037326 0 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-generator/src/main/java/org/fusesource/hawtjni/generator /*******************************************************************************
* Copyright (C) 2009-2011 FuseSource Corp.
* Copyright (c) 2004 IBM Corporation and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*******************************************************************************/
package org.fusesource.hawtjni.generator;
import java.lang.reflect.Modifier;
import java.util.List;
import org.fusesource.hawtjni.generator.model.JNIClass;
import org.fusesource.hawtjni.generator.model.JNIField;
import org.fusesource.hawtjni.generator.model.JNIType;
import org.fusesource.hawtjni.generator.model.ReflectClass;
/**
*
* @author Hiram Chirino
*/
public class ConstantsGenerator extends JNIGenerator {
public void generate(JNIClass clazz) {
List fields = clazz.getDeclaredFields();
generate(fields);
}
public void generate(List fields) {
sortFields(fields);
outputln("int main() {");
for (JNIField field : fields) {
if ((field.getModifiers() & Modifier.FINAL) == 0)
continue;
generate(field);
}
outputln("}");
}
public void generate(JNIField field) {
JNIType type = field.getType();
output("\tprintf(\"public static final ");
output(field.getType().getTypeSignature3(false));
output(" ");
output(field.getName());
output(" = ");
if (type.isType("java.lang.String") || type.isType("[B"))
output("\"%s\"");
else
output("0x%x");
output(";\\n\", ");
output(field.getName());
outputln(");");
}
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Usage: java ConstantsGenerator ");
return;
}
try {
ConstantsGenerator gen = new ConstantsGenerator();
for (String clazzName : args) {
Class> clazz = Class.forName(clazzName);
gen.generate(new ReflectClass(clazz));
}
} catch (Exception e) {
System.out.println("Problem");
e.printStackTrace(System.out);
}
}
}
DOMWriter.java 0000775 0000000 0000000 00000007641 13744017712 0035326 0 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-generator/src/main/java/org/fusesource/hawtjni/generator /*******************************************************************************
* Copyright (C) 2009-2011 FuseSource Corp.
* Copyright (c) 2008 IBM Corporation and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*******************************************************************************/
package org.fusesource.hawtjni.generator;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Comparator;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
*
* @author Hiram Chirino
*/
public class DOMWriter {
static String ENCONDING = "UTF8";
PrintStream out;
String[] attributeFilter;
String nodeFilter;
public DOMWriter(PrintStream out) {
this.out = new PrintStream(out);
}
String nodeName(Node node) {
// TODO use getLocalName()?
return node.getNodeName();
}
boolean filter(Attr attr) {
if (attributeFilter == null) return false;
String name = attr.getNodeName();
for (int i = 0; i < attributeFilter.length; i++) {
if (name.matches(attributeFilter[i])) return false;
}
return true;
}
void print(String str) {
out.print(str);
}
void println() {
out.println();
}
public void print(Node node) {
print(node, 0);
}
public void print(Node node, int level) {
if (node == null)
return;
int type = node.getNodeType();
switch (type) {
case Node.DOCUMENT_NODE: {
print("");
println();
print(((Document) node).getDocumentElement());
break;
}
case Node.ELEMENT_NODE: {
Attr attrs[] = sort(node.getAttributes());
String name = nodeName(node);
boolean gen = name.equals("arg") || name.equals("retval");
for (int i = 0; i < attrs.length && !gen; i++) {
Attr attr = attrs[i];
if (nodeName(attr).startsWith(nodeFilter)) gen = true;
}
if (!gen) break;
for (int i = 0; i < level; i++) print("\t");
print("<");
print(name);
for (int i = 0; i < attrs.length; i++) {
Attr attr = attrs[i];
if (filter(attr)) continue;
print(" ");
print(nodeName(attr));
print("=\"");
print(normalize(attr.getNodeValue()));
print("\"");
}
print(">");
NodeList children = node.getChildNodes();
int count = 0;
if (children != null) {
int len = children.getLength();
for (int i = 0; i < len; i++) {
if (children.item(i).getNodeType() == Node.ELEMENT_NODE) count++;
}
if (count > 0) println();
for (int i = 0; i < len; i++) {
print(children.item(i), level + 1);
}
if (count > 0) {
for (int i = 0; i < level; i++) print("\t");
}
}
print("");
print(nodeName(node));
print(">");
println();
break;
}
}
out.flush();
}
Attr[] sort(NamedNodeMap attrs) {
if (attrs == null)
return new Attr[0];
Attr result[] = new Attr[attrs.getLength()];
for (int i = 0; i < result.length; i++) {
result[i] = (Attr) attrs.item(i);
}
Arrays.sort(result, new Comparator() {
public int compare(Node arg0, Node arg1) {
return nodeName(arg0).compareTo(nodeName(arg1));
}
});
return result;
}
String normalize(String s) {
if (s == null) return "";
StringBuffer str = new StringBuffer();
for (int i = 0, length = s.length(); i < length; i++) {
char ch = s.charAt(i);
switch (ch) {
case '"': str.append("\""); break;
case '\r':
case '\n':
// FALL THROUGH
default: str.append(ch);
}
}
return str.toString();
}
public void setNodeFilter(String filter) {
nodeFilter = filter;
}
public void setAttributeFilter(String[] filter) {
attributeFilter = filter;
}
} HawtJNI.java 0000775 0000000 0000000 00000041237 13744017712 0034755 0 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-generator/src/main/java/org/fusesource/hawtjni/generator /*******************************************************************************
* Copyright (C) 2009-2011 FuseSource Corp.
* Copyright (c) 2004, 2007 IBM Corporation and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*******************************************************************************/
package org.fusesource.hawtjni.generator;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.xbean.finder.ClassFinder;
import org.apache.xbean.finder.UrlSet;
import org.fusesource.hawtjni.generator.model.JNIClass;
import org.fusesource.hawtjni.generator.model.ReflectClass;
import org.fusesource.hawtjni.generator.util.FileSupport;
import org.fusesource.hawtjni.runtime.ClassFlag;
import org.fusesource.hawtjni.runtime.JniClass;
import static org.fusesource.hawtjni.generator.util.OptionBuilder.*;
/**
*
* @author Hiram Chirino
*/
public class HawtJNI {
public static final String END_YEAR_TAG = "%END_YEAR%";
private ProgressMonitor progress;
private File nativeOutput = new File(".");
// private File javaOutputDir = new File(".");
private List classpaths = new ArrayList();
private List packages = new ArrayList();
private String name = "hawtjni_native";
private String copyright = "";
private boolean callbacks = true;
///////////////////////////////////////////////////////////////////
// Command line entry point
///////////////////////////////////////////////////////////////////
public static void main(String[] args) {
String jv = System.getProperty("java.version").substring(0, 3);
if (jv.compareTo("1.5") < 0) {
System.err.println("This application requires jdk 1.5 or higher to run, the current java version is " + System.getProperty("java.version"));
System.exit(-1);
return;
}
HawtJNI app = new HawtJNI();
System.exit(app.execute(args));
}
///////////////////////////////////////////////////////////////////
// Entry point for an embedded users who want to call us with
// via command line arguments.
///////////////////////////////////////////////////////////////////
public int execute(String[] args) {
CommandLine cli = null;
try {
cli = new PosixParser().parse(createOptions(), args, true);
} catch (ParseException e) {
System.err.println( "Unable to parse command line options: " + e.getMessage() );
displayHelp();
return 1;
}
if( cli.hasOption("h") ) {
displayHelp();
return 0;
}
if( cli.hasOption("v") ) {
progress = new ProgressMonitor() {
public void step() {
}
public void setTotal(int total) {
}
public void setMessage(String message) {
System.out.println(message);
}
};
}
name = cli.getOptionValue("n", "hawtjni_native");
nativeOutput = new File(cli.getOptionValue("o", "."));
// javaOutputDir = new File(cli.getOptionValue("j", "."));
String[] values = cli.getOptionValues("p");
if( values!=null ) {
packages = Arrays.asList(values);
}
values = cli.getArgs();
if( values!=null ) {
classpaths = Arrays.asList(values);
}
try {
if( classpaths.isEmpty() ) {
throw new UsageException("No classpath supplied.");
}
generate();
} catch (UsageException e) {
System.err.println("Invalid usage: "+e.getMessage());
displayHelp();
return 1;
} catch (Throwable e) {
System.out.flush();
System.err.println("Unexpected failure:");
e.printStackTrace();
Set exceptions = new HashSet();
exceptions.add(e);
for (int i = 0; i < 10; i++) {
e = e.getCause();
if (e != null && exceptions.add(e)) {
System.err.println("Reason: " + e);
e.printStackTrace();
} else {
break;
}
}
return 2;
}
return 0;
}
///////////////////////////////////////////////////////////////////
// Entry point for an embedded users who want use us like a pojo
///////////////////////////////////////////////////////////////////
public ProgressMonitor getProgress() {
return progress;
}
public void setProgress(ProgressMonitor progress) {
this.progress = progress;
}
public File getNativeOutput() {
return nativeOutput;
}
public void setNativeOutput(File nativeOutput) {
this.nativeOutput = nativeOutput;
}
public List getClasspaths() {
return classpaths;
}
public void setClasspaths(List classpaths) {
this.classpaths = classpaths;
}
public List getPackages() {
return packages;
}
public void setPackages(List packages) {
this.packages = packages;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setCopyright(String copyright) {
this.copyright = copyright;
}
public boolean isCallbacks() {
return callbacks;
}
public void setCallbacks(boolean enableCallbacks) {
this.callbacks = enableCallbacks;
}
public void generate() throws UsageException, IOException {
progress("Analyzing classes...");
ArrayList natives = new ArrayList();
ArrayList structs = new ArrayList();
findClasses(natives, structs);
if( natives.isEmpty() && structs.isEmpty() ) {
throw new RuntimeException("No @JniClass or @JniStruct annotated classes found.");
}
if (progress != null) {
int nativeCount = 0;
for (JNIClass clazz : natives) {
nativeCount += clazz.getNativeMethods().size();
}
int total = nativeCount * 4;
total += natives.size() * (3);
total += structs.size() * 2;
progress.setTotal(total);
}
File file;
nativeOutput.mkdirs();
progress("Generating...");
file = nativeFile(".c");
generate(new NativesGenerator(), natives, file);
file = nativeFile("_stats.h");
generate(new StatsGenerator(true), natives, file);
file = nativeFile("_stats.c");
generate(new StatsGenerator(false), natives, file);
file = nativeFile("_structs.h");
generate(new StructsGenerator(true), structs, file);
file = nativeFile("_structs.c");
generate(new StructsGenerator(false), structs, file);
file = new File(nativeOutput, "hawtjni.h");
generateFromResource("hawtjni.h", file);
file = new File(nativeOutput, "hawtjni.c");
generateFromResource("hawtjni.c", file);
file = new File(nativeOutput, "hawtjni-callback.c");
if( callbacks ) {
generateFromResource("hawtjni-callback.c", file);
} else {
file.delete();
}
file = new File(nativeOutput, "windows");
file.mkdirs();
file = new File(file, "stdint.h");
generateFromResource("windows/stdint.h", file);
progress("Done.");
}
///////////////////////////////////////////////////////////////////
// Helper methods
///////////////////////////////////////////////////////////////////
private void findClasses(ArrayList jni, ArrayList structs) throws UsageException {
ArrayList urls = new ArrayList();
for (String classpath : classpaths) {
String[] fileNames = classpath.replace(';', ':').split(":");
for (String fileName : fileNames) {
try {
File file = new File(fileName);
if( file.isDirectory() ) {
urls.add(new URL(url(file)+"/"));
} else {
urls.add(new URL(url(file)));
}
} catch (Exception e) {
throw new UsageException("Invalid class path. Not a valid file: "+fileName);
}
}
}
LinkedHashSet> jniClasses = new LinkedHashSet>();
try {
URLClassLoader classLoader = new URLClassLoader(array(URL.class, urls), JniClass.class.getClassLoader());
UrlSet urlSet = new UrlSet(classLoader);
urlSet = urlSet.excludeJavaHome();
ClassFinder finder = new ClassFinder(classLoader, urlSet.getUrls());
collectMatchingClasses(finder, JniClass.class, jniClasses);
} catch (Exception e) {
throw new RuntimeException(e);
}
for (Class> clazz : jniClasses) {
ReflectClass rc = new ReflectClass(clazz);
if( rc.getFlag(ClassFlag.STRUCT) ) {
structs.add(rc);
}
if( !rc.getNativeMethods().isEmpty() ) {
jni.add(rc);
}
}
}
static private Options createOptions() {
Options options = new Options();
options.addOption("h", "help", false, "Display help information");
options.addOption("v", "verbose", false, "Verbose generation");
options.addOption("o", "offline", false, "Work offline");
options.addOption(ob()
.id("n")
.name("name")
.arg("value")
.description("The base name of the library, used to determine generated file names. Defaults to 'hawtjni_native'.").op());
options.addOption(ob()
.id("o")
.name("native-output")
.arg("dir")
.description("Directory where generated native source code will be stored. Defaults to the current directory.").op());
// options.addOption(ob()
// .id("j")
// .name("java-output")
// .arg("dir")
// .description("Directory where generated native source code will be stored. Defaults to the current directory.").op());
options.addOption(ob()
.id("p")
.name("package")
.arg("package")
.description("Restrict looking for JNI classes to the specified package.").op());
return options;
}
private void displayHelp() {
System.err.flush();
String app = System.getProperty("hawtjni.application");
if( app == null ) {
try {
URL location = getClass().getProtectionDomain().getCodeSource().getLocation();
String[] split = location.toString().split("/");
if( split[split.length-1].endsWith(".jar") ) {
app = split[split.length-1];
}
} catch (Throwable e) {
}
if( app == null ) {
app = getClass().getSimpleName();
}
}
// The commented out line is 80 chars long. We have it here as a visual reference
// p(" ");
p();
p("Usage: "+ app +" [options] ");
p();
p("Description:");
p();
pw(" "+app+" is a code generator that produces the JNI code needed to implement java native methods.", 2);
p();
p("Options:");
p();
PrintWriter out = new PrintWriter(System.out);
HelpFormatter formatter = new HelpFormatter();
formatter.printOptions(out, 78, createOptions(), 2, 2);
out.flush();
p();
p("Examples:");
p();
pw(" "+app+" -o build foo.jar bar.jar ", 2);
pw(" "+app+" -o build foo.jar:bar.jar ", 2);
pw(" "+app+" -o build -p org.mypackage foo.jar;bar.jar ", 2);
p();
}
private void p() {
System.out.println();
}
private void p(String s) {
System.out.println(s);
}
private void pw(String message, int indent) {
PrintWriter out = new PrintWriter(System.out);
HelpFormatter formatter = new HelpFormatter();
formatter.printWrapped(out, 78, indent, message);
out.flush();
}
@SuppressWarnings("unchecked")
private void collectMatchingClasses(ClassFinder finder, Class annotation, LinkedHashSet> collector) {
List> annotated = finder.findAnnotatedClasses(annotation);
for (Class> clazz : annotated) {
if( packages.isEmpty() ) {
collector.add(clazz);
} else {
if( packages.contains(clazz.getPackage().getName()) ) {
collector.add(clazz);
}
}
}
}
private void progress(String message) {
if (progress != null) {
progress.setMessage(message);
}
}
private void generate(JNIGenerator gen, ArrayList classes, File target) throws IOException {
gen.setOutputName(name);
gen.setClasses(classes);
gen.setCopyright(getCopyright());
gen.setProgressMonitor(progress);
ByteArrayOutputStream out = new ByteArrayOutputStream();
gen.setOutput(new PrintStream(out));
gen.generate();
if (out.size() > 0) {
if( target.getName().endsWith(".c") && gen.isCPP ) {
target = new File(target.getParentFile(), target.getName()+"pp");
}
if( FileSupport.write(out.toByteArray(), target) ) {
progress("Wrote: "+target);
}
}
}
private void generateFromResource(String resource, File target) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream is = getClass().getClassLoader().getResourceAsStream(resource);
FileSupport.copy(is, out);
String content = new String(out.toByteArray(), "UTF-8");
String[] parts = content.split(Pattern.quote("/* == HEADER-SNIP-LOCATION == */"));
if( parts.length==2 ) {
content = parts[1];
}
out.reset();
PrintStream ps = new PrintStream(out);
ps.print(JNIGenerator.fixDelimiter(getCopyright()));
ps.print(JNIGenerator.fixDelimiter(content));
ps.close();
if( FileSupport.write(out.toByteArray(), target) ) {
progress("Wrote: "+target);
}
}
@SuppressWarnings("unchecked")
private T[] array(Class type, ArrayList urls) {
return urls.toArray((T[])Array.newInstance(type, urls.size()));
}
private String url(File file) throws IOException {
return "file:"+(file.getCanonicalPath().replace(" ", "%20"));
}
@SuppressWarnings("serial")
public static class UsageException extends Exception {
public UsageException(String message) {
super(message);
}
}
private File nativeFile(String suffix) {
return new File(nativeOutput, name+suffix);
}
public String getCopyright() {
if (copyright == null)
return "";
int index = copyright.indexOf(END_YEAR_TAG);
if (index != -1) {
String temp = copyright.substring(0, index);
temp += Calendar.getInstance().get(Calendar.YEAR);
temp += copyright.substring(index + END_YEAR_TAG.length());
copyright = temp;
}
return copyright;
}
}
JNIGenerator.java 0000775 0000000 0000000 00000015415 13744017712 0035777 0 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-generator/src/main/java/org/fusesource/hawtjni/generator /*******************************************************************************
* Copyright (C) 2009-2011 FuseSource Corp.
* Copyright (c) 2004, 2006 IBM Corporation and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*******************************************************************************/
package org.fusesource.hawtjni.generator;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.fusesource.hawtjni.generator.model.JNIClass;
import org.fusesource.hawtjni.generator.model.JNIField;
import org.fusesource.hawtjni.generator.model.JNIMethod;
import org.fusesource.hawtjni.generator.model.JNIType;
import org.fusesource.hawtjni.runtime.ClassFlag;
/**
*
* @author Hiram Chirino
*/
public abstract class JNIGenerator {
static final String delimiter = System.getProperty("line.separator");
static final String JNI64 = "JNI64";
ArrayList classes;
String copyright = "";
boolean isCPP;
PrintStream output = System.out;
ProgressMonitor progress;
private String outputName;
static String fixDelimiter(String str) {
if (delimiter.equals("\n")) {
return str;
}
return str.replaceAll("\n", delimiter);
}
static String getFunctionName(JNIMethod method) {
return getFunctionName(method, method.getParameterTypes());
}
static String getFunctionName(JNIMethod method, List paramTypes) {
if ((method.getModifiers() & Modifier.NATIVE) == 0)
return method.getName();
String function = toC(method.getName());
if (!method.isNativeUnique()) {
StringBuffer buffer = new StringBuffer();
buffer.append(function);
buffer.append("__");
for (JNIType paramType : paramTypes) {
buffer.append(toC(paramType.getTypeSignature(false)));
}
return buffer.toString();
}
return function;
}
static String loadFile(String file) {
try {
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
StringBuffer str = new StringBuffer();
char[] buffer = new char[1024];
int read;
while ((read = br.read(buffer)) != -1) {
str.append(buffer, 0, read);
}
fr.close();
return str.toString();
} catch (IOException e) {
throw new RuntimeException("File not found:" + file, e);
}
}
public static void sortMethods(List methods) {
Collections.sort(methods, new Comparator() {
public int compare(JNIMethod mth1, JNIMethod mth2) {
int result = mth1.getName().compareTo(mth2.getName());
return result != 0 ? result : getFunctionName(mth1).compareTo(getFunctionName(mth2));
}
});
}
static void sortFields(List fields) {
Collections.sort(fields, new Comparator() {
public int compare(JNIField a, JNIField b) {
return a.getName().compareTo(b.getName());
}
});
}
static void sortClasses(ArrayList classes) {
Collections.sort(classes, new Comparator() {
public int compare(JNIClass a, JNIClass b) {
return a.getName().compareTo(b.getName());
}
});
}
static String toC(String str) {
int length = str.length();
StringBuffer buffer = new StringBuffer(length * 2);
for (int i = 0; i < length; i++) {
char c = str.charAt(i);
switch (c) {
case '_':
buffer.append("_1");
break;
case ';':
buffer.append("_2");
break;
case '[':
buffer.append("_3");
break;
case '.':
buffer.append("_");
break;
case '/':
buffer.append("_");
break;
default:
if(
('a' <= c && c <= 'z')
|| ('A' <= c && c <= 'Z')
|| ('0' <= c && c <= '9')
) {
buffer.append(c);
} else {
buffer.append(String.format("_0%04x",(int)c));
}
}
}
return buffer.toString();
}
public abstract void generate(JNIClass clazz);
public void generateCopyright() {
}
public void generateIncludes() {
}
public void generate() {
if (classes == null)
return;
generateCopyright();
generateIncludes();
sortClasses(classes);
for (JNIClass clazz : classes) {
if (clazz.getFlag(ClassFlag.CPP)) {
isCPP = true;
break;
}
}
generate(classes);
output.flush();
}
protected void generate(ArrayList classes) {
for (JNIClass clazz : classes) {
if (clazz.getGenerate())
generate(clazz);
if (progress != null)
progress.step();
}
}
public boolean getCPP() {
return isCPP;
}
public String getDelimiter() {
return delimiter;
}
public PrintStream getOutput() {
return output;
}
public String getOutputName() {
return outputName;
}
public void setOutputName(String outputName) {
this.outputName = outputName;
}
public ProgressMonitor getProgressMonitor() {
return progress;
}
public void output(String str) {
output.print(str);
}
public void outputln() {
output(getDelimiter());
}
public void outputln(String str) {
output(str);
output(getDelimiter());
}
public void setClasses(ArrayList classes) {
this.classes = classes;
}
public void setOutput(PrintStream output) {
this.output = output;
}
public void setProgressMonitor(ProgressMonitor progress) {
this.progress = progress;
}
public String getCopyright() {
return copyright;
}
public void setCopyright(String copyright) {
this.copyright = copyright;
}
}
LockGenerator.java 0000775 0000000 0000000 00000013074 13744017712 0036246 0 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-generator/src/main/java/org/fusesource/hawtjni/generator /*******************************************************************************
* Copyright (C) 2009-2011 FuseSource Corp.
* Copyright (c) 2004, 2007 IBM Corporation and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*******************************************************************************/
package org.fusesource.hawtjni.generator;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.fusesource.hawtjni.generator.model.JNIClass;
import org.fusesource.hawtjni.generator.model.JNIMethod;
import org.fusesource.hawtjni.generator.model.JNIType;
import org.fusesource.hawtjni.generator.model.ReflectClass;
import org.fusesource.hawtjni.generator.model.ReflectType;
/**
*
* @author Hiram Chirino
*/
public class LockGenerator extends CleanupClass {
public LockGenerator() {
}
String getParams(JNIMethod method) {
int n_args = method.getParameters().size();
if (n_args == 0)
return "";
String name = method.getName();
String params = "";
int index = 0;
while (true) {
index = classSource.indexOf(name, index + 1);
if (!Character.isWhitespace(classSource.charAt(index - 1)))
continue;
if (index == -1)
return null;
int parantesesStart = classSource.indexOf("(", index);
if (classSource.substring(index + name.length(), parantesesStart).trim().length() == 0) {
int parantesesEnd = classSource.indexOf(")", parantesesStart);
params = classSource.substring(parantesesStart + 1, parantesesEnd);
break;
}
}
return params;
}
String getReturn(JNIMethod method) {
JNIType returnType = method.getReturnType32();
if (!returnType.isType("int"))
return returnType.getTypeSignature3(false);
String modifierStr = Modifier.toString(method.getModifiers());
String name = method.getName();
Pattern p = Pattern.compile(modifierStr + ".*" + name + ".*(.*)");
Matcher m = p.matcher(classSource);
if (m.find()) {
String methodStr = classSource.substring(m.start(), m.end());
int index = methodStr.indexOf("/*long*/");
if (index != -1 && index < methodStr.indexOf(name)) {
return new ReflectType(Integer.TYPE).getTypeSignature3(false) + " /*long*/";
}
}
return new ReflectType(Integer.TYPE).getTypeSignature3(false);
}
public void generate(JNIClass clazz) {
super.generate(clazz);
generate(clazz.getDeclaredMethods());
}
public void generate(List methods) {
sortMethods(methods);
for (JNIMethod method : methods) {
if ((method.getModifiers() & Modifier.NATIVE) == 0)
continue;
generate(method);
}
}
public void generate(JNIMethod method) {
int modifiers = method.getModifiers();
boolean lock = (modifiers & Modifier.SYNCHRONIZED) != 0;
String returnStr = getReturn(method);
String paramsStr = getParams(method);
if (lock) {
String modifiersStr = Modifier.toString(modifiers & ~Modifier.SYNCHRONIZED);
output(modifiersStr);
if (modifiersStr.length() > 0)
output(" ");
output(returnStr);
output(" _");
output(method.getName());
output("(");
output(paramsStr);
outputln(");");
}
String modifiersStr = Modifier.toString(modifiers & ~(Modifier.SYNCHRONIZED | (lock ? Modifier.NATIVE : 0)));
output(modifiersStr);
if (modifiersStr.length() > 0)
output(" ");
output(returnStr);
output(" ");
output(method.getName());
output("(");
output(paramsStr);
output(")");
if (lock) {
outputln(" {");
outputln("\tlock.lock();");
outputln("\ttry {");
output("\t\t");
if (!method.getReturnType32().isType("void")) {
output("return ");
}
output("_");
output(method.getName());
output("(");
String[] paramNames = getArgNames(method);
for (int i = 0; i < paramNames.length; i++) {
if (i != 0)
output(", ");
output(paramNames[i]);
}
outputln(");");
outputln("\t} finally {");
outputln("\t\tlock.unlock();");
outputln("\t}");
outputln("}");
} else {
outputln(";");
}
}
public static void main(String[] args) {
if (args.length < 2) {
System.out.println("Usage: java LockGenerator ");
return;
}
try {
LockGenerator gen = new LockGenerator();
String clazzName = args[0];
String classSource = args[1];
Class> clazz = Class.forName(clazzName);
gen.setClassSourcePath(classSource);
gen.generate(new ReflectClass(clazz));
} catch (Exception e) {
System.out.println("Problem");
e.printStackTrace(System.out);
}
}
}
MacGenerator.java 0000775 0000000 0000000 00000207625 13744017712 0036065 0 ustar 00root root 0000000 0000000 hawtjni-hawtjni-project-1.18/hawtjni-generator/src/main/java/org/fusesource/hawtjni/generator /*******************************************************************************
* Copyright (C) 2009-2011 FuseSource Corp.
* Copyright (c) 2008 IBM Corporation and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*******************************************************************************/
package org.fusesource.hawtjni.generator;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import javax.xml.parsers.DocumentBuilderFactory;
import org.fusesource.hawtjni.generator.HawtJNI.UsageException;
import org.fusesource.hawtjni.generator.util.FileSupport;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
/**
*
* @author Hiram Chirino
*/
public class MacGenerator {
String[] xmls;
Document[] documents;
String outputDir, mainClassName;
String delimiter = System.getProperty("line.separator");
PrintStream out;
public MacGenerator() {
}
static void list(File path, ArrayList list) {
if (path == null)
return;
File[] frameworks = path.listFiles();
if (frameworks == null)
return;
for (int i = 0; i < frameworks.length; i++) {
File file = frameworks[i];
String name = file.getName();
int index = name.lastIndexOf(".");
if (index != -1) {
String xml = file.getAbsolutePath() + "/Resources/BridgeSupport/" + name.substring(0, index) + "Full.bridgesupport";
if (new File(xml).exists()) {
list.add(xml);
}
}
}
}
int getLevel(Node node) {
int level = 0;
while (node != null) {
level++;
node = node.getParentNode();
}
return level;
}
void merge(Document document, Document extraDocument) {
if (extraDocument == null)
return;
/* Build a lookup table for extraDocument */
HashMap extras = new HashMap();
buildLookup(extraDocument, extras);
/*
* Merge attributes on existing elements building a lookup table for
* document
*/
HashMap lookup = new HashMap();
merge(document, extras, lookup);
/*
* Merge new elements. Extras at this point contains only elements that
* were not found in the document.
*/
ArrayList sortedNodes = Collections.list(Collections.enumeration(extras.values()));
Collections.sort(sortedNodes, new Comparator() {
public int compare(Node arg0, Node arg1) {
int compare = getLevel(arg0) - getLevel(arg1);
if (compare == 0) {
return (arg0).getNodeName().compareTo((arg1).getNodeName());
}
return compare;
}
});
String delimiter = System.getProperty("line.separator");
for (Iterator iterator = sortedNodes.iterator(); iterator.hasNext();) {
Node node = iterator.next();
String name = node.getNodeName();
if ("arg".equals(name) || "retval".equals(name)) {
if (!sortedNodes.contains(node.getParentNode()))
continue;
}
Node parent = lookup.get(getKey(node.getParentNode()));
Element element = document.createElement(node.getNodeName());
String text = parent.getChildNodes().getLength() == 0 ? delimiter : "";
for (int i = 0, level = getLevel(parent) - 1; i < level; i++) {
text += " ";
}
parent.appendChild(document.createTextNode(text));
parent.appendChild(element);
parent.appendChild(document.createTextNode(delimiter));
NamedNodeMap attributes = node.getAttributes();
for (int j = 0, length = attributes.getLength(); j < length; j++) {
Node attr = (Node) attributes.item(j);
element.setAttribute(attr.getNodeName(), attr.getNodeValue());
}
lookup.put(getKey(element), element);
}
}
public void generate(ProgressMonitor progress) throws UsageException {
if (progress != null) {
progress.setTotal(3);
progress.setMessage("extra attributes...");
}
generateExtraAttributes();
if (progress != null) {
progress.step();
progress.setMessage(mainClassName);
}
generateMainClass();
if (progress != null) {
progress.step();
progress.setMessage("classes...");
}
generateClasses();
if (progress != null) {
progress.step();
progress.setMessage("Done.");
}
}
String fixDelimiter(String str) {
if (delimiter.equals("\n"))
return str;
int index = 0, length = str.length();
StringBuffer buffer = new StringBuffer();
while (index != -1) {
int start = index;
index = str.indexOf('\n', start);
if (index == -1) {
buffer.append(str.substring(start, length));
} else {
buffer.append(str.substring(start, index));
buffer.append(delimiter);
index++;
}
}
return buffer.toString();
}
void generateMethods(String className, ArrayList methods) {
for (Node method : methods) {
NamedNodeMap mthAttributes = method.getAttributes();
String sel = mthAttributes.getNamedItem("selector").getNodeValue();
out("public ");
boolean isStatic = isStatic(method);
if (isStatic)
out("static ");
Node returnNode = getReturnNode(method.getChildNodes());
if (getType(returnNode).equals("void"))
returnNode = null;
String returnType = "", returnType64 = "";
if (returnNode != null) {
String type = returnType = getJavaType(returnNode), type64 = returnType64 = getJavaType64(returnNode);
out(type);
if (!type.equals(type64)) {
out(" /*");
out(type64);
out("*/");
}
out(" ");
} else {
out("void ");
}
String methodName = sel;
if (isUnique(method, methods)) {
int index = methodName.indexOf(":");
if (index != -1)
methodName = methodName.substring(0, index);
} else {
// TODO improve this selector
methodName = methodName.replaceAll(":", "_");
if (isStatic)
methodName = "static_" + methodName;
}
out(methodName);
out("(");
NodeList params = method.getChildNodes();
boolean first = true;
for (int k = 0; k < params.getLength(); k++) {
Node param = params.item(k);
if ("arg".equals(param.getNodeName())) {
NamedNodeMap paramAttributes = param.getAttributes();
if (!first)
out(", ");
String type = getJavaType(param), type64 = getJavaType64(param);
out(type);
if (!type.equals(type64)) {
out(" /*");
out(type64);
out("*/");
}
first = false;
out(" ");
String paramName = paramAttributes.getNamedItem("name").getNodeValue();
if (paramName.length() == 0)
paramName = "arg" + paramAttributes.getNamedItem("index").getNodeValue();
if (paramName.equals("boolean"))
paramName = "b";
out(paramName);
}
}
out(") {");
outln();
if (returnNode != null && isStruct(returnNode)) {
out("\t");
out(returnType);
out(" result = new ");
out(returnType);
out("();");
outln();
out("\tOS.objc_msgSend_stret(result, ");
} else if (returnNode != null && isBoolean(returnNode)) {
out("\treturn ");
out("OS.objc_msgSend_bool(");
} else if (returnNode != null && isFloatingPoint(returnNode)) {
out("\treturn ");
if (returnType.equals("float"))
out("(float)");
out("OS.objc_msgSend_fpret(");
} else if (returnNode != null && isObject(returnNode)) {
out("\tint /*long*/ result = OS.objc_msgSend(");
} else {
if (returnNode != null) {
out("\treturn ");
if ((returnType.equals("int") && returnType64.equals("int")) || !returnType.equals("int")) {
out("(");
out(returnType);
out(")");
}
if (returnType.equals("int") && returnType64.equals("int")) {
out("/*64*/");
}
} else {
out("\t");
}
out("OS.objc_msgSend(");
}
if (isStatic) {
out("OS.class_");
out(className);
} else {
out("this.id");
}
out(", OS.");
out(getSelConst(sel));
first = false;
for (int k = 0; k < params.getLength(); k++) {
Node param = params.item(k);
if ("arg".equals(param.getNodeName())) {
NamedNodeMap paramAttributes = param.getAttributes();
if (!first)
out(", ");
first = false;
String paramName = paramAttributes.getNamedItem("name").getNodeValue();
if (paramName.length() == 0)
paramName = "arg" + paramAttributes.getNamedItem("index").getNodeValue();
if (paramName.equals("boolean"))
paramName = "b";
if (isObject(param)) {
out(paramName);
out(" != null ? ");
out(paramName);
out(".id : 0");
} else {
out(paramName);
}
}
}
out(")");
out(";");
outln();
if (returnNode != null && isObject(returnNode)) {
if (!isStatic && returnType.equals(className)) {
out("\treturn result == this.id ? this : (result != 0 ? new ");
out(returnType);
out("(result) : null);");
} else {
out("\treturn result != 0 ? new ");
NamedNodeMap attributes = returnNode.getAttributes();
Node hawtjni_alloc = attributes.getNamedItem("hawtjni_alloc");
if (hawtjni_alloc != null && hawtjni_alloc.getNodeValue().equals("true")) {
out(className);
} else {
out(returnType);
}
out("(result) : null;");
}
outln();
} else if (returnNode != null && isStruct(returnNode)) {
out("\treturn result;");
outln();
}
out("}");
outln();
outln();
}
}
void generateExtraMethods(String className) {
/* Empty constructor */
out("public ");
out(className);
out("() {");
outln();
out("\tsuper();");
outln();
out("}");
outln();
outln();
/* pointer constructor */
out("public ");
out(className);
out("(int /*long*/ id) {");
outln();
out("\tsuper(id);");
outln();
out("}");
outln();
outln();
/* object constructor */
out("public ");
out(className);
out("(id id) {");
outln();
out("\tsuper(id);");
outln();
out("}");
outln();
outln();
/* NSObject helpers */
if (className.equals("NSObject")) {
out("public NSObject alloc() {");
outln();
out("\tthis.id = OS.objc_msgSend(objc_getClass(), OS.sel_alloc);");
outln();
out("\treturn this;");
outln();
out("}");
outln();
outln();
}
/* NSString helpers */
if (className.equals("NSString")) {
/* Get java string */
out("public String getString() {");
outln();
out("\tchar[] buffer = new char[(int)/*64*/length()];");
outln();
out("\tgetCharacters(buffer);");
outln();
out("\treturn new String(buffer);");
outln();
out("}");
outln();
outln();
/* create NSString */
out("public NSString initWithString(String str) {");
outln();
out("\tchar[] buffer = new char[str.length()];");
outln();
out("\tstr.getChars(0, buffer.length, buffer, 0);");
outln();
out("\treturn initWithCharacters(buffer, buffer.length);");
outln();
out("}");
outln();
outln();
out("public static NSString stringWith(String str) {");
outln();
out("\tchar[] buffer = new char[str.length()];");
outln();
out("\tstr.getChars(0, buffer.length, buffer, 0);");
outln();
out("\treturn stringWithCharacters(buffer, buffer.length);");
outln();
out("}");
outln();
outln();
}
}
static class NodeEntry {
private final Node parent;
private final ArrayList children;
public NodeEntry(Node parent, ArrayList children) {
this.parent = parent;
this.children = children;
}
}
TreeMap getGeneratedClasses() {
TreeMap classes = new TreeMap();
for (int x = 0; x < xmls.length; x++) {
Document document = documents[x];
if (document == null)
continue;
NodeList list = document.getDocumentElement().getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if ("class".equals(node.getNodeName()) && getGen(node)) {
ArrayList methods;
String name = node.getAttributes().getNamedItem("name").getNodeValue();
NodeEntry clazz = classes.get(name);
if (clazz == null) {
methods = new ArrayList();
classes.put(name, new NodeEntry(node, methods));
} else {
methods = clazz.children;
}
NodeList methodList = node.getChildNodes();
for (int j = 0; j < methodList.getLength(); j++) {
Node method = methodList.item(j);
if ("method".equals(method.getNodeName()) && getGen(method)) {
methods.add(method);
}
}
}
}
}
return classes;
}
void copyClassMethodsDown(final Map classes) {
ArrayList sortedClasses = Collections.list(Collections.enumeration(classes.values()));
Collections.sort(sortedClasses, new Comparator() {
int getHierarchyLevel(Node node) {
String superclass = getSuperclassName(node);
int level = 0;
while (!superclass.equals("id")) {
level++;
superclass = getSuperclassName(classes.get(superclass).parent);
}
return level;
}
public int compare(NodeEntry arg0, NodeEntry arg1) {
return getHierarchyLevel(arg0.parent) - getHierarchyLevel(arg1.parent);
}
});
for (NodeEntry clazz : sortedClasses) {
Node node = (Node) clazz.parent;
ArrayList methods = (ArrayList) clazz.children;
NodeEntry superclass = classes.get(getSuperclassName(node));
if (superclass != null) {
for (Node method : superclass.children) {
if (isStatic(method)) {
methods.add(method);
}
}
}
}
}
String getSuperclassName(Node node) {
NamedNodeMap attributes = node.getAttributes();
Node superclass = attributes.getNamedItem("hawtjni_superclass");
if (superclass != null) {
return superclass.getNodeValue();
} else {
Node name = attributes.getNamedItem("name");
if (name.getNodeValue().equals("NSObject")) {
return "id";
} else {
return "NSObject";
}
}
}
void generateClasses() {
TreeMap classes = getGeneratedClasses();
copyClassMethodsDown(classes);
Set classNames = classes.keySet();
for (Iterator iterator = classNames.iterator(); iterator.hasNext();) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
this.out = new PrintStream(out);
// out(fixDelimiter(metaData.getCopyright()));
String className = iterator.next();
NodeEntry clazz = classes.get(className);
Node node = clazz.parent;
ArrayList methods = clazz.children;
out("package ");
String packageName = getPackageName(mainClassName);
out(packageName);
out(";");
outln();
outln();
out("public class ");
out(className);
out(" extends ");
out(getSuperclassName(node));
out(" {");
outln();
outln();
generateExtraMethods(className);
generateMethods(className, methods);
out("}");
outln();
String fileName = outputDir + packageName.replace('.', '/') + "/" + className + ".java";
try {
out.flush();
if (out.size() > 0) {
FileSupport.write(out.toByteArray(), new File(fileName));
}
} catch (Exception e) {
System.out.println("Problem");
e.printStackTrace(System.out);
}
out = null;
}
}
void generateExtraAttributes() {
Document[] documents = getDocuments();
for (int x = 0; x < xmls.length; x++) {
Document document = documents[x];
if (document == null || !getGen(document.getDocumentElement()))
continue;
saveExtraAttributes(xmls[x], document);
}
}
void generateMainClass() {
ByteArrayOutputStream out = new ByteArrayOutputStream();
this.out = new PrintStream(out);
String header = "", footer = "";
String fileName = outputDir + mainClassName.replace('.', '/') + ".java";
FileInputStream is = null;
try {
InputStreamReader input = new InputStreamReader(new BufferedInputStream(is = new FileInputStream(fileName)));
StringBuffer str = new StringBuffer();
char[] buffer = new char[4096];
int read;
while ((read = input.read(buffer)) != -1) {
str.append(buffer, 0, read);
}
String section = "/** This section is auto generated */";
int start = str.indexOf(section) + section.length();
int end = str.indexOf(section, start);
header = str.substring(0, start);
footer = str.substring(end);
} catch (IOException e) {
} finally {
try {
if (is != null)
is.close();
} catch (IOException e) {
}
}
out(header);
outln();
outln();
out("/** Custom callbacks */");
outln();
generateCustomCallbacks();
outln();
out("/** Classes */");
outln();
generateClassesConst();
outln();
out("/** Protocols */");
outln();
generateProtocolsConst();
outln();
out("/** Selectors */");
outln();
generateSelectorsConst();
outln();
out("/** Constants */");
outln();
generateEnums();
outln();
out("/** Globals */");
outln();
generateConstants();
outln();
out("/** Functions */");
outln();
outln();
generateFunctions();
outln();
out("/** Super Sends */");
outln();
generateSends(true);
outln();
out("/** Sends */");
outln();
generateSends(false);
outln();
generateStructNatives();
outln();
out(footer);
try {
out.flush();
if (out.size() > 0) {
FileSupport.write(out.toByteArray(), new File(fileName));
}
} catch (Exception e) {
System.out.println("Problem");
e.printStackTrace(System.out);
}
}
public Document[] getDocuments() {
if (documents == null) {
String[] xmls = getXmls();
documents = new Document[xmls.length];
for (int i = 0; i < xmls.length; i++) {
String xmlPath = xmls[i];
Document document = documents[i] = getDocument(xmlPath);
if (document == null)
continue;
if (mainClassName != null && outputDir != null) {
String packageName = getPackageName(mainClassName);
String extrasPath = outputDir + packageName.replace('.', '/') + "/" + getFileName(xmlPath) + ".extras";
merge(document, getDocument(extrasPath));
}
}
}
return documents;
}
public String[] getXmls() {
if (xmls == null || xmls.length == 0) {
ArrayList array = new ArrayList();
list(new File("/System/Library/Frameworks"), array);
list(new File("/System/Library/Frameworks/CoreServices.framework/Frameworks"), array);
list(new File("/System/Library/Frameworks/ApplicationServices.framework/Frameworks"), array);
Collections.sort(array, new Comparator() {
public int compare(String o1, String o2) {
return new File(o1).getName().compareTo(new File(o2).getName());
}
});
xmls = array.toArray(new String[array.size()]);
}
return xmls;
}
void saveExtraAttributes(String xmlPath, Document document) {
try {
String packageName = getPackageName(mainClassName);
String fileName = outputDir + packageName.replace('.', '/') + "/" + getFileName(xmlPath) + ".extras";
ByteArrayOutputStream out = new ByteArrayOutputStream();
DOMWriter writer = new DOMWriter(new PrintStream(out));
String[] names = getIDAttributeNames();
String[] filter = new String[names.length + 2];
filter[0] = "class_method";
filter[1] = "hawtjni_.*";
System.arraycopy(names, 0, filter, 2, names.length);
writer.setAttributeFilter(filter);
writer.setNodeFilter("hawtjni_");
writer.print(document);
if (out.size() > 0) {
FileSupport.write(out.toByteArray(), new File(fileName));
}
} catch (Exception e) {
System.out.println("Problem");
e.printStackTrace(System.out);
}
}
public void setOutputDir(String dir) {
if (dir != null) {
if (!dir.endsWith("\\") && !dir.endsWith("/")) {
dir += "/";
}
}
this.outputDir = dir;
}
public void setXmls(String[] xmls) {
this.xmls = xmls;
this.documents = null;
}
public void setMainClass(String mainClassName) {
this.mainClassName = mainClassName;
}
Document getDocument(String xmlPath) {
try {
InputStream is = null;
if (xmlPath.indexOf(File.separatorChar) == -1)
is = getClass().getResourceAsStream(xmlPath);
if (is == null)
is = new BufferedInputStream(new FileInputStream(xmlPath));
if (is != null)
return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(is));
} catch (Exception e) {
// e.printStackTrace();
}
return null;
}
public String[] getExtraAttributeNames(Node node) {
String name = node.getNodeName();
if (name.equals("method")) {
return new String[] { "hawtjni_gen_super_msgSend", "hawtjni_gen_custom_callback" };
} else if (name.equals("function")) {
NamedNodeMap attribs = node.getAttributes();
if (attribs != null && attribs.getNamedItem("variadic") != null) {
return new String[] { "hawtjni_variadic_count", "hawtjni_variadic_java_types" };
}
} else if (name.equals("class")) {
return new String[] { "hawtjni_superclass" };
} else if (name.equals("retval")) {
return new String[] { "hawtjni_java_type", "hawtjni_java_type64", "hawtjni_alloc" };
} else if (name.equals("arg")) {
return new String[] { "hawtjni_java_type", "hawtjni_java_type64" };
}
return new String[0];
}
public String getFileName(String xmlPath) {
File file = new File(xmlPath);
return file.getName();
}
String getKey(Node node) {
StringBuffer buffer = new StringBuffer();
while (node != null) {
if (buffer.length() > 0)
buffer.append("_");
String name = node.getNodeName();
StringBuffer key = new StringBuffer(name);
Node nameAttrib = getIDAttribute(node);
if (nameAttrib != null) {
key.append("-");
key.append(nameAttrib.getNodeValue());
}
NamedNodeMap attributes = node.getAttributes();
if (attributes != null) {
boolean isStatic = attributes.getNamedItem("class_method") != null;
if (isStatic)
key.append("-static");
}
buffer.append(key.reverse());
node = node.getParentNode();
}
buffer.reverse();
return buffer.toString();
}
public Node getIDAttribute(Node node) {
NamedNodeMap attributes = node.getAttributes();
if (attributes == null)
return null;
String[] names = getIDAttributeNames();
for (int i = 0; i < names.length; i++) {
Node nameAttrib = attributes.getNamedItem(names[i]);
if (nameAttrib != null)
return nameAttrib;
}
return null;
}
public String[] getIDAttributeNames() {
return new String[] { "name", "selector", "path", };
}
void merge(Node node, HashMap extras, HashMap docLookup) {
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node childNode = list.item(i);
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
String key = getKey(childNode);
if (docLookup != null && docLookup.get(key) == null) {
docLookup.put(key, childNode);
}
Node extra = extras.remove(key);
if (extra != null) {
NamedNodeMap attributes = extra.getAttributes();
for (int j = 0, length = attributes.getLength(); j < length; j++) {
Node attr = (Node) attributes.item(j);
String name = attr.getNodeName();
if (name.startsWith("hawtjni_")) {
((Element) childNode).setAttribute(name, attr.getNodeValue());
}
}
}
}
merge(childNode, extras, docLookup);
}
}
void out(String str) {
PrintStream out = this.out;
if (out == null)
out = System.out;
out.print(str);
}
void outln() {
PrintStream out = this.out;
if (out == null)
out = System.out;
out.println();
}
void generateConstants() {
for (int x = 0; x < xmls.length; x++) {
Document document = documents[x];
if (document == null)
continue;
NodeList list = document.getDocumentElement().getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if ("constant".equals(node.getNodeName())) {
if (getGen(node)) {
NamedNodeMap attributes = node.getAttributes();
String constName = attributes.getNamedItem("name").getNodeValue();
out("/** @method flags=const */");
outln();
out("public static final native ");
String type = getType(node), type64 = getType64(node);
out(type);
if (!type.equals(type64)) {
out(" /*");
out(type64);
out("*/");
}
out(" ");
out(constName);
out("();");
outln();
if (attributes.getNamedItem("declared_type").getNodeValue().equals("NSString*")) {
out("public static final NSString ");
out(constName);
out(" = new NSString(");
out(constName);
out("());");
outln();
}
}
}
}
}
}
void generateEnums() {
for (int x = 0; x < xmls.length; x++) {
Document document = documents[x];
if (document == null)
continue;
NodeList list = document.getDocumentElement().getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if ("enum".equals(node.getNodeName())) {
if (getGen(node)) {
NamedNodeMap attributes = node.getAttributes();
Node valueNode = attributes.getNamedItem("value");
if (valueNode != null) {
String value = valueNode.getNodeValue();
out("public static final ");
boolean isLong = false;
if (value.indexOf('.') != -1) {
out("double ");
} else {
try {
Integer.parseInt(value);
out("int ");
} catch (NumberFormatException e) {
isLong = true;
out("long ");
}
}
out(attributes.getNamedItem("name").getNodeValue());
out(" = ");
out(value);
if (isLong && !value.endsWith("L"))
out("L");
out(";");
outln();
}
}
}
}
}
}
boolean getGen(Node node) {
NamedNodeMap attributes = node.getAttributes();
if (attributes == null)
return false;
Node gen = attributes.getNamedItem("hawtjni_gen");
return gen != null && !gen.getNodeValue().equals("false");
}
boolean getGenSuper(Node node) {
NamedNodeMap attributes = node.getAttributes();
if (attributes == null)
return false;
Node gen = attributes.getNamedItem("hawtjni_gen_super_msgSend");
return gen != null && !gen.getNodeValue().equals("false");
}
boolean getGenCallback(Node node) {
NamedNodeMap attributes = node.getAttributes();
if (attributes == null)
return false;
Node gen = attributes.getNamedItem("hawtjni_gen_custom_callback");
return gen != null && !gen.getNodeValue().equals("false");
}
boolean isStatic(Node node) {
NamedNodeMap attributes = node.getAttributes();
Node isStatic = attributes.getNamedItem("class_method");
return isStatic != null && isStatic.getNodeValue().equals("true");
}
boolean isStruct(Node node) {
NamedNodeMap attributes = node.getAttributes();
String code = attributes.getNamedItem("type").getNodeValue();
return code.startsWith("{");
}
boolean isFloatingPoint(Node node) {
NamedNodeMap attributes = node.getAttributes();
String code = attributes.getNamedItem("type").getNodeValue();
return code.equals("f") || code.equals("d");
}
boolean isObject(Node node) {
NamedNodeMap attributes = node.getAttributes();
String code = attributes.getNamedItem("type").getNodeValue();
return code.equals("@");
}
boolean isBoolean(Node node) {
NamedNodeMap attributes = node.getAttributes();
String code = attributes.getNamedItem("type").getNodeValue();
return code.equals("B");
}
void buildLookup(Node node, HashMap table) {
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node childNode = list.item(i);
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
String key = getKey(childNode);
if (table.get(key) == null)
table.put(key, childNode);
buildLookup(childNode, table);
}
}
}
boolean isUnique(Node method, ArrayList methods) {
String methodName = method.getAttributes().getNamedItem("selector").getNodeValue();
String signature = "";
NodeList params = method.getChildNodes();
for (int k = 0; k < params.getLength(); k++) {
Node param = params.item(k);
if ("arg".equals(param.getNodeName())) {
signature += getJavaType(param);
}
}
int index = methodName.indexOf(":");
if (index != -1)
methodName = methodName.substring(0, index);
for (Node node : methods) {
NamedNodeMap attributes = node.getAttributes();
Node otherSel = null;
if (attributes != null)
otherSel = attributes.getNamedItem("selector");
if (node != method && otherSel != null) {
String otherName = otherSel.getNodeValue();
index = otherName.indexOf(":");
if (index != -1)
otherName = otherName.substring(0, index);
if (methodName.equals(otherName)) {
NodeList otherParams = node.getChildNodes();
String otherSignature = "";
for (int k = 0; k < otherParams.getLength(); k++) {
Node param = otherParams.item(k);
if ("arg".equals(param.getNodeName())) {
otherSignature += getJavaType(param);
}
}
if (signature.equals(otherSignature)) {
return false;
}
}
}
}
return true;
}
void generateSelectorsConst() {
TreeSet set = new TreeSet();
for (int x = 0; x < xmls.length; x++) {
Document document = documents[x];
if (document == null)
continue;
NodeList list = document.getDocumentElement().getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if ("class".equals(node.getNodeName()) || "informal_protocol".equals(node.getNodeName())) {
if (getGen(node)) {
NodeList methods = node.getChildNodes();
for (int j = 0; j < methods.getLength(); j++) {
Node method = methods.item(j);
if (getGen(method)) {
NamedNodeMap mthAttributes = method.getAttributes();
String sel = mthAttributes.getNamedItem("selector").getNodeValue();
set.add(sel);
}
}
}
}
}
}
set.add("alloc");
for (Iterator iterator = set.iterator(); iterator.hasNext();) {
String sel = iterator.next();
String selConst = getSelConst(sel);
out("public static final int /*long*/ ");
out(selConst);
out(" = ");
out("sel_registerName(\"");
out(sel);
out("\");");
outln();
}
}
void generateStructNatives() {
TreeSet set = new TreeSet();
for (int x = 0; x < xmls.length; x++) {
Document document = documents[x];
if (document == null)
continue;
NodeList list = document.getDocumentElement().getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if ("struct".equals(node.getNodeName()) && getGen(node)) {
set.add(getIDAttribute(node).getNodeValue());
}
}
}
out("/** Sizeof natives */");
outln();
for (Iterator iterator = set.iterator(); iterator.hasNext();) {
String struct = iterator.next();
out("public static final native int ");
out(struct);
out("_sizeof();");
outln();
}
outln();
out("/** Memmove natives */");
outln();
outln();
for (Iterator iterator = set.iterator(); iterator.hasNext();) {
String struct = iterator.next();
out("/**");
outln();
out(" * @param dest cast=(void *),flags=no_in critical");
outln();
out(" * @param src cast=(void *),flags=critical");
// out(" * @param src cast=(void *),flags=no_out critical");
outln();
out(" */");
outln();
out("public static final native void memmove(");
out("int /*long*/ dest, ");
out(struct);
out(" src, int /*long*/ size);");
outln();
out("/**");
outln();
out(" * @param dest cast=(void *),flags=no_in critical");
outln();
out(" * @param src cast=(void *),flags=critical");
// out(" * @param src cast=(void *),flags=no_out critical");
outln();
out(" */");
outln();
out("public static final native void memmove(");
out(struct);
out(" dest, int /*long*/ src, int /*long*/ size);");
outln();
}
}
String buildSend(Node method, boolean tags, boolean only64, boolean superCall) {
Node returnNode = getReturnNode(method.getChildNodes());
StringBuffer buffer = new StringBuffer();
buffer.append("public static final native ");
if (returnNode != null && isStruct(returnNode)) {
buffer.append("void ");
buffer.append(superCall ? "objc_msgSendSuper_stret" : "objc_msgSend_stret");
buffer.append("(");
buffer.append(getJavaType(returnNode));
buffer.append(" result, ");
} else if (returnNode != null && isFloatingPoint(returnNode)) {
buffer.append("double ");
buffer.append(superCall ? "objc_msgSendSuper_fpret" : "objc_msgSend_fpret");
buffer.append("(");
} else if (returnNode != null && isBoolean(returnNode)) {
buffer.append("boolean ");
buffer.append(superCall ? "objc_msgSendSuper_bool" : "objc_msgSend_bool");
buffer.append("(");
} else {
if (only64) {
buffer.append("long");
} else {
if (tags) {
buffer.append("int /*long*/");
} else {
buffer.append("int");
}
}
buffer.append(" ");
buffer.append(superCall ? "objc_msgSendSuper" : "objc_msgSend");
buffer.append("(");
}
if (superCall) {
if (only64) {
buffer.append("objc_super superId, long sel");
} else {
if (tags) {
buffer.append("objc_super superId, int /*long*/ sel");
} else {
buffer.append("objc_super superId, int sel");
}
}
} else {
if (only64) {
buffer.append("long id, long sel");
} else {
if (tags) {
buffer.append("int /*long*/ id, int /*long*/ sel");
} else {
buffer.append("int id, int sel");
}
}
}
NodeList params = method.getChildNodes();
boolean first = false;
int count = 0;
for (int k = 0; k < params.getLength(); k++) {
Node param = params.item(k);
if ("arg".equals(param.getNodeName())) {
if (!first)
buffer.append(", ");
if (isStruct(param)) {
buffer.append(getJavaType(param));
} else {
String type = getType(param), type64 = getType64(param);
buffer.append(only64 ? type64 : type);
if (!only64 && tags && !type.equals(type64)) {
buffer.append(" /*");
buffer.append(type64);
buffer.append("*/");
}
}
first = false;
buffer.append(" arg");
buffer.append(String.valueOf(count++));
}
}
buffer.append(");");
return buffer.toString();
}
String getCType(Node node) {
NamedNodeMap attributes = node.getAttributes();
return attributes.getNamedItem("declared_type").getNodeValue();
}
Node findNSObjectMethod(Node method) {
NamedNodeMap methodAttributes = method.getAttributes();
String selector = methodAttributes.getNamedItem("selector").getNodeValue();
NodeList list = method.getParentNode().getParentNode().getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node cls = list.item(i);
if ("class".equals(cls.getNodeName())) {
NamedNodeMap classAttributes = cls.getAttributes();
if ("NSObject".equals(classAttributes.getNamedItem("name").getNodeValue())) {
NodeList methods = cls.getChildNodes();
for (int j = 0; j < methods.getLength(); j++) {
Node mth = methods.item(j);
if ("method".equals(mth.getNodeName())) {
NamedNodeMap mthAttributes = mth.getAttributes();
if (selector.equals(mthAttributes.getNamedItem("selector").getNodeValue())) {
return mth;
}
}
}
}
}
}
return null;
}
void generateCustomCallbacks() {
TreeMap set = new TreeMap();
for (int x = 0; x < xmls.length; x++) {
Document document = documents[x];
if (document == null)
continue;
NodeList list = document.getDocumentElement().getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if (("class".equals(node.getNodeName()) || "informal_protocol".equals(node.getNodeName())) && getGen(node)) {
NodeList methods = node.getChildNodes();
for (int j = 0; j < methods.getLength(); j++) {
Node method = methods.item(j);
if ("method".equals(method.getNodeName()) && getGen(method) && getGenCallback(method)) {
NamedNodeMap mthAttributes = method.getAttributes();
String sel = mthAttributes.getNamedItem("selector").getNodeValue();
set.put(sel, method);
}
}
}
}
}
for (Iterator iterator = set.keySet().iterator(); iterator.hasNext();) {
String key = iterator.next();
Node method = set.get(key);
if ("informal_protocol".equals(method.getParentNode().getNodeName())) {
method = findNSObjectMethod(method);
if (method == null)
continue;
}
String nativeMth = key.replaceAll(":", "_");
out("/** @method callback_types=");
Node returnNode = getReturnNode(method.getChildNodes());
out(returnNode == null ? "void" : getCType(returnNode));
out(";id;SEL;");
NodeList params = method.getChildNodes();
for (int k = 0; k < params.getLength(); k++) {
Node param = params.item(k);
if ("arg".equals(param.getNodeName())) {
out(getCType(param));
out(";");
}
}
out(",callback_flags=");
out(returnNode != null && isStruct(returnNode) ? "struct" : "none");
out(";none;none;");
for (int k = 0; k < params.getLength(); k++) {
Node param = params.item(k);
if ("arg".equals(param.getNodeName())) {
out(isStruct(param) ? "struct" : "none");
out(";");
}
}
out(" */");
outln();
out("public static final native int /*long*/ CALLBACK_");
out(nativeMth);
out("(int /*long*/ func);");
outln();
}
}
void generateSends(boolean superCall) {
TreeMap set = new TreeMap();
TreeMap set64 = new TreeMap();
for (int x = 0; x < xmls.length; x++) {
Document document = documents[x];
if (document == null)
continue;
NodeList list = document.getDocumentElement().getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if ("class".equals(node.getNodeName()) && getGen(node)) {
NodeList methods = node.getChildNodes();
for (int j = 0; j < methods.getLength(); j++) {
Node method = methods.item(j);
if ("method".equals(method.getNodeName()) && getGen(method) && (!superCall || getGenSuper(method))) {
String code = buildSend(method, false, false, superCall);
String code64 = buildSend(method, false, true, superCall);
if (set.get(code) == null) {
set.put(code, method);
}
if (set64.get(code64) == null) {
set64.put(code64, method);
}
}
}
}
}
}
outln();
TreeMap tagsSet = new TreeMap();
for (Iterator iterator = set.keySet().iterator(); iterator.hasNext();) {
String key = iterator.next();
Node method = set.get(key);
String tagCode = buildSend(method, false, true, superCall);
if (set64.get(tagCode) != null) {
tagsSet.put(key, method);
iterator.remove();
set64.remove(tagCode);
}
}
TreeMap all = new TreeMap();
for (Iterator iterator = tagsSet.keySet().iterator(); iterator.hasNext();) {
String key = iterator.next();
Node method = tagsSet.get(key);
all.put(buildSend(method, true, false, superCall), method);
}
for (Iterator iterator = set.keySet().iterator(); iterator.hasNext();) {
String key = iterator.next();
all.put(key, set.get(key));
}
for (Iterator iterator = set64.keySet().iterator(); iterator.hasNext();) {
String key = iterator.next();
all.put(key, set64.get(key));
}
for (Iterator iterator = all.keySet().iterator(); iterator.hasNext();) {
String key = iterator.next();
Node method = all.get(key);
NodeList params = method.getChildNodes();
ArrayList tags = new ArrayList();
int count = 0;
for (int k = 0; k < params.getLength(); k++) {
Node param = params.item(k);
if ("arg".equals(param.getNodeName())) {
if (isStruct(param)) {
tags.add(" * @param arg" + count + " flags=struct");
}
count++;
}
}
out("/**");
if (tags.size() > 0) {
outln();
out(" *");
}
out(" @method flags=cast");
if (tags.size() > 0)
outln();
for (String tag : tags) {
out(tag);
outln();
}
out(" */");
outln();
out(key.toString());
outln();
}
}
String getSelConst(String sel) {
return "sel_" + sel.replaceAll(":", "_");
}
void generateClassesConst() {
TreeSet set = new TreeSet();
for (int x = 0; x < xmls.length; x++) {
Document document = documents[x];
if (document == null)
continue;
NodeList list = document.getDocumentElement().getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if ("class".equals(node.getNodeName())) {
if (getGen(node)) {
NamedNodeMap attributes = node.getAttributes();
String name = attributes.getNamedItem("name").getNodeValue();
set.add(name);
}
}
}
}
for (Iterator iterator = set.iterator(); iterator.hasNext();) {
String cls = iterator.next();
String clsConst = "class_" + cls;
out("public static final int /*long*/ ");
out(clsConst);
out(" = ");
out("objc_getClass(\"");
out(cls);
out("\");");
outln();
}
}
void generateProtocolsConst() {
TreeSet set = new TreeSet();
for (int x = 0; x < xmls.length; x++) {
Document document = documents[x];
if (document == null)
continue;
NodeList list = document.getDocumentElement().getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if ("informal_protocol".equals(node.getNodeName())) {
if (getGen(node)) {
NamedNodeMap attributes = node.getAttributes();
String name = attributes.getNamedItem("name").getNodeValue();
set.add(name);
}
}
}
}
for (Iterator iterator = set.iterator(); iterator.hasNext();) {
String cls = iterator.next();
String clsConst = "protocol_" + cls;
out("public static final int /*long*/ ");
out(clsConst);
out(" = ");
out("objc_getProtocol(\"");
out(cls);
out("\");");
outln();
}
}
String getPackageName(String className) {
int dot = mainClassName.lastIndexOf('.');
if (dot == -1)
return "";
return mainClassName.substring(0, dot);
}
String getClassName(String className) {
int dot = mainClassName.lastIndexOf('.');
if (dot == -1)
return mainClassName;
return mainClassName.substring(dot + 1);
}
Node getReturnNode(NodeList list) {
for (int j = 0; j < list.getLength(); j++) {
Node node = list.item(j);
if ("retval".equals(node.getNodeName())) {
return node;
}
}
return null;
}
String getType(Node node) {
NamedNodeMap attributes = node.getAttributes();
Node javaType = attributes.getNamedItem("hawtjni_java_type");
if (javaType != null)
return javaType.getNodeValue();
String code = attributes.getNamedItem("type").getNodeValue();
return getType(code, attributes, false);
}
String getType64(Node node) {
NamedNodeMap attributes = node.getAttributes();
Node javaType = attributes.getNamedItem("hawtjni_java_type");
if (javaType != null) {
Node javaType64 = attributes.getNamedItem("hawtjni_java_type64");
return javaType64 != null ? javaType64.getNodeValue() : javaType.getNodeValue();
}
Node attrib = attributes.getNamedItem("type");
String code = attrib.getNodeValue();
Node attrib64 = attributes.getNamedItem("type64");
if (attrib64 != null)
code = attrib64.getNodeValue();
return getType(code, attributes, true);
}
String getType(String code, NamedNodeMap attributes, boolean is64) {
if (code.equals("c"))
return "byte";
if (code.equals("i"))
return "int";
if (code.equals("s"))
return "short";
if (code.equals("l"))
return "int";
if (code.equals("q"))
return "long";
if (code.equals("C"))
return "byte";
if (code.equals("I"))
return "int";
if (code.equals("S"))
return "short";
if (code.equals("L"))
return "int";
if (code.equals("Q"))
return "long";
if (code.equals("f"))
return "float";
if (code.equals("d"))
return "double";
if (code.equals("B"))
return "boolean";
if (code.equals("v"))
return "void";
if (code.equals("*"))
return is64 ? "long" : "int";
if (code.equals("@"))
return is64 ? "long" : "int";
if (code.equals("#"))
return is64 ? "long" : "int";
if (code.equals(":"))
return is64 ? "long" : "int";
if (code.startsWith("^"))
return is64 ? "long" : "int";
if (code.startsWith("{")) {
return attributes.getNamedItem("declared_type").getNodeValue();
}
return "BAD " + code;
}
String getJNIType(Node node) {
NamedNodeMap attributes = node.getAttributes();
String code = attributes.getNamedItem("type").getNodeValue();
if (code.equals("c"))
return "B";
if (code.equals("i"))
return "I";
if (code.equals("s"))
return "S";
if (code.equals("l"))
return "I";
if (code.equals("q"))
return "J";
if (code.equals("C"))
return "B";
if (code.equals("I"))
return "I";
if (code.equals("S"))
return "S";
if (code.equals("L"))
return "I";
if (code.equals("Q"))
return "J";
if (code.equals("f"))
return "F";
if (code.equals("d"))
return "D";
if (code.equals("B"))
return "Z";
if (code.equals("v"))
return "V";
if (code.equals("*"))
return "I";
if (code.equals("@"))
return "I";
if (code.equals("#"))
return "I";
if (code.equals(":"))
return "I";
if (code.startsWith("^"))
return "I";
if (code.startsWith("["))
return "BAD " + code;
if (code.startsWith("{")) {
return "BAD " + code;
}
if (code.startsWith("("))
return "BAD " + code;
return "BAD " + code;
}
String getJavaType(Node node) {
NamedNodeMap attributes = node.getAttributes();
Node javaType = attributes.getNamedItem("hawtjni_java_type");
if (javaType != null)
return javaType.getNodeValue().trim();
String code = attributes.getNamedItem("type").getNodeValue();
return getJavaType(code, attributes, false);
}
String getJavaType64(Node node) {
NamedNodeMap attributes = node.getAttributes();
Node javaType = attributes.getNamedItem("hawtjni_java_type");
if (javaType != null) {
Node javaType64 = attributes.getNamedItem("hawtjni_java_type64");
return javaType64 != null ? javaType64.getNodeValue() : javaType.getNodeValue();
}
Node attrib = attributes.getNamedItem("type");
String code = attrib.getNodeValue();
Node attrib64 = attributes.getNamedItem("type64");
if (attrib64 != null)
code = attrib64.getNodeValue();
return getJavaType(code, attributes, true);
}
String getJavaType(String code, NamedNodeMap attributes, boolean is64) {
if (code.equals("c"))
return "byte";
if (code.equals("i"))
return "int";
if (code.equals("s"))
return "short";
if (code.equals("l"))
return "int";
if (code.equals("q"))
return "long";
if (code.equals("C"))
return "byte";
if (code.equals("I"))
return "int";
if (code.equals("S"))
return "short";
if (code.equals("L"))
return "int";
if (code.equals("Q"))
return "long";
if (code.equals("f"))
return "float";
if (code.equals("d"))
return "double";
if (code.equals("B"))
return "boolean";
if (code.equals("v"))
return "void";
if (code.equals("*"))
return is64 ? "long" : "int";
if (code.equals("#"))
return is64 ? "long" : "int";
if (code.equals(":"))
return is64 ? "long" : "int";
if (code.startsWith("^"))
return is64 ? "long" : "int";
if (code.equals("@")) {
String type = attributes.getNamedItem("declared_type").getNodeValue();
int index = type.indexOf('*');
if (index != -1)
type = type.substring(0, index);
index = type.indexOf('<');
if (index != -1)
type = type.substring(0, index);
return type.trim();
}
if (code.startsWith("{")) {
return attributes.getNamedItem("declared_type").getNodeValue().trim();
}
return "BAD " + code;
}
static String[] split(String str, String separator) {
StringTokenizer tk = new StringTokenizer(str, separator);
ArrayList