mirror of https://github.com/apache/maven.git
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:
parent
d8a1cb1b9a
commit
419a1d4627
|
@ -40,6 +40,7 @@ import org.apache.maven.execution.ProjectDependencyGraph;
|
|||
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 @@ public class DefaultMaven
|
|||
|
||||
for ( ModelProblem problem : result.getProblems() )
|
||||
{
|
||||
logger.warn( problem.getMessage() + " @ " + problem.getLocation() );
|
||||
logger.warn( problem.getMessage() + " @ "
|
||||
+ ModelProblemUtils.formatLocation( problem, result.getProjectId() ) );
|
||||
}
|
||||
|
||||
problems = true;
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.List;
|
|||
|
||||
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 @@ public class DefaultExceptionHandler
|
|||
{
|
||||
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 ) )
|
||||
{
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.io.StringWriter;
|
|||
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 @@ public class ProjectBuildingException
|
|||
writer.print( "] " );
|
||||
writer.print( problem.getMessage() );
|
||||
writer.print( " @ " );
|
||||
writer.println( problem.getLocation() );
|
||||
writer.println( ModelProblemUtils.formatLocation( problem, result.getProjectId() ) );
|
||||
}
|
||||
}
|
||||
writer.close();
|
||||
|
|
|
@ -106,42 +106,6 @@ public class DefaultModelProblem
|
|||
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 class DefaultModelProblem
|
|||
|
||||
buffer.append( "[" ).append( getSeverity() ).append( "] " );
|
||||
buffer.append( getMessage() );
|
||||
buffer.append( " @ " ).append( getLocation() );
|
||||
buffer.append( " @ " ).append( ModelProblemUtils.formatLocation( this, null ) );
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ public class ModelBuildingException
|
|||
writer.print( "] " );
|
||||
writer.print( problem.getMessage() );
|
||||
writer.print( " @ " );
|
||||
writer.println( problem.getLocation() );
|
||||
writer.println( ModelProblemUtils.formatLocation( problem, modelId ) );
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
|
|
|
@ -78,15 +78,6 @@ public interface ModelProblem
|
|||
*/
|
||||
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).
|
||||
*
|
||||
|
|
|
@ -24,11 +24,11 @@ import java.io.File;
|
|||
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 @@ class ModelProblemUtils
|
|||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static String toPath( Model model )
|
||||
static String toPath( Model model )
|
||||
{
|
||||
String path = "";
|
||||
|
||||
|
@ -74,7 +74,7 @@ class ModelProblemUtils
|
|||
return path;
|
||||
}
|
||||
|
||||
public static String toId( Model model )
|
||||
static String toId( Model model )
|
||||
{
|
||||
if ( model == null )
|
||||
{
|
||||
|
@ -106,7 +106,7 @@ class ModelProblemUtils
|
|||
* @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 @@ class ModelProblemUtils
|
|||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue