Skip to content

Commit

Permalink
#49 Loading asset modules for all paths first, then loading all other…
Browse files Browse the repository at this point in the history
… modules
  • Loading branch information
rjrudin committed Aug 24, 2015
1 parent ab08109 commit a380ecf
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.rjrudin.marklogic.appdeployer.command.modules;

import java.io.File;

import com.rjrudin.marklogic.modulesloader.Modules;
import com.rjrudin.marklogic.modulesloader.impl.BaseModulesFinder;

public class AllButAssetsModulesFinder extends BaseModulesFinder {

@Override
public Modules findModules(File baseDir) {
Modules modules = new Modules();
addNamespaces(modules, baseDir);
addOptions(modules, baseDir);
addPropertiesFile(modules, baseDir);
addServices(modules, baseDir);
addTransforms(modules, baseDir);
return modules;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.rjrudin.marklogic.appdeployer.command.modules;

import java.io.File;

import com.rjrudin.marklogic.modulesloader.Modules;
import com.rjrudin.marklogic.modulesloader.impl.BaseModulesFinder;

public class AssetModulesFinder extends BaseModulesFinder {

@Override
public Modules findModules(File baseDir) {
Modules modules = new Modules();
addAssets(modules, baseDir);
return modules;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.rjrudin.marklogic.appdeployer.command.AbstractCommand;
import com.rjrudin.marklogic.appdeployer.command.CommandContext;
import com.rjrudin.marklogic.appdeployer.command.SortOrderConstants;
import com.rjrudin.marklogic.modulesloader.ModulesLoader;
import com.rjrudin.marklogic.modulesloader.impl.DefaultModulesLoader;
import com.rjrudin.marklogic.modulesloader.impl.TestServerModulesFinder;
import com.rjrudin.marklogic.modulesloader.impl.XccAssetLoader;
Expand All @@ -18,7 +17,7 @@
*/
public class LoadModulesCommand extends AbstractCommand {

private ModulesLoader modulesLoader;
private DefaultModulesLoader modulesLoader;

// As defined by the REST API
private String defaultAssetRolesAndCapabilities = "rest-admin,read,rest-admin,update,rest-extension-user,execute";
Expand All @@ -40,6 +39,13 @@ public void execute(CommandContext context) {
}
}

/**
* If we have multiple module paths, we want to load via XCC the assets for each first, and then iterate over the
* paths again and load all the REST API resources. This ensures that if the REST server for loading REST API
* resources has a custom rewriter, it's guaranteed to be loaded before we try to load any REST API resources.
*
* @param context
*/
protected void loadModulesIntoMainServer(CommandContext context) {
if (modulesLoader == null) {
this.modulesLoader = new DefaultModulesLoader(newXccAssetLoader(context));
Expand All @@ -50,8 +56,15 @@ protected void loadModulesIntoMainServer(CommandContext context) {
DatabaseClient client = DatabaseClientFactory.newClient(config.getHost(), config.getRestPort(),
config.getRestAdminUsername(), config.getRestAdminPassword(), config.getAuthentication());

this.modulesLoader.setModulesFinder(new AssetModulesFinder());
for (String modulesPath : config.getModulePaths()) {
logger.info("Loading asset modules from dir: " + modulesPath);
modulesLoader.loadModules(new File(modulesPath), client);
}

this.modulesLoader.setModulesFinder(new AllButAssetsModulesFinder());
for (String modulesPath : config.getModulePaths()) {
logger.info("Loading modules from dir: " + modulesPath);
logger.info("Loading all non-asset modules from dir: " + modulesPath);
modulesLoader.loadModules(new File(modulesPath), client);
}
}
Expand Down Expand Up @@ -104,7 +117,7 @@ protected XccAssetLoader newXccAssetLoader(CommandContext context) {
return l;
}

public void setModulesLoader(ModulesLoader modulesLoader) {
public void setModulesLoader(DefaultModulesLoader modulesLoader) {
this.modulesLoader = modulesLoader;
}

Expand Down

0 comments on commit a380ecf

Please sign in to comment.