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 2019/03/10 19:32:29 UTC
[maven-dist-tool] branch master updated: Introduce
'check-primary-branch' goal (until
https://issues.jenkins-ci.org/browse/JENKINS-53934 is solved)
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 0d8549c Introduce 'check-primary-branch' goal (until https://issues.jenkins-ci.org/browse/JENKINS-53934 is solved)
0d8549c is described below
commit 0d8549cc96aaf69abd38875eb72efc7015d30dfd
Author: rfscholte <rf...@apache.org>
AuthorDate: Sun Mar 10 20:32:20 2019 +0100
Introduce 'check-primary-branch' goal (until https://issues.jenkins-ci.org/browse/JENKINS-53934 is solved)
---
pom.xml | 5 +-
src/it/check-primary-branch/invoker.properties | 18 ++
.../dist/tools/scmrepo/CheckPrimaryBranchMojo.java | 199 +++++++++++++++++++++
.../apache/maven/dist/tools/scmrepo/Result.java | 74 ++++++++
4 files changed, 294 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 958c8fb..4f71c01 100644
--- a/pom.xml
+++ b/pom.xml
@@ -53,8 +53,8 @@
<properties>
<netbeans.checkstyle.format>true</netbeans.checkstyle.format>
<mvnversion>3.0.4</mvnversion>
- <maven.compiler.source>1.7</maven.compiler.source>
- <maven.compiler.target>1.7</maven.compiler.target>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
@@ -249,6 +249,7 @@
<report>check-index-page</report>
<report>check-errors</report>
<report>list-plugins-prerequisites</report>
+ <report>check-primary-branch</report>
</reports>
</reportSet>
<reportSet>
diff --git a/src/it/check-primary-branch/invoker.properties b/src/it/check-primary-branch/invoker.properties
new file mode 100644
index 0000000..09d4486
--- /dev/null
+++ b/src/it/check-primary-branch/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:check-primary-branch -e
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/dist/tools/scmrepo/CheckPrimaryBranchMojo.java b/src/main/java/org/apache/maven/dist/tools/scmrepo/CheckPrimaryBranchMojo.java
new file mode 100644
index 0000000..73dae09
--- /dev/null
+++ b/src/main/java/org/apache/maven/dist/tools/scmrepo/CheckPrimaryBranchMojo.java
@@ -0,0 +1,199 @@
+package org.apache.maven.dist.tools.scmrepo;
+
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import org.apache.maven.dist.tools.JsoupRetry;
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.reporting.AbstractMavenReport;
+import org.apache.maven.reporting.MavenReportException;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+
+/**
+ * Generate report with build status of the master for every repository
+ * @author Robert Scholte
+ */
+@Mojo( name = "check-primary-branch", requiresProject = false )
+public class CheckPrimaryBranchMojo extends AbstractMavenReport
+{
+ private String gitboxUrl = "https://gitbox.apache.org/repos/asf";
+ private String baseUrl = "https://builds.apache.org/job/maven-box/job/";
+
+ private Collection<String> excluded = Arrays.asList( "maven-integration-testing", // runs with maven
+ "maven-jenkins-env",
+ "maven-jenkins-lib",
+ "maven-sources",
+ "maven-studies" );
+
+ @Override
+ public String getOutputName()
+ {
+ return "check-primary-branch";
+ }
+
+ @Override
+ public String getName( Locale locale )
+ {
+ return "Check Primary Branch";
+ }
+
+ @Override
+ public String getDescription( Locale locale )
+ {
+ return "Shows the statuses of all Maven repositories on one page";
+ }
+
+ @Override
+ protected void executeReport( Locale locale )
+ throws MavenReportException
+ {
+ Collection<String> repositoryNames;
+ try
+ {
+ repositoryNames = repositoryNames();
+ }
+ catch ( IOException e )
+ {
+ throw new MavenReportException( "Failed to extract repositorynames", e );
+ }
+
+ List<Result> repoStatus = new ArrayList<>( repositoryNames.size() );
+
+ Collection<String> included = repositoryNames.stream()
+ .filter( s -> !excluded.contains( s ) )
+ .collect( Collectors.toList() );
+
+ for ( String repository : included )
+ {
+ Document doc;
+ try
+ {
+ final String buildUrl = baseUrl + repository;
+ doc = JsoupRetry.get( buildUrl );
+
+ Result result = new Result( repository, buildUrl );
+
+ Element masterRow = doc.getElementById( "job_master" );
+ if ( masterRow == null )
+ {
+ getLog().warn( baseUrl + repository + " is missing id job_master" );
+ }
+ else if ( masterRow.hasClass( "job-status-red" ) )
+ {
+ result.setStatus( "FAILURE" );
+ }
+ else if ( masterRow.hasClass( "job-status-yellow" ) )
+ {
+ result.setStatus( "UNSTABLE" );
+ }
+ else if ( masterRow.hasClass( "job-status-blue" ) )
+ {
+ result.setStatus( "SUCCESS" );
+ }
+ else
+ {
+ result.setStatus( "UNKNOWN" );
+ }
+ result.setIcon( masterRow.select( "img" ).first().outerHtml() );
+
+ repoStatus.add( result );
+ }
+ catch ( IOException e )
+ {
+ getLog().warn( "Failed to read status for " + repository );
+ }
+ }
+
+ generateReport( repoStatus );
+ }
+
+ private void generateReport( List<Result> repoStatus )
+ {
+ Sink sink = getSink();
+
+ sink.head();
+ sink.title();
+ sink.title_();
+ sink.head_();
+
+ sink.body();
+
+ Map<String, List<Result>> groupedResults = repoStatus.stream()
+ .collect( Collectors.groupingBy( Result::getStatus ) );
+
+ groupedResults.entrySet().stream().sorted( Map.Entry.comparingByKey( resultComparator() ) ).forEach( e ->
+ {
+ sink.text( "Repository " + e.getKey() );
+ sink.list();
+ e.getValue().forEach( r ->
+ {
+ sink.listItem();
+ sink.rawText( r.getIcon() );
+ sink.link( r.getBuildUrl() );
+ sink.rawText( r.getRepositoryName() );
+ sink.link_();
+ sink.listItem_();
+ } );
+ sink.list_();
+
+ sink.table_();
+ } );
+
+ sink.body_();
+ }
+
+ private Comparator<String> resultComparator()
+ {
+ final List<String> orderedStatus = Arrays.asList( "FAILURE", "UNSTABLE", "UNKNOWN", "SUCCESS" );
+ return ( l, r ) ->
+ {
+ return Integer.compare( orderedStatus.indexOf( l ), orderedStatus.indexOf( r ) );
+ };
+ }
+
+ protected Collection<String> repositoryNames()
+ throws IOException
+ {
+ List<String> names = new ArrayList<>( 100 );
+ Document doc = JsoupRetry.get( gitboxUrl );
+ // find Apache Maven table
+ Element apacheMavenTable = doc.getElementsMatchingText( "^Apache Maven$" ).parents().get( 0 );
+
+ Elements gitRepo = apacheMavenTable.select( "tbody td:first-child a" );
+
+ for ( Element element : gitRepo )
+ {
+ names.add( element.text().split( "\\.git" )[0] );
+ }
+ return names;
+ }
+}
diff --git a/src/main/java/org/apache/maven/dist/tools/scmrepo/Result.java b/src/main/java/org/apache/maven/dist/tools/scmrepo/Result.java
new file mode 100644
index 0000000..afa5a39
--- /dev/null
+++ b/src/main/java/org/apache/maven/dist/tools/scmrepo/Result.java
@@ -0,0 +1,74 @@
+package org.apache.maven.dist.tools.scmrepo;
+
+/*
+ * 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.
+ */
+
+
+/**
+ * Represent build result of a repository
+ *
+ * @author Robert Scholte
+ *
+ */
+public class Result
+{
+ private String repositoryName;
+
+ private String status;
+
+ private String buildUrl;
+
+ private String icon;
+
+ public Result( String repositoryName, String buildUrl )
+ {
+ this.repositoryName = repositoryName;
+ this.buildUrl = buildUrl;
+ }
+
+ public void setStatus( String status )
+ {
+ this.status = status;
+ }
+
+ public void setIcon( String icon )
+ {
+ this.icon = icon;
+ }
+
+ public String getRepositoryName()
+ {
+ return repositoryName;
+ }
+
+ public String getStatus()
+ {
+ return status;
+ }
+
+ public String getBuildUrl()
+ {
+ return buildUrl;
+ }
+
+ public String getIcon()
+ {
+ return icon;
+ }
+}