Skip to content

Commit

Permalink
mojohaus#343 Parent updates report
Browse files Browse the repository at this point in the history
  • Loading branch information
jarmoniuk committed Sep 27, 2022
1 parent 1dd4a31 commit 3468b47
Show file tree
Hide file tree
Showing 12 changed files with 506 additions and 122 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/
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";
}
}

0 comments on commit 3468b47

Please sign in to comment.