mirror of https://github.com/apache/maven.git
PR: MNG-122
exception clean up phase 1 git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@320668 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
44779c4da6
commit
5de6418c69
|
@ -75,8 +75,8 @@ public abstract class AbstractArtifactTask
|
|||
localRepository = getDefaultLocalRepository();
|
||||
}
|
||||
|
||||
ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
|
||||
localRepository.getLayout() );
|
||||
ArtifactRepositoryLayout repositoryLayout =
|
||||
(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, localRepository.getLayout() );
|
||||
|
||||
CustomWagonManager manager = (CustomWagonManager) lookup( WagonManager.ROLE );
|
||||
manager.setLocalRepository( localRepository.getLocation() );
|
||||
|
@ -86,8 +86,8 @@ public abstract class AbstractArtifactTask
|
|||
|
||||
protected ArtifactRepository createRemoteArtifactRepository( RemoteRepository repository )
|
||||
{
|
||||
ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
|
||||
repository.getLayout() );
|
||||
ArtifactRepositoryLayout repositoryLayout =
|
||||
(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, repository.getLayout() );
|
||||
|
||||
WagonManager manager = (WagonManager) lookup( WagonManager.ROLE );
|
||||
|
||||
|
@ -367,22 +367,22 @@ public abstract class AbstractArtifactTask
|
|||
|
||||
return pom;
|
||||
}
|
||||
|
||||
|
||||
public void diagnoseError( Throwable error )
|
||||
{
|
||||
try
|
||||
{
|
||||
ErrorDiagnostics diagnostics = (ErrorDiagnostics) embedder.lookup( ErrorDiagnostics.ROLE );
|
||||
|
||||
|
||||
StringBuffer message = new StringBuffer();
|
||||
|
||||
message.append( "An error has occurred while processing the Maven artifact tasks.\n" );
|
||||
message.append( " Diagnosis:\n\n" );
|
||||
|
||||
message.append( diagnostics.diagnose( error ) );
|
||||
|
||||
|
||||
message.append( "\n\n" );
|
||||
|
||||
|
||||
log( message.toString(), Project.MSG_INFO );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
|
@ -440,4 +440,23 @@ public abstract class AbstractArtifactTask
|
|||
policy.setUpdatePolicy( pomRepoPolicy.getUpdatePolicy() );
|
||||
return policy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection RefusedBequest
|
||||
*/
|
||||
public void execute()
|
||||
{
|
||||
try
|
||||
{
|
||||
doExecute();
|
||||
}
|
||||
catch ( BuildException e )
|
||||
{
|
||||
diagnoseError( e );
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void doExecute();
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
|
|||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.TypeArtifactFilter;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Repository;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
|
@ -70,175 +69,156 @@ public class DependenciesTask
|
|||
|
||||
private boolean verbose;
|
||||
|
||||
/**
|
||||
* @noinspection RefusedBequest
|
||||
*/
|
||||
public void execute()
|
||||
protected void doExecute()
|
||||
{
|
||||
try
|
||||
ArtifactRepository localRepo = createLocalArtifactRepository();
|
||||
|
||||
ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
|
||||
MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
|
||||
ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
||||
MavenMetadataSource metadataSource = (MavenMetadataSource) lookup( ArtifactMetadataSource.ROLE );
|
||||
|
||||
List dependencies = this.dependencies;
|
||||
|
||||
Pom pom = buildPom( projectBuilder, localRepo );
|
||||
if ( pom != null )
|
||||
{
|
||||
ArtifactRepository localRepo = createLocalArtifactRepository();
|
||||
|
||||
ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
|
||||
MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
|
||||
ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
||||
MavenMetadataSource metadataSource = (MavenMetadataSource) lookup( ArtifactMetadataSource.ROLE );
|
||||
|
||||
List dependencies = this.dependencies;
|
||||
|
||||
Pom pom = buildPom( projectBuilder, localRepo );
|
||||
if ( pom != null )
|
||||
if ( !dependencies.isEmpty() )
|
||||
{
|
||||
if ( !dependencies.isEmpty() )
|
||||
{
|
||||
throw new BuildException( "You cannot specify both dependencies and a pom in the dependencies task" );
|
||||
}
|
||||
|
||||
dependencies = pom.getDependencies();
|
||||
|
||||
for ( Iterator i = pom.getRepositories().iterator(); i.hasNext(); )
|
||||
{
|
||||
Repository pomRepository = (Repository) i.next();
|
||||
|
||||
remoteRepositories.add( createAntRemoteRepository( pomRepository ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// we have to have some sort of Pom object in order to satisfy the requirements for building the
|
||||
// originating Artifact below...
|
||||
pom = createDummyPom();
|
||||
throw new BuildException( "You cannot specify both dependencies and a pom in the dependencies task" );
|
||||
}
|
||||
|
||||
if ( dependencies.isEmpty() )
|
||||
dependencies = pom.getDependencies();
|
||||
|
||||
for ( Iterator i = pom.getRepositories().iterator(); i.hasNext(); )
|
||||
{
|
||||
log( "There were no dependencies specified", Project.MSG_WARN );
|
||||
}
|
||||
Repository pomRepository = (Repository) i.next();
|
||||
|
||||
Set artifacts;
|
||||
try
|
||||
{
|
||||
artifacts = MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null, null );
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new BuildException( "Invalid version specification", e );
|
||||
}
|
||||
|
||||
log( "Resolving dependencies...", Project.MSG_VERBOSE );
|
||||
|
||||
WagonManager wagonManager = (WagonManager) lookup( WagonManager.ROLE );
|
||||
wagonManager.setDownloadMonitor( new AntDownloadMonitor() );
|
||||
|
||||
ArtifactResolutionResult result;
|
||||
try
|
||||
{
|
||||
Artifact pomArtifact = artifactFactory.createBuildArtifact( pom.getGroupId(), pom.getArtifactId(), pom
|
||||
.getVersion(), pom.getPackaging() );
|
||||
|
||||
List listeners = Collections.EMPTY_LIST;
|
||||
if ( verbose )
|
||||
{
|
||||
listeners = Collections.singletonList( new AntResolutionListener( getProject() ) );
|
||||
}
|
||||
|
||||
List remoteRepositories = getRemoteRepositories();
|
||||
|
||||
RemoteRepository remoteRepository = getDefaultRemoteRepository();
|
||||
remoteRepositories.add( remoteRepository );
|
||||
|
||||
List remoteArtifactRepositories = createRemoteArtifactRepositories( remoteRepositories );
|
||||
|
||||
// TODO: managed dependencies
|
||||
Map managedDependencies = Collections.EMPTY_MAP;
|
||||
|
||||
ArtifactFilter filter = null;
|
||||
if ( useScope != null )
|
||||
{
|
||||
filter = new ScopeArtifactFilter( useScope );
|
||||
}
|
||||
if ( type != null )
|
||||
{
|
||||
TypeArtifactFilter typeArtifactFilter = new TypeArtifactFilter( type );
|
||||
if ( filter != null )
|
||||
{
|
||||
AndArtifactFilter andFilter = new AndArtifactFilter();
|
||||
andFilter.add( filter );
|
||||
andFilter.add( typeArtifactFilter );
|
||||
filter = andFilter;
|
||||
}
|
||||
else
|
||||
{
|
||||
filter = typeArtifactFilter;
|
||||
}
|
||||
}
|
||||
|
||||
result = resolver.resolveTransitively( artifacts, pomArtifact, managedDependencies, localRepo,
|
||||
remoteArtifactRepositories, metadataSource, filter, listeners );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new BuildException( "Unable to resolve artifact", e );
|
||||
}
|
||||
catch ( ArtifactNotFoundException e )
|
||||
{
|
||||
// TODO: improve handling
|
||||
throw new BuildException( "Unable to locate artifact", e );
|
||||
}
|
||||
|
||||
if ( pathId != null && getProject().getReference( pathId ) != null )
|
||||
{
|
||||
throw new BuildException( "Reference ID " + pathId + " already exists" );
|
||||
}
|
||||
|
||||
if ( filesetId != null && getProject().getReference( filesetId ) != null )
|
||||
{
|
||||
throw new BuildException( "Reference ID " + filesetId + " already exists" );
|
||||
}
|
||||
|
||||
FileList fileList = new FileList();
|
||||
fileList.setDir( getLocalRepository().getLocation() );
|
||||
|
||||
FileSet fileSet = new FileSet();
|
||||
fileSet.setDir( fileList.getDir( getProject() ) );
|
||||
|
||||
if ( result.getArtifacts().isEmpty() )
|
||||
{
|
||||
fileSet.createExclude().setName( "**/**" );
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
|
||||
{
|
||||
Artifact artifact = (Artifact) i.next();
|
||||
String filename = localRepo.pathOf( artifact );
|
||||
|
||||
FileList.FileName file = new FileList.FileName();
|
||||
file.setName( filename );
|
||||
|
||||
fileList.addConfiguredFile( file );
|
||||
|
||||
fileSet.createInclude().setName( filename );
|
||||
}
|
||||
}
|
||||
|
||||
if ( pathId != null )
|
||||
{
|
||||
Path path = new Path( getProject() );
|
||||
path.addFilelist( fileList );
|
||||
getProject().addReference( pathId, path );
|
||||
}
|
||||
|
||||
if ( filesetId != null )
|
||||
{
|
||||
getProject().addReference( filesetId, fileSet );
|
||||
remoteRepositories.add( createAntRemoteRepository( pomRepository ) );
|
||||
}
|
||||
}
|
||||
catch ( BuildException e )
|
||||
else
|
||||
{
|
||||
diagnoseError( e );
|
||||
|
||||
throw e;
|
||||
// we have to have some sort of Pom object in order to satisfy the requirements for building the
|
||||
// originating Artifact below...
|
||||
pom = createDummyPom();
|
||||
}
|
||||
|
||||
if ( dependencies.isEmpty() )
|
||||
{
|
||||
log( "There were no dependencies specified", Project.MSG_WARN );
|
||||
}
|
||||
|
||||
log( "Resolving dependencies...", Project.MSG_VERBOSE );
|
||||
|
||||
WagonManager wagonManager = (WagonManager) lookup( WagonManager.ROLE );
|
||||
wagonManager.setDownloadMonitor( new AntDownloadMonitor() );
|
||||
|
||||
ArtifactResolutionResult result;
|
||||
Set artifacts;
|
||||
try
|
||||
{
|
||||
artifacts = metadataSource.createArtifacts( artifactFactory, dependencies, null, null, null );
|
||||
|
||||
Artifact pomArtifact = artifactFactory.createBuildArtifact( pom.getGroupId(), pom.getArtifactId(), pom
|
||||
.getVersion(), pom.getPackaging() );
|
||||
|
||||
List listeners = Collections.EMPTY_LIST;
|
||||
if ( verbose )
|
||||
{
|
||||
listeners = Collections.singletonList( new AntResolutionListener( getProject() ) );
|
||||
}
|
||||
|
||||
List remoteRepositories = getRemoteRepositories();
|
||||
|
||||
RemoteRepository remoteRepository = getDefaultRemoteRepository();
|
||||
remoteRepositories.add( remoteRepository );
|
||||
|
||||
List remoteArtifactRepositories = createRemoteArtifactRepositories( remoteRepositories );
|
||||
|
||||
// TODO: managed dependencies
|
||||
Map managedDependencies = Collections.EMPTY_MAP;
|
||||
|
||||
ArtifactFilter filter = null;
|
||||
if ( useScope != null )
|
||||
{
|
||||
filter = new ScopeArtifactFilter( useScope );
|
||||
}
|
||||
if ( type != null )
|
||||
{
|
||||
TypeArtifactFilter typeArtifactFilter = new TypeArtifactFilter( type );
|
||||
if ( filter != null )
|
||||
{
|
||||
AndArtifactFilter andFilter = new AndArtifactFilter();
|
||||
andFilter.add( filter );
|
||||
andFilter.add( typeArtifactFilter );
|
||||
filter = andFilter;
|
||||
}
|
||||
else
|
||||
{
|
||||
filter = typeArtifactFilter;
|
||||
}
|
||||
}
|
||||
|
||||
result = resolver.resolveTransitively( artifacts, pomArtifact, managedDependencies, localRepo,
|
||||
remoteArtifactRepositories, metadataSource, filter, listeners );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new BuildException( "Unable to resolve artifact", e );
|
||||
}
|
||||
catch ( ArtifactNotFoundException e )
|
||||
{
|
||||
// TODO: improve handling
|
||||
throw new BuildException( "Unable to locate artifact", e );
|
||||
}
|
||||
|
||||
if ( pathId != null && getProject().getReference( pathId ) != null )
|
||||
{
|
||||
throw new BuildException( "Reference ID " + pathId + " already exists" );
|
||||
}
|
||||
|
||||
if ( filesetId != null && getProject().getReference( filesetId ) != null )
|
||||
{
|
||||
throw new BuildException( "Reference ID " + filesetId + " already exists" );
|
||||
}
|
||||
|
||||
FileList fileList = new FileList();
|
||||
fileList.setDir( getLocalRepository().getLocation() );
|
||||
|
||||
FileSet fileSet = new FileSet();
|
||||
fileSet.setDir( fileList.getDir( getProject() ) );
|
||||
|
||||
if ( result.getArtifacts().isEmpty() )
|
||||
{
|
||||
fileSet.createExclude().setName( "**/**" );
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
|
||||
{
|
||||
Artifact artifact = (Artifact) i.next();
|
||||
String filename = localRepo.pathOf( artifact );
|
||||
|
||||
FileList.FileName file = new FileList.FileName();
|
||||
file.setName( filename );
|
||||
|
||||
fileList.addConfiguredFile( file );
|
||||
|
||||
fileSet.createInclude().setName( filename );
|
||||
}
|
||||
}
|
||||
|
||||
if ( pathId != null )
|
||||
{
|
||||
Path path = new Path( getProject() );
|
||||
path.addFilelist( fileList );
|
||||
getProject().addReference( pathId, path );
|
||||
}
|
||||
|
||||
if ( filesetId != null )
|
||||
{
|
||||
getProject().addReference( filesetId, fileSet );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,92 +43,83 @@ public class DeployTask
|
|||
|
||||
private File file;
|
||||
|
||||
public void execute()
|
||||
protected void doExecute()
|
||||
{
|
||||
try
|
||||
ArtifactRepository localRepo = createLocalArtifactRepository();
|
||||
MavenProjectBuilder builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
|
||||
|
||||
Pom pom = buildPom( builder, localRepo );
|
||||
|
||||
if ( pom == null )
|
||||
{
|
||||
ArtifactRepository localRepo = createLocalArtifactRepository();
|
||||
MavenProjectBuilder builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
|
||||
throw new BuildException( "A POM element is required to deploy to the repository" );
|
||||
}
|
||||
|
||||
Pom pom = buildPom( builder, localRepo );
|
||||
Artifact artifact = createArtifact( pom );
|
||||
|
||||
if ( pom == null )
|
||||
DistributionManagement distributionManagement = pom.getDistributionManagement();
|
||||
|
||||
if ( remoteSnapshotRepository == null && remoteRepository == null )
|
||||
{
|
||||
if ( distributionManagement != null )
|
||||
{
|
||||
throw new BuildException( "A POM element is required to deploy to the repository" );
|
||||
}
|
||||
|
||||
Artifact artifact = createArtifact( pom );
|
||||
|
||||
DistributionManagement distributionManagement = pom.getDistributionManagement();
|
||||
|
||||
if ( remoteSnapshotRepository == null && remoteRepository == null )
|
||||
{
|
||||
if ( distributionManagement != null )
|
||||
if ( distributionManagement.getSnapshotRepository() != null )
|
||||
{
|
||||
if ( distributionManagement.getSnapshotRepository() != null )
|
||||
{
|
||||
remoteSnapshotRepository = createAntRemoteRepositoryBase( distributionManagement
|
||||
.getSnapshotRepository() );
|
||||
}
|
||||
if ( distributionManagement.getRepository() != null )
|
||||
{
|
||||
remoteRepository = createAntRemoteRepositoryBase( distributionManagement.getRepository() );
|
||||
}
|
||||
remoteSnapshotRepository = createAntRemoteRepositoryBase( distributionManagement
|
||||
.getSnapshotRepository() );
|
||||
}
|
||||
if ( distributionManagement.getRepository() != null )
|
||||
{
|
||||
remoteRepository = createAntRemoteRepositoryBase( distributionManagement.getRepository() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( remoteSnapshotRepository == null )
|
||||
{
|
||||
remoteSnapshotRepository = remoteRepository;
|
||||
}
|
||||
if ( remoteSnapshotRepository == null )
|
||||
{
|
||||
remoteSnapshotRepository = remoteRepository;
|
||||
}
|
||||
|
||||
ArtifactRepository deploymentRepository = null;
|
||||
if ( artifact.isSnapshot() && remoteSnapshotRepository != null )
|
||||
ArtifactRepository deploymentRepository;
|
||||
if ( artifact.isSnapshot() && remoteSnapshotRepository != null )
|
||||
{
|
||||
deploymentRepository = createRemoteArtifactRepository( remoteSnapshotRepository );
|
||||
}
|
||||
else if ( remoteRepository != null )
|
||||
{
|
||||
deploymentRepository = createRemoteArtifactRepository( remoteRepository );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BuildException(
|
||||
"A distributionManagement element or remoteRepository element is required to deploy" );
|
||||
}
|
||||
|
||||
// Deploy the POM
|
||||
boolean isPomArtifact = "pom".equals( pom.getPackaging() );
|
||||
if ( !isPomArtifact )
|
||||
{
|
||||
ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pom.getFile() );
|
||||
artifact.addMetadata( metadata );
|
||||
}
|
||||
|
||||
log( "Deploying to " + deploymentRepository.getUrl() );
|
||||
ArtifactDeployer deployer = (ArtifactDeployer) lookup( ArtifactDeployer.ROLE );
|
||||
try
|
||||
{
|
||||
if ( !isPomArtifact )
|
||||
{
|
||||
deploymentRepository = createRemoteArtifactRepository( remoteSnapshotRepository );
|
||||
}
|
||||
else if ( remoteRepository != null )
|
||||
{
|
||||
deploymentRepository = createRemoteArtifactRepository( remoteRepository );
|
||||
deployer.deploy( file, artifact, deploymentRepository, localRepo );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BuildException(
|
||||
"A distributionManagement element or remoteRepository element is required to deploy" );
|
||||
}
|
||||
|
||||
// Deploy the POM
|
||||
boolean isPomArtifact = "pom".equals( pom.getPackaging() );
|
||||
if ( !isPomArtifact )
|
||||
{
|
||||
ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pom.getFile() );
|
||||
artifact.addMetadata( metadata );
|
||||
}
|
||||
|
||||
log( "Deploying to " + deploymentRepository.getUrl() );
|
||||
ArtifactDeployer deployer = (ArtifactDeployer) lookup( ArtifactDeployer.ROLE );
|
||||
try
|
||||
{
|
||||
if ( !isPomArtifact )
|
||||
{
|
||||
deployer.deploy( file, artifact, deploymentRepository, localRepo );
|
||||
}
|
||||
else
|
||||
{
|
||||
deployer.deploy( pom.getFile(), artifact, deploymentRepository, localRepo );
|
||||
}
|
||||
}
|
||||
catch ( ArtifactDeploymentException e )
|
||||
{
|
||||
// TODO: deployment exception that does not give a trace
|
||||
throw new BuildException( "Error deploying artifact", e );
|
||||
deployer.deploy( pom.getFile(), artifact, deploymentRepository, localRepo );
|
||||
}
|
||||
}
|
||||
catch ( BuildException e )
|
||||
catch ( ArtifactDeploymentException e )
|
||||
{
|
||||
diagnoseError( e );
|
||||
|
||||
throw e;
|
||||
// TODO: deployment exception that does not give a trace
|
||||
throw new BuildException( "Error deploying artifact", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,47 +39,38 @@ public class InstallTask
|
|||
{
|
||||
private File file;
|
||||
|
||||
public void execute()
|
||||
protected void doExecute()
|
||||
{
|
||||
ArtifactRepository localRepo = createLocalArtifactRepository();
|
||||
|
||||
MavenProjectBuilder builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
|
||||
Pom pom = buildPom( builder, localRepo );
|
||||
|
||||
Artifact artifact = createArtifact( pom );
|
||||
|
||||
boolean isPomArtifact = "pom".equals( pom.getPackaging() );
|
||||
if ( !isPomArtifact )
|
||||
{
|
||||
ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pom.getFile() );
|
||||
artifact.addMetadata( metadata );
|
||||
}
|
||||
|
||||
ArtifactInstaller installer = (ArtifactInstaller) lookup( ArtifactInstaller.ROLE );
|
||||
try
|
||||
{
|
||||
ArtifactRepository localRepo = createLocalArtifactRepository();
|
||||
|
||||
MavenProjectBuilder builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
|
||||
Pom pom = buildPom( builder, localRepo );
|
||||
|
||||
Artifact artifact = createArtifact( pom );
|
||||
|
||||
boolean isPomArtifact = "pom".equals( pom.getPackaging() );
|
||||
if ( !isPomArtifact )
|
||||
{
|
||||
ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pom.getFile() );
|
||||
artifact.addMetadata( metadata );
|
||||
installer.install( file, artifact, localRepo );
|
||||
}
|
||||
|
||||
ArtifactInstaller installer = (ArtifactInstaller) lookup( ArtifactInstaller.ROLE );
|
||||
try
|
||||
else
|
||||
{
|
||||
if ( !isPomArtifact )
|
||||
{
|
||||
installer.install( file, artifact, localRepo );
|
||||
}
|
||||
else
|
||||
{
|
||||
installer.install( pom.getFile(), artifact, localRepo );
|
||||
}
|
||||
}
|
||||
catch ( ArtifactInstallationException e )
|
||||
{
|
||||
// TODO: install exception that does not give a trace
|
||||
throw new BuildException( "Error installing artifact", e );
|
||||
installer.install( pom.getFile(), artifact, localRepo );
|
||||
}
|
||||
}
|
||||
catch ( BuildException e )
|
||||
catch ( ArtifactInstallationException e )
|
||||
{
|
||||
diagnoseError( e );
|
||||
|
||||
throw e;
|
||||
// TODO: install exception that does not give a trace
|
||||
throw new BuildException( "Error installing artifact", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.maven.artifact.ant;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.ArtifactUtils;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
@ -47,6 +48,8 @@ public class InstallWagonProviderTask
|
|||
|
||||
private String version;
|
||||
|
||||
private static final String WAGON_GROUP_ID = "org.apache.maven.wagon";
|
||||
|
||||
public String getArtifactId()
|
||||
{
|
||||
return artifactId;
|
||||
|
@ -67,59 +70,60 @@ public class InstallWagonProviderTask
|
|||
this.version = version;
|
||||
}
|
||||
|
||||
public void execute()
|
||||
public void doExecute()
|
||||
throws BuildException
|
||||
{
|
||||
MavenMetadataSource metadataSource = (MavenMetadataSource) lookup( ArtifactMetadataSource.ROLE );
|
||||
|
||||
ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
|
||||
ArtifactRepository artifactRepository = createRemoteArtifactRepository( getDefaultRemoteRepository() );
|
||||
List remoteRepositories = Collections.singletonList( artifactRepository );
|
||||
|
||||
VersionRange versionRange;
|
||||
try
|
||||
{
|
||||
MavenMetadataSource metadataSource = (MavenMetadataSource) lookup( ArtifactMetadataSource.ROLE );
|
||||
|
||||
ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
|
||||
ArtifactRepository artifactRepository = createRemoteArtifactRepository( getDefaultRemoteRepository() );
|
||||
List remoteRepositories = Collections.singletonList( artifactRepository );
|
||||
try
|
||||
{
|
||||
ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
||||
VersionRange versionRange = VersionRange.createFromVersionSpec( version );
|
||||
Artifact providerArtifact = factory.createExtensionArtifact( "org.apache.maven.wagon", artifactId,
|
||||
versionRange );
|
||||
ArtifactResolutionResult result = resolver.resolveTransitively( Collections
|
||||
.singleton( providerArtifact ), createArtifact( createDummyPom() ),
|
||||
createLocalArtifactRepository(),
|
||||
remoteRepositories, metadataSource,
|
||||
null );
|
||||
|
||||
log( "Installing provider: " + providerArtifact );
|
||||
|
||||
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
|
||||
{
|
||||
Artifact a = (Artifact) i.next();
|
||||
getEmbedder().getContainer().addJarResource( a.getFile() );
|
||||
}
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new BuildException( "Unable to locate wagon provider in remote repository", e );
|
||||
}
|
||||
catch ( PlexusContainerException e )
|
||||
{
|
||||
throw new BuildException( "Unable to locate wagon provider in remote repository", e );
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new BuildException( "Unable to locate wagon provider in remote repository", e );
|
||||
}
|
||||
catch ( ArtifactNotFoundException e )
|
||||
{
|
||||
throw new BuildException( "Unable to locate wagon provider in remote repository", e );
|
||||
}
|
||||
versionRange = VersionRange.createFromVersionSpec( version );
|
||||
}
|
||||
catch ( BuildException e )
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
diagnoseError( e );
|
||||
|
||||
throw e;
|
||||
throw new BuildException( "Unable to get extension '" +
|
||||
ArtifactUtils.versionlessKey( WAGON_GROUP_ID, artifactId ) + "' because version '" + version +
|
||||
" is invalid: " + e.getMessage(), e );
|
||||
}
|
||||
|
||||
ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
||||
Artifact providerArtifact = factory.createExtensionArtifact( WAGON_GROUP_ID, artifactId, versionRange );
|
||||
|
||||
ArtifactResolutionResult result;
|
||||
try
|
||||
{
|
||||
result = resolver.resolveTransitively( Collections.singleton( providerArtifact ),
|
||||
createArtifact( createDummyPom() ), createLocalArtifactRepository(),
|
||||
remoteRepositories, metadataSource, null );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new BuildException( "Unable to locate wagon provider in remote repository", e );
|
||||
}
|
||||
catch ( ArtifactNotFoundException e )
|
||||
{
|
||||
throw new BuildException( "Unable to locate wagon provider in remote repository", e );
|
||||
}
|
||||
|
||||
log( "Installing provider: " + providerArtifact );
|
||||
|
||||
try
|
||||
{
|
||||
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
|
||||
{
|
||||
Artifact a = (Artifact) i.next();
|
||||
getEmbedder().getContainer().addJarResource( a.getFile() );
|
||||
}
|
||||
}
|
||||
catch ( PlexusContainerException e )
|
||||
{
|
||||
throw new BuildException( "Unable to locate wagon provider in remote repository", e );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ public class Pom
|
|||
/**
|
||||
* Registers POMPropertyHelper as a property interceptor
|
||||
*/
|
||||
public void execute()
|
||||
protected void doExecute()
|
||||
{
|
||||
ArtifactRepository localRepo = createLocalArtifactRepository();
|
||||
MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
|
||||
|
|
|
@ -117,9 +117,7 @@ public class DefaultArtifactResolver
|
|||
{
|
||||
if ( !wagonManager.isOnline() )
|
||||
{
|
||||
getLogger().debug( "System is offline. Cannot resolve artifact: " + artifact + "." );
|
||||
|
||||
return;
|
||||
throw new ArtifactResolutionException( "System is offline.", artifact );
|
||||
}
|
||||
|
||||
try
|
||||
|
|
|
@ -133,10 +133,10 @@ public class AbstractArtifactResolutionException
|
|||
sb.append( "Path to dependency: " );
|
||||
sb.append( LS );
|
||||
int num = 1;
|
||||
for ( Iterator i = path.iterator(); i.hasNext(); )
|
||||
for ( Iterator i = path.iterator(); i.hasNext(); num++ )
|
||||
{
|
||||
sb.append( "\t" );
|
||||
sb.append( num++ );
|
||||
sb.append( num );
|
||||
sb.append( ") " );
|
||||
sb.append( i.next() );
|
||||
sb.append( LS );
|
||||
|
|
|
@ -33,6 +33,12 @@ public class ArtifactResolutionException
|
|||
super( message, groupId, artifactId, version, type, remoteRepositories, path, t );
|
||||
}
|
||||
|
||||
public ArtifactResolutionException( String message, String groupId, String artifactId, String version, String type,
|
||||
Throwable t )
|
||||
{
|
||||
super( message, groupId, artifactId, version, type, null, null, t );
|
||||
}
|
||||
|
||||
public ArtifactResolutionException( String message, Artifact artifact )
|
||||
{
|
||||
super( message, artifact );
|
||||
|
|
|
@ -258,11 +258,9 @@ public class DefaultArtifactCollector
|
|||
catch ( CyclicDependencyException e )
|
||||
{
|
||||
// would like to throw this, but we have crappy stuff in the repo
|
||||
// no logger to use here either just now
|
||||
|
||||
// TODO: should the remoteRepositories list be null here?!
|
||||
fireEvent( ResolutionListener.OMIT_FOR_CYCLE, listeners,
|
||||
new ResolutionNode( e.getArtifact(), null, child ) );
|
||||
new ResolutionNode( e.getArtifact(), remoteRepositories, child ) );
|
||||
}
|
||||
catch ( ArtifactMetadataRetrievalException e )
|
||||
{
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package org.apache.maven;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* One or more builds failed.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class BuildFailureException
|
||||
extends Throwable
|
||||
{
|
||||
public BuildFailureException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
}
|
|
@ -38,7 +38,7 @@ import org.apache.maven.profiles.activation.ProfileActivationException;
|
|||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.reactor.ReactorException;
|
||||
import org.apache.maven.reactor.MavenExecutionException;
|
||||
import org.apache.maven.settings.Mirror;
|
||||
import org.apache.maven.settings.Proxy;
|
||||
import org.apache.maven.settings.Server;
|
||||
|
@ -88,7 +88,7 @@ public class DefaultMaven
|
|||
protected LifecycleExecutor lifecycleExecutor;
|
||||
|
||||
protected PlexusContainer container;
|
||||
|
||||
|
||||
protected ErrorDiagnostics errorDiagnostics;
|
||||
|
||||
protected RuntimeInformation runtimeInformation;
|
||||
|
@ -104,7 +104,7 @@ public class DefaultMaven
|
|||
// ----------------------------------------------------------------------
|
||||
|
||||
public MavenExecutionResponse execute( MavenExecutionRequest request )
|
||||
throws ReactorException, SettingsConfigurationException
|
||||
throws SettingsConfigurationException, MavenExecutionException
|
||||
{
|
||||
if ( request.getSettings().isOffline() )
|
||||
{
|
||||
|
@ -120,7 +120,7 @@ public class DefaultMaven
|
|||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new ReactorException( "Cannot retrieve WagonManager in order to set offline mode.", e );
|
||||
throw new MavenExecutionException( "Cannot retrieve WagonManager in order to set offline mode.", e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -141,11 +141,11 @@ public class DefaultMaven
|
|||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new ReactorException( "Unable to configure Maven for execution", e );
|
||||
throw new MavenExecutionException( "Unable to configure Maven for execution", e );
|
||||
}
|
||||
catch ( ComponentLifecycleException e )
|
||||
{
|
||||
throw new ReactorException( "Unable to configure Maven for execution", e );
|
||||
throw new MavenExecutionException( "Unable to configure Maven for execution", e );
|
||||
}
|
||||
|
||||
EventDispatcher dispatcher = request.getEventDispatcher();
|
||||
|
@ -182,7 +182,7 @@ public class DefaultMaven
|
|||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new ReactorException( "Error processing projects for the reactor: ", e );
|
||||
throw new MavenExecutionException( "Error processing projects for the reactor: ", e );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
|
@ -225,87 +225,77 @@ public class DefaultMaven
|
|||
}
|
||||
}
|
||||
|
||||
MavenSession session = createSession( request, rm );
|
||||
|
||||
session.setUsingPOMsFromFilesystem( foundProjects );
|
||||
|
||||
try
|
||||
{
|
||||
MavenSession session = createSession( request, rm );
|
||||
MavenExecutionResponse response = lifecycleExecutor.execute( session, rm, dispatcher );
|
||||
|
||||
session.setUsingPOMsFromFilesystem( foundProjects );
|
||||
|
||||
try
|
||||
// TODO: is this perhaps more appropriate in the CLI?
|
||||
if ( response.isExecutionFailure() )
|
||||
{
|
||||
MavenExecutionResponse response = lifecycleExecutor.execute( session, rm, dispatcher );
|
||||
dispatcher.dispatchError( event, request.getBaseDirectory(), response.getException() );
|
||||
|
||||
// TODO: is this perhaps more appropriate in the CLI?
|
||||
if ( response.isExecutionFailure() )
|
||||
// TODO: yuck! Revisit when cleaning up the exception handling from the top down
|
||||
Throwable exception = response.getException();
|
||||
|
||||
// TODO: replace all handling by buildfailureexception/mavenexecutionexception or lifecycleexecutionexception
|
||||
if ( exception instanceof BuildFailureException )
|
||||
{
|
||||
dispatcher.dispatchError( event, request.getBaseDirectory(), response.getException() );
|
||||
logFailure( response, rm, exception, null );
|
||||
}
|
||||
else if ( exception instanceof MojoFailureException )
|
||||
{
|
||||
MojoFailureException e = (MojoFailureException) exception;
|
||||
|
||||
// TODO: yuck! Revisit when cleaning up the exception handling from the top down
|
||||
Throwable exception = response.getException();
|
||||
|
||||
if ( ReactorManager.FAIL_AT_END.equals( rm.getFailureBehavior() ) &&
|
||||
exception instanceof ReactorException )
|
||||
logFailure( response, rm, e, e.getLongMessage() );
|
||||
}
|
||||
else if ( exception instanceof MojoExecutionException )
|
||||
{
|
||||
// TODO: replace by above
|
||||
if ( exception.getCause() == null )
|
||||
{
|
||||
logFailure( response, rm, exception, null );
|
||||
}
|
||||
else if ( exception instanceof MojoFailureException )
|
||||
{
|
||||
MojoFailureException e = (MojoFailureException) exception;
|
||||
MojoExecutionException e = (MojoExecutionException) exception;
|
||||
|
||||
logFailure( response, rm, e, e.getLongMessage() );
|
||||
}
|
||||
else if ( exception instanceof MojoExecutionException )
|
||||
{
|
||||
// TODO: replace by above
|
||||
if ( exception.getCause() == null )
|
||||
{
|
||||
MojoExecutionException e = (MojoExecutionException) exception;
|
||||
|
||||
logFailure( response, rm, e, e.getLongMessage() );
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: throw exceptions like this, so "failures" are just that
|
||||
logError( response );
|
||||
}
|
||||
}
|
||||
else if ( exception instanceof ArtifactNotFoundException )
|
||||
{
|
||||
logFailure( response, rm, exception, null );
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: this should be a "FATAL" exception, reported to the
|
||||
// developers - however currently a LOT of
|
||||
// "user" errors fall through the cracks (like invalid POMs, as
|
||||
// one example)
|
||||
// TODO: throw exceptions like this, so "failures" are just that
|
||||
logError( response );
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
else if ( exception instanceof ArtifactNotFoundException )
|
||||
{
|
||||
logFailure( response, rm, exception, null );
|
||||
}
|
||||
else
|
||||
{
|
||||
logSuccess( response, rm );
|
||||
// TODO: this should be a "FATAL" exception, reported to the
|
||||
// developers - however currently a LOT of
|
||||
// "user" errors fall through the cracks (like invalid POMs, as
|
||||
// one example)
|
||||
logError( response );
|
||||
}
|
||||
}
|
||||
catch ( LifecycleExecutionException e )
|
||||
else
|
||||
{
|
||||
logFatal( e );
|
||||
|
||||
throw new ReactorException( "Error executing project within the reactor", e );
|
||||
logSuccess( response, rm );
|
||||
}
|
||||
|
||||
dispatcher.dispatchEnd( event, request.getBaseDirectory() );
|
||||
|
||||
// TODO: not really satisfactory
|
||||
return null;
|
||||
return response;
|
||||
}
|
||||
catch ( ReactorException e )
|
||||
catch ( LifecycleExecutionException e )
|
||||
{
|
||||
logFatal( e );
|
||||
|
||||
dispatcher.dispatchError( event, request.getBaseDirectory(), e );
|
||||
|
||||
throw e;
|
||||
throw new MavenExecutionException( "Error executing project within the reactor", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -418,8 +408,8 @@ public class DefaultMaven
|
|||
|
||||
private List collectProjects( List files, ArtifactRepository localRepository, boolean recursive, Settings settings,
|
||||
ProfileManager globalProfileManager, boolean isRoot )
|
||||
throws ProjectBuildingException, ReactorException, IOException, ArtifactResolutionException,
|
||||
ProfileActivationException
|
||||
throws ArtifactResolutionException, ProjectBuildingException, ProfileActivationException,
|
||||
MavenExecutionException
|
||||
{
|
||||
List projects = new ArrayList( files.size() );
|
||||
|
||||
|
@ -445,10 +435,17 @@ public class DefaultMaven
|
|||
if ( project.getPrerequisites() != null && project.getPrerequisites().getMaven() != null )
|
||||
{
|
||||
DefaultArtifactVersion version = new DefaultArtifactVersion( project.getPrerequisites().getMaven() );
|
||||
if ( runtimeInformation.getApplicationVersion().compareTo( version ) < 0 )
|
||||
try
|
||||
{
|
||||
throw new ProjectBuildingException( project.getId(), "Unable to build project '" + project.getFile() +
|
||||
"; it requires Maven version " + version.toString() );
|
||||
if ( runtimeInformation.getApplicationVersion().compareTo( version ) < 0 )
|
||||
{
|
||||
throw new ProjectBuildingException( project.getId(), "Unable to build project '" +
|
||||
project.getFile() + "; it requires Maven version " + version.toString() );
|
||||
}
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new MavenExecutionException( "Unable to get Maven application version", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -479,8 +476,8 @@ public class DefaultMaven
|
|||
moduleFiles.add( moduleFile );
|
||||
}
|
||||
|
||||
List collectedProjects = collectProjects( moduleFiles, localRepository, recursive, settings,
|
||||
globalProfileManager, false );
|
||||
List collectedProjects =
|
||||
collectProjects( moduleFiles, localRepository, recursive, settings, globalProfileManager, false );
|
||||
projects.addAll( collectedProjects );
|
||||
project.setCollectedProjects( collectedProjects );
|
||||
}
|
||||
|
@ -498,8 +495,8 @@ public class DefaultMaven
|
|||
{
|
||||
if ( pom.length() == 0 )
|
||||
{
|
||||
throw new ProjectBuildingException(
|
||||
"unknown", "The file " + pom.getAbsolutePath() + " you specified has zero length." );
|
||||
throw new ProjectBuildingException( "unknown", "The file " + pom.getAbsolutePath() +
|
||||
" you specified has zero length." );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.apache.maven;
|
|||
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionResponse;
|
||||
import org.apache.maven.reactor.ReactorException;
|
||||
import org.apache.maven.reactor.MavenExecutionException;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
|
||||
|
@ -33,5 +33,5 @@ public interface Maven
|
|||
String RELEASE_POMv4 = "release-pom.xml";
|
||||
|
||||
MavenExecutionResponse execute( MavenExecutionRequest request )
|
||||
throws ReactorException, SettingsConfigurationException;
|
||||
throws MavenExecutionException, SettingsConfigurationException;
|
||||
}
|
|
@ -41,7 +41,7 @@ import org.apache.maven.monitor.event.EventDispatcher;
|
|||
import org.apache.maven.plugin.Mojo;
|
||||
import org.apache.maven.profiles.DefaultProfileManager;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
import org.apache.maven.reactor.ReactorException;
|
||||
import org.apache.maven.reactor.MavenExecutionException;
|
||||
import org.apache.maven.settings.MavenSettingsBuilder;
|
||||
import org.apache.maven.settings.RuntimeInfo;
|
||||
import org.apache.maven.settings.Settings;
|
||||
|
@ -250,7 +250,7 @@ public class MavenCli
|
|||
{
|
||||
response = maven.execute( request );
|
||||
}
|
||||
catch ( ReactorException e )
|
||||
catch ( MavenExecutionException e )
|
||||
{
|
||||
showFatalError( "Error executing Maven for a project", e, showErrors );
|
||||
return 1;
|
||||
|
@ -461,11 +461,11 @@ public class MavenCli
|
|||
{
|
||||
// TODO: release
|
||||
// TODO: something in plexus to show all active hooks?
|
||||
ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) embedder.lookup(
|
||||
ArtifactRepositoryLayout.ROLE, "default" );
|
||||
ArtifactRepositoryLayout repositoryLayout =
|
||||
(ArtifactRepositoryLayout) embedder.lookup( ArtifactRepositoryLayout.ROLE, "default" );
|
||||
|
||||
ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder.lookup(
|
||||
ArtifactRepositoryFactory.ROLE );
|
||||
ArtifactRepositoryFactory artifactRepositoryFactory =
|
||||
(ArtifactRepositoryFactory) embedder.lookup( ArtifactRepositoryFactory.ROLE );
|
||||
|
||||
String url = settings.getLocalRepository();
|
||||
|
||||
|
@ -677,7 +677,7 @@ public class MavenCli
|
|||
"Synonym for " + FORCE_PLUGIN_UPDATES ).create( FORCE_PLUGIN_UPDATES2 ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "no-plugin-updates" ).withDescription(
|
||||
"Suppress upToDate check for any relevant registered plugins" ).create( SUPPRESS_PLUGIN_UPDATES ) );
|
||||
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "no-plugin-registry" ).withDescription(
|
||||
"Don't use ~/.m2/plugin-registry.xml for plugin versions" ).create( SUPPRESS_PLUGIN_REGISTRY ) );
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
|||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.model.Extension;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.PlexusConstants;
|
||||
|
@ -53,8 +52,7 @@ public class DefaultExtensionManager
|
|||
private PlexusContainer container;
|
||||
|
||||
public void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException, PlexusContainerException, InvalidVersionSpecificationException,
|
||||
ArtifactNotFoundException
|
||||
throws ArtifactResolutionException, PlexusContainerException, ArtifactNotFoundException
|
||||
{
|
||||
String extensionId = ArtifactUtils.versionlessKey( extension.getGroupId(), extension.getArtifactId() );
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.maven.extension;
|
|||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.model.Extension;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.PlexusContainerException;
|
||||
|
@ -33,6 +32,5 @@ import org.codehaus.plexus.PlexusContainerException;
|
|||
public interface ExtensionManager
|
||||
{
|
||||
void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException, PlexusContainerException, InvalidVersionSpecificationException,
|
||||
ArtifactNotFoundException;
|
||||
throws ArtifactResolutionException, PlexusContainerException, ArtifactNotFoundException;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ package org.apache.maven.lifecycle;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.BuildFailureException;
|
||||
import org.apache.maven.artifact.handler.ArtifactHandler;
|
||||
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
@ -45,7 +46,6 @@ import org.apache.maven.plugin.lifecycle.Execution;
|
|||
import org.apache.maven.plugin.lifecycle.Phase;
|
||||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.reactor.ReactorException;
|
||||
import org.apache.maven.reporting.MavenReport;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.codehaus.plexus.PlexusContainerException;
|
||||
|
@ -129,31 +129,20 @@ public class DefaultLifecycleExecutor
|
|||
{
|
||||
if ( goals.isEmpty() )
|
||||
{
|
||||
// TODO: delete
|
||||
throw new NoGoalsSpecifiedException( "You must specify at least one goal. Try 'install'" );
|
||||
}
|
||||
|
||||
List taskSegments = segmentTaskListByAggregationNeeds( goals, session, rootProject );
|
||||
|
||||
// TODO: probably don't want to do all this up front
|
||||
for ( Iterator i = session.getSortedProjects().iterator(); i.hasNext(); )
|
||||
{
|
||||
MavenProject project = (MavenProject) i.next();
|
||||
|
||||
for ( Iterator j = project.getBuildExtensions().iterator(); j.hasNext(); )
|
||||
{
|
||||
Extension extension = (Extension) j.next();
|
||||
extensionManager.addExtension( extension, project, session.getLocalRepository() );
|
||||
}
|
||||
|
||||
Map handlers = findArtifactTypeHandlers( project, session.getSettings(), session.getLocalRepository() );
|
||||
artifactHandlerManager.addHandlers( handlers );
|
||||
}
|
||||
findExtensions( session );
|
||||
|
||||
executeTaskSegments( taskSegments, rm, session, rootProject, dispatcher, response );
|
||||
|
||||
if ( ReactorManager.FAIL_AT_END.equals( rm.getFailureBehavior() ) && rm.hasBuildFailures() )
|
||||
{
|
||||
response.setException( new ReactorException( "One or more projects failed to build." ) );
|
||||
response.setException( new BuildFailureException( "One or more projects failed to build." ) );
|
||||
}
|
||||
}
|
||||
catch ( MojoExecutionException e )
|
||||
|
@ -168,22 +157,6 @@ public class DefaultLifecycleExecutor
|
|||
{
|
||||
response.setException( e );
|
||||
}
|
||||
catch ( PlexusContainerException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Unable to initialise extensions", e );
|
||||
}
|
||||
catch ( PluginManagerException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Unable to initialise extensions", e );
|
||||
}
|
||||
catch ( PluginVersionResolutionException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Unable to initialise extensions", e );
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Unable to initialise extensions", e );
|
||||
}
|
||||
catch ( NoGoalsSpecifiedException e )
|
||||
{
|
||||
response.setException( e );
|
||||
|
@ -200,6 +173,31 @@ public class DefaultLifecycleExecutor
|
|||
return response;
|
||||
}
|
||||
|
||||
private void findExtensions( MavenSession session )
|
||||
throws ArtifactNotFoundException, ArtifactResolutionException, LifecycleExecutionException
|
||||
{
|
||||
for ( Iterator i = session.getSortedProjects().iterator(); i.hasNext(); )
|
||||
{
|
||||
MavenProject project = (MavenProject) i.next();
|
||||
|
||||
for ( Iterator j = project.getBuildExtensions().iterator(); j.hasNext(); )
|
||||
{
|
||||
Extension extension = (Extension) j.next();
|
||||
try
|
||||
{
|
||||
extensionManager.addExtension( extension, project, session.getLocalRepository() );
|
||||
}
|
||||
catch ( PlexusContainerException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Unable to initialise extensions", e );
|
||||
}
|
||||
}
|
||||
|
||||
Map handlers = findArtifactTypeHandlers( project, session.getSettings(), session.getLocalRepository() );
|
||||
artifactHandlerManager.addHandlers( handlers );
|
||||
}
|
||||
}
|
||||
|
||||
private void executeTaskSegments( List taskSegments, ReactorManager rm, MavenSession session,
|
||||
MavenProject rootProject, EventDispatcher dispatcher,
|
||||
MavenExecutionResponse response )
|
||||
|
@ -228,7 +226,8 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
long buildStartTime = System.currentTimeMillis();
|
||||
|
||||
dispatcher.dispatchStart( event, rootProject.getId() + " ( " + segment + " )" );
|
||||
String target = rootProject.getId() + " ( " + segment + " )";
|
||||
dispatcher.dispatchStart( event, target );
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -237,37 +236,17 @@ public class DefaultLifecycleExecutor
|
|||
{
|
||||
String task = (String) goalIterator.next();
|
||||
|
||||
try
|
||||
{
|
||||
executeGoal( task, session, rootProject, response );
|
||||
}
|
||||
catch ( MojoExecutionException e )
|
||||
{
|
||||
// TODO: should this be removed?
|
||||
handleExecutionFailure( rm, rootProject, e, task, buildStartTime );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
// TODO: should this be removed?
|
||||
handleExecutionFailure( rm, rootProject, e, task, buildStartTime );
|
||||
}
|
||||
catch ( MojoFailureException e )
|
||||
{
|
||||
handleExecutionFailure( rm, rootProject, e, task, buildStartTime );
|
||||
}
|
||||
catch ( ArtifactNotFoundException e )
|
||||
{
|
||||
handleExecutionFailure( rm, rootProject, e, task, buildStartTime );
|
||||
}
|
||||
executeGoalAndHandleFailures( task, session, rootProject, response, dispatcher, event, rm,
|
||||
buildStartTime, target );
|
||||
}
|
||||
|
||||
rm.registerBuildSuccess( rootProject, System.currentTimeMillis() - buildStartTime );
|
||||
|
||||
dispatcher.dispatchEnd( event, rootProject.getId() + " ( " + segment + " )" );
|
||||
dispatcher.dispatchEnd( event, target );
|
||||
}
|
||||
catch ( LifecycleExecutionException e )
|
||||
{
|
||||
dispatcher.dispatchError( event, rootProject.getId() + " ( " + segment + " )", e );
|
||||
dispatcher.dispatchError( event, target, e );
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
@ -313,7 +292,8 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
long buildStartTime = System.currentTimeMillis();
|
||||
|
||||
dispatcher.dispatchStart( event, currentProject.getId() + " ( " + segment + " )" );
|
||||
String target = currentProject.getId() + " ( " + segment + " )";
|
||||
dispatcher.dispatchStart( event, target );
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -321,37 +301,17 @@ public class DefaultLifecycleExecutor
|
|||
{
|
||||
String task = (String) goalIterator.next();
|
||||
|
||||
try
|
||||
{
|
||||
executeGoal( task, session, currentProject, response );
|
||||
}
|
||||
catch ( MojoExecutionException e )
|
||||
{
|
||||
// TODO: should this be removed?
|
||||
handleExecutionFailure( rm, currentProject, e, task, buildStartTime );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
// TODO: should this be removed?
|
||||
handleExecutionFailure( rm, currentProject, e, task, buildStartTime );
|
||||
}
|
||||
catch ( MojoFailureException e )
|
||||
{
|
||||
handleExecutionFailure( rm, currentProject, e, task, buildStartTime );
|
||||
}
|
||||
catch ( ArtifactNotFoundException e )
|
||||
{
|
||||
handleExecutionFailure( rm, currentProject, e, task, buildStartTime );
|
||||
}
|
||||
executeGoalAndHandleFailures( task, session, currentProject, response, dispatcher,
|
||||
event, rm, buildStartTime, target );
|
||||
}
|
||||
|
||||
rm.registerBuildSuccess( currentProject, System.currentTimeMillis() - buildStartTime );
|
||||
|
||||
dispatcher.dispatchEnd( event, currentProject.getId() + " ( " + segment + " )" );
|
||||
dispatcher.dispatchEnd( event, target );
|
||||
}
|
||||
catch ( LifecycleExecutionException e )
|
||||
{
|
||||
dispatcher.dispatchError( event, currentProject.getId() + " ( " + segment + " )", e );
|
||||
dispatcher.dispatchError( event, target, e );
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
@ -374,6 +334,44 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
}
|
||||
|
||||
private void executeGoalAndHandleFailures( String task, MavenSession session, MavenProject project,
|
||||
MavenExecutionResponse response, EventDispatcher dispatcher,
|
||||
String event, ReactorManager rm, long buildStartTime, String target )
|
||||
throws LifecycleExecutionException, MojoExecutionException, MojoFailureException, ArtifactNotFoundException,
|
||||
ArtifactResolutionException
|
||||
{
|
||||
try
|
||||
{
|
||||
executeGoal( task, session, project, response );
|
||||
}
|
||||
catch ( MojoExecutionException e )
|
||||
{
|
||||
dispatcher.dispatchError( event, target, e );
|
||||
|
||||
handleExecutionFailure( rm, project, e, task, buildStartTime );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
dispatcher.dispatchError( event, target, e );
|
||||
|
||||
handleExecutionFailure( rm, project, e, task, buildStartTime );
|
||||
}
|
||||
catch ( MojoFailureException e )
|
||||
{
|
||||
// TODO: should be dispatchFailure?
|
||||
dispatcher.dispatchError( event, target, e );
|
||||
|
||||
handleExecutionFailure( rm, project, e, task, buildStartTime );
|
||||
}
|
||||
catch ( ArtifactNotFoundException e )
|
||||
{
|
||||
// TODO: should be dispatchFailure?
|
||||
dispatcher.dispatchError( event, target, e );
|
||||
|
||||
handleExecutionFailure( rm, project, e, task, buildStartTime );
|
||||
}
|
||||
}
|
||||
|
||||
private void handleExecutionFailure( ReactorManager rm, MavenProject project, Exception e, String task,
|
||||
long buildStartTime )
|
||||
throws MojoExecutionException, MojoFailureException, ArtifactNotFoundException, ArtifactResolutionException
|
||||
|
@ -600,7 +598,8 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
catch ( PluginManagerException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Internal error in the plugin manager", e );
|
||||
throw new LifecycleExecutionException(
|
||||
"Internal error in the plugin manager executing goal '" + mojoDescriptor.getId(), e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -672,30 +671,19 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
List reportSets = reportPlugin.getReportSets();
|
||||
|
||||
try
|
||||
if ( reportSets == null || reportSets.isEmpty() )
|
||||
{
|
||||
if ( reportSets == null || reportSets.isEmpty() )
|
||||
reports.addAll( getReports( reportPlugin, null, project, session, mojoExecution ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( Iterator j = reportSets.iterator(); j.hasNext(); )
|
||||
{
|
||||
reports.addAll( getReports( reportPlugin, null, project, session, mojoExecution ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( Iterator j = reportSets.iterator(); j.hasNext(); )
|
||||
{
|
||||
ReportSet reportSet = (ReportSet) j.next();
|
||||
ReportSet reportSet = (ReportSet) j.next();
|
||||
|
||||
reports.addAll( getReports( reportPlugin, reportSet, project, session, mojoExecution ) );
|
||||
}
|
||||
reports.addAll( getReports( reportPlugin, reportSet, project, session, mojoExecution ) );
|
||||
}
|
||||
}
|
||||
catch ( PluginManagerException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Error getting reports", e );
|
||||
}
|
||||
catch ( PluginVersionResolutionException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Error getting reports", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
return reports;
|
||||
|
@ -703,10 +691,9 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
private List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session,
|
||||
MojoExecution mojoExecution )
|
||||
throws PluginManagerException, PluginVersionResolutionException, ArtifactResolutionException,
|
||||
ArtifactNotFoundException
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException, LifecycleExecutionException
|
||||
{
|
||||
PluginDescriptor pluginDescriptor = pluginManager.verifyReportPlugin( reportPlugin, project, session );
|
||||
PluginDescriptor pluginDescriptor = verifyReportPlugin( reportPlugin, project, session );
|
||||
|
||||
List reports = new ArrayList();
|
||||
for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); )
|
||||
|
@ -725,13 +712,21 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
MojoExecution reportExecution = new MojoExecution( mojoDescriptor, id );
|
||||
|
||||
MavenReport reportMojo = pluginManager.getReport( project, reportExecution, session );
|
||||
|
||||
// Comes back null if it was a plugin, not a report - these are mojos in the reporting plugins that are not reports
|
||||
if ( reportMojo != null )
|
||||
try
|
||||
{
|
||||
reports.add( reportMojo );
|
||||
mojoExecution.addMojoExecution( reportExecution );
|
||||
MavenReport reportMojo = pluginManager.getReport( project, reportExecution, session );
|
||||
|
||||
// Comes back null if it was a plugin, not a report - these are mojos in the reporting plugins that are not reports
|
||||
if ( reportMojo != null )
|
||||
{
|
||||
reports.add( reportMojo );
|
||||
mojoExecution.addMojoExecution( reportExecution );
|
||||
}
|
||||
}
|
||||
catch ( PluginManagerException e )
|
||||
{
|
||||
throw new LifecycleExecutionException(
|
||||
"Error getting reports from the plugin '" + reportPlugin.getKey() + "'", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -796,11 +791,13 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Unable to read lifecycle mapping file", e );
|
||||
throw new LifecycleExecutionException( "Unable to read lifecycle mapping file: " + e.getMessage(),
|
||||
e );
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Unable to parse lifecycle mapping file", e );
|
||||
throw new LifecycleExecutionException( "Unable to parse lifecycle mapping file: " + e.getMessage(),
|
||||
e );
|
||||
}
|
||||
|
||||
if ( lifecycleOverlay == null )
|
||||
|
@ -866,8 +863,8 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
if ( desc == null )
|
||||
{
|
||||
String message = "Required goal '" + goal + "' not found in plugin '" + pluginDescriptor.getGoalPrefix() +
|
||||
"'";
|
||||
String message =
|
||||
"Required goal '" + goal + "' not found in plugin '" + pluginDescriptor.getGoalPrefix() + "'";
|
||||
int index = goal.indexOf( ':' );
|
||||
if ( index >= 0 )
|
||||
{
|
||||
|
@ -889,8 +886,8 @@ public class DefaultLifecycleExecutor
|
|||
String mojoIdWithVersion = pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId() + ":" +
|
||||
pluginDescriptor.getVersion() + ":" + mojoDescriptor.getGoal();
|
||||
|
||||
String mojoIdWithoutVersion = pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId() + ":" +
|
||||
mojoDescriptor.getGoal();
|
||||
String mojoIdWithoutVersion =
|
||||
pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId() + ":" + mojoDescriptor.getGoal();
|
||||
|
||||
for ( Iterator it = lifecycleMappings.values().iterator(); it.hasNext(); )
|
||||
{
|
||||
|
@ -972,25 +969,11 @@ public class DefaultLifecycleExecutor
|
|||
String packaging = project.getPackaging();
|
||||
Map mappings = null;
|
||||
|
||||
try
|
||||
LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging,
|
||||
session.getSettings(), session.getLocalRepository() );
|
||||
if ( m != null )
|
||||
{
|
||||
LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging,
|
||||
session.getSettings(),
|
||||
session.getLocalRepository() );
|
||||
if ( m != null )
|
||||
{
|
||||
mappings = m.getPhases( lifecycle.getId() );
|
||||
}
|
||||
}
|
||||
catch ( PluginVersionResolutionException e )
|
||||
{
|
||||
throw new LifecycleExecutionException(
|
||||
"Cannot load extension plugin obtaining lifecycle mappings for: \'" + packaging + "\'.", e );
|
||||
}
|
||||
catch ( PluginManagerException e )
|
||||
{
|
||||
throw new LifecycleExecutionException(
|
||||
"Cannot load extension plugin obtaining lifecycle mappings for: \'" + packaging + "\'.", e );
|
||||
mappings = m.getPhases( lifecycle.getId() );
|
||||
}
|
||||
|
||||
Map defaultMappings = lifecycle.getDefaultPhases();
|
||||
|
@ -999,7 +982,7 @@ public class DefaultLifecycleExecutor
|
|||
{
|
||||
try
|
||||
{
|
||||
LifecycleMapping m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging );
|
||||
m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging );
|
||||
mappings = m.getPhases( lifecycle.getId() );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
|
@ -1030,8 +1013,7 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
private Object findExtension( MavenProject project, String role, String roleHint, Settings settings,
|
||||
ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException,
|
||||
ArtifactNotFoundException
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException, LifecycleExecutionException
|
||||
{
|
||||
for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
|
||||
{
|
||||
|
@ -1039,7 +1021,7 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
if ( plugin.isExtensions() )
|
||||
{
|
||||
pluginManager.verifyPlugin( plugin, project, settings, localRepository );
|
||||
verifyPlugin( plugin, project, settings, localRepository );
|
||||
|
||||
// TODO: if moved to the plugin manager we already have the descriptor from above and so do can lookup the container directly
|
||||
try
|
||||
|
@ -1050,6 +1032,11 @@ public class DefaultLifecycleExecutor
|
|||
{
|
||||
getLogger().debug( "Unable to find the lifecycle component in the extension", e );
|
||||
}
|
||||
catch ( PluginManagerException e )
|
||||
{
|
||||
throw new LifecycleExecutionException(
|
||||
"Error getting extensions from the plugin '" + plugin.getKey() + "'", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -1060,8 +1047,7 @@ public class DefaultLifecycleExecutor
|
|||
* lookup directly, or have them passed in
|
||||
*/
|
||||
private Map findArtifactTypeHandlers( MavenProject project, Settings settings, ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException,
|
||||
ArtifactNotFoundException
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException, LifecycleExecutionException
|
||||
{
|
||||
Map map = new HashMap();
|
||||
for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
|
||||
|
@ -1070,28 +1056,32 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
if ( plugin.isExtensions() )
|
||||
{
|
||||
pluginManager.verifyPlugin( plugin, project, settings, localRepository );
|
||||
verifyPlugin( plugin, project, settings, localRepository );
|
||||
|
||||
// TODO: if moved to the plugin manager we already have the descriptor from above and so do can lookup the container directly
|
||||
try
|
||||
{
|
||||
Map components = pluginManager.getPluginComponents( plugin, ArtifactHandler.ROLE );
|
||||
map.putAll( components );
|
||||
|
||||
// shudder...
|
||||
for ( Iterator j = map.values().iterator(); j.hasNext(); )
|
||||
{
|
||||
ArtifactHandler handler = (ArtifactHandler) j.next();
|
||||
if ( project.getPackaging().equals( handler.getPackaging() ) )
|
||||
{
|
||||
project.getArtifact().setArtifactHandler( handler );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
getLogger().debug( "Unable to find the lifecycle component in the extension", e );
|
||||
}
|
||||
catch ( PluginManagerException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Error looking up available components from a plugin", e );
|
||||
}
|
||||
|
||||
// shudder...
|
||||
for ( Iterator j = map.values().iterator(); j.hasNext(); )
|
||||
{
|
||||
ArtifactHandler handler = (ArtifactHandler) j.next();
|
||||
if ( project.getPackaging().equals( handler.getPackaging() ) )
|
||||
{
|
||||
project.getArtifact().setArtifactHandler( handler );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
|
@ -1111,7 +1101,7 @@ public class DefaultLifecycleExecutor
|
|||
PluginDescriptor pluginDescriptor;
|
||||
Settings settings = session.getSettings();
|
||||
|
||||
pluginDescriptor = verifyPlugin( plugin, session, project );
|
||||
pluginDescriptor = verifyPlugin( plugin, project, session.getSettings(), session.getLocalRepository() );
|
||||
|
||||
if ( pluginDescriptor.getMojos() != null && !pluginDescriptor.getMojos().isEmpty() )
|
||||
{
|
||||
|
@ -1139,14 +1129,14 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
}
|
||||
|
||||
private PluginDescriptor verifyPlugin( Plugin plugin, MavenSession session, MavenProject project )
|
||||
private PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
|
||||
ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException
|
||||
{
|
||||
PluginDescriptor pluginDescriptor;
|
||||
try
|
||||
{
|
||||
ArtifactRepository localRepository = session.getLocalRepository();
|
||||
pluginDescriptor = pluginManager.verifyPlugin( plugin, project, session.getSettings(), localRepository );
|
||||
pluginDescriptor = pluginManager.verifyPlugin( plugin, project, settings, localRepository );
|
||||
}
|
||||
catch ( PluginManagerException e )
|
||||
{
|
||||
|
@ -1156,6 +1146,33 @@ public class DefaultLifecycleExecutor
|
|||
{
|
||||
throw new LifecycleExecutionException( "Error resolving plugin version", e );
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Error resolving plugin version", e );
|
||||
}
|
||||
return pluginDescriptor;
|
||||
}
|
||||
|
||||
private PluginDescriptor verifyReportPlugin( ReportPlugin plugin, MavenProject project, MavenSession session )
|
||||
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException
|
||||
{
|
||||
PluginDescriptor pluginDescriptor;
|
||||
try
|
||||
{
|
||||
pluginDescriptor = pluginManager.verifyReportPlugin( plugin, project, session );
|
||||
}
|
||||
catch ( PluginManagerException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Internal error in the plugin manager", e );
|
||||
}
|
||||
catch ( PluginVersionResolutionException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Error resolving plugin version", e );
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Error resolving plugin version", e );
|
||||
}
|
||||
return pluginDescriptor;
|
||||
}
|
||||
|
||||
|
@ -1302,22 +1319,11 @@ public class DefaultLifecycleExecutor
|
|||
{
|
||||
Plugin buildPlugin = (Plugin) i.next();
|
||||
|
||||
try
|
||||
PluginDescriptor desc =
|
||||
verifyPlugin( buildPlugin, project, session.getSettings(), session.getLocalRepository() );
|
||||
if ( prefix.equals( desc.getGoalPrefix() ) )
|
||||
{
|
||||
PluginDescriptor desc = pluginManager.verifyPlugin( buildPlugin, project, session.getSettings(),
|
||||
session.getLocalRepository() );
|
||||
if ( prefix.equals( desc.getGoalPrefix() ) )
|
||||
{
|
||||
plugin = buildPlugin;
|
||||
}
|
||||
}
|
||||
catch ( PluginManagerException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Internal error in the plugin manager", e );
|
||||
}
|
||||
catch ( PluginVersionResolutionException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Error resolving plugin version", e );
|
||||
plugin = buildPlugin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1364,19 +1370,7 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
if ( pluginDescriptor == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
pluginDescriptor = pluginManager.verifyPlugin( plugin, project, session.getSettings(),
|
||||
session.getLocalRepository() );
|
||||
}
|
||||
catch ( PluginManagerException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Internal error in the plugin manager", e );
|
||||
}
|
||||
catch ( PluginVersionResolutionException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Error resolving plugin version", e );
|
||||
}
|
||||
pluginDescriptor = verifyPlugin( plugin, project, session.getSettings(), session.getLocalRepository() );
|
||||
}
|
||||
|
||||
// this has been simplified from the old code that injected the plugin management stuff, since
|
||||
|
|
|
@ -148,7 +148,7 @@ public class DefaultPluginManager
|
|||
public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
|
||||
ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException,
|
||||
ArtifactNotFoundException
|
||||
ArtifactNotFoundException, InvalidVersionSpecificationException
|
||||
{
|
||||
// TODO: this should be possibly outside
|
||||
// All version-resolution logic has been moved to DefaultPluginVersionManager.
|
||||
|
@ -165,7 +165,7 @@ public class DefaultPluginManager
|
|||
private PluginDescriptor verifyVersionedPlugin( Plugin plugin, MavenProject project,
|
||||
ArtifactRepository localRepository )
|
||||
throws PluginVersionResolutionException, PluginManagerException, ArtifactNotFoundException,
|
||||
ArtifactResolutionException
|
||||
ArtifactResolutionException, InvalidVersionSpecificationException
|
||||
{
|
||||
// TODO: this might result in an artifact "RELEASE" being resolved continuously
|
||||
// FIXME: need to find out how a plugin gets marked as 'installed'
|
||||
|
@ -180,35 +180,31 @@ public class DefaultPluginManager
|
|||
remoteRepositories.addAll( project.getRemoteArtifactRepositories() );
|
||||
|
||||
checkRequiredMavenVersion( plugin, localRepository, remoteRepositories );
|
||||
|
||||
Artifact pluginArtifact = artifactFactory.createPluginArtifact( plugin.getGroupId(),
|
||||
plugin.getArtifactId(), versionRange );
|
||||
|
||||
|
||||
Artifact pluginArtifact =
|
||||
artifactFactory.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), versionRange );
|
||||
|
||||
pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact );
|
||||
|
||||
artifactResolver.resolve( pluginArtifact, project.getPluginArtifactRepositories(), localRepository );
|
||||
|
||||
if ( !pluginArtifact.isResolved() )
|
||||
{
|
||||
throw new PluginContainerException( plugin, "Cannot resolve artifact for plugin." );
|
||||
}
|
||||
|
||||
PlexusContainer pluginContainer = container.getChildContainer( plugin.getKey() );
|
||||
|
||||
|
||||
File pluginFile = pluginArtifact.getFile();
|
||||
|
||||
|
||||
if ( !pluginCollector.isPluginInstalled( plugin ) || pluginContainer == null )
|
||||
{
|
||||
addPlugin( plugin, pluginArtifact, project, localRepository );
|
||||
}
|
||||
else if ( pluginFile.lastModified() > pluginContainer.getCreationDate().getTime() )
|
||||
{
|
||||
getLogger().info( "Reloading plugin container for: " + plugin.getKey() + ". The plugin artifact has changed." );
|
||||
|
||||
getLogger().info(
|
||||
"Reloading plugin container for: " + plugin.getKey() + ". The plugin artifact has changed." );
|
||||
|
||||
pluginContainer.dispose();
|
||||
|
||||
|
||||
pluginCollector.flushPluginDescriptor( plugin );
|
||||
|
||||
|
||||
addPlugin( plugin, pluginArtifact, project, localRepository );
|
||||
}
|
||||
|
||||
|
@ -234,12 +230,7 @@ public class DefaultPluginManager
|
|||
throw e;
|
||||
}
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new PluginVersionResolutionException( plugin.getGroupId(), plugin.getArtifactId(),
|
||||
"Invalid version specification", e );
|
||||
}
|
||||
|
||||
|
||||
return pluginCollector.getPluginDescriptor( plugin );
|
||||
}
|
||||
|
||||
|
@ -254,13 +245,13 @@ public class DefaultPluginManager
|
|||
{
|
||||
Artifact artifact = artifactFactory.createProjectArtifact( plugin.getGroupId(), plugin.getArtifactId(),
|
||||
plugin.getVersion() );
|
||||
MavenProject project = mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories,
|
||||
localRepository, false );
|
||||
MavenProject project =
|
||||
mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository, false );
|
||||
// if we don't have the required Maven version, then ignore an update
|
||||
if ( project.getPrerequisites() != null && project.getPrerequisites().getMaven() != null )
|
||||
{
|
||||
DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion(
|
||||
project.getPrerequisites().getMaven() );
|
||||
DefaultArtifactVersion requiredVersion =
|
||||
new DefaultArtifactVersion( project.getPrerequisites().getMaven() );
|
||||
if ( runtimeInformation.getApplicationVersion().compareTo( requiredVersion ) < 0 )
|
||||
{
|
||||
throw new PluginVersionResolutionException( plugin.getGroupId(), plugin.getArtifactId(),
|
||||
|
@ -293,7 +284,7 @@ public class DefaultPluginManager
|
|||
}
|
||||
catch ( PlexusContainerException e )
|
||||
{
|
||||
throw new PluginContainerException( plugin, "Failed to create plugin container.", e );
|
||||
throw new PluginManagerException( "Failed to create plugin container for plugin '" + plugin + "'", e );
|
||||
}
|
||||
|
||||
// this plugin's descriptor should have been discovered in the child creation, so we should be able to
|
||||
|
@ -309,13 +300,14 @@ public class DefaultPluginManager
|
|||
|
||||
try
|
||||
{
|
||||
Set artifacts = MavenMetadataSource.createArtifacts( artifactFactory, plugin.getDependencies(), null, null,
|
||||
project );
|
||||
Set artifacts =
|
||||
MavenMetadataSource.createArtifacts( artifactFactory, plugin.getDependencies(), null, null, project );
|
||||
|
||||
addedPlugin.setIntroducedDependencyArtifacts( artifacts );
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
catch ( ProjectBuildingException e )
|
||||
{
|
||||
throw new PluginManagerException( "Unable to get one of the plugins additional dependencies", e );
|
||||
throw new PluginManagerException( "Error getting plugin dependencies", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -360,8 +352,16 @@ public class DefaultPluginManager
|
|||
for ( Iterator i = projects.iterator(); i.hasNext(); )
|
||||
{
|
||||
MavenProject p = (MavenProject) i.next();
|
||||
resolveTransitiveDependencies( session, artifactResolver,
|
||||
mojoDescriptor.isDependencyResolutionRequired(), artifactFactory, p );
|
||||
try
|
||||
{
|
||||
resolveTransitiveDependencies( session, artifactResolver,
|
||||
mojoDescriptor.isDependencyResolutionRequired(), artifactFactory,
|
||||
p );
|
||||
}
|
||||
catch ( ProjectBuildingException e )
|
||||
{
|
||||
throw new PluginManagerException( e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
|
||||
downloadDependencies( project, session, artifactResolver );
|
||||
|
@ -485,7 +485,7 @@ public class DefaultPluginManager
|
|||
|
||||
public PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session )
|
||||
throws PluginVersionResolutionException, ArtifactResolutionException, PluginManagerException,
|
||||
ArtifactNotFoundException
|
||||
ArtifactNotFoundException, InvalidVersionSpecificationException
|
||||
{
|
||||
String version = reportPlugin.getVersion();
|
||||
|
||||
|
@ -518,7 +518,7 @@ public class DefaultPluginManager
|
|||
{
|
||||
throw new PluginManagerException( "Cannot find PlexusContainer for plugin: " + pluginKey );
|
||||
}
|
||||
|
||||
|
||||
return pluginContainer;
|
||||
}
|
||||
|
||||
|
@ -578,8 +578,8 @@ public class DefaultPluginManager
|
|||
project,
|
||||
session.getExecutionProperties() );
|
||||
|
||||
PlexusConfiguration extractedMojoConfiguration = extractMojoConfiguration( mergedConfiguration,
|
||||
mojoDescriptor );
|
||||
PlexusConfiguration extractedMojoConfiguration =
|
||||
extractMojoConfiguration( mergedConfiguration, mojoDescriptor );
|
||||
|
||||
checkRequiredParameters( mojoDescriptor, extractedMojoConfiguration, expressionEvaluator );
|
||||
|
||||
|
@ -671,8 +671,8 @@ public class DefaultPluginManager
|
|||
|
||||
if ( artifactFile == null )
|
||||
{
|
||||
String resource = "/META-INF/maven/" + artifact.getGroupId() + "/" + artifact.getArtifactId() +
|
||||
"/pom.xml";
|
||||
String resource =
|
||||
"/META-INF/maven/" + artifact.getGroupId() + "/" + artifact.getArtifactId() + "/pom.xml";
|
||||
|
||||
URL resourceUrl = container.getContainerRealm().getResource( resource );
|
||||
|
||||
|
@ -801,7 +801,7 @@ public class DefaultPluginManager
|
|||
}
|
||||
catch ( ExpressionEvaluationException e )
|
||||
{
|
||||
throw new PluginConfigurationException( goal.getPluginDescriptor(), "Bad expression", e );
|
||||
throw new PluginConfigurationException( goal.getPluginDescriptor(), e.getMessage(), e );
|
||||
}
|
||||
|
||||
// only mark as invalid if there are no child nodes
|
||||
|
@ -1045,8 +1045,8 @@ public class DefaultPluginManager
|
|||
// so that this meethod could entirely be handled by a plexus lookup?
|
||||
if ( StringUtils.isNotEmpty( configuratorId ) )
|
||||
{
|
||||
configurator = (ComponentConfigurator) pluginContainer.lookup( ComponentConfigurator.ROLE,
|
||||
configuratorId );
|
||||
configurator =
|
||||
(ComponentConfigurator) pluginContainer.lookup( ComponentConfigurator.ROLE, configuratorId );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1155,7 +1155,7 @@ public class DefaultPluginManager
|
|||
|
||||
private void resolveTransitiveDependencies( MavenSession context, ArtifactResolver artifactResolver, String scope,
|
||||
ArtifactFactory artifactFactory, MavenProject project )
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException, ProjectBuildingException
|
||||
{
|
||||
ArtifactFilter filter = new ScopeArtifactFilter( scope );
|
||||
|
||||
|
@ -1165,18 +1165,10 @@ public class DefaultPluginManager
|
|||
|
||||
// TODO: we don't need to resolve over and over again, as long as we are sure that the parameters are the same
|
||||
// check this with yourkit as a hot spot.
|
||||
try
|
||||
// Don't recreate if already created - for effeciency, and because clover plugin adds to it
|
||||
if ( project.getDependencyArtifacts() == null )
|
||||
{
|
||||
// Don't recreate if already created - for effeciency, and because clover plugin adds to it
|
||||
if ( project.getDependencyArtifacts() == null )
|
||||
{
|
||||
project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) );
|
||||
}
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
// TODO: should that exception be derived from ArtifactResolutionException instead?
|
||||
throw new ArtifactResolutionException( e.getMessage(), artifact );
|
||||
project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) );
|
||||
}
|
||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(),
|
||||
artifact, context.getLocalRepository(),
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package org.apache.maven.plugin;
|
||||
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
|
@ -18,6 +16,25 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.usability.diagnostics.DiagnosisUtils;
|
||||
import org.apache.maven.usability.plugin.Expression;
|
||||
import org.apache.maven.usability.plugin.ExpressionDocumentationException;
|
||||
import org.apache.maven.usability.plugin.ExpressionDocumenter;
|
||||
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
|
||||
import org.codehaus.plexus.configuration.PlexusConfiguration;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
|
@ -26,8 +43,12 @@ public class PluginConfigurationException
|
|||
extends Exception
|
||||
{
|
||||
private final PluginDescriptor pluginDescriptor;
|
||||
|
||||
private String originalMessage;
|
||||
|
||||
private static final List UNMODIFIABLE_EXPRESSIONS = Arrays.asList(
|
||||
new String[]{"localRepository", "reactorProjects", "settings", "project", "session", "plugin", "basedir"} );
|
||||
|
||||
public PluginConfigurationException( PluginDescriptor pluginDescriptor, String message )
|
||||
{
|
||||
super( "Error configuring: " + pluginDescriptor.getPluginLookupKey() + ". Reason: " + message );
|
||||
|
@ -47,14 +68,217 @@ public class PluginConfigurationException
|
|||
this.pluginDescriptor = pluginDescriptor;
|
||||
this.originalMessage = message;
|
||||
}
|
||||
|
||||
|
||||
public PluginDescriptor getPluginDescriptor()
|
||||
{
|
||||
return pluginDescriptor;
|
||||
}
|
||||
|
||||
|
||||
public String getOriginalMessage()
|
||||
{
|
||||
return originalMessage;
|
||||
}
|
||||
|
||||
protected static void addParameterUsageInfo( String expression, StringBuffer messageBuffer )
|
||||
{
|
||||
StringBuffer expressionMessageBuffer = new StringBuffer();
|
||||
|
||||
Matcher exprMatcher = Pattern.compile( "\\$\\{(.+)\\}" ).matcher( expression );
|
||||
|
||||
boolean unmodifiableElementsFound = false;
|
||||
boolean activeElementsFound = false;
|
||||
|
||||
int elementCount = 0;
|
||||
|
||||
while ( exprMatcher.find() )
|
||||
{
|
||||
elementCount++;
|
||||
|
||||
activeElementsFound = true;
|
||||
|
||||
String subExpression = exprMatcher.group( 1 );
|
||||
|
||||
StringTokenizer expressionParts = new StringTokenizer( subExpression, "." );
|
||||
|
||||
String firstPart = expressionParts.nextToken();
|
||||
|
||||
Map expressions = null;
|
||||
try
|
||||
{
|
||||
expressions = ExpressionDocumenter.load();
|
||||
}
|
||||
catch ( ExpressionDocumentationException e )
|
||||
{
|
||||
expressionMessageBuffer.append( "\n\nERROR!! Failed to load expression documentation!" );
|
||||
|
||||
StringWriter sWriter = new StringWriter();
|
||||
PrintWriter pWriter = new PrintWriter( sWriter );
|
||||
|
||||
e.printStackTrace( pWriter );
|
||||
|
||||
expressionMessageBuffer.append( "\n\nException:\n\n" ).append( sWriter.toString() );
|
||||
}
|
||||
|
||||
if ( expressions != null )
|
||||
{
|
||||
Expression expr = (Expression) expressions.get( subExpression );
|
||||
|
||||
if ( expr != null )
|
||||
{
|
||||
if ( !expr.isEditable() )
|
||||
{
|
||||
unmodifiableElementsFound = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
addParameterConfigDocumentation( firstPart, exprMatcher.group( 0 ), subExpression,
|
||||
expressionMessageBuffer, expressions );
|
||||
}
|
||||
}
|
||||
else if ( UNMODIFIABLE_EXPRESSIONS.contains( subExpression ) )
|
||||
{
|
||||
unmodifiableElementsFound = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
expressionMessageBuffer.append( "on the command line, specify: \'-D" ).append( subExpression )
|
||||
.append( "=VALUE\'" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( activeElementsFound )
|
||||
{
|
||||
messageBuffer.append( expressionMessageBuffer );
|
||||
}
|
||||
else
|
||||
{
|
||||
messageBuffer.append(
|
||||
" (found static expression: \'" + expression + "\' which may act as a default value).\n" );
|
||||
}
|
||||
|
||||
if ( unmodifiableElementsFound )
|
||||
{
|
||||
if ( elementCount > 1 )
|
||||
{
|
||||
messageBuffer.append( " " );
|
||||
}
|
||||
|
||||
messageBuffer
|
||||
.append( "NOTE: One or more purely derived expression elements were detected in \'" + expression +
|
||||
"\'.\n If you continue to get this error after any other expression elements are specified correctly," +
|
||||
"\n please report this issue to the Maven development team.\n" );
|
||||
}
|
||||
}
|
||||
|
||||
private static void addParameterConfigDocumentation( String firstPart, String wholeExpression, String subExpression,
|
||||
StringBuffer expressionMessageBuffer, Map expressionDoco )
|
||||
{
|
||||
Expression expr = (Expression) expressionDoco.get( subExpression );
|
||||
|
||||
if ( expr != null )
|
||||
{
|
||||
expressionMessageBuffer.append( "check that the following section of " );
|
||||
if ( "project".equals( firstPart ) )
|
||||
{
|
||||
expressionMessageBuffer.append( "the pom.xml " );
|
||||
}
|
||||
else if ( "settings".equals( firstPart ) )
|
||||
{
|
||||
expressionMessageBuffer.append( "your ~/.m2/settings.xml file " );
|
||||
}
|
||||
|
||||
expressionMessageBuffer.append( "is present and correct:\n\n" );
|
||||
|
||||
String message = expr.getConfiguration();
|
||||
|
||||
if ( message == null )
|
||||
{
|
||||
message = expr.getDescription();
|
||||
}
|
||||
|
||||
expressionMessageBuffer.append( message );
|
||||
|
||||
Properties cliConfig = expr.getCliOptions();
|
||||
|
||||
if ( cliConfig != null && !cliConfig.isEmpty() )
|
||||
{
|
||||
expressionMessageBuffer.append( "\n\n-OR-\n\nUse the following command-line switches:\n" );
|
||||
|
||||
prettyPrintCommandLineSwitches( cliConfig, '.', expressionMessageBuffer );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
expressionMessageBuffer.append( "ensure that the expression: \'" + wholeExpression + "\' is satisfied" );
|
||||
}
|
||||
}
|
||||
|
||||
private static void prettyPrintCommandLineSwitches( Properties switches, char filler,
|
||||
StringBuffer expressionMessageBuffer )
|
||||
{
|
||||
int maxKeyLen = 0;
|
||||
|
||||
for ( Iterator it = switches.entrySet().iterator(); it.hasNext(); )
|
||||
{
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
|
||||
String key = (String) entry.getKey();
|
||||
|
||||
int keyLen = key.length();
|
||||
if ( keyLen > maxKeyLen )
|
||||
{
|
||||
maxKeyLen = keyLen;
|
||||
}
|
||||
}
|
||||
|
||||
final int minFillerCount = 4;
|
||||
|
||||
for ( Iterator it = switches.entrySet().iterator(); it.hasNext(); )
|
||||
{
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
|
||||
String key = (String) entry.getKey();
|
||||
|
||||
int keyLen = key.length();
|
||||
|
||||
int fillerCount = maxKeyLen - keyLen + minFillerCount;
|
||||
|
||||
expressionMessageBuffer.append( '\n' ).append( key ).append( ' ' );
|
||||
|
||||
for ( int i = 0; i < fillerCount; i++ )
|
||||
{
|
||||
expressionMessageBuffer.append( filler );
|
||||
}
|
||||
|
||||
expressionMessageBuffer.append( ' ' ).append( entry.getValue() );
|
||||
}
|
||||
|
||||
expressionMessageBuffer.append( '\n' );
|
||||
}
|
||||
|
||||
public String buildConfigurationDiagnosticMessage( ComponentConfigurationException cce )
|
||||
{
|
||||
StringBuffer message = new StringBuffer();
|
||||
|
||||
PluginDescriptor descriptor = getPluginDescriptor();
|
||||
|
||||
PlexusConfiguration failedConfiguration = cce.getFailedConfiguration();
|
||||
|
||||
message.append( "Failed to configure plugin parameters for: " + descriptor.getId() + "\n\n" );
|
||||
|
||||
if ( failedConfiguration != null )
|
||||
{
|
||||
String value = failedConfiguration.getValue( null );
|
||||
addParameterUsageInfo( value, message );
|
||||
}
|
||||
|
||||
message.append( "Reason: " ).append( cce.getMessage() ).append( "\n" );
|
||||
|
||||
Throwable root = DiagnosisUtils.getRootCause( cce );
|
||||
|
||||
message.append( "Root Cause: " ).append( root.getMessage() ).append( "\n\n" );
|
||||
|
||||
return message.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
package org.apache.maven.plugin;
|
||||
|
||||
import org.apache.maven.model.Plugin;
|
||||
|
||||
public class PluginContainerException
|
||||
extends PluginManagerException
|
||||
{
|
||||
|
||||
private final Plugin plugin;
|
||||
private final String originalMessage;
|
||||
|
||||
public PluginContainerException( Plugin plugin, String message, Exception e )
|
||||
{
|
||||
super( "Error configuring container for: " + plugin.getKey() + ". Message was: " + message, e );
|
||||
|
||||
this.plugin = plugin;
|
||||
this.originalMessage = message;
|
||||
}
|
||||
|
||||
public PluginContainerException( Plugin plugin, String message )
|
||||
{
|
||||
super( "Error configuring container for: " + plugin.getKey() + ". Message was: " + message );
|
||||
|
||||
this.plugin = plugin;
|
||||
this.originalMessage = message;
|
||||
}
|
||||
|
||||
public String getOriginalMessage()
|
||||
{
|
||||
return originalMessage;
|
||||
}
|
||||
|
||||
public Plugin getPlugin()
|
||||
{
|
||||
return plugin;
|
||||
}
|
||||
|
||||
}
|
|
@ -19,6 +19,7 @@ package org.apache.maven.plugin;
|
|||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.ReportPlugin;
|
||||
|
@ -54,11 +55,11 @@ public interface PluginManager
|
|||
PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
|
||||
ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException,
|
||||
ArtifactNotFoundException;
|
||||
ArtifactNotFoundException, InvalidVersionSpecificationException;
|
||||
|
||||
PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session )
|
||||
throws PluginVersionResolutionException, ArtifactResolutionException, PluginManagerException,
|
||||
ArtifactNotFoundException;
|
||||
ArtifactNotFoundException, InvalidVersionSpecificationException;
|
||||
|
||||
Object getPluginComponent( Plugin plugin, String role, String roleHint )
|
||||
throws ComponentLookupException, PluginManagerException;
|
||||
|
|
|
@ -17,7 +17,10 @@ package org.apache.maven.plugin;
|
|||
*/
|
||||
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.Parameter;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class PluginParameterException
|
||||
|
@ -30,7 +33,8 @@ public class PluginParameterException
|
|||
|
||||
public PluginParameterException( MojoDescriptor mojo, List parameters )
|
||||
{
|
||||
super( mojo.getPluginDescriptor(), "Invalid or missing parameters: " + parameters + " for mojo: " + mojo.getRoleHint() );
|
||||
super( mojo.getPluginDescriptor(),
|
||||
"Invalid or missing parameters: " + parameters + " for mojo: " + mojo.getRoleHint() );
|
||||
|
||||
this.mojo = mojo;
|
||||
|
||||
|
@ -39,7 +43,8 @@ public class PluginParameterException
|
|||
|
||||
public PluginParameterException( MojoDescriptor mojo, List parameters, Throwable cause )
|
||||
{
|
||||
super( mojo.getPluginDescriptor(), "Invalid or missing parameters: " + parameters + " for mojo: " + mojo.getRoleHint(), cause );
|
||||
super( mojo.getPluginDescriptor(),
|
||||
"Invalid or missing parameters: " + parameters + " for mojo: " + mojo.getRoleHint(), cause );
|
||||
|
||||
this.mojo = mojo;
|
||||
|
||||
|
@ -56,4 +61,63 @@ public class PluginParameterException
|
|||
return parameters;
|
||||
}
|
||||
|
||||
private static void decomposeParameterIntoUserInstructions( MojoDescriptor mojo, Parameter param,
|
||||
StringBuffer messageBuffer )
|
||||
{
|
||||
String expression = param.getExpression();
|
||||
|
||||
if ( param.isEditable() )
|
||||
{
|
||||
messageBuffer.append( "inside the definition for plugin: \'" + mojo.getPluginDescriptor().getArtifactId() +
|
||||
"\'specify the following:\n\n<configuration>\n ...\n <" + param.getName() + ">VALUE</" +
|
||||
param.getName() + ">\n</configuration>" );
|
||||
|
||||
String alias = param.getAlias();
|
||||
if ( StringUtils.isNotEmpty( alias ) )
|
||||
{
|
||||
messageBuffer.append(
|
||||
"\n\n-OR-\n\n<configuration>\n ...\n <" + alias + ">VALUE</" + alias + ">\n</configuration>\n" );
|
||||
}
|
||||
}
|
||||
|
||||
if ( StringUtils.isEmpty( expression ) )
|
||||
{
|
||||
messageBuffer.append( "." );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( param.isEditable() )
|
||||
{
|
||||
messageBuffer.append( "\n\n-OR-\n\n" );
|
||||
}
|
||||
|
||||
addParameterUsageInfo( expression, messageBuffer );
|
||||
}
|
||||
}
|
||||
|
||||
public String buildDiagnosticMessage()
|
||||
{
|
||||
StringBuffer messageBuffer = new StringBuffer();
|
||||
|
||||
List params = getParameters();
|
||||
MojoDescriptor mojo = getMojoDescriptor();
|
||||
|
||||
messageBuffer.append( "One or more required plugin parameters are invalid/missing for \'" )
|
||||
.append( mojo.getPluginDescriptor().getGoalPrefix() ).append( ":" ).append( mojo.getGoal() )
|
||||
.append( "\'\n" );
|
||||
|
||||
int idx = 0;
|
||||
for ( Iterator it = params.iterator(); it.hasNext(); idx++ )
|
||||
{
|
||||
Parameter param = (Parameter) it.next();
|
||||
|
||||
messageBuffer.append( "\n[" ).append( idx ).append( "] " );
|
||||
|
||||
decomposeParameterIntoUserInstructions( mojo, param, messageBuffer );
|
||||
|
||||
messageBuffer.append( "\n" );
|
||||
}
|
||||
|
||||
return messageBuffer.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.maven.plugin.version;
|
|||
public class PluginVersionResolutionException
|
||||
extends Exception
|
||||
{
|
||||
|
||||
private final String groupId;
|
||||
|
||||
private final String artifactId;
|
||||
|
|
|
@ -20,24 +20,24 @@ package org.apache.maven.reactor;
|
|||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ReactorException
|
||||
public class MavenExecutionException
|
||||
extends Exception
|
||||
{
|
||||
public ReactorException()
|
||||
public MavenExecutionException()
|
||||
{
|
||||
}
|
||||
|
||||
public ReactorException( String message )
|
||||
public MavenExecutionException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
public ReactorException( Throwable cause )
|
||||
public MavenExecutionException( Throwable cause )
|
||||
{
|
||||
super( cause );
|
||||
}
|
||||
|
||||
public ReactorException( String message, Throwable cause )
|
||||
public MavenExecutionException( String message, Throwable cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
|
@ -18,50 +18,13 @@ package org.apache.maven.usability;
|
|||
|
||||
import org.apache.maven.plugin.PluginConfigurationException;
|
||||
import org.apache.maven.plugin.PluginParameterException;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.Parameter;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.usability.diagnostics.DiagnosisUtils;
|
||||
import org.apache.maven.usability.diagnostics.ErrorDiagnoser;
|
||||
import org.apache.maven.usability.plugin.Expression;
|
||||
import org.apache.maven.usability.plugin.ExpressionDocumentationException;
|
||||
import org.apache.maven.usability.plugin.ExpressionDocumenter;
|
||||
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
|
||||
import org.codehaus.plexus.configuration.PlexusConfiguration;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PluginConfigurationDiagnoser
|
||||
implements ErrorDiagnoser
|
||||
{
|
||||
|
||||
private static final List UNMODIFIABLE_EXPRESSIONS;
|
||||
|
||||
static
|
||||
{
|
||||
List exprs = new ArrayList();
|
||||
|
||||
exprs.add( "localRepository" );
|
||||
exprs.add( "reactorProjects" );
|
||||
exprs.add( "settings" );
|
||||
exprs.add( "project" );
|
||||
exprs.add( "session" );
|
||||
exprs.add( "plugin" );
|
||||
exprs.add( "basedir" );
|
||||
|
||||
UNMODIFIABLE_EXPRESSIONS = exprs;
|
||||
}
|
||||
|
||||
public boolean canDiagnose( Throwable error )
|
||||
{
|
||||
return DiagnosisUtils.containsInCausality( error, PluginConfigurationException.class );
|
||||
|
@ -69,287 +32,25 @@ public class PluginConfigurationDiagnoser
|
|||
|
||||
public String diagnose( Throwable error )
|
||||
{
|
||||
PluginConfigurationException pce = (PluginConfigurationException) DiagnosisUtils
|
||||
.getFromCausality( error, PluginConfigurationException.class );
|
||||
PluginConfigurationException pce =
|
||||
(PluginConfigurationException) DiagnosisUtils.getFromCausality( error, PluginConfigurationException.class );
|
||||
|
||||
if ( pce instanceof PluginParameterException )
|
||||
{
|
||||
PluginParameterException exception = (PluginParameterException) pce;
|
||||
|
||||
return buildParameterDiagnosticMessage( exception );
|
||||
return exception.buildDiagnosticMessage();
|
||||
}
|
||||
else if ( DiagnosisUtils.containsInCausality( pce, ComponentConfigurationException.class ) )
|
||||
{
|
||||
ComponentConfigurationException cce = (ComponentConfigurationException) DiagnosisUtils
|
||||
.getFromCausality( pce, ComponentConfigurationException.class );
|
||||
|
||||
return buildConfigurationDiagnosticMessage( pce, cce );
|
||||
ComponentConfigurationException cce = (ComponentConfigurationException) DiagnosisUtils.getFromCausality(
|
||||
pce, ComponentConfigurationException.class );
|
||||
|
||||
return pce.buildConfigurationDiagnosticMessage( cce );
|
||||
}
|
||||
else
|
||||
{
|
||||
return pce.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
private String buildConfigurationDiagnosticMessage( PluginConfigurationException pce, ComponentConfigurationException cce )
|
||||
{
|
||||
StringBuffer message = new StringBuffer();
|
||||
|
||||
PluginDescriptor descriptor = pce.getPluginDescriptor();
|
||||
|
||||
PlexusConfiguration failedConfiguration = cce.getFailedConfiguration();
|
||||
|
||||
message.append( "Failed to configure plugin parameters for: " + descriptor.getId() + "\n\n" );
|
||||
|
||||
if ( failedConfiguration != null )
|
||||
{
|
||||
String value = failedConfiguration.getValue( null );
|
||||
addParameterUsageInfo( value, message );
|
||||
}
|
||||
|
||||
message.append( "Reason: " ).append( cce.getMessage() ).append( "\n" );
|
||||
|
||||
Throwable root = DiagnosisUtils.getRootCause( cce );
|
||||
|
||||
message.append( "Root Cause: " ).append( root.getMessage() ).append( "\n\n" );
|
||||
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
private String buildParameterDiagnosticMessage( PluginParameterException exception )
|
||||
{
|
||||
StringBuffer messageBuffer = new StringBuffer();
|
||||
|
||||
List params = exception.getParameters();
|
||||
MojoDescriptor mojo = exception.getMojoDescriptor();
|
||||
|
||||
messageBuffer.append( "One or more required plugin parameters are invalid/missing for \'" )
|
||||
.append( mojo.getPluginDescriptor().getGoalPrefix() ).append( ":" ).append( mojo.getGoal() )
|
||||
.append( "\'\n" );
|
||||
|
||||
int idx = 0;
|
||||
for ( Iterator it = params.iterator(); it.hasNext(); )
|
||||
{
|
||||
Parameter param = (Parameter) it.next();
|
||||
|
||||
messageBuffer.append( "\n[" ).append( idx++ ).append( "] " );
|
||||
|
||||
decomposeParameterIntoUserInstructions( mojo, param, messageBuffer );
|
||||
|
||||
messageBuffer.append( "\n" );
|
||||
}
|
||||
|
||||
return messageBuffer.toString();
|
||||
}
|
||||
|
||||
private void decomposeParameterIntoUserInstructions( MojoDescriptor mojo, Parameter param,
|
||||
StringBuffer messageBuffer )
|
||||
{
|
||||
String expression = param.getExpression();
|
||||
|
||||
if ( param.isEditable() )
|
||||
{
|
||||
messageBuffer.append( "inside the definition for plugin: \'" + mojo.getPluginDescriptor().getArtifactId()
|
||||
+ "\'specify the following:\n\n<configuration>\n ...\n <" + param.getName() + ">VALUE</"
|
||||
+ param.getName() + ">\n</configuration>" );
|
||||
|
||||
String alias = param.getAlias();
|
||||
if ( StringUtils.isNotEmpty( alias ) )
|
||||
{
|
||||
messageBuffer.append( "\n\n-OR-\n\n<configuration>\n ...\n <" + alias + ">VALUE</" + alias
|
||||
+ ">\n</configuration>\n" );
|
||||
}
|
||||
}
|
||||
|
||||
if ( StringUtils.isEmpty( expression ) )
|
||||
{
|
||||
messageBuffer.append( "." );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( param.isEditable() )
|
||||
{
|
||||
messageBuffer.append( "\n\n-OR-\n\n" );
|
||||
}
|
||||
|
||||
addParameterUsageInfo( expression, messageBuffer );
|
||||
}
|
||||
}
|
||||
|
||||
private void addParameterUsageInfo( String expression, StringBuffer messageBuffer )
|
||||
{
|
||||
StringBuffer expressionMessageBuffer = new StringBuffer();
|
||||
|
||||
Matcher exprMatcher = Pattern.compile( "\\$\\{(.+)\\}" ).matcher( expression );
|
||||
|
||||
boolean unmodifiableElementsFound = false;
|
||||
boolean activeElementsFound = false;
|
||||
|
||||
int elementCount = 0;
|
||||
|
||||
while ( exprMatcher.find() )
|
||||
{
|
||||
elementCount++;
|
||||
|
||||
activeElementsFound = true;
|
||||
|
||||
String subExpression = exprMatcher.group( 1 );
|
||||
|
||||
StringTokenizer expressionParts = new StringTokenizer( subExpression, "." );
|
||||
|
||||
String firstPart = expressionParts.nextToken();
|
||||
|
||||
try
|
||||
{
|
||||
Map expressions = ExpressionDocumenter.load();
|
||||
Expression expr = (Expression) expressions.get( subExpression );
|
||||
|
||||
if ( expr != null )
|
||||
{
|
||||
if ( !expr.isEditable() )
|
||||
{
|
||||
unmodifiableElementsFound = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
addParameterConfigDocumentation( firstPart, exprMatcher.group( 0 ), subExpression,
|
||||
expressionMessageBuffer );
|
||||
}
|
||||
}
|
||||
else if ( UNMODIFIABLE_EXPRESSIONS.contains( subExpression ) )
|
||||
{
|
||||
unmodifiableElementsFound = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
expressionMessageBuffer.append( "on the command line, specify: \'-D" ).append( subExpression )
|
||||
.append( "=VALUE\'" );
|
||||
}
|
||||
}
|
||||
catch ( ExpressionDocumentationException e )
|
||||
{
|
||||
expressionMessageBuffer.append( "\n\nERROR!! Failed to load expression documentation!" );
|
||||
|
||||
StringWriter sWriter = new StringWriter();
|
||||
PrintWriter pWriter = new PrintWriter( sWriter );
|
||||
|
||||
e.printStackTrace( pWriter );
|
||||
|
||||
expressionMessageBuffer.append( "\n\nException:\n\n" ).append( sWriter.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( activeElementsFound )
|
||||
{
|
||||
messageBuffer.append( expressionMessageBuffer );
|
||||
}
|
||||
else
|
||||
{
|
||||
messageBuffer.append( " (found static expression: \'" + expression
|
||||
+ "\' which may act as a default value).\n" );
|
||||
}
|
||||
|
||||
if ( unmodifiableElementsFound )
|
||||
{
|
||||
if ( elementCount > 1 )
|
||||
{
|
||||
messageBuffer.append( " " );
|
||||
}
|
||||
|
||||
messageBuffer
|
||||
.append( "NOTE: One or more purely derived expression elements were detected in \'"
|
||||
+ expression
|
||||
+ "\'.\n If you continue to get this error after any other expression elements are specified correctly,"
|
||||
+ "\n please report this issue to the Maven development team.\n" );
|
||||
}
|
||||
}
|
||||
|
||||
private void addParameterConfigDocumentation( String firstPart, String wholeExpression, String subExpression,
|
||||
StringBuffer expressionMessageBuffer )
|
||||
throws ExpressionDocumentationException
|
||||
{
|
||||
Map expressionDoco = ExpressionDocumenter.load();
|
||||
|
||||
Expression expr = (Expression) expressionDoco.get( subExpression );
|
||||
|
||||
if ( expr != null )
|
||||
{
|
||||
expressionMessageBuffer.append( "check that the following section of " );
|
||||
if ( "project".equals( firstPart ) )
|
||||
{
|
||||
expressionMessageBuffer.append( "the pom.xml " );
|
||||
}
|
||||
else if ( "settings".equals( firstPart ) )
|
||||
{
|
||||
expressionMessageBuffer.append( "your ~/.m2/settings.xml file " );
|
||||
}
|
||||
|
||||
expressionMessageBuffer.append( "is present and correct:\n\n" );
|
||||
|
||||
String message = expr.getConfiguration();
|
||||
|
||||
if ( message == null )
|
||||
{
|
||||
message = expr.getDescription();
|
||||
}
|
||||
|
||||
expressionMessageBuffer.append( message );
|
||||
|
||||
Properties cliConfig = expr.getCliOptions();
|
||||
|
||||
if ( cliConfig != null && !cliConfig.isEmpty() )
|
||||
{
|
||||
expressionMessageBuffer.append( "\n\n-OR-\n\nUse the following command-line switches:\n" );
|
||||
|
||||
prettyPrintCommandLineSwitches( cliConfig, '.', expressionMessageBuffer );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
expressionMessageBuffer.append( "ensure that the expression: \'" + wholeExpression + "\' is satisfied" );
|
||||
}
|
||||
}
|
||||
|
||||
private void prettyPrintCommandLineSwitches( Properties switches, char filler, StringBuffer expressionMessageBuffer )
|
||||
{
|
||||
int maxKeyLen = 0;
|
||||
|
||||
for ( Iterator it = switches.entrySet().iterator(); it.hasNext(); )
|
||||
{
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
|
||||
String key = (String) entry.getKey();
|
||||
|
||||
int keyLen = key.length();
|
||||
if ( keyLen > maxKeyLen )
|
||||
{
|
||||
maxKeyLen = keyLen;
|
||||
}
|
||||
}
|
||||
|
||||
final int minFillerCount = 4;
|
||||
|
||||
for ( Iterator it = switches.entrySet().iterator(); it.hasNext(); )
|
||||
{
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
|
||||
String key = (String) entry.getKey();
|
||||
|
||||
int keyLen = key.length();
|
||||
|
||||
int fillerCount = maxKeyLen - keyLen + minFillerCount;
|
||||
|
||||
expressionMessageBuffer.append( '\n' ).append( key ).append( ' ' );
|
||||
|
||||
for ( int i = 0; i < fillerCount; i++ )
|
||||
{
|
||||
expressionMessageBuffer.append( filler );
|
||||
}
|
||||
|
||||
expressionMessageBuffer.append( ' ' ).append( entry.getValue() );
|
||||
}
|
||||
|
||||
expressionMessageBuffer.append( '\n' );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
package org.apache.maven.usability;
|
||||
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.plugin.PluginContainerException;
|
||||
import org.apache.maven.usability.diagnostics.DiagnosisUtils;
|
||||
import org.apache.maven.usability.diagnostics.ErrorDiagnoser;
|
||||
|
||||
public class PluginContainerDiagnoser
|
||||
implements ErrorDiagnoser
|
||||
{
|
||||
|
||||
public boolean canDiagnose( Throwable error )
|
||||
{
|
||||
return DiagnosisUtils.containsInCausality( error, PluginContainerException.class );
|
||||
}
|
||||
|
||||
public String diagnose( Throwable error )
|
||||
{
|
||||
PluginContainerException exception = (PluginContainerException) DiagnosisUtils.getFromCausality( error, PluginContainerException.class );
|
||||
|
||||
// this is a little hackish, but it's simple.
|
||||
String originalMessage = exception.getOriginalMessage();
|
||||
Plugin plugin = exception.getPlugin();
|
||||
|
||||
StringBuffer message = new StringBuffer();
|
||||
|
||||
message.append( "Failed to prepare plugin for execution.");
|
||||
message.append( "\n" );
|
||||
message.append( "\nGroupId: " ).append( plugin.getGroupId() );
|
||||
message.append( "\nArtifactId: " ).append( plugin.getArtifactId() );
|
||||
message.append( "\nVersion: " ).append( plugin.getVersion() );
|
||||
message.append( "\nReason: " ).append( originalMessage );
|
||||
|
||||
if ( originalMessage.startsWith( "Cannot resolve artifact" ) )
|
||||
{
|
||||
message.append( SystemWarnings.getOfflineWarning() );
|
||||
}
|
||||
else
|
||||
{
|
||||
Throwable rootCause = DiagnosisUtils.getRootCause( exception );
|
||||
|
||||
if ( rootCause != null )
|
||||
{
|
||||
message.append( "\nRoot Cause: " ).append( rootCause.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
message.append( "\n\n" );
|
||||
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -130,16 +130,6 @@
|
|||
<role-hint>PluginConfigurationDiagnoser</role-hint>
|
||||
<implementation>org.apache.maven.usability.PluginConfigurationDiagnoser</implementation>
|
||||
</component>
|
||||
<!--
|
||||
|
|
||||
|PluginContainerDiagnoser
|
||||
|
|
||||
-->
|
||||
<component>
|
||||
<role>org.apache.maven.usability.diagnostics.ErrorDiagnoser</role>
|
||||
<role-hint>PluginContainerDiagnoser</role-hint>
|
||||
<implementation>org.apache.maven.usability.PluginContainerDiagnoser</implementation>
|
||||
</component>
|
||||
<!--
|
||||
|
|
||||
|ArtifactNotFoundDiagnoser
|
||||
|
|
|
@ -1,8 +1,25 @@
|
|||
package org.apache.maven.plugins.projecthelp;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
|
@ -29,7 +46,7 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* Describes the attributes of a plugin and/or plugin mojo.
|
||||
*
|
||||
*
|
||||
* @goal describe
|
||||
* @requiresProject false
|
||||
* @aggregator
|
||||
|
@ -40,11 +57,11 @@ public class DescribeMojo
|
|||
|
||||
/**
|
||||
* The plugin/mojo to describe. This must be specified in one of three ways:
|
||||
*
|
||||
*
|
||||
* 1. plugin-prefix
|
||||
* 2. groupId:artifactId
|
||||
* 3. groupId:artifactId:version
|
||||
*
|
||||
*
|
||||
* @parameter expression="${plugin}" alias="prefix"
|
||||
*/
|
||||
private String plugin;
|
||||
|
@ -53,25 +70,25 @@ public class DescribeMojo
|
|||
* The plugin groupId to describe.
|
||||
* <br/>
|
||||
* (Used with artifactId specification).
|
||||
*
|
||||
*
|
||||
* @parameter expression="${groupId}"
|
||||
*/
|
||||
private String groupId;
|
||||
|
||||
/**
|
||||
* The plugin artifactId to describe.
|
||||
* The plugin artifactId to describe.
|
||||
* <br/>
|
||||
* (Used with groupId specification).
|
||||
*
|
||||
*
|
||||
* @parameter expression="${artifactId}"
|
||||
*/
|
||||
private String artifactId;
|
||||
|
||||
/**
|
||||
* The plugin version to describe.
|
||||
* The plugin version to describe.
|
||||
* <br/>
|
||||
* (Used with groupId/artifactId specification).
|
||||
*
|
||||
*
|
||||
* @parameter expression="${version}"
|
||||
*/
|
||||
private String version;
|
||||
|
@ -81,15 +98,15 @@ public class DescribeMojo
|
|||
* <br/>
|
||||
* If this parameter is specified, only the corresponding mojo will
|
||||
* <br/>
|
||||
* be described, rather than the whole plugin.
|
||||
*
|
||||
* be described, rather than the whole plugin.
|
||||
*
|
||||
* @parameter expression="${mojo}"
|
||||
*/
|
||||
private String mojo;
|
||||
|
||||
/**
|
||||
* The plugin manager instance used to resolve plugin descriptors.
|
||||
*
|
||||
*
|
||||
* @component role="org.apache.maven.plugin.PluginManager"
|
||||
*/
|
||||
private PluginManager pluginManager;
|
||||
|
@ -100,7 +117,7 @@ public class DescribeMojo
|
|||
* in the event there is no current MavenProject instance. Some MavenProject
|
||||
* <br/>
|
||||
* instance has to be present to use in the plugin manager APIs.
|
||||
*
|
||||
*
|
||||
* @component role="org.apache.maven.project.MavenProjectBuilder"
|
||||
*/
|
||||
private MavenProjectBuilder projectBuilder;
|
||||
|
@ -113,17 +130,17 @@ public class DescribeMojo
|
|||
* parameter is empty at execution time, this mojo will instead use the
|
||||
* <br/>
|
||||
* super-project.
|
||||
*
|
||||
*
|
||||
* @parameter expression="${project}"
|
||||
* @readonly
|
||||
*/
|
||||
private MavenProject project;
|
||||
|
||||
/**
|
||||
* The current user system settings for use in Maven. This is used for
|
||||
* The current user system settings for use in Maven. This is used for
|
||||
* <br/>
|
||||
* plugin manager API calls.
|
||||
*
|
||||
*
|
||||
* @parameter expression="${settings}"
|
||||
* @required
|
||||
* @readonly
|
||||
|
@ -131,10 +148,10 @@ public class DescribeMojo
|
|||
private Settings settings;
|
||||
|
||||
/**
|
||||
* The current build session instance. This is used for
|
||||
* The current build session instance. This is used for
|
||||
* <br/>
|
||||
* plugin manager API calls.
|
||||
*
|
||||
*
|
||||
* @parameter expression="${session}"
|
||||
* @required
|
||||
* @readonly
|
||||
|
@ -145,7 +162,7 @@ public class DescribeMojo
|
|||
* The local repository ArtifactRepository instance. This is used
|
||||
* <br/>
|
||||
* for plugin manager API calls.
|
||||
*
|
||||
*
|
||||
* @parameter expression="${localRepository}"
|
||||
* @required
|
||||
* @readonly
|
||||
|
@ -156,16 +173,16 @@ public class DescribeMojo
|
|||
* If specified, this parameter will cause the plugin/mojo descriptions
|
||||
* <br/>
|
||||
* to be written to the path specified, instead of writing to the console.
|
||||
*
|
||||
*
|
||||
* @parameter expression="${output}"
|
||||
*/
|
||||
private File output;
|
||||
|
||||
|
||||
/**
|
||||
* This flag specifies that full (verbose) information should be
|
||||
* <br/>
|
||||
* given. Use true/false.
|
||||
*
|
||||
*
|
||||
* @parameter expression="${full}" default-value="false"
|
||||
*/
|
||||
private boolean full;
|
||||
|
@ -184,11 +201,11 @@ public class DescribeMojo
|
|||
throw new MojoExecutionException( "Error while retrieving the super-project.", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PluginInfo pi = new PluginInfo();
|
||||
|
||||
|
||||
parsePluginLookupInfo( pi );
|
||||
|
||||
|
||||
PluginDescriptor descriptor = lookupPluginDescriptor( pi );
|
||||
|
||||
StringBuffer descriptionBuffer = new StringBuffer();
|
||||
|
@ -205,7 +222,8 @@ public class DescribeMojo
|
|||
writeDescription( descriptionBuffer );
|
||||
}
|
||||
|
||||
private void writeDescription( StringBuffer descriptionBuffer ) throws MojoExecutionException
|
||||
private void writeDescription( StringBuffer descriptionBuffer )
|
||||
throws MojoExecutionException
|
||||
{
|
||||
if ( output != null )
|
||||
{
|
||||
|
@ -213,7 +231,7 @@ public class DescribeMojo
|
|||
try
|
||||
{
|
||||
output.getParentFile().mkdirs();
|
||||
|
||||
|
||||
out = new FileWriter( output );
|
||||
|
||||
out.write( descriptionBuffer.toString() );
|
||||
|
@ -236,7 +254,7 @@ public class DescribeMojo
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
getLog().info( "Wrote descriptions to: " + output );
|
||||
}
|
||||
else
|
||||
|
@ -245,16 +263,17 @@ public class DescribeMojo
|
|||
}
|
||||
}
|
||||
|
||||
private PluginDescriptor lookupPluginDescriptor( PluginInfo pi ) throws MojoExecutionException, MojoFailureException
|
||||
private PluginDescriptor lookupPluginDescriptor( PluginInfo pi )
|
||||
throws MojoExecutionException, MojoFailureException
|
||||
{
|
||||
PluginDescriptor descriptor = null;
|
||||
|
||||
|
||||
Plugin forLookup = null;
|
||||
|
||||
|
||||
if ( pi.prefix != null )
|
||||
{
|
||||
descriptor = pluginManager.getPluginDescriptorForPrefix( pi.prefix );
|
||||
|
||||
|
||||
if ( descriptor == null )
|
||||
{
|
||||
try
|
||||
|
@ -271,7 +290,7 @@ public class DescribeMojo
|
|||
else if ( pi.groupId != null && pi.artifactId != null )
|
||||
{
|
||||
forLookup = new Plugin();
|
||||
|
||||
|
||||
forLookup.setGroupId( pi.groupId );
|
||||
forLookup.setArtifactId( pi.artifactId );
|
||||
|
||||
|
@ -282,9 +301,10 @@ public class DescribeMojo
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new MojoFailureException("You must either specify \'groupId\' and \'artifactId\', or a valid \'plugin\' parameter." );
|
||||
throw new MojoFailureException(
|
||||
"You must either specify \'groupId\' and \'artifactId\', or a valid \'plugin\' parameter." );
|
||||
}
|
||||
|
||||
|
||||
if ( descriptor == null && forLookup != null )
|
||||
{
|
||||
try
|
||||
|
@ -293,30 +313,36 @@ public class DescribeMojo
|
|||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId
|
||||
+ "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
|
||||
throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId +
|
||||
"\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
|
||||
}
|
||||
catch ( PluginManagerException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId
|
||||
+ "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
|
||||
throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId +
|
||||
"\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
|
||||
}
|
||||
catch ( PluginVersionResolutionException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId
|
||||
+ "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
|
||||
throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId +
|
||||
"\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
|
||||
}
|
||||
catch ( ArtifactNotFoundException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId
|
||||
+ "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
|
||||
throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId +
|
||||
"\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId +
|
||||
"\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
private void parsePluginLookupInfo( PluginInfo pi ) throws MojoFailureException
|
||||
private void parsePluginLookupInfo( PluginInfo pi )
|
||||
throws MojoFailureException
|
||||
{
|
||||
if ( plugin != null && plugin.length() > 0 )
|
||||
{
|
||||
|
@ -346,7 +372,8 @@ public class DescribeMojo
|
|||
}
|
||||
default:
|
||||
{
|
||||
throw new MojoFailureException("plugin parameter must be a plugin prefix, or conform to: 'groupId:artifactId[:version]." );
|
||||
throw new MojoFailureException(
|
||||
"plugin parameter must be a plugin prefix, or conform to: 'groupId:artifactId[:version]." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -370,24 +397,24 @@ public class DescribeMojo
|
|||
{
|
||||
name = pd.getId();
|
||||
}
|
||||
|
||||
|
||||
buffer.append( "Plugin: \'" ).append( name ).append( '\'' );
|
||||
buffer.append( "\n-----------------------------------------------" );
|
||||
buffer.append( "\nGroup Id: " ).append( pd.getGroupId() );
|
||||
buffer.append( "\nArtifact Id: " ).append( pd.getArtifactId() );
|
||||
buffer.append( "\nVersion: " ).append( pd.getVersion() );
|
||||
buffer.append( "\nGoal Prefix: " ).append( pd.getGoalPrefix() );
|
||||
|
||||
|
||||
buffer.append( "\nDescription:\n\n" );
|
||||
prettyAppend( formatDescription( pd.getDescription() ), buffer );
|
||||
buffer.append( "\n" );
|
||||
|
||||
|
||||
if ( full )
|
||||
{
|
||||
buffer.append( "\nMojos:\n" );
|
||||
|
||||
String line = "\n===============================================";
|
||||
|
||||
|
||||
for ( Iterator it = pd.getMojos().iterator(); it.hasNext(); )
|
||||
{
|
||||
MojoDescriptor md = (MojoDescriptor) it.next();
|
||||
|
@ -395,9 +422,9 @@ public class DescribeMojo
|
|||
buffer.append( line );
|
||||
buffer.append( "\nGoal: \'" ).append( md.getGoal() ).append( '\'' );
|
||||
buffer.append( line );
|
||||
|
||||
|
||||
describeMojoGuts( md, buffer, true );
|
||||
|
||||
|
||||
buffer.append( line );
|
||||
buffer.append( "\n\n" );
|
||||
}
|
||||
|
@ -410,12 +437,12 @@ public class DescribeMojo
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
String result = description.replaceAll( " ?\\<br\\/?\\> ?", "\n" );
|
||||
|
||||
result = result.replaceAll(" ?\\<p\\> ?", "" );
|
||||
result = result.replaceAll(" ?\\</p\\> ?", "\n\n" );
|
||||
|
||||
|
||||
result = result.replaceAll( " ?\\<p\\> ?", "" );
|
||||
result = result.replaceAll( " ?\\</p\\> ?", "\n\n" );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -434,13 +461,13 @@ public class DescribeMojo
|
|||
private void describeMojo( MojoDescriptor md, StringBuffer buffer )
|
||||
{
|
||||
String line = "\n===============================================";
|
||||
|
||||
|
||||
buffer.append( "Mojo: \'" ).append( md.getFullGoalName() ).append( '\'' );
|
||||
buffer.append( line );
|
||||
buffer.append( "\nGoal: \'" ).append( md.getGoal() ).append( "\'" );
|
||||
|
||||
describeMojoGuts( md, buffer, full );
|
||||
|
||||
|
||||
buffer.append( line );
|
||||
buffer.append( "\n\n" );
|
||||
}
|
||||
|
@ -450,14 +477,14 @@ public class DescribeMojo
|
|||
buffer.append( "\nDescription:\n\n" );
|
||||
prettyAppend( formatDescription( md.getDescription() ), buffer );
|
||||
buffer.append( "\n" );
|
||||
|
||||
|
||||
String deprecation = md.getDeprecated();
|
||||
|
||||
|
||||
if ( deprecation != null )
|
||||
{
|
||||
buffer.append( "\n\nNOTE: This mojo is deprecated.\n" ).append( deprecation ).append( "\n" );
|
||||
}
|
||||
|
||||
|
||||
if ( fullDescription )
|
||||
{
|
||||
buffer.append( "\nImplementation: " ).append( md.getImplementation() );
|
||||
|
@ -502,9 +529,9 @@ public class DescribeMojo
|
|||
private void describeMojoRequirements( MojoDescriptor md, StringBuffer buffer )
|
||||
{
|
||||
buffer.append( "\n" );
|
||||
|
||||
|
||||
List reqs = md.getRequirements();
|
||||
|
||||
|
||||
if ( reqs == null || reqs.isEmpty() )
|
||||
{
|
||||
buffer.append( "\nThis mojo doesn't have any component requirements." );
|
||||
|
@ -512,28 +539,28 @@ public class DescribeMojo
|
|||
else
|
||||
{
|
||||
buffer.append( "\nComponent Requirements:\n" );
|
||||
|
||||
|
||||
String line = "\n-----------------------------------------------";
|
||||
|
||||
|
||||
int idx = 0;
|
||||
for ( Iterator it = reqs.iterator(); it.hasNext(); )
|
||||
for ( Iterator it = reqs.iterator(); it.hasNext(); idx++ )
|
||||
{
|
||||
ComponentRequirement req = (ComponentRequirement) it.next();
|
||||
|
||||
|
||||
buffer.append( line );
|
||||
|
||||
buffer.append( "\n[" ).append( idx++ ).append( "] " );
|
||||
|
||||
buffer.append( "\n[" ).append( idx ).append( "] " );
|
||||
buffer.append( "Role: " ).append( req.getRole() );
|
||||
|
||||
|
||||
String hint = req.getRoleHint();
|
||||
if ( hint != null )
|
||||
{
|
||||
buffer.append( "\nRole-Hint: " ).append( hint );
|
||||
}
|
||||
|
||||
|
||||
buffer.append( "\n" );
|
||||
}
|
||||
|
||||
|
||||
buffer.append( line );
|
||||
}
|
||||
}
|
||||
|
@ -541,9 +568,9 @@ public class DescribeMojo
|
|||
private void describeMojoParameters( MojoDescriptor md, StringBuffer buffer )
|
||||
{
|
||||
buffer.append( "\n" );
|
||||
|
||||
|
||||
List params = md.getParameters();
|
||||
|
||||
|
||||
if ( params == null || params.isEmpty() )
|
||||
{
|
||||
buffer.append( "\nThis mojo doesn't use any parameters." );
|
||||
|
@ -551,56 +578,56 @@ public class DescribeMojo
|
|||
else
|
||||
{
|
||||
buffer.append( "\nParameters:" );
|
||||
|
||||
|
||||
String line = "\n-----------------------------------------------";
|
||||
|
||||
|
||||
int idx = 0;
|
||||
for ( Iterator it = params.iterator(); it.hasNext(); )
|
||||
{
|
||||
Parameter parameter = (Parameter) it.next();
|
||||
|
||||
|
||||
buffer.append( line );
|
||||
buffer.append( "\n\n[" ).append( idx++ ).append( "] " );
|
||||
buffer.append( "Name: " );
|
||||
prettyAppend( parameter.getName(), buffer );
|
||||
|
||||
|
||||
String alias = parameter.getAlias();
|
||||
if ( alias != null )
|
||||
{
|
||||
buffer.append( " (Alias: " ).append( alias ).append( ")" );
|
||||
}
|
||||
|
||||
|
||||
buffer.append( "\nType: " );
|
||||
prettyAppend( parameter.getType(), buffer );
|
||||
|
||||
|
||||
String expression = parameter.getExpression();
|
||||
if ( expression != null )
|
||||
{
|
||||
buffer.append( "\nExpression: " ).append( expression );
|
||||
}
|
||||
|
||||
|
||||
String defaultVal = parameter.getDefaultValue();
|
||||
if ( defaultVal != null )
|
||||
{
|
||||
buffer.append( "\nDefault value: \'" ).append( defaultVal );
|
||||
}
|
||||
|
||||
|
||||
buffer.append( "\nRequired: " ).append( parameter.isRequired() );
|
||||
buffer.append( "\nDirectly editable: " ).append( parameter.isEditable() );
|
||||
|
||||
|
||||
buffer.append( "\nDescription:\n\n" );
|
||||
prettyAppend( formatDescription( parameter.getDescription() ), buffer );
|
||||
|
||||
|
||||
String deprecation = parameter.getDeprecated();
|
||||
|
||||
|
||||
if ( deprecation != null )
|
||||
{
|
||||
buffer.append( "\n\nNOTE: This parameter is deprecated.\n" ).append( deprecation ).append( "\n" );
|
||||
}
|
||||
|
||||
|
||||
buffer.append( "\n" );
|
||||
}
|
||||
|
||||
|
||||
buffer.append( line );
|
||||
}
|
||||
}
|
||||
|
@ -704,16 +731,21 @@ public class DescribeMojo
|
|||
{
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
|
||||
private static class PluginInfo
|
||||
{
|
||||
String prefix;
|
||||
|
||||
String groupId;
|
||||
|
||||
String artifactId;
|
||||
|
||||
String version;
|
||||
|
||||
String mojo;
|
||||
|
||||
|
||||
Plugin plugin;
|
||||
|
||||
PluginDescriptor pluginDescriptor;
|
||||
}
|
||||
|
||||
|
|
|
@ -66,14 +66,4 @@ public abstract class AbstractReleaseMojo
|
|||
|
||||
return scmHelper;
|
||||
}
|
||||
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
executeTask();
|
||||
}
|
||||
|
||||
protected abstract void executeTask()
|
||||
throws MojoExecutionException;
|
||||
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public class PerformReleaseMojo
|
|||
|
||||
private ReleaseProgressTracker releaseProgress;
|
||||
|
||||
protected void executeTask()
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
checkout();
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.apache.maven.model.ReportPlugin;
|
|||
import org.apache.maven.model.Reporting;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugin.version.PluginVersionManager;
|
||||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
||||
import org.apache.maven.plugins.release.helpers.ProjectScmRewriter;
|
||||
|
@ -176,8 +177,8 @@ public class PrepareReleaseMojo
|
|||
|
||||
private ProjectScmRewriter scmRewriter;
|
||||
|
||||
protected void executeTask()
|
||||
throws MojoExecutionException
|
||||
public void execute()
|
||||
throws MojoExecutionException, MojoFailureException
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -818,7 +819,7 @@ public class PrepareReleaseMojo
|
|||
}
|
||||
|
||||
private void generateReleasePoms()
|
||||
throws MojoExecutionException
|
||||
throws MojoExecutionException, MojoFailureException
|
||||
{
|
||||
if ( !getReleaseProgress().verifyCheckpoint( ReleaseProgressTracker.CP_GENERATED_RELEASE_POM ) )
|
||||
{
|
||||
|
@ -939,12 +940,14 @@ public class PrepareReleaseMojo
|
|||
}
|
||||
catch ( PluginVersionResolutionException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Cannot resolve version for plugin: " + plugin, e );
|
||||
getLog().debug( "Error resolving plugin version", e );
|
||||
throw new MojoFailureException(
|
||||
"Cannot resolve version for plugin '" + plugin.getKey() + "': " + e.getMessage() );
|
||||
}
|
||||
|
||||
if ( ArtifactUtils.isSnapshot( version ) )
|
||||
{
|
||||
throw new MojoExecutionException(
|
||||
throw new MojoFailureException(
|
||||
"Resolved version of plugin is a snapshot. Please release this plugin before releasing this project.\n\nGroupId: " +
|
||||
plugin.getGroupId() + "\nArtifactId: " + plugin.getArtifactId() +
|
||||
"\nResolved Version: " + version + "\n\n" );
|
||||
|
@ -974,14 +977,15 @@ public class PrepareReleaseMojo
|
|||
}
|
||||
catch ( PluginVersionResolutionException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Cannot resolve version for report plugin: " + plugin,
|
||||
e );
|
||||
getLog().debug( "Error resolving report version", e );
|
||||
throw new MojoFailureException(
|
||||
"Cannot resolve version for report '" + plugin.getKey() + "': " + e.getMessage() );
|
||||
}
|
||||
|
||||
if ( ArtifactUtils.isSnapshot( version ) )
|
||||
{
|
||||
throw new MojoExecutionException(
|
||||
"Resolved version of plugin is a snapshot. Please release this report plugin before releasing this project.\n\nGroupId: " +
|
||||
throw new MojoFailureException(
|
||||
"Resolved version of report is a snapshot. Please release this report plugin before releasing this project.\n\nGroupId: " +
|
||||
plugin.getGroupId() + "\nArtifactId: " + plugin.getArtifactId() +
|
||||
"\nResolved Version: " + version + "\n\n" );
|
||||
}
|
||||
|
|
|
@ -191,14 +191,7 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
ensureMetadataSourceIsInitialized();
|
||||
|
||||
try
|
||||
{
|
||||
project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) );
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new ProjectBuildingException( projectId, "Error in dependency version", e );
|
||||
}
|
||||
project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) );
|
||||
|
||||
if ( transferListener != null )
|
||||
{
|
||||
|
@ -254,7 +247,8 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new ProjectBuildingException( projectId, "Unable to parse dependency version", e );
|
||||
throw new ProjectBuildingException( projectId, "Unable to parse version '" + d.getVersion() +
|
||||
"' for dependency '" + d.getManagementKey() + "': " + e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1154,7 +1148,9 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new ProjectBuildingException( projectId, "Unable to parse plugin version", e );
|
||||
throw new ProjectBuildingException( projectId, "Unable to parse version '" + version +
|
||||
"' for plugin '" + ArtifactUtils.versionlessKey( p.getGroupId(), p.getArtifactId() ) + "': " +
|
||||
e.getMessage(), e );
|
||||
}
|
||||
|
||||
if ( artifact != null )
|
||||
|
@ -1196,7 +1192,9 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new ProjectBuildingException( projectId, "Unable to parse plugin version", e );
|
||||
throw new ProjectBuildingException( projectId, "Unable to parse version '" + version +
|
||||
"' for report '" + ArtifactUtils.versionlessKey( p.getGroupId(), p.getArtifactId() ) + "': " +
|
||||
e.getMessage(), e );
|
||||
}
|
||||
|
||||
if ( artifact != null )
|
||||
|
@ -1234,12 +1232,15 @@ public class DefaultMavenProjectBuilder
|
|||
Artifact artifact;
|
||||
try
|
||||
{
|
||||
artifact = artifactFactory.createExtensionArtifact( ext.getGroupId(), ext.getArtifactId(),
|
||||
VersionRange.createFromVersionSpec( version ) );
|
||||
VersionRange versionRange = VersionRange.createFromVersionSpec( version );
|
||||
artifact =
|
||||
artifactFactory.createExtensionArtifact( ext.getGroupId(), ext.getArtifactId(), versionRange );
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new ProjectBuildingException( projectId, "Unable to parse extension version", e );
|
||||
throw new ProjectBuildingException( projectId, "Unable to parse version '" + version +
|
||||
"' for extension '" + ArtifactUtils.versionlessKey( ext.getGroupId(), ext.getArtifactId() ) +
|
||||
"': " + e.getMessage(), e );
|
||||
}
|
||||
|
||||
if ( artifact != null )
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.apache.maven.artifact.DependencyResolutionRequiredException;
|
|||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.CiManagement;
|
||||
import org.apache.maven.model.Contributor;
|
||||
|
@ -1406,7 +1405,7 @@ public class MavenProject
|
|||
*/
|
||||
public Set createArtifacts( ArtifactFactory artifactFactory, String inheritedScope,
|
||||
ArtifactFilter dependencyFilter )
|
||||
throws InvalidVersionSpecificationException
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
return MavenMetadataSource.createArtifacts( artifactFactory, getDependencies(), inheritedScope,
|
||||
dependencyFilter, this );
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.maven.project.artifact;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.ArtifactUtils;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||
|
@ -110,7 +111,8 @@ public class MavenMetadataSource
|
|||
catch ( InvalidProjectModelException e )
|
||||
{
|
||||
getLogger().warn( "POM for: \'" + pomArtifact +
|
||||
"\' does not appear to be valid. Its will be ignored for artifact resolution.\n\nReason: " + e.getMessage() + "\n\n" );
|
||||
"\' does not appear to be valid. Its will be ignored for artifact resolution.\n\nReason: " +
|
||||
e.getMessage() + "\n\n" );
|
||||
|
||||
project = null;
|
||||
}
|
||||
|
@ -188,22 +190,18 @@ public class MavenMetadataSource
|
|||
{
|
||||
// TODO: we could possibly use p.getDependencyArtifacts instead of this call, but they haven't been filtered
|
||||
// or used the inherited scope (should that be passed to the buildFromRepository method above?)
|
||||
artifacts = project.createArtifacts( artifactFactory, artifact.getScope(),
|
||||
artifact.getDependencyFilter() );
|
||||
artifacts =
|
||||
project.createArtifacts( artifactFactory, artifact.getScope(), artifact.getDependencyFilter() );
|
||||
}
|
||||
|
||||
List repositories = aggregateRepositoryLists( remoteRepositories,
|
||||
project.getRemoteArtifactRepositories() );
|
||||
List repositories =
|
||||
aggregateRepositoryLists( remoteRepositories, project.getRemoteArtifactRepositories() );
|
||||
|
||||
result = new ResolutionGroup( pomArtifact, artifacts, repositories );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
|
||||
}
|
||||
catch ( ProjectBuildingException e )
|
||||
{
|
||||
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
|
||||
|
@ -256,9 +254,12 @@ public class MavenMetadataSource
|
|||
return repositories;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo desperately needs refactoring. It's just here because it's implementation is maven-project specific
|
||||
*/
|
||||
public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies, String inheritedScope,
|
||||
ArtifactFilter dependencyFilter, MavenProject project )
|
||||
throws InvalidVersionSpecificationException
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
Set projectArtifacts = new HashSet( dependencies.size() );
|
||||
|
||||
|
@ -275,7 +276,19 @@ public class MavenMetadataSource
|
|||
d.setScope( scope );
|
||||
}
|
||||
|
||||
VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
|
||||
VersionRange versionRange;
|
||||
try
|
||||
{
|
||||
versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
String projectId = project != null ? ArtifactUtils.versionlessKey( project.getGroupId(),
|
||||
project.getArtifactId() )
|
||||
: "unknown";
|
||||
throw new ProjectBuildingException( projectId, "Unable to parse version '" + d.getVersion() +
|
||||
"' for dependency '" + d.getManagementKey() + "': " + e.getMessage(), e );
|
||||
}
|
||||
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
|
||||
versionRange, d.getType(), d.getClassifier(),
|
||||
scope, inheritedScope, d.isOptional() );
|
||||
|
|
|
@ -15,92 +15,94 @@ import java.util.Map;
|
|||
public class MavenMetadataSourceTest
|
||||
extends PlexusTestCase
|
||||
{
|
||||
|
||||
public void testShouldUseCompileScopeIfDependencyScopeEmpty() throws Exception
|
||||
|
||||
public void testShouldUseCompileScopeIfDependencyScopeEmpty()
|
||||
throws Exception
|
||||
{
|
||||
String groupId = "org.apache.maven";
|
||||
String artifactId = "maven-model";
|
||||
|
||||
|
||||
Dependency dep = new Dependency();
|
||||
|
||||
dep.setGroupId(groupId);
|
||||
dep.setArtifactId(artifactId);
|
||||
dep.setVersion("2.0-alpha-3");
|
||||
|
||||
|
||||
dep.setGroupId( groupId );
|
||||
dep.setArtifactId( artifactId );
|
||||
dep.setVersion( "2.0-alpha-3" );
|
||||
|
||||
Model model = new Model();
|
||||
|
||||
model.addDependency(dep);
|
||||
|
||||
|
||||
model.addDependency( dep );
|
||||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
|
||||
ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
||||
|
||||
project.setArtifacts( project.createArtifacts(factory, null, null) );
|
||||
|
||||
String key = ArtifactUtils.versionlessKey(groupId, artifactId );
|
||||
|
||||
|
||||
project.setArtifacts( project.createArtifacts( factory, null, null ) );
|
||||
|
||||
String key = ArtifactUtils.versionlessKey( groupId, artifactId );
|
||||
|
||||
Map artifactMap = project.getArtifactMap();
|
||||
|
||||
|
||||
assertNotNull( "artifact-map should not be null.", artifactMap );
|
||||
assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() );
|
||||
|
||||
|
||||
Artifact artifact = (Artifact) artifactMap.get( key );
|
||||
|
||||
|
||||
assertNotNull( "dependency artifact not found in map.", artifact );
|
||||
assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_COMPILE, artifact.getScope() );
|
||||
|
||||
|
||||
//check for back-propagation of default scope.
|
||||
assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_COMPILE, dep.getScope() );
|
||||
}
|
||||
|
||||
public void testShouldUseInjectedTestScopeFromDependencyManagement() throws Exception
|
||||
public void testShouldUseInjectedTestScopeFromDependencyManagement()
|
||||
throws Exception
|
||||
{
|
||||
String groupId = "org.apache.maven";
|
||||
String artifactId = "maven-model";
|
||||
|
||||
|
||||
Dependency dep = new Dependency();
|
||||
|
||||
dep.setGroupId(groupId);
|
||||
dep.setArtifactId(artifactId);
|
||||
dep.setVersion("2.0-alpha-3");
|
||||
|
||||
|
||||
dep.setGroupId( groupId );
|
||||
dep.setArtifactId( artifactId );
|
||||
dep.setVersion( "2.0-alpha-3" );
|
||||
|
||||
Model model = new Model();
|
||||
|
||||
model.addDependency(dep);
|
||||
|
||||
|
||||
model.addDependency( dep );
|
||||
|
||||
Dependency mgd = new Dependency();
|
||||
mgd.setGroupId( groupId);
|
||||
mgd.setGroupId( groupId );
|
||||
mgd.setArtifactId( artifactId );
|
||||
mgd.setScope( Artifact.SCOPE_TEST);
|
||||
|
||||
mgd.setScope( Artifact.SCOPE_TEST );
|
||||
|
||||
DependencyManagement depMgmt = new DependencyManagement();
|
||||
|
||||
depMgmt.addDependency(mgd);
|
||||
|
||||
model.setDependencyManagement(depMgmt);
|
||||
|
||||
|
||||
depMgmt.addDependency( mgd );
|
||||
|
||||
model.setDependencyManagement( depMgmt );
|
||||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
|
||||
ModelDefaultsInjector injector = (ModelDefaultsInjector) lookup( ModelDefaultsInjector.ROLE );
|
||||
|
||||
|
||||
injector.injectDefaults( model );
|
||||
|
||||
|
||||
ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
||||
|
||||
project.setArtifacts( project.createArtifacts(factory, null, null) );
|
||||
|
||||
String key = ArtifactUtils.versionlessKey(groupId, artifactId );
|
||||
|
||||
|
||||
project.setArtifacts( project.createArtifacts( factory, null, null ) );
|
||||
|
||||
String key = ArtifactUtils.versionlessKey( groupId, artifactId );
|
||||
|
||||
Map artifactMap = project.getArtifactMap();
|
||||
|
||||
|
||||
assertNotNull( "artifact-map should not be null.", artifactMap );
|
||||
assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() );
|
||||
|
||||
|
||||
Artifact artifact = (Artifact) artifactMap.get( key );
|
||||
|
||||
|
||||
assertNotNull( "dependency artifact not found in map.", artifact );
|
||||
assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_TEST, artifact.getScope() );
|
||||
|
||||
|
||||
//check for back-propagation of default scope.
|
||||
assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_TEST, dep.getScope() );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue