Details

    • Type: New Feature New Feature
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Plugin
    • Labels:
      None
    • Number of attachments :
      0

      Description

      It would be useful if the output from the enforcer plugin could be in a report format such as HTML, XML, etc.

        Activity

        Hide
        Lars Gohlke added a comment -

        I implemented this as optional for DependencyConvergence and offer a patch for this here

        against r1535845

        Index: enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java
        IDEA additional info:
        Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
        <+>UTF-8
        ===================================================================
        --- enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java	(revision 1535845)
        +++ enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java	(revision )
        @@ -24,6 +24,7 @@
         import java.util.List;
         
         import org.apache.maven.artifact.Artifact;
        +import org.apache.maven.artifact.DefaultArtifact;
         import org.apache.maven.artifact.factory.ArtifactFactory;
         import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
         import org.apache.maven.artifact.repository.ArtifactRepository;
        @@ -41,7 +42,11 @@
         import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
         import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
         import org.codehaus.plexus.i18n.I18N;
        +import org.codehaus.plexus.util.FileUtils;
         
        +import java.io.File;
        +import java.io.IOException;
        +import com.thoughtworks.xstream.XStream;
         /**
          * @author <a href="mailto:rex@e-hoffman.org">Rex Hoffman</a>
          */
        @@ -52,20 +57,26 @@
             private static Log log;
         
             private static I18N i18n;
        -    
        -    private boolean uniqueVersions; 
        +
        +    private boolean uniqueVersions;
         
             public void setUniqueVersions( boolean uniqueVersions )
             {
                 this.uniqueVersions = uniqueVersions;
             }
        -    
        +
        +    private File xmlReport;
        +
        +    public void setXmlReport(File xmlReport) {
        +      this.xmlReport = xmlReport;
        +    }
        +
             /**
              * Uses the {@link EnforcerRuleHelper} to populate the values of the
              * {@link DependencyTreeBuilder#buildDependencyTree(MavenProject, ArtifactRepository, ArtifactFactory, ArtifactMetadataSource, ArtifactFilter, ArtifactCollector)}
              * factory method. <br/>
              * This method simply exists to hide all the ugly lookup that the {@link EnforcerRuleHelper} has to do.
        -     * 
        +     *
              * @param helper
              * @return a Dependency Node which is the root of the project's dependency tree
              * @throws EnforcerRuleException
        @@ -121,7 +132,11 @@
                     visitor.setUniqueVersions( uniqueVersions );
                     node.accept( visitor );
                     List<CharSequence> errorMsgs = new ArrayList<CharSequence>();
        -            errorMsgs.addAll( getConvergenceErrorMsgs( visitor.getConflictedVersionNumbers() ) );
        +
        +            List<List<DependencyNode>> conflictedVersionNumbers = visitor.getConflictedVersionNumbers();
        +            errorMsgs.addAll( getConvergenceErrorMsgs(conflictedVersionNumbers) );
        +            writeConflictedVersionNumbers(conflictedVersionNumbers);
        +
                     for ( CharSequence errorMsg : errorMsgs )
                     {
                         log.warn( errorMsg );
        @@ -138,6 +153,24 @@
                 catch ( Exception e )
                 {
                     throw new EnforcerRuleException( e.getLocalizedMessage(), e );
        +        }
        +    }
        +
        +  private void writeConflictedVersionNumbers(List<List<DependencyNode>> conflictedVersionNumbers) {
        +        if ( null != xmlReport ){
        +          XStream xStream = new XStream();
        +          xStream.omitField(DefaultArtifact.class,"artifactHandler");
        +          xStream.omitField(DefaultArtifact.class,"versionRange");
        +          xStream.omitField(DependencyNode.class,"parent");
        +          xStream.omitField(DependencyNode.class,"state");
        +
        +          xStream.alias("dependency",DependencyNode.class);
        +
        +          try {
        +            FileUtils.fileWrite(xmlReport.getAbsolutePath(),xStream.toXML(conflictedVersionNumbers));
        +          } catch (IOException e) {
        +            throw new IllegalStateException(e);
        +          }
                 }
             }
         
        @@ -222,7 +255,7 @@
              * allow double checking of the results. Most of the time this can be done by generating unique ids, but sometimes
              * the results of objects returned by the helper need to be queried. You may for example, store certain objects in
              * your rule and then query them later.
        -     * 
        +     *
              * @param rule
              */
             public boolean isResultValid( EnforcerRule rule )
        \ No newline at end of file
        Index: enforcer-rules/pom.xml
        IDEA additional info:
        Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
        <+>UTF-8
        ===================================================================
        --- enforcer-rules/pom.xml	(revision 1535845)
        +++ enforcer-rules/pom.xml	(revision )
        @@ -15,7 +15,7 @@
           * "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. 
        +  * under the License.
           *
         -->
         <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        @@ -93,7 +93,12 @@
               <groupId>org.codehaus.plexus</groupId>
               <artifactId>plexus-i18n</artifactId>
               <version>1.0-beta-6</version>
        -    </dependency>    
        +    </dependency>
        +    <dependency>
        +      <groupId>com.thoughtworks.xstream</groupId>
        +      <artifactId>xstream</artifactId>
        +      <version>1.4.5</version>
        +    </dependency>
           </dependencies>
         
           <build>
        
        

        Any comments are welcome!

        I'd like to have this merged for decouple http://docs.codehaus.org/display/SONAR/SonarQube+Mojo+Bridge.

        Currently it injects very tight coupled a mojo while runtime. Makes a lot of problems between the maven versions - as it can be expected.

        Cheers Lars

        Show
        Lars Gohlke added a comment - I implemented this as optional for DependencyConvergence and offer a patch for this here against r1535845 Index: enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java (revision 1535845) +++ enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java (revision ) @@ -24,6 +24,7 @@ import java.util.List; import org.apache.maven.artifact.Artifact; + import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -41,7 +42,11 @@ import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.i18n.I18N; + import org.codehaus.plexus.util.FileUtils; + import java.io.File; + import java.io.IOException; + import com.thoughtworks.xstream.XStream; /** * @author <a href= "mailto:rex@e-hoffman.org" >Rex Hoffman</a> */ @@ -52,20 +57,26 @@ private static Log log; private static I18N i18n; - - private boolean uniqueVersions; + + private boolean uniqueVersions; public void setUniqueVersions( boolean uniqueVersions ) { this .uniqueVersions = uniqueVersions; } - + + private File xmlReport; + + public void setXmlReport(File xmlReport) { + this .xmlReport = xmlReport; + } + /** * Uses the {@link EnforcerRuleHelper} to populate the values of the * {@link DependencyTreeBuilder#buildDependencyTree(MavenProject, ArtifactRepository, ArtifactFactory, ArtifactMetadataSource, ArtifactFilter, ArtifactCollector)} * factory method. <br/> * This method simply exists to hide all the ugly lookup that the {@link EnforcerRuleHelper} has to do . - * + * * @param helper * @ return a Dependency Node which is the root of the project's dependency tree * @ throws EnforcerRuleException @@ -121,7 +132,11 @@ visitor.setUniqueVersions( uniqueVersions ); node.accept( visitor ); List<CharSequence> errorMsgs = new ArrayList<CharSequence>(); - errorMsgs.addAll( getConvergenceErrorMsgs( visitor.getConflictedVersionNumbers() ) ); + + List<List<DependencyNode>> conflictedVersionNumbers = visitor.getConflictedVersionNumbers(); + errorMsgs.addAll( getConvergenceErrorMsgs(conflictedVersionNumbers) ); + writeConflictedVersionNumbers(conflictedVersionNumbers); + for ( CharSequence errorMsg : errorMsgs ) { log.warn( errorMsg ); @@ -138,6 +153,24 @@ catch ( Exception e ) { throw new EnforcerRuleException( e.getLocalizedMessage(), e ); + } + } + + private void writeConflictedVersionNumbers(List<List<DependencyNode>> conflictedVersionNumbers) { + if ( null != xmlReport ){ + XStream xStream = new XStream(); + xStream.omitField(DefaultArtifact.class, "artifactHandler" ); + xStream.omitField(DefaultArtifact.class, "versionRange" ); + xStream.omitField(DependencyNode.class, "parent" ); + xStream.omitField(DependencyNode.class, "state" ); + + xStream.alias( "dependency" ,DependencyNode.class); + + try { + FileUtils.fileWrite(xmlReport.getAbsolutePath(),xStream.toXML(conflictedVersionNumbers)); + } catch (IOException e) { + throw new IllegalStateException(e); + } } } @@ -222,7 +255,7 @@ * allow double checking of the results. Most of the time this can be done by generating unique ids, but sometimes * the results of objects returned by the helper need to be queried. You may for example, store certain objects in * your rule and then query them later. - * + * * @param rule */ public boolean isResultValid( EnforcerRule rule ) \ No newline at end of file Index: enforcer-rules/pom.xml IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- enforcer-rules/pom.xml (revision 1535845) +++ enforcer-rules/pom.xml (revision ) @@ -15,7 +15,7 @@ * "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. + * under the License. * --> <project xmlns= "http: //maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > @@ -93,7 +93,12 @@ <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-i18n</artifactId> <version>1.0-beta-6</version> - </dependency> + </dependency> + <dependency> + <groupId>com.thoughtworks.xstream</groupId> + <artifactId>xstream</artifactId> + <version>1.4.5</version> + </dependency> </dependencies> <build> Any comments are welcome! I'd like to have this merged for decouple http://docs.codehaus.org/display/SONAR/SonarQube+Mojo+Bridge . Currently it injects very tight coupled a mojo while runtime. Makes a lot of problems between the maven versions - as it can be expected. Cheers Lars

          People

          • Assignee:
            Unassigned
            Reporter:
            Shaun
          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: