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.consumers.AbstractMonitoredConsumer;
25 import org.apache.archiva.consumers.ConsumerException;
26 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
27 import org.apache.archiva.converter.artifact.ArtifactConversionException;
28 import org.apache.archiva.converter.artifact.ArtifactConverter;
29 import org.apache.archiva.model.ArtifactReference;
30 import org.apache.archiva.repository.ManagedRepository;
31 import org.apache.archiva.repository.ManagedRepositoryContent;
32 import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent;
33 import org.apache.archiva.repository.layout.LayoutException;
34 import org.apache.maven.artifact.Artifact;
35 import org.apache.maven.artifact.factory.ArtifactFactory;
36 import org.apache.maven.artifact.repository.ArtifactRepository;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.context.annotation.Scope;
40 import org.springframework.stereotype.Service;
42 import javax.inject.Inject;
43 import javax.inject.Named;
44 import java.util.ArrayList;
45 import java.util.Date;
46 import java.util.List;
49 * LegacyConverterArtifactConsumer - convert artifacts as they are found
50 * into the destination repository.
54 @Service( "knownRepositoryContentConsumer#artifact-legacy-to-default-converter" )
56 public class LegacyConverterArtifactConsumer
57 extends AbstractMonitoredConsumer
58 implements KnownRepositoryContentConsumer
60 private Logger log = LoggerFactory.getLogger( LegacyConverterArtifactConsumer.class );
63 @Named("artifactConverter#legacy-to-default")
64 private ArtifactConverter artifactConverter;
66 private ArtifactFactory artifactFactory;
68 private ManagedRepositoryContent managedRepository;
70 private ArtifactRepository destinationRepository;
72 private List<String> includes;
74 private List<String> excludes;
77 public LegacyConverterArtifactConsumer( PlexusSisuBridge plexusSisuBridge )
78 throws PlexusSisuBridgeException
80 includes = new ArrayList<>( 3 );
81 includes.add( "**/*.jar" );
82 includes.add( "**/*.ear" );
83 includes.add( "**/*.war" );
84 artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class );
88 public void beginScan( org.apache.archiva.repository.ManagedRepository repository, Date whenGathered )
89 throws ConsumerException
91 this.managedRepository = new ManagedDefaultRepositoryContent();
92 this.managedRepository.setRepository( repository );
96 public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
97 throws ConsumerException
99 beginScan( repository, whenGathered );
103 public void completeScan()
109 public void completeScan( boolean executeOnEntireRepo )
115 public List<String> getExcludes()
121 public List<String> getIncludes()
127 public void processFile( String path )
128 throws ConsumerException
132 ArtifactReference reference = managedRepository.toArtifactReference( path );
133 Artifact artifact = artifactFactory.createArtifact( reference.getGroupId(), reference.getArtifactId(),
134 reference.getVersion(), reference.getClassifier(),
135 reference.getType() );
136 artifactConverter.convert( artifact, destinationRepository );
138 catch ( LayoutException e )
140 log.warn( "Unable to convert artifact: {} : {}",path , e.getMessage(), e );
142 catch ( ArtifactConversionException e )
144 log.warn( "Unable to convert artifact: {} : {}",path , e.getMessage(), e );
149 public void processFile( String path, boolean executeOnEntireRepo )
156 public String getDescription()
158 return "Legacy Artifact to Default Artifact Converter";
162 public String getId()
164 return "artifact-legacy-to-default-converter";
167 public void setExcludes( List<String> excludes )
169 this.excludes = excludes;
172 public void setIncludes( List<String> includes )
174 this.includes = includes;
177 public ArtifactRepository getDestinationRepository()
179 return destinationRepository;
182 public void setDestinationRepository( ArtifactRepository destinationRepository )
184 this.destinationRepository = destinationRepository;