mirror of https://github.com/apache/maven.git
[MNG-2739] Adding validation logic to DefaultMavenTools and ProjectUtils, to make sure repositories have id and url before constructing an ArtifactRepository instance...this code is used ahead of normal model validation, so it needs to be included here. Also, introducing a new exception to handle the errors when these elements are missing.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@659680 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ca2bb6a32f
commit
e26974da98
|
@ -2574,6 +2574,7 @@
|
|||
<field>
|
||||
<name>id</name>
|
||||
<version>4.0.0</version>
|
||||
<required>true</required>
|
||||
<description>
|
||||
<![CDATA[
|
||||
A unique identifier for a repository. This is used to match the repository
|
||||
|
@ -2595,6 +2596,7 @@
|
|||
<field>
|
||||
<name>url</name>
|
||||
<version>4.0.0</version>
|
||||
<required>true</required>
|
||||
<description>
|
||||
<![CDATA[
|
||||
The url of the repository, in the form <code>protocol://hostname/path</code>.
|
||||
|
|
|
@ -6,12 +6,13 @@ import org.apache.maven.project.artifact.MavenMetadataSource;
|
|||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.project.InvalidProjectVersionException;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.artifact.UnknownRepositoryLayoutException;
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Repository;
|
||||
import org.apache.maven.model.DeploymentRepository;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.MavenTools;
|
||||
import org.apache.maven.DefaultMavenTools;
|
||||
import org.apache.maven.project.build.model.DefaultModelLineageBuilder;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.DefaultMavenProjectBuilder;
|
||||
|
@ -57,7 +58,8 @@ public privileged aspect PBEDerivativeReporterAspect
|
|||
// <-- UnknownRepositoryLayoutException
|
||||
// <---------- ProjectBuildingException
|
||||
// =========================================================================
|
||||
after( MavenProject project, File pomFile, DeploymentRepository repo ) throwing( UnknownRepositoryLayoutException cause ):
|
||||
|
||||
after( MavenProject project, File pomFile, DeploymentRepository repo ) throwing( InvalidRepositoryException cause ):
|
||||
mavenTools_buildDeploymentArtifactRepository( repo ) &&
|
||||
cflow( pbldr_processProjectLogic( project, pomFile ) )
|
||||
&& within_DefaultMavenProjectBuilder()
|
||||
|
@ -83,7 +85,7 @@ public privileged aspect PBEDerivativeReporterAspect
|
|||
// <------ UnknownRepositoryLayoutException
|
||||
// <---------- ProjectBuildingException
|
||||
// =========================================================================
|
||||
after( MavenProject project, File pomFile, Repository repo ) throwing( UnknownRepositoryLayoutException cause ):
|
||||
after( MavenProject project, File pomFile, Repository repo ) throwing( InvalidRepositoryException cause ):
|
||||
mavenTools_buildArtifactRepository( repo )
|
||||
&& cflow( pbldr_processProjectLogic( project, pomFile ) )
|
||||
{
|
||||
|
@ -106,7 +108,7 @@ public privileged aspect PBEDerivativeReporterAspect
|
|||
// <------ UnknownRepositoryLayoutException
|
||||
// <------ ProjectBuildingException
|
||||
// =========================================================================
|
||||
after( Model model, File pomFile, Repository repo ) throwing( UnknownRepositoryLayoutException cause ):
|
||||
after( Model model, File pomFile, Repository repo ) throwing( InvalidRepositoryException cause ):
|
||||
mavenTools_buildArtifactRepository( repo )
|
||||
&& cflow( mlbldr_updateRepositorySet( model, pomFile ) )
|
||||
{
|
||||
|
|
|
@ -19,13 +19,14 @@ package org.apache.maven;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.UnknownRepositoryLayoutException;
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
||||
import org.apache.maven.model.DeploymentRepository;
|
||||
import org.apache.maven.model.Repository;
|
||||
import org.apache.maven.model.RepositoryPolicy;
|
||||
import org.apache.maven.project.MissingRepositoryElementException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
@ -43,7 +44,7 @@ public class DefaultMavenTools
|
|||
// ----------------------------------------------------------------------------
|
||||
|
||||
public List buildArtifactRepositories( List repositories )
|
||||
throws UnknownRepositoryLayoutException
|
||||
throws InvalidRepositoryException
|
||||
{
|
||||
List repos = new ArrayList();
|
||||
|
||||
|
@ -62,7 +63,7 @@ public class DefaultMavenTools
|
|||
}
|
||||
|
||||
public ArtifactRepository buildDeploymentArtifactRepository( DeploymentRepository repo )
|
||||
throws UnknownRepositoryLayoutException
|
||||
throws InvalidRepositoryException
|
||||
{
|
||||
if ( repo != null )
|
||||
{
|
||||
|
@ -79,13 +80,23 @@ public class DefaultMavenTools
|
|||
}
|
||||
|
||||
public ArtifactRepository buildArtifactRepository( Repository repo )
|
||||
throws UnknownRepositoryLayoutException
|
||||
throws InvalidRepositoryException
|
||||
{
|
||||
if ( repo != null )
|
||||
{
|
||||
String id = repo.getId();
|
||||
String url = repo.getUrl();
|
||||
|
||||
if ( id == null || id.trim().length() < 1 )
|
||||
{
|
||||
throw new MissingRepositoryElementException( "Repository ID must not be empty (URL is: " + url + ")." );
|
||||
}
|
||||
|
||||
if ( url == null || url.trim().length() < 1 )
|
||||
{
|
||||
throw new MissingRepositoryElementException( "Repository URL must not be empty (ID is: " + id + ").", id );
|
||||
}
|
||||
|
||||
ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repo.getSnapshots() );
|
||||
|
||||
ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repo.getReleases() );
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.apache.maven;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.UnknownRepositoryLayoutException;
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.model.DeploymentRepository;
|
||||
import org.apache.maven.model.Repository;
|
||||
|
@ -38,11 +38,11 @@ public interface MavenTools
|
|||
// ----------------------------------------------------------------------------
|
||||
|
||||
List buildArtifactRepositories( List repositories )
|
||||
throws UnknownRepositoryLayoutException;
|
||||
throws InvalidRepositoryException;
|
||||
|
||||
ArtifactRepository buildDeploymentArtifactRepository( DeploymentRepository repo )
|
||||
throws UnknownRepositoryLayoutException;
|
||||
throws InvalidRepositoryException;
|
||||
|
||||
ArtifactRepository buildArtifactRepository( Repository repo )
|
||||
throws UnknownRepositoryLayoutException;
|
||||
throws InvalidRepositoryException;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.apache.maven.artifact.Artifact;
|
|||
import org.apache.maven.artifact.ArtifactStatus;
|
||||
import org.apache.maven.artifact.ArtifactUtils;
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.artifact.UnknownRepositoryLayoutException;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
@ -619,7 +618,7 @@ public class DefaultMavenProjectBuilder
|
|||
normalized.add( item );
|
||||
normalizationNeeded = true;
|
||||
}
|
||||
catch ( UnknownRepositoryLayoutException e )
|
||||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
throw new ProjectBuildingException( projectId, "Error building artifact repository for id: " + repo.getId(), e );
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package org.apache.maven.project;
|
||||
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
|
||||
public class MissingRepositoryElementException
|
||||
extends InvalidRepositoryException
|
||||
{
|
||||
|
||||
public MissingRepositoryElementException( String message,
|
||||
String repositoryId )
|
||||
{
|
||||
super( message, repositoryId );
|
||||
}
|
||||
|
||||
public MissingRepositoryElementException( String message )
|
||||
{
|
||||
super( message, "-unknown-" );
|
||||
}
|
||||
|
||||
}
|
|
@ -19,7 +19,7 @@ package org.apache.maven.project;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.UnknownRepositoryLayoutException;
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
||||
|
@ -41,7 +41,7 @@ public final class ProjectUtils
|
|||
public static List buildArtifactRepositories( List repositories,
|
||||
ArtifactRepositoryFactory artifactRepositoryFactory,
|
||||
PlexusContainer container )
|
||||
throws UnknownRepositoryLayoutException
|
||||
throws InvalidRepositoryException
|
||||
{
|
||||
|
||||
List repos = new ArrayList();
|
||||
|
@ -64,7 +64,7 @@ public final class ProjectUtils
|
|||
public static ArtifactRepository buildDeploymentArtifactRepository( DeploymentRepository repo,
|
||||
ArtifactRepositoryFactory artifactRepositoryFactory,
|
||||
PlexusContainer container )
|
||||
throws UnknownRepositoryLayoutException
|
||||
throws InvalidRepositoryException
|
||||
{
|
||||
if ( repo != null )
|
||||
{
|
||||
|
@ -83,13 +83,23 @@ public final class ProjectUtils
|
|||
public static ArtifactRepository buildArtifactRepository( Repository repo,
|
||||
ArtifactRepositoryFactory artifactRepositoryFactory,
|
||||
PlexusContainer container )
|
||||
throws UnknownRepositoryLayoutException
|
||||
throws InvalidRepositoryException
|
||||
{
|
||||
if ( repo != null )
|
||||
{
|
||||
String id = repo.getId();
|
||||
String url = repo.getUrl();
|
||||
|
||||
if ( id == null || id.trim().length() < 1 )
|
||||
{
|
||||
throw new MissingRepositoryElementException( "Repository ID must not be empty (URL is: " + url + ")." );
|
||||
}
|
||||
|
||||
if ( url == null || url.trim().length() < 1 )
|
||||
{
|
||||
throw new MissingRepositoryElementException( "Repository URL must not be empty (ID is: " + id + ").", id );
|
||||
}
|
||||
|
||||
ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repo.getSnapshots() );
|
||||
ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repo.getReleases() );
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.apache.maven.project.error;
|
||||
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.artifact.UnknownRepositoryLayoutException;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
|
@ -343,7 +342,7 @@ public class DefaultProjectErrorReporter
|
|||
public void reportErrorCreatingArtifactRepository( String projectId,
|
||||
File pomFile,
|
||||
Repository repo,
|
||||
UnknownRepositoryLayoutException cause )
|
||||
InvalidRepositoryException cause )
|
||||
{
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
|
@ -352,7 +351,7 @@ public class DefaultProjectErrorReporter
|
|||
writer.write( NEWLINE );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( "Repository-Id: " );
|
||||
writer.write( ((InvalidRepositoryException)cause).getRepositoryId() );
|
||||
writer.write( cause.getRepositoryId() );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( "Reason: " );
|
||||
|
@ -369,7 +368,7 @@ public class DefaultProjectErrorReporter
|
|||
public void reportErrorCreatingDeploymentArtifactRepository( MavenProject project,
|
||||
File pomFile,
|
||||
DeploymentRepository repo,
|
||||
UnknownRepositoryLayoutException cause )
|
||||
InvalidRepositoryException cause )
|
||||
{
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
|
@ -378,7 +377,7 @@ public class DefaultProjectErrorReporter
|
|||
writer.write( NEWLINE );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( "Repository-Id: " );
|
||||
writer.write( ((InvalidRepositoryException)cause).getRepositoryId() );
|
||||
writer.write( cause.getRepositoryId() );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( NEWLINE );
|
||||
writer.write( "Reason: " );
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.apache.maven.project.error;
|
||||
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.artifact.UnknownRepositoryLayoutException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.model.DeploymentRepository;
|
||||
|
@ -158,7 +157,7 @@ public interface ProjectErrorReporter
|
|||
void reportErrorCreatingDeploymentArtifactRepository( MavenProject project,
|
||||
File pomFile,
|
||||
DeploymentRepository repo,
|
||||
UnknownRepositoryLayoutException cause );
|
||||
InvalidRepositoryException cause );
|
||||
|
||||
/**
|
||||
* <b>Call Stack:</b>
|
||||
|
@ -179,7 +178,7 @@ public interface ProjectErrorReporter
|
|||
void reportErrorCreatingArtifactRepository( String projectId,
|
||||
File pomFile,
|
||||
Repository repo,
|
||||
UnknownRepositoryLayoutException cause );
|
||||
InvalidRepositoryException cause );
|
||||
|
||||
/**
|
||||
* <b>Call Stack:</b>
|
||||
|
|
Loading…
Reference in New Issue