Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit d803acf

Browse files
committed
#110 ModulesLoader now supports loading modules from multiple paths
1 parent 88f6b9e commit d803acf

File tree

4 files changed

+134
-86
lines changed

4 files changed

+134
-86
lines changed

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
group=com.marklogic
22
javadocsDir=../gh-pages-marklogic-java/javadocs
3-
version=3.11.0
3+
#version=3.11.0
4+
version=3.12.develop
Lines changed: 79 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,87 @@
11
package com.marklogic.client.ext.modulesloader;
22

3-
import java.util.List;
4-
53
import org.springframework.core.io.Resource;
64

5+
import java.util.ArrayList;
6+
import java.util.List;
7+
78
public class Modules {
89

9-
private List<Resource> assets;
10-
private List<Resource> services;
11-
private List<Resource> assetDirectories;
12-
private List<Resource> transforms;
13-
private List<Resource> options;
14-
private List<Resource> namespaces;
15-
private Resource propertiesFile;
16-
17-
public List<Resource> getServices() {
18-
return services;
19-
}
20-
21-
public List<Resource> getTransforms() {
22-
return transforms;
23-
}
24-
25-
public List<Resource> getOptions() {
26-
return options;
27-
}
28-
29-
public void setServices(List<Resource> resources) {
30-
this.services = resources;
31-
}
32-
33-
public void setTransforms(List<Resource> transforms) {
34-
this.transforms = transforms;
35-
}
36-
37-
public void setOptions(List<Resource> queryOptions) {
38-
this.options = queryOptions;
39-
}
40-
41-
public List<Resource> getNamespaces() {
42-
return namespaces;
43-
}
44-
45-
public void setNamespaces(List<Resource> namespaces) {
46-
this.namespaces = namespaces;
47-
}
48-
49-
public Resource getPropertiesFile() {
50-
return propertiesFile;
51-
}
52-
53-
public void setPropertiesFile(Resource propertiesFile) {
54-
this.propertiesFile = propertiesFile;
55-
}
56-
57-
public List<Resource> getAssetDirectories() {
58-
return assetDirectories;
59-
}
60-
61-
public void setAssetDirectories(List<Resource> assetDirectories) {
62-
this.assetDirectories = assetDirectories;
63-
}
64-
65-
public List<Resource> getAssets() {
66-
return assets;
67-
}
68-
69-
public void setAssets(List<Resource> assets) {
70-
this.assets = assets;
71-
}
10+
private List<Resource> assetDirectories;
11+
private List<Resource> namespaces;
12+
private List<Resource> options;
13+
private List<Resource> services;
14+
private List<Resource> transforms;
15+
private Resource propertiesFile;
16+
17+
public void addModules(Modules modules) {
18+
assetDirectories = addLists(assetDirectories, modules.getAssetDirectories());
19+
namespaces = addLists(namespaces, modules.getNamespaces());
20+
options = addLists(options, modules.getOptions());
21+
services = addLists(services, modules.getServices());
22+
transforms = addLists(transforms, modules.getTransforms());
23+
if (modules.getPropertiesFile() != null) {
24+
propertiesFile = modules.getPropertiesFile();
25+
}
26+
}
27+
28+
protected List<Resource> addLists(List<Resource> myList, List<Resource> otherList) {
29+
if (otherList == null) {
30+
return myList;
31+
}
32+
if (myList == null) {
33+
myList = new ArrayList<>();
34+
}
35+
myList.addAll(otherList);
36+
return myList;
37+
}
38+
39+
public List<Resource> getServices() {
40+
return services;
41+
}
42+
43+
public List<Resource> getTransforms() {
44+
return transforms;
45+
}
46+
47+
public List<Resource> getOptions() {
48+
return options;
49+
}
50+
51+
public void setServices(List<Resource> resources) {
52+
this.services = resources;
53+
}
54+
55+
public void setTransforms(List<Resource> transforms) {
56+
this.transforms = transforms;
57+
}
58+
59+
public void setOptions(List<Resource> queryOptions) {
60+
this.options = queryOptions;
61+
}
62+
63+
public List<Resource> getNamespaces() {
64+
return namespaces;
65+
}
66+
67+
public void setNamespaces(List<Resource> namespaces) {
68+
this.namespaces = namespaces;
69+
}
70+
71+
public Resource getPropertiesFile() {
72+
return propertiesFile;
73+
}
74+
75+
public void setPropertiesFile(Resource propertiesFile) {
76+
this.propertiesFile = propertiesFile;
77+
}
78+
79+
public List<Resource> getAssetDirectories() {
80+
return assetDirectories;
81+
}
82+
83+
public void setAssetDirectories(List<Resource> assetDirectories) {
84+
this.assetDirectories = assetDirectories;
85+
}
7286

7387
}
Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
package com.marklogic.client.ext.modulesloader;
22

