View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.shared.dependency.analyzer;
20  
21  import java.io.IOException;
22  import java.net.URL;
23  import java.util.Set;
24  import java.util.stream.Collectors;
25  
26  /**
27   * Gets the set of classes referenced by a library given either as a jar file or an exploded directory.
28   *
29   * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
30   */
31  public interface DependencyAnalyzer {
32  
33      /**
34       * <p>analyze.</p>
35       *
36       * @param url            the JAR file or directory to analyze
37       * @return the set of class names referenced by the library
38       * @throws IOException if an error occurs reading a JAR or .class file
39       */
40      default Set<String> analyze(URL url) throws IOException {
41          return analyze(url, new ClassesPatterns());
42      }
43  
44      /**
45       * <p>analyze.</p>
46       *
47       * @param url            the JAR file or directory to analyze
48       * @param excludeClasses a class list to exclude
49       * @return the set of class names referenced by the library
50       * @throws IOException if an error occurs reading a JAR or .class file
51       */
52      default Set<String> analyze(URL url, ClassesPatterns excludeClasses) throws IOException {
53          return analyzeUsages(url, excludeClasses).stream()
54                  .map(DependencyUsage::getDependencyClass)
55                  .collect(Collectors.toSet());
56      }
57  
58      /**
59       * <p>analyzeUsages.</p>
60       *
61       * @param url the JAR file or directory to analyze
62       * @return the set of class names referenced by the library, paired with the
63       * classes declaring those references.
64       * @throws IOException if an error occurs reading a JAR or .class file
65       */
66      Set<DependencyUsage> analyzeUsages(URL url, ClassesPatterns excludeClasses) throws IOException;
67  }