1
1
package com .marklogic .hub .commands ;
2
2
3
+ import java .io .File ;
3
4
import java .io .IOException ;
4
5
import java .io .InputStream ;
5
6
import java .util .ArrayList ;
22
23
import com .marklogic .client .modulesloader .impl .XccAssetLoader ;
23
24
import com .marklogic .client .modulesloader .xcc .CommaDelimitedPermissionsParser ;
24
25
import com .marklogic .client .modulesloader .xcc .DefaultDocumentFormatGetter ;
26
+ import com .marklogic .client .modulesloader .xcc .DocumentFormatGetter ;
25
27
import com .marklogic .client .modulesloader .xcc .PermissionsParser ;
26
28
import com .marklogic .xcc .Content ;
27
29
import com .marklogic .xcc .ContentCreateOptions ;
@@ -40,6 +42,7 @@ public class LoadHubModulesCommand extends AbstractCommand {
40
42
41
43
private DefaultModulesLoader modulesLoader ;
42
44
private ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver ();
45
+ private DocumentFormatGetter documentFormatGetter = new DefaultDocumentFormatGetter ();
43
46
private PermissionsParser permissionsParser = new CommaDelimitedPermissionsParser ();
44
47
45
48
private String permissions = "rest-admin,read,rest-admin,update,rest-extension-user,execute" ;
@@ -73,12 +76,7 @@ private List<Resource> findResources(String basePath, String... paths) throws IO
73
76
74
77
protected void loadFile (String uri , InputStream inputStream , AppConfig config ) throws IOException {
75
78
ContentCreateOptions options = new ContentCreateOptions ();
76
- if (uri .endsWith ("xml" )) {
77
- options .setFormatXml ();
78
- }
79
- else {
80
- options .setFormatText ();
81
- }
79
+ options .setFormat (documentFormatGetter .getDocumentFormat (new File (uri )));
82
80
options .setPermissions (permissionsParser .parsePermissions (this .permissions ));
83
81
if (this .collections != null ) {
84
82
options .setCollections (collections );
@@ -107,10 +105,6 @@ protected void loadFile(String uri, InputStream inputStream, AppConfig config) t
107
105
protected void initializeActiveSession (CommandContext context ) {
108
106
AppConfig config = context .getAppConfig ();
109
107
XccAssetLoader xccAssetLoader = context .getAppConfig ().newXccAssetLoader ();
110
- DefaultDocumentFormatGetter documentFormatGetter = new DefaultDocumentFormatGetter ();
111
- documentFormatGetter .getBinaryExtensions ().add ("woff2" );
112
- documentFormatGetter .getBinaryExtensions ().add ("otf" );
113
- xccAssetLoader .setDocumentFormatGetter (documentFormatGetter );
114
108
this .modulesLoader = new DefaultModulesLoader (xccAssetLoader );
115
109
this .modulesLoader .setDatabaseClient (config .newDatabaseClient ());
116
110
ContentSource cs = ContentSourceFactory .newContentSource (config .getHost (), port , config .getRestAdminUsername (), config .getRestAdminPassword (), config .getModulesDatabaseName (),
@@ -127,33 +121,39 @@ public void execute(CommandContext context) {
127
121
String rootPath = "/ml-modules/root" ;
128
122
129
123
AppConfig appConfig = context .getAppConfig ();
130
- List <Resource > resources = findResources ("classpath*:" + rootPath , "/**/*.x??" );
131
- for (Resource r : resources ) {
132
- String path = r .getURL ().getPath ();
133
- if (path .contains ("!" )) {
134
- String [] splits = path .split ("!" );
135
- path = splits [splits .length - 1 ];
136
- }
124
+ ArrayList <String > classpaths = new ArrayList <String >();
125
+ classpaths .add ("/com.marklogic.hub/**/*.x??" );
126
+ classpaths .add ("/trace-ui/**/*" );
127
+
128
+ for (String classpath : classpaths ) {
129
+ List <Resource > resources = findResources ("classpath*:" + rootPath , classpath );
130
+ for (Resource r : resources ) {
131
+ String path = r .getURL ().getPath ();
132
+ if (path .contains ("!" )) {
133
+ String [] splits = path .split ("!" );
134
+ path = splits [splits .length - 1 ];
135
+ }
137
136
138
- String rootPathAbs = resolver .getResource (rootPath ).getURL ().getPath ();
139
- if (rootPathAbs .contains ("!" )) {
140
- String [] splits = rootPathAbs .split ("!" );
141
- rootPathAbs = splits [splits .length - 1 ];
142
- }
143
- if (path .startsWith (rootPathAbs )) {
144
- path = path .substring (rootPathAbs .length ());
145
- if (logger .isDebugEnabled ()) {
146
- logger .debug ("Path without root path: " + path );
137
+ String rootPathAbs = resolver .getResource (rootPath ).getURL ().getPath ();
138
+ if (rootPathAbs .contains ("!" )) {
139
+ String [] splits = rootPathAbs .split ("!" );
140
+ rootPathAbs = splits [splits .length - 1 ];
141
+ }
142
+ if (path .startsWith (rootPathAbs )) {
143
+ path = path .substring (rootPathAbs .length ());
144
+ if (logger .isDebugEnabled ()) {
145
+ logger .debug ("Path without root path: " + path );
146
+ }
147
147
}
148
- }
149
148
150
- loadFile (path , r .getInputStream (), appConfig );
149
+ loadFile (path , r .getInputStream (), appConfig );
150
+ }
151
151
}
152
152
activeSession .commit ();
153
153
154
154
logger .info ("Loading Service Extensions" );
155
155
long startTime = System .nanoTime ();
156
- resources = findResources ("classpath*:/ml-modules/services" , "/**/*.xq*" );
156
+ List < Resource > resources = findResources ("classpath*:/ml-modules/services" , "/**/*.xq*" );
157
157
for (Resource r : resources ) {
158
158
ExtensionMetadataAndParams emap = extensionMetadataProvider .provideExtensionMetadataAndParams (r );
159
159
this .modulesLoader .installService (r , emap .metadata , emap .methods .toArray (new MethodParameters [] {}));
0 commit comments