447979 Refactor to make MetaData responsible for progressively ordering web-inf jars

This commit is contained in:
Jan Bartel 2014-10-24 12:46:46 +11:00
parent fac197f868
commit 1ab6d7398c
4 changed files with 72 additions and 54 deletions

View File

@ -760,11 +760,12 @@ public class AnnotationConfiguration extends AbstractConfiguration
if (isFromContainerClassPath(context, sci)) if (isFromContainerClassPath(context, sci))
return false; return false;
List<Resource> orderedJars = context.getMetaData().getOrderedWebInfJars();
//If no ordering, nothing is excluded //If no ordering, nothing is excluded
if (context.getMetaData().getOrdering() == null) if (context.getMetaData().getOrdering() == null)
return false; return false;
List<Resource> orderedJars = context.getMetaData().getOrderedWebInfJars();
//there is an ordering, but there are no jars resulting from the ordering, everything excluded //there is an ordering, but there are no jars resulting from the ordering, everything excluded
if (orderedJars.isEmpty()) if (orderedJars.isEmpty())
@ -1007,10 +1008,12 @@ public class AnnotationConfiguration extends AbstractConfiguration
//they have to participate in the ordering //they have to participate in the ordering
ArrayList<URI> webInfUris = new ArrayList<URI>(); ArrayList<URI> webInfUris = new ArrayList<URI>();
List<Resource> jars = context.getMetaData().getOrderedWebInfJars(); List<Resource> jars = null;
//No ordering just use the jars in any order if (context.getMetaData().getOrdering() != null)
if (jars == null || jars.isEmpty()) jars = context.getMetaData().getOrderedWebInfJars();
else
//No ordering just use the jars in any order
jars = context.getMetaData().getWebInfJars(); jars = context.getMetaData().getWebInfJars();
_webInfLibStats = new CounterStatistic(); _webInfLibStats = new CounterStatistic();

View File

@ -69,8 +69,8 @@ public class AnnotationConfiguration extends org.eclipse.jetty.annotations.Annot
public AnnotationConfiguration() public AnnotationConfiguration()
{ {
System.err.println("Constructed osgi.AnnotationConfiguration");
} }
/** /**
* This parser scans the bundles using the OSGi APIs instead of assuming a jar. * This parser scans the bundles using the OSGi APIs instead of assuming a jar.
*/ */

View File

@ -45,15 +45,6 @@ public class FragmentConfiguration extends AbstractConfiguration
} }
@Override
public void configure(WebAppContext context) throws Exception
{
if (!context.isConfigurationDiscovered())
return;
//order the fragments
context.getMetaData().orderFragments();
}
@Override @Override
public void postConfigure(WebAppContext context) throws Exception public void postConfigure(WebAppContext context) throws Exception

View File

