You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2024/12/21 12:01:25 UTC

(maven-remote-resources-plugin) branch MRRESOURCES-154 created (now 183ce17)

This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a change to branch MRRESOURCES-154
in repository https://gitbox.apache.org/repos/asf/maven-remote-resources-plugin.git


      at 183ce17  [MRRESOURCES-154] Allow to require project properties by bundle

This branch includes the following new commits:

     new 183ce17  [MRRESOURCES-154] Allow to require project properties by bundle

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(maven-remote-resources-plugin) 01/01: [MRRESOURCES-154] Allow to require project properties by bundle

Posted by sj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch MRRESOURCES-154
in repository https://gitbox.apache.org/repos/asf/maven-remote-resources-plugin.git

commit 183ce17772f6147179fc5f016a16af5f573ad415
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Sat Dec 21 13:00:51 2024 +0100

    [MRRESOURCES-154] Allow to require project properties by bundle
---
 pom.xml                                            |  6 ++--
 .../invoker.properties                             | 19 ++++++++++++
 .../pom.xml                                        | 15 +++++-----
 .../verify.groovy                                  | 24 +++++++++++++++
 .../invoker.properties                             | 18 +++++++++++
 .../pom.xml                                        | 16 +++++-----
 .../verify.groovy                                  | 23 ++++++++++++++
 src/it/setup-bundle/{ => mrrp-bundle-c}/pom.xml    | 35 +++++-----------------
 .../src/main/resources/required-property.txt.vm    | 18 +++++++++++
 src/it/setup-bundle/pom.xml                        |  2 ++
 .../remote/AbstractProcessRemoteResourcesMojo.java | 16 ++++++++++
 .../remote/BundleRemoteResourcesMojo.java          | 13 ++++++--
 src/main/mdo/remote-resources.mdo                  | 21 +++++++++----
 src/main/mdo/supplemental-model.mdo                |  4 +--
 14 files changed, 177 insertions(+), 53 deletions(-)

diff --git a/pom.xml b/pom.xml
index b2b4214..acc83b0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -281,7 +281,7 @@ under the License.
             </goals>
             <phase>pre-site</phase>
             <configuration>
-              <version>1.1.0</version>
+              <version>1.2.0</version>
               <outputDirectory>${project.reporting.outputDirectory}/xsd</outputDirectory>
               <models>
                 <model>src/main/mdo/remote-resources.mdo</model>
@@ -309,7 +309,7 @@ under the License.
             </goals>
             <phase>pre-site</phase>
             <configuration>
-              <version>1.1.0</version>
+              <version>1.2.0</version>
               <models>
                 <model>src/main/mdo/remote-resources.mdo</model>
               </models>
@@ -336,7 +336,7 @@ under the License.
               <goal>xpp3-reader</goal>
             </goals>
             <configuration>
-              <version>1.1.0</version>
+              <version>1.2.0</version>
               <models>
                 <model>src/main/mdo/remote-resources.mdo</model>
               </models>
diff --git a/src/it/process-required-project-properties-missing/invoker.properties b/src/it/process-required-project-properties-missing/invoker.properties
new file mode 100644
index 0000000..7e8906f
--- /dev/null
+++ b/src/it/process-required-project-properties-missing/invoker.properties
@@ -0,0 +1,19 @@
+# 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.
+
+invoker.goals = generate-resources
+invoker.buildResult = failure
diff --git a/src/it/setup-bundle/pom.xml b/src/it/process-required-project-properties-missing/pom.xml
similarity index 83%
copy from src/it/setup-bundle/pom.xml
copy to src/it/process-required-project-properties-missing/pom.xml
index 2fb7a4a..c42bb5b 100644
--- a/src/it/setup-bundle/pom.xml
+++ b/src/it/process-required-project-properties-missing/pom.xml
@@ -23,17 +23,13 @@ under the License.
   <modelVersion>4.0.0</modelVersion>
 
   <groupId>org.apache.maven.its</groupId>
-  <artifactId>mrrp-bundle-parent</artifactId>
+  <artifactId>mrrp-process-required-properties</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>pom</packaging>
 
