mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
No effective change - remove unused code (old ClassPathReader etc)
This commit is contained in:
@@ -17,7 +17,6 @@ import com.avaje.ebean.event.changelog.ChangeLogRegister;
|
||||
import com.avaje.ebean.event.readaudit.ReadAuditLogger;
|
||||
import com.avaje.ebean.event.readaudit.ReadAuditPrepare;
|
||||
import com.avaje.ebeaninternal.server.type.ScalarType;
|
||||
import com.avaje.ebeaninternal.server.util.ClassPathSearchMatcher;
|
||||
import org.avaje.classpath.scanner.ClassFilter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -35,7 +34,7 @@ import java.util.List;
|
||||
* Interesting classes for a EbeanServer such as Embeddable, Entity,
|
||||
* ScalarTypes, Finders, Listeners and Controllers.
|
||||
*/
|
||||
public class BootupClasses implements ClassPathSearchMatcher, ClassFilter {
|
||||
public class BootupClasses implements ClassFilter {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BootupClasses.class);
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.util;
|
||||
|
||||
/**
|
||||
* Get the paths used to search for entity beans etc.
|
||||
* <p>
|
||||
* Typically this will return a URL[] of the classpath.
|
||||
* </p>
|
||||
*/
|
||||
public interface ClassPathReader {
|
||||
|
||||
/**
|
||||
* Return the paths in the classpath to search for entity beans etc.
|
||||
* <p>
|
||||
* This will typically return a URL[] or String[] of the entries in the
|
||||
* class path.
|
||||
* </p>
|
||||
*/
|
||||
Object[] readPath(ClassLoader classLoader);
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.util;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Used to reduce the classes searched by excluding jars and packages.
|
||||
*/
|
||||
public class ClassPathSearchFilter {
|
||||
|
||||
private static final String COM_AVAJE_EBEANINTERNAL_SERVER_BEAN = "com.avaje.ebeaninternal.server.bean";
|
||||
|
||||
private static final String COM_AVAJE_EBEAN_META = "com.avaje.ebean.meta";
|
||||
|
||||
private boolean defaultPackageMatch = true;
|
||||
|
||||
private boolean defaultJarMatch = false;
|
||||
|
||||
private final HashSet<String> includePackageSet = new HashSet<String>();
|
||||
|
||||
private final HashSet<String> excludePackageSet = new HashSet<String>();
|
||||
|
||||
private final HashSet<String> includeJarSet = new HashSet<String>();
|
||||
|
||||
private final HashSet<String> excludeJarSet = new HashSet<String>();
|
||||
|
||||
public ClassPathSearchFilter() {
|
||||
addDefaultExcludePackages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the explicit packages that should be searched.
|
||||
*/
|
||||
public Set<String> getIncludePackages() {
|
||||
return includePackageSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add some packages which by default will be excluded from a search.
|
||||
* <p>
|
||||
* This includes java, javax, etc.
|
||||
* </p>
|
||||
* <p>
|
||||
* This is not used when the includePackages is set, but can speed a search
|
||||
* when includePackages has not been set.
|
||||
* </p>
|
||||
*/
|
||||
public void addDefaultExcludePackages() {
|
||||
excludePackage("sun");
|
||||
excludePackage("com.sun");
|
||||
excludePackage("java");
|
||||
excludePackage("javax");
|
||||
excludePackage("junit");
|
||||
excludePackage("org.w3c");
|
||||
excludePackage("org.xml");
|
||||
excludePackage("org.apache");
|
||||
excludePackage("com.mysql");
|
||||
excludePackage("oracle.jdbc");
|
||||
excludePackage("com.microsoft.sqlserver");
|
||||
excludePackage("com.avaje.ebean");
|
||||
excludePackage("com.avaje.lib");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default for jar matching when a jar is neither explicitly
|
||||
* included or excluded.
|
||||
*/
|
||||
public void setDefaultJarMatch(boolean defaultJarMatch) {
|
||||
this.defaultJarMatch = defaultJarMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default for package matching when a package is neither explicitly
|
||||
* included or excluded.
|
||||
*/
|
||||
public void setDefaultPackageMatch(boolean defaultPackageMatch) {
|
||||
this.defaultPackageMatch = defaultPackageMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a package to explicitly include in the search.
|
||||
*/
|
||||
public void includePackage(String pckgName) {
|
||||
includePackageSet.add(pckgName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a package to explicitly exclude in the search.
|
||||
*/
|
||||
public void excludePackage(String pckgName) {
|
||||
excludePackageSet.add(pckgName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a jar to explicitly include in the search.
|
||||
*/
|
||||
public void includeJar(String jarName) {
|
||||
includeJarSet.add(jarName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the package should be included in the search.
|
||||
*/
|
||||
public boolean isSearchPackage(String packageName) {
|
||||
// special case... "meta" entity beans.
|
||||
if (COM_AVAJE_EBEAN_META.equals(packageName)) {
|
||||
return true;
|
||||
}
|
||||
// special case... BeanFinders etc for "meta" beans.
|
||||
if (COM_AVAJE_EBEANINTERNAL_SERVER_BEAN.equals(packageName)) {
|
||||
return true;
|
||||
}
|
||||
if (includePackageSet != null && !includePackageSet.isEmpty()){
|
||||
return containedIn(includePackageSet, packageName);
|
||||
}
|
||||
if (containedIn(excludePackageSet, packageName)) {
|
||||
return false;
|
||||
}
|
||||
return defaultPackageMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the jar should be included in the search.
|
||||
*/
|
||||
public boolean isSearchJar(String jarName, String jarOffset) {
|
||||
|
||||
if (containedIn(includeJarSet, jarName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (containedIn(excludeJarSet, jarName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// by default scan the root level in runnable jar (spring boot etc)
|
||||
return "/".equals(jarOffset) || defaultJarMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to determine is a match is contained in the set.
|
||||
*/
|
||||
protected boolean containedIn(HashSet<String> set, String match) {
|
||||
if (set.contains(match)) {
|
||||
return true;
|
||||
}
|
||||
for (String val : set) {
|
||||
if (match.contains(val)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.util;
|
||||
|
||||
/**
|
||||
* Defines interface for finding classes via a class path search.
|
||||
*/
|
||||
public interface ClassPathSearchMatcher {
|
||||
|
||||
/**
|
||||
* Return true if the class matches the specific search.
|
||||
* <p>
|
||||
* Note that the location in terms of jars and packages is noted and can be
|
||||
* used to make future searches faster.
|
||||
* </p>
|
||||
*/
|
||||
boolean isMatch(Class<?> cls);
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.util;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
/**
|
||||
* Default implementation for getting the classPath from the classLoader.
|
||||
* <p>
|
||||
* This class path is used to search for entity beans etc.
|
||||
* </p>
|
||||
*/
|
||||
public class DefaultClassPathReader implements ClassPathReader {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DefaultClassPathReader.class);
|
||||
|
||||
public Object[] readPath(ClassLoader classLoader) {
|
||||
|
||||
if (classLoader instanceof URLClassLoader){
|
||||
// this is really what we are hoping for
|
||||
URLClassLoader ucl = (URLClassLoader)classLoader;
|
||||
return ucl.getURLs();
|
||||
}
|
||||
|
||||
try {
|
||||
// search for a "getClassPath" method... resin2
|
||||
Method method = classLoader.getClass().getMethod("getClassPath");
|
||||
if (method != null){
|
||||
logger.info("Using getClassPath() method on classLoader["+classLoader.getClass()+"]");
|
||||
String s = method.invoke(classLoader).toString();
|
||||
return s.split(File.pathSeparator);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
// Not really an error...
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unexpected Error trying to read classpath from classloader", e);
|
||||
}
|
||||
|
||||
try {
|
||||
// search for a "getClasspath" method... Ant
|
||||
Method method = classLoader.getClass().getMethod("getClasspath");
|
||||
if (method != null){
|
||||
logger.info("Using getClasspath() method on classLoader["+classLoader.getClass()+"]");
|
||||
String s = method.invoke(classLoader).toString();
|
||||
|
||||
return s.split(File.pathSeparator);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
// Not really an error...
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unexpected Error trying to read classpath from classloader", e);
|
||||
}
|
||||
|
||||
String imsg = "Unsure how to read classpath from classLoader ["+classLoader.getClass()+"]";
|
||||
logger.info(imsg);
|
||||
|
||||
String msg = "Using java.class.path system property to search for entity beans";
|
||||
logger.warn(msg);
|
||||
|
||||
return System.getProperty("java.class.path", "").split(File.pathSeparator);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user