001package org.apache.maven.tools.plugin;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.maven.artifact.Artifact;
023import org.apache.maven.artifact.repository.ArtifactRepository;
024import org.apache.maven.plugin.descriptor.PluginDescriptor;
025import org.apache.maven.project.MavenProject;
026import org.codehaus.plexus.util.ReaderFactory;
027import org.codehaus.plexus.util.StringUtils;
028
029import java.util.HashSet;
030import java.util.List;
031import java.util.Set;
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
042    implements PluginToolsRequest
043{
044
045    private static final String DEFAULT_ENCODING = ReaderFactory.FILE_ENCODING;
046
047    private PluginDescriptor pluginDescriptor;
048
049    private MavenProject project;
050
051    private String encoding = DEFAULT_ENCODING;
052
053    private boolean skipErrorNoDescriptorsFound;
054
055    private Set<Artifact> dependencies;
056
057    private List<ArtifactRepository> remoteRepos;
058
059    private ArtifactRepository local;
060
061    public DefaultPluginToolsRequest( MavenProject project, PluginDescriptor pluginDescriptor )
062    {
063        this.project = project;
064        this.pluginDescriptor = pluginDescriptor;
065    }
066
067    /**
068     * {@inheritDoc}
069     */
070    public PluginDescriptor getPluginDescriptor()
071    {
072        return pluginDescriptor;
073    }
074
075    /**
076     * {@inheritDoc}
077     */
078    public PluginToolsRequest setPluginDescriptor( PluginDescriptor pluginDescriptor )
079    {
080        this.pluginDescriptor = pluginDescriptor;
081        return this;
082    }
083
084    /**
085     * {@inheritDoc}
086     */
087    public MavenProject getProject()
088    {
089        return project;
090    }
091
092    /**
093     * {@inheritDoc}
094     */
095    public PluginToolsRequest setProject( MavenProject project )
096    {
097        this.project = project;
098        return this;
099    }
100
101    /**
102     * {@inheritDoc}
103     */
104    public String getEncoding()
105    {
106        return this.encoding;
107    }
108
109    /**
110     * {@inheritDoc}
111     */
112    public PluginToolsRequest setEncoding( String encoding )
113    {
114        if ( StringUtils.isNotEmpty( encoding ) )
115        {
116            this.encoding = encoding;
117        }
118        else
119        {
120            this.encoding = DEFAULT_ENCODING;
121        }
122
123        return this;
124    }
125
126    /**
127     * {@inheritDoc}
128     */
129    public boolean isSkipErrorNoDescriptorsFound()
130    {
131        return skipErrorNoDescriptorsFound;
132    }
133
134    /**
135     * {@inheritDoc}
136     */
137    public PluginToolsRequest setSkipErrorNoDescriptorsFound( boolean skipErrorNoDescriptorsFound )
138    {
139        this.skipErrorNoDescriptorsFound = skipErrorNoDescriptorsFound;
140        return this;
141    }
142
143    public Set<Artifact> getDependencies()
144    {
145        if ( this.dependencies == null )
146        {
147            this.dependencies = new HashSet<Artifact>();
148        }
149        return dependencies;
150    }
151
152    public PluginToolsRequest setDependencies( Set<Artifact> dependencies )
153    {
154        this.dependencies = dependencies;
155        return this;
156    }
157
158    public List<ArtifactRepository> getRemoteRepos()
159    {
160        return remoteRepos;
161    }
162
163    public PluginToolsRequest setRemoteRepos( List<ArtifactRepository> remoteRepos )
164    {
165        this.remoteRepos = remoteRepos;
166        return this;
167    }
168
169    public ArtifactRepository getLocal()
170    {
171        return local;
172    }
173
174    public PluginToolsRequest setLocal( ArtifactRepository local )
175    {
176        this.local = local;
177        return this;
178    }
179}