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 java.util.ArrayList;
23 import java.util.Date;
24 import java.util.List;
26 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
27 import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
28 import org.apache.maven.archiva.consumers.ConsumerException;
29 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
30 import org.apache.maven.archiva.converter.artifact.ArtifactConversionException;
31 import org.apache.maven.archiva.converter.artifact.ArtifactConverter;
32 import org.apache.maven.archiva.model.ArtifactReference;
33 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
34 import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
35 import org.apache.maven.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;
43 * LegacyConverterArtifactConsumer - convert artifacts as they are found
44 * into the destination repository.
48 * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
49 * role-hint="artifact-legacy-to-default-converter"
50 * instantiation-strategy="per-lookup"
52 public class LegacyConverterArtifactConsumer
53 extends AbstractMonitoredConsumer
54 implements KnownRepositoryContentConsumer
56 private Logger log = LoggerFactory.getLogger( LegacyConverterArtifactConsumer.class );
59 * @plexus.requirement role-hint="legacy-to-default"
61 private ArtifactConverter artifactConverter;
66 private ArtifactFactory artifactFactory;
68 private ManagedRepositoryContent managedRepository;
70 private ArtifactRepository destinationRepository;
72 private List includes;
74 private List excludes;
76 public LegacyConverterArtifactConsumer()
78 includes = new ArrayList();
79 includes.add( "**/*.jar" );
80 includes.add( "**/*.ear" );
81 includes.add( "**/*.war" );
84 public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered )
85 throws ConsumerException
87 this.managedRepository = new ManagedDefaultRepositoryContent();
88 this.managedRepository.setRepository( repository );
91 public void completeScan()
96 public List getExcludes()
101 public List getIncludes()
106 public void processFile( String path )
107 throws ConsumerException
111 ArtifactReference reference = managedRepository.toArtifactReference( path );
112 Artifact artifact = artifactFactory.createArtifact( reference.getGroupId(), reference.getArtifactId(),
113 reference.getVersion(), reference.getClassifier(),
114 reference.getType() );
115 artifactConverter.convert( artifact, destinationRepository );
117 catch ( LayoutException e )
119 log.warn( "Unable to convert artifact: " + path + " : " + e.getMessage(), e );
121 catch ( ArtifactConversionException e )
123 log.warn( "Unable to convert artifact: " + path + " : " + e.getMessage(), e );
127 public String getDescription()
129 return "Legacy Artifact to Default Artifact Converter";
132 public String getId()
134 return "artifact-legacy-to-default-converter";
137 public boolean isPermanent()
142 public void setExcludes( List excludes )
144 this.excludes = excludes;
147 public void setIncludes( List includes )
149 this.includes = includes;
152 public ArtifactRepository getDestinationRepository()
154 return destinationRepository;
157 public void setDestinationRepository( ArtifactRepository destinationRepository )
159 this.destinationRepository = destinationRepository;