You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2021/04/18 09:37:55 UTC

[maven-dist-tool] branch master updated: Add lastBuild date to master jobs page (with 1 month warning limit)

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

rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dist-tool.git


The following commit(s) were added to refs/heads/master by this push:
     new 199bf96  Add lastBuild date to master jobs page (with 1 month warning limit)
199bf96 is described below

commit 199bf968f8c246fb821ffd524a9d41ae2836d7fe
Author: rfscholte <rf...@apache.org>
AuthorDate: Sun Apr 18 11:36:45 2021 +0200

    Add lastBuild date to master jobs page (with 1 month warning limit)
---
 .../dist/tools/masterjobs/ListMasterJobsMojo.java  | 49 +++++++++++++++++++++-
 .../apache/maven/dist/tools/masterjobs/Result.java | 14 +++++++
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/maven/dist/tools/masterjobs/ListMasterJobsMojo.java b/src/main/java/org/apache/maven/dist/tools/masterjobs/ListMasterJobsMojo.java
index a3ab3e2..a36fadf 100644
--- a/src/main/java/org/apache/maven/dist/tools/masterjobs/ListMasterJobsMojo.java
+++ b/src/main/java/org/apache/maven/dist/tools/masterjobs/ListMasterJobsMojo.java
@@ -20,6 +20,8 @@ package org.apache.maven.dist.tools.masterjobs;
  */
 
 import java.io.IOException;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -128,6 +130,9 @@ public class ListMasterJobsMojo extends AbstractMavenReport
                 }
                 result.setIcon( masterRow.select( "img" ).first().outerHtml() );
                 
+                result.setLastBuild( getLastBuild( masterRow.child( 3 ).attr( "data" ),
+                                                   masterRow.child( 4 ).attr( "data" ) ) );
+                
                 repoStatus.add( result );
             }
             catch ( IOException e )
@@ -155,7 +160,7 @@ public class ListMasterJobsMojo extends AbstractMavenReport
         
         Map<String, List<Result>> groupedResults = repoStatus.stream()
                                                              .collect( Collectors.groupingBy( Result::getStatus ) );
-        
+
         groupedResults.entrySet()
                       .stream()
                       .sorted( Map.Entry.comparingByKey( resultComparator() ) )
@@ -169,6 +174,17 @@ public class ListMasterJobsMojo extends AbstractMavenReport
                 {
                     sink.listItem();
                     sink.rawText( r.getIcon() );
+                    
+                    if ( r.getLastBuild().isBefore( ZonedDateTime.now().minusMonths( 1 ) ) )
+                    {
+                                  sink.rawText( "<span style=\"color:red\">("
+                                      + r.getLastBuild().format( DateTimeFormatter.ISO_DATE ) + ")</span> " );
+                              }
+                    else
+                    {
+                                  sink.rawText( "<span>(" + r.getLastBuild().format( DateTimeFormatter.ISO_DATE )
+                                      + ")</span> " );
+                              }
                     sink.link( r.getBuildUrl() );
                     sink.rawText( r.getRepositoryName() );
                     sink.link_();
@@ -192,6 +208,37 @@ public class ListMasterJobsMojo extends AbstractMavenReport
             };
     }
 
+    private ZonedDateTime getLastBuild( String lastSuccess, String lastFailure )
+    {
+        ZonedDateTime success = null;
+        if ( !"-".equals( lastSuccess ) )
+        {
+            success = ZonedDateTime.parse( lastSuccess );
+        }
+        ZonedDateTime failure = null;
+        if ( !"-".equals( lastFailure ) )
+        {
+            failure = ZonedDateTime.parse( lastFailure );
+        }
+        
+        if ( success == null )
+        {
+            return failure;
+        }
+        else if ( failure == null )
+        {
+            return success;
+        }
+        else if ( success.compareTo( failure ) >= 0 ) 
+        {
+            return success;
+        }
+        else
+        {
+            return failure;
+        }
+    }
+    
     /**
      * Extract Git repository names for Apache Maven from
      * <a href="https://gitbox.apache.org/repos/asf">Gitbox main page</a>.
diff --git a/src/main/java/org/apache/maven/dist/tools/masterjobs/Result.java b/src/main/java/org/apache/maven/dist/tools/masterjobs/Result.java
index 3281863..898c895 100644
--- a/src/main/java/org/apache/maven/dist/tools/masterjobs/Result.java
+++ b/src/main/java/org/apache/maven/dist/tools/masterjobs/Result.java
@@ -19,6 +19,8 @@ package org.apache.maven.dist.tools.masterjobs;
  * under the License.
  */
 
+import java.time.ZonedDateTime;
+
 /**
  * Represent build result of a Jenkins job for a Git master branch.
  * 
@@ -33,6 +35,8 @@ public class Result
     private String buildUrl;
 
     private String icon;
+    
+    private ZonedDateTime lastBuild;
 
     public Result( String repositoryName, String buildUrl )
     {
@@ -50,6 +54,16 @@ public class Result
         this.icon = icon;
     }
 
+    public void setLastBuild( ZonedDateTime lastBuild )
+    {
+        this.lastBuild = lastBuild;
+    }
+    
+    public ZonedDateTime getLastBuild()
+    {
+        return lastBuild;
+    }
+    
     public String getRepositoryName()
     {
         return repositoryName;