This project has retired. For details please refer to its Attic page.
Source code
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.codehaus.plexus.digest.Digester;
023import org.codehaus.plexus.digest.Md5Digester;
024import org.codehaus.plexus.digest.Sha1Digester;
025import org.slf4j.Logger;
026import org.slf4j.LoggerFactory;
027import org.springframework.stereotype.Service;
028
029import javax.inject.Inject;
030import java.util.Arrays;
031import java.util.List;
032
033/**
034 * @author Olivier Lamy
035 * @since 1.4-M1
036 */
037@Service( "digesterUtils" )
038public class DigesterUtils
039{
040
041    private Logger log = LoggerFactory.getLogger( getClass() );
042
043    private List<? extends Digester> allDigesters;
044
045    @Inject
046    public DigesterUtils( PlexusSisuBridge plexusSisuBridge )
047        throws PlexusSisuBridgeException
048    {
049        this.allDigesters = plexusSisuBridge.lookupList( Digester.class );
050
051        if ( allDigesters == null || allDigesters.isEmpty() )
052        {
053            // olamy when the TCL is not a URLClassLoader lookupList fail !
054            // when using tomcat maven plugin so adding a simple hack
055            log.warn( "using lookupList from sisu plexus failed so build plexus Digesters manually" );
056
057            allDigesters = Arrays.asList( new Sha1Digester(), new Md5Digester() );
058
059        }
060
061        if ( allDigesters == null || allDigesters.isEmpty() )
062        {
063            throw  new PlexusSisuBridgeException( "no way to initiliaze IndexCreator" );
064        }
065
066        log.debug( "allIndexCreators {}", allDigesters );
067
068    }
069
070    public List<? extends Digester> getAllDigesters()
071    {
072        return allDigesters;
073    }
074
075    public void setAllDigesters( List<? extends Digester> allDigesters )
076    {
077        this.allDigesters = allDigesters;
078    }
079}