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;
020
021import java.util.ArrayList;
022import java.util.Collections;
023import java.util.List;
024import java.util.Objects;
025
026import org.apache.maven.plugin.descriptor.MojoDescriptor;
027import org.apache.maven.plugin.descriptor.Parameter;
028
029/**
030 * Extensions to {@link MojoDescriptor} not supported by Maven 3.2.5.
031 *
032 * @author Kristian Rosenvold
033 */
034public class ExtendedMojoDescriptor extends MojoDescriptor {
035    private final boolean containsXhtmlTextValues;
036    private boolean v4Api;
037    private List<AfterLink> afterLinks;
038
039    public ExtendedMojoDescriptor() {
040        this(false);
041    }
042
043    /**
044     * @param containsXhtmlTextValues
045     * @since 3.7.0
046     */
047    public ExtendedMojoDescriptor(boolean containsXhtmlTextValues) {
048        this.containsXhtmlTextValues = containsXhtmlTextValues;
049    }
050
051    /**
052     * Indicates if the methods {@link #getDescription()}, {@link #getDeprecated()}, {@link Parameter#getDescription()}
053     * and {@link Parameter#getDeprecated()} return XHTML values.
054     * @return {@code true} if aforementioned methods return XHTML values, if {@code false} those values contain
055     * javadoc (HTML + custom javadoc tags) (for legacy extractors)
056     * @since 3.7.0
057     */
058    public boolean containsXhtmlTextValues() {
059        return containsXhtmlTextValues;
060    }
061
062    public boolean isV4Api() {
063        return v4Api;
064    }
065
066    public void setV4Api(boolean v4Api) {
067        this.v4Api = v4Api;
068    }
069
070    /**
071     * Returns the after-links declared via {@code @After} annotations.
072     *
073     * @return unmodifiable list of after-links, never {@code null}
074     * @since 4.0.0
075     */
076    public List<AfterLink> getAfterLinks() {
077        return afterLinks != null ? Collections.unmodifiableList(afterLinks) : Collections.emptyList();
078    }
079
080    /**
081     * Adds an after-link.
082     *
083     * @param afterLink the after-link to add
084     * @since 4.0.0
085     */
086    public void addAfterLink(AfterLink afterLink) {
087        if (this.afterLinks == null) {
088            this.afterLinks = new ArrayList<>();
089        }
090        this.afterLinks.add(afterLink);
091    }
092
093    /**
094     * Holds after-link data from the {@code @After} annotation.
095     * <p>
096     * Mirrors the {@code org.apache.maven.api.plugin.descriptor.AfterLink} model class
097     * from the Maven 4 API without introducing a compile-time dependency on it.
098     *
099     * @since 4.0.0
100     */
101    public static class AfterLink {
102        private final String phase;
103        private final String type;
104        private final String scope;
105
106        public AfterLink(String phase, String type, String scope) {
107            this.phase = phase;
108            this.type = type;
109            this.scope = scope;
110        }
111
112        public String getPhase() {
113            return phase;
114        }
115
116        public String getType() {
117            return type;
118        }
119
120        public String getScope() {
121            return scope;
122        }
123
124        @Override
125        public String toString() {
126            return "AfterLink{phase='" + phase + "', type='" + type + "', scope='" + scope + "'}";
127        }
128    }
129
130    @Override
131    public int hashCode() {
132        return Objects.hash(containsXhtmlTextValues, v4Api);
133    }
134
135    @Override
136    public boolean equals(Object obj) {
137        if (this == obj) {
138            return true;
139        }
140        if (!super.equals(obj)) {
141            return false;
142        }
143        if (getClass() != obj.getClass()) {
144            return false;
145        }
146        ExtendedMojoDescriptor other = (ExtendedMojoDescriptor) obj;
147        return Objects.equals(containsXhtmlTextValues, other.containsXhtmlTextValues)
148                && Objects.equals(v4Api, other.v4Api);
149    }
150}