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.admin.model.managed.ManagedRepository;
23 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
24 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
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 @Service( "knownRepositoryContentConsumer#artifact-legacy-to-default-converter" )
55 public class LegacyConverterArtifactConsumer
56 extends AbstractMonitoredConsumer
57 implements KnownRepositoryContentConsumer
59 private Logger log = LoggerFactory.getLogger( LegacyConverterArtifactConsumer.class );
65 private ArtifactConverter artifactConverter;
70 private ArtifactFactory artifactFactory;
72 private ManagedRepositoryContent managedRepository;
74 private ArtifactRepository destinationRepository;
76 private List<String> includes;
78 private List<String> excludes;
81 public LegacyConverterArtifactConsumer( PlexusSisuBridge plexusSisuBridge )
82 throws PlexusSisuBridgeException
84 includes = new ArrayList<String>();
85 includes.add( "**/*.jar" );
86 includes.add( "**/*.ear" );
87 includes.add( "**/*.war" );
88 artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class );
91 public void beginScan( ManagedRepository repository, Date whenGathered )
92 throws ConsumerException
94 this.managedRepository = new ManagedDefaultRepositoryContent();
95 this.managedRepository.setRepository( repository );
98 public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
99 throws ConsumerException
101 beginScan( repository, whenGathered );
104 public void completeScan()
109 public void completeScan( boolean executeOnEntireRepo )
114 public List<String> getExcludes()
119 public List<String> getIncludes()
124 public void processFile( String path )
125 throws ConsumerException
129 ArtifactReference reference = managedRepository.toArtifactReference( path );
130 Artifact artifact = artifactFactory.createArtifact( reference.getGroupId(), reference.getArtifactId(),
131 reference.getVersion(), reference.getClassifier(),
132 reference.getType() );
133 artifactConverter.convert( artifact, destinationRepository );
135 catch ( LayoutException e )
137 log.warn( "Unable to convert artifact: " + path + " : " + e.getMessage(), e );
139 catch ( ArtifactConversionException e )
141 log.warn( "Unable to convert artifact: " + path + " : " + e.getMessage(), e );
145 public void processFile( String path, boolean executeOnEntireRepo )
151 public String getDescription()
153 return "Legacy Artifact to Default Artifact Converter";
156 public String getId()
158 return "artifact-legacy-to-default-converter";
161 public boolean isPermanent()
166 public void setExcludes( List<String> excludes )
168 this.excludes = excludes;
171 public void setIncludes( List<String> includes )
173 this.includes = includes;
176 public ArtifactRepository getDestinationRepository()
178 return destinationRepository;
181 public void setDestinationRepository( ArtifactRepository destinationRepository )
183 this.destinationRepository = destinationRepository;