Removed extension scanner. It was tied up into the old model lineage code, which is very buggy. Needs to be reimplemented.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@700226 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2008-09-29 19:51:10 +00:00
parent 90c71d6b73
commit 534b660b4e
26 changed files with 2 additions and 4254 deletions

View File

@ -22,8 +22,6 @@ package org.apache.maven;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.execution.*;
import org.apache.maven.extension.BuildExtensionScanner;
import org.apache.maven.extension.ExtensionScanningException;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.lifecycle.TaskValidationResult;
@ -77,8 +75,6 @@ public class DefaultMaven
protected RuntimeInformation runtimeInformation;
private BuildExtensionScanner buildExtensionScanner;
private Logger logger;
// ----------------------------------------------------------------------
@ -263,17 +259,6 @@ public class DefaultMaven
e );
}
// TODO: We should probably do this discovery just-in-time, if we can move to building project
// instances just-in-time.
try
{
buildExtensionScanner.scanForBuildExtensions( files, request, false );
}
catch ( ExtensionScanningException e )
{
throw new MavenExecutionException( "Error scanning for extensions: " + e.getMessage(), e );
}
projects = collectProjects( files, request, !request.useReactor() );
return projects;

View File

@ -13,8 +13,6 @@ import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.extension.ExtensionManagerException;
import org.apache.maven.extension.ModelInterpolationException;
import org.apache.maven.lifecycle.LifecycleException;
import org.apache.maven.lifecycle.LifecycleLoaderException;
import org.apache.maven.lifecycle.LifecycleSpecificationException;
@ -37,7 +35,6 @@ import org.apache.maven.project.DuplicateArtifactAttachmentException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.errors.ProjectErrorReporter;
import org.apache.maven.path.PathTranslator;
import org.apache.maven.reactor.MavenExecutionException;
import org.apache.maven.reactor.MissingModuleException;
@ -69,14 +66,10 @@ public interface CoreErrorReporter
void reportErrorFormulatingBuildPlan( List tasks, MavenProject project, MavenSession session, LifecycleException cause );
void reportErrorInterpolatingModel( Model model, Map inheritedValues, File pomFile, MavenExecutionRequest request, ModelInterpolationException cause );
void reportErrorLoadingPlugin( MojoBinding binding, MavenProject project, PluginLoaderException cause );
void reportErrorManagingRealmForExtension( Artifact extensionArtifact, Artifact projectArtifact, List remoteRepos, MavenExecutionRequest request, RealmManagementException cause );
void reportErrorResolvingExtensionDependencies( Artifact extensionArtifact, Artifact projectArtifact, List remoteRepos, MavenExecutionRequest request, ArtifactResolutionResult resolutionResult, ExtensionManagerException err );
void reportErrorResolvingExtensionDirectDependencies( Artifact extensionArtifact, Artifact projectArtifact, List remoteRepos, MavenExecutionRequest request, ArtifactMetadataRetrievalException cause );
void reportErrorSearchingforCompatibleExtensionPluginVersion( Plugin plugin, Model originModel, List remoteRepos, MavenExecutionRequest request, String requiredMavenVersion, String currentMavenVersion, InvalidVersionSpecificationException cause );

View File

@ -1,7 +1,6 @@
package org.apache.maven.errors;
import org.apache.maven.ProjectCycleException;
import org.apache.maven.extension.ModelInterpolationException;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
@ -181,13 +180,6 @@ public final class CoreErrorTips
return null;
}
public static List getTipsForModelInterpolationError( Model model,
File pomFile,
ModelInterpolationException cause )
{
// TODO Auto-generated method stub
return null;
}
public static List getIncompatibleProjectMavenVersionPrereqTips( MavenProject project,
ArtifactVersion mavenVersion )

View File

@ -9,14 +9,11 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
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.CyclicDependencyException;
import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.extension.ExtensionManagerException;
import org.apache.maven.lifecycle.LifecycleException;
import org.apache.maven.lifecycle.LifecycleLoaderException;
import org.apache.maven.lifecycle.LifecycleSpecificationException;
@ -42,10 +39,6 @@ import org.apache.maven.project.DuplicateArtifactAttachmentException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.errors.DefaultProjectErrorReporter;
import org.apache.maven.errors.ProjectErrorReporter;
import org.apache.maven.errors.ProjectReporterManager;
import org.apache.maven.extension.ModelInterpolationException;
import org.apache.maven.reactor.MavenExecutionException;
import org.apache.maven.reactor.MissingModuleException;
import org.apache.maven.realm.RealmManagementException;
@ -60,7 +53,6 @@ import java.io.File;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -844,26 +836,6 @@ public class DefaultCoreErrorReporter
registerBuildError( exception, formattedMessage, reportedException );
}
public void reportErrorInterpolatingModel( Model model,
Map inheritedValues,
File pomFile,
MavenExecutionRequest request,
ModelInterpolationException cause )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "You have an invalid expression in your POM (interpolation failed):" );
writer.write( NEWLINE );
writer.write( cause.getMessage() );
writeProjectCoordinate( model, pomFile, writer );
addTips( CoreErrorTips.getTipsForModelInterpolationError( model, pomFile, cause ),
writer );
registerBuildError( cause, writer.toString(), cause.getCause() );
}
public void reportErrorResolvingExtensionDirectDependencies( Artifact extensionArtifact,
Artifact projectArtifact,
List remoteRepos,
@ -901,140 +873,6 @@ public class DefaultCoreErrorReporter
registerBuildError( cause, writer.toString(), cause.getCause() );
}
public void reportErrorResolvingExtensionDependencies( Artifact extensionArtifact,
Artifact projectArtifact,
List remoteRepos,
MavenExecutionRequest request,
ArtifactResolutionResult resolutionResult,
ExtensionManagerException err )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "Maven encountered an error while trying to resolve the artifacts for a build extension used in your project." );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Project:" );
writeArtifactInfo( projectArtifact, writer, false );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Extension:" );
writeArtifactInfo( extensionArtifact, writer, false );
writer.write( NEWLINE );
writer.write( NEWLINE );
List missingArtifacts = resolutionResult.getMissingArtifacts();
if ( ( missingArtifacts != null ) && !missingArtifacts.isEmpty() )
{
writer.write( "The following artifacts were not found." );
writer.write( NEWLINE );
writer.write( "(Format is: groupId:artifactId:version:type[:classifier])" );
writer.write( NEWLINE );
for ( Iterator it = missingArtifacts.iterator(); it.hasNext(); )
{
Artifact artifact = (Artifact) it.next();
writer.write( NEWLINE );
writeCompactArtifactCoordinate( "- ", artifact, writer );
}
writer.write( NEWLINE );
writer.write( NEWLINE );
}
List circularDependencyExceptions = resolutionResult.getCircularDependencyExceptions();
if ( ( circularDependencyExceptions != null ) && !circularDependencyExceptions.isEmpty() )
{
writer.write( "The following dependency cycles were found." );
writer.write( NEWLINE );
writer.write( "(Format is: groupId:artifactId:version:type[:classifier]), followed by the dependency trail that included the offending artifact.)" );
writer.write( NEWLINE );
int i = 1;
for ( Iterator it = circularDependencyExceptions.iterator(); it.hasNext(); )
{
CyclicDependencyException cde = (CyclicDependencyException) it.next();
Artifact artifact = cde.getArtifact();
writer.write( NEWLINE );
writeCompactArtifactCoordinate( i + ". ", artifact, writer );
List trail = artifact.getDependencyTrail();
for ( Iterator trailIt = trail.iterator(); trailIt.hasNext(); )
{
String id = (String) trailIt.next();
writer.write( NEWLINE );
writer.write( " - " );
writer.write( id );
}
writer.write( NEWLINE );
i++;
}
writer.write( NEWLINE );
}
Map mapOfLists = new LinkedHashMap();
List metadataExceptions = resolutionResult.getMetadataResolutionExceptions();
if ( ( metadataExceptions != null ) && !metadataExceptions.isEmpty() )
{
mapOfLists.put( "The following metadata-resolution errors were found.", metadataExceptions );
}
List errorArtifactExceptions = resolutionResult.getErrorArtifactExceptions();
if ( ( errorArtifactExceptions != null ) && !errorArtifactExceptions.isEmpty() )
{
mapOfLists.put( "The following artifact-resolution errors were found.", errorArtifactExceptions );
}
List versionRangeViolations = resolutionResult.getVersionRangeViolations();
if ( ( versionRangeViolations != null ) && !versionRangeViolations.isEmpty() )
{
mapOfLists.put( "The following artifact version-range violations were found.", versionRangeViolations );
}
for ( Iterator entryIt = mapOfLists.entrySet().iterator(); entryIt.hasNext(); )
{
Map.Entry entry = (Map.Entry) entryIt.next();
String key = (String) entry.getKey();
List exceptions = (List) entry.getValue();
writer.write( key );
writer.write( NEWLINE );
int i = 1;
for ( Iterator it = exceptions.iterator(); it.hasNext(); )
{
Exception e = (Exception) it.next();
writer.write( NEWLINE );
writer.write( i );
writer.write( ". " );
writer.write( e.getMessage() );
Throwable t = getRootCause( e );
if ( ( t != null ) && ( t != e ) )
{
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( "Root error: " );
writer.write( NEWLINE );
writer.write( NEWLINE );
writer.write( t.getMessage() );
}
writer.write( NEWLINE );
i++;
}
writer.write( NEWLINE );
}
addTips( CoreErrorTips.getErrorResolvingExtensionArtifactsTips( extensionArtifact, projectArtifact, resolutionResult ),
writer );
registerBuildError( err, writer.toString() );
}
private void writeCompactArtifactCoordinate( String linePrefix,
Artifact artifact,
StringWriter writer )

View File

