Ignore missing modules during extension-scanning when MavenEmbedder.readProject(..) is called. At other times, as in the case of normal builds, don't suppress missing module exceptions.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@629571 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2008-02-20 18:53:09 +00:00
parent 793020c798
commit d54cf5b9bb
7 changed files with 61 additions and 22 deletions

View File

@ -266,7 +266,7 @@ public class DefaultMaven
// instances just-in-time.
try
{
buildExtensionScanner.scanForBuildExtensions( files, request );
buildExtensionScanner.scanForBuildExtensions( files, request, false );
}
catch ( ExtensionScanningException e )
{

View File

@ -31,11 +31,13 @@ public interface BuildExtensionScanner
String ROLE = BuildExtensionScanner.class.getName();
void scanForBuildExtensions( List files,
MavenExecutionRequest request )
MavenExecutionRequest request,
boolean ignoreMissingModules )
throws ExtensionScanningException, MissingModuleException;
void scanForBuildExtensions( File pom,
MavenExecutionRequest request )
MavenExecutionRequest request,
boolean ignoreMissingModules )
throws ExtensionScanningException, MissingModuleException;
}

View File

@ -89,38 +89,41 @@ public class DefaultBuildExtensionScanner
}
public void scanForBuildExtensions( List files,
MavenExecutionRequest request )
MavenExecutionRequest request,
boolean ignoreMissingModules )
throws ExtensionScanningException, MissingModuleException
{
List visited = new ArrayList();
List internalFiles = new ArrayList();
internalFiles.addAll(files);
for ( Iterator it = files.iterator(); it.hasNext(); )
{
File pom = (File) it.next();
scanInternal( pom, request, visited, internalFiles );
scanInternal( pom, request, visited, internalFiles, ignoreMissingModules );
}
}
public void scanForBuildExtensions( File pom,
MavenExecutionRequest request )
MavenExecutionRequest request,
boolean ignoreMissingModules )
throws ExtensionScanningException, MissingModuleException
{
List internalFiles = new ArrayList();
internalFiles.add( pom );
scanInternal( pom, request, new ArrayList(), internalFiles );
scanInternal( pom, request, new ArrayList(), internalFiles, ignoreMissingModules );
}
private void scanInternal( File pom,
MavenExecutionRequest request,
List visitedModelIds,
List reactorFiles )
List reactorFiles,
boolean ignoreMissingModules )
throws ExtensionScanningException, MissingModuleException
{
@ -195,7 +198,8 @@ public class DefaultBuildExtensionScanner
request,
originalRemoteRepositories,
visitedModelIds,
reactorFiles );
reactorFiles,
ignoreMissingModules );
}
}
}
@ -251,7 +255,8 @@ public class DefaultBuildExtensionScanner
MavenExecutionRequest request,
List originalRemoteRepositories,
List visitedModelIds,
List reactorFiles )
List reactorFiles,
boolean ignoreMissingModules )
throws ExtensionScanningException, MissingModuleException
{
// FIXME: This gets a little sticky, because modules can be added by profiles that require
@ -310,12 +315,19 @@ public class DefaultBuildExtensionScanner
if ( !modulePomDirectory.exists() )
{
throw new MissingModuleException( moduleSubpath, modulePomDirectory, containingPom );
if ( ignoreMissingModules )
{
continue;
}
else
{
throw new MissingModuleException( moduleSubpath, modulePomDirectory, containingPom );
}
}
reactorFiles.add( modulePomDirectory );
scanInternal( modulePomDirectory, request, visitedModelIds, reactorFiles );
scanInternal( modulePomDirectory, request, visitedModelIds, reactorFiles, ignoreMissingModules );
}
}
}

View File

@ -134,7 +134,8 @@ public class DefaultBuildExtensionScannerTest
new DefaultBuildExtensionScanner( extensionManager, projectBuilder, modelLineageBuilder,
modelInterpolator, new ConsoleLogger( Logger.LEVEL_DEBUG,
"test" ) ).scanForBuildExtensions( pomFile,
request );
request,
false );
mockManager.verifyAll();
}
@ -213,7 +214,8 @@ public class DefaultBuildExtensionScannerTest
new DefaultBuildExtensionScanner( extensionManager, projectBuilder, modelLineageBuilder,
modelInterpolator, new ConsoleLogger( Logger.LEVEL_DEBUG,
"test" ) ).scanForBuildExtensions( pomFile,
request );
request,
false );
mockManager.verifyAll();
}
@ -324,7 +326,8 @@ public class DefaultBuildExtensionScannerTest
new DefaultBuildExtensionScanner( extensionManager, projectBuilder, modelLineageBuilder,
modelInterpolator, new ConsoleLogger( Logger.LEVEL_DEBUG,
"test" ) ).scanForBuildExtensions( pomFile,
request );
request,
false );
mockManager.verifyAll();
}

View File

@ -363,7 +363,7 @@ public class MavenEmbedder
{
getLogger().debug( "Scanning for extensions: " + mavenProject );
extensionScanner.scanForBuildExtensions( mavenProject, request );
extensionScanner.scanForBuildExtensions( mavenProject, request, true );
getLogger().debug( "Building MavenProject instance: " + mavenProject );

View File

@ -338,6 +338,15 @@ public class MavenEmbedderTest
assertEquals( "scm:svn:https://host/trunk/parent/modules/child1", project.getScm().getDeveloperConnection() );
}
public void testProjectReading_SkipMissingModuleSilently()
throws Exception
{
File pomFile = new File( basedir,
"src/test/projects/readProject-missingModuleIgnored/pom.xml" );
maven.readProject( pomFile );
}
/*
public void testProjectReadingWithDistributionStatus()
throws Exception

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?><project>
<modelVersion>4.0.0</modelVersion>
<groupId>missing.module</groupId>
<artifactId>parent</artifactId>
<version>1</version>
<packaging>pom</packaging>
<modules>
<module>child1</module>
</modules>
</project>