Coverage Report - org.apache.maven.archiva.converter.legacy.LegacyConverterArtifactConsumer
 
Classes in this File Line Coverage Branch Coverage Complexity
LegacyConverterArtifactConsumer
0%
0/38
N/A
0
 
 1  
 package org.apache.maven.archiva.converter.legacy;
 2  
 
 3  
 /*
 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
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 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
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.util.ArrayList;
 23  
 import java.util.Date;
 24  
 import java.util.List;
 25  
 
 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;
 41  
 
 42  
 /**
 43  
  * LegacyConverterArtifactConsumer - convert artifacts as they are found
 44  
  * into the destination repository. 
 45  
  *
 46  
  * @version $Id: LegacyConverterArtifactConsumer.java 1041824 2010-12-03 14:11:05Z brett $
 47  
  * 
 48  
  * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
 49  
  *     role-hint="artifact-legacy-to-default-converter"
 50  
  *     instantiation-strategy="per-lookup"
 51  
  */
 52  
 public class LegacyConverterArtifactConsumer
 53  
     extends AbstractMonitoredConsumer
 54  
     implements KnownRepositoryContentConsumer
 55  
 {
 56  0
     private Logger log = LoggerFactory.getLogger( LegacyConverterArtifactConsumer.class );
 57  
     
 58  
     /**
 59  
      * @plexus.requirement role-hint="legacy-to-default"
 60  
      */
 61  
     private ArtifactConverter artifactConverter;
 62  
 
 63  
     /**
 64  
      * @plexus.requirement
 65  
      */
 66  
     private ArtifactFactory artifactFactory;
 67  
 
 68  
     private ManagedRepositoryContent managedRepository;
 69  
     
 70  
     private ArtifactRepository destinationRepository;
 71  
 
 72  
     private List<String> includes;
 73  
 
 74  
     private List<String> excludes;
 75  
 
 76  
     public LegacyConverterArtifactConsumer()
 77  0
     {
 78  0
         includes = new ArrayList<String>();
 79  0
         includes.add( "**/*.jar" );
 80  0
         includes.add( "**/*.ear" );
 81  0
         includes.add( "**/*.war" );
 82  0
     }
 83  
 
 84  
     public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered )
 85  
         throws ConsumerException
 86  
     {
 87  0
         this.managedRepository = new ManagedDefaultRepositoryContent();
 88  0
         this.managedRepository.setRepository( repository );
 89  0
     }
 90  
 
 91  
     public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
 92  
         throws ConsumerException
 93  
     {
 94  0
         beginScan( repository, whenGathered );
 95  0
     }
 96  
 
 97  
     public void completeScan()
 98  
     {
 99  
 
 100  0
     }
 101  
 
 102  
     public void completeScan( boolean executeOnEntireRepo )
 103  
     {
 104  0
         completeScan();
 105  0
     }
 106  
 
 107  
     public List<String> getExcludes()
 108  
     {
 109  0
         return excludes;
 110  
     }
 111  
 
 112  
     public List<String> getIncludes()
 113  
     {
 114  0
         return includes;
 115  
     }
 116  
 
 117  
     public void processFile( String path )
 118  
         throws ConsumerException
 119  
     {
 120  
         try
 121  
         {
 122  0
             ArtifactReference reference = managedRepository.toArtifactReference( path );
 123  0
             Artifact artifact = artifactFactory.createArtifact( reference.getGroupId(), reference.getArtifactId(),
 124  
                                                                 reference.getVersion(), reference.getClassifier(),
 125  
                                                                 reference.getType() );
 126  0
             artifactConverter.convert( artifact, destinationRepository );
 127  
         }
 128  0
         catch ( LayoutException e )
 129  
         {
 130  0
             log.warn( "Unable to convert artifact: " + path + " : " + e.getMessage(), e );
 131  
         }
 132  0
         catch ( ArtifactConversionException e )
 133  
         {
 134  0
             log.warn( "Unable to convert artifact: " + path + " : " + e.getMessage(), e );
 135  0
         }
 136  0
     }
 137  
 
 138  
     public void processFile( String path, boolean executeOnEntireRepo )
 139  
         throws Exception
 140  
     {
 141  0
         processFile( path );
 142  0
     }
 143  
 
 144  
     public String getDescription()
 145  
     {
 146  0
         return "Legacy Artifact to Default Artifact Converter";
 147  
     }
 148  
 
 149  
     public String getId()
 150  
     {
 151  0
         return "artifact-legacy-to-default-converter";
 152  
     }
 153  
 
 154  
     public boolean isPermanent()
 155  
     {
 156  0
         return false;
 157  
     }
 158  
 
 159  
     public void setExcludes( List<String> excludes )
 160  
     {
 161  0
         this.excludes = excludes;
 162  0
     }
 163  
 
 164  
     public void setIncludes( List<String> includes )
 165  
     {
 166  0
         this.includes = includes;
 167  0
     }
 168  
 
 169  
     public ArtifactRepository getDestinationRepository()
 170  
     {
 171  0
         return destinationRepository;
 172  
     }
 173  
 
 174  
     public void setDestinationRepository( ArtifactRepository destinationRepository )
 175  
     {
 176  0
         this.destinationRepository = destinationRepository;
 177  0
     }
 178  
 }