This project has retired. For details please refer to its Attic page.
DigesterUtils 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.codehaus.plexus.digest.Digester;
23  import org.codehaus.plexus.digest.Md5Digester;
24  import org.codehaus.plexus.digest.Sha1Digester;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  import org.springframework.stereotype.Service;
28  
29  import javax.inject.Inject;
30  import java.util.Arrays;
31  import java.util.List;
32  
33  /**
34   * @author Olivier Lamy
35   * @since 1.4-M1
36   */
37  @Service( "digesterUtils" )
38  public class DigesterUtils
39  {
40  
41      private Logger log = LoggerFactory.getLogger( getClass() );
42  
43      private List<? extends Digester> allDigesters;
44  
45      @Inject
46      public DigesterUtils( PlexusSisuBridge plexusSisuBridge )
47          throws PlexusSisuBridgeException
48      {
49          this.allDigesters = plexusSisuBridge.lookupList( Digester.class );
50  
51          if ( allDigesters == null || allDigesters.isEmpty() )
52          {
53              // olamy when the TCL is not a URLClassLoader lookupList fail !
54              // when using tomcat maven plugin so adding a simple hack
55              log.warn( "using lookupList from sisu plexus failed so build plexus Digesters manually" );
56  
57              allDigesters = Arrays.asList( new Sha1Digester(), new Md5Digester() );
58  
59          }
60  
61          if ( allDigesters == null || allDigesters.isEmpty() )
62          {
63              throw  new PlexusSisuBridgeException( "no way to initiliaze IndexCreator" );
64          }
65  
66          log.debug( "allIndexCreators {}", allDigesters );
67  
68      }
69  
70      public List<? extends Digester> getAllDigesters()
71      {
72          return allDigesters;
73      }
74  
75      public void setAllDigesters( List<? extends Digester> allDigesters )
76      {
77          this.allDigesters = allDigesters;
78      }
79  }