Skip to content

Commit

Permalink
#563 introduce property "versions.displayTerminalWidth" (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Mar 9, 2022
1 parent 65fa0ee commit 8cfe5d0
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:display-dependency-updates
invoker.mavenOpts=-Dverbose=true -Dversions.outputFile=./dependencyUpdate.txt -DoutputEncoding=UTF-8 -Dversions.displayTerminalWidth=120
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<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-display-dependency-updates-008-displayTerminalWidth</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>display-dependency-updates</name>
<description>Validate usage of displayTerminalWidth parameter</description>
<url>http://localhost/</url>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>localhost</groupId>
<artifactId>dummy-maven-plugin</artifactId>
<version>1.0</version>
</plugin>
<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>2.0</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.io.*;
import org.codehaus.plexus.util.FileUtils;

try
{

// validate outputFile
File outputFile = new File( basedir, "dependencyUpdate.txt" );
if (!outputFile.exists()) {
System.out.println( "outputFile not found: " + outputFile.getPath() );
return false;
}
buf = FileUtils.fileRead( outputFile );
if ( !buf.contains("localhost:dummy-api ............................................................................... 1.1 ->") )
{
System.out.println( "displayTerminalWidth parameter not respected" );
return false;
}

}
catch( Throwable t )
{
t.printStackTrace();
return false;
}

return true;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:display-plugin-updates -Dversions.outputFile=./dependencyUpdate.txt -Dversions.displayTerminalWidth=120
33 changes: 33 additions & 0 deletions src/it/it-display-plugin-updates-012-displayTerminalWidth/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<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-display-plugin-updates-012-displayTerminalWidth</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>display-plugin-updates</name>

<description>Validate usage of displayTerminalWidth parameter</description>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>localhost</groupId>
<artifactId>dummy-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.io.*;
import org.codehaus.plexus.util.FileUtils;

try
{

// validate outputFile
File outputFile = new File( basedir, "dependencyUpdate.txt" );
if (!outputFile.exists()) {
System.out.println( "outputFile not found: " + outputFile.getPath() );
return false;
}
buf = FileUtils.fileRead( outputFile );
if ( !buf.contains("maven-deploy-plugin ............................................................................ 2.3 ->") )
{
System.out.println( "displayTerminalWidth parameter not respected" );
return false;
}

}
catch( Throwable t )
{
t.printStackTrace();
return false;
}

return true;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=-DautoLinkItems=true ${project.groupId}:${project.artifactId}:${project.version}:display-property-updates -Dversions.outputFile=./dependencyUpdate.txt -Dversions.displayTerminalWidth=120
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<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-display-property-updates-002-displayTerminalWidth</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>display-property-updates</name>

<description>Validate usage of displayTerminalWidth parameter</description>

<properties>
<api>1.0</api>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>[${api},2.1-!)</version>
</dependency>
</dependencies>
</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>2.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.io.*;
import org.codehaus.plexus.util.FileUtils;

try
{

// validate outputFile
File outputFile = new File( basedir, "dependencyUpdate.txt" );
if (!outputFile.exists()) {
System.out.println( "outputFile not found: " + outputFile.getPath() );
return false;
}
buf = FileUtils.fileRead( outputFile );
if ( !buf.contains("${api} ........................................................................................... 1.0 ->") )
{
System.out.println( "displayTerminalWidth parameter not respected" );
return false;
}

}
catch( Throwable t )
{
t.printStackTrace();
return false;
}

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
public abstract class AbstractVersionsDisplayMojo
extends AbstractVersionsUpdaterMojo
{

private static final int DEFAULT_DISPLAY_TERMINAL_WIDTH = 80;

/**
* If specified then the display output will be sent to the specified file.
*
Expand All @@ -60,6 +63,14 @@ public abstract class AbstractVersionsDisplayMojo
@Parameter( property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}" )
private String outputEncoding;

/**
* Terminal width which should be used to format the padding of the version info list output.
*
* @since 2.10.0
*/
@Parameter( property = "versions.displayTerminalWidth", defaultValue = AbstractVersionsDisplayMojo.DEFAULT_DISPLAY_TERMINAL_WIDTH + "" )
private int displayTerminalWidth;

private boolean outputFileError = false;

protected void logInit()
Expand Down Expand Up @@ -150,4 +161,11 @@ protected void logLine( boolean error, String line )
}
}

/**
* @return Offset of the configured display terminal width compared to the default with of 80.
*/
protected int getDisplayTerminalWidthOffset() {
return this.displayTerminalWidth - DEFAULT_DISPLAY_TERMINAL_WIDTH;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,15 @@ private void logUpdates( Map<Dependency, ArtifactVersions> updates, String secti
}
String right = " " + ( latest == null ? current : current + " -> " + latest );
List<String> t = latest == null ? usingCurrent : withUpdates;
if ( right.length() + left.length() + 3 > INFO_PAD_SIZE )
if ( right.length() + left.length() + 3 > INFO_PAD_SIZE + getDisplayTerminalWidthOffset() )
{
t.add( left + "..." );
t.add( StringUtils.leftPad( right, INFO_PAD_SIZE ) );
t.add( StringUtils.leftPad( right, INFO_PAD_SIZE + getDisplayTerminalWidthOffset() ) );

}
else
{
t.add( StringUtils.rightPad( left, INFO_PAD_SIZE - right.length(), "." ) + right );
t.add( StringUtils.rightPad( left, INFO_PAD_SIZE + getDisplayTerminalWidthOffset() - right.length(), "." ) + right );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,12 @@ public void execute()
{
// plugin version configured that require a Maven version higher than spec
upgradePlugins.put( upgradePluginKey,
pad( upgradePluginKey, INFO_PAD_SIZE, newer ) );
pad( upgradePluginKey, INFO_PAD_SIZE + getDisplayTerminalWidthOffset(), newer ) );
}
else
{
// plugin that can be upgraded
upgradePlugins.put( upgradePluginKey, pad( upgradePluginKey, INFO_PAD_SIZE,
upgradePlugins.put( upgradePluginKey, pad( upgradePluginKey, INFO_PAD_SIZE + getDisplayTerminalWidthOffset(),
effectiveVersion, " -> ", newer ) );
}
}
Expand Down Expand Up @@ -551,7 +551,7 @@ public void execute()
superPomDrivingMinVersion = true;
}

pluginLockdowns.add( pad( compactKey( groupId, artifactId ), WARN_PAD_SIZE,
pluginLockdowns.add( pad( compactKey( groupId, artifactId ), WARN_PAD_SIZE + getDisplayTerminalWidthOffset(),
superPomDrivingMinVersion ? FROM_SUPER_POM : "", newVersion ) );
}
else if ( artifactVersion != null )
Expand All @@ -565,7 +565,7 @@ else if ( artifactVersion != null )
if ( version != null && artifactVersion != null && newVersion != null && effectiveVersion != null
&& new DefaultArtifactVersion( effectiveVersion ).compareTo( new DefaultArtifactVersion( newVersion ) ) < 0 )
{
pluginUpdates.add( pad( compactKey( groupId, artifactId ), INFO_PAD_SIZE,
pluginUpdates.add( pad( compactKey( groupId, artifactId ), INFO_PAD_SIZE + getDisplayTerminalWidthOffset(),
effectiveVersion, " -> ", newVersion ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void execute()
buf.append( property.getName() );
buf.append( "} " );
final String newVersion = winner.toString();
int padding = INFO_PAD_SIZE - currentVersion.length() - newVersion.length() - 4;
int padding = INFO_PAD_SIZE - currentVersion.length() - newVersion.length() - 4 + getDisplayTerminalWidthOffset();
while ( buf.length() < padding )
{
buf.append( '.' );
Expand All @@ -165,7 +165,7 @@ public void execute()
buf.append( "${" );
buf.append( property.getName() );
buf.append( "} " );
int padding = INFO_PAD_SIZE - currentVersion.length();
int padding = INFO_PAD_SIZE - currentVersion.length() + getDisplayTerminalWidthOffset();
while ( buf.length() < padding )
{
buf.append( '.' );
Expand Down

0 comments on commit 8cfe5d0

Please sign in to comment.