work in progress

This commit is contained in:
Greg Wilkins 2016-03-15 10:11:49 +11:00
parent 61d2c07534
commit 725be8c051
12 changed files with 116 additions and 30 deletions

View File

@ -0,0 +1 @@
org.eclipse.jetty.webapp.JndiConfiguration

View File

@ -117,6 +117,12 @@
org.xml.sax.helpers,
*
</Import-Package>
<Require-Capability>
osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"
</Require-Capability>
<Provide-Capability>
osgi.serviceloader; osgi.serviceloader=org.eclipse.jetty.webapp.Configuration
</Provide-Capability>
<_nouses>true</_nouses>
</instructions>
</configuration>

View File

@ -13,7 +13,24 @@
<bundle-symbolic-name>${project.groupId}.plus</bundle-symbolic-name>
</properties>
<build>
<plugins>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Require-Capability>
osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"
</Require-Capability>
<Provide-Capability>
osgi.serviceloader;
osgi.serviceloader=org.eclipse.jetty.webapp.Configuration
</Provide-Capability>
</instructions>
</configuration>
</plugin>
<!-- always include the sources to be able to prepare the eclipse-jetty-SDK feature
with a snapshot. -->
<plugin>

View File

@ -709,10 +709,10 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
MetaData metadata = context.getMetaData();
metadata.resolve(context);
Resource quickStartWebXml = context.getResource("/WEB-INF/quickstart-web.xml");
Resource quickStartWebXml = context.getBaseResource().addPath("/WEB-INF/quickstart-web.xml");
if (!quickStartWebXml.exists())
quickStartWebXml.getFile().createNewFile();
try (FileOutputStream fos = new FileOutputStream(quickStartWebXml.getFile()))
try (FileOutputStream fos = new FileOutputStream(quickStartWebXml.getFile(),false))
{
generateQuickStartWebXml(context,fos);
}

View File

@ -212,12 +212,14 @@ public class ResourceCollection extends Resource
int i=0;
for(; i<_resources.length; i++)
{
resource = _resources[i].addPath(path);
if (resource.exists())
Resource r = _resources[i].addPath(path);
if (resource==null)
resource=r;
if (r.exists())
{
if (resource.isDirectory())
if (r.isDirectory())
break;
return resource;
return r;
}
}

View File

@ -42,6 +42,19 @@
<reuseForks>false</reuseForks>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Require-Capability>
osgi.extender; filter:="(osgi.extender=osgi.serviceloader.processor)",
osgi.serviceloader; filter:="(osgi.serviceloader=org.eclipse.jetty.webapp.Configuration)";cardinality:=multiple
</Require-Capability>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>

View File

