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 2021/05/21 14:29:11 UTC

[GitHub] [maven-enforcer] rfscholte commented on a change in pull request #96: MENFORCER-383 add rulesFile user property to supply enforcer rules from cmd line

rfscholte commented on a change in pull request #96:
URL: https://github.com/apache/maven-enforcer/pull/96#discussion_r636965178



##########
File path: maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java
##########
@@ -150,6 +175,53 @@ public void execute()
             this.rules = createRulesFromCommandLineOptions();
         }
         
+        if ( rulesFilename != null && rulesFilename.length() > 0 )
+        {
+            Xpp3Dom configuration = null;
+            try
+            {
+                configuration = Xpp3DomBuilder.build( new FileReader( rulesFilename ) );
+            }
+            catch ( org.codehaus.plexus.util.xml.pull.XmlPullParserException | IOException e )
+            {
+                String apath = rulesFilename;
+                try
+                {
+                    apath = new File( rulesFilename ).getCanonicalPath();
+                }
+                catch ( IOException e1 )
+                {
+                }
+                throw new MojoExecutionException( "Unable to locate rules configuration xml file " + apath, e );
+            }
+            MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
+            
+            configuration = Xpp3DomUtils.mergeXpp3Dom( configuration,
+                toXpp3Dom( mojoDescriptor.getMojoConfiguration() ) );
+            Xpp3Dom[] cs = configuration.getChildren();
+            for ( int i = 0; i < cs.length; i++ )
+            {
+                Xpp3Dom c = cs[i];
+                if ( "rulesFilename".equals( c.getName() ) )
+                {
+                    configuration.removeChild( i ); // remove to avoid re-doing this if block
+                    break; // done exit
+                }
+            }
+            MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, configuration );
+            
+            try
+            {
+                pluginManager.executeMojo( session, mojoExecution );

Review comment:
       This is some kind of inception that doesn't make sense here. There is a better way to solve these kind of problems: maven-extensions.
   I've implemented MENFORCER-384, which makes commandlineRules absolete.




-- 
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.

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