Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves #359: XML Property Updates Report #804

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions model-report/pom.xml
Expand Up @@ -62,6 +62,7 @@
<models>
<model>src/main/mdo/dependency-updates-report.mdo</model>
<model>src/main/mdo/plugin-updates-report.mdo</model>
<model>src/main/mdo/property-updates-report.mdo</model>
</models>
<version>${modelloNamespaceReportVersion}</version>
</configuration>
Expand Down
1 change: 0 additions & 1 deletion model-report/src/main/mdo/dependency-updates-report.mdo
Expand Up @@ -85,7 +85,6 @@ under the License.
</field>
<field>
<name>nextIncrementalAvailable</name>
<version>1.0.0+</version>
<required>true</required>
<type>String</type>
</field>
Expand Down
1 change: 0 additions & 1 deletion model-report/src/main/mdo/plugin-updates-report.mdo
Expand Up @@ -85,7 +85,6 @@ under the License.
</field>
<field>
<name>nextIncrementalAvailable</name>
<version>1.0.0+</version>
<required>true</required>
<type>String</type>
</field>
Expand Down
171 changes: 171 additions & 0 deletions model-report/src/main/mdo/property-updates-report.mdo
@@ -0,0 +1,171 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
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.
-->

<model xmlns="http://codehaus-plexus.github.io/MODELLO/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://codehaus-plexus.github.io/MODELLO/2.0.0 https://codehaus-plexus.github.io/modello/xsd/modello-2.0.0.xsd"
xml.namespace="https://www.mojohaus.org/VERSIONS/PROPERTY-UPDATES-REPORT/${version}"
xml.schemaLocation="https://www.mojohaus.org/versions/model-report/xsd/property-updates-report-${version}.xsd">
<id>property-updates-report</id>
<name>PropertyUpdatesReport</name>
<description>
XML version of the Property Updates Report
</description>

<defaults>
<default>
<key>package</key>
<value>org.codehaus.mojo.versions.reporting.model</value>
</default>
</defaults>

<versionDefinition>
<type>namespace</type>
</versionDefinition>

<classes>

<class rootElement="true" xml.tagName="PropertyUpdatesReport">
<name>PropertyUpdatesReport</name>
<fields>
<field>
<name>summary</name>
<required>true</required>
<association>
<type>PropertyReportSummary</type>
<multiplicity>1</multiplicity>
</association>
</field>
<field>
<name>properties</name>
<association xml.itemsStyle="wrapped" xml.tagName="property">
<type>PropertyInfo</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
</class>

<class>
<name>PropertyReportSummary</name>
<fields>
<field>
<name>usingLastVersion</name>
<required>true</required>
<type>String</type>
</field>
<field>
<name>nextVersionAvailable</name>
<required>true</required>
<type>String</type>
</field>
<field>
<name>nextIncrementalAvailable</name>
<required>true</required>
<type>String</type>
</field>
<field>
<name>nextMinorAvailable</name>
<required>true</required>
<type>String</type>
</field>
<field>
<name>nextMajorAvailable</name>
<required>true</required>
<type>String</type>
</field>
</fields>
</class>

<class>
<name>PropertyInfo</name>
<fields>
<field>
<name>propertyName</name>
<required>true</required>
<type>String</type>
</field>
<field>
<name>propertyAssociations</name>
<association xml.itemsStyle="wrapped" xml.tagName="propertyAssociation">
<type>PropertyAssociation</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>currentVersion</name>
<type>String</type>
</field>
<field>
<name>lastVersion</name>
<type>String</type>
</field>
<field>
<name>any</name>
<association xml.itemsStyle="wrapped" xml.tagName="any">
<type>String</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>incrementals</name>
<association xml.itemsStyle="wrapped" xml.tagName="incremental">
<type>String</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>minors</name>
<association xml.itemsStyle="wrapped" xml.tagName="minor">
<type>String</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>majors</name>
<association xml.itemsStyle="wrapped" xml.tagName="major">
<type>String</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>status</name>
<required>true</required>
<type>String</type>
</field>
</fields>
</class>

<class>
<name>PropertyAssociation</name>
<fields>
<field>
<name>groupId</name>
<type>String</type>
</field>
<field>
<name>artifactId</name>
<type>String</type>
</field>
</fields>
</class>

