1 package org.apache.maven.plugins.jdeprscan.consumers;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.HashMap;
23 import java.util.HashSet;
24 import java.util.Map;
25 import java.util.Set;
26 import java.util.regex.Matcher;
27 import java.util.regex.Pattern;
28
29 import org.codehaus.plexus.util.cli.CommandLineUtils;
30 import org.codehaus.plexus.util.cli.StreamConsumer;
31
32
33
34
35
36
37
38 public class JDeprScanConsumer
39 extends CommandLineUtils.StringStreamConsumer
40 implements StreamConsumer
41 {
42
43 private Map<String, Set<String>> deprecatedClasses = new HashMap<>();
44
45 private Map<String, Set<String>> deprecatedMethods = new HashMap<>();
46
47 public static final Pattern DEPRECATED_CLASS = Pattern.compile( "^class (\\S+) uses deprecated class (\\S+)" );
48
49 public static final Pattern DEPRECATED_METHOD = Pattern.compile( "^class (\\S+) uses deprecated method (\\S+)" );
50
51 public Map<String, Set<String>> getDeprecatedClasses()
52 {
53 return deprecatedClasses;
54 }
55
56 public Map<String, Set<String>> getDeprecatedMethods()
57 {
58 return deprecatedMethods;
59 }
60
61 @Override
62 public void consumeLine( String line )
63 {
64 super.consumeLine( line );
65
66 Matcher matcher;
67
68 matcher = DEPRECATED_CLASS.matcher( line );
69 if ( matcher.find() )
70 {
71 Set<String> dc = deprecatedClasses.get( matcher.group( 1 ) );
72 if ( dc == null )
73 {
74 dc = new HashSet<>();
75 deprecatedClasses.put( matcher.group( 1 ), dc );
76 }
77 dc.add( matcher.group( 2 ) );
78 return;
79 }
80
81 matcher = DEPRECATED_METHOD.matcher( line );
82 if ( matcher.find() )
83 {
84 Set<String> dm = deprecatedMethods.get( matcher.group( 1 ) );
85 if ( dm == null )
86 {
87 dm = new HashSet<>();
88 deprecatedMethods.put( matcher.group( 1 ), dm );
89 }
90 dm.add( matcher.group( 2 ) );
91 return;
92 }
93 }
94 }