-  <modules>
-    <module>mrrp-bundle-a</module>
-    <module>mrrp-bundle-b</module>
-  </modules>
-
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <testProperty1>test1</testProperty1>
   </properties>
 
   <build>
@@ -42,10 +38,15 @@ under the License.
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-remote-resources-plugin</artifactId>
         <version>@project.version@</version>
+        <configuration>
+          <resourceBundles>
+            <resourceBundle>org.apache.maven.its:mrrp-bundle-c:1.0-SNAPSHOT</resourceBundle>
+          </resourceBundles>
+        </configuration>
         <executions>
           <execution>
             <goals>
-              <goal>bundle</goal>
+              <goal>process</goal>
             </goals>
           </execution>
         </executions>
diff --git a/src/it/process-required-project-properties-missing/verify.groovy b/src/it/process-required-project-properties-missing/verify.groovy
new file mode 100644
index 0000000..d9629ba
--- /dev/null
+++ b/src/it/process-required-project-properties-missing/verify.groovy
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+def logs = new File(basedir, 'build.log').text
+
+assert logs.contains('Required project property: \'testProperty2\' is not present for bundle')
+
+assert !new File(basedir, 'target/maven-shared-archive-resources').exists()
diff --git a/src/it/process-required-project-properties-ok/invoker.properties b/src/it/process-required-project-properties-ok/invoker.properties
new file mode 100644
index 0000000..0097f00
--- /dev/null
+++ b/src/it/process-required-project-properties-ok/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals = generate-resources
diff --git a/src/it/setup-bundle/pom.xml b/src/it/process-required-project-properties-ok/pom.xml
similarity index 81%
copy from src/it/setup-bundle/pom.xml
copy to src/it/process-required-project-properties-ok/pom.xml
index 2fb7a4a..9cafc8a 100644
--- a/src/it/setup-bundle/pom.xml
+++ b/src/it/process-required-project-properties-ok/pom.xml
@@ -23,17 +23,14 @@ under the License.
   <modelVersion>4.0.0</modelVersion>
 
   <groupId>org.apache.maven.its</groupId>
-  <artifactId>mrrp-bundle-parent</artifactId>
+  <artifactId>mrrp-process-required-properties</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>pom</packaging>
 
-  <modules>
-    <module>mrrp-bundle-a</module>
-    <module>mrrp-bundle-b</module>
-  </modules>
-
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <testProperty1>test1</testProperty1>
+    <testProperty2>test2</testProperty2>
   </properties>
 
   <build>
@@ -42,10 +39,15 @@ under the License.
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-remote-resources-plugin</artifactId>
         <version>@project.version@</version>
+        <configuration>
+          <resourceBundles>
+            <resourceBundle>org.apache.maven.its:mrrp-bundle-c:1.0-SNAPSHOT</resourceBundle>
+          </resourceBundles>
+        </configuration>
         <executions>
           <execution>
             <goals>
-              <goal>bundle</goal>
+              <goal>process</goal>
             </goals>
           </execution>
         </executions>
diff --git a/src/it/process-required-project-properties-ok/verify.groovy b/src/it/process-required-project-properties-ok/verify.groovy
new file mode 100644
index 0000000..ce577bd
--- /dev/null
+++ b/src/it/process-required-project-properties-ok/verify.groovy
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+def dir = new File(basedir, 'target/maven-shared-archive-resources')
+
+assert new File(dir, 'required-property.txt').text
+        .contains('mrrp-bundle-c org.apache.maven.its:mrrp-process-required-properties - test1 - test2')
diff --git a/src/it/setup-bundle/pom.xml b/src/it/setup-bundle/mrrp-bundle-c/pom.xml
similarity index 60%
copy from src/it/setup-bundle/pom.xml
copy to src/it/setup-bundle/mrrp-bundle-c/pom.xml
index 2fb7a4a..20a32d0 100644
--- a/src/it/setup-bundle/pom.xml
+++ b/src/it/setup-bundle/mrrp-bundle-c/pom.xml
@@ -22,34 +22,15 @@ under the License.
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
 
