diff --git a/api/src/main/java/org/jboss/shrinkwrap/resolver/api/Invokable.java b/api/src/main/java/org/jboss/shrinkwrap/resolver/api/Invokable.java index 18e92a930..37962d730 100644 --- a/api/src/main/java/org/jboss/shrinkwrap/resolver/api/Invokable.java +++ b/api/src/main/java/org/jboss/shrinkwrap/resolver/api/Invokable.java @@ -98,19 +98,8 @@ Object invokeMethod(String name, Class[] parameterTypes, Object instance, Obj throws InvocationException { try { return findMethod(name, parameterTypes).invoke(instance, parameters); - } catch (IllegalAccessException e) { - throw new InvocationException(e, "Unable to invoke {0}({1}) on object {2} with parameters {3}", name, - parameterTypes, instance == null ? "" : instance.getClass().getName(), parameters); - } catch (IllegalArgumentException e) { - throw new InvocationException(e, "Unable to invoke {0}({1}) on object {2} with parameters {3}", name, - parameterTypes, instance == null ? "" : instance.getClass().getName(), parameters); - } catch (InvocationTargetException e) { - throw new InvocationException(e, "Unable to invoke {0}({1}) on object {2} with parameters {3}", name, - parameterTypes, instance == null ? "" : instance.getClass().getName(), parameters); - } catch (SecurityException e) { - throw new InvocationException(e, "Unable to invoke {0}({1}) on object {2} with parameters {3}", name, - parameterTypes, instance == null ? "" : instance.getClass().getName(), parameters); - } catch (InvocationException e) { + } catch (IllegalAccessException | InvocationException | SecurityException | InvocationTargetException | + IllegalArgumentException e) { throw new InvocationException(e, "Unable to invoke {0}({1}) on object {2} with parameters {3}", name, parameterTypes, instance == null ? "" : instance.getClass().getName(), parameters); } @@ -129,27 +118,8 @@ Object invokeConstructor(Class[] parameterTypes, Object[] parameters) throws try { Constructor con = classType.getConstructor(parameterTypes); return con.newInstance(parameters); - } catch (NoSuchMethodException e) { - throw new InvocationException(e, "Unable to invoke constructor {0}({1}) with parameters {3}", - classType.getSimpleName(), - parameterTypes, parameters); - } catch (SecurityException e) { - throw new InvocationException(e, "Unable to invoke constructor {0}({1}) with parameters {3}", - classType.getSimpleName(), - parameterTypes, parameters); - } catch (InstantiationException e) { - throw new InvocationException(e, "Unable to invoke constructor {0}({1}) with parameters {3}", - classType.getSimpleName(), - parameterTypes, parameters); - } catch (IllegalAccessException e) { - throw new InvocationException(e, "Unable to invoke constructor {0}({1}) with parameters {3}", - classType.getSimpleName(), - parameterTypes, parameters); - } catch (IllegalArgumentException e) { - throw new InvocationException(e, "Unable to invoke constructor {0}({1}) with parameters {3}", - classType.getSimpleName(), - parameterTypes, parameters); - } catch (InvocationTargetException e) { + } catch (NoSuchMethodException | InvocationTargetException | IllegalArgumentException | IllegalAccessException | + InstantiationException | SecurityException e) { throw new InvocationException(e, "Unable to invoke constructor {0}({1}) with parameters {3}", classType.getSimpleName(), parameterTypes, parameters); diff --git a/gradle/impl-gradle-embedded-archive/src/main/java/org/jboss/shrinkwrap/impl/gradle/archive/importer/embedded/EmbeddedGradleImporterImpl.java b/gradle/impl-gradle-embedded-archive/src/main/java/org/jboss/shrinkwrap/impl/gradle/archive/importer/embedded/EmbeddedGradleImporterImpl.java index f62895ab9..97644d425 100644 --- a/gradle/impl-gradle-embedded-archive/src/main/java/org/jboss/shrinkwrap/impl/gradle/archive/importer/embedded/EmbeddedGradleImporterImpl.java +++ b/gradle/impl-gradle-embedded-archive/src/main/java/org/jboss/shrinkwrap/impl/gradle/archive/importer/embedded/EmbeddedGradleImporterImpl.java @@ -18,7 +18,6 @@ package org.jboss.shrinkwrap.impl.gradle.archive.importer.embedded; import java.io.File; -import java.io.FilenameFilter; import java.net.URI; import org.gradle.tooling.BuildLauncher; @@ -112,12 +111,7 @@ private File importFromDefaultLibsDirectory() { final GradleProject currentGradleProject = findCurrentGradleProject(); final File buildDir = currentGradleProject.getBuildDirectory(); final File libsDir = new File(buildDir, "libs"); - final File[] results = libsDir.listFiles(new FilenameFilter() { - @Override - public boolean accept(final File dir, final String name) { - return name.startsWith(currentGradleProject.getName()); - } - }); + final File[] results = libsDir.listFiles((dir, name) -> name.startsWith(currentGradleProject.getName())); if (results == null || results.length == 0) { throw new IllegalArgumentException( diff --git a/gradle/impl-gradle-embedded-archive/src/test/java/org/jboss/shrinkwrap/impl/gradle/archive/importer/embedded/AssertArchive.java b/gradle/impl-gradle-embedded-archive/src/test/java/org/jboss/shrinkwrap/impl/gradle/archive/importer/embedded/AssertArchive.java index a5c96c746..a4229526a 100644 --- a/gradle/impl-gradle-embedded-archive/src/test/java/org/jboss/shrinkwrap/impl/gradle/archive/importer/embedded/AssertArchive.java +++ b/gradle/impl-gradle-embedded-archive/src/test/java/org/jboss/shrinkwrap/impl/gradle/archive/importer/embedded/AssertArchive.java @@ -28,12 +28,12 @@ private AssertArchive() { throw new UnsupportedOperationException("Utils class"); } - public static void assertContains(Archive archive, String path) { + public static void assertContains(Archive archive, String path) { assertThat(archive.contains(path)).as(path + " should be included in archive " + archive.toString(true)) .isTrue(); } - public static void assertNotContains(Archive archive, String path) { + public static void assertNotContains(Archive archive, String path) { assertThat(archive.contains(path)).as(path + " should NOT be included in archive " + archive.toString(true)) .isFalse(); } diff --git a/gradle/impl-gradle/src/main/java/org/jboss/shrinkwrap/resolver/impl/gradle/GradleEffectiveDependencies.java b/gradle/impl-gradle/src/main/java/org/jboss/shrinkwrap/resolver/impl/gradle/GradleEffectiveDependencies.java index 2e34fefc6..568b9bbd8 100644 --- a/gradle/impl-gradle/src/main/java/org/jboss/shrinkwrap/resolver/impl/gradle/GradleEffectiveDependencies.java +++ b/gradle/impl-gradle/src/main/java/org/jboss/shrinkwrap/resolver/impl/gradle/GradleEffectiveDependencies.java @@ -24,7 +24,7 @@ public List getDependenciesByScope(final ScopeType scopeType) { if (effectiveModelGroupedByScope.containsKey(scopeType)) { return Collections.unmodifiableList(effectiveModelGroupedByScope.get(scopeType)); } else { - return Collections.unmodifiableList(new ArrayList()); + return Collections.unmodifiableList(new ArrayList<>()); } } diff --git a/gradle/impl-gradle/src/main/java/org/jboss/shrinkwrap/resolver/impl/gradle/GradleStrategyStage.java b/gradle/impl-gradle/src/main/java/org/jboss/shrinkwrap/resolver/impl/gradle/GradleStrategyStage.java index 943a854ce..a8b3f0e35 100644 --- a/gradle/impl-gradle/src/main/java/org/jboss/shrinkwrap/resolver/impl/gradle/GradleStrategyStage.java +++ b/gradle/impl-gradle/src/main/java/org/jboss/shrinkwrap/resolver/impl/gradle/GradleStrategyStage.java @@ -30,8 +30,8 @@ public GradleStrategyStage(final String projectDirectory, final Set s * @param archive ShrinkWrap archive. * @return Array of dependencies and transitive ones for configured state. */ - public Archive[] as(final Class archive) { - final List archives = asList(archive); + public Archive[] as(final Class> archive) { + final List> archives = asList(archive); return archives.toArray(new Archive[archives.size()]); } @@ -40,16 +40,16 @@ public Archive[] as(final Class archive) { * @param archive ShrinkWrap archive. * @return List of dependencies and transitive ones for configured state. */ - public List asList(final Class archive) { + public List> asList(final Class> archive) { - final List archives = new ArrayList<>(); + final List> archives = new ArrayList<>(); final GradleEffectiveDependencies gradleEffectiveDependencies = GradleRunner.getEffectiveDependencies(projectDirectory); for (ScopeType scopeType : scopeTypesDependencies) { final List dependenciesByScope = gradleEffectiveDependencies.getDependenciesByScope(scopeType); for (File dependency : dependenciesByScope) { try { - final Archive dep = ShrinkWrap.create(ZipImporter.class, dependency.getName()).importFrom(dependency).as(archive); + final Archive dep = ShrinkWrap.create(ZipImporter.class, dependency.getName()).importFrom(dependency).as(archive); archives.add(dep); } catch (Exception e) { log.log(Level.WARNING, "Cannot import gradle dependency " + dependency + ". Not a zip-like format", e); diff --git a/gradle/impl-gradle/src/test/java/org/jboss/shrinkwrap/resolver/impl/gradle/ShrinkWrapGradleTestCase.java b/gradle/impl-gradle/src/test/java/org/jboss/shrinkwrap/resolver/impl/gradle/ShrinkWrapGradleTestCase.java index 71f6a777f..e9848c7ed 100644 --- a/gradle/impl-gradle/src/test/java/org/jboss/shrinkwrap/resolver/impl/gradle/ShrinkWrapGradleTestCase.java +++ b/gradle/impl-gradle/src/test/java/org/jboss/shrinkwrap/resolver/impl/gradle/ShrinkWrapGradleTestCase.java @@ -12,7 +12,7 @@ public class ShrinkWrapGradleTestCase { @Test public void should_return_dependencies_by_scope_in_simple_build_script() { - final List archives = Gradle.resolver().forProjectDirectory("src/test/resources/simple") + final List> archives = Gradle.resolver().forProjectDirectory("src/test/resources/simple") .importCompileAndRuntime() .resolve().asList(JavaArchive.class); @@ -21,7 +21,7 @@ public void should_return_dependencies_by_scope_in_simple_build_script() { @Test public void should_return_dependencies_by_scope_in_dependency_management_build_script() { - final List archives = Gradle.resolver().forProjectDirectory("src/test/resources/dependencymanager") + final List> archives = Gradle.resolver().forProjectDirectory("src/test/resources/dependencymanager") .importRuntime() .resolve().asList(JavaArchive.class); @@ -30,7 +30,7 @@ public void should_return_dependencies_by_scope_in_dependency_management_build_s @Test public void should_skip_non_zip_files_in_depchain_build_script() { - final List archives = Gradle.resolver().forProjectDirectory("src/test/resources/depchain") + final List> archives = Gradle.resolver().forProjectDirectory("src/test/resources/depchain") .importCompileAndRuntime() .resolve().asList(JavaArchive.class); diff --git a/maven/api-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/embedded/BuiltProject.java b/maven/api-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/embedded/BuiltProject.java index 3f21a091c..65325a524 100644 --- a/maven/api-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/embedded/BuiltProject.java +++ b/maven/api-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/embedded/BuiltProject.java @@ -27,7 +27,7 @@ public interface BuiltProject { * * @return An {@link Archive} with a default name. If no archive is found then null is returned */ - Archive getDefaultBuiltArchive(); + Archive getDefaultBuiltArchive(); /** * Returns an instance of {@link BuiltProject} representing module with the given name. @@ -59,7 +59,7 @@ public interface BuiltProject { * @return A list of all supported {@link Archive}s found in the first level of the build target directory. * If no target directory is present then null is returned. */ - List getArchives(); + List> getArchives(); /** * Returns a list of all {@link Archive}s of the given type of {@link Archive} found in the first level of the build diff --git a/maven/api-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/embedded/pom/equipped/ConfigurationStage.java b/maven/api-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/embedded/pom/equipped/ConfigurationStage.java index b5eeb042b..cf7f27153 100644 --- a/maven/api-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/embedded/pom/equipped/ConfigurationStage.java +++ b/maven/api-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/embedded/pom/equipped/ConfigurationStage.java @@ -26,12 +26,13 @@ import org.jboss.shrinkwrap.resolver.api.maven.embedded.BuildStage; import org.jboss.shrinkwrap.resolver.api.maven.embedded.BuiltProject; import org.jboss.shrinkwrap.resolver.api.maven.embedded.daemon.DaemonBuildTrigger; +import org.jboss.shrinkwrap.resolver.api.maven.embedded.daemon.WithTimeoutDaemonBuilder; /** * @author Matous Jobanek */ -public interface ConfigurationStage - extends BuildStage { +public interface ConfigurationStage + , DAEMON_TRIGGER_TYPE extends DaemonBuildTrigger> extends BuildStage { /** * Sets the interaction mode of the Maven invocation. Equivalent of {@code -B} and {@code --batch-mode} diff --git a/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/PackagingType.java b/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/PackagingType.java index 67ddf9dfb..157642736 100644 --- a/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/PackagingType.java +++ b/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/PackagingType.java @@ -28,7 +28,7 @@ */ public class PackagingType { - private static final ConcurrentHashMap cache = new ConcurrentHashMap(); + private static final ConcurrentHashMap cache = new ConcurrentHashMap<>(); public static final PackagingType POM = new PackagingType("pom"); public static final PackagingType JAR = new PackagingType("jar"); diff --git a/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/filter/RejectDependenciesFilter.java b/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/filter/RejectDependenciesFilter.java index cce83bfb3..6ea569bfa 100644 --- a/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/filter/RejectDependenciesFilter.java +++ b/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/filter/RejectDependenciesFilter.java @@ -51,7 +51,7 @@ public RejectDependenciesFilter(final boolean rejectTransitives, final String... throw new IllegalArgumentException("There must be at least one coordinate specified to be rejected."); } - final Set bannedDependencies = new HashSet(coordinates.length); + final Set bannedDependencies = new HashSet<>(coordinates.length); for (final String coords : coordinates) { final MavenCoordinate coordinate = MavenCoordinates.createCoordinate(coords); final MavenDependency dependency = MavenDependencies.createDependency(coordinate, ScopeType.COMPILE, false); diff --git a/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/strategy/AcceptScopesStrategy.java b/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/strategy/AcceptScopesStrategy.java index 25c7c7dd7..505243bfc 100644 --- a/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/strategy/AcceptScopesStrategy.java +++ b/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/strategy/AcceptScopesStrategy.java @@ -51,7 +51,7 @@ public AcceptScopesStrategy(final ScopeType... scopes) throws IllegalArgumentExc if (scopes == null || scopes.length == 0) { throw new IllegalArgumentException("at least one scope must be specified"); } - final Set allowedScopes = new HashSet(scopes.length); + final Set allowedScopes = new HashSet<>(scopes.length); allowedScopes.addAll(Arrays.asList(scopes)); this.resolutionFilters = new MavenResolutionFilter[] { new ScopeFilter( allowedScopes.toArray(new ScopeType[] {})) }; diff --git a/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/strategy/CombinedStrategy.java b/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/strategy/CombinedStrategy.java index f3c449482..0e2bb5b5d 100644 --- a/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/strategy/CombinedStrategy.java +++ b/maven/api-maven/src/main/java/org/jboss/shrinkwrap/resolver/api/maven/strategy/CombinedStrategy.java @@ -41,7 +41,7 @@ public CombinedStrategy(final MavenResolutionStrategy... strategies) { if (strategies.length == 0) { throw new IllegalArgumentException("There must be at least one strategy for a combined strategy."); } - final List resolutionFilterChains = new ArrayList(); + final List resolutionFilterChains = new ArrayList<>(); for (final MavenResolutionStrategy strategy : strategies) { resolutionFilterChains.add(strategy.getResolutionFilters()); } @@ -54,7 +54,7 @@ public MavenResolutionFilter[] getResolutionFilters() { } private MavenResolutionFilter[] combine(final MavenResolutionFilter[]... inputFilterChains) { - final List combinedFilters = new ArrayList(); + final List combinedFilters = new ArrayList<>(); for (final MavenResolutionFilter[] filterChain : inputFilterChains) { combinedFilters.addAll(Arrays.asList(filterChain)); } diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/SecurityActions.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/SecurityActions.java index 3ffac3442..5f0b48322 100644 --- a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/SecurityActions.java +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/SecurityActions.java @@ -59,12 +59,7 @@ static ClassLoader getThreadContextClassLoader() { static String getProperty(final String key) { try { - String value = AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public String run() { - return System.getProperty(key); - } - }); + String value = AccessController.doPrivileged((PrivilegedExceptionAction) () -> System.getProperty(key)); return value; } // Unwrap @@ -93,12 +88,7 @@ public String run() { static Properties getProperties() { try { - return AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public Properties run() { - return System.getProperties(); - } - }); + return AccessController.doPrivileged((PrivilegedExceptionAction) System::getProperties); } // Unwrap catch (final PrivilegedActionException pae) { @@ -128,13 +118,8 @@ static URL getResource(final String resource) { // AccessController.doPrivileged(SecurityActions.GetTcclAction.INSTANCE).getResource(resourceName); try { - URL value = AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public URL run() { - return getThreadContextClassLoader().getResource(resource); - } - - }); + URL value = AccessController.doPrivileged((PrivilegedExceptionAction) + () -> getThreadContextClassLoader().getResource(resource)); return value; } diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/ArchiveFilteringUtils.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/ArchiveFilteringUtils.java index acc10c3a0..5da9cbb75 100644 --- a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/ArchiveFilteringUtils.java +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/ArchiveFilteringUtils.java @@ -23,7 +23,6 @@ import org.codehaus.plexus.util.SelectorUtils; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ArchivePath; -import org.jboss.shrinkwrap.api.Filter; import org.jboss.shrinkwrap.api.Node; import org.jboss.shrinkwrap.api.ShrinkWrap; @@ -44,32 +43,28 @@ public static > T filterArchiveContent(T archive, Class final List excludes) { // get all files that should be included in archive - Map includePart = archive.getContent(new Filter() { - @Override - public boolean include(ArchivePath path) { + Map includePart = archive.getContent(path -> { - // trim first slash - String pathAsString = path.get(); - pathAsString = pathAsString.startsWith("/") ? pathAsString.substring(1) : pathAsString; + // trim first slash + String pathAsString = path.get(); + pathAsString = pathAsString.startsWith("/") ? pathAsString.substring(1) : pathAsString; - boolean include = false; - // include all files that should be included - includesLoop: for (String i : includes) { - // paths in ShrinkWrap archives are always "/" separated - if (SelectorUtils.matchPath(i, pathAsString, "/", true)) { - // if file should be included, check also for excludes - for (String e : excludes) { - if (SelectorUtils.matchPath(e, pathAsString, "/", true)) { - break includesLoop; - } + boolean include = false; + // include all files that should be included + includesLoop: for (String i : includes) { + // paths in ShrinkWrap archives are always "/" separated + if (SelectorUtils.matchPath(i, pathAsString, "/", true)) { + // if file should be included, check also for excludes + for (String e : excludes) { + if (SelectorUtils.matchPath(e, pathAsString, "/", true)) { + break includesLoop; } - include = true; - break; } + include = true; + break; } - - return include; } + return include; }); // create new archive and merge content together diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/ManifestAsset.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/ManifestAsset.java index 5cbd949f0..7eb9ab03a 100644 --- a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/ManifestAsset.java +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/ManifestAsset.java @@ -46,18 +46,12 @@ class ManifestAsset extends StringAsset { * @return String representation of the Manifest */ private static String manifestAsString(Manifest manifest) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try { + try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { manifest.write(baos); return baos.toString("UTF-8"); } catch (IOException e) { throw new IllegalStateException("Unable to write MANIFEST.MF to an archive Asset", e); - } finally { - try { - baos.close(); - } catch (IOException e) { - } } } diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/WarPackagingProcessor.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/WarPackagingProcessor.java index 5bc0a1092..6cbab242c 100644 --- a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/WarPackagingProcessor.java +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/packaging/WarPackagingProcessor.java @@ -128,20 +128,17 @@ public WarPackagingProcessor importBuildOutput(MavenResolutionStrategy strategy) protected Filter createFilter(WarPluginConfiguration configuration) { final List filesToIncludes = Arrays.asList(getFilesToIncludes(configuration.getWarSourceDirectory(), configuration.getIncludes(), configuration.getExcludes())); - return new Filter() { - @Override - public boolean include(ArchivePath archivePath) { - final String stringifiedPath = archivePath.get(); - if (filesToIncludes.contains(stringifiedPath)) { + return archivePath -> { + final String stringifiedPath = archivePath.get(); + if (filesToIncludes.contains(stringifiedPath)) { + return true; + } + for (String fileToInclude : filesToIncludes) { + if (fileToInclude.startsWith(stringifiedPath)) { return true; } - for (String fileToInclude : filesToIncludes) { - if (fileToInclude.startsWith(stringifiedPath)) { - return true; - } - } - return false; } + return false; }; } diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/CompilerPluginConfiguration.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/CompilerPluginConfiguration.java index ffd553745..eee6afb8f 100644 --- a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/CompilerPluginConfiguration.java +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/CompilerPluginConfiguration.java @@ -94,8 +94,8 @@ public String getEncoding() { public Map getAdditionalCompilerArgs() { // merge old and new argument definitions together - Map compilerArgumentsAsMap = new HashMap(additionalCompilerArguments.size() - + additionalCompilerArgs.size() + 1); + Map compilerArgumentsAsMap = new HashMap<>(additionalCompilerArguments.size() + + additionalCompilerArgs.size() + 1); if (!additionalCompilerArgument.isEmpty()) { compilerArgumentsAsMap.put(additionalCompilerArgument, null); @@ -133,7 +133,7 @@ public CompilerConfiguration asCompilerConfiguration() { } private static Map prependKeysWithDash(Map original) { - Map map = new HashMap(original.size()); + Map map = new HashMap<>(original.size()); for (Map.Entry entry : original.entrySet()) { map.put("-" + entry.getKey(), entry.getValue()); } diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/ConfigurationUtils.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/ConfigurationUtils.java index 7f774ef60..b3c205de1 100644 --- a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/ConfigurationUtils.java +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/ConfigurationUtils.java @@ -115,10 +115,9 @@ static Map valueAsMap(Map map, Key key, Map valueAsMapOfStrings(Map map, Key key, Map defaultValue) { - Map castedDefaultValue = new HashMap(defaultValue); - + Map castedDefaultValue = new HashMap<>(defaultValue); Map uncastedResult = valueAsMap(map, key, castedDefaultValue); - Map castedResult = new HashMap(); + Map castedResult = new HashMap<>(); for (Map.Entry entry : uncastedResult.entrySet()) { castedResult.put(entry.getKey(), entry.getValue() == null ? null : entry.getValue().toString()); } @@ -165,7 +164,7 @@ static List valueAsStringList(Map map, Key key, List) { - List list = new ArrayList(); + List list = new ArrayList<>(); for (Object nested : (Iterable) nestedRaw) { list.addAll(tokenize(nested, key.delimiter)); } @@ -180,7 +179,7 @@ else if (nestedRaw instanceof Iterable) { } private static List tokenize(Object object, String delimiter) { - List list = new ArrayList(); + List list = new ArrayList<>(); final StringTokenizer tokenizer = new StringTokenizer(object.toString(), delimiter); while (tokenizer.hasMoreElements()) { list.add(tokenizer.nextToken()); diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/MavenArchiveConfiguration.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/MavenArchiveConfiguration.java index 2ac78d52c..c259c8a9f 100644 --- a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/MavenArchiveConfiguration.java +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/MavenArchiveConfiguration.java @@ -87,7 +87,7 @@ public class MavenArchiveConfiguration { public MavenArchiveConfiguration(ParsedPomFile pomFile, Map configuration) { this.pomFile = pomFile; - this.manifestEntries = new HashMap(); + this.manifestEntries = new HashMap<>(); this.manifestEntries.putAll(ConfigurationUtils.valueAsMapOfStrings(configuration, new Key("manifestEntries"), Collections. emptyMap())); this.manifestFile = ConfigurationUtils.valueAsFile(configuration, new Key("manifestFile"), pomFile.getBaseDirectory(), @@ -149,7 +149,7 @@ public Manifest asManifest() throws MavenImporterException { private Map> parseManifestSections(Map configuration) { - Map> map = new HashMap>(); + Map> map = new HashMap<>(); Object rawOrSectionMap = configuration.get("manifestSections"); if (rawOrSectionMap == null || !(rawOrSectionMap instanceof Map)) { @@ -199,19 +199,12 @@ private class ManifestBuilder { ManifestBuilder loadFile() throws MavenImporterException { if (Validate.isReadable(getManifestFile())) { - InputStream is = null; - try { - is = Files.newInputStream(getManifestFile().toPath()); + try (InputStream is = Files.newInputStream(getManifestFile().toPath())) { Manifest userSupplied = new Manifest(is); this.manifest = ManifestMerger.merge(userSupplied, manifest); } catch (IOException e) { throw new MavenImporterException("Unable to build MANIFEST.MF from file " + getManifestFile().getAbsolutePath(), e); - } finally { - try { - is.close(); - } catch (IOException e) { - } } } return this; diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/SecurityActions.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/SecurityActions.java index 49202ffab..b9beebb6f 100644 --- a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/SecurityActions.java +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/SecurityActions.java @@ -40,12 +40,7 @@ private SecurityActions() { static String getProperty(final String key) { try { - String value = AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public String run() { - return System.getProperty(key); - } - }); + String value = AccessController.doPrivileged((PrivilegedExceptionAction) () -> System.getProperty(key)); return value; } // Unwrap @@ -74,12 +69,7 @@ public String run() { static Properties getProperties() { try { - Properties value = AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public Properties run() { - return System.getProperties(); - } - }); + Properties value = AccessController.doPrivileged((PrivilegedExceptionAction) System::getProperties); return value; } // Unwrap diff --git a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/WarPluginConfiguration.java b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/WarPluginConfiguration.java index d8ff500b0..9aecb27ca 100644 --- a/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/WarPluginConfiguration.java +++ b/maven/impl-maven-archive/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/plugins/WarPluginConfiguration.java @@ -47,7 +47,7 @@ public WarPluginConfiguration(ParsedPomFile pomFile) { pomFile.getBaseDirectory(), new File(pomFile.getBaseDirectory(), "src/main/webapp")); // excludes - List excludes = new ArrayList(); + List excludes = new ArrayList<>(); excludes.addAll(ConfigurationUtils.valueAsStringList(rawValues, new Key("excludes", "exclude"), Collections. emptyList())); excludes.addAll(ConfigurationUtils.valueAsStringList(rawValues, new Key("packagingExcludes"), @@ -57,7 +57,7 @@ public WarPluginConfiguration(ParsedPomFile pomFile) { this.excludes = excludes.toArray(new String[0]); // includes - List includes = new ArrayList(); + List includes = new ArrayList<>(); includes.addAll(ConfigurationUtils.valueAsStringList(rawValues, new Key("includes", "include"), Collections.singletonList("**/**"))); includes.addAll(ConfigurationUtils.valueAsStringList(rawValues, new Key("packagingIncludes"), Collections. emptyList())); diff --git a/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/ArchiveContentMatchers.java b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/ArchiveContentMatchers.java index 914db1da9..9d2a114bf 100644 --- a/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/ArchiveContentMatchers.java +++ b/maven/impl-maven-archive/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/archive/importer/ArchiveContentMatchers.java @@ -111,19 +111,10 @@ public boolean matches(Object item) { } private Manifest getManifest(Asset asset) { - InputStream is = null; - try { - is = asset.openStream(); + try (InputStream is = asset.openStream()) { return new Manifest(is); } catch (IOException e) { - } finally { - try { - if (is != null) { - is.close(); - } - } catch (IOException e) { - } } return new Manifest(); } diff --git a/maven/impl-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/BuiltProjectImpl.java b/maven/impl-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/BuiltProjectImpl.java index c99aa63bd..e52119e1b 100644 --- a/maven/impl-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/BuiltProjectImpl.java +++ b/maven/impl-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/BuiltProjectImpl.java @@ -64,7 +64,7 @@ public Model getModel() { return model; } - public Archive getDefaultBuiltArchive() { + public Archive getDefaultBuiltArchive() { String finalName = getModel().getBuild().getFinalName(); String buildDirectory = getModel().getBuild().getDirectory(); String packaging = getModel().getPackaging(); @@ -83,7 +83,7 @@ public Archive getDefaultBuiltArchive() { } } - private Class getArchiveRepresentation(PackagingType packagingType) { + private Class> getArchiveRepresentation(PackagingType packagingType) { if (packagingType == PackagingType.EAR) { return EnterpriseArchive.class; } else if (packagingType == PackagingType.WAR) { @@ -133,15 +133,15 @@ public File getTargetDirectory() { return new File(getModel().getBuild().getDirectory()); } - public List getArchives() { + public List> getArchives() { File[] allFirstLevelFiles = getFirstLevelFiles(); if (allFirstLevelFiles == null){ return null; } - List archives = new ArrayList<>(allFirstLevelFiles.length); + List> archives = new ArrayList<>(allFirstLevelFiles.length); for (File file : allFirstLevelFiles) { - Class archiveType = getIfSupported(file); + Class> archiveType = getIfSupported(file); if (archiveType != null) { archives.add(ShrinkWrap.createFromZipFile(archiveType, file)); } @@ -157,7 +157,7 @@ private File[] getFirstLevelFiles(){ return targetDirectory.listFiles(); } - private Class getIfSupported(File file) { + private Class> getIfSupported(File file) { String extension = FilenameUtils.getExtension(file.getName()); if (!Validate.isNullOrEmpty(extension)) { PackagingType packagingType = PackagingType.fromCache(extension); @@ -176,7 +176,7 @@ public > List getArchives(Class type) { List archives = new ArrayList<>(); for (File file : allFirstLevelFiles) { - Class archiveType = getIfSupported(file); + Class> archiveType = getIfSupported(file); if (archiveType != null && archiveType.isAssignableFrom(type)) { archives.add(ShrinkWrap.createFromZipFile(type, file)); } diff --git a/maven/impl-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/DistributionStageImpl.java b/maven/impl-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/DistributionStageImpl.java index ffa6e61dd..714f44314 100644 --- a/maven/impl-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/DistributionStageImpl.java +++ b/maven/impl-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/DistributionStageImpl.java @@ -1,7 +1,6 @@ package org.jboss.shrinkwrap.resolver.impl.maven.embedded; import java.io.File; -import java.io.FileFilter; import java.io.FileInputStream; import java.io.IOException; import java.net.MalformedURLException; @@ -59,13 +58,7 @@ public NEXT_STEP useDistribution(URL mavenDistribution, boolean useCache) { } private File retrieveBinDirectory(File uncompressed) { - File[] extracted = uncompressed.listFiles(new FileFilter() { - - @Override - public boolean accept(File file) { - return file.isDirectory(); - } - }); + File[] extracted = uncompressed.listFiles(File::isDirectory); if (extracted.length == 0) { throw new IllegalArgumentException("No directory has been extracted from the archive: " + uncompressed); } diff --git a/maven/impl-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/invoker/equipped/MavenInvokerEquippedEmbeddedMavenImpl.java b/maven/impl-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/invoker/equipped/MavenInvokerEquippedEmbeddedMavenImpl.java index 202a003ed..827daa88d 100644 --- a/maven/impl-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/invoker/equipped/MavenInvokerEquippedEmbeddedMavenImpl.java +++ b/maven/impl-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/invoker/equipped/MavenInvokerEquippedEmbeddedMavenImpl.java @@ -43,7 +43,7 @@ protected boolean isQuiet() { } @Override - protected BuildStage returnNextStepType() { + protected BuildStage returnNextStepType() { return this; } } diff --git a/maven/impl-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/pom/equipped/PomEquippedEmbeddedMavenImpl.java b/maven/impl-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/pom/equipped/PomEquippedEmbeddedMavenImpl.java index b6ea86467..42ea58766 100644 --- a/maven/impl-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/pom/equipped/PomEquippedEmbeddedMavenImpl.java +++ b/maven/impl-maven-embedded/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/pom/equipped/PomEquippedEmbeddedMavenImpl.java @@ -25,6 +25,7 @@ import org.apache.maven.shared.invoker.Invoker; import org.apache.maven.shared.invoker.InvokerLogger; import org.jboss.shrinkwrap.impl.base.Validate; +import org.jboss.shrinkwrap.resolver.api.maven.embedded.daemon.WithTimeoutDaemonBuilder; import org.jboss.shrinkwrap.resolver.api.maven.embedded.pom.equipped.ConfigurationDistributionStage; import org.jboss.shrinkwrap.resolver.api.maven.embedded.pom.equipped.ConfigurationStage; import org.jboss.shrinkwrap.resolver.api.maven.embedded.pom.equipped.PomEquippedEmbeddedMaven; @@ -67,7 +68,7 @@ protected Invoker getInvoker() { } @Override - protected ConfigurationStage returnNextStepType() { + protected ConfigurationStage returnNextStepType() { return this; } diff --git a/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/BuildOutputTestCase.java b/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/BuildOutputTestCase.java index 7e6a43a81..4a21c1187 100644 --- a/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/BuildOutputTestCase.java +++ b/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/BuildOutputTestCase.java @@ -67,7 +67,7 @@ private void verifyBuildContent(boolean shouldContain) { } private void assertBuildStdoutContains(String expectedString, boolean shouldContain){ - StringBuffer assertWarn = new StringBuffer("The build output printed on stdout should "); + StringBuilder assertWarn = new StringBuilder("The build output printed on stdout should "); if (!shouldContain){ assertWarn.append("NOT "); } diff --git a/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/ConfigurationStageTestCase.java b/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/ConfigurationStageTestCase.java index c855c1ba5..eb4c01b3b 100644 --- a/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/ConfigurationStageTestCase.java +++ b/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/ConfigurationStageTestCase.java @@ -11,6 +11,8 @@ import org.apache.maven.shared.invoker.InvokerLogger; import org.assertj.core.api.JUnitSoftAssertions; import org.jboss.shrinkwrap.resolver.api.maven.embedded.EmbeddedMaven; +import org.jboss.shrinkwrap.resolver.api.maven.embedded.daemon.WithTimeoutDaemonBuilder; +import org.jboss.shrinkwrap.resolver.api.maven.embedded.pom.equipped.ConfigurationDistributionStage; import org.jboss.shrinkwrap.resolver.api.maven.embedded.pom.equipped.ConfigurationStage; import org.jboss.shrinkwrap.resolver.impl.maven.embedded.pom.equipped.ConfigurationStageImpl; import org.junit.Assert; @@ -32,7 +34,7 @@ public class ConfigurationStageTestCase { put("propertyKey1", "propertyValue1"); put("propertyKey2", "propertyValue2"); }}; - final Map shellEnvironments = new HashMap() {{ + final Map shellEnvironments = new HashMap() {{ put("shellEnvName1", "shellEnvValue1"); put("shellEnvName2", "shellEnvValue2"); }}; @@ -124,7 +126,7 @@ public void runTest() { } private ConfigurationStageImpl getConfigurationStageImpl(File jarSamplePom) { - ConfigurationStage configurationStage = + ConfigurationStage configurationStage = EmbeddedMaven.forProject(jarSamplePom) .useMaven3Version("3.3.9") .setGoals(goals) diff --git a/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/DistributionStageImplTestCase.java b/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/DistributionStageImplTestCase.java index f5d7fbc05..f714fcf1c 100644 --- a/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/DistributionStageImplTestCase.java +++ b/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/DistributionStageImplTestCase.java @@ -61,16 +61,13 @@ private void verifyOneOccurrenceInLog(String expMsg){ } private Thread createThreadWithDownload(final CountDownLatch startLatch, final CountDownLatch stopLatch) { - return new Thread(new Runnable() { - @Override - public void run() { - try { - startLatch.await(); - downloadAndExtractMavenBinaryArchive(); - stopLatch.countDown(); - } catch (Exception e) { - e.printStackTrace(); - } + return new Thread(() -> { + try { + startLatch.await(); + downloadAndExtractMavenBinaryArchive(); + stopLatch.countDown(); + } catch (Exception e) { + e.printStackTrace(); } }); } diff --git a/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/FileExtractorTestCase.java b/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/FileExtractorTestCase.java index 41bc423ab..d53556e94 100644 --- a/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/FileExtractorTestCase.java +++ b/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/FileExtractorTestCase.java @@ -59,17 +59,14 @@ public void testDownloadDefaultMavenAndExtractUsingMultipleThreads() throws IOEx private Thread createThreadWithExtract(final CountDownLatch startLatch, final CountDownLatch stopLatch, final File downloaded) { - return new Thread(new Runnable() { - @Override - public void run() { - try { - startLatch.await(); - FileExtractor.extract(downloaded, - Paths.get(MAVEN_TARGET_DIR, "948110de4aab290033c23bf4894f7d9a").toFile()); - stopLatch.countDown(); - } catch (InterruptedException e) { - e.printStackTrace(); - } + return new Thread(() -> { + try { + startLatch.await(); + FileExtractor.extract(downloaded, + Paths.get(MAVEN_TARGET_DIR, "948110de4aab290033c23bf4894f7d9a").toFile()); + stopLatch.countDown(); + } catch (InterruptedException e) { + e.printStackTrace(); } }); } diff --git a/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/MavenDownloadsTestCase.java b/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/MavenDownloadsTestCase.java index b6cf7e723..5404a8a3d 100644 --- a/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/MavenDownloadsTestCase.java +++ b/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/MavenDownloadsTestCase.java @@ -1,7 +1,6 @@ package org.jboss.shrinkwrap.resolver.impl.maven.embedded; import java.io.File; -import java.io.FileFilter; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -97,16 +96,13 @@ public void testDownloadInMultipleThreads() throws InterruptedException { } private Thread createThreadWithDownload(final CountDownLatch startLatch, final CountDownLatch stopLatch) { - return new Thread(new Runnable() { - @Override - public void run() { - try { - startLatch.await(); - downloadSWRArchive("3.0.0-alpha-1"); - stopLatch.countDown(); - } catch (InterruptedException e) { - e.printStackTrace(); - } + return new Thread(() -> { + try { + startLatch.await(); + downloadSWRArchive("3.0.0-alpha-1"); + stopLatch.countDown(); + } catch (InterruptedException e) { + e.printStackTrace(); } }); } @@ -190,11 +186,7 @@ public void shouldExtractZipInDirWithNameMD5HashOfFile() { } private void verifyExtraction(int expectedNumberOfDirs, String... expectedDirNames) { - File[] dirsForExtraction = targetMavenDir.listFiles(new FileFilter() { - @Override public boolean accept(File file) { - return !file.getName().equals("downloaded"); - } - }); + File[] dirsForExtraction = targetMavenDir.listFiles(file -> !file.getName().equals("downloaded")); assertThat(dirsForExtraction) .as("there should be " + expectedNumberOfDirs + " dir(s) containing extraction") @@ -205,11 +197,7 @@ private void verifyExtraction(int expectedNumberOfDirs, String... expectedDirNam File[] allFiles = dirsForExtraction[i].listFiles(); assertThat(allFiles).as("there should be one dir with extracted files").hasSize(1); - File[] extractedDir = dirsForExtraction[i].listFiles(new FileFilter() { - @Override public boolean accept(File file) { - return file.isDirectory(); - } - }); + File[] extractedDir = dirsForExtraction[i].listFiles(File::isDirectory); assertTrue("the name of the extracted dir has to be in the list of expected names: " + allExpectedDirNames, allExpectedDirNames.remove(extractedDir[0].getName())); diff --git a/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/Utils.java b/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/Utils.java index d7a8ea2ea..f1a9b5607 100644 --- a/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/Utils.java +++ b/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/Utils.java @@ -35,7 +35,7 @@ public class Utils { public static final String archiveNameModuleTwoParamKey = "module.two.archive.name"; public static final String archiveNameModuleTwoParamValue = "cool-ear-name"; - public static void verifyThatArchiveContains(Archive archive, String path) { + public static void verifyThatArchiveContains(Archive archive, String path) { assertTrue("The archive should contain " + path, archive.contains(path)); } @@ -59,7 +59,7 @@ public static void verifyJarSampleSimpleBuild(BuiltProject builtProject) { assertEquals("The exit code should be 0", 0, builtProject.getMavenBuildExitCode()); // verify archive name - Archive defaultBuiltArchive = builtProject.getDefaultBuiltArchive(); + Archive defaultBuiltArchive = builtProject.getDefaultBuiltArchive(); assertEquals(jarSampleArchiveBaseName + ".jar", defaultBuiltArchive.getName()); // contains both the compiled classes and resources @@ -111,7 +111,7 @@ public static void verifyWarSampleWithSources(BuiltProject builtProject) { assertEquals("The exit code should be 0", 0, builtProject.getMavenBuildExitCode()); // verify archive name - Archive defaultBuiltArchive = builtProject.getDefaultBuiltArchive(); + Archive defaultBuiltArchive = builtProject.getDefaultBuiltArchive(); assertEquals("cool-war-sample.war", defaultBuiltArchive.getName()); // contains both the compiled classes and resources @@ -165,7 +165,7 @@ public static void verifyMultiModuleSampleWasCleaned(BuiltProject builtProject) public static void verifyModuleOne(BuiltProject builtProject) { // verify archive name - Archive defaultBuiltArchive = builtProject.getDefaultBuiltArchive(); + Archive defaultBuiltArchive = builtProject.getDefaultBuiltArchive(); assertEquals(baseArchiveNameModuleOne + ".jar", defaultBuiltArchive.getName()); // contains the compiled class @@ -187,7 +187,7 @@ public static void verifyModuleOne(BuiltProject builtProject) { public static void verifyModuleTwo(BuiltProject builtProject) { // verify archive name - Archive defaultBuiltArchive = builtProject.getDefaultBuiltArchive(); + Archive defaultBuiltArchive = builtProject.getDefaultBuiltArchive(); assertEquals(archiveNameModuleTwoParamValue + ".ear", defaultBuiltArchive.getName()); verifyThatArchiveContains(defaultBuiltArchive, "/" + baseArchiveNameModuleOne + ".jar"); diff --git a/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/invoker/equipped/InvokerEquippedEmbeddedMavenRunningAsDaemonTestCase.java b/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/invoker/equipped/InvokerEquippedEmbeddedMavenRunningAsDaemonTestCase.java index 2ee7c3940..97f7be0c0 100644 --- a/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/invoker/equipped/InvokerEquippedEmbeddedMavenRunningAsDaemonTestCase.java +++ b/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/invoker/equipped/InvokerEquippedEmbeddedMavenRunningAsDaemonTestCase.java @@ -4,7 +4,6 @@ import java.io.File; import java.io.PrintStream; import java.util.Arrays; -import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import org.apache.maven.shared.invoker.DefaultInvocationRequest; import org.apache.maven.shared.invoker.DefaultInvoker; @@ -51,20 +50,12 @@ public void testWhenDaemonIsUsedEndOfTheBuildIsNotReached() { .useAsDaemon() .build(); - Awaitility.await("Wait till maven build is started").atMost(5, TimeUnit.SECONDS).until(new Callable() { - @Override - public Boolean call() { - return outContent.toString().contains("Embedded Maven build started"); - } - }); + Awaitility.await("Wait till maven build is started").atMost(5, TimeUnit.SECONDS) + .until(() -> outContent.toString().contains("Embedded Maven build started")); Assertions.assertThat(outContent.toString()).doesNotContain("Embedded Maven build stopped"); - Awaitility.await("Wait till project is not be null").atMost(20, TimeUnit.SECONDS).until(new Callable() { - @Override - public Boolean call() { - return daemonBuild.getBuiltProject() != null; - } - }); + Awaitility.await("Wait till project is not be null").atMost(20, TimeUnit.SECONDS) + .until(() -> daemonBuild.getBuiltProject() != null); Assertions.assertThat(daemonBuild.isAlive()).isFalse(); } diff --git a/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/pom/equipped/PomEquippedEmbeddedMavenRunningAsDaemonTestCase.java b/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/pom/equipped/PomEquippedEmbeddedMavenRunningAsDaemonTestCase.java index 45627f902..a13a28755 100644 --- a/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/pom/equipped/PomEquippedEmbeddedMavenRunningAsDaemonTestCase.java +++ b/maven/impl-maven-embedded/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/embedded/pom/equipped/PomEquippedEmbeddedMavenRunningAsDaemonTestCase.java @@ -1,6 +1,5 @@ package org.jboss.shrinkwrap.resolver.impl.maven.embedded.pom.equipped; -import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.assertj.core.api.Assertions; @@ -34,12 +33,8 @@ public void testDaemonShouldWaitForBuildSuccess() throws TimeoutException { .withWaitUntilOutputLineMathes(".*BUILD SUCCESS.*") .build(); - Awaitility.await("Wait till thread is not be alive").atMost(20, TimeUnit.SECONDS).until(new Callable() { - @Override - public Boolean call() { - return !daemonBuild.isAlive(); - } - }); + Awaitility.await("Wait till thread is not be alive").atMost(20, TimeUnit.SECONDS) + .until(() -> !daemonBuild.isAlive()); Assertions.assertThat(daemonBuild.getBuiltProject()).isNotNull(); verifyJarSampleSimpleBuild(daemonBuild.getBuiltProject()); @@ -55,23 +50,16 @@ public void testDaemonWithoutWaitShouldNotReachTheEndOfTheBuild() { .useAsDaemon() .build(); - Awaitility.await("Wait till maven build is started").atMost(5, TimeUnit.SECONDS).until(new Callable() { - @Override - public Boolean call() { - return systemOutRule.getLog().contains("Embedded Maven build started"); - } - }); + Awaitility.await("Wait till maven build is started").atMost(5, TimeUnit.SECONDS) + .until(() -> systemOutRule.getLog().contains("Embedded Maven build started")); + Assertions.assertThat(systemOutRule.getLog()).doesNotContain("Embedded Maven build stopped"); Assertions.assertThat(systemOutRule.getLog()).doesNotContain("Embedded Maven build stopped"); Assertions.assertThat(daemonBuild.isAlive()).isTrue(); Assertions.assertThat(daemonBuild.getBuiltProject()).isNull(); - Awaitility.await("Wait till thread is not be alive").atMost(20, TimeUnit.SECONDS).until(new Callable() { - @Override - public Boolean call() { - return !daemonBuild.isAlive(); - } - }); + Awaitility.await("Wait till thread is not be alive").atMost(20, TimeUnit.SECONDS) + .until(() -> !daemonBuild.isAlive()); Assertions.assertThat(daemonBuild.isAlive()).isFalse(); verifyJarSampleSimpleBuild(daemonBuild.getBuiltProject()); diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/MavenResolvedArtifactImpl.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/MavenResolvedArtifactImpl.java index cd2877eb8..1df4b8947 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/MavenResolvedArtifactImpl.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/MavenResolvedArtifactImpl.java @@ -216,7 +216,7 @@ static void packageDirectories(final File outputFile, final File... directories) } private static List fileListing(final File directory) { - final List list = new ArrayList(); + final List list = new ArrayList<>(); generateFileList(list, directory, directory); return list; } diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/MavenVersionRangeResultImpl.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/MavenVersionRangeResultImpl.java index d0fb376ea..a2cf39a4e 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/MavenVersionRangeResultImpl.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/MavenVersionRangeResultImpl.java @@ -60,7 +60,7 @@ public MavenCoordinate getHighestVersion() { public List getVersions() { if (versions == null) { final List versions = versionRangeResult.getVersions(); - final List coordinates = new ArrayList(versions.size()); + final List coordinates = new ArrayList<>(versions.size()); for (final Version version : versions) { coordinates.add(getCoordinate(version)); diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/MavenWorkingSessionImpl.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/MavenWorkingSessionImpl.java index 239f92811..d2ba4a3bd 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/MavenWorkingSessionImpl.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/MavenWorkingSessionImpl.java @@ -192,9 +192,9 @@ public MavenWorkingSession loadPomFromFile(File pomFile, Properties userProperti public Collection resolveDependencies(final MavenResolutionStrategy strategy) throws ResolutionException { - final List depsForResolution = Collections.unmodifiableList(new ArrayList( + final List depsForResolution = Collections.unmodifiableList(new ArrayList<>( this.getDependenciesForResolution())); - final List depManagement = new ArrayList(this.getDependencyManagement()); + final List depManagement = new ArrayList<>(this.getDependencyManagement()); final List repos = this.getRemoteRepositories(); @@ -206,7 +206,7 @@ public Collection resolveDependencies(final MavenResoluti // Set the dependency selector used in resolving transitive dependencies based on our transitive exclusion // policy abstraction - final Set dependencySelectors = new LinkedHashSet(3); + final Set dependencySelectors = new LinkedHashSet<>(3); final TransitiveExclusionPolicy transitiveExclusionPolicy = strategy.getTransitiveExclusionPolicy(); final ScopeType[] filteredScopes = transitiveExclusionPolicy.getFilteredScopes(); final int numFilteredScopes = filteredScopes.length; @@ -231,7 +231,7 @@ public Collection resolveDependencies(final MavenResoluti throw wrapException(e); } - final Collection resolvedArtifacts = new ArrayList(results.size()); + final Collection resolvedArtifacts = new ArrayList<>(results.size()); for (final ArtifactResult result : results) { resolvedArtifacts.add(MavenResolvedArtifactImpl.fromArtifactResult(result)); @@ -301,11 +301,7 @@ public void addRemoteRepo(MavenRemoteRepository repository) { .getUpdatePolicy().apiValue(), repository.getChecksumPolicy() == null ? null : repository .getChecksumPolicy().apiValue())); - for (RemoteRepository r : this.additionalRemoteRepositories) { - if (r.getId().equals(repository.getId())) { - this.additionalRemoteRepositories.remove(r); - } - } + this.additionalRemoteRepositories.removeIf(r -> r.getId().equals(repository.getId())); this.additionalRemoteRepositories.add(builder.build()); } diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/PostResolutionFilterApplicator.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/PostResolutionFilterApplicator.java index 7cc1c196f..17e76b84a 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/PostResolutionFilterApplicator.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/PostResolutionFilterApplicator.java @@ -49,7 +49,7 @@ class PostResolutionFilterApplicator { static Collection postFilter(final Collection artifactResults) { final MavenResolutionFilter postResolutionFilter = RestrictPomArtifactFilter.INSTANCE; - final Collection filteredArtifacts = new ArrayList(); + final Collection filteredArtifacts = new ArrayList<>(); final List emptyList = Collections.emptyList(); for (final MavenResolvedArtifact artifact : artifactResults) { diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/SecurityActions.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/SecurityActions.java index 41d8b45ab..2a5da41a1 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/SecurityActions.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/SecurityActions.java @@ -47,12 +47,7 @@ static ClassLoader getThreadContextClassLoader() { static String getProperty(final String key) { try { - String value = AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public String run() { - return System.getProperty(key); - } - }); + String value = AccessController.doPrivileged((PrivilegedExceptionAction) () -> System.getProperty(key)); return value; } // Unwrap @@ -81,12 +76,7 @@ public String run() { static Properties getProperties() { try { - Properties value = AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public Properties run() { - return System.getProperties(); - } - }); + Properties value = AccessController.doPrivileged((PrivilegedExceptionAction) System::getProperties); return value; } // Unwrap diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/SettingsManager.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/SettingsManager.java index 9923b29c2..610bba431 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/SettingsManager.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/SettingsManager.java @@ -99,7 +99,7 @@ protected void setOffline(Boolean programmaticOffline) { */ protected boolean isOffline() { if (this.programmaticOffline != null) { - return this.programmaticOffline.booleanValue(); + return this.programmaticOffline; } return this.getSettings().isOffline(); } @@ -107,7 +107,7 @@ protected boolean isOffline() { // utility methods private void propagateProgrammaticOfflineIntoSettings() { if (this.programmaticOffline != null && this.settings != null) { - this.settings.setOffline(this.programmaticOffline.booleanValue()); + this.settings.setOffline(this.programmaticOffline); } } } diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/aether/ClasspathWorkspaceReader.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/aether/ClasspathWorkspaceReader.java index e6d751083..ef35784f8 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/aether/ClasspathWorkspaceReader.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/aether/ClasspathWorkspaceReader.java @@ -108,28 +108,28 @@ private boolean isDirectory() { } } - private final Set classPathEntries = new LinkedHashSet(); + private final Set classPathEntries = new LinkedHashSet<>(); /** * Cache classpath File objects and retrieved isFile isDirectory values. Key is a classpath entry * * @see #getClasspathFileInfo(String) */ - private final Map classpathFileInfoCache = new HashMap(); + private final Map classpathFileInfoCache = new HashMap<>(); /** * Cache pom File objects and retrieved isFile isDirectory values. Key - child File * * @see #getPomFileInfo(java.io.File) */ - private final Map pomFileInfoCache = new HashMap(); + private final Map pomFileInfoCache = new HashMap<>(); /** * Cache Found in classpath artifacts. Key is a pom file. * * @see #getFoundArtifact(java.io.File) */ - private final Map foundArtifactCache = new HashMap(); + private final Map foundArtifactCache = new HashMap<>(); /** * The relative path of the "flattened" pom.xml to prefer over the regular pom.xml, if present. @@ -267,7 +267,7 @@ private Set getClassPathEntries(final String classPath) { if (Validate.isNullOrEmpty(classPath)) { return Collections.emptySet(); } - return new LinkedHashSet(Arrays.asList(classPath.split(String.valueOf(File.pathSeparatorChar)))); + return new LinkedHashSet<>(Arrays.asList(classPath.split(String.valueOf(File.pathSeparatorChar)))); } private FileInfo getClasspathFileInfo(final String classpathEntry) { diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/aether/SecurityActions.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/aether/SecurityActions.java index 6c82f0616..d73d8603f 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/aether/SecurityActions.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/aether/SecurityActions.java @@ -47,12 +47,7 @@ private SecurityActions() { static String getProperty(final String key) { try { - String value = AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public String run() { - return System.getProperty(key); - } - }); + String value = AccessController.doPrivileged((PrivilegedExceptionAction) () -> System.getProperty(key)); return value; } // Unwrap diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/MavenRepositorySystem.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/MavenRepositorySystem.java index 6cc50f2b3..421887fdc 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/MavenRepositorySystem.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/MavenRepositorySystem.java @@ -119,7 +119,7 @@ public Collection resolveDependencies(final RepositorySystemSess final MavenWorkingSession swrSession, final CollectRequest request, final MavenResolutionFilter[] filters) throws DependencyResolutionException { final DependencyRequest depRequest = new DependencyRequest(request, new MavenResolutionFilterWrap(filters, - Collections.unmodifiableList(new ArrayList(swrSession.getDependenciesForResolution())))); + Collections.unmodifiableList(new ArrayList<>(swrSession.getDependenciesForResolution())))); DependencyResult result = context.repositorySystem().resolveDependencies(repoSession, depRequest); return result.getArtifactResults(); @@ -192,7 +192,7 @@ public boolean accept(final DependencyNode node, List parents) { return false; } - List ancestors = new ArrayList(); + List ancestors = new ArrayList<>(); for (DependencyNode parent : parents) { Dependency parentDependency = parent.getDependency(); if (parentDependency != null) { diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/MavenSettingsBuilder.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/MavenSettingsBuilder.java index f6c321c9c..43909725f 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/MavenSettingsBuilder.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/MavenSettingsBuilder.java @@ -268,7 +268,7 @@ private Settings enrichWithOfflineMode(Settings settings) { String goOffline = SecurityActions.getProperty(ALT_MAVEN_OFFLINE); if (goOffline != null && !goOffline.isEmpty()) { - settings.setOffline(Boolean.valueOf(goOffline)); + settings.setOffline(Boolean.parseBoolean(goOffline)); } return settings; diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/SecurityActions.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/SecurityActions.java index ac866e7b2..b722f9a80 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/SecurityActions.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/SecurityActions.java @@ -52,12 +52,7 @@ private SecurityActions() { static String getProperty(final String key) { try { - String value = AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public String run() { - return System.getProperty(key); - } - }); + String value = AccessController.doPrivileged((PrivilegedExceptionAction) () -> System.getProperty(key)); return value; } // Unwrap @@ -86,12 +81,7 @@ public String run() { static String getEnvProperty(final String key) { try { - String value = AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public String run() { - return System.getenv(key); - } - }); + String value = AccessController.doPrivileged((PrivilegedExceptionAction) () -> System.getenv(key)); return value; } // Unwrap @@ -120,12 +110,7 @@ public String run() { static Properties getProperties() { try { - return AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public Properties run() { - return System.getProperties(); - } - }); + return AccessController.doPrivileged((PrivilegedExceptionAction) System::getProperties); } // Unwrap catch (final PrivilegedActionException pae) { @@ -200,11 +185,8 @@ static T newInstance(final Class implClass, final Class[] argumentType static Constructor getConstructor(final Class clazz, final Class... argumentTypes) throws NoSuchMethodException { try { - return AccessController.doPrivileged(new PrivilegedExceptionAction>() { - public Constructor run() throws NoSuchMethodException { - return clazz.getDeclaredConstructor(argumentTypes); - } - }); + return AccessController.doPrivileged((PrivilegedExceptionAction>) + () -> clazz.getDeclaredConstructor(argumentTypes)); } // Unwrap catch (final PrivilegedActionException pae) { diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/convert/MavenConverter.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/convert/MavenConverter.java index d8521af5a..b2a236e60 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/convert/MavenConverter.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/convert/MavenConverter.java @@ -90,7 +90,7 @@ public static MavenDependencyExclusion fromExclusion(final Exclusion exclusion) } public static Set fromExclusions(final Collection exclusions) { - Set set = new LinkedHashSet(exclusions.size()); + Set set = new LinkedHashSet<>(exclusions.size()); for (final Exclusion e : exclusions) { set.add(fromExclusion(e)); } @@ -142,7 +142,7 @@ public static MavenDependency fromDependency(final Dependency dependency) { public static Set fromDependencies(Collection dependencies) { - Set set = new LinkedHashSet(); + Set set = new LinkedHashSet<>(); for (Dependency d : dependencies) { set.add(fromDependency(d)); } @@ -176,7 +176,7 @@ public static MavenDependency fromDependency(org.apache.maven.model.Dependency d Artifact artifact = new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), null, dependency.getVersion(), props, stereotype); - Set exclusions = new LinkedHashSet(); + Set exclusions = new LinkedHashSet<>(); for (org.apache.maven.model.Exclusion e : dependency.getExclusions()) { exclusions.add(fromExclusion(e)); } @@ -210,7 +210,7 @@ public static MavenDependency fromDependency(org.apache.maven.model.Dependency d public static Set fromDependencies(Collection dependencies, ArtifactTypeRegistry registry) { - Set set = new LinkedHashSet(); + Set set = new LinkedHashSet<>(); for (org.apache.maven.model.Dependency d : dependencies) { set.add(fromDependency(d, registry)); } @@ -241,7 +241,7 @@ public static Dependency asDependency(MavenDependencySPI dependency, ArtifactTyp } public static List asDependencies(List dependencies, ArtifactTypeRegistry registry) { - final List list = new ArrayList(dependencies.size()); + final List list = new ArrayList<>(dependencies.size()); for (final MavenDependency d : dependencies) { list.add(asDependency((MavenDependencySPI) d, registry)); } @@ -271,7 +271,7 @@ public static Exclusion asExclusion(MavenDependencyExclusion coordinates) { } public static List asExclusions(Collection exclusions) { - List list = new ArrayList(exclusions.size()); + List list = new ArrayList<>(exclusions.size()); for (MavenDependencyExclusion coords : exclusions) { list.add(asExclusion(coords)); } @@ -337,7 +337,7 @@ public static Profile asProfile(org.apache.maven.settings.Profile profile) { } public static List asProfiles(List profiles) { - List mavenProfiles = new ArrayList(); + List mavenProfiles = new ArrayList<>(); for (org.apache.maven.settings.Profile p : profiles) { mavenProfiles.add(asProfile(p)); } @@ -360,7 +360,7 @@ private static Repository asRepository(org.apache.maven.settings.Repository repo } private static List asRepositories(List repositories) { - List mavenRepositories = new ArrayList(); + List mavenRepositories = new ArrayList<>(); for (org.apache.maven.settings.Repository repository : repositories) { mavenRepositories.add(asRepository(repository)); } diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/coordinate/MavenDependencyImpl.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/coordinate/MavenDependencyImpl.java index e1076b1dd..0032632a7 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/coordinate/MavenDependencyImpl.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/coordinate/MavenDependencyImpl.java @@ -82,7 +82,7 @@ public MavenDependencyImpl(final MavenCoordinate coordinate, final ScopeType sco this.scope = scope == null ? ScopeType.COMPILE : scope; this.optional = optional; this.undeclaredScope = undeclaredScope; - final Set exclusionsToSet = new HashSet( + final Set exclusionsToSet = new HashSet<>( exclusions == null ? 0 : exclusions.length); if (exclusions != null) { for (final MavenDependencyExclusion exclusion : exclusions) { diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/MavenModelResolver.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/MavenModelResolver.java index edd192d4c..15c95f64e 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/MavenModelResolver.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/MavenModelResolver.java @@ -75,12 +75,12 @@ public MavenModelResolver(MavenRepositorySystem system, RepositorySystemSession this.session = session; // RemoteRepository is mutable - this.repositories = new ArrayList(remoteRepositories.size()); + this.repositories = new ArrayList<>(remoteRepositories.size()); for (final RemoteRepository remoteRepository : remoteRepositories) { this.repositories.add(new RemoteRepository.Builder(remoteRepository).build()); } - this.repositoryIds = new HashSet(repositories.size()); + this.repositoryIds = new HashSet<>(repositories.size()); for (final RemoteRepository repository : repositories) { repositoryIds.add(repository.getId()); diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/SettingsXmlProfileSelector.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/SettingsXmlProfileSelector.java index eb3734455..a26093449 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/SettingsXmlProfileSelector.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/SettingsXmlProfileSelector.java @@ -36,7 +36,7 @@ public static List explicitlyActivatedProfiles(String... profiles) { if (profiles.length == 0) { return Collections. emptyList(); } - List activated = new ArrayList(); + List activated = new ArrayList<>(); for (String profileId : profiles) { Validate.notNullOrEmpty(profileId, "Invalid name (\"" + profileId + "\") of a profile to be activated"); if (!(profileId.startsWith("-") || profileId.startsWith("!"))) { @@ -52,7 +52,7 @@ public static List explicitlyDisabledProfiles(String... profiles) { if (profiles.length == 0) { return Collections. emptyList(); } - List disabled = new ArrayList(); + List disabled = new ArrayList<>(); for (String profileId : profiles) { if (profileId != null && (profileId.startsWith("-") || profileId.startsWith("!"))) { String disabledId = profileId.substring(1); diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/decrypt/MavenSecurityDispatcher.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/decrypt/MavenSecurityDispatcher.java index a3c78e215..7b354725d 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/decrypt/MavenSecurityDispatcher.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/decrypt/MavenSecurityDispatcher.java @@ -128,7 +128,7 @@ private Map stripAttributes(String str) { while (st.hasMoreTokens()) { if (res == null) { - res = new HashMap(st.countTokens()); + res = new HashMap<>(st.countTokens()); } String pair = st.nextToken(); diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/decrypt/MavenSettingsDecrypter.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/decrypt/MavenSettingsDecrypter.java index 061efd16f..c10c1b9e1 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/decrypt/MavenSettingsDecrypter.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/internal/decrypt/MavenSettingsDecrypter.java @@ -48,9 +48,9 @@ public MavenSettingsDecrypter(File securitySettings) { } public SettingsDecryptionResult decrypt(SettingsDecryptionRequest request) { - List problems = new ArrayList(); + List problems = new ArrayList<>(); - List servers = new ArrayList(); + List servers = new ArrayList<>(); for (Server server : request.getServers()) { server = server.clone(); @@ -71,7 +71,7 @@ public SettingsDecryptionResult decrypt(SettingsDecryptionRequest request) { } } - List proxies = new ArrayList(); + List proxies = new ArrayList<>(); for (Proxy proxy : request.getProxies()) { proxy = proxy.clone(); diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/logging/LogTransferListener.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/logging/LogTransferListener.java index 37e49ffbd..83f68cbf4 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/logging/LogTransferListener.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/logging/LogTransferListener.java @@ -44,7 +44,7 @@ public class LogTransferListener extends AbstractTransferListener { private static final Logger log = Logger.getLogger(LogTransferListener.class.getName()); // a map of transferred data sizes for the last notification - private final Map downloads = new ConcurrentHashMap(); + private final Map downloads = new ConcurrentHashMap<>(); // a minimal amount of data transferred for an artifact required to inform // the user @@ -64,7 +64,7 @@ public void transferInitiated(TransferEvent event) { .append(event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploading" : "Downloading").append(":") .append(resource.getRepositoryUrl()).append(resource.getResourceName()); - downloads.put(resource, new Long(0)); + downloads.put(resource, 0L); log.fine(sb.toString()); } @@ -82,7 +82,7 @@ public void transferProgressed(TransferEvent event) { long transferred = event.getTransferredBytes(); if (transferred - lastTransferred >= TRANSFER_THRESHOLD) { - downloads.put(resource, Long.valueOf(transferred)); + downloads.put(resource, transferred); long total = resource.getContentLength(); log.finer(getStatus(transferred, total) + ", "); } diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/pom/ParsedPomFileImpl.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/pom/ParsedPomFileImpl.java index c585c90f7..558bc72aa 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/pom/ParsedPomFileImpl.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/pom/ParsedPomFileImpl.java @@ -133,7 +133,7 @@ public File getBuildOutputDirectory() { @Override public List getResources() { - List list = new ArrayList(); + List list = new ArrayList<>(); List resources = model.getBuild().getResources(); // FIXME resources content should be filtered @@ -158,7 +158,7 @@ public List getResources() @Override public List getTestResources() { - List list = new ArrayList(); + List list = new ArrayList<>(); List resources = model.getBuild().getTestResources(); // FIXME resources content should be filtered @@ -238,7 +238,7 @@ public Properties getProperties() { @SuppressWarnings("unchecked") private Map toMappedConfiguration(Xpp3Dom node) { - final HashMap map = new HashMap(); + final HashMap map = new HashMap<>(); for (Xpp3Dom child : node.getChildren()) { Object value; if (child.getChildCount() > 0) { @@ -249,7 +249,7 @@ private Map toMappedConfiguration(Xpp3Dom node) { if (map.containsKey(child.getName())) { Object oldValue = map.get(child.getName()); if (!(oldValue instanceof List)) { - final ArrayList objects = new ArrayList(); + final ArrayList objects = new ArrayList<>(); objects.add(oldValue); oldValue = objects; } @@ -293,8 +293,8 @@ private static final class FileUtils { private static final String[] EMPTY_STRING_ARRAY = new String[0]; public static Collection listFiles(File root) { - List allFiles = new ArrayList(); - Queue dirs = new LinkedList(); + List allFiles = new ArrayList<>(); + Queue dirs = new LinkedList<>(); dirs.add(root); while (!dirs.isEmpty()) { for (File f : dirs.poll().listFiles()) { diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/task/AddAllDeclaredDependenciesTask.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/task/AddAllDeclaredDependenciesTask.java index e561ab31d..045c4aa61 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/task/AddAllDeclaredDependenciesTask.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/task/AddAllDeclaredDependenciesTask.java @@ -43,7 +43,7 @@ public enum AddAllDeclaredDependenciesTask implements MavenWorkingSessionTask dependencies = new ArrayList(session.getDeclaredDependencies()); + final List dependencies = new ArrayList<>(session.getDeclaredDependencies()); // For all declared dependencies, add 'em to the Set of dependencies to be resolved for // this request diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/task/AddScopedDependenciesTask.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/task/AddScopedDependenciesTask.java index 07d574887..48cc3447e 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/task/AddScopedDependenciesTask.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/task/AddScopedDependenciesTask.java @@ -34,7 +34,7 @@ */ public class AddScopedDependenciesTask implements MavenWorkingSessionTask { - private static final List EMPTY_LIST = new ArrayList(0); + private static final List EMPTY_LIST = new ArrayList<>(0); private final ScopeType[] scopes; @@ -58,7 +58,7 @@ public AddScopedDependenciesTask(ScopeType... scopes) { public MavenWorkingSession execute(MavenWorkingSession session) { // Get all declared dependencies - final List dependencies = new ArrayList(session.getDeclaredDependencies()); + final List dependencies = new ArrayList<>(session.getDeclaredDependencies()); // Filter by scope final MavenResolutionFilter preResolutionFilter = new ScopeFilter(scopes); diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/task/ResolveVersionFromMetadataTask.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/task/ResolveVersionFromMetadataTask.java index e3cda2e49..554e74313 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/task/ResolveVersionFromMetadataTask.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/task/ResolveVersionFromMetadataTask.java @@ -17,7 +17,6 @@ package org.jboss.shrinkwrap.resolver.impl.maven.task; import java.text.MessageFormat; -import java.util.Iterator; import java.util.logging.Level; import java.util.logging.Logger; @@ -66,9 +65,8 @@ public String execute(MavenWorkingSession session) { // get the dependency from internal dependencyManagement MavenDependency resolved = null; - Iterator it = session.getDependencyManagement().iterator(); - while (it.hasNext()) { - resolved = it.next(); + for (MavenDependency mavenDependency : session.getDependencyManagement()) { + resolved = mavenDependency; if (resolved.equals(dependency)) { break; } @@ -92,9 +90,8 @@ public String execute(MavenWorkingSession session) { // get the dependency from internal dependencyManagement MavenDependency resolved = null; - Iterator it = session.getDependencyManagement().iterator(); - while (it.hasNext()) { - resolved = it.next(); + for (MavenDependency mavenDependency : session.getDependencyManagement()) { + resolved = mavenDependency; if (resolved.equals(newDependency)) { break; } diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/task/SecurityActions.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/task/SecurityActions.java index 16acd2953..249b6a7f4 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/task/SecurityActions.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/task/SecurityActions.java @@ -59,12 +59,7 @@ static ClassLoader getThreadContextClassLoader() { static String getProperty(final String key) { try { - String value = AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public String run() { - return System.getProperty(key); - } - }); + String value = AccessController.doPrivileged((PrivilegedExceptionAction) () -> System.getProperty(key)); return value; } // Unwrap @@ -93,12 +88,7 @@ public String run() { static Properties getProperties() { try { - return AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public Properties run() { - return System.getProperties(); - } - }); + return AccessController.doPrivileged((PrivilegedExceptionAction) System::getProperties); } // Unwrap catch (final PrivilegedActionException pae) { @@ -128,13 +118,8 @@ static URL getResource(final String resource) { // AccessController.doPrivileged(SecurityActions.GetTcclAction.INSTANCE).getResource(resourceName); try { - URL value = AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public URL run() { - return getThreadContextClassLoader().getResource(resource); - } - - }); + URL value = AccessController.doPrivileged((PrivilegedExceptionAction) + () -> getThreadContextClassLoader().getResource(resource)); return value; } diff --git a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/util/SecurityActions.java b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/util/SecurityActions.java index 7bae602a7..a48186aa9 100644 --- a/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/util/SecurityActions.java +++ b/maven/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/util/SecurityActions.java @@ -40,12 +40,7 @@ private SecurityActions() { static String getProperty(final String key) { try { - String value = AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public String run() { - return System.getProperty(key); - } - }); + String value = AccessController.doPrivileged((PrivilegedExceptionAction) () -> System.getProperty(key)); return value; } // Unwrap diff --git a/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/DefaultSettingsXmlLocationTestCase.java b/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/DefaultSettingsXmlLocationTestCase.java index edb8fe629..45698622c 100644 --- a/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/DefaultSettingsXmlLocationTestCase.java +++ b/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/DefaultSettingsXmlLocationTestCase.java @@ -84,19 +84,8 @@ private SettingsBuildingRequest createBuildingRequest() { Method m = clazz.getDeclaredMethod("getDefaultSettingsBuildingRequest"); m.setAccessible(true); return (SettingsBuildingRequest) m.invoke(builder); - } catch (SecurityException e) { - e.printStackTrace(); - Assert.fail("Unable to call getDefaultSettingsBuildingRequest via reflection, reason: " + e.getMessage()); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - Assert.fail("Unable to call getDefaultSettingsBuildingRequest via reflection, reason: " + e.getMessage()); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - Assert.fail("Unable to call getDefaultSettingsBuildingRequest via reflection, reason: " + e.getMessage()); - } catch (IllegalAccessException e) { - e.printStackTrace(); - Assert.fail("Unable to call getDefaultSettingsBuildingRequest via reflection, reason: " + e.getMessage()); - } catch (InvocationTargetException e) { + } catch (SecurityException | NoSuchMethodException | IllegalArgumentException | IllegalAccessException | + InvocationTargetException e) { e.printStackTrace(); Assert.fail("Unable to call getDefaultSettingsBuildingRequest via reflection, reason: " + e.getMessage()); } diff --git a/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/integration/DependenciesUnitTestCase.java b/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/integration/DependenciesUnitTestCase.java index e68da45e4..ce5a5e333 100644 --- a/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/integration/DependenciesUnitTestCase.java +++ b/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/integration/DependenciesUnitTestCase.java @@ -150,7 +150,7 @@ public void multipleResolution() { @Test public void multipleResolutionCollectionCanonicalForm() { - final Collection canonicalForms = new ArrayList(); + final Collection canonicalForms = new ArrayList<>(); canonicalForms.add("org.jboss.shrinkwrap.test:test-deps-c:1.0.0"); canonicalForms.add("org.jboss.shrinkwrap.test:test-deps-g:1.0.0"); File[] files = Maven.resolver().resolve(canonicalForms).withTransitivity().as(File.class); @@ -165,7 +165,7 @@ public void multipleResolutionCollectionCanonicalForm() { @Test public void multipleResolutionCollectionDependencies() { - final Collection dependencies = new ArrayList(); + final Collection dependencies = new ArrayList<>(); dependencies.add(MavenDependencies.createDependency("org.jboss.shrinkwrap.test:test-deps-c:1.0.0", null, false, (MavenDependencyExclusion) null)); dependencies.add(MavenDependencies.createDependency("org.jboss.shrinkwrap.test:test-deps-g:1.0.0", null, false, diff --git a/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/integration/MavenPlexusCipherTestCase.java b/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/integration/MavenPlexusCipherTestCase.java index 700dc9d46..3599a8e6f 100644 --- a/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/integration/MavenPlexusCipherTestCase.java +++ b/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/integration/MavenPlexusCipherTestCase.java @@ -69,7 +69,7 @@ public class MavenPlexusCipherTestCase { @Parameterized.Parameters public static Collection getParameters() { - List parameters = new ArrayList(); + List parameters = new ArrayList<>(); for (String decorator1 : DECORATION_VARIANTS) { for (String decorator2 : DECORATION_VARIANTS) { String decCombination = decorator1 + decorator2; diff --git a/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/util/ValidationUtil.java b/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/util/ValidationUtil.java index 925e42375..ec61b6ce2 100644 --- a/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/util/ValidationUtil.java +++ b/maven/impl-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/util/ValidationUtil.java @@ -25,7 +25,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; @@ -48,7 +47,7 @@ public class ValidationUtil { * {@link ValidationUtil#validate(File[])} calls. */ public ValidationUtil(final String... requiredFileNamePrefixes) { - this.requiredFileNamePrefixes = new ArrayList(requiredFileNamePrefixes.length); + this.requiredFileNamePrefixes = new ArrayList<>(requiredFileNamePrefixes.length); this.requiredFileNamePrefixes.addAll(Arrays.asList(requiredFileNamePrefixes)); } @@ -72,7 +71,7 @@ public static ValidationUtil fromDependencyTree(File dependencyTree, ScopeType.. */ public static ValidationUtil fromDependencyTree(File dependencyTree, boolean includeRoot, ScopeType... allowedScopesArray) throws IllegalArgumentException { - List allowedScopes = new ArrayList(); + List allowedScopes = new ArrayList<>(); for (ScopeType scope : allowedScopesArray) { allowedScopes.add(scope.toString()); } @@ -91,8 +90,8 @@ public static ValidationUtil fromDependencyTree(File dependencyTree, boolean inc public static ValidationUtil fromDependencyTree(final File dependencyTree, boolean includeRoot, final List allowedScopes) throws IllegalArgumentException { - List files = new ArrayList(); - final List realAllowedScopes = new ArrayList(); + List files = new ArrayList<>(); + final List realAllowedScopes = new ArrayList<>(); if (allowedScopes == null || allowedScopes.isEmpty()) { for (final ScopeType scope : ScopeType.values()) { realAllowedScopes.add(scope.toString()); @@ -101,10 +100,7 @@ public static ValidationUtil fromDependencyTree(final File dependencyTree, boole realAllowedScopes.addAll(allowedScopes); } - BufferedReader input = null; - try { - input = new BufferedReader(new FileReader(dependencyTree)); - + try (BufferedReader input = new BufferedReader(new FileReader(dependencyTree))) { String line = null; while ((line = input.readLine()) != null) { final ArtifactMetaData artifact = new ArtifactMetaData(line); @@ -129,16 +125,9 @@ else if (realAllowedScopes.contains(artifact.scope)) { } } catch (final IOException e) { throw new CoordinateParseException(MessageFormat.format( - "Unable to load dependency tree from {0} to verify", dependencyTree)); - } finally { - if (input != null) { - try { - input.close(); - } catch (final IOException ioe) { - // Swallow - } - } + "Unable to load dependency tree from {0} to verify", dependencyTree)); } + // Swallow return new ValidationUtil(files.toArray(new String[0])); } @@ -158,13 +147,13 @@ public void validate(final boolean validateOrder, final File... files) { public void validate(final boolean validateOrder, final List resolvedFiles) throws AssertionError { Assert.assertNotNull("There must be some files passed for validation, but the array was null", resolvedFiles); - final Collection resolvedFileNames = new ArrayList(resolvedFiles.size()); + final Collection resolvedFileNames = new ArrayList<>(resolvedFiles.size()); for (final File resolvedFile : resolvedFiles) { resolvedFileNames.add(resolvedFile.getName()); } - final Collection foundNotAllowed = new ArrayList(); - final Collection requiredNotFound = new ArrayList(); + final Collection foundNotAllowed = new ArrayList<>(); + final Collection requiredNotFound = new ArrayList<>(); // Check for resolved files found but not allowed for (final String resolvedFileName : resolvedFileNames) { @@ -182,15 +171,11 @@ public void validate(final boolean validateOrder, final List resolvedFiles // Check for required files not found in those resolved int i = 0; - Iterator requiredFileNamePrefixesIterator = this.requiredFileNamePrefixes.iterator(); - while (requiredFileNamePrefixesIterator.hasNext()) { - final String requiredFileName = requiredFileNamePrefixesIterator.next(); + for (String requiredFileName : this.requiredFileNamePrefixes) { i++; int j = 0; boolean found = false; - Iterator resolvedFileNamesIterator = resolvedFileNames.iterator(); - while (resolvedFileNamesIterator.hasNext()) { - final String resolvedFileName = resolvedFileNamesIterator.next(); + for (String resolvedFileName : resolvedFileNames) { j++; if (resolvedFileName.startsWith(requiredFileName)) { if (validateOrder && i == j) { diff --git a/maven/maven-plugin/src/main/java/org/jboss/shrinkwrap/resolver/plugin/DependencyTreeMojo.java b/maven/maven-plugin/src/main/java/org/jboss/shrinkwrap/resolver/plugin/DependencyTreeMojo.java index f86642a46..96a34e9b5 100644 --- a/maven/maven-plugin/src/main/java/org/jboss/shrinkwrap/resolver/plugin/DependencyTreeMojo.java +++ b/maven/maven-plugin/src/main/java/org/jboss/shrinkwrap/resolver/plugin/DependencyTreeMojo.java @@ -113,20 +113,11 @@ public void execute() { // write output to file if specified if (outputFile != null) { - FileWriter writer = null; - try { - writer = new FileWriter(outputFile); + try (FileWriter writer = new FileWriter(outputFile)) { writer.write(dependencyTree); getLog().info("Dependency tree output was writen into: " + outputFile.getAbsolutePath()); } catch (IOException e) { - } finally { - try { - if (writer != null) { - writer.close(); - } - } catch (IOException e) { - } } } // write an output to console @@ -165,7 +156,7 @@ private static String buildDependencyTree(StringBuilder sb, String indent, Maven // creates a class loader that has access to both current thread classloader and Maven Core classloader private ClassLoader getCombinedClassLoader(ClassRealmManager manager) { - List urlList = new ArrayList(); + List urlList = new ArrayList<>(); // add thread classpath ClassLoader threadCL = SecurityActions.getThreadContextClassLoader(); diff --git a/maven/maven-plugin/src/main/java/org/jboss/shrinkwrap/resolver/plugin/SecurityActions.java b/maven/maven-plugin/src/main/java/org/jboss/shrinkwrap/resolver/plugin/SecurityActions.java index 746e54ae1..040e2691e 100644 --- a/maven/maven-plugin/src/main/java/org/jboss/shrinkwrap/resolver/plugin/SecurityActions.java +++ b/maven/maven-plugin/src/main/java/org/jboss/shrinkwrap/resolver/plugin/SecurityActions.java @@ -52,12 +52,7 @@ private SecurityActions() { static String getProperty(final String key) { try { - String value = AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public String run() { - return System.getProperty(key); - } - }); + String value = AccessController.doPrivileged((PrivilegedExceptionAction) () -> System.getProperty(key)); return value; } // Unwrap @@ -86,12 +81,7 @@ public String run() { static Properties getProperties() { try { - return AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public Properties run() { - return System.getProperties(); - } - }); + return AccessController.doPrivileged((PrivilegedExceptionAction) System::getProperties); } // Unwrap catch (final PrivilegedActionException pae) { @@ -119,14 +109,11 @@ public Properties run() { static void addProperties(final Properties additionalProperties) { try { - AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public Void run() { - Properties properties = System.getProperties(); - properties.putAll(additionalProperties); - System.setProperties(properties); - return null; - } + AccessController.doPrivileged((PrivilegedExceptionAction) () -> { + Properties properties = System.getProperties(); + properties.putAll(additionalProperties); + System.setProperties(properties); + return null; }); } // Unwrap diff --git a/spi/src/main/java/org/jboss/shrinkwrap/resolver/spi/loader/SecurityActions.java b/spi/src/main/java/org/jboss/shrinkwrap/resolver/spi/loader/SecurityActions.java index f97a4a175..9f6d657fd 100644 --- a/spi/src/main/java/org/jboss/shrinkwrap/resolver/spi/loader/SecurityActions.java +++ b/spi/src/main/java/org/jboss/shrinkwrap/resolver/spi/loader/SecurityActions.java @@ -47,11 +47,8 @@ private SecurityActions() { static Constructor getConstructor(final Class clazz, final Class... argumentTypes) throws NoSuchMethodException { try { - return AccessController.doPrivileged(new PrivilegedExceptionAction>() { - public Constructor run() throws NoSuchMethodException { - return clazz.getConstructor(argumentTypes); - } - }); + return AccessController.doPrivileged((PrivilegedExceptionAction>) + () -> clazz.getConstructor(argumentTypes)); } // Unwrap catch (final PrivilegedActionException pae) { diff --git a/spi/src/main/java/org/jboss/shrinkwrap/resolver/spi/loader/ServiceRegistry.java b/spi/src/main/java/org/jboss/shrinkwrap/resolver/spi/loader/ServiceRegistry.java index 0b34f7784..7c4667e20 100644 --- a/spi/src/main/java/org/jboss/shrinkwrap/resolver/spi/loader/ServiceRegistry.java +++ b/spi/src/main/java/org/jboss/shrinkwrap/resolver/spi/loader/ServiceRegistry.java @@ -43,7 +43,7 @@ public class ServiceRegistry implements ServiceLoader { */ public ServiceRegistry(ServiceLoader serviceLoader) { this.serviceLoader = serviceLoader; - this.cachedServiceInstances = Collections.synchronizedMap(new HashMap, Collection>()); + this.cachedServiceInstances = Collections.synchronizedMap(new HashMap<>()); } /** diff --git a/spi/src/main/java/org/jboss/shrinkwrap/resolver/spi/loader/SpiServiceLoader.java b/spi/src/main/java/org/jboss/shrinkwrap/resolver/spi/loader/SpiServiceLoader.java index 0dcba1a7d..668f49a74 100644 --- a/spi/src/main/java/org/jboss/shrinkwrap/resolver/spi/loader/SpiServiceLoader.java +++ b/spi/src/main/java/org/jboss/shrinkwrap/resolver/spi/loader/SpiServiceLoader.java @@ -21,6 +21,7 @@ import java.io.InputStreamReader; import java.lang.reflect.Constructor; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Enumeration; import java.util.LinkedHashSet; @@ -137,17 +138,15 @@ public void setClassLoader(ClassLoader classLoader) { private Set> load(Class serviceClass) { String serviceFile = SERVICES + "/" + serviceClass.getName(); - LinkedHashSet> providers = new LinkedHashSet>(); + LinkedHashSet> providers = new LinkedHashSet<>(); try { Enumeration enumeration = classLoader.getResources(serviceFile); while (enumeration.hasMoreElements()) { final URL url = enumeration.nextElement(); final InputStream is = url.openStream(); - BufferedReader reader = null; - try { - reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { String line = reader.readLine(); while (null != line) { line = skipCommentAndTrim(line); @@ -171,10 +170,6 @@ private Set> load(Class serviceClass) { } line = reader.readLine(); } - } finally { - if (reader != null) { - reader.close(); - } } } } catch (Exception e) { @@ -194,7 +189,7 @@ private String skipCommentAndTrim(String line) { } private Set createInstances(Class serviceType, Set> providers) { - Set providerImpls = new LinkedHashSet(); + Set providerImpls = new LinkedHashSet<>(); for (Class serviceClass : providers) { // support enums as possible service providers if (serviceClass.isEnum()) {