Issue #2983 less verbose

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2018-10-16 21:23:14 +11:00
parent 458f402cf0
commit 1957e858ee
3 changed files with 61 additions and 23 deletions

View File

@ -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<? extends Configuration> replaces() { return null; }
default Class<? extends Configuration> replaces() { return null; }
/** Get known Configuration Dependencies.
* @return The names of Configurations that {@link TopologicalSort} must order
* before this configuration.
*/
public default Collection<String> getDependencies() { return Collections.emptyList(); }
default Collection<String> getDependencies() { return Collections.emptyList(); }
/** Get known Configuration Dependents.
* @return The names of Configurations that {@link TopologicalSort} must order
* after this configuration.
*/
public default Collection<String> getDependents(){ return Collections.emptyList(); }
default Collection<String> 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.
* <p>
@ -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.
* <p>
@ -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)

View File

@ -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<Configuration>
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<Configuration>
{
try
{
Class<?> clazz = Loader.loadClass(c);
Class<? extends Configuration> 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<Configuration>
{
@SuppressWarnings("unchecked")
Class<Configuration> clazz = Loader.loadClass(classname);
return clazz.newInstance();
return clazz.getConstructor().newInstance();
}
catch (ClassNotFoundException | InstantiationException | IllegalAccessException e)
catch (Throwable e)
{
throw new RuntimeException(e);
}

View File

@ -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;
}
}