Package org.codehaus.mojo.properties
Class ReadPropertiesMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- 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 org.apache.maven.plugin.AbstractMojo
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ReadPropertiesMojo.FileResource
private static class
ReadPropertiesMojo.Resource
private static class
ReadPropertiesMojo.UrlResource
-
Field Summary
Fields Modifier and Type Field Description private java.io.File[]
files
The properties files that will be used when reading properties.private java.lang.String
keyPrefix
Prefix that will be added before name of each property.private org.apache.maven.project.MavenProject
project
private boolean
quiet
If the plugin should be quiet if any of the files was not foundprivate PropertyResolver
resolver
Used for resolving property placeholders.private java.lang.String[]
urls
The URLs that will be used when reading properties.
-
Constructor Summary
Constructors Constructor Description ReadPropertiesMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
checkParameters()
void
execute()
private java.lang.String
getPropertyValue(java.lang.String k, java.util.Properties p, java.util.Properties environment)
(package private) java.util.Properties
getSystemEnvVars()
Override-able for test purposes.private void
load(ReadPropertiesMojo.Resource resource)
private void
loadFiles()
private void
loadProperties(ReadPropertiesMojo.Resource resource)
private java.util.Properties
loadSystemEnvironmentPropertiesWhenDefined()
private void
loadUrls()
private void
missing(ReadPropertiesMojo.Resource resource)
private void
resolveProperties()
void
setFiles(java.io.File[] files)
void
setKeyPrefix(java.lang.String keyPrefix)
(package private) void
setProject(org.apache.maven.project.MavenProject project)
Default scope for test access.(package private) void
setQuiet(boolean quiet)
Default scope for test access.void
setUrls(java.lang.String[] urls)
Default scope for test access.
-
-
-
Field Detail
-
project
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject project
-
files
@Parameter private java.io.File[] files
The properties files that will be used when reading properties.
-
urls
@Parameter private java.lang.String[] urls
The URLs that will be used when reading properties. These may be non-standard URLs of the formclasspath:com/company/resource.properties
. Note that the type is notURL
for this reason and therefore will be explicitly checked by this Mojo.
-
quiet
@Parameter(defaultValue="false") private boolean quiet
If the plugin should be quiet if any of the files was not found
-
keyPrefix
@Parameter private java.lang.String keyPrefix
Prefix that will be added before name of each property. Can be useful for separating properties with same name from different files.
-
resolver
private final PropertyResolver resolver
Used for resolving property placeholders.
-
-
Method Detail
-
setFiles
public void setFiles(java.io.File[] files)
- Parameters:
files
- The files to set for tests.
-
setUrls
public void setUrls(java.lang.String[] urls)
Default scope for test access.- Parameters:
urls
- The URLs to set for tests.
-
setKeyPrefix
public void setKeyPrefix(java.lang.String keyPrefix)
-
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 java.util.Properties loadSystemEnvironmentPropertiesWhenDefined() throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
getPropertyValue
private java.lang.String getPropertyValue(java.lang.String k, java.util.Properties p, java.util.Properties environment) throws org.apache.maven.plugin.MojoFailureException
- Throws:
org.apache.maven.plugin.MojoFailureException
-
getSystemEnvVars
java.util.Properties getSystemEnvVars() throws java.io.IOException
Override-able for test purposes.- Returns:
- The shell environment variables, can be empty but never
null
. - Throws:
java.io.IOException
- If the environment variables could not be queried from the shell.
-
setQuiet
void setQuiet(boolean quiet)
Default scope for test access.- Parameters:
quiet
- Set totrue
if missing files can be skipped.
-
setProject
void setProject(org.apache.maven.project.MavenProject project)
Default scope for test access.- Parameters:
project
- The test project.
-
-