001/* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014 015package org.basepom.mojo.propertyhelper; 016 017import org.basepom.mojo.propertyhelper.fields.NumberField; 018 019import java.io.IOException; 020import java.util.List; 021 022import com.google.common.flogger.FluentLogger; 023import org.apache.maven.plugin.MojoExecutionException; 024import org.apache.maven.plugins.annotations.Mojo; 025import org.apache.maven.plugins.annotations.Parameter; 026 027/** 028 * Fetches the defined numbers, adds properties and increments all numbers. 029 */ 030@Mojo(name = "inc", threadSafe = true) 031public final class IncMojo 032 extends AbstractPropertyHelperMojo { 033 private static final FluentLogger LOG = FluentLogger.forEnclosingClass(); 034 035 /** 036 * If set to true, all fields that have a {@code <propertyFile>} configuration 037 * attribute are persisted to disk. 038 */ 039 @Parameter(defaultValue = "true") 040 boolean persist = true; 041 042 @Override 043 protected void doExecute() throws IOException, MojoExecutionException { 044 LOG.atFine().log("Running IncrementNumbers"); 045 046 createFieldDefinitions(); 047 createFields(); 048 createGroups(); 049 050 final List<NumberField> numberFields = getNumbers(); 051 052 if (numberFields != null) { 053 for (NumberField nf : numberFields) { 054 nf.increment(); 055 } 056 } 057 058 if (persist) { 059 valueCache.persist(); 060 } 061 } 062}