View Javadoc
1   package org.apache.maven.tools.plugin;
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 org.apache.maven.artifact.Artifact;
23  import org.apache.maven.artifact.repository.ArtifactRepository;
24  import org.apache.maven.plugin.descriptor.PluginDescriptor;
25  import org.apache.maven.project.MavenProject;
26  import org.codehaus.plexus.util.ReaderFactory;
27  import org.codehaus.plexus.util.StringUtils;
28  
29  import java.util.HashSet;
30  import java.util.List;
31  import java.util.Set;
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
42      implements PluginToolsRequest
43  {
44  
45      private static final String DEFAULT_ENCODING = ReaderFactory.FILE_ENCODING;
46  
47      private PluginDescriptor pluginDescriptor;
48  
49      private MavenProject project;
50  
51      private String encoding = DEFAULT_ENCODING;
52  
53      private boolean skipErrorNoDescriptorsFound;
54  
55      private Set<Artifact> dependencies;
56  
57      private List<ArtifactRepository> remoteRepos;
58  
59      private ArtifactRepository local;
60  
61      public DefaultPluginToolsRequest( MavenProject project, PluginDescriptor pluginDescriptor )
62      {
63          this.project = project;
64          this.pluginDescriptor = pluginDescriptor;
65      }
66  
67      /**
68       * {@inheritDoc}
69       */
70      @Override
71      public PluginDescriptor getPluginDescriptor()
72      {
73          return pluginDescriptor;
74      }
75  
76      /**
77       * {@inheritDoc}
78       */
79      @Override
80      public PluginToolsRequest setPluginDescriptor( PluginDescriptor pluginDescriptor )
81      {
82          this.pluginDescriptor = pluginDescriptor;
83          return this;
84      }
85  
86      /**
87       * {@inheritDoc}
88       */
89      @Override
90      public MavenProject getProject()
91      {
92          return project;
93      }
94  
95      /**
96       * {@inheritDoc}
97       */
98      @Override
99      public PluginToolsRequest setProject( MavenProject project )
100     {
101         this.project = project;
102         return this;
103     }
104 
105     /**
106      * {@inheritDoc}
107      */
108     @Override
109     public String getEncoding()
110     {
111         return this.encoding;
112     }
113 
114     /**
115      * {@inheritDoc}
116      */
117     @Override
118     public PluginToolsRequest setEncoding( String encoding )
119     {
120         if ( StringUtils.isNotEmpty( encoding ) )
121         {
122             this.encoding = encoding;
123         }
124         else
125         {
126             this.encoding = DEFAULT_ENCODING;
127         }
128 
129         return this;
130     }
131 
132     /**
133      * {@inheritDoc}
134      */
135     @Override
136     public boolean isSkipErrorNoDescriptorsFound()
137     {
138         return skipErrorNoDescriptorsFound;
139     }
140 
141     /**
142      * {@inheritDoc}
143      */
144     @Override
145     public PluginToolsRequest setSkipErrorNoDescriptorsFound( boolean skipErrorNoDescriptorsFound )
146     {
147         this.skipErrorNoDescriptorsFound = skipErrorNoDescriptorsFound;
148         return this;
149     }
150 
151     @Override
152     public Set<Artifact> getDependencies()
153     {
154         if ( this.dependencies == null )
155         {
156             this.dependencies = new HashSet<>();
157         }
158         return dependencies;
159     }
160 
161     @Override
162     public PluginToolsRequest setDependencies( Set<Artifact> dependencies )
163     {
164         this.dependencies = dependencies;
165         return this;
166     }
167 
168     @Override
169     public List<ArtifactRepository> getRemoteRepos()
170     {
171         return remoteRepos;
172     }
173 
174     @Override
175     public PluginToolsRequest setRemoteRepos( List<ArtifactRepository> remoteRepos )
176     {
177         this.remoteRepos = remoteRepos;
178         return this;
179     }
180 
181     @Override
182     public ArtifactRepository getLocal()
183     {
184         return local;
185     }
186 
187     @Override
188     public PluginToolsRequest setLocal( ArtifactRepository local )
189     {
190         this.local = local;
191         return this;
192     }
193 }