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.HashMap; 022import java.util.Map; 023 024import org.apache.maven.artifact.Artifact; 025import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ComponentAnnotationContent; 026import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ExecuteAnnotationContent; 027import org.apache.maven.tools.plugin.extractor.annotations.datamodel.MojoAnnotationContent; 028import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ParameterAnnotationContent; 029 030/** 031 * @author Olivier Lamy 032 * @since 3.0 033 */ 034public class MojoAnnotatedClass { 035 private String className; 036 037 private int classVersion; 038 039 private String parentClassName; 040 041 private MojoAnnotationContent mojo; 042 043 private ExecuteAnnotationContent execute; 044 045 /** 046 * key is field name 047 */ 048 private Map<String, ParameterAnnotationContent> parameters; 049 050 /** 051 * key is field name 052 */ 053 private Map<String, ComponentAnnotationContent> components; 054 055 /** 056 * artifact which contains this annotation 057 */ 058 private Artifact artifact; 059 060 private boolean v4Api; 061 062 public MojoAnnotatedClass() { 063 // no op 064 } 065 066 public String getClassName() { 067 return className; 068 } 069 070 public MojoAnnotatedClass setClassName(String className) { 071 this.className = className; 072 return this; 073 } 074 075 public int getClassVersion() { 076 return classVersion; 077 } 078 079 public MojoAnnotatedClass setClassVersion(int classVersion) { 080 this.classVersion = classVersion; 081 return this; 082 } 083 084 public MojoAnnotationContent getMojo() { 085 return mojo; 086 } 087 088 public MojoAnnotatedClass setMojo(MojoAnnotationContent mojo) { 089 this.mojo = mojo; 090 return this; 091 } 092 093 public ExecuteAnnotationContent getExecute() { 094 return execute; 095 } 096 097 public MojoAnnotatedClass setExecute(ExecuteAnnotationContent execute) { 098 this.execute = execute; 099 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}