1 package org.apache.maven.plugins.jdeps.consumers;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.util.HashMap;
23 import java.util.Map;
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
26
27 import org.codehaus.plexus.util.cli.CommandLineUtils;
28 import org.codehaus.plexus.util.cli.StreamConsumer;
29
30 /**
31 * Consumes the output of the jdeps tool
32 *
33 * @author Robert Scholte
34 *
35 */
36 public class JDepsConsumer
37 extends CommandLineUtils.StringStreamConsumer
38 implements StreamConsumer
39 {
40
41 /**
42 * JDK8 Windows: JDK internal API (rt.jar)
43 * JDK8 Linux: JDK internal API (JDK removed internal API)
44 * JDK9: JDK internal API (java.base)
45 */
46 private static final Pattern JDKINTERNALAPI = Pattern.compile( ".+->\\s([a-z\\.]+)\\s+(JDK internal API .+)" );
47
48 /**
49 * <dl>
50 * <dt>key</dt><dd>The offending package</dd>
51 * <dt>value</dt><dd>Offending details</dd>
52 * </dl>
53 */
54 private Map<String, String> offendingPackages = new HashMap<String, String>();
55
56 private static final Pattern PROFILE = Pattern.compile( "\\s+->\\s([a-z\\.]+)\\s+(\\S+)" );
57
58 /**
59 * <dl>
60 * <dt>key</dt><dd>The package</dd>
61 * <dt>value</dt><dd>The profile</dd>
62 * </dl>
63 */
64 private Map<String, String> profiles = new HashMap<String, String>();
65
66
67 public void consumeLine( String line )
68 {
69 super.consumeLine( line );
70 Matcher matcher;
71
72 matcher = JDKINTERNALAPI.matcher( line );
73 if ( matcher.matches() )
74 {
75 offendingPackages.put( matcher.group( 1 ), matcher.group( 2 ) );
76 return;
77 }
78
79 matcher = PROFILE.matcher( line );
80 if ( matcher.matches() )
81 {
82 profiles.put( matcher.group( 1 ), matcher.group( 2 ) );
83 return;
84 }
85 }
86
87 public Map<String, String> getOffendingPackages()
88 {
89 return offendingPackages;
90 }
91
92 public Map<String, String> getProfiles()
93 {
94 return profiles;
95 }
96
97 }