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.datamodel; 020 021import java.lang.annotation.Annotation; 022import java.util.Objects; 023 024import org.apache.maven.plugins.annotations.InstantiationStrategy; 025import org.apache.maven.plugins.annotations.LifecyclePhase; 026import org.apache.maven.plugins.annotations.Mojo; 027import org.apache.maven.plugins.annotations.ResolutionScope; 028 029/** 030 * @author Olivier Lamy 031 * @since 3.0 032 */ 033public class MojoAnnotationContent extends AnnotatedContent implements Mojo { 034 private String name; 035 036 private LifecyclePhase defaultPhase = LifecyclePhase.NONE; 037 038 private ResolutionScope requiresDependencyResolution = ResolutionScope.NONE; 039 040 private ResolutionScope requiresDependencyCollection = ResolutionScope.NONE; 041 042 private InstantiationStrategy instantiationStrategy = InstantiationStrategy.PER_LOOKUP; 043 044 private String executionStrategy = "once-per-session"; 045 046 private boolean requiresProject = true; 047 048 private boolean requiresReports = false; 049 050 private boolean aggregator = false; 051 052 private boolean requiresDirectInvocation = false; 053 054 private boolean requiresOnline = false; 055 056 private boolean inheritByDefault = true; 057 058 private String configurator; 059 060 private boolean threadSafe = false; 061 062 @Override 063 public Class<? extends Annotation> annotationType() { 064 return null; 065 } 066 067 @Override 068 public LifecyclePhase defaultPhase() { 069 return defaultPhase; 070 } 071 072 public void defaultPhase(String phase) { 073 if (phase != null && !phase.isEmpty()) { 074 for (LifecyclePhase p : LifecyclePhase.values()) { 075 if (Objects.equals(phase, p.id()) || Objects.equals(phase, p.name())) { 076 this.defaultPhase = p; 077 return; 078 } 079 } 080 throw new IllegalArgumentException("Could not find a matching phase for " + phase); 081 } else { 082 this.defaultPhase = null; 083 } 084 } 085 086 @Override 087 public ResolutionScope requiresDependencyResolution() { 088 return requiresDependencyResolution; 089 } 090 091 public void requiresDependencyResolution(String requiresDependencyResolution) { 092 this.requiresDependencyResolution = ResolutionScope.valueOf(requiresDependencyResolution); 093 } 094 095 public void dependencyResolutionRequired(String dependencyResolutionRequired) { 096 this.requiresDependencyResolution = ResolutionScope.valueOf(dependencyResolutionRequired); 097 } 098 099 @Override 100 public ResolutionScope requiresDependencyCollection() { 101 return requiresDependencyCollection; 102 } 103 104 public void requiresDependencyCollection(String requiresDependencyCollection) { 105 this.requiresDependencyCollection = ResolutionScope.valueOf(requiresDependencyCollection); 106 } 107 108 @Override 109 public InstantiationStrategy instantiationStrategy() { 110 return instantiationStrategy; 111 } 112 113 public void instantiationStrategy(String instantiationStrategy) { 114 this.instantiationStrategy = InstantiationStrategy.valueOf(instantiationStrategy); 115 } 116 117 @Override 118 public String executionStrategy() { 119 return executionStrategy; 120 } 121 122 public void executionStrategy(String executionStrategy) { 123 this.executionStrategy = executionStrategy; 124 } 125 126 @Override 127 public boolean requiresProject() { 128 return requiresProject; 129 } 130 131 public void requiresProject(boolean requiresProject) { 132 this.requiresProject = requiresProject; 133 } 134 135 public void projectRequired(boolean requiresProject) { 136 this.requiresProject = requiresProject; 137 } 138 139 @Override 140 public boolean requiresReports() { 141 return requiresReports; 142 } 143 144 public void requiresReports(boolean requiresReports) { 145 this.requiresReports = requiresReports; 146 } 147 148 @Override 149 public boolean aggregator() { 150 return aggregator; 151 } 152 153 public void aggregator(boolean aggregator) { 154 this.aggregator = aggregator; 155 } 156 157 @Override 158 public boolean requiresDirectInvocation() { 159 return requiresDirectInvocation; 160 } 161 162 public void requiresDirectInvocation(boolean requiresDirectInvocation) { 163 this.requiresDirectInvocation = requiresDirectInvocation; 164 } 165 166 @Override 167 public boolean requiresOnline() { 168 return requiresOnline; 169 } 170 171 public void requiresOnline(boolean requiresOnline) { 172 this.requiresOnline = requiresOnline; 173 } 174 175 @Override 176 public boolean inheritByDefault() { 177 return inheritByDefault; 178 } 179 180 public void inheritByDefault(boolean inheritByDefault) { 181 this.inheritByDefault = inheritByDefault; 182 } 183 184 @Override 185 public String configurator() { 186 return configurator; 187 } 188 189 public void configurator(String configurator) { 190 this.configurator = configurator; 191 } 192 193 @Override 194 public boolean threadSafe() { 195 return threadSafe; 196 } 197 198 public void threadSafe(boolean threadSafe) { 199 this.threadSafe = threadSafe; 200 } 201 202 @Override 203 public String name() { 204 return this.name; 205 } 206 207 public void name(String name) { 208 this.name = name; 209 } 210 211 @Override 212 public String toString() { 213 final StringBuilder sb = new StringBuilder(); 214 sb.append("MojoAnnotationContent"); 215 sb.append("{name='").append(name).append('\''); 216 sb.append(", defaultPhase=").append(defaultPhase); 217 sb.append(", requiresDependencyResolution='") 218 .append(requiresDependencyResolution) 219 .append('\''); 220 sb.append(", requiresDependencyCollection='") 221 .append(requiresDependencyCollection) 222 .append('\''); 223 sb.append(", instantiationStrategy='").append(instantiationStrategy).append('\''); 224 sb.append(", executionStrategy='").append(executionStrategy).append('\''); 225 sb.append(", requiresProject=").append(requiresProject); 226 sb.append(", requiresReports=").append(requiresReports); 227 sb.append(", aggregator=").append(aggregator); 228 sb.append(", requiresDirectInvocation=").append(requiresDirectInvocation); 229 sb.append(", requiresOnline=").append(requiresOnline); 230 sb.append(", inheritByDefault=").append(inheritByDefault); 231 sb.append(", configurator='").append(configurator).append('\''); 232 sb.append(", threadSafe=").append(threadSafe); 233 sb.append('}'); 234 return sb.toString(); 235 } 236}