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 java.io.IOException;
18  
19  import com.google.common.flogger.FluentLogger;
20  import org.apache.maven.plugin.MojoExecutionException;
21  import org.apache.maven.plugins.annotations.Mojo;
22  import org.apache.maven.plugins.annotations.Parameter;
23  
24  /**
25   * Fetches the defined numbers and add properties.
26   */
27  @Mojo(name = "get", threadSafe = true)
28  public final class GetMojo extends AbstractPropertyHelperMojo {
29  
30      private static final FluentLogger LOG = FluentLogger.forEnclosingClass();
31  
32      /**
33       * If set to true, all fields that have a {@code <propertyFile>} configuration
34       * attribute are persisted to disk.
35       */
36      @Parameter(defaultValue = "false")
37      boolean persist = false;
38  
39  
40      @Override
41      protected void doExecute() throws MojoExecutionException, IOException {
42          LOG.atFine().log("Running property-helper:get");
43  
44          createFieldDefinitions();
45          createFields();
46          createGroups();
47  
48          if (persist) {
49              LOG.atFine().log("Persisting value cache");
50              // Now dump the value cache back to the files if necessary.
51              valueCache.persist();
52          }
53      }
54  }