001    package org.apache.maven.repository.legacy.resolver.conflict;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *  http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.codehaus.plexus.PlexusConstants;
023    import org.codehaus.plexus.PlexusContainer;
024    import org.codehaus.plexus.component.annotations.Component;
025    import org.codehaus.plexus.component.annotations.Requirement;
026    import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
027    import org.codehaus.plexus.context.Context;
028    import org.codehaus.plexus.context.ContextException;
029    import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
030    
031    /**
032     * A conflict resolver factory that obtains instances from a plexus container.
033     *
034     * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
035     * @todo you don't need the container in here with the active maps (jvz).
036     * @since 3.0
037     */
038    @Component( role = ConflictResolverFactory.class )
039    public class DefaultConflictResolverFactory
040        implements ConflictResolverFactory, Contextualizable
041    {
042        // fields -----------------------------------------------------------------
043    
044        /**
045         * The plexus container used to obtain instances from.
046         */
047        @Requirement
048        private PlexusContainer container;
049    
050        // ConflictResolverFactory methods ----------------------------------------
051    
052        /*
053        * @see org.apache.maven.artifact.resolver.conflict.ConflictResolverFactory#getConflictResolver(java.lang.String)
054        */
055    
056        public ConflictResolver getConflictResolver( String type )
057            throws ConflictResolverNotFoundException
058        {
059            try
060            {
061                return (ConflictResolver) container.lookup( ConflictResolver.ROLE, type );
062            }
063            catch ( ComponentLookupException exception )
064            {
065                throw new ConflictResolverNotFoundException( "Cannot find conflict resolver of type: " + type );
066            }
067        }
068    
069        // Contextualizable methods -----------------------------------------------
070    
071        /*
072         * @see org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable#contextualize(org.codehaus.plexus.context.Context)
073         */
074    
075        public void contextualize( Context context )
076            throws ContextException
077        {
078            container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
079        }
080    }