001    package org.apache.archiva.common.plexusbridge;
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.apache.maven.index.context.IndexCreator;
023    import org.apache.maven.index.creator.JarFileContentsIndexCreator;
024    import org.apache.maven.index.creator.MavenArchetypeArtifactInfoIndexCreator;
025    import org.apache.maven.index.creator.MavenPluginArtifactInfoIndexCreator;
026    import org.apache.maven.index.creator.MinimalArtifactInfoIndexCreator;
027    import org.apache.maven.index.creator.OsgiArtifactIndexCreator;
028    import org.slf4j.Logger;
029    import org.slf4j.LoggerFactory;
030    import org.springframework.stereotype.Service;
031    
032    import javax.inject.Inject;
033    import java.util.ArrayList;
034    import java.util.Arrays;
035    import java.util.List;
036    
037    /**
038     * @author Olivier Lamy
039     * @since 1.4-M1
040     */
041    @Service( "mavenIndexerUtils" )
042    public class MavenIndexerUtils
043    {
044    
045        private Logger log = LoggerFactory.getLogger( getClass() );
046    
047        private List<? extends IndexCreator> allIndexCreators;
048    
049        @Inject
050        public MavenIndexerUtils( PlexusSisuBridge plexusSisuBridge )
051            throws PlexusSisuBridgeException
052        {
053            allIndexCreators = new ArrayList( plexusSisuBridge.lookupList( IndexCreator.class ) );
054    
055            if ( allIndexCreators == null || allIndexCreators.isEmpty() )
056            {
057                // olamy when the TCL is not a URLClassLoader lookupList fail !
058                // when using tomcat maven plugin so adding a simple hack
059                log.warn( "using lookupList from sisu plexus failed so build indexCreator manually" );
060    
061                allIndexCreators =
062                    Arrays.asList( plexusSisuBridge.lookup( IndexCreator.class, OsgiArtifactIndexCreator.ID ),
063                                   plexusSisuBridge.lookup( IndexCreator.class, MavenArchetypeArtifactInfoIndexCreator.ID ),
064                                   plexusSisuBridge.lookup( IndexCreator.class, MinimalArtifactInfoIndexCreator.ID ),
065                                   plexusSisuBridge.lookup( IndexCreator.class, JarFileContentsIndexCreator.ID ),
066                                   plexusSisuBridge.lookup( IndexCreator.class, MavenPluginArtifactInfoIndexCreator.ID ) );
067    
068            }
069    
070            if ( allIndexCreators == null || allIndexCreators.isEmpty() )
071            {
072                throw new PlexusSisuBridgeException( "no way to initiliaze IndexCreator" );
073            }
074    
075            log.debug( "allIndexCreators {}", allIndexCreators );
076        }
077    
078        public List<? extends IndexCreator> getAllIndexCreators()
079        {
080            return allIndexCreators;
081        }
082    
083        public void setAllIndexCreators( List<IndexCreator> allIndexCreators )
084        {
085            this.allIndexCreators = allIndexCreators;
086        }
087    }