From 34348ecee0a3588037287df2cad9269e10975c40 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 20 Aug 2023 12:23:09 +0000 Subject: [PATCH] [MNG-6847] Use diamond operator As discussed on - https://github.com/apache/maven-scm/pull/184 - https://issues.apache.org/jira/browse/MNG-6847 Review requested of @elharo Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.staticanalysis.UseDiamondOperator?organizationId=QXBhY2hlIE1hdmVu Co-authored-by: Moderne --- .../tree/BuildingDependencyNodeVisitor.java | 4 +- .../TestCopyDependenciesMojo.java | 30 +++++++-------- .../TestCopyDependenciesMojo2.java | 18 ++++----- .../TestUnpackDependenciesMojo.java | 38 +++++++++---------- .../ResolveDependenciesMojoTest.java | 2 +- 5 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/dependency/tree/BuildingDependencyNodeVisitor.java b/src/main/java/org/apache/maven/plugins/dependency/tree/BuildingDependencyNodeVisitor.java index b2e3ef0e1..411a1fb5c 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/tree/BuildingDependencyNodeVisitor.java +++ b/src/main/java/org/apache/maven/plugins/dependency/tree/BuildingDependencyNodeVisitor.java @@ -70,7 +70,7 @@ public BuildingDependencyNodeVisitor() { public BuildingDependencyNodeVisitor(DependencyNodeVisitor visitor) { this.visitor = visitor; - parentNodes = new Stack(); + parentNodes = new Stack<>(); } // DependencyNodeVisitor methods ------------------------------------------ @@ -90,7 +90,7 @@ public boolean visit(DependencyNode node) { node.getOptional(), node.getExclusions(), node.toNodeString()); - newNode.setChildren(new ArrayList()); + newNode.setChildren(new ArrayList<>()); if (parentNodes.empty()) { rootNode = newNode; diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java index e8b5da787..b79a876b6 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java @@ -156,7 +156,7 @@ public void testNoTransitive() throws Exception { public void testExcludeType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeTypes = "jar"; mojo.execute(); @@ -170,7 +170,7 @@ public void testExcludeType() throws Exception { public void testIncludeType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeTypes = "jar"; mojo.excludeTypes = "jar"; @@ -198,7 +198,7 @@ public void testIncludeType() throws Exception { public void testExcludeArtifactId() throws Exception { mojo.getProject().setArtifacts(stubFactory.getArtifactArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeArtifactIds = "one"; mojo.execute(); @@ -212,7 +212,7 @@ public void testExcludeArtifactId() throws Exception { public void testIncludeArtifactId() throws Exception { mojo.getProject().setArtifacts(stubFactory.getArtifactArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeArtifactIds = "one"; mojo.excludeArtifactIds = "one"; @@ -240,7 +240,7 @@ public void testIncludeArtifactId() throws Exception { public void testIncludeGroupId() throws Exception { mojo.getProject().setArtifacts(stubFactory.getGroupIdArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeGroupIds = "one"; mojo.excludeGroupIds = "one"; // shouldn't get anything @@ -267,7 +267,7 @@ public void testIncludeGroupId() throws Exception { public void testExcludeGroupId() throws Exception { mojo.getProject().setArtifacts(stubFactory.getGroupIdArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeGroupIds = "one"; mojo.execute(); @@ -282,7 +282,7 @@ public void testExcludeGroupId() throws Exception { public void testExcludeMultipleGroupIds() throws Exception { mojo.getProject().setArtifacts(stubFactory.getGroupIdArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeGroupIds = "one,two"; mojo.execute(); @@ -298,7 +298,7 @@ public void testExcludeMultipleGroupIds() throws Exception { public void testExcludeClassifier() throws Exception { mojo.getProject().setArtifacts(stubFactory.getClassifiedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeClassifiers = "one"; mojo.execute(); @@ -312,7 +312,7 @@ public void testExcludeClassifier() throws Exception { public void testIncludeClassifier() throws Exception { mojo.getProject().setArtifacts(stubFactory.getClassifiedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeClassifiers = "one"; mojo.excludeClassifiers = "one"; @@ -340,7 +340,7 @@ public void testIncludeClassifier() throws Exception { public void testSubPerType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.useSubDirectoryPerType = true; mojo.execute(); @@ -555,7 +555,7 @@ public void testGetDependencies() throws MojoExecutionException { public void testExcludeProvidedScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeScope = "provided"; // mojo.silent = false; @@ -573,7 +573,7 @@ public void testExcludeProvidedScope() throws Exception { public void testExcludeSystemScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeScope = "system"; // mojo.silent = false; @@ -591,7 +591,7 @@ public void testExcludeSystemScope() throws Exception { public void testExcludeCompileScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeScope = "compile"; mojo.execute(); ScopeArtifactFilter saf = new ScopeArtifactFilter(mojo.excludeScope); @@ -607,7 +607,7 @@ public void testExcludeCompileScope() throws Exception { public void testExcludeTestScope() throws IOException, MojoFailureException { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeScope = "test"; try { @@ -620,7 +620,7 @@ public void testExcludeTestScope() throws IOException, MojoFailureException { public void testExcludeRuntimeScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeScope = "runtime"; mojo.execute(); ScopeArtifactFilter saf = new ScopeArtifactFilter(mojo.excludeScope); diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo2.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo2.java index 629cd811a..59b2b60fd 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo2.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo2.java @@ -82,7 +82,7 @@ protected void setUp() throws Exception { public void testCopyDependenciesMojoIncludeCompileScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeScope = "compile"; mojo.execute(); @@ -100,7 +100,7 @@ public void testCopyDependenciesMojoIncludeCompileScope() throws Exception { public void testCopyDependenciesMojoIncludeTestScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeScope = "test"; mojo.execute(); @@ -118,7 +118,7 @@ public void testCopyDependenciesMojoIncludeTestScope() throws Exception { public void testCopyDependenciesMojoIncludeRuntimeScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeScope = "runtime"; mojo.execute(); @@ -136,7 +136,7 @@ public void testCopyDependenciesMojoIncludeRuntimeScope() throws Exception { public void testCopyDependenciesMojoIncludeprovidedScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeScope = "provided"; mojo.execute(); @@ -152,7 +152,7 @@ public void testCopyDependenciesMojoIncludeprovidedScope() throws Exception { public void testCopyDependenciesMojoIncludesystemScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeScope = "system"; mojo.execute(); @@ -183,7 +183,7 @@ public void testSubPerArtifact() throws Exception { public void testSubPerArtifactAndType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.useSubDirectoryPerArtifact = true; mojo.useSubDirectoryPerType = true; @@ -201,7 +201,7 @@ public void testSubPerArtifactAndType() throws Exception { public void testSubPerArtifactAndScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.useSubDirectoryPerArtifact = true; mojo.useSubDirectoryPerScope = true; @@ -322,7 +322,7 @@ public void testSubPerArtifactRemoveVersion() throws Exception { public void testSubPerArtifactAndTypeRemoveVersion() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.useSubDirectoryPerArtifact = true; mojo.useSubDirectoryPerType = true; mojo.stripVersion = true; @@ -357,7 +357,7 @@ public void testSubPerArtifactRemoveType() throws Exception { public void testSubPerArtifactAndTypeRemoveType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.useSubDirectoryPerArtifact = true; mojo.useSubDirectoryPerType = true; mojo.stripType = true; diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java index 9f54efdda..c8e9f0dfe 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java @@ -139,7 +139,7 @@ public void testNoTransitive() throws Exception { public void testExcludeType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArchiveArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeTypes = "jar"; mojo.execute(); @@ -150,7 +150,7 @@ public void testExcludeType() throws Exception { public void testExcludeProvidedScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeScope = "provided"; // mojo.silent = false; @@ -163,7 +163,7 @@ public void testExcludeProvidedScope() throws Exception { public void testExcludeSystemScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeScope = "system"; // mojo.silent = false; @@ -176,7 +176,7 @@ public void testExcludeSystemScope() throws Exception { public void testExcludeCompileScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeScope = "compile"; mojo.execute(); ScopeArtifactFilter saf = new ScopeArtifactFilter(mojo.excludeScope); @@ -188,7 +188,7 @@ public void testExcludeCompileScope() throws Exception { public void testExcludeTestScope() throws IOException, MojoFailureException { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeScope = "test"; try { @@ -201,7 +201,7 @@ public void testExcludeTestScope() throws IOException, MojoFailureException { public void testExcludeRuntimeScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeScope = "runtime"; mojo.execute(); ScopeArtifactFilter saf = new ScopeArtifactFilter(mojo.excludeScope); @@ -213,7 +213,7 @@ public void testExcludeRuntimeScope() throws Exception { public void testIncludeType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArchiveArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeTypes = "jar"; mojo.excludeTypes = "jar"; @@ -241,7 +241,7 @@ public void testIncludeType() throws Exception { public void testSubPerType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArchiveArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.useSubDirectoryPerType = true; mojo.execute(); @@ -261,7 +261,7 @@ public void testSubPerArtifact() throws Exception { public void testSubPerArtifactAndType() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArchiveArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.useSubDirectoryPerArtifact = true; mojo.useSubDirectoryPerType = true; mojo.execute(); @@ -283,7 +283,7 @@ public void testSubPerArtifactRemoveVersion() throws Exception { public void testSubPerArtifactAndTypeRemoveVersion() throws Exception { mojo.getProject().setArtifacts(stubFactory.getTypedArchiveArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.useSubDirectoryPerArtifact = true; mojo.useSubDirectoryPerType = true; mojo.stripVersion = true; @@ -296,7 +296,7 @@ public void testSubPerArtifactAndTypeRemoveVersion() throws Exception { public void testIncludeCompileScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeScope = "compile"; mojo.execute(); ScopeArtifactFilter saf = new ScopeArtifactFilter(mojo.includeScope); @@ -308,7 +308,7 @@ public void testIncludeCompileScope() throws Exception { public void testIncludeTestScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeScope = "test"; mojo.execute(); @@ -321,7 +321,7 @@ public void testIncludeTestScope() throws Exception { public void testIncludeRuntimeScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeScope = "runtime"; mojo.execute(); ScopeArtifactFilter saf = new ScopeArtifactFilter(mojo.includeScope); @@ -333,7 +333,7 @@ public void testIncludeRuntimeScope() throws Exception { public void testIncludeprovidedScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeScope = "provided"; mojo.execute(); @@ -344,7 +344,7 @@ public void testIncludeprovidedScope() throws Exception { public void testIncludesystemScope() throws Exception { mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeScope = "system"; mojo.execute(); @@ -356,7 +356,7 @@ public void testIncludesystemScope() throws Exception { public void testIncludeArtifactId() throws Exception { mojo.getProject().setArtifacts(stubFactory.getArtifactArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeArtifactIds = "one"; mojo.excludeArtifactIds = "one"; @@ -380,7 +380,7 @@ public void testIncludeArtifactId() throws Exception { public void testExcludeArtifactId() throws Exception { mojo.getProject().setArtifacts(stubFactory.getArtifactArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeArtifactIds = "one"; mojo.execute(); @@ -394,7 +394,7 @@ public void testExcludeArtifactId() throws Exception { public void testExcludeGroupId() throws Exception { mojo.getProject().setArtifacts(stubFactory.getGroupIdArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.excludeGroupIds = "one"; mojo.execute(); @@ -405,7 +405,7 @@ public void testExcludeGroupId() throws Exception { public void testIncludeGroupId() throws Exception { mojo.getProject().setArtifacts(stubFactory.getGroupIdArtifacts()); - mojo.getProject().setDependencyArtifacts(new HashSet()); + mojo.getProject().setDependencyArtifacts(new HashSet<>()); mojo.includeGroupIds = "one"; mojo.excludeGroupIds = "one"; // shouldn't get anything diff --git a/src/test/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojoTest.java b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojoTest.java index b4de4fcb2..a9d3c6077 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojoTest.java @@ -45,7 +45,7 @@ public void testDependencyStatusLogNullFiles() throws IOException { } public void testDependencyStatusEmptySet() { - doTestDependencyStatusLog(new HashSet()); + doTestDependencyStatusLog(new HashSet<>()); } public void testOptionalDependencyFormatting() throws IOException {