View Javadoc
1   package org.apache.maven.repository.legacy.resolver.conflict;
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.codehaus.plexus.PlexusConstants;
23  import org.codehaus.plexus.PlexusContainer;
24  import org.codehaus.plexus.component.annotations.Component;
25  import org.codehaus.plexus.component.annotations.Requirement;
26  import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
27  import org.codehaus.plexus.context.Context;
28  import org.codehaus.plexus.context.ContextException;
29  import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
30  
31  /**
32   * A conflict resolver factory that obtains instances from a plexus container.
33   *
34   * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
35   * @todo you don't need the container in here with the active maps (jvz).
36   * @since 3.0
37   */
38  @Component( role = ConflictResolverFactory.class )
39  public class DefaultConflictResolverFactory
40      implements ConflictResolverFactory, Contextualizable
41  {
42      // fields -----------------------------------------------------------------
43  
44      /**
45       * The plexus container used to obtain instances from.
46       */
47      @Requirement
48      private PlexusContainer container;
49  
50      // ConflictResolverFactory methods ----------------------------------------
51  
52      /*
53      * @see org.apache.maven.artifact.resolver.conflict.ConflictResolverFactory#getConflictResolver(java.lang.String)
54      */
55  
56      public ConflictResolver getConflictResolver( String type )
57          throws ConflictResolverNotFoundException
58      {
59          try
60          {
61              return (ConflictResolver) container.lookup( ConflictResolver.ROLE, type );
62          }
63          catch ( ComponentLookupException exception )
64          {
65              throw new ConflictResolverNotFoundException( "Cannot find conflict resolver of type: " + type );
66          }
67      }
68  
69      // Contextualizable methods -----------------------------------------------
70  
71      /*
72       * @see org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable#contextualize(org.codehaus.plexus.context.Context)
73       */
74  
75      public void contextualize( Context context )
76          throws ContextException
77      {
78          container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
79      }
80  }