From ba6b57625ca70182fb90533aa67747fcc041e2f9 Mon Sep 17 00:00:00 2001 From: Andrzej Jarmoniuk Date: Fri, 28 Oct 2022 15:34:34 +0200 Subject: [PATCH] Resolves #359: XML Property Updates Report --- model-report/pom.xml | 1 + .../main/mdo/dependency-updates-report.mdo | 1 - .../src/main/mdo/plugin-updates-report.mdo | 1 - .../src/main/mdo/property-updates-report.mdo | 171 ++++++++++++++++++ .../invoker.properties | 2 + .../pom.xml | 45 +++++ .../verify.groovy | 13 ++ .../versions/DependencyUpdatesReportMojo.java | 3 +- .../versions/PropertyUpdatesReportMojo.java | 40 +++- .../versions/reporting/OverviewStats.java | 7 +- .../reporting/PluginOverviewStats.java | 5 +- .../PropertyUpdatesReportRenderer.java | 26 +-- .../xml/CommonXmlReportRendererUtils.java | 59 ++++++ .../DependencyUpdatesXmlReportRenderer.java | 23 +-- .../xml/PluginUpdatesXmlReportRenderer.java | 24 +-- .../xml/PropertyUpdatesXmlReportRenderer.java | 134 ++++++++++++++ .../PropertyUpdatesReportMojoTest.java | 2 +- 17 files changed, 479 insertions(+), 78 deletions(-) create mode 100644 model-report/src/main/mdo/property-updates-report.mdo create mode 100644 versions-maven-plugin/src/it/it-xml-property-updates-report-001/invoker.properties create mode 100644 versions-maven-plugin/src/it/it-xml-property-updates-report-001/pom.xml create mode 100644 versions-maven-plugin/src/it/it-xml-property-updates-report-001/verify.groovy create mode 100644 versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/CommonXmlReportRendererUtils.java create mode 100644 versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/PropertyUpdatesXmlReportRenderer.java diff --git a/model-report/pom.xml b/model-report/pom.xml index 6b7c918785..cb4f5a59a1 100644 --- a/model-report/pom.xml +++ b/model-report/pom.xml @@ -62,6 +62,7 @@ src/main/mdo/dependency-updates-report.mdo src/main/mdo/plugin-updates-report.mdo + src/main/mdo/property-updates-report.mdo ${modelloNamespaceReportVersion} diff --git a/model-report/src/main/mdo/dependency-updates-report.mdo b/model-report/src/main/mdo/dependency-updates-report.mdo index c8f41b2d8d..ea30dcaceb 100644 --- a/model-report/src/main/mdo/dependency-updates-report.mdo +++ b/model-report/src/main/mdo/dependency-updates-report.mdo @@ -85,7 +85,6 @@ under the License. nextIncrementalAvailable - 1.0.0+ true String diff --git a/model-report/src/main/mdo/plugin-updates-report.mdo b/model-report/src/main/mdo/plugin-updates-report.mdo index 685d75e3d0..f311d2edcf 100644 --- a/model-report/src/main/mdo/plugin-updates-report.mdo +++ b/model-report/src/main/mdo/plugin-updates-report.mdo @@ -85,7 +85,6 @@ under the License. nextIncrementalAvailable - 1.0.0+ true String diff --git a/model-report/src/main/mdo/property-updates-report.mdo b/model-report/src/main/mdo/property-updates-report.mdo new file mode 100644 index 0000000000..0f9a2df326 --- /dev/null +++ b/model-report/src/main/mdo/property-updates-report.mdo @@ -0,0 +1,171 @@ + + + + + + property-updates-report + PropertyUpdatesReport + + XML version of the Property Updates Report + + + + + package + org.codehaus.mojo.versions.reporting.model + + + + + namespace + + + + + + PropertyUpdatesReport + + + summary + true + + PropertyReportSummary + 1 + + + + properties + + PropertyInfo + * + + + + + + + PropertyReportSummary + + + usingLastVersion + true + String + + + nextVersionAvailable + true + String + + + nextIncrementalAvailable + true + String + + + nextMinorAvailable + true + String + + + nextMajorAvailable + true + String + + + + + + PropertyInfo + + + propertyName + true + String + + + propertyAssociations + + PropertyAssociation + * + + + + currentVersion + String + + + lastVersion + String + + + any + + String + * + + + + incrementals + + String + * + + + + minors + + String + * + + + + majors + + String + * + + + + status + true + String + + + + + + PropertyAssociation + + + groupId + String + + + artifactId + String + + + + + + diff --git a/versions-maven-plugin/src/it/it-xml-property-updates-report-001/invoker.properties b/versions-maven-plugin/src/it/it-xml-property-updates-report-001/invoker.properties new file mode 100644 index 0000000000..fdf91e0dd6 --- /dev/null +++ b/versions-maven-plugin/src/it/it-xml-property-updates-report-001/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:property-updates-report +invoker.mavenOpts = -DpropertyUpdatesReportFormats=xml diff --git a/versions-maven-plugin/src/it/it-xml-property-updates-report-001/pom.xml b/versions-maven-plugin/src/it/it-xml-property-updates-report-001/pom.xml new file mode 100644 index 0000000000..ebba6d39b1 --- /dev/null +++ b/versions-maven-plugin/src/it/it-xml-property-updates-report-001/pom.xml @@ -0,0 +1,45 @@ + + 4.0.0 + localhost + it-xml-property-updates-report-001 + 1.0 + + + 1.0 + 2.0 + 3.0 + + + + + localhost + dummy-api + [${api-version},2.1-!) + + + localhost + dummy-impl + ${impl-version} + + + + + + + localhost + dummy-maven-plugin + ${plugin-version} + + + localhost + dummy-api + ${plugin-version} + + + + + + + diff --git a/versions-maven-plugin/src/it/it-xml-property-updates-report-001/verify.groovy b/versions-maven-plugin/src/it/it-xml-property-updates-report-001/verify.groovy new file mode 100644 index 0000000000..dcaae22494 --- /dev/null +++ b/versions-maven-plugin/src/it/it-xml-property-updates-report-001/verify.groovy @@ -0,0 +1,13 @@ +def pom = new XmlSlurper() + .parse( new File( basedir, 'target/property-updates-report.xml' ) ) + +assert pom.summary.usingLastVersion == 1 +assert pom.summary.nextIncrementalAvailable == 1 +assert pom.summary.nextMinorAvailable == 1 + +assert pom.properties.property.find { node -> node.propertyName == 'api-version' } + .status == 'incremental available' +assert pom.properties.property.find { node -> node.propertyName == 'impl-version' } + .status == 'minor available' +assert pom.properties.property.find { node -> node.propertyName == 'plugin-version' } + .status == 'no new available' diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojo.java index f7c1a30c99..69c5a66e67 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojo.java @@ -224,10 +224,9 @@ && getProject().getOriginalModel().getDependencyManagement().getDependencies() ! .collect( Collectors.joining( ", " ) ) ) ); } + DependencyUpdatesModel model = new DependencyUpdatesModel( dependencyUpdates, dependencyManagementUpdates ); for ( String format : formats ) { - DependencyUpdatesModel model = - new DependencyUpdatesModel( dependencyUpdates, dependencyManagementUpdates ); if ( "html".equals( format ) ) { rendererFactory.createReportRenderer( getOutputName(), sink, locale, model ).render(); diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/PropertyUpdatesReportMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/PropertyUpdatesReportMojo.java index 60f758678c..480949fefd 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/PropertyUpdatesReportMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/PropertyUpdatesReportMojo.java @@ -21,6 +21,10 @@ import javax.inject.Inject; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Locale; import java.util.Map; import java.util.TreeMap; @@ -40,6 +44,7 @@ import org.codehaus.mojo.versions.reporting.ReportRendererFactory; import org.codehaus.mojo.versions.reporting.model.PropertyUpdatesModel; import org.codehaus.mojo.versions.utils.PropertyComparator; +import org.codehaus.mojo.versions.xml.PropertyUpdatesXmlReportRenderer; import org.codehaus.plexus.i18n.I18N; /** @@ -93,6 +98,14 @@ public class PropertyUpdatesReportMojo extends AbstractVersionsReport subclass of {@linkplain ArtifactVersions} * @return instance of the {@linkplain OverviewStats} */ - public static T fromUpdates( Collection updates, - ArtifactVersionsCache cache ) + public static + T fromUpdates( Collection updates, ArtifactVersionsCache cache ) { OverviewStats stats = new OverviewStats(); updates.forEach( details -> @@ -93,7 +94,7 @@ else if ( getNewestUpdate( cache, details, of( MAJOR ) ) != null ) return (T) stats; } - protected static ArtifactVersion getNewestUpdate( ArtifactVersionsCache cache, + protected static ArtifactVersion getNewestUpdate( ArtifactVersionsCache cache, V details, Optional segment ) { diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/PluginOverviewStats.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/PluginOverviewStats.java index 2d215b75cf..81dea82dd6 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/PluginOverviewStats.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/PluginOverviewStats.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.codehaus.mojo.versions.PluginUpdatesDetails; +import org.codehaus.mojo.versions.api.AbstractVersionDetails; import org.codehaus.mojo.versions.api.ArtifactVersions; import org.codehaus.mojo.versions.api.ArtifactVersionsCache; import org.codehaus.mojo.versions.reporting.model.PluginUpdatesModel; @@ -60,8 +61,8 @@ public void incrementDependencies() * @param always equal to {@linkplain org.codehaus.mojo.versions.PluginUpdatesDetails} * @return instance of the {@linkplain PluginOverviewStats}, initialised with the update information */ - public static T fromUpdates( Collection updates, - ArtifactVersionsCache cache ) + public static + T fromUpdates( Collection updates, ArtifactVersionsCache cache ) { PluginOverviewStats stats = new PluginOverviewStats(); updates.forEach( details -> diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/PropertyUpdatesReportRenderer.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/PropertyUpdatesReportRenderer.java index ddb7287e82..1ca1730906 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/PropertyUpdatesReportRenderer.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/reporting/PropertyUpdatesReportRenderer.java @@ -396,31 +396,7 @@ protected void renderSummaryTableHeader( boolean hasScope, boolean hasType ) @Override protected OverviewStats computeOverviewStats() { - OverviewStats stats = new OverviewStats(); - model.getAllUpdates().values().forEach( details -> - { - if ( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null ) - { - stats.incrementAny(); - } - else if ( newestUpdateCache.get( details, of( INCREMENTAL ) ) != null ) - { - stats.incrementIncremental(); - } - else if ( newestUpdateCache.get( details, of( MINOR ) ) != null ) - { - stats.incrementMinor(); - } - else if ( newestUpdateCache.get( details, of( MAJOR ) ) != null ) - { - stats.incrementMajor(); - } - else - { - stats.incrementUpToDate(); - } - } ); - return stats; + return OverviewStats.fromUpdates( model.getAllUpdates().values(), newestUpdateCache ); } private void renderPropertyDetail( Property property, PropertyVersions details ) diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/CommonXmlReportRendererUtils.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/CommonXmlReportRendererUtils.java new file mode 100644 index 0000000000..e828d3d785 --- /dev/null +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/CommonXmlReportRendererUtils.java @@ -0,0 +1,59 @@ +package org.codehaus.mojo.versions.xml; + +/* + * 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.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.codehaus.mojo.versions.api.AbstractVersionDetails; +import org.codehaus.mojo.versions.api.Segment; + +import static java.util.Optional.of; +import static java.util.Optional.ofNullable; + +/** + * Common utils for Xml report renderers + */ +class CommonXmlReportRendererUtils +{ + static void setSection( AbstractVersionDetails versions, Segment segment, Consumer> setterFunction ) + { + ofNullable( versions.getAllUpdates( of( segment ) ) ) + .map( v -> Arrays.stream( v ) + .map( ArtifactVersion::toString ) + .collect( Collectors.toList() ) ) + .ifPresent( setterFunction ); + } + + static String statusFor( String lastVersion, Collection incrementals, Collection minors ) + { + return lastVersion == null + ? "no new available" + : incrementals != null && !incrementals.isEmpty() + ? "incremental available" + : minors != null && !minors.isEmpty() + ? "minor available" + : "major available"; + } +} diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/DependencyUpdatesXmlReportRenderer.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/DependencyUpdatesXmlReportRenderer.java index dee099f597..d360a92ab1 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/DependencyUpdatesXmlReportRenderer.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/DependencyUpdatesXmlReportRenderer.java @@ -24,10 +24,8 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Arrays; import java.util.List; import java.util.Map; -import java.util.function.Consumer; import java.util.stream.Collectors; import org.apache.maven.artifact.versioning.ArtifactVersion; @@ -36,7 +34,6 @@ import org.codehaus.mojo.versions.api.ArtifactVersions; import org.codehaus.mojo.versions.api.ArtifactVersionsCache; import org.codehaus.mojo.versions.api.ReportRenderer; -import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.reporting.OverviewStats; import org.codehaus.mojo.versions.reporting.model.DependencyInfo; import org.codehaus.mojo.versions.reporting.model.DependencyReportSummary; @@ -45,11 +42,12 @@ import org.codehaus.mojo.versions.reporting.model.io.xpp3.DependencyUpdatesReportXpp3Writer; import static java.util.Optional.empty; -import static java.util.Optional.of; import static java.util.Optional.ofNullable; import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL; import static org.codehaus.mojo.versions.api.Segment.MAJOR; import static org.codehaus.mojo.versions.api.Segment.MINOR; +import static org.codehaus.mojo.versions.xml.CommonXmlReportRendererUtils.setSection; +import static org.codehaus.mojo.versions.xml.CommonXmlReportRendererUtils.statusFor; /** * XML renderer for DependencyUpdatesReport creates an xml file in target directory and writes report about available @@ -106,15 +104,6 @@ public void render() } } - private static void setSection( ArtifactVersions versions, Segment segment, Consumer> setterFunction ) - { - ofNullable( versions.getAllUpdates( of( segment ) ) ) - .map( v -> Arrays.stream( v ) - .map( ArtifactVersion::toString ) - .collect( Collectors.toList() ) ) - .ifPresent( setterFunction ); - } - private static List createDependencyInfo( Map versions ) { return versions.entrySet().stream().map( e -> @@ -134,13 +123,7 @@ private static List createDependencyInfo( Map> setterFunction ) - { - ofNullable( versions.getAllUpdates( of( segment ) ) ) - .map( v -> Arrays.stream( v ) - .map( ArtifactVersion::toString ) - .collect( Collectors.toList() ) ) - .ifPresent( setterFunction ); - } - private static List createPluginInfo( Map versions ) { return versions.entrySet().stream().map( e -> @@ -136,13 +124,7 @@ private static List createPluginInfo( Map createPropertyInfo( Map versions ) + { + return versions.entrySet().stream().map( e -> + new PropertyInfo() + {{ + setPropertyName( e.getKey().getName() ); + if ( e.getValue().getAssociations() != null + && e.getValue().getAssociations().length != 0 ) + { + setPropertyAssociations( Arrays.stream( e.getValue().getAssociations() ) + .map( a -> + { + PropertyAssociation pa = new PropertyAssociation(); + pa.setGroupId( a.getGroupId() ); + pa.setArtifactId( a.getArtifactId() ); + return pa; + } ).collect( Collectors.toList() ) ); + } + setCurrentVersion( e.getKey().getVersion() ); + ofNullable( e.getValue().getNewestUpdate( empty() ) ) + .map( ArtifactVersion::toString ).ifPresent( this::setLastVersion ); + + setSection( e.getValue(), INCREMENTAL, this::setIncrementals ); + setSection( e.getValue(), MINOR, this::setMinors ); + setSection( e.getValue(), MAJOR, this::setMajors ); + + setStatus( statusFor( getLastVersion(), getIncrementals(), getMinors() ) ); + }} ).collect( Collectors.toList() ); + } +} diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/PropertyUpdatesReportMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/PropertyUpdatesReportMojoTest.java index 4d498592d4..f0adb37f64 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/PropertyUpdatesReportMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/PropertyUpdatesReportMojoTest.java @@ -74,7 +74,7 @@ public void testIncludeParentTrueShouldContainProperty() throws Exception } @Test - public void testIncludeParentFalseShouldNotCountainProperty() throws Exception + public void testIncludeParentFalseShouldNotContainProperty() throws Exception { OutputStream os = new ByteArrayOutputStream(); SinkFactory sinkFactory = new Xhtml5SinkFactory();