#1173 - Ebean server should read ebean.mf entity-packages to locate entity beans

This commit is contained in:
rob bygrave
2017-10-18 23:58:22 +13:00
parent a54c4157e6
commit 00fdb632d7
7 changed files with 68 additions and 15 deletions
@@ -16,8 +16,6 @@ public class BootupClassPathSearch {
private static final Logger logger = LoggerFactory.getLogger(BootupClassPathSearch.class);
private static final String EBEAN_MF = "META-INF/ebean.mf";
private final List<String> packages;
private final List<ClassPathScanner> scanners;
@@ -33,8 +31,11 @@ public class BootupClassPathSearch {
private BootupClassPathSearch(ServerConfig serverConfig) {
// find packages defined in META-INF/ebean.mf resources
Set<String> mfPackages = ManifestReader.readManifests(serverConfig.getClassLoadConfig().getClassLoader(), EBEAN_MF);
// find packages defined in ebean.mf resources
Set<String> mfPackages = ManifestReader.create(serverConfig.getClassLoadConfig().getClassLoader())
.read("META-INF/ebean.mf")
.read("ebean.mf")
.entityPackages();
this.packages = DistillPackages.distill(serverConfig.getPackages(), mfPackages);
this.scanners = ClassPathScanners.find(serverConfig);
@@ -1,10 +1,9 @@
package io.ebeaninternal.server.core.bootup;
import io.ebean.util.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.ebean.util.StringHelper;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -24,11 +23,32 @@ class ManifestReader {
private final Set<String> packageSet = new HashSet<>();
private final ClassLoader classLoader;
/**
* Create with a classLoader to use to read the ebean.mf resources.
*/
static ManifestReader create(ClassLoader classLoader) {
return new ManifestReader(classLoader);
}
private ManifestReader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
/**
* Read the packages from ebean.mf manifest files found as resources.
*/
static Set<String> readManifests(ClassLoader classLoader, String resourcePath) {
return new ManifestReader().read(classLoader, resourcePath);
ManifestReader read(String resourcePath) {
read(classLoader, resourcePath);
return this;
}
/**
* Return all the entityPackages read.
*/
Set<String> entityPackages() {
return packageSet;
}
/**
@@ -47,7 +67,7 @@ class ManifestReader {
}
}
} catch (IOException e) {
logger.warn("Error reading META-INF/ebean.mf manifest resources", e);
logger.warn("Error reading " + resourcePath + " manifest resources", e);
}
return packageSet;
}
@@ -61,14 +81,15 @@ class ManifestReader {
}
/**
* Read the packages from the manifest.
* Read the entity packages from the manifest.
*/
private void read(Manifest manifest) throws IOException {
Attributes attributes = manifest.getMainAttributes();
String packages = attributes.getValue("packages");
if (packages != null) {
add(packages);
String agentOnlyUse = attributes.getValue("agent-use-only");
if (agentOnlyUse == null || !"true".equalsIgnoreCase(agentOnlyUse.trim())) {
add(attributes.getValue("packages"));
add(attributes.getValue("entity-packages"));
}
}
@@ -76,6 +97,8 @@ class ManifestReader {
* Collect each individual package splitting by delimiters.
*/
private void add(String packages) {
Collections.addAll(packageSet, StringHelper.splitNames(packages));
if (packages != null) {
Collections.addAll(packageSet, StringHelper.splitNames(packages));
}
}
}