removed Configuration marker classes

This commit is contained in:
Greg Wilkins 2017-05-11 11:32:23 +02:00
parent cbe857de01
commit b5a3eb1f70
16 changed files with 163 additions and 175 deletions

View File

@ -133,7 +133,7 @@ public class TestAnnotationConfiguration
File testSciJar = new File(jarDir, "test-sci.jar");
assertTrue(testSciJar.exists());
URLClassLoader webAppLoader = new URLClassLoader(new URL[]{testSciJar.toURI().toURL()}, Thread.currentThread().getContextClassLoader());
ClassLoader orig = Thread.currentThread().getContextClassLoader();
try
{

View File

@ -19,7 +19,6 @@
package org.eclipse.jetty.maven.plugin;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
@ -37,7 +36,6 @@ import org.eclipse.jetty.plus.webapp.PlusConfiguration;
import org.eclipse.jetty.quickstart.ExtraXmlDescriptorProcessor;
import org.eclipse.jetty.quickstart.QuickStartConfiguration;
import org.eclipse.jetty.quickstart.QuickStartConfiguration.Mode;
import org.eclipse.jetty.quickstart.QuickStartGeneratorConfiguration;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.FilterMapping;
import org.eclipse.jetty.servlet.ServletHolder;
@ -49,12 +47,8 @@ import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceCollection;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.FragmentConfiguration;
import org.eclipse.jetty.webapp.JettyWebXmlConfiguration;
import org.eclipse.jetty.webapp.MetaInfConfiguration;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.webapp.WebInfConfiguration;
import org.eclipse.jetty.webapp.WebXmlConfiguration;
/**
* JettyWebAppContext
@ -81,10 +75,7 @@ public class JettyWebAppContext extends WebAppContext
private List<File> _classpathFiles; //webInfClasses+testClasses+webInfJars
private String _jettyEnvXml;
private List<Overlay> _overlays;
private Resource _quickStartWebXml;
private String _originAttribute;
private boolean _generateOrigin;
/**
* Set the "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern" with a pattern for matching jars on
* container classpath to scan. This is analogous to the WebAppContext.setAttribute() call.
@ -210,29 +201,20 @@ public class JettyWebAppContext extends WebAppContext
{
_overlays = overlays;
}
public void setOriginAttribute (String name)
{
setAttribute(QuickStartConfiguration.ORIGIN_ATTRIBUTE,name);
}
/**
* @return the originAttribute
*/
public String getOriginAttribute()
{
return _originAttribute;
}
/**
* @param originAttribute the originAttribute to set
*/
public void setOriginAttribute(String originAttribute)
{
_originAttribute = originAttribute;
}
/**
* @return the generateOrigin
*/
public boolean isGenerateOrigin()
{
return _generateOrigin;
Object attr = getAttribute(QuickStartConfiguration.ORIGIN_ATTRIBUTE);
return attr==null?null:attr.toString();
}
/**
@ -240,7 +222,16 @@ public class JettyWebAppContext extends WebAppContext
*/
public void setGenerateOrigin(boolean generateOrigin)
{
_generateOrigin = generateOrigin;
setAttribute(QuickStartConfiguration.GENERATE_ORIGIN,generateOrigin);
}
/**
* @return the generateOrigin
*/
public boolean isGenerateOrigin()
{
Object attr = getAttribute(QuickStartConfiguration.GENERATE_ORIGIN);
return attr==null?false:Boolean.valueOf(attr.toString());
}
/* ------------------------------------------------------------ */
@ -270,13 +261,13 @@ public class JettyWebAppContext extends WebAppContext
/* ------------------------------------------------------------ */
protected void setQuickStartWebDescriptor (Resource quickStartWebXml)
{
_quickStartWebXml = quickStartWebXml;
setAttribute(QuickStartConfiguration.QUICKSTART_WEB_XML,quickStartWebXml.toString());
}
/* ------------------------------------------------------------ */
public Resource getQuickStartWebDescriptor ()
{
return _quickStartWebXml;
return (Resource)getAttribute(QuickStartConfiguration.QUICKSTART_WEB_XML);
}
/* ------------------------------------------------------------ */
@ -326,24 +317,17 @@ public class JettyWebAppContext extends WebAppContext
if (!isGenerateQuickStart() && getQuickStartWebDescriptor() != null)
{
MavenQuickStartConfiguration quickStart = new MavenQuickStartConfiguration();
quickStart.setMode(Mode.QUCKSTART);
quickStart.setQuickStartWebXml(getQuickStartWebDescriptor());
quickStart.setMode(Mode.QUICKSTART);
addConfiguration(quickStart);
}
else
{
if (isGenerateQuickStart())
{
MavenQuickStartConfiguration quickStart = new MavenQuickStartConfiguration();
quickStart.setMode(Mode.GENERATE);
quickStart.getGenerator().setGenerateOrigin(isGenerateOrigin());
quickStart.getGenerator().setOriginAttribute(getOriginAttribute());
quickStart.setQuickStartWebXml(getQuickStartWebDescriptor());
quickStart.getGenerator().setQuickStartWebXml(getQuickStartWebDescriptor());
addConfiguration(quickStart);
}
else if (isGenerateQuickStart())
{
MavenQuickStartConfiguration quickStart = new MavenQuickStartConfiguration();
quickStart.setMode(Mode.GENERATE);
addConfiguration(quickStart);
}
//Set up the pattern that tells us where the jars are that need scanning
//Allow user to set up pattern for names of jars from the container classpath

View File

@ -39,24 +39,6 @@ import org.eclipse.jetty.webapp.WebAppContext;
public class MavenQuickStartConfiguration extends QuickStartConfiguration
{
private static final Logger LOG = Log.getLogger(QuickStartConfiguration.class);
private Resource _quickStartWebXml;
public void setQuickStartWebXml (Resource r)
{
_quickStartWebXml = r;
}
@Override
public Resource getQuickStartWebXml(WebAppContext context) throws Exception
{
return _quickStartWebXml;
}
@Override
public void preConfigure(WebAppContext context) throws Exception

View File

@ -109,14 +109,11 @@ public class PreconfigureQuickStartWar
xmlConfiguration.configure(webapp);
}
webapp.setResourceBase(dir.getFile().getAbsolutePath());
webapp.setGenerate(true);
webapp.setMode(QuickStartConfiguration.Mode.GENERATE);
server.setHandler(webapp);
server.start();
server.stop();
}
private static void error(String message)
{

View File

@ -18,6 +18,7 @@
package org.eclipse.jetty.quickstart;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
@ -41,11 +42,15 @@ import org.eclipse.jetty.webapp.WebXmlConfiguration;
* Re-inflate a deployable webapp from a saved effective-web.xml
* which combines all pre-parsed web xml descriptors and annotations.
*/
public class QuickStartConfiguration extends AbstractConfiguration implements Configuration.DisabledByDefault
public class QuickStartConfiguration extends AbstractConfiguration
{
private static final Logger LOG = Log.getLogger(QuickStartConfiguration.class);
public static final Set<Class<? extends Configuration>> __replacedConfigurations = new HashSet<>();
public static final String ORIGIN_ATTRIBUTE = "org.eclipse.jetty.quickstart.ORIGIN_ATTRIBUTE";
public static final String GENERATE_ORIGIN = "org.eclipse.jetty.quickstart.GENERATE_ORIGIN";
public static final String QUICKSTART_WEB_XML = "org.eclipse.jetty.quickstart.QUICKSTART_WEB_XML";
static
{
__replacedConfigurations.add(org.eclipse.jetty.webapp.WebXmlConfiguration.class);
@ -54,15 +59,20 @@ public class QuickStartConfiguration extends AbstractConfiguration implements Co
__replacedConfigurations.add(org.eclipse.jetty.annotations.AnnotationConfiguration.class);
};
public enum Mode {DISABLED, GENERATE, AUTO, QUCKSTART};
public enum Mode
{
DISABLED, // No Quick start
GENERATE, // Generate quickstart-web.xml and then stop
AUTO, // use or generate depending on the existance of quickstart-web.xml
QUICKSTART // Use quickstart-web.xml
};
private Mode _mode=Mode.AUTO;
private boolean _quickStart;
private QuickStartGeneratorConfiguration _generator = new QuickStartGeneratorConfiguration();
public QuickStartConfiguration()
{
super(true);
addDependencies(WebInfConfiguration.class);
addDependents(WebXmlConfiguration.class);
}
@ -76,12 +86,7 @@ public class QuickStartConfiguration extends AbstractConfiguration implements Co
{
return _mode;
}
public QuickStartGeneratorConfiguration getGenerator()
{
return _generator;
}
/**
* @see org.eclipse.jetty.webapp.AbstractConfiguration#preConfigure(org.eclipse.jetty.webapp.WebAppContext)
*/
@ -105,24 +110,29 @@ public class QuickStartConfiguration extends AbstractConfiguration implements Co
break;
case GENERATE:
super.preConfigure(context);
context.addConfiguration(_generator);
context.addConfiguration(new StopContextConfiguration());
{
super.preConfigure(context);
QuickStartGeneratorConfiguration generator = new QuickStartGeneratorConfiguration(true);
configure(generator, context);
context.addConfiguration(generator);
break;
}
case AUTO:
{
if (quickStartWebXml.exists())
quickStart(context,quickStartWebXml);
quickStart(context, quickStartWebXml);
else
{
super.preConfigure(context);
context.addConfiguration(new QuickStartGeneratorConfiguration());
QuickStartGeneratorConfiguration generator = new QuickStartGeneratorConfiguration(false);
configure(generator, context);
context.addConfiguration(generator);
}
break;
}
case QUCKSTART:
case QUICKSTART:
if (quickStartWebXml.exists())
quickStart(context,quickStartWebXml);
else
@ -130,7 +140,23 @@ public class QuickStartConfiguration extends AbstractConfiguration implements Co
break;
}
}
protected void configure(QuickStartGeneratorConfiguration generator, WebAppContext context) throws IOException
{
Object attr;
attr = context.getAttribute(GENERATE_ORIGIN);
if (attr!=null)
generator.setGenerateOrigin(Boolean.valueOf(attr.toString()));
attr = context.getAttribute(ORIGIN_ATTRIBUTE);
if (attr!=null)
generator.setOriginAttribute(attr.toString());
attr = context.getAttribute(QUICKSTART_WEB_XML);
if (attr instanceof Resource)
generator.setQuickStartWebXml((Resource)attr);
else if (attr!=null)
generator.setQuickStartWebXml(Resource.newResource(attr.toString()));
}
protected void quickStart(WebAppContext context, Resource quickStartWebXml)
throws Exception
{

View File

@ -73,22 +73,36 @@ import org.eclipse.jetty.xml.XmlAppendable;
* Generate an effective web.xml from a WebAppContext, including all components
* from web.xml, web-fragment.xmls annotations etc.
*/
public class QuickStartGeneratorConfiguration extends AbstractConfiguration implements Configuration.DisabledByDefault
public class QuickStartGeneratorConfiguration extends AbstractConfiguration
{
private static final Logger LOG = Log.getLogger(QuickStartGeneratorConfiguration.class);
public static final String ORIGIN = "org.eclipse.jetty.originAttribute";
public static final String DEFAULT_ORIGIN_ATTRIBUTE_NAME = "origin";
protected final boolean _abort;
protected String _originAttribute;
protected boolean _generateOrigin;
protected int _count;
protected Resource _quickStartWebXml;
public QuickStartGeneratorConfiguration()
{
_count = 0;
this(false);
}
public QuickStartGeneratorConfiguration(boolean abort)
{
super(true);
_count = 0;
_abort = abort;
}
@Override
public boolean abort(WebAppContext context)
{
return _abort;
}
public void setOriginAttribute (String name)
{
_originAttribute = name;
@ -596,7 +610,6 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration impl
*
* @param out
* @param attribute
* @param resourceBase
* @throws IOException
*/
private void addContextParamFromAttribute(WebAppContext context, XmlAppendable out, String attribute, AttributeNormalizer normalizer) throws IOException
@ -630,7 +643,6 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration impl
*
* @param out
* @param md
* @param tag
* @param holder
* @throws IOException
*/

View File

@ -29,10 +29,8 @@ import org.eclipse.jetty.webapp.WebAppContext;
*/
public class QuickStartWebApp extends WebAppContext
{
private final QuickStartConfiguration _quickStartConfiguration;
private String _originAttribute;
private boolean _generateOrigin;
public QuickStartWebApp()
@ -51,30 +49,40 @@ public class QuickStartWebApp extends WebAppContext
@Deprecated
public boolean isPreconfigure()
{
return isGenerate();
switch(_quickStartConfiguration.getMode())
{
case AUTO:
case GENERATE:
return true;
default: return false;
}
}
@Deprecated
public void setPreconfigure(boolean preconfigure)
{
setGenerate(preconfigure);
_quickStartConfiguration.setMode(preconfigure?Mode.GENERATE:Mode.DISABLED);
}
@Deprecated
public boolean isAutoPreconfigure()
{
return isAutoGenerate();
switch(_quickStartConfiguration.getMode())
{
case AUTO: return true;
default: return false;
}
}
@Deprecated
public void setAutoPreconfigure(boolean autoPrecompile)
{
setAutoGenerate(autoPrecompile);
_quickStartConfiguration.setMode(autoPrecompile?Mode.AUTO:Mode.DISABLED);
}
public void setOriginAttribute (String name)
{
_quickStartConfiguration.getGenerator().setOriginAttribute(name);
setAttribute(QuickStartConfiguration.ORIGIN_ATTRIBUTE,name);
}
/**
@ -82,15 +90,8 @@ public class QuickStartWebApp extends WebAppContext
*/
public String getOriginAttribute()
{
return _originAttribute;
}
/**
* @return the generateOrigin
*/
public boolean isGenerateOrigin()
{
return _generateOrigin;
Object attr = getAttribute(QuickStartConfiguration.ORIGIN_ATTRIBUTE);
return attr==null?null:attr.toString();
}
/**
@ -98,26 +99,25 @@ public class QuickStartWebApp extends WebAppContext
*/
public void setGenerateOrigin(boolean generateOrigin)
{
_quickStartConfiguration.getGenerator().setGenerateOrigin(generateOrigin);
setAttribute(QuickStartConfiguration.GENERATE_ORIGIN,generateOrigin);
}
public boolean isGenerate()
/**
* @return the generateOrigin
*/
public boolean isGenerateOrigin()
{
return _quickStartConfiguration.getMode()==Mode.GENERATE;
Object attr = getAttribute(QuickStartConfiguration.GENERATE_ORIGIN);
return attr==null?false:Boolean.valueOf(attr.toString());
}
public void setGenerate(boolean preconfigure)
public Mode getMode()
{
_quickStartConfiguration.setMode(Mode.GENERATE);
return _quickStartConfiguration.getMode();
}
public boolean isAutoGenerate()
public void setMode(Mode mode)
{
return _quickStartConfiguration.getMode()==Mode.AUTO;
}
public void setAutoGenerate(boolean autoPrecompile)
{
_quickStartConfiguration.setMode(Mode.AUTO);
_quickStartConfiguration.setMode(mode);
}
}

View File

@ -1,26 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.quickstart;
import org.eclipse.jetty.webapp.AbstractConfiguration;
import org.eclipse.jetty.webapp.Configuration;
public class StopContextConfiguration extends AbstractConfiguration implements Configuration.AbortConfiguration
{
}

View File

@ -1,3 +1,2 @@
org.eclipse.jetty.quickstart.QuickStartConfiguration
org.eclipse.jetty.quickstart.QuickStartGeneratorConfiguration
org.eclipse.jetty.quickstart.StopContextConfiguration

View File

@ -39,8 +39,7 @@ public class TestQuickStart
{
File testDir;
File webInf;
@Before
public void setUp()
{
@ -49,9 +48,7 @@ public class TestQuickStart
webInf = new File(testDir, "WEB-INF");
FS.ensureDirExists(webInf);
}
@Test
public void testProgrammaticOverrideOfDefaultServletMapping() throws Exception
{
@ -64,7 +61,7 @@ public class TestQuickStart
//generate a quickstart-web.xml
QuickStartWebApp quickstart = new QuickStartWebApp();
quickstart.setResourceBase(testDir.getAbsolutePath());
quickstart.setPreconfigure(true);
quickstart.setMode(QuickStartConfiguration.Mode.GENERATE);
quickstart.setGenerateOrigin(true);
ServletHolder fooHolder = new ServletHolder();
fooHolder.setServlet(new FooServlet());
@ -80,7 +77,7 @@ public class TestQuickStart
//now run the webapp again purely from the generated quickstart
QuickStartWebApp webapp = new QuickStartWebApp();
webapp.setResourceBase(testDir.getAbsolutePath());
webapp.setPreconfigure(false);
webapp.setMode(QuickStartConfiguration.Mode.QUICKSTART);
webapp.setClassLoader(Thread.currentThread().getContextClassLoader()); //only necessary for junit testing
server.setHandler(webapp);

View File

@ -27,14 +27,20 @@ import java.util.stream.Collectors;
public class AbstractConfiguration implements Configuration
{
protected static final boolean ENABLE_BY_DEFAULT = true;
private final boolean _disabledByDefault;
private final List<String> _after=new ArrayList<>();
private final List<String> _beforeThis=new ArrayList<>();
private final ClasspathPattern _system=new ClasspathPattern();
private final ClasspathPattern _server=new ClasspathPattern();
protected AbstractConfiguration()
{
this(false);
}
protected AbstractConfiguration(boolean disabledByDefault)
{
_disabledByDefault=disabledByDefault;
}
/**
@ -174,6 +180,18 @@ public class AbstractConfiguration implements Configuration
{
}
@Override
public boolean isDisabledByDefault()
{
return _disabledByDefault;
}
@Override
public boolean abort(WebAppContext context)
{
return false;
}
public void cloneConfigure(WebAppContext template, WebAppContext context) throws Exception
{
}

View File

@ -129,18 +129,17 @@ public interface Configuration
* @throws Exception if unable to destroy
*/
public void destroy (WebAppContext context) throws Exception;
/**
* A Configuration that is not added by default to a context
*
* @return true if configuration is disabled by default
*/
interface DisabledByDefault extends Configuration {}
public boolean isDisabledByDefault();
/**
* A Configuration that will cause {@link Configurations#configure(WebAppContext)} to abort with a false return
* @return true if configuration should be aborted
*/
interface AbortConfiguration extends DisabledByDefault,Configuration {}
public boolean abort(WebAppContext context);
/**
* @deprecated Use {@link Configurations}
*/

View File

@ -187,7 +187,7 @@ public class Configurations extends AbstractList<Configuration>
if (configurations==null)
{
configurations=new Configurations(Configurations.getKnown().stream()
.filter(c->!(c instanceof Configuration.DisabledByDefault))
.filter(c->!c.isDisabledByDefault())
.map(c->c.getClass().getName())
.toArray(String[]::new));
}
@ -438,7 +438,7 @@ public class Configurations extends AbstractList<Configuration>
/**
* @param webapp The webapp to configure
* @return false if a {@link Configuration.AbortConfiguration} was encountered, true otherwise
* @return false if a {@link Configuration#abort(WebAppContext)} returns true, true otherwise
* @throws Exception Thrown by {@link Configuration#configure(WebAppContext)}
*/
public boolean configure(WebAppContext webapp) throws Exception
@ -448,7 +448,7 @@ public class Configurations extends AbstractList<Configuration>
{
LOG.debug("configure {}",configuration);
configuration.configure(webapp);
if (configuration instanceof Configuration.AbortConfiguration)
if (configuration.abort(webapp))
return false;
}
return true;

View File

@ -57,7 +57,7 @@ public class WebAppContextTest
public void testConfigurationClassesFromDefault ()
{
String[] known_and_enabled=Configurations.getKnown().stream()
.filter(c->!(c instanceof Configuration.DisabledByDefault))
.filter(c->!c.isDisabledByDefault())
.map(c->c.getClass().getName())
.toArray(String[]::new);

View File

@ -61,7 +61,7 @@ public class QuickStartTest
Server server = new Server(0);
QuickStartWebApp webapp = new QuickStartWebApp();
webapp.setAutoGenerate(true);
webapp.setMode(QuickStartConfiguration.Mode.AUTO);
webapp.setWar(war);
webapp.setContextPath("/");
@ -107,7 +107,7 @@ public class QuickStartTest
Server server = new Server(0);
QuickStartWebApp webapp = new QuickStartWebApp();
webapp.setAutoGenerate(true);
webapp.setMode(QuickStartConfiguration.Mode.AUTO);
webapp.setWar(war);
webapp.setContextPath("/");
@ -153,7 +153,7 @@ public class QuickStartTest
Server server = new Server(0);
QuickStartWebApp webapp = new QuickStartWebApp();
webapp.setAutoGenerate(true);
webapp.setMode(QuickStartConfiguration.Mode.AUTO);
webapp.setWar(war);
webapp.setContextPath("/");

View File

@ -41,7 +41,7 @@ public class Quickstart
Server server = new Server(8080);
QuickStartWebApp webapp = new QuickStartWebApp();
webapp.setAutoGenerate(true);
webapp.setMode(QuickStartConfiguration.Mode.AUTO);
webapp.setWar(war);
webapp.setContextPath("/");