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