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