Author: brett
Date: Thu Jan  3 12:35:24 2013
New Revision: 1428319

URL: http://svn.apache.org/viewvc?rev=1428319&view=rev
Log:
[MPIR-266] ensure consistent output from the dependencies report

Using random numbers for identifiers causes the depedencies report to
generate different output on every run, which can negatively impact site
deployment that relies on modified files (such as the ASF's svnpubsub setup).
Switching to a simple incrementing counter for each identifier still allows
unique IDs within the document, in a way that will produce the same result on
two runs against the same input data.

Modified:
    
maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java

Modified: 
maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java?rev=1428319&r1=1428318&r2=1428319&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java
 (original)
+++ 
maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java
 Thu Jan  3 12:35:24 2013
@@ -81,9 +81,6 @@ public class DependenciesRenderer
     /** URL for the 'close.gif' image */
     private static final String IMG_CLOSE_URL = "./images/close.gif";
 
-    /** Random used to generate a UID */
-    private static final SecureRandom RANDOM;
-
     /** Used to format decimal values in the "Dependency File Details" table */
     protected static final DecimalFormat DEFAULT_DECIMAL_FORMAT = new 
DecimalFormat( "#,##0" );
 
@@ -114,6 +111,9 @@ public class DependenciesRenderer
      */
     private int section;
 
+    /** Counter for unique IDs that is consistent across generations. */
+    private int idCounter = 0;
+
     /**
      * Will be filled with license name / set of projects.
      */
@@ -156,15 +156,6 @@ public class DependenciesRenderer
         jarSubtype.add( "ejb" );
         JAR_SUBTYPE = Collections.unmodifiableSet( jarSubtype );
 
-        try
-        {
-            RANDOM = SecureRandom.getInstance( "SHA1PRNG" );
-        }
-        catch ( NoSuchAlgorithmException e )
-        {
-            throw new RuntimeException( e );
-        }
-
         StringBuilder sb = new StringBuilder();
         sb.append( "<script language=\"javascript\" type=\"text/javascript\">" 
).append( SystemUtils.LINE_SEPARATOR );
         sb.append( "      function toggleDependencyDetail( divId, imgId )" 
).append( SystemUtils.LINE_SEPARATOR );
@@ -883,8 +874,8 @@ public class DependenciesRenderer
     {
         Artifact artifact = node.getArtifact();
         String id = artifact.getId();
-        String dependencyDetailId = getUUID();
-        String imgId = getUUID();
+        String dependencyDetailId = "_dep" + idCounter++;
+        String imgId = "_img" + idCounter++;
 
         sink.listItem();
 
@@ -1472,15 +1463,6 @@ public class DependenciesRenderer
     }
 
     /**
-     * @return a valid HTML ID respecting <a 
href="http://www.w3.org/TR/xhtml1/#C_8";>XHTML 1.0 section C.8. Fragment
-     *         Identifiers</a>
-     */
-    private static String getUUID()
-    {
-        return "_" + Math.abs( RANDOM.nextInt() );
-    }
-
-    /**
      * Formats file length with the associated <a 
href="http://en.wikipedia.org/wiki/SI_prefix#Computing";>SI</a> unit
      * (GB, MB, kB) and using the pattern <code>########.00</code> by default.
      * 


Reply via email to