This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.converter.legacy;
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.archiva.common.filelock.FileLockManager;
023import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
024import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
025import org.apache.archiva.configuration.FileTypes;
026import org.apache.archiva.consumers.AbstractMonitoredConsumer;
027import org.apache.archiva.consumers.ConsumerException;
028import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
029import org.apache.archiva.converter.artifact.ArtifactConversionException;
030import org.apache.archiva.converter.artifact.ArtifactConverter;
031import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
032import org.apache.archiva.model.ArtifactReference;
033import org.apache.archiva.repository.LayoutException;
034import org.apache.archiva.repository.ManagedRepository;
035import org.apache.archiva.repository.ManagedRepositoryContent;
036import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent;
037import org.apache.maven.artifact.Artifact;
038import org.apache.maven.artifact.factory.ArtifactFactory;
039import org.apache.maven.artifact.repository.ArtifactRepository;
040import org.slf4j.Logger;
041import org.slf4j.LoggerFactory;
042import org.springframework.context.annotation.Scope;
043import org.springframework.stereotype.Service;
044
045import javax.inject.Inject;
046import javax.inject.Named;
047import java.util.ArrayList;
048import java.util.Date;
049import java.util.List;
050
051/**
052 * LegacyConverterArtifactConsumer - convert artifacts as they are found
053 * into the destination repository.
054 *
055 *
056 */
057@Service( "knownRepositoryContentConsumer#artifact-legacy-to-default-converter" )
058@Scope( "prototype" )
059public class LegacyConverterArtifactConsumer
060    extends AbstractMonitoredConsumer
061    implements KnownRepositoryContentConsumer
062{
063    private Logger log = LoggerFactory.getLogger( LegacyConverterArtifactConsumer.class );
064
065    @Inject
066    @Named("artifactConverter#legacy-to-default")
067    private ArtifactConverter artifactConverter;
068
069    @Inject
070    private List<? extends ArtifactMappingProvider> artifactMappingProviders;
071
072    @Inject
073    private FileTypes fileTypes;
074
075    @Inject
076    private FileLockManager fileLockManager;
077
078    private ArtifactFactory artifactFactory;
079
080    private ManagedRepositoryContent managedRepository;
081
082    private ArtifactRepository destinationRepository;
083
084    private List<String> includes;
085
086    private List<String> excludes;
087
088    @Inject
089    public LegacyConverterArtifactConsumer( PlexusSisuBridge plexusSisuBridge )
090        throws PlexusSisuBridgeException
091    {
092        includes = new ArrayList<>( 3 );
093        includes.add( "**/*.jar" );
094        includes.add( "**/*.ear" );
095        includes.add( "**/*.war" );
096        artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class );
097    }
098
099    @Override
100    public void beginScan( ManagedRepository repository, Date whenGathered )
101        throws ConsumerException
102    {
103        this.managedRepository = new ManagedDefaultRepositoryContent(repository, artifactMappingProviders, fileTypes, fileLockManager);
104    }
105
106    @Override
107    public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
108        throws ConsumerException
109    {
110        beginScan( repository, whenGathered );
111    }
112
113    @Override
114    public void completeScan()
115    {
116        // no op
117    }
118
119    @Override
120    public void completeScan( boolean executeOnEntireRepo )
121    {
122        completeScan();
123    }
124
125    @Override
126    public List<String> getExcludes()
127    {
128        return excludes;
129    }
130
131    @Override
132    public List<String> getIncludes()
133    {
134        return includes;
135    }
136
137    @Override
138    public void processFile( String path )
139        throws ConsumerException
140    {
141        try
142        {
143            ArtifactReference reference = managedRepository.toArtifactReference( path );
144            Artifact artifact = artifactFactory.createArtifact( reference.getGroupId(), reference.getArtifactId(),
145                                                                reference.getVersion(), reference.getClassifier(),
146                                                                reference.getType() );
147            artifactConverter.convert( artifact, destinationRepository );
148        }
149        catch ( LayoutException e )
150        {
151            log.warn( "Unable to convert artifact: {} : {}",path , e.getMessage(), e );
152        }
153        catch ( ArtifactConversionException e )
154        {
155            log.warn( "Unable to convert artifact: {} : {}",path , e.getMessage(), e );
156        }
157    }
158
159    @Override
160    public void processFile( String path, boolean executeOnEntireRepo )
161        throws Exception
162    {
163        processFile( path );
164    }
165
166    @Override
167    public String getDescription()
168    {
169        return "Legacy Artifact to Default Artifact Converter";
170    }
171
172    @Override
173    public String getId()
174    {
175        return "artifact-legacy-to-default-converter";
176    }
177
178    public void setExcludes( List<String> excludes )
179    {
180        this.excludes = excludes;
181    }
182
183    public void setIncludes( List<String> includes )
184    {
185        this.includes = includes;
186    }
187
188    public ArtifactRepository getDestinationRepository()
189    {
190        return destinationRepository;
191    }
192
193    public void setDestinationRepository( ArtifactRepository destinationRepository )
194    {
195        this.destinationRepository = destinationRepository;
196    }
197}