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.tools.plugin;
20  
21  import java.net.URI;
22  import java.util.HashSet;
23  import java.util.List;
24  import java.util.Set;
25  
26  import org.apache.maven.artifact.Artifact;
27  import org.apache.maven.plugin.descriptor.PluginDescriptor;
28  import org.apache.maven.project.MavenProject;
29  import org.apache.maven.settings.Settings;
30  import org.codehaus.plexus.util.ReaderFactory;
31  import org.eclipse.aether.RepositorySystemSession;
32  
33  /**
34   * Default implementation of {@link PluginToolsRequest}, which is used to pass parameters to components used to extract
35   * {@link org.apache.maven.plugin.descriptor.MojoDescriptor MojoDescriptor} instances from different types of metadata
36   * for a given plugin.
37   *
38   * @author jdcasey
39   * @since 2.5
40   */
41  public class DefaultPluginToolsRequest implements PluginToolsRequest {
42  
43      private static final String DEFAULT_ENCODING = ReaderFactory.FILE_ENCODING;
44  
45      private PluginDescriptor pluginDescriptor;
46  
47      private MavenProject project;
48  
49      private String encoding = DEFAULT_ENCODING;
50  
51      private boolean skipErrorNoDescriptorsFound;
52  
53      private Set<Artifact> dependencies;
54  
55      private RepositorySystemSession repoSession;
56  
57      private URI internalJavadocBaseUrl;
58  
59      private String internalJavadocVersion;
60  
61      private List<URI> externalJavadocBaseUrls;
62  
63      private Settings settings;
64  
65      private String requiredJavaVersion;
66  
67      private String mavenApiVersion;
68  
69      public DefaultPluginToolsRequest(MavenProject project, PluginDescriptor pluginDescriptor) {
70          this.project = project;
71          this.pluginDescriptor = pluginDescriptor;
72      }
73  
74      /**
75       * {@inheritDoc}
76       */
77      @Override
78      public PluginDescriptor getPluginDescriptor() {
79          return pluginDescriptor;
80      }
81  
82      /**
83       * {@inheritDoc}
84       */
85      @Override
86      public PluginToolsRequest setPluginDescriptor(PluginDescriptor pluginDescriptor) {
87          this.pluginDescriptor = pluginDescriptor;
88          return this;
89      }
90  
91      /**
92       * {@inheritDoc}
93       */
94      @Override
95      public MavenProject getProject() {
96          return project;
97      }
98  
99      /**
100      * {@inheritDoc}
101      */
102     @Override
103     public PluginToolsRequest setProject(MavenProject project) {
104         this.project = project;
105         return this;
106     }
107 
108     /**
109      * {@inheritDoc}
110      */
111     @Override
112     public String getEncoding() {
113         return this.encoding;
114     }
115 
116     /**
117      * {@inheritDoc}
118      */
119     @Override
120     public PluginToolsRequest setEncoding(String encoding) {
121         if (encoding != null && !encoding.isEmpty()) {
122             this.encoding = encoding;
123         } else {
124             this.encoding = DEFAULT_ENCODING;
125         }
126 
127         return this;
128     }
129 
130     /**
131      * {@inheritDoc}
132      */
133     @Override
134     public boolean isSkipErrorNoDescriptorsFound() {
135         return skipErrorNoDescriptorsFound;
136     }
137 
138     /**
139      * {@inheritDoc}
140      */
141     @Override
142     public PluginToolsRequest setSkipErrorNoDescriptorsFound(boolean skipErrorNoDescriptorsFound) {
143         this.skipErrorNoDescriptorsFound = skipErrorNoDescriptorsFound;
144         return this;
145     }
146 
147     @Override
148     public Set<Artifact> getDependencies() {
149         if (this.dependencies == null) {
150             this.dependencies = new HashSet<>();
151         }
152         return dependencies;
153     }
154 
155     @Override
156     public PluginToolsRequest setDependencies(Set<Artifact> dependencies) {
157         this.dependencies = dependencies;
158         return this;
159     }
160 
161     @Override
162     public RepositorySystemSession getRepoSession() {
163         return repoSession;
164     }
165 
166     public void setRepoSession(RepositorySystemSession repoSession) {
167         this.repoSession = repoSession;
168     }
169 
170     @Override
171     public PluginToolsRequest setInternalJavadocBaseUrl(URI baseUrl) {
172         internalJavadocBaseUrl = baseUrl;
173         return this;
174     }
175 
176     @Override
177     public URI getInternalJavadocBaseUrl() {
178         return internalJavadocBaseUrl;
179     }
180 
181     @Override
182     public PluginToolsRequest setInternalJavadocVersion(String javadocVersion) {
183         this.internalJavadocVersion = javadocVersion;
184         return this;
185     }
186 
187     @Override
188     public String getInternalJavadocVersion() {
189         return internalJavadocVersion;
190     }
191 
192     @Override
193     public PluginToolsRequest setExternalJavadocBaseUrls(List<URI> javadocLinks) {
194         this.externalJavadocBaseUrls = javadocLinks;
195         return this;
196     }
197 
198     @Override
199     public List<URI> getExternalJavadocBaseUrls() {
200         return externalJavadocBaseUrls;
201     }
202 
203     @Override
204     public PluginToolsRequest setSettings(Settings settings) {
205         this.settings = settings;
206         return this;
207     }
208 
209     @Override
210     public Settings getSettings() {
211         return settings;
212     }
213 
214     @Override
215     public PluginToolsRequest setRequiredJavaVersion(String requiredJavaVersion) {
216         this.requiredJavaVersion = requiredJavaVersion;
217         return this;
218     }
219 
220     @Override
221     public String getRequiredJavaVersion() {
222         return requiredJavaVersion;
223     }
224 
225     @Override
226     public PluginToolsRequest setUsedMavenApiVersion(String mavenApiVersion) {
227         this.mavenApiVersion = mavenApiVersion;
228         return this;
229     }
230 
231     @Override
232     public String getUsedMavenApiVersion() {
233         return mavenApiVersion;
234     }
235 }