Merge branch 'jetty-9.4.x' into jetty-10.0.x

This commit is contained in:
olivier lamy 2020-12-14 09:24:17 +10:00
commit 0c1f9636b3
7 changed files with 75 additions and 89 deletions

View File

@ -159,7 +159,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
if (pathSpec == null || "".equals(pathSpec.trim()) || constraintMappings == null || constraintMappings.size() == 0)
return Collections.emptyList();
List<ConstraintMapping> mappings = new ArrayList<ConstraintMapping>();
List<ConstraintMapping> mappings = new ArrayList<>();
for (ConstraintMapping mapping : constraintMappings)
{
if (pathSpec.equals(mapping.getPathSpec()))
@ -183,7 +183,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
if (pathSpec == null || "".equals(pathSpec.trim()) || constraintMappings == null || constraintMappings.size() == 0)
return Collections.emptyList();
List<ConstraintMapping> mappings = new ArrayList<ConstraintMapping>();
List<ConstraintMapping> mappings = new ArrayList<>();
for (ConstraintMapping mapping : constraintMappings)
{
//Remove the matching mappings by only copying in non-matching mappings
@ -205,10 +205,10 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
*/
public static List<ConstraintMapping> createConstraintsWithMappingsForPath(String name, String pathSpec, ServletSecurityElement securityElement)
{
List<ConstraintMapping> mappings = new ArrayList<ConstraintMapping>();
List<ConstraintMapping> mappings = new ArrayList<>();
//Create a constraint that will describe the default case (ie if not overridden by specific HttpMethodConstraints)
Constraint httpConstraint = null;
Constraint httpConstraint;
ConstraintMapping httpConstraintMapping = null;
if (securityElement.getEmptyRoleSemantic() != EmptyRoleSemantic.PERMIT ||
@ -225,7 +225,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
}
//See Spec 13.4.1.2 p127
List<String> methodOmissions = new ArrayList<String>();
List<String> methodOmissions = new ArrayList<>();
//make constraint mappings for this url for each of the HttpMethodConstraintElements
Collection<HttpMethodConstraintElement> methodConstraintElements = securityElement.getHttpMethodConstraints();
@ -250,7 +250,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
//See spec 13.4.1.2 p127 - add an omission for every method name to the default constraint
//UNLESS the default constraint contains all default values. In that case, we won't add it. See Servlet Spec 3.1 pg 129
if (methodOmissions.size() > 0 && httpConstraintMapping != null)
httpConstraintMapping.setMethodOmissions(methodOmissions.toArray(new String[methodOmissions.size()]));
httpConstraintMapping.setMethodOmissions(methodOmissions.toArray(new String[0]));
return mappings;
}
@ -394,10 +394,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
_constraintRoles.reset();
if (_constraintMappings != null)
{
for (ConstraintMapping mapping : _constraintMappings)
{
processConstraintMapping(mapping);
}
_constraintMappings.stream().forEach(this::processConstraintMapping);
}
//Servlet Spec 3.1 pg 147 sec 13.8.4.2 log paths for which there are uncovered http methods
@ -424,7 +421,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
Map<String, RoleInfo> mappings = _constraintRoles.get(PathMappings.asPathSpec(mapping.getPathSpec()));
if (mappings == null)
{
mappings = new HashMap<String, RoleInfo>();
mappings = new HashMap<>();
_constraintRoles.put(mapping.getPathSpec(), mappings);
}
RoleInfo allMethodsRoleInfo = mappings.get(ALL_METHODS);
@ -579,7 +576,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
if (roleInfo == null)
{
//No specific http-method names matched
List<RoleInfo> applicableConstraints = new ArrayList<RoleInfo>();
List<RoleInfo> applicableConstraints = new ArrayList<>();
//Get info for constraint that matches all methods if it exists
RoleInfo all = mappings.get(ALL_METHODS);
@ -715,8 +712,8 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
public void dump(Appendable out, String indent) throws IOException
{
dumpObjects(out, indent,
DumpableCollection.from("roles", _roles),
DumpableCollection.from("constraints", _constraintMappings));
DumpableCollection.from("roles", _roles),
DumpableCollection.from("constraints", _constraintMappings));
}
@Override
@ -767,7 +764,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
if (_denyUncoveredMethods)
return Collections.emptySet();
Set<String> uncoveredPaths = new HashSet<String>();
Set<String> uncoveredPaths = new HashSet<>();
for (MappedResource<Map<String, RoleInfo>> resource : _constraintRoles)
{
@ -839,7 +836,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
return Collections.emptySet();
String[] strings = omission.split("\\.");
Set<String> methods = new HashSet<String>();
Set<String> methods = new HashSet<>();
for (int i = 0; i < strings.length - 1; i++)
{
methods.add(strings[i]);

View File

@ -66,13 +66,10 @@ public class Licensing
System.err.printf(" + contains software not covered by the Eclipse Public License!%n");
System.err.printf(" + has not been audited for compliance with its license%n");
for (String key : licenseMap.keySet())
for (Map.Entry<String, List<String>> entry : licenseMap.entrySet())
{
System.err.printf("%n Module: %s%n", key);
for (String line : licenseMap.get(key))
{
System.err.printf(" + %s%n", line);
}
System.err.printf("%n Module: %s%n", entry.getKey());
entry.getValue().forEach(line -> System.err.printf(" + %s%n", line));
}
boolean licenseAck = false;

View File

@ -76,12 +76,12 @@ public class Scanner extends AbstractLifeCycle
{
ADDED, CHANGED, REMOVED, STABLE
}
enum Notification
{
ADDED, CHANGED, REMOVED
}
/**
* PathMatcherSet
*
@ -104,7 +104,7 @@ public class Scanner extends AbstractLifeCycle
/**
* MetaData
*
*
* Metadata about a file: Last modified time, file size and
* last file status (ADDED, CHANGED, DELETED, STABLE)
*/
@ -131,7 +131,7 @@ public class Scanner extends AbstractLifeCycle
return "[lm=" + _lastModified + ",sz=" + _size + ",s=" + _status + "]";
}
}
private class ScanTask implements Runnable
{
@Override
@ -153,28 +153,28 @@ public class Scanner extends AbstractLifeCycle
Map<String, MetaData> scanInfoMap;
IncludeExcludeSet<PathMatcher,Path> rootIncludesExcludes;
Path root;
public Visitor(Path root, IncludeExcludeSet<PathMatcher,Path> rootIncludesExcludes, Map<String, MetaData> scanInfoMap)
{
this.root = root;
this.rootIncludesExcludes = rootIncludesExcludes;
this.scanInfoMap = scanInfoMap;
}
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException
{
if (!Files.exists(dir))
return FileVisitResult.SKIP_SUBTREE;
File f = dir.toFile();
//if we want to report directories and we haven't already seen it
if (_reportDirs && !scanInfoMap.containsKey(f.getCanonicalPath()))
{
boolean accepted = false;
if (rootIncludesExcludes != null && !rootIncludesExcludes.isEmpty())
{
{
//accepted if not explicitly excluded and either is explicitly included or there are no explicit inclusions
accepted = rootIncludesExcludes.test(dir);
}
@ -219,7 +219,7 @@ public class Scanner extends AbstractLifeCycle
scanInfoMap.put(f.getCanonicalPath(), new MetaData(f.lastModified(), f.isDirectory() ? 0 : f.length()));
if (LOG.isDebugEnabled()) LOG.debug("scan accepted {} mod={}", f, f.lastModified());
}
return FileVisitResult.CONTINUE;
}
@ -236,7 +236,7 @@ public class Scanner extends AbstractLifeCycle
return FileVisitResult.CONTINUE;
}
}
/**
* Listener
*
@ -251,11 +251,11 @@ public class Scanner extends AbstractLifeCycle
*/
public interface DiscreteListener extends Listener
{
public void fileChanged(String filename) throws Exception;
void fileChanged(String filename) throws Exception;
public void fileAdded(String filename) throws Exception;
void fileAdded(String filename) throws Exception;
public void fileRemoved(String filename) throws Exception;
void fileRemoved(String filename) throws Exception;
}
/**
@ -271,11 +271,11 @@ public class Scanner extends AbstractLifeCycle
*/
public interface ScanCycleListener extends Listener
{
public default void scanStarted(int cycle) throws Exception
default void scanStarted(int cycle) throws Exception
{
}
public default void scanEnded(int cycle) throws Exception
default void scanEnded(int cycle) throws Exception
{
}
}
@ -303,7 +303,7 @@ public class Scanner extends AbstractLifeCycle
{
if (isRunning())
throw new IllegalStateException("Scanner started");
_scanInterval = scanInterval;
}
@ -326,14 +326,14 @@ public class Scanner extends AbstractLifeCycle
/**
* Add a file to be scanned. The file must not be null, and must exist.
*
*
* @param p the Path of the file to scan.
*/
public void addFile(Path p)
{
if (isRunning())
throw new IllegalStateException("Scanner started");
if (p == null)
throw new IllegalStateException("Null path");
@ -351,7 +351,7 @@ public class Scanner extends AbstractLifeCycle
/**
* Add a directory to be scanned. The directory must not be null and must exist.
*
*
* @param p the directory to scan.
* @return an IncludeExcludeSet to which the caller can add PathMatcher patterns to match
*/
@ -359,7 +359,7 @@ public class Scanner extends AbstractLifeCycle
{
if (isRunning())
throw new IllegalStateException("Scanner started");
if (p == null)
throw new IllegalStateException("Null path");
@ -379,7 +379,7 @@ public class Scanner extends AbstractLifeCycle
throw new IllegalStateException(e);
}
}
/**
* Apply a filter to files found in the scan directory.
@ -428,7 +428,7 @@ public class Scanner extends AbstractLifeCycle
{
if (isRunning())
throw new IllegalStateException("Scanner started");
_scanDepth = scanDepth;
}
@ -500,7 +500,7 @@ public class Scanner extends AbstractLifeCycle
{
if (LOG.isDebugEnabled())
LOG.debug("Scanner start: rprtExists={}, depth={}, rprtDirs={}, interval={}, filter={}, scannables={}",
_reportExisting, _scanDepth, _reportDirs, _scanInterval, _filter, _scannables);
_reportExisting, _scanDepth, _reportDirs, _scanInterval, _filter, _scannables);
if (_reportExisting)
{
@ -513,12 +513,12 @@ public class Scanner extends AbstractLifeCycle
//just register the list of existing files and only report changes
_prevScan = scanFiles();
}
//Create the scheduler and start it
_scheduler = new ScheduledExecutorScheduler("Scanner-" + SCANNER_IDS.getAndIncrement(), true, 1);
_scheduler.start();
//schedule the scan
schedule();
}
@ -576,7 +576,7 @@ public class Scanner extends AbstractLifeCycle
}
/**
* Hint to the scanner to perform a scan cycle as soon as possible.
* Hint to the scanner to perform a scan cycle as soon as possible.
* NOTE that the scan is not guaranteed to have happened by the
* time this method returns.
*/
@ -586,17 +586,17 @@ public class Scanner extends AbstractLifeCycle
throw new IllegalStateException("Scanner not running");
scan(Callback.NOOP);
}
/**
* Get the scanner to perform a scan cycle as soon as possible
* and call the Callback when the scan is finished or failed.
*
*
* @param complete called when the scan cycle finishes or fails.
*/
public void scan(Callback complete)
{
Scheduler scheduler = _scheduler;
if (!isRunning() || scheduler == null)
{
complete.failed(new IllegalStateException("Scanner not running"));
@ -636,11 +636,12 @@ public class Scanner extends AbstractLifeCycle
private Map<String, MetaData> scanFiles()
{
Map<String, MetaData> currentScan = new HashMap<>();
for (Path p : _scannables.keySet())
for (Map.Entry<Path, IncludeExcludeSet<PathMatcher, Path>> entry : _scannables.entrySet())
{
try
{
Files.walkFileTree(p, EnumSet.allOf(FileVisitOption.class),_scanDepth, new Visitor(p, _scannables.get(p), currentScan));
Files.walkFileTree(entry.getKey(), EnumSet.allOf(FileVisitOption.class),_scanDepth,
new Visitor(entry.getKey(), entry.getValue(), currentScan));
}
catch (IOException e)
{
@ -652,7 +653,7 @@ public class Scanner extends AbstractLifeCycle
/**
* Report the adds/changes/removes to the registered listeners
*
*
* Only report an add or change once a file has stablilized in size.
*
* @param currentScan the info from the most recent pass
@ -663,7 +664,7 @@ public class Scanner extends AbstractLifeCycle
Map<String, Notification> changes = new HashMap<>();
//Handle deleted files
Set<String> oldScanKeys = new HashSet<>(oldScan.keySet());
Set<String> oldScanKeys = new HashSet<>(oldScan.keySet());
oldScanKeys.removeAll(currentScan.keySet());
for (String file : oldScanKeys)
{
@ -671,10 +672,10 @@ public class Scanner extends AbstractLifeCycle
}
// Handle new and changed files
for (String file : currentScan.keySet())
for (Map.Entry<String, MetaData> entry : currentScan.entrySet())
{
MetaData current = currentScan.get(file);
MetaData previous = oldScan.get(file);
MetaData current = entry.getValue();
MetaData previous = oldScan.get(entry.getKey());
if (previous == null)
{
@ -700,9 +701,9 @@ public class Scanner extends AbstractLifeCycle
//Unchanged file: if it was previously
//ADDED, we can now send the ADDED event.
if (previous._status == Status.ADDED)
changes.put(file, Notification.ADDED);
changes.put(entry.getKey(), Notification.ADDED);
else if (previous._status == Status.CHANGED)
changes.put(file, Notification.CHANGED);
changes.put(entry.getKey(), Notification.CHANGED);
current._status = Status.STABLE;
}
@ -711,7 +712,7 @@ public class Scanner extends AbstractLifeCycle
if (LOG.isDebugEnabled())
LOG.debug("scanned {}", _scannables.keySet());
//Call the DiscreteListeners
//Call the DiscreteListeners
for (Map.Entry<String, Notification> entry : changes.entrySet())
{
switch (entry.getValue())
@ -790,7 +791,7 @@ public class Scanner extends AbstractLifeCycle
{
if (filename == null)
return;
for (Listener l : _listeners)
{
try
@ -807,14 +808,14 @@ public class Scanner extends AbstractLifeCycle
/**
* Report the list of filenames for which changes were detected.
*
*
* @param filenames names of all files added/changed/removed
*/
private void reportBulkChanges(Set<String> filenames)
{
if (filenames == null || filenames.isEmpty())
return;
for (Listener l : _listeners)
{
try
@ -831,7 +832,7 @@ public class Scanner extends AbstractLifeCycle
/**
* Call ScanCycleListeners with start of scan
*
*
* @param cycle scan count
*/
private void reportScanStart(int cycle)
@ -852,7 +853,7 @@ public class Scanner extends AbstractLifeCycle
/**
* Call ScanCycleListeners with end of scan.
*
*
* @param cycle scan count
*/
private void reportScanEnd(int cycle)

View File

@ -57,16 +57,9 @@ public class FragmentConfiguration extends AbstractConfiguration
Map<Resource, Resource> frags = (Map<Resource, Resource>)context.getAttribute(FRAGMENT_RESOURCES);
if (frags != null)
{
for (Resource key : frags.keySet())
for (Map.Entry<Resource, Resource> entry : frags.entrySet())
{
if (key.isDirectory()) //tolerate the case where the library is a directory, not a jar. useful for OSGi for example
{
metaData.addFragmentDescriptor(key, new FragmentDescriptor(frags.get(key)));
}
else //the standard case: a jar most likely inside WEB-INF/lib
{
metaData.addFragmentDescriptor(key, new FragmentDescriptor(frags.get(key)));
}
metaData.addFragmentDescriptor(entry.getKey(), new FragmentDescriptor(entry.getValue()));
}
}
}

View File

@ -458,7 +458,7 @@ public class MetaData
if (isOrdered())
{
orderedWebInfJars = getWebInfResources(true);
List<String> orderedLibs = new ArrayList<String>();
List<String> orderedLibs = new ArrayList<>();
for (Resource webInfJar : orderedWebInfJars)
{
//get just the name of the jar file
@ -611,12 +611,12 @@ public class MetaData
*/
public Resource getJarForFragmentName(String name)
{
Resource jar = null;
FragmentDescriptor f = getFragmentDescriptor(name);
if (f == null)
return null;
Resource jar = null;
for (Map.Entry<Resource, FragmentDescriptor> entry : _webFragmentResourceMap.entrySet())
{
if (entry.getValue().equals(f))

View File

@ -54,7 +54,7 @@ public class XmlAppendable
{
_out = out;
_indent = indent;
_out.append("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n");
_out.append("<?xml version=\"1.0\" encoding=\"").append(encoding).append("\"?>\n");
}
public XmlAppendable openTag(String tag, Map<String, String> attributes) throws IOException
@ -146,11 +146,10 @@ public class XmlAppendable
private void attributes(Map<String, String> attributes) throws IOException
{
for (String k : attributes.keySet())
for (Map.Entry<String, String> entry : attributes.entrySet())
{
String v = attributes.get(k);
_out.append(' ').append(k).append("=\"");
content(v);
_out.append(' ').append(entry.getKey()).append("=\"");
content(entry.getValue());
_out.append('"');
}
}

View File

@ -1811,10 +1811,9 @@ public class XmlConfiguration
if (properties.size() > 0)
{
Map<String, String> props = new HashMap<>();
for (Object key : properties.keySet())
{
props.put(key.toString(), String.valueOf(properties.get(key)));
}
properties.entrySet().stream()
.forEach(objectObjectEntry -> props.put(objectObjectEntry.getKey().toString(),
String.valueOf(objectObjectEntry.getValue())));
configuration.getProperties().putAll(props);
}