Coverage Report - org.apache.maven.archiva.dependency.DependencyGraphFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
DependencyGraphFactory
0%
0/48
0%
0/8
0
 
 1  
 package org.apache.maven.archiva.dependency;
 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.ArrayList;
 23  
 import java.util.List;
 24  
 
 25  
 import org.apache.maven.archiva.dependency.graph.DependencyGraph;
 26  
 import org.apache.maven.archiva.dependency.graph.DependencyGraphBuilder;
 27  
 import org.apache.maven.archiva.dependency.graph.GraphListener;
 28  
 import org.apache.maven.archiva.dependency.graph.GraphPhaseEvent;
 29  
 import org.apache.maven.archiva.dependency.graph.GraphTask;
 30  
 import org.apache.maven.archiva.dependency.graph.GraphTaskException;
 31  
 import org.apache.maven.archiva.dependency.graph.PotentialCyclicEdgeProducer;
 32  
 import org.apache.maven.archiva.dependency.graph.tasks.FlagCyclicEdgesTask;
 33  
 import org.apache.maven.archiva.dependency.graph.tasks.FlagExcludedEdgesTask;
 34  
 import org.apache.maven.archiva.dependency.graph.tasks.PopulateGraphMasterTask;
 35  
 import org.apache.maven.archiva.dependency.graph.tasks.ReduceEnabledEdgesTask;
 36  
 import org.apache.maven.archiva.dependency.graph.tasks.ReduceScopeTask;
 37  
 import org.apache.maven.archiva.dependency.graph.tasks.ReduceTransitiveEdgesTask;
 38  
 import org.apache.maven.archiva.dependency.graph.tasks.RefineConflictsTask;
 39  
 import org.apache.maven.archiva.dependency.graph.tasks.UpdateScopesTask;
 40  
 import org.apache.maven.archiva.model.DependencyScope;
 41  
 import org.apache.maven.archiva.model.VersionedReference;
 42  
 
 43  
 /**
 44  
  * DependencyGraphFactory 
 45  
  *
 46  
  * @version $Id: DependencyGraphFactory.java 755277 2009-03-17 15:18:35Z brett $
 47  
  */
 48  
 public class DependencyGraphFactory
 49  
 {
 50  
     private GraphTask taskFlagCyclicEdges;
 51  
 
 52  
     private PopulateGraphMasterTask taskPopulateGraph;
 53  
 
 54  
     private ReduceScopeTask taskReduceScope;
 55  
 
 56  
     private List<GraphListener> listeners;
 57  
 
 58  
     private DependencyGraphBuilder graphBuilder;
 59  
 
 60  
     private List<GraphTask> tasks;
 61  
 
 62  
     public DependencyGraphFactory()
 63  0
     {
 64  0
         listeners = new ArrayList<GraphListener>();
 65  
 
 66  0
         taskFlagCyclicEdges = new FlagCyclicEdgesTask();
 67  0
         taskPopulateGraph = new PopulateGraphMasterTask();
 68  0
         taskReduceScope = new ReduceScopeTask( DependencyScope.TEST );
 69  
 
 70  0
         tasks = new ArrayList<GraphTask>();
 71  
 
 72  
         /* Take the basic graph, and expand the nodes fully, including depman.
 73  
          */
 74  0
         tasks.add( taskPopulateGraph );
 75  
 
 76  
         /* Identify, flag, and disable excluded edges.
 77  
          */
 78  0
         tasks.add( new FlagExcludedEdgesTask() );
 79  
 
 80  
         /* Reduce the edges of the graph to only those that are enabled.
 81  
          */
 82  0
         tasks.add( new ReduceEnabledEdgesTask() );
 83  
 
 84  
         /* Identify dependencies that conflict, resolve to single node.
 85  
          * 
 86  
          * This will ...
 87  
          * 1) filter the distant conflicts away for the nearer ones.
 88  
          * 2) same distance nodes will pick 'newest' version.
 89  
          * 
 90  
          * This can cause a collapsing of node versions.
 91  
          */
 92  0
         tasks.add( new RefineConflictsTask() );
 93  
 
 94  
         /* Reduce the scope of the graph to those visible by the 'test' scope.
 95  
          */
 96  0
         tasks.add( taskReduceScope );
 97  
 
 98  
         /* Reduce the edges of the graph.  Use the transitive reduction algorithm
 99  
          * to remove redundant edges.
 100  
          */
 101  0
         tasks.add( new ReduceTransitiveEdgesTask() );
 102  
 
 103  
         /* Update the scopes of the edges to conform to the parent setting. 
 104  
          */
 105  0
         tasks.add( new UpdateScopesTask() );
 106  0
     }
 107  
 
 108  
     public void addGraphListener( GraphListener listener )
 109  
     {
 110  0
         this.listeners.add( listener );
 111  0
     }
 112  
 
 113  
     /**
 114  
      * Get the Graph for a specific Versioned Project Reference.
 115  
      * 
 116  
      * @param versionedProjectReference
 117  
      * @return
 118  
      */
 119  
     public DependencyGraph getGraph( VersionedReference versionedProjectReference )
 120  
         throws GraphTaskException
 121  
     {
 122  0
         DependencyGraph graph = graphBuilder.createGraph( versionedProjectReference );
 123  
 
 124  0
         triggerGraphPhase( GraphPhaseEvent.GRAPH_NEW, null, graph );
 125  
 
 126  0
         for ( GraphTask task : this.tasks )
 127  
         {
 128  
             try
 129  
             {
 130  0
                 triggerGraphPhase( GraphPhaseEvent.GRAPH_TASK_PRE, task, graph );
 131  0
                 task.executeTask( graph );
 132  0
                 if ( task instanceof PotentialCyclicEdgeProducer )
 133  
                 {
 134  0
                     taskFlagCyclicEdges.executeTask( graph );
 135  
                 }
 136  0
                 triggerGraphPhase( GraphPhaseEvent.GRAPH_TASK_POST, task, graph );
 137  
             }
 138  0
             catch ( GraphTaskException e )
 139  
             {
 140  0
                 triggerGraphError( e, graph );
 141  0
                 throw e;
 142  
             }
 143  0
             catch ( Exception e )
 144  
             {
 145  0
                 GraphTaskException gte = new GraphTaskException( e.getMessage(), e );
 146  0
                 triggerGraphError( gte, graph );
 147  0
                 throw gte;
 148  0
             }
 149  
         }
 150  
 
 151  0
         triggerGraphPhase( GraphPhaseEvent.GRAPH_DONE, null, graph );
 152  
 
 153  0
         return graph;
 154  
     }
 155  
 
 156  
     public void removeGraphListener( GraphListener listener )
 157  
     {
 158  0
         this.listeners.remove( listener );
 159  0
     }
 160  
 
 161  
     public void setDesiredScope( String scope )
 162  
     {
 163  0
         taskReduceScope.setScope( scope );
 164  0
     }
 165  
 
 166  
     public void setGraphBuilder( DependencyGraphBuilder graphBuilder )
 167  
     {
 168  0
         this.graphBuilder = graphBuilder;
 169  0
         taskPopulateGraph.setBuilder( graphBuilder );
 170  0
     }
 171  
 
 172  
     private void triggerGraphError( GraphTaskException e, DependencyGraph graph )
 173  
     {
 174  0
         for ( GraphListener listener : listeners )
 175  
         {
 176  0
             listener.graphError( e, graph );
 177  
         }
 178  0
     }
 179  
 
 180  
     private void triggerGraphPhase( int type, GraphTask task, DependencyGraph graph )
 181  
     {
 182  0
         GraphPhaseEvent evt = new GraphPhaseEvent( type, task, graph );
 183  
 
 184  0
         for ( GraphListener listener : listeners )
 185  
         {
 186  0
             listener.graphPhaseEvent( evt );
 187  
         }
 188  0
     }
 189  
 
 190  
 }