Package init

This commit is contained in:
dogsheng 2019-12-14 18:58:38 +08:00
parent 7b5b976e28
commit a353b6ca0d
7 changed files with 227 additions and 75 deletions

View File

@ -0,0 +1,36 @@
From eaa1c5968d3953ea59b01cc2620da0a9eabb17d4 Mon Sep 17 00:00:00 2001
From: Michael Simacek <msimacek@redhat.com>
Date: Wed, 20 Sep 2017 16:12:27 +0300
Subject: [PATCH 1/2] Load lib from system
Try to load native library from /usr/lib*/native-platform
instead of extractDir or classpath.
---
.../platform/internal/NativeLibraryLocator.java | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/main/java/net/rubygrapefruit/platform/internal/NativeLibraryLocator.java b/src/main/java/net/rubygrapefruit/platform/internal/NativeLibraryLocator.java
index d08a40d..332187a 100755
--- a/src/main/java/net/rubygrapefruit/platform/internal/NativeLibraryLocator.java
+++ b/src/main/java/net/rubygrapefruit/platform/internal/NativeLibraryLocator.java
@@ -32,6 +32,17 @@ public class NativeLibraryLocator {
public File find(LibraryDef libraryDef) throws IOException {
String resourceName = String.format("net/rubygrapefruit/platform/%s/%s", libraryDef.platform, libraryDef.name);
+ String bits = "";
+
+ if (System.getProperty("os.arch").contains("64")) {
+ bits = "64";
+ }
+
+ File usrLibFile = new File("/usr/lib" + bits + "/native-platform/" + libraryDef.name);
+ if (usrLibFile.isFile()) {
+ return usrLibFile;
+ }
+
if (extractDir != null) {
File libFile = new File(extractDir, String.format("%s/%s/%s", NativeLibraryFunctions.VERSION, libraryDef.platform, libraryDef.name));
File lockFile = new File(libFile.getParentFile(), libFile.getName() + ".lock");
--
2.13.5

View File

@ -0,0 +1,50 @@
From c022c0a3318dd2d0471440ca73ff35ee75f69169 Mon Sep 17 00:00:00 2001
From: Michael Simacek <msimacek@redhat.com>
Date: Wed, 20 Sep 2017 17:51:37 +0300
Subject: [PATCH 2/2] Use library name without arch
---
.../java/net/rubygrapefruit/platform/internal/Platform.java | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/main/java/net/rubygrapefruit/platform/internal/Platform.java b/src/main/java/net/rubygrapefruit/platform/internal/Platform.java
index 3cb3f63..7120a9f 100755
--- a/src/main/java/net/rubygrapefruit/platform/internal/Platform.java
+++ b/src/main/java/net/rubygrapefruit/platform/internal/Platform.java
@@ -40,11 +40,7 @@ public abstract class Platform {
platform = new Window64Bit();
}
} else if (osName.contains("linux")) {
- if (arch.equals("amd64") || arch.equals("x86_64")) {
- platform = new Linux64Bit();
- } else if (arch.equals("i386") || arch.equals("x86")) {
- platform = new Linux32Bit();
- }
+ platform = new Linux();
} else if (osName.contains("os x") || osName.contains("darwin")) {
if (arch.equals("i386")) {
platform = new MacOs32Bit();
@@ -240,7 +236,7 @@ public abstract class Platform {
}
}
- private abstract static class Linux extends Unix {
+ private static class Linux extends Unix {
@Override
public <T extends NativeIntegration> T get(Class<T> type, NativeLibraryLoader nativeLibraryLoader) {
return super.get(type, nativeLibraryLoader);
@@ -255,6 +251,11 @@ public abstract class Platform {
public boolean isLinux() {
return true;
}
+
+ @Override
+ public String getId() {
+ return "linux";
+ }
}
private static class Linux32Bit extends Linux {
--
2.13.5

View File

@ -1,36 +0,0 @@
# native-platform
#### Description
{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
#### Software Architecture
Software architecture description
#### Installation
1. xxxx
2. xxxx
3. xxxx
#### Instructions
1. xxxx
2. xxxx
3. xxxx
#### Contribution
1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request
#### Gitee Feature
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)

View File

@ -1,39 +0,0 @@
# native-platform
#### 介绍
{**以下是码云平台说明,您可以替换此简介**
码云是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN。专为开发者提供稳定、高效、安全的云端软件开发协作平台
无论是个人、团队、或是企业,都能够用码云实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
#### 软件架构
软件架构说明
#### 安装教程
1. xxxx
2. xxxx
3. xxxx
#### 使用说明
1. xxxx
2. xxxx
3. xxxx
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
#### 码云特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目
5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)

BIN
native-platform-0.14.tar.gz Normal file

Binary file not shown.

View File

@ -0,0 +1,87 @@
# Description: Use make as buildsystem instead of Gradle to
# avoid a circular dependencies between gradle and native-platform.
# This is very minimalistic Makefile so it will only work for
# Debian use case for now.
# Author: Damien Raude-Morvan <drazzib@debian.org>
# Adapted for Fedora by: gil cattaneo <puntogil@libero.it>
CXX=g++
STRIP=strip
# which is the best solution?
JOPT_JAR=$(shell build-classpath jopt-simple)
#JOPT_JAR=$(shell locate jopt-simple.jar)
IDIR=src/shared/headers
SRCDIR=src/main/cpp
#SRCSHAREDIR=src/shared/cpp
#SRCCURSESDIR=src/curses/cpp
JSRCDIR=src/main/java
BUILD=build
IGEN=$(BUILD)/headers
JCLASSESDIR=$(BUILD)/classes
JDOCDIR=$(BUILD)/docs/javadoc
ODIR=$(BUILD)/binaries
JAR=$(BUILD)/native-platform.jar
known_os_archs :=
JAR_ARCH=$(BUILD)/native-platform-linux.jar
JTARGET=1.5
JSOURCE=1.5
INCLUDE=-I$(IDIR) -I$(IGEN) -I/usr/include -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
#LDLIBS=-lncurses
_OBJ_STD = generic.o generic_posix.o linux.o osx.o posix.o win.o unix_strings.o
_OBJ_CURSES = generic.o generic_posix.o curses.o unix_strings.o
OBJ_STD = $(patsubst %,$(ODIR)/%,$(_OBJ_STD))
OBJ_CURSES = $(patsubst %,$(ODIR)/%,$(_OBJ_CURSES))
_JAVA = $(shell find $(JSRCDIR) -name "*.java" -print)
.PHONY: clean jar javadoc
build: $(ODIR)/libnative-platform.so $(ODIR)/libnative-platform-curses.so jar javadoc arch-jar
$(ODIR)/libnative-platform.so: $(OBJ_STD)
$(CXX) -shared -fPIC $(CFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^
$(STRIP) $@
$(ODIR)/libnative-platform-curses.so: $(OBJ_CURSES)
$(CXX) $(CFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -lcurses -shared -fPIC -o $@ $^
$(STRIP) $@
$(JCLASSESDIR)/%.class: javafiles-list
mkdir -p $(JCLASSESDIR)
$(JAVA_HOME)/bin/javac -source $(JTARGET) -target $(JSOURCE) -d $(JCLASSESDIR) -classpath $(JOPT_JAR) @javafiles-list
javafiles-list: $(_JAVA)
echo $^ > javafiles-list
javadoc: javafiles-list
mkdir -p $(JDOCDIR)
$(JAVA_HOME)/bin/javadoc -d $(JDOCDIR) -classpath $(JOPT_JAR) @javafiles-list
jar: $(JCLASSESDIR)/%.class
mkdir -p $(JDOCDIR)
(cd $(JCLASSESDIR) ; $(JAVA_HOME)/bin/jar cf ../../$(JAR) .)
arch-jar: $(ODIR)/libnative-platform.so $(ODIR)/libnative-platform-curses.so
(cd $(ODIR) ; $(JAVA_HOME)/bin/jar cf ../../$(JAR_ARCH) *.so)
$(ODIR)/%.o: $(SRCDIR)/%.cpp $(IGEN)/native.h
mkdir -p $(ODIR)
$(CXX) $(CFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(INCLUDE) -fPIC -c -o $@ $<
$(IGEN)/native.h: $(JCLASSESDIR)/%.class
mkdir -p $(IGEN)
$(JAVA_HOME)/bin/javah -o $(IGEN)/native.h -classpath $(JCLASSESDIR) \
net.rubygrapefruit.platform.internal.jni.NativeLibraryFunctions \
net.rubygrapefruit.platform.internal.jni.PosixFileFunctions \
net.rubygrapefruit.platform.internal.jni.PosixFileSystemFunctions \
net.rubygrapefruit.platform.internal.jni.PosixProcessFunctions \
net.rubygrapefruit.platform.internal.jni.PosixTerminalFunctions \
net.rubygrapefruit.platform.internal.jni.TerminfoFunctions \
net.rubygrapefruit.platform.internal.jni.WindowsConsoleFunctions \
net.rubygrapefruit.platform.internal.jni.WindowsHandleFunctions \
net.rubygrapefruit.platform.internal.jni.WindowsRegistryFunctions
clean:
-rm javafiles-list
-rm -Rf $(BUILD)

54
native-platform.spec Normal file
View File

@ -0,0 +1,54 @@
%global debug_package %{nil}
Name: native-platform
Version: 0.14
Release: 15
Summary: Java bindings for various native APIs
License: ASL 2.0
URL: https://github.com/adammurdoch/native-platform
Source0: native-platform-%{version}.tar.gz
Source1: native-platform-0.7-Makefile
Patch0: 0001-Load-lib-from-system.patch
Patch1: 0002-Use-library-name-without-arch.patch
BuildRequires: gcc-c++ java-devel javapackages-local ncurses-devel jopt-simple
Obsoletes: native-platform-javadoc < %{version}-%{release}
Provides: native-platform-javadoc = %{version}-%{release}
%description
A collection of cross-platform Java APIs for various native APIs.
%prep
%autosetup -n native-platform-%{version} -p1
find . -name "*.jar" -delete
find . -name "*.class" -delete
cp -p %{SOURCE1} Makefile
chmod 644 readme.md
mv src/curses/cpp/*.cpp src/main/cpp
mv src/shared/cpp/* src/main/cpp
%build
CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS ;
CPPFLAGS="${CPPFLAGS:-%optflags}" ; export CPPFLAGS ;
CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS ;
LDFLAGS="${LDFLAGS:-%__global_ldflags}"; export LDFLAGS;
%{make_build} JAVA_HOME=%{_jvmdir}/java
%mvn_artifact net.rubygrapefruit:native-platform:%{version} build/native-platform.jar
%mvn_file : native-platform
%install
%mvn_install -J build/docs/javadoc
mkdir -p %{buildroot}%{_libdir}/native-platform
install -pm 0755 build/binaries/libnative-platform-curses.so %{buildroot}%{_libdir}/native-platform/
install -pm 0755 build/binaries/libnative-platform.so %{buildroot}%{_libdir}/native-platform/
%files
%attr(0644,root,root) %{_datadir}/maven-metadata/native-platform.xml
%attr(0644,root,root) /usr/lib/java/native-platform.jar
%{_libdir}/native-platform
%doc readme.md
%license LICENSE
%{_javadocdir}/%{name}
%changelog
* Thu Dec 7 2019 openEuler Buildteam <buildteam@openeuler.org> - 0.14-15
- Package init