Coverage Report - org.apache.maven.project.ProjectUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
ProjectUtils
0%
0/44
0%
0/22
3.5
 
 1  
 package org.apache.maven.project;
 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 org.apache.maven.artifact.InvalidRepositoryException;
 23  
 import org.apache.maven.artifact.repository.ArtifactRepository;
 24  
 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
 25  
 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
 26  
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 27  
 import org.apache.maven.model.DeploymentRepository;
 28  
 import org.apache.maven.model.Repository;
 29  
 import org.apache.maven.model.RepositoryBase;
 30  
 import org.apache.maven.model.RepositoryPolicy;
 31  
 import org.codehaus.plexus.PlexusContainer;
 32  
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 33  
 
 34  
 import java.util.ArrayList;
 35  
 import java.util.Iterator;
 36  
 import java.util.List;
 37  
 
 38  
 public final class ProjectUtils
 39  
 {
 40  
     private ProjectUtils()
 41  0
     {
 42  0
     }
 43  
 
 44  
     public static List buildArtifactRepositories( List repositories,
 45  
                                                   ArtifactRepositoryFactory artifactRepositoryFactory,
 46  
                                                   PlexusContainer container )
 47  
         throws InvalidRepositoryException
 48  
     {
 49  
 
 50  0
         List repos = new ArrayList();
 51  
 
 52  0
         for ( Iterator i = repositories.iterator(); i.hasNext(); )
 53  
         {
 54  0
             Repository mavenRepo = (Repository) i.next();
 55  
 
 56  0
             ArtifactRepository artifactRepo =
 57  
                 buildArtifactRepository( mavenRepo, artifactRepositoryFactory, container );
 58  
 
 59  0
             if ( !repos.contains( artifactRepo ) )
 60  
             {
 61  0
                 repos.add( artifactRepo );
 62  
             }
 63  0
         }
 64  0
         return repos;
 65  
     }
 66  
 
 67  
     public static ArtifactRepository buildDeploymentArtifactRepository( DeploymentRepository repo,
 68  
                                                                         ArtifactRepositoryFactory artifactRepositoryFactory,
 69  
                                                                         PlexusContainer container )
 70  
         throws InvalidRepositoryException
 71  
     {
 72  0
         if ( repo != null )
 73  
         {
 74  0
             String id = repo.getId();
 75  0
             String url = repo.getUrl();
 76  
 
 77  
             // TODO: make this a map inside the factory instead, so no lookup needed
 78  0
             ArtifactRepositoryLayout layout = getRepositoryLayout( repo, container );
 79  
 
 80  0
             return artifactRepositoryFactory.createDeploymentArtifactRepository( id, url, layout,
 81  
                                                                                  repo.isUniqueVersion() );
 82  
         }
 83  
         else
 84  
         {
 85  0
             return null;
 86  
         }
 87  
     }
 88  
 
 89  
     public static ArtifactRepository buildArtifactRepository( Repository repo,
 90  
                                                               ArtifactRepositoryFactory artifactRepositoryFactory,
 91  
                                                               PlexusContainer container )
 92  
         throws InvalidRepositoryException
 93  
     {
 94  0
         if ( repo != null )
 95  
         {
 96  0
             String id = repo.getId();
 97  0
             String url = repo.getUrl();
 98  
 
 99  0
             if ( id == null || id.trim().length() < 1 )
 100  
             {
 101  0
                 throw new InvalidRepositoryException( "Repository ID must not be empty (URL is: " + url + ").", new IllegalArgumentException( "repository.id" ) );
 102  
             }
 103  
 
 104  0
             if ( url == null || url.trim().length() < 1 )
 105  
             {
 106  0
                 throw new InvalidRepositoryException( "Repository URL must not be empty (ID is: " + id + ").", new IllegalArgumentException( "repository.url" ) );
 107  
             }
 108  
 
 109  
             // TODO: make this a map inside the factory instead, so no lookup needed
 110  0
             ArtifactRepositoryLayout layout = getRepositoryLayout( repo, container );
 111  
 
 112  0
             ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repo.getSnapshots() );
 113  0
             ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repo.getReleases() );
 114  
 
 115  0
             return artifactRepositoryFactory.createArtifactRepository( id, url, layout, snapshots, releases );
 116  
         }
 117  
         else
 118  
         {
 119  0
             return null;
 120  
         }
 121  
     }
 122  
 
 123  
     private static ArtifactRepositoryPolicy buildArtifactRepositoryPolicy( RepositoryPolicy policy )
 124  
     {
 125  0
         boolean enabled = true;
 126  0
         String updatePolicy = null;
 127  0
         String checksumPolicy = null;
 128  
 
 129  0
         if ( policy != null )
 130  
         {
 131  0
             enabled = policy.isEnabled();
 132  0
             if ( policy.getUpdatePolicy() != null )
 133  
             {
 134  0
                 updatePolicy = policy.getUpdatePolicy();
 135  
             }
 136  0
             if ( policy.getChecksumPolicy() != null )
 137  
             {
 138  0
                 checksumPolicy = policy.getChecksumPolicy();
 139  
             }
 140  
         }
 141  
 
 142  0
         return new ArtifactRepositoryPolicy( enabled, updatePolicy, checksumPolicy );
 143  
     }
 144  
 
 145  
     private static ArtifactRepositoryLayout getRepositoryLayout( RepositoryBase mavenRepo, PlexusContainer container )
 146  
         throws InvalidRepositoryException
 147  
     {
 148  0
         String layout = mavenRepo.getLayout();
 149  
 
 150  
         ArtifactRepositoryLayout repositoryLayout;
 151  
         try
 152  
         {
 153  0
             repositoryLayout = (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE, layout );
 154  
         }
 155  0
         catch ( ComponentLookupException e )
 156  
         {
 157  0
             throw new InvalidRepositoryException( "Cannot find layout implementation corresponding to: \'" + layout +
 158  
                 "\' for remote repository with id: \'" + mavenRepo.getId() + "\'.", e );
 159  0
         }
 160  0
         return repositoryLayout;
 161  
     }
 162  
 
 163  
 }