This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-jdeprscan-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new a57eda2  Remove duplicate code snippet, extract into method.
a57eda2 is described below

commit a57eda25b7b0196d2deae2752c502cf006f9e057
Author: Benjamin Marwell <[email protected]>
AuthorDate: Fri Feb 26 17:13:59 2021 +0100

    Remove duplicate code snippet, extract into method.
    
     - Convert line breaks to unix
---
 .../maven/plugins/jdeprscan/BaseJDeprScanMojo.java |   3 +-
 .../maven/plugins/jdeprscan/JDeprScanMojo.java     |   3 +-
 .../maven/plugins/jdeprscan/TestJDeprScanMojo.java |   3 +-
 .../jdeprscan/consumers/JDeprScanConsumer.java     | 183 ++++++++++-----------
 4 files changed, 94 insertions(+), 98 deletions(-)

diff --git 
a/src/main/java/org/apache/maven/plugins/jdeprscan/BaseJDeprScanMojo.java 
b/src/main/java/org/apache/maven/plugins/jdeprscan/BaseJDeprScanMojo.java
index 763d90e..f9fa9d7 100644
--- a/src/main/java/org/apache/maven/plugins/jdeprscan/BaseJDeprScanMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jdeprscan/BaseJDeprScanMojo.java
@@ -29,13 +29,12 @@ import java.util.Set;
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
-
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.jdeprscan.consumers.JDeprScanConsumer;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.cli.Commandline;
 import org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer;
