2020-03-23 15:35:58 +01:00
|
|
|
/*
|
|
|
|
|
* MIT License
|
2010-10-31 19:22:53 +01:00
|
|
|
*
|
2020-03-23 15:35:58 +01:00
|
|
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
2010-10-31 19:22:53 +01:00
|
|
|
*
|
2020-03-23 15:35:58 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2010-10-31 19:22:53 +01:00
|
|
|
*
|
2020-03-23 15:35:58 +01:00
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
2010-10-31 19:22:53 +01:00
|
|
|
*
|
2020-03-23 15:35:58 +01:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
2010-10-12 09:16:40 +02:00
|
|
|
*/
|
2020-04-16 12:03:12 +02:00
|
|
|
|
2010-12-01 14:26:29 +01:00
|
|
|
package sonia.scm.plugin;
|
2010-10-12 09:16:40 +02:00
|
|
|
|
|
|
|
|
//~--- non-JDK imports --------------------------------------------------------
|
|
|
|
|
|
2014-03-28 22:49:55 +01:00
|
|
|
import com.google.common.base.Throwables;
|
2013-01-18 09:39:32 +01:00
|
|
|
import com.google.common.collect.ImmutableSet;
|
2014-03-28 22:49:55 +01:00
|
|
|
import com.google.common.collect.ImmutableSet.Builder;
|
2010-10-12 09:16:40 +02:00
|
|
|
|
2020-04-16 12:03:12 +02:00
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
|
import javax.xml.bind.JAXBException;
|
2010-10-12 09:16:40 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.URL;
|
2010-12-01 14:26:29 +01:00
|
|
|
import java.util.Collection;
|
2010-10-12 09:16:40 +02:00
|
|
|
import java.util.Enumeration;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
2020-04-16 12:03:12 +02:00
|
|
|
//~--- JDK imports ------------------------------------------------------------
|
2010-10-12 09:16:40 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @author Sebastian Sdorra
|
|
|
|
|
*/
|
2010-12-13 18:59:00 +01:00
|
|
|
public class DefaultPluginLoader implements PluginLoader
|
2010-10-12 09:16:40 +02:00
|
|
|
{
|
|
|
|
|
|
2010-12-21 17:08:41 +01:00
|
|
|
/** Field description */
|
2014-03-28 22:49:55 +01:00
|
|
|
public static final String PATH_MODULECONFIG = "META-INF/scm/module.xml";
|
2013-01-18 09:39:32 +01:00
|
|
|
|
2010-10-12 09:16:40 +02:00
|
|
|
/** Field description */
|
2010-12-01 14:26:29 +01:00
|
|
|
public static final String PATH_PLUGINCONFIG = "META-INF/scm/plugin.xml";
|
|
|
|
|
|
|
|
|
|
//~--- constructors ---------------------------------------------------------
|
2010-10-12 09:16:40 +02:00
|
|
|
|
|
|
|
|
/**
|
2010-12-01 14:26:29 +01:00
|
|
|
* Constructs ...
|
2010-10-12 09:16:40 +02:00
|
|
|
*
|
2014-08-27 21:01:05 +02:00
|
|
|
* @param servletContext
|
2014-06-06 08:57:41 +02:00
|
|
|
* @param parent
|
2014-08-27 21:01:05 +02:00
|
|
|
* @param installedPlugins
|
2010-10-12 09:16:40 +02:00
|
|
|
*/
|
2014-08-27 21:01:05 +02:00
|
|
|
public DefaultPluginLoader(ServletContext servletContext, ClassLoader parent,
|
2019-08-20 07:54:00 +02:00
|
|
|
Set<InstalledPlugin> installedPlugins)
|
2010-10-12 09:16:40 +02:00
|
|
|
{
|
2014-08-27 21:01:05 +02:00
|
|
|
this.installedPlugins = installedPlugins;
|
|
|
|
|
this.uberClassLoader = new UberClassLoader(parent, installedPlugins);
|
|
|
|
|
this.uberWebResourceLoader =
|
|
|
|
|
new DefaultUberWebResourceLoader(servletContext, installedPlugins);
|
2010-10-12 09:16:40 +02:00
|
|
|
|
2010-12-01 14:26:29 +01:00
|
|
|
try
|
2010-10-12 09:16:40 +02:00
|
|
|
{
|
2014-03-28 22:49:55 +01:00
|
|
|
JAXBContext context = JAXBContext.newInstance(ScmModule.class,
|
2019-08-20 08:05:41 +02:00
|
|
|
InstalledPluginDescriptor.class);
|
2010-10-12 09:16:40 +02:00
|
|
|
|
2014-06-06 08:57:41 +02:00
|
|
|
modules = getInstalled(parent, context, PATH_MODULECONFIG);
|
|
|
|
|
|
2020-04-16 12:03:12 +02:00
|
|
|
ExtensionCollector collector = new ExtensionCollector(parent, modules, installedPlugins);
|
2014-12-19 17:15:50 +01:00
|
|
|
extensionProcessor = new DefaultExtensionProcessor(collector);
|
2013-01-18 09:39:32 +01:00
|
|
|
}
|
2014-06-06 08:57:41 +02:00
|
|
|
catch (IOException | JAXBException ex)
|
2013-01-18 09:39:32 +01:00
|
|
|
{
|
2014-03-28 22:49:55 +01:00
|
|
|
throw Throwables.propagate(ex);
|
2013-01-18 09:39:32 +01:00
|
|
|
}
|
2013-01-15 16:55:07 +01:00
|
|
|
}
|
|
|
|
|
|
2014-12-19 17:15:50 +01:00
|
|
|
//~--- get methods ----------------------------------------------------------
|
2014-03-28 22:49:55 +01:00
|
|
|
|
2013-01-18 09:39:32 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
2014-12-19 17:15:50 +01:00
|
|
|
* @return
|
2013-01-18 09:39:32 +01:00
|
|
|
*/
|
2014-03-28 22:49:55 +01:00
|
|
|
@Override
|
2014-12-19 17:15:50 +01:00
|
|
|
public ExtensionProcessor getExtensionProcessor()
|
2013-01-18 09:39:32 +01:00
|
|
|
{
|
2014-12-19 17:15:50 +01:00
|
|
|
return extensionProcessor;
|
2010-10-12 09:16:40 +02:00
|
|
|
}
|
|
|
|
|
|
2013-01-18 09:39:32 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2014-03-28 22:49:55 +01:00
|
|
|
@Override
|
|
|
|
|
public Collection<ScmModule> getInstalledModules()
|
2010-12-21 17:08:41 +01:00
|
|
|
{
|
2014-03-28 22:49:55 +01:00
|
|
|
return modules;
|
2010-12-21 17:08:41 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-01 14:26:29 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
2013-01-18 09:39:32 +01:00
|
|
|
* @return
|
2010-12-01 14:26:29 +01:00
|
|
|
*/
|
2014-03-28 22:49:55 +01:00
|
|
|
@Override
|
2019-08-20 07:54:00 +02:00
|
|
|
public Collection<InstalledPlugin> getInstalledPlugins()
|
2013-01-18 09:39:32 +01:00
|
|
|
{
|
2014-08-27 21:01:05 +02:00
|
|
|
return installedPlugins;
|
2013-01-18 09:39:32 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-06 08:57:41 +02:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ClassLoader getUberClassLoader()
|
|
|
|
|
{
|
|
|
|
|
return uberClassLoader;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-27 21:01:05 +02:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public UberWebResourceLoader getUberWebResourceLoader()
|
|
|
|
|
{
|
|
|
|
|
return uberWebResourceLoader;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-28 22:49:55 +01:00
|
|
|
//~--- get methods ----------------------------------------------------------
|
|
|
|
|
|
2013-01-18 09:39:32 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param classLoader
|
2014-03-28 22:49:55 +01:00
|
|
|
* @param context
|
|
|
|
|
* @param path
|
|
|
|
|
* @param <T>
|
|
|
|
|
*
|
|
|
|
|
* @return
|
2013-01-18 09:39:32 +01:00
|
|
|
*
|
|
|
|
|
* @throws IOException
|
2014-03-28 22:49:55 +01:00
|
|
|
* @throws JAXBException
|
2013-01-18 09:39:32 +01:00
|
|
|
*/
|
2014-08-19 21:45:23 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2014-03-28 22:49:55 +01:00
|
|
|
private <T> Set<T> getInstalled(ClassLoader classLoader, JAXBContext context,
|
|
|
|
|
String path)
|
|
|
|
|
throws IOException, JAXBException
|
2013-01-18 09:39:32 +01:00
|
|
|
{
|
2014-03-28 22:49:55 +01:00
|
|
|
Builder<T> builder = ImmutableSet.builder();
|
|
|
|
|
Enumeration<URL> urls = classLoader.getResources(path);
|
2013-01-18 09:39:32 +01:00
|
|
|
|
2014-03-28 22:49:55 +01:00
|
|
|
while (urls.hasMoreElements())
|
2013-01-18 09:39:32 +01:00
|
|
|
{
|
2014-03-28 22:49:55 +01:00
|
|
|
URL url = urls.nextElement();
|
|
|
|
|
T module = (T) context.createUnmarshaller().unmarshal(url);
|
|
|
|
|
|
|
|
|
|
builder.add(module);
|
2013-01-18 09:39:32 +01:00
|
|
|
}
|
2014-03-28 22:49:55 +01:00
|
|
|
|
|
|
|
|
return builder.build();
|
2013-01-18 09:39:32 +01:00
|
|
|
}
|
|
|
|
|
|
2010-10-12 09:16:40 +02:00
|
|
|
//~--- fields ---------------------------------------------------------------
|
|
|
|
|
|
2013-01-15 16:55:07 +01:00
|
|
|
/** Field description */
|
2014-12-19 17:15:50 +01:00
|
|
|
private final ExtensionProcessor extensionProcessor;
|
2013-01-18 09:39:32 +01:00
|
|
|
|
|
|
|
|
/** Field description */
|
2019-08-20 07:54:00 +02:00
|
|
|
private final Set<InstalledPlugin> installedPlugins;
|
2013-01-18 09:39:32 +01:00
|
|
|
|
|
|
|
|
/** Field description */
|
2014-12-19 17:15:50 +01:00
|
|
|
private final Set<ScmModule> modules;
|
2014-08-27 21:01:05 +02:00
|
|
|
|
|
|
|
|
/** Field description */
|
2014-12-19 17:15:50 +01:00
|
|
|
private final ClassLoader uberClassLoader;
|
2013-01-18 09:39:32 +01:00
|
|
|
|
|
|
|
|
/** Field description */
|
2014-12-19 17:15:50 +01:00
|
|
|
private final UberWebResourceLoader uberWebResourceLoader;
|
2010-10-12 09:16:40 +02:00
|
|
|
}
|