View Javadoc

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 java.util.ArrayList;
23  import java.util.Arrays;
24  import java.util.List;
25  
26  import org.apache.maven.artifact.InvalidRepositoryException;
27  import org.apache.maven.artifact.repository.ArtifactRepository;
28  import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
29  import org.apache.maven.execution.MavenExecutionRequest;
30  import org.apache.maven.model.DeploymentRepository;
31  import org.apache.maven.model.Repository;
32  import org.apache.maven.plugin.LegacySupport;
33  import org.apache.maven.repository.RepositorySystem;
34  import org.codehaus.plexus.PlexusContainer;
35  import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
36  
37  // This class needs to stick around because it was exposed the the remote resources plugin started using it instead of
38  // getting the repositories from the project.
39  
40  @Deprecated
41  public final class ProjectUtils
42  {
43  
44      private ProjectUtils()
45      {
46      }
47  
48      public static List<ArtifactRepository> buildArtifactRepositories( List<Repository> repositories,
49                                                                        ArtifactRepositoryFactory artifactRepositoryFactory,
50                                                                        PlexusContainer c )
51          throws InvalidRepositoryException
52      {
53  
54          List<ArtifactRepository> remoteRepositories = new ArrayList<ArtifactRepository>();
55  
56          for ( Repository r : repositories )
57          {
58              remoteRepositories.add( buildArtifactRepository( r, artifactRepositoryFactory, c ) );
59          }
60  
61          return remoteRepositories;
62      }
63  
64      public static ArtifactRepository buildDeploymentArtifactRepository( DeploymentRepository repo,
65                                                                          ArtifactRepositoryFactory artifactRepositoryFactory,
66                                                                          PlexusContainer c )
67          throws InvalidRepositoryException
68      {
69          return buildArtifactRepository( repo, artifactRepositoryFactory, c );
70      }
71  
72      public static ArtifactRepository buildArtifactRepository( Repository repo,
73                                                                ArtifactRepositoryFactory artifactRepositoryFactory,
74                                                                PlexusContainer c )
75          throws InvalidRepositoryException
76      {
77          RepositorySystem repositorySystem = rs( c );
78          MavenExecutionRequest executionRequest = er( c );
79  
80          ArtifactRepository repository = repositorySystem.buildArtifactRepository( repo );
81  
82          if ( executionRequest != null )
83          {
84              repositorySystem.injectMirror( Arrays.asList( repository ), executionRequest.getMirrors() );
85              repositorySystem.injectProxy( Arrays.asList( repository ), executionRequest.getProxies() );
86              repositorySystem.injectAuthentication( Arrays.asList( repository ), executionRequest.getServers() );
87          }
88  
89          return repository;
90      }
91  
92      private static RepositorySystem rs( PlexusContainer c )
93      {
94          try
95          {
96              return c.lookup( RepositorySystem.class );
97          }
98          catch ( ComponentLookupException e )
99          {
100             throw new IllegalStateException( e );
101         }
102     }
103 
104     private static MavenExecutionRequest er( PlexusContainer c )
105     {
106         try
107         {
108             LegacySupport legacySupport = c.lookup( LegacySupport.class );
109 
110             if ( legacySupport.getSession() != null )
111             {
112                 return legacySupport.getSession().getRequest();
113             }
114             else
115             {
116                 return null;
117             }
118         }
119         catch ( ComponentLookupException e )
120         {
121             throw new IllegalStateException( e );
122         }
123     }
124 
125 }