From c3493d3d939b8fc51cd52d4085e0ce9c94ab39c1 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Wed, 18 Sep 2024 18:19:25 -0500 Subject: [PATCH] Make slf4j optional, fall back on j.u.logging In order to avoid the hard dependency on slf4j, this patch abstracts the Logger interface and LoggerFactory factory to fall back on a java.util.logging-based implementation if slf4j is not present. Fixes #1094 --- Makefile | 9 ++------- Makefile.common | 12 ++++-------- README.adoc | 7 +++---- pom.xml | 1 + src/main/java/org/sqlite/JDBC.java | 8 ++++---- src/main/java/org/sqlite/SQLiteJDBCLoader.java | 4 ++-- src/main/java/org/sqlite/core/NativeDB.java | 4 ++-- .../java/org/sqlite/jdbc3/JDBC3DatabaseMetaData.java | 4 ++-- src/main/java/org/sqlite/jdbc3/JDBC3Statement.java | 4 ++-- src/main/java/org/sqlite/util/OSInfo.java | 2 -- .../org/sqlite/architecture/CodingRulesTest.java | 2 -- 11 files changed, 22 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index a698f2645..90ebf4ede 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,6 @@ DOCKER_RUN_OPTS=--rm MVN:=mvn CODESIGN:=docker run $(DOCKER_RUN_OPTS) -v $$PWD:/workdir gotson/rcodesign sign SRC:=src/main/java -JAVA_CLASSPATH:=$(TARGET)/classpath/slf4j-api.jar SQLITE_OUT:=$(TARGET)/$(sqlite)-$(OS_NAME)-$(OS_ARCH) SQLITE_OBJ?=$(SQLITE_OUT)/sqlite3.o SQLITE_ARCHIVE:=$(TARGET)/$(sqlite)-amal.zip @@ -44,19 +43,15 @@ $(SQLITE_UNPACKED): $(SQLITE_ARCHIVE) (mv $(TARGET)/tmp.$(version)/$(SQLITE_AMAL_PREFIX) $(TARGET) && rmdir $(TARGET)/tmp.$(version)) || mv $(TARGET)/tmp.$(version)/ $(TARGET)/$(SQLITE_AMAL_PREFIX) touch $@ -$(JAVA_CLASSPATH): - @mkdir -p $(@D) - curl -L -f -o$@ https://search.maven.org/remotecontent?filepath=org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar - $(TARGET)/common-lib/org/sqlite/%.class: src/main/java/org/sqlite/%.java @mkdir -p $(@D) $(JAVAC) -source 1.6 -target 1.6 -sourcepath $(SRC) -d $(TARGET)/common-lib $< jni-header: $(TARGET)/common-lib/NativeDB.h -$(TARGET)/common-lib/NativeDB.h: src/main/java/org/sqlite/core/NativeDB.java $(JAVA_CLASSPATH) +$(TARGET)/common-lib/NativeDB.h: src/main/java/org/sqlite/core/NativeDB.java @mkdir -p $(TARGET)/common-lib - $(JAVAC) -cp $(JAVA_CLASSPATH) -d $(TARGET)/common-lib -sourcepath $(SRC) -h $(TARGET)/common-lib src/main/java/org/sqlite/core/NativeDB.java + $(JAVAC) -d $(TARGET)/common-lib -sourcepath $(SRC) -h $(TARGET)/common-lib src/main/java/org/sqlite/core/NativeDB.java mv target/common-lib/org_sqlite_core_NativeDB.h target/common-lib/NativeDB.h test: diff --git a/Makefile.common b/Makefile.common index fb5dd4810..a75d78041 100644 --- a/Makefile.common +++ b/Makefile.common @@ -9,24 +9,20 @@ JAVAC := "$$JAVA_HOME/bin/javac" JAVAH := "$$JAVA_HOME/bin/javah" TARGET := target -SRC:=src/main/java OSINFO_CLASS := org.sqlite.util.OSInfo OSINFO_PROG := lib/org/sqlite/util/OSInfo.class -JAVA_CLASSPATH:=$(TARGET)/classpath/slf4j-api.jar ## building OSInfo.java ifeq ("$(wildcard $(OSINFO_PROG))","") $(info Building OSInfo tool) -$(shell mkdir -p $(TARGET)/classpath) -$(shell curl -L -f -o$(JAVA_CLASSPATH) https://search.maven.org/remotecontent?filepath=org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar) -$(shell $(JAVAC) -cp $(JAVA_CLASSPATH) -sourcepath $(SRC) -d lib src/main/java/org/sqlite/util/OSInfo.java) +$(shell $(JAVAC) -cp src/main/java -d lib src/main/java/org/sqlite/util/OSInfo.java) endif ifndef OS_NAME -OS_NAME := $(shell $(JAVA) -cp lib:$(JAVA_CLASSPATH) $(OSINFO_CLASS) --os) +OS_NAME := $(shell $(JAVA) -cp lib $(OSINFO_CLASS) --os) endif ifndef OS_ARCH -OS_ARCH := $(shell $(JAVA) -cp lib:$(JAVA_CLASSPATH) $(OSINFO_CLASS) --arch) +OS_ARCH := $(shell $(JAVA) -cp lib $(OSINFO_CLASS) --arch) endif # Windows uses different path separators @@ -59,7 +55,7 @@ ifeq (,$(findstring $(strip $(target)),$(known_targets))) target := Default endif -$(info Will build using target: $(target) (detected os: $(OS_NAME), arch: $(OS_ARCH))) +$(info Will build using target: $(target) (detected os: $(OS_NAME) arch: $(OS_ARCH))) # cross-compilation toolchain prefix (e.g. "arm-linux-gnueabi-") CROSS_PREFIX := diff --git a/README.adoc b/README.adoc index 05da93e19..4a3a047ce 100644 --- a/README.adoc +++ b/README.adoc @@ -29,19 +29,18 @@ SQLite JDBC is a library for accessing SQLite databases through the JDBC API. Fo . <> `sqlite-jdbc-{project-version}.jar` then append this jar file into your classpath. -. https://search.maven.org/remotecontent?filepath=org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar[Download] `slf4j-api-1.7.36.jar` then append this jar file into your classpath. . Open a SQLite database connection from your code. (see the example below) === Example usage -Assuming `sqlite-jdbc-{project-version}.jar` and `slf4j-api-1.7.36.jar` are placed in the current directory. +Assuming `sqlite-jdbc-{project-version}.jar` is placed in the current directory. [source,shell,subs="attributes+"] ---- > javac Sample.java -> java -classpath ".;sqlite-jdbc-{project-version}.jar;slf4j-api-1.7.36.jar" Sample # in Windows +> java -classpath ".;sqlite-jdbc-{project-version}.jar" Sample # in Windows or -> java -classpath ".:sqlite-jdbc-{project-version}.jar:slf4j-api-1.7.36.jar" Sample # in macOS or Linux +> java -classpath ".:sqlite-jdbc-{project-version}.jar" Sample # in macOS or Linux name = leo id = 1 name = yui diff --git a/pom.xml b/pom.xml index 7f3d2782e..81d6cfb0a 100644 --- a/pom.xml +++ b/pom.xml @@ -415,6 +415,7 @@ org.slf4j slf4j-api 1.7.36 + compile