mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 03:57:45 +00:00
#1173 - Ebean server should read ebean.mf entity-packages to locate entity beans
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,32 @@ public class ManifestReaderTest {
|
||||
assertThat(packageSet).contains("com.foo.domain", "com.bar.domain");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readEntityPackages() throws Exception {
|
||||
|
||||
Set<String> packageSet = readMf("META-INF/test/test-entity-packages.mf");
|
||||
assertThat(packageSet).contains("com.baz", "org.bax.domain");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readCombined() throws Exception {
|
||||
|
||||
Set<String> packageSet = readMf("META-INF/test/test-combined.mf");
|
||||
assertThat(packageSet).contains("com.foo.domain", "com.bar.domain", "com.baz.domain");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readAgentOnlyUse() throws Exception {
|
||||
|
||||
Set<String> packageSet = readMf("META-INF/test/test-agent-only-use.mf");
|
||||
assertThat(packageSet).isEmpty();
|
||||
}
|
||||
|
||||
private Set<String> readMf(String path) {
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
return ManifestReader.readManifests(classLoader, path);
|
||||
return ManifestReader.create(classLoader)
|
||||
.read(path)
|
||||
.entityPackages();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
entity-packages: com.baz, org.bax.domain
|
||||
agent-use-only: true
|
||||
@@ -0,0 +1,2 @@
|
||||
packages: com.foo.domain, com.bar.domain
|
||||
entity-packages: com.baz.domain
|
||||
@@ -0,0 +1 @@
|
||||
entity-packages: com.baz, org.bax.domain
|
||||
@@ -1,3 +1,4 @@
|
||||
agent-use-only: true
|
||||
entity-packages: org,misc
|
||||
transactional-packages: org
|
||||
querybean-packages: none
|
||||
|
||||
Reference in New Issue
Block a user