fixed some sonarqube findings

This commit is contained in:
Sebastian Sdorra
2020-04-16 12:03:12 +02:00
parent 81e8dc428c
commit 0d4976ecf1
5 changed files with 30 additions and 89 deletions

View File

@@ -21,11 +21,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.filter;
import java.util.Objects;
import lombok.Value;
import sonia.scm.plugin.WebElementDescriptor;
/**
@@ -34,48 +33,8 @@ import sonia.scm.plugin.WebElementDescriptor;
* @param <T>
* @since 2.0.0
*/
public final class TypedWebElementDescriptor<T>
{
private final Class<T> clazz;
private final 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);
}
@Value
public class TypedWebElementDescriptor<T> {
Class<T> clazz;
WebElementDescriptor descriptor;
}

View File

@@ -69,9 +69,8 @@ public final class WebElementCollector
@SuppressWarnings("unchecked")
private WebElementCollector(Iterable<WebElementExtension> elements)
{
List<TypedWebElementDescriptor<? extends Filter>> fl = Lists.newArrayList();
List<TypedWebElementDescriptor<? extends HttpServlet>> sl =
Lists.newArrayList();
List<TypedWebElementDescriptor<Filter>> fl = Lists.newArrayList();
List<TypedWebElementDescriptor<HttpServlet>> sl = Lists.newArrayList();
for (WebElementExtension element : elements)
{
@@ -79,13 +78,13 @@ public final class WebElementCollector
{
fl.add(
new TypedWebElementDescriptor<>(
(Class<? extends Filter>) element.getClazz(), element.getDescriptor()));
(Class<Filter>) element.getClazz(), element.getDescriptor()));
}
else if (Servlet.class.isAssignableFrom(element.getClazz()))
{
sl.add(
new TypedWebElementDescriptor<>(
(Class<? extends HttpServlet>) element.getClazz(), element.getDescriptor()));
(Class<HttpServlet>) element.getClazz(), element.getDescriptor()));
}
else
{
@@ -95,8 +94,7 @@ public final class WebElementCollector
}
}
TypedWebElementDescriptorOrdering ordering =
new TypedWebElementDescriptorOrdering();
TypedWebElementDescriptorOrdering ordering = new TypedWebElementDescriptorOrdering();
filters = ordering.immutableSortedCopy(fl);
servlets = ordering.immutableSortedCopy(sl);
@@ -126,7 +124,7 @@ public final class WebElementCollector
*
* @return
*/
public Iterable<TypedWebElementDescriptor<? extends Filter>> getFilters()
public Iterable<TypedWebElementDescriptor<Filter>> getFilters()
{
return filters;
}
@@ -137,7 +135,7 @@ public final class WebElementCollector
*
* @return
*/
public Iterable<TypedWebElementDescriptor<? extends HttpServlet>> getServlets()
public Iterable<TypedWebElementDescriptor<HttpServlet>> getServlets()
{
return servlets;
}
@@ -177,8 +175,8 @@ public final class WebElementCollector
//~--- fields ---------------------------------------------------------------
/** Field description */
private final Iterable<TypedWebElementDescriptor<? extends Filter>> filters;
private final Iterable<TypedWebElementDescriptor<Filter>> filters;
/** Field description */
private final Iterable<TypedWebElementDescriptor<? extends HttpServlet>> servlets;
private final Iterable<TypedWebElementDescriptor<HttpServlet>> servlets;
}

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 --------------------------------------------------------
@@ -75,13 +75,12 @@ public class WebElementModule extends ServletModule
@Override
protected void configureServlets()
{
for (TypedWebElementDescriptor<? extends Filter> f : collector.getFilters())
for (TypedWebElementDescriptor<Filter> f : collector.getFilters())
{
bindFilter(f);
}
for (TypedWebElementDescriptor<? extends HttpServlet> s :
collector.getServlets())
for (TypedWebElementDescriptor<HttpServlet> s : collector.getServlets())
{
bindServlet(s);
}
@@ -93,9 +92,9 @@ public class WebElementModule extends ServletModule
*
* @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);
@@ -125,9 +124,9 @@ public class WebElementModule extends ServletModule
* @param servlet
*/
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);

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 --------------------------------------------------------
@@ -29,25 +29,17 @@ package sonia.scm.plugin;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet;
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.net.URL;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Set;
import javax.servlet.ServletContext;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
//~--- JDK imports ------------------------------------------------------------
/**
*
@@ -62,10 +54,6 @@ public class DefaultPluginLoader implements PluginLoader
/** Field description */
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 ---------------------------------------------------------
/**
@@ -90,7 +78,7 @@ public class DefaultPluginLoader implements PluginLoader
modules = getInstalled(parent, context, PATH_MODULECONFIG);
collector = new ExtensionCollector(parent, modules, installedPlugins);
ExtensionCollector collector = new ExtensionCollector(parent, modules, installedPlugins);
extensionProcessor = new DefaultExtensionProcessor(collector);
}
catch (IOException | JAXBException ex)
@@ -198,9 +186,6 @@ public class DefaultPluginLoader implements PluginLoader
//~--- fields ---------------------------------------------------------------
/** Field description */
private final ExtensionCollector collector;
/** Field description */
private final ExtensionProcessor extensionProcessor;

View File

@@ -98,7 +98,7 @@ public final class ExtensionCollector
if (collection == null)
{
collection = Collections.EMPTY_SET;
collection = Collections.emptySet();
}
return collection;
@@ -123,7 +123,7 @@ public final class ExtensionCollector
}
else
{
exts = Collections.EMPTY_SET;
exts = Collections.emptySet();
}
return exts;