mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
improve jersey configuration
This commit is contained in:
@@ -29,6 +29,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm;
|
package sonia.scm;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
@@ -42,6 +44,9 @@ import sonia.scm.util.ServiceUtil;
|
|||||||
public class SCMContext
|
public class SCMContext
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String DEFAULT_PACKAGE = "sonia.scm";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private static volatile SCMContextProvider provider;
|
private static volatile SCMContextProvider provider;
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ package sonia.scm.plugin;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import sonia.scm.SCMContext;
|
||||||
import sonia.scm.plugin.ext.ExtensionObject;
|
import sonia.scm.plugin.ext.ExtensionObject;
|
||||||
import sonia.scm.plugin.ext.ExtensionProcessor;
|
import sonia.scm.plugin.ext.ExtensionProcessor;
|
||||||
import sonia.scm.plugin.ext.JARExtensionScanner;
|
import sonia.scm.plugin.ext.JARExtensionScanner;
|
||||||
@@ -65,9 +66,6 @@ import javax.xml.bind.JAXB;
|
|||||||
public class DefaultPluginManager implements PluginManager
|
public class DefaultPluginManager implements PluginManager
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String DEFAULT_PACKAGE = "sonia.scm";
|
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String PATH_PLUGINCONFIG = "META-INF/scm/plugin.xml";
|
public static final String PATH_PLUGINCONFIG = "META-INF/scm/plugin.xml";
|
||||||
|
|
||||||
@@ -123,7 +121,7 @@ public class DefaultPluginManager implements PluginManager
|
|||||||
packageSet = new HashSet<String>();
|
packageSet = new HashSet<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
packageSet.add(DEFAULT_PACKAGE);
|
packageSet.add(SCMContext.DEFAULT_PACKAGE);
|
||||||
input = new FileInputStream(plugin.getPath());
|
input = new FileInputStream(plugin.getPath());
|
||||||
scanner.processExtensions(classLoader, extensions, input, packageSet);
|
scanner.processExtensions(classLoader, extensions, input, packageSet);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ import sonia.scm.cache.CacheManager;
|
|||||||
import sonia.scm.cache.EhCacheManager;
|
import sonia.scm.cache.EhCacheManager;
|
||||||
import sonia.scm.config.ScmConfiguration;
|
import sonia.scm.config.ScmConfiguration;
|
||||||
import sonia.scm.filter.SecurityFilter;
|
import sonia.scm.filter.SecurityFilter;
|
||||||
|
import sonia.scm.plugin.Plugin;
|
||||||
import sonia.scm.plugin.PluginManager;
|
import sonia.scm.plugin.PluginManager;
|
||||||
import sonia.scm.plugin.ScriptResourceServlet;
|
import sonia.scm.plugin.ScriptResourceServlet;
|
||||||
import sonia.scm.repository.RepositoryManager;
|
import sonia.scm.repository.RepositoryManager;
|
||||||
@@ -69,8 +70,12 @@ import com.sun.jersey.spi.container.servlet.ServletContainer;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.xml.bind.JAXB;
|
import javax.xml.bind.JAXB;
|
||||||
|
|
||||||
@@ -191,12 +196,105 @@ public class ScmServletModule extends ServletModule
|
|||||||
params.put(ResourceConfig.FEATURE_REDIRECT, Boolean.TRUE.toString());
|
params.put(ResourceConfig.FEATURE_REDIRECT, Boolean.TRUE.toString());
|
||||||
params.put(ServletContainer.RESOURCE_CONFIG_CLASS,
|
params.put(ServletContainer.RESOURCE_CONFIG_CLASS,
|
||||||
UriExtensionsConfig.class.getName());
|
UriExtensionsConfig.class.getName());
|
||||||
params.put(PackagesResourceConfig.PROPERTY_PACKAGES, REST_PACKAGE);
|
|
||||||
|
String restPath = getRestPackages();
|
||||||
|
|
||||||
|
if (logger.isInfoEnabled())
|
||||||
|
{
|
||||||
|
logger.info("configure jersey with package path: {}", restPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
params.put(PackagesResourceConfig.PROPERTY_PACKAGES, restPath);
|
||||||
serve(PATTERN_RESTAPI).with(GuiceContainer.class, params);
|
serve(PATTERN_RESTAPI).with(GuiceContainer.class, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param packageSet
|
||||||
|
* @param plugin
|
||||||
|
*/
|
||||||
|
private void appendPluginPackages(Set<String> packageSet, Plugin plugin)
|
||||||
|
{
|
||||||
|
Set<String> pluginPackageSet = plugin.getPackageSet();
|
||||||
|
|
||||||
|
if (pluginPackageSet != null)
|
||||||
|
{
|
||||||
|
for (String pluginPkg : pluginPackageSet)
|
||||||
|
{
|
||||||
|
boolean append = true;
|
||||||
|
|
||||||
|
for (String pkg : packageSet)
|
||||||
|
{
|
||||||
|
if (pluginPkg.startsWith(pkg))
|
||||||
|
{
|
||||||
|
append = false;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (append)
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
String name = "unknown";
|
||||||
|
|
||||||
|
if (plugin.getInformation() != null)
|
||||||
|
{
|
||||||
|
name = plugin.getInformation().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("plugin {} added rest path {}", name, pluginPkg);
|
||||||
|
}
|
||||||
|
|
||||||
|
packageSet.add(pluginPkg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String getRestPackages()
|
||||||
|
{
|
||||||
|
Set<String> packageSet = new HashSet<String>();
|
||||||
|
|
||||||
|
packageSet.add(SCMContext.DEFAULT_PACKAGE);
|
||||||
|
|
||||||
|
Collection<Plugin> plugins = pluginManager.getPlugins();
|
||||||
|
|
||||||
|
if (plugins != null)
|
||||||
|
{
|
||||||
|
for (Plugin plugin : plugins)
|
||||||
|
{
|
||||||
|
appendPluginPackages(packageSet, plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder buffer = new StringBuilder();
|
||||||
|
Iterator<String> pkgIterator = packageSet.iterator();
|
||||||
|
|
||||||
|
while (pkgIterator.hasNext())
|
||||||
|
{
|
||||||
|
buffer.append(pkgIterator.next());
|
||||||
|
|
||||||
|
if (pkgIterator.hasNext())
|
||||||
|
{
|
||||||
|
buffer.append(";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user