</classes>
</model>
@@ -0,0 +1,2 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:property-updates-report
invoker.mavenOpts = -DpropertyUpdatesReportFormats=xml
@@ -0,0 +1,45 @@
<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>
<groupId>localhost</groupId>
<artifactId>it-xml-property-updates-report-001</artifactId>
<version>1.0</version>

<properties>
<api-version>1.0</api-version>
<impl-version>2.0</impl-version>
<plugin-version>3.0</plugin-version>
</properties>

<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>[${api-version},2.1-!)</version>
</dependency>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-impl</artifactId>
<version>${impl-version}</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>localhost</groupId>
<artifactId>dummy-maven-plugin</artifactId>
<version>${plugin-version}</version>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>${plugin-version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
@@ -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'
Expand Up @@ -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();
Expand Down
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -93,6 +98,14 @@ public class PropertyUpdatesReportMojo extends AbstractVersionsReport<PropertyUp
@Parameter( property = "includeParent", defaultValue = "true" )
private boolean includeParent = true;

/**
* Report formats (html and/or xml). HTML by default.
*
* @since 2.14.0
*/
@Parameter( property = "propertyUpdatesReportFormats", defaultValue = "html" )
protected String[] formats = new String[] {"html"};

@Inject
protected PropertyUpdatesReportMojo( I18N i18n, RepositorySystem repositorySystem,
ArtifactResolver artifactResolver,
Expand Down Expand Up @@ -142,8 +155,31 @@ protected void doGenerateReport( Locale locale, Sink sink )
{
throw new MavenReportException( e.getMessage(), e );
}
rendererFactory.createReportRenderer( getOutputName(), getSink(), locale,
new PropertyUpdatesModel( updateSet ) ).render();
PropertyUpdatesModel model = new PropertyUpdatesModel( updateSet );
for ( String format : formats )
{
if ( "html".equals( format ) )
{
rendererFactory.createReportRenderer( getOutputName(), getSink(), locale, model ).render();
}
else if ( "xml".equals( format ) )
{
Path outputDir = Paths.get( getProject().getBuild().getDirectory() );
if ( !Files.exists( outputDir ) )
{
try
{
Files.createDirectories( outputDir );
}
catch ( IOException e )
{
throw new MavenReportException( "Could not create the output directory" );
}
}
Path outputFile = outputDir.resolve( getOutputName() + ".xml" );
new PropertyUpdatesXmlReportRenderer( model, outputFile ).render();
}
}
}

/**
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.Optional;

import org.apache.maven.artifact.versioning.ArtifactVersion;
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.api.Segment;
Expand Down Expand Up @@ -63,8 +64,8 @@ public class OverviewStats
* @param <V> subclass of {@linkplain ArtifactVersions}
* @return instance of the {@linkplain OverviewStats}
*/
public static <T extends OverviewStats, V extends ArtifactVersions> T fromUpdates( Collection<V> updates,
ArtifactVersionsCache cache )
public static <T extends OverviewStats, V extends AbstractVersionDetails>
T fromUpdates( Collection<V> updates, ArtifactVersionsCache cache )
{
OverviewStats stats = new OverviewStats();
updates.forEach( details ->
Expand Down Expand Up @@ -93,7 +94,7 @@ else if ( getNewestUpdate( cache, details, of( MAJOR ) ) != null )
return (T) stats;
}

protected static <V extends ArtifactVersions> ArtifactVersion getNewestUpdate( ArtifactVersionsCache cache,
protected static <V extends AbstractVersionDetails> ArtifactVersion getNewestUpdate( ArtifactVersionsCache cache,
V details,
Optional<Segment> segment )
{
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -60,8 +61,8 @@ public void incrementDependencies()
* @param <V> always equal to {@linkplain org.codehaus.mojo.versions.PluginUpdatesDetails}
* @return instance of the {@linkplain PluginOverviewStats}, initialised with the update information
*/
public static <T extends OverviewStats, V extends ArtifactVersions> T fromUpdates( Collection<V> updates,
ArtifactVersionsCache cache )
public static <T extends OverviewStats, V extends AbstractVersionDetails>
T fromUpdates( Collection<V> updates, ArtifactVersionsCache cache )
{
PluginOverviewStats stats = new PluginOverviewStats();
updates.forEach( details ->
Expand Down