mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 22:15:45 +01:00
rebuild plugin system
This commit is contained in:
@@ -40,6 +40,7 @@ import com.google.inject.Singleton;
|
|||||||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
|
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
|
||||||
|
|
||||||
import sonia.scm.Type;
|
import sonia.scm.Type;
|
||||||
|
import sonia.scm.plugin.ext.Extension;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ import java.io.IOException;
|
|||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@Extension
|
||||||
public class GitRepositoryHandler
|
public class GitRepositoryHandler
|
||||||
extends AbstractSimpleRepositoryHandler<GitConfig>
|
extends AbstractSimpleRepositoryHandler<GitConfig>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,49 +29,39 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.web;
|
package sonia.scm.web;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import sonia.scm.web.plugin.ClasspathWebResource;
|
import com.google.inject.servlet.ServletModule;
|
||||||
import sonia.scm.web.plugin.ScmWebPlugin;
|
import sonia.scm.plugin.ext.Extension;
|
||||||
import sonia.scm.web.plugin.ScmWebPluginContext;
|
|
||||||
|
import sonia.scm.web.filter.BasicAuthenticationFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public class HgWebPlugin implements ScmWebPlugin
|
@Extension
|
||||||
|
public class GitServletModule extends ServletModule
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String SCRIPT = "/sonia/scm/hg.config.js";
|
public static final String PATTERN_GIT = "/git/*";
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void contextDestroyed(ScmWebPluginContext context)
|
protected void configureServlets()
|
||||||
{
|
{
|
||||||
|
filter(PATTERN_GIT).through(BasicAuthenticationFilter.class);
|
||||||
// do nothing
|
filter(PATTERN_GIT).through(GitPermissionFilter.class);
|
||||||
}
|
serve(PATTERN_GIT).with(ScmGitServlet.class);
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void contextInitialized(ScmWebPluginContext context)
|
|
||||||
{
|
|
||||||
context.addScriptResource(new ClasspathWebResource(SCRIPT));
|
|
||||||
context.addInjectModule(new HgServletModule());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2010, 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.web;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.google.inject.servlet.ServletModule;
|
|
||||||
|
|
||||||
import sonia.scm.web.filter.BasicAuthenticationFilter;
|
|
||||||
import sonia.scm.web.plugin.ClasspathWebResource;
|
|
||||||
import sonia.scm.web.plugin.ScmWebPlugin;
|
|
||||||
import sonia.scm.web.plugin.ScmWebPluginContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class GitWebPlugin implements ScmWebPlugin
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String PATTERN_GIT = "/git/*";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String SCRIPT = "/sonia/scm/git.config.js";
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void contextDestroyed(ScmWebPluginContext context)
|
|
||||||
{
|
|
||||||
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void contextInitialized(ScmWebPluginContext context)
|
|
||||||
{
|
|
||||||
context.addScriptResource(new ClasspathWebResource(SCRIPT));
|
|
||||||
context.addInjectModule(new ServletModule()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected void configureServlets()
|
|
||||||
{
|
|
||||||
filter(PATTERN_GIT).through(BasicAuthenticationFilter.class);
|
|
||||||
filter(PATTERN_GIT).through(GitPermissionFilter.class);
|
|
||||||
serve(PATTERN_GIT).with(ScmGitServlet.class);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -40,12 +40,18 @@
|
|||||||
Purpose of the document follows.
|
Purpose of the document follows.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<plugin-config>
|
<plugin>
|
||||||
|
|
||||||
<web-plugin>sonia.scm.web.GitWebPlugin</web-plugin>
|
<information>
|
||||||
|
<name>${project.name}</name>
|
||||||
|
<description>${project.description}</description>
|
||||||
|
<author>Sebastian Sdorra</author>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<url>http://bitbucket.org/sdorra/scm-manager</url>
|
||||||
|
</information>
|
||||||
|
|
||||||
<repository-handlers>
|
<resources>
|
||||||
<repository-handler>sonia.scm.repository.GitRepositoryHandler</repository-handler>
|
<script>/sonia/scm/git.config.js</script>
|
||||||
</repository-handlers>
|
</resources>
|
||||||
|
|
||||||
</plugin-config>
|
</plugin>
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import sonia.scm.io.ExtendedCommand;
|
|||||||
import sonia.scm.io.INIConfiguration;
|
import sonia.scm.io.INIConfiguration;
|
||||||
import sonia.scm.io.INIConfigurationWriter;
|
import sonia.scm.io.INIConfigurationWriter;
|
||||||
import sonia.scm.io.INISection;
|
import sonia.scm.io.INISection;
|
||||||
|
import sonia.scm.plugin.ext.Extension;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -53,6 +54,7 @@ import java.io.IOException;
|
|||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@Extension
|
||||||
public class HgRepositoryHandler
|
public class HgRepositoryHandler
|
||||||
extends AbstractSimpleRepositoryHandler<HgConfig>
|
extends AbstractSimpleRepositoryHandler<HgConfig>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ package sonia.scm.web;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import com.google.inject.servlet.ServletModule;
|
import com.google.inject.servlet.ServletModule;
|
||||||
|
import sonia.scm.plugin.ext.Extension;
|
||||||
|
|
||||||
import sonia.scm.web.filter.BasicAuthenticationFilter;
|
import sonia.scm.web.filter.BasicAuthenticationFilter;
|
||||||
|
|
||||||
@@ -43,6 +44,7 @@ import sonia.scm.web.filter.BasicAuthenticationFilter;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
|
@Extension
|
||||||
public class HgServletModule extends ServletModule
|
public class HgServletModule extends ServletModule
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -40,12 +40,18 @@
|
|||||||
Purpose of the document follows.
|
Purpose of the document follows.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<plugin-config>
|
<plugin>
|
||||||
|
|
||||||
<web-plugin>sonia.scm.web.HgWebPlugin</web-plugin>
|
<information>
|
||||||
|
<name>scm-hg-plugin</name>
|
||||||
|
<description>Mercurial Plugin</description>
|
||||||
|
<author>Sebastian Sdorra</author>
|
||||||
|
<version>1.0-M3-SNAPSHOT</version>
|
||||||
|
<url>http://bitbucket.org/sdorra/scm-manager</url>
|
||||||
|
</information>
|
||||||
|
|
||||||
<repository-handlers>
|
<resources>
|
||||||
<repository-handler>sonia.scm.repository.HgRepositoryHandler</repository-handler>
|
<script>/sonia/scm/hg.config.js</script>
|
||||||
</repository-handlers>
|
</resources>
|
||||||
|
|
||||||
</plugin-config>
|
</plugin>
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import org.tmatesoft.svn.core.SVNException;
|
|||||||
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
|
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
|
||||||
|
|
||||||
import sonia.scm.Type;
|
import sonia.scm.Type;
|
||||||
|
import sonia.scm.plugin.ext.Extension;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -52,6 +53,7 @@ import java.io.IOException;
|
|||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@Extension
|
||||||
public class SvnRepositoryHandler
|
public class SvnRepositoryHandler
|
||||||
extends AbstractSimpleRepositoryHandler<SvnConfig>
|
extends AbstractSimpleRepositoryHandler<SvnConfig>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,11 +43,13 @@ import sonia.scm.web.filter.BasicAuthenticationFilter;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import sonia.scm.plugin.ext.Extension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
|
@Extension
|
||||||
public class SvnServletModule extends ServletModule
|
public class SvnServletModule extends ServletModule
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -1,79 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2010, 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.web;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import sonia.scm.web.plugin.ClasspathWebResource;
|
|
||||||
import sonia.scm.web.plugin.ScmWebPlugin;
|
|
||||||
import sonia.scm.web.plugin.ScmWebPluginContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
public class SvnWebPlugin implements ScmWebPlugin
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String SCRIPT = "/sonia/scm/svn.config.js";
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void contextDestroyed(ScmWebPluginContext context)
|
|
||||||
{
|
|
||||||
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void contextInitialized(ScmWebPluginContext context)
|
|
||||||
{
|
|
||||||
context.addScriptResource(new ClasspathWebResource(SCRIPT));
|
|
||||||
context.addInjectModule(new SvnServletModule());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -40,12 +40,18 @@
|
|||||||
Purpose of the document follows.
|
Purpose of the document follows.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<plugin-config>
|
<plugin>
|
||||||
|
|
||||||
<web-plugin>sonia.scm.web.SvnWebPlugin</web-plugin>
|
<information>
|
||||||
|
<name>${project.name}</name>
|
||||||
|
<description>${project.description}</description>
|
||||||
|
<author>Sebastian Sdorra</author>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<url>http://bitbucket.org/sdorra/scm-manager</url>
|
||||||
|
</information>
|
||||||
|
|
||||||
<repository-handlers>
|
<resources>
|
||||||
<repository-handler>sonia.scm.repository.SvnRepositoryHandler</repository-handler>
|
<script>/sonia/scm/svn.config.js</script>
|
||||||
</repository-handlers>
|
</resources>
|
||||||
|
|
||||||
</plugin-config>
|
</plugin>
|
||||||
@@ -1 +0,0 @@
|
|||||||
sonia.scm.web.SvnWebPlugin
|
|
||||||
@@ -29,21 +29,31 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sonia.scm.web.plugin;
|
|
||||||
|
|
||||||
|
package sonia.scm.plugin;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import sonia.scm.plugin.ext.ExtensionObject;
|
||||||
|
import sonia.scm.plugin.ext.ExtensionProcessor;
|
||||||
|
import sonia.scm.plugin.ext.JARExtensionScanner;
|
||||||
|
import sonia.scm.util.IOUtil;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.xml.bind.JAXB;
|
import javax.xml.bind.JAXB;
|
||||||
@@ -52,15 +62,38 @@ import javax.xml.bind.JAXB;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public class SCMPluginManager
|
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";
|
||||||
|
|
||||||
/** Field description */
|
/** the logger for DefaultPluginManager */
|
||||||
private static final Logger logger =
|
private static final Logger logger =
|
||||||
LoggerFactory.getLogger(SCMPluginManager.class);
|
LoggerFactory.getLogger(DefaultPluginManager.class);
|
||||||
|
|
||||||
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public DefaultPluginManager()
|
||||||
|
{
|
||||||
|
ClassLoader classLoader = getClassLoader();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
load(classLoader);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
@@ -68,20 +101,64 @@ public class SCMPluginManager
|
|||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @param processor
|
||||||
*/
|
*/
|
||||||
public void load() throws IOException
|
@Override
|
||||||
|
public void processExtensions(ExtensionProcessor processor)
|
||||||
{
|
{
|
||||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
Set<ExtensionObject> extensions = new HashSet<ExtensionObject>();
|
||||||
|
ClassLoader classLoader = getClassLoader();
|
||||||
|
JARExtensionScanner scanner = new JARExtensionScanner();
|
||||||
|
|
||||||
if (classLoader == null)
|
for (Plugin plugin : plugins)
|
||||||
{
|
{
|
||||||
classLoader = SCMPluginManager.class.getClassLoader();
|
InputStream input = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Set<String> packageSet = plugin.getPackageSet();
|
||||||
|
|
||||||
|
if (packageSet == null)
|
||||||
|
{
|
||||||
|
packageSet = new HashSet<String>();
|
||||||
|
}
|
||||||
|
|
||||||
|
packageSet.add(DEFAULT_PACKAGE);
|
||||||
|
input = new FileInputStream(plugin.getPath());
|
||||||
|
scanner.processExtensions(classLoader, extensions, input, packageSet);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
logger.error(ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IOUtil.close(input);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
load(classLoader);
|
for (ExtensionObject exo : extensions)
|
||||||
|
{
|
||||||
|
processor.processExtension(exo.getExtension(), exo.getExtensionClass());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Collection<Plugin> getPlugins()
|
||||||
|
{
|
||||||
|
return plugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -90,7 +167,7 @@ public class SCMPluginManager
|
|||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void load(ClassLoader classLoader) throws IOException
|
private void load(ClassLoader classLoader) throws IOException
|
||||||
{
|
{
|
||||||
Enumeration<URL> urlEnum = classLoader.getResources(PATH_PLUGINCONFIG);
|
Enumeration<URL> urlEnum = classLoader.getResources(PATH_PLUGINCONFIG);
|
||||||
|
|
||||||
@@ -105,21 +182,6 @@ public class SCMPluginManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public Set<SCMPlugin> getPlugins()
|
|
||||||
{
|
|
||||||
return plugins;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -130,13 +192,20 @@ public class SCMPluginManager
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SCMPlugin plugin = JAXB.unmarshal(url, SCMPlugin.class);
|
|
||||||
|
// jar:file:/some/path/file.jar!/META-INF/scm/plugin.xml
|
||||||
|
String path = url.toExternalForm();
|
||||||
|
|
||||||
|
path = path.substring("jar:file:".length(), path.lastIndexOf("!"));
|
||||||
|
|
||||||
if (logger.isInfoEnabled())
|
if (logger.isInfoEnabled())
|
||||||
{
|
{
|
||||||
logger.info("load plugin {}", url.toExternalForm());
|
logger.info("load plugin {}", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Plugin plugin = JAXB.unmarshal(url, Plugin.class);
|
||||||
|
|
||||||
|
plugin.setPath(path);
|
||||||
plugins.add(plugin);
|
plugins.add(plugin);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -145,8 +214,28 @@ public class SCMPluginManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private ClassLoader getClassLoader()
|
||||||
|
{
|
||||||
|
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
|
if (classLoader == null)
|
||||||
|
{
|
||||||
|
classLoader = DefaultPluginManager.class.getClassLoader();
|
||||||
|
}
|
||||||
|
|
||||||
|
return classLoader;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Set<SCMPlugin> plugins = new LinkedHashSet<SCMPlugin>();
|
private Set<Plugin> plugins = new HashSet<Plugin>();
|
||||||
}
|
}
|
||||||
@@ -31,15 +31,12 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.web.plugin;
|
package sonia.scm.plugin;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import sonia.scm.repository.RepositoryHandler;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.net.URL;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
@@ -47,36 +44,26 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
|||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import javax.xml.bind.annotation.XmlTransient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@XmlRootElement(name = "plugin-config")
|
@XmlRootElement
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
public class SCMPlugin
|
public class Plugin
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public SCMPlugin()
|
|
||||||
{
|
|
||||||
repositoryHandlers = new HashSet<Class<? extends RepositoryHandler>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Class<? extends RepositoryHandler>> getRepositoryHandlers()
|
public PluginInformation getInformation()
|
||||||
{
|
{
|
||||||
return repositoryHandlers;
|
return information;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,9 +72,9 @@ public class SCMPlugin
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public SecurityConfig getSecurityConfig()
|
public Set<String> getPackageSet()
|
||||||
{
|
{
|
||||||
return securityConfig;
|
return packageSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,9 +83,20 @@ public class SCMPlugin
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Class<? extends ScmWebPlugin> getWebPlugin()
|
public String getPath()
|
||||||
{
|
{
|
||||||
return webPlugin;
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public PluginResources getResources()
|
||||||
|
{
|
||||||
|
return resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
//~--- set methods ----------------------------------------------------------
|
||||||
@@ -107,48 +105,60 @@ public class SCMPlugin
|
|||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param repositoryHandlers
|
* @param information
|
||||||
*/
|
*/
|
||||||
public void setRepositoryHandlers(
|
public void setInformation(PluginInformation information)
|
||||||
Set<Class<? extends RepositoryHandler>> repositoryHandlers)
|
|
||||||
{
|
{
|
||||||
this.repositoryHandlers = repositoryHandlers;
|
this.information = information;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param securityConfig
|
* @param packageSet
|
||||||
*/
|
*/
|
||||||
public void setSecurityConfig(SecurityConfig securityConfig)
|
public void setPackageSet(Set<String> packageSet)
|
||||||
{
|
{
|
||||||
this.securityConfig = securityConfig;
|
this.packageSet = packageSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param webPlugin
|
* @param path
|
||||||
*/
|
*/
|
||||||
public void setWebPlugin(Class<? extends ScmWebPlugin> webPlugin)
|
public void setPath(String path)
|
||||||
{
|
{
|
||||||
this.webPlugin = webPlugin;
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param resources
|
||||||
|
*/
|
||||||
|
public void setResources(PluginResources resources)
|
||||||
|
{
|
||||||
|
this.resources = resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@XmlElementWrapper(name = "repository-handlers")
|
private PluginInformation information;
|
||||||
@XmlElement(name = "repository-handler")
|
|
||||||
private Set<Class<? extends RepositoryHandler>> repositoryHandlers;
|
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@XmlElement(name = "security")
|
@XmlElement(name = "package")
|
||||||
private SecurityConfig securityConfig;
|
@XmlElementWrapper(name = "packages")
|
||||||
|
private Set<String> packageSet;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@XmlElement(name = "web-plugin")
|
@XmlTransient
|
||||||
private Class<? extends ScmWebPlugin> webPlugin;
|
private String path;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private PluginResources resources;
|
||||||
}
|
}
|
||||||
@@ -29,95 +29,26 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sonia.scm.web.plugin;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.google.inject.Module;
|
package sonia.scm.plugin;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public class ScmWebPluginContext
|
public class PluginInformation
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param servletContext
|
|
||||||
*/
|
|
||||||
public ScmWebPluginContext(ServletContext servletContext)
|
|
||||||
{
|
|
||||||
this.servletContext = servletContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param module
|
|
||||||
*/
|
|
||||||
public void addInjectModule(Module module)
|
|
||||||
{
|
|
||||||
injectModules.add(module);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param resource
|
|
||||||
*/
|
|
||||||
public void addScriptResource(WebResource resource)
|
|
||||||
{
|
|
||||||
scriptResources.add(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param module
|
|
||||||
*/
|
|
||||||
public void removeInjectModule(Module module)
|
|
||||||
{
|
|
||||||
injectModules.remove(module);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param resource
|
|
||||||
*/
|
|
||||||
public void removeScriptResource(WebResource resource)
|
|
||||||
{
|
|
||||||
scriptResources.remove(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Collection<Module> getInjectModules()
|
public String getAuthor()
|
||||||
{
|
{
|
||||||
return injectModules;
|
return author;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,9 +57,9 @@ public class ScmWebPluginContext
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Collection<WebResource> getScriptResources()
|
public String getDescription()
|
||||||
{
|
{
|
||||||
return scriptResources;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -137,19 +68,104 @@ public class ScmWebPluginContext
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public ServletContext getServletContext()
|
public String getName()
|
||||||
{
|
{
|
||||||
return servletContext;
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getUrl()
|
||||||
|
{
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getVersion()
|
||||||
|
{
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- set methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param author
|
||||||
|
*/
|
||||||
|
public void setAuthor(String author)
|
||||||
|
{
|
||||||
|
this.author = author;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param description
|
||||||
|
*/
|
||||||
|
public void setDescription(String description)
|
||||||
|
{
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
public void setName(String name)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
*/
|
||||||
|
public void setUrl(String url)
|
||||||
|
{
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param version
|
||||||
|
*/
|
||||||
|
public void setVersion(String version)
|
||||||
|
{
|
||||||
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Set<WebResource> scriptResources = new HashSet<WebResource>();
|
private String author;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Set<Module> injectModules = new HashSet<Module>();
|
private String description;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private ServletContext servletContext;
|
private String name;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private String version;
|
||||||
}
|
}
|
||||||
@@ -35,39 +35,36 @@ package sonia.scm.plugin;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import sonia.scm.web.plugin.WebResource;
|
import com.google.inject.Binder;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.util.Collection;
|
||||||
|
import sonia.scm.plugin.ext.ExtensionProcessor;
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public class WebResourceComparator
|
public interface PluginManager
|
||||||
implements Comparator<WebResource>, Serializable
|
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private static final long serialVersionUID = -5916499507958881372L;
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param resource
|
* @param binder
|
||||||
* @param resource1
|
*/
|
||||||
|
public void processExtensions(ExtensionProcessor processor);
|
||||||
|
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
public Collection<Plugin> getPlugins();
|
||||||
public int compare(WebResource resource, WebResource resource1)
|
|
||||||
{
|
|
||||||
return resource.getId().compareTo(resource1.getId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -29,15 +29,14 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sonia.scm.web.plugin;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import sonia.scm.security.EncryptionHandler;
|
package sonia.scm.plugin;
|
||||||
import sonia.scm.web.security.Authenticator;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
@@ -46,8 +45,8 @@ import javax.xml.bind.annotation.XmlElement;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.NONE)
|
||||||
public class SecurityConfig
|
public class PluginResources
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,9 +55,9 @@ public class SecurityConfig
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Class<? extends Authenticator> getAuthenticator()
|
public Set<String> getScriptResources()
|
||||||
{
|
{
|
||||||
return authenticator;
|
return scriptResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,9 +66,9 @@ public class SecurityConfig
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Class<? extends EncryptionHandler> getEncryptionHandler()
|
public Set<String> getStylesheetResources()
|
||||||
{
|
{
|
||||||
return encryptionHandler;
|
return stylesheetResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
//~--- set methods ----------------------------------------------------------
|
||||||
@@ -78,32 +77,31 @@ public class SecurityConfig
|
|||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param authenticator
|
* @param scriptResources
|
||||||
*/
|
*/
|
||||||
public void setAuthenticator(Class<? extends Authenticator> authenticator)
|
public void setScriptResources(Set<String> scriptResources)
|
||||||
{
|
{
|
||||||
this.authenticator = authenticator;
|
this.scriptResources = scriptResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param encryptionHandler
|
* @param stylesheetResources
|
||||||
*/
|
*/
|
||||||
public void setEncryptionHandler(
|
public void setStylesheetResources(Set<String> stylesheetResources)
|
||||||
Class<? extends EncryptionHandler> encryptionHandler)
|
|
||||||
{
|
{
|
||||||
this.encryptionHandler = encryptionHandler;
|
this.stylesheetResources = stylesheetResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@XmlElement(name = "authenticator")
|
@XmlElement(name = "script")
|
||||||
private Class<? extends Authenticator> authenticator;
|
private Set<String> scriptResources;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@XmlElement(name = "encryption-handler")
|
@XmlElement(name = "stylesheet")
|
||||||
private Class<? extends EncryptionHandler> encryptionHandler;
|
private Set<String> stylesheetResources;
|
||||||
}
|
}
|
||||||
@@ -31,35 +31,21 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.web.plugin;
|
package sonia.scm.plugin.ext;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.lang.annotation.Documented;
|
||||||
import java.io.InputStream;
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public interface WebResource
|
@Documented
|
||||||
{
|
@Target({ ElementType.TYPE })
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
/**
|
public @interface Extension {}
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public InputStream getContent() throws IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getId();
|
|
||||||
}
|
|
||||||
@@ -31,28 +31,26 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.web.plugin;
|
package sonia.scm.plugin.ext;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public class ClasspathWebResource implements WebResource
|
public class ExtensionObject
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param contentPath
|
* @param extension
|
||||||
|
* @param extensionClass
|
||||||
*/
|
*/
|
||||||
public ClasspathWebResource(String contentPath)
|
public ExtensionObject(Extension extension, Class<?> extensionClass)
|
||||||
{
|
{
|
||||||
this.contentPath = contentPath;
|
this.extension = extension;
|
||||||
|
this.extensionClass = extensionClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@@ -63,10 +61,9 @@ public class ClasspathWebResource implements WebResource
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
public Extension getExtension()
|
||||||
public InputStream getContent()
|
|
||||||
{
|
{
|
||||||
return ClasspathWebResource.class.getResourceAsStream(contentPath);
|
return extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,14 +72,16 @@ public class ClasspathWebResource implements WebResource
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
public Class<?> getExtensionClass()
|
||||||
public String getId()
|
|
||||||
{
|
{
|
||||||
return contentPath;
|
return extensionClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private String contentPath;
|
private Extension extension;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private Class<?> extensionClass;
|
||||||
}
|
}
|
||||||
@@ -29,28 +29,23 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sonia.scm.web.plugin;
|
|
||||||
|
|
||||||
|
package sonia.scm.plugin.ext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public interface ScmWebPlugin
|
public interface ExtensionProcessor
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param context
|
* @param extension
|
||||||
|
* @param extensionClass
|
||||||
*/
|
*/
|
||||||
public void contextDestroyed(ScmWebPluginContext context);
|
public void processExtension(Extension extension, Class<?> extensionClass);
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
*/
|
|
||||||
public void contextInitialized(ScmWebPluginContext context);
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010, 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.ext;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public interface ExtensionScanner
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param classLoader
|
||||||
|
* @param extensionObjects
|
||||||
|
* @param input
|
||||||
|
* @param packagess
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void processExtensions(ClassLoader classLoader,
|
||||||
|
Collection<ExtensionObject> extensionObjects,
|
||||||
|
InputStream input, Collection<String> packagess)
|
||||||
|
throws IOException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,228 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010, 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.ext;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import sonia.scm.util.IOUtil;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarInputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class JARExtensionScanner implements ExtensionScanner
|
||||||
|
{
|
||||||
|
|
||||||
|
/** the logger for JARExtensionScanner */
|
||||||
|
private static final Logger logger =
|
||||||
|
LoggerFactory.getLogger(JARExtensionScanner.class);
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param classLoader
|
||||||
|
* @param extensionObjects
|
||||||
|
* @param inputStream
|
||||||
|
* @param packages
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void processExtensions(ClassLoader classLoader,
|
||||||
|
Collection<ExtensionObject> extensionObjects,
|
||||||
|
InputStream inputStream,
|
||||||
|
Collection<String> packages)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
JarInputStream input = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
input = new JarInputStream(inputStream);
|
||||||
|
|
||||||
|
JarEntry entry = input.getNextJarEntry();
|
||||||
|
|
||||||
|
while (entry != null)
|
||||||
|
{
|
||||||
|
if (!entry.isDirectory())
|
||||||
|
{
|
||||||
|
processEntry(classLoader, extensionObjects, packages, entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
entry = input.getNextJarEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IOUtil.close(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param classLoader
|
||||||
|
* @param name
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Class<?> createClass(ClassLoader classLoader, String name)
|
||||||
|
{
|
||||||
|
Class<?> clazz = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
clazz = classLoader.loadClass(name);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.error(ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param classLoader
|
||||||
|
* @param extensionObjects
|
||||||
|
* @param packages
|
||||||
|
* @param entry
|
||||||
|
*/
|
||||||
|
private void processEntry(ClassLoader classLoader,
|
||||||
|
Collection<ExtensionObject> extensionObjects,
|
||||||
|
Collection<String> packages, JarEntry entry)
|
||||||
|
{
|
||||||
|
String name = entry.getName();
|
||||||
|
|
||||||
|
if (name.endsWith(".class"))
|
||||||
|
{
|
||||||
|
name = getClassName(name);
|
||||||
|
|
||||||
|
if (isManagedClass(packages, name))
|
||||||
|
{
|
||||||
|
Class<?> managedClass = createClass(classLoader, name);
|
||||||
|
|
||||||
|
if (managedClass != null)
|
||||||
|
{
|
||||||
|
processManagedClass(extensionObjects, managedClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param extensionObjects
|
||||||
|
* @param managedClass
|
||||||
|
*/
|
||||||
|
private void processManagedClass(
|
||||||
|
Collection<ExtensionObject> extensionObjects, Class<?> managedClass)
|
||||||
|
{
|
||||||
|
Extension extension = managedClass.getAnnotation(Extension.class);
|
||||||
|
|
||||||
|
if (extension != null)
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("found extension class {}", managedClass.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
extensionObjects.add(new ExtensionObject(extension, managedClass));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String getClassName(String name)
|
||||||
|
{
|
||||||
|
return name.replaceAll("/", ".").substring(0, name.length() - 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param packages
|
||||||
|
* @param name
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean isManagedClass(Collection<String> packages, String name)
|
||||||
|
{
|
||||||
|
boolean result = false;
|
||||||
|
|
||||||
|
for (String pkg : packages)
|
||||||
|
{
|
||||||
|
if (name.startsWith(pkg))
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
<artifactId>scm-hg-plugin</artifactId>
|
<artifactId>scm-hg-plugin</artifactId>
|
||||||
<version>1.0-M3-SNAPSHOT</version>
|
<version>1.0-M3-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>sonia.scm.plugins</groupId>
|
<groupId>sonia.scm.plugins</groupId>
|
||||||
<artifactId>scm-svn-plugin</artifactId>
|
<artifactId>scm-svn-plugin</artifactId>
|
||||||
|
|||||||
@@ -0,0 +1,226 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010, 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;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.inject.Binder;
|
||||||
|
import com.google.inject.Module;
|
||||||
|
import com.google.inject.multibindings.Multibinder;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import sonia.scm.plugin.ext.Extension;
|
||||||
|
import sonia.scm.plugin.ext.ExtensionProcessor;
|
||||||
|
import sonia.scm.repository.RepositoryHandler;
|
||||||
|
import sonia.scm.security.EncryptionHandler;
|
||||||
|
import sonia.scm.web.security.Authenticator;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class BindingExtensionProcessor implements ExtensionProcessor
|
||||||
|
{
|
||||||
|
|
||||||
|
/** the logger for BindingExtensionProcessor */
|
||||||
|
private static final Logger logger =
|
||||||
|
LoggerFactory.getLogger(BindingExtensionProcessor.class);
|
||||||
|
|
||||||
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public BindingExtensionProcessor()
|
||||||
|
{
|
||||||
|
this.moduleSet = new HashSet<Module>();
|
||||||
|
this.extensions = new HashSet<Class<?>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param binder
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void bindExtensions(Binder binder)
|
||||||
|
{
|
||||||
|
Multibinder<RepositoryHandler> repositoryHandlers =
|
||||||
|
Multibinder.newSetBinder(binder, RepositoryHandler.class);
|
||||||
|
|
||||||
|
for (Class extensionClass : extensions)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (RepositoryHandler.class.isAssignableFrom(extensionClass))
|
||||||
|
{
|
||||||
|
if (logger.isInfoEnabled())
|
||||||
|
{
|
||||||
|
logger.info("bind RepositoryHandler {}", extensionClass.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
binder.bind(extensionClass);
|
||||||
|
|
||||||
|
repositoryHandlers.addBinding().to(extensionClass);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (EncryptionHandler.class.isAssignableFrom(extensionClass))
|
||||||
|
{
|
||||||
|
bind(binder, EncryptionHandler.class, extensionClass);
|
||||||
|
}
|
||||||
|
else if (Authenticator.class.isAssignableFrom(extensionClass))
|
||||||
|
{
|
||||||
|
bind(binder, Authenticator.class, extensionClass);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (logger.isInfoEnabled())
|
||||||
|
{
|
||||||
|
logger.info("bind {}", extensionClass.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
binder.bind(extensionClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.error(ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param extension
|
||||||
|
* @param extensionClass
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void processExtension(Extension extension, Class extensionClass)
|
||||||
|
{
|
||||||
|
if (Module.class.isAssignableFrom(extensionClass))
|
||||||
|
{
|
||||||
|
if (logger.isInfoEnabled())
|
||||||
|
{
|
||||||
|
logger.info("add GuiceModule {}", extensionClass.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
addModuleClass(extensionClass);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
extensions.add(extensionClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Set<Module> getModuleSet()
|
||||||
|
{
|
||||||
|
return moduleSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param extensionClass
|
||||||
|
*/
|
||||||
|
private void addModuleClass(Class<? extends Module> extensionClass)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Module module = extensionClass.newInstance();
|
||||||
|
|
||||||
|
moduleSet.add(module);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.error(ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param binder
|
||||||
|
* @param type
|
||||||
|
* @param bindingType
|
||||||
|
* @param <T>
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private <T> void bind(Binder binder, Class<T> type,
|
||||||
|
Class<? extends T> bindingType)
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("bind Authenticator {}", type.getName(),
|
||||||
|
bindingType.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
binder.bind(type).to(bindingType);
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private Set<Class<?>> extensions;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private Set<Module> moduleSet;
|
||||||
|
}
|
||||||
@@ -40,29 +40,16 @@ import com.google.inject.Injector;
|
|||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.servlet.GuiceServletContextListener;
|
import com.google.inject.servlet.GuiceServletContextListener;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import sonia.scm.plugin.DefaultPluginManager;
|
||||||
import org.slf4j.LoggerFactory;
|
import sonia.scm.plugin.PluginManager;
|
||||||
|
|
||||||
import sonia.scm.repository.RepositoryManager;
|
import sonia.scm.repository.RepositoryManager;
|
||||||
import sonia.scm.user.UserManager;
|
import sonia.scm.user.UserManager;
|
||||||
import sonia.scm.util.Util;
|
|
||||||
import sonia.scm.web.plugin.SCMPlugin;
|
|
||||||
import sonia.scm.web.plugin.SCMPluginManager;
|
|
||||||
import sonia.scm.web.plugin.ScmWebPlugin;
|
|
||||||
import sonia.scm.web.plugin.ScmWebPluginContext;
|
|
||||||
import sonia.scm.web.security.Authenticator;
|
import sonia.scm.web.security.Authenticator;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContextEvent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -71,77 +58,6 @@ import javax.servlet.ServletContextEvent;
|
|||||||
public class ContextListener extends GuiceServletContextListener
|
public class ContextListener extends GuiceServletContextListener
|
||||||
{
|
{
|
||||||
|
|
||||||
/** the logger for ContextListener */
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(ContextListener.class);
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param servletContextEvent
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void contextDestroyed(ServletContextEvent servletContextEvent)
|
|
||||||
{
|
|
||||||
for (ScmWebPlugin plugin : webPluginSet)
|
|
||||||
{
|
|
||||||
plugin.contextDestroyed(webPluginContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.contextDestroyed(servletContextEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param servletContextEvent
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void contextInitialized(ServletContextEvent servletContextEvent)
|
|
||||||
{
|
|
||||||
pluginManager = new SCMPluginManager();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pluginManager.load();
|
|
||||||
webPluginContext =
|
|
||||||
new ScmWebPluginContext(servletContextEvent.getServletContext());
|
|
||||||
|
|
||||||
for (SCMPlugin plugin : pluginManager.getPlugins())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
webPluginSet.add(plugin.getWebPlugin().newInstance());
|
|
||||||
}
|
|
||||||
catch (InstantiationException ex)
|
|
||||||
{
|
|
||||||
logger.error(ex.getMessage(), ex);
|
|
||||||
}
|
|
||||||
catch (IllegalAccessException ex)
|
|
||||||
{
|
|
||||||
logger.error(ex.getMessage(), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ScmWebPlugin plugin : webPluginSet)
|
|
||||||
{
|
|
||||||
plugin.contextInitialized(webPluginContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.contextInitialized(servletContextEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -151,18 +67,19 @@ public class ContextListener extends GuiceServletContextListener
|
|||||||
@Override
|
@Override
|
||||||
protected Injector getInjector()
|
protected Injector getInjector()
|
||||||
{
|
{
|
||||||
List<Module> modules = new ArrayList<Module>();
|
PluginManager manager = new DefaultPluginManager();
|
||||||
|
BindingExtensionProcessor bindExtProcessor =
|
||||||
|
new BindingExtensionProcessor();
|
||||||
|
|
||||||
modules.add(new ScmServletModule(pluginManager, webPluginContext));
|
manager.processExtensions(bindExtProcessor);
|
||||||
|
|
||||||
Collection<Module> pluginModules = webPluginContext.getInjectModules();
|
ScmServletModule main = new ScmServletModule(manager, bindExtProcessor);
|
||||||
|
List<Module> moduleList =
|
||||||
|
new ArrayList<Module>(bindExtProcessor.getModuleSet());
|
||||||
|
|
||||||
if (Util.isNotEmpty(pluginModules))
|
moduleList.add(0, main);
|
||||||
{
|
|
||||||
modules.addAll(pluginModules);
|
|
||||||
}
|
|
||||||
|
|
||||||
Injector injector = Guice.createInjector(modules);
|
Injector injector = Guice.createInjector(moduleList);
|
||||||
|
|
||||||
// init RepositoryManager
|
// init RepositoryManager
|
||||||
injector.getInstance(RepositoryManager.class).init(SCMContext.getContext());
|
injector.getInstance(RepositoryManager.class).init(SCMContext.getContext());
|
||||||
@@ -175,15 +92,4 @@ public class ContextListener extends GuiceServletContextListener
|
|||||||
|
|
||||||
return injector;
|
return injector;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private SCMPluginManager pluginManager;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private ScmWebPluginContext webPluginContext;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private Set<ScmWebPlugin> webPluginSet = new LinkedHashSet<ScmWebPlugin>();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ package sonia.scm;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import com.google.inject.multibindings.Multibinder;
|
|
||||||
import com.google.inject.servlet.ServletModule;
|
import com.google.inject.servlet.ServletModule;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -46,20 +45,16 @@ 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.PluginManager;
|
||||||
import sonia.scm.plugin.ScriptResourceServlet;
|
import sonia.scm.plugin.ScriptResourceServlet;
|
||||||
import sonia.scm.repository.RepositoryHandler;
|
|
||||||
import sonia.scm.repository.RepositoryManager;
|
import sonia.scm.repository.RepositoryManager;
|
||||||
import sonia.scm.repository.xml.XmlRepositoryManager;
|
import sonia.scm.repository.xml.XmlRepositoryManager;
|
||||||
import sonia.scm.security.EncryptionHandler;
|
import sonia.scm.security.EncryptionHandler;
|
||||||
import sonia.scm.security.MessageDigestEncryptionHandler;
|
import sonia.scm.security.MessageDigestEncryptionHandler;
|
||||||
|
import sonia.scm.security.SecurityContext;
|
||||||
import sonia.scm.user.UserManager;
|
import sonia.scm.user.UserManager;
|
||||||
import sonia.scm.user.xml.XmlUserManager;
|
import sonia.scm.user.xml.XmlUserManager;
|
||||||
import sonia.scm.util.DebugServlet;
|
import sonia.scm.util.DebugServlet;
|
||||||
import sonia.scm.util.Util;
|
|
||||||
import sonia.scm.web.plugin.SCMPlugin;
|
|
||||||
import sonia.scm.web.plugin.SCMPluginManager;
|
|
||||||
import sonia.scm.web.plugin.ScmWebPluginContext;
|
|
||||||
import sonia.scm.web.plugin.SecurityConfig;
|
|
||||||
import sonia.scm.web.security.Authenticator;
|
import sonia.scm.web.security.Authenticator;
|
||||||
import sonia.scm.web.security.BasicSecurityContext;
|
import sonia.scm.web.security.BasicSecurityContext;
|
||||||
import sonia.scm.web.security.WebSecurityContext;
|
import sonia.scm.web.security.WebSecurityContext;
|
||||||
@@ -74,14 +69,10 @@ 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.LinkedHashSet;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXB;
|
import javax.xml.bind.JAXB;
|
||||||
import sonia.scm.security.SecurityContext;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -131,15 +122,14 @@ public class ScmServletModule extends ServletModule
|
|||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
* @param manager
|
||||||
* @param pluginManager
|
* @param bindExtProcessor
|
||||||
* @param webPluginContext
|
|
||||||
*/
|
*/
|
||||||
ScmServletModule(SCMPluginManager pluginManager,
|
ScmServletModule(PluginManager manager,
|
||||||
ScmWebPluginContext webPluginContext)
|
BindingExtensionProcessor bindExtProcessor)
|
||||||
{
|
{
|
||||||
this.pluginManager = pluginManager;
|
this.pluginManager = manager;
|
||||||
this.webPluginContext = webPluginContext;
|
this.bindExtProcessor = bindExtProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
@@ -158,19 +148,18 @@ public class ScmServletModule extends ServletModule
|
|||||||
ScmConfiguration config = getScmConfiguration(context);
|
ScmConfiguration config = getScmConfiguration(context);
|
||||||
|
|
||||||
bind(ScmConfiguration.class).toInstance(config);
|
bind(ScmConfiguration.class).toInstance(config);
|
||||||
|
bind(PluginManager.class).toInstance(pluginManager);
|
||||||
// bind(EncryptionHandler.class).to(MessageDigestEncryptionHandler.class);
|
bind(EncryptionHandler.class).to(MessageDigestEncryptionHandler.class);
|
||||||
// bind(Authenticator.class).to(XmlAuthenticator.class);
|
bind(Authenticator.class).to(XmlAuthenticator.class);
|
||||||
bind(SecurityContext.class).to(BasicSecurityContext.class);
|
bind(SecurityContext.class).to(BasicSecurityContext.class);
|
||||||
bind(WebSecurityContext.class).to(BasicSecurityContext.class);
|
bind(WebSecurityContext.class).to(BasicSecurityContext.class);
|
||||||
loadPlugins(pluginManager);
|
bindExtProcessor.bindExtensions(binder());
|
||||||
bind(CacheManager.class).to(EhCacheManager.class);
|
bind(CacheManager.class).to(EhCacheManager.class);
|
||||||
|
|
||||||
// bind(RepositoryManager.class).annotatedWith(Undecorated.class).to(
|
// bind(RepositoryManager.class).annotatedWith(Undecorated.class).to(
|
||||||
// BasicRepositoryManager.class);
|
// BasicRepositoryManager.class);
|
||||||
bind(RepositoryManager.class).to(XmlRepositoryManager.class);
|
bind(RepositoryManager.class).to(XmlRepositoryManager.class);
|
||||||
bind(UserManager.class).to(XmlUserManager.class);
|
bind(UserManager.class).to(XmlUserManager.class);
|
||||||
bind(ScmWebPluginContext.class).toInstance(webPluginContext);
|
|
||||||
|
|
||||||
// filter(PATTERN_RESTAPI).through(LoggingFilter.class);
|
// filter(PATTERN_RESTAPI).through(LoggingFilter.class);
|
||||||
|
|
||||||
@@ -206,91 +195,6 @@ public class ScmServletModule extends ServletModule
|
|||||||
serve(PATTERN_RESTAPI).with(GuiceContainer.class, params);
|
serve(PATTERN_RESTAPI).with(GuiceContainer.class, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repositoryHandlerBinder
|
|
||||||
* @param handlerSet
|
|
||||||
*/
|
|
||||||
private void bindRepositoryHandlers(
|
|
||||||
Multibinder<RepositoryHandler> repositoryHandlerBinder,
|
|
||||||
Set<Class<? extends RepositoryHandler>> handlerSet)
|
|
||||||
{
|
|
||||||
for (Class<? extends RepositoryHandler> handlerClass : handlerSet)
|
|
||||||
{
|
|
||||||
if (logger.isInfoEnabled())
|
|
||||||
{
|
|
||||||
logger.info("load RepositoryHandler {}", handlerClass.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
bind(handlerClass);
|
|
||||||
repositoryHandlerBinder.addBinding().to(handlerClass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param pluginManager
|
|
||||||
*/
|
|
||||||
private void loadPlugins(SCMPluginManager pluginManager)
|
|
||||||
{
|
|
||||||
Set<SCMPlugin> pluginSet = pluginManager.getPlugins();
|
|
||||||
|
|
||||||
if (Util.isNotEmpty(pluginSet))
|
|
||||||
{
|
|
||||||
|
|
||||||
// repository handlers
|
|
||||||
Multibinder<RepositoryHandler> repositoryHandlerBinder =
|
|
||||||
Multibinder.newSetBinder(binder(), RepositoryHandler.class);
|
|
||||||
Set<Class<? extends RepositoryHandler>> repositoryHandlerSet =
|
|
||||||
new LinkedHashSet<Class<? extends RepositoryHandler>>();
|
|
||||||
|
|
||||||
// security stuff
|
|
||||||
Class<? extends EncryptionHandler> encryptionHandler =
|
|
||||||
MessageDigestEncryptionHandler.class;
|
|
||||||
Class<? extends Authenticator> authenticator = XmlAuthenticator.class;
|
|
||||||
|
|
||||||
for (SCMPlugin plugin : pluginSet)
|
|
||||||
{
|
|
||||||
Collection<Class<? extends RepositoryHandler>> pluginRepositoryHandlers =
|
|
||||||
plugin.getRepositoryHandlers();
|
|
||||||
|
|
||||||
if (Util.isNotEmpty(pluginRepositoryHandlers))
|
|
||||||
{
|
|
||||||
repositoryHandlerSet.addAll(pluginRepositoryHandlers);
|
|
||||||
}
|
|
||||||
|
|
||||||
SecurityConfig securityConfig = plugin.getSecurityConfig();
|
|
||||||
|
|
||||||
if (securityConfig != null)
|
|
||||||
{
|
|
||||||
Class<? extends EncryptionHandler> enc =
|
|
||||||
securityConfig.getEncryptionHandler();
|
|
||||||
|
|
||||||
if (enc != null)
|
|
||||||
{
|
|
||||||
encryptionHandler = enc;
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<? extends Authenticator> auth =
|
|
||||||
securityConfig.getAuthenticator();
|
|
||||||
|
|
||||||
if (auth != null)
|
|
||||||
{
|
|
||||||
authenticator = auth;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bind(EncryptionHandler.class).to(encryptionHandler);
|
|
||||||
bind(Authenticator.class).to(authenticator);
|
|
||||||
bindRepositoryHandlers(repositoryHandlerBinder, repositoryHandlerSet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -329,8 +233,8 @@ public class ScmServletModule extends ServletModule
|
|||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private SCMPluginManager pluginManager;
|
private BindingExtensionProcessor bindExtProcessor;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private ScmWebPluginContext webPluginContext;
|
private PluginManager pluginManager;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,25 +213,27 @@ public class RepositoryResource extends AbstractResource<Repository>
|
|||||||
*/
|
*/
|
||||||
private void appendUrl(Repository repository)
|
private void appendUrl(Repository repository)
|
||||||
{
|
{
|
||||||
StringBuilder url = new StringBuilder(request.getScheme());
|
|
||||||
|
|
||||||
url.append("://").append(configuration.getServername());
|
|
||||||
url.append(":").append(request.getLocalPort());
|
|
||||||
|
|
||||||
String ctxPath = request.getContextPath();
|
|
||||||
|
|
||||||
if (ctxPath.endsWith("/"))
|
|
||||||
{
|
|
||||||
ctxPath = ctxPath.substring(0, ctxPath.length() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
url.append(ctxPath);
|
|
||||||
|
|
||||||
RepositoryHandler handler =
|
RepositoryHandler handler =
|
||||||
repositoryManager.getHandler(repository.getType());
|
repositoryManager.getHandler(repository.getType());
|
||||||
|
|
||||||
url.append(handler.createResourcePath(repository));
|
if (handler != null)
|
||||||
repository.setUrl(url.toString());
|
{
|
||||||
|
StringBuilder url = new StringBuilder(request.getScheme());
|
||||||
|
|
||||||
|
url.append("://").append(configuration.getServername());
|
||||||
|
url.append(":").append(request.getLocalPort());
|
||||||
|
|
||||||
|
String ctxPath = request.getContextPath();
|
||||||
|
|
||||||
|
if (ctxPath.endsWith("/"))
|
||||||
|
{
|
||||||
|
ctxPath = ctxPath.substring(0, ctxPath.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
url.append(ctxPath);
|
||||||
|
url.append(handler.createResourcePath(repository));
|
||||||
|
repository.setUrl(url.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|||||||
@@ -40,8 +40,6 @@ import com.google.inject.Singleton;
|
|||||||
|
|
||||||
import sonia.scm.util.IOUtil;
|
import sonia.scm.util.IOUtil;
|
||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
import sonia.scm.web.plugin.ScmWebPluginContext;
|
|
||||||
import sonia.scm.web.plugin.WebResource;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -49,10 +47,9 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Set;
|
||||||
import java.util.List;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
|
||||||
@@ -70,6 +67,20 @@ public class ScriptResourceServlet extends AbstractResourceServlet
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
private static final long serialVersionUID = -5769146163848821050L;
|
private static final long serialVersionUID = -5769146163848821050L;
|
||||||
|
|
||||||
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param manager
|
||||||
|
*/
|
||||||
|
@Inject
|
||||||
|
public ScriptResourceServlet(PluginManager manager)
|
||||||
|
{
|
||||||
|
this.manager = manager;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,19 +100,13 @@ public class ScriptResourceServlet extends AbstractResourceServlet
|
|||||||
"function sayPluginHello(){ alert('Plugin Hello !'); }".concat(
|
"function sayPluginHello(){ alert('Plugin Hello !'); }".concat(
|
||||||
System.getProperty("line.separator")).getBytes());
|
System.getProperty("line.separator")).getBytes());
|
||||||
|
|
||||||
Collection<WebResource> scriptResources =
|
Collection<String> scriptResources = getScriptResources();
|
||||||
webPluginContext.getScriptResources();
|
|
||||||
|
|
||||||
if (Util.isNotEmpty(scriptResources))
|
if (Util.isNotEmpty(scriptResources))
|
||||||
{
|
{
|
||||||
List<WebResource> resourceList =
|
for (String resource : scriptResources)
|
||||||
new ArrayList<WebResource>(scriptResources);
|
|
||||||
|
|
||||||
Collections.sort(resourceList, new WebResourceComparator());
|
|
||||||
|
|
||||||
for (WebResource scriptResource : resourceList)
|
|
||||||
{
|
{
|
||||||
appendResource(stream, scriptResource);
|
appendResource(stream, resource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,10 +137,10 @@ public class ScriptResourceServlet extends AbstractResourceServlet
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws ServletException
|
* @throws ServletException
|
||||||
*/
|
*/
|
||||||
private void appendResource(OutputStream stream, WebResource script)
|
private void appendResource(OutputStream stream, String script)
|
||||||
throws ServletException, IOException
|
throws ServletException, IOException
|
||||||
{
|
{
|
||||||
InputStream input = script.getContent();
|
InputStream input = ScriptResourceServlet.class.getResourceAsStream(script);
|
||||||
|
|
||||||
if (input != null)
|
if (input != null)
|
||||||
{
|
{
|
||||||
@@ -150,9 +155,54 @@ public class ScriptResourceServlet extends AbstractResourceServlet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param resources
|
||||||
|
* @param plugin
|
||||||
|
*/
|
||||||
|
private void processPlugin(Set<String> resources, Plugin plugin)
|
||||||
|
{
|
||||||
|
PluginResources pluginResources = plugin.getResources();
|
||||||
|
|
||||||
|
if (pluginResources != null)
|
||||||
|
{
|
||||||
|
Set<String> scriptResources = pluginResources.getScriptResources();
|
||||||
|
|
||||||
|
if (scriptResources != null)
|
||||||
|
{
|
||||||
|
resources.addAll(scriptResources);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Collection<String> getScriptResources()
|
||||||
|
{
|
||||||
|
Set<String> resources = new TreeSet<String>();
|
||||||
|
Collection<Plugin> plugins = manager.getPlugins();
|
||||||
|
|
||||||
|
if (plugins != null)
|
||||||
|
{
|
||||||
|
for (Plugin plugin : plugins)
|
||||||
|
{
|
||||||
|
processPlugin(resources, plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resources;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@Inject
|
private PluginManager manager;
|
||||||
private ScmWebPluginContext webPluginContext;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user