Skip to content

Commit

Permalink
Merge pull request #18 from cjstehno/development
Browse files Browse the repository at this point in the history
Library Resolver Update (v0.3)
  • Loading branch information
cjstehno authored Sep 23, 2016
2 parents 74b25c6 + 0aac4d9 commit 31601f0
Show file tree
Hide file tree
Showing 27 changed files with 1,105 additions and 592 deletions.
49 changes: 27 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Gradle Natives Plugin

A Gradle plugin to aid in working with Java-based project that provide supporting native libraries.

> ⚠️ Recently, JOGL and LWJGL have changed the layouts of their jars with respect to where the native libraries are located. This causes the plugin to stop working for those libraries. The way the plugin resolves the native libraries will need to be addressed and refactored. I don't really use this plugin, nor do I have a lot of time to work on it... so unless someone wants to create a pull request, it might be a while. If you use this plugin and this issue will cause problems for you, feel free to comment on [#15](https://github.com/cjstehno/gradle-natives/issues/15) to that effect - if there is enough interest, I will feel bad and fix it sooner. :-)
A Gradle plugin to aid in working with Java-based projects that provide supporting native libraries.

## Build

`gradlew clean build`
./gradlew clean build

## Installation

Expand All @@ -20,7 +18,7 @@ buildscript {
}
}
dependencies {
classpath "gradle.plugin.com.stehno:gradle-natives:0.2.4"
classpath "gradle.plugin.com.stehno:gradle-natives:0.3.0"
}
}
Expand All @@ -31,44 +29,51 @@ Alternately, you can use the new plug definition block in Gradle 2.1 and beyond.

```groovy
plugins {
id 'com.stehno.natives' version '0.2.4'
id 'com.stehno.natives' version '0.3.0'
}
```

The plugin is compiled on Java 7.

## Usage

To do anything useful with it, you need to configure it using the `natives` extension configuration, for example:
Without any additional configuration, the plugin will find all native libraries in all `compile` and `runtime` dependency configurations, for all platforms, and unpack them into
the `build/natives` directory of your project. You can configure this behavior by adding a `natives` block to your `build.gradle` file. The default behavior has the following configuration:

```groovy
natives {
jars = [ 'lwjgl-platform-2.9.1-natives-windows' ]
platforms = 'windows'
configurations = ['compile', 'runtime']
platforms = Platform.all()
outputDir = 'natives'
}
```

Which will find the specified jar in the project and extract the `.dll` files contained in it when the `unpackNatives` task is executed.
A `libraries` Closure may also be added to filter the resolved libraries, such as:

The `natives.jars` property accepts a single string or collection of strings representing names of jar files configured
on the project classpath (from other dependencies). If the string does not end with ".jar" the extension will be added.
```groovy
natives {
configurations = ['compile', 'runtime']
platforms = Platform.all()
outputDir = 'natives'
libraries {
exclude = ['somelib.dll']
}
}
```

The `platforms` property accepts a single string or single Platform enum value, as well as a collection of either (or both mixed). If no platforms
are specified (value left null), all supported platforms will be assumed.
There are two tasks provided by the plguin:

Then to add the native libraries to the build, simply run:
* `listNatives` - lists all of the native libraries resolved by the current configuration.
* `includeNatives` - includes (copies) the resolved native libraries into the configured output directory.

```
gradlew unpackNatives
```
## Warning

Which will add the native libraries to the build under the directory `build/natives/PLATFORM` (where PLATFORM is the name
of the configured platform).
This plugin only resolves native libraries that are on the project classpath as dependencies of the project (Gradle dependencies, either direct or transitive).

## References

* http://cjstehno.github.io/gradle-natives
* https://github.com/cjstehno/coffeaelectronica/wiki/Going-Native-with-Gradle
* Site: http://cjstehno.github.io/gradle-natives
* Blog Post: http://coffeaelectronica.com/blog/2014/going-native-with-gradle.html


[![Build Status](https://drone.io/github.com/cjstehno/gradle-natives/status.png)](https://drone.io/github.com/cjstehno/gradle-natives/latest)
53 changes: 24 additions & 29 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,52 +1,40 @@
/*
* Copyright (c) 2014 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id 'com.gradle.plugin-publish' version '0.9.0'
id 'groovy'
id 'com.github.hierynomus.license' version '0.13.1'
id 'com.gradle.plugin-publish' version '0.9.4'
id 'maven-publish'
id 'java-gradle-plugin'
}

apply plugin:'groovy'

group='com.stehno'
version='0.2.4'
group = 'com.stehno'
version = '0.3.0'

// explicit requests were made to build under Java 7
sourceCompatibility = 7
targetCompatibility = 7

repositories {
jcenter()
jcenter()
}

dependencies {
compile gradleApi()
compile localGroovy()
compile gradleApi()
compile localGroovy()

testCompile 'junit:junit:4.11'
testCompile 'org.mockito:mockito-all:1.9.5'
testCompile 'junit:junit:4.12'
testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
exclude module: 'groovy-all'
}
}

task wrapper( type:Wrapper) {
gradleVersion = '2.3'
task wrapper(type: Wrapper) {
gradleVersion = '2.14'
}

pluginBundle {
website = 'http://cjstehno.github.io/gradle-natives/'
vcsUrl = 'https://github.com/cjstehno/gradle-natives'
description = 'Gradle plugin to aid in managing native libraries associated with Java-based projects.'
description = 'Gradle plugin to aid in handling native libraries associated with Java-based projects.'
tags = ['gradle', 'groovy', 'native']

plugins {
Expand All @@ -56,3 +44,10 @@ pluginBundle {
}
}
}

license {
header rootProject.file('license_header.txt')
ext.name = 'Christopher J. Stehno'
ext.email = '[email protected]'
ext.year = Calendar.instance.get(Calendar.YEAR)
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Apr 07 17:30:29 CDT 2015
#Sat Sep 17 06:59:08 CDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-all.zip
57 changes: 31 additions & 26 deletions gradlew
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,30 @@
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

Expand All @@ -30,6 +48,7 @@ die ( ) {
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
Expand All @@ -40,31 +59,11 @@ case "`uname`" in
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
Expand All @@ -90,7 +89,7 @@ location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
Expand All @@ -114,6 +113,7 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
Expand Down Expand Up @@ -161,4 +161,9 @@ function splitJvmOpts() {
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
14 changes: 4 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

Expand Down Expand Up @@ -46,10 +46,9 @@ echo location of your Java installation.
goto fail

:init
@rem Get command-line arguments, handling Windowz variants
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

:win9xME_args
@rem Slurp the command line arguments.
Expand All @@ -60,11 +59,6 @@ set _SKIP=2
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line
Expand Down
13 changes: 13 additions & 0 deletions license_header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright (C) ${year} ${name} <${email}>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Loading

0 comments on commit 31601f0

Please sign in to comment.