1 package org.apache.archiva.converter.legacy;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
23 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
24 import org.apache.archiva.configuration.FileTypes;
25 import org.apache.archiva.consumers.AbstractMonitoredConsumer;
26 import org.apache.archiva.consumers.ConsumerException;
27 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
28 import org.apache.archiva.converter.artifact.ArtifactConversionException;
29 import org.apache.archiva.converter.artifact.ArtifactConverter;
30 import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
31 import org.apache.archiva.model.ArtifactReference;
32 import org.apache.archiva.repository.ManagedRepository;
33 import org.apache.archiva.repository.ManagedRepositoryContent;
34 import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent;
35 import org.apache.archiva.repository.layout.LayoutException;
36 import org.apache.maven.artifact.Artifact;
37 import org.apache.maven.artifact.factory.ArtifactFactory;
38 import org.apache.maven.artifact.repository.ArtifactRepository;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41 import org.springframework.context.annotation.Scope;
42 import org.springframework.stereotype.Service;
44 import javax.inject.Inject;
45 import javax.inject.Named;
46 import java.util.ArrayList;
47 import java.util.Date;
48 import java.util.List;
51 * LegacyConverterArtifactConsumer - convert artifacts as they are found
52 * into the destination repository.
56 @Service( "knownRepositoryContentConsumer#artifact-legacy-to-default-converter" )
58 public class LegacyConverterArtifactConsumer
59 extends AbstractMonitoredConsumer
60 implements KnownRepositoryContentConsumer
62 private Logger log = LoggerFactory.getLogger( LegacyConverterArtifactConsumer.class );
65 @Named("artifactConverter#legacy-to-default")
66 private ArtifactConverter artifactConverter;
69 private List<? extends ArtifactMappingProvider> artifactMappingProviders;
72 private FileTypes fileTypes;
74 private ArtifactFactory artifactFactory;
76 private ManagedRepositoryContent managedRepository;
78 private ArtifactRepository destinationRepository;
80 private List<String> includes;
82 private List<String> excludes;
85 public LegacyConverterArtifactConsumer( PlexusSisuBridge plexusSisuBridge )
86 throws PlexusSisuBridgeException
88 includes = new ArrayList<>( 3 );
89 includes.add( "**/*.jar" );
90 includes.add( "**/*.ear" );
91 includes.add( "**/*.war" );
92 artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class );
96 public void beginScan( org.apache.archiva.repository.ManagedRepository repository, Date whenGathered )
97 throws ConsumerException
99 this.managedRepository = new ManagedDefaultRepositoryContent(artifactMappingProviders, fileTypes);
100 this.managedRepository.setRepository( repository );
104 public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
105 throws ConsumerException
107 beginScan( repository, whenGathered );
111 public void completeScan()
117 public void completeScan( boolean executeOnEntireRepo )
123 public List<String> getExcludes()
129 public List<String> getIncludes()
135 public void processFile( String path )
136 throws ConsumerException
140 ArtifactReference reference = managedRepository.toArtifactReference( path );
141 Artifact artifact = artifactFactory.createArtifact( reference.getGroupId(), reference.getArtifactId(),
142 reference.getVersion(), reference.getClassifier(),
143 reference.getType() );
144 artifactConverter.convert( artifact, destinationRepository );
146 catch ( LayoutException e )
148 log.warn( "Unable to convert artifact: {} : {}",path , e.getMessage(), e );
150 catch ( ArtifactConversionException e )
152 log.warn( "Unable to convert artifact: {} : {}",path , e.getMessage(), e );
157 public void processFile( String path, boolean executeOnEntireRepo )
164 public String getDescription()
166 return "Legacy Artifact to Default Artifact Converter";
170 public String getId()
172 return "artifact-legacy-to-default-converter";
175 public void setExcludes( List<String> excludes )
177 this.excludes = excludes;
180 public void setIncludes( List<String> includes )
182 this.includes = includes;
185 public ArtifactRepository getDestinationRepository()
187 return destinationRepository;
190 public void setDestinationRepository( ArtifactRepository destinationRepository )
192 this.destinationRepository = destinationRepository;