Class ReadPropertiesMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.codehaus.mojo.properties.AbstractPropertiesMojo
org.codehaus.mojo.properties.ReadPropertiesMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

@Mojo(name="read-project-properties", defaultPhase=NONE, threadSafe=true) public class ReadPropertiesMojo extends AbstractPropertiesMojo
The read-project-properties goal reads property files and URLs and stores the properties as project properties. It serves as an alternate to specifying properties in pom.xml. It is especially useful when making properties defined in a runtime resource available at build time.
Since:
1.0.0
  • Field Details

    • project

      @Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject project
    • files

      @Parameter private File[] files
      The properties files that will be used when reading properties.
      Since:
      1.0.0
    • urls

      @Parameter private String[] urls
      The URLs that will be used when reading properties. These may be non-standard URLs of the form classpath:com/company/resource.properties. Note that the type is not URL for this reason and therefore will be explicitly checked by this Mojo.
      Since:
      1.0.0
    • quiet

      @Parameter(defaultValue="false") private boolean quiet
      If the plugin should be quiet if any of the files was not found
      Since:
      1.0.0
    • keyPrefix

      @Parameter private String keyPrefix
      Prefix that will be added before name of each property. Can be useful for separating properties with same name from different files.
      Since:
      1.1.0
    • skipLoadProperties

      @Parameter(defaultValue="false", property="prop.skipLoadProperties") private boolean skipLoadProperties
      Skip plugin execution.
      Since:
      1.2.0
    • useDefaultValues

      @Parameter(defaultValue="false") private boolean useDefaultValues
      If the plugin should process default values within property placeholders
      Since:
      1.2.0
    • override

      @Parameter(defaultValue="true") private boolean override
      Determine, whether existing properties should be overridden or not. Default: true.
      Since:
      1.2.0
    • resolver

      private final PropertyResolver resolver
      Used for resolving property placeholders.
  • Constructor Details

    • ReadPropertiesMojo

      @Inject public ReadPropertiesMojo(List<PropertiesManager> propertiesManagers)
      Default constructor
      Parameters:
      propertiesManagers - list of properties managers
  • Method Details

    • setFiles

      public void setFiles(File[] files)
      Parameters:
      files - The files to set for tests.
    • setUrls

      public void setUrls(String[] urls)
      Default scope for test access.
      Parameters:
      urls - The URLs to set for tests.
    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
      org.apache.maven.plugin.MojoFailureException
    • checkParameters

      private void checkParameters() throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • loadFiles

      private void loadFiles() throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • loadUrls

      private void loadUrls() throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • load

      private void load(ReadPropertiesMojo.Resource resource) throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • loadProperties

      private void loadProperties(ReadPropertiesMojo.Resource resource) throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • missing

      private void missing(ReadPropertiesMojo.Resource resource) throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • resolveProperties

      private void resolveProperties() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
      org.apache.maven.plugin.MojoFailureException
    • loadSystemEnvironmentPropertiesWhenDefined

      private Properties loadSystemEnvironmentPropertiesWhenDefined() throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • getPropertyValue

      private String getPropertyValue(String k, Properties p, Properties environment) throws org.apache.maven.plugin.MojoFailureException
      Throws:
      org.apache.maven.plugin.MojoFailureException
    • getSystemEnvVars

      Properties getSystemEnvVars() throws IOException
      Override-able for test purposes.
      Returns:
      The shell environment variables, can be empty but never null.
      Throws:
      IOException - If the environment variables could not be queried from the shell.
    • setUseDefaultValues

      public void setUseDefaultValues(boolean useDefaultValues)
      Parameters:
      useDefaultValues - set to true if default values need to be processed within property placeholders
    • setKeyPrefix

      void setKeyPrefix(String keyPrefix)
    • setOverride

      void setOverride(boolean override)
    • setProject

      void setProject(org.apache.maven.project.MavenProject project)
      Default scope for test access.
      Parameters:
      project - The test project.
    • getProject

      public org.apache.maven.project.MavenProject getProject()
      For test access.
      Returns:
      The test project