3-
import java.io.File;
4-
import java.util.Set;
5-
63
import com.marklogic.client.DatabaseClient;
74
import org.springframework.core.io.Resource;
85

6+
import java.util.Set;
7+
98
/**
109
* Interface for objects that can load a set of modules via the REST API, which is intended to include not just what the
1110
* REST API calls "assets" (regular modules), but also options, services, transforms, and namespaces.
1211
*/
1312
public interface ModulesLoader {
1413

15-
/**
16-
* Use the given DatabaseClient to load modules found in the given directory. Return a set containing any files that
17-
* were loaded.
18-
*
19-
* @param directory
20-
* @param modulesFinder
21-
* @param client
22-
* @return
23-
*/
24-
Set<Resource> loadModules(String directory, ModulesFinder modulesFinder, DatabaseClient client);
14+
/**
15+
* Use the given DatabaseClient to load modules found in the given directory. Return a set containing any files that
16+
* were loaded.
17+
*
18+
* @param directory
19+
* @param modulesFinder
20+
* @param client
21+
* @return
22+
*/
23+
Set<Resource> loadModules(String directory, ModulesFinder modulesFinder, DatabaseClient client);
24+
25+
/**
26+
* Prefer this method when loading modules from multiple paths, as the non-REST modules from all paths should be
27+
* loaded in a single batch.
28+
*
29+
* @param client
30+
* @param modulesFinder
31+
* @param paths
32+
* @return
33+
*/
34+
Set<Resource> loadModules(DatabaseClient client, ModulesFinder modulesFinder, String... paths);
2535
}

src/main/java/com/marklogic/client/ext/modulesloader/impl/DefaultModulesLoader.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,45 @@ public void initializeDefaultTaskExecutor() {
127127
* because the /v1/ext endpoint is too slow when there are e.g. hundreds of modules or more - asset modules are
128128
* instead loaded via AssetFileLoader.
129129
*/
130-
public Set<Resource> loadModules(String baseDir, ModulesFinder modulesFinder, DatabaseClient client) {
130+
@Override
131+
public Set<Resource> loadModules(DatabaseClient client, ModulesFinder modulesFinder, String... paths) {
132+
List<String> pathsList = Arrays.asList(paths);
133+
131134
if (logger.isDebugEnabled()) {
132-
logger.debug("Loading modules from base directory: " + baseDir);
135+
logger.debug("Loading modules from paths: " + pathsList);
133136
}
137+
134138
setDatabaseClient(client);
135139

136140
if (modulesManager != null) {
137141
modulesManager.initialize();
138142
}
139143

140-
Modules modules = modulesFinder.findModules(baseDir);
144+
Modules allModules = new Modules();
145+
for (String path : paths) {
146+
allModules.addModules(modulesFinder.findModules(path));
147+
}
148+
149+
if (logger.isDebugEnabled()) {
150+
logger.debug("Finished loading modules from paths: " + pathsList);
151+
}
152+
153+
return loadModules(allModules);
154+
}
155+
156+
/**
157+
* Just delegates to the loadModules method that takes an array of paths.
158+
*
159+
* @param baseDir
160+
* @param modulesFinder
161+
* @param client
162+
* @return
163+
*/
164+
public Set<Resource> loadModules(String baseDir, ModulesFinder modulesFinder, DatabaseClient client) {
165+
return loadModules(client, modulesFinder, baseDir);
166+
}
141167

168+
protected Set<Resource> loadModules(Modules modules) {
142169
if (taskExecutor == null) {
143170
initializeDefaultTaskExecutor();
144171
}
@@ -155,10 +182,6 @@ public Set<Resource> loadModules(String baseDir, ModulesFinder modulesFinder, Da
155182
waitForTaskExecutorToFinish();
156183
rethrowRestModulesFailureIfOneExists();
157184

158-
if (logger.isDebugEnabled()) {
159-
logger.debug("Finished loading modules from base directory: " + baseDir);
160-
}
161-
162185
return loadedModules;
163186
}
164187

0 commit comments

Comments
 (0)