+import org.codehaus.plexus.util.cli.Commandline;
 
 /**
  * Base class for all explicit jdeprscan mojos
diff --git 
a/src/main/java/org/apache/maven/plugins/jdeprscan/JDeprScanMojo.java 
b/src/main/java/org/apache/maven/plugins/jdeprscan/JDeprScanMojo.java
index 7da7982..2d85ff3 100644
--- a/src/main/java/org/apache/maven/plugins/jdeprscan/JDeprScanMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jdeprscan/JDeprScanMojo.java
@@ -22,6 +22,7 @@ package org.apache.maven.plugins.jdeprscan;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
@@ -59,6 +60,6 @@ public class JDeprScanMojo extends BaseJDeprScanMojo
             classPath.add( Paths.get( elm ) );
         }
 
-        return classPath;
+        return Collections.unmodifiableSet( classPath );
     }
 }
diff --git 
a/src/main/java/org/apache/maven/plugins/jdeprscan/TestJDeprScanMojo.java 
b/src/main/java/org/apache/maven/plugins/jdeprscan/TestJDeprScanMojo.java
index 88cee58..dc17851 100644
--- a/src/main/java/org/apache/maven/plugins/jdeprscan/TestJDeprScanMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jdeprscan/TestJDeprScanMojo.java
@@ -22,6 +22,7 @@ package org.apache.maven.plugins.jdeprscan;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
@@ -59,6 +60,6 @@ public class TestJDeprScanMojo extends BaseJDeprScanMojo
             classPath.add( Paths.get( elm ) );
         }
 
-        return classPath;
+        return Collections.unmodifiableSet( classPath );
     }
 }
diff --git 
a/src/main/java/org/apache/maven/plugins/jdeprscan/consumers/JDeprScanConsumer.java
 
b/src/main/java/org/apache/maven/plugins/jdeprscan/consumers/JDeprScanConsumer.java
index 1a5d51c..188b6b8 100644
--- 
a/src/main/java/org/apache/maven/plugins/jdeprscan/consumers/JDeprScanConsumer.java
+++ 
b/src/main/java/org/apache/maven/plugins/jdeprscan/consumers/JDeprScanConsumer.java
@@ -1,94 +1,89 @@
-package org.apache.maven.plugins.jdeprscan.consumers;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.codehaus.plexus.util.cli.CommandLineUtils;
-import org.codehaus.plexus.util.cli.StreamConsumer;
-
-/**
- * Consumes output of jdeprscan tool
- * 
- * @author Robert Scholte
- * @since 3.0.0
- */
-public class JDeprScanConsumer
-    extends CommandLineUtils.StringStreamConsumer
-    implements StreamConsumer
-{
-
-    private Map<String, Set<String>> deprecatedClasses = new HashMap<>();
-
-    private Map<String, Set<String>> deprecatedMethods = new HashMap<>();
-
-    public static final Pattern DEPRECATED_CLASS = Pattern.compile( "^class 
(\\S+) uses deprecated class (\\S+)" );
-
-    public static final Pattern DEPRECATED_METHOD = Pattern.compile( "^class 
(\\S+) uses deprecated method (\\S+)" );
-
-    public Map<String, Set<String>> getDeprecatedClasses()
-    {
-        return deprecatedClasses;
-    }
-    
-    public Map<String, Set<String>> getDeprecatedMethods()
-    {
-        return deprecatedMethods;
-    }
-    
-    @Override
-    public void consumeLine( String line )
-    {
-        super.consumeLine( line );
-
-        Matcher matcher;
-        
-        matcher = DEPRECATED_CLASS.matcher( line );
-        if ( matcher.find() )
-        {
-            Set<String> dc = deprecatedClasses.get( matcher.group( 1 ) );
-            if ( dc == null )
-            {
-                dc = new HashSet<>();
-                deprecatedClasses.put( matcher.group( 1 ), dc );
-            }
-            dc.add( matcher.group( 2 ) );
-            return;
-        }
-        
-        matcher = DEPRECATED_METHOD.matcher( line );
-        if ( matcher.find() )
-        {
-            Set<String> dm = deprecatedMethods.get( matcher.group( 1 ) );
-            if ( dm == null )
-            {
-                dm = new HashSet<>();
-                deprecatedMethods.put( matcher.group( 1 ), dm );
-            }
-            dm.add( matcher.group( 2 ) );
-            return;
-        }
-    }
-}
+package org.apache.maven.plugins.jdeprscan.consumers;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.StreamConsumer;
+
+/**
+ * Consumes output of jdeprscan tool
+ * 
+ * @author Robert Scholte
+ * @since 3.0.0
+ */
+public class JDeprScanConsumer
+    extends CommandLineUtils.StringStreamConsumer
+    implements StreamConsumer
+{
+
+    private final Map<String, Set<String>> deprecatedClasses = new HashMap<>();
+
+    private final Map<String, Set<String>> deprecatedMethods = new HashMap<>();
+
+    public static final Pattern DEPRECATED_CLASS = Pattern.compile( "^class 
(\\S+) uses deprecated class (\\S+)" );
+
+    public static final Pattern DEPRECATED_METHOD = Pattern.compile( "^class 
(\\S+) uses deprecated method (\\S+)" );
+
+    public Map<String, Set<String>> getDeprecatedClasses( )
+    {
+        return Collections.unmodifiableMap( deprecatedClasses );
+    }
+
+    public Map<String, Set<String>> getDeprecatedMethods( )
+    {
+        return Collections.unmodifiableMap( deprecatedMethods );
+    }
+
+    @Override
+    public void consumeLine( String line )
+    {
+        super.consumeLine( line );
+
+        Matcher deprecatedClassMatcher = DEPRECATED_CLASS.matcher( line );
+        matcherCollector( deprecatedClassMatcher, deprecatedClasses );
+
+        Matcher deprecatedMethodMatcher = DEPRECATED_METHOD.matcher( line );
+        matcherCollector( deprecatedMethodMatcher, deprecatedMethods );
+    }
+
+    private void matcherCollector( Matcher matcher, Map<String, Set<String>> 
deprecatedMethods )
+    {
+        if ( !matcher.find() )
+        {
+            return;
+        }
+
+        Set<String> dm = deprecatedMethods.get( matcher.group( 1 ) );
+        if ( dm == null )
+        {
+            dm = new HashSet<>();
+            deprecatedMethods.put( matcher.group( 1 ), dm );
+        }
+        dm.add( matcher.group( 2 ) );
+    }
+}

Reply via email to