This project has retired. For details please refer to its Attic page.
MavenIndexerUtils xref
View Javadoc
1   package org.apache.archiva.common.plexusbridge;
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.apache.maven.index.context.IndexCreator;
23  import org.apache.maven.index.creator.JarFileContentsIndexCreator;
24  import org.apache.maven.index.creator.MavenArchetypeArtifactInfoIndexCreator;
25  import org.apache.maven.index.creator.MavenPluginArtifactInfoIndexCreator;
26  import org.apache.maven.index.creator.MinimalArtifactInfoIndexCreator;
27  import org.apache.maven.index.creator.OsgiArtifactIndexCreator;
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  import org.springframework.stereotype.Service;
31  
32  import javax.inject.Inject;
33  import java.util.ArrayList;
34  import java.util.Arrays;
35  import java.util.List;
36  
37  /**
38   * @author Olivier Lamy
39   * @since 1.4-M1
40   */
41  @Service( "mavenIndexerUtils" )
42  public class MavenIndexerUtils
43  {
44  
45      private Logger log = LoggerFactory.getLogger( getClass() );
46  
47      private List<? extends IndexCreator> allIndexCreators;
48  
49      @Inject
50      public MavenIndexerUtils( PlexusSisuBridge plexusSisuBridge )
51          throws PlexusSisuBridgeException
52      {
53          allIndexCreators = new ArrayList( plexusSisuBridge.lookupList( IndexCreator.class ) );
54  
55          if ( allIndexCreators == null || allIndexCreators.isEmpty() )
56          {
57              // olamy when the TCL is not a URLClassLoader lookupList fail !
58              // when using tomcat maven plugin so adding a simple hack
59              log.warn( "using lookupList from sisu plexus failed so build indexCreator manually" );
60  
61              allIndexCreators =
62                  Arrays.asList( plexusSisuBridge.lookup( IndexCreator.class, OsgiArtifactIndexCreator.ID ),
63                                 plexusSisuBridge.lookup( IndexCreator.class, MavenArchetypeArtifactInfoIndexCreator.ID ),
64                                 plexusSisuBridge.lookup( IndexCreator.class, MinimalArtifactInfoIndexCreator.ID ),
65                                 plexusSisuBridge.lookup( IndexCreator.class, JarFileContentsIndexCreator.ID ),
66                                 plexusSisuBridge.lookup( IndexCreator.class, MavenPluginArtifactInfoIndexCreator.ID ) );
67  
68          }
69  
70          if ( allIndexCreators == null || allIndexCreators.isEmpty() )
71          {
72              throw new PlexusSisuBridgeException( "no way to initiliaze IndexCreator" );
73          }
74  
75          log.debug( "allIndexCreators {}", allIndexCreators );
76      }
77  
78      public List<? extends IndexCreator> getAllIndexCreators()
79      {
80          return allIndexCreators;
81      }
82  
83      public void setAllIndexCreators( List<IndexCreator> allIndexCreators )
84      {
85          this.allIndexCreators = allIndexCreators;
86      }
87  }