diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/coreplugin/CorePluginsInjectingPropertyPlaceholderConfigurer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/coreplugin/CorePluginsInjectingPropertyPlaceholderConfigurer.java index 94b47e491dec9ea56ef6112e070ae07f501ae28b..c2f03edf248084a69a085e559c1ed95e17500ca7 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/coreplugin/CorePluginsInjectingPropertyPlaceholderConfigurer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/coreplugin/CorePluginsInjectingPropertyPlaceholderConfigurer.java @@ -38,6 +38,9 @@ public class CorePluginsInjectingPropertyPlaceholderConfigurer extends ExposablePropertyPlaceholderConfigurer { + static final PluginType PLUGIN_TYPE_WEBAPPS = new PluginType("webapps", + BasicConstant.WEB_APPS_PROPERTY); + @Override protected void loadProperties(Properties properties) throws IOException { @@ -51,7 +54,7 @@ public class CorePluginsInjectingPropertyPlaceholderConfigurer extends CustomImport.PropertyNames.CUSTOM_IMPORTS.getName()); PluginType queryDatabases = new PluginType("query-databases", "query-databases"); PluginType miscellaneous = new PluginType("miscellaneous", null); - PluginType webapps = new PluginType("webapps", BasicConstant.WEB_APPS_PROPERTY); + PluginType webapps = PLUGIN_TYPE_WEBAPPS; new CorePluginsInjector(ScannerType.AS, new IPluginType[] { maintenanceTasks, customImports, queryDatabases, miscellaneous, dssDataSources, diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/coreplugin/JettyWebAppPluginInjector.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/coreplugin/JettyWebAppPluginInjector.java index f3f19202d6c178c77ee32433e7833094f00908d4..a1bada3c601ca7349e44b9edea71bf684131e890 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/coreplugin/JettyWebAppPluginInjector.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/coreplugin/JettyWebAppPluginInjector.java @@ -16,7 +16,10 @@ package ch.systemsx.cisd.openbis.generic.server.coreplugin; +import static ch.systemsx.cisd.openbis.generic.server.coreplugin.CorePluginsInjectingPropertyPlaceholderConfigurer.PLUGIN_TYPE_WEBAPPS; + import java.io.File; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -25,12 +28,16 @@ import java.util.Properties; import org.apache.log4j.Logger; +import ch.systemsx.cisd.base.unix.Unix; import ch.systemsx.cisd.common.filesystem.FileUtilities; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; import ch.systemsx.cisd.common.utilities.PropertyParametersUtil; import ch.systemsx.cisd.common.utilities.PropertyUtils; import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.CorePlugin; +import ch.systemsx.cisd.openbis.generic.shared.coreplugin.CorePluginScanner; +import ch.systemsx.cisd.openbis.generic.shared.coreplugin.CorePluginScanner.ScannerType; /** * A class that injects web apps into jetty. @@ -39,6 +46,8 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; */ public class JettyWebAppPluginInjector { + private static final String WEBAPP_FOLDER = "webapp"; + /** * A utility class that generates a configuration file for a Jetty context for a webapp. * @@ -109,6 +118,8 @@ public class JettyWebAppPluginInjector public static final String WEB_APP_FOLDER_PROPERTY = "webapp-folder"; + private Map<String, File> webappToFoldersMap; + private static Map<String, Properties> extractWebappProperties(Properties props, List<String> webapps) { @@ -130,6 +141,31 @@ public class JettyWebAppPluginInjector PropertyUtils.tryGetListInOriginalCase(props, BasicConstant.WEB_APPS_PROPERTY); webapps = (null == appList) ? Collections.<String> emptyList() : appList; webappProperties = extractWebappProperties(props, webapps); + webappToFoldersMap = new HashMap<String, File>(); + String corePluginsFolder = props.getProperty("core-plugins-folder", "../../core-plugins"); + CorePluginScanner scanner = new CorePluginScanner(corePluginsFolder, ScannerType.AS); + List<CorePlugin> plugins = scanner.scanForPlugins(); + for (CorePlugin plugin : plugins) + { + File webappsFolder = + new File(corePluginsFolder, CorePluginScanner.constructPath(plugin, + ScannerType.AS, PLUGIN_TYPE_WEBAPPS)); + if (webappsFolder.isDirectory()) + { + File[] pluginFolders = webappsFolder.listFiles(); + for (File folder : pluginFolders) + { + String webappName = folder.getName(); + if (webappName.startsWith(".") == false) + { + String f = + webappProperties.get(webappName).getProperty( + WEB_APP_FOLDER_PROPERTY); + webappToFoldersMap.put(webappName, new File(folder, f)); + } + } + } + } } public void injectWebApps() @@ -137,14 +173,29 @@ public class JettyWebAppPluginInjector logWebappsToInject(); // Leave if there is nothing to do - if (webapps.size() < 1) + if (webapps.isEmpty()) { return; } if (false == isRunningUnderJetty()) { - // We are not running in Jetty. Log and then get out. - operationLog.error("Not running under jetty. Cannot inject webapps."); + List<File> targets = findInjectionTargets(); + for (String webapp : webapps) + { + File folder = webappToFoldersMap.get(webapp); + String path = folder.getAbsolutePath(); + for (File target : targets) + { + File link = new File(target, webapp); + if (link.exists() == false) + { + String linkPath = link.getAbsolutePath(); + Unix.createSymbolicLink(path, linkPath); + operationLog.info("WebApp '" + webapp + "': Symbolic link " + linkPath + + " -> " + path); + } + } + } return; } if (false == ensureContextFolderExists()) @@ -159,6 +210,28 @@ public class JettyWebAppPluginInjector } } + private List<File> findInjectionTargets() + { + List<File> list = new ArrayList<File>(); + String jettyHome = System.getProperty("jetty.home"); + if (jettyHome != null) + { + list.add(new File(jettyHome + "/webapps/openbis/" + WEBAPP_FOLDER)); + } else + { + File[] files = new File("targets/www").listFiles(); + for (File file : files) + { + File webappFolder = new File(file, WEBAPP_FOLDER); + if (webappFolder.isDirectory()) + { + list.add(webappFolder); + } + } + } + return list; + } + private void logWebappsToInject() { StringBuilder sb = new StringBuilder(); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/CorePluginScanner.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/CorePluginScanner.java index 47f5e445f1d1125e7030152324fa65020d5745b6..c7e553d853d60523c970bee7655aa70015a31859 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/CorePluginScanner.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/CorePluginScanner.java @@ -59,6 +59,13 @@ public class CorePluginScanner implements ICorePluginResourceLoader } } + public static String constructPath(CorePlugin corePlugin, ScannerType scannerType, + IPluginType pluginType) + { + return corePlugin.getName() + "/" + corePlugin.getVersion() + "/" + + scannerType.getSubFolderName() + "/" + pluginType.getSubFolderName(); + } + private static final ISimpleLogger DEFAULT_LOGGER = new Log4jSimpleLogger(LogFactory.getLogger( LogCategory.OPERATION, CorePluginScanner.class)); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/CorePluginsInjector.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/CorePluginsInjector.java index 5c397aa3d430586395d40978963031d43262eb04..ccbacf653f22764170ac71e6a87897fbad7ae936 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/CorePluginsInjector.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/coreplugin/CorePluginsInjector.java @@ -232,12 +232,11 @@ public class CorePluginsInjector + "' are not enabled."); continue; } - File dssFolder = - new File(corePluginsFolderPath, technology + "/" + corePlugin.getVersion() - + "/" + scannerType.getSubFolderName()); for (IPluginType pluginType : pluginTypes) { - File file = new File(dssFolder, pluginType.getSubFolderName()); + File file = + new File(corePluginsFolderPath, CorePluginScanner.constructPath(corePlugin, + scannerType, pluginType)); if (file.isDirectory()) { File[] pluginFolders = file.listFiles(new FilenameFilter() diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/webapp/.dummy_file_to_make_this_folder_not_empty b/openbis/source/java/ch/systemsx/cisd/openbis/public/webapp/.dummy_file_to_make_this_folder_not_empty new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391