1 package org.apache.maven.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.maven.archiva.configuration.ManagedRepositoryConfiguration;
25 import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
26 import org.apache.maven.archiva.consumers.ConsumerException;
27 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
28 import org.apache.maven.archiva.converter.artifact.ArtifactConversionException;
29 import org.apache.maven.archiva.converter.artifact.ArtifactConverter;
30 import org.apache.maven.archiva.model.ArtifactReference;
31 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
32 import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
33 import org.apache.maven.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 java.util.ArrayList;
44 import java.util.Date;
45 import java.util.List;
48 * LegacyConverterArtifactConsumer - convert artifacts as they are found
49 * into the destination repository.
53 * plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
54 * role-hint="artifact-legacy-to-default-converter"
55 * instantiation-strategy="per-lookup"
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 * plexus.requirement role-hint="legacy-to-default"
69 private ArtifactConverter artifactConverter;
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<String>();
89 includes.add( "**/*.jar" );
90 includes.add( "**/*.ear" );
91 includes.add( "**/*.war" );
92 artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class );
95 public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered )
96 throws ConsumerException
98 this.managedRepository = new ManagedDefaultRepositoryContent();
99 this.managedRepository.setRepository( repository );
102 public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
103 throws ConsumerException
105 beginScan( repository, whenGathered );
108 public void completeScan()
113 public void completeScan( boolean executeOnEntireRepo )
118 public List<String> getExcludes()
123 public List<String> getIncludes()
128 public void processFile( String path )
129 throws ConsumerException
133 ArtifactReference reference = managedRepository.toArtifactReference( path );
134 Artifact artifact = artifactFactory.createArtifact( reference.getGroupId(), reference.getArtifactId(),
135 reference.getVersion(), reference.getClassifier(),
136 reference.getType() );
137 artifactConverter.convert( artifact, destinationRepository );
139 catch ( LayoutException e )
141 log.warn( "Unable to convert artifact: " + path + " : " + e.getMessage(), e );
143 catch ( ArtifactConversionException e )
145 log.warn( "Unable to convert artifact: " + path + " : " + e.getMessage(), e );
149 public void processFile( String path, boolean executeOnEntireRepo )
155 public String getDescription()
157 return "Legacy Artifact to Default Artifact Converter";
160 public String getId()
162 return "artifact-legacy-to-default-converter";
165 public boolean isPermanent()
170 public void setExcludes( List<String> excludes )
172 this.excludes = excludes;
175 public void setIncludes( List<String> includes )
177 this.includes = includes;
180 public ArtifactRepository getDestinationRepository()
182 return destinationRepository;
185 public void setDestinationRepository( ArtifactRepository destinationRepository )
187 this.destinationRepository = destinationRepository;