Use system line separator wherever possible

This closes #424
This commit is contained in:
Michael Osipov 2020-12-31 00:21:42 +01:00
parent 2caed6218a
commit 31ad2ff43a
16 changed files with 131 additions and 111 deletions

View File

@ -32,6 +32,8 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
public class MultipleArtifactsNotFoundException
extends ArtifactResolutionException
{
private static final String LS = System.lineSeparator();
private final List<Artifact> resolvedArtifacts;
private final List<Artifact> missingArtifacts;
@ -86,8 +88,8 @@ public class MultipleArtifactsNotFoundException
{
StringBuilder buffer = new StringBuilder( 256 );
buffer.append( "Missing:\n" );
buffer.append( "----------\n" );
buffer.append( "Missing:" ).append( LS );
buffer.append( "----------" ).append( LS );
int counter = 0;
@ -100,7 +102,7 @@ public class MultipleArtifactsNotFoundException
artifact.getDownloadUrl(), artifact.getDependencyTrail() ) );
}
buffer.append( "----------\n" );
buffer.append( "----------" ).append( LS );
int size = artifacts.size();
@ -115,7 +117,7 @@ public class MultipleArtifactsNotFoundException
buffer.append( " is" );
}
buffer.append( " missing.\n\nfor artifact: " );
buffer.append( " missing." ).append( LS ).append( LS ).append( "for artifact: " );
return buffer.toString();
}

View File

