View Javadoc
1   package org.apache.maven.tools.plugin.extractor.annotations.scanner;
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.tools.plugin.extractor.annotations.datamodel.ComponentAnnotationContent;
24  import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ExecuteAnnotationContent;
25  import org.apache.maven.tools.plugin.extractor.annotations.datamodel.MojoAnnotationContent;
26  import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ParameterAnnotationContent;
27  
28  import java.util.HashMap;
29  import java.util.Map;
30  
31  /**
32   * @author Olivier Lamy
33   * @since 3.0
34   */
35  public class MojoAnnotatedClass
36  {
37      private String className;
38  
39      private String parentClassName;
40  
41      private MojoAnnotationContent mojo;
42  
43      private ExecuteAnnotationContent execute;
44  
45      /**
46       * key is field name
47       */
48      private Map<String, ParameterAnnotationContent> parameters;
49  
50      /**
51       * key is field name
52       */
53      private Map<String, ComponentAnnotationContent> components;
54  
55      /**
56       * artifact which contains this annotation
57       */
58      private Artifact artifact;
59  
60      public MojoAnnotatedClass()
61      {
62          // no op
63      }
64  
65      public String getClassName()
66      {
67          return className;
68      }
69  
70      public MojoAnnotatedClass setClassName( String className )
71      {
72          this.className = className;
73          return this;
74      }
75  
76      public MojoAnnotationContent getMojo()
77      {
78          return mojo;
79      }
80  
81      public MojoAnnotatedClass setMojo( MojoAnnotationContent mojo )
82      {
83          this.mojo = mojo;
84          return this;
85      }
86  
87      public ExecuteAnnotationContent getExecute()
88      {
89          return execute;
90      }
91  
92      public MojoAnnotatedClass setExecute( ExecuteAnnotationContent execute )
93      {
94          this.execute = execute;
95          return this;
96      }
97  
98      public Map<String, ParameterAnnotationContent> getParameters()
99      {
100         if ( this.parameters == null )
101         {
102             this.parameters = new HashMap<String, ParameterAnnotationContent>();
103         }
104         return parameters;
105     }
106 
107     public MojoAnnotatedClass setParameters( Map<String, ParameterAnnotationContent> parameters )
108     {
109         this.parameters = parameters;
110         return this;
111     }
112 
113     public Map<String, ComponentAnnotationContent> getComponents()
114     {
115         if ( this.components == null )
116         {
117             this.components = new HashMap<String, ComponentAnnotationContent>();
118         }
119         return components;
120     }
121 
122     public MojoAnnotatedClass setComponents( Map<String, ComponentAnnotationContent> components )
123     {
124         this.components = components;
125         return this;
126     }
127 
128     public String getParentClassName()
129     {
130         return parentClassName;
131     }
132 
133     public MojoAnnotatedClass setParentClassName( String parentClassName )
134     {
135         this.parentClassName = parentClassName;
136         return this;
137     }
138 
139     public Artifact getArtifact()
140     {
141         return artifact;
142     }
143 
144     public void setArtifact( Artifact artifact )
145     {
146         this.artifact = artifact;
147     }
148 
149     public boolean hasAnnotations()
150     {
151         return !( getComponents().isEmpty() && getParameters().isEmpty() && execute == null && mojo == null );
152     }
153 
154     @Override
155     public String toString()
156     {
157         final StringBuilder sb = new StringBuilder();
158         sb.append( "MojoAnnotatedClass" );
159         sb.append( "{className='" ).append( className ).append( '\'' );
160         sb.append( ", parentClassName='" ).append( parentClassName ).append( '\'' );
161         sb.append( ", mojo=" ).append( mojo );
162         sb.append( ", execute=" ).append( execute );
163         sb.append( ", parameters=" ).append( parameters );
164         sb.append( ", components=" ).append( components );
165         sb.append( '}' );
166         return sb.toString();
167     }
168 }