001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.tools.plugin;
020
021import java.net.URI;
022import java.util.HashSet;
023import java.util.List;
024import java.util.Set;
025
026import org.apache.maven.artifact.Artifact;
027import org.apache.maven.plugin.descriptor.PluginDescriptor;
028import org.apache.maven.project.MavenProject;
029import org.apache.maven.settings.Settings;
030import org.codehaus.plexus.util.ReaderFactory;
031import org.eclipse.aether.RepositorySystemSession;
032
033/**
034 * Default implementation of {@link PluginToolsRequest}, which is used to pass parameters to components used to extract
035 * {@link org.apache.maven.plugin.descriptor.MojoDescriptor MojoDescriptor} instances from different types of metadata
036 * for a given plugin.
037 *
038 * @author jdcasey
039 * @since 2.5
040 */
041public class DefaultPluginToolsRequest implements PluginToolsRequest {
042
043    private static final String DEFAULT_ENCODING = ReaderFactory.FILE_ENCODING;
044
045    private PluginDescriptor pluginDescriptor;
046
047    private MavenProject project;
048
049    private String encoding = DEFAULT_ENCODING;
050
051    private boolean skipErrorNoDescriptorsFound;
052
053    private Set<Artifact> dependencies;
054
055    private RepositorySystemSession repoSession;
056
057    private URI internalJavadocBaseUrl;
058
059    private String internalJavadocVersion;
060
061    private List<URI> externalJavadocBaseUrls;
062
063    private Settings settings;
064
065    private String requiredJavaVersion;
066
067    private String mavenApiVersion;
068
069    public DefaultPluginToolsRequest(MavenProject project, PluginDescriptor pluginDescriptor) {
070        this.project = project;
071        this.pluginDescriptor = pluginDescriptor;
072    }
073
074    /**
075     * {@inheritDoc}
076     */
077    @Override
078    public PluginDescriptor getPluginDescriptor() {
079        return pluginDescriptor;
080    }
081
082    /**
083     * {@inheritDoc}
084     */
085    @Override
086    public PluginToolsRequest setPluginDescriptor(PluginDescriptor pluginDescriptor) {
087        this.pluginDescriptor = pluginDescriptor;
088        return this;
089    }
090
091    /**
092     * {@inheritDoc}
093     */
094    @Override
095    public MavenProject getProject() {
096        return project;
097    }
098
099    /**
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}