@ -37,6 +37,8 @@ import org.apache.maven.repository.Proxy;
public class MavenArtifactRepository
implements ArtifactRepository
{
private static final String LS = System.lineSeparator();
private String id;
private String url;
@ -139,25 +141,25 @@ public class MavenArtifactRepository
{
StringBuilder sb = new StringBuilder( 256 );
sb.append( " id: " ).append( getId() ).append( '\n' );
sb.append( " url: " ).append( getUrl() ).append( '\n' );
sb.append( " layout: " ).append( layout != null ? layout : "none" ).append( '\n' );
sb.append( " id: " ).append( getId() ).append( LS );
sb.append( " url: " ).append( getUrl() ).append( LS );
sb.append( " layout: " ).append( layout != null ? layout : "none" );
if ( proxy != null )
{
sb.append( " proxy: " ).append( proxy.getHost() ).append( ':' ).append( proxy.getPort() ).append( '\n' );
sb.append( LS ).append( " proxy: " ).append( proxy.getHost() ).append( ':' ).append( proxy.getPort() );
}
if ( snapshots != null )
{
sb.append( "snapshots: [enabled => " ).append( snapshots.isEnabled() );
sb.append( ", update => " ).append( snapshots.getUpdatePolicy() ).append( "]\n" );
sb.append( LS ).append( "snapshots: [enabled => " ).append( snapshots.isEnabled() );
sb.append( ", update => " ).append( snapshots.getUpdatePolicy() ).append( ']' );
}
if ( releases != null )
{
sb.append( " releases: [enabled => " ).append( releases.isEnabled() );
sb.append( ", update => " ).append( releases.getUpdatePolicy() ).append( "]\n" );
sb.append( LS ).append( "releases: [enabled => " ).append( releases.isEnabled() );
sb.append( ", update => " ).append( releases.getUpdatePolicy() ).append( ']' );
}
return sb.toString();

View File

@ -42,6 +42,8 @@ import java.io.Writer;
public abstract class AbstractRepositoryMetadata
implements RepositoryMetadata
{
private static final String LS = System.lineSeparator();
private Metadata metadata;
protected AbstractRepositoryMetadata( Metadata metadata )
@ -197,10 +199,10 @@ public abstract class AbstractRepositoryMetadata
{
StringBuilder buffer = new StringBuilder( 256 );
buffer.append( "\nRepository Metadata\n--------------------------" );
buffer.append( "\nGroupId: " ).append( getGroupId() );
buffer.append( "\nArtifactId: " ).append( getArtifactId() );
buffer.append( "\nMetadata Type: " ).append( getClass().getName() );
buffer.append( LS ).append( "Repository Metadata" ).append( LS ).append( "--------------------------" );
buffer.append( LS ).append( "GroupId: " ).append( getGroupId() );
buffer.append( LS ).append( "ArtifactId: " ).append( getArtifactId() );
buffer.append( LS ).append( "Metadata Type: " ).append( getClass().getName() );
return buffer.toString();
}

View File

@ -42,6 +42,7 @@ import org.apache.maven.settings.Server;
public class ArtifactResolutionRequest
implements RepositoryRequest
{
private static final String LS = System.lineSeparator();
private Artifact artifact;
@ -234,11 +235,11 @@ public class ArtifactResolutionRequest
public String toString()
{
StringBuilder sb = new StringBuilder()
.append( "REQUEST: " ).append( "\n" )
.append( "artifact: " ).append( artifact ).append( "\n" )
.append( artifactDependencies ).append( "\n" )
.append( "localRepository: " ).append( localRepository ).append( "\n" )
.append( "remoteRepositories: " ).append( remoteRepositories ).append( "\n" );
.append( "REQUEST: " ).append( LS )
.append( "artifact: " ).append( artifact ).append( LS )
.append( artifactDependencies ).append( LS )
.append( "localRepository: " ).append( localRepository ).append( LS )
.append( "remoteRepositories: " ).append( remoteRepositories );
return sb.toString();
}

View File

@ -47,6 +47,8 @@ import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
*/
public class ArtifactResolutionResult
{
private static final String LS = System.lineSeparator();
private Artifact originatingArtifact;
private List<Artifact> missingArtifacts;
@ -359,14 +361,14 @@ public class ArtifactResolutionResult
if ( artifacts != null )
{
int i = 1;
sb.append( "---------\n" );
sb.append( artifacts.size() ).append( '\n' );
sb.append( "---------" ).append( LS );
sb.append( artifacts.size() ).append( LS );
for ( Artifact a : artifacts )
{
sb.append( i ).append( ' ' ).append( a ).append( '\n' );
sb.append( i ).append( ' ' ).append( a ).append( LS );
i++;
}
sb.append( "---------\n" );
sb.append( "---------" );
}
return sb.toString();

View File

@ -148,8 +148,8 @@ public class DefaultExceptionHandler
return null;
}
String message =
"\nThe project " + result.getProjectId() + " (" + result.getPomFile() + ") has "
String message = System.lineSeparator()
+ "The project " + result.getProjectId() + " (" + result.getPomFile() + ") has "
+ children.size() + " error" + ( children.size() == 1 ? "" : "s" );
return new ExceptionSummary( null, message, null, children );
@ -290,7 +290,7 @@ public class DefaultExceptionHandler
}
else if ( !exceptionMessage.contains( longMessage ) )
{
exceptionMessage = join( exceptionMessage, '\n' + longMessage );
exceptionMessage = join( exceptionMessage, System.lineSeparator() + longMessage );
}
}
}

View File

@ -36,6 +36,8 @@ public class PluginParameterException
extends PluginConfigurationException
{
private static final String LS = System.lineSeparator();
private final List<Parameter> parameters;
private final MojoDescriptor mojo;
@ -105,50 +107,53 @@ public class PluginParameterException
messageBuffer.append( "Inside the definition for plugin \'" );
messageBuffer.append( mojo.getPluginDescriptor().getArtifactId() );
messageBuffer.append( "\', specify the following:\n\n<configuration>\n ...\n" );
messageBuffer.append( "\', specify the following:" ).append( LS ).append( LS );
messageBuffer.append( "<configuration>" ).append( LS ).append( " ..." ).append( LS );
messageBuffer.append( " <" ).append( param.getName() ).append( '>' );
if ( isArray || isCollection )
{
messageBuffer.append( '\n' );
messageBuffer.append( LS );
messageBuffer.append( " <item>" );
}
else if ( isProperties )
{
messageBuffer.append( '\n' );
messageBuffer.append( " <property>\n" );
messageBuffer.append( " <name>KEY</name>\n" );
messageBuffer.append( LS );
messageBuffer.append( " <property>" ).append( LS );
messageBuffer.append( " <name>KEY</name>" ).append( LS );
messageBuffer.append( " <value>" );
}
else if ( isMap )
{
messageBuffer.append( '\n' );
messageBuffer.append( LS );
messageBuffer.append( " <KEY>" );
}
messageBuffer.append( "VALUE" );
if ( isArray || isCollection )
{
messageBuffer.append( "</item>\n" );
messageBuffer.append( "</item>" ).append( LS );
messageBuffer.append( " " );
}
else if ( isProperties )
{
messageBuffer.append( "</value>\n" );
messageBuffer.append( " </property>\n" );
messageBuffer.append( "</value>" ).append( LS );
messageBuffer.append( " </property>" ).append( LS );
messageBuffer.append( " " );
}
else if ( isMap )
{
messageBuffer.append( "</KEY>\n" );
messageBuffer.append( "</KEY>" ).append( LS );
messageBuffer.append( " " );
}
messageBuffer.append( "</" ).append( param.getName() ).append( ">\n" );
messageBuffer.append( "</" ).append( param.getName() ).append( ">" ).append( LS );
messageBuffer.append( "</configuration>" );
String alias = param.getAlias();
if ( StringUtils.isNotEmpty( alias ) && !alias.equals( param.getName() ) )
{
messageBuffer.append( "\n\n-OR-\n\n<configuration>\n ...\n <" ).append( alias ).append(
">VALUE</" ).append( alias ).append( ">\n</configuration>\n" );
messageBuffer.append( LS ).append( LS ).append( "-OR-" ).append( LS ).append( LS );
messageBuffer.append( "<configuration>" ).append( LS ).append( " ..." ).append( LS );
messageBuffer.append( " <" ).append( alias ).append(
">VALUE</" ).append( alias ).append( ">" ).append( LS ).append( "</configuration>" ).append( LS );
}
}
@ -160,7 +165,7 @@ public class PluginParameterException
{
if ( param.isEditable() )
{
messageBuffer.append( "\n\n-OR-\n\n" );
messageBuffer.append( LS ).append( LS ).append( "-OR-" ).append( LS ).append( LS );
}
//addParameterUsageInfo( expression, messageBuffer );
@ -176,18 +181,18 @@ public class PluginParameterException
messageBuffer.append( "One or more required plugin parameters are invalid/missing for \'" )
.append( mojo.getPluginDescriptor().getGoalPrefix() ).append( ':' ).append( mojo.getGoal() )
.append( "\'\n" );
.append( "\'" ).append( LS );
int idx = 0;
for ( Iterator<Parameter> it = params.iterator(); it.hasNext(); idx++ )
{
Parameter param = it.next();
messageBuffer.append( "\n[" ).append( idx ).append( "] " );
messageBuffer.append( LS ).append( "[" ).append( idx ).append( "] " );
decomposeParameterIntoUserInstructions( mojo, param, messageBuffer );
messageBuffer.append( '\n' );
messageBuffer.append( LS );
}
return messageBuffer.toString();

View File

@ -291,7 +291,7 @@ public class ActiveProjectArtifact
/** {@inheritDoc} */
public String toString()
{
return "active project artifact:\n\tartifact = " + artifact + ";\n\tproject: " + project;
return "active project artifact[artifact: " + artifact + ", project: " + project + "]";
}
/** {@inheritDoc} */

View File

@ -688,23 +688,23 @@ public class MavenMetadataSource
}
String message =
"\n This artifact has been relocated to " + artifact.getGroupId() + ":"
+ artifact.getArtifactId() + ":" + artifact.getVersion() + ".\n";
" this artifact has been relocated to " + artifact.getGroupId() + ":"
+ artifact.getArtifactId() + ":" + artifact.getVersion() + ".";
if ( relocation.getMessage() != null )
{
message += " " + relocation.getMessage() + "\n";
message += " " + relocation.getMessage();
}
if ( artifact.getDependencyTrail() != null && artifact.getDependencyTrail().size() == 1 )
{
logger.warn( "While downloading " + pomArtifact.getGroupId() + ":"
+ pomArtifact.getArtifactId() + ":" + pomArtifact.getVersion() + message + "\n" );
+ pomArtifact.getArtifactId() + ":" + pomArtifact.getVersion() + message );
}
else
{
logger.debug( "While downloading " + pomArtifact.getGroupId() + ":"
+ pomArtifact.getArtifactId() + ":" + pomArtifact.getVersion() + message + "\n" );
+ pomArtifact.getArtifactId() + ":" + pomArtifact.getVersion() + message );
}
}
else