@ -59,8 +59,8 @@ public class MetaData
protected final Map<Resource, List<DiscoveredAnnotation>> _annotations = new HashMap<Resource, List<DiscoveredAnnotation>>(); protected final Map<Resource, List<DiscoveredAnnotation>> _annotations = new HashMap<Resource, List<DiscoveredAnnotation>>();
protected final List<Resource> _webInfClasses = new ArrayList<Resource>(); protected final List<Resource> _webInfClasses = new ArrayList<Resource>();
protected final List<Resource> _webInfJars = new ArrayList<Resource>(); protected final List<Resource> _webInfJars = new ArrayList<Resource>();
protected final List<Resource> _orderedWebInfJars = new ArrayList<Resource>();
protected final List<Resource> _orderedContainerResources = new ArrayList<Resource>(); protected final List<Resource> _orderedContainerResources = new ArrayList<Resource>();
protected final List<Resource> _orderedWebInfResources = new ArrayList<Resource>();
protected Ordering _ordering;//can be set to RelativeOrdering by web-default.xml, web.xml, web-override.xml protected Ordering _ordering;//can be set to RelativeOrdering by web-default.xml, web.xml, web-override.xml
protected boolean allowDuplicateFragmentNames = false; protected boolean allowDuplicateFragmentNames = false;
@ -158,7 +158,7 @@ public class MetaData
_webFragmentResourceMap.clear(); _webFragmentResourceMap.clear();
_annotations.clear(); _annotations.clear();
_webInfJars.clear(); _webInfJars.clear();
_orderedWebInfJars.clear(); _orderedWebInfResources.clear();
_orderedContainerResources.clear(); _orderedContainerResources.clear();
_ordering = null; _ordering = null;
allowDuplicateFragmentNames = false; allowDuplicateFragmentNames = false;
@ -171,17 +171,21 @@ public class MetaData
_webDefaultsRoot.parse(); _webDefaultsRoot.parse();
if (_webDefaultsRoot.isOrdered()) if (_webDefaultsRoot.isOrdered())
{ {
if (_ordering == null) Ordering ordering = getOrdering();
_ordering = new Ordering.AbsoluteOrdering(this); if (ordering == null)
ordering = new Ordering.AbsoluteOrdering(this);
List<String> order = _webDefaultsRoot.getOrdering(); List<String> order = _webDefaultsRoot.getOrdering();
for (String s:order) for (String s:order)
{ {
if (s.equalsIgnoreCase("others")) if (s.equalsIgnoreCase("others"))
((Ordering.AbsoluteOrdering)_ordering).addOthers(); ((Ordering.AbsoluteOrdering)ordering).addOthers();
else else
((Ordering.AbsoluteOrdering)_ordering).add(s); ((Ordering.AbsoluteOrdering)ordering).add(s);
} }
//(re)set the ordering to cause webinf jar order to be recalculated
setOrdering(ordering);
} }
} }
@ -194,17 +198,21 @@ public class MetaData
if (_webXmlRoot.isOrdered()) if (_webXmlRoot.isOrdered())
{ {
if (_ordering == null) Ordering ordering = getOrdering();
_ordering = new Ordering.AbsoluteOrdering(this); if (ordering == null)
ordering = new Ordering.AbsoluteOrdering(this);
List<String> order = _webXmlRoot.getOrdering(); List<String> order = _webXmlRoot.getOrdering();
for (String s:order) for (String s:order)
{ {
if (s.equalsIgnoreCase("others")) if (s.equalsIgnoreCase("others"))
((Ordering.AbsoluteOrdering)_ordering).addOthers(); ((Ordering.AbsoluteOrdering)ordering).addOthers();
else else
((Ordering.AbsoluteOrdering)_ordering).add(s); ((Ordering.AbsoluteOrdering)ordering).add(s);
} }
//(re)set the ordering to cause webinf jar order to be recalculated
setOrdering(ordering);
} }
} }
@ -229,17 +237,22 @@ public class MetaData
if (webOverrideRoot.isOrdered()) if (webOverrideRoot.isOrdered())
{ {
if (_ordering == null) Ordering ordering = getOrdering();
_ordering = new Ordering.AbsoluteOrdering(this);
if (ordering == null)
ordering = new Ordering.AbsoluteOrdering(this);
List<String> order = webOverrideRoot.getOrdering(); List<String> order = webOverrideRoot.getOrdering();
for (String s:order) for (String s:order)
{ {
if (s.equalsIgnoreCase("others")) if (s.equalsIgnoreCase("others"))
((Ordering.AbsoluteOrdering)_ordering).addOthers(); ((Ordering.AbsoluteOrdering)ordering).addOthers();
else else
((Ordering.AbsoluteOrdering)_ordering).add(s); ((Ordering.AbsoluteOrdering)ordering).add(s);
} }
//set or reset the ordering to cause the webinf jar ordering to be recomputed
setOrdering(ordering);
} }
_webOverrideRoots.add(webOverrideRoot); _webOverrideRoots.add(webOverrideRoot);
} }
@ -276,12 +289,16 @@ public class MetaData
_webFragmentNameMap.put(descriptor.getName(), descriptor); _webFragmentNameMap.put(descriptor.getName(), descriptor);
} }
//If web.xml has specified an absolute ordering, ignore any relative ordering in the fragment
if (_ordering != null && _ordering.isAbsolute())
return;
//only accept an ordering from the fragment if there is no ordering already established
if (_ordering == null && descriptor.isOrdered()) if (_ordering == null && descriptor.isOrdered())
_ordering = new Ordering.RelativeOrdering(this); {
setOrdering(new Ordering.RelativeOrdering(this));
return;
}
//recompute the ordering with the new fragment name
orderFragments();
} }
/** /**
@ -343,14 +360,9 @@ public class MetaData
public void orderFragments () public void orderFragments ()
{ {
//if we have already ordered them don't do it again _orderedWebInfResources.clear();
if (_orderedWebInfJars.size()==_webInfJars.size()) if (getOrdering() != null)
return; _orderedWebInfResources.addAll(getOrdering().order(_webInfJars));
if (_ordering != null)
_orderedWebInfJars.addAll(_ordering.order(_webInfJars));
else
_orderedWebInfJars.addAll(_webInfJars);
} }
@ -367,10 +379,12 @@ public class MetaData
_origins.clear(); _origins.clear();
// Set the ordered lib attribute // Set the ordered lib attribute
if (_ordering != null) List<Resource> orderedWebInfJars = null;
if (getOrdering() != null)
{ {
orderedWebInfJars = getOrderedWebInfJars();
List<String> orderedLibs = new ArrayList<String>(); List<String> orderedLibs = new ArrayList<String>();
for (Resource webInfJar:_orderedWebInfJars) for (Resource webInfJar:orderedWebInfJars)
{ {
//get just the name of the jar file //get just the name of the jar file
String fullname = webInfJar.getName(); String fullname = webInfJar.getName();
@ -413,7 +427,13 @@ public class MetaData
//apply the annotations that are associated with a fragment, according to the //apply the annotations that are associated with a fragment, according to the
//established ordering //established ordering
List<Resource> resources = getOrderedWebInfJars(); List<Resource> resources = null;
if (getOrdering() != null)
resources = orderedWebInfJars;
else
resources = getWebInfJars();
for (Resource r:resources) for (Resource r:resources)
{ {
FragmentDescriptor fd = _webFragmentResourceMap.get(r); FragmentDescriptor fd = _webFragmentResourceMap.get(r);
@ -448,12 +468,15 @@ public class MetaData
for (WebDescriptor d : _webOverrideRoots) for (WebDescriptor d : _webOverrideRoots)
distributable&=d.isDistributable(); distributable&=d.isDistributable();
List<Resource> orderedResources = getOrderedWebInfJars(); if (getOrdering() != null)
for (Resource r: orderedResources)
{ {
FragmentDescriptor d = _webFragmentResourceMap.get(r); List<Resource> orderedResources = getOrderedWebInfJars();
if (d!=null) for (Resource r: orderedResources)
distributable = distributable && d.isDistributable(); {
FragmentDescriptor d = _webFragmentResourceMap.get(r);
if (d!=null)
distributable = distributable && d.isDistributable();
}
} }
return distributable; return distributable;
} }
@ -481,16 +504,16 @@ public class MetaData
public List<Resource> getOrderedWebInfJars() public List<Resource> getOrderedWebInfJars()
{ {
return _orderedWebInfJars == null? new ArrayList<Resource>(): _orderedWebInfJars; return _orderedWebInfResources;
} }
public List<FragmentDescriptor> getOrderedFragments () public List<FragmentDescriptor> getOrderedFragments ()
{ {
List<FragmentDescriptor> list = new ArrayList<FragmentDescriptor>(); List<FragmentDescriptor> list = new ArrayList<FragmentDescriptor>();
if (_orderedWebInfJars == null) if (getOrdering() == null)
return list; return list;
for (Resource r:_orderedWebInfJars) for (Resource r:getOrderedWebInfJars())
{ {
FragmentDescriptor fd = _webFragmentResourceMap.get(r); FragmentDescriptor fd = _webFragmentResourceMap.get(r);
if (fd != null) if (fd != null)
@ -505,8 +528,9 @@ public class MetaData
} }
public void setOrdering (Ordering o) public void setOrdering (Ordering o)
{ {
_ordering = o; _ordering = o;
orderFragments();
} }
public FragmentDescriptor getFragment (Resource jar) public FragmentDescriptor getFragment (Resource jar)