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.macros.MacroType;
018
019import java.io.File;
020import java.util.Collections;
021import java.util.Map;
022import java.util.Properties;
023
024import org.apache.maven.project.MavenProject;
025import org.apache.maven.settings.Settings;
026
027/**
028 * All accessible values from the Maven build system for a Field.
029 */
030public interface FieldContext {
031
032    /** Returns a fixed instance for testing. Do not use outside test code. */
033    static FieldContext forTesting() {
034        return new FieldContext() {
035
036            @Override
037            public Map<String, MacroType> getMacros() {
038                return Collections.emptyMap();
039            }
040
041            @Override
042            public Properties getProjectProperties() {
043                return new Properties();
044            }
045
046            @Override
047            public MavenProject getProject() {
048                return new MavenProject();
049            }
050
051            @Override
052            public Settings getSettings() {
053                return new Settings();
054            }
055
056            @Override
057            public File getBasedir() {
058                throw new UnsupportedOperationException();
059            }
060
061            @Override
062            public InterpolatorFactory getInterpolatorFactory() {
063                return InterpolatorFactory.forTesting();
064            }
065
066            @Override
067            public TransformerRegistry getTransformerRegistry() {
068                return TransformerRegistry.INSTANCE;
069            }
070        };
071    }
072
073    /**
074     * Returns a map with all known macros. Key value is the macro hint as given by the plexus component annotation.
075     * @return A map with all known macros.
076     */
077    Map<String, MacroType> getMacros();
078
079    /**
080     * Return the maven project properties.
081     * @return A properties object for the project properties.
082     */
083    Properties getProjectProperties();
084
085    /**
086     * Returns a reference to the {@link MavenProject}.
087     * @return A {@link MavenProject} object
088     */
089    MavenProject getProject();
090
091    /**
092     * Returns the current maven {@link Settings} object
093     * @return A {@link Settings} object
094     */
095    Settings getSettings();
096
097    /**
098     * Returns the base dir for this maven build execution.
099     *
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}