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.filelock.FileLockManager;
23 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
24 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
25 import org.apache.archiva.configuration.FileTypes;
26 import org.apache.archiva.consumers.AbstractMonitoredConsumer;
27 import org.apache.archiva.consumers.ConsumerException;
28 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
29 import org.apache.archiva.converter.artifact.ArtifactConversionException;
30 import org.apache.archiva.converter.artifact.ArtifactConverter;
31 import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
32 import org.apache.archiva.model.ArtifactReference;
33 import org.apache.archiva.repository.LayoutException;
34 import org.apache.archiva.repository.ManagedRepository;
35 import org.apache.archiva.repository.ManagedRepositoryContent;
36 import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent;
37 import org.apache.maven.artifact.Artifact;
38 import org.apache.maven.artifact.factory.ArtifactFactory;
39 import org.apache.maven.artifact.repository.ArtifactRepository;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42 import org.springframework.context.annotation.Scope;
43 import org.springframework.stereotype.Service;
45 import javax.inject.Inject;
46 import javax.inject.Named;
47 import java.util.ArrayList;
48 import java.util.Date;
49 import java.util.List;
52 * LegacyConverterArtifactConsumer - convert artifacts as they are found
53 * into the destination repository.
57 @Service( "knownRepositoryContentConsumer#artifact-legacy-to-default-converter" )
59 public class LegacyConverterArtifactConsumer
60 extends AbstractMonitoredConsumer
61 implements KnownRepositoryContentConsumer
63 private Logger log = LoggerFactory.getLogger( LegacyConverterArtifactConsumer.class );
66 @Named("artifactConverter#legacy-to-default")
67 private ArtifactConverter artifactConverter;
70 private List<? extends ArtifactMappingProvider> artifactMappingProviders;
73 private FileTypes fileTypes;
76 private FileLockManager fileLockManager;
78 private ArtifactFactory artifactFactory;
80 private ManagedRepositoryContent managedRepository;
82 private ArtifactRepository destinationRepository;
84 private List<String> includes;
86 private List<String> excludes;
89 public LegacyConverterArtifactConsumer( PlexusSisuBridge plexusSisuBridge )
90 throws PlexusSisuBridgeException
92 includes = new ArrayList<>( 3 );
93 includes.add( "**/*.jar" );
94 includes.add( "**/*.ear" );
95 includes.add( "**/*.war" );
96 artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class );
100 public void beginScan( ManagedRepository repository, Date whenGathered )
101 throws ConsumerException
103 this.managedRepository = new ManagedDefaultRepositoryContent(repository, artifactMappingProviders, fileTypes, fileLockManager);
107 public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
108 throws ConsumerException
110 beginScan( repository, whenGathered );
114 public void completeScan()
120 public void completeScan( boolean executeOnEntireRepo )
126 public List<String> getExcludes()
132 public List<String> getIncludes()
138 public void processFile( String path )
139 throws ConsumerException
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 );
149 catch ( LayoutException e )
151 log.warn( "Unable to convert artifact: {} : {}",path , e.getMessage(), e );
153 catch ( ArtifactConversionException e )
155 log.warn( "Unable to convert artifact: {} : {}",path , e.getMessage(), e );
160 public void processFile( String path, boolean executeOnEntireRepo )
167 public String getDescription()
169 return "Legacy Artifact to Default Artifact Converter";
173 public String getId()
175 return "artifact-legacy-to-default-converter";
178 public void setExcludes( List<String> excludes )
180 this.excludes = excludes;
183 public void setIncludes( List<String> includes )
185 this.includes = includes;
188 public ArtifactRepository getDestinationRepository()
190 return destinationRepository;
193 public void setDestinationRepository( ArtifactRepository destinationRepository )
195 this.destinationRepository = destinationRepository;