This is an automated email from the ASF dual-hosted git repository. jbonofre pushed a commit to branch karaf-4.2.x in repository https://gitbox.apache.org/repos/asf/karaf.git
The following commit(s) were added to refs/heads/karaf-4.2.x by this push: new 285d1d5 Code clean-up 285d1d5 is described below commit 285d1d5ca7075df0ff43f06878cf9441353feb6a Author: Stephen Kitt <sk...@redhat.com> AuthorDate: Fri Aug 21 11:31:02 2020 +0200 Code clean-up Mostly automated: * Remove unused imports * Use String.join() instead of streaming * Use List.sort() instead of Collections.sort() * Use switch instead of long if/else chains * Use removeIf() instead of looping * Optimise string construction * Avoid concatenating strings in calls to .append() * Avoid concatenating strings in loops * Use charset constants instead of Charset.forName() * Remove redundant instanceof null checks (instanceof checks for null itself, there's no need to explicitly check) Signed-off-by: Stephen Kitt <sk...@redhat.com> (cherry picked from commit aaf053c07e45cca5c42fa403a9e45de921e41074) --- .../org/apache/karaf/bundle/command/Watch.java | 8 +- .../java/org/apache/karaf/client/ClientConfig.java | 193 +++++++++++---------- .../main/java/org/apache/karaf/client/Main.java | 2 - .../apache/karaf/examples/itests/ExampleITest.java | 13 -- .../features/command/ListFeaturesCommand.java | 2 +- .../karaf/features/command/RegionInfoCommand.java | 2 +- .../download/impl/DownloadManagerHelper.java | 2 +- .../region/AbstractRegionDigraphVisitor.java | 10 +- .../features/internal/region/OfflineResolver.java | 2 +- .../internal/region/SubsystemResolver.java | 2 +- .../http/core/internal/ServletEventHandler.java | 9 +- .../http/core/internal/proxy/ProxyServlet.java | 1 - .../java/org/apache/karaf/itests/MavenTest.java | 5 +- .../karaf/itests/examples/JaasExampleTest.java | 3 - .../karaf/itests/examples/ServletExampleTest.java | 5 +- .../itests/features/Spring52FeaturesTest.java | 9 - .../karaf/jaas/command/ListGroupsCommand.java | 6 +- .../karaf/jaas/command/ListPendingCommand.java | 2 +- .../apache/karaf/jaas/modules/BackingEngine.java | 1 - .../modules/properties/AutoEncryptionSupport.java | 9 +- .../karaf/jaas/modules/ldap/LdapPropsUpdater.java | 5 +- .../modules/syncope/SyncopeLoginModuleTest.java | 3 +- .../log/core/internal/layout/PatternParser.java | 1 - .../karaf/log/core/internal/osgi/Activator.java | 1 - .../java/org/apache/karaf/main/InstanceHelper.java | 1 - .../karaf/management/KarafMBeanServerGuard.java | 26 +-- .../org/apache/karaf/profile/assembly/Builder.java | 8 +- .../karaf/profile/assembly/FakeBundleRevision.java | 64 +++---- .../apache/karaf/service/command/ListServices.java | 4 +- .../service/guard/impl/GuardProxyCatalog.java | 7 +- .../commands/basic/DefaultActionPreparator.java | 2 +- .../commands/basic/DefaultActionPreparator.java | 2 +- .../console/commands/NumberToStringConverter.java | 3 +- .../help/wikidoc/AnsiPrintingWikiVisitor.java | 7 +- .../console/commands/help/wikidoc/WikiParser.java | 41 +++-- .../java/org/apache/karaf/tooling/VerifyMojo.java | 64 +++---- .../karaf/webconsole/features/FeaturesPlugin.java | 2 +- .../karaf/webconsole/http/ServletEventHandler.java | 9 +- .../karaf/webconsole/instance/InstancePlugin.java | 16 +- 39 files changed, 264 insertions(+), 288 deletions(-) diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/command/Watch.java b/bundle/core/src/main/java/org/apache/karaf/bundle/command/Watch.java index 9203f59..2a914a6 100644 --- a/bundle/core/src/main/java/org/apache/karaf/bundle/command/Watch.java +++ b/bundle/core/src/main/java/org/apache/karaf/bundle/command/Watch.java @@ -89,17 +89,17 @@ public class Watch implements Action { } if (list) { //List the watched bundles. - String format = "%-40s %6s %-80s"; - System.out.println(String.format(format, "URL", "ID", "Bundle Name")); + String format = "%-40s %6s %-80s%n"; + System.out.printf(format, "URL", "ID", "Bundle Name"); for (String url : bundleWatcher.getWatchURLs()) { List<Bundle> bundleList = bundleWatcher.getBundlesByURL(url); if (bundleList != null && bundleList.size() > 0) { for (Bundle bundle : bundleList) { - System.out.println(String.format(format, url, bundle.getBundleId(), bundle.getHeaders().get(Constants.BUNDLE_NAME))); + System.out.printf(format, url, bundle.getBundleId(), bundle.getHeaders().get(Constants.BUNDLE_NAME)); } } else { - System.out.println(String.format(format, url, "", "")); + System.out.printf(format, url, "", ""); } } } else { diff --git a/client/src/main/java/org/apache/karaf/client/ClientConfig.java b/client/src/main/java/org/apache/karaf/client/ClientConfig.java index 8f57481..562ba1e 100644 --- a/client/src/main/java/org/apache/karaf/client/ClientConfig.java +++ b/client/src/main/java/org/apache/karaf/client/ClientConfig.java @@ -71,99 +71,114 @@ public class ClientConfig { for (int i = 0; i < args.length; i++) { if (!endOfOptionsMarkerReached && args[i].charAt(0) == '-') { - if (args[i].equals("-a")) { - if (args.length <= ++i) { - System.err.println("miss the port"); - System.exit(1); - } else { - port = Integer.parseInt(args[i]); - } - } else if (args[i].equals("-h")) { - if (args.length <= ++i) { - System.err.println("miss the host"); - System.exit(1); - } else { - host = args[i]; - } - } else if (args[i].equals("-u")) { - if (args.length <= ++i) { - System.err.println("miss the user"); - System.exit(1); - } else { - user = args[i]; - interactiveMode = true; - password = null;//get chance to input the password with interactive way - } - } else if (args[i].equals("-v")) { - level++; - } else if (args[i].equals("-l")) { - if (args.length <= ++i) { - System.err.println("miss the log level"); - System.exit(1); - } else { - int levelValue = Integer.parseInt(args[i]); - if (levelValue < 0 || levelValue > 4) { - System.err.println("log level can only be 0, 1, 2, 3, or 4"); + switch (args[i]) { + case "-a": + if (args.length <= ++i) { + System.err.println("miss the port"); System.exit(1); } else { - level = levelValue; + port = Integer.parseInt(args[i]); } - } - } else if (args[i].equals("-r")) { - if (args.length <= ++i) { - System.err.println("miss the attempts"); - System.exit(1); - } else { - retryAttempts = Integer.parseInt(args[i]); - } - - } else if (args[i].equals("-p")) { - if (args.length <= ++i) { - System.err.println("miss the password"); - System.exit(1); - } else { - password = args[i]; - interactiveMode = false; - inputPassword = true; - } - } else if (args[i].equals("-d")) { - if (args.length <= ++i) { - System.err.println("miss the delay in seconds"); - System.exit(1); - } else { - retryDelay = Integer.parseInt(args[i]); - } - } else if (args[i].equals("-b")) { - batch = true; - } else if (args[i].equals("-f")) { - if (args.length <= ++i) { - System.err.println("miss the commands file"); - System.exit(1); - } else { - file = args[i]; - } - } else if (args[i].equals("-k")) { - if (args.length <= ++i) { - System.err.println("miss the key file"); - System.exit(1); - } else { - keyFile = args[i]; - } - } else if (args[i].equals("-t")) { - if (args.length <= ++i) { - System.err.println("miss the idle timeout"); + break; + case "-h": + if (args.length <= ++i) { + System.err.println("miss the host"); + System.exit(1); + } else { + host = args[i]; + } + break; + case "-u": + if (args.length <= ++i) { + System.err.println("miss the user"); + System.exit(1); + } else { + user = args[i]; + interactiveMode = true; + password = null;//get chance to input the password with interactive way + } + break; + case "-v": + level++; + break; + case "-l": + if (args.length <= ++i) { + System.err.println("miss the log level"); + System.exit(1); + } else { + int levelValue = Integer.parseInt(args[i]); + if (levelValue < 0 || levelValue > 4) { + System.err.println("log level can only be 0, 1, 2, 3, or 4"); + System.exit(1); + } else { + level = levelValue; + } + } + break; + case "-r": + if (args.length <= ++i) { + System.err.println("miss the attempts"); + System.exit(1); + } else { + retryAttempts = Integer.parseInt(args[i]); + } + + break; + case "-p": + if (args.length <= ++i) { + System.err.println("miss the password"); + System.exit(1); + } else { + password = args[i]; + interactiveMode = false; + inputPassword = true; + } + break; + case "-d": + if (args.length <= ++i) { + System.err.println("miss the delay in seconds"); + System.exit(1); + } else { + retryDelay = Integer.parseInt(args[i]); + } + break; + case "-b": + batch = true; + break; + case "-f": + if (args.length <= ++i) { + System.err.println("miss the commands file"); + System.exit(1); + } else { + file = args[i]; + } + break; + case "-k": + if (args.length <= ++i) { + System.err.println("miss the key file"); + System.exit(1); + } else { + keyFile = args[i]; + } + break; + case "-t": + if (args.length <= ++i) { + System.err.println("miss the idle timeout"); + System.exit(1); + } else { + idleTimeout = Long.parseLong(args[i]); + } + break; + case "--help": + showHelp(); + break; + case "--": + endOfOptionsMarkerReached = true; + break; + default: + System.err.println("Unknown option: " + args[i]); + System.err.println("Run with --help for usage"); System.exit(1); - } else { - idleTimeout = Long.parseLong(args[i]); - } - } else if (args[i].equals("--help")) { - showHelp(); - } else if (args[i].equals("--")) { - endOfOptionsMarkerReached = true; - } else { - System.err.println("Unknown option: " + args[i]); - System.err.println("Run with --help for usage"); - System.exit(1); } } else { commandBuilder.append(args[i]); diff --git a/client/src/main/java/org/apache/karaf/client/Main.java b/client/src/main/java/org/apache/karaf/client/Main.java index eb8ea71..354c42e 100644 --- a/client/src/main/java/org/apache/karaf/client/Main.java +++ b/client/src/main/java/org/apache/karaf/client/Main.java @@ -18,12 +18,10 @@ package org.apache.karaf.client; import java.io.BufferedReader; import java.io.ByteArrayInputStream; -import java.io.Closeable; import java.io.Console; import java.io.FileInputStream; import java.io.IOError; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.io.ObjectInputStream; import java.io.Reader; diff --git a/examples/karaf-itest-example/src/test/java/org/apache/karaf/examples/itests/ExampleITest.java b/examples/karaf-itest-example/src/test/java/org/apache/karaf/examples/itests/ExampleITest.java index 16f8075..5d19bd1 100644 --- a/examples/karaf-itest-example/src/test/java/org/apache/karaf/examples/itests/ExampleITest.java +++ b/examples/karaf-itest-example/src/test/java/org/apache/karaf/examples/itests/ExampleITest.java @@ -19,23 +19,10 @@ import org.apache.karaf.itests.KarafTestSupport; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; -import org.ops4j.pax.exam.karaf.options.LogLevelOption; -import org.ops4j.pax.exam.options.MavenArtifactUrlReference; import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; import org.ops4j.pax.exam.spi.reactors.PerClass; -import java.io.File; - -import static org.ops4j.pax.exam.CoreOptions.maven; -import static org.ops4j.pax.exam.CoreOptions.mavenBundle; -import org.ops4j.pax.exam.karaf.container.internal.JavaVersionUtil; -import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.*; -import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut; -import org.ops4j.pax.exam.options.extra.VMOption; - @RunWith(PaxExam.class) @ExamReactorStrategy(PerClass.class) public class ExampleITest extends KarafTestSupport { diff --git a/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java b/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java index 9e17153..cc26e52 100644 --- a/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java +++ b/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java @@ -71,7 +71,7 @@ public class ListFeaturesCommand extends FeaturesCommandSupport { for (Repository r : repos) { List<Feature> features = Arrays.asList(r.getFeatures()); if (ordered) { - Collections.sort(features, new FeatureComparator()); + features.sort(new FeatureComparator()); } for (Feature f : features) { if (onlyInstalled && !featuresService.isInstalled(f)) { diff --git a/features/command/src/main/java/org/apache/karaf/features/command/RegionInfoCommand.java b/features/command/src/main/java/org/apache/karaf/features/command/RegionInfoCommand.java index d49ae03..c13b12b 100644 --- a/features/command/src/main/java/org/apache/karaf/features/command/RegionInfoCommand.java +++ b/features/command/src/main/java/org/apache/karaf/features/command/RegionInfoCommand.java @@ -86,7 +86,7 @@ public class RegionInfoCommand implements Action { if (verbose || bundles) { for (Long id : new TreeSet<>(region.getBundleIds())) { Bundle b = bundleContext.getBundle(id); - System.out.println(String.format(" %3d %s%s", id, getStateString(b), b)); + System.out.printf(" %3d %s%s%n", id, getStateString(b), b); } } if (verbose || filters || namespaces) { diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/download/impl/DownloadManagerHelper.java b/features/core/src/main/java/org/apache/karaf/features/internal/download/impl/DownloadManagerHelper.java index a3951ec..6504c06 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/download/impl/DownloadManagerHelper.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/download/impl/DownloadManagerHelper.java @@ -45,7 +45,7 @@ public final class DownloadManagerHelper { public static void setExtraProtocols( Collection<String> protocols ){ StringBuilder sb = new StringBuilder( DEFAULT_IGNORED_PROTOCOL_PATTERN ); for (String proto : protocols) { - sb.append( "|" + proto ); + sb.append("|").append(proto); } setIgnoredProtocolPattern(sb.toString()); diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/AbstractRegionDigraphVisitor.java b/features/core/src/main/java/org/apache/karaf/features/internal/region/AbstractRegionDigraphVisitor.java index 2165580..eae0f46 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/region/AbstractRegionDigraphVisitor.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/AbstractRegionDigraphVisitor.java @@ -21,9 +21,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Deque; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; - import org.eclipse.equinox.region.Region; import org.eclipse.equinox.region.RegionDigraphVisitor; import org.eclipse.equinox.region.RegionFilter; @@ -73,13 +71,7 @@ public abstract class AbstractRegionDigraphVisitor<C> implements RegionDigraphVi // remove any candidates contained in the current region candidates.removeAll(allowed); // apply the filter across remaining candidates - Iterator<C> i = candidates.iterator(); - while (i.hasNext()) { - C candidate = i.next(); - if (!isAllowed(candidate, regionFilter)) { - i.remove(); - } - } + candidates.removeIf(candidate -> !isAllowed(candidate, regionFilter)); if (candidates.isEmpty()) { return false; // this filter does not apply; avoid traversing this edge } diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/OfflineResolver.java b/features/core/src/main/java/org/apache/karaf/features/internal/region/OfflineResolver.java index eecb7a4..bea1b04 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/region/OfflineResolver.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/OfflineResolver.java @@ -112,7 +112,7 @@ public class OfflineResolver { } // Sort caps - Collections.sort(caps, candidateComparator); + caps.sort(candidateComparator); return caps; } diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java b/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java index aa0c31f..6019e63 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java @@ -130,7 +130,7 @@ public class SubsystemResolver implements SubsystemResolverResolution, Subsystem } Subsystem ss = root; for (int i = 1; i < parts.length; i++) { - String childName = Arrays.stream(Arrays.copyOfRange(parts, 0, i + 1)).collect(Collectors.joining("/")); + String childName = String.join("/", Arrays.copyOfRange(parts, 0, i + 1)); ss = getOrCreateChild(ss, childName, parts[i]); } for (String requirement : entry.getValue()) { diff --git a/http/src/main/java/org/apache/karaf/http/core/internal/ServletEventHandler.java b/http/src/main/java/org/apache/karaf/http/core/internal/ServletEventHandler.java index 479a0c5..de3bafb 100644 --- a/http/src/main/java/org/apache/karaf/http/core/internal/ServletEventHandler.java +++ b/http/src/main/java/org/apache/karaf/http/core/internal/ServletEventHandler.java @@ -18,7 +18,6 @@ package org.apache.karaf.http.core.internal; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -42,13 +41,7 @@ public class ServletEventHandler implements ServletListener { } public synchronized void removeEventsForBundle(Bundle bundle) { - Iterator<Map.Entry<String,ServletEvent>> iterator = servletEvents.entrySet().iterator(); - while (iterator.hasNext()) { - Map.Entry<String,ServletEvent> entry = iterator.next(); - if (entry.getValue().getBundle() == bundle) { - iterator.remove(); - } - } + servletEvents.entrySet().removeIf(entry -> entry.getValue().getBundle() == bundle); } } diff --git a/http/src/main/java/org/apache/karaf/http/core/internal/proxy/ProxyServlet.java b/http/src/main/java/org/apache/karaf/http/core/internal/proxy/ProxyServlet.java index 226a08e..9de76bb 100644 --- a/http/src/main/java/org/apache/karaf/http/core/internal/proxy/ProxyServlet.java +++ b/http/src/main/java/org/apache/karaf/http/core/internal/proxy/ProxyServlet.java @@ -52,7 +52,6 @@ import java.util.BitSet; import java.util.Enumeration; import java.util.Formatter; import java.util.List; -import java.util.Random; /** * This is a simple servlet acting as a HTTP reverse proxy/gateway. It works with any webcontainer as it's a regular servlet. diff --git a/itests/test/src/test/java/org/apache/karaf/itests/MavenTest.java b/itests/test/src/test/java/org/apache/karaf/itests/MavenTest.java index b7a8cd9..6147d35 100644 --- a/itests/test/src/test/java/org/apache/karaf/itests/MavenTest.java +++ b/itests/test/src/test/java/org/apache/karaf/itests/MavenTest.java @@ -19,6 +19,7 @@ package org.apache.karaf.itests; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Dictionary; import java.util.LinkedList; @@ -217,9 +218,9 @@ public class MavenTest /*extends BaseTest*/ { private void updateSettings() throws IOException { File settingsFile = new File(System.getProperty("karaf.home"), "etc/maven-settings.xml"); - String settings = FileUtils.readFileToString(settingsFile, Charset.forName("UTF-8")); + String settings = FileUtils.readFileToString(settingsFile, StandardCharsets.UTF_8); settings = settings.replace("@@port@@", Integer.toString(port)); - FileUtils.write(settingsFile, settings, Charset.forName("UTF-8")); + FileUtils.write(settingsFile, settings, StandardCharsets.UTF_8); } /** diff --git a/itests/test/src/test/java/org/apache/karaf/itests/examples/JaasExampleTest.java b/itests/test/src/test/java/org/apache/karaf/itests/examples/JaasExampleTest.java index da6a059..ec2671b 100644 --- a/itests/test/src/test/java/org/apache/karaf/itests/examples/JaasExampleTest.java +++ b/itests/test/src/test/java/org/apache/karaf/itests/examples/JaasExampleTest.java @@ -20,9 +20,6 @@ import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; import org.ops4j.pax.exam.spi.reactors.PerMethod; -import java.net.HttpURLConnection; -import java.net.URL; - @RunWith(PaxExam.class) @ExamReactorStrategy(PerMethod.class) public class JaasExampleTest extends BaseTest { diff --git a/itests/test/src/test/java/org/apache/karaf/itests/examples/ServletExampleTest.java b/itests/test/src/test/java/org/apache/karaf/itests/examples/ServletExampleTest.java index 27c541a..f4568a2 100644 --- a/itests/test/src/test/java/org/apache/karaf/itests/examples/ServletExampleTest.java +++ b/itests/test/src/test/java/org/apache/karaf/itests/examples/ServletExampleTest.java @@ -27,7 +27,6 @@ import org.ops4j.pax.exam.spi.reactors.PerMethod; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.FileWriter; import java.io.InputStreamReader; import java.io.OutputStream; @@ -136,7 +135,7 @@ public class ServletExampleTest extends BaseTest { OutputStream outputStream = connection.getOutputStream(); PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream), true); - writer.append("--" + boundary).append("\r\n"); + writer.append("--").append(boundary).append("\r\n"); writer.append("Content-Disposition: form-data; name=\"test\"; filename=\"test.txt\"").append("\r\n"); writer.append("Content-Type: text/plain; charset=UTF-8").append("\r\n"); writer.append("Content-Transfer-Encoding: binary").append("\r\n"); @@ -153,7 +152,7 @@ public class ServletExampleTest extends BaseTest { fileInputStream.close(); writer.append("\r\n"); writer.append("\r\n"); - writer.append("--" + boundary + "--").append("\r\n"); + writer.append("--").append(boundary).append("--").append("\r\n"); writer.flush(); writer.close(); diff --git a/itests/test/src/test/java/org/apache/karaf/itests/features/Spring52FeaturesTest.java b/itests/test/src/test/java/org/apache/karaf/itests/features/Spring52FeaturesTest.java index 74fb762..a3ac7bb 100644 --- a/itests/test/src/test/java/org/apache/karaf/itests/features/Spring52FeaturesTest.java +++ b/itests/test/src/test/java/org/apache/karaf/itests/features/Spring52FeaturesTest.java @@ -16,19 +16,10 @@ package org.apache.karaf.itests.features; import org.apache.karaf.itests.BaseTest; import org.junit.Test; import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.MavenUtils; -import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; import org.ops4j.pax.exam.spi.reactors.PerClass; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut; - @RunWith(PaxExam.class) @ExamReactorStrategy(PerClass.class) public class Spring52FeaturesTest extends BaseTest { diff --git a/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListGroupsCommand.java b/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListGroupsCommand.java index 3c04963..8638463 100644 --- a/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListGroupsCommand.java +++ b/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListGroupsCommand.java @@ -27,7 +27,7 @@ import org.apache.karaf.shell.api.action.lifecycle.Service; @Service public class ListGroupsCommand extends JaasCommandSupport { - private static final String GROUP_LIST_FORMAT = "%-10s %-80s"; + private static final String GROUP_LIST_FORMAT = "%-10s %-80s%n"; @Override @@ -52,11 +52,11 @@ public class ListGroupsCommand extends JaasCommandSupport { @Override protected Object doExecute(BackingEngine engine) throws Exception { - System.out.println(String.format(GROUP_LIST_FORMAT, "Group", "Roles")); + System.out.printf(GROUP_LIST_FORMAT, "Group", "Roles"); for (GroupPrincipal group : engine.listGroups().keySet()) { - System.out.println(String.format(GROUP_LIST_FORMAT, group.getName(), engine.listGroups().get(group))); + System.out.printf(GROUP_LIST_FORMAT, group.getName(), engine.listGroups().get(group)); } return null; } diff --git a/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListPendingCommand.java b/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListPendingCommand.java index 51a8d40..3382069 100644 --- a/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListPendingCommand.java +++ b/jaas/command/src/main/java/org/apache/karaf/jaas/command/ListPendingCommand.java @@ -38,7 +38,7 @@ public class ListPendingCommand extends JaasCommandSupport { if (realm != null && entry != null) { String moduleClass = (String) entry.getOptions().get(ProxyLoginModule.PROPERTY_MODULE); - System.out.println(String.format("JAAS Realm %s/JAAS Login Module %s", realm.getName(), moduleClass)); + System.out.printf("JAAS Realm %s/JAAS Login Module %s%n", realm.getName(), moduleClass); if (commandQueue != null && !commandQueue.isEmpty()) { for (JaasCommandSupport command : commandQueue) { diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/BackingEngine.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/BackingEngine.java index fa9ea1f..b5d7275 100644 --- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/BackingEngine.java +++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/BackingEngine.java @@ -21,7 +21,6 @@ import java.util.Map; import org.apache.karaf.jaas.boot.principal.GroupPrincipal; import org.apache.karaf.jaas.boot.principal.RolePrincipal; import org.apache.karaf.jaas.boot.principal.UserPrincipal; -import org.apache.karaf.jaas.config.impl.Module; public interface BackingEngine { diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/AutoEncryptionSupport.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/AutoEncryptionSupport.java index 4ac608c..a1fc239 100644 --- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/AutoEncryptionSupport.java +++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/AutoEncryptionSupport.java @@ -138,14 +138,11 @@ public class AutoEncryptionSupport implements Runnable, Closeable { String encryptedPassword = encryptionSupport.encrypt(storedPassword); if (!storedPassword.equals(encryptedPassword)) { LOGGER.debug("The password isn't flagged as encrypted, encrypt it."); - userInfos = encryptedPassword + ","; + StringBuilder userInfosBuilder = new StringBuilder(encryptedPassword); for (int i = 1; i < infos.length; i++) { - if (i == (infos.length - 1)) { - userInfos = userInfos + infos[i]; - } else { - userInfos = userInfos + infos[i] + ","; - } + userInfosBuilder.append(',').append(infos[i]); } + userInfos = userInfosBuilder.toString(); if (user.contains("\\")) { users.remove(user); user = user.replace("\\", "\\\\"); diff --git a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapPropsUpdater.java b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapPropsUpdater.java index 8bf9059..2ad091f 100644 --- a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapPropsUpdater.java +++ b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapPropsUpdater.java @@ -18,6 +18,7 @@ package org.apache.karaf.jaas.modules.ldap; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; @@ -35,11 +36,11 @@ public class LdapPropsUpdater { basedir = new File(".").getCanonicalPath(); } Path inPath = new File(basedir + "/src/test/resources/" + propsPath).toPath(); - List<String> lines = Files.lines(inPath, Charset.forName("UTF-8")) + List<String> lines = Files.lines(inPath, StandardCharsets.UTF_8) .map(mapFunction) .collect(Collectors.toList()); Path outPath = new File(basedir + "/target/test-classes/" + propsPath).toPath(); - Files.write(outPath, lines, Charset.forName("UTF-8")); + Files.write(outPath, lines, StandardCharsets.UTF_8); } } diff --git a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/syncope/SyncopeLoginModuleTest.java b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/syncope/SyncopeLoginModuleTest.java index 5e62df5..cc1234c 100644 --- a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/syncope/SyncopeLoginModuleTest.java +++ b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/syncope/SyncopeLoginModuleTest.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Collections; @@ -62,7 +63,7 @@ public class SyncopeLoginModuleTest { private String read(String resourceName) throws URISyntaxException, IOException { URI response = this.getClass().getResource(resourceName).toURI(); - return Files.lines(Paths.get(response), Charset.forName("UTF-8")) + return Files.lines(Paths.get(response), StandardCharsets.UTF_8) .collect(Collectors.joining("\n")); } diff --git a/log/src/main/java/org/apache/karaf/log/core/internal/layout/PatternParser.java b/log/src/main/java/org/apache/karaf/log/core/internal/layout/PatternParser.java index b69fa1d..85979a8 100644 --- a/log/src/main/java/org/apache/karaf/log/core/internal/layout/PatternParser.java +++ b/log/src/main/java/org/apache/karaf/log/core/internal/layout/PatternParser.java @@ -25,7 +25,6 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; -import org.ops4j.pax.logging.PaxLogger; import org.ops4j.pax.logging.spi.PaxLocationInfo; import org.ops4j.pax.logging.spi.PaxLoggingEvent; diff --git a/log/src/main/java/org/apache/karaf/log/core/internal/osgi/Activator.java b/log/src/main/java/org/apache/karaf/log/core/internal/osgi/Activator.java index f47b456..038b296 100644 --- a/log/src/main/java/org/apache/karaf/log/core/internal/osgi/Activator.java +++ b/log/src/main/java/org/apache/karaf/log/core/internal/osgi/Activator.java @@ -28,7 +28,6 @@ import org.apache.karaf.util.tracker.annotation.Managed; import org.apache.karaf.util.tracker.annotation.ProvideService; import org.apache.karaf.util.tracker.annotation.RequireService; import org.apache.karaf.util.tracker.annotation.Services; -import org.ops4j.pax.logging.PaxLogger; import org.ops4j.pax.logging.spi.PaxAppender; import org.osgi.service.cm.ConfigurationAdmin; import org.osgi.service.cm.ManagedService; diff --git a/main/src/main/java/org/apache/karaf/main/InstanceHelper.java b/main/src/main/java/org/apache/karaf/main/InstanceHelper.java index 2f70a3e..31688fc 100644 --- a/main/src/main/java/org/apache/karaf/main/InstanceHelper.java +++ b/main/src/main/java/org/apache/karaf/main/InstanceHelper.java @@ -31,7 +31,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.felix.utils.properties.Properties; -import org.apache.felix.utils.properties.TypedProperties; import org.apache.karaf.util.locks.FileLockUtils; import org.osgi.framework.launch.Framework; diff --git a/management/server/src/main/java/org/apache/karaf/management/KarafMBeanServerGuard.java b/management/server/src/main/java/org/apache/karaf/management/KarafMBeanServerGuard.java index a1527cb..abed459 100644 --- a/management/server/src/main/java/org/apache/karaf/management/KarafMBeanServerGuard.java +++ b/management/server/src/main/java/org/apache/karaf/management/KarafMBeanServerGuard.java @@ -98,16 +98,22 @@ public class KarafMBeanServerGuard implements InvocationHandler { } ObjectName objectName = (ObjectName) args[0]; - if ("getAttribute".equals(method.getName())) { - handleGetAttribute(mbs, objectName, (String) args[1]); - } else if ("getAttributes".equals(method.getName())) { - handleGetAttributes(mbs, objectName, (String[]) args[1]); - } else if ("setAttribute".equals(method.getName())) { - handleSetAttribute(mbs, objectName, (Attribute) args[1]); - } else if ("setAttributes".equals(method.getName())) { - handleSetAttributes(mbs, objectName, (AttributeList) args[1]); - } else if ("invoke".equals(method.getName())) { - handleInvoke(mbs, objectName, (String) args[1], (Object[]) args[2], (String[]) args[3]); + switch (method.getName()) { + case "getAttribute": + handleGetAttribute(mbs, objectName, (String) args[1]); + break; + case "getAttributes": + handleGetAttributes(mbs, objectName, (String[]) args[1]); + break; + case "setAttribute": + handleSetAttribute(mbs, objectName, (Attribute) args[1]); + break; + case "setAttributes": + handleSetAttributes(mbs, objectName, (AttributeList) args[1]); + break; + case "invoke": + handleInvoke(mbs, objectName, (String) args[1], (Object[]) args[2], (String[]) args[3]); + break; } return null; diff --git a/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java b/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java index e05d93e..060d57a 100644 --- a/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java +++ b/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java @@ -923,7 +923,7 @@ public class Builder { allProfiles = loadExternalProfiles(profilesUris); if (allProfiles.size() > 0) { StringBuilder sb = new StringBuilder(); - LOGGER.info(" Found profiles: " + allProfiles.keySet().stream().collect(Collectors.joining(", "))); + LOGGER.info(" Found profiles: " + String.join(", ", allProfiles.keySet())); } // Generate initial profile to collect overrides and blacklisting instructions @@ -1954,8 +1954,8 @@ public class Builder { // Resolve // LOGGER.info(" Resolving startup features and bundles"); - LOGGER.info(" Features: " + startupEffective.getFeatures().stream().collect(Collectors.joining(", "))); - LOGGER.info(" Bundles: " + startupEffective.getBundles().stream().collect(Collectors.joining(", "))); + LOGGER.info(" Features: " + String.join(", ", startupEffective.getFeatures())); + LOGGER.info(" Bundles: " + String.join(", ", startupEffective.getBundles())); Map<String, Integer> bundles = resolve(manager, @@ -2094,7 +2094,7 @@ public class Builder { if (stagedParentProfiles.isEmpty()) { LOGGER.info("Generating {} profile", name); } else { - LOGGER.info("Generating {} profile with parents: {}", name, stagedParentProfiles.stream().collect(Collectors.joining(", "))); + LOGGER.info("Generating {} profile with parents: {}", name, String.join(", ", stagedParentProfiles)); } return ProfileBuilder.Factory.create(name) diff --git a/profile/src/main/java/org/apache/karaf/profile/assembly/FakeBundleRevision.java b/profile/src/main/java/org/apache/karaf/profile/assembly/FakeBundleRevision.java index 95b805b..24385ef 100644 --- a/profile/src/main/java/org/apache/karaf/profile/assembly/FakeBundleRevision.java +++ b/profile/src/main/java/org/apache/karaf/profile/assembly/FakeBundleRevision.java @@ -119,37 +119,39 @@ public class FakeBundleRevision extends ResourceImpl implements BundleRevision, @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - if (method.getName().equals("hashCode")) { - return FakeBundleRevision.this.hashCode(); - } else if (method.getName().equals("equals")) { - return proxy == args[0]; - } else if (method.getName().equals("toString")) { - return bundle.getSymbolicName() + "/" + bundle.getVersion(); - } else if (method.getName().equals("adapt")) { - if (args.length == 1 && args[0] == BundleRevision.class) { - return FakeBundleRevision.this; - } else if (args.length == 1 && args[0] == BundleStartLevel.class) { - return FakeBundleRevision.this; - } - } else if (method.getName().equals("getHeaders")) { - return headers; - } else if (method.getName().equals("getBundleId")) { - return bundleId; - } else if (method.getName().equals("getLocation")) { - return location; - } else if (method.getName().equals("getSymbolicName")) { - String name = headers.get(Constants.BUNDLE_SYMBOLICNAME); - int idx = name.indexOf(';'); - if (idx > 0) { - name = name.substring(0, idx).trim(); - } - return name; - } else if (method.getName().equals("getVersion")) { - return new Version(headers.get(Constants.BUNDLE_VERSION)); - } else if (method.getName().equals("getState")) { - return Bundle.ACTIVE; - } else if (method.getName().equals("getLastModified")) { - return 0l; + switch (method.getName()) { + case "hashCode": + return FakeBundleRevision.this.hashCode(); + case "equals": + return proxy == args[0]; + case "toString": + return bundle.getSymbolicName() + "/" + bundle.getVersion(); + case "adapt": + if (args.length == 1 && args[0] == BundleRevision.class) { + return FakeBundleRevision.this; + } else if (args.length == 1 && args[0] == BundleStartLevel.class) { + return FakeBundleRevision.this; + } + break; + case "getHeaders": + return headers; + case "getBundleId": + return bundleId; + case "getLocation": + return location; + case "getSymbolicName": + String name = headers.get(Constants.BUNDLE_SYMBOLICNAME); + int idx = name.indexOf(';'); + if (idx > 0) { + name = name.substring(0, idx).trim(); + } + return name; + case "getVersion": + return new Version(headers.get(Constants.BUNDLE_VERSION)); + case "getState": + return Bundle.ACTIVE; + case "getLastModified": + return 0l; } return null; } diff --git a/service/core/src/main/java/org/apache/karaf/service/command/ListServices.java b/service/core/src/main/java/org/apache/karaf/service/command/ListServices.java index 46e5a5d..365c5c9 100644 --- a/service/core/src/main/java/org/apache/karaf/service/command/ListServices.java +++ b/service/core/src/main/java/org/apache/karaf/service/command/ListServices.java @@ -74,7 +74,7 @@ public class ListServices implements Action { } } - Collections.sort(serviceRefs, new ServiceClassComparator()); + serviceRefs.sort(new ServiceClassComparator()); for (ServiceReference<?> serviceRef : serviceRefs) { if (showAll || !isCommand((String[])serviceRef.getProperty(Constants.OBJECTCLASS))) { @@ -160,7 +160,7 @@ public class ListServices implements Action { private String getObjectClass(ServiceReference<?> o1) { Object value = o1.getProperty(Constants.OBJECTCLASS); - if (value == null || !(value instanceof String[])) { + if (!(value instanceof String[])) { return ""; } String[] values = (String[]) value; diff --git a/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java b/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java index 3be00bc..1e12133 100644 --- a/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java +++ b/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java @@ -169,12 +169,7 @@ public class GuardProxyCatalog implements ServiceListener { private void handleOriginalServiceUnregistering(Long orgServiceID) { // If the service queued up to be proxied, remove it. - for (Iterator<CreateProxyRunnable> i = createProxyQueue.iterator(); i.hasNext(); ) { - CreateProxyRunnable cpr = i.next(); - if (orgServiceID.equals(cpr.getOriginalServiceID())) { - i.remove(); - } - } + createProxyQueue.removeIf(cpr -> orgServiceID.equals(cpr.getOriginalServiceID())); ServiceRegistrationHolder holder = proxyMap.remove(orgServiceID); if (holder != null) { diff --git a/shell/console/src/main/java/org/apache/felix/gogo/commands/basic/DefaultActionPreparator.java b/shell/console/src/main/java/org/apache/felix/gogo/commands/basic/DefaultActionPreparator.java index 7090814..ea436c6 100644 --- a/shell/console/src/main/java/org/apache/felix/gogo/commands/basic/DefaultActionPreparator.java +++ b/shell/console/src/main/java/org/apache/felix/gogo/commands/basic/DefaultActionPreparator.java @@ -557,6 +557,6 @@ public class DefaultActionPreparator implements ActionPreparator { private int getWidth(CommandSession session) { Object cols = session.get("COLUMNS"); - return (cols != null && cols instanceof Integer) ? (Integer)cols : 80; + return cols instanceof Integer ? (Integer)cols : 80; } } diff --git a/shell/console/src/main/java/org/apache/karaf/shell/commands/basic/DefaultActionPreparator.java b/shell/console/src/main/java/org/apache/karaf/shell/commands/basic/DefaultActionPreparator.java index 92639a9..4fa084b 100644 --- a/shell/console/src/main/java/org/apache/karaf/shell/commands/basic/DefaultActionPreparator.java +++ b/shell/console/src/main/java/org/apache/karaf/shell/commands/basic/DefaultActionPreparator.java @@ -218,6 +218,6 @@ public class DefaultActionPreparator implements ActionPreparator { private int getWidth(CommandSession session) { Object cols = session.get("COLUMNS"); - return (cols != null && cols instanceof Integer) ? (Integer)cols : 80; + return cols instanceof Integer ? (Integer)cols : 80; } } diff --git a/shell/console/src/main/java/org/apache/karaf/shell/console/commands/NumberToStringConverter.java b/shell/console/src/main/java/org/apache/karaf/shell/console/commands/NumberToStringConverter.java index 42b25f3..9c4faa1 100644 --- a/shell/console/src/main/java/org/apache/karaf/shell/console/commands/NumberToStringConverter.java +++ b/shell/console/src/main/java/org/apache/karaf/shell/console/commands/NumberToStringConverter.java @@ -26,8 +26,7 @@ public class NumberToStringConverter implements Converter { @Override public boolean canConvert(Object sourceObject, ReifiedType targetType) { - return sourceObject != null && sourceObject instanceof Number - && targetType.getRawClass() == String.class; + return sourceObject instanceof Number && targetType.getRawClass() == String.class; } @Override diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/commands/help/wikidoc/AnsiPrintingWikiVisitor.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/commands/help/wikidoc/AnsiPrintingWikiVisitor.java index 79f0fbe..b18db35 100644 --- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/commands/help/wikidoc/AnsiPrintingWikiVisitor.java +++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/commands/help/wikidoc/AnsiPrintingWikiVisitor.java @@ -38,10 +38,11 @@ public class AnsiPrintingWikiVisitor implements WikiVisitor { @Override public void startPara(int size) { - indent = ""; - while (size-- > 0) { - indent += " "; + StringBuilder indentBuilder = new StringBuilder(); + for (int i = 0; i < size; i++) { + indentBuilder.append(' '); } + indent = indentBuilder.toString(); } @Override diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/commands/help/wikidoc/WikiParser.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/commands/help/wikidoc/WikiParser.java index 7ac02c4..f4e426b 100644 --- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/commands/help/wikidoc/WikiParser.java +++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/commands/help/wikidoc/WikiParser.java @@ -54,13 +54,13 @@ public class WikiParser { if (first) { first = false; int tabs = 0; + StringBuilder prefix = new StringBuilder(); for (int i = 0; i < token.length() && token.charAt(i) == '\t'; i++) { tabs++; + prefix.append(" "); } - token = token.substring(tabs); - for (int i = 0; i < tabs; i++) { - token = " " + token; - } + prefix.append(token.substring(tabs)); + token = prefix.toString(); int i = 0; while (i < token.length() && token.charAt(i) == ' ') { i++; @@ -68,19 +68,26 @@ public class WikiParser { visitor.startPara(i); token = token.substring(i); } - if ("\u001B".equals(token)) { - parseEsc(tokenizer, token); - } else if ("[".equals(token)) { - parseLink(tokenizer); - } else if ("h".equals(token)) { - parseHeading(tokenizer); - } else if ("*".equals(token)) { - parseEnumeration(tokenizer); - } else if ("**".equals(token)) { - bold = !bold; - visitor.bold(bold); - } else { - visitor.text(token); + switch (token) { + case "\u001B": + parseEsc(tokenizer, token); + break; + case "[": + parseLink(tokenizer); + break; + case "h": + parseHeading(tokenizer); + break; + case "*": + parseEnumeration(tokenizer); + break; + case "**": + bold = !bold; + visitor.bold(bold); + break; + default: + visitor.text(token); + break; } } if (first) { diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java index c4aabec..fecdd27 100644 --- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java +++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java @@ -691,37 +691,39 @@ public class VerifyMojo extends MojoSupport { new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) { - if (method.getName().equals("hashCode")) { - return FakeBundleRevision.this.hashCode(); - } else if (method.getName().equals("equals")) { - return proxy == args[0]; - } else if (method.getName().equals("toString")) { - return bundle.getSymbolicName() + "/" + bundle.getVersion(); - } else if (method.getName().equals("adapt")) { - if (args.length == 1 && args[0] == BundleRevision.class) { - return FakeBundleRevision.this; - } else if (args.length == 1 && args[0] == BundleStartLevel.class) { - return FakeBundleRevision.this; - } - } else if (method.getName().equals("getHeaders")) { - return headers; - } else if (method.getName().equals("getBundleId")) { - return bundleId; - } else if (method.getName().equals("getLocation")) { - return location; - } else if (method.getName().equals("getSymbolicName")) { - String name = headers.get(Constants.BUNDLE_SYMBOLICNAME); - int idx = name.indexOf(';'); - if (idx > 0) { - name = name.substring(0, idx).trim(); - } - return name; - } else if (method.getName().equals("getVersion")) { - return new Version(headers.get(Constants.BUNDLE_VERSION)); - } else if (method.getName().equals("getState")) { - return Bundle.ACTIVE; - } else if (method.getName().equals("getLastModified")) { - return 0l; + switch (method.getName()) { + case "hashCode": + return FakeBundleRevision.this.hashCode(); + case "equals": + return proxy == args[0]; + case "toString": + return bundle.getSymbolicName() + "/" + bundle.getVersion(); + case "adapt": + if (args.length == 1 && args[0] == BundleRevision.class) { + return FakeBundleRevision.this; + } else if (args.length == 1 && args[0] == BundleStartLevel.class) { + return FakeBundleRevision.this; + } + break; + case "getHeaders": + return headers; + case "getBundleId": + return bundleId; + case "getLocation": + return location; + case "getSymbolicName": + String name = headers.get(Constants.BUNDLE_SYMBOLICNAME); + int idx = name.indexOf(';'); + if (idx > 0) { + name = name.substring(0, idx).trim(); + } + return name; + case "getVersion": + return new Version(headers.get(Constants.BUNDLE_VERSION)); + case "getState": + return Bundle.ACTIVE; + case "getLastModified": + return 0l; } return null; } diff --git a/webconsole/features/src/main/java/org/apache/karaf/webconsole/features/FeaturesPlugin.java b/webconsole/features/src/main/java/org/apache/karaf/webconsole/features/FeaturesPlugin.java index 820a82e..287ddec 100644 --- a/webconsole/features/src/main/java/org/apache/karaf/webconsole/features/FeaturesPlugin.java +++ b/webconsole/features/src/main/java/org/apache/karaf/webconsole/features/FeaturesPlugin.java @@ -340,7 +340,7 @@ public class FeaturesPlugin extends AbstractWebConsolePlugin { this.log.error(e.getMessage()); } - Collections.sort(features, new ExtendedFeatureComparator()); + features.sort(new ExtendedFeatureComparator()); return features; } diff --git a/webconsole/http/src/main/java/org/apache/karaf/webconsole/http/ServletEventHandler.java b/webconsole/http/src/main/java/org/apache/karaf/webconsole/http/ServletEventHandler.java index 0702bae..f27dc04 100644 --- a/webconsole/http/src/main/java/org/apache/karaf/webconsole/http/ServletEventHandler.java +++ b/webconsole/http/src/main/java/org/apache/karaf/webconsole/http/ServletEventHandler.java @@ -19,7 +19,6 @@ package org.apache.karaf.webconsole.http; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import org.ops4j.pax.web.service.spi.ServletEvent; @@ -67,13 +66,7 @@ public class ServletEventHandler implements ServletListener, BundleListener { } public synchronized void removeEventsForBundle(Bundle bundle) { - Iterator<Map.Entry<String,ServletEvent>> iterator = servletEvents.entrySet().iterator(); - while (iterator.hasNext()) { - Map.Entry<String,ServletEvent> entry = iterator.next(); - if (entry.getValue().getBundle() == bundle) { - iterator.remove(); - } - } + servletEvents.entrySet().removeIf(entry -> entry.getValue().getBundle() == bundle); } } diff --git a/webconsole/instance/src/main/java/org/apache/karaf/webconsole/instance/InstancePlugin.java b/webconsole/instance/src/main/java/org/apache/karaf/webconsole/instance/InstancePlugin.java index bd73cb6..9d0ba59 100644 --- a/webconsole/instance/src/main/java/org/apache/karaf/webconsole/instance/InstancePlugin.java +++ b/webconsole/instance/src/main/java/org/apache/karaf/webconsole/instance/InstancePlugin.java @@ -275,12 +275,16 @@ public class InstancePlugin extends AbstractWebConsolePlugin { int started = 0, starting = 0, stopped = 0; for (Instance instance : instances) { try { - if (instance.getState().equals(Instance.STARTED)) { - started++; - } else if (instance.getState().equals(Instance.STARTING)) { - starting++; - } else if (instance.getState().equals(Instance.STOPPED)) { - stopped++; + switch (instance.getState()) { + case Instance.STARTED: + started++; + break; + case Instance.STARTING: + starting++; + break; + case Instance.STOPPED: + stopped++; + break; } } catch (Exception ex) { Logger.getLogger(InstancePlugin.class.getName()).log(Level.SEVERE, null, ex);