@ -33,8 +33,6 @@ import org.eclipse.jetty.util.annotation.Name;
public interface Configuration
{
public final static String ATTR="org.eclipse.jetty.webapp.configuration";
public default String getName() { return getClass().getName(); }
/* ------------------------------------------------------------------------------- */
/** Get a class that this class replaces/extends

View File

@ -48,7 +48,7 @@ public class Configurations extends AbstractList<Configuration>
{
ServiceLoader<Configuration> configs = ServiceLoader.load(Configuration.class);
for (Configuration configuration : configs)
__knownByClassName.put(configuration.getName(),configuration);
__knownByClassName.put(configuration.getClass().getName(),configuration);
__known.addAll(__knownByClassName.values());
sort(__known);
if (LOG.isDebugEnabled())
@ -177,13 +177,13 @@ public class Configurations extends AbstractList<Configuration>
public void add(Configuration... configurations)
{
for (Configuration configuration : configurations)
add(configuration.getName(),configuration);
addConfiguration(configuration);
}
public void add(@Name("configClass")String... configClass)
{
for (String name : configClass)
add(name,getConfiguration(name));
addConfiguration(getConfiguration(name));
}
public void clear()
@ -194,24 +194,22 @@ public class Configurations extends AbstractList<Configuration>
public void set(Configuration... configurations)
{
clear();
for (Configuration configuration : configurations)
add(configuration.getName(),configuration);
add(configurations);
}
public void set(@Name("configClass")String... configClass)
{
clear();
for (String name : configClass)
add(name,getConfiguration(name));
add(configClass);
}
public void remove(Configuration... configurations)
{
List<String> names = Arrays.asList(configurations).stream().map(Configuration::getName).collect(Collectors.toList());
List<String> names = Arrays.asList(configurations).stream().map(c->c.getClass().getName()).collect(Collectors.toList());
for (ListIterator<Configuration> i=_configurations.listIterator();i.hasNext();)
{
Configuration configuration=i.next();
if (names.contains(configuration.getName()))
if (names.contains(configuration.getClass().getName()))
i.remove();
}
}
@ -222,7 +220,7 @@ public class Configurations extends AbstractList<Configuration>
for (ListIterator<Configuration> i=_configurations.listIterator();i.hasNext();)
{
Configuration configuration=i.next();
if (names.contains(configuration.getName()))
if (names.contains(configuration.getClass().getName()))
i.remove();
}
}
@ -234,7 +232,7 @@ public class Configurations extends AbstractList<Configuration>
public String[] toArray()
{
return _configurations.stream().map(Configuration::getName).toArray(String[]::new);
return _configurations.stream().map(c->c.getClass().getName()).toArray(String[]::new);
}
public void sort()
@ -254,7 +252,7 @@ public class Configurations extends AbstractList<Configuration>
TopologicalSort<Configuration> sort = new TopologicalSort<>();
for (Configuration c:configurations)
map.put(c.getName(),c);
map.put(c.getClass().getName(),c);
for (Configuration c:configurations)
{
for (String b:c.getConfigurationsBeforeThis())
@ -291,8 +289,9 @@ public class Configurations extends AbstractList<Configuration>
return getConfigurations().iterator();
}
private void add(String name,Configuration configuration)
private void addConfiguration(Configuration configuration)
{
String name=configuration.getClass().getName();
// Is this configuration known?
if (!__knownByClassName.containsKey(name))
LOG.warn("Unknown configuration {}. Not declared for ServiceLoader!",name);
@ -303,7 +302,7 @@ public class Configurations extends AbstractList<Configuration>
{
for (ListIterator<Configuration> i=_configurations.listIterator();i.hasNext();)
{
if (i.next().getName().equals(replaces.getName()))
if (i.next().getClass().getName().equals(replaces.getName()))
{
i.set(configuration);
return;
@ -314,7 +313,7 @@ public class Configurations extends AbstractList<Configuration>
return;
}
if (!_configurations.stream().map(Configuration::getName).anyMatch(n->{return name.equals(n);}))
if (!_configurations.stream().map(c->c.getClass().getName()).anyMatch(n->{return name.equals(n);}))
_configurations.add(configuration);
}

View File

@ -0,0 +1,47 @@
//
// ========================================================================
// Copyright (c) 1995-2016 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.webapp;
import java.util.ServiceLoader;
/**
* <p>JNDI Configuration</p>
* <p>This configuration configures the WebAppContext system/server classes to
* be able to see the org.eclipse.jetty.jaas package.
* This class is defined in the webapp package, as it implements the {@link Configuration} interface,
* which is unknown to the jndi package. However, the corresponding {@link ServiceLoader}
* resource is defined in the jndi package, so that this configuration only be
* loaded if the jetty-jndi jars are on the classpath.
* </p>
*/
public class JndiConfiguration extends AbstractConfiguration
{
public JndiConfiguration()
{
super(true,
new String[]{WebXmlConfiguration.class.getName(),MetaInfConfiguration.class.getName(),WebInfConfiguration.class.getName(),FragmentConfiguration.class.getName()},
new String[]{WebAppConfiguration.class.getName()},
new String[]{
"org.eclipse.jetty.jndi."
},
new String[]{
"-org.eclipse.jetty.jndi.",
});
}
}

View File

@ -988,7 +988,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
{
loadConfigurations();
for (Configuration configuration : _configurations)
if (configClass.isAssignableFrom(configuration.getClass()) && configuration.getName().equals(configClass.getName()))
if (configClass.isAssignableFrom(configuration.getClass()))
return (T)configuration;
return null;
}

View File

@ -19,7 +19,6 @@
package org.eclipse.jetty.webapp;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
@ -29,8 +28,8 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.GenericServlet;
import javax.servlet.ServletContext;
@ -80,7 +79,7 @@ public class WebAppContextTest
{
WebAppContext wac = new WebAppContext();
wac.setServer(new Server());
Assert.assertThat(Arrays.asList(wac.getConfigurations()).stream().map(Configuration::getName).collect(Collectors.toList()),
Assert.assertThat(Arrays.asList(wac.getConfigurations()).stream().map(c->c.getClass().getName()).collect(Collectors.toList()),
Matchers.contains(
"org.eclipse.jetty.webapp.JmxConfiguration",
"org.eclipse.jetty.webapp.WebInfConfiguration",

View File

@ -22,8 +22,12 @@
<extensions>true</extensions>
<configuration>
<instructions>
<Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"</Require-Capability>
<Provide-Capability>osgi.serviceloader; osgi.serviceloader=org.eclipse.jetty.websocket.servlet.WebSocketServletFactory</Provide-Capability>
<Require-Capability>
osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"
</Require-Capability>
<Provide-Capability>
osgi.serviceloader; osgi.serviceloader=org.eclipse.jetty.websocket.servlet.WebSocketServletFactory,org.eclipse.jetty.webapp.Configuration
</Provide-Capability>
</instructions>
</configuration>
</plugin>