Skip to content

Commit

Permalink
[MRRESOURCES-151] Deprecate includeProjectProperties parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Dec 19, 2024
1 parent 93a1e11 commit 6e36902
Showing 1 changed file with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,17 @@ public abstract class AbstractProcessRemoteResourcesMojo extends AbstractMojo {
* javadoc for MavenProject</a> for information about the properties on the MavenProject.
*/
@Parameter
protected Map<String, Object> properties = new HashMap<>();
protected Map<String, String> properties = new HashMap<>();

/**
* Whether to include properties defined in the project when filtering resources.
*
* @deprecated as Maven Project is available in Velocity context we can simply use
* <code>$project.properties.propertyName</code>
*
* @since 1.2
*/
@Deprecated
@Parameter(defaultValue = "false")
protected boolean includeProjectProperties = false;

Expand Down Expand Up @@ -419,13 +423,6 @@ public void execute() throws MojoExecutionException {

configureLocator();

if (includeProjectProperties) {
final Properties projectProperties = project.getProperties();
for (Object key : projectProperties.keySet()) {
properties.put(key.toString(), projectProperties.get(key).toString());
}
}

ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
try {
validate();
Expand All @@ -442,7 +439,7 @@ public void execute() throws MojoExecutionException {
velocity.setProperty("resource.loader.classpath.class", ClasspathResourceLoader.class.getName());
velocity.init();

VelocityContext context = buildVelocityContext(properties);
VelocityContext context = buildVelocityContext();

processResourceBundles(classLoader, context);

Expand Down Expand Up @@ -745,9 +742,19 @@ protected void validate() throws MojoExecutionException {
private static final String KEY_PROJECTS = "projects";
private static final String KEY_PROJECTS_ORGS = "projectsSortedByOrganization";

protected VelocityContext buildVelocityContext(Map<String, Object> properties) {
protected VelocityContext buildVelocityContext() {

Map<String, Object> contextProperties = new HashMap<>(properties);

if (includeProjectProperties) {
final Properties projectProperties = project.getProperties();
for (String key : projectProperties.stringPropertyNames()) {
contextProperties.put(key, projectProperties.getProperty(key));
}
}

// the following properties are expensive to calculate, so we provide them lazily
VelocityContext context = new VelocityContext(properties) {
VelocityContext context = new VelocityContext(contextProperties) {
@Override
public Object internalGet(String key) {
Object result = super.internalGet(key);
Expand Down

0 comments on commit 6e36902

Please sign in to comment.