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.eclipse.aether.internal.impl.scope;
20  
21  import java.util.Comparator;
22  import java.util.stream.Collectors;
23  
24  import org.eclipse.aether.impl.scope.BuildScope;
25  import org.eclipse.aether.impl.scope.ScopeManagerConfiguration;
26  import org.eclipse.aether.scope.ResolutionScope;
27  
28  import static org.eclipse.aether.impl.scope.BuildScopeQuery.all;
29  
30  /**
31   * This is a diagnostic tool to dump out scope manager states.
32   */
33  public final class ScopeManagerDump {
34  
35      /**
36       * Invoke this method with configuration and this class will dump its interpretation.
37       */
38      public static void dump(ScopeManagerConfiguration configuration) {
39          new ScopeManagerDump(configuration);
40      }
41  
42      private ScopeManagerDump(ScopeManagerConfiguration configuration) {
43          ScopeManagerImpl scopeManager = new ScopeManagerImpl(configuration);
44          System.out.println();
45          dumpBuildScopes(scopeManager);
46          System.out.println();
47          dumpDependencyScopes(scopeManager);
48          System.out.println();
49          dumpDependencyScopeDerives(scopeManager);
50          System.out.println();
51          dumpResolutionScopes(scopeManager);
52      }
53  
54      private void dumpBuildScopes(ScopeManagerImpl scopeManager) {
55          System.out.println(scopeManager.getId() + " defined build scopes:");
56          scopeManager.getBuildScopeSource().query(all()).stream()
57                  .sorted(Comparator.comparing(BuildScope::order))
58                  .forEach(s -> System.out.println(s.getId() + " (order=" + s.order() + ")"));
59      }
60  
61      private void dumpDependencyScopes(ScopeManagerImpl scopeManager) {
62          System.out.println(scopeManager.getId() + " defined dependency scopes:");
63          scopeManager.getDependencyScopeUniverse().stream()
64                  .sorted(Comparator.comparing(scopeManager::getDependencyScopeWidth)
65                          .reversed())
66                  .forEach(s -> {
67                      System.out.println(s + " (width=" + scopeManager.getDependencyScopeWidth(s) + ")");
68                      System.out.println("  Query : " + scopeManager.getPresence(s));
69                      System.out.println("  Presence: "
70                              + scopeManager.getBuildScopeSource().query(scopeManager.getPresence(s)).stream()
71                                      .map(BuildScope::getId)
72                                      .collect(Collectors.toSet()));
73                      System.out.println("  Main project scope: "
74                              + scopeManager
75                                      .getDependencyScopeMainProjectBuildScope(s)
76                                      .map(BuildScope::getId)
77                                      .orElse("null"));
78                  });
79      }
80  
81      private void dumpDependencyScopeDerives(ScopeManagerImpl scopeManager) {
82          System.out.println(scopeManager.getId() + " defined dependency derive matrix:");
83          ManagedScopeDeriver deriver = new ManagedScopeDeriver(scopeManager);
84          scopeManager.getDependencyScopeUniverse().stream()
85                  .sorted(Comparator.comparing(scopeManager::getDependencyScopeWidth)
86                          .reversed())
87                  .forEach(parent -> scopeManager.getDependencyScopeUniverse().stream()
88                          .sorted(Comparator.comparing(scopeManager::getDependencyScopeWidth)
89                                  .reversed())
90                          .forEach(child -> System.out.println(parent.getId() + " w/ child " + child.getId() + " -> "
91                                  + deriver.getDerivedScope(parent.getId(), child.getId()))));
92      }
93  
94      private void dumpResolutionScopes(ScopeManagerImpl scopeManager) {
95          System.out.println(scopeManager.getId() + " defined resolution scopes:");
96          scopeManager.getResolutionScopeUniverse().stream()
97                  .sorted(Comparator.comparing(ResolutionScope::getId))
98                  .forEach(s -> {
99                      System.out.println("* " + s.getId());
100                     System.out.println("     Directly included: " + scopeManager.getDirectlyIncludedLabels(s));
101                     System.out.println("     Directly excluded: " + scopeManager.getDirectlyExcludedLabels(s));
102                     System.out.println(" Transitively excluded: " + scopeManager.getTransitivelyExcludedLabels(s));
103                 });
104     }
105 }