View Javadoc
1   package org.eclipse.aether.internal.impl.collect;
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 org.eclipse.aether.RepositorySystemSession;
23  import org.eclipse.aether.collection.CollectResult;
24  import org.eclipse.aether.graph.Dependency;
25  import org.eclipse.aether.util.ConfigUtils;
26  
27  class Results
28  {
29  
30      private final CollectResult result;
31  
32      private final int maxExceptions;
33  
34      private final int maxCycles;
35  
36      String errorPath;
37  
38      @SuppressWarnings( { "checkstyle:magicnumber" } )
39      Results( CollectResult result, RepositorySystemSession session )
40      {
41          this.result = result;
42          maxExceptions = ConfigUtils.getInteger( session, 50, DefaultDependencyCollector.CONFIG_PROP_MAX_EXCEPTIONS );
43          maxCycles = ConfigUtils.getInteger( session, 10, DefaultDependencyCollector.CONFIG_PROP_MAX_CYCLES );
44      }
45  
46      public void addException( Dependency dependency, Exception e, NodeStack nodes )
47      {
48          if ( maxExceptions < 0 || result.getExceptions().size() < maxExceptions )
49          {
50              result.addException( e );
51              if ( errorPath == null )
52              {
53                  StringBuilder buffer = new StringBuilder( 256 );
54                  for ( int i = 0; i < nodes.size(); i++ )
55                  {
56                      if ( buffer.length() > 0 )
57                      {
58                          buffer.append( " -> " );
59                      }
60                      Dependency dep = nodes.get( i ).getDependency();
61                      if ( dep != null )
62                      {
63                          buffer.append( dep.getArtifact() );
64                      }
65                  }
66                  if ( buffer.length() > 0 )
67                  {
68                      buffer.append( " -> " );
69                  }
70                  buffer.append( dependency.getArtifact() );
71                  errorPath = buffer.toString();
72              }
73          }
74      }
75  
76      public void addCycle( NodeStack nodes, int cycleEntry, Dependency dependency )
77      {
78          if ( maxCycles < 0 || result.getCycles().size() < maxCycles )
79          {
80              result.addCycle( new DefaultDependencyCycle( nodes, cycleEntry, dependency ) );
81          }
82      }
83  
84  }