View Javadoc

1   package org.apache.maven.jelly.tags.maven;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  import java.util.Iterator;
22  import java.util.List;
23  
24  import org.apache.maven.project.Project;
25  
26  /**
27   * @author <a href="mailto:bwalding@apache.org">Ben Walding</a>
28   * @version $Id: DependencyResolver.java 517014 2007-03-11 21:15:50Z ltheussl $
29   */
30  public class DependencyResolver
31      implements DependencyResolverInterface
32  {
33  
34      private final DependencyResolverInterface impl;
35  
36      /**
37       * Creates the dependency resolver. The implementation is chosen by the
38       * System property "maven.core.dependencyresolver".  By default it is
39       * the WerkzDependencyResolver. Ultimately I see this proxy being removed.
40       *
41       * @see java.lang.Object#Object()
42       */
43      public DependencyResolver()
44      {
45          String prop = "maven.core.dependencyresolver";
46          String type = System.getProperty( prop );
47          try
48          {
49  
50              if ( type == null )
51              {
52                  impl = new WerkzDependencyResolver();
53              }
54              else
55              {
56                  impl = (DependencyResolverInterface) Class.forName( type ).newInstance();
57              }
58          }
59          catch ( Exception e )
60          {
61              throw new RuntimeException( "Unable to create " + type );
62          }
63      }
64  
65      /**
66       * Creates the dependency resolver with a specific implementation
67       *
68       * @param impl
69       */
70      public DependencyResolver( DependencyResolverInterface impl )
71      {
72          this.impl = impl;
73      }
74  
75      /**
76       * @see org.apache.maven.jelly.tags.maven.DependencyResolverInterface#clear()
77       */
78      public void clear()
79      {
80          impl.clear();
81      }
82  
83      /**
84       * @see org.apache.maven.jelly.tags.maven.DependencyResolverInterface#setProjects(java.util.List)
85       */
86      public void setProjects( List projects )
87      {
88          impl.setProjects( projects );
89      }
90  
91      /**
92       * @see org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(org.apache.maven.project.Project)
93       */
94      public List getSortedDependencies( Project project )
95          throws DependencyResolverException
96      {
97          return impl.getSortedDependencies( project );
98      }
99  
100     /**
101      * @see org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(org.apache.maven.project.Project, boolean)
102      */
103     public List getSortedDependencies( Project project, boolean sourceBuild )
104         throws DependencyResolverException
105     {
106         return impl.getSortedDependencies( project, sourceBuild );
107     }
108 
109     /**
110      * @see org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(boolean)
111      */
112     public List getSortedDependencies( boolean sourceBuild )
113         throws DependencyResolverException
114     {
115         return impl.getSortedDependencies( sourceBuild );
116     }
117 
118     public static Project getProject( List projects, String id )
119     {
120         Iterator iter = projects.iterator();
121         while ( iter.hasNext() )
122         {
123             Project project = (Project) iter.next();
124             if ( project.getId().equals( id ) )
125             {
126                 return project;
127             }
128         }
129         return null;
130 
131     }
132 
133 }