mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 17:05:43 +01:00
implement WebResourceLoaders for loading plugin web resources
This commit is contained in:
@@ -38,6 +38,7 @@ package sonia.scm.plugin;
|
||||
import com.google.inject.Binder;
|
||||
import com.google.inject.Module;
|
||||
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -81,13 +82,23 @@ public interface PluginLoader
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Collection<Plugin> getInstalledPlugins();
|
||||
public Collection<PluginWrapper> getInstalledPlugins();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Returns a {@link ClassLoader} which is able to load classes and resources
|
||||
* from the webapp and all installed plugins.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @return uber classloader
|
||||
*/
|
||||
public ClassLoader getUberClassLoader();
|
||||
|
||||
/**
|
||||
* Returns a {@link WebResourceLoader} which is able to load web resources
|
||||
* from the webapp and all installed plugins.
|
||||
*
|
||||
*
|
||||
* @return uber webresourceloader
|
||||
*/
|
||||
public UberWebResourceLoader getUberWebResourceLoader();
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ package sonia.scm.plugin;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* Wrapper for a {@link Plugin}. The wrapper holds the directory and the
|
||||
* {@link ClassLoader}, which is able to load plugin classes.
|
||||
* Wrapper for a {@link Plugin}. The wrapper holds the directory,
|
||||
* {@link ClassLoader} and {@link WebResourceLoader} of a plugin.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 2.0.0
|
||||
@@ -50,12 +50,15 @@ public final class PluginWrapper
|
||||
*
|
||||
* @param plugin wrapped plugin
|
||||
* @param classLoader plugin class loader
|
||||
* @param webResourceLoader web resource loader
|
||||
* @param directory plugin directory
|
||||
*/
|
||||
public PluginWrapper(Plugin plugin, ClassLoader classLoader, Path directory)
|
||||
public PluginWrapper(Plugin plugin, ClassLoader classLoader,
|
||||
WebResourceLoader webResourceLoader, Path directory)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.classLoader = classLoader;
|
||||
this.webResourceLoader = webResourceLoader;
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
@@ -105,6 +108,17 @@ public final class PluginWrapper
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link WebResourceLoader} for this plugin.
|
||||
*
|
||||
*
|
||||
* @return web resource loader
|
||||
*/
|
||||
public WebResourceLoader getWebResourceLoader()
|
||||
{
|
||||
return webResourceLoader;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** plugin class loader */
|
||||
@@ -115,4 +129,7 @@ public final class PluginWrapper
|
||||
|
||||
/** plugin */
|
||||
private final Plugin plugin;
|
||||
|
||||
/** plugin web resource loader */
|
||||
private final WebResourceLoader webResourceLoader;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Sebastian Sdorra All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer. 2. Redistributions in
|
||||
* binary form must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
|
||||
* nor the names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
/**
|
||||
* Load resources from {@link ServletContext} and from the installed plugins.
|
||||
* The UberWebResourceLoader will first look into the {@link ServletContext} and
|
||||
* afterwards it will search the plugin directories.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public interface UberWebResourceLoader extends WebResourceLoader
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns all {@link URL} objects for the given path. The method will collect
|
||||
* all resources from {@link ServletContext} and all plugin directories which
|
||||
* matches the given path. The method will return an empty list, if no url
|
||||
* could be found for the given path.
|
||||
*
|
||||
* @param path resource path
|
||||
*
|
||||
* @return list of url objects for the given path
|
||||
*/
|
||||
public List<URL> getResources(String path);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Sebastian Sdorra All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer. 2. Redistributions in
|
||||
* binary form must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
|
||||
* nor the names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
/**
|
||||
* The WebResourceLoader is able to load web resources. The resources are loaded
|
||||
* from a plugin webapp directory or from the {@link ServletContext}, according
|
||||
* to its implementation. The {@link UberWebResourceLoader} is able to load
|
||||
* resources from the {@link ServletContext} and all plugin directories.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public interface WebResourceLoader
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns a {@link URL} for the given path. The method will return null if no
|
||||
* resources could be found for the given path.
|
||||
*
|
||||
* @param path resource path
|
||||
*
|
||||
* @return url object for the given path or null
|
||||
*/
|
||||
public URL getResource(String path);
|
||||
}
|
||||
@@ -95,8 +95,8 @@ public enum ResourceType
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String contentType;
|
||||
private final String contentType;
|
||||
|
||||
/** Field description */
|
||||
private String extension;
|
||||
private final String extension;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user