View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.tools.plugin;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.List;
24  import java.util.Objects;
25  
26  import org.apache.maven.plugin.descriptor.MojoDescriptor;
27  import org.apache.maven.plugin.descriptor.Parameter;
28  
29  /**
30   * Extensions to {@link MojoDescriptor} not supported by Maven 3.2.5.
31   *
32   * @author Kristian Rosenvold
33   */
34  public class ExtendedMojoDescriptor extends MojoDescriptor {
35      private final boolean containsXhtmlTextValues;
36      private boolean v4Api;
37      private List<AfterLink> afterLinks;
38  
39      public ExtendedMojoDescriptor() {
40          this(false);
41      }
42  
43      /**
44       * @param containsXhtmlTextValues
45       * @since 3.7.0
46       */
47      public ExtendedMojoDescriptor(boolean containsXhtmlTextValues) {
48          this.containsXhtmlTextValues = containsXhtmlTextValues;
49      }
50  
51      /**
52       * Indicates if the methods {@link #getDescription()}, {@link #getDeprecated()}, {@link Parameter#getDescription()}
53       * and {@link Parameter#getDeprecated()} return XHTML values.
54       * @return {@code true} if aforementioned methods return XHTML values, if {@code false} those values contain
55       * javadoc (HTML + custom javadoc tags) (for legacy extractors)
56       * @since 3.7.0
57       */
58      public boolean containsXhtmlTextValues() {
59          return containsXhtmlTextValues;
60      }
61  
62      public boolean isV4Api() {
63          return v4Api;
64      }
65  
66      public void setV4Api(boolean v4Api) {
67          this.v4Api = v4Api;
68      }
69  
70      /**
71       * Returns the after-links declared via {@code @After} annotations.
72       *
73       * @return unmodifiable list of after-links, never {@code null}
74       * @since 4.0.0
75       */
76      public List<AfterLink> getAfterLinks() {
77          return afterLinks != null ? Collections.unmodifiableList(afterLinks) : Collections.emptyList();
78      }
79  
80      /**
81       * Adds an after-link.
82       *
83       * @param afterLink the after-link to add
84       * @since 4.0.0
85       */
86      public void addAfterLink(AfterLink afterLink) {
87          if (this.afterLinks == null) {
88              this.afterLinks = new ArrayList<>();
89          }
90          this.afterLinks.add(afterLink);
91      }
92  
93      /**
94       * Holds after-link data from the {@code @After} annotation.
95       * <p>
96       * Mirrors the {@code org.apache.maven.api.plugin.descriptor.AfterLink} model class
97       * from the Maven 4 API without introducing a compile-time dependency on it.
98       *
99       * @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 }