diff --git a/src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java b/src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java index b5974fc..4e5baca 100644 --- a/src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java +++ b/src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java @@ -80,7 +80,6 @@ import org.apache.maven.shared.filtering.MavenFileFilterRequest; import org.apache.maven.shared.filtering.MavenFilteringException; import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.Velocity; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.exception.MethodInvocationException; import org.apache.velocity.exception.ParseErrorException; @@ -980,8 +979,7 @@ protected void processResourceBundles(ClassLoader classLoader, VelocityContext c try (CachingOutputStream os = new CachingOutputStream(outputFile); Reader reader = getReader(bundle.getSourceEncoding(), appendedVmResourceFile); Writer writer = getWriter(bundle.getSourceEncoding(), os)) { - Velocity.init(); - Velocity.evaluate(context, writer, "remote-resources", reader); + velocity.evaluate(context, writer, "remote-resources", reader); } } } diff --git a/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java b/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java index 78d895e..6511a2a 100644 --- a/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java +++ b/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java @@ -254,6 +254,38 @@ public void testFilteredBundles() throws Exception { assertTrue(data.contains("projectsSortedByOrganization: {")); } + public void testFilteredAppendedResource() throws Exception { + final MavenProjectResourcesStub project = createTestProject("default-appended-filtered-resource"); + final ProcessRemoteResourcesMojo mojo = lookupProcessMojoWithSettings(project, new String[] {"test:test:1.4"}); + + setupDefaultProject(project); + + String path = pathOf(new DefaultArtifact( + "test", "test", VersionRange.createFromVersion("1.4"), null, "jar", "", new DefaultArtifactHandler())); + File bundleJar = new File(path); + bundleJar.getParentFile().mkdirs(); + buildResourceBundle( + "default-appended-filtered-resource-create", + null, + new String[] {"BUNDLE_FILTER.txt.vm", "APPENDED_FILTER.txt"}, + bundleJar); + + File appendedResourcesDirectory = new File(project.getBasedir(), "src/main/appended-resources"); + appendedResourcesDirectory.mkdirs(); + FileUtils.fileWrite( + new File(appendedResourcesDirectory, "APPENDED_FILTER.txt.vm").getAbsolutePath(), + "appended: $project.name"); + setVariableValueToObject(mojo, "appendedResourcesDirectory", appendedResourcesDirectory); + + mojo.execute(); + + File outputDirectory = (File) getVariableValueFromObject(mojo, "outputDirectory"); + String appendedData = FileUtils.fileRead(new File(outputDirectory, "APPENDED_FILTER.txt")); + assertTrue(appendedData.contains("appended: Test Project default-appended-filtered-resource")); + String bundleData = FileUtils.fileRead(new File(outputDirectory, "BUNDLE_FILTER.txt")); + assertTrue(bundleData.contains("project.name: Test Project default-appended-filtered-resource")); + } + public void testFilteredBundlesWithProjectProperties() throws Exception { final MavenProjectResourcesStub project = createTestProject("default-filterbundles-two"); final ProcessRemoteResourcesMojo mojo = diff --git a/src/test/resources/APPENDED_FILTER.txt b/src/test/resources/APPENDED_FILTER.txt new file mode 100644 index 0000000..73e7a71 --- /dev/null +++ b/src/test/resources/APPENDED_FILTER.txt @@ -0,0 +1,17 @@ +## Licensed to the Apache Software Foundation (ASF) under one +## or more contributor license agreements. See the NOTICE file +## distributed with this work for additional information +## regarding copyright ownership. The ASF licenses this file +## to you under the Apache License, Version 2.0 (the +## "License"); you may not use this file except in compliance +## with the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, +## software distributed under the License is distributed on an +## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +## KIND, either express or implied. See the License for the +## specific language governing permissions and limitations +## under the License. +bundle content should be replaced by the appended Velocity template diff --git a/src/test/resources/BUNDLE_FILTER.txt.vm b/src/test/resources/BUNDLE_FILTER.txt.vm new file mode 100644 index 0000000..3701096 --- /dev/null +++ b/src/test/resources/BUNDLE_FILTER.txt.vm @@ -0,0 +1,17 @@ +## Licensed to the Apache Software Foundation (ASF) under one +## or more contributor license agreements. See the NOTICE file +## distributed with this work for additional information +## regarding copyright ownership. The ASF licenses this file +## to you under the Apache License, Version 2.0 (the +## "License"); you may not use this file except in compliance +## with the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, +## software distributed under the License is distributed on an +## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +## KIND, either express or implied. See the License for the +## specific language governing permissions and limitations +## under the License. +project.name: ${project.name}