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.plugins.enforcer.internal;
20  
21  import org.apache.maven.enforcer.rule.api.EnforcerLevel;
22  import org.apache.maven.enforcer.rule.api.EnforcerRuleBase;
23  
24  /**
25   * Description of rule to execute.
26   *
27   * @author Slawomir Jaranowski
28   * @since 3.2.0
29   */
30  public final class EnforcerRuleDesc {
31  
32      private final String name;
33  
34      private final EnforcerRuleBase rule;
35  
36      /**
37       * Create a new Rule Description
38       *
39       * @param name  a rule name
40       * @param rule  a rule instance
41       */
42      public EnforcerRuleDesc(String name, EnforcerRuleBase rule) {
43          this.name = name;
44          this.rule = rule;
45      }
46  
47      public String getName() {
48          String ruleName = rule.getRuleName();
49          return ruleName == null || ruleName.isEmpty() ? name : ruleName;
50      }
51  
52      public EnforcerRuleBase getRule() {
53          return rule;
54      }
55  
56      public EnforcerLevel getLevel() {
57          return rule.getLevel();
58      }
59  
60      @Override
61      public String toString() {
62          return String.format("EnforcerRuleDesc[name=%s, rule=%s, level=%s]", name, rule, getLevel());
63      }
64  }