mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 09:25:43 +01:00
fixed some sonarqube findings
This commit is contained in:
@@ -24,8 +24,7 @@
|
|||||||
|
|
||||||
package sonia.scm.filter;
|
package sonia.scm.filter;
|
||||||
|
|
||||||
import java.util.Objects;
|
import lombok.Value;
|
||||||
|
|
||||||
import sonia.scm.plugin.WebElementDescriptor;
|
import sonia.scm.plugin.WebElementDescriptor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,48 +33,8 @@ import sonia.scm.plugin.WebElementDescriptor;
|
|||||||
* @param <T>
|
* @param <T>
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public final class TypedWebElementDescriptor<T>
|
@Value
|
||||||
{
|
public class TypedWebElementDescriptor<T> {
|
||||||
private final Class<T> clazz;
|
Class<T> clazz;
|
||||||
private final WebElementDescriptor descriptor;
|
WebElementDescriptor descriptor;
|
||||||
|
|
||||||
public TypedWebElementDescriptor(Class<T> clazz,
|
|
||||||
WebElementDescriptor descriptor)
|
|
||||||
{
|
|
||||||
this.clazz = clazz;
|
|
||||||
this.descriptor = descriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<T> getClazz()
|
|
||||||
{
|
|
||||||
return clazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WebElementDescriptor getDescriptor()
|
|
||||||
{
|
|
||||||
return descriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(clazz, descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (obj == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (getClass() != obj.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final TypedWebElementDescriptor other = (TypedWebElementDescriptor) obj;
|
|
||||||
return Objects.equals(clazz, other.clazz)
|
|
||||||
&& Objects.equals(descriptor, other.descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,9 +69,8 @@ public final class WebElementCollector
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private WebElementCollector(Iterable<WebElementExtension> elements)
|
private WebElementCollector(Iterable<WebElementExtension> elements)
|
||||||
{
|
{
|
||||||
List<TypedWebElementDescriptor<? extends Filter>> fl = Lists.newArrayList();
|
List<TypedWebElementDescriptor<Filter>> fl = Lists.newArrayList();
|
||||||
List<TypedWebElementDescriptor<? extends HttpServlet>> sl =
|
List<TypedWebElementDescriptor<HttpServlet>> sl = Lists.newArrayList();
|
||||||
Lists.newArrayList();
|
|
||||||
|
|
||||||
for (WebElementExtension element : elements)
|
for (WebElementExtension element : elements)
|
||||||
{
|
{
|
||||||
@@ -79,13 +78,13 @@ public final class WebElementCollector
|
|||||||
{
|
{
|
||||||
fl.add(
|
fl.add(
|
||||||
new TypedWebElementDescriptor<>(
|
new TypedWebElementDescriptor<>(
|
||||||
(Class<? extends Filter>) element.getClazz(), element.getDescriptor()));
|
(Class<Filter>) element.getClazz(), element.getDescriptor()));
|
||||||
}
|
}
|
||||||
else if (Servlet.class.isAssignableFrom(element.getClazz()))
|
else if (Servlet.class.isAssignableFrom(element.getClazz()))
|
||||||
{
|
{
|
||||||
sl.add(
|
sl.add(
|
||||||
new TypedWebElementDescriptor<>(
|
new TypedWebElementDescriptor<>(
|
||||||
(Class<? extends HttpServlet>) element.getClazz(), element.getDescriptor()));
|
(Class<HttpServlet>) element.getClazz(), element.getDescriptor()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -95,8 +94,7 @@ public final class WebElementCollector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TypedWebElementDescriptorOrdering ordering =
|
TypedWebElementDescriptorOrdering ordering = new TypedWebElementDescriptorOrdering();
|
||||||
new TypedWebElementDescriptorOrdering();
|
|
||||||
|
|
||||||
filters = ordering.immutableSortedCopy(fl);
|
filters = ordering.immutableSortedCopy(fl);
|
||||||
servlets = ordering.immutableSortedCopy(sl);
|
servlets = ordering.immutableSortedCopy(sl);
|
||||||
@@ -126,7 +124,7 @@ public final class WebElementCollector
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Iterable<TypedWebElementDescriptor<? extends Filter>> getFilters()
|
public Iterable<TypedWebElementDescriptor<Filter>> getFilters()
|
||||||
{
|
{
|
||||||
return filters;
|
return filters;
|
||||||
}
|
}
|
||||||
@@ -137,7 +135,7 @@ public final class WebElementCollector
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Iterable<TypedWebElementDescriptor<? extends HttpServlet>> getServlets()
|
public Iterable<TypedWebElementDescriptor<HttpServlet>> getServlets()
|
||||||
{
|
{
|
||||||
return servlets;
|
return servlets;
|
||||||
}
|
}
|
||||||
@@ -177,8 +175,8 @@ public final class WebElementCollector
|
|||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private final Iterable<TypedWebElementDescriptor<? extends Filter>> filters;
|
private final Iterable<TypedWebElementDescriptor<Filter>> filters;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private final Iterable<TypedWebElementDescriptor<? extends HttpServlet>> servlets;
|
private final Iterable<TypedWebElementDescriptor<HttpServlet>> servlets;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,13 +75,12 @@ public class WebElementModule extends ServletModule
|
|||||||
@Override
|
@Override
|
||||||
protected void configureServlets()
|
protected void configureServlets()
|
||||||
{
|
{
|
||||||
for (TypedWebElementDescriptor<? extends Filter> f : collector.getFilters())
|
for (TypedWebElementDescriptor<Filter> f : collector.getFilters())
|
||||||
{
|
{
|
||||||
bindFilter(f);
|
bindFilter(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (TypedWebElementDescriptor<? extends HttpServlet> s :
|
for (TypedWebElementDescriptor<HttpServlet> s : collector.getServlets())
|
||||||
collector.getServlets())
|
|
||||||
{
|
{
|
||||||
bindServlet(s);
|
bindServlet(s);
|
||||||
}
|
}
|
||||||
@@ -93,9 +92,9 @@ public class WebElementModule extends ServletModule
|
|||||||
*
|
*
|
||||||
* @param filter
|
* @param filter
|
||||||
*/
|
*/
|
||||||
private void bindFilter(TypedWebElementDescriptor<? extends Filter> filter)
|
private void bindFilter(TypedWebElementDescriptor<Filter> filter)
|
||||||
{
|
{
|
||||||
Class<? extends Filter> clazz = filter.getClazz();
|
Class<Filter> clazz = filter.getClazz();
|
||||||
|
|
||||||
logger.info("bind filter {} to filter chain", clazz);
|
logger.info("bind filter {} to filter chain", clazz);
|
||||||
|
|
||||||
@@ -125,9 +124,9 @@ public class WebElementModule extends ServletModule
|
|||||||
* @param servlet
|
* @param servlet
|
||||||
*/
|
*/
|
||||||
private void bindServlet(
|
private void bindServlet(
|
||||||
TypedWebElementDescriptor<? extends HttpServlet> servlet)
|
TypedWebElementDescriptor<HttpServlet> servlet)
|
||||||
{
|
{
|
||||||
Class<? extends HttpServlet> clazz = servlet.getClazz();
|
Class<HttpServlet> clazz = servlet.getClazz();
|
||||||
|
|
||||||
logger.info("bind servlet {} to servlet chain", clazz);
|
logger.info("bind servlet {} to servlet chain", clazz);
|
||||||
|
|
||||||
|
|||||||
@@ -29,25 +29,17 @@ package sonia.scm.plugin;
|
|||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.ImmutableSet.Builder;
|
import com.google.common.collect.ImmutableSet.Builder;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.xml.bind.JAXBContext;
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
|
||||||
import javax.xml.bind.JAXBException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -62,10 +54,6 @@ public class DefaultPluginLoader implements PluginLoader
|
|||||||
/** 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";
|
||||||
|
|
||||||
/** the logger for DefaultPluginLoader */
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(DefaultPluginLoader.class);
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,7 +78,7 @@ public class DefaultPluginLoader implements PluginLoader
|
|||||||
|
|
||||||
modules = getInstalled(parent, context, PATH_MODULECONFIG);
|
modules = getInstalled(parent, context, PATH_MODULECONFIG);
|
||||||
|
|
||||||
collector = new ExtensionCollector(parent, modules, installedPlugins);
|
ExtensionCollector collector = new ExtensionCollector(parent, modules, installedPlugins);
|
||||||
extensionProcessor = new DefaultExtensionProcessor(collector);
|
extensionProcessor = new DefaultExtensionProcessor(collector);
|
||||||
}
|
}
|
||||||
catch (IOException | JAXBException ex)
|
catch (IOException | JAXBException ex)
|
||||||
@@ -198,9 +186,6 @@ public class DefaultPluginLoader implements PluginLoader
|
|||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private final ExtensionCollector collector;
|
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private final ExtensionProcessor extensionProcessor;
|
private final ExtensionProcessor extensionProcessor;
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ public final class ExtensionCollector
|
|||||||
|
|
||||||
if (collection == null)
|
if (collection == null)
|
||||||
{
|
{
|
||||||
collection = Collections.EMPTY_SET;
|
collection = Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
return collection;
|
return collection;
|
||||||
@@ -123,7 +123,7 @@ public final class ExtensionCollector
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
exts = Collections.EMPTY_SET;
|
exts = Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
return exts;
|
return exts;
|
||||||
|
|||||||
Reference in New Issue
Block a user