View Javadoc
1   /*
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    * http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   */
14  
15  package org.basepom.mojo.propertyhelper;
16  
17  import org.basepom.mojo.propertyhelper.fields.NumberField;
18  
19  import java.io.IOException;
20  import java.util.List;
21  
22  import com.google.common.flogger.FluentLogger;
23  import org.apache.maven.plugin.MojoExecutionException;
24  import org.apache.maven.plugins.annotations.Mojo;
25  import org.apache.maven.plugins.annotations.Parameter;
26  
27  /**
28   * Fetches the defined numbers, adds properties and increments all numbers.
29   */
30  @Mojo(name = "inc", threadSafe = true)
31  public final class IncMojo
32          extends AbstractPropertyHelperMojo {
33      private static final FluentLogger LOG = FluentLogger.forEnclosingClass();
34  
35      /**
36       * If set to true, all fields that have a {@code <propertyFile>} configuration
37       * attribute are persisted to disk.
38       */
39      @Parameter(defaultValue = "true")
40      boolean persist = true;
41  
42      @Override
43      protected void doExecute() throws IOException, MojoExecutionException {
44          LOG.atFine().log("Running IncrementNumbers");
45  
46          createFieldDefinitions();
47          createFields();
48          createGroups();
49  
50          final List<NumberField> numberFields = getNumbers();
51  
52          if (numberFields != null) {
53              for (NumberField nf : numberFields) {
54                  nf.increment();
55              }
56          }
57  
58          if (persist) {
59              valueCache.persist();
60          }
61      }
62  }