001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.tools.plugin.extractor.annotations.scanner;
020
021import java.util.ArrayList;
022import java.util.HashMap;
023import java.util.List;
024import java.util.Map;
025
026import org.apache.maven.artifact.Artifact;
027import org.apache.maven.tools.plugin.extractor.annotations.datamodel.AfterAnnotationContent;
028import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ComponentAnnotationContent;
029import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ExecuteAnnotationContent;
030import org.apache.maven.tools.plugin.extractor.annotations.datamodel.MojoAnnotationContent;
031import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ParameterAnnotationContent;
032
033/**
034 * @author Olivier Lamy
035 * @since 3.0
036 */
037public class MojoAnnotatedClass {
038    private String className;
039
040    private int classVersion;
041
042    private String parentClassName;
043
044    private MojoAnnotationContent mojo;
045
046    private ExecuteAnnotationContent execute;
047
048    private List<AfterAnnotationContent> afterAnnotations;
049
050    /**
051     * key is field name
052     */
053    private Map<String, ParameterAnnotationContent> parameters;
054
055    /**
056     * key is field name
057     */
058    private Map<String, ComponentAnnotationContent> components;
059
060    /**
061     * artifact which contains this annotation
062     */
063    private Artifact artifact;
064
065    private boolean v4Api;
066
067    public MojoAnnotatedClass() {
068        // no op
069    }
070
071    public String getClassName() {
072        return className;
073    }
074
075    public MojoAnnotatedClass setClassName(String className) {
076        this.className = className;
077        return this;
078    }
079
080    public int getClassVersion() {
081        return classVersion;
082    }
083
084    public MojoAnnotatedClass setClassVersion(int classVersion) {
085        this.classVersion = classVersion;
086        return this;
087    }
088
089    public MojoAnnotationContent getMojo() {
090        return mojo;
091    }
092
093    public MojoAnnotatedClass setMojo(MojoAnnotationContent mojo) {
094        this.mojo = mojo;
095        return this;
096    }
097
098    public ExecuteAnnotationContent getExecute() {
099        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}