You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/08/11 17:09:57 UTC

[GitHub] [maven-enforcer] gastaldi opened a new pull request, #180: [MENFORCER-422] Added descriptors rule

gastaldi opened a new pull request, #180:
URL: https://github.com/apache/maven-enforcer/pull/180

   Following this checklist to help us incorporate your 
   contribution quickly and easily:
   
    - [x] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/MENFORCER) filed 
          for the change (usually before you start working on it).  Trivial changes like typos do not 
          require a JIRA issue.  Your pull request should address just this issue, without 
          pulling in other changes.
    - [x] Each commit in the pull request should have a meaningful subject line and body.
    - [x] Format the pull request title like `[MENFORCER-XXX] - Fixes bug in ApproximateQuantiles`,
          where you replace `MENFORCER-XXX` with the appropriate JIRA issue. Best practice
          is to use the JIRA issue title in the pull request title and in the first line of the 
          commit message.
    - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
    - [x] Run `mvn clean verify` to make sure basic checks pass. A more thorough check will 
          be performed on your pull request automatically.
    - [x] You have run the integration tests successfully (`mvn -Prun-its clean verify`).
   
   If your pull request is about ~20 lines of code you don't need to sign an
   [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
   please ask on the developers list.
   
   To make clear that you license your contribution under 
   the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
    - [x] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   
    - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] gastaldi commented on a diff in pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
gastaldi commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r947993117


##########
enforcer-rules/src/site/apt/externalRules.apt.vm:
##########
@@ -0,0 +1,104 @@
+~~ 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.
+
+  ------
+  External Rules
+  ------
+  George Gastaldi
+  ------
+  August 2022
+  ------
+
+External Rules
+
+    This rule will evaluate rules from an external resource. It can be a classpath resource present in a <<<maven-enforcer-plugin>>> dependency or a local file.
+
+
+    Sample Plugin Configuration:
+
++---+
+<project>
+    [...]
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-enforcer-plugin</artifactId>
+                <version>${project.version}</version>
+                <dependencies>
+                    <!-- Dependency containing the enforcer/rules.xml file -->
+                    <dependency>
+                        <groupId>org.foo</groupId>
+                        <artifactId>foobar-rules</artifactId>
+                        <version>1.0.0</version>
+                    </dependency>
+                </dependencies>
+                <executions>
+                    <execution>
+                        <id>enforce</id>
+                        <goals>
+                            <goal>enforce</goal>
+                        </goals>
+                        <configuration>
+                            <rules>
+                                <ExternalRules>
+                                    <!-- enforcer/rules.xml is supposed to be a classpath resource present -->
+                                    <!-- in org.foo:foobar-rules dependency of maven-enforcer-plugin defined above -->
+                                    <location>classpath:enforcer/rules.xml</location>
+                                </ExternalRules>
+                                <ExternalRules>
+                                    <!-- You can add multiple <ExternalRules> elements if you need to enforce -->
+                                    <!-- rules from multiple resources. -->
+                                    <!-- src/build/rules.xml is a local file path relative to ${project.basedir} -->
+                                    <!-- Protip: to set the same resource for all modules in your multimodule setup, --> 
+                                    <!-- prefix the path with ${maven.multiModuleProjectDirectory}. That makes it -->

Review Comment:
   I removed the pro-tip for now



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] gastaldi commented on a diff in pull request #180: [MENFORCER-422] Added descriptors rule

Posted by GitBox <gi...@apache.org>.
gastaldi commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r943892982


##########
maven-enforcer-plugin/src/it/projects/descriptors-local-always-pass/pom.xml:
##########
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.enforcer</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+
+  <description>
+  </description>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-enforcer-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>test</id>
+            <goals>
+              <goal>enforce</goal>
+            </goals>
+            <configuration>
+              <rules>
+                <Descriptors>

Review Comment:
   It doesn't matter for Plexus. The tests use capitalized names for rules so I used that



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] michael-o commented on pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
michael-o commented on PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#issuecomment-1220535530

   > @michael-o do you happen to know whether an Enforcer release is planned already? Not sure where to look for that kind of info, although I am a committer.
   
   We don't publish any plans since we are volunteers.
   
   First of all, please complete the accompanying JIRA issue. Second, someone needs to tackle https://issues.apache.org/jira/browse/MENFORCER-407 then we can consider a release.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] gastaldi commented on a diff in pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
gastaldi commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r947942361


##########
enforcer-rules/src/site/apt/externalRules.apt.vm:
##########
@@ -0,0 +1,104 @@
+~~ 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.
+
+  ------
+  External Rules
+  ------
+  George Gastaldi
+  ------
+  August 2022

Review Comment:
   I copied the format from the `evaluateBeanshell.apt.vm` in this same directory, what ISO format are you expecting here? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] gastaldi commented on a diff in pull request #180: [MENFORCER-422] Added descriptors rule

Posted by GitBox <gi...@apache.org>.
gastaldi commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r943894987


##########
enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/Descriptors.java:
##########
@@ -0,0 +1,148 @@
+package org.apache.maven.plugins.enforcer;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.enforcer.rule.api.EnforcerRule;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
+import org.apache.maven.plugin.MojoExecution;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+import org.codehaus.plexus.component.configurator.ComponentConfigurator;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+
+/**
+ * An enforcer rule that will invoke rules from an external resource
+ *
+ * @author <a href="mailto:gastaldi@apache.org">George Gastaldi</a>
+ */
+public class Descriptors extends AbstractNonCacheableEnforcerRule
+{
+    String descriptorRef;
+
+    String descriptor;

Review Comment:
   True, but you can also add another `<Descriptor>` rule, so that was an intended design choice 😉 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] ppalaga commented on a diff in pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
ppalaga commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r945546145