View File

@ -29,6 +29,8 @@ import org.apache.maven.artifact.Artifact;
public abstract class AbstractArtifactMetadata
implements ArtifactMetadata
{
private static final String LS = System.lineSeparator();
protected Artifact artifact;
protected AbstractArtifactMetadata( Artifact artifact )
@ -55,10 +57,10 @@ public abstract class AbstractArtifactMetadata
{
StringBuilder buffer = new StringBuilder( 256 );
buffer.append( "\nArtifact Metadata\n--------------------------" );
buffer.append( "\nGroupId: " ).append( getGroupId() );
buffer.append( "\nArtifactId: " ).append( getArtifactId() );
buffer.append( "\nMetadata Type: " ).append( getClass().getName() );
buffer.append( LS ).append( "Artifact Metadata" ).append( LS ).append( "--------------------------" );
buffer.append( LS ).append( "GroupId: " ).append( getGroupId() );
buffer.append( LS ).append( "ArtifactId: " ).append( getArtifactId() );
buffer.append( LS ).append( "Metadata Type: " ).append( getClass().getName() );
return buffer.toString();
}

View File

@ -43,8 +43,8 @@ public class SettingsConfigurationException
public SettingsConfigurationException( String message, Throwable cause, int lineNumber, int columnNumber )
{
super( message + ( lineNumber > 0 ? "\n Line: " + lineNumber : "" )
+ ( columnNumber > 0 ? "\n Column: " + columnNumber : "" ), cause );
super( message + ( lineNumber > 0 ? System.lineSeparator() + " Line: " + lineNumber : "" )
+ ( columnNumber > 0 ? System.lineSeparator() + " Column: " + columnNumber : "" ), cause );
this.lineNumber = lineNumber;
this.columnNumber = columnNumber;
}

View File

@ -37,6 +37,8 @@ public class PluginParameterExceptionTest
extends TestCase
{
private final String LS = System.lineSeparator();
public void testMissingRequiredStringArrayTypeParameter()
{
MojoDescriptor mojoDescriptor = new MojoDescriptor();
@ -55,16 +57,16 @@ public class PluginParameterExceptionTest
PluginParameterException exception =
new PluginParameterException( mojoDescriptor, Collections.singletonList( parameter ) );
assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'\n" +
"\n" +
"[0] Inside the definition for plugin 'artifactId', specify the following:\n" +
"\n" +
"<configuration>\n" +
" ...\n" +
" <toAddresses>\n" +
" <item>VALUE</item>\n" +
" </toAddresses>\n" +
"</configuration>.\n", exception.buildDiagnosticMessage() );
assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'" +
LS + LS +
"[0] Inside the definition for plugin 'artifactId', specify the following:" +
LS + LS +
"<configuration>" + LS +
" ..." + LS +
" <toAddresses>" + LS +
" <item>VALUE</item>" + LS +
" </toAddresses>" + LS +
"</configuration>." + LS, exception.buildDiagnosticMessage() );
}
public void testMissingRequiredCollectionTypeParameter()
@ -85,16 +87,16 @@ public class PluginParameterExceptionTest
PluginParameterException exception =
new PluginParameterException( mojoDescriptor, Collections.singletonList( parameter ) );
assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'\n" +
"\n" +
"[0] Inside the definition for plugin 'artifactId', specify the following:\n" +
"\n" +
"<configuration>\n" +
" ...\n" +
" <toAddresses>\n" +
" <item>VALUE</item>\n" +
" </toAddresses>\n" +
"</configuration>.\n", exception.buildDiagnosticMessage() );
assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'" +
LS + LS +
"[0] Inside the definition for plugin 'artifactId', specify the following:" +
LS + LS +
"<configuration>" + LS +
" ..." + LS +
" <toAddresses>" + LS +
" <item>VALUE</item>" + LS +
" </toAddresses>" + LS +
"</configuration>." + LS, exception.buildDiagnosticMessage() );
}
public void testMissingRequiredMapTypeParameter()
@ -115,16 +117,16 @@ public class PluginParameterExceptionTest
PluginParameterException exception =
new PluginParameterException( mojoDescriptor, Collections.singletonList( parameter ) );
assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'\n" +
"\n" +
"[0] Inside the definition for plugin 'artifactId', specify the following:\n" +
"\n" +
"<configuration>\n" +
" ...\n" +
" <toAddresses>\n" +
" <KEY>VALUE</KEY>\n" +
" </toAddresses>\n" +
"</configuration>.\n", exception.buildDiagnosticMessage() );
assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'" +
LS + LS +
"[0] Inside the definition for plugin 'artifactId', specify the following:" +
LS + LS +
"<configuration>" + LS +
" ..." + LS +
" <toAddresses>" + LS +
" <KEY>VALUE</KEY>" + LS +
" </toAddresses>" + LS +
"</configuration>." + LS, exception.buildDiagnosticMessage() );
}
public void testMissingRequiredPropertiesTypeParameter()
@ -145,20 +147,19 @@ public class PluginParameterExceptionTest
PluginParameterException exception =
new PluginParameterException( mojoDescriptor, Collections.singletonList( parameter ) );
assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'\n" +
"\n" +
"[0] Inside the definition for plugin 'artifactId', specify the following:\n" +
"\n" +
"<configuration>\n" +
" ...\n" +
" <toAddresses>\n" +
" <property>\n" +
" <name>KEY</name>\n" +
" <value>VALUE</value>\n" +
" </property>\n" +
" </toAddresses>\n" +
"</configuration>.\n", exception.buildDiagnosticMessage() );
assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'" +
LS + LS +
"[0] Inside the definition for plugin 'artifactId', specify the following:" +
LS + LS +
"<configuration>" + LS +
" ..." + LS +
" <toAddresses>" + LS +
" <property>" + LS +
" <name>KEY</name>" + LS +
" <value>VALUE</value>" + LS +
" </property>" + LS +
" </toAddresses>" + LS +
"</configuration>." + LS, exception.buildDiagnosticMessage() );
}
}

