Migrate to jlibloader and produce maven artifacts

This commit is contained in:
2014-11-29 13:40:44 +00:00
parent f228bb4d10
commit c818598abc
2 changed files with 64 additions and 17 deletions

View File

@@ -79,8 +79,7 @@ libraries {
} }
all { all {
binaries.withType(SharedLibraryBinary) { binary -> binaries.withType(SharedLibraryBinary) { binary ->
cppCompiler.define 'JXINPUT_EXPORTS' cppCompiler.define 'JXINPUT_EXPORTS'
//cppCompiler.args '-Wall'
cppCompiler.args '-I' + jniHeadersDir cppCompiler.args '-I' + jniHeadersDir
if (targetPlatform.operatingSystem.macOsX) { if (targetPlatform.operatingSystem.macOsX) {
cppCompiler.args '-I', "/System/Library/Frameworks/JavaVM.framework/Headers" cppCompiler.args '-I', "/System/Library/Frameworks/JavaVM.framework/Headers"
@@ -101,21 +100,69 @@ libraries {
} }
} }
} }
tasks.withType(Upload) {
repositories {
mavenDeployer {
repository(url: uri('.maven'))
}
}
}
configurations {
jni
}
def deployer = uploadJni.repositories.mavenDeployer
binaries.withType(SharedLibraryBinary) { binary -> binaries.withType(SharedLibraryBinary) { binary ->
if (buildable) { if (!buildable) {
def builderTask = binary.tasks.builder return
jar.into("native/${targetPlatform.operatingSystem.name}/${targetPlatform.architecture.name}") { }
from builderTask.outputFile def variantName = "${targetPlatform.operatingSystem.name}-${targetPlatform.architecture.name}"
} def taskName = "jar-${variantName}"
jar.dependsOn builderTask def nativeJar = project.tasks.findByName(taskName)
} if (nativeJar == null) {
nativeJar = project.task(taskName, type: Jar) {
baseName = "${project.archivesBaseName}-$variantName"
}
artifacts {
jni nativeJar
}
def jniPom = deployer.addFilter(variantName) { artifact, file ->
return file == nativeJar.archivePath
}
jniPom.groupId = project.group
jniPom.artifactId = nativeJar.baseName
jniPom.version = project.version
jniPom.scopeMappings.mappings.clear()
}
def builderTask = binary.tasks.builder
def libraryDirectory = project.group.replace('.', '/') + "/${project.archivesBaseName}/${variantName}"
nativeJar.into(libraryDirectory) { from builderTask.outputFile }
nativeJar.dependsOn builderTask
} }
task sourcesJar(type: Jar, dependsOn: classes) { def mainPom = uploadArchives.repositories.mavenDeployer.pom
classifier = 'sources' mainPom.groupId = project.group
from sourceSets.main.java.srcDirs mainPom.artifactId = jar.baseName
mainPom.version = project.version
mainPom.scopeMappings.mappings.clear()
mainPom.withXml { provider ->
def node = provider.asNode()
def deps = node.appendNode('dependencies')
['windows-amd64', 'windows-i386'].each { platform ->
def dep = deps.appendNode('dependency')
dep.appendNode('groupId', project.group)
dep.appendNode('artifactId', "${project.archivesBaseName}-${platform}")
dep.appendNode('version', project.version)
}
def dep = deps.appendNode('dependency')
dep.appendNode('groupId', 'com.github.boukefalos')
dep.appendNode('artifactId', 'jlibloader')
dep.appendNode('version', '0.2')
} }
artifacts { jar {
archives sourcesJar from sourceSets.main.allSource
} }

View File

@@ -10,6 +10,8 @@ package de.hardcode.jxinput.directinput;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import com.github.boukefalos.jlibloader.Native;
/** /**
* DirectInputDriver: the connection to the Win32 joystick. * DirectInputDriver: the connection to the Win32 joystick.
* There is only one allowed, so the layout of this class is merely static. * There is only one allowed, so the layout of this class is merely static.
@@ -44,9 +46,7 @@ class DirectInputDriver
{ {
try try
{ {
// Load the native lib. Native.load("com.github.boukefalos", "jlibxinput");
System.loadLibrary( NATIVE_LIB_NAME );
init(); init();
} }
catch( SecurityException e ) catch( SecurityException e )