From 1957e858ee78da74edd6a42172045fd63a45645d Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Tue, 16 Oct 2018 21:23:14 +1100 Subject: [PATCH] Issue #2983 less verbose Signed-off-by: Greg Wilkins --- .../eclipse/jetty/webapp/Configuration.java | 38 +++++++++++-------- .../eclipse/jetty/webapp/Configurations.java | 24 +++++++++--- .../jetty/webapp/JmxConfiguration.java | 22 ++++++++++- 3 files changed, 61 insertions(+), 23 deletions(-) diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configuration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configuration.java index 5fbbcec7386..1442acf5ba7 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configuration.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configuration.java @@ -56,37 +56,45 @@ import org.eclipse.jetty.util.annotation.Name; */ public interface Configuration { - public final static String ATTR="org.eclipse.jetty.webapp.configuration"; - + String ATTR="org.eclipse.jetty.webapp.configuration"; + + /** + * @return True if the feature this configuration represents is available and has all its dependencies. + */ + default boolean isAvailable() + { + return true; + } + /** Get a class that this class replaces/extends. * If this is added to {@link Configurations} collection that already contains a * configuration of the replaced class or that reports to replace the same class, then * it is replaced with this instance. * @return The class this Configuration replaces/extends or null if it replaces no other configuration */ - public default Class replaces() { return null; } + default Class replaces() { return null; } /** Get known Configuration Dependencies. * @return The names of Configurations that {@link TopologicalSort} must order * before this configuration. */ - public default Collection getDependencies() { return Collections.emptyList(); } + default Collection getDependencies() { return Collections.emptyList(); } /** Get known Configuration Dependents. * @return The names of Configurations that {@link TopologicalSort} must order * after this configuration. */ - public default Collection getDependents(){ return Collections.emptyList(); } + default Collection getDependents(){ return Collections.emptyList(); } /** Get the system classes associated with this Configuration. * @return ClasspathPattern of system classes. */ - public default ClasspathPattern getSystemClasses() { return new ClasspathPattern(); } + default ClasspathPattern getSystemClasses() { return new ClasspathPattern(); } /** Get the system classes associated with this Configuration. * @return ClasspathPattern of server classes. */ - public default ClasspathPattern getServerClasses() { return new ClasspathPattern(); } + default ClasspathPattern getServerClasses() { return new ClasspathPattern(); } /** Set up for configuration. *

@@ -97,7 +105,7 @@ public interface Configuration * @param context The context to configure * @throws Exception if unable to pre configure */ - public void preConfigure (WebAppContext context) throws Exception; + void preConfigure (WebAppContext context) throws Exception; /** Configure WebApp. *

@@ -106,13 +114,13 @@ public interface Configuration * @param context The context to configure * @throws Exception if unable to configure */ - public void configure (WebAppContext context) throws Exception; + void configure (WebAppContext context) throws Exception; /** Clear down after configuration. * @param context The context to configure * @throws Exception if unable to post configure */ - public void postConfigure (WebAppContext context) throws Exception; + void postConfigure (WebAppContext context) throws Exception; /** DeConfigure WebApp. * This method is called to undo all configuration done. This is @@ -120,7 +128,7 @@ public interface Configuration * @param context The context to configure * @throws Exception if unable to deconfigure */ - public void deconfigure (WebAppContext context) throws Exception; + void deconfigure (WebAppContext context) throws Exception; /** Destroy WebApp. * This method is called to destroy a webappcontext. It is typically called when a context @@ -128,23 +136,23 @@ public interface Configuration * @param context The context to configure * @throws Exception if unable to destroy */ - public void destroy (WebAppContext context) throws Exception; + void destroy (WebAppContext context) throws Exception; /** * @return true if configuration is disabled by default */ - public boolean isDisabledByDefault(); + boolean isDisabledByDefault(); /** * @return true if configuration should be aborted */ - public boolean abort(WebAppContext context); + boolean abort(WebAppContext context); /** * @deprecated Use {@link Configurations} */ @Deprecated - public class ClassList extends Configurations + class ClassList extends Configurations { @Deprecated public void addAfter(@Name("afterClass") String afterClass,@Name("configClass")String... configClass) diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configurations.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configurations.java index 1c318961a56..d392436d4d7 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configurations.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configurations.java @@ -18,6 +18,7 @@ package org.eclipse.jetty.webapp; +import java.lang.reflect.InvocationTargetException; import java.util.AbstractList; import java.util.ArrayList; import java.util.Arrays; @@ -78,14 +79,18 @@ public class Configurations extends AbstractList try { Configuration configuration = i.next(); + if (!configuration.isAvailable()) + { + if (LOG.isDebugEnabled()) + LOG.debug("Configuration unavailable: "+configuration); + continue; + } __known.add(configuration); __knownByClassName.add(configuration.getClass().getName()); } catch (Throwable e) { - LOG.info("Configuration unavailable: "+e.getMessage()); - if (LOG.isDebugEnabled()) - LOG.debug(e); + LOG.warn(e); } } @@ -113,7 +118,14 @@ public class Configurations extends AbstractList { try { - Class clazz = Loader.loadClass(c); + Class clazz = Loader.loadClass(c); + Configuration configuration = clazz.getConstructor().newInstance(); + if (!configuration.isAvailable()) + { + if (LOG.isDebugEnabled()) + LOG.warn("Configuration unavailable: "+configuration); + continue; + } __known.add((Configuration)clazz.newInstance()); __knownByClassName.add(c); } @@ -232,9 +244,9 @@ public class Configurations extends AbstractList { @SuppressWarnings("unchecked") Class clazz = Loader.loadClass(classname); - return clazz.newInstance(); + return clazz.getConstructor().newInstance(); } - catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) + catch (Throwable e) { throw new RuntimeException(e); } diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JmxConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JmxConfiguration.java index 5f32a9b9244..c6d166d6146 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JmxConfiguration.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JmxConfiguration.java @@ -18,7 +18,9 @@ package org.eclipse.jetty.webapp; -import org.eclipse.jetty.jmx.ObjectMBean; +import org.eclipse.jetty.util.Loader; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; import java.util.ServiceLoader; @@ -35,9 +37,25 @@ import java.util.ServiceLoader; */ public class JmxConfiguration extends AbstractConfiguration { + private static final Logger LOG = Log.getLogger(JmxConfiguration.class); + public JmxConfiguration() { addDependents(WebXmlConfiguration.class, MetaInfConfiguration.class, WebInfConfiguration.class); - protectAndExpose(ObjectMBean.class.getPackage().getName()+"."); + protectAndExpose("org.eclipse.jetty.jmx."); + } + + @Override + public boolean isAvailable() + { + try + { + return Loader.loadClass("org.eclipse.jetty.jmx.ObjectMBean")!=null; + } + catch (Throwable e) + { + LOG.ignore(e); + } + return false; } }