View File

@ -176,8 +176,10 @@ public class CLIManager
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( pw, HelpFormatter.DEFAULT_WIDTH, "mvn [options] [<goal(s)>] [<phase(s)>]", "\nOptions:",
options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, "\n", false );
formatter.printHelp( pw, HelpFormatter.DEFAULT_WIDTH, "mvn [options] [<goal(s)>] [<phase(s)>]",
System.lineSeparator() + "Options:", options,
HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD,
System.lineSeparator(), false );
pw.flush();
}

View File

@ -1231,7 +1231,7 @@ public class MavenCli
// There are too many ConfigurationProcessors so we don't know which one to run so report the error.
//
StringBuilder sb = new StringBuilder(
String.format( "\nThere can only be one user supplied ConfigurationProcessor, there are %s:\n\n",
String.format( "%nThere can only be one user supplied ConfigurationProcessor, there are %s:%n%n",
userSuppliedConfigurationProcessorCount ) );
for ( Entry<String, ConfigurationProcessor> entry : configurationProcessors.entrySet() )
{
@ -1239,10 +1239,9 @@ public class MavenCli
if ( !hint.equals( SettingsXmlConfigurationProcessor.HINT ) )
{
ConfigurationProcessor configurationProcessor = entry.getValue();
sb.append( String.format( "%s\n", configurationProcessor.getClass().getName() ) );
sb.append( String.format( "%s%n", configurationProcessor.getClass().getName() ) );
}
}
sb.append( "\n" );
throw new Exception( sb.toString() );
}
}

View File

@ -30,8 +30,8 @@ public class DuplicateMojoDescriptorException
String newImplementation )
{
super( "Goal: " + goal + " already exists in the plugin descriptor for prefix: " + goalPrefix
+ "\nExisting implementation is: " + existingImplementation
+ "\nConflicting implementation is: " + newImplementation );
+ System.lineSeparator() + "Existing implementation is: " + existingImplementation
+ System.lineSeparator() + "Conflicting implementation is: " + newImplementation );
}
}

View File

@ -123,7 +123,8 @@ public class SystemStreamLog
error.printStackTrace( pWriter );
System.err.println( "[error] " + content.toString() + "\n\n" + sWriter.toString() );
System.err.println( "[error] " + content.toString()
+ System.lineSeparator() + System.lineSeparator() + sWriter.toString() );
}
/**
@ -194,6 +195,7 @@ public class SystemStreamLog
error.printStackTrace( pWriter );
System.out.println( "[" + prefix + "] " + content.toString() + "\n\n" + sWriter.toString() );
System.out.println( "[" + prefix + "] " + content.toString()
+ System.lineSeparator() + System.lineSeparator() + sWriter.toString() );
}
}