001package 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 022import org.apache.maven.index.context.IndexCreator; 023import org.apache.maven.index.creator.JarFileContentsIndexCreator; 024import org.apache.maven.index.creator.MavenArchetypeArtifactInfoIndexCreator; 025import org.apache.maven.index.creator.MavenPluginArtifactInfoIndexCreator; 026import org.apache.maven.index.creator.MinimalArtifactInfoIndexCreator; 027import org.apache.maven.index.creator.OsgiArtifactIndexCreator; 028import org.slf4j.Logger; 029import org.slf4j.LoggerFactory; 030import org.springframework.stereotype.Service; 031 032import javax.inject.Inject; 033import java.util.ArrayList; 034import java.util.Arrays; 035import java.util.List; 036 037/** 038 * @author Olivier Lamy 039 * @since 1.4-M1 040 */ 041@Service( "mavenIndexerUtils" ) 042public 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}