mirror of https://github.com/apache/maven.git
o Refactored code
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@804894 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9d381f5aeb
commit
eb8b7072a8
|
@ -35,6 +35,7 @@ import org.apache.maven.model.Build;
|
|||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.model.building.DefaultModelBuildingRequest;
|
||||
import org.apache.maven.model.building.DefaultModelProblem;
|
||||
import org.apache.maven.model.building.FileModelSource;
|
||||
import org.apache.maven.model.building.ModelBuilder;
|
||||
import org.apache.maven.model.building.ModelBuildingException;
|
||||
|
@ -382,10 +383,9 @@ public class DefaultProjectBuilder
|
|||
|
||||
if ( !moduleFile.isFile() )
|
||||
{
|
||||
String source = toSourceHint( model );
|
||||
ModelProblem problem =
|
||||
new ModelProblem( "Child module " + moduleFile + " of " + source + " does not exist",
|
||||
ModelProblem.Severity.ERROR, source );
|
||||
new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile
|
||||
+ " does not exist", ModelProblem.Severity.ERROR, model );
|
||||
result.getProblems().add( problem );
|
||||
|
||||
errors = true;
|
||||
|
@ -495,23 +495,4 @@ public class DefaultProjectBuilder
|
|||
return project;
|
||||
}
|
||||
|
||||
private String toSourceHint( Model model )
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder( 192 );
|
||||
|
||||
buffer.append( model.getGroupId() );
|
||||
buffer.append( ':' );
|
||||
buffer.append( model.getArtifactId() );
|
||||
buffer.append( ':' );
|
||||
buffer.append( model.getVersion() );
|
||||
|
||||
File pomFile = model.getPomFile();
|
||||
if ( pomFile != null )
|
||||
{
|
||||
buffer.append( " (" ).append( pomFile ).append( ")" );
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -276,14 +276,14 @@ public class DefaultModelBuilder
|
|||
}
|
||||
catch ( ModelParseException e )
|
||||
{
|
||||
problems.add( new ModelProblem( "Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage(),
|
||||
ModelProblem.Severity.FATAL, modelSource.getLocation(), e ) );
|
||||
problems.add( new DefaultModelProblem( "Non-parseable POM " + modelSource.getLocation() + ": "
|
||||
+ e.getMessage(), ModelProblem.Severity.FATAL, modelSource.getLocation(), e ) );
|
||||
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
problems.add( new ModelProblem( "Non-readable POM " + modelSource.getLocation() + ": " + e.getMessage(),
|
||||
ModelProblem.Severity.FATAL, modelSource.getLocation(), e ) );
|
||||
problems.add( new DefaultModelProblem( "Non-readable POM " + modelSource.getLocation() + ": "
|
||||
+ e.getMessage(), ModelProblem.Severity.FATAL, modelSource.getLocation(), e ) );
|
||||
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
package org.apache.maven.model.building;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
|
||||
/**
|
||||
* Describes a problem that was encountered during model building. A problem can either be an exception that was thrown
|
||||
* or a simple string message. In addition, a problem carries a hint about its source, e.g. the POM file that exhibits
|
||||
* the problem.
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
*/
|
||||
public class DefaultModelProblem
|
||||
implements ModelProblem
|
||||
{
|
||||
|
||||
private final String source;
|
||||
|
||||
private final String message;
|
||||
|
||||
private final Exception exception;
|
||||
|
||||
private final Severity severity;
|
||||
|
||||
/**
|
||||
* Creates a new problem with the specified message.
|
||||
*
|
||||
* @param message The message describing the problem, may be {@code null}.
|
||||
* @param severity The severity level of the problem, may be {@code null} to default to {@link Severity#ERROR}.
|
||||
* @param source The source of the problem, may be {@code null}.
|
||||
*/
|
||||
public DefaultModelProblem( String message, Severity severity, Model source )
|
||||
{
|
||||
this( message, severity, ModelProblemUtils.toSourceHint( source ), null );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new problem with the specified message.
|
||||
*
|
||||
* @param message The message describing the problem, may be {@code null}.
|
||||
* @param severity The severity level of the problem, may be {@code null} to default to {@link Severity#ERROR}.
|
||||
* @param source A hint about the source of the problem, may be {@code null}.
|
||||
*/
|
||||
public DefaultModelProblem( String message, Severity severity, String source )
|
||||
{
|
||||
this( message, severity, source, null );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new problem with the specified message and exception.
|
||||
*
|
||||
* @param message The message describing the problem, may be {@code null}.
|
||||
* @param severity The severity level of the problem, may be {@code null} to default to {@link Severity#ERROR}.
|
||||
* @param source A hint about the source of the problem, may be {@code null}.
|
||||
* @param exception The exception that caused this problem, may be {@code null}.
|
||||
*/
|
||||
public DefaultModelProblem( String message, Severity severity, String source, Exception exception )
|
||||
{
|
||||
this.message = message;
|
||||
this.severity = ( severity != null ) ? severity : Severity.ERROR;
|
||||
this.source = ( source != null ) ? source : "";
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public String getSource()
|
||||
{
|
||||
return source;
|
||||
}
|
||||
|
||||
public Exception getException()
|
||||
{
|
||||
return exception;
|
||||
}
|
||||
|
||||
public String getMessage()
|
||||
{
|
||||
String msg;
|
||||
|
||||
if ( message != null && message.length() > 0 )
|
||||
{
|
||||
msg = message;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = exception.getMessage();
|
||||
|
||||
if ( msg == null )
|
||||
{
|
||||
msg = "";
|
||||
}
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
public Severity getSeverity()
|
||||
{
|
||||
return severity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder( 128 );
|
||||
|
||||
buffer.append( "[" ).append( getSeverity() ).append( "] " );
|
||||
buffer.append( getSource() ).append( ": " ).append( getMessage() );
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -98,32 +98,32 @@ class DefaultModelProblemCollector
|
|||
|
||||
public void addFatalError( String message )
|
||||
{
|
||||
problems.add( new ModelProblem( message, ModelProblem.Severity.FATAL, getSourceHint() ) );
|
||||
problems.add( new DefaultModelProblem( message, ModelProblem.Severity.FATAL, getSourceHint() ) );
|
||||
}
|
||||
|
||||
public void addFatalError( String message, Exception cause )
|
||||
{
|
||||
problems.add( new ModelProblem( message, ModelProblem.Severity.FATAL, getSourceHint(), cause ) );
|
||||
problems.add( new DefaultModelProblem( message, ModelProblem.Severity.FATAL, getSourceHint(), cause ) );
|
||||
}
|
||||
|
||||
public void addError( String message )
|
||||
{
|
||||
problems.add( new ModelProblem( message, ModelProblem.Severity.ERROR, getSourceHint() ) );
|
||||
problems.add( new DefaultModelProblem( message, ModelProblem.Severity.ERROR, getSourceHint() ) );
|
||||
}
|
||||
|
||||
public void addError( String message, Exception cause )
|
||||
{
|
||||
problems.add( new ModelProblem( message, ModelProblem.Severity.ERROR, getSourceHint(), cause ) );
|
||||
problems.add( new DefaultModelProblem( message, ModelProblem.Severity.ERROR, getSourceHint(), cause ) );
|
||||
}
|
||||
|
||||
public void addWarning( String message )
|
||||
{
|
||||
problems.add( new ModelProblem( message, ModelProblem.Severity.WARNING, getSourceHint() ) );
|
||||
problems.add( new DefaultModelProblem( message, ModelProblem.Severity.WARNING, getSourceHint() ) );
|
||||
}
|
||||
|
||||
public void addWarning( String message, Exception cause )
|
||||
{
|
||||
problems.add( new ModelProblem( message, ModelProblem.Severity.WARNING, getSourceHint(), cause ) );
|
||||
problems.add( new DefaultModelProblem( message, ModelProblem.Severity.WARNING, getSourceHint(), cause ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ package org.apache.maven.model.building;
|
|||
*
|
||||
* @author Benjamin Bentmann
|
||||
*/
|
||||
public class ModelProblem
|
||||
public interface ModelProblem
|
||||
{
|
||||
|
||||
/**
|
||||
|
@ -41,42 +41,6 @@ public class ModelProblem
|
|||
|
||||
}
|
||||
|
||||
private final String source;
|
||||
|
||||
private final String message;
|
||||
|
||||
private final Exception exception;
|
||||
|
||||
private final Severity severity;
|
||||
|
||||
/**
|
||||
* Creates a new problem with the specified message.
|
||||
*
|
||||
* @param message The message describing the problem, may be {@code null}.
|
||||
* @param severity The severity level of the problem, may be {@code null} to default to {@link Severity#ERROR}.
|
||||
* @param source A hint about the source of the problem, may be {@code null}.
|
||||
*/
|
||||
public ModelProblem( String message, Severity severity, String source )
|
||||
{
|
||||
this( message, severity, source, null );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new problem with the specified message and exception.
|
||||
*
|
||||
* @param message The message describing the problem, may be {@code null}.
|
||||
* @param severity The severity level of the problem, may be {@code null} to default to {@link Severity#ERROR}.
|
||||
* @param source A hint about the source of the problem, may be {@code null}.
|
||||
* @param exception The exception that caused this problem, may be {@code null}.
|
||||
*/
|
||||
public ModelProblem( String message, Severity severity, String source, Exception exception )
|
||||
{
|
||||
this.message = message;
|
||||
this.severity = ( severity != null ) ? severity : Severity.ERROR;
|
||||
this.source = ( source != null ) ? source : "";
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the hint about the source of the problem. While the syntax of this hint is unspecified and depends on the
|
||||
* creator of the problem, the general expectation is that the hint provides sufficient information to the user to
|
||||
|
@ -84,66 +48,27 @@ public class ModelProblem
|
|||
*
|
||||
* @return The hint about the source of the problem, never {@code null}.
|
||||
*/
|
||||
public String getSource()
|
||||
{
|
||||
return source;
|
||||
}
|
||||
public String getSource();
|
||||
|
||||
/**
|
||||
* Gets the exception that caused this problem (if any).
|
||||
*
|
||||
* @return The exception that caused this problem or {@code null} if not applicable.
|
||||
*/
|
||||
public Exception getException()
|
||||
{
|
||||
return exception;
|
||||
}
|
||||
public Exception getException();
|
||||
|
||||
/**
|
||||
* Gets the message that describes this problem.
|
||||
*
|
||||
* @return The message describing this problem, never {@code null}.
|
||||
*/
|
||||
public String getMessage()
|
||||
{
|
||||
String msg;
|
||||
|
||||
if ( message != null && message.length() > 0 )
|
||||
{
|
||||
msg = message;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = exception.getMessage();
|
||||
|
||||
if ( msg == null )
|
||||
{
|
||||
msg = "";
|
||||
}
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
public String getMessage();
|
||||
|
||||
/**
|
||||
* Gets the severity level of this problem.
|
||||
*
|
||||
* @return The severity level of this problem, never {@code null}.
|
||||
*/
|
||||
public Severity getSeverity()
|
||||
{
|
||||
return severity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder( 128 );
|
||||
|
||||
buffer.append( "[" ).append( getSeverity() ).append( "] " );
|
||||
buffer.append( getSource() ).append( ": " ).append( getMessage() );
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
public Severity getSeverity();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue