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 * @version $Id: DefaultConflictResolverFactory.java 958295 2010-06-26 23:16:18Z hboutemy $
36 * @todo you don't need the container in here with the active maps (jvz).
37 * @since 3.0
38 */
39 @Component( role = ConflictResolverFactory.class )
40 public class DefaultConflictResolverFactory
41 implements ConflictResolverFactory, Contextualizable
42 {
43 // fields -----------------------------------------------------------------
44
45 /**
46 * The plexus container used to obtain instances from.
47 */
48 @Requirement
49 private PlexusContainer container;
50
51 // ConflictResolverFactory methods ----------------------------------------
52
53 /*
54 * @see org.apache.maven.artifact.resolver.conflict.ConflictResolverFactory#getConflictResolver(java.lang.String)
55 */
56
57 public ConflictResolver getConflictResolver( String type )
58 throws ConflictResolverNotFoundException
59 {
60 try
61 {
62 return (ConflictResolver) container.lookup( ConflictResolver.ROLE, type );
63 }
64 catch ( ComponentLookupException exception )
65 {
66 throw new ConflictResolverNotFoundException( "Cannot find conflict resolver of type: " + type );
67 }
68 }
69
70 // Contextualizable methods -----------------------------------------------
71
72 /*
73 * @see org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable#contextualize(org.codehaus.plexus.context.Context)
74 */
75
76 public void contextualize( Context context )
77 throws ContextException
78 {
79 container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
80 }
81 }