@ -21,7 +21,6 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.ModelAndFile;
import org.apache.maven.extension.ModelInterpolationException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@ -416,23 +415,6 @@ public class DefaultProjectErrorReporter
registerBuildError( cause, writer.toString() );
}
public void reportErrorInterpolatingModel( MavenProject project,
File pomFile,
ModelInterpolationException cause )
{
StringWriter writer = new StringWriter();
writer.write( NEWLINE );
writer.write( "You have an invalid expression in your POM (interpolation failed):" );
writer.write( NEWLINE );
writer.write( cause.getMessage() );
addStandardInfo( project.getId(), pomFile, writer );
addTips( ProjectErrorTips.getTipsForProjectInterpolationError( project, pomFile, cause ),
writer );
registerBuildError( cause, writer.toString() );
}
public void reportProjectValidationFailure( MavenProject project,
File pomFile,

View File

@ -18,7 +18,6 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.ModelAndFile;
import org.apache.maven.extension.ModelInterpolationException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@ -180,25 +179,6 @@ public interface ProjectErrorReporter
Repository repo,
InvalidRepositoryException cause );
/**
* <b>Call Stack:</b>
* <br/>
* <pre>
* ...
* --&gt; DefaultMavenProjectBuilder.buildFromRepository(..)
* DefaultMavenProjectBuilder.build(..)
* --&gt; DefaultMavenProjectBuilder.buildFromSourceFileInternal(..) (private)
* --&gt; DefaultMavenProjectBuilder.buildInternal(..) (private)
* --&gt; DefaultMavenProjectBuilder.processProjectLogic(..) (private)
* --&gt; ModelInterpolator.interpolate(..)
* &lt;-- ModelInterpolationException
* &lt;---------- ProjectBuildingException
* </pre>
*/
void reportErrorInterpolatingModel( MavenProject project,
File pomFile,
ModelInterpolationException cause );
/**
* <b>Call Stack:</b>
* <br/>

View File

@ -11,7 +11,6 @@ import org.apache.maven.profiles.activation.ProfileActivator;
import org.apache.maven.execution.DuplicateProjectException;
import org.apache.maven.project.InvalidProjectVersionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.extension.ModelInterpolationException;
import org.apache.maven.project.validation.ModelValidationResult;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@ -126,14 +125,6 @@ public final class ProjectErrorTips
return null;
}
public static List getTipsForProjectInterpolationError( MavenProject project,
File pomFile,
ModelInterpolationException cause )
{
// TODO Auto-generated method stub
return null;
}
public static List getTipsForPomParsingError( String projectId,
File pomFile,
Exception cause )

View File

@ -1,43 +0,0 @@
package org.apache.maven.extension;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.reactor.MissingModuleException;
import java.io.File;
import java.util.List;
public interface BuildExtensionScanner
{
String ROLE = BuildExtensionScanner.class.getName();
void scanForBuildExtensions( List files,
MavenExecutionRequest request,
boolean ignoreMissingModules )
throws ExtensionScanningException, MissingModuleException;
void scanForBuildExtensions( File pom,
MavenExecutionRequest request,
boolean ignoreMissingModules )
throws ExtensionScanningException, MissingModuleException;
}

View File

@ -1,485 +0,0 @@
package org.apache.maven.extension;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.model.Build;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.builder.PomClassicTransformer;
import org.apache.maven.project.builder.PomInterpolatorTag;
import org.apache.maven.extension.lineage.ModelLineage;
import org.apache.maven.extension.lineage.ModelLineageBuilder;
import org.apache.maven.extension.lineage.ModelLineageIterator;
import org.apache.maven.extension.ModelInterpolationException;
import org.apache.maven.reactor.MissingModuleException;
import org.apache.maven.shared.model.InterpolatorProperty;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.text.SimpleDateFormat;
public class DefaultBuildExtensionScanner
implements BuildExtensionScanner, LogEnabled
{
private Logger logger;
private ExtensionManager extensionManager;
private MavenProjectBuilder projectBuilder;
private ModelLineageBuilder modelLineageBuilder;
// cached.
private MavenProject basicSuperProject;
public DefaultBuildExtensionScanner()
{
}
public void scanForBuildExtensions( List files,
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, ignoreMissingModules );
}
}
public void scanForBuildExtensions( File pom,
MavenExecutionRequest request,
boolean ignoreMissingModules )
throws ExtensionScanningException, MissingModuleException
{
List internalFiles = new ArrayList();
internalFiles.add( pom );
scanInternal( pom, request, new ArrayList(), internalFiles, ignoreMissingModules );
}
private void scanInternal( File pom,
MavenExecutionRequest request,
List visitedModelIds,
List reactorFiles,
boolean ignoreMissingModules )
throws ExtensionScanningException, MissingModuleException
{
try
{
List originalRemoteRepositories = getInitialRemoteRepositories( request.getProjectBuildingConfiguration() );
getLogger().debug( "Pre-scanning POM lineage of: " + pom + " for build extensions." );
ModelLineage lineage = buildModelLineage( pom, request.getProjectBuildingConfiguration(), originalRemoteRepositories );
Map inheritedInterpolationValues = new HashMap();
List inheritedRemoteRepositories = new ArrayList();
inheritedRemoteRepositories.addAll( originalRemoteRepositories );
Set managedPluginsWithExtensionsFlag = new HashSet();
for ( ModelLineageIterator lineageIterator = lineage.reversedLineageIterator(); lineageIterator.hasNext(); )
{
Model model = (Model) lineageIterator.next();
File modelPom = lineageIterator.getPOMFile();
List remoteRepos = lineageIterator.getArtifactRepositories();
if ( ( remoteRepos != null ) && !remoteRepos.isEmpty() )
{
inheritedRemoteRepositories.addAll( remoteRepos );
}
String key = createKey( model );
ProjectBuilderConfiguration config = request.getProjectBuildingConfiguration();
Properties execProps = new Properties();
if ( config.getExecutionProperties() != null )
{
execProps.putAll( config.getExecutionProperties() );
}
if ( inheritedInterpolationValues != null )
{
execProps.putAll( inheritedInterpolationValues );
}
else
{
inheritedInterpolationValues = new HashMap();
}
config.setExecutionProperties( execProps );
//INTERPOLATION
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties(),
PomInterpolatorTag.SYSTEM_PROPERTIES.name()));
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getUserProperties(),
PomInterpolatorTag.USER_PROPERTIES.name()));
if(config.getBuildStartTime() != null)
{
interpolatorProperties.add(new InterpolatorProperty("${build.timestamp}",
new SimpleDateFormat("yyyyMMdd-hhmm").format( config.getBuildStartTime() ),
PomInterpolatorTag.PROJECT_PROPERTIES.name()));
}
model = PomClassicTransformer.interpolateModel( model, interpolatorProperties, modelPom.getParentFile());
grabManagedPluginsWithExtensionsFlagTurnedOn( model, managedPluginsWithExtensionsFlag );
Properties modelProps = model.getProperties();
if ( modelProps != null )
{
inheritedInterpolationValues.putAll( modelProps );
}
if ( visitedModelIds.contains( key ) )
{
getLogger().debug( "Already visited: " + key + "; continuing." );
continue;
}
visitedModelIds.add( key );
getLogger().debug(
"Checking: " + model.getId() + " for extensions. (It has "
+ model.getModules().size() + " modules.)" );
checkModelBuildForExtensions( model, request, inheritedRemoteRepositories, managedPluginsWithExtensionsFlag );
if ( !reactorFiles.contains( modelPom ) )
{
getLogger().debug(
"POM: " + modelPom
+ " is not in the current reactor. Its modules will not be scanned." );
}
else if ( request.isRecursive() )
{
checkModulesForExtensions( modelPom,
model,
request,
originalRemoteRepositories,
visitedModelIds,
reactorFiles,
ignoreMissingModules );
}
}
}
catch ( IOException e )
{
throw new ExtensionScanningException( "Failed to interpolate model from: " + pom
+ " prior to scanning for extensions.", pom, new ModelInterpolationException(e.getMessage()) );
}
}
private void grabManagedPluginsWithExtensionsFlagTurnedOn( Model model,
Set managedPluginsWithExtensionsFlag )
{
Build build = model.getBuild();
if ( build != null )
{
PluginManagement pluginManagement = build.getPluginManagement();
if ( pluginManagement != null )
{
List plugins = pluginManagement.getPlugins();
if ( ( plugins != null ) && !plugins.isEmpty() )
{
for ( Iterator it = plugins.iterator(); it.hasNext(); )
{
Plugin plugin = (Plugin) it.next();
if ( plugin.isExtensions() )
{
managedPluginsWithExtensionsFlag.add( plugin.getKey() );
}
}
}
}
}
}
private String createKey( Model model )
{
Parent parent = model.getParent();
String groupId = model.getGroupId();
if ( groupId == null )
{
groupId = parent.getGroupId();
}
String artifactId = model.getArtifactId();
return groupId + ":" + artifactId;
}
private void checkModulesForExtensions( File containingPom,
Model model,
MavenExecutionRequest request,
List originalRemoteRepositories,
List visitedModelIds,
List reactorFiles,
boolean ignoreMissingModules )
throws ExtensionScanningException, MissingModuleException
{
// FIXME: This gets a little sticky, because modules can be added by profiles that require
// an extension in place before they can be activated.
List modules = model.getModules();
if ( modules != null )
{
File basedir = containingPom.getParentFile();
getLogger().debug( "Basedir is: " + basedir );
for ( Iterator it = modules.iterator(); it.hasNext(); )
{
// TODO: change this if we ever find a way to replace module definitions with g:a:v
String moduleSubpath = (String) it.next();
getLogger().debug( "Scanning module: " + moduleSubpath );
File modulePomDirectory;
try
{
modulePomDirectory = new File( basedir, moduleSubpath ).getCanonicalFile();
// ----------------------------------------------------------------------------
// We need to make sure we don't loop infinitely in the case where we have
// something like:
//
// <modules>
// <module>../MNGECLIPSE-256web</module>
// <module>../MNGECLIPSE-256utility</module>
// </modules>
//
// Where once we walk into the first module it will just get its parent dir
// containing its POM over and over again unless we make a comparison to
// basedir and the modulePomDirectory.
// ----------------------------------------------------------------------------
if ( modulePomDirectory.equals( basedir.getCanonicalFile() ) )
{
break;
}
}
catch ( IOException e )
{
throw new ExtensionScanningException( "Error getting canonical path for modulePomDirectory.", containingPom, moduleSubpath, e );
}
if ( modulePomDirectory.isDirectory() )
{
getLogger().debug(
"Assuming POM file 'pom.xml' in module: " + moduleSubpath + " under basedir: "
+ basedir );
modulePomDirectory = new File( modulePomDirectory, "pom.xml" );
}
if ( !modulePomDirectory.exists() )
{
if ( ignoreMissingModules )
{
continue;
}
else
{
throw new MissingModuleException( moduleSubpath, modulePomDirectory, containingPom );
}
}
reactorFiles.add( modulePomDirectory );
scanInternal( modulePomDirectory, request, visitedModelIds, reactorFiles, ignoreMissingModules );
}
}
}
private void checkModelBuildForExtensions( Model model,
MavenExecutionRequest request,
List remoteRepositories,
Set managedPluginsWithExtensionsFlag )
throws ExtensionScanningException
{
getLogger().debug( "Checking " + model.getId() + " for extensions." );
Build build = model.getBuild();
if ( build != null )
{
List extensions = build.getExtensions();
if ( ( extensions != null ) && !extensions.isEmpty() )
{
// thankfully, we don't have to deal with dependencyManagement here, yet.
// TODO Revisit if/when extensions are made to use the info in dependencyManagement
for ( Iterator extensionIterator = extensions.iterator(); extensionIterator.hasNext(); )
{
Extension extension = (Extension) extensionIterator.next();
getLogger().debug(
"Adding extension: "
+ ArtifactUtils.versionlessKey( extension.getGroupId(), extension
.getArtifactId() ) + " from model: " + model.getId() );
try
{
extensionManager.addExtension( extension, model, remoteRepositories, request );
}
catch ( ExtensionManagerException e )
{
throw new ExtensionScanningException( "Cannot resolve pre-scanned extension artifact: "
+ extension.getGroupId() + ":" + extension.getArtifactId() + ": " + e.getMessage(), model, extension, e );
}
}
}
List plugins = build.getPlugins();
if ( ( plugins != null ) && !plugins.isEmpty() )
{
for ( Iterator extensionIterator = plugins.iterator(); extensionIterator.hasNext(); )
{
Plugin plugin = (Plugin) extensionIterator.next();
if ( plugin.isExtensions() || managedPluginsWithExtensionsFlag.contains( plugin.getKey() ) )
{
getLogger().debug( "Adding plugin: " + plugin.getKey() + " as an extension(from model: " + model.getId() + ")" );
try
{
extensionManager.addPluginAsExtension( plugin, model, remoteRepositories, request );
}
catch ( ExtensionManagerException e )
{
throw new ExtensionScanningException( "Cannot resolve pre-scanned plugin artifact (for use as an extension): "
+ plugin.getKey() + ": " + e.getMessage(), model, plugin, e );
}
}
}
}
}
}
private ModelLineage buildModelLineage( File pom, ProjectBuilderConfiguration config,
List originalRemoteRepositories )
throws ExtensionScanningException
{
ProfileManager profileManager = config.getGlobalProfileManager();
ProfileActivationContext profileActivationContext = profileManager == null
? new DefaultProfileActivationContext( config.getExecutionProperties(), false )
: profileManager.getProfileActivationContext();
boolean suppressActivatorFailure = profileActivationContext.isCustomActivatorFailureSuppressed();
ModelLineage lineage;
try
{
getLogger().debug( "Building model-lineage for: " + pom + " to pre-scan for extensions." );
// NOTE: We're assuming that this scan happens only for local filesystem POMs,
// not for POMs from the repository...otherwise, we would need to be more careful with
// the last parameter here and determine whether it's appropriate for the POM to have
// an accompanying profiles.xml file.
profileActivationContext.setCustomActivatorFailureSuppressed( true );
lineage = modelLineageBuilder.buildModelLineage( pom, config, originalRemoteRepositories, false, true );
}
catch ( ProjectBuildingException e )
{
throw new ExtensionScanningException( "Error building model lineage in order to pre-scan for extensions: "
+ e.getMessage(), pom, e );
}
finally
{
profileActivationContext.setCustomActivatorFailureSuppressed( suppressActivatorFailure );
}
return lineage;
}
private List<ArtifactRepository> getInitialRemoteRepositories( ProjectBuilderConfiguration config )
throws ExtensionScanningException
{
if ( basicSuperProject == null )
{
try
{
basicSuperProject = projectBuilder.buildStandaloneSuperProject( config );
}
catch ( ProjectBuildingException e )
{
throw new ExtensionScanningException(
"Error building super-POM for retrieving the default remote repository list: "
+ e.getMessage(), e );
}
}
return basicSuperProject.getRemoteArtifactRepositories();
}
protected Logger getLogger()
{
if ( logger == null )
{
logger = new ConsoleLogger( Logger.LEVEL_DEBUG, "DefaultBuildExtensionScanner:internal" );
}
return logger;
}
public void enableLogging( Logger logger )
{
this.logger = logger;
}
}

View File

@ -1,438 +0,0 @@
package org.apache.maven.extension;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.ArtifactFilterManager;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.metadata.ResolutionGroup;
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.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Plugin;
import org.apache.maven.monitor.event.DefaultEventDispatcher;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.plugin.InvalidPluginException;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.PluginManagerException;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.realm.RealmManagementException;
import org.apache.maven.realm.RealmUtils;
import org.codehaus.plexus.MutablePlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
/**
* Used to locate extensions.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @author Jason van Zyl
* @version $Id$
*/
public class DefaultExtensionManager
extends AbstractLogEnabled
implements ExtensionManager, Contextualizable
{
private ArtifactFactory artifactFactory;
private ArtifactResolver artifactResolver;
private ArtifactMetadataSource artifactMetadataSource;
private MutablePlexusContainer container;
private ArtifactFilterManager artifactFilterManager;
private WagonManager wagonManager;
private PluginManager pluginManager;
// used for unit testing.
protected DefaultExtensionManager( ArtifactFactory artifactFactory,
ArtifactResolver artifactResolver,
ArtifactMetadataSource artifactMetadataSource,
MutablePlexusContainer container,
ArtifactFilterManager artifactFilterManager,
WagonManager wagonManager )
{
this.artifactFactory = artifactFactory;
this.artifactResolver = artifactResolver;
this.artifactMetadataSource = artifactMetadataSource;
this.container = container;
this.artifactFilterManager = artifactFilterManager;
this.wagonManager = wagonManager;
}
public DefaultExtensionManager()
{
// used for plexus init.
}
public void addExtension( Extension extension,
Model originatingModel,
List remoteRepositories,
MavenExecutionRequest request )
throws ExtensionManagerException
{
Artifact extensionArtifact = artifactFactory.createBuildArtifact( extension.getGroupId(),
extension.getArtifactId(),
extension.getVersion(), "jar" );
Parent originatingParent = originatingModel.getParent();
String groupId = originatingModel.getGroupId();
if ( ( groupId == null ) && ( originatingParent != null ) )
{
groupId = originatingParent.getGroupId();
}
String artifactId = originatingModel.getArtifactId();
String version = originatingModel.getVersion();
if ( ( version == null ) && ( originatingParent != null ) )
{
version = originatingParent.getVersion();
}
Artifact projectArtifact = artifactFactory.createProjectArtifact( groupId, artifactId, version );
addExtension( extensionArtifact,
projectArtifact,
remoteRepositories,
request,
null,
groupId,
artifactId,
version );
}
public void addPluginAsExtension( Plugin plugin,
Model originatingModel,
List remoteRepositories,
MavenExecutionRequest request )
throws ExtensionManagerException
{
getLogger().debug( "Adding plugin: " + plugin.getKey() + " as an extension." );
Parent originatingParent = originatingModel.getParent();
String groupId = originatingModel.getGroupId();
if ( ( groupId == null ) && ( originatingParent != null ) )
{
groupId = originatingParent.getGroupId();
}
String artifactId = originatingModel.getArtifactId();
String version = originatingModel.getVersion();
if ( ( version == null ) && ( originatingParent != null ) )
{
version = originatingParent.getVersion();
}
String pluginVersion = plugin.getVersion();
// TODO: Forbid this?
if ( pluginVersion == null )
{
pluginVersion = Artifact.RELEASE_VERSION;
}
Artifact pluginArtifact = artifactFactory.createBuildArtifact( plugin.getGroupId(),
plugin.getArtifactId(),
pluginVersion, "maven-plugin" );
getLogger().debug( "Starting extension-addition process for: " + pluginArtifact );
ArtifactFilter coreFilter = artifactFilterManager.getArtifactFilter();
MavenRealmManager realmManager = request.getRealmManager();
// if the extension is null,
// or if it's excluded by the core filter,
//
// skip it.
if ( ( pluginArtifact != null )
&& coreFilter.include( pluginArtifact ) )
{
MavenProject dummyProject = new MavenProject( originatingModel );
dummyProject.setRemoteArtifactRepositories( remoteRepositories );
EventDispatcher dispatcher = new DefaultEventDispatcher( request.getEventMonitors() );
MavenSession session = new MavenSession( container, request, dispatcher, null );
PluginDescriptor pd;
try
{
pd = pluginManager.verifyPlugin( plugin, dummyProject, session );
pluginArtifact = pd.getPluginArtifact();
}
catch ( ArtifactResolutionException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( ArtifactNotFoundException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( PluginNotFoundException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( PluginVersionResolutionException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( InvalidPluginException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( PluginManagerException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( PluginVersionNotFoundException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
if ( !realmManager.hasExtensionRealm( pluginArtifact ) )
{
try
{
realmManager.createExtensionRealm( pluginArtifact, pd.getArtifacts() );
}
catch ( RealmManagementException e )
{
String projectId = RealmUtils.createProjectId( groupId, artifactId, version );
throw new ExtensionManagerException( "Unable to create extension ClassRealm for extension: " + pluginArtifact.getId() + " within session for project: " + projectId, pluginArtifact, groupId, artifactId, version, e );
}
}
try
{
realmManager.importExtensionsIntoProjectRealm( groupId, artifactId, version, pluginArtifact );
}
catch ( RealmManagementException e )
{
throw new ExtensionManagerException( "Unable to import extension components into project realm.", pluginArtifact, groupId, artifactId, version, e );
}
}
}
public void addExtension( Extension extension,
MavenProject project,
MavenExecutionRequest request )
throws ExtensionManagerException
{
String extensionId = ArtifactUtils.versionlessKey( extension.getGroupId(), extension.getArtifactId() );
getLogger().debug( "Initialising extension: " + extensionId );
Artifact artifact = (Artifact) project.getExtensionArtifactMap().get( extensionId );
addExtension( artifact,
project.getArtifact(),
project.getRemoteArtifactRepositories(),
request,
new ActiveArtifactResolver( project ),
project.getGroupId(),
project.getArtifactId(),
project.getVersion() );
}
private void addExtension( Artifact extensionArtifact,
Artifact projectArtifact,
List<ArtifactRepository> remoteRepositories,
MavenExecutionRequest request,
ActiveArtifactResolver activeArtifactResolver,
String projectGroupId,
String projectArtifactId,
String projectVersion )
throws ExtensionManagerException
{
getLogger().debug( "Starting extension-addition process for: " + extensionArtifact );
ArtifactFilter coreFilter = artifactFilterManager.getArtifactFilter();
MavenRealmManager realmManager = request.getRealmManager();
// if the extension is null,
// or if it's excluded by the core filter,
//
// skip it.
if ( ( extensionArtifact != null )
&& coreFilter.include( extensionArtifact ) )
{
ArtifactFilter filter =
new ProjectArtifactExceptionFilter( coreFilter, projectArtifact );
ResolutionGroup resolutionGroup;
ArtifactRepository localRepository = request.getLocalRepository();
try
{
resolutionGroup = artifactMetadataSource.retrieve( extensionArtifact, localRepository, remoteRepositories );
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new ExtensionManagerException( "Unable to download metadata from repository for extension artifact '" +
extensionArtifact.getId() + "': " + e.getMessage(), extensionArtifact, projectGroupId, projectArtifactId, projectVersion, e );
}
Set<Artifact> dependencies = new LinkedHashSet<Artifact>();
dependencies.add( extensionArtifact );
dependencies.addAll( resolutionGroup.getArtifacts() );
ArtifactResolutionRequest dependencyReq = new ArtifactResolutionRequest().setArtifact( projectArtifact )
.setArtifactDependencies( dependencies )
.setFilter( filter )
.setLocalRepository( localRepository )
.setRemoteRepostories( remoteRepositories )
.setMetadataSource( artifactMetadataSource );
// TODO: Make this work with managed dependencies, or an analogous management section in the POM.
ArtifactResolutionResult result = artifactResolver.resolve( dependencyReq );
if ( result.hasCircularDependencyExceptions() || result.hasErrorArtifactExceptions()
|| result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() )
{
throw new ExtensionManagerException( "Failed to resolve extension: " + extensionArtifact, extensionArtifact, projectGroupId, projectArtifactId, projectVersion, result );
}
Set resultArtifacts = new LinkedHashSet();
for ( Iterator iterator = result.getArtifacts().iterator(); iterator.hasNext(); )
{
Artifact a = (Artifact) iterator.next();
if ( activeArtifactResolver != null )
{
a = activeArtifactResolver.replaceWithActiveArtifact( a );
}
getLogger().debug( "Adding: " + a.getFile() + " to classpath for extension: " + extensionArtifact.getId() );
resultArtifacts.add( a );
}
if ( !realmManager.hasExtensionRealm( extensionArtifact ) )
{
try
{
realmManager.createExtensionRealm( extensionArtifact, new ArrayList( resultArtifacts ) );
}
catch ( RealmManagementException e )
{
String projectId = RealmUtils.createProjectId( projectGroupId, projectArtifactId, projectVersion );
throw new ExtensionManagerException( "Unable to create extension ClassRealm for extension: " + extensionArtifact.getId() + " within session for project: " + projectId, extensionArtifact, projectGroupId, projectArtifactId, projectVersion, e );
}
}
try
{
realmManager.importExtensionsIntoProjectRealm( projectGroupId, projectArtifactId, projectVersion, extensionArtifact );
}
catch ( RealmManagementException e )
{
throw new ExtensionManagerException( "Unable to import extension components into project realm.", extensionArtifact, projectGroupId, projectArtifactId, projectVersion, e );
}
}
}
public void registerWagons()
{
wagonManager.findAndRegisterWagons( container );
}
public void contextualize( Context context )
throws ContextException
{
container = (MutablePlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
private static final class ActiveArtifactResolver
{
private MavenProject project;
ActiveArtifactResolver( MavenProject project )
{
this.project = project;
}
Artifact replaceWithActiveArtifact( Artifact artifact )
{
return project.replaceWithActiveArtifact( artifact );
}
}
private static final class ProjectArtifactExceptionFilter
implements ArtifactFilter
{
private ArtifactFilter passThroughFilter;
private String projectDependencyConflictId;
ProjectArtifactExceptionFilter( ArtifactFilter passThroughFilter,
Artifact projectArtifact )
{
this.passThroughFilter = passThroughFilter;
projectDependencyConflictId = projectArtifact.getDependencyConflictId();
}
public boolean include( Artifact artifact )
{
String depConflictId = artifact.getDependencyConflictId();
return projectDependencyConflictId.equals( depConflictId ) || passThroughFilter.include( artifact );
}
}
}

View File

@ -1,56 +0,0 @@
package org.apache.maven.extension;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
import java.util.List;
/**
* Used to locate extensions.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public interface ExtensionManager
{
void addExtension( Extension extension,
MavenProject project,
MavenExecutionRequest request )
throws ExtensionManagerException;
void registerWagons();
void addExtension( Extension extension,
Model originatingModel,
List remoteRepositories,
MavenExecutionRequest request )
throws ExtensionManagerException;
void addPluginAsExtension( Plugin plugin,
Model originatingModel,
List remoteRepositories,
MavenExecutionRequest request )
throws ExtensionManagerException;
}

View File

@ -1,195 +0,0 @@
package org.apache.maven.extension;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
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.plugin.InvalidPluginException;
import org.apache.maven.plugin.PluginManagerException;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.realm.RealmManagementException;
public class ExtensionManagerException
extends Exception
{
private Artifact extensionArtifact;
private ArtifactResolutionResult resolutionResult;
private String projectGroupId;
private String projectArtifactId;
private String projectVersion;
public ExtensionManagerException( String message,
Artifact extensionArtifact,
String projectGroupId,
String projectArtifactId,
String projectVersion,
ArtifactMetadataRetrievalException cause )
{
super( message, cause );
this.extensionArtifact = extensionArtifact;
this.projectGroupId = projectGroupId;
this.projectArtifactId = projectArtifactId;
this.projectVersion = projectVersion;
}
public ExtensionManagerException( String message,
Artifact extensionArtifact,
String projectGroupId,
String projectArtifactId,
String projectVersion,
ArtifactResolutionResult result )
{
super( message );
this.extensionArtifact = extensionArtifact;
this.projectGroupId = projectGroupId;
this.projectArtifactId = projectArtifactId;
this.projectVersion = projectVersion;
resolutionResult = result;
}
public ExtensionManagerException( String message,
Artifact extensionArtifact,
String projectGroupId,
String projectArtifactId,
String projectVersion,
RealmManagementException cause )
{
super( message, cause );
this.extensionArtifact = extensionArtifact;
this.projectGroupId = projectGroupId;
this.projectArtifactId = projectArtifactId;
this.projectVersion = projectVersion;
}
public ExtensionManagerException( String message,
Artifact extensionArtifact,
String projectGroupId,
String projectArtifactId,
String projectVersion,
ArtifactResolutionException cause )
{
super( message, cause );
this.extensionArtifact = extensionArtifact;
this.projectGroupId = projectGroupId;
this.projectArtifactId = projectArtifactId;
this.projectVersion = projectVersion;
}
public ExtensionManagerException( String message,
Artifact extensionArtifact,
String projectGroupId,
String projectArtifactId,
String projectVersion,
ArtifactNotFoundException cause )
{
super( message, cause );
this.extensionArtifact = extensionArtifact;
this.projectGroupId = projectGroupId;
this.projectArtifactId = projectArtifactId;
this.projectVersion = projectVersion;
}
public ExtensionManagerException( String message,
Artifact extensionArtifact,
String projectGroupId,
String projectArtifactId,
String projectVersion,
PluginNotFoundException cause )
{
super( message, cause );
this.extensionArtifact = extensionArtifact;
this.projectGroupId = projectGroupId;
this.projectArtifactId = projectArtifactId;
this.projectVersion = projectVersion;
}
public ExtensionManagerException( String message,
Artifact extensionArtifact,
String projectGroupId,
String projectArtifactId,
String projectVersion,
PluginVersionResolutionException cause )
{
super( message, cause );
this.extensionArtifact = extensionArtifact;
this.projectGroupId = projectGroupId;
this.projectArtifactId = projectArtifactId;
this.projectVersion = projectVersion;
}
public ExtensionManagerException( String message,
Artifact extensionArtifact,
String projectGroupId,
String projectArtifactId,
String projectVersion,
InvalidPluginException cause )
{
super( message, cause );
this.extensionArtifact = extensionArtifact;
this.projectGroupId = projectGroupId;
this.projectArtifactId = projectArtifactId;
this.projectVersion = projectVersion;
}
public ExtensionManagerException( String message,
Artifact extensionArtifact,
String projectGroupId,
String projectArtifactId,
String projectVersion,
PluginManagerException cause )
{
super( message, cause );
this.extensionArtifact = extensionArtifact;
this.projectGroupId = projectGroupId;
this.projectArtifactId = projectArtifactId;
this.projectVersion = projectVersion;
}
public ExtensionManagerException( String message,
Artifact extensionArtifact,
String projectGroupId,
String projectArtifactId,
String projectVersion,
PluginVersionNotFoundException cause )
{
super( message, cause );
this.extensionArtifact = extensionArtifact;
this.projectGroupId = projectGroupId;
this.projectArtifactId = projectArtifactId;
this.projectVersion = projectVersion;
}
public Artifact getExtensionArtifact()
{
return extensionArtifact;
}
public String getProjectGroupId()
{
return projectGroupId;
}
public String getProjectArtifactId()
{
return projectArtifactId;
}
public String getProjectVersion()
{
return projectVersion;
}
public ArtifactResolutionResult getArtifactResolutionResult()
{
return resolutionResult;
}
}

View File

@ -1,112 +0,0 @@
package org.apache.maven.extension;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.extension.ModelInterpolationException;
import java.io.File;
import java.io.IOException;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
public class ExtensionScanningException
extends Exception
{
private File pomFile;
private String extensionId;
private String modelId;
private String moduleSubpath;
public ExtensionScanningException( String message,
File pomFile,
ProjectBuildingException cause )
{
super( message, cause );
this.pomFile = pomFile;
}
public ExtensionScanningException( String message,
Model model,
Extension extension,
ExtensionManagerException cause )
{
super( message, cause );
modelId = model.getId();
extensionId = extension.getGroupId() + ":" + extension.getArtifactId();
}
public ExtensionScanningException( String message,
ProjectBuildingException cause )
{
super( message, cause );
}
public ExtensionScanningException( String message,
File pomFile,
String moduleSubpath,
IOException cause )
{
super( message, cause );
this.pomFile = pomFile;
this.moduleSubpath = moduleSubpath;
}
public ExtensionScanningException( String message,
File pomFile,
ModelInterpolationException cause )
{
super( message, cause );
this.pomFile = pomFile;
}
public ExtensionScanningException( String message,
Model model,
Plugin plugin,
ExtensionManagerException cause )
{
super( message, cause );
modelId = model.getId();
extensionId = plugin.getGroupId() + ":" + plugin.getArtifactId();
}
public File getPomFile()
{
return pomFile;
}
public String getExtensionId()
{
return extensionId;
}
public String getModelId()
{
return modelId;
}
public String getModuleSubpath()
{
return moduleSubpath;
}
}

View File

@ -1,70 +0,0 @@
package org.apache.maven.extension;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @author jdcasey
* <p/>
* Created on Feb 2, 2005
*/
public class ModelInterpolationException
extends Exception
{
private String expression;
private String originalMessage;
public ModelInterpolationException( String message )
{
super( message );
}
public ModelInterpolationException( String message, Throwable cause )
{
super( message, cause );
}
public ModelInterpolationException( String expression, String message, Throwable cause )
{
super( "The POM expression: " + expression + " could not be evaluated. Reason: " + message, cause );
this.expression = expression;
this.originalMessage = message;
}
public ModelInterpolationException( String expression, String message )
{
super( "The POM expression: " + expression + " could not be evaluated. Reason: " + message );
this.expression = expression;
this.originalMessage = message;
}
public String getExpression()
{
return expression;
}
public String getOriginalMessage()
{
return originalMessage;
}
}

View File

@ -1,446 +0,0 @@
package org.apache.maven.extension.lineage;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.model.Model;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* @see ModelLineage
*/
public class DefaultModelLineage
implements ModelLineage
{
private List tuples = new ArrayList();
/**
* @see ModelLineage#addParent(org.apache.maven.model.Model, java.io.File, java.util.List)
*/
public void addParent( Model model, File pomFile, List artifactRepositories, boolean validProfilesXmlLocation )
{
if ( tuples.isEmpty() )
{
throw new IllegalStateException( "You must call setOrigin(..) before adding a parent to the lineage." );
}
tuples.add( new ModelLineageTuple( model, pomFile, artifactRepositories, validProfilesXmlLocation ) );
}
/**
* @see ModelLineage#artifactRepositoryListIterator()
*/
public Iterator artifactRepositoryListIterator()
{
return new Iterator()
{
private int idx = 0;
public boolean hasNext()
{
return tuples.size() > idx;
}
public Object next()
{
return ( (ModelLineageTuple) tuples.get( idx++ ) ).remoteRepositories;
}
public void remove()
{
tuples.remove( idx );
}
};
}
/**
* @see ModelLineage#fileIterator()
*/
public Iterator fileIterator()
{
return new Iterator()
{
private int idx = 0;
public boolean hasNext()
{
return tuples.size() > idx;
}
public Object next()
{
return ( (ModelLineageTuple) tuples.get( idx++ ) ).file;
}
public void remove()
{
tuples.remove( idx );
}
};
}
/**
* @see ModelLineage#getArtifactRepositories(org.apache.maven.model.Model)
*/
public List getArtifactRepositories( Model model )
{
int index = tuples.indexOf( new ModelLineageTuple( model ) );
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( index );
return tuple != null ? tuple.remoteRepositories : null;
}
public List getArtifactRepositoryListsInDescendingOrder()
{
if ( tuples.isEmpty() )
{
return Collections.EMPTY_LIST;
}
List tuplesInReverse = new ArrayList( tuples );
Collections.reverse( tuplesInReverse );
List results = new ArrayList( tuplesInReverse.size() );
for ( Iterator it = tuplesInReverse.iterator(); it.hasNext(); )
{
ModelLineageTuple tuple = (ModelLineageTuple) it.next();
results.add( tuple.remoteRepositories );
}
return results;
}
/**
* @see ModelLineage#getFile(org.apache.maven.model.Model)
*/
public File getFile( Model model )
{
int index = tuples.indexOf( new ModelLineageTuple( model ) );
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( index );
return tuple != null ? tuple.file : null;
}
public List getFilesInDescendingOrder()
{
if ( tuples.isEmpty() )
{
return Collections.EMPTY_LIST;
}
List tuplesInReverse = new ArrayList( tuples );
Collections.reverse( tuplesInReverse );
List results = new ArrayList( tuplesInReverse.size() );
for ( Iterator it = tuplesInReverse.iterator(); it.hasNext(); )
{
ModelLineageTuple tuple = (ModelLineageTuple) it.next();
results.add( tuple.file );
}
return results;
}
public List getModelsInDescendingOrder()
{
if ( tuples.isEmpty() )
{
return Collections.EMPTY_LIST;
}
List tuplesInReverse = new ArrayList( tuples );
Collections.reverse( tuplesInReverse );
List results = new ArrayList( tuplesInReverse.size() );
for ( Iterator it = tuplesInReverse.iterator(); it.hasNext(); )
{
ModelLineageTuple tuple = (ModelLineageTuple) it.next();
results.add( tuple.model );
}
return results;
}
public List getOriginatingArtifactRepositoryList()
{
if ( tuples.isEmpty() )
{
return null;
}
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 );
return tuple.remoteRepositories;
}
public Model getOriginatingModel()
{
if ( tuples.isEmpty() )
{
return null;
}
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 );
return tuple.model;
}
public File getOriginatingPOMFile()
{
if ( tuples.isEmpty() )
{
return null;
}
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( 0 );
return tuple.file;
}
public List getDeepestAncestorArtifactRepositoryList()
{
if ( tuples.isEmpty() )
{
return null;
}
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( tuples.size() - 1 );
return tuple.remoteRepositories;
}
public File getDeepestAncestorFile()
{
if ( tuples.isEmpty() )
{
return null;
}
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( tuples.size() - 1 );
return tuple.file;
}
public Model getDeepestAncestorModel()
{
if ( tuples.isEmpty() )
{
return null;
}
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( tuples.size() - 1 );
return tuple.model;
}
public boolean isDeepestAncestorUsingProfilesXml()
{
if ( tuples.isEmpty() )
{
return false;
}
ModelLineageTuple tuple = (ModelLineageTuple) tuples.get( tuples.size() - 1 );
return tuple.validProfilesXmlLocation;
}
/**
* @see ModelLineage#modelIterator()
*/
public Iterator modelIterator()
{
return new Iterator()
{
private int idx = 0;
public boolean hasNext()
{
return tuples.size() > idx;
}
public Object next()
{
return ( (ModelLineageTuple) tuples.get( idx++ ) ).model;
}
public void remove()
{
tuples.remove( idx );
}
};
}
public void setOrigin( Model model, File pomFile, List artifactRepositories, boolean validProfilesXmlLocation )
{
if ( !tuples.isEmpty() )
{
throw new IllegalStateException( "Origin already set; you must use addParent(..) for successive additions to the lineage." );
}
tuples.add( new ModelLineageTuple( model, pomFile, artifactRepositories, validProfilesXmlLocation ) );
}
/**
* @see ModelLineage#size()
*/
public int size()
{
return tuples.size();
}
private static final class ModelLineageTuple
{
private Model model;
private File file;
private List remoteRepositories;
private final boolean validProfilesXmlLocation;
private ModelLineageTuple( Model model )
{
this.model = model;
validProfilesXmlLocation = false;
}
private ModelLineageTuple( Model model, File file, List remoteRepositories, boolean validProfilesXmlLocation )
{
this.model = model;
this.file = file;
this.remoteRepositories = remoteRepositories;
this.validProfilesXmlLocation = validProfilesXmlLocation;
}
public boolean equals( Object other )
{
if ( this == other )
{
return true;
}
else if ( other instanceof ModelLineageTuple )
{
ModelLineageTuple otherTuple = (ModelLineageTuple) other;
return model.getId().equals( otherTuple.model.getId() );
}
return false;
}
}
public ModelLineageIterator lineageIterator()
{
return new ModelLineageIterator()
{
private int idx = -1;
public boolean hasNext()
{
return tuples.size() > idx + 1;
}
public Object next()
{
return ( (ModelLineageTuple) tuples.get( ( ++idx ) ) ).model;
}
public void remove()
{
tuples.remove( idx );
}
public List getArtifactRepositories()
{
return ( (ModelLineageTuple) tuples.get( idx ) ).remoteRepositories;
}
public Model getModel()
{
return ( (ModelLineageTuple) tuples.get( idx ) ).model;
}
public File getPOMFile()
{
return ( (ModelLineageTuple) tuples.get( idx ) ).file;
}
};
}
public ModelLineageIterator reversedLineageIterator()
{
return new ModelLineageIterator()
{
private int idx = tuples.size();
public boolean hasNext()
{
return idx > 0;
}
public Object next()
{
return ( (ModelLineageTuple) tuples.get( ( --idx ) ) ).model;
}
public void remove()
{
tuples.remove( idx );
}
public List getArtifactRepositories()
{
return ( (ModelLineageTuple) tuples.get( idx ) ).remoteRepositories;
}
public Model getModel()
{
return ( (ModelLineageTuple) tuples.get( idx ) ).model;
}
public File getPOMFile()
{
return ( (ModelLineageTuple) tuples.get( idx ) ).file;
}
};
}
}

View File

@ -1,491 +0,0 @@
package org.apache.maven.extension.lineage;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.MavenTools;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.profiles.build.ProfileAdvisor;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.ModelAndFile;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
/**
* @see ModelLineageBuilder
*/
public class DefaultModelLineageBuilder
implements ModelLineageBuilder, LogEnabled
{
public static final String ROLE_HINT = "default";
private ArtifactFactory artifactFactory;
private ArtifactResolver artifactResolver;
private MavenTools mavenTools;
private ProfileAdvisor profileAdvisor;
private Logger logger;
public DefaultModelLineageBuilder()
{
}
public DefaultModelLineageBuilder( ArtifactResolver resolver,
ArtifactFactory artifactFactory )
{
artifactResolver = resolver;
this.artifactFactory = artifactFactory;
}
/**
* @see ModelLineageBuilder#buildModelLineage(java.io.File, org.apache.maven.artifact.repository.ArtifactRepository, java.util.List)
*/
public ModelLineage buildModelLineage( File pom,
ProjectBuilderConfiguration config,
List remoteRepositories,
boolean allowStubs,
boolean isReactorProject )
throws ProjectBuildingException
{
ModelLineage lineage = new DefaultModelLineage();
List currentRemoteRepositories = remoteRepositories == null ? new ArrayList()
: new ArrayList( remoteRepositories );
ModelAndFile current = current = new ModelAndFile( readModel( pom ), pom, isReactorProject );
do
{
currentRemoteRepositories = updateRepositorySet( current.getModel(),
currentRemoteRepositories,
current.getFile(),
config,
current.isValidProfilesXmlLocation() );
if ( lineage.size() == 0 )
{
lineage.setOrigin( current.getModel(),
current.getFile(),
currentRemoteRepositories,
current.isValidProfilesXmlLocation() );
}
else
{
lineage.addParent( current.getModel(),
current.getFile(),
currentRemoteRepositories,
current.isValidProfilesXmlLocation() );
}
current = resolveParentPom( current,
currentRemoteRepositories,
config,
allowStubs,
isReactorProject );
}
while ( current != null );
return lineage;
}
/**
* Read the Model instance from the given POM file. Skip caching the Model on this call, since
* it's meant for diagnostic purposes (to determine a parent match).
*/
private Model readModel( File pomFile )
throws ProjectBuildingException
{
if ( pomFile.isDirectory() )
{
pomFile = new File( pomFile, "pom.xml" );
}
Model model;
Reader reader = null;
try
{
reader = ReaderFactory.newXmlReader( pomFile );
model = new MavenXpp3Reader().read( reader );
}
catch ( IOException e )
{
throw new ProjectBuildingException( "unknown", "Failed to read model from: " + pomFile,
pomFile, e );
}
catch ( XmlPullParserException e )
{
throw new ProjectBuildingException( "unknown",
"Failed to parse model from: " + pomFile, pomFile,
e );
}
finally
{
IOUtil.close( reader );
}
return model;
}
/**
* Update the remote repository set used to resolve parent POMs, by adding those declared in
* the given model to the HEAD of a new list, then appending the old remote repositories list.
* The specified pomFile is used for error reporting.
* @param profileManager
*/
private List updateRepositorySet( Model model,
List oldArtifactRepositories,
File pomFile,
ProjectBuilderConfiguration config,
boolean useProfilesXml )
throws ProjectBuildingException
{
List repositories = model.getRepositories();
Set artifactRepositories = null;
if ( repositories != null )
{
try
{
List lastRemoteRepos = oldArtifactRepositories;
List remoteRepos = mavenTools.buildArtifactRepositories( repositories );
loadActiveProfileRepositories( remoteRepos,
model,
config,
pomFile,
useProfilesXml );
artifactRepositories = new LinkedHashSet( remoteRepos.size()
+ oldArtifactRepositories.size() );
artifactRepositories.addAll( remoteRepos );
artifactRepositories.addAll( lastRemoteRepos );
}
catch ( InvalidRepositoryException e )
{
throw new ProjectBuildingException( model.getId(),
"Failed to create ArtifactRepository list for: "
+ pomFile, pomFile, e );
}
}
return new ArrayList( artifactRepositories );
}
private void loadActiveProfileRepositories( List repositories,
Model model,
ProjectBuilderConfiguration config,
File pomFile,
boolean useProfilesXml )
throws ProjectBuildingException
{
// getLogger().debug( "Grabbing profile-injected repositories for: " + model.getId() );
// FIXME: Find a way to pass in this context, so it's never null!
ProfileActivationContext context;
if ( config.getGlobalProfileManager() != null )
{
context = config.getGlobalProfileManager().getProfileActivationContext();
}
else
{
context = new DefaultProfileActivationContext( config.getExecutionProperties(), false );
}
LinkedHashSet profileRepos = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model,
pomFile,
config.getGlobalProfileManager() );
// getLogger().debug( "Got external-profile repositories: " + profileRepos );
LinkedHashSet pomProfileRepos = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model,
pomFile,
useProfilesXml,
context );
// getLogger().debug( "Got pom-profile repositories: " + pomProfileRepos );
profileRepos.addAll( pomProfileRepos );
if ( !profileRepos.isEmpty() )
{
repositories.addAll( profileRepos );
}
}
/**
* Pull the parent specification out of the given model, construct an Artifact instance, and
* resolve that artifact...then, return the resolved POM file for the parent.
* @param projectBuildCache
* @param allowStubs
* @param childIsReactorProject
*/
private ModelAndFile resolveParentPom( ModelAndFile child,
List remoteRepositories,
ProjectBuilderConfiguration config,
boolean allowStubs,
boolean childIsReactorProject )
throws ProjectBuildingException
{
Model model = child.getModel();
File modelPomFile = child.getFile();
Parent modelParent = model.getParent();
ModelAndFile result = null;
if ( modelParent != null )
{
validateParentDeclaration( modelParent, model );
String key = modelParent.getGroupId() + ":" + modelParent.getArtifactId() + ":" + modelParent.getVersion();
File parentPomFile = null;
if ( childIsReactorProject && modelPomFile != null )
{
// getLogger().debug( "Attempting to locate parent model using relativePath and local filesystem; child is a reactor project." );
// if the child isn't a reactor project, don't resolve the parent from the local filesystem...use the repository.
String relativePath = modelParent.getRelativePath();
File modelDir = modelPomFile.getParentFile();
parentPomFile = new File( modelDir, relativePath );
if ( parentPomFile.isDirectory() )
{
parentPomFile = new File( parentPomFile, "pom.xml" );
}
}
if ( parentPomFile != null )
{
if ( parentPomFile.exists() )
{
Model parentModel = readModel( parentPomFile );
if ( !parentModelMatches( modelParent, parentModel ) )
{
parentPomFile = null;
}
}
else
{
parentPomFile = null;
}
}
boolean isResolved = false;
if ( parentPomFile == null )
{
try
{
// getLogger().debug( "Attempting to resolve parent POM: " + modelParent.getId() + " using repositories:\n" + StringUtils.join( remoteRepositories.iterator(), "\n" ) );
parentPomFile = resolveParentFromRepositories( modelParent,
config,
remoteRepositories,
model.getId(),
modelPomFile );
isResolved = true;
}
catch ( ProjectBuildingException e )
{
if ( allowStubs )
{
getLogger().warn( "An error was encountered while resolving artifact for: "
+ modelParent.getId() + "\n\nError was: "
+ e.getMessage() );
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "Stack trace: ", e );
}
parentPomFile = null;
}
else
{
throw e;
}
}
}
if ( parentPomFile == null )
{
if ( allowStubs )
{
getLogger().warn( "Cannot find parent POM: " + modelParent.getId()
+ " for child: " + model.getId()
+ ".\n\nMaven is using a stub model instead for this build." );
Model parent = new Model();
parent.setGroupId( modelParent.getGroupId() );
parent.setArtifactId( modelParent.getArtifactId() );
parent.setVersion( modelParent.getVersion() );
// we act as if the POM was resolved from the repository,
// for the purposes of external profiles.xml files...
// that's what the last parameter is about.
result = new ModelAndFile( parent, parentPomFile, false );
}
else
{
getLogger().error( "Cannot find parent POM: " + modelParent.getId() );
}
}
else
{
Model parent = readModel( parentPomFile );
result = new ModelAndFile( parent, parentPomFile, !isResolved );
}
}
return result;
}
private boolean parentModelMatches( Parent modelParent, Model parentModel )
{
boolean groupsMatch = ( parentModel.getGroupId() == null )
|| parentModel.getGroupId().equals( modelParent.getGroupId() );
boolean versionsMatch = ( parentModel.getVersion() == null )
|| parentModel.getVersion().equals( modelParent.getVersion() );
if ( groupsMatch && versionsMatch
&& parentModel.getArtifactId().equals( modelParent.getArtifactId() ) )
{
return true;
}
return false;
}
private void validateParentDeclaration( Parent modelParent,
Model model )
throws ProjectBuildingException
{
if ( StringUtils.isEmpty( modelParent.getGroupId() ) )
{
throw new ProjectBuildingException( model.getId(),
"Missing groupId element from parent element" );
}
else if ( StringUtils.isEmpty( modelParent.getArtifactId() ) )
{
throw new ProjectBuildingException( model.getId(),
"Missing artifactId element from parent element" );
}
else if ( modelParent.getGroupId().equals( model.getGroupId() )
&& modelParent.getArtifactId().equals( model.getArtifactId() ) )
{
throw new ProjectBuildingException( model.getId(), "Parent element is a duplicate of "
+ "the current project " );
}
else if ( StringUtils.isEmpty( modelParent.getVersion() ) )
{
throw new ProjectBuildingException( model.getId(),
"Missing version element from parent element" );
}
}
private File resolveParentFromRepositories( Parent modelParent,
ProjectBuilderConfiguration config,
List remoteRepositories,
String childId,
File childPomFile )
throws ProjectBuildingException
{
Artifact parentPomArtifact = artifactFactory.createBuildArtifact( modelParent.getGroupId(),
modelParent.getArtifactId(),
modelParent.getVersion(),
"pom" );
try
{
artifactResolver.resolve( parentPomArtifact, remoteRepositories, config.getLocalRepository() );
}
catch ( ArtifactResolutionException e )
{
throw new ProjectBuildingException( childId, "Failed to resolve parent POM: "
+ modelParent.getId(), childPomFile, e );
}
catch ( ArtifactNotFoundException e )
{
throw new ProjectBuildingException( childId, "Cannot find artifact for parent POM: "
+ modelParent.getId(), childPomFile, e );
}
if ( parentPomArtifact.isResolved() )
{
return parentPomArtifact.getFile();
}
else
{
return null;
}
}
private Logger getLogger()
{
if ( logger == null )
{
logger = new ConsoleLogger( Logger.LEVEL_DEBUG, "DefaultModelLineageBuilder:internal" );
}
return logger;
}
public void enableLogging( Logger logger )
{
this.logger = logger;
}
}

View File

@ -1,168 +0,0 @@
package org.apache.maven.extension.lineage;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.model.Model;
import java.io.File;
import java.util.Iterator;
import java.util.List;
/**
* Tracks information from a current POM and its ancestors, including Model instances, associated
* POM files, and repository lists used to resolve each model.
*
* @author jdcasey
*
*/
public interface ModelLineage
{
/**
* Retrieve the Model instance for the deepest ancestor which has been resolved so far in this
* lineage.
*/
Model getDeepestAncestorModel();
/**
* Retrieve the flag telling whether discovery of a profiles.xml file is appropriate
* for the deepest model in this lineage.
*/
boolean isDeepestAncestorUsingProfilesXml();
/**
* Retrieve the POM file for the deepest ancestor which has been resolved so far in this
* lineage.
*/
File getDeepestAncestorFile();
/**
* Retrieve the remote-repository list for the deepest ancestor which has been resolved so far
* in this lineage.
*/
List getDeepestAncestorArtifactRepositoryList();
/**
* Retrieve the Model instance for the POM from which this lineage was constructed. This is the
* "leaf" of the inheritance hierarchy, or the current POM, or the child (all means the same
* thing).
*/
Model getOriginatingModel();
/**
* Retrieve the File for the POM from which this lineage was constructed. This is the
* "leaf" of the inheritance hierarchy, or the current POM, or the child (all means the same
* thing).
*/
File getOriginatingPOMFile();
/**
* Retrieve the List of ArtifactRepository instances used to resolve the first parent POM of the
* POM from which this lineage was constructed. This is the "leaf" of the inheritance hierarchy,
* or the current POM, or the child (all means the same thing).
*/
List getOriginatingArtifactRepositoryList();
/**
* Setup the originating POM information from which this lineage is constructed. This is the
* "child" POM that is the starting point of the build.
*
* @throws IllegalStateException When the originating POM information has already been set.
*/
void setOrigin( Model model, File pomFile, List artifactRepositories, boolean validProfilesXmlLocation );
/**
* Add a parent model, along with its file and the repositories used to resolve it.
* NOTE: If setOrigin(..) hasn't been called, this method will result in an IllegalStateException.
*
* @throws IllegalStateException When the originating POM information has not yet been set.
*/
void addParent( Model model, File pomFile, List artifactRepositories, boolean validProfilesXmlLocation );
/**
* Retrieve the models in this lineage, with the deepest parent at the zero index, and the current
* POM at the last index.
*/
List getModelsInDescendingOrder();
/**
* Retrieve the files used to construct this lineage, with that of the deepest parent at the
* zero index, and that of the current POM at the last index.
*/
List getFilesInDescendingOrder();
/**
* Retrieve the remote-artifact repository lists used to construct this lineage, with
* that of the deepest parent at the zero index, and that of the current POM at the last index.
*/
List getArtifactRepositoryListsInDescendingOrder();
/**
* Retrieve an Iterator derivative that functions in the simplest sense just like the return
* value of the modelIterator() method. However, the ModelLineageIterator also gives access to
* the current POM file and current remote ArtifactRepository instances used to resolve the
* current Model...along with a method to give explicit access to the current Model instance.
*/
ModelLineageIterator lineageIterator();
/**
* Retrieve an Iterator derivative that functions in the simplest sense just like the return
* value of the modelIterator() method. However, the ModelLineageIterator also gives access to
* the current POM file and current remote ArtifactRepository instances used to resolve the
* current Model...along with a method to give explicit access to the current Model instance.
*/
ModelLineageIterator reversedLineageIterator();
/**
* Iterate over the lineage of Model instances, starting with the child (current) Model,
* and ending with the deepest ancestor.
*/
Iterator modelIterator();
/**
* Iterate over the lineage of POM Files, starting with the child (current) POM and ending with
* the deepest ancestor.
*/
Iterator fileIterator();
/**
* Iterate over the remote-repository Lists used to resolve the lineage, starting with the
* child (current) remote-repository List and ending with the deepest ancestor.
*/
Iterator artifactRepositoryListIterator();
/**
* Retrieve the File from which the given Model instance was read. If the model itself doesn't
* belong to this lineage, match it in the lineage by Model.getId().
*/
File getFile( Model model );
/**
* Retrieve the List of remote repositories from which the given Model instance was resolved.
* If the model itself doesn't belong to this lineage, match it in the lineage by Model.getId().
*/
List getArtifactRepositories( Model model );
/**
* Retrieve the number of entries (POMs) in this lineage.
*/
int size();
}

View File

@ -1,64 +0,0 @@
package org.apache.maven.extension.lineage;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.project.ProjectBuildingException;
import java.io.File;
import java.util.List;
/**
* Builds the lineage of Model instances, starting from a given POM file, and stretching back through
* all of the parent POMs that are defined in the respective <parent/> sections.
*
* NOTE: In all of the build/resume methods below, each Model MUST have its active profiles searched
* for new repositories from which to discover parent POMs.
*/
public interface ModelLineageBuilder
{
String ROLE = ModelLineageBuilder.class.getName();
/**
* Construct a lineage of the current POM plus all of its ancestors.
*
* @param pom The current POM, whose Model will terminate the constructed lineage
*
* @param config The project-building configuration to use, which contains the global profile manager,
* local repository, and execution- and user-level properties.
*
* @param remoteRepositories List of ArtifactRepository instances against which parent POMs
* should be resolved
*
* @param allowStubs Whether stubbed-out Model instances should be constructed in the event that
* a parent-POM cannot be resolved.
*
* @param isReactorProject Whether the model being built is part of the build we're trying to execute,
* or if it's actually being read from the repository.
*/
ModelLineage buildModelLineage( File pom,
ProjectBuilderConfiguration config,
List remoteRepositories,
boolean allowStubs,
boolean isReactorProject )
throws ProjectBuildingException;
}

View File

@ -1,56 +0,0 @@
package org.apache.maven.extension.lineage;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.model.Model;
import java.io.File;
import java.util.Iterator;
import java.util.List;
/**
* Iterator that gives access to all information associated with each model in a ModelLineage.
* The result of the next() method is the Model instance itself, but you can also retrieve this
* Model instance using getModel() below.
*
* @author jdcasey
*/
public interface ModelLineageIterator
extends Iterator
{
/**
* Retrieve the Model instance associated with the current position in the ModelLineage.
* This is the same return value as the next() method.
*/
Model getModel();
/**
* Retrieve the POM File associated with the current position in the ModelLineage
*/
File getPOMFile();
/**
* Retrieve the remote ArtifactRepository instances associated with the current position
* in the ModelLineage.
*/
List getArtifactRepositories();
}

View File

@ -19,7 +19,6 @@ package org.apache.maven.reactor;
* under the License.
*/
import org.apache.maven.extension.ExtensionScanningException;
import org.apache.maven.project.ProjectBuildingException;
import java.io.File;
@ -51,11 +50,6 @@ public class MavenExecutionException
super( message, cause );
}
public MavenExecutionException( String message, ExtensionScanningException cause )
{
super( message, cause );
}
public MavenExecutionException( String message,
ProjectBuildingException cause )
{

View File

@ -183,24 +183,6 @@ under the License.
</configuration>
</component>
<component>
<role>org.apache.maven.extension.BuildExtensionScanner</role>
<role-hint>default</role-hint>
<implementation>org.apache.maven.extension.DefaultBuildExtensionScanner</implementation>
<requirements>
<requirement>
<role>org.apache.maven.extension.ExtensionManager</role>
</requirement>
<requirement>
<role>org.apache.maven.extension.lineage.ModelLineageBuilder</role>
<role-hint>default</role-hint>
</requirement>
<requirement>
<role>org.apache.maven.project.MavenProjectBuilder</role>
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.extension.lineage.ModelLineageBuilder</role>
<role-hint>default</role-hint>
@ -314,10 +296,6 @@ under the License.
<role>org.apache.maven.Maven</role>
<implementation>org.apache.maven.DefaultMaven</implementation>
<requirements>
<requirement>
<role>org.apache.maven.extension.BuildExtensionScanner</role>
<role-hint>default</role-hint>
</requirement>
<requirement>
<role>org.apache.maven.project.MavenProjectBuilder</role>
</requirement>

View File

@ -1,311 +0,0 @@
package org.apache.maven.extension;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.ArtifactFilterManager;
import org.apache.maven.DefaultArtifactFilterManager;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
import org.apache.maven.model.Build;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.apache.maven.realm.DefaultMavenRealmManager;
import org.apache.maven.realm.MavenRealmManager;
import org.codehaus.plexus.MutablePlexusContainer;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
public class DefaultExtensionManagerTest
extends PlexusTestCase
{
private Set toDelete = new HashSet();
private MutablePlexusContainer container;
private ArtifactFilterManager filterManager;
private ArtifactRepositoryFactory repoFactory;
private ArtifactFactory factory;
private ArtifactResolver resolver;
private ArtifactMetadataSource metadataSource;
private WagonManager wagonManager;
public void setUp()
throws Exception
{
super.setUp();
container = (MutablePlexusContainer) getContainer();
// container.getLoggerManager().setThreshold( Logger.LEVEL_DEBUG );
filterManager = new DefaultArtifactFilterManager();
repoFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
metadataSource = (ArtifactMetadataSource) lookup( ArtifactMetadataSource.ROLE );
wagonManager = (WagonManager) lookup( WagonManager.ROLE );
}
public void tearDown()
throws Exception
{
super.tearDown();
for ( Iterator it = toDelete.iterator(); it.hasNext(); )
{
File f = (File) it.next();
if ( f.exists() )
{
try
{
FileUtils.forceDelete( f );
}
catch (IOException e)
{
//the files on windows can still be locked. They were creaed in a temp directory anyway and will get removed in a subsequent clean.
//we can safely ignore this error.
}
}
}
}
public void test_addExtension_usingModel_ShouldLoadExtensionComponent()
throws Exception
{
System.out.println( "\n\n\n\n\n\n\nSTART\n\n" );
File remoteRepoDir = findRemoteRepositoryDirectory();
File localRepo = createTempDir();
Model model = createModel( "org.test", "artifact-name", "1" );
Extension ext = addExtension( model, "org.apache.maven.core.test", "test-extension", "1" );
List remoteRepositories = new ArrayList();
remoteRepositories.add( repoFactory.createArtifactRepository( "central",
remoteRepoDir.toURI()
.toURL()
.toExternalForm(),
"default",
null,
null ) );
DefaultArtifactRepository localRepository = new DefaultArtifactRepository(
"local",
localRepo.getAbsolutePath(),
new DefaultRepositoryLayout() );
localRepository.setBasedir( localRepo.getAbsolutePath() );
ExtensionManager mgr = newDefaultExtensionManager();
MavenRealmManager realmManager = new DefaultMavenRealmManager(
container,
new ConsoleLogger(
Logger.LEVEL_DEBUG,
"test" ) );
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setLocalRepository( localRepository )
.setRealmManager( realmManager );
mgr.addExtension( ext, model, remoteRepositories, request );
ClassRealm projectRealm = realmManager.getProjectRealm( model.getGroupId(), model.getArtifactId(), model.getVersion() );
ClassRealm oldRealm = getContainer().setLookupRealm( projectRealm );
List compList = getContainer().getComponentDescriptorList( ArtifactFactory.ROLE );
System.out.println( "Got: " + compList );
ArtifactFactory result = (ArtifactFactory) lookup( ArtifactFactory.ROLE, "test" );
assertNotNull( result );
getContainer().setLookupRealm( oldRealm );
System.out.println( "\n\nEND\n\n\n\n\n\n\n" );
}
public void test_addExtension_usingModel_ShouldLoadCustomLifecycleMappingAndArtifactHandler()
throws Exception
{
File remoteRepoDir = findRemoteRepositoryDirectory();
File localRepo = createTempDir();
Model model = createModel( "org.test", "artifact-name", "1" );
Extension ext = addExtension( model, "org.apache.maven.core.test", "test-lifecycle-and-artifactHandler", "1" );
List remoteRepositories = new ArrayList();
remoteRepositories.add( repoFactory.createArtifactRepository( "central",
remoteRepoDir.toURI()
.toURL()
.toExternalForm(),
"default",
null,
null ) );
DefaultArtifactRepository localRepository = new DefaultArtifactRepository(
"local",
localRepo.getAbsolutePath(),
new DefaultRepositoryLayout() );
localRepository.setBasedir( localRepo.getAbsolutePath() );
ExtensionManager mgr = newDefaultExtensionManager();
MavenRealmManager realmManager = new DefaultMavenRealmManager(
container,
new ConsoleLogger(
Logger.LEVEL_DEBUG,
"test" ) );
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setLocalRepository( localRepository )
.setRealmManager( realmManager );
mgr.addExtension( ext, model, remoteRepositories, request );
List lcCompList = getContainer().getComponentDescriptorList( LifecycleMapping.ROLE );
System.out.println( "Got lifecyle mappings: " + lcCompList );
List ahCompList = getContainer().getComponentDescriptorList( ArtifactHandler.ROLE );
System.out.println( "Got artifact handlers: " + ahCompList );
ClassRealm projectRealm = realmManager.getProjectRealm( model.getGroupId(), model.getArtifactId(), model.getVersion() );
ClassRealm oldRealm = getContainer().setLookupRealm( projectRealm );
LifecycleMapping lcResult = (LifecycleMapping) lookup( LifecycleMapping.ROLE, "test" );
assertNotNull( lcResult );
ArtifactHandler ahResult = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "test" );
assertNotNull( ahResult );
getContainer().setLookupRealm( oldRealm );
}
private ExtensionManager newDefaultExtensionManager()
throws Exception
{
DefaultExtensionManager mgr = new DefaultExtensionManager( factory, resolver,
metadataSource, container,
filterManager, wagonManager );
Logger logger = getContainer().getLoggerManager()
.getLoggerForComponent( DefaultExtensionManager.class.getName() );
mgr.enableLogging( logger );
return mgr;
}
private Model createModel( String groupId,
String artifactId,
String version )
{
Model model = new Model();
model.setGroupId( groupId );
model.setArtifactId( artifactId );
model.setVersion( version );
return model;
}
private Extension addExtension( Model model,
String groupId,
String artifactId,
String version )
{
Extension ext = new Extension();
ext.setGroupId( groupId );
ext.setArtifactId( artifactId );
ext.setVersion( version );
Build build = model.getBuild();
if ( build == null )
{
build = new Build();
model.setBuild( build );
}
build.addExtension( ext );
return ext;
}
private File createTempDir()
throws IOException
{
File dir = File.createTempFile( "DefaultExtensionManagerTest.", ".dir" );
FileUtils.forceDelete( dir );
dir.mkdirs();
toDelete.add( dir );
return dir;
}
private File findRemoteRepositoryDirectory()
{
String classPath = getClass().getPackage().getName().replace( '.', '/' )
+ "/test-extension-repo/repo-marker.txt";
ClassLoader cloader = Thread.currentThread().getContextClassLoader();
URL resource = cloader.getResource( classPath );
if ( resource == null )
{
throw new IllegalStateException( "Cannot find repository marker file: " + classPath
+ " in context classloader!" );
}
File repoDir = new File( resource.getPath() ).getParentFile();
return repoDir;
}
}

View File

@ -1,425 +0,0 @@
package org.apache.maven.extension.lineage;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import junit.framework.TestCase;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.model.Model;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public abstract class AbstractModelLineageTest
extends TestCase
{
protected abstract ModelLineage newModelLineage();
public void testAddParent_ShouldThrowIllegalStateExceptionWhenSetOriginNotCalled()
{
ModelLineage ml = newModelLineage();
assertEquals( 0, ml.size() );
try
{
ml.addParent( new Model(), null, null, false );
fail( "Should throw IllegalStateException when setOrigin(..) is not called first." );
}
catch ( IllegalStateException e )
{
// expected
}
}
public void testSetOrigin_ShouldThrowIllegalStateExceptionWhenSetOriginCalledRepeatedly()
{
ModelLineage ml = newModelLineage();
assertEquals( 0, ml.size() );
ml.setOrigin( new Model(), null, null, false );
assertEquals( 1, ml.size() );
try
{
ml.setOrigin( new Model(), null, null, false );
fail( "Should throw IllegalStateException when setOrigin(..) called multiple times." );
}
catch ( IllegalStateException e )
{
// expected
}
}
public void testSetOriginAndSize_SizeShouldIncrementByOneWhenOriginSet()
{
ModelLineage ml = newModelLineage();
assertEquals( 0, ml.size() );
ml.setOrigin( new Model(), null, null, false );
assertEquals( 1, ml.size() );
}
public void testLineageIterator_ShouldAddTwoEntriesAndIterateInFIFOOrder()
throws IOException
{
ModelLineage ml = newModelLineage();
String gOne = "group1";
String aOne = "artifact1";
String vOne = "1";
Model mOne = new Model();
mOne.setGroupId( gOne );
mOne.setArtifactId( aOne );
mOne.setVersion( vOne );
File fOne = File.createTempFile( "ModelLineageTest.modelLineageIterator-test.", "" );
fOne.deleteOnExit();
ml.setOrigin( mOne, fOne, null, false );
String gTwo = "group2";
String aTwo = "artifact2";
String vTwo = "2";
Model mTwo = new Model();
mOne.setGroupId( gTwo );
mOne.setArtifactId( aTwo );
mOne.setVersion( vTwo );
File fTwo = File.createTempFile( "ModelLineageTest.fileIterator-test.", "" );
fTwo.deleteOnExit();
ml.addParent( mTwo, fTwo, null, false );
ModelLineageIterator it = ml.lineageIterator();
assertTrue( it.hasNext() );
assertEquals( mOne.getId(), ( (Model) it.next() ).getId() );
assertEquals( mOne.getId(), it.getModel().getId() );
assertEquals( fOne, it.getPOMFile() );
assertTrue( it.hasNext() );
assertEquals( mTwo.getId(), ( (Model) it.next() ).getId() );
assertEquals( mTwo.getId(), it.getModel().getId() );
assertEquals( fTwo, it.getPOMFile() );
}
public void testModelIterator_ShouldAddTwoModelsAndIterateInFIFOOrder()
{
ModelLineage ml = newModelLineage();
String gOne = "group1";
String aOne = "artifact1";
String vOne = "1";
Model mOne = new Model();
mOne.setGroupId( gOne );
mOne.setArtifactId( aOne );
mOne.setVersion( vOne );
ml.setOrigin( mOne, null, null, false );
String gTwo = "group2";
String aTwo = "artifact2";
String vTwo = "2";
Model mTwo = new Model();
mOne.setGroupId( gTwo );
mOne.setArtifactId( aTwo );
mOne.setVersion( vTwo );
ml.addParent( mTwo, null, null, false );
Iterator it = ml.modelIterator();
assertTrue( it.hasNext() );
assertEquals( mOne.getId(), ( (Model) it.next() ).getId() );
assertTrue( it.hasNext() );
assertEquals( mTwo.getId(), ( (Model) it.next() ).getId() );
}
public void testFileIterator_ShouldAddTwoParentsAndIterateInFIFOOrder()
throws IOException
{
ModelLineage ml = newModelLineage();
File fOne = File.createTempFile( "ModelLineageTest.fileIterator-test.", "" );
fOne.deleteOnExit();
ml.setOrigin( new Model(), fOne, null, false );
File fTwo = File.createTempFile( "ModelLineageTest.fileIterator-test.", "" );
fTwo.deleteOnExit();
ml.addParent( new Model(), fTwo, null, false );
Iterator it = ml.fileIterator();
assertTrue( it.hasNext() );
assertEquals( fOne, it.next() );
assertTrue( it.hasNext() );
assertEquals( fTwo, it.next() );
}
public void testArtifactRepositoryListIterator_ShouldAddTwoParentsAndIterateInFIFOOrder()
{
DefaultRepositoryLayout layout = new DefaultRepositoryLayout();
ModelLineage ml = newModelLineage();
ArtifactRepository arOne = new DefaultArtifactRepository( "", "", layout );
ml.setOrigin( new Model(), null, Collections.singletonList( arOne ), false );
ArtifactRepository arTwo = new DefaultArtifactRepository( "", "", layout );
ml.addParent( new Model(), null, Collections.singletonList( arTwo ), false );
Iterator it = ml.artifactRepositoryListIterator();
assertTrue( it.hasNext() );
assertSame( arOne, ( (List) it.next() ).get( 0 ) );
assertTrue( it.hasNext() );
assertSame( arTwo, ( (List) it.next() ).get( 0 ) );
}
public void testAddParentAndGetFile_ShouldRetrieveCorrectFileForModel()
throws IOException
{
ModelLineage ml = newModelLineage();
File fOne = File.createTempFile( "ModelLineageTest.fileIterator-test.", "" );
fOne.deleteOnExit();
Model mOne = new Model();
String gOne = "group";
String aOne = "artifact";
String vOne = "1";
mOne.setGroupId( gOne );
mOne.setArtifactId( aOne );
mOne.setVersion( vOne );
ml.setOrigin( mOne, fOne, null, false );
File fTwo = File.createTempFile( "ModelLineageTest.fileIterator-test.", "" );
fTwo.deleteOnExit();
ml.addParent( new Model(), fTwo, null, false );
Model retriever = new Model();
retriever.setGroupId( gOne );
retriever.setArtifactId( aOne );
retriever.setVersion( vOne );
assertEquals( fOne, ml.getFile( retriever ) );
}
public void testAddParentAndGetArtifactRepositories_ShouldRetrieveCorrectRepoListForModel()
throws IOException
{
DefaultRepositoryLayout layout = new DefaultRepositoryLayout();
ModelLineage ml = newModelLineage();
Model mOne = new Model();
String gOne = "group";
String aOne = "artifact";
String vOne = "1";
mOne.setGroupId( gOne );
mOne.setArtifactId( aOne );
mOne.setVersion( vOne );
ArtifactRepository arOne = new DefaultArtifactRepository( "", "", layout );
ml.setOrigin( mOne, null, Collections.singletonList( arOne ), false );
ArtifactRepository arTwo = new DefaultArtifactRepository( "", "", layout );
ml.addParent( new Model(), null, Collections.singletonList( arTwo ), false );
Model retriever = new Model();
retriever.setGroupId( gOne );
retriever.setArtifactId( aOne );
retriever.setVersion( vOne );
assertSame( arOne, ( ml.getArtifactRepositories( retriever ) ).get( 0 ) );
}
public void testSetOriginAndGetOriginatingModel()
{
Model model = new Model();
model.setGroupId( "group" );
model.setArtifactId( "artifact" );
model.setVersion( "1" );
ModelLineage ml = newModelLineage();
ml.setOrigin( model, null, null, false );
assertEquals( model.getId(), ml.getOriginatingModel().getId() );
}
public void testSetOriginAndGetOriginatingFile()
throws IOException
{
ModelLineage ml = newModelLineage();
File pomFile = File.createTempFile( "ModelLineage.test.", ".pom" );
pomFile.deleteOnExit();
ml.setOrigin( null, pomFile, null, false );
assertEquals( pomFile, ml.getOriginatingPOMFile() );
}
public void testSetOriginAndGetOriginatingArtifactRepositoryList()
{
DefaultRepositoryLayout layout = new DefaultRepositoryLayout();
ModelLineage ml = newModelLineage();
Model mOne = new Model();
String gOne = "group";
String aOne = "artifact";
String vOne = "1";
mOne.setGroupId( gOne );
mOne.setArtifactId( aOne );
mOne.setVersion( vOne );
ArtifactRepository arOne = new DefaultArtifactRepository( "", "", layout );
ml.setOrigin( mOne, null, Collections.singletonList( arOne ), false );
assertSame( arOne, ml.getOriginatingArtifactRepositoryList().get( 0 ) );
}
public void testGetModelsInDescendingOrder_ShouldAddTwoAndRetrieveInLIFOOrder()
{
ModelLineage ml = newModelLineage();
String gOne = "group1";
String aOne = "artifact1";
String vOne = "1";
Model mOne = new Model();
mOne.setGroupId( gOne );
mOne.setArtifactId( aOne );
mOne.setVersion( vOne );
ml.setOrigin( mOne, null, null, false );
String gTwo = "group2";
String aTwo = "artifact2";
String vTwo = "2";
Model mTwo = new Model();
mOne.setGroupId( gTwo );
mOne.setArtifactId( aTwo );
mOne.setVersion( vTwo );
ml.addParent( mTwo, null, null, false );
Iterator it = ml.getModelsInDescendingOrder().iterator();
assertTrue( it.hasNext() );
assertEquals( mTwo.getId(), ( (Model) it.next() ).getId() );
assertTrue( it.hasNext() );
assertEquals( mOne.getId(), ( (Model) it.next() ).getId() );
}
public void testGetFilesInDescendingOrder_ShouldAddTwoAndRetrieveInLIFOOrder()
throws IOException
{
ModelLineage ml = newModelLineage();
File fOne = File.createTempFile( "ModelLineageTest.fileIterator-test.", "" );
fOne.deleteOnExit();
ml.setOrigin( new Model(), fOne, null, false );
File fTwo = File.createTempFile( "ModelLineageTest.fileIterator-test.", "" );
fTwo.deleteOnExit();
ml.addParent( new Model(), fTwo, null, false );
Iterator it = ml.getFilesInDescendingOrder().iterator();
assertTrue( it.hasNext() );
assertEquals( fTwo, it.next() );
assertTrue( it.hasNext() );
assertEquals( fOne, it.next() );
}
public void testGetArtifactRepositoryListsInDescendingOrder_ShouldAddTwoAndRetrieveInLIFOOrder()
{
DefaultRepositoryLayout layout = new DefaultRepositoryLayout();
ModelLineage ml = newModelLineage();
ArtifactRepository arOne = new DefaultArtifactRepository( "", "", layout );
ml.setOrigin( new Model(), null, Collections.singletonList( arOne ), false );
ArtifactRepository arTwo = new DefaultArtifactRepository( "", "", layout );
ml.addParent( new Model(), null, Collections.singletonList( arTwo ), false );
Iterator it = ml.getArtifactRepositoryListsInDescendingOrder().iterator();
assertTrue( it.hasNext() );
assertSame( arTwo, ( (List) it.next() ).get( 0 ) );
assertTrue( it.hasNext() );
assertSame( arOne, ( (List) it.next() ).get( 0 ) );
}
}

View File

@ -1,580 +0,0 @@
package org.apache.maven.extension.lineage;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Profile;
import org.apache.maven.model.Repository;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.errors.ProjectErrorReporter;
import org.apache.maven.errors.ProjectReporterManager;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.WriterFactory;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
public class DefaultModelLineageBuilderTest
extends PlexusTestCase
{
private DefaultModelLineageBuilder modelLineageBuilder;
private ArtifactRepositoryLayout defaultLayout;
private Set toDelete = new HashSet();
public void setUp()
throws Exception
{
super.setUp();
getContainer().getLoggerManager().setThresholds( Logger.LEVEL_DEBUG );
modelLineageBuilder = (DefaultModelLineageBuilder) lookup( ModelLineageBuilder.ROLE,
DefaultModelLineageBuilder.ROLE_HINT );
defaultLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
}
public void tearDown()
throws Exception
{
super.tearDown();
for ( Iterator it = toDelete.iterator(); it.hasNext(); )
{
File f = (File) it.next();
if ( f.exists() )
{
FileUtils.forceDelete( f );
}
}
}
public void testShouldReadSinglePomWithNoParents()
throws IOException, ProjectBuildingException
{
String groupId = "groupId";
String artifactId = "artifactId";
String version = "1.0";
Model model = new Model();
model.setGroupId( groupId );
model.setArtifactId( artifactId );
model.setVersion( version );
File pomFile = File.createTempFile( "DefaultModelLineageBuilder.test.", ".pom" );
pomFile.deleteOnExit();
Writer writer = null;
try
{
writer = WriterFactory.newXmlWriter( pomFile );
new MavenXpp3Writer().write( writer, model );
}
finally
{
IOUtil.close( writer );
}
ModelLineage lineage = modelLineageBuilder.buildModelLineage( pomFile,
new DefaultProjectBuilderConfiguration(),
null,
false,
true );
assertEquals( 1, lineage.size() );
assertEquals( model.getId(), lineage.getOriginatingModel().getId() );
}
public void testReadPOMWithTwoAncestorsInLocalRepository()
throws IOException, ProjectBuildingException
{
// 1. create local repository directory
File localRepoDirectory = File.createTempFile( "DefaultModelLineageBuilder.localRepository.",
"" );
localRepoDirectory.delete();
localRepoDirectory.mkdirs();
deleteDirOnExit( localRepoDirectory );
// 2. create and write the ancestor model to the local repo directory
Model ancestor = createModel( "group", "ancestor", "1" );
writeModel( ancestor, new File( localRepoDirectory, "group/ancestor/1/ancestor-1.pom" ) );
// 3. create the parent model with a parent-ref to the ancestor model
Model parent = createModel( "group", "parent", "1" );
Parent parentParent = new Parent();
parentParent.setGroupId( "group" );
parentParent.setArtifactId( "ancestor" );
parentParent.setVersion( "1" );
parent.setParent( parentParent );
// 4. write the parent model to the local repo directory
writeModel( parent, new File( localRepoDirectory, "group/parent/1/parent-1.pom" ) );
// 5. create the current pom with a parent-ref on the parent model
Model current = createModel( "group", "current", "1" );
Parent currentParent = new Parent();
currentParent.setGroupId( "group" );
currentParent.setArtifactId( "parent" );
currentParent.setVersion( "1" );
current.setParent( currentParent );
// 6. write the current pom somewhere
File currentPOM = File.createTempFile( "DefaultModelLineageBuilder.test.", ".pom" );
currentPOM.deleteOnExit();
writeModel( current, currentPOM );
// 7. build the lineage.
ArtifactRepository localRepository = new DefaultArtifactRepository(
"local",
localRepoDirectory.toURL()
.toExternalForm(),
defaultLayout );
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM,
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ),
Collections.EMPTY_LIST,
false,
true );
assertEquals( 3, lineage.size() );
Iterator modelIterator = lineage.modelIterator();
assertEquals( current.getId(), ( (Model) modelIterator.next() ).getId() );
assertEquals( parent.getId(), ( (Model) modelIterator.next() ).getId() );
assertEquals( ancestor.getId(), ( (Model) modelIterator.next() ).getId() );
}
public void testReadPOMWithMissingParentAndAllowStubsSetToTrue()
throws IOException, ProjectBuildingException
{
// 1. create local repository directory
File localRepoDirectory = File.createTempFile( "DefaultModelLineageBuilder.localRepository.",
"" );
localRepoDirectory.delete();
localRepoDirectory.mkdirs();
deleteDirOnExit( localRepoDirectory );
// 5. create the current pom with a parent-ref on the parent model
Model current = createModel( "group", "current", "1" );
Parent currentParent = new Parent();
currentParent.setGroupId( "group" );
currentParent.setArtifactId( "parent" );
currentParent.setVersion( "1" );
current.setParent( currentParent );
// 6. write the current pom somewhere
File currentPOM = File.createTempFile( "DefaultModelLineageBuilder.test.", ".pom" );
currentPOM.deleteOnExit();
writeModel( current, currentPOM );
// 7. build the lineage.
ArtifactRepository localRepository = new DefaultArtifactRepository(
"local",
localRepoDirectory.toURL()
.toExternalForm(),
defaultLayout );
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM,
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ),
Collections.EMPTY_LIST,
true,
true );
assertEquals( 2, lineage.size() );
Iterator modelIterator = lineage.modelIterator();
assertEquals( current.getId(), ( (Model) modelIterator.next() ).getId() );
Model parent = (Model) modelIterator.next();
assertEquals( currentParent.getGroupId(), parent.getGroupId() );
assertEquals( currentParent.getArtifactId(), parent.getArtifactId() );
assertEquals( currentParent.getVersion(), parent.getVersion() );
}
public void testReadPOMWithParentInLocalRepositoryAndAncestorInRemoteRepository()
throws IOException, ProjectBuildingException
{
// 1. create local and remote repository directories
File localRepoDirectory = File.createTempFile( "DefaultModelLineageBuilder.localRepository.",
"" );
localRepoDirectory.delete();
localRepoDirectory.mkdirs();
deleteDirOnExit( localRepoDirectory );
File remoteRepoDirectory = File.createTempFile( "DefaultModelLineageBuilder.remoteRepository.",
"" );
remoteRepoDirectory.delete();
remoteRepoDirectory.mkdirs();
deleteDirOnExit( remoteRepoDirectory );
// 2. create and write the ancestor model to the local repo directory
Model ancestor = createModel( "group", "ancestor", "1" );
writeModel( ancestor, new File( remoteRepoDirectory, "group/ancestor/1/ancestor-1.pom" ) );
// 3. create the parent model with a parent-ref to the ancestor model
Model parent = createModel( "group", "parent", "1" );
Parent parentParent = new Parent();
parentParent.setGroupId( "group" );
parentParent.setArtifactId( "ancestor" );
parentParent.setVersion( "1" );
parent.setParent( parentParent );
// 4. write the parent model to the local repo directory
writeModel( parent, new File( localRepoDirectory, "group/parent/1/parent-1.pom" ) );
// 5. create the current pom with a parent-ref on the parent model
Model current = createModel( "group", "current", "1" );
Parent currentParent = new Parent();
currentParent.setGroupId( "group" );
currentParent.setArtifactId( "parent" );
currentParent.setVersion( "1" );
current.setParent( currentParent );
// 6. write the current pom somewhere
File currentPOM = File.createTempFile( "DefaultModelLineageBuilder.test.", ".pom" );
currentPOM.deleteOnExit();
writeModel( current, currentPOM );
// 7. build the lineage.
ArtifactRepository localRepository = new DefaultArtifactRepository(
"local",
localRepoDirectory.toURL()
.toExternalForm(),
defaultLayout );
ArtifactRepository remoteRepository = new DefaultArtifactRepository(
"test",
remoteRepoDirectory.toURL()
.toExternalForm(),
defaultLayout );
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM,
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ),
Collections.singletonList( remoteRepository ),
false,
true );
assertEquals( 3, lineage.size() );
Iterator modelIterator = lineage.modelIterator();
assertEquals( current.getId(), ( (Model) modelIterator.next() ).getId() );
assertEquals( parent.getId(), ( (Model) modelIterator.next() ).getId() );
assertEquals( ancestor.getId(), ( (Model) modelIterator.next() ).getId() );
}
public void testReadPOMWithParentInSiblingDirectoryUsingSpecifiedRelativePathThatIsADirectory()
throws IOException, ProjectBuildingException
{
// 1. create project-root directory.
File projectRootDirectory = File.createTempFile( "DefaultModelLineageBuilder.projectRootDir.",
"" );
projectRootDirectory.delete();
projectRootDirectory.mkdirs();
deleteDirOnExit( projectRootDirectory );
// 2. create dir for parent POM within project root directory.
File parentDir = new File( projectRootDirectory, "parent" );
parentDir.mkdirs();
// 2. create dir for child project within project root directory.
File childDir = new File( projectRootDirectory, "child" );
childDir.mkdirs();
// 3. create the parent model in the parent-POM directory
Model parent = createModel( "group", "parent", "1" );
writeModel( parent, new File( parentDir, "pom.xml" ) );
// 5. create the current pom with a parent-ref on the parent model
Model current = createModel( "group", "child", "1" );
Parent currentParent = new Parent();
currentParent.setGroupId( "group" );
currentParent.setArtifactId( "parent" );
currentParent.setVersion( "1" );
currentParent.setRelativePath( "../parent" );
current.setParent( currentParent );
// 6. write the current POM to the child directory
File currentPOM = new File( childDir, "pom.xml" );
writeModel( current, currentPOM );
// 7. build the lineage.
ArtifactRepository localRepository = new DefaultArtifactRepository(
"local",
projectRootDirectory.toURL()
.toExternalForm(),
defaultLayout );
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM,
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ),
Collections.EMPTY_LIST,
false,
true );
assertEquals( 2, lineage.size() );
Iterator modelIterator = lineage.modelIterator();
assertEquals( current.getId(), ( (Model) modelIterator.next() ).getId() );
assertEquals( parent.getId(), ( (Model) modelIterator.next() ).getId() );
}
public void testReadPOMWithParentInRepoBroughtInViaExternalProfile()
throws Exception
{
// 1. create project-root directory.
File projectRootDirectory = createTempDir( "projectRootDir" );
// 1. create project-root directory.
File repoRootDirectory = createTempDir( "repoRootDir" );
File localRepoRootDirectory = createTempDir( "localRepoRootDir" );
// 2. create dir for parent POM within project root directory.
File parentDir = new File( repoRootDirectory, "group/parent/1" );
parentDir.mkdirs();
// 3. create the parent model in the parent-POM directory
Model parent = createModel( "group", "parent", "1" );
writeModel( parent, new File( parentDir, "parent-1.pom" ) );
// 5. create the current pom with a parent-ref on the parent model
Model current = createModel( "group", "child", "1" );
Parent currentParent = new Parent();
currentParent.setGroupId( "group" );
currentParent.setArtifactId( "parent" );
currentParent.setVersion( "1" );
current.setParent( currentParent );
// 6. write the current POM to the child directory
File currentPOM = new File( projectRootDirectory, "pom.xml" );
writeModel( current, currentPOM );
// 7. build the lineage.
ArtifactRepository localRepository = new DefaultArtifactRepository(
"local",
localRepoRootDirectory.toURL()
.toExternalForm(),
defaultLayout );
Profile profile = new Profile();
profile.setId( "external" );
Repository repository = new Repository();
repository.setId( "temp" );
repository.setUrl( repoRootDirectory.toURL().toExternalForm() );
profile.addRepository( repository );
Properties props = System.getProperties();
ProfileActivationContext ctx = new DefaultProfileActivationContext( props, false );
ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx );
profileManager.addProfile( profile );
profileManager.explicitlyActivate( profile.getId() );
ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM,
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository )
.setGlobalProfileManager( profileManager ),
Collections.EMPTY_LIST,
false,
true );
assertEquals( 2, lineage.size() );
Iterator modelIterator = lineage.modelIterator();
assertEquals( current.getId(), ( (Model) modelIterator.next() ).getId() );
assertEquals( parent.getId(), ( (Model) modelIterator.next() ).getId() );
}
private File createTempDir( String basename )
throws IOException
{
File dir = File.createTempFile( "DefaultModelLineageBuilder." + basename + ".", "" );
dir.delete();
dir.mkdirs();
deleteDirOnExit( dir );
return dir;
}
private void deleteDirOnExit( File f )
{
toDelete.add( f );
}
private void writeModel( Model model,
File file )
throws IOException
{
Writer writer = null;
try
{
file.getParentFile().mkdirs();
writer = WriterFactory.newXmlWriter( file );
new MavenXpp3Writer().write( writer, model );
writer.flush();
}
finally
{
IOUtil.close( writer );
}
System.out.println( "Verifying that: " + file.getAbsolutePath() + " exists: "
+ file.exists() );
}
// TODO: Should this even work reliably? Isn't it a fluke if this is cached, which is what we're testing here??
// public void testReadPOMWithParentInOtherLocalFileWithBadRelativePath()
// throws Exception
// {
// // 1. create the parent model in a "local" POM file.
// File parentPOM = File.createTempFile( "DefaultModelLineageBuilder.test.", ".pom" );
// parentPOM.deleteOnExit();
//
// Model parent = createModel( "group", "parent", "1" );
//
// // 4. write the parent model to the local repo directory
// writeModel( parent, parentPOM );
//
// BuildContextManager buildContextManager = (BuildContextManager) lookup(
// BuildContextManager.ROLE,
// "default" );
//
// ProjectBuildCache cache = ProjectBuildCache.read( buildContextManager );
// cache.cacheModelFileForModel( parentPOM, parent );
// cache.store( buildContextManager );
//
// // 5. create the current pom with a parent-ref on the parent model
// Model current = createModel( "group", "current", "1" );
//
// Parent currentParent = new Parent();
// currentParent.setGroupId( "group" );
// currentParent.setArtifactId( "parent" );
// currentParent.setVersion( "1" );
// currentParent.setRelativePath( "../parent/pom.xml" );
//
// current.setParent( currentParent );
//
// // 6. write the current pom somewhere
// File currentPOM = File.createTempFile( "DefaultModelLineageBuilder.test.", ".pom" );
// currentPOM.deleteOnExit();
//
// writeModel( current, currentPOM );
//
// // 7. build the lineage.
// File localRepoRootDirectory = createTempDir( "localRepoRootDir" );
// ArtifactRepository localRepository = new DefaultArtifactRepository(
// "local",
// localRepoRootDirectory.toURL()
// .toExternalForm(),
// defaultLayout );
//
// ModelLineage lineage = modelLineageBuilder.buildModelLineage( currentPOM, localRepository,
// Collections.EMPTY_LIST, null,
// false, true );
//
// assertEquals( 2, lineage.size() );
//
// Iterator modelIterator = lineage.modelIterator();
//
// assertEquals( current.getId(), ( (Model) modelIterator.next() ).getId() );
// assertEquals( parent.getId(), ( (Model) modelIterator.next() ).getId() );
// }
private Model createModel( String groupId,
String artifactId,
String version )
{
Model model = new Model();
model.setGroupId( groupId );
model.setArtifactId( artifactId );
model.setVersion( version );
return model;
}
}

