Skip to content

Commit 6b6c246

Browse files
committed
CGLIB made internal, MyBatis now should be able to enable lazyLoading without checking cglib Enhancer in the classpath
fixed OSGi issue
1 parent b1bb2a9 commit 6b6c246

File tree

2 files changed

+88
-23
lines changed

2 files changed

+88
-23
lines changed

pom.xml

Lines changed: 87 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<properties>
2525
<findbugs.onlyAnalyze>org.apache.ibatis.*</findbugs.onlyAnalyze>
2626
<clirr.comparisonVersion>3.0.2</clirr.comparisonVersion>
27+
<osgi.import>!net.sf.cglib.proxy,!org.apache.commons.logging,!org.apache.log4j,!org.slf4j,*</osgi.import>
2728
</properties>
2829
<reporting>
2930
<plugins>
@@ -42,6 +43,81 @@
4243
</reporting>
4344
<build>
4445
<plugins>
46+
<plugin>
47+
<groupId>org.sonatype.plugins</groupId>
48+
<artifactId>jarjar-maven-plugin</artifactId>
49+
<version>1.3</version>
50+
<configuration>
51+
<includes>
52+
<include>*:asm</include>
53+
<include>*:cglib</include>
54+
</includes>
55+
<rules>
56+
<!--
57+
| relocate CGLIB + ASM as internal stuff
58+
-->
59+
<rule>
60+
<pattern>net.sf.cglib.*</pattern>
61+
<result>org.apache.ibatis.internal.cglib.$@1</result>
62+
</rule>
63+
<rule>
64+
<pattern>net.sf.cglib.**.*</pattern>
65+
<result>org.apache.ibatis.internal.cglib.@1.$@2</result>
66+
</rule>
67+
<rule>
68+
<pattern>org.objectweb.asm.*</pattern>
69+
<result>org.apache.ibatis.internal.asm.$@1</result>
70+
</rule>
71+
<rule>
72+
<pattern>org.objectweb.asm.**.*</pattern>
73+
<result>org.apache.ibatis.internal.asm.@1.$@2</result>
74+
</rule>
75+
<!--
76+
| keep original source
77+
-->
78+
<keep>
79+
<pattern>org.apache.ibatis.**</pattern>
80+
</keep>
81+
<!--
82+
| keep test source
83+
-->
84+
<keep>
85+
<pattern>com.**</pattern>
86+
</keep>
87+
<keep>
88+
<pattern>databases.**</pattern>
89+
</keep>
90+
<keep>
91+
<pattern>domain.**</pattern>
92+
</keep>
93+
</rules>
94+
</configuration>
95+
<!--
96+
| JarJar all classes before running tests
97+
-->
98+
<executions>
99+
<execution>
100+
<id>jarjar-classes</id>
101+
<phase>process-test-classes</phase>
102+
<goals>
103+
<goal>jarjar</goal>
104+
</goals>
105+
<configuration>
106+
<input>{classes}</input>
107+
</configuration>
108+
</execution>
109+
<execution>
110+
<id>jarjar-test-classes</id>
111+
<phase>process-test-classes</phase>
112+
<goals>
113+
<goal>jarjar</goal>
114+
</goals>
115+
<configuration>
116+
<input>{test-classes}</input>
117+
</configuration>
118+
</execution>
119+
</executions>
120+
</plugin>
45121
<plugin>
46122
<groupId>org.apache.maven.plugins</groupId>
47123
<artifactId>maven-assembly-plugin</artifactId>
@@ -71,7 +147,9 @@
71147
</goals>
72148
<configuration>
73149
<uploads>
74-
<!-- Core -->
150+
<!--
151+
| Core
152+
-->
75153
<upload>
76154
<file>${project.build.directory}/${project.artifactId}-${project.version}-bundle.zip</file>
77155
<summary>MyBatis Persistence Framework ${project.version}</summary>
@@ -102,7 +180,9 @@
102180
<label>Version-${project.version}</label>
103181
</labels>
104182
</upload>
105-
<!-- Migrations -->
183+
<!--
184+
| Migrations
185+
-->
106186
<upload>
107187
<file>${project.build.directory}/${project.artifactId}-${project.version}-migrations.zip</file>
108188
<summary>MyBatis Schema Migrations ${project.version}</summary>
@@ -150,17 +230,10 @@
150230
</execution>
151231
</executions>
152232
</plugin>
153-
<plugin>
154-
<groupId>org.apache.maven.plugins</groupId>
155-
<artifactId>maven-surefire-plugin</artifactId>
156-
<configuration>
157-
<forkMode>always</forkMode>
158-
</configuration>
159-
</plugin>
160233
</plugins>
161234
<resources>
162235
<resource>
163-
<directory>.</directory>
236+
<directory>${basedir}</directory>
164237
<targetPath>META-INF</targetPath>
165238
<includes>
166239
<include>LICENSE</include>
@@ -209,16 +282,16 @@
209282
<optional>true</optional>
210283
</dependency>
211284
<dependency>
212-
<groupId>cglib</groupId>
285+
<groupId>org.sonatype.sisu.inject</groupId>
213286
<artifactId>cglib</artifactId>
214-
<version>2.1_3</version>
215-
<optional>true</optional>
287+
<version>2.2.1</version>
288+
<scope>provided</scope>
216289
</dependency>
217290
<!-- Test dependencies -->
218291
<dependency>
219292
<groupId>junit</groupId>
220293
<artifactId>junit</artifactId>
221-
<version>4.8.2</version>
294+
<version>4.3.1</version>
222295
<scope>test</scope>
223296
</dependency>
224297
<dependency>

src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private void settingsElement(XNode context) throws Exception {
153153
}
154154
configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(stringValueOf(props.getProperty("autoMappingBehavior"), "PARTIAL")));
155155
configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
156-
configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), safeCglibCheck()));
156+
configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
157157
configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), true));
158158
configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
159159
configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
@@ -163,14 +163,6 @@ private void settingsElement(XNode context) throws Exception {
163163
}
164164
}
165165

166-
private boolean safeCglibCheck() {
167-
try {
168-
return Resources.classForName("net.sf.cglib.proxy.Enhancer") != null;
169-
} catch (Exception e) {
170-
return false;
171-
}
172-
}
173-
174166
private void environmentsElement(XNode context) throws Exception {
175167
if (context != null) {
176168
if (environment == null) {

0 commit comments

Comments
 (0)