support requires annotation on WebElements

This commit is contained in:
Sebastian Sdorra
2020-04-16 11:57:38 +02:00
parent b9acc7c9f6
commit 81e8dc428c
9 changed files with 188 additions and 150 deletions

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.filter;
//~--- non-JDK imports --------------------------------------------------------
@@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory;
import sonia.scm.Priorities;
import sonia.scm.plugin.PluginLoader;
import sonia.scm.plugin.WebElementDescriptor;
import sonia.scm.plugin.WebElementExtension;
//~--- JDK imports ------------------------------------------------------------
@@ -67,25 +67,25 @@ public final class WebElementCollector
* @param elements
*/
@SuppressWarnings("unchecked")
private WebElementCollector(Iterable<WebElementDescriptor> elements)
private WebElementCollector(Iterable<WebElementExtension> elements)
{
List<TypedWebElementDescriptor<? extends Filter>> fl = Lists.newArrayList();
List<TypedWebElementDescriptor<? extends HttpServlet>> sl =
Lists.newArrayList();
for (WebElementDescriptor element : elements)
for (WebElementExtension element : elements)
{
if (Filter.class.isAssignableFrom(element.getClazz()))
{
fl.add(
new TypedWebElementDescriptor<>(
(Class<? extends Filter>) element.getClazz(), element));
(Class<? extends Filter>) element.getClazz(), element.getDescriptor()));
}
else if (Servlet.class.isAssignableFrom(element.getClazz()))
{
sl.add(
new TypedWebElementDescriptor<>(
(Class<? extends HttpServlet>) element.getClazz(), element));
(Class<? extends HttpServlet>) element.getClazz(), element.getDescriptor()));
}
else
{

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.lifecycle.modules;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -193,7 +193,7 @@ class ScmServletModule extends ServletModule {
// bind sslcontext provider
bind(SSLContext.class).toProvider(SSLContextProvider.class);
// bind ahc
Multibinder<ContentTransformer> transformers =
Multibinder.newSetBinder(binder(), ContentTransformer.class);
@@ -207,7 +207,7 @@ class ScmServletModule extends ServletModule {
// bind new hook api
bind(HookContextFactory.class);
bind(HookEventFacade.class);
// bind user-agent parser
bind(UserAgentParser.class);
@@ -215,7 +215,7 @@ class ScmServletModule extends ServletModule {
if ("true".equalsIgnoreCase(System.getProperty(SYSTEM_PROPERTY_DEBUG_HTTP))) {
filter(PATTERN_ALL).through(LoggingFilter.class);
}
// debug servlet
serve(PATTERN_DEBUG).with(DebugServlet.class);

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.plugin;
//~--- non-JDK imports --------------------------------------------------------
@@ -115,7 +115,7 @@ public class DefaultExtensionProcessor implements ExtensionProcessor
* @return
*/
@Override
public Iterable<WebElementDescriptor> getWebElements()
public Iterable<WebElementExtension> getWebElements()
{
return collector.getWebElements();
}

View File

@@ -21,22 +21,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.plugin;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@@ -45,6 +42,8 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra
@@ -63,6 +62,7 @@ public final class ExtensionCollector
for (ScmModule module : modules) {
collectRootElements(moduleClassLoader, module);
}
for (InstalledPlugin plugin : installedPlugins) {
collectRootElements(plugin.getClassLoader(), plugin.getDescriptor());
}
@@ -218,7 +218,7 @@ public final class ExtensionCollector
*
* @return
*/
public Set<WebElementDescriptor> getWebElements()
public Set<WebElementExtension> getWebElements()
{
return webElements;
}
@@ -272,6 +272,17 @@ public final class ExtensionCollector
return classes;
}
private Set<WebElementExtension> collectWebElementExtensions(ClassLoader defaultClassLoader, Iterable<WebElementDescriptor> descriptors) {
Set<WebElementExtension> webElementExtensions = new HashSet<>();
for (WebElementDescriptor descriptor : descriptors) {
if (isRequirementFulfilled(descriptor)) {
Class<?> loadedClass = loadExtension(defaultClassLoader, descriptor);
webElementExtensions.add(new WebElementExtension(loadedClass, descriptor));
}
}
return webElementExtensions;
}
private Class<?> loadExtension(ClassLoader classLoader, ClassElement extension) {
try {
return classLoader.loadClass(extension.getClazz());
@@ -307,13 +318,14 @@ public final class ExtensionCollector
restProviders.addAll(collectClasses(classLoader, module.getRestProviders()));
restResources.addAll(collectClasses(classLoader, module.getRestResources()));
Iterables.addAll(webElements, module.getWebElements());
webElements.addAll(collectWebElementExtensions(classLoader, module.getWebElements()));
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private final Set<WebElementDescriptor> webElements = Sets.newHashSet();
private final Set<WebElementExtension> webElements = Sets.newHashSet();
/** Field description */
private final Set<Class> restResources = Sets.newHashSet();