Skip to content

Commit

Permalink
#343 Parent updates report
Browse files Browse the repository at this point in the history
  • Loading branch information
jarmoniuk authored and slawekjaranowski committed Sep 27, 2022
1 parent e6ca372 commit 8ac4923
Show file tree
Hide file tree
Showing 12 changed files with 463 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/it/it-parent-updates-report-001/invoker.properties
@@ -0,0 +1 @@
invoker.goals=site
54 changes: 54 additions & 0 deletions src/it/it-parent-updates-report-001/module/pom.xml
@@ -0,0 +1,54 @@
<project>
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>localhost</groupId>
<artifactId>dummy-parent3</artifactId>
<version>1.0.0</version>
</parent>

<artifactId>module</artifactId>
<version>1.0.0</version>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>@sitePluginVersion@</version>
</plugin>
</plugins>
</pluginManagement>
</build>

<reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<reportSets>
<reportSet>
<reports>
<report>parent-updates-report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>

</project>
60 changes: 60 additions & 0 deletions src/it/it-parent-updates-report-001/pom.xml
@@ -0,0 +1,60 @@
<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">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>localhost</groupId>
<artifactId>dummy-parent2</artifactId>
<version>1.0</version>
</parent>

<artifactId>it-parent-updates-report-001</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

<modules>
<module>module</module>
</modules>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>@sitePluginVersion@</version>
</plugin>
</plugins>
</pluginManagement>
</build>

<reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<reportSets>
<reportSet>
<reports>
<report>parent-updates-report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>

</project>
7 changes: 7 additions & 0 deletions src/it/it-parent-updates-report-001/src/site/site.xml
@@ -0,0 +1,7 @@
<project>
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-default-skin</artifactId>
<version>1.0</version>
</skin>
</project>
13 changes: 13 additions & 0 deletions src/it/it-parent-updates-report-001/verify.groovy
@@ -0,0 +1,13 @@
report = new File( basedir, "target/site/parent-updates-report.html" ).text
.replaceAll( "<[^>]+>", " " )
.replaceAll( "&[^;]+;", " " )
.replaceAll( "\\s+", " " )

assert report =~ /dummy-parent2 +1.0 +pom +3.1/

report = new File( basedir, "module/target/site/parent-updates-report.html" ).text
.replaceAll( "<[^>]+>", " " )
.replaceAll( "&[^;]+;", " " )
.replaceAll( "\\s+", " " )

assert report =~ /dummy-parent3 +1.0.0 +pom/
Expand Up @@ -72,10 +72,9 @@ protected void renderBody()

renderSummaryTotalsTable( allUpdates );

renderSummaryTable( "report.overview.dependencyManagement", dependencyManagementUpdates,
"report.overview.noDependencyManagement" );
renderDependencyManagementSummary();

renderSummaryTable( "report.overview.dependency", dependencyUpdates, "report.overview.noDependency" );
renderDependencySummary();

sink.section1_();

Expand All @@ -94,7 +93,18 @@ protected void renderBody()
sink.section1_();
}

private void renderSummaryTable( String titleKey, Map<Dependency, ArtifactVersions> contents, String emptyKey )
protected void renderDependencySummary()
{
renderSummaryTable( "report.overview.dependency", dependencyUpdates, "report.overview.noDependency" );
}

protected void renderDependencyManagementSummary()
{
renderSummaryTable( "report.overview.dependencyManagement", dependencyManagementUpdates,
"report.overview.noDependencyManagement" );
}