-  <groupId>org.apache.maven.its</groupId>
-  <artifactId>mrrp-bundle-parent</artifactId>
-  <version>1.0-SNAPSHOT</version>
-  <packaging>pom</packaging>
-
-  <modules>
-    <module>mrrp-bundle-a</module>
-    <module>mrrp-bundle-b</module>
-  </modules>
+  <parent>
+    <groupId>org.apache.maven.its</groupId>
+    <artifactId>mrrp-bundle-parent</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
 
+  <artifactId>mrrp-bundle-c</artifactId>
   <properties>
-    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <bundle.requiredProjectProperties>testProperty1,testProperty2</bundle.requiredProjectProperties>
   </properties>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-remote-resources-plugin</artifactId>
-        <version>@project.version@</version>
-        <executions>
-          <execution>
-            <goals>
-              <goal>bundle</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
 </project>
diff --git a/src/it/setup-bundle/mrrp-bundle-c/src/main/resources/required-property.txt.vm b/src/it/setup-bundle/mrrp-bundle-c/src/main/resources/required-property.txt.vm
new file mode 100644
index 0000000..950bbed
--- /dev/null
+++ b/src/it/setup-bundle/mrrp-bundle-c/src/main/resources/required-property.txt.vm
@@ -0,0 +1,18 @@
+# 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.
+
+mrrp-bundle-c ${project.groupId}:${project.artifactId} - ${project.properties.testProperty1} - ${project.properties.testProperty2}
diff --git a/src/it/setup-bundle/pom.xml b/src/it/setup-bundle/pom.xml
index 2fb7a4a..4ab7261 100644
--- a/src/it/setup-bundle/pom.xml
+++ b/src/it/setup-bundle/pom.xml
@@ -30,10 +30,12 @@ under the License.
   <modules>
     <module>mrrp-bundle-a</module>
     <module>mrrp-bundle-b</module>
+    <module>mrrp-bundle-c</module>
   </modules>
 
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <maven.test.skip>true</maven.test.skip>
   </properties>
 
   <build>
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 53fb02a..1aa5255 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
@@ -871,6 +871,8 @@ public abstract class AbstractProcessRemoteResourcesMojo extends AbstractMojo {
                     bundle = bundleReader.read(in);
                 }
 
+                verifyRequiredProperties(bundle, url);
+
                 int n = 0;
                 for (String bundleResource : bundle.getRemoteResources()) {
                     n++;
@@ -956,6 +958,20 @@ public abstract class AbstractProcessRemoteResourcesMojo extends AbstractMojo {
         }
     }
 
