001package org.apache.maven.tools.plugin.extractor.annotations.scanner;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.maven.artifact.Artifact;
023import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ComponentAnnotationContent;
024import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ExecuteAnnotationContent;
025import org.apache.maven.tools.plugin.extractor.annotations.datamodel.MojoAnnotationContent;
026import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ParameterAnnotationContent;
027
028import java.util.HashMap;
029import java.util.Map;
030
031/**
032 * @author Olivier Lamy
033 * @since 3.0
034 */
035public class MojoAnnotatedClass
036{
037    private String className;
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    public MojoAnnotatedClass()
061    {
062        // no op
063    }
064
065    public String getClassName()
066    {
067        return className;
068    }
069
070    public MojoAnnotatedClass setClassName( String className )
071    {
072        this.className = className;
073        return this;
074    }
075
076    public MojoAnnotationContent getMojo()
077    {
078        return mojo;
079    }
080
081    public MojoAnnotatedClass setMojo( MojoAnnotationContent mojo )
082    {
083        this.mojo = mojo;
084        return this;
085    }
086
087    public ExecuteAnnotationContent getExecute()
088    {
089        return execute;
090    }
091
092    public MojoAnnotatedClass setExecute( ExecuteAnnotationContent execute )
093    {
094        this.execute = execute;
095        return this;
096    }
097
098    public Map<String, ParameterAnnotationContent> getParameters()
099    {
100        if ( this.parameters == null )
101        {
102            this.parameters = new HashMap<String, ParameterAnnotationContent>();
103        }
104        return parameters;
105    }
106
107    public MojoAnnotatedClass setParameters( Map<String, ParameterAnnotationContent> parameters )
108    {
109        this.parameters = parameters;
110        return this;
111    }
112
113    public Map<String, ComponentAnnotationContent> getComponents()
114    {
115        if ( this.components == null )
116        {
117            this.components = new HashMap<String, ComponentAnnotationContent>();
118        }
119        return components;
120    }
121
122    public MojoAnnotatedClass setComponents( Map<String, ComponentAnnotationContent> components )
123    {
124        this.components = components;
125        return this;
126    }
127
128    public String getParentClassName()
129    {
130        return parentClassName;
131    }
132
133    public MojoAnnotatedClass setParentClassName( String parentClassName )
134    {
135        this.parentClassName = parentClassName;
136        return this;
137    }
138
139    public Artifact getArtifact()
140    {
141        return artifact;
142    }
143
144    public void setArtifact( Artifact artifact )
145    {
146        this.artifact = artifact;
147    }
148
149    public boolean hasAnnotations()
150    {
151        return !( getComponents().isEmpty() && getParameters().isEmpty() && execute == null && mojo == null );
152    }
153
154    @Override
155    public String toString()
156    {
157        final StringBuilder sb = new StringBuilder();
158        sb.append( "MojoAnnotatedClass" );
159        sb.append( "{className='" ).append( className ).append( '\'' );
160        sb.append( ", parentClassName='" ).append( parentClassName ).append( '\'' );
161        sb.append( ", mojo=" ).append( mojo );
162        sb.append( ", execute=" ).append( execute );
163        sb.append( ", parameters=" ).append( parameters );
164        sb.append( ", components=" ).append( components );
165        sb.append( '}' );
166        return sb.toString();
167    }
168}