Skip to content

Commit

Permalink
Merge pull request #89 from mybatis/drop-cdi-1.0-support
Browse files Browse the repository at this point in the history
Drop cdi 1.0 support.
  • Loading branch information
mnesarco committed Oct 20, 2018
2 parents 0215242 + 25035df commit a1ea496
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 191 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ nb-configuration.xml
*.iml
/.idea
.mvn/wrapper/maven-wrapper.jar
.mvn/wrapper/MavenWrapperDownloader.java
110 changes: 0 additions & 110 deletions .mvn/wrapper/MavenWrapperDownloader.java

This file was deleted.

1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ env:
- MAVEN_PROFILE="-Pcdi-2.0"
- MAVEN_PROFILE="-Pcdi-1.2"
- MAVEN_PROFILE="-Pcdi-1.1"
- MAVEN_PROFILE="-Pcdi-1.0"
global:
- secure: Yt0S6+G81okW0/575CBg9pP2CcNnilyar2KKDw+4bPnFxlMS0t4y1YyX08p/Zvj5/1q7n88NrPDFdnr/qwZ0gKjmKcYMm4WTCfy+UOPtYhyQSxX6aTYOhYDMpbAQ84jB3Gh70mG52ULXxF56Hc5bNAXT0lSNfIAOndrF/LIBJAU=
- secure: QAeXjP+BabMYAHSivnbYaxrcr9pj6+FBEO/fpTlB4M0W5nALBoj8nVTOVYGv6zQHV1cxDv4DOLUxg/2sDcrWPyHV+8xbXbHvXK80T4wgeTc/SFEGOINMm/oXGdTGtY6lJ6i5VEDGwJDMRUt+M/W22HD0lqUZNDJ8xL5PAwKVr6g=
17 changes: 0 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,6 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>cdi-1.0</id>
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
<version>1.1.34.Final</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>

</project>
65 changes: 2 additions & 63 deletions src/main/java/org/mybatis/cdi/CDIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@
package org.mybatis.cdi;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.Set;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.CDI;
import javax.enterprise.util.AnnotationLiteral;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.apache.ibatis.session.SqlSessionFactory;

Expand All @@ -36,65 +34,6 @@
*/
public final class CDIUtils {

private static class CDI {

private static final Method getBeanManager;

private static final Method current;

private static final String DEFAULT_JNDI_NAME = "java:comp/BeanManager";

private static final String NAME;

static {

// Portable 1.1+ CDI Lookup ----------------------------------------------
Method currentM, getBeanManagerM;
try {
Class c = Class.forName("javax.enterprise.inject.spi.CDI");
currentM = c.getMethod("current");
getBeanManagerM = c.getMethod("getBeanManager");
} catch (Exception ex) {
currentM = null;
getBeanManagerM = null;
}
current = currentM;
getBeanManager = getBeanManagerM;

// JNDI Based Lookup fallback --------------------------------------------
if (current == null) {
String jndiName = DEFAULT_JNDI_NAME;
try {
if (InitialContext.doLookup("java:comp/env/BeanManager") != null) {
jndiName = "java:comp/env/BeanManager";
}
} catch (NamingException e) {
// Fallback to default, do nothing
}
NAME = jndiName;
} else {
NAME = null;
}
}

static BeanManager getBeanManager() {
if (current != null) {
try {
Object cdi = current.invoke(null);
return (BeanManager) getBeanManager.invoke(cdi);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
try {
return InitialContext.doLookup(NAME);
} catch (NamingException e) {
throw new RuntimeException(e);
}
}

}

private CDIUtils() {
// this class cannot be instantiated
}
Expand All @@ -105,7 +44,7 @@ private CDIUtils() {
* @return BeanManager instance
*/
private static BeanManager getBeanManager() {
return CDI.getBeanManager();
return CDI.current().getBeanManager();
}

/**
Expand Down

0 comments on commit a1ea496

Please sign in to comment.