View File

@ -1,31 +0,0 @@
package org.apache.maven.extension.lineage;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
public class DefaultModelLineageTest
extends AbstractModelLineageTest
{
protected ModelLineage newModelLineage()
{
return new DefaultModelLineage();
}
}

View File

@ -34,8 +34,6 @@ import org.apache.maven.embedder.execution.MavenExecutionRequestPopulator;
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.errors.CoreReporterManager;
import org.apache.maven.execution.*;
import org.apache.maven.extension.BuildExtensionScanner;
import org.apache.maven.extension.ExtensionScanningException;
import org.apache.maven.lifecycle.LifecycleException;
import org.apache.maven.lifecycle.LifecycleUtils;
import org.apache.maven.lifecycle.plan.BuildPlan;
@ -135,8 +133,6 @@ public class MavenEmbedder
private MavenProjectBuilder mavenProjectBuilder;
private BuildExtensionScanner extensionScanner;
private MavenXpp3Reader modelReader;
private MavenXpp3Writer modelWriter;
@ -345,7 +341,7 @@ public class MavenEmbedder
// ----------------------------------------------------------------------
public MavenProject readProject( File mavenProject )
throws ProjectBuildingException, ExtensionScanningException, MavenExecutionException
throws ProjectBuildingException, MavenExecutionException
{
CoreErrorReporter errorReporter = request.getErrorReporter();
errorReporter.clearErrors();
@ -356,12 +352,8 @@ public class MavenEmbedder
}
private MavenProject readProject( File mavenProject, MavenExecutionRequest request )
throws ProjectBuildingException, ExtensionScanningException, MissingModuleException
throws ProjectBuildingException, MissingModuleException
{
getLogger().debug( "Scanning for extensions: " + mavenProject );
extensionScanner.scanForBuildExtensions( mavenProject, request, true );
getLogger().debug( "Building MavenProject instance: " + mavenProject );
return mavenProjectBuilder.build( mavenProject, request.getProjectBuildingConfiguration() );
@ -416,10 +408,6 @@ public class MavenEmbedder
{
return result.addException( e );
}
catch ( ExtensionScanningException e )
{
return result.addException( e );
}
catch ( MissingModuleException e )
{
return result.addException( e );
@ -676,8 +664,6 @@ public class MavenEmbedder
mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE );
extensionScanner = (BuildExtensionScanner) container.lookup( BuildExtensionScanner.ROLE );
// ----------------------------------------------------------------------
// Artifact related components
// ----------------------------------------------------------------------