View Javadoc
1   package org.apache.maven.plugin.prefix;
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.Collections;
23  import java.util.List;
24  
25  import org.apache.maven.execution.MavenSession;
26  import org.apache.maven.model.Model;
27  import org.apache.maven.project.MavenProject;
28  import org.eclipse.aether.RepositorySystemSession;
29  import org.eclipse.aether.repository.RemoteRepository;
30  
31  /**
32   * Collects settings required to resolve a plugin prefix.
33   *
34   * @since 3.0
35   * @author Benjamin Bentmann
36   */
37  public class DefaultPluginPrefixRequest
38      implements PluginPrefixRequest
39  {
40  
41      private String prefix;
42  
43      private List<String> pluginGroups = Collections.emptyList();
44  
45      private Model pom;
46  
47      private List<RemoteRepository> repositories = Collections.emptyList();
48  
49      private RepositorySystemSession session;
50  
51      /**
52       * Creates an empty request.
53       */
54      public DefaultPluginPrefixRequest()
55      {
56      }
57  
58      /**
59       * Creates a request for the specified plugin prefix and build session. The provided build session will be used to
60       * configure repository settings. If the session has a current project, its plugin repositories and model will be
61       * used as well.
62       *
63       * @param prefix The plugin prefix to resolve, must not be {@code null}.
64       * @param session The build session from which to derive further settings, must not be {@code null}.
65       */
66      public DefaultPluginPrefixRequest( String prefix, MavenSession session )
67      {
68          setPrefix( prefix );
69  
70          setRepositorySession( session.getRepositorySession() );
71  
72          MavenProject project = session.getCurrentProject();
73          if ( project != null )
74          {
75              setRepositories( project.getRemotePluginRepositories() );
76              setPom( project.getModel() );
77          }
78  
79          setPluginGroups( session.getPluginGroups() );
80      }
81  
82      public String getPrefix()
83      {
84          return prefix;
85      }
86  
87      public DefaultPluginPrefixRequest setPrefix( String prefix )
88      {
89          this.prefix = prefix;
90  
91          return this;
92      }
93  
94      public List<String> getPluginGroups()
95      {
96          return pluginGroups;
97      }
98  
99      public DefaultPluginPrefixRequest setPluginGroups( List<String> pluginGroups )
100     {
101         if ( pluginGroups != null )
102         {
103             this.pluginGroups = pluginGroups;
104         }
105         else
106         {
107             this.pluginGroups = Collections.emptyList();
108         }
109 
110         return this;
111     }
112 
113     public Model getPom()
114     {
115         return pom;
116     }
117 
118     public DefaultPluginPrefixRequest setPom( Model pom )
119     {
120         this.pom = pom;
121 
122         return this;
123     }
124 
125     public List<RemoteRepository> getRepositories()
126     {
127         return repositories;
128     }
129 
130     public DefaultPluginPrefixRequest setRepositories( List<RemoteRepository> repositories )
131     {
132         if ( repositories != null )
133         {
134             this.repositories = repositories;
135         }
136         else
137         {
138             this.repositories = Collections.emptyList();
139         }
140 
141         return this;
142     }
143 
144     public RepositorySystemSession getRepositorySession()
145     {
146         return session;
147     }
148 
149     public DefaultPluginPrefixRequest setRepositorySession( RepositorySystemSession session )
150     {
151         this.session = session;
152 
153         return this;
154     }
155 
156 }