+    private void verifyRequiredProperties(RemoteResourcesBundle bundle, URL url) throws MojoExecutionException {
+        if (bundle.getRequiredProjectProperties() == null
+                || bundle.getRequiredProjectProperties().isEmpty()) {
+            return;
+        }
+
+        for (String requiredProperty : bundle.getRequiredProjectProperties()) {
+            if (!project.getProperties().containsKey(requiredProperty)) {
+                throw new MojoExecutionException(
+                        "Required project property: '" + requiredProperty + "' is not present for bundle: " + url);
+            }
+        }
+    }
+
     private Writer getWriter(RemoteResourcesBundle bundle, File f) throws IOException {
         Writer writer;
         if (bundle.getSourceEncoding() == null) {
diff --git a/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java b/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java
index 591d080..8dedbeb 100644
--- a/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java
+++ b/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java
@@ -23,7 +23,6 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
 import java.nio.charset.Charset;
-import java.util.Arrays;
 import java.util.Comparator;
 import java.util.List;
 
@@ -87,6 +86,15 @@ public class BundleRemoteResourcesMojo extends AbstractMojo {
     @Parameter(defaultValue = "${project.build.sourceEncoding}")
     private String sourceEncoding;
 
+    /**
+     * List of required project properties needed to process Velocity
+     * template by this resource bundle.
+     *
+     * @since 3.3.0
+     */
+    @Parameter(property = "bundle.requiredProjectProperties")
+    private List<String> requiredProjectProperties;
+
     @Override
     public void execute() throws MojoExecutionException {
         if (!resourcesDirectory.exists()) {
@@ -105,6 +113,7 @@ public class BundleRemoteResourcesMojo extends AbstractMojo {
 
         RemoteResourcesBundle remoteResourcesBundle = new RemoteResourcesBundle();
         remoteResourcesBundle.setSourceEncoding(sourceEncoding);
+        remoteResourcesBundle.setRequiredProjectProperties(requiredProjectProperties);
 
         DirectoryScanner scanner = new DirectoryScanner();
         scanner.setFilenameComparator(Comparator.naturalOrder());
@@ -123,7 +132,7 @@ public class BundleRemoteResourcesMojo extends AbstractMojo {
         scanner.addDefaultExcludes();
         scanner.scan();
 
-        List<String> includedFiles = Arrays.asList(scanner.getIncludedFiles());
+        String[] includedFiles = scanner.getIncludedFiles();
 
         for (String resource : includedFiles) {
             remoteResourcesBundle.addRemoteResource(StringUtils.replace(resource, '\\', '/'));
diff --git a/src/main/mdo/remote-resources.mdo b/src/main/mdo/remote-resources.mdo
index b8f63bd..21140c9 100644
--- a/src/main/mdo/remote-resources.mdo
+++ b/src/main/mdo/remote-resources.mdo
@@ -17,8 +17,8 @@ specific language governing permissions and limitations
 under the License.
 -->
 
-<model xmlns="https://codehaus-plexus.github.io/MODELLO/1.8.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="https://codehaus-plexus.github.io/MODELLO/1.8.0 https://codehaus-plexus.github.io/modello/xsd/modello-1.8.0.xsd"
+<model xmlns="http://codehaus-plexus.github.io/MODELLO/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://codehaus-plexus.github.io/MODELLO/2.0.0 https://codehaus-plexus.github.io/modello/xsd/modello-2.0.0.xsd"
        xml.namespace="http://maven.apache.org/remote-resources/${version}"
        xml.schemaLocation="https://maven.apache.org/xsd/remote-resources-${version}.xsd">
   <id>remote-resources</id>
@@ -36,12 +36,12 @@ under the License.
   <classes>
     <class rootElement="true" xml.tagName="remoteResourcesBundle">
       <name>RemoteResourcesBundle</name>
-      <version>1.1.0</version>
+      <version>1.1.0+</version>
       <description>Root element of the remote-resources.xml file.</description>
       <fields>
         <field>
           <name>remoteResources</name>
-          <version>1.1.0</version>
+          <version>1.1.0+</version>
           <description><![CDATA[
             Remote resources that are contained in a remote resources bundle.
           ]]></description>
@@ -52,12 +52,23 @@ under the License.
         </field>
         <field>
           <name>sourceEncoding</name>
-          <version>1.1.0</version>
+          <version>1.1.0+</version>
           <description><![CDATA[
             Source encoding of the remote resources contained in the bundle.
           ]]></description>
           <type>String</type>
         </field>
+        <field>
+          <name>requiredProjectProperties</name>
+          <version>1.2.0+</version>
+          <description><![CDATA[
+           Required project properties needed to process Velocity template by this resource bundle
+          ]]></description>
+          <association>
+            <type>String</type>
+            <multiplicity>*</multiplicity>
+          </association>
+        </field>
       </fields>
     </class>
   </classes>
diff --git a/src/main/mdo/supplemental-model.mdo b/src/main/mdo/supplemental-model.mdo
index 6b6e74a..475485e 100644
--- a/src/main/mdo/supplemental-model.mdo
+++ b/src/main/mdo/supplemental-model.mdo
@@ -17,8 +17,8 @@ specific language governing permissions and limitations
 under the License.
 -->
 
-<model xmlns="https://codehaus-plexus.github.io/MODELLO/1.8.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="https://codehaus-plexus.github.io/MODELLO/1.8.0 https://codehaus-plexus.github.io/modello/xsd/modello-1.8.0.xsd"
+<model xmlns="http://codehaus-plexus.github.io/MODELLO/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://codehaus-plexus.github.io/MODELLO/2.0.0 https://codehaus-plexus.github.io/modello/xsd/modello-2.0.0.xsd"
        xml.namespace="http://maven.apache.org/supplemental-model/${version}"
        xml.schemaLocation="https://maven.apache.org/xsd/supplemental-model-${version}.xsd">
   <id>supplemental-model</id>