protected void renderSummaryTable( String titleKey, Map<Dependency, ArtifactVersions> contents, String emptyKey )
{
sink.section2();
sink.sectionTitle2();
Expand All @@ -114,7 +124,7 @@ private void renderSummaryTable( String titleKey, Map<Dependency, ArtifactVersio
sink.section2_();
}

private void renderSummaryTotalsTable( Map<Dependency, ArtifactVersions> allUpdates )
protected void renderSummaryTotalsTable( Map<Dependency, ArtifactVersions> allUpdates )
{
int numInc = 0;
int numMin = 0;
Expand Down Expand Up @@ -203,7 +213,7 @@ else if ( details.getOldestUpdate( of( MAJOR ) ) != null )
sink.table_();
}

private void renderDependencyDetail( Dependency dependency, ArtifactVersions details )
protected void renderDependencyDetail( Dependency dependency, ArtifactVersions details )
{
sink.section2();
sink.sectionTitle2();
Expand Down
145 changes: 145 additions & 0 deletions src/main/java/org/codehaus/mojo/versions/ParentUpdatesReport.java
@@ -0,0 +1,145 @@
package org.codehaus.mojo.versions;

/*
* 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 javax.inject.Inject;

import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.mojo.versions.api.ArtifactVersions;
import org.codehaus.mojo.versions.utils.DependencyBuilder;
import org.codehaus.plexus.i18n.I18N;

import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;

/**
* Generates a report on available updates for parent artifacts
*
* @author Andrzej Jarmoniuk
* @since 2.13.0
*/
@Mojo( name = "parent-updates-report",
requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = false )
public class ParentUpdatesReport extends AbstractVersionsReport
{
@Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true )
protected List<MavenProject> reactorProjects;

@Inject
protected ParentUpdatesReport( I18N i18n, RepositorySystem repositorySystem, ArtifactResolver artifactResolver,
ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager )
{
super( i18n, repositorySystem, artifactResolver, artifactMetadataSource, wagonManager );
}

/**
* {@inheritDoc}
*/
public boolean isExternalReport()
{
return false;
}

/**
* {@inheritDoc}
*/
public boolean canGenerateReport()
{
if ( getProject().getParent() == null )
{
getLog().warn( "Project does not have a parent." );
return false;
}

if ( reactorProjects.contains( getProject().getParent() ) )
{
getLog().warn( "Parent project is part of the reactor." );
return false;
}

return true;
}

/**
* generates an empty report in case there are no sources to generate a report with
*
* @param locale the locale to generate the report for.
* @param sink the report formatting tool
*/
@SuppressWarnings( "deprecation" )
protected void doGenerateReport( Locale locale, Sink sink ) throws MavenReportException
{
try
{
ArtifactVersions artifactVersions = getHelper().lookupArtifactVersions( project.getParentArtifact(),
false );
artifactVersions.setIncludeSnapshots( allowSnapshots );
Dependency parent = DependencyBuilder.newBuilder()
.withGroupId( artifactVersions.getGroupId() )
.withArtifactId( artifactVersions.getArtifactId() )
.withVersion( artifactVersions.getArtifact().getVersion() )
.withScope( artifactVersions.getArtifact().getScope() )
.withType( artifactVersions.getArtifact().getType() )
.withClassifier( artifactVersions.getArtifact().getClassifier() )
.build();
new DependencyUpdatesRenderer( sink, getI18n(), getOutputName(), locale,
singletonMap( parent, artifactVersions ), emptyMap() )
{
@Override
protected void renderSummaryTotalsTable( Map<Dependency, ArtifactVersions> allUpdates )
{
}

@Override
protected void renderDependencyManagementSummary()
{
}
}
.renderBody();
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new MavenReportException( e.getMessage(), e );
}
}

/**
* {@inheritDoc}
*/
public String getOutputName()
{
return "parent-updates-report";
}
}
58 changes: 58 additions & 0 deletions src/main/resources/parent-updates-report.properties
@@ -0,0 +1,58 @@
# 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.

report.title=Parent Updates Report
report.description=Provides information on parent artifact updates
report.overview.title=Overview
report.overview.text=This report summarizes newer versions that may be available for your project's parent artifacts
report.overview.dependency=Parent artifact
report.overview.noDependency=This project does not declare a parent artifact
report.overview.numUpToDate=# of parent artifacts using the latest version available
report.overview.numNewerMajorAvailable=# of parent artifacts where the next version available is a major version update
report.overview.numNewerMinorAvailable=# of parent artifacts where the next version available is a minor version update
report.overview.numNewerIncrementalAvailable=# of parent artifacts where the next version available is an incremental \
version update
report.overview.numNewerVersionAvailable=# of parent artifacts where the next version available is smaller than an \
incremental version update
report.overview.property=Summary of parent artifacts associated with artifact versions
report.overview.noProperty=No properties associated with artifacts have been defined.
report.detail.title=Parent Update
report.detail.text=
report.status=Status
report.groupId=Group Id
report.artifactId=Artifact Id
report.currentVersion=Current Version
report.scope=Scope
report.classifier=Classifier
report.type=Type
report.nextVersion=Next Version
report.latestSubIncremental=Latest Subincremental
report.nextIncremental=Next Incremental
report.latestIncremental=Latest Incremental
report.nextMinor=Next Minor
report.latestMinor=Latest Minor
report.nextMajor=Next Major
report.latestMajor=Latest Major
report.updateVersions=Newer versions
report.noUpdatesAvailable=No newer versions available.
report.otherUpdatesAvailable=There is at least one newer version available.
report.incrementalUpdatesAvailable=There is at least one newer incremental version available. \
Incremental updates are typically passive.
report.minorUpdatesAvailable=There is at least one newer minor version available. \
Minor updates are sometimes passive.
report.majorUpdatesAvailable=There is at least one newer major version available. \
Major updates are rarely passive.

0 comments on commit 8ac4923

Please sign in to comment.