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.macros.MacroType;
18  
19  import java.io.File;
20  import java.util.Collections;
21  import java.util.Map;
22  import java.util.Properties;
23  
24  import org.apache.maven.project.MavenProject;
25  import org.apache.maven.settings.Settings;
26  
27  /**
28   * All accessible values from the Maven build system for a Field.
29   */
30  public interface FieldContext {
31  
32      /** Returns a fixed instance for testing. Do not use outside test code. */
33      static FieldContext forTesting() {
34          return new FieldContext() {
35  
36              @Override
37              public Map<String, MacroType> getMacros() {
38                  return Collections.emptyMap();
39              }
40  
41              @Override
42              public Properties getProjectProperties() {
43                  return new Properties();
44              }
45  
46              @Override
47              public MavenProject getProject() {
48                  return new MavenProject();
49              }
50  
51              @Override
52              public Settings getSettings() {
53                  return new Settings();
54              }
55  
56              @Override
57              public File getBasedir() {
58                  throw new UnsupportedOperationException();
59              }
60  
61              @Override
62              public InterpolatorFactory getInterpolatorFactory() {
63                  return InterpolatorFactory.forTesting();
64              }
65  
66              @Override
67              public TransformerRegistry getTransformerRegistry() {
68                  return TransformerRegistry.INSTANCE;
69              }
70          };
71      }
72  
73      /**
74       * Returns a map with all known macros. Key value is the macro hint as given by the plexus component annotation.
75       * @return A map with all known macros.
76       */
77      Map<String, MacroType> getMacros();
78  
79      /**
80       * Return the maven project properties.
81       * @return A properties object for the project properties.
82       */
83      Properties getProjectProperties();
84  
85      /**
86       * Returns a reference to the {@link MavenProject}.
87       * @return A {@link MavenProject} object
88       */
89      MavenProject getProject();
90  
91      /**
92       * Returns the current maven {@link Settings} object
93       * @return A {@link Settings} object
94       */
95      Settings getSettings();
96  
97      /**
98       * Returns the base dir for this maven build execution.
99       *
100      * @return A {@link File} object.
101      */
102     File getBasedir();
103 
104     /**
105      * Returns the {@link InterpolatorFactory} that can interpolate "late resolution" properties.
106      * @return An {@link InterpolatorFactory} reference.
107      */
108     InterpolatorFactory getInterpolatorFactory();
109 
110     /**
111      * Returns a reference to the {@link TransformerRegistry}.
112      * @return A {@link TransformerRegistry} object.
113      */
114     TransformerRegistry getTransformerRegistry();
115 }