View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugin.prefix;
20  
21  import java.util.Collections;
22  import java.util.List;
23  
24  import org.apache.maven.execution.MavenSession;
25  import org.apache.maven.model.Model;
26  import org.apache.maven.project.MavenProject;
27  import org.eclipse.aether.RepositorySystemSession;
28  import org.eclipse.aether.repository.RemoteRepository;
29  
30  /**
31   * Collects settings required to resolve a plugin prefix.
32   *
33   * @since 3.0
34   */
35  public class DefaultPluginPrefixRequest implements PluginPrefixRequest {
36  
37      private String prefix;
38  
39      private List<String> pluginGroups = Collections.emptyList();
40  
41      private Model pom;
42  
43      private List<RemoteRepository> repositories = Collections.emptyList();
44  
45      private RepositorySystemSession session;
46  
47      /**
48       * Creates an empty request.
49       */
50      public DefaultPluginPrefixRequest() {}
51  
52      /**
53       * Creates a request for the specified plugin prefix and build session. The provided build session will be used to
54       * configure repository settings. If the session has a current project, its plugin repositories and model will be
55       * used as well.
56       *
57       * @param prefix The plugin prefix to resolve, must not be {@code null}.
58       * @param session The build session from which to derive further settings, must not be {@code null}.
59       */
60      public DefaultPluginPrefixRequest(String prefix, MavenSession session) {
61          setPrefix(prefix);
62  
63          setRepositorySession(session.getRepositorySession());
64  
65          MavenProject project = session.getCurrentProject();
66          if (project != null) {
67              setRepositories(project.getRemotePluginRepositories());
68              setPom(project.getModel());
69          }
70  
71          setPluginGroups(session.getPluginGroups());
72      }
73  
74      public String getPrefix() {
75          return prefix;
76      }
77  
78      public DefaultPluginPrefixRequest setPrefix(String prefix) {
79          this.prefix = prefix;
80  
81          return this;
82      }
83  
84      public List<String> getPluginGroups() {
85          return pluginGroups;
86      }
87  
88      public DefaultPluginPrefixRequest setPluginGroups(List<String> pluginGroups) {
89          if (pluginGroups != null) {
90              this.pluginGroups = Collections.unmodifiableList(pluginGroups);
91          } else {
92              this.pluginGroups = Collections.emptyList();
93          }
94  
95          return this;
96      }
97  
98      public Model getPom() {
99          return pom;
100     }
101 
102     public DefaultPluginPrefixRequest setPom(Model pom) {
103         this.pom = pom;
104 
105         return this;
106     }
107 
108     public List<RemoteRepository> getRepositories() {
109         return repositories;
110     }
111 
112     public DefaultPluginPrefixRequest setRepositories(List<RemoteRepository> repositories) {
113         if (repositories != null) {
114             this.repositories = Collections.unmodifiableList(repositories);
115         } else {
116             this.repositories = Collections.emptyList();
117         }
118 
119         return this;
120     }
121 
122     public RepositorySystemSession getRepositorySession() {
123         return session;
124     }
125 
126     public DefaultPluginPrefixRequest setRepositorySession(RepositorySystemSession session) {
127         this.session = session;
128 
129         return this;
130     }
131 }