##########
enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/ExternalRules.java:
##########
@@ -0,0 +1,151 @@
+package org.apache.maven.plugins.enforcer;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.enforcer.rule.api.EnforcerRule;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
+import org.apache.maven.plugin.MojoExecution;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+import org.codehaus.plexus.component.configurator.ComponentConfigurator;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+
+/**
+ * An enforcer rule that will invoke rules from an external resource
+ *
+ * @author <a href="mailto:gastaldi@apache.org">George Gastaldi</a>
+ */
+public class ExternalRules extends AbstractNonCacheableEnforcerRule
+{
+    private static final String LOCATION_PREFIX_CLASSPATH = "classpath:";
+
+    /**
+     * The external rules location. If it starts with "classpath:", the resource is read from the classpath

Review Comment:
   ```suggestion
        * The external rules location. If it starts with "classpath:", the resource is read from the classpath.
        * Otherwise, it is handled as a filesystem path, either absolute, or relative to <code>${project.basedir}</code>
   ```
   The "Otherwise" sentence is just my guess. Please correct it if necessary.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] ppalaga commented on a diff in pull request #180: [MENFORCER-422] Added descriptors rule

Posted by GitBox <gi...@apache.org>.
ppalaga commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r943916426


##########
enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/Descriptors.java:
##########
@@ -0,0 +1,148 @@
+package org.apache.maven.plugins.enforcer;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.enforcer.rule.api.EnforcerRule;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
+import org.apache.maven.plugin.MojoExecution;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+import org.codehaus.plexus.component.configurator.ComponentConfigurator;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+
+/**
+ * An enforcer rule that will invoke rules from an external resource
+ *
+ * @author <a href="mailto:gastaldi@apache.org">George Gastaldi</a>
+ */
+public class Descriptors extends AbstractNonCacheableEnforcerRule
+{
+    String descriptorRef;
+
+    String descriptor;
+
+    @Override
+    public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException
+    {
+        // Find descriptor
+        EnforcerDescriptor enforcerDescriptor = getEnforcerDescriptor( helper );
+        for ( EnforcerRule rule : enforcerDescriptor.getRules() )
+        {
+            rule.execute( helper );
+        }
+    }
+
+    /**
+     * Resolve the {@link EnforcerDescriptor} based on the provided {@link #descriptor} or {@link #descriptorRef}
+     *
+     * @param helper used to build the {@link EnforcerDescriptor}
+     * @return an {@link EnforcerDescriptor} for this rule
+     * @throws EnforcerRuleException if any failure happens while reading the descriptor
+     */
+    EnforcerDescriptor getEnforcerDescriptor( EnforcerRuleHelper helper )
+            throws EnforcerRuleException
+    {
+        try ( InputStream descriptorStream = resolveDescriptor( helper ) )
+        {
+            EnforcerDescriptor descriptor = new EnforcerDescriptor();
+            // To get configuration from the enforcer-plugin mojo do:
+            //helper.evaluate(helper.getComponent(MojoExecution.class).getConfiguration().getChild("fail").getValue())
+            // Get the enforcer plugin's class resolver
+            ClassRealm realm = helper.getComponent( MojoExecution.class ).getMojoDescriptor().getRealm();
+            ComponentConfigurator configurator = helper.getComponent( ComponentConfigurator.class, "basic" );
+            // Configure EnforcerDescriptor from the XML
+            configurator.configureComponent( descriptor, toPlexusConfiguration( descriptorStream ), helper, realm );
+            return descriptor;
+        }
+        catch ( EnforcerRuleException e )
+        {
+            throw e;
+        }
+        catch ( Exception e )
+        {
+            throw new EnforcerRuleException( "Error while enforcing rules", e );
+        }
+    }
+
+    private InputStream resolveDescriptor( EnforcerRuleHelper helper ) throws EnforcerRuleException
+    {
+        InputStream descriptorStream;
+        if ( descriptorRef != null )
+        {
+            descriptorStream = Thread.currentThread().getContextClassLoader()
+                    .getResourceAsStream( "enforcer-rules/" + descriptorRef + ".xml" );

Review Comment:
   I prefer doing it that way in my tools, but I do not know from top of my head whether any ASF plugins do it like that. 
   
   If you want to stay similar with Assembly plugin, I can live with it.
   
   Maybe we could try to find a better name for the top level element. How about `<externalRules>`?
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] michael-o commented on a diff in pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
michael-o commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r947662859


##########
enforcer-rules/src/site/apt/externalRules.apt.vm:
##########
@@ -0,0 +1,104 @@
+~~ 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.
+
+  ------
+  External Rules
+  ------
+  George Gastaldi
+  ------
+  August 2022

Review Comment:
   ISO format



##########
enforcer-rules/src/site/apt/externalRules.apt.vm:
##########
@@ -0,0 +1,104 @@
+~~ 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.
+
+  ------
+  External Rules
+  ------
+  George Gastaldi
+  ------
+  August 2022
+  ------
+
+External Rules
+
+    This rule will evaluate rules from an external resource. It can be a classpath resource present in a <<<maven-enforcer-plugin>>> dependency or a local file.
+
+
+    Sample Plugin Configuration:
+
++---+
+<project>
+    [...]
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-enforcer-plugin</artifactId>
+                <version>${project.version}</version>
+                <dependencies>
+                    <!-- Dependency containing the enforcer/rules.xml file -->
+                    <dependency>
+                        <groupId>org.foo</groupId>
+                        <artifactId>foobar-rules</artifactId>
+                        <version>1.0.0</version>
+                    </dependency>
+                </dependencies>
+                <executions>
+                    <execution>
+                        <id>enforce</id>
+                        <goals>
+                            <goal>enforce</goal>
+                        </goals>
+                        <configuration>
+                            <rules>
+                                <ExternalRules>
+                                    <!-- enforcer/rules.xml is supposed to be a classpath resource present -->
+                                    <!-- in org.foo:foobar-rules dependency of maven-enforcer-plugin defined above -->
+                                    <location>classpath:enforcer/rules.xml</location>
+                                </ExternalRules>
+                                <ExternalRules>
+                                    <!-- You can add multiple <ExternalRules> elements if you need to enforce -->
+                                    <!-- rules from multiple resources. -->
+                                    <!-- src/build/rules.xml is a local file path relative to ${project.basedir} -->
+                                    <!-- Protip: to set the same resource for all modules in your multimodule setup, --> 
+                                    <!-- prefix the path with ${maven.multiModuleProjectDirectory}. That makes it -->

Review Comment:
   Note that this property is an implementation detail and it should not be used in public



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] ppalaga commented on pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
ppalaga commented on PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#issuecomment-1220540421

   Thanks for the info @michael-o !


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] ppalaga commented on a diff in pull request #180: [MENFORCER-422] Added descriptors rule

Posted by GitBox <gi...@apache.org>.
ppalaga commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r943874201


##########
enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/Descriptors.java:
##########
@@ -0,0 +1,148 @@
+package org.apache.maven.plugins.enforcer;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.enforcer.rule.api.EnforcerRule;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
+import org.apache.maven.plugin.MojoExecution;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+import org.codehaus.plexus.component.configurator.ComponentConfigurator;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+
+/**
+ * An enforcer rule that will invoke rules from an external resource
+ *
+ * @author <a href="mailto:gastaldi@apache.org">George Gastaldi</a>
+ */
+public class Descriptors extends AbstractNonCacheableEnforcerRule
+{
+    String descriptorRef;
+
+    String descriptor;
+
+    @Override
+    public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException
+    {
+        // Find descriptor
+        EnforcerDescriptor enforcerDescriptor = getEnforcerDescriptor( helper );
+        for ( EnforcerRule rule : enforcerDescriptor.getRules() )
+        {
+            rule.execute( helper );
+        }
+    }
+
+    /**
+     * Resolve the {@link EnforcerDescriptor} based on the provided {@link #descriptor} or {@link #descriptorRef}
+     *
+     * @param helper used to build the {@link EnforcerDescriptor}
+     * @return an {@link EnforcerDescriptor} for this rule
+     * @throws EnforcerRuleException if any failure happens while reading the descriptor
+     */
+    EnforcerDescriptor getEnforcerDescriptor( EnforcerRuleHelper helper )
+            throws EnforcerRuleException
+    {
+        try ( InputStream descriptorStream = resolveDescriptor( helper ) )
+        {
+            EnforcerDescriptor descriptor = new EnforcerDescriptor();
+            // To get configuration from the enforcer-plugin mojo do:
+            //helper.evaluate(helper.getComponent(MojoExecution.class).getConfiguration().getChild("fail").getValue())
+            // Get the enforcer plugin's class resolver
+            ClassRealm realm = helper.getComponent( MojoExecution.class ).getMojoDescriptor().getRealm();
+            ComponentConfigurator configurator = helper.getComponent( ComponentConfigurator.class, "basic" );
+            // Configure EnforcerDescriptor from the XML
+            configurator.configureComponent( descriptor, toPlexusConfiguration( descriptorStream ), helper, realm );
+            return descriptor;
+        }
+        catch ( EnforcerRuleException e )
+        {
+            throw e;
+        }
+        catch ( Exception e )
+        {
+            throw new EnforcerRuleException( "Error while enforcing rules", e );
+        }
+    }
+
+    private InputStream resolveDescriptor( EnforcerRuleHelper helper ) throws EnforcerRuleException
+    {
+        InputStream descriptorStream;
+        if ( descriptorRef != null )
+        {
+            descriptorStream = Thread.currentThread().getContextClassLoader()
+                    .getResourceAsStream( "enforcer-rules/" + descriptorRef + ".xml" );

Review Comment:
   I find this a bit lacking on self-explainability. I can imagine I'll need to google up every time what is the name of the magic folder. Can't we simply use a single xml element for both files and classpath resources, something like:
   
   ```
   <descriptors>
       <descriptor>file:foo/bar.xml</descriptor><!-- relative to ${basedir} -->
       <descriptor>file:${maven.multiModuleProjectDirectory}/bar/baz.xml</descriptor><!-- absolute path within the source tree -->
       <descriptor>classpath:foo/bar.xml</descriptor><!-- class path resource -->
   </descriptors>
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] gastaldi commented on pull request #180: [MENFORCER-422] Added descriptors rule

Posted by GitBox <gi...@apache.org>.
gastaldi commented on PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#issuecomment-1212443930

   > Another important feature for the future: be able to customize the descriptor before processing, ideally through an XSLT. Motivation: some artifacts that are banned in Quarkus might be required in Camel Quarkus. With XSLT I could remove those specific ones from Quarkus descriptor and keep the rest.
   
   @ppalaga because other transformation steps might be needed and because I wanted to keep it simple, I think this would be better served if the transformed file were already available as a separate dependency (eg. you could use the Maven dependency plugin to unpack the original rule XML, transform and include the transformed file in another dependency with another GAV), but we can discuss about that.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] ppalaga commented on pull request #180: [MENFORCER-422] Added descriptors rule

Posted by GitBox <gi...@apache.org>.
ppalaga commented on PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#issuecomment-1212467432

   > you could use the Maven dependency plugin to unpack the original rule XML, transform and include the transformed file in another dependency with another GAV), but we can discuss about that.
   
   Yes, I know, but it is a sh** lot of XML that I hoped to be able to avoid :)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] ppalaga commented on pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
ppalaga commented on PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#issuecomment-1220407109

   Thanks, @gastaldi !


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] ppalaga commented on a diff in pull request #180: [MENFORCER-422] Added descriptors rule

Posted by GitBox <gi...@apache.org>.
ppalaga commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r943905739


##########
enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/Descriptors.java:
##########
@@ -0,0 +1,148 @@
+package org.apache.maven.plugins.enforcer;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.enforcer.rule.api.EnforcerRule;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
+import org.apache.maven.plugin.MojoExecution;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+import org.codehaus.plexus.component.configurator.ComponentConfigurator;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+
+/**
+ * An enforcer rule that will invoke rules from an external resource
+ *
+ * @author <a href="mailto:gastaldi@apache.org">George Gastaldi</a>
+ */
+public class Descriptors extends AbstractNonCacheableEnforcerRule
+{
+    String descriptorRef;
+
+    String descriptor;

Review Comment:
   OK, thanks, that sounds good.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] ppalaga commented on pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
ppalaga commented on PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#issuecomment-1217730819

   Would you like to review, @michael-o ? Otherwise, I could merge.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] gastaldi commented on a diff in pull request #180: [MENFORCER-422] Added descriptors rule

Posted by GitBox <gi...@apache.org>.
gastaldi commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r943933035


##########
enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/Descriptors.java:
##########
@@ -0,0 +1,148 @@
+package org.apache.maven.plugins.enforcer;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.enforcer.rule.api.EnforcerRule;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
+import org.apache.maven.plugin.MojoExecution;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+import org.codehaus.plexus.component.configurator.ComponentConfigurator;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+
+/**
+ * An enforcer rule that will invoke rules from an external resource
+ *
+ * @author <a href="mailto:gastaldi@apache.org">George Gastaldi</a>
+ */
+public class Descriptors extends AbstractNonCacheableEnforcerRule
+{
+    String descriptorRef;
+
+    String descriptor;
+
+    @Override
+    public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException
+    {
+        // Find descriptor
+        EnforcerDescriptor enforcerDescriptor = getEnforcerDescriptor( helper );
+        for ( EnforcerRule rule : enforcerDescriptor.getRules() )
+        {
+            rule.execute( helper );
+        }
+    }
+
+    /**
+     * Resolve the {@link EnforcerDescriptor} based on the provided {@link #descriptor} or {@link #descriptorRef}
+     *
+     * @param helper used to build the {@link EnforcerDescriptor}
+     * @return an {@link EnforcerDescriptor} for this rule
+     * @throws EnforcerRuleException if any failure happens while reading the descriptor
+     */
+    EnforcerDescriptor getEnforcerDescriptor( EnforcerRuleHelper helper )
+            throws EnforcerRuleException
+    {
+        try ( InputStream descriptorStream = resolveDescriptor( helper ) )
+        {
+            EnforcerDescriptor descriptor = new EnforcerDescriptor();
+            // To get configuration from the enforcer-plugin mojo do:
+            //helper.evaluate(helper.getComponent(MojoExecution.class).getConfiguration().getChild("fail").getValue())
+            // Get the enforcer plugin's class resolver
+            ClassRealm realm = helper.getComponent( MojoExecution.class ).getMojoDescriptor().getRealm();
+            ComponentConfigurator configurator = helper.getComponent( ComponentConfigurator.class, "basic" );
+            // Configure EnforcerDescriptor from the XML
+            configurator.configureComponent( descriptor, toPlexusConfiguration( descriptorStream ), helper, realm );
+            return descriptor;
+        }
+        catch ( EnforcerRuleException e )
+        {
+            throw e;
+        }
+        catch ( Exception e )
+        {
+            throw new EnforcerRuleException( "Error while enforcing rules", e );
+        }
+    }
+
+    private InputStream resolveDescriptor( EnforcerRuleHelper helper ) throws EnforcerRuleException
+    {
+        InputStream descriptorStream;
+        if ( descriptorRef != null )
+        {
+            descriptorStream = Thread.currentThread().getContextClassLoader()
+                    .getResourceAsStream( "enforcer-rules/" + descriptorRef + ".xml" );

Review Comment:
   +1, that sounds better, I suck at naming things 😀
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] ppalaga commented on pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
ppalaga commented on PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#issuecomment-1220520018

   @michael-o do you happen to know whether an Enforcer release is planned already? Not sure where to look for that kind of info, although I am a committer.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] ppalaga commented on a diff in pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
ppalaga commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r949946657


##########
enforcer-rules/src/site/apt/externalRules.apt.vm:
##########
@@ -0,0 +1,104 @@
+~~ 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.
+
+  ------
+  External Rules
+  ------
+  George Gastaldi
+  ------
+  August 2022
+  ------
+
+External Rules
+
+    This rule will evaluate rules from an external resource. It can be a classpath resource present in a <<<maven-enforcer-plugin>>> dependency or a local file.
+
+
+    Sample Plugin Configuration:
+
++---+
+<project>
+    [...]
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-enforcer-plugin</artifactId>
+                <version>${project.version}</version>
+                <dependencies>
+                    <!-- Dependency containing the enforcer/rules.xml file -->
+                    <dependency>
+                        <groupId>org.foo</groupId>
+                        <artifactId>foobar-rules</artifactId>
+                        <version>1.0.0</version>
+                    </dependency>
+                </dependencies>
+                <executions>
+                    <execution>
+                        <id>enforce</id>
+                        <goals>
+                            <goal>enforce</goal>
+                        </goals>
+                        <configuration>
+                            <rules>
+                                <ExternalRules>
+                                    <!-- enforcer/rules.xml is supposed to be a classpath resource present -->
+                                    <!-- in org.foo:foobar-rules dependency of maven-enforcer-plugin defined above -->
+                                    <location>classpath:enforcer/rules.xml</location>
+                                </ExternalRules>
+                                <ExternalRules>
+                                    <!-- You can add multiple <ExternalRules> elements if you need to enforce -->
+                                    <!-- rules from multiple resources. -->
+                                    <!-- src/build/rules.xml is a local file path relative to ${project.basedir} -->
+                                    <!-- Protip: to set the same resource for all modules in your multimodule setup, --> 
+                                    <!-- prefix the path with ${maven.multiModuleProjectDirectory}. That makes it -->

Review Comment:
   What a pity! Is there any official way to make a path relative to the root dir?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] gastaldi commented on a diff in pull request #180: [MENFORCER-422] Added descriptors rule

Posted by GitBox <gi...@apache.org>.
gastaldi commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r943902433


##########
enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/Descriptors.java:
##########
@@ -0,0 +1,148 @@
+package org.apache.maven.plugins.enforcer;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.enforcer.rule.api.EnforcerRule;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
+import org.apache.maven.plugin.MojoExecution;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+import org.codehaus.plexus.component.configurator.ComponentConfigurator;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+
+/**
+ * An enforcer rule that will invoke rules from an external resource
+ *
+ * @author <a href="mailto:gastaldi@apache.org">George Gastaldi</a>
+ */
+public class Descriptors extends AbstractNonCacheableEnforcerRule
+{
+    String descriptorRef;
+
+    String descriptor;
+
+    @Override
+    public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException
+    {
+        // Find descriptor
+        EnforcerDescriptor enforcerDescriptor = getEnforcerDescriptor( helper );
+        for ( EnforcerRule rule : enforcerDescriptor.getRules() )
+        {
+            rule.execute( helper );
+        }
+    }
+
+    /**
+     * Resolve the {@link EnforcerDescriptor} based on the provided {@link #descriptor} or {@link #descriptorRef}
+     *
+     * @param helper used to build the {@link EnforcerDescriptor}
+     * @return an {@link EnforcerDescriptor} for this rule
+     * @throws EnforcerRuleException if any failure happens while reading the descriptor
+     */
+    EnforcerDescriptor getEnforcerDescriptor( EnforcerRuleHelper helper )
+            throws EnforcerRuleException
+    {
+        try ( InputStream descriptorStream = resolveDescriptor( helper ) )
+        {
+            EnforcerDescriptor descriptor = new EnforcerDescriptor();
+            // To get configuration from the enforcer-plugin mojo do:
+            //helper.evaluate(helper.getComponent(MojoExecution.class).getConfiguration().getChild("fail").getValue())
+            // Get the enforcer plugin's class resolver
+            ClassRealm realm = helper.getComponent( MojoExecution.class ).getMojoDescriptor().getRealm();
+            ComponentConfigurator configurator = helper.getComponent( ComponentConfigurator.class, "basic" );
+            // Configure EnforcerDescriptor from the XML
+            configurator.configureComponent( descriptor, toPlexusConfiguration( descriptorStream ), helper, realm );
+            return descriptor;
+        }
+        catch ( EnforcerRuleException e )
+        {
+            throw e;
+        }
+        catch ( Exception e )
+        {
+            throw new EnforcerRuleException( "Error while enforcing rules", e );
+        }
+    }
+
+    private InputStream resolveDescriptor( EnforcerRuleHelper helper ) throws EnforcerRuleException
+    {
+        InputStream descriptorStream;
+        if ( descriptorRef != null )
+        {
+            descriptorStream = Thread.currentThread().getContextClassLoader()
+                    .getResourceAsStream( "enforcer-rules/" + descriptorRef + ".xml" );

Review Comment:
   That's an interesting approach. Just out of curiosity: Do we have other maven plugins doing the same? Just thinking how other plugins managed to solve the same problem



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] gastaldi commented on a diff in pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
gastaldi commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r944013362


##########
enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/Descriptors.java:
##########
@@ -0,0 +1,148 @@
+package org.apache.maven.plugins.enforcer;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.enforcer.rule.api.EnforcerRule;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
+import org.apache.maven.plugin.MojoExecution;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+import org.codehaus.plexus.component.configurator.ComponentConfigurator;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+
+/**
+ * An enforcer rule that will invoke rules from an external resource
+ *
+ * @author <a href="mailto:gastaldi@apache.org">George Gastaldi</a>
+ */
+public class Descriptors extends AbstractNonCacheableEnforcerRule
+{
+    String descriptorRef;
+
+    String descriptor;
+
+    @Override
+    public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException
+    {
+        // Find descriptor
+        EnforcerDescriptor enforcerDescriptor = getEnforcerDescriptor( helper );
+        for ( EnforcerRule rule : enforcerDescriptor.getRules() )
+        {
+            rule.execute( helper );
+        }
+    }
+
+    /**
+     * Resolve the {@link EnforcerDescriptor} based on the provided {@link #descriptor} or {@link #descriptorRef}
+     *
+     * @param helper used to build the {@link EnforcerDescriptor}
+     * @return an {@link EnforcerDescriptor} for this rule
+     * @throws EnforcerRuleException if any failure happens while reading the descriptor
+     */
+    EnforcerDescriptor getEnforcerDescriptor( EnforcerRuleHelper helper )
+            throws EnforcerRuleException
+    {
+        try ( InputStream descriptorStream = resolveDescriptor( helper ) )
+        {
+            EnforcerDescriptor descriptor = new EnforcerDescriptor();
+            // To get configuration from the enforcer-plugin mojo do:
+            //helper.evaluate(helper.getComponent(MojoExecution.class).getConfiguration().getChild("fail").getValue())
+            // Get the enforcer plugin's class resolver
+            ClassRealm realm = helper.getComponent( MojoExecution.class ).getMojoDescriptor().getRealm();
+            ComponentConfigurator configurator = helper.getComponent( ComponentConfigurator.class, "basic" );
+            // Configure EnforcerDescriptor from the XML
+            configurator.configureComponent( descriptor, toPlexusConfiguration( descriptorStream ), helper, realm );
+            return descriptor;
+        }
+        catch ( EnforcerRuleException e )
+        {
+            throw e;
+        }
+        catch ( Exception e )
+        {
+            throw new EnforcerRuleException( "Error while enforcing rules", e );
+        }
+    }
+
+    private InputStream resolveDescriptor( EnforcerRuleHelper helper ) throws EnforcerRuleException
+    {
+        InputStream descriptorStream;
+        if ( descriptorRef != null )
+        {
+            descriptorStream = Thread.currentThread().getContextClassLoader()
+                    .getResourceAsStream( "enforcer-rules/" + descriptorRef + ".xml" );

Review Comment:
   @ppalaga now it's called `location` and it expects a file path or a resource from the classpath if it starts with `classpath:`
   ```xml
   <externalRules>
       <location>classpath:enforcer-rules/quarkus.xml</location>
   </externalRules>
   ```
   
   You don't specify the `classpath:` prefix, it will respect the implementation in `org.apache.maven.plugin.PluginParameterExpressionEvaluator#alignToBaseDirectory`:
   
   ```xml
   <externalRules>
       <location>classpath:enforcer-rules/quarkus.xml</location>
   </externalRules>
   ```
   
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] gastaldi commented on a diff in pull request #180: [MENFORCER-422] Added descriptors rule

Posted by GitBox <gi...@apache.org>.
gastaldi commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r943933810


##########
enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/Descriptors.java:
##########
@@ -0,0 +1,148 @@
+package org.apache.maven.plugins.enforcer;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.enforcer.rule.api.EnforcerRule;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
+import org.apache.maven.plugin.MojoExecution;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+import org.codehaus.plexus.component.configurator.ComponentConfigurator;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+
+/**
+ * An enforcer rule that will invoke rules from an external resource
+ *
+ * @author <a href="mailto:gastaldi@apache.org">George Gastaldi</a>
+ */
+public class Descriptors extends AbstractNonCacheableEnforcerRule
+{
+    String descriptorRef;
+
+    String descriptor;
+
+    @Override
+    public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException
+    {
+        // Find descriptor
+        EnforcerDescriptor enforcerDescriptor = getEnforcerDescriptor( helper );
+        for ( EnforcerRule rule : enforcerDescriptor.getRules() )
+        {
+            rule.execute( helper );
+        }
+    }
+
+    /**
+     * Resolve the {@link EnforcerDescriptor} based on the provided {@link #descriptor} or {@link #descriptorRef}
+     *
+     * @param helper used to build the {@link EnforcerDescriptor}
+     * @return an {@link EnforcerDescriptor} for this rule
+     * @throws EnforcerRuleException if any failure happens while reading the descriptor
+     */
+    EnforcerDescriptor getEnforcerDescriptor( EnforcerRuleHelper helper )
+            throws EnforcerRuleException
+    {
+        try ( InputStream descriptorStream = resolveDescriptor( helper ) )
+        {
+            EnforcerDescriptor descriptor = new EnforcerDescriptor();
+            // To get configuration from the enforcer-plugin mojo do:
+            //helper.evaluate(helper.getComponent(MojoExecution.class).getConfiguration().getChild("fail").getValue())
+            // Get the enforcer plugin's class resolver
+            ClassRealm realm = helper.getComponent( MojoExecution.class ).getMojoDescriptor().getRealm();
+            ComponentConfigurator configurator = helper.getComponent( ComponentConfigurator.class, "basic" );
+            // Configure EnforcerDescriptor from the XML
+            configurator.configureComponent( descriptor, toPlexusConfiguration( descriptorStream ), helper, realm );
+            return descriptor;
+        }
+        catch ( EnforcerRuleException e )
+        {
+            throw e;
+        }
+        catch ( Exception e )
+        {
+            throw new EnforcerRuleException( "Error while enforcing rules", e );
+        }
+    }
+
+    private InputStream resolveDescriptor( EnforcerRuleHelper helper ) throws EnforcerRuleException
+    {
+        InputStream descriptorStream;
+        if ( descriptorRef != null )
+        {
+            descriptorStream = Thread.currentThread().getContextClassLoader()
+                    .getResourceAsStream( "enforcer-rules/" + descriptorRef + ".xml" );

Review Comment:
   > If you want to stay similar with Assembly plugin, I can live with it.
   
   I don't mind changing it, I just want to avoid potential CVEs in the future 😀



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] michael-o commented on a diff in pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
michael-o commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r947987535


##########
enforcer-rules/src/site/apt/externalRules.apt.vm:
##########
@@ -0,0 +1,104 @@
+~~ 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.
+
+  ------
+  External Rules
+  ------
+  George Gastaldi
+  ------
+  August 2022
+  ------
+
+External Rules
+
+    This rule will evaluate rules from an external resource. It can be a classpath resource present in a <<<maven-enforcer-plugin>>> dependency or a local file.
+
+
+    Sample Plugin Configuration:
+
++---+
+<project>
+    [...]
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-enforcer-plugin</artifactId>
+                <version>${project.version}</version>
+                <dependencies>
+                    <!-- Dependency containing the enforcer/rules.xml file -->
+                    <dependency>
+                        <groupId>org.foo</groupId>
+                        <artifactId>foobar-rules</artifactId>
+                        <version>1.0.0</version>
+                    </dependency>
+                </dependencies>
+                <executions>
+                    <execution>
+                        <id>enforce</id>
+                        <goals>
+                            <goal>enforce</goal>
+                        </goals>
+                        <configuration>
+                            <rules>
+                                <ExternalRules>
+                                    <!-- enforcer/rules.xml is supposed to be a classpath resource present -->
+                                    <!-- in org.foo:foobar-rules dependency of maven-enforcer-plugin defined above -->
+                                    <location>classpath:enforcer/rules.xml</location>
+                                </ExternalRules>
+                                <ExternalRules>
+                                    <!-- You can add multiple <ExternalRules> elements if you need to enforce -->
+                                    <!-- rules from multiple resources. -->
+                                    <!-- src/build/rules.xml is a local file path relative to ${project.basedir} -->
+                                    <!-- Protip: to set the same resource for all modules in your multimodule setup, --> 
+                                    <!-- prefix the path with ${maven.multiModuleProjectDirectory}. That makes it -->

Review Comment:
   Either that or say that the behavior is undefined because this can break with every new release.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] michael-o commented on a diff in pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
michael-o commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r947986938


##########
enforcer-rules/src/site/apt/externalRules.apt.vm:
##########
@@ -0,0 +1,104 @@
+~~ 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.
+
+  ------
+  External Rules
+  ------
+  George Gastaldi
+  ------
+  August 2022

Review Comment:
   https://maven.apache.org/doxia/references/apt-format.html#title



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] michael-o commented on a diff in pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
michael-o commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r950006772


##########
enforcer-rules/src/site/apt/externalRules.apt.vm:
##########
@@ -0,0 +1,104 @@
+~~ 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.
+
+  ------
+  External Rules
+  ------
+  George Gastaldi
+  ------
+  August 2022
+  ------
+
+External Rules
+
+    This rule will evaluate rules from an external resource. It can be a classpath resource present in a <<<maven-enforcer-plugin>>> dependency or a local file.
+
+
+    Sample Plugin Configuration:
+
++---+
+<project>
+    [...]
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-enforcer-plugin</artifactId>
+                <version>${project.version}</version>
+                <dependencies>
+                    <!-- Dependency containing the enforcer/rules.xml file -->
+                    <dependency>
+                        <groupId>org.foo</groupId>
+                        <artifactId>foobar-rules</artifactId>
+                        <version>1.0.0</version>
+                    </dependency>
+                </dependencies>
+                <executions>
+                    <execution>
+                        <id>enforce</id>
+                        <goals>
+                            <goal>enforce</goal>
+                        </goals>
+                        <configuration>
+                            <rules>
+                                <ExternalRules>
+                                    <!-- enforcer/rules.xml is supposed to be a classpath resource present -->
+                                    <!-- in org.foo:foobar-rules dependency of maven-enforcer-plugin defined above -->
+                                    <location>classpath:enforcer/rules.xml</location>
+                                </ExternalRules>
+                                <ExternalRules>
+                                    <!-- You can add multiple <ExternalRules> elements if you need to enforce -->
+                                    <!-- rules from multiple resources. -->
+                                    <!-- src/build/rules.xml is a local file path relative to ${project.basedir} -->
+                                    <!-- Protip: to set the same resource for all modules in your multimodule setup, --> 
+                                    <!-- prefix the path with ${maven.multiModuleProjectDirectory}. That makes it -->

Review Comment:
   @ppalaga  https://issues.apache.org/jira/browse/MNG-7038



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] michael-o commented on a diff in pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
michael-o commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r949985124


##########
enforcer-rules/src/site/apt/externalRules.apt.vm:
##########
@@ -0,0 +1,104 @@
+~~ 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.
+
+  ------
+  External Rules
+  ------
+  George Gastaldi
+  ------
+  August 2022
+  ------
+
+External Rules
+
+    This rule will evaluate rules from an external resource. It can be a classpath resource present in a <<<maven-enforcer-plugin>>> dependency or a local file.
+
+
+    Sample Plugin Configuration:
+
++---+
+<project>
+    [...]
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-enforcer-plugin</artifactId>
+                <version>${project.version}</version>
+                <dependencies>
+                    <!-- Dependency containing the enforcer/rules.xml file -->
+                    <dependency>
+                        <groupId>org.foo</groupId>
+                        <artifactId>foobar-rules</artifactId>
+                        <version>1.0.0</version>
+                    </dependency>
+                </dependencies>
+                <executions>
+                    <execution>
+                        <id>enforce</id>
+                        <goals>
+                            <goal>enforce</goal>
+                        </goals>
+                        <configuration>
+                            <rules>
+                                <ExternalRules>
+                                    <!-- enforcer/rules.xml is supposed to be a classpath resource present -->
+                                    <!-- in org.foo:foobar-rules dependency of maven-enforcer-plugin defined above -->
+                                    <location>classpath:enforcer/rules.xml</location>
+                                </ExternalRules>
+                                <ExternalRules>
+                                    <!-- You can add multiple <ExternalRules> elements if you need to enforce -->
+                                    <!-- rules from multiple resources. -->
+                                    <!-- src/build/rules.xml is a local file path relative to ${project.basedir} -->
+                                    <!-- Protip: to set the same resource for all modules in your multimodule setup, --> 
+                                    <!-- prefix the path with ${maven.multiModuleProjectDirectory}. That makes it -->

Review Comment:
   There is an open JIRA issue



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] ppalaga commented on a diff in pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
ppalaga commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r946542255


##########
enforcer-rules/src/site/apt/externalRules.apt.vm:
##########
@@ -0,0 +1,72 @@
+~~ 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.
+
+  ------
+  External Rules
+  ------
+  George Gastaldi
+  ------
+  August 2022
+  ------
+
+External Rules
+
+    This rule will evaluate rules from an external resource. It is useful for reusing enforcer rules from other dependencies.

Review Comment:
   ```suggestion
       This rule will evaluate rules from an external resource. It can be a classpath resource present in a <<<maven-enforcer-plugin>>> dependency or a local file.
   ```



##########
enforcer-rules/src/site/apt/externalRules.apt.vm:
##########
@@ -0,0 +1,72 @@
+~~ 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.
+
+  ------
+  External Rules
+  ------
+  George Gastaldi
+  ------
+  August 2022
+  ------
+
+External Rules
+
+    This rule will evaluate rules from an external resource. It is useful for reusing enforcer rules from other dependencies.
+
+
+    Sample Plugin Configuration:
+
++---+
+<project>
+    [...]
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-enforcer-plugin</artifactId>
+                <version>${project.version}</version>
+                <dependencies>
+                    <!-- Dependency containing the enforcer/rules.xml file -->
+                    <dependency>
+                        <groupId>org.foo</groupId>
+                        <artifactId>foobar-rules</artifactId>
+                        <version>1.0.0</version>
+                    </dependency>
+                </dependencies>
+                <executions>
+                    <execution>
+                        <id>enforce</id>
+                        <goals>
+                            <goal>enforce</goal>
+                        </goals>
+                        <configuration>
+                            <rules>
+                                <ExternalRules>
+                                    <!-- if referencing a file, remove the 'classpath:' prefix -->
+                                    <location>classpath:enforcer/rules.xml</location>
+                                </ExternalRules>
+                            </rules>
+                            <fail>true</fail>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+    [...]
+</project>
++---+

Review Comment:
   A `rules.xml` example would be nice here.



##########
enforcer-rules/src/site/apt/externalRules.apt.vm:
##########
@@ -0,0 +1,72 @@
+~~ 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.
+
+  ------
+  External Rules
+  ------
+  George Gastaldi
+  ------
+  August 2022
+  ------
+
+External Rules
+
+    This rule will evaluate rules from an external resource. It is useful for reusing enforcer rules from other dependencies.
+
+
+    Sample Plugin Configuration:
+
++---+
+<project>
+    [...]
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-enforcer-plugin</artifactId>
+                <version>${project.version}</version>
+                <dependencies>
+                    <!-- Dependency containing the enforcer/rules.xml file -->
+                    <dependency>
+                        <groupId>org.foo</groupId>
+                        <artifactId>foobar-rules</artifactId>
+                        <version>1.0.0</version>
+                    </dependency>
+                </dependencies>
+                <executions>
+                    <execution>
+                        <id>enforce</id>
+                        <goals>
+                            <goal>enforce</goal>
+                        </goals>
+                        <configuration>
+                            <rules>
+                                <ExternalRules>
+                                    <!-- if referencing a file, remove the 'classpath:' prefix -->
+                                    <location>classpath:enforcer/rules.xml</location>
+                                </ExternalRules>

Review Comment:
   ```suggestion
                                   <ExternalRules>
                                       <!-- enforcer/rules.xml is supposed to be a classpath resource present -->
                                       <!-- in org.foo:foobar-rules dependency of maven-enforcer-plugin defined above -->
                                       <location>classpath:enforcer/rules.xml</location>
                                   </ExternalRules>
                                   <ExternalRules>
                                       <!-- You can add multiple <ExternalRules> elements if you need to enforce -->
                                       <!-- rules from multiple resources. -->
                                       <!-- src/build/rules.xml is a local file path relative to ${project.basedir} -->
                                       <!-- Protip: to set the same resource for all modules in your multimodule setup, --> 
                                       <!-- prefix the path with ${maven.multiModuleProjectDirectory}. That makes it -->
                                       <!-- relative to the root of your Maven module hierarchy. Make sure that there is -->
                                       <!-- a .mvn directory in your source tree root directory. -->
                                       <location>src/build/rules.xml</location>
                                   </ExternalRules>
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] gastaldi commented on a diff in pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
gastaldi commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r947939341


##########
enforcer-rules/src/site/apt/externalRules.apt.vm:
##########
@@ -0,0 +1,104 @@
+~~ 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.
+
+  ------
+  External Rules
+  ------
+  George Gastaldi
+  ------
+  August 2022
+  ------
+
+External Rules
+
+    This rule will evaluate rules from an external resource. It can be a classpath resource present in a <<<maven-enforcer-plugin>>> dependency or a local file.
+
+
+    Sample Plugin Configuration:
+
++---+
+<project>
+    [...]
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-enforcer-plugin</artifactId>
+                <version>${project.version}</version>
+                <dependencies>
+                    <!-- Dependency containing the enforcer/rules.xml file -->
+                    <dependency>
+                        <groupId>org.foo</groupId>
+                        <artifactId>foobar-rules</artifactId>
+                        <version>1.0.0</version>
+                    </dependency>
+                </dependencies>
+                <executions>
+                    <execution>
+                        <id>enforce</id>
+                        <goals>
+                            <goal>enforce</goal>
+                        </goals>
+                        <configuration>
+                            <rules>
+                                <ExternalRules>
+                                    <!-- enforcer/rules.xml is supposed to be a classpath resource present -->
+                                    <!-- in org.foo:foobar-rules dependency of maven-enforcer-plugin defined above -->
+                                    <location>classpath:enforcer/rules.xml</location>
+                                </ExternalRules>
+                                <ExternalRules>
+                                    <!-- You can add multiple <ExternalRules> elements if you need to enforce -->
+                                    <!-- rules from multiple resources. -->
+                                    <!-- src/build/rules.xml is a local file path relative to ${project.basedir} -->
+                                    <!-- Protip: to set the same resource for all modules in your multimodule setup, --> 
+                                    <!-- prefix the path with ${maven.multiModuleProjectDirectory}. That makes it -->

Review Comment:
   So should we remove the pro-tip? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] ppalaga merged pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
ppalaga merged PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] ppalaga commented on a diff in pull request #180: [MENFORCER-422] Added descriptors rule

Posted by GitBox <gi...@apache.org>.
ppalaga commented on code in PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#discussion_r943862140


##########
maven-enforcer-plugin/src/it/projects/descriptors-local-always-pass/pom.xml:
##########
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.enforcer</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+
+  <description>
+  </description>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-enforcer-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>test</id>
+            <goals>
+              <goal>enforce</goal>
+            </goals>
+            <configuration>
+              <rules>
+                <Descriptors>

Review Comment:
   Shouldn't this be `<descriptors>` with lowercase `d`?
   



##########
enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/Descriptors.java:
##########
@@ -0,0 +1,148 @@
+package org.apache.maven.plugins.enforcer;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.enforcer.rule.api.EnforcerRule;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
+import org.apache.maven.plugin.MojoExecution;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+import org.codehaus.plexus.component.configurator.ComponentConfigurator;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+
+/**
+ * An enforcer rule that will invoke rules from an external resource
+ *
+ * @author <a href="mailto:gastaldi@apache.org">George Gastaldi</a>
+ */
+public class Descriptors extends AbstractNonCacheableEnforcerRule
+{
+    String descriptorRef;
+
+    String descriptor;

Review Comment:
   It looks I can only set one descriptor? It would be nice if I could set multiple descriptors from multiple sources and also be able to combine refs and local paths.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-enforcer] gastaldi commented on pull request #180: [MENFORCER-422] Added externalRules rule

Posted by GitBox <gi...@apache.org>.
gastaldi commented on PR #180:
URL: https://github.com/apache/maven-enforcer/pull/180#issuecomment-1215056039

   > Otherwise, I wonder whether there is any Enforcer end user docs, where an `externalRules` example could be added?
   
   I added an example doc in the generated site


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org