diff --git a/jetty-security/src/main/java/org/eclipse/jetty/security/ConstraintSecurityHandler.java b/jetty-security/src/main/java/org/eclipse/jetty/security/ConstraintSecurityHandler.java index 067130ded680..6cab593f157c 100644 --- a/jetty-security/src/main/java/org/eclipse/jetty/security/ConstraintSecurityHandler.java +++ b/jetty-security/src/main/java/org/eclipse/jetty/security/ConstraintSecurityHandler.java @@ -159,7 +159,7 @@ public static List getConstraintMappingsForPath(String pathSp if (pathSpec == null || "".equals(pathSpec.trim()) || constraintMappings == null || constraintMappings.size() == 0) return Collections.emptyList(); - List mappings = new ArrayList(); + List mappings = new ArrayList<>(); for (ConstraintMapping mapping : constraintMappings) { if (pathSpec.equals(mapping.getPathSpec())) @@ -183,7 +183,7 @@ public static List removeConstraintMappingsForPath(String pat if (pathSpec == null || "".equals(pathSpec.trim()) || constraintMappings == null || constraintMappings.size() == 0) return Collections.emptyList(); - List mappings = new ArrayList(); + List mappings = new ArrayList<>(); for (ConstraintMapping mapping : constraintMappings) { //Remove the matching mappings by only copying in non-matching mappings @@ -205,10 +205,10 @@ public static List removeConstraintMappingsForPath(String pat */ public static List createConstraintsWithMappingsForPath(String name, String pathSpec, ServletSecurityElement securityElement) { - List mappings = new ArrayList(); + List 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 static List createConstraintsWithMappingsForPath(Strin } //See Spec 13.4.1.2 p127 - List methodOmissions = new ArrayList(); + List methodOmissions = new ArrayList<>(); //make constraint mappings for this url for each of the HttpMethodConstraintElements Collection methodConstraintElements = securityElement.getHttpMethodConstraints(); @@ -250,7 +250,7 @@ public static List createConstraintsWithMappingsForPath(Strin //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 @@ protected void doStart() throws Exception _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 @@ protected void processConstraintMapping(ConstraintMapping mapping) Map mappings = _constraintRoles.get(PathMappings.asPathSpec(mapping.getPathSpec())); if (mappings == null) { - mappings = new HashMap(); + mappings = new HashMap<>(); _constraintRoles.put(mapping.getPathSpec(), mappings); } RoleInfo allMethodsRoleInfo = mappings.get(ALL_METHODS); @@ -579,7 +576,7 @@ protected RoleInfo prepareConstraintInfo(String pathInContext, Request request) if (roleInfo == null) { //No specific http-method names matched - List applicableConstraints = new ArrayList(); + List applicableConstraints = new ArrayList<>(); //Get info for constraint that matches all methods if it exists RoleInfo all = mappings.get(ALL_METHODS); @@ -715,8 +712,8 @@ protected boolean checkWebResourcePermissions(String pathInContext, Request requ 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 Set getPathsWithUncoveredHttpMethods() if (_denyUncoveredMethods) return Collections.emptySet(); - Set uncoveredPaths = new HashSet(); + Set uncoveredPaths = new HashSet<>(); for (MappedResource> resource : _constraintRoles) { @@ -839,7 +836,7 @@ protected Set getOmittedMethods(String omission) return Collections.emptySet(); String[] strings = omission.split("\\."); - Set methods = new HashSet(); + Set methods = new HashSet<>(); for (int i = 0; i < strings.length - 1; i++) { methods.add(strings[i]); diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Licensing.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Licensing.java index 5dfde2d1f75d..9fb7897b8c99 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Licensing.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Licensing.java @@ -66,13 +66,10 @@ public boolean acknowledgeLicenses() throws IOException 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> 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; diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java index 8c55743fcab8..dc361af3772a 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java @@ -76,12 +76,12 @@ private enum Status { ADDED, CHANGED, REMOVED, STABLE } - + enum Notification { ADDED, CHANGED, REMOVED } - + /** * PathMatcherSet * @@ -104,7 +104,7 @@ public boolean test(Path p) /** * MetaData - * + * * Metadata about a file: Last modified time, file size and * last file status (ADDED, CHANGED, DELETED, STABLE) */ @@ -131,7 +131,7 @@ public String toString() return "[lm=" + _lastModified + ",sz=" + _size + ",s=" + _status + "]"; } } - + private class ScanTask implements Runnable { @Override @@ -153,28 +153,28 @@ private class Visitor implements FileVisitor Map scanInfoMap; IncludeExcludeSet rootIncludesExcludes; Path root; - + public Visitor(Path root, IncludeExcludeSet rootIncludesExcludes, Map 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 @@ else if (_filter == null || _filter.accept(f.getParentFile(), f.getName())) 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 FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx return FileVisitResult.CONTINUE; } } - + /** * Listener * @@ -251,11 +251,11 @@ public interface Listener */ 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 interface BulkListener extends Listener */ 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 void setScanInterval(int scanInterval) { if (isRunning()) throw new IllegalStateException("Scanner started"); - + _scanInterval = scanInterval; } @@ -326,14 +326,14 @@ public void setScanDirs(List dirs) /** * 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 void addFile(Path p) /** * 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 IncludeExcludeSet addDirectory(Path p) { if (isRunning()) throw new IllegalStateException("Scanner started"); - + if (p == null) throw new IllegalStateException("Null path"); @@ -379,7 +379,7 @@ public IncludeExcludeSet addDirectory(Path p) throw new IllegalStateException(e); } } - + /** * Apply a filter to files found in the scan directory. @@ -428,7 +428,7 @@ public void setScanDepth(int scanDepth) { if (isRunning()) throw new IllegalStateException("Scanner started"); - + _scanDepth = scanDepth; } @@ -500,7 +500,7 @@ public void doStart() throws Exception { 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 void doStart() throws Exception //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 boolean exists(String path) } /** - * 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 void nudge() 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 @@ void scan() private Map scanFiles() { Map currentScan = new HashMap<>(); - for (Path p : _scannables.keySet()) + for (Map.Entry> 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 @@ private Map scanFiles() /** * 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 @@ private void reportDifferences(Map currentScan, Map changes = new HashMap<>(); //Handle deleted files - Set oldScanKeys = new HashSet<>(oldScan.keySet()); + Set oldScanKeys = new HashSet<>(oldScan.keySet()); oldScanKeys.removeAll(currentScan.keySet()); for (String file : oldScanKeys) { @@ -671,10 +672,10 @@ private void reportDifferences(Map currentScan, Map 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 @@ else if (current.isModified(previous)) //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 @@ else if (previous._status == Status.CHANGED) if (LOG.isDebugEnabled()) LOG.debug("scanned {}", _scannables.keySet()); - //Call the DiscreteListeners + //Call the DiscreteListeners for (Map.Entry entry : changes.entrySet()) { switch (entry.getValue()) @@ -790,7 +791,7 @@ private void reportChange(String filename) { if (filename == null) return; - + for (Listener l : _listeners) { try @@ -807,14 +808,14 @@ private void reportChange(String filename) /** * Report the list of filenames for which changes were detected. - * + * * @param filenames names of all files added/changed/removed */ private void reportBulkChanges(Set filenames) { if (filenames == null || filenames.isEmpty()) return; - + for (Listener l : _listeners) { try @@ -831,7 +832,7 @@ private void reportBulkChanges(Set filenames) /** * Call ScanCycleListeners with start of scan - * + * * @param cycle scan count */ private void reportScanStart(int cycle) @@ -852,7 +853,7 @@ private void reportScanStart(int cycle) /** * Call ScanCycleListeners with end of scan. - * + * * @param cycle scan count */ private void reportScanEnd(int cycle) diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/FragmentConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/FragmentConfiguration.java index 9671ddecc9a7..8388fb1a695e 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/FragmentConfiguration.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/FragmentConfiguration.java @@ -57,16 +57,9 @@ public void addWebFragments(final WebAppContext context, final MetaData metaData Map frags = (Map)context.getAttribute(FRAGMENT_RESOURCES); if (frags != null) { - for (Resource key : frags.keySet()) + for (Map.Entry 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())); } } } diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaData.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaData.java index 4a5550a101b7..253a9399016d 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaData.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaData.java @@ -458,7 +458,7 @@ public void resolve(WebAppContext context) if (isOrdered()) { orderedWebInfJars = getWebInfResources(true); - List orderedLibs = new ArrayList(); + List orderedLibs = new ArrayList<>(); for (Resource webInfJar : orderedWebInfJars) { //get just the name of the jar file @@ -611,12 +611,12 @@ public FragmentDescriptor getFragmentDescriptor(Resource descriptorResource) */ public Resource getJarForFragmentName(String name) { - Resource jar = null; - FragmentDescriptor f = getFragmentDescriptor(name); if (f == null) return null; + Resource jar = null; + for (Map.Entry entry : _webFragmentResourceMap.entrySet()) { if (entry.getValue().equals(f)) diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlAppendable.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlAppendable.java index dbbf15ab5818..e217a166133c 100644 --- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlAppendable.java +++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlAppendable.java @@ -54,7 +54,7 @@ public XmlAppendable(Appendable out, int indent, String encoding) throws IOExcep { _out = out; _indent = indent; - _out.append("\n"); + _out.append("\n"); } public XmlAppendable openTag(String tag, Map attributes) throws IOException @@ -146,11 +146,10 @@ public XmlAppendable closeTag() throws IOException private void attributes(Map attributes) throws IOException { - for (String k : attributes.keySet()) + for (Map.Entry 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('"'); } } diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java index 90bc31d5eaaa..d34d9e131f5c 100644 --- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java +++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java @@ -1811,10 +1811,9 @@ else if (arg.toLowerCase(Locale.ENGLISH).endsWith(".properties")) if (properties.size() > 0) { Map 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); }