o Refactored code

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@934861 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-04-16 13:18:48 +00:00
parent d8a1cb1b9a
commit 419a1d4627
7 changed files with 64 additions and 66 deletions

View File

@ -40,6 +40,7 @@
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.lifecycle.internal.ExecutionEventCatapult;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.building.ModelProblemUtils;
import org.apache.maven.model.building.ModelSource;
import org.apache.maven.model.building.UrlModelSource;
import org.apache.maven.project.DuplicateProjectException;
@ -414,7 +415,8 @@ private void collectProjects( List<MavenProject> projects, List<File> files, Mav
for ( ModelProblem problem : result.getProblems() )
{
logger.warn( problem.getMessage() + " @ " + problem.getLocation() );
logger.warn( problem.getMessage() + " @ "
+ ModelProblemUtils.formatLocation( problem, result.getProjectId() ) );
}
problems = true;

View File

@ -25,6 +25,7 @@
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.building.ModelProblemUtils;
import org.apache.maven.plugin.AbstractMojoExecutionException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@ -149,17 +150,7 @@ private ExceptionSummary handle( ModelProblem problem, String projectId )
{
String message = problem.getMessage();
String location = "";
if ( !problem.getModelId().equals( projectId ) )
{
location += problem.getModelId();
if ( StringUtils.isNotEmpty( problem.getSource() ) )
{
location += " (" + problem.getSource() + ")";
}
}
String location = ModelProblemUtils.formatLocation( problem, projectId );
if ( StringUtils.isNotEmpty( location ) )
{

View File

@ -25,6 +25,7 @@
import java.util.List;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.building.ModelProblemUtils;
/**
* @author Jason van Zyl
@ -134,7 +135,7 @@ private static String createMessage( List<ProjectBuildingResult> results )
writer.print( "] " );
writer.print( problem.getMessage() );
writer.print( " @ " );
writer.println( problem.getLocation() );
writer.println( ModelProblemUtils.formatLocation( problem, result.getProjectId() ) );
}
}
writer.close();

View File

@ -106,42 +106,6 @@ public String getModelId()
return modelId;
}
public String getLocation()
{
StringBuilder buffer = new StringBuilder( 256 );
buffer.append( getModelId() );
if ( getSource().length() > 0 )
{
if ( buffer.length() > 0 )
{
buffer.append( ", " );
}
buffer.append( getSource() );
}
if ( getLineNumber() > 0 )
{
if ( buffer.length() > 0 )
{
buffer.append( ", " );
}
buffer.append( "line " ).append( getLineNumber() );
}
if ( getColumnNumber() > 0 )
{
if ( buffer.length() > 0 )
{
buffer.append( ", " );
}
buffer.append( "column " ).append( getColumnNumber() );
}
return buffer.toString();
}
public Exception getException()
{
return exception;
@ -180,7 +144,7 @@ public String toString()
buffer.append( "[" ).append( getSeverity() ).append( "] " );
buffer.append( getMessage() );
buffer.append( " @ " ).append( getLocation() );
buffer.append( " @ " ).append( ModelProblemUtils.formatLocation( this, null ) );
return buffer.toString();
}

View File

@ -119,7 +119,7 @@ private static String toMessage( String modelId, List<ModelProblem> problems )
writer.print( "] " );
writer.print( problem.getMessage() );
writer.print( " @ " );
writer.println( problem.getLocation() );
writer.println( ModelProblemUtils.formatLocation( problem, modelId ) );
}
return buffer.toString();

View File

@ -78,15 +78,6 @@ enum Severity
*/
String getModelId();
/**
* Gets the location of the problem. The location is a user-friendly combination of the values from
* {@link #getModelId()}, {@link #getSource()}, {@link #getLineNumber()} and {@link #getColumnNumber()}. The exact
* syntax of the returned value is undefined.
*
* @return The location of the problem, never {@code null}.
*/
String getLocation();
/**
* Gets the exception that caused this problem (if any).
*

View File

@ -24,11 +24,11 @@
import org.apache.maven.model.Model;
/**
* Assists in the creation of model problems.
* Assists in the handling of model problems.
*
* @author Benjamin Bentmann
*/
class ModelProblemUtils
public class ModelProblemUtils
{
/**
@ -37,7 +37,7 @@ class ModelProblemUtils
* @param model The model to create a source hint for, may be {@code null}.
* @return The user-friendly source hint, never {@code null}.
*/
public static String toSourceHint( Model model )
static String toSourceHint( Model model )
{
if ( model == null )
{
@ -57,7 +57,7 @@ public static String toSourceHint( Model model )
return buffer.toString();
}
public static String toPath( Model model )
static String toPath( Model model )
{
String path = "";
@ -74,7 +74,7 @@ public static String toPath( Model model )
return path;
}
public static String toId( Model model )
static String toId( Model model )
{
if ( model == null )
{
@ -106,7 +106,7 @@ public static String toId( Model model )
* @param version The version, may be {@code null}.
* @return The user-friendly artifact id, never {@code null}.
*/
public static String toId( String groupId, String artifactId, String version )
static String toId( String groupId, String artifactId, String version )
{
StringBuilder buffer = new StringBuilder( 96 );
@ -119,4 +119,53 @@ public static String toId( String groupId, String artifactId, String version )
return buffer.toString();
}
/**
* Creates a string with all location details for the specified model problem. If the project identifier is
* provided, the generated location will omit the model id and source information and only give line/column
* information for problems originating directly from this POM.
*
* @param problem The problem whose location should be formatted, must not be {@code null}.
* @param projectId The {@code <groupId>:<artifactId>:<version>} of the corresponding project, may be {@code null}
* to force output of model id and source.
* @return The formatted problem location or an empty string if unknown, never {@code null}.
*/
public static String formatLocation( ModelProblem problem, String projectId )
{
StringBuilder buffer = new StringBuilder( 256 );
if ( !problem.getModelId().equals( projectId ) )
{
buffer.append( problem.getModelId() );
if ( problem.getSource().length() > 0 )
{
if ( buffer.length() > 0 )
{
buffer.append( ", " );
}
buffer.append( problem.getSource() );
}
}
if ( problem.getLineNumber() > 0 )
{
if ( buffer.length() > 0 )
{
buffer.append( ", " );
}
buffer.append( "line " ).append( problem.getLineNumber() );
}
if ( problem.getColumnNumber() > 0 )
{
if ( buffer.length() > 0 )
{
buffer.append( ", " );
}
buffer.append( "column " ).append( problem.getColumnNumber() );
}
return buffer.toString();
}
}