• Stars
    star
    116
  • Rank 303,894 (Top 6 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 12 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Java bindings for various native APIs

Native-platform: Java bindings for native APIs

A collection of cross-platform Java APIs for various native APIs. Currently supports OS X, Linux, Windows and FreeBSD on Intel architectures.

These APIs support Java 5 and later. Some of these APIs overlap with APIs available in later Java versions.

Available bindings

Terminal and console

These bindings work for the UNIX terminal, the Windows console and Mintty from Cygwin and MSys on Windows.

  • Determine whether stdin/stdout/stderr are attached to a terminal.
  • Query the terminal size. Not supported for Mintty
  • Change foreground color on the terminal.
  • Switch between bold and normal text mode on the terminal.
  • Switch between dim, bright and normal text intensity on the terminal.
  • Move terminal cursor up, down, left, right, start of line.
  • Clear to end of line.
  • Show and hide the cursor.
  • Read raw input from the terminal. Not support for Mintty.
  • Read arrow keys and other function keys from the terminal. Not support for Mintty.

See Terminals

  • Utility class to display various kinds of prompts to the user on the terminal.

See Prompter

System information

  • Query kernel name and version.
  • Query machine architecture.
  • Query hostname.
  • Query total and available memory (OS X only).

See SystemInfo

Processes

  • Query the PID of the current process.
  • Query and set the process working directory.
  • Query and set the process environment variables.
  • Detach process from its controlling console

See Process

File systems

  • Query and set UNIX file mode.
  • Create and read symbolic links on UNIX and Windows.
  • Query UNIX file uid and gid.
  • Query file type, size and timestamps.
  • Query directory contents.

See Files

  • List the available file systems on the machine and details of each file system.
  • Query file system mount point.
  • Query file system type.
  • Query file system device name.
  • Query whether a file system is local or remote.
  • Query whether a file system is case-sensitive and case preserving.

See FileSystems

Windows registry

  • Query registry value.
  • Query the subkeys and values of a registry key.

See WindowsRegistry

Supported platforms

Currently ported to OS X, Linux, FreeBSD and Windows. Support for Solaris is a work in progress. Supported on:

  • OS X, version 10.9 and later (x86_64)
  • Fedora 23 and later (amd64).
  • Ubuntu 8.04 and later (amd64).
  • Ubuntu 18.04 and later (aarch64).
  • FreeBSD 10 and later (amd64).
  • Windows XP and later (amd64, i386). Console integration works with cmd.exe, powershell, ConEmu, Mintty from Cygwin, Mintty from Msys (includes Git for Windows).

Using

Include native-platform.jar and native-platform-${os}-${arch}.jar in your classpath. From Gradle, you can do this:

repositories {
    jcenter()
}

dependencies {
    compile "net.rubygrapefruit:native-platform:0.21"
}

You can also download the Jars from bintray

A test application is also available from bintray

Some sample code to use the terminal:

import net.rubygrapefruit.platform.Native;
import net.rubygrapefruit.platform.terminal.Terminals;
import net.rubygrapefruit.platform.terminal.TerminalOutput;
import static net.rubygrapefruit.platform.terminal.Terminals.Output.*;

Terminals terminals = Native.get(Terminals.class);

// check if terminal
terminals.isTerminal(Stdout);

// use terminal
TerminalOutput stdout = terminals.getTerminal(Stdout);
stdout.bold();
System.out.println("bold text");

Changes

0.22 (unreleased)

  • Remove support for 32bit Linux & FreeBSD, as well as support for FreeBSD < 10.

0.21

  • Some preparation for a new API to watch the file system for changes.

0.20

  • Removed FileEvents API for watching the file system for changes.

0.19

  • Added SystemInfo.getHostname(). Thanks to Tom Dunstan
  • Fixed terminal integration on Arch linux.
  • Fixed terminal integration on Amazon linux 2 aarch64.

0.18

  • Support for symlinks on Windows. Thanks to Renaud Paquay.
  • Fixed handling of long paths on Windows. Thanks to Renaud Paquay.
  • Support for Linux on aarch64. Thanks to Amey.

0.17

  • Fixed handling of supplementary characters in environment variable values. Thanks to Gary Hale.
  • Added TerminalInput.supportsRawMode() to determine whether terminal supports raw mode.
  • Improve Prompter to show an alternate UI when the terminal input does not support raw mode.

0.16

  • Change Terminals to support running under Mintty from Cygwin and MSYS on Windows. Supported for Windows 2008 and later. TerminalOutput is supported, however TerminalInput is not.

0.15

  • Fixed Files.stat() when the path points to a descendent of a file. Thanks to Gary Hale.
  • Renamed Terminal to TerminalOutput.
  • Moved some types to subpackages.
  • Added TerminalInput to read text from the terminal. Supports raw mode and arrow keys.
  • Added method to Terminals to determine whether stdin is attached to a terminal.
  • Added method to Terminals to force the use of ANSI escape sequences to write the terminal output.
  • Added methods to TerminalOutput to show and hide the cursor.
  • Added methods to TerminalOutput to set foreground text color to its default value.
  • Added methods to TerminalOutput to set bright and dim foreground text intensity.
  • Added methods to TerminalOutput to write text to the terminal. Anything written to System.out or System.err is no longer automatically flushed before cursor or text attributes are changed.
  • Added Prompter utility class to display prompts on the terminal to ask the user various questions.
  • Moved releases to JCenter.

0.14

  • Added Memory, for OS X only. Thanks to Paul Merlin
  • NativeIntegrationLinkageException is thrown by Native.get() when a particular native library cannot be loaded due to a linkage error.

0.13

  • Added overloads of Files.stat() and Files.listDir() that follow links.
  • Improvements to error handling for Files.stat() and listDir().
  • Fixes for build time detection of ncurses 6. Thanks to Marcin Zajฤ…czkowski

0.12

  • Added Files.listDir().
  • Fixes for terminal integration for Linux distributions that use ncurses 6, such as Fedora 24 and later.
  • Fixes for running on FreeBSD 10 and later without requiring GCC to be installed on the machine.

0.11

  • Added support to detach the current process from its controlling console. Thanks to Gary Hale.
  • Fixes for handling Windows shares from Linux. Thanks to Thierry Guรฉrin.
  • Added initial implementation of FileEvents, which allows an application to listen for changes to a file system directory.
  • Added more properties to PosixFile.
  • Added Files and WindowsFiles.
  • Added FileSystem.isCaseSensitive() and FileSystem.isCasePreserving().
  • Fixes running under GCJ.

0.10

  • Fixes for broken 0.9 release.

0.9

  • Fixes for non-ascii file names on OS X when running under the Apple JVM.

You should avoid using this release, and use 0.10 or later instead.

0.8

0.7

  • Some fixes for a broken 0.6 release.

0.6

  • Some fixes for Windows 7 and OS X 10.6.

You should avoid using this release, and use 0.7 or later instead.

0.5

  • Query the available values of a Windows registry key. Thanks to Michael Putters.

0.4

  • Get file type.
  • Query Windows registry value and subkeys.
  • Fixes to work on 64-bit Windows XP.

0.3

  • Get and set process working directory.
  • Get and set process environment variables.
  • Launch processes.
  • Fixed character set issue on Linux and Mac OS X.
  • Fixes to work with 64-bit OpenJDK 7 on Mac OS X. Thanks to Rene Groeschke.

0.2

  • Fixes to make native library extraction multi-process safe.
  • Fixes to windows terminal detection and reset.

0.1

  • Initial release.

Development

Building

This project uses (Gradle)[https://www.gradle.org] to build. Just run gradlew in the root of the source repo. You will need Java 8 or later to run the tests.

Ubuntu

The g++ compiler is required to build the native library. You will need to install the g++ package for this. Alternatively, you can use the Clang C++ compiler.

You need to install the libncurses5-dev package to pick up the ncurses header files. Also worth installing the ncurses-doc package too.

64-bit machines with multi-arch support

Where multi-arch support is available (e.g. recent Ubuntu releases), you can build the i386 and amd64 versions of the library on the same machine.

You need to install the gcc-multilib and g++-multilib packages to pick up i386 support.

You need to install the lib32ncurses5-dev package to pick up the ncurses i386 version.

Windows

You need to install Visual studio 2012 or later, plus the Windows SDK to allow you to build both x86 and x64 binaries.

OS X

The clang compiler is required to build the native library. You will need to install the XCode command-line tools for this.

Solaris

For Solaris 11, you need to install the development/gcc-45 and system/header packages.

Running

Run gradlew installDist to install the test application into test-app/build/install/native-platform-test. Or gradle distZip to create an application distribution in test-app/build/distributions/native-platform-test-$version.zip.

You can run $INSTALL_DIR/bin/native-platform-test to run the test application.

Testing integration with another project

When developing a new feature in native platform, you often want to test the features in a real-world project which uses native platform. There are various ways how to test the changes of native platform in the consuming project.

Use composite build on a developer machine

From the command line

From the checkout directory of the consuming project you can run:

./gradlew --include-build ../native-platform ...

This assumes that native-platform is checked out in ../native-platform relative to the consuming project.

From IDEA

In IDEA, open the consuming project. Then link the native-platform project. Finally, add the linked native-platform project as a participant to the Gradle build and sync the consuming project.

WARNING: You need to use IDEA 2020.1 for the composite build to work. See https://youtrack.jetbrains.com/issue/IDEA-228368 and https://youtrack.jetbrains.com/issue/IDEA-206799.

Use a published snapshot on a developer machine/CI

  • Publish a snapshot from the branch you want to test by using this Teamcity build.
  • Change the version of native platform in the consuming project to match the version you just published, e.g. 0.22-snapshot-20200128143135+0000, and push the changes to a branch.
  • Run some tests on CI on the branch of the consuming project you just pushed.
  • Test what you want to test on the consuming project.

Use mavenLocal() on a developer machine

  • Install a dev version of native platform to your local Maven repository by running
    ./gradlew publishToMavenLocal -PonlyLocalVariants
  • Add mavenLocal() as a repository in the consuming project.
  • Change the version of native platform in the consuming project to match the version you just built, e.g. 0.22-dev.
  • Test what you want to test on the consuming project.

Releasing

  1. Check the version number in build.gradle.
  2. Create a tag
  3. Build each variant.
    1. Checkout tag.
    2. ./gradlew clean :native-platform:test :native-platform:uploadJni -Prelease -PpublishUserName=<> -PpublishApiKey=<>.
  4. Build Java library:
    1. Checkout tag.
    2. ./gradlew clean :native-platform:test :native-platform:uploadMain -Prelease -PpublishUserName=<> -PpublishApiKey=<>
  5. Build the test app:
    1. Checkout tag.
    2. ./gradlew clean :test-app:uploadMain -Prelease -PpublishUserName=<> -PpublishApiKey=<>
  6. Publish on bintray
  7. Checkout master
  8. Increment version number in gradle.properties and this readme.
  9. Push changes.

Use -Pmilestone instead of -Prelease to publish a milestone version.

Testing

  • Test on IBM JVM.
  • Test on Java 5, 6, 7.
  • Test on Windows 7, Windows XP

TODO

Fixes

  • OS X: Watch for changes to files in directory.
  • FreeBSD: Watch for changes to files in directory.
  • Linux: Fix spurious change event on close.
  • All: Handle deletion and recreation of watched file/directory.
  • All: Watch for creation and changes to missing file/directory.
  • Windows: Watch for changes to a file (directory works, file does not).
  • All: FileWatch tests: file truncated, last modified changed, content changed, recreated as file/dir, file renamed
  • All: Thread safety for FileWatch.
  • All: Bulk read of multiple file change events, coalesce events, use background thread to drain queue.
  • Linux: Fix detection of multiarch support
  • FreeBSD: Fix detection of multiarch support
  • All: Process.getPid() should return a long
  • All: fail subsequent calls to Native.get() when Native.initialize() fails.
  • Posix: allow terminal to be detected when ncurses cannot be loaded
  • Windows: fix detection of shared drive under VMWare fusion and Windows XP
  • Windows: restore std handles after launching child process
  • Linux: detect remote filesystems.
  • All: cache reflective lookup in native functions.
  • Solaris: fix unicode file name handling.
  • Solaris: fail for unsupported architecture.
  • Solaris: build 32 bit and 64 bit libraries.

Improvements

  • All: fall back to WrapperProcessLauncher + DefaultProcessLauncher for all platforms, regardless of whether a native integration is available or not.
  • All: change the terminal API to handle the fact that stdout/stderr/stdin can all be attached to the same or to different terminals.
  • All: have Terminal extend Appendable and Flushable
  • All: add a method to Terminal that returns a PrintStream that can be used to write to the terminal, regardless of what System.out or System.err point to.
  • Windows: use wchar_to_java() for system and file system info.
  • All: test network file systems
  • Windows: test mount points
  • All: cache class, method and field lookups
  • Unix: change readLink() implementation so that it does not need to NULL terminate the encoded content
  • All: don't use NewStringUTF() anywhere
  • Mac: change java_to_char() to convert java string directly to utf-8 char string.
  • Mac: change char_to_java() to assume utf-8 encoding and convert directly to java string.
  • Linux: change char_to_java() to use iconv() to convert from C char string to UTF-16 then to java string.
  • Windows: support for cygwin terminal input
  • Solaris: use TERM=xtermc instead of TERM=xterm.
  • All: add diagnostics for terminal.
  • All: version each native interface separately.
  • Windows: string names for errno values.
  • All: split into multiple projects.
  • Mac: use fully decomposed form for unicode file names on hfs+ filesystems.
  • All: extend FileSystem to deal with removable media.
  • Unix: add a Terminal implementation that uses ANSI control codes. Use this when TERM != 'dumb' and libncurses cannot be loaded.
  • All: add a method to Terminal that indicates whether the cursor wraps to the next line when a character is written to the rightmost character position.
  • All: check for null parameters.

Ideas

More Repositories

1

gradle

Adaptable, fast automation for all
Groovy
16,800
star
2

kotlin-dsl-samples

Samples builds using the Gradle Kotlin DSL
Kotlin
3,706
star
3

gradle-profiler

A tool for gathering profiling and benchmarking information for Gradle builds
Java
1,279
star
4

gradle-completion

Gradle tab completion for bash and zsh
Shell
966
star
5

gradle-build-action

Execute your Gradle build and trigger dependency submission
672
star
6

android-cache-fix-gradle-plugin

Gradle plugin that fixes Android build caching problems.
Groovy
440
star
7

wrapper-validation-action

Gradle Wrapper Validation Action
256
star
8

oreilly-gradle-book-examples

Java
249
star
9

test-retry-gradle-plugin

Gradle plugin to retry tests that have failed to mitigate test flakiness.
Groovy
219
star
10

native-samples

Samples of modern build automation for native languages with Gradle
Java
153
star
11

actions

A collection of GitHub Actions to accelerate your Gradle Builds on GitHub
TypeScript
147
star
12

gradle-build-scan-quickstart

An example project to experience the Build Scanยฎ service of Gradle Enterprise with Gradle builds.
Kotlin
132
star
13

foojay-toolchains

Java Toolchain Resolve Plugin based on the foojay DiscoAPI
Kotlin
120
star
14

declarative-gradle

Declarative Gradle is a project targeting better isolation of concern and expressing any build in a clear and understandable way
Java
110
star
15

gradle-native

The home of Gradle's support for natively compiled languages
92
star
16

build-tool-training-exercises

Exercises for live gradle.com/training sessions
Java
90
star
17

gradle-enterprise-build-validation-scripts

Executable scripts to assist in validating that your Gradle and Maven builds are in an optimal state in terms of maximizing work avoidance when using Develocity.
Shell
86
star
18

github-dependency-graph-gradle-plugin

Gradle Plugin for Extracting Dependency Information to send to GitHub
Groovy
81
star
19

develocity-build-config-samples

Code samples that demonstrate how to customize your Develocity build configuration using Gradle, Maven, Bazel or sbt
Java
68
star
20

playframework

Gradle Play Support
Java
47
star
21

guides

The Gradle Guides at https://guides.gradle.org.
Java
47
star
22

wrapper-upgrade-gradle-plugin

Gradle plugin that detects and updates Gradle and Maven wrappers to the latest Gradle and Maven version.
Java
43
star
23

gradle-site-plugin

Kotlin
43
star
24

build-tool-roadmap

Gradle Build Tool roadmap
41
star
25

common-custom-user-data-gradle-plugin

Gradle plugin that enhances published build scans by adding a set of tags, links and custom values that have proven to be useful for many projects building with Develocity.
Java
41
star
26

kotlin-dsl-docs

Generates Kotlin DSL API reference
Kotlin
38
star
27

gradle-talks

A javascript based custom slide and build framework for presentations. Many of the Gradle engineers have been using this for their presentations. Those presentations are part of this repo and can be found in the talks directory.
Ruby
35
star
28

exemplar

Discover and verify code samples and services
Java
34
star
29

gradle2kts

Gradle Groovy to Gradle Kotlin conversion tool - discontinued spike
Kotlin
34
star
30

gradle-checksum

A Gradle plugin for creating checksums for files in your build.
Groovy
31
star
31

kotlin-dsl-conventions

Gradle Kotlin DSL conventional plugins
Kotlin
26
star
32

maven-build-scan-quickstart

An example project to experience the Build Scanยฎ service of Develocity with Maven builds.
Java
20
star
33

bazel-comparison

20
star
34

develocity-oss-projects

19
star
35

gradle-distributions

Repository for Gradle Build Tool distributions downloads
17
star
36

performance-comparisons

A set of synthetic projects used to benchmark Gradle against other build tools
16
star
37

community

Gradle Community content and Gradle Cookbook. Open for Contributions
HTML
16
star
38

gradle-java-modules

A (former) place for experimenting with Java 9's module system. Gradle officially supports Java Modules since version 6.4
Java
16
star
39

gcc2speedscope

Space usage analysis for the Gradle configuration cache via speedscope
Kotlin
15
star
40

cc-hackathon-2022

Configuration Cache Hackathon 2022
15
star
41

.github

Maintains all of the default policies for the Gradle organization
14
star
42

perf-enterprise-large

A large Java based build to use when benchmarking and profiling Gradle
Groovy
14
star
43

gradle-enterprise-export-api-samples

A repository of samples that demonstrate how to use the Gradle Enterprise Export API.
14
star
44

gradle-jdocbook

A Gradle plugin for jdocbook
Groovy
13
star
45

cucumber-companion

Maven & Gradle plugins providing convenient support for running Cucumber test directly from Maven/Gradle
Groovy
13
star
46

multi-project-composite-gradle-plugins-builds

Multi-project build using composite Gradle plugins
Kotlin
12
star
47

develocity-api-samples

A repository of samples that demonstrate how to use the Develocity API.
Java
12
star
48

webinar-getting-started-with-the-gradle-kotlin-dsl

Webinar - Getting Started with the Kotlin DSL
Kotlin
12
star
49

plugin-portal-requests

Gradle Plugin Portal issues and requests.
12
star
50

speed-challenge

Instructions and overview for the Gradle and Maven Speed Challenge event
11
star
51

imaginate

Using the Kotlin language for production, test and build makes it easier for everyone to work with your software code base. Letโ€™s go 100% Kotlin!
Kotlin
11
star
52

continuous-delivery-jump-start

Sample application used for training "Continuous Delivery Jump Start"
Java
11
star
53

santa-tracker-performance

Performance tests for Santa Tracker Android project
Shell
10
star
54

perf-android-large-2

Another large Android build for performance experiments
10
star
55

build-analysis-demo

Build data analysis applications
Kotlin
10
star
56

gradle-issue-reproducer

Template repository for providing Gradle issue reproducers
10
star
57

gradle-benchmark-base

Base scenarios for Gradle Profiler to benchmark Gradle builds
9
star
58

gradle-org-conventions-plugin

Java
9
star
59

gradle-hello-world-plugin

Groovy
9
star
60

gradle-profiler-plugin

Java
9
star
61

develocity-testing-annotations

Common annotations for Develocity and Test Retry
Java
9
star
62

tooling-commons

A small layer on top of the Gradle Tooling API that provides the Tooling Client and other convenience useful for IDE integration.
Java
9
star
63

gradle-client

Desktop application acting as a Gradle Tooling API client
Kotlin
9
star
64

configuration-cache-report

Kotlin
8
star
65

jfr-polyfill

A polyfill for JDK Flight Recorder (JFR) to avoid errors on JDKs that don't support JFR yet
Java
8
star
66

common-custom-user-data-maven-extension

Maven extension that enhances published build scans by adding a set of tags, links and custom values that have proven to be useful for many projects building with Develocity.
Java
8
star
67

develocity-gitlab-templates

GitLab CI/CD templates to automatically connect Gradle/Maven builds to Develocity
Shell
7
star
68

bt-dev-prod-data-collector

Data collector for Gradle Build Tool Developer productivity metrics
Kotlin
7
star
69

gradle-hazelcast-plugin

Groovy
6
star
70

source-resolution-demo

Java
6
star
71

gradle-enterprise-build-optimization-experiments

Self-guiding experiments to optimize the performance of your Gradle and Maven builds with Gradle Enterprise.
6
star
72

gradle-plugin-analyzer

Analyzes the bytecode of Gradle plugins
Java
6
star
73

integrations

A repository for Gradle Integrations and the related knowledge base
6
star
74

gradle-rules-configuration-workshop

6
star
75

gradle-project-templates

Learning day experiment: project init templates for Gradle
Java
5
star
76

greeting-plugin-example

Java
5
star
77

gradle-dependency-constrain

Java
5
star
78

maven-build-cache-unstable-inputs-samples

An example project containing a build with unstable inputs
Java
5
star
79

dpeuni-gradle-intro-devs-init

Hands-on exercise for DPE University
5
star
80

develocity-actions

Shared Github Actions
TypeScript
4
star
81

develocity-bamboo-plugin

Develocity plugin for Bamboo
Java
4
star
82

stable-plugins-dsl

Getting the plugins {} DSL block out of incubation
Java
4
star
83

perf-native-large

A Place to Profile Particularly Prickly Projects
C
4
star
84

backend-code-project

A scaffold for the Develocity Backend Engineer code project assignment.
Java
3
star
85

ide-smoke-tests

Java
3
star
86

gradle-all

A composite build that includes all the pieces of Gradle
Kotlin
3
star
87

ge-export

Java
3
star
88

webinar-dep-mgmt-part-1

Kotlin
3
star
89

gradle-to-trace-converter

Kotlin
3
star
90

provider-api-migration-testbed

A testbed to try out mitigation strategies for the provider API migration
Kotlin
3
star
91

gradle-model-vis

JavaScript
3
star
92

gradle-performance

Gradle performance benchmarks using the Gradle build tool itself
Shell
3
star
93

sbt-build-scan-quickstart

An example project showcasing how to experience the Build Scanยฎ service of Develocity with sbt
Scala
3
star
94

dpeuni-gradle-intro-devs-tasks

Hands-on exercise for DPE University
Java
3
star
95

declarative-samples-android-app

A sample Android application written in the Declarative Gradle DSL, using the prototype Declarative Android `androidApplication` Software Type defined in the `org.gradle.experimental.android-ecosystem` ecosystem plugin.
Kotlin
3
star
96

gradle-groovy-all

Replacement for groovy-all.jar discontinued in Groovy 2.5. This is intended to be used with Gradle only.
Kotlin
3
star
97

declarative-samples-java-app

A sample Java application written in the Declarative Gradle DSL, using the prototype Declarative Java java-application ecosystem plugin.
Java
2
star
98

apachecon2021

Instructions and code repository for the ApacheCon 2021 Gradle Virtual Booth Event
2
star
99

kotlin-relocation-test

Cache relocatability test for Kotlin using Spek
Groovy
2
star
100

github-dependency-submission-demo

Java
2
star