Skip to content

Commit 9321917

Browse files
authored
Merge pull request #116 from domaframework/support-module
Minimal support for module system
2 parents 5c03dac + 85a309f commit 9321917

File tree

13 files changed

+179
-70
lines changed

13 files changed

+179
-70
lines changed

.github/workflows/ci.yml

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,39 @@ jobs:
1212
runs-on: ubuntu-latest
1313
timeout-minutes: 30
1414

15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Set up JDK 8
19+
uses: actions/setup-java@v2
20+
with:
21+
distribution: zulu
22+
java-version: 8
23+
cache: maven
24+
25+
- name: Grant execute permission for mvnw
26+
run: chmod +x mvnw
27+
28+
- name: Test with Maven
29+
run: ./mvnw test -B
30+
31+
- name: Upload reports
32+
if: failure()
33+
uses: actions/upload-artifact@v2
34+
with:
35+
name: reports
36+
path: ./**/target/surefire-reports
37+
38+
test-matrix:
39+
if: contains(github.event.head_commit.message, '[skip ci]') == false
40+
runs-on: ubuntu-latest
41+
timeout-minutes: 30
42+
needs: [ test ]
43+
1544
strategy:
1645
matrix:
17-
java: [ 8, 11, 17 ]
18-
spring-boot-version: [ 2.2.13.RELEASE, 2.3.12.RELEASE, 2.4.10, 2.5.4 ]
46+
java: [ 11, 17 ]
47+
spring-boot-version: [ 2.2.13.RELEASE, 2.3.12.RELEASE, 2.4.12, 2.5.6 ]
1948

2049
steps:
2150
- uses: actions/checkout@v2
@@ -40,9 +69,10 @@ jobs:
4069
name: reports
4170
path: ./**/target/surefire-reports
4271

43-
deploy:
44-
if: github.event_name == 'push' && contains(github.event.head_commit.message, '[skip ci]') == false
72+
test-slf4j-backward-compatible:
73+
if: contains(github.event.head_commit.message, '[skip ci]') == false
4574
runs-on: ubuntu-latest
75+
timeout-minutes: 30
4676
needs: [ test ]
4777

4878
steps:
@@ -53,16 +83,38 @@ jobs:
5383
with:
5484
distribution: zulu
5585
java-version: 8
86+
cache: maven
5687

5788
- name: Grant execute permission for mvnw
5889
run: chmod +x mvnw
5990

60-
- name: Cache Maven packages
61-
uses: actions/cache@v2
91+
- name: Test with Maven
92+
run: ./mvnw -B compile -Pbackward-compatible && ./mvnw -B test -Dmaven.main.skip=true -Ddoma.version=2.49.0
93+
94+
- name: Upload reports
95+
if: failure()
96+
uses: actions/upload-artifact@v2
97+
with:
98+
name: reports
99+
path: ./**/target/surefire-reports
100+
101+
deploy:
102+
if: github.event_name == 'push' && contains(github.event.head_commit.message, '[skip ci]') == false
103+
runs-on: ubuntu-latest
104+
needs: [ test-matrix, test-slf4j-backward-compatible ]
105+
106+
steps:
107+
- uses: actions/checkout@v2
108+
109+
- name: Set up JDK 8
110+
uses: actions/setup-java@v2
62111
with:
63-
path: ~/.m2
64-
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
65-
restore-keys: ${{ runner.os }}-m2
112+
distribution: zulu
113+
java-version: 8
114+
cache: maven
115+
116+
- name: Grant execute permission for mvnw
117+
run: chmod +x mvnw
66118

67119
- name: Release Maven package
68120
uses: samuelmeuli/action-maven-publish@v1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Add the following dependencies to `pom.xml` so that we can use Doma with Spring
7171
<groupId>org.seasar.doma</groupId>
7272
<artifactId>doma-processor</artifactId>
7373
<version>2.30.0</version>
74-
<scope>provided</scope>
74+
<optional>true</optional>
7575
</dependency>
7676
```
7777

doma-spring-boot-autoconfigure/pom.xml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
<relativePath>../pom.xml</relativePath>
1717
</parent>
1818

19-
<properties>
20-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21-
<java.version>1.8</java.version>
22-
<rootDir>${project.basedir}/..</rootDir>
23-
</properties>
24-
2519
<dependencies>
2620
<dependency>
2721
<groupId>org.seasar.doma.boot</groupId>
@@ -32,6 +26,7 @@
3226
<groupId>org.seasar.doma</groupId>
3327
<artifactId>doma-slf4j</artifactId>
3428
<version>${doma.version}</version>
29+
<optional>true</optional>
3530
</dependency>
3631
<dependency>
3732
<groupId>org.springframework</groupId>
@@ -73,4 +68,19 @@
7368
</dependency>
7469
</dependencies>
7570

71+
<build>
72+
<plugins>
73+
<plugin>
74+
<groupId>org.apache.maven.plugins</groupId>
75+
<artifactId>maven-jar-plugin</artifactId>
76+
<configuration>
77+
<archive>
78+
<manifestEntries>
79+
<Automatic-Module-Name>doma.spring.boot.autoconfigure</Automatic-Module-Name>
80+
</manifestEntries>
81+
</archive>
82+
</configuration>
83+
</plugin>
84+
</plugins>
85+
</build>
7686
</project>

doma-spring-boot-autoconfigure/src/main/java/org/seasar/doma/boot/autoconfigure/DomaProperties.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
import java.util.function.Supplier;
66

7+
import org.apache.commons.logging.Log;
8+
import org.apache.commons.logging.LogFactory;
79
import org.seasar.doma.jdbc.*;
810
import org.seasar.doma.jdbc.dialect.*;
11+
import org.seasar.doma.slf4j.Slf4jJdbcLogger;
912
import org.springframework.boot.context.properties.ConfigurationProperties;
1013

1114
/**
@@ -227,7 +230,24 @@ public Naming naming() {
227230

228231
public static enum JdbcLoggerType {
229232
JUL(UtilLoggingJdbcLogger::new),
230-
SLF4J(Slf4jJdbcLogger::new);
233+
SLF4J(JdbcLoggerType::slf4jJdbcLogger);
234+
235+
private static JdbcLogger slf4jJdbcLogger() {
236+
try {
237+
return new Slf4jJdbcLogger();
238+
} catch (NoClassDefFoundError e) {
239+
Log logger = LogFactory.getLog(JdbcLoggerType.class);
240+
logger.info(
241+
"org.seasar.doma.slf4j.Slf4jJdbcLogger is not found, fallback to org.seasar.doma.jdbc.Slf4jJdbcLogger");
242+
try {
243+
return (JdbcLogger) Class.forName("org.seasar.doma.jdbc.Slf4jJdbcLogger")
244+
.getConstructor().newInstance();
245+
} catch (ReflectiveOperationException roe) {
246+
logger.warn("org.seasar.doma.jdbc.Slf4jJdbcLogger could not be instantiated either.", roe);
247+
}
248+
throw e;
249+
}
250+
}
231251

232252
private final Supplier<JdbcLogger> constructor;
233253

doma-spring-boot-autoconfigure/src/test/java/org/seasar/doma/boot/autoconfigure/DomaAutoConfigurationTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.seasar.doma.jdbc.NoCacheSqlFileRepository;
2525
import org.seasar.doma.jdbc.UtilLoggingJdbcLogger;
2626
import org.seasar.doma.jdbc.SqlFileRepository;
27-
import org.seasar.doma.jdbc.UtilLoggingJdbcLogger;
2827
import org.seasar.doma.jdbc.criteria.Entityql;
2928
import org.seasar.doma.jdbc.criteria.NativeSql;
3029
import org.seasar.doma.jdbc.dialect.Dialect;
@@ -242,6 +241,19 @@ public void testDialectByDomaPropertiesIgnoreDataSourceUrl() {
242241
assertThat(dialect, is(instanceOf(PostgresDialect.class)));
243242
}
244243

244+
@Test
245+
public void testJdbcLoggerSlf4J() {
246+
MutablePropertySources sources = context.getEnvironment()
247+
.getPropertySources();
248+
Map<String, Object> source = new HashMap<>();
249+
source.put("doma.jdbcLogger", "SLF4J");
250+
sources.addFirst(new MapPropertySource("test", source));
251+
this.context.register(DomaAutoConfiguration.class, DataSourceAutoConfiguration.class);
252+
this.context.refresh();
253+
JdbcLogger jdbcLogger = this.context.getBean(JdbcLogger.class);
254+
assertThat(jdbcLogger.getClass().getSimpleName(), is("Slf4jJdbcLogger"));
255+
}
256+
245257
@After
246258
public void tearDown() {
247259
if (this.context != null) {

doma-spring-boot-core/pom.xml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
<relativePath>../pom.xml</relativePath>
1717
</parent>
1818

19-
<properties>
20-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21-
<java.version>1.8</java.version>
22-
<rootDir>${project.basedir}/..</rootDir>
23-
</properties>
24-
2519
<dependencies>
2620
<dependency>
2721
<groupId>org.seasar.doma</groupId>
@@ -72,4 +66,19 @@
7266
</dependency>
7367
</dependencies>
7468

69+
<build>
70+
<plugins>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-jar-plugin</artifactId>
74+
<configuration>
75+
<archive>
76+
<manifestEntries>
77+
<Automatic-Module-Name>doma.spring.boot.core</Automatic-Module-Name>
78+
</manifestEntries>
79+
</archive>
80+
</configuration>
81+
</plugin>
82+
</plugins>
83+
</build>
7584
</project>

doma-spring-boot-samples/doma-spring-boot-sample-entity-listener/pom.xml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@
1616
<relativePath>../pom.xml</relativePath>
1717
</parent>
1818

19-
<properties>
20-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21-
<java.version>1.8</java.version>
22-
<rootDir>${project.basedir}/../..</rootDir>
23-
</properties>
24-
2519
<dependencies>
2620
<dependency>
2721
<groupId>org.seasar.doma</groupId>
2822
<artifactId>doma-processor</artifactId>
2923
<version>${doma.version}</version>
30-
<scope>provided</scope>
24+
<optional>true</optional>
3125
</dependency>
3226
<dependency>
3327
<groupId>org.seasar.doma.boot</groupId>
@@ -74,5 +68,4 @@
7468
</plugins>
7569
</build>
7670

77-
7871
</project>

doma-spring-boot-samples/doma-spring-boot-sample-event-handler/pom.xml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@
1616
<relativePath>../pom.xml</relativePath>
1717
</parent>
1818

19-
<properties>
20-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21-
<java.version>1.8</java.version>
22-
<rootDir>${project.basedir}/../..</rootDir>
23-
</properties>
24-
2519
<dependencies>
2620
<dependency>
2721
<groupId>org.seasar.doma</groupId>
2822
<artifactId>doma-processor</artifactId>
2923
<version>${doma.version}</version>
30-
<scope>provided</scope>
24+
<optional>true</optional>
3125
</dependency>
3226
<dependency>
3327
<groupId>org.seasar.doma.boot</groupId>
@@ -74,5 +68,4 @@
7468
</plugins>
7569
</build>
7670

77-
7871
</project>

doma-spring-boot-samples/doma-spring-boot-sample-simple/pom.xml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@
1616
<relativePath>../pom.xml</relativePath>
1717
</parent>
1818

19-
<properties>
20-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21-
<java.version>1.8</java.version>
22-
<rootDir>${project.basedir}/../..</rootDir>
23-
</properties>
24-
2519
<dependencies>
2620
<dependency>
2721
<groupId>org.seasar.doma</groupId>
2822
<artifactId>doma-processor</artifactId>
2923
<version>${doma.version}</version>
30-
<scope>provided</scope>
24+
<optional>true</optional>
3125
</dependency>
3226
<dependency>
3327
<groupId>org.seasar.doma.boot</groupId>
@@ -70,5 +64,4 @@
7064
</plugins>
7165
</build>
7266

73-
7467
</project>

doma-spring-boot-samples/doma-spring-boot-sample-two-datasource/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,11 @@
1616
<relativePath>../pom.xml</relativePath>
1717
</parent>
1818

19-
<properties>
20-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21-
<java.version>1.8</java.version>
22-
<rootDir>${project.basedir}/../..</rootDir>
23-
</properties>
24-
2519
<dependencies>
2620
<dependency>
2721
<groupId>org.seasar.doma</groupId>
2822
<artifactId>doma-processor</artifactId>
2923
<version>${doma.version}</version>
30-
<scope>compile</scope>
3124
<optional>true</optional>
3225
</dependency>
3326
<dependency>
@@ -57,5 +50,4 @@
5750
</plugins>
5851
</build>
5952

60-
6153
</project>

0 commit comments

Comments
 (0)