11package com .marklogic .hub .commands ;
22
3+ import java .io .File ;
34import java .io .IOException ;
45import java .io .InputStream ;
56import java .util .ArrayList ;
2223import com .marklogic .client .modulesloader .impl .XccAssetLoader ;
2324import com .marklogic .client .modulesloader .xcc .CommaDelimitedPermissionsParser ;
2425import com .marklogic .client .modulesloader .xcc .DefaultDocumentFormatGetter ;
26+ import com .marklogic .client .modulesloader .xcc .DocumentFormatGetter ;
2527import com .marklogic .client .modulesloader .xcc .PermissionsParser ;
2628import com .marklogic .xcc .Content ;
2729import com .marklogic .xcc .ContentCreateOptions ;
@@ -40,6 +42,7 @@ public class LoadHubModulesCommand extends AbstractCommand {
4042
4143 private DefaultModulesLoader modulesLoader ;
4244 private ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver ();
45+ private DocumentFormatGetter documentFormatGetter = new DefaultDocumentFormatGetter ();
4346 private PermissionsParser permissionsParser = new CommaDelimitedPermissionsParser ();
4447
4548 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
7376
7477 protected void loadFile (String uri , InputStream inputStream , AppConfig config ) throws IOException {
7578 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 )));
8280 options .setPermissions (permissionsParser .parsePermissions (this .permissions ));
8381 if (this .collections != null ) {
8482 options .setCollections (collections );
@@ -107,10 +105,6 @@ protected void loadFile(String uri, InputStream inputStream, AppConfig config) t
107105 protected void initializeActiveSession (CommandContext context ) {
108106 AppConfig config = context .getAppConfig ();
109107 XccAssetLoader xccAssetLoader = context .getAppConfig ().newXccAssetLoader ();
110- DefaultDocumentFormatGetter documentFormatGetter = new DefaultDocumentFormatGetter ();
111- documentFormatGetter .getBinaryExtensions ().add ("woff2" );
112- documentFormatGetter .getBinaryExtensions ().add ("otf" );
113- xccAssetLoader .setDocumentFormatGetter (documentFormatGetter );
114108 this .modulesLoader = new DefaultModulesLoader (xccAssetLoader );
115109 this .modulesLoader .setDatabaseClient (config .newDatabaseClient ());
116110 ContentSource cs = ContentSourceFactory .newContentSource (config .getHost (), port , config .getRestAdminUsername (), config .getRestAdminPassword (), config .getModulesDatabaseName (),
@@ -127,33 +121,39 @@ public void execute(CommandContext context) {
127121 String rootPath = "/ml-modules/root" ;
128122
129123 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+ }
137136
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+ }
147147 }
148- }
149148
150- loadFile (path , r .getInputStream (), appConfig );
149+ loadFile (path , r .getInputStream (), appConfig );
150+ }
151151 }
152152 activeSession .commit ();
153153
154154 logger .info ("Loading Service Extensions" );
155155 long startTime = System .nanoTime ();
156- resources = findResources ("classpath*:/ml-modules/services" , "/**/*.xq*" );
156+ List < Resource > resources = findResources ("classpath*:/ml-modules/services" , "/**/*.xq*" );
157157 for (Resource r : resources ) {
158158 ExtensionMetadataAndParams emap = extensionMetadataProvider .provideExtensionMetadataAndParams (r );
159159 this .modulesLoader .installService (r , emap .metadata , emap .methods .toArray (new MethodParameters